#include "StdAfx.h" #include "CProgramPlugin.h" #include "T2Tenant.h" #include "T2TenantArray.h" #include "T2TenantDef.h" #include "../T2TowerDoc.h" T2TenantArray::T2TenantArray(unsigned int startID) : T2ObjectArray(startID) { mTenants = new T2Tenant[kGroupSize]; for (unsigned int i = 0; i < kGroupSize; i++) mTenants[i].mEquipID = mStartID + i; } /*virtual*/ T2TenantArray::~T2TenantArray() { if (mTenants) delete[] mTenants; } T2Tenant* T2TenantArray::FindUnusedTenant() { for (int i = 0; i < kGroupSize; i++) { if (!mTenants[i].IsUsed()) return &mTenants[i]; } return NULL; } /*virtual*/ void T2TenantArray::DispatchIdle(T2TowerDoc* towerDoc, int startIndex) { int counter = 0; T2Tenant *tenant = mTenants; for (int i = 0; i < kGroupSize; i++) { if (tenant->mUsed) { if ((counter % 32) == startIndex || towerDoc->mDebugStepRunEnabled) tenant->Idle(towerDoc); counter++; } tenant++; } } int T2TenantArray::CalcMentenanceCost(T2TowerDoc* towerDoc) const { int cost = 0; for (int i = 0; i < kGroupSize; i++) { if (mTenants[i].IsUsed()) cost += mTenants[i].CalcMentenanceCost(towerDoc); } return cost; } void T2TenantArray::TenantRemoved(unsigned int id) { for (int i = 0; i < kGroupSize; i++) { T2Tenant *tenant = &mTenants[i]; if (tenant->IsUsed() && !tenant->IsFloor() && tenant->GetRelatedTenantID() == id) tenant->SetRelatedTenantID(0); } } T2Tenant* T2TenantArray::GetTenantByPID(DWORD pluginID) { T2EquipDef *theDef; CProgramPlugin *thePlugin; for (int i = 0; i < kGroupSize; i++) { if (mTenants[i].IsUsed()) { theDef = mTenants[i].GetEquipDef(); thePlugin = theDef ? theDef->GetPlugin() : NULL; if (thePlugin && thePlugin->GetID() == pluginID) return &mTenants[i]; } } return NULL; } void T2TenantArray::BreakoutEmergency(T2TowerDoc* towerDoc) { for (int i = 0; i < kGroupSize; i++) { T2Tenant *tenant = &mTenants[i]; if (tenant->IsUsed() && !tenant->IsFloor()) tenant->BreakoutEmergency(towerDoc); } } void T2TenantArray::RecoverRelatedTenantList(T2RegistedTenantDB* db) { T2Tenant *tenant = mTenants; for (unsigned int i = 0; i < kGroupSize; i++, tenant++) { if (tenant->IsUsed()) tenant->RecoverRelatedTenantList(db); } } void T2TenantArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) { for (int i = 0; i < kGroupSize; i++) mTenants[i].Load(archive, towerDoc); } void T2TenantArray::Write(T2Archive& archive) { for (int i = 0; i < kGroupSize; i++) mTenants[i].Save(archive); }