diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2Pool.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2Pool.cpp | 237 |
1 files changed, 220 insertions, 17 deletions
diff --git a/src/T2DLL/T2Pool.cpp b/src/T2DLL/T2Pool.cpp index 1b1d709..8d280c2 100644 --- a/src/T2DLL/T2Pool.cpp +++ b/src/T2DLL/T2Pool.cpp @@ -1,58 +1,261 @@ +#include "CResFile.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleDef.h" +#include "T2PeopleDemandList.h" +#include "T2PeopleType.h" #include "T2Pool.h" +#include "T2PoolDef.h" +#include "T2SeasonParamDef.h" +#include "T2TemplatePluginList.h" +#include "T2TenantMemberDef.h" +#include "T2TenantMemberTableDef.h" +#include "T2WorldDef.h" -T2Pool::T2Pool(T2PoolDef*, T2SeasonParamDef*, T2TemplatePluginList*, T2PeopleArrayList*, int, unsigned int, unsigned int, T2WorldDef*) { +T2Pool::T2Pool(T2PoolDef* inDef, T2SeasonParamDef* inSeason, T2TemplatePluginList* inPluginList, T2PeopleArrayList* inPeopleList, int inLevel, unsigned int inIndex, unsigned int inSomeNum, T2WorldDef* inWorldDef) { + mLevel = 0; + mSpecialFlag = inDef->Get20(); + mPopulation = 0; + mLostPopulation = 0; + mPrevPopulation = 0; + + mPoolDef = inDef; + mPlugins = inPluginList; + mPeopleList = inPeopleList; + mDemandList = new T2PeopleDemandList(mPoolDef, inSeason, inWorldDef); + + for (int level = 1; level <= inLevel; level++) + GameLevelChanged(level); + + mDemandList->Init(inIndex, inSomeNum); } -T2Pool::T2Pool(T2Archive&, T2PoolDef*, T2SeasonParamDef*, T2TemplatePluginList*, T2PeopleArrayList*, T2WorldDef*) { +T2Pool::T2Pool(T2Archive& inArchive, T2PoolDef* inDef, T2SeasonParamDef* inSeason, T2TemplatePluginList* inPluginList, T2PeopleArrayList* inPeopleList, T2WorldDef* inWorldDef) { + short s; + + inArchive >> s; + mLevel = s; + + inArchive >> mPopulation; + inArchive >> mLostPopulation; + + mPrevPopulation = mPopulation; + mSpecialFlag = inDef->Get20(); + + mPoolDef = inDef; + mPlugins = inPluginList; + mPeopleList = inPeopleList; + mDemandList = new T2PeopleDemandList(inArchive, inSeason, inWorldDef); } /*virtual*/ T2Pool::~T2Pool() { + if (mDemandList) + delete mDemandList; } -void T2Pool::GameLevelChanged(int) { +void T2Pool::GameLevelChanged(int inLevel) { + BOOL changed = (mLevel < inLevel); + mLevel = inLevel; + + if (changed) { + int resID = mPoolDef->GetGradeDefResID(mLevel); + if (resID > 0) { + HMODULE theModule = mPoolDef->GetModuleHandle(); + + CResFile resFile; + resFile.OpenResource(theModule, resID, 'PgDf'); + + T2PoolGradeDef *theGradeDef = NULL; + theGradeDef = new T2PoolGradeDef(resFile); + mDemandList->Add(theGradeDef); + delete theGradeDef; + } + } } -void T2Pool::IncHour(T2DateTime*) { +void T2Pool::IncHour(T2DateTime* inDateTime) { + mDemandList->IncHour(inDateTime->GetMonth()); + + int hour = inDateTime->Get24Hour(); + if (hour == 0) + DayChanged(); } void T2Pool::DayChanged() { + mPopulation -= mLostPopulation; + mLostPopulation = 0; } -int T2Pool::IsChangePopulation() { +BOOL T2Pool::IsChangePopulation() { + BOOL changed = false; + + if (mPopulation != mPrevPopulation) { + mPrevPopulation = mPopulation; + changed = true; + } + + return changed; } -int T2Pool::Find(T2TenantMemberDef*, int, unsigned int, int) const { +BOOL T2Pool::Find(T2TenantMemberDef* inMember, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + return mDemandList->Find(inMember, inEconoType, inTransportType, inCheckOnlyFirstEconoType); } -int T2Pool::Find(T2TenantMemberTableDef*, int, unsigned int, int) const { +BOOL T2Pool::Find(T2TenantMemberTableDef* inTable, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + BOOL found = false; + int numOfElem = inTable->GetNumOfElem(); + + if (numOfElem > 0) { + found = true; + int econoType = inEconoType; + BOOL checkOnlyFirstEconoType = inCheckOnlyFirstEconoType; + + for (int i = 0; found && i < numOfElem; i++) { + if ((i == 1) && inCheckOnlyFirstEconoType) { + econoType = -1; + checkOnlyFirstEconoType = false; + } + + T2TenantMemberDef *theElem = inTable->GetElem(i); + if (theElem) { + if (!Find(theElem, econoType, inTransportType, checkOnlyFirstEconoType)) + found = false; + } else { + found = false; + } + } + } + + return found; } -T2People* T2Pool::Call(T2TenantMemberDef*, int, unsigned int, unsigned int) { +T2People* T2Pool::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, unsigned int inSpecialFlag) { + T2People *thePeople = NULL; + T2PeopleType type; + + if (mDemandList->Call(inTenantMemberDef, inEconoType, inTransportType, type)) { + thePeople = RecoverPeople(&type); + if (thePeople) + thePeople->SetSpecialFlag(inSpecialFlag); + } + + return thePeople; } -void T2Pool::Enter(T2People*) { +void T2Pool::Enter(T2People* inPeople) { + if (inPeople->IsSetSpecialFlag(kSpecialFlag2)) + inPeople->IncEstimate(-30); + + inPeople->ClearDestination(); + inPeople->UpdateEstimation(); + inPeople->ChangeStatus(kStatus1); + inPeople->SetCurrEquipID(1); + + if (inPeople->IsVIP() || inPeople->IsMaru() || inPeople->IsReggae()) + return; + + if (inPeople->IsGeneral()) { + int estimate = inPeople->GetEstimate(); + T2PeopleType type; + ShrinkPeople(inPeople, type); + + if (estimate > 200) { + mDemandList->DispatchRestore(type); + DuplicatePeople(&type); + } else if (estimate > 70) { + static int counter = 0; + mDemandList->DispatchRestore(type); + counter++; + if (counter >= 5) { + DuplicatePeople(&type); + counter = 0; + } + } else if (type.IsImmortal()) { + mDemandList->DispatchRestore(type); + } + } else { + inPeople->ClearSpecialFlag(mSpecialFlag); + } } -void T2Pool::Leave(T2People*) { +void T2Pool::Leave(T2People* inPeople) { + inPeople->SetPrevTenantType(-1); } -T2People* T2Pool::RecoverPeople(T2PeopleType*) { +T2People* T2Pool::RecoverPeople(T2PeopleType* inPeopleType) { + T2People *thePeople = NULL; + T2PeopleDef *thePeopleDef = mPlugins->FindPeopleDef(inPeopleType->GetSilhouetteType()); + + if (thePeopleDef) { + thePeople = mPeopleList->FindUnusedPeople(); + if (thePeople) { + thePeople->Initialize(thePeopleDef, inPeopleType); + thePeople->SetUsed(true); + thePeople->SetStatus(kStatus1); + + unsigned int tenantID = 1; + if (inPeopleType->GetTransportType() == kTransportLobbyRight) + tenantID++; + thePeople->SetHomeTenant(tenantID); + thePeople->SetWorkTenant(tenantID); + } + } else { + CString err; + err.Format("** Undefined people type : %d **\r\n", inPeopleType->GetSilhouetteType()); + OutputDebugString(err); + } + + mPopulation++; + return thePeople; } -void T2Pool::ShrinkPeople(T2People*, T2PeopleType&) { +void T2Pool::ShrinkPeople(T2People* inPeople, T2PeopleType& outPeopleType) { +#line 293 + _ASSERT(inPeople->GetPeopleType() != NULL); + + outPeopleType = *inPeople->GetPeopleType(); + inPeople->SetUsed(false); + mLostPopulation++; } -void T2Pool::DuplicatePeople(T2PeopleType*) { +void T2Pool::DuplicatePeople(T2PeopleType* inPeopleType) { + T2PeopleType type; + inPeopleType->Duplicate(type); + mDemandList->DispatchAdd(&type); } -void T2Pool::RemovePeople(T2People*) { +void T2Pool::RemovePeople(T2People* inPeople) { + T2PeopleType type; + ShrinkPeople(inPeople, type); + if (type.IsImmortal()) + mDemandList->DispatchRestore(type); } -T2People* T2Pool::BornVIP(int, int) { +T2People* T2Pool::BornVIP(int inSilhouetteType, int inEconoType) { + T2PeopleType type; + type.SetSilhouetteType(inSilhouetteType); + type.SetTransportType(kTransportLobbyLeft); + if (inEconoType < 0) + type.SetEconoType(kEconoType7); + else + type.SetEconoType(inEconoType); + type.SetLifeCount(127); + + return RecoverPeople(&type); } -void T2Pool::DeadVIP(T2People*) { +void T2Pool::DeadVIP(T2People* inPeople) { + T2PeopleType type; + ShrinkPeople(inPeople, type); } -void T2Pool::Write(T2Archive&) { +void T2Pool::Write(T2Archive& inArchive) { + inArchive << (short) mLevel; + inArchive << mPopulation; + inArchive << mLostPopulation; + + if (mDemandList) + mDemandList->Write(inArchive); } |