blob: 716419a1466b4b97cc6eb2845c73758966814013 (
plain)
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
|
#include "T2Archive.h"
#include "T2MoverArray.h"
#include "T2MoverArrayList.h"
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* inArray) {
InsertItemsAt(1, mItemCount + 1, &inArray);
}
unsigned int T2MoverArrayList::GetItemCount() {
return GetCount();
}
T2MoverArray* T2MoverArrayList::GetItemAt(int inIndex) {
T2MoverArray *theArray;
FetchItemAt(inIndex, &theArray);
return theArray;
}
T2Mover* T2MoverArrayList::GetMoverByID(unsigned int inMoverID) {
if (inMoverID == 0)
return NULL;
int groupNum = (inMoverID - 1) / T2MoverArray::kGroupSize;
int indexInGroup = (inMoverID - 1) % T2MoverArray::kGroupSize;
if (GetCount() > groupNum)
return GetItemAt(groupNum + 1)->GetIndexMover(indexInGroup);
else
return NULL;
}
T2Mover* T2MoverArrayList::FindUnusedMover() {
T2Mover *theMover = NULL;
LArrayIterator iter(*this);
T2MoverArray *theArray = NULL;
while (!theMover && iter.Next(&theArray))
theMover = theArray->FindUnusedMover();
if (!theMover) {
unsigned int lastStartID = 1;
if (theArray)
lastStartID = theArray->GetStartID() + T2MoverArray::kGroupSize;
if ((lastStartID + T2MoverArray::kGroupSize) < 1000) {
theArray = new T2MoverArray(lastStartID);
if (theArray) {
Add(theArray);
theMover = theArray->FindUnusedMover();
}
}
}
return theMover;
}
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* inDoc) {
LArrayIterator iterator(*this);
T2MoverArray *theArray;
while (iterator.Next(&theArray))
theArray->DispatchIdle(inDoc, 0);
}
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 iter(*this);
T2MoverArray *theArray;
while (iter.Next(&theArray))
theArray->Read(inArchive, inDoc);
}
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* inDoc) const {
int cost = 0;
LArrayIterator iter(*this);
T2MoverArray *theArray;
while (iter.Next(&theArray))
cost += theArray->CalcMentenanceCost(inDoc);
return cost;
}
LArray* T2MoverArrayList::MakeMoverList(int inType) {
LArray *result = new LArray(sizeof(T2Mover *));
LArrayIterator iter(*this);
T2MoverArray *theMoverArray;
while (iter.Next(&theMoverArray)) {
for (int i = 0; i < T2MoverArray::kGroupSize; i++) {
T2Mover *theMover = &theMoverArray->mMover[i];
if (theMover->IsUsed() && theMover->GetEquipType() == inType)
result->Add(&theMover);
}
}
if (result->GetCount() > 0) {
return result;
} else {
delete result;
return NULL;
}
}
|