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
|
#include "StdAfx.h"
#include "T2Archive.h"
#include "T2ElevatorModule.h"
#include "T2ElvModuleList.h"
#include "T2MoverDef.h"
#include "../T2TowerDoc.h"
#include "UT2Coordinate.h"
T2ElvModuleList::T2ElvModuleList() {
SetRect(&mModuleInset, 0, 0, 0, 0);
}
/*virtual*/ T2ElvModuleList::~T2ElvModuleList() {
}
/*virtual*/ BOOL T2ElvModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) {
BOOL success = T2MoverModuleList::Init(moverDef, baseRect);
if (success) {
moverDef->GetModuleInset(mModuleInset);
for (int i = 0; i < mMaxModule; i++) {
T2ElevatorModule *elevatorModule = new T2ElevatorModule(i);
if (elevatorModule)
success = InsertModuleAt(mItemCount + 1, elevatorModule);
else
success = false;
}
}
return success;
}
void T2ElvModuleList::AddModule(T2TowerDoc* towerDoc, int count, int position) {
LArrayIterator iterator(*this);
T2ElevatorModule *elevatorModule;
while (iterator.Next(&elevatorModule)) {
if (!elevatorModule->IsUsed()) {
elevatorModule->Init(count, position);
elevatorModule->SetModuleID(towerDoc);
mModuleCount++;
break;
}
}
}
/*virtual*/ void T2ElvModuleList::Destruct(T2TowerDoc* towerDoc) {
LArrayIterator iterator(*this);
T2ElevatorModule *elevatorModule = NULL;
while (iterator.Next(&elevatorModule)) {
if (elevatorModule)
RemoveModule(towerDoc, elevatorModule);
}
}
/*virtual*/ T2MoverModule* T2ElvModuleList::ConstructModule() {
return new T2ElevatorModule(0);
}
void T2ElvModuleList::CalcBaseQDRect(RECT& outRect) {
UT2Coordinate::UnitToQD(mBaseRect, outRect, 0, true);
UT2Coordinate::AddRect(outRect, mModuleInset);
}
int T2ElvModuleList::DestructModule(T2TowerDoc* towerDoc, T2Mover* mover, POINT inPt) {
RECT theBaseQDRect;
int theModuleIndex = -1;
int theZoomLevel = towerDoc->GetZoomLevel();
POINT pt = inPt;
CalcBaseQDRect(theBaseQDRect);
T2ElevatorModule *theElevatorModuleToRemove = NULL;
LArrayIterator iter(*this, GetCount() + 1);
T2ElevatorModule *theModule;
while (!theElevatorModuleToRemove && iter.Previous(&theModule)) {
if (theModule->IsPtInArea(pt, theBaseQDRect))
theElevatorModuleToRemove = theModule;
}
if (theElevatorModuleToRemove) {
theModuleIndex = theElevatorModuleToRemove->GetIndex();
theElevatorModuleToRemove->Remove(towerDoc, mover);
mModuleCount--;
}
return theModuleIndex;
}
BOOL T2ElvModuleList::IsHomePosition(int position) {
BOOL isHomePosition = false;
LArrayIterator iterator(*this);
T2ElevatorModule *theModule = NULL;
while (iterator.Next(&theModule) && !isHomePosition) {
if (theModule && theModule->GetHomePosition() == position)
isHomePosition = true;
}
return isHomePosition;
}
void T2ElvModuleList::MoverExpanded(T2Mover* mover, EEquipPos pos, int count) {
if (pos == EEquipPos_3)
OffsetRect(&mBaseRect, 0, count);
LArrayIterator iterator(*this);
T2ElevatorModule *elevatorModule;
while (iterator.Next(&elevatorModule)) {
if (elevatorModule->IsUsed())
elevatorModule->MoverExpanded(mover, pos, count);
}
}
/*virtual*/ void T2ElvModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover* mover, int position) {
LArrayIterator iterator(*this);
T2ElevatorModule *elevatorModule;
while (iterator.Next(&elevatorModule)) {
if (elevatorModule->IsUsed())
elevatorModule->StopAdded(towerDoc, mover, position);
}
}
/*virtual*/ void T2ElvModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover* mover, int position) {
LArrayIterator iterator(*this);
T2ElevatorModule *elevatorModule;
while (iterator.Next(&elevatorModule)) {
if (elevatorModule->IsUsed())
elevatorModule->StopRemoved(towerDoc, mover, position);
}
}
/*virtual*/ void T2ElvModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
T2MoverModuleList::Read(archive, towerDoc);
int numOfModules;
archive >> numOfModules;
mMaxModule = numOfModules;
BOOL ok = true;
for (int i = 0; i < numOfModules && ok; i++) {
T2ElevatorModule *elevatorModule = new T2ElevatorModule(i);
if (elevatorModule) {
elevatorModule->Load(archive, towerDoc);
ok = InsertModuleAt(mItemCount + 1, elevatorModule);
}
}
LArrayIterator iter(*this);
T2ElevatorModule *theModule;
while (iter.Next(&theModule)) {
if (theModule->IsUsed())
mModuleCount++;
}
archive.ReadSRect(mModuleInset);
}
/*virtual*/ void T2ElvModuleList::Write(T2Archive& archive) {
T2MoverModuleList::Write(archive);
archive.WriteSRect(mModuleInset);
}
|