#include "LArray.h" #include "T2Archive.h" #include "T2DateTime.h" #include "T2MoverDef.h" #include "T2OuterObjDef.h" #include "T2Settlement.h" #include "T2TemplatePluginList.h" #include "T2TenantDef.h" #include "T2TowerDoc.h" #include "T2TowerMessage.h" T2Settlement::T2Settlement(T2TowerDoc* towerDoc, int funds) { Initialize(towerDoc, funds); } T2Settlement::T2Settlement(T2TowerDoc* towerDoc, T2Archive& archive) { Initialize(towerDoc, 0); archive >> mCurrentFunds; archive >> mPreviousFunds; archive >> mC; archive >> m10; archive >> m14; archive >> m18; archive >> m1C; unsigned int i, count; archive >> count; for (i = 0; i < count; i++) { short theType; int value; archive >> theType; archive >> value; T2TenantDef *theDef = mDocument->mTenantTemplates->FindTenantDef(theType); if (theDef && theDef->IsLoaded()) theDef->mSettlement = value; } archive >> count; for (i = 0; i < count; i++) { short theType; int value; archive >> theType; archive >> value; T2MoverDef *theDef = mDocument->mMoverTemplates->FindMoverDef(theType); if (theDef && theDef->IsLoaded()) theDef->mSettlement = value; } archive >> count; for (i = 0; i < count; i++) { short theType; int value; archive >> theType; archive >> value; T2OuterObjDef *theDef = mDocument->mOuterObjTemplates->FindOutObjDef(theType); if (theDef && theDef->IsLoaded()) theDef->mSettlement = value; } } T2Settlement::~T2Settlement() { } T2Archive& T2Settlement::Write(T2Archive& archive) const { archive << mCurrentFunds; archive << mPreviousFunds; archive << mC; archive << m10; archive << m14; archive << m18; archive << m1C; archive << (unsigned int) mDocument->GetTenantTemplates()->GetCount(); LArrayIterator theTenantIter(*mDocument->GetTenantTemplates()); T2TenantDef *theTenantDef = NULL; while (theTenantIter.Next(&theTenantDef)) { archive << (short) theTenantDef->GetToolType(); archive << theTenantDef->mSettlement; } archive << (unsigned int) mDocument->GetMoverTemplates()->GetCount(); LArrayIterator theMoverIter(*mDocument->GetMoverTemplates()); T2MoverDef *theMoverDef = NULL; while (theMoverIter.Next(&theMoverDef)) { archive << (short) theMoverDef->GetToolType(); archive << theMoverDef->mSettlement; } archive << (unsigned int) mDocument->GetOuterObjTemplates()->GetCount(); LArrayIterator theOuterObjIter(*mDocument->GetOuterObjTemplates()); T2OuterObjDef *theOuterObjDef = NULL; while (theOuterObjIter.Next(&theOuterObjDef)) { archive << (short) theOuterObjDef->GetToolType(); archive << theOuterObjDef->mSettlement; } return archive; } void T2Settlement::DoPay(int funds, short fundGroup) { mCurrentFunds -= funds; switch (fundGroup) { case kFundGroup1: m10 += funds; break; case kFundGroup2: m14 += funds; break; case kFundGroup4: m1C += funds; break; } } void T2Settlement::DoPayTool(int funds, short fundGroup, T2ToolDef* inToolDef) { mCurrentFunds -= funds; #line 171 _ASSERT(inToolDef != NULL); switch (fundGroup) { case kFundGroup0: mC += funds; inToolDef->mSettlement += funds; break; case kFundGroup3: m18 += funds; inToolDef->mSettlement += funds; break; } } void T2Settlement::EmitPayToolMessage(T2TowerDoc* towerDoc, T2ToolDef* inToolDef, const CString& str, int length, int type) { BOOL canPay = true; T2DateTime *theNow = towerDoc->GetNow(); #line 197 _ASSERT(theNow != NULL); if (length && type) { T2DateTime *theTimeLimit = GetTimeLimitOfMessage(towerDoc, inToolDef, type); if (theTimeLimit && *theNow <= *theTimeLimit) canPay = false; } if (canPay) { T2DateTime *theTimeLimit = CalcTimeLimitOfMessage(theNow, length); #line 210 _ASSERT(theTimeLimit != NULL); SetTimeLimitOfMessage(towerDoc, inToolDef, type, theTimeLimit); delete theTimeLimit; towerDoc->towerDoc_vf13C()->InfoBarMessage(str, 120, "Cash"); } } T2DateTime* T2Settlement::GetTimeLimitOfMessage(T2TowerDoc* towerDoc, T2ToolDef* inToolDef, int type) { T2DateTime *theTimeLimit = NULL; switch (type) { case kTimeLimitTypeNone: break; case kTimeLimitTypeTool: theTimeLimit = inToolDef->mToolQuietUntil; if (!theTimeLimit) { theTimeLimit = new T2DateTime; #line 234 _ASSERT(theTimeLimit != NULL); inToolDef->mToolQuietUntil = theTimeLimit; } break; case kTimeLimitTypeCategory: theTimeLimit = inToolDef->mCategoryQuietUntil; if (!theTimeLimit) { theTimeLimit = FindCategoryTimeLimit(towerDoc, inToolDef); #line 243 _ASSERT(theTimeLimit != NULL); LinkCategoryTimeLimit(towerDoc, inToolDef, theTimeLimit); } break; } return theTimeLimit; } void T2Settlement::SetTimeLimitOfMessage(T2TowerDoc* inDoc, T2ToolDef* inToolDef, int type, T2DateTime* inTimeLimit) { switch (type) { case kTimeLimitTypeNone: break; case kTimeLimitTypeTool: if (!inToolDef->mToolQuietUntil) { inToolDef->mToolQuietUntil = new T2DateTime(*inTimeLimit); #line 267 _ASSERT(inToolDef->mToolQuietUntil); } else { *inToolDef->mToolQuietUntil = *inTimeLimit; } break; case kTimeLimitTypeCategory: { T2DateTime *theTimeLimit = inToolDef->mCategoryQuietUntil; if (!theTimeLimit) { theTimeLimit = FindCategoryTimeLimit(inDoc, inToolDef); #line 279 _ASSERT(theTimeLimit != NULL); LinkCategoryTimeLimit(inDoc, inToolDef, theTimeLimit); } *theTimeLimit = *inTimeLimit; break; } } } T2DateTime* T2Settlement::FindCategoryTimeLimit(T2TowerDoc* inDoc, T2ToolDef* inToolDef) { T2DateTime *theTimeLimit = NULL; T2TemplatePluginList *thePluginList = NULL; int theCategory = inToolDef->GetCategory(); switch (theCategory) { default: thePluginList = inDoc->GetTenantTemplates(); break; case 20: thePluginList = inDoc->GetMoverTemplates(); break; case 200: thePluginList = inDoc->GetOuterObjTemplates(); break; } if (thePluginList) { LArrayIterator iterator(*thePluginList); T2ToolDef *theToolDef; while (!theTimeLimit && iterator.Next(&theToolDef)) { if (theToolDef->GetCategory() == theCategory) theTimeLimit = theToolDef->mCategoryQuietUntil; } } if (!theTimeLimit) { theTimeLimit = new T2DateTime; #line 315 _ASSERT(theTimeLimit != NULL); mCategoryTimeLimitList->Add(&theTimeLimit); } return theTimeLimit; } void T2Settlement::LinkCategoryTimeLimit(T2TowerDoc* inDoc, T2ToolDef* inToolDef, T2DateTime* inTimeLimit) { T2TemplatePluginList *thePluginList = NULL; int theCategory = inToolDef->GetCategory(); switch (theCategory) { default: thePluginList = inDoc->GetTenantTemplates(); break; case 20: thePluginList = inDoc->GetMoverTemplates(); break; case 200: thePluginList = inDoc->GetOuterObjTemplates(); break; } if (thePluginList) { LArrayIterator iterator(*thePluginList); T2ToolDef *theToolDef; while (iterator.Next(&theToolDef)) { if (theToolDef->GetCategory() == theCategory) { #line 344 _ASSERT(theToolDef->mCategoryQuietUntil == NULL || theToolDef->mCategoryQuietUntil == inTimeLimit); theToolDef->mCategoryQuietUntil = inTimeLimit; } } } } /*static*/ T2DateTime* T2Settlement::CalcTimeLimitOfMessage(T2DateTime* inBaseTime, int length) { T2DateTime *theTimeLimit = new T2DateTime(*inBaseTime); #line 360 _ASSERT(theTimeLimit != NULL); switch (length) { case kTimeLimitLengthNone: break; case kTimeLimitLength3Min: theTimeLimit->AddMinutes(3); break; case kTimeLimitLength30Min: theTimeLimit->AddMinutes(30); break; case kTimeLimitLength1Month: theTimeLimit->mMonth += 1; theTimeLimit->mRawMinutes = 0; theTimeLimit->mSeconds = 0; theTimeLimit->Validate(); break; } return theTimeLimit; } int T2Settlement::GetCurrentFunds() const { return mCurrentFunds; } int T2Settlement::GetPreviousFunds() const { return mPreviousFunds; } int T2Settlement::GetTotalSettlement(short fundGroup) const { int total = 0; switch (fundGroup) { case kFundGroup0: total = mC; break; case kFundGroup1: total = m10; break; case kFundGroup2: total = m14; break; case kFundGroup3: total = m18; break; case kFundGroup4: total = m1C; break; case kFundGroup5: total = m18 + mC; break; case kFundGroup6: total = m1C + m14; break; } return total; } int T2Settlement::GetToolSettlement(T2ToolDef* inToolDef) const { int result = 0; if (inToolDef) result = inToolDef->mSettlement; return result; } int T2Settlement::GetCategorySettlement(int inCategory) const { int result = 0; switch (inCategory) { default: { LArrayIterator theTenantIter(*mDocument->GetTenantTemplates()); T2ToolDef *theTenantDef = NULL; while (theTenantIter.Next(&theTenantDef)) { if (theTenantDef->GetCategory() == inCategory) result += theTenantDef->mSettlement; } break; } case 20: { LArrayIterator theMoverIter(*mDocument->GetMoverTemplates()); T2ToolDef *theMoverDef = NULL; while (theMoverIter.Next(&theMoverDef)) { result += theMoverDef->mSettlement; } break; } case 200: { LArrayIterator theOuterObjIter(*mDocument->GetOuterObjTemplates()); T2ToolDef *theOuterObjDef = NULL; while (theOuterObjIter.Next(&theOuterObjDef)) { result += theOuterObjDef->mSettlement; } break; } } return result; } void T2Settlement::Initialize(T2TowerDoc* towerDoc, int funds) { mDocument = towerDoc; #line 473 _ASSERT(mDocument != NULL); mCurrentFunds = funds; mPreviousFunds = mCurrentFunds; mC = 0; m10 = 0; m14 = 0; m18 = 0; m1C = 0; mCategoryTimeLimitList = new LArray; #line 485 _ASSERT(mCategoryTimeLimitList != NULL); } void T2Settlement::Update() { mPreviousFunds = mCurrentFunds; mC = 0; m10 = 0; m14 = 0; m18 = 0; m1C = 0; LArrayIterator theTenantIter(*mDocument->GetTenantTemplates()); T2TenantDef *theTenantDef = NULL; while (theTenantIter.Next(&theTenantDef)) { theTenantDef->mSettlement = 0; } LArrayIterator theMoverIter(*mDocument->GetMoverTemplates()); T2MoverDef *theMoverDef = NULL; while (theMoverIter.Next(&theMoverDef)) { theMoverDef->mSettlement = 0; } LArrayIterator theOuterObjIter(*mDocument->GetOuterObjTemplates()); T2OuterObjDef *theOuterObjDef = NULL; while (theOuterObjIter.Next(&theOuterObjDef)) { theOuterObjDef->mSettlement = 0; } }