#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 type; int num; archive >> type; archive >> num; T2TenantDef *def = mDocument->mTenantTemplates->FindTenantDef(type); if (def && def->IsLoaded()) def->mSettlement = num; } archive >> count; for (i = 0; i < count; i++) { short type; int num; archive >> type; archive >> num; T2MoverDef *def = mDocument->mMoverTemplates->FindMoverDef(type); if (def && def->IsLoaded()) def->mSettlement = num; } archive >> count; for (i = 0; i < count; i++) { short type; int num; archive >> type; archive >> num; T2OuterObjDef *def = mDocument->mOuterObjTemplates->FindOutObjDef(type); if (def && def->IsLoaded()) def->mSettlement = num; } } 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->towerDoc_vf178()->GetCount(); LArrayIterator tenantIterator(*mDocument->towerDoc_vf178()); T2TenantDef *tenantDef = NULL; while (tenantIterator.Next(&tenantDef)) { archive << (short) tenantDef->GetToolType(); archive << tenantDef->mSettlement; } archive << (unsigned int) mDocument->towerDoc_vf17C()->GetCount(); LArrayIterator moverIterator(*mDocument->towerDoc_vf17C()); T2MoverDef *moverDef = NULL; while (moverIterator.Next(&moverDef)) { archive << (short) moverDef->GetToolType(); archive << moverDef->mSettlement; } archive << (unsigned int) mDocument->towerDoc_vf180()->GetCount(); LArrayIterator outObjIterator(*mDocument->towerDoc_vf180()); T2OuterObjDef *outObjDef = NULL; while (outObjIterator.Next(&outObjDef)) { archive << (short) outObjDef->GetToolType(); archive << outObjDef->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 flag = true; T2DateTime *theNow = towerDoc->towerDoc_vf120(); #line 197 _ASSERT(theNow != NULL); if (length && type) { T2DateTime *theTimeLimit = GetTimeLimitOfMessage(towerDoc, inToolDef, type); if (theTimeLimit && *theNow >= *theTimeLimit) flag = false; } if (flag) { 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 != NULL); } 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 *theList = NULL; int theCategory = inToolDef->GetCategory(); switch (theCategory) { default: theList = inDoc->towerDoc_vf178(); break; case 20: theList = inDoc->towerDoc_vf17C(); break; case 200: theList = inDoc->towerDoc_vf180(); break; } if (theList) { LArrayIterator iterator(*theList); 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 *theList = NULL; int theCategory = inToolDef->GetCategory(); switch (theCategory) { default: theList = inDoc->towerDoc_vf178(); break; case 20: theList = inDoc->towerDoc_vf17C(); break; case 200: theList = inDoc->towerDoc_vf180(); break; } if (theList) { LArrayIterator iterator(*theList); 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 iterator(*mDocument->towerDoc_vf178()); T2ToolDef *theToolDef = NULL; while (iterator.Next(&theToolDef)) { if (theToolDef->GetCategory() == inCategory) result += theToolDef->mSettlement; } break; } case 20: { LArrayIterator iterator(*mDocument->towerDoc_vf17C()); T2ToolDef *theToolDef = NULL; while (iterator.Next(&theToolDef)) { result += theToolDef->mSettlement; } break; } case 200: { LArrayIterator iterator(*mDocument->towerDoc_vf180()); T2ToolDef *theToolDef = NULL; while (iterator.Next(&theToolDef)) { result += theToolDef->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 tenantIterator(*mDocument->towerDoc_vf178()); T2TenantDef *tenantDef = NULL; while (tenantIterator.Next(&tenantDef)) { tenantDef->mSettlement = 0; } LArrayIterator moverIterator(*mDocument->towerDoc_vf17C()); T2MoverDef *moverDef = NULL; while (moverIterator.Next(&moverDef)) { moverDef->mSettlement = 0; } LArrayIterator outObjIterator(*mDocument->towerDoc_vf180()); T2OuterObjDef *outObjDef = NULL; while (outObjIterator.Next(&outObjDef)) { outObjDef->mSettlement = 0; } }