#include "StdAfx.h" #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 someNum, unsigned int isFixed, T2WorldDef* worldDef) : LArray(sizeof(T2PeopleTypeArray *)) { mIsFixed = isFixed; _20 = false; 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& archive, T2WorldDef* worldDef) : LArray(sizeof(T2PeopleTypeArray *)) { #pragma var_order(uc, c, i, count) _20 = false; 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 *array = new T2PeopleTypeArray(archive); Add(array); } } /*virtual*/ T2PeopleTimeZoneList::~T2PeopleTimeZoneList() { T2PeopleTypeArray *array; LArrayIterator iterator(*this); while (iterator.Next(&array)) delete array; } void T2PeopleTimeZoneList::Add(T2PeopleTypeArray* inArray) { InsertItemsAt(1, mItemCount + 1, &inArray); } void T2PeopleTimeZoneList::Add(T2PeopleType* inPeopleType, T2PoolDefDemandElem* inDemandElem) { T2PeopleTypeArray *array; LArrayIterator iterator(*this); unsigned int timeZoneType = 0; while (iterator.Next(&array)) { inPeopleType->SetTimeZoneType(timeZoneType); TimeZoneInfo *theTimeZoneInfo = inDemandElem->GetTimeZoneInfo(timeZoneType); CResFile resFile; if (resFile.OpenResource(mWorldDef->mModuleHandle, theTimeZoneInfo->m0, 'PzDf')) { T2PoolTimeZoneDef *theTimeZoneDef = new T2PoolTimeZoneDef(resFile); array->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 inHour, float limit) { mCurrentItem = inHour / mHoursPerItem; mCurrentHour = inHour % mHoursPerItem; T2PeopleTypeArray *array; LArrayIterator iterator(*this); while (iterator.Next(&array)) array->InitSearchLimit(limit); } 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 inIndex) const { T2PeopleTypeArray *array; int index = inIndex + 1; if (!FetchItemAt(index, &array)) array = NULL; return array; } T2PeopleTypeArray* T2PeopleTimeZoneList::CurrentItem() const { return GetItem(mCurrentItem); } BOOL T2PeopleTimeZoneList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { T2PeopleTypeArray *array = CurrentItem(); return array->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType); } BOOL T2PeopleTimeZoneList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) { T2PeopleTypeArray *array = CurrentItem(); return array->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); } void T2PeopleTimeZoneList::DispatchRestore(T2PeopleType& inPeopleType) { T2PeopleTypeArray *array = GetItem(inPeopleType.GetTimeZoneType()); if (array) array->Restore(inPeopleType); } void T2PeopleTimeZoneList::DispatchAdd(T2PeopleType* inPeopleType) { T2PeopleTypeArray *array = GetItem(inPeopleType->GetTimeZoneType()); if (array) array->Add(inPeopleType, 1); } void T2PeopleTimeZoneList::Write(T2Archive& archive) { #pragma var_order(uc, c, i) 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 *array = GetItem(i); if (array) array->Write(archive); } }