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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
#include "GlobalFunc.h"
#include "T2Archive.h"
#include "T2FloorInfo.h"
#include "T2Mover.h"
#include "T2MoverModule.h"
#include "T2Name.h"
#include "T2NameList.h"
#include "T2People.h"
#include "T2PeopleArrayList.h"
#include "T2Tenant.h"
#include "T2TowerDoc.h"
T2MoverModule::T2MoverModule() {
mPosition = 0;
mDirection = 0;
mWaitCounter = 0;
mPatIndex = 0;
mNumPeople = 0;
_4C = 0;
mLink1 = NULL;
mLink2 = NULL;
mModuleID = 0;
}
/*virtual*/ T2MoverModule::~T2MoverModule() {
}
/*virtual*/ void T2MoverModule::SetUsed(BOOL used) {
if (!used) {
T2TowerDoc *theTowerDoc = GetCurrentT2TowerDoc();
#line 35
ASSERT(theTowerDoc != NULL);
T2NameList *theNameDB = theTowerDoc->mNameDB;
#line 38
ASSERT(theNameDB != NULL);
T2Name *name = theNameDB->Search(this, true);
if (name) {
theNameDB->RemoveName(name);
delete name;
}
name = theNameDB->Search(this, false);
if (name) {
theNameDB->RemoveName(name);
delete name;
}
}
T2Object::SetUsed(used);
}
/*virtual*/ void T2MoverModule::RemoveContents(T2TowerDoc* towerDoc) {
T2FloorInfo *theFloorInfo = towerDoc->mFloorInfo;
while (mLink1) {
T2People *thePeople = (T2People *) mLink1;
Leave(thePeople);
POINT destPos = thePeople->GetCurrDestPos();
T2Tenant *theFloor = theFloorInfo->GetFloor(destPos.y, destPos.x);
if (theFloor) {
theFloor->Enter(thePeople);
thePeople->IncEstimate(-100);
}
}
}
/*virtual*/ void T2MoverModule::StopAdded(T2TowerDoc*, T2Mover*, int) {
}
/*virtual*/ void T2MoverModule::StopRemoved(T2TowerDoc*, T2Mover*, int) {
}
/*virtual*/ void T2MoverModule::Enter(T2Mover* mover, T2People* people) {
people->mCurrEquipID = mover->GetEquipID();
RECT area;
mover->GetEquipArea(area);
people->mCurPosition.x = (area.left + area.right) / 2;
people->ChangeStatus(kStatus8);
Enter(people);
}
/*virtual*/ BOOL T2MoverModule::Enter(CLink* link) {
mNumPeople++;
if (!mLink1) {
mLink1 = link;
mLink2 = link;
link->SetPrev(NULL);
return true;
}
if (mLink2) {
mLink2->InsertAt(link);
mLink2 = link;
return true;
}
return false;
}
/*virtual*/ BOOL T2MoverModule::Leave(CLink* link) {
mNumPeople--;
if (mLink1) {
if (mLink1 == link) {
mLink1 = link->GetNext();
if (mLink1 == NULL)
mLink2 = NULL;
else if (mLink1->GetNext() == NULL)
mLink2 = mLink1;
link->Remove();
return true;
}
if (mLink2 != link) {
link->Remove();
} else if (mLink2 == link) {
mLink2 = link->GetPrev();
link->Remove();
if (mLink2 == NULL)
mLink1 = NULL;
return true;
}
}
return false;
}
/*virtual*/ void T2MoverModule::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) {
T2Object::LoadSelf(archive, towerDoc);
if (IsUsed()) {
short s;
archive >> s;
mPosition = s;
archive >> s;
mDirection = s;
archive >> s;
mWaitCounter = s;
archive >> s;
mPatIndex = s;
archive >> s;
mNumPeople = s;
archive >> s;
_4C = s;
unsigned int peopleID;
archive >> peopleID;
if (peopleID)
mLink1 = towerDoc->mPeopleArrayList->FindPeople(peopleID);
else
mLink1 = NULL;
archive >> peopleID;
if (peopleID)
mLink2 = towerDoc->mPeopleArrayList->FindPeople(peopleID);
else
mLink2 = NULL;
}
}
/*virtual*/ void T2MoverModule::SaveSelf(T2Archive& archive) {
T2Object::SaveSelf(archive);
if (IsUsed()) {
short s;
s = mPosition;
archive << s;
s = mDirection;
archive << s;
s = mWaitCounter;
archive << s;
s = mPatIndex;
archive << s;
s = mNumPeople;
archive << s;
s = _4C;
archive << s;
unsigned int peopleID;
if (mLink1)
peopleID = ((T2People *) mLink1)->GetPeopleID();
else
peopleID = 0;
archive << peopleID;
if (mLink2)
peopleID = ((T2People *) mLink2)->GetPeopleID();
else
peopleID = 0;
archive << peopleID;
}
}
void T2MoverModule::SetDirection(int direction) {
mDirection = direction;
T2MoverModuleMessageData data;
data.moverModule = this;
data.value = mPosition;
BroadcastMessage(1000, &data);
}
void T2MoverModule::AddPosition(int value) {
int oldPosition = mPosition;
mPosition += value;
T2MoverModuleMessageData data;
data.moverModule = this;
data.value = oldPosition;
BroadcastMessage(1000, &data);
}
/*static*/ unsigned int T2MoverModule::sModuleID;
/*static*/ unsigned int T2MoverModule::GetNewModuleID(T2TowerDoc* towerDoc) {
incAgain:
sModuleID++;
if (towerDoc->GetFloorInfo()->GetModule(sModuleID))
goto incAgain;
return sModuleID;
}
void T2MoverModule::SetModuleID(T2TowerDoc* towerDoc) {
mModuleID = GetNewModuleID(towerDoc);
}
|