summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2TenantArray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/T2TenantArray.cpp')
-rw-r--r--src/T2DLL/T2TenantArray.cpp85
1 files changed, 76 insertions, 9 deletions
diff --git a/src/T2DLL/T2TenantArray.cpp b/src/T2DLL/T2TenantArray.cpp
index e7dfb45..4c536e8 100644
--- a/src/T2DLL/T2TenantArray.cpp
+++ b/src/T2DLL/T2TenantArray.cpp
@@ -1,34 +1,101 @@
+#include "CProgramPlugin.h"
+#include "T2Tenant.h"
#include "T2TenantArray.h"
+#include "T2TenantDef.h"
+#include "T2TowerDoc.h"
-T2TenantArray::T2TenantArray(unsigned int) {
+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*, int) {
+/*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->m180)
+ tenant->Idle(towerDoc);
+ counter++;
+ }
+ tenant++;
+ }
}
-int T2TenantArray::CalcMentenanceCost(T2TowerDoc*) const {
+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) {
+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(unsigned long) {
+T2Tenant* T2TenantArray::GetTenantByPID(DWORD pluginID) {
+ for (int i = 0; i < kGroupSize; i++) {
+ if (mTenants[i].IsUsed()) {
+ T2EquipDef *equipDef = mTenants[i].GetEquipDef();
+ CProgramPlugin *plugin = equipDef ? equipDef->GetPlugin() : NULL;
+
+ if (plugin && plugin->GetID() == pluginID)
+ return &mTenants[i];
+ }
+ }
+
+ return NULL;
}
-void T2TenantArray::BreakoutEmergency(T2TowerDoc*) {
+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*) {
+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&, T2TowerDoc*) {
+void T2TenantArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
+ for (int i = 0; i < kGroupSize; i++)
+ mTenants[i].Load(archive, towerDoc);
}
-void T2TenantArray::Write(T2Archive&) {
+void T2TenantArray::Write(T2Archive& archive) {
+ for (int i = 0; i < kGroupSize; i++)
+ mTenants[i].Save(archive);
}