#include "T2Archive.h" #include "T2PeopleDemandList.h" #include "T2PeopleTimeZoneList.h" #include "T2PeopleType.h" #include "T2PoolDef.h" #include "T2SeasonParamDef.h" #include "T2TenantMemberDef.h" #include "UT2Utils.h" T2PeopleDemandList::T2PeopleDemandList(T2PoolDef* inPoolDef, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef) : LArray(sizeof(T2PeopleTimeZoneList *)) , mSeasonParamDef(inSeasonParamDef) { int numDemand = inPoolDef->GetNumOfDemand(); for (int i = 0; i < numDemand; i++) { DemandInfo *theDemand = inPoolDef->GetDemandInfo(i); T2PeopleTimeZoneList *list = new T2PeopleTimeZoneList(theDemand->b, theDemand->a, inWorldDef); Add(list); } } T2PeopleDemandList::T2PeopleDemandList(T2Archive& inArchive, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef) : LArray(sizeof(T2PeopleTimeZoneList *)) , mSeasonParamDef(inSeasonParamDef) { unsigned int count; inArchive >> count; for (unsigned int i = 0; i < count; i++) { T2PeopleTimeZoneList *theTimeZoneList = new T2PeopleTimeZoneList(inArchive, inWorldDef); Add(theTimeZoneList); } } /*virtual*/ T2PeopleDemandList::~T2PeopleDemandList() { LArrayIterator iterator(*this); T2PeopleTimeZoneList *theTimeZoneList; while (iterator.Next(&theTimeZoneList)) delete theTimeZoneList; } void T2PeopleDemandList::Add(T2PeopleTimeZoneList* inTimeZoneList) { InsertItemsAt(1, mItemCount + 1, &inTimeZoneList); } void T2PeopleDemandList::Add(T2PoolGradeDef* inGradeDef) { T2PeopleTimeZoneList *theTimeZoneList; LArrayIterator iterator(*this); int theDemandType = 0; T2PeopleType peopleType; while (iterator.Next(&theTimeZoneList)) { peopleType.SetDemandType(theDemandType); T2PoolDefDemandElem *theDemandElem = inGradeDef->GetDemandElem(theDemandType); theTimeZoneList->Add(&peopleType, theDemandElem); theDemandType++; } } void T2PeopleDemandList::Init(unsigned int inMonth, unsigned int inSomeNum) { float theRate = 0.0f; if (mSeasonParamDef) theRate = mSeasonParamDef->GetRate(inMonth - 1); LArrayIterator iterator(*this); T2PeopleTimeZoneList *theTimeZoneList; while (iterator.Next(&theTimeZoneList)) theTimeZoneList->Init(inSomeNum, theRate); } void T2PeopleDemandList::IncHour(unsigned int inMonth) { float theRate = 1.0f; if (mSeasonParamDef) theRate = mSeasonParamDef->GetRate(inMonth - 1); LArrayIterator iterator(*this); T2PeopleTimeZoneList *theTimeZoneList; while (iterator.Next(&theTimeZoneList)) theTimeZoneList->IncHour(theRate); } T2PeopleTimeZoneList* T2PeopleDemandList::GetItem(int inDemandType) const { int index = inDemandType + 1; T2PeopleTimeZoneList *theList; if (!FetchItemAt(index, &theList)) theList = NULL; return theList; } BOOL T2PeopleDemandList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { BOOL found = false; T2PeopleTimeZoneList *theList = GetItem(inTenantMemberDef->GetDemandType()); if (theList) found = theList->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType); return found; } BOOL T2PeopleDemandList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) const { BOOL found = false; int theDemandType = inTenantMemberDef->GetDemandType(); if (theDemandType != -1) { T2PeopleTimeZoneList *theList = GetItem(theDemandType); if (theList) found = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); } else { for (int i = UT2Utils::Randomize(mItemCount) + 1, j = 0; !found && j < mItemCount; j++, i++) { if (i > mItemCount) i = 1; T2PeopleTimeZoneList *theList = GetItem(i); if (theList && !theList->IsFixed()) found = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); } } return found; } void T2PeopleDemandList::DispatchRestore(T2PeopleType& peopleType) { T2PeopleTimeZoneList *theList = GetItem(peopleType.GetDemandType()); if (theList) theList->DispatchRestore(peopleType); } void T2PeopleDemandList::DispatchAdd(T2PeopleType* peopleType) { T2PeopleTimeZoneList *theList = GetItem(peopleType->GetDemandType()); if (theList) theList->DispatchAdd(peopleType); } void T2PeopleDemandList::Write(T2Archive& archive) { unsigned int count = GetCount(); archive << count; for (unsigned int i = 0; i < count; i++) { T2PeopleTimeZoneList *theList = GetItem(i); if (theList) theList->Write(archive); } }