diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2MoverArrayList.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2MoverArrayList.cpp | 128 |
1 files changed, 118 insertions, 10 deletions
diff --git a/src/T2DLL/T2MoverArrayList.cpp b/src/T2DLL/T2MoverArrayList.cpp index 09894aa..d36c2de 100644 --- a/src/T2DLL/T2MoverArrayList.cpp +++ b/src/T2DLL/T2MoverArrayList.cpp @@ -1,40 +1,148 @@ +#include "T2Archive.h" +#include "T2MoverArray.h" #include "T2MoverArrayList.h" -T2MoverArrayList::T2MoverArrayList() { +T2MoverArrayList::T2MoverArrayList() + : LArray(sizeof(T2MoverArray *)) +{ + T2MoverArray *theArray = new T2MoverArray; + Add(theArray); } /*virtual*/ T2MoverArrayList::~T2MoverArrayList() { + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + delete theArray; } -void T2MoverArrayList::Add(T2MoverArray*) { +void T2MoverArrayList::Add(T2MoverArray* inArray) { + InsertItemsAt(1, mItemCount + 1, &inArray); } unsigned int T2MoverArrayList::GetItemCount() { + return GetCount(); } -T2MoverArray* T2MoverArrayList::GetItemAt(int) { +T2MoverArray* T2MoverArrayList::GetItemAt(int inIndex) { + T2MoverArray *theArray; + FetchItemAt(inIndex, &theArray); + return theArray; } -T2Mover* T2MoverArrayList::GetMoverByID(unsigned int) { +T2Mover* T2MoverArrayList::GetMoverByID(unsigned int inMoverID) { + if (inMoverID == 0) + return NULL; + + int groupID = (inMoverID - 1) / T2MoverArray::kGroupSize; + int indexInGroup = (inMoverID - 1) % T2MoverArray::kGroupSize; + if (GetCount() > groupID) + return GetItemAt(groupID + 1)->GetIndexMover(indexInGroup); + else + return NULL; } T2Mover* T2MoverArrayList::FindUnusedMover() { + T2Mover *result = NULL; + LArrayIterator iterator(*this); + T2MoverArray *theArray = NULL; + + while (!result && iterator.Next(&theArray)) + result = theArray->FindUnusedMover(); + + if (!result) { + unsigned int startID = 1; + if (theArray) + startID = theArray->GetStartID() + T2MoverArray::kGroupSize; + + if ((startID + T2MoverArray::kGroupSize) < 1000) { + theArray = new T2MoverArray(startID); + if (theArray) { + Add(theArray); + result = theArray->FindUnusedMover(); + } + } + } + + return result; } -void T2MoverArrayList::DrawMoverAll(T2TowerDoc*, const RECT&) { +void T2MoverArrayList::DrawMoverAll(T2TowerDoc* inDoc, const RECT& inRect) { + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->DrawMoverAll(inDoc, inRect); } -void T2MoverArrayList::DispatchIdle(T2TowerDoc*) { +void T2MoverArrayList::DispatchIdle(T2TowerDoc* inDoc) { + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->DispatchIdle(inDoc, 0); } -void T2MoverArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2MoverArrayList::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + int groupCount; + inArchive >> groupCount; + + RemoveItemsAt(GetCount(), 1); + + unsigned int startID = 1; + for (int i = 0; i < groupCount; i++) { + Add(new T2MoverArray(startID)); + startID += T2MoverArray::kGroupSize; + } + + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->Read(inArchive, inDoc); } -void T2MoverArrayList::Write(T2Archive&) { +void T2MoverArrayList::Write(T2Archive& inArchive) { + int groupCount = GetItemCount(); + inArchive << groupCount; + + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->Write(inArchive); } -int T2MoverArrayList::CalcMentenanceCost(T2TowerDoc*) const { +int T2MoverArrayList::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int cost = 0; + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + cost += theArray->CalcMentenanceCost(inDoc); + + return cost; } -LArray* T2MoverArrayList::MakeMoverList(int) { +LArray* T2MoverArrayList::MakeMoverList(int inType) { + LArray *result = new LArray(sizeof(T2Mover *)); + + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + T2Mover *theMover = &theArray->mMover[i]; + if (theMover->IsUsed() && theMover->GetEquipType() == inType) + result->Add(&theMover); + } + } + + if (result->GetCount() > 0) { + return result; + } else { + delete result; + return NULL; + } } |