summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2TenantArrayList.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
commitc0c336500955a23e344651e5412c9d9d441ef4ee (patch)
tree790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2TenantArrayList.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2TenantArrayList.cpp180
1 files changed, 167 insertions, 13 deletions
diff --git a/src/T2DLL/T2TenantArrayList.cpp b/src/T2DLL/T2TenantArrayList.cpp
index 6383c6d..be01aeb 100644
--- a/src/T2DLL/T2TenantArrayList.cpp
+++ b/src/T2DLL/T2TenantArrayList.cpp
@@ -1,52 +1,206 @@
+#include "T2Archive.h"
+#include "T2Tenant.h"
+#include "T2TenantArray.h"
#include "T2TenantArrayList.h"
T2TenantArrayList::T2TenantArrayList() {
+ mCounter = 0;
+ T2TenantArray *tenantArray = new T2TenantArray;
+ Add(tenantArray);
}
/*virtual*/ T2TenantArrayList::~T2TenantArrayList() {
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ delete tenantArray;
}
-void T2TenantArrayList::Add(T2TenantArray*) {
+void T2TenantArrayList::Add(T2TenantArray* tenantArray) {
+ InsertItemsAt(1, mItemCount + 1, &tenantArray);
}
unsigned int T2TenantArrayList::GetItemCount() {
+ return GetCount();
}
-T2TenantArray* T2TenantArrayList::GetItemAt(int) {
+T2TenantArray* T2TenantArrayList::GetItemAt(int index) {
+ T2TenantArray *tenantArray = NULL;
+ FetchItemAt(index, &tenantArray);
+ return tenantArray;
}
-T2Tenant* T2TenantArrayList::GetTenantByID(unsigned int) {
+T2Tenant* T2TenantArrayList::GetTenantByID(unsigned int tenantID) {
+ if (tenantID == 0)
+ return NULL;
+
+ int group = (tenantID - 1000) / T2TenantArray::kGroupSize;
+ int indexInGroup = (tenantID - 1000) % T2TenantArray::kGroupSize;
+ T2TenantArray *tenantArray = GetItemAt(group + 1);
+ if (tenantArray)
+ return tenantArray->GetIndexTenant(indexInGroup);
+ else
+ return NULL;
}
-T2Tenant* T2TenantArrayList::GetTenantByPID(unsigned long) {
+T2Tenant* T2TenantArrayList::GetTenantByPID(DWORD pluginID) {
+ T2Tenant *tenant = NULL;
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (!tenant && iterator.Next(&tenantArray)) {
+ tenant = tenantArray->GetTenantByPID(pluginID);
+ }
+
+ return tenant;
}
T2Tenant* T2TenantArrayList::FindUnusedTenant() {
+ T2Tenant *result = NULL;
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray = NULL;
+
+ while (!result && iterator.Next(&tenantArray)) {
+ result = tenantArray->FindUnusedTenant();
+ }
+
+ if (!result) {
+ unsigned int newStartID = 1000;
+ if (tenantArray)
+ newStartID = tenantArray->GetStartID() + T2TenantArray::kGroupSize;
+
+ tenantArray = new T2TenantArray(newStartID);
+ if (tenantArray) {
+ Add(tenantArray);
+ result = tenantArray->FindUnusedTenant();
+ }
+ }
+
+ return result;
}
-void T2TenantArrayList::DispatchIdle(T2TowerDoc*) {
+void T2TenantArrayList::DispatchIdle(T2TowerDoc* towerDoc) {
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ tenantArray->DispatchIdle(towerDoc, mCounter);
+
+ mCounter++;
+ if (mCounter >= 32)
+ mCounter = 0;
}
-void T2TenantArrayList::TenantRemoved(unsigned int) {
+void T2TenantArrayList::TenantRemoved(unsigned int v) {
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ tenantArray->TenantRemoved(v);
}
-void T2TenantArrayList::BreakoutEmergency(T2TowerDoc*) {
+void T2TenantArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) {
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ tenantArray->BreakoutEmergency(towerDoc);
}
-int T2TenantArrayList::CalcMentenanceCost(T2TowerDoc*) const {
+int T2TenantArrayList::CalcMentenanceCost(T2TowerDoc* towerDoc) const {
+ int cost = 0;
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ cost += tenantArray->CalcMentenanceCost(towerDoc);
+
+ return cost;
}
-LArray* T2TenantArrayList::MakeTenantList(int) {
+LArray* T2TenantArrayList::MakeTenantList(int type) {
+ LArray *result = new LArray(sizeof(T2Tenant *));
+
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray)) {
+ for (int i = 0; i < T2TenantArray::kGroupSize; i++) {
+ T2Tenant *tenant = &tenantArray->mTenants[i];
+ if (tenant->IsUsed() && tenant->GetEquipType() == type)
+ result->Add(&tenant);
+ }
+ }
+
+ if (result->GetCount() > 0) {
+ return result;
+ } else {
+ delete result;
+ return NULL;
+ }
}
-LArray* T2TenantArrayList::MakeTenantList(int, (__cdecl*)(class, const T2Tenant*, )) {
+LArray* T2TenantArrayList::MakeTenantList(BOOL(*func) (const T2Tenant*)) {
+ LArray *result = new LArray(sizeof(T2Tenant *));
+
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray)) {
+ for (int i = 0; i < T2TenantArray::kGroupSize; i++) {
+ T2Tenant *tenant = &tenantArray->mTenants[i];
+ if (tenant->IsUsed() && func(tenant))
+ result->Add(&tenant);
+ }
+ }
+
+ if (result->GetCount() > 0) {
+ return result;
+ } else {
+ delete result;
+ return NULL;
+ }
}
-void T2TenantArrayList::Read(T2Archive&, T2TowerDoc*) {
+void T2TenantArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
+ archive >> mCounter;
+
+ int count;
+ archive >> count;
+
+ RemoveItemsAt(GetCount(), 1);
+ unsigned int startID = 1000;
+
+ for (int i = 0; i < count; i++) {
+ Add(new T2TenantArray(startID));
+ startID += T2TenantArray::kGroupSize;
+ }
+
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ tenantArray->Read(archive, towerDoc);
}
-void T2TenantArrayList::Write(T2Archive&) {
+void T2TenantArrayList::Write(T2Archive& archive) {
+ archive << mCounter;
+
+ int count = GetItemCount();
+ archive << count;
+
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ tenantArray->Write(archive);
}
-void T2TenantArrayList::RecoverRelatedTenantList(T2RegistedTenantDB*) {
+void T2TenantArrayList::RecoverRelatedTenantList(T2RegistedTenantDB* db) {
+ LArrayIterator iterator(*this);
+ T2TenantArray *tenantArray;
+
+ while (iterator.Next(&tenantArray))
+ tenantArray->RecoverRelatedTenantList(db);
}