From c0c336500955a23e344651e5412c9d9d441ef4ee Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 28 Jun 2023 22:22:32 +0100 Subject: first pass of T2DLL --- src/T2DLL/T2PeopleDemandList.cpp | 132 +++++++++++++++++++++++++++++++++++---- 1 file changed, 120 insertions(+), 12 deletions(-) (limited to 'src/T2DLL/T2PeopleDemandList.cpp') diff --git a/src/T2DLL/T2PeopleDemandList.cpp b/src/T2DLL/T2PeopleDemandList.cpp index 06e943c..e8def3b 100644 --- a/src/T2DLL/T2PeopleDemandList.cpp +++ b/src/T2DLL/T2PeopleDemandList.cpp @@ -1,40 +1,148 @@ +#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*, T2SeasonParamDef*, T2WorldDef*) { +T2PeopleDemandList::T2PeopleDemandList(T2PoolDef* inPoolDef, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef) + : LArray(sizeof(T2PeopleTimeZoneList *)) + , mSeasonParamDef(inSeasonParamDef) +{ + int count = inPoolDef->GetNumOfDemand(); + for (int i = 0; i < count; i++) { + DemandInfo *theDemandInfo = inPoolDef->GetDemandInfo(i); + T2PeopleTimeZoneList *theTimeZoneList = new T2PeopleTimeZoneList(theDemandInfo->b, theDemandInfo->a, inWorldDef); + Add(theTimeZoneList); + } } -T2PeopleDemandList::T2PeopleDemandList(T2Archive&, T2SeasonParamDef*, T2WorldDef*) { +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*) { +void T2PeopleDemandList::Add(T2PeopleTimeZoneList* inTimeZoneList) { + InsertItemsAt(1, mItemCount + 1, &inTimeZoneList); } -void T2PeopleDemandList::Add(T2PoolGradeDef*) { +void T2PeopleDemandList::Add(T2PoolGradeDef* inGradeDef) { + LArrayIterator iterator(*this); + int demandType = 0; + T2PeopleType peopleType; + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) { + peopleType.SetDemandType(demandType); + + T2PoolDefDemandElem *theDemandElem = inGradeDef->GetDemandElem(demandType); + theTimeZoneList->Add(&peopleType, theDemandElem); + + demandType++; + } } -void T2PeopleDemandList::Init(unsigned int, unsigned int) { +void T2PeopleDemandList::Init(unsigned int inMonth, unsigned int inSomeNum) { + float rate = 0.0f; + if (mSeasonParamDef) + rate = mSeasonParamDef->GetRate(inMonth - 1); + + LArrayIterator iterator(*this); + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) + theTimeZoneList->Init(inSomeNum, rate); } -void T2PeopleDemandList::IncHour(unsigned int) { +void T2PeopleDemandList::IncHour(unsigned int inMonth) { + float rate = 0.0f; + if (mSeasonParamDef) + rate = mSeasonParamDef->GetRate(inMonth - 1); + + LArrayIterator iterator(*this); + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) + theTimeZoneList->IncHour(rate); } -T2PeopleTimeZoneList* T2PeopleDemandList::GetItem(int) const { +T2PeopleTimeZoneList* T2PeopleDemandList::GetItem(int inDemandType) const { + int index = inDemandType + 1; + T2PeopleTimeZoneList *theList; + if (!FetchItemAt(index, &theList)) + theList = NULL; + return theList; } -int T2PeopleDemandList::Find(T2TenantMemberDef*, int, unsigned int, int) const { +BOOL T2PeopleDemandList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + BOOL result = false; + + T2PeopleTimeZoneList *theList = GetItem(inTenantMemberDef->GetDemandType()); + if (theList) + result = theList->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType); + + return result; } -int T2PeopleDemandList::Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&) const { +BOOL T2PeopleDemandList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) const { + BOOL result = false; + int demandType = inTenantMemberDef->GetDemandType(); + + if (demandType != -1) { + T2PeopleTimeZoneList *theList = GetItem(demandType); + if (theList) + result = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); + } else { + for (int i = UT2Utils::Randomize(mItemCount) + 1, j = 0; !result && j < mItemCount; j++, i++) { + if (i > mItemCount) + i = 1; + + T2PeopleTimeZoneList *theList = GetItem(i); + if (theList && !theList->IsFixed()) + result = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); + } + } + + return result; } -void T2PeopleDemandList::DispatchRestore(T2PeopleType&) { +void T2PeopleDemandList::DispatchRestore(T2PeopleType& peopleType) { + T2PeopleTimeZoneList *theList = GetItem(peopleType.GetDemandType()); + if (theList) + theList->DispatchRestore(peopleType); } -void T2PeopleDemandList::DispatchAdd(T2PeopleType*) { +void T2PeopleDemandList::DispatchAdd(T2PeopleType* peopleType) { + T2PeopleTimeZoneList *theList = GetItem(peopleType->GetDemandType()); + if (theList) + theList->DispatchAdd(peopleType); } -void T2PeopleDemandList::Write(T2Archive&) { +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); + } } -- cgit v1.2.3