From c0c336500955a23e344651e5412c9d9d441ef4ee Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 28 Jun 2023 22:22:32 +0100 Subject: first pass of T2DLL --- src/T2DLL/T2PeopleArrayList.cpp | 130 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 11 deletions(-) (limited to 'src/T2DLL/T2PeopleArrayList.cpp') diff --git a/src/T2DLL/T2PeopleArrayList.cpp b/src/T2DLL/T2PeopleArrayList.cpp index 19db7d8..91b94a6 100644 --- a/src/T2DLL/T2PeopleArrayList.cpp +++ b/src/T2DLL/T2PeopleArrayList.cpp @@ -1,46 +1,154 @@ +#include "T2Archive.h" +#include "T2PeopleArray.h" #include "T2PeopleArrayList.h" T2PeopleArrayList::T2PeopleArrayList() { + mCounter = 0; + T2PeopleArray *peopleArray = new T2PeopleArray; + Add(peopleArray); } /*virtual*/ T2PeopleArrayList::~T2PeopleArrayList() { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + delete peopleArray; } -void T2PeopleArrayList::Add(T2PeopleArray*) { +void T2PeopleArrayList::Add(T2PeopleArray* peopleArray) { + LArray::Add(&peopleArray); } unsigned int T2PeopleArrayList::GetItemCount() { + return GetCount(); } -T2PeopleArray* T2PeopleArrayList::GetItemAt(int) { +T2PeopleArray* T2PeopleArrayList::GetItemAt(int index) { + T2PeopleArray *peopleArray; + FetchItemAt(index, &peopleArray); + return peopleArray; } -T2People* T2PeopleArrayList::FindPeople(unsigned int) { +T2People* T2PeopleArrayList::FindPeople(unsigned int peopleID) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) { + T2People *people = peopleArray->FindPeople(peopleID); + if (people) + return people; + } + + return NULL; } T2People* T2PeopleArrayList::FindUnusedPeople() { + T2People *result = NULL; + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray = NULL; + + while (!result && iterator.Next(&peopleArray)) { + result = peopleArray->FindUnusedPeople(); + } + + if (!result) { + unsigned int newStartID = 1; + if (peopleArray) + newStartID = peopleArray->GetStartID() + 256; + + peopleArray = new T2PeopleArray(newStartID); + if (peopleArray) { + Add(peopleArray); + result = peopleArray->FindUnusedPeople(); + } + } + + return result; } -void T2PeopleArrayList::DispatchIdle(T2TowerDoc*) { +void T2PeopleArrayList::DispatchIdle(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->DispatchIdle(towerDoc, mCounter); + + mCounter++; + if (mCounter >= 8) + mCounter = 0; } -void T2PeopleArrayList::DrawSearchedPerson(T2TowerDoc*) { +void T2PeopleArrayList::DrawSearchedPerson(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->DrawSearchedPerson(towerDoc); } -void T2PeopleArrayList::SetWalkPeople(int) { +void T2PeopleArrayList::SetWalkPeople(int v) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->SetWalkPeople(v); } -void T2PeopleArrayList::TenantRemoved(unsigned int) { +void T2PeopleArrayList::TenantRemoved(unsigned int v) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->TenantRemoved(v); } -void T2PeopleArrayList::AddStress(int) { +void T2PeopleArrayList::AddStress(int v) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->AddStress(v); } -void T2PeopleArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2PeopleArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + int count; + archive >> count; + + RemoveItemsAt(GetCount(), 1); + unsigned int startID = 1; + + for (int i = 0; i < count; i++) { + Add(new T2PeopleArray(startID)); + startID += 256; + } + + T2PeopleArray *peopleArray; + + LArrayIterator iterator1(*this); + while (iterator1.Next(&peopleArray)) + peopleArray->Read(archive, towerDoc); + + LArrayIterator iterator2(*this); + while (iterator2.Next(&peopleArray)) + peopleArray->ResolveLink(this); } -void T2PeopleArrayList::Write(T2Archive&) { +void T2PeopleArrayList::Write(T2Archive& archive) { + int count = GetItemCount(); + archive << count; + + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->Write(archive); } -void T2PeopleArrayList::BreakoutEmergency(T2TowerDoc*) { +void T2PeopleArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->BreakoutEmergency(towerDoc); } -- cgit v1.2.3