diff options
Diffstat (limited to 'src/T2DLL/T2Tenant.cpp')
-rw-r--r-- | src/T2DLL/T2Tenant.cpp | 1799 |
1 files changed, 1692 insertions, 107 deletions
diff --git a/src/T2DLL/T2Tenant.cpp b/src/T2DLL/T2Tenant.cpp index 5d36e88..7fb98fb 100644 --- a/src/T2DLL/T2Tenant.cpp +++ b/src/T2DLL/T2Tenant.cpp @@ -1,316 +1,1901 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2CustomerTableIterator.h" +#include "T2DateTime.h" +#include "T2EquipPtrList.h" +#include "T2FloorCEArray.h" +#include "T2FloorInfo.h" +#include "T2HallEventPlugin.h" +#include "T2MetroRailway.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleAnimeDef.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleLinkIterator.h" +#include "T2PeoplePtrList.h" +#include "T2Pool.h" +#include "T2RegistedTenantDB.h" +#include "T2RouteNavigator.h" +#include "T2SoundPlayer.h" +#include "T2SubPlugin.h" +#include "T2TemplatePluginList.h" #include "T2Tenant.h" +#include "T2TenantCEArray.h" +#include "T2TenantMemberDef.h" +#include "T2TenantMemberTableDef.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2Transport.h" +#include "T2TrafficInfo.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" +#include "UT2Utils.h" T2Tenant::T2Tenant() { + mKindIndex = 0; + mResideDay = 0; + mPeopleEstimate = 0; + mEstimate = 0; + + mFirstPeople = NULL; + m64 = NULL; + + mMark = -1; + mIsBind = true; + + mRelatedTenantID = 0; + + mReserveCount = 0; + mBelongCount = 0; + mWorkCount = 0; + mCustomerCount = 0; + mTotalCustomer = 0; + + mBelongList = NULL; + mRelatedTenantList = NULL; + + mMerchandiseCount = 0; } /*virtual*/ T2Tenant::~T2Tenant() { + if (mBelongList) + delete mBelongList; } -unsigned int T2Tenant::GetFloorID(int) { -} +unsigned int T2Tenant::GetFloorID(int inV) { + if (IsFloor()) + return GetEquipID(); + + if (!mCEArray) + return 0; + + int v = inV; + if (v == -1) + v = 1; + else + v = mArea.bottom - inV; + + unsigned int theFloorID = ((T2TenantCEArray *) mCEArray)->GetFloorID(v); + return theFloorID; +} + +void T2Tenant::SetFloorID(T2FloorInfo* inFloorInfo) { + if (inFloorInfo && mCEArray) { + for (int v = mArea.bottom - 1; v >= mArea.top; v--) { + T2Tenant *theTenant = inFloorInfo->GetTenant(v, mArea.left); +#line 64 + _ASSERT(theTenant != NULL); + + if (theTenant) { + unsigned int floorID = theTenant->GetEquipID(); + ((T2TenantCEArray *) mCEArray)->SetFloorID(floorID); + } + } + } +} + +/*virtual*/ PROCCODE T2Tenant::DoDestruct(T2TowerDoc* inDoc, POINT inPt, RECT& outRect) { + PROCCODE result = GetEquipDef()->DoDestructProc(inDoc, this, inPt, outRect); + + if (result == ProcCode_0) { + PARTCODE partCode = GetPartFromPoint(inDoc, inPt, NULL); + if (partCode == PartCode_2) { + GetEquipArea(outRect); + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; + + if (theFloorInfo) { + if (IsFloor()) { + inDoc->towerDoc_vf124()->FloorRemoved(this, false); + theFloorInfo->FillTenantID(outRect, 0); + outRect.left -= theFloorInfo->GetEntranceWidth(); + outRect.right += theFloorInfo->GetEntranceWidth(); + } else { + RemovePeople(inDoc); + inDoc->towerDoc_vf268(this); + + RECT rect = outRect; + rect.top = rect.bottom - 1; + + unsigned int tenantID; + LArrayIterator iterator(*mCEArray); + while (iterator.Next(&tenantID)) { + theFloorInfo->FillTenantID(rect, tenantID); + OffsetRect(&rect, 0, -1); + } + } + } + + if (GetEquipDef()) + GetEquipDef()->DestructFinish(inDoc, this); + + SetUsed(false); + return ProcCode_1; + } else { + return ProcCode_2; + } + } + + return result; +} + +void T2Tenant::AddPopulation(T2People* inPeople) { + if (IsBelongPeople(inPeople)) { + mBelongCount++; + } else { + if (mReserveCount > 0) + mReserveCount--; + mCustomerCount++; + } +} + +void T2Tenant::SubPopulation(T2People* inPeople) { + if (IsBelongPeople(inPeople)) + mBelongCount--; + else + mCustomerCount--; +} + +/*virtual*/ BOOL T2Tenant::Enter(CLink* inLink) { + T2People *thePeople = (T2People *) inLink; + + thePeople->SetCurrEquipID(mEquipID); + AddPopulation(thePeople); + + if (IsFloor()) { + POINT theCurPt = thePeople->GetCurPosition(); + if (theCurPt.x < mArea.left) + thePeople->MoveHTo(mArea.left); + else if (theCurPt.x > (mArea.right - 2)) + thePeople->MoveHTo(mArea.right - 2); + + thePeople->MoveVTo(mArea.bottom - 1); + thePeople->ChangeStatus(kStatus3); + } else { + POINT theEntrancePt = GetEntrancePt(); + POINT theCurPt = thePeople->GetCurPosition(); + + if (theCurPt.x != theEntrancePt.x || theCurPt.y != theEntrancePt.y) { + thePeople->MoveVTo(theEntrancePt.y); + thePeople->MoveHTo(theEntrancePt.x); + } + + thePeople->ChangeStatus(kStatus11); + } + + if (!mFirstPeople) { + mFirstPeople = (T2People *) inLink; + m64 = (T2People *) inLink; + inLink->SetPrev(NULL); + return true; + } + + if (m64) { + m64->InsertAt(inLink); + m64 = (T2People *) inLink; + return true; + } + + return false; +} + +/*virtual*/ BOOL T2Tenant::Leave(CLink* inLink) { + SubPopulation((T2People *) inLink); + + if (mFirstPeople) { + if (mFirstPeople == inLink) { + mFirstPeople = (T2People *) inLink->GetNext(); + + if (!mFirstPeople) { + m64 = NULL; + } else if (!mFirstPeople->GetNext()) { + m64 = mFirstPeople; + } + + inLink->Remove(); + return true; + } + + if (m64 != inLink) { + inLink->Remove(); + } else if (m64 == inLink) { + m64 = (T2People *) inLink->GetPrev(); + inLink->Remove(); + + if (!m64) + mFirstPeople = NULL; + + return true; + } + } + + return false; +} + +void T2Tenant::EnterTenant(T2TowerDoc* inDoc, T2People* inPeople) { + if (IsOpen() || IsBelongPeople(inPeople)) { + if (!IsNeedToilet() || !inPeople->IsSetSpecialFlag(kSpecialFlag2) || !inPeople->SearchToilet(inDoc)) { + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; + + T2Tenant *thePreviousTenant = theFloorInfo->GetTenant(inPeople->mCurrEquipID); + if (thePreviousTenant) + thePreviousTenant->Leave(inPeople); + Enter(inPeople); -void T2Tenant::SetFloorID(T2FloorInfo*) { -} + inPeople->ClearDestination(); + inPeople->UpdateEstimation(); -/*virtual*/ PROCCODE T2Tenant::DoDestruct(T2TowerDoc*, POINT, RECT&) { + T2TenantDef *theDef = (T2TenantDef *) GetEquipDef(); + if (theDef) { + inPeople->ClearSpecialFlag(theDef->GetDownFlag()); + theDef->EnterTenant(inDoc, this, inPeople); + } + } + } else { + inPeople->Return(); + inPeople->IncEstimate(-100); + } } -void T2Tenant::AddPopulation(T2People*) { -} +void T2Tenant::LeaveTenant(T2TowerDoc* inDoc, T2People* inPeople) { + Leave(inPeople); -void T2Tenant::SubPopulation(T2People*) { -} + inPeople->mPrevTenantType = mEquipType; -/*virtual*/ int T2Tenant::Enter(CLink*) { -} + POINT exitPos = GetExitPt(); + inPeople->MoveVTo(exitPos.y); + inPeople->MoveHTo(exitPos.x); -/*virtual*/ int T2Tenant::Leave(CLink*) { -} + unsigned int theFloorID = GetExitFloorID(); + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; -void T2Tenant::EnterTenant(T2TowerDoc*, T2People*) { -} + T2Tenant *theFloor = theFloorInfo->GetTenant(theFloorID); + if (theFloor) + theFloor->Enter(inPeople); -void T2Tenant::LeaveTenant(T2TowerDoc*, T2People*) { + T2TenantDef *theTenantDef = (T2TenantDef *) GetEquipDef(); + if (theTenantDef) + theTenantDef->LeaveTenant(inDoc, this, inPeople); } -/*virtual*/ void T2Tenant::Draw(T2TowerDoc*, const RECT&) { -} +/*virtual*/ void T2Tenant::Draw(T2TowerDoc* inDoc, const RECT& inRect) { + if (inDoc->mViewMode != ViewMode_1 && IsFire() && !IsFloor()) { + inDoc->towerDoc_vf170()->DrawRubble(inDoc, this); + } else { + GetEquipDef()->DrawProc(this, inRect, inDoc); + if (true) + GetEquipDef()->DrawPeople(inDoc, this); -/*virtual*/ void T2Tenant::DrawSelf(T2TowerDoc*, const RECT&) { -} + if (mMark > -1 && inDoc->towerDoc_vf140() != ViewMode_1) { + T2WorldDef *theWorldDef = inDoc->mWorldDef; + if (theWorldDef) { + RECT equipArea, qdRect; + GetEquipArea(equipArea); + UT2Coordinate::UnitToQD(equipArea, qdRect, inDoc->mZoomLevel); -/*virtual*/ unsigned int T2Tenant::Idle(T2TowerDoc*) { + theWorldDef->DrawMark(inDoc->towerDoc_vf10C(), qdRect, inDoc->towerDoc_vf108(), mMark); + } + } + } + + T2WorldDef *theWorldDef = inDoc->mWorldDef; + if (theWorldDef->IsBlackOut()) { + CRect rect = mArea; + DrawColorMesh(inDoc, rect, 1); + } else if (inDoc->towerDoc_vf140() == ViewMode_5) { + CRect rect = inRect; + DrawTrafficColor(inDoc, rect); + } else if (inDoc->towerDoc_vf140() != ViewMode_0) { + DrawViewModeColor(inDoc); + } + + unsigned int entranceFloorID = GetEntranceFloorID(); + if (!IsFloor() && mCEArray->GetCount() == 0) { + CRect rect = mArea; + DrawColorMesh(inDoc, rect, 9); + } } -/*virtual*/ void T2Tenant::AddCEMoverID(const T2FloorInfo*, POINT, unsigned int) { +/*virtual*/ void T2Tenant::DrawSelf(T2TowerDoc* inDoc, const RECT& inRect) { } -int T2Tenant::InitTenant(T2TenantDef*, const RECT&, unsigned int) { +/*virtual*/ unsigned int T2Tenant::Idle(T2TowerDoc* inDoc) { + if (mStatus != kTenantStatus0) { + unsigned int result = GetEquipDef()->IdleProc(this, inDoc); + + if (result != -1 && result > 0) { + inDoc->GetTowerMainView()->tmv_vf128(mArea); + mDrawMode = DrawMode1; + } + + return result; + } + + return 0; } -/*virtual*/ void T2Tenant::LoadSelf(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2Tenant::AddCEMoverID(const T2FloorInfo* inFloorInfo, POINT inPt, unsigned int inID) { + int moverID = inFloorInfo->GetLeftMoverID(inPt, mArea.left); + InsertCEID(moverID, inID); } -/*virtual*/ void T2Tenant::SaveSelf(T2Archive&) { +BOOL T2Tenant::InitTenant(T2TenantDef* inDef, const RECT& inRect, unsigned int inValiation) { + InitEquip(inDef, inRect, inValiation); + + mStatus = kTenantStatus0; + mDrawMode = DrawMode2; + + mFirstPeople = NULL; + m64 = NULL; + + mKindIndex = 0; + mResideDay = 0; + mPeopleEstimate = 300; + mEstimate = 0; + + mMark = -1; + mIsBind = true; + + mRelatedTenantID = 0; + + mReserveCount = 0; + mBelongCount = 0; + mCustomerCount = 0; + mWorkCount = 0; + mTotalCustomer = 0; + + mSubPlugin = NULL; + + mBelongList = NULL; + mRelatedTenantList = NULL; + + mMerchandiseCount = 0; + + if (IsFloor()) + mCEArray = new T2FloorCEArray; + else + mCEArray = new T2TenantCEArray; + + InitBelongList(); + return true; +} + +/*virtual*/ void T2Tenant::LoadSelf(T2Archive& inArchive, T2TowerDoc* inDoc) { + DWORD code; + inArchive >> code; +#line 422 + _ASSERT(code == '<TN>'); + + T2Equip::LoadSelf(inArchive, inDoc); + + if (IsUsed()) { + SetEquipDef(inDoc->mTenantTemplates->FindTenantDef(mEquipType)); + + if (mToolDef) { + mAttribute = mToolDef->GetAttribute(); + mCapacity = GetEquipDef()->GetCapacity(); + } + +#pragma var_order(ui, uc, s, pptrList, us, theLinkData, code) + unsigned char uc; + unsigned short us; + unsigned int ui; + short s; + + inArchive >> uc; + mKindIndex = uc; + + inArchive >> mResideDay; + + inArchive >> s; + mPeopleEstimate = s; + inArchive >> s; + mEstimate = s; + + inArchive >> uc; + mIsBind = (uc != 0); + + inArchive >> us; + mRelatedTenantID = us; + + inArchive >> s; + mReserveCount = s; + inArchive >> s; + mBelongCount = s; + inArchive >> s; + mCustomerCount = s; + inArchive >> s; + mWorkCount = s; + inArchive >> s; + mTotalCustomer = s; + + inArchive >> us; + mTenantNumber = us; + + inArchive >> ui; + mRelatedTenantList = (T2EquipPtrList *) ui; + + inArchive >> s; + mMerchandiseCount = s; + + if (mMerchandiseCount > 0) { + for (int i = 0; i < mMerchandiseCount; i++) { + unsigned char val; + inArchive >> val; + mMerchandise[i] = val; + } + } + + DWORD code; + inArchive >> code; + + unsigned int theLinkData; + inArchive >> theLinkData; + if (theLinkData != 0) { + T2People *thePeople = inDoc->mPeopleArrayList->FindPeople(theLinkData); + mFirstPeople = thePeople; + } + + inArchive >> theLinkData; + if (theLinkData != 0) { + T2People *thePeople = inDoc->mPeopleArrayList->FindPeople(theLinkData); + m64 = thePeople; + } + + unsigned int pptrList; + inArchive >> pptrList; + + if (pptrList != 0) { + mBelongList = new T2PeoplePtrList; + if (mBelongList) + mBelongList->LoadSelf(inArchive, inDoc->mPeopleArrayList); + } + + if (GetEquipDef()) { + GetEquipDef()->LoadExtraData(inArchive, inDoc, this); + } else { + int len; + inArchive >> len; + for (int i = 0; i < len; i++) { + char tmp; + inArchive >> tmp; + } + } + + if (GetRegistID() == kTenantRegistID1 && mStatus == kTenantStatus38) + SetMark(0); + + if (mToolDef && mToolDef->GetCategory() == 50 && mWorkCount > 2) + SetMark(1); + + mDrawMode = DrawMode2; + } +} + +/*virtual*/ void T2Tenant::SaveSelf(T2Archive& inArchive) { + DWORD code = '<TN>'; + inArchive << code; + + T2Equip::SaveSelf(inArchive); + + if (IsUsed()) { + inArchive << (unsigned char) mKindIndex; + inArchive << mResideDay; + inArchive << (short) mPeopleEstimate; + inArchive << (short) mEstimate; + inArchive << (unsigned char) (mIsBind != 0); + inArchive << (unsigned short) mRelatedTenantID; + inArchive << (short) mReserveCount; + inArchive << (short) mBelongCount; + inArchive << (short) mCustomerCount; + inArchive << (short) mWorkCount; + inArchive << (short) mTotalCustomer; + inArchive << (unsigned short) mTenantNumber; + +#pragma var_order(thePeople, relatedTenantList, zero, code) + unsigned int relatedTenantList = 0; + if (mRelatedTenantList) + relatedTenantList = mRelatedTenantList->GetAttribute(); + inArchive << relatedTenantList; + + inArchive << (short) mMerchandiseCount; + if (mMerchandiseCount > 0) { + for (int i = 0; i < mMerchandiseCount; i++) { + unsigned char val = mMerchandise[i]; + inArchive << val; + } + } + + DWORD code = 'pLk>'; + inArchive << code; + + unsigned int zero = 0; + T2People *thePeople; + + if (mFirstPeople) { + thePeople = mFirstPeople; + unsigned int id = thePeople->GetPeopleID(); + inArchive << id; + } else { + inArchive << zero; + } + + if (m64) { + thePeople = m64; + unsigned int id = thePeople->GetPeopleID(); + inArchive << id; + } else { + inArchive << zero; + } + + if (mBelongList) { + unsigned int flag = 1; + inArchive << flag; + mBelongList->SaveSelf(inArchive); + } else { + unsigned int flag = 0; + inArchive << flag; + } + + GetEquipDef()->SaveExtraData(inArchive, this); + } } /*virtual*/ unsigned int T2Tenant::GetEntranceFloorID() { + unsigned int result = 0; + + if (IsFloor()) { + result = mEquipID; + } else { + int v = 1; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) + v += def->GetEntranceV(); + + result = ((T2TenantCEArray *) mCEArray)->GetFloorID(v); + } + + return result; } POINT T2Tenant::GetEntrancePt() const { + POINT pt; + pt.y = mArea.bottom - 1; + pt.x = mArea.left; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) { + pt.y -= def->GetEntranceV(); + pt.x += def->GetEntranceH(); + } + + return pt; } /*virtual*/ unsigned int T2Tenant::GetExitFloorID() { + unsigned int result = 0; + + if (IsFloor()) { + result = mEquipID; + } else { + int v = 1; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) + v += def->GetExitV(); + + result = ((T2TenantCEArray *) mCEArray)->GetFloorID(v); + } + + return result; } POINT T2Tenant::GetExitPt() { + POINT pt; + pt.y = mArea.bottom - 1; + pt.x = mArea.left; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) { + pt.y -= def->GetExitV(); + pt.x += def->GetExitH(); + } + + return pt; } T2People* T2Tenant::GetFirstCustomer() const { + T2People *firstCustomer = NULL; + + T2PeopleLinkIterator iterator(GetFirstPeople()); + T2People *thePeople; + + while (!firstCustomer && iterator.Next(&thePeople)) { + if (!IsBelongPeople(thePeople)) + firstCustomer = thePeople; + } + + return firstCustomer; } int T2Tenant::GetBelongCapacity() { + int result = 0; + result = ((T2TenantDef *) GetEquipDef())->GetBelongCapacity(); + return result; } -int T2Tenant::IsTherePeople(T2People*) { +BOOL T2Tenant::IsTherePeople(T2People* inPeople) { + BOOL found = false; + + T2PeopleLinkIterator iterator(mFirstPeople); + T2People *thePeople; + + while (!found && iterator.Next(&thePeople)) { + if (thePeople == inPeople) + found = true; + } + + return found; } void T2Tenant::StartBuild() { + if (IsFloor()) { + mStatus = kTenantStatus1; + } else { + mStatus = kTenantStatus2; + mTenantNumber = GetCurrentT2TowerDoc()->towerDoc_vf27C(mArea.bottom - 1); + } + + ((T2TenantDef *) GetEquipDef())->BuildStartProc(GetCurrentT2TowerDoc(), this); } void T2Tenant::UpdatePatternIndex() { + mPatIndex = (GetNumOfPattern() * mKindIndex) + mStatus - 10; } -void T2Tenant::UpdatePatternIndex(int) { +void T2Tenant::UpdatePatternIndex(int inIndex) { + mPatIndex = (GetNumOfPattern() * mKindIndex) + inIndex; } int T2Tenant::GetNumOfPattern() const { -} + int result = 1; + result = ((T2TenantDef *) GetEquipDef())->GetNumOfPattern(); + return result; +} + +int T2Tenant::CollectCustomerFromPool(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime, T2Tenant* inTenant) { + int numCustomer = 0; + + int searchScore = inTable->GetScore(T2PlaceParamDef::Place_0); + unsigned int checkRoute = CheckRouteFromPool(inDoc, searchScore); -int T2Tenant::CollectCustomerFromPool(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int, T2Tenant*) { + if (checkRoute > 0) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + unsigned int restCapacity = CalcRestCapacity(); + int econoType = inTable->GetEconoType(); + + T2CustomerTableIterator custIterator(inTable); + + unsigned int theFloorID; + if (!inTenant) + theFloorID = mEquipID; + else + theFloorID = inTenant->GetEquipID(); + + T2TenantMemberDef *theMemberDef; + unsigned int theRate; + while (restCapacity > 0 && custIterator.Next(theMemberDef, theRate)) { + if (theRate > restCapacity) + theRate = restCapacity; + + BOOL outOfPeople = false; + for (unsigned int i = 0; !outOfPeople && i < theRate; i++) { + T2People *people = thePool->Call(theMemberDef, econoType, checkRoute, inTable->GetSpecialFlag()); + if (people) { + people->SetDestination(theFloorID, inTime + i * 2); + numCustomer++; + restCapacity--; + } else { + outOfPeople = true; + } + } + } + } + + return numCustomer; +} + +int T2Tenant::CollectCustomerFromTenant(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime) { + int numCustomer = 0; + + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); + T2Tenant *theTenant = theNavigator->SelectNearTenant(GetEntrancePt(), inTable->GetScore(T2PlaceParamDef::Place_1)); + + if (theTenant) { + unsigned int restCapacity = CalcRestCapacity(); + int econoType = inTable->GetEconoType(); + unsigned int theSpecialFlag = inTable->GetSpecialFlag(); + + T2CustomerTableIterator custTableIterator(inTable); + T2TenantMemberDef *memberDef; + unsigned int theRate; + + T2PeopleLinkIterator peopleLinkIterator(theTenant->GetFirstPeople()); + T2People *people; + + int time = GetBindTime(); + + while (restCapacity > 0 && custTableIterator.Next(memberDef, theRate)) { + if (theRate > restCapacity) + theRate = restCapacity; + + peopleLinkIterator.Reset(); + unsigned int i = 0; + while (i < theRate && peopleLinkIterator.Next(&people)) { + if (people->IsSetSpecialFlag(theSpecialFlag)) { + if (people->CalledInTenant(memberDef, econoType, time, mEquipType, mEquipID, inTime)) { + i++; + numCustomer++; + restCapacity--; + } + } + } + } + } + + return numCustomer; +} + +int T2Tenant::CollectCustomerFromFloor(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime) { + int numCustomer = 0; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + unsigned int theEntranceFloorID = GetEntranceFloorID(); + T2Tenant *theEntranceFloor = theFloorInfo->GetTenant(theEntranceFloorID); + + if (theEntranceFloor->IsTherePeople()) { + unsigned int restCapacity = CalcRestCapacity(); + int searchScore = inTable->GetScore(T2PlaceParamDef::Place_2); + int econoType = inTable->GetEconoType(); + unsigned int theSpecialFlag = inTable->GetSpecialFlag(); + + T2CustomerTableIterator custTableIterator(inTable); + T2TenantMemberDef *memberDef; + unsigned int theRate; + + T2PeopleLinkIterator peopleLinkIterator(theEntranceFloor->GetFirstPeople()); + T2People *people; + + int time = GetBindTime(); + + while (restCapacity > 0 && custTableIterator.Next(memberDef, theRate)) { + if (theRate > restCapacity) + theRate = restCapacity; + + peopleLinkIterator.Reset(); + unsigned int i = 0; + while (i < theRate && peopleLinkIterator.Next(&people)) { + if (people->IsSetSpecialFlag(theSpecialFlag)) { + T2Tenant *theTenant = theFloorInfo->GetTenant(people->GetDstTenant()); + if ((theTenant && theTenant->GetEquipType() != mEquipType) || !theTenant) { + if (people->StopOnHisWay(memberDef, econoType, searchScore, mArea, time, mEquipType, mEquipID, inTime)) { + i++; + numCustomer++; + restCapacity--; + } + } + } + } + } + } + + return numCustomer; +} + +void T2Tenant::CollectCustomer(T2TowerDoc* inDoc, T2Tenant* inTenant) { + if (!WillBeFull()) { + T2DateTime *theNow = inDoc->towerDoc_vf120(); + if (theNow->WithinMinutes(GetOpenTime(), GetCloseTime() - GetBindTime() - 60)) { + T2TenantMemberTableDef *theTable = GetCustomerTableDef(true); + if (theTable) { + int minutes = theNow->GetRawMinutes(); + + if (theTable->IsCollectFromPool(inDoc)) + mReserveCount += CollectCustomerFromPool(inDoc, theTable, minutes, inTenant); + if (theTable->IsCollectFromTenant()) + mReserveCount += CollectCustomerFromTenant(inDoc, theTable, minutes); + if (theTable->IsCollectFromFloor()) + mReserveCount += CollectCustomerFromFloor(inDoc, theTable, minutes); + } + } + } +} + +void T2Tenant::CollectCustomer(T2TowerDoc* inDoc, int inNum) { + T2TenantMemberTableDef *theTable = GetCustomerTableDef(true); + if (theTable) { + int numElem = theTable->GetNumOfElem(); + + for (int i = 0; i < numElem && inNum > 0; i++) { + T2TenantMemberDef *memberDef = theTable->GetElem(i); + if (memberDef) { + if (memberDef->GetNumOfPeople() < inNum) { + inNum -= memberDef->GetNumOfPeople(); + } else { + memberDef->SetNumOfPeople(inNum); + inNum = 0; + } + } + } + } + + CollectCustomer(inDoc, (T2Tenant *) NULL); +} + +int T2Tenant::CollectEmployee(T2TowerDoc* inDoc) { + int numEmployee = 0; + + T2TenantMemberTableDef *theTable = GetEmployeeTableDef(); + if (theTable && theTable->IsCollectFromPool(inDoc)) + numEmployee = CollectEmployeeFromPool(inDoc, theTable); + + return numEmployee; +} + +void T2Tenant::RegistBelongPeople(T2People* inPeople) { + if (mBelongList) { + mBelongList->Add(inPeople); + + if (IsHome()) + inPeople->SetHomeTenant(mEquipID); + else + inPeople->SetWorkTenant(mEquipID); + } } -int T2Tenant::CollectCustomerFromTenant(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int) { +int T2Tenant::CalcInMoney() const { + int result = 0; + result = (GetInMoney() * mTotalCustomer) / 100; + result -= GetOutMoney(); + return result; } -int T2Tenant::CollectCustomerFromFloor(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int) { +void T2Tenant::EnterCustomer(T2People* inPeople, int inBindTime) { + SetBindTime(inPeople, inBindTime); + mTotalCustomer++; } -void T2Tenant::CollectCustomer(T2TowerDoc*, T2Tenant*) { -} +BOOL T2Tenant::IsBelongPeople(T2People* inPeople) const { + BOOL result = false; -void T2Tenant::CollectCustomer(T2TowerDoc*, int) { -} + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; -int T2Tenant::CollectEmployee(T2TowerDoc*) { -} + while (!result && iterator.Next(&people)) { + if (people == inPeople) + result = true; + } + } -void T2Tenant::RegistBelongPeople(T2People*) { + return result; } -int T2Tenant::CalcInMoney() const { -} +void T2Tenant::PushOutPeople(T2TowerDoc* inDoc, T2People* inPeople) { + if (!inPeople) + inPeople = mFirstPeople; -void T2Tenant::EnterCustomer(T2People*, int) { -} + if (inPeople) { + if (!inPeople->IsSetDestination()) { + if (inPeople->IsSetReturn()) + inPeople->SetReturnToDestination(); + else + inPeople->SetDestination(inPeople->mHomeTenant, inDoc->towerDoc_vf120()->GetRawMinutes() + 180); + } -int T2Tenant::IsBelongPeople(T2People*) const { + LeaveTenant(inDoc, inPeople); + } } -void T2Tenant::PushOutPeople(T2TowerDoc*, T2People*) { +void T2Tenant::PushOutAll(T2TowerDoc* inDoc) { + while (mFirstPeople) + PushOutPeople(inDoc, mFirstPeople); } -void T2Tenant::PushOutAll(T2TowerDoc*) { -} +void T2Tenant::PushOutAllCustomer(T2TowerDoc* inDoc) { + T2PeopleLinkIterator iterator(mFirstPeople); + T2People *prevPeople = NULL; + T2People *people = NULL; + + iterator.Next(&prevPeople); + while (prevPeople) { + if (iterator.Next(&people)) + people = NULL; + + if (!IsBelongPeople(prevPeople)) + PushOutPeople(inDoc, prevPeople); -void T2Tenant::PushOutAllCustomer(T2TowerDoc*) { + prevPeople = people; + people = NULL; + } } int T2Tenant::GetPriceIndex() const { + int result = 0; + + if (GetEquipDef() && GetEquipDef()->GetNumOfInMoney() > 1) + result = GetInMoneyIndex() + 1; + + return result; } -void T2Tenant::DuplicateBelongPeople(T2TowerDoc*) { +void T2Tenant::DuplicateBelongPeople(T2TowerDoc* inDoc) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->Duplicate(inDoc); + } + } } -void T2Tenant::RemoveBelongPeople(T2TowerDoc*) { +void T2Tenant::RemoveBelongPeople(T2TowerDoc* inDoc) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->Remove(inDoc, mEquipID); + } + + mBelongList->Clear(); + } } -void T2Tenant::RemovePeople(T2TowerDoc*) { +void T2Tenant::RemovePeople(T2TowerDoc* inDoc) { + RemoveBelongPeople(inDoc); + + T2PeopleLinkIterator iterator(mFirstPeople); + T2People *people; + + while (iterator.Next(&people)) + people->IncEstimate(-200); + + PushOutAll(inDoc); } void T2Tenant::ClearBelongPeople() { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + if (people->mHomeTenant == mEquipID) + people->mHomeTenant = 1; + if (people->mWorkTenant == mEquipID) + people->mWorkTenant = 1; + } + } + + mBelongList->Clear(); + } } -void T2Tenant::ClearBelongPeople(T2People*) { +void T2Tenant::ClearBelongPeople(T2People* inPeople) { + if (mBelongList) { + if (inPeople->mHomeTenant == mEquipID) + inPeople->mHomeTenant = 1; + if (inPeople->mWorkTenant == mEquipID) + inPeople->mWorkTenant = 1; + + mBelongList->Clear(inPeople); + } } -void T2Tenant::CallBelongPeople(unsigned int) { +void T2Tenant::CallBelongPeople(unsigned int inTime) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + unsigned int time = inTime + (rand() * 10) % 6; + people->SetDestination(mEquipID, time); + } + } + } } -T2People* T2Tenant::GetBelongPeople(int) { +T2People* T2Tenant::GetBelongPeople(int inIndex) { + T2People *result = NULL; + + if (mBelongList) + result = mBelongList->GetItemAt(inIndex); + + return result; } -T2People* T2Tenant::GetBelongPeopleIn(int) { +T2People* T2Tenant::GetBelongPeopleIn(int inIndex) { + T2People *result = GetBelongPeople(inIndex); + + if (result && result->GetCurTenantID() != mEquipID) + result = NULL; + + return result; } void T2Tenant::SetKind() { + int num = GetNumOfKind(); + + if (num == 0) + mKindIndex = 0; + else + mKindIndex = rand() % num; } int T2Tenant::GetNumOfKind() const { + int result = 1; + result = ((T2TenantDef *) GetEquipDef())->GetNumOfKind(); + return result; } -/*virtual*/ void T2Tenant::SetUsed(int) { +/*virtual*/ void T2Tenant::SetUsed(BOOL used) { + if (!used && IsFavorite()) + GetCurrentT2TowerDoc()->towerDoc_vf1CC(this, false); + + T2Equip::SetUsed(used); + + if (used == 1) + return; + + if (mCEArray) { + delete mCEArray; + mCEArray = NULL; + } + if (mBelongList) { + delete mBelongList; + mBelongList = NULL; + } } unsigned int T2Tenant::GetRegistID() const { + unsigned int result = 0; + + if (mToolDef) + result = ((T2TenantDef *) mToolDef)->GetRegistID(); + + return result; } int T2Tenant::GetEmployeeSearchScore() const { + int searchScore = 0; + + T2TenantMemberTableDef *theTableDef = GetEmployeeTableDef(); + if (theTableDef) + searchScore = theTableDef->GetScore(T2PlaceParamDef::Place_1); + + return searchScore; } int T2Tenant::GetCustomerSearchScore() const { + int searchScore = 0; + + T2TenantMemberTableDef *theTableDef = GetCustomerTableDef(true); + if (theTableDef) + searchScore = theTableDef->GetScore(T2PlaceParamDef::Place_1); + + return searchScore; } -int T2Tenant::IsMoverAvailable() const { +BOOL T2Tenant::IsMoverAvailable() const { + BOOL result = false; + + if (IsFloor() && mCEArray) + result = ((T2RouteCEArray *) mCEArray)->HasCrossEquip(); + + return result; } void T2Tenant::RemoveBelongList() { + if (mBelongList) { + delete mBelongList; + mBelongList = NULL; + } } -int T2Tenant::GetQTMovieName(CString) { +BOOL T2Tenant::GetQTMovieName(CString str) { + BOOL result = false; + + T2TenantDef *theDef = (T2TenantDef *) GetEquipDef(); + if (theDef) + result = theDef->GetQTMovieName(this, str); + + return result; } -void T2Tenant::Destruct(T2TowerDoc*, CRect&) { +void T2Tenant::Destruct(T2TowerDoc* inDoc, CRect& outRect) { + GetEquipArea(outRect); + + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; + if (theFloorInfo) { + if (IsFloor()) { + inDoc->towerDoc_vf124()->FloorRemoved(this, false); + theFloorInfo->FillTenantID(outRect, 0); + outRect.left -= theFloorInfo->GetEntranceWidth(); + outRect.right += theFloorInfo->GetEntranceWidth(); + } else { + RemovePeople(inDoc); + inDoc->towerDoc_vf268(this); + + RECT rect = outRect; + rect.top = rect.bottom - 1; + + unsigned int tenantID; + LArrayIterator iterator(*mCEArray); + while (iterator.Next(&tenantID)) { + theFloorInfo->FillTenantID(rect, tenantID); + OffsetRect(&rect, 0, -1); + } + } + } + + if (GetEquipDef()) + GetEquipDef()->DestructFinish(inDoc, this); + + SetUsed(false); } -void T2Tenant::SetBindTime(T2People*, unsigned int) { +void T2Tenant::SetBindTime(T2People* inPeople, unsigned int inTime) { + inPeople->SetStartTime(inTime + GetBindTime()); } -int T2Tenant::SetEstimate(int) { +BOOL T2Tenant::SetEstimate(int inEstimate) { + int oldCol = CalcEstimateColor(); + + mEstimate = inEstimate; + if (mEstimate > 300) + mEstimate = 300; + else if (mEstimate < 1) + mEstimate = 1; + + return CalcEstimateColor() != oldCol; } -int T2Tenant::SetPeopleAnime() { +BOOL T2Tenant::SetPeopleAnime() { + BOOL changed = false; + + for (int i = 0; i < GetBelongCapacity(); i++) { + T2People *people = GetBelongPeopleIn(i + 1); + if (people) { + SetPeopleAnime(people, i); + changed |= true; + } + } + + return changed; } -void T2Tenant::SetPeopleAnime(T2People*, int) { +void T2Tenant::SetPeopleAnime(T2People* inPeople, int inIndex) { + if (GetEquipDef()) { + T2PeopleAnimeDef *theDef = ((T2TenantDef *) GetEquipDef())->GetPeopleAnimeDef(); + if (theDef) + theDef->Set(inPeople, mArea.left, inIndex); + } } -void T2Tenant::PushOutCustomer(T2TowerDoc*, int) { +void T2Tenant::PushOutCustomer(T2TowerDoc* inDoc, int inCount) { + T2PeopleLinkIterator iterator(GetFirstPeople()); + T2People *prevPeople = NULL; + T2People *people = NULL; + int numCustomer = 0; + + iterator.Next(&prevPeople); + while (prevPeople && numCustomer < inCount) { + iterator.Next(&people); + + if (!IsBelongPeople(prevPeople)) { + PushOutPeople(inDoc, prevPeople); + numCustomer++; + } + + prevPeople = people; + people = NULL; + } } -int T2Tenant::GetBelongPeopleIndex(T2People*, int&) const { +BOOL T2Tenant::GetBelongPeopleIndex(T2People* inPeople, int& outIndex) const { + BOOL result = false; + + if (mBelongList) + result = mBelongList->GetPeopleIndex(inPeople, outIndex); + + return result; } -int T2Tenant::SetPeopleToSleep() { +BOOL T2Tenant::SetPeopleToSleep() { + BOOL changed = false; + + if (mBelongList) { + BOOL found = false; + + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (!found && iterator.Next(&people)) { + if (people && !people->IsSleep()) { + if (!changed) { + people->SetToSleep(); + changed = true; + } else { + changed = false; + found = true; + } + } + } + } + + return changed; } void T2Tenant::SetAllPeopleToSleep() { -} + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; -void T2Tenant::UnionFloorPeople(T2Tenant*) { + while (iterator.Next(&people)) { + if (people) + people->SetToSleep(); + } + } } -int T2Tenant::IsWithinSearchRange(T2TowerDoc*, T2Tenant*) const { -} +void T2Tenant::UnionFloorPeople(T2Tenant* inTenant) { + if (inTenant->IsTherePeople()) { + T2PeopleLinkIterator iterator(inTenant->GetFirstPeople()); + T2People *people; -void T2Tenant::SetMoviePlugin(T2SubPlugin*) { -} + while (iterator.Next(&people)) + people->SetCurrEquipID(mEquipID); -void T2Tenant::SetHallEventPlugin(T2HallEventPlugin*) { -} + if (IsTherePeople()) + m64->InsertAt(inTenant->mFirstPeople); + else + mFirstPeople = inTenant->mFirstPeople; -int T2Tenant::GetFloorNumber(T2FloorInfo*) const { + m64 = inTenant->m64; + } } -int T2Tenant::GetRoomNumber(T2FloorInfo*) const { -} +BOOL T2Tenant::IsWithinSearchRange(T2TowerDoc* inDoc, T2Tenant* inTenant) const { + BOOL result = false; -void T2Tenant::GetRoomName(T2TowerDoc*, CString&) const { + if (inTenant) { + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); + T2TenantMemberTableDef *theTable = inTenant->GetCustomerTableDef(true); + + if (theTable) { + if (IsFloor()) { + if (GetValiation() == 1) { + if (theNavigator->IsConnectRouteFromLobby(inTenant->GetEntrancePt())) + result = true; + } + } else { + int score = theTable->GetScore(T2PlaceParamDef::Place_1); + if (theNavigator->CheckRoute(inTenant->GetEntrancePt(), GetEntrancePt(), score)) + result = true; + } + } + } + + return result; } -/*virtual*/ void T2Tenant::PlaySoundA(T2TowerDoc*, int, unsigned int, unsigned int) const { +void T2Tenant::SetMoviePlugin(T2SubPlugin* inPlugin) { + SetSubPlugin(inPlugin); + + if (GetEquipDef()) + ((T2TenantDef *) GetEquipDef())->SetCustomerTable(inPlugin); } -int T2Tenant::IsEmptyParking() const { +void T2Tenant::SetHallEventPlugin(T2HallEventPlugin* inPlugin) { + SetSubPlugin(inPlugin); } -T2People* T2Tenant::FindPeople(POINT) const { +int T2Tenant::GetFloorNumber(T2FloorInfo* inFloorInfo) const { + return inFloorInfo->UnitToFloor(mArea.bottom - 1); } -int T2Tenant::InitBelongList() { +int T2Tenant::GetRoomNumber(T2FloorInfo* inFloorInfo) const { + int floorNumber = GetFloorNumber(inFloorInfo); + return (floorNumber > 0) ? ((floorNumber * 1000) + mTenantNumber) : ((floorNumber * 1000) - mTenantNumber); } -void T2Tenant::DrawViewModeColor(T2TowerDoc*) const { +void T2Tenant::GetRoomName(T2TowerDoc* inDoc, CString& outStr) const { + CString roomNum; + UT2Utils::GetRoomNumberString(inDoc->towerDoc_vf12C()->UnitToFloor(mArea.bottom - 1), roomNum); + + outStr += roomNum; + outStr += "\x8A\x4B"; + outStr += (char) GetTenantNumber(); + outStr += "\x8D\x86\x8E\xBA"; + + T2Name *theName = inDoc->mNameDB->Search(this, false); + + CString nameStr; + if (theName) { + unsigned int id; + theName->GetName(nameStr, id); + } else { + GetTypicalName(nameStr); + } + outStr += nameStr; } -void T2Tenant::DrawTrafficColor(T2TowerDoc*, const CRect&) const { +/*virtual*/ void T2Tenant::PlaySound(T2TowerDoc* inDoc, int inID, unsigned int inMask, unsigned int inFlags) const { + if (inDoc->towerDoc_vf15C(mArea)) { + T2EquipDef *theDef = GetEquipDef(); + T2SoundPlayer *thePlayer = inDoc->towerDoc_vf134(); + if (theDef && thePlayer) { + CRect rect; + GetEquipArea(rect); + + CPoint pt = rect.CenterPoint(); + + CString soundName = theDef->CalcSoundID(inID); + + thePlayer->Play(soundName, inMask, inFlags, &pt, PlayMode_0, 100); + } + } } -/*static*/ void T2Tenant::DrawColorMesh(T2TowerDoc*, const CRect&, int) { +BOOL T2Tenant::IsEmptyParking() const { + BOOL result = false; + + if (mBelongList) + result = mBelongList->HasSpace(); + + return result; } -void T2Tenant::IncPeopleEstimate(int) { +T2People* T2Tenant::FindPeople(POINT inPt) const { + T2People *result = NULL; + + if (IsTherePeople()) { + T2PeopleLinkIterator iterator(GetFirstPeople()); + T2People *people; + + while (!result && iterator.Next(&people)) { + if (people->IsWalk()) { + CRect rect; + people->CalcWalkingSilhouetteArea(rect); + + if (rect.PtInRect(inPt)) + result = people; + } + } + } + + return result; +} + +BOOL T2Tenant::InitBelongList() { + BOOL result = true; + + unsigned int capacity = GetBelongCapacity(); + + if (capacity > 0) { + mBelongList = new T2PeoplePtrList(capacity); + if (!mBelongList) + result = false; + } + + return result; +} + +void T2Tenant::DrawViewModeColor(T2TowerDoc* inDoc) const { + T2Tenant *tenant; + int color = -1; + + switch (inDoc->towerDoc_vf140()) { + case ViewMode_2: + color = CalcEstimateColor(); + break; + case ViewMode_3: + switch (GetPriceIndex()) { + case 4: + color = 9; + break; + case 3: + color = 14; + break; + case 2: + color = 15; + break; + case 1: + color = 12; + break; + } + break; + case ViewMode_4: + if (GetRegistID() == kTenantRegistID1 && GetStatus() >= kTenantStatus35) + color = 9; + break; + case ViewMode_6: + tenant = inDoc->towerDoc_vf18C(); + if (tenant) { + if (this == tenant) + color = 14; + else if (IsWithinSearchRange(inDoc, tenant)) + color = 16; + } + break; + } + + if (color != -1) { + CRect rect = mArea; + DrawColorMesh(inDoc, rect, color); + } +} + +void T2Tenant::DrawTrafficColor(T2TowerDoc* inDoc, const CRect& inRect) const { + T2TrafficInfo *theTrafficInfo = inDoc->towerDoc_vf150(); + CRect rect1 = inRect; + + if (inRect.Height() > 1) { + if (IsFloor() || GetEquipDef()->GetCategory() == 100) + rect1.top = inRect.bottom - 1; + } + + for (CPoint pt = rect1.TopLeft(); pt.y < rect1.bottom; pt.y++) { + int baseline = theTrafficInfo->GetRange(pt); + while (pt.x < rect1.right) { + CRect drawRect(pt.x, pt.y, pt.x + 1, pt.y + 1); + + int range; + for (pt.x++; pt.x < rect1.right; pt.x++) { + range = theTrafficInfo->GetRange(pt); + if (range != baseline) + break; + drawRect.right++; + } + + int color; + switch (baseline) { + case 0: + color = 0; + break; + case 1: + color = 7; + break; + case 2: + color = 8; + break; + case 3: + color = 9; + break; + } + + DrawColorMesh(inDoc, drawRect, color); + baseline = range; + } + } +} + +/*static*/ void T2Tenant::DrawColorMesh(T2TowerDoc* inDoc, const CRect& inRect, int inClr) { + CRect qdRect; + UT2Coordinate::UnitToQD(inRect, qdRect, inDoc->mZoomLevel); + + inDoc->towerDoc_vf10C()->FillMesh(qdRect, T2PaletteAnimeDef::GetCommonColor(inClr)); +} + +void T2Tenant::IncPeopleEstimate(int inEstimate) { + mPeopleEstimate += inEstimate; + + if (mPeopleEstimate > 300) + mPeopleEstimate = 300; + else if (mPeopleEstimate < 0) + mPeopleEstimate = 0; } int T2Tenant::CalcEstimateColor() const { -} + int result = -1; + + if (mEstimate != 0) { + if (mEstimate > 200) + result = 12; + else if (mEstimate >= 70) + result = 14; + else + result = 9; + } -int T2Tenant::CollectEmployeeFromPool(T2TowerDoc*, T2TenantMemberTableDef*) { -} + return result; +} + +BOOL T2Tenant::CollectEmployeeFromPool(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable) { + BOOL found = false; + + int searchScore = inTable->GetScore(T2PlaceParamDef::Place_0); + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); -int T2Tenant::IsRegist() const { -} + unsigned int checkRoute = CheckRouteFromPool(inDoc, searchScore); + if (checkRoute > 0) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + int econoType = inTable->GetEconoType(); + BOOL checkOnlyFirstEconoType = inTable->IsCheckOnlyFirstEconoType(); + if (thePool->Find(inTable, econoType, checkRoute, checkOnlyFirstEconoType)) { + unsigned int numOfElem = inTable->GetNumOfElem(); + for (unsigned int i = 0; i < numOfElem; i++) { + T2TenantMemberDef *memberDef = inTable->GetElem(i); + if (memberDef) { + int numPeople = memberDef->GetNumOfPeople(); + for (int j = 0; j < numPeople; j++) { + T2People *people = thePool->Call(memberDef, econoType, checkRoute, 0); + if (people) + RegistBelongPeople(people); + } + } + } + + found = true; + + T2DateTime *theNow = inDoc->towerDoc_vf120(); + mResideDay = theNow->CalcTotalDays(); + } + } + + return found; +} + +BOOL T2Tenant::IsRegist() const { + BOOL result = false; + + if (mToolDef) + result = (((T2TenantDef *) mToolDef)->GetRegistID() > 0) && (mValiation == 0); + + return result; +} + +unsigned int T2Tenant::CheckRouteFromPool(T2TowerDoc* inDoc, unsigned int inScore) const { + unsigned int checkRoute = 0; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); + + POINT entrancePt = GetEntrancePt(); + + if (theNavigator->CheckRoute(theFloorInfo->GetEntrancePt(1000), entrancePt, inScore)) + checkRoute |= kTransportLobbyLeft | kTransportLobbyRight; + + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + T2Tenant *theTenant = theDB->FindEmptyParking(); + if (theTenant) { + if (theNavigator->CheckRoute(theTenant->GetExitPt(), entrancePt, inScore)) + checkRoute |= kTransportParking; + } + + T2TowerEvent *towerEvent = inDoc->towerDoc_vf170()->GetTowerEvent(); + T2DateTime *theDateTime = inDoc->towerDoc_vf120(); + theTenant = theDB->GetFirstTenant(kTenantRegistID8); + if (theTenant && theTenant->IsOpen()) { + if (theNavigator->CheckRoute(theTenant->GetExitPt(), entrancePt, inScore)) + checkRoute |= kTransportSubway; + } + + T2Transport *theTransport; + if (checkRoute & kTransportSubway) { + theTransport = towerEvent->GetMetroRailway(); + if (theTransport && !theTransport->GetAvailable(theDateTime) != NULL) + checkRoute &= ~kTransportSubway; + } -unsigned int T2Tenant::CheckRouteFromPool(T2TowerDoc*, unsigned int) const { + theTenant = theDB->GetFirstTenant(kTenantRegistID9); + if (theTenant && theTenant->IsOpen()) { + if (theNavigator->CheckRoute(theTenant->GetExitPt(), entrancePt, inScore)) + checkRoute |= kTransportShip; + } + + if (checkRoute & kTransportShip) { + theTransport = towerEvent->GetCruise(); + if (theTransport && !theTransport->GetAvailable(theDateTime) != NULL) + checkRoute &= ~kTransportShip; + } + + return checkRoute; } -T2TenantMemberTableDef* T2Tenant::GetCustomerTableDef(int) const { +T2TenantMemberTableDef* T2Tenant::GetCustomerTableDef(BOOL inFlag) const { + T2TenantMemberTableDef *result = NULL; + + if (GetEquipDef()) { + T2SubPlugin *subPlugin = (T2SubPlugin *) GetSubPlugin(); + if (subPlugin && inFlag) + ((T2TenantDef *) GetEquipDef())->SetCustomerTable(subPlugin); + result = ((T2TenantDef *) GetEquipDef())->GetCustomerTableDef(); + } + + return result; } -int T2Tenant::UpdateResidencialEstimate(T2TowerDoc*) { +BOOL T2Tenant::UpdateResidencialEstimate(T2TowerDoc* inDoc) { + int oldCol = CalcEstimateColor(); + + if (GetMark()) { + if (mBelongList) { + unsigned int totalEstimate = 0; + unsigned int numResidents = 0; + + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + totalEstimate += people->CalcCurrEstimate(); + numResidents++; + } + } + + if (numResidents > 0) + mPeopleEstimate = totalEstimate / numResidents; + } + + mEstimate = mPeopleEstimate; + + int senseOfNoise = ((T2TenantDef *) GetEquipDef())->GetSenseOfNoise(); + if (senseOfNoise != 0) { + T2TrafficInfo *theTrafficInfo = inDoc->towerDoc_vf150(); + if (theTrafficInfo) + mEstimate -= senseOfNoise * theTrafficInfo->GetRange(GetEntrancePt()); + } + + if (GetPriceIndex() != 0) + mEstimate += (GetPriceIndex() - 3) * -30; + + mEstimate += inDoc->towerDoc_vf120()->CalcLapseYears(mBuildDay) * -1; + } else { + mEstimate = 1; + } + + if (mEstimate < 1) + mEstimate = 1; + else if (mEstimate > 300) + mEstimate = 300; + + return CalcEstimateColor() != oldCol; } -void T2Tenant::BreakoutEmergency(T2TowerDoc*) { +void T2Tenant::BreakoutEmergency(T2TowerDoc* inDoc) { + if (GetRegistID() != kTenantRegistID5) { + int result = GetEquipDef()->EmergencyProc(inDoc, this); + if (result) { + SetDrawMode(result); + inDoc->GetTowerMainView()->tmv_vf128(mArea); + } + } } -void T2Tenant::BurntDown(T2TowerDoc*) { +void T2Tenant::BurntDown(T2TowerDoc* inDoc) { + if (mStatus != kTenantStatus10000) { + RemoveBelongPeople(inDoc); + mStatus = kTenantStatus10000; + +#line 2243 + _ASSERT(GetEquipDef() != NULL); + + GetEquipDef()->BurntDownProc(inDoc, this); + mDrawMode = DrawMode1; + inDoc->GetTowerMainView()->tmv_vf128(mArea); + } } -void T2Tenant::RecoverRelatedTenantList(T2RegistedTenantDB*) { +void T2Tenant::RecoverRelatedTenantList(T2RegistedTenantDB* inDB) { + if (mRelatedTenantList) + mRelatedTenantList = inDB->GetList((unsigned int) mRelatedTenantList); } int T2Tenant::GetTotalBelong() const { -} + int result = 0; -int T2Tenant::CanReplaceWorker() const { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + result++; + } + } + + return result; } -int T2Tenant::ReplaceWorker(T2TowerDoc*, T2People*) { +BOOL T2Tenant::CanReplaceWorker() const { + BOOL result = false; + + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (!result && iterator.Next(&people)) { + if (people && people->GetHomeTenant() == 1) + result = true; + } + } + + return result; } -void T2Tenant::CallEmployee(unsigned int) { +BOOL T2Tenant::ReplaceWorker(T2TowerDoc* inDoc, T2People* inPeople) { + BOOL result = false; + + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (!result && iterator.Next(&people)) { + if (people && people->GetHomeTenant() == 1) { + mBelongList->AssignItemsAt(1, iterator.GetCurrentIndex(), &inPeople); + inPeople->SetWorkTenant(mEquipID); + people->Remove(inDoc, mEquipID); + result = true; + } + } + } + + return result; } -int T2Tenant::DecideResidencialEstimation(T2TowerDoc*) { +void T2Tenant::CallEmployee(unsigned int inTime) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + if (!people->IsSetSpecialFlag(kSpecialFlag4) || people->GetHomeTenant() < 1000) { + unsigned int time = inTime + UT2Utils::Randomize(6) * 10; + people->SetDestination(mEquipID, time); + } + } + } + } } -int T2Tenant::UpdateCommercialEstimate() { +BOOL T2Tenant::DecideResidencialEstimation(T2TowerDoc* inDoc) { + BOOL result = false; + + if (mEstimate < 70) { + RemovePeople(inDoc); + result = true; + } else if (mEstimate > 200) { + DuplicateBelongPeople(inDoc); + } else { + static int counter; + counter++; + if (counter >= 5) { + DuplicateBelongPeople(inDoc); + counter = 0; + } + } + + return result; } -int T2Tenant::CalcProfitEstimate() const { +BOOL T2Tenant::UpdateCommercialEstimate() { + int oldCol = CalcEstimateColor(); + mEstimate = CalcProfitEstimate(); + return CalcEstimateColor() != oldCol; } -void T2Tenant::GetMerchandise(int&, int*&) { +int T2Tenant::CalcProfitEstimate() const { + int theInMoney = CalcInMoney(); + int theOutMoney = GetOutMoney(); + int val = (theInMoney + theOutMoney) * 70; + + if (val <= 0) + val = 1; + + int theEstimate; + if (theOutMoney != 0) + theEstimate = val / theOutMoney; + else + theEstimate = val; + + if (theEstimate < 1) + theEstimate = 1; + if (theEstimate > 300) + theEstimate = 300; + + return theEstimate; +} + +void T2Tenant::GetMerchandise(int& outCount, int*& outArray) { + if (mMerchandiseCount > 0) { + outCount = mMerchandiseCount; + for (int i = 0; i < outCount; i++) + outArray[i] = mMerchandise[i]; + + } else { + outCount = 0; + if (GetEquipDef()) { + T2TenantMemberTableDef *theTable = ((T2TenantDef *) GetEquipDef())->GetCustomerTableDef(); + + if (theTable) { + outCount = theTable->GetNumOfElem(); + for (int i = 0; i < outCount; i++) { + T2TenantMemberDef *memberDef = theTable->GetElem(i); + if (memberDef) + outArray[i] = memberDef->GetPercent(); + } + } + } + } } T2TenantMemberTableDef* T2Tenant::GetMerchandiseTMT() { + T2TenantMemberTableDef *result = NULL; + + if (GetEquipDef()) { + result = ((T2TenantDef *) GetEquipDef())->GetCustomerTableDef(); + if (result && mMerchandiseCount > 0) { + for (int i = 0; i < mMerchandiseCount; i++) { + T2TenantMemberDef *memberDef = result->GetElem(i); + if (memberDef) + memberDef->SetPercent(mMerchandise[i]); + } + } + } + + return result; } -void T2Tenant::SetMerchandise(int, int*) { +void T2Tenant::SetMerchandise(int inCount, int* inArray) { + if (inCount > 0 && inCount <= 4) { + mMerchandiseCount = inCount; + for (int i = 0; i < mMerchandiseCount; i++) + mMerchandise[i] = inArray[i]; + } } -void T2Tenant::SetRelatedTenant(T2TowerDoc*, unsigned int) { +void T2Tenant::SetRelatedTenant(T2TowerDoc* inDoc, unsigned int inRegistID) { + if (!mRelatedTenantList) { + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + mRelatedTenantList = theDB->GetList(inRegistID); + } + + if (mRelatedTenantList) + mRelatedTenantList->SetRelatedTenantID(mEquipID); } -/*virtual*/ void T2Tenant::BuildStart(T2TowerDoc*) { +/*virtual*/ void T2Tenant::BuildStart(T2TowerDoc* inDoc) { + SetStatus(kTenantStatus1); + ((T2TenantDef *) GetEquipDef())->BuildStartProc(inDoc, this); } |