summaryrefslogtreecommitdiff
path: root/src/Plugins/Common/StdTenantInfoDialog.cpp
blob: 33276743c494f5c14162716de59a8f4dfdca7d9d (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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#include "StdAfx.h"
#include "StdTenantInfoDialog.h"
#include "../../T2DLL/T2DlgItemCustomerGage.h"
#include "../../T2DLL/T2DlgItemPeopleView.h"
#include "../../T2DLL/T2DlgItemProfitsGage.h"
#include "../../T2DLL/T2DlgItemText.h"
#include "../../T2DLL/T2FloorInfo.h"
#include "../../T2DLL/T2Maru_Reggae.h"
#include "../../T2DLL/T2Mover.h"
#include "../../T2DLL/T2Name.h"
#include "../../T2DLL/T2NameList.h"
#include "../../T2DLL/T2People.h"
#include "../../T2DLL/T2PeopleLinkIterator.h"
#include "../../T2DLL/T2PeoplePtrList.h"
#include "../../T2DLL/T2RouteCEArray.h"
#include "../../T2DLL/T2RouteNavigator.h"
#include "../../T2DLL/T2Tenant.h"
#include "../../T2DLL/T2TenantDef.h"
#include "../../T2TowerDoc.h"
#include "../../T2DLL/T2WorldDef.h"
#include "../../T2DLL/UT2Coordinate.h"
#include "../../T2DLL/UT2Utils.h"

StdTenantInfoDialog::StdTenantInfoDialog(T2Tenant *inTenant)
    : T2TenantInfoDialog(inTenant)
    , mNumCommentLines(0)
{
    mIsFavorited = 0;
}

/*virtual*/ StdTenantInfoDialog::~StdTenantInfoDialog() {
}

/*virtual*/ BOOL StdTenantInfoDialog::OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) {
    WORD code = HIWORD(inWParam);
    WORD id = LOWORD(inWParam);

    if (code == -1 && id == 7090) { // favourite button
        GetT2DlgItem(7090)->EnableWindow(false);
        mIsFavorited = 1;

        CString name;
        T2DlgItem *nameField = (T2DlgItem *) GetDlgItem(7003);
        nameField->GetDescriptor(name);

        if (name == "")
            nameField->SetDescriptor(mTenantName);
    }

    return false;
}

/*virtual*/ void StdTenantInfoDialog::OnT2Create() {
    if (!GetDocument() || !GetDocument()->mWorldDef)
        return;

    CString text;
    T2DlgItem *item = NULL;

    // ID
    item = GetT2DlgItem(7001);
    if (item) {
        int roomNumber = GetTenant()->GetRoomNumber(GetDocument()->mFloorInfo);
        UT2Utils::GetRoomNumberString(roomNumber, text);
        item->SetDescriptor(text);
    }

    // Name
    item = GetT2DlgItem(7003);
    if (item) {
        T2Name *theName = GetDocument()->mNameDB->Search(GetTenant());
        if (theName) {
            unsigned int id;
            theName->GetName(mTenantName, id);
        } else {
            GetTenant()->GetTypicalName(mTenantName);
        }
        item->SetDescriptor(mTenantName);
    }

    // Image
    item = GetT2DlgItem(7004);
    if (item)
        UpdateViewOfTenant(item);

    GenerateStatus();

    if (!GetTenant()->IsFire()) {
        // Hours
        item = GetT2DlgItem(7021);
        if (item) {
            int theOpenTime = GetTenant()->GetOpenTime();
            int theCloseTime = GetTenant()->GetCloseTime();
            text.Format(
                "%d:%02d\x81\x60%d:%02d",
                theOpenTime / 60, theOpenTime % 60,
                theCloseTime / 60, theCloseTime % 60
            );
            item->SetDescriptor(text);
        }

        item = GetT2DlgItem(7022);
        if (item) {
            text.Format("%d", GetDocument()->mWorldDef->ExchangeMoney(GetTenant()->GetInMoney()));
            item->SetDescriptor(text);
        }

        item = GetT2DlgItem(7023);
        if (item) {
            item->GetDescriptor(text);
            text += GetDocument()->mWorldDef->GetMoneyUnit();
            item->SetDescriptor(text);
        }

        // Customers
        item = GetT2DlgItem(7030);
        if (item) {
            text.Format("%d", GetTenant()->GetTotalCustomer());
            item->SetDescriptor(text);
        }

        item = GetT2DlgItem(7031);
        if (item) {
            text.Format("%d", GetDocument()->mWorldDef->ExchangeMoney(GetTenant()->GetInMoney() * 100));
            item->SetDescriptor(text);
        }

        item = GetT2DlgItem(7032);
        if (item) {
            item->GetDescriptor(text);
            text += GetDocument()->mWorldDef->GetMoneyUnit();
            item->SetDescriptor(text);
        }

        item = GetT2DlgItem(7042);
        if (item) {
            T2DlgItemProfitsGage *profitsGage = (T2DlgItemProfitsGage *) item;
            profitsGage->SetTenant(GetTenant());
        }

        item = GetT2DlgItem(7043);
        if (item) {
            item->GetDescriptor(text);
            text += GetDocument()->mWorldDef->GetMoneyUnit();
            item->SetDescriptor(text);
        }

        T2PeoplePtrList *theBelongList = GetTenant()->GetBelongList();
        item = GetT2DlgItem(7060);
        if (theBelongList && item) {
            T2DlgItemPeopleView *peopleView = (T2DlgItemPeopleView *) item;
            peopleView->StartAdd();

            T2People *thePeople;
            LArrayIterator iterator(*theBelongList);

            while (iterator.Next(&thePeople)) {
                if (thePeople && thePeople->GetCurTenantID() == GetTenant()->GetEquipID())
                    peopleView->AddOne(thePeople);
            }

            peopleView->FinishAdd();
        }

        T2People *theFirstPeople = GetTenant()->GetFirstPeople();
        item = GetT2DlgItem(7061);
        if (theFirstPeople && item) {
            T2DlgItemPeopleView *thePeopleView = (T2DlgItemPeopleView *) item;
            thePeopleView->StartAdd();

            T2People *thePeople;
            T2PeopleLinkIterator theIterator(theFirstPeople);

            while (theIterator.Next(&thePeople)) {
                if (
                    thePeople &&
                    thePeople->GetCurTenantID() == GetTenant()->GetEquipID() &&
                    thePeople->GetWorkTenant() != GetTenant()->GetEquipID()
                    )
                    thePeopleView->AddOne(thePeople);
            }

            thePeopleView->FinishAdd();
        }

        item = GetT2DlgItem(7042);
        if (item) {
            T2DlgItemCustomerGage *customerGage = (T2DlgItemCustomerGage *) item;
            customerGage->SetTenant(GetTenant());
        }
    }

    T2Name *theExistingName = mTowerDoc->mNameDB->Search(GetTenant());
    if (theExistingName)
        GetT2DlgItem(7090)->EnableWindow(false);

    GenerateComments();
}

/*virtual*/ void StdTenantInfoDialog::OnT2Destroy() {
    // empty
}

/*virtual*/ void StdTenantInfoDialog::AppendLine(const CString &inStr) {
    if (mNumCommentLines < 4) {
        mNumCommentLines++;

        T2DlgItem *theItem = GetT2DlgItem(7080);
        if (theItem) {
            CString str;
            theItem->GetDescriptor(str);
            str += '\r';
            theItem->SetDescriptor(str);
        }
    }
}

/*virtual*/ void StdTenantInfoDialog::AppendComment(unsigned int inID, T2Equip *inEquip) {
    CString str, comment;

    if (inEquip)
        inEquip->GetTypicalName(str);

    GetCommentString(inID, comment);
    str += comment;
    AppendLine(str);
}

/*virtual*/ void StdTenantInfoDialog::UpdateViewOfTenant(T2DlgItem *inItem) {
    T2TenantDef *theTenantDef = GetTenantDef();
    T2Tenant *theTenant = GetTenant();
    CString str;

    if (theTenantDef && theTenant) {
        if (theTenant->IsFire()) {
            inItem->SetDescriptor("Rubble");
            inItem->SetValue(0);
        } else {
            inItem->SetValue(
                GetTenant()->GetValiation() * 1000 +
                theTenantDef->mHeight * 100 +
                GetTenant()->GetPatIndex()
                );
        }

        CRect theDialogArea, theTenantRect;
        GetClientRect(theDialogArea);
        theTenant->GetEquipArea(theTenantRect);

        CSize theSize = theTenantRect.Size();

        int multiplier = (theSize.cy == 1) ? 2 : 1;
        int theHeight = ((theSize.cy * UT2Coordinate::UnitVSize(0)) - UT2Coordinate::CalcRoofThick(0) - UT2Coordinate::CalcFloorThick(0)) * multiplier;
        int theWidth = min(theSize.cx * UT2Coordinate::UnitHSize(0) * multiplier, theDialogArea.Width() - 26);

        CRect rect(0, 0, theWidth, theHeight);
        inItem->MapWindowPoints(inItem->GetParent(), rect);
        inItem->MoveWindow(rect);

        T2DlgItem *theBox = GetT2DlgItem(7504);
        if (theBox) {
            rect.InflateRect(1, 1);
            theBox->MoveWindow(rect);
        }
    }
}

/*virtual*/ BOOL StdTenantInfoDialog::GenerateStatusProc(CString &outStr, BOOL &outIsBad) {
    return false;
}

void StdTenantInfoDialog::GenerateStatus() {
    T2DlgItemText *theTextItem = (T2DlgItemText *) GetT2DlgItem(7010);
    if (theTextItem) {
        CString str;
        BOOL bad = false;

        if (!GetDocument()->GetRouteNavi()->IsConnectRouteFromLobby(GetTenant()->GetEntrancePt())) {
            // "ロビー未接続" - Lobby not connected
            str = "\x83\x8D\x83\x72\x81\x5B\x96\xA2\x90\xDA\x91\xB1";
            bad = true;
        } else if (0) {
            // "停電" - Blackout
            str = "\x92\xE2\x93\x64";
            bad = true;
        } else if (GetTenant()->IsFire()) {
            // "火災の焼け跡" - fire scars
            str = "\x89\xCE\x8D\xD0\x82\xCC\x8F\xC4\x82\xAF\x90\xD5";
            bad = true;
        } else if (GenerateStatusProc(str, bad)) {
            // use it as-is
        } else {
            // "稼働中" - in operation
            str = "\x89\xD2\x93\xAD\x92\x86";
        }

        theTextItem->SetDescriptor(str);
        if (bad)
            theTextItem->SetTextColor(PALETTERGB(255, 0, 0));
    }
}

/*virtual*/ void StdTenantInfoDialog::GenerateComments() {
    ClearComment();

    if (!GetDocument()->GetRouteNavi()->IsConnectRouteFromLobby(GetTenant()->GetEntrancePt())) {
        // EN: Need a more direct route to destination.
        AppendComment(2);
    } else if (GetTenant()->GetInMoney() != 0 && GetTenant()->GetBelongCapacity() != 0) {
        T2Tenant *theEntranceFloor = GetDocument()->mFloorInfo->GetTenant(GetTenant()->GetEntranceFloorID());
#line 380
        _ASSERT(theEntranceFloor != NULL);

        POINT entrancePt = GetTenant()->GetEntrancePt();
        T2Mover *nearMover = NULL;
        unsigned int nearMoverScore = 0xFFFFFFFF;

        unsigned int theID = 0;
        LArrayIterator iterator(*theEntranceFloor->GetCEArray());
        while (iterator.Next(&theID)) {
            T2Mover *theMover = GetDocument()->mFloorInfo->GetMover(theID);
            if (!theMover || !theMover->IsSetAttribute(kMoverAttrRoutingTable0))
                continue;

            CRect moverArea;
            theMover->GetEquipArea(moverArea);

            int h = (moverArea.left + moverArea.right) / 2;
            int theDistance = abs(h - entrancePt.x);
            if (theDistance < nearMoverScore) {
                nearMover = theMover;
                nearMoverScore = theDistance;
            }
        }

        if (nearMover) {
            if (nearMoverScore >= 160) {
                if (nearMover->IsStair()) {
                    // EN: is far away.
                    AppendComment(6, nearMover);
                } else {
                    // EN: Elevator is far away.
                    AppendComment(4);
                }
            } else if (nearMoverScore >= 96) {
                if (nearMover->IsStair()) {
                    // EN: is a bit far away.
                    AppendComment(5, nearMover);
                } else {
                    // EN: Elevator is far away.
                    AppendComment(4);
                }
            }
        }
    }

    T2Maru_Reggae *theReggae = GetDocument()->mWorldDef->GetReggae();
    if (theReggae && theReggae->GetVisitTenant() == GetTenant()) {
        // EN: Uncle Reggae is noisy and annoying.
        AppendComment(8);
    }
}

/*virtual*/ void StdTenantInfoDialog::OnT2OK() {
    CString str;
    ((T2DlgItem *) GetDlgItem(7003))->GetDescriptor(str);
    if (str == "")
        str = mTenantName;

    if (mTenantName != str || mIsFavorited == 1) {
        T2Name *theName = mTowerDoc->mNameDB->Search(GetTenant());
        if (theName) {
            theName->SetName(str);
        } else {
            T2Name *newName = new T2Name(str, GetTenant(), false);
            mTowerDoc->mNameDB->Add(newName);
        }
    }
}

/*virtual*/ void StdTenantInfoDialog::OnT2Cancel() {
    // empty
}

void StdTenantInfoDialog::ClearComment() {
    T2DlgItem *theItem = GetT2DlgItem(7080);
    if (theItem)
        theItem->SetDescriptor("");
    mNumCommentLines = 0;
}