#include "StdAfx.h" #include "T2Archive.h" #include "T2PeopleType.h" #include "T2PeopleTypeArray.h" #include "T2PoolDef.h" #include "T2TenantMemberDef.h" T2PeopleTypeArray::T2PeopleTypeArray(unsigned int val) : LArray(sizeof(T2PeopleType)) { m24 = val; m20 = false; InitSearchLimit(1.0f); } T2PeopleTypeArray::T2PeopleTypeArray(T2Archive& archive) : LArray(sizeof(T2PeopleType)) { m20 = false; Read(archive); } /*virtual*/ T2PeopleTypeArray::~T2PeopleTypeArray() { } void T2PeopleTypeArray::Add(T2PeopleType* type, unsigned int count, int where) { if (where == 0) { for (unsigned int i = 0; i < count; i++) LArray::Add(type); } else { InsertItemsAt(count, where, type); } } void T2PeopleTypeArray::Add(T2PeopleType* type, T2PoolTimeZoneDef* timeZoneDef, unsigned int count) { for (unsigned int i = 0; i < count; i++) { unsigned int numOfElems = timeZoneDef->GetNumOfElems(); for (unsigned int j = 0; j < numOfElems; j++) { PeopleElem *thePeopleElem = timeZoneDef->GetPeopleElem(j); #line 49 _ASSERT(thePeopleElem != NULL); type->SetSilhouetteType(thePeopleElem->mSilhouetteType); type->SetEconoType(thePeopleElem->mEconoType); type->SetTransportType(thePeopleElem->mTransportType); type->SetLifeCount(127); Add(type, thePeopleElem->m4, 1); } } } void T2PeopleTypeArray::AdjustLife() { for (int i = m2C; i >= m28; i--) { T2PeopleType peopleType; if (FetchItemAt(i, &peopleType)) { peopleType.DecreaseLife(); if (peopleType.HasLife()) AssignItemsAt(1, i, &peopleType); else RemoveItemsAt(1, i); } } } void T2PeopleTypeArray::InitSearchLimit(float limit) { m28 = 1; m2C = GetCount(); if (m24 == 0) m2C = m2C * limit; } BOOL T2PeopleTypeArray::Find(T2TenantMemberDef* tenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { BOOL result = false; T2PeopleType thePeopleType; int n; int numPeople = tenantMemberDef->GetNumOfPeople(); int numCheck = 0; int theEconoType = inEconoType; if (numPeople > 1 && m24 != 0) numPeople = 1; for (n = m28; !result && n <= m2C; n++) { if (FetchItemAt(n, &thePeopleType)) { if (thePeopleType.Check(tenantMemberDef, theEconoType, inTransportType)) { numCheck++; if (numCheck >= numPeople) { result = true; } else if (numCheck == 1 && inCheckOnlyFirstEconoType) { theEconoType = -1; } } } } return result; } BOOL T2PeopleTypeArray::Call(T2TenantMemberDef* tenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) { BOOL result = false; T2PeopleType thePeopleType; for (int n = m28; !result && n <= m2C; n++) { if (FetchItemAt(n, &thePeopleType)) { if (thePeopleType.Check(tenantMemberDef, inEconoType, inTransportType)) { result = true; outPeopleType = thePeopleType; if (!m24) { RemoveItemsAt(1, n); m2C--; } } } } return result; } void T2PeopleTypeArray::Restore(T2PeopleType& peopleType) { peopleType.RecoverLife(); InsertItemsAt(1, 1, &peopleType); m28++; m2C++; } void T2PeopleTypeArray::Read(T2Archive& archive) { RemoveItemsAt(GetCount(), 1); int numPeople; archive >> numPeople; for (int i = 0; i < numPeople; i++) { T2PeopleType peopleType; peopleType.Read(archive); Add(&peopleType, 1); } archive >> m24; archive >> m28; archive >> m2C; } void T2PeopleTypeArray::Write(T2Archive& archive) { archive << mItemCount; LArrayIterator iter(*this); T2PeopleType peopleType; while (iter.Next(&peopleType)) peopleType.Write(archive); archive << m24; archive << m28; archive << m2C; }