1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#include "T2Archive.h"
#include "T2FloorInfo.h"
#include "T2Request.h"
#include "T2RequestIDArray.h"
#include "T2TowerDoc.h"
T2RequestIDArray::T2RequestIDArray() {
}
/*virtual*/ T2RequestIDArray::~T2RequestIDArray() {
}
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);
}
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 index, ERequestUpDown upDown, unsigned int requestID) {
AssignItemsAt(1, GetIndex(index, upDown), &requestID);
}
unsigned int T2RequestIDArray::GetRequestIDAt(int index, ERequestUpDown upDown) const {
unsigned int requestID = 0;
FetchItemAt(GetIndex(index, upDown), &requestID);
return requestID;
}
int T2RequestIDArray::GetIndex(int index, ERequestUpDown upDown) const {
int index_ = 1;
index_ += index * 2;
if (upDown == ERequestUpDown_1)
index_++;
return index_;
}
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* towerDoc, int index, ERequestUpDown upDown) {
unsigned int requestID = GetRequestIDAt(index, upDown);
if (requestID) {
T2FloorInfo *floorInfo = towerDoc->GetFloorInfo();
if (floorInfo) {
T2Request *request = floorInfo->GetRequest(requestID);
if (request)
request->RemoveRequest(towerDoc);
SetRequestIDAt(index, upDown, 0);
}
}
}
void T2RequestIDArray::Union(T2RequestIDArray* otherArray) {
LArrayIterator iterator(*otherArray);
unsigned int theReqID;
while (iterator.Next(&theReqID))
InsertItemsAt(1, mItemCount + 1, &theReqID);
}
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* towerDoc, int y) {
T2FloorInfo *theFloorInfo = towerDoc->GetFloorInfo();
#line 142
_ASSERT(theFloorInfo != NULL);
LArrayIterator iterator(*this);
unsigned int theReqID;
while (iterator.Next(&theReqID)) {
if (theReqID) {
T2Request *theRequest = theFloorInfo->GetRequest(theReqID);
if (theRequest)
theRequest->StopRemoved(towerDoc, y);
}
}
}
void T2RequestIDArray::ModuleRemoved(T2TowerDoc* towerDoc, unsigned int moduleIndex) {
T2FloorInfo *theFloorInfo = towerDoc->GetFloorInfo();
LArrayIterator iterator(*this);
unsigned int theReqID;
while (iterator.Next(&theReqID)) {
if (theReqID) {
T2Request *theRequest = theFloorInfo->GetRequest(theReqID);
if (theRequest && theRequest->GetModuleIndex() == moduleIndex)
theRequest->CancelReservingModule();
}
}
}
/*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* array, T2Archive& archive) {
DWORD code;
if (!array) {
code = 'xRqA';
archive << code;
} else {
code = 'RIDA';
archive << code;
array->WriteAsWord(archive);
}
}
|