summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2PeopleTimeZoneList.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2PeopleTimeZoneList.cpp156
1 files changed, 144 insertions, 12 deletions
diff --git a/src/T2DLL/T2PeopleTimeZoneList.cpp b/src/T2DLL/T2PeopleTimeZoneList.cpp
index 8cb68ee..b9601aa 100644
--- a/src/T2DLL/T2PeopleTimeZoneList.cpp
+++ b/src/T2DLL/T2PeopleTimeZoneList.cpp
@@ -1,43 +1,175 @@
+#include "CResFile.h"
+#include "T2Archive.h"
#include "T2PeopleTimeZoneList.h"
+#include "T2PeopleType.h"
+#include "T2PeopleTypeArray.h"
+#include "T2PoolDef.h"
+#include "T2WorldDef.h"
-T2PeopleTimeZoneList::T2PeopleTimeZoneList(unsigned int, unsigned int, T2WorldDef*) {
+T2PeopleTimeZoneList::T2PeopleTimeZoneList(unsigned int someNum, unsigned int isFixed, T2WorldDef* worldDef)
+ : LArray(sizeof(T2PeopleTypeArray *))
+{
+ mIsFixed = isFixed;
+ _20 = 0;
+ mHoursPerItem = 0;
+ mCurrentItem = 0;
+ mCurrentHour = 0;
+ mWorldDef = worldDef;
+
+ for (unsigned int i = 0; i < someNum; i++) {
+ T2PeopleTypeArray *array = new T2PeopleTypeArray(isFixed);
+ Add(array);
+ }
+
+ mHoursPerItem = 24 / someNum;
}
-T2PeopleTimeZoneList::T2PeopleTimeZoneList(T2Archive&, T2WorldDef*) {
+T2PeopleTimeZoneList::T2PeopleTimeZoneList(T2Archive& archive, T2WorldDef* worldDef)
+ : LArray(sizeof(T2PeopleTypeArray *))
+{
+ _20 = 0;
+ mWorldDef = worldDef;
+
+ int count;
+ archive >> count;
+
+ unsigned char uc;
+ char c;
+
+ archive >> uc;
+ mIsFixed = uc != 0;
+
+ archive >> c;
+ mHoursPerItem = c;
+ archive >> c;
+ mCurrentItem = c;
+ archive >> c;
+ mCurrentHour = c;
+
+ for (int i = 0; i < count; i++) {
+ T2PeopleTypeArray *theArray = new T2PeopleTypeArray(archive);
+ Add(theArray);
+ }
}
/*virtual*/ T2PeopleTimeZoneList::~T2PeopleTimeZoneList() {
+ LArrayIterator iterator(*this);
+ T2PeopleTypeArray *theArray;
+
+ while (iterator.Next(&theArray))
+ delete theArray;
}
-void T2PeopleTimeZoneList::Add(T2PeopleTypeArray*) {
+void T2PeopleTimeZoneList::Add(T2PeopleTypeArray* inArray) {
+ InsertItemsAt(1, mItemCount + 1, &inArray);
}
-void T2PeopleTimeZoneList::Add(T2PeopleType*, T2PoolDefDemandElem*) {
+void T2PeopleTimeZoneList::Add(T2PeopleType* inPeopleType, T2PoolDefDemandElem* inDemandElem) {
+ LArrayIterator iterator(*this);
+ T2PeopleTypeArray *theArray;
+ unsigned int timeZoneType = 0;
+
+ while (iterator.Next(&theArray)) {
+ inPeopleType->SetTimeZoneType(timeZoneType);
+
+ TimeZoneInfo *theTimeZoneInfo = inDemandElem->GetTimeZoneInfo(timeZoneType);
+ CResFile resFile;
+ if (resFile.OpenResource(mWorldDef->mModuleHandle, theTimeZoneInfo->m0, 'PzDf')) {
+ T2PoolTimeZoneDef *theTimeZoneDef = new T2PoolTimeZoneDef(resFile);
+ theArray->Add(inPeopleType, theTimeZoneDef, theTimeZoneInfo->m4);
+ delete theTimeZoneDef;
+ } else {
+ CString str;
+ str.Format("** T2PeopleTimeZoneDef not found : %d **\r\n", theTimeZoneInfo->m0);
+ OutputDebugString(str);
+ }
+
+ timeZoneType++;
+ }
}
-void T2PeopleTimeZoneList::Init(unsigned int, float) {
+void T2PeopleTimeZoneList::Init(unsigned int someNum, float limit) {
+ mCurrentItem = someNum / mHoursPerItem;
+ mCurrentHour = someNum % mHoursPerItem;
+
+ LArrayIterator iterator(*this);
+ T2PeopleTypeArray *theArray;
+
+ while (iterator.Next(&theArray))
+ theArray->InitSearchLimit(limit);
}
-void T2PeopleTimeZoneList::IncHour(float) {
+void T2PeopleTimeZoneList::IncHour(float limit) {
+ mCurrentHour++;
+ if (mCurrentHour >= mHoursPerItem) {
+ T2PeopleTypeArray *thePrevArray = CurrentItem();
+ if (thePrevArray)
+ thePrevArray->AdjustLife();
+
+ mCurrentHour = 0;
+ mCurrentItem++;
+ if (mCurrentItem > GetCount())
+ mCurrentItem = 0;
+
+ T2PeopleTypeArray *theNewArray = CurrentItem();
+ if (theNewArray)
+ theNewArray->InitSearchLimit(limit);
+ }
}
-T2PeopleTypeArray* T2PeopleTimeZoneList::GetItem(int) const {
+T2PeopleTypeArray* T2PeopleTimeZoneList::GetItem(int inIndex) const {
+ T2PeopleTypeArray *theArray;
+ int index = inIndex + 1;
+ if (!FetchItemAt(index, &theArray))
+ theArray = NULL;
+ return theArray;
}
T2PeopleTypeArray* T2PeopleTimeZoneList::CurrentItem() const {
+ return GetItem(mCurrentItem);
}
-int T2PeopleTimeZoneList::Find(T2TenantMemberDef*, int, unsigned int, int) const {
+BOOL T2PeopleTimeZoneList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const {
+ T2PeopleTypeArray *theArray = CurrentItem();
+ return theArray->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType);
}
-int T2PeopleTimeZoneList::Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&) {
+BOOL T2PeopleTimeZoneList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) {
+ T2PeopleTypeArray *theArray = CurrentItem();
+ return theArray->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType);
}
-void T2PeopleTimeZoneList::DispatchRestore(T2PeopleType&) {
+void T2PeopleTimeZoneList::DispatchRestore(T2PeopleType& inPeopleType) {
+ T2PeopleTypeArray *theArray = GetItem(inPeopleType.GetTimeZoneType());
+ if (theArray)
+ theArray->Restore(inPeopleType);
}
-void T2PeopleTimeZoneList::DispatchAdd(T2PeopleType*) {
+void T2PeopleTimeZoneList::DispatchAdd(T2PeopleType* inPeopleType) {
+ T2PeopleTypeArray *theArray = GetItem(inPeopleType->GetTimeZoneType());
+ if (theArray)
+ theArray->Add(inPeopleType, 1);
}
-void T2PeopleTimeZoneList::Write(T2Archive&) {
+void T2PeopleTimeZoneList::Write(T2Archive& archive) {
+ archive << mItemCount;
+
+ unsigned char uc;
+ char c;
+
+ uc = mIsFixed ? 1 : 0;
+ archive << uc;
+
+ c = mHoursPerItem;
+ archive << c;
+ c = mCurrentItem;
+ archive << c;
+ c = mCurrentHour;
+ archive << c;
+
+ for (int i = 0; i < mItemCount; i++) {
+ T2PeopleTypeArray *theArray = GetItem(i);
+ if (theArray)
+ theArray->Write(archive);
+ }
}