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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
#include "StdAfx.h"
#include "CResFile.h"
#include "T2BitImage.h"
#include "T2FloorInfo.h"
#include "T2ImageObj.h"
#include "T2PaletteAnime.h"
#include "T2PeopleAnimeDef.h"
#include "T2SubPlugin.h"
#include "T2Tenant.h"
#include "T2TenantDef.h"
#include "T2TenantMemberTableDef.h"
#include "T2TenantPlugin.h"
#include "../T2TowerDoc.h"
#include "../T2TowerMainView.h"
#include "T2TowerMessage.h"
#include "T2WorldDef.h"
#include "UT2Coordinate.h"
T2TenantDef::T2TenantDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2TenantPlugin* plugin)
: T2EquipDef(type, specifier, resFile, worldDef, plugin)
{
DWORD tmp;
*resFile >> mRegistID;
*resFile >> mDownFlag;
*resFile >> mNumOfKind;
*resFile >> mNumOfPattern;
*resFile >> mBelongCapacity;
*resFile >> mSenseOfNoise;
*resFile >> mEntranceV;
*resFile >> mEntranceH;
*resFile >> mExitV;
*resFile >> mExitH;
*resFile >> mOpenTime;
*resFile >> mCloseTime;
*resFile >> mBindTime;
*resFile >> mMaxBuildCount;
*resFile >> tmp;
*resFile >> tmp;
*resFile >> tmp;
*resFile >> m184;
mEmployeeTableDef = NULL;
mCustomerTableDef = NULL;
mPeopleAnimeDef = NULL;
CResFile subResFile;
if (subResFile.OpenResource(mModuleHandle, 1, 'TmDf')) {
mEmployeeTableDef = new T2TenantMemberTableDef(mModuleHandle, &subResFile, 0.0f);
subResFile.End();
}
MakeCustomerTableDef(2, NULL);
if (subResFile.OpenResource(mModuleHandle, 1, 'PaDf')) {
mPeopleAnimeDef = new T2PeopleAnimeDef(subResFile);
subResFile.End();
}
m180 = 0;
mDrawRoof = (m154 == 0);
mDrawFloor = true;
mIsLoaded = true;
}
/*virtual*/ T2TenantDef::~T2TenantDef() {
if (mEmployeeTableDef)
delete mEmployeeTableDef;
if (mCustomerTableDef)
delete mCustomerTableDef;
if (mPeopleAnimeDef)
delete mPeopleAnimeDef;
}
/*virtual*/ void T2TenantDef::GetName(CString& outStr) {
outStr = "TENANT";
}
/*virtual*/ BOOL T2TenantDef::InitObject(T2Object* obj) {
T2EquipDef::InitObject(obj);
((T2Equip *) obj)->mDrawMode = DrawMode2;
return true;
}
/*virtual*/ void T2TenantDef::DrawProc(T2HaveOutViewObject* obj, const RECT& inRect, T2TowerDoc* towerDoc) const {
T2Tenant *tenant = (T2Tenant *) obj;
RECT tenantRect = inRect;
int objID;
int pattern;
BOOL includeRoofAndFloor;
if (towerDoc->mViewMode != 1) {
objID = 100;
includeRoofAndFloor = true;
pattern = 0;
pattern += tenant->mValiation * 1000;
pattern += mHeight * 100;
pattern += tenant->GetPatIndex();
} else {
objID = 101;
includeRoofAndFloor = false;
pattern = (towerDoc->mWorldDef->GetOutViewKind() + 1) * 10000;
pattern += tenant->mValiation * 1000;
pattern += mHeight * 100;
if (tenant->IsFire())
pattern += 2;
else if (towerDoc->GetPaletteAnime()->IsSnow())
pattern += 1;
}
UT2Coordinate::UnitToQD(tenantRect, towerDoc->GetZoomLevel(), !includeRoofAndFloor);
int objectIndex = mImageObj->FindObject(objID, pattern);
if (objectIndex >= 0) {
mImageObj->DrawObject(towerDoc->GetImage(), objectIndex, tenantRect, towerDoc->GetZoomLevel());
} else if (tenant->m58) {
towerDoc->GetImage()->FillRect(tenantRect, 1);
} else {
CString err;
#ifdef _MSC_VER
err.Format("Undefined Image %d %s", pattern, mStr48);
#else
err.Format("Undefined Image %d %s", pattern, &mStr48);
#endif
MessageBox(NULL, mStr48, err, MB_OK);
}
}
/*virtual*/ int T2TenantDef::DrawData(int y) {
return y;
}
/*virtual*/ void T2TenantDef::DrawPeople(T2TowerDoc* towerDoc, T2Equip* equip) {
if (towerDoc->mViewMode != 1)
T2EquipDef::DrawPeople(towerDoc, equip);
}
/*virtual*/ int T2TenantDef::DrawAttribute(int y) {
return y;
}
/*virtual*/ unsigned int T2TenantDef::IdleProc(T2HaveOutViewObject* obj, T2TowerDoc* towerDoc) {
T2Equip *theEquip = (T2Equip *) obj;
int status = theEquip->GetStatus();
unsigned int result = 0;
if (status < kTenantStatus10) {
if (status <= kTenantStatus2 || status == kTenantStatus9)
result = 1;
status++;
theEquip->SetStatus(status);
if (status == kTenantStatus10) {
BuildFinish(towerDoc, theEquip);
towerDoc->mTowerMainView->InvalUnitRect(theEquip->mArea, true);
}
}
T2Tenant *theTenant = (T2Tenant *) theEquip;
status = theTenant->GetStatus();
if (status >= kTenantStatus9 && ChangeStatusOnIdle(towerDoc, theTenant, status)) {
if (status == kTenantStatus9)
theTenant->SetDrawMode(DrawMode2);
else
theTenant->SetDrawMode(DrawMode1);
}
if (theTenant->GetDrawMode() != DrawMode0)
towerDoc->mTowerMainView->InvalUnitRect(theTenant->mArea, false);
return result;
}
/*virtual*/ BOOL T2TenantDef::ChangeStatusOnIdle(T2TowerDoc*, T2Tenant*, int) {
return false;
}
/*virtual*/ AREACHECKCODE T2TenantDef::AreaCheck(T2TowerDoc* towerDoc, RECT& rect, unsigned int a, BOOL inShowError) {
if (GetCategory() != 100 && rect.top <= towerDoc->mWorldDef->mTopFloorLine) {
if (inShowError) {
// EN: Only Final item can be placed on the top floor of building.
towerDoc->GetTowerMessage()->BuildErr(68, NULL);
}
return AreaCheckCode_0;
}
if (rect.bottom > towerDoc->mWorldDef->mBottomFloorLine) {
if (inShowError) {
// EN: Can not place items beyond the edges of the floor below.
towerDoc->GetTowerMessage()->BuildErr(2, NULL);
}
return AreaCheckCode_0;
}
return AreaCheckCode_1;
}
/*virtual*/ int T2TenantDef::CalcPayment(T2TowerDoc* towerDoc, RECT& rect, unsigned int variation) {
int result = 0;
if (IsFloor()) {
for (int y = rect.top; y < rect.bottom; y++) {
for (int x = rect.left; x < rect.right; x++) {
if (!towerDoc->mFloorInfo->GetTenant(y, x))
result += mPrice[variation];
}
}
} else {
result = mPrice[variation];
}
return result;
}
/*virtual*/ void T2TenantDef::EnterTenant(T2TowerDoc*, T2Tenant*, T2People*) {
}
/*virtual*/ void T2TenantDef::LeaveTenant(T2TowerDoc*, T2Tenant*, T2People*) {
}
/*virtual*/ void T2TenantDef::BuildStartProc(T2TowerDoc*, T2Tenant*) {
}
/*virtual*/ void T2TenantDef::DoPeopleAnimation(T2TowerDoc*, T2Tenant*) {
}
/*virtual*/ BOOL T2TenantDef::GetQTMovieName(T2Tenant*, CString& outStr) {
outStr = "";
return outStr != NULL;
}
void T2TenantDef::SetCustomerTable(T2SubPlugin* subPlugin) {
if (subPlugin) {
int prevBindTime = mBindTime;
mBindTime = 1;
int resID = subPlugin->DupCustomerTableDefRes();
MakeCustomerTableDef(resID, subPlugin->mSpecifier.mPath);
mBindTime = prevBindTime;
}
}
void T2TenantDef::MakeCustomerTableDef(int resID, const char* path) {
if (mCustomerTableDef)
delete mCustomerTableDef;
mCustomerTableDef = NULL;
if (resID) {
CResFile resFile;
if (path) {
if (resFile.OpenResource(path, resID, 'TMDF')) {
mCustomerTableDef = new T2TenantMemberTableDef(path, &resFile, CalcNumOfCustomerUnit());
resFile.End();
}
} else {
if (resFile.OpenResource(mModuleHandle, resID, 'TmDf')) {
mCustomerTableDef = new T2TenantMemberTableDef(mModuleHandle, &resFile, CalcNumOfCustomerUnit());
resFile.End();
}
}
}
}
float T2TenantDef::CalcNumOfCustomerUnit() {
float result = 0.0f;
if (mBindTime > 0 && mCapacity > 0) {
if (mBindTime > 8)
result = (mCapacity * 8.0f) / mBindTime;
else
result = mCapacity;
}
return result;
}
/*virtual*/ BOOL T2TenantDef::EmergencyProc(T2TowerDoc* towerDoc, T2Equip* equip) {
((T2Tenant *) equip)->PushOutAll(towerDoc);
((T2Tenant *) equip)->ClearReserveCount();
((T2Tenant *) equip)->Bind();
return true;
}
/*virtual*/ int T2TenantDef::CalcMentenanceCostProc(const T2HaveOutViewObject* obj) const {
int cost = 0;
T2ToolDef *def = obj->GetToolDef();
if (def->IsSetAttribute(kToolAttrNormalMenteCost)) {
if (((T2TenantDef *) def)->IsValiableLength()) {
RECT rect;
((T2Equip *) obj)->GetEquipArea(rect);
int width = rect.right - rect.left;
cost = obj->GetToolDef()->GetOutMoney(obj->GetValiation());
cost *= width;
} else {
cost = T2ToolDef::CalcMentenanceCostProc(obj);
}
}
return cost;
}
|