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
|
#include "GlobalFunc.h"
#include "T2Archive.h"
#include "T2DateTime.h"
#include "T2Equip.h"
#include "T2RouteCEArray.h"
#include "T2SoundPlayer.h"
#include "T2TowerDoc.h"
T2Equip::T2Equip() {
mEquipID = 0;
SetRect(&mArea, 0, 0, 0, 0);
mEquipType = 0;
mDrawMode = DrawMode0;
mPatIndex = 0;
mCapacity = 0;
m44 = 0;
mInMoneyIndex = 0;
m48 = 0;
mBuildDay = 0;
mAttribute = 0;
mCEArray = NULL;
m58 = 0;
}
/*virtual*/ T2Equip::~T2Equip() {
if (mCEArray)
delete mCEArray;
}
int T2Equip::InitEquip(T2EquipDef* def, const RECT& area, unsigned int valiation) {
if (def) {
mEquipType = def->GetEquipType();
mCapacity = def->GetCapacity();
mAttribute = def->GetAttribute();
mToolDef = def;
}
mValiation = valiation;
mArea = area;
mDrawMode = DrawMode0;
m44 = 0;
m48 = 0;
mPatIndex = 0;
T2TowerDoc *towerDoc = GetCurrentT2TowerDoc();
if (towerDoc)
mBuildDay = towerDoc->GetNow()->CalcTotalDays();
else
mBuildDay = 0;
mInMoneyIndex = (GetEquipDef()->GetNumOfInMoney() > 1) ? (GetEquipDef()->GetNumOfInMoney() / 2) : 0;
SetUsed(true);
return true;
}
/*virtual*/ void T2Equip::SetUsed(BOOL inUsed) {
if (!inUsed && mCEArray) {
delete mCEArray;
mCEArray = NULL;
}
T2HaveOutViewObject::SetUsed(inUsed);
}
int T2Equip::DaysSinceBuilt(const T2TowerDoc* towerDoc) const {
return towerDoc->GetNow()->CalcLapseDays(mBuildDay);
}
void T2Equip::SetEquipArea(const RECT& rect) {
mArea = rect;
}
/*virtual*/ int T2Equip::GetOutMoney() const {
int cost = 0;
cost = GetEquipDef()->GetOutMoney(0);
return cost;
}
/*virtual*/ int T2Equip::GetInMoney() const {
int cost = 0;
cost = GetEquipDef()->GetInMoney(mInMoneyIndex);
return cost;
}
/*virtual*/ PARTCODE T2Equip::GetClickPart(T2TowerDoc* towerDoc, CPoint pt, int* val) {
return GetEquipDef()->GetPartFromPoint(towerDoc, this, pt, val);
}
/*virtual*/ PROCCODE T2Equip::DoDestruct(T2TowerDoc*, POINT, RECT&) {
if (mCEArray)
delete mCEArray;
return ProcCode_2;
}
void T2Equip::InsertCEID(int a, int b) {
if (mCEArray)
((T2RouteCEArray *) mCEArray)->Insert(a, b);
}
void T2Equip::RemoveCEID(int id) {
if (mCEArray)
mCEArray->Remove(&id);
}
void T2Equip::ReplaceCEID(unsigned int oldID, unsigned int newID) {
if (mCEArray)
mCEArray->ReplaceID(oldID, newID);
}
/*virtual*/ PARTCODE T2Equip::GetPartFromPoint(T2TowerDoc* towerDoc, POINT pt, int* val) {
return GetEquipDef()->GetPartFromPoint(towerDoc, this, pt, val);
}
/*virtual*/ void T2Equip::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) {
T2Object::LoadSelf(archive, towerDoc);
if (IsUsed()) {
#pragma var_order(uc, s, us)
unsigned short us;
short s;
unsigned char uc;
archive >> us;
mEquipID = us;
archive.ReadSRect(mArea);
archive >> s;
mEquipType = s;
archive >> s;
mDrawMode = s;
archive >> uc;
mPatIndex = uc;
archive >> s;
m44 = s;
archive >> s;
mInMoneyIndex = s;
archive >> s;
m48 = s;
archive >> mBuildDay;
mCEArray = (T2RouteCEArray *) T2CrossEquipArray::ReadCEArray(archive);
archive >> mValiation;
}
}
/*virtual*/ void T2Equip::SaveSelf(T2Archive& archive) {
T2Object::SaveSelf(archive);
if (IsUsed()) {
#pragma var_order(uc, s, us)
unsigned short us;
short s;
unsigned char uc;
us = mEquipID;
archive << us;
archive.WriteSRect(mArea);
s = mEquipType;
archive << s;
s = mDrawMode;
archive << s;
uc = mPatIndex;
archive << uc;
s = m44;
archive << s;
s = mInMoneyIndex;
archive << s;
s = m48;
archive << s;
archive << mBuildDay;
T2CrossEquipArray::WriteCEArray(mCEArray, archive);
archive << mValiation;
}
}
/*virtual*/ T2InfoDialog* T2Equip::ShowInfoDialog(T2TowerDoc* towerDoc) {
return GetEquipDef()->ShowInfoDialog(towerDoc, this);
}
/*virtual*/ void T2Equip::PlaySound(T2TowerDoc* inDoc, int id, unsigned int inMask, unsigned int inFlags) const {
if (inDoc->IsRectInView(mArea)) {
T2EquipDef *equipDef = GetEquipDef();
T2SoundPlayer *soundPlayer = inDoc->GetSoundPlayer();
if (equipDef && soundPlayer) {
CRect theArea;
GetEquipArea(theArea);
CPoint pt = theArea.CenterPoint();
CString theName = equipDef->CalcSoundID(id);
soundPlayer->Play(
theName,
inMask,
inFlags,
&pt,
PlayMode_0,
100
);
}
}
}
/*virtual*/ void T2Equip::DrawHitMask(T2TowerDoc* towerDoc) {
m58 = true;
if (mToolDef->DrawHitMask(towerDoc, this) == ProcCode_0) {
RECT rect;
GetEquipArea(rect);
Draw(towerDoc, rect);
}
m58 = false;
}
inline void T2Equip::GetTypicalName(CString& outStr) const {
GetEquipDef()->GetName(outStr, GetValiation());
}
|