summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2RequestIDArray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/T2RequestIDArray.cpp')
-rw-r--r--src/T2DLL/T2RequestIDArray.cpp134
1 files changed, 121 insertions, 13 deletions
diff --git a/src/T2DLL/T2RequestIDArray.cpp b/src/T2DLL/T2RequestIDArray.cpp
index 5cd2209..4228bf6 100644
--- a/src/T2DLL/T2RequestIDArray.cpp
+++ b/src/T2DLL/T2RequestIDArray.cpp
@@ -1,4 +1,8 @@
+#include "T2Archive.h"
+#include "T2FloorInfo.h"
+#include "T2Request.h"
#include "T2RequestIDArray.h"
+#include "T2TowerDoc.h"
T2RequestIDArray::T2RequestIDArray() {
}
@@ -6,47 +10,151 @@ T2RequestIDArray::T2RequestIDArray() {
/*virtual*/ T2RequestIDArray::~T2RequestIDArray() {
}
-void T2RequestIDArray::Init(const RECT&) {
+void T2RequestIDArray::Init(const RECT& rect) {
+ Expand(ReqIDArrayPos_1, rect.bottom - rect.top);
}
unsigned int T2RequestIDArray::GetItemCount() const {
+ return GetCount();
}
void T2RequestIDArray::AllClear() {
+ RemoveItemsAt(mItemCount, 1);
}
-void T2RequestIDArray::Expand(EReqIDArrayPos, int) {
+static const unsigned int zeroID = 0;
+
+void T2RequestIDArray::Expand(EReqIDArrayPos pos, int count) {
+ int where = mItemCount + 1;
+ if (pos == ReqIDArrayPos_0)
+ where = 1;
+
+ if (count > 0) {
+ int actualCount = count * 2;
+ for (int i = 0; i < actualCount; i++)
+ InsertItemsAt(1, where, &zeroID);
+ } else {
+ int actualCount = -count * 2;
+ for (int i = 0; i < actualCount; i++)
+ RemoveItemsAt(1, where);
+ }
}
-void T2RequestIDArray::SetRequestIDAt(int, ERequestUpDown, unsigned int) {
+void T2RequestIDArray::SetRequestIDAt(int index, ERequestUpDown upDown, unsigned int requestID) {
+ AssignItemsAt(1, GetIndex(index, upDown), &requestID);
}
-unsigned int T2RequestIDArray::GetRequestIDAt(int, ERequestUpDown) const {
+unsigned int T2RequestIDArray::GetRequestIDAt(int index, ERequestUpDown upDown) const {
+ unsigned int requestID = 0;
+ FetchItemAt(GetIndex(index, upDown), &requestID);
+ return requestID;
}
-int T2RequestIDArray::GetIndex(int, ERequestUpDown) const {
+int T2RequestIDArray::GetIndex(int index, ERequestUpDown upDown) const {
+ int index_ = 1;
+ index_ += index * 2;
+ if (upDown == ERequestUpDown_1)
+ index_++;
+ return index_;
}
-int T2RequestIDArray::IsStopPosition(int) const {
+BOOL T2RequestIDArray::IsStopPosition(int index) const {
+ BOOL result = false;
+
+ if (GetRequestIDAt(index, ERequestUpDown_0) || GetRequestIDAt(index, ERequestUpDown_1))
+ result = true;
+
+ return result;
}
-void T2RequestIDArray::RemoveRequest(T2TowerDoc*, int, ERequestUpDown) {
+void T2RequestIDArray::RemoveRequest(T2TowerDoc* towerDoc, int index, ERequestUpDown upDown) {
+ unsigned int requestID = GetRequestIDAt(index, upDown);
+ if (requestID) {
+ T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C();
+ if (floorInfo) {
+ T2Request *request = floorInfo->GetRequest(requestID);
+ if (request)
+ request->RemoveRequest(towerDoc);
+ SetRequestIDAt(index, upDown, 0);
+ }
+ }
}
-void T2RequestIDArray::Union(T2RequestIDArray*) {
+void T2RequestIDArray::Union(T2RequestIDArray* otherArray) {
+ LArrayIterator iterator(*otherArray);
+ unsigned int requestID;
+
+ while (iterator.Next(&requestID))
+ InsertItemsAt(1, mItemCount + 1, &requestID);
}
-void T2RequestIDArray::MoverIDChanged(T2FloorInfo*, unsigned int) {
+void T2RequestIDArray::MoverIDChanged(T2FloorInfo* floorInfo, unsigned int moverID) {
+ LArrayIterator iterator(*this);
+ unsigned int requestID;
+
+ while (iterator.Next(&requestID)) {
+ T2Request *request = floorInfo->GetRequest(requestID);
+ if (request)
+ request->MoverIDChanged(moverID);
+ }
}
-void T2RequestIDArray::StopRemoved(T2TowerDoc*, int) {
+void T2RequestIDArray::StopRemoved(T2TowerDoc* towerDoc, int y) {
+ T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C();
+#line 142
+ _ASSERT(floorInfo);
+
+ LArrayIterator iterator(*this);
+ unsigned int requestID;
+
+ while (iterator.Next(&requestID)) {
+ if (requestID) {
+ T2Request *request = floorInfo->GetRequest(requestID);
+ if (request)
+ request->StopRemoved(towerDoc, y);
+ }
+ }
}
-void T2RequestIDArray::ModuleRemoved(T2TowerDoc*, unsigned int) {
+void T2RequestIDArray::ModuleRemoved(T2TowerDoc* towerDoc, unsigned int moduleIndex) {
+ T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C();
+
+ LArrayIterator iterator(*this);
+ unsigned int requestID;
+
+ while (iterator.Next(&requestID)) {
+ if (requestID) {
+ T2Request *request = floorInfo->GetRequest(requestID);
+ if (request && request->GetModuleIndex() == moduleIndex)
+ request->CancelReservingModule();
+ }
+ }
}
-/*static*/ T2RequestIDArray* T2RequestIDArray::ReadReqIDArray(T2Archive&) {
+/*static*/ T2RequestIDArray* T2RequestIDArray::ReadReqIDArray(T2Archive& archive) {
+ T2RequestIDArray *array = NULL;
+
+ DWORD code;
+ archive >> code;
+
+ if (code == 'RIDA')
+ array = new T2RequestIDArray;
+
+ if (array)
+ array->ReadAsWord(archive);
+
+ return array;
}
-/*static*/ void T2RequestIDArray::WriteReqIDArray(T2RequestIDArray*, T2Archive&) {
+/*static*/ void T2RequestIDArray::WriteReqIDArray(T2RequestIDArray* array, T2Archive& archive) {
+ DWORD code;
+
+ if (!array) {
+ code = 'xRqA';
+ archive << code;
+ } else {
+ code = 'RIDA';
+ archive << code;
+ array->WriteAsWord(archive);
+ }
}