summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2Name.cpp
blob: 078071e8eaa2aa3ef93b612d53478d72cbcb2685 (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
#include "T2Archive.h"
#include "T2FloorInfo.h"
#include "T2Mover.h"
#include "T2MoverModule.h"
#include "T2Name.h"
#include "T2People.h"
#include "T2PeopleArrayList.h"
#include "T2Tenant.h"
#include "T2TowerDoc.h"
#include "UT2Utils.h"

T2Name::T2Name() {
    mName.Empty();
    mType = 0;
    mID = 0;
    mFavorite = false;
}

T2Name::T2Name(T2Archive& archive) {
#pragma var_order(valUChar, valUShort, valInt, str)
    unsigned short valUShort;
    unsigned char valUChar;
    int valInt;
    char str[4];

    archive >> valUShort;
    mType = valUShort;

    archive >> mID;

    archive >> valUChar;
    mFavorite = (valUChar != 0);

    archive >> valInt;

    if (valInt == 2 || valInt == 4) {
        archive >> valUChar;
        if ((valInt - 1) != valUChar) {
            valInt--;
            str[valInt] = 0;
            valInt--;
            str[valInt] = valUChar;

            while (valInt > 0) {
                valInt--;
                archive >> str[valInt];
            }

            char tmp;
            archive >> tmp;
        } else {
            int i;
            for (i = 0; i < (valInt - 1); i++)
                archive >> str[i];
            str[i] = 0;
        }
        mName = str;
    } else {
        archive.ReadPStr(mName);
    }
}

T2Name::T2Name(CString str, T2Tenant* tenant, BOOL favorite) {
    mName = str;
    mType = kTenantNameType;
    mID = tenant->GetEquipID();
    mFavorite = favorite;
}

T2Name::T2Name(CString str, T2People* people, BOOL favorite) {
    mName = str;
    mType = kPeopleNameType;
    mID = people->mMatterID;
    mFavorite = favorite;
}

T2Name::T2Name(CString str, T2Mover* mover, BOOL favorite) {
    mName = str;
    mType = kMoverNameType;
    mID = mover->GetEquipID();
    mFavorite = favorite;
}

T2Name::T2Name(CString str, T2MoverModule* moverModule, BOOL favorite) {
    mName = str;
    mType = kMoverModuleNameType;
    mID = moverModule->GetModuleID();
    mFavorite = favorite;
}

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

short T2Name::GetName(CString& outName, unsigned int& outID) {
    if (!mName.IsEmpty()) {
        outName = mName;
        outID = mID;
    }
    return mType;
}

void T2Name::SetName(CString name) {
    mName = name;
}

void T2Name::MakeFullName(T2TowerDoc* inDoc, CString& outStr) {
    if (mName != NULL) {
        switch (GetType()) {
            case kTenantNameType:
                if (inDoc && inDoc->GetFloorInfo()) {
                    T2FloorInfo *theFloorInfo = inDoc->GetFloorInfo();
                    T2Tenant *theTenant = theFloorInfo->GetTenant(GetID());
                    if (theTenant) {
                        CString str;
                        int theRoomNumber = theTenant->GetRoomNumber(theFloorInfo);
                        UT2Utils::GetRoomNumberString(theRoomNumber, str);
                        str += "\x8D\x86\x8E\xBA"; // "号室"
                        outStr = str + mName;
                    }
                }
                break;

            case kPeopleNameType:
                if (inDoc && inDoc->GetFloorInfo() && inDoc->mPeopleArrayList) {
                    T2People *thePeople = inDoc->mPeopleArrayList->FindPeople(GetID());
                    if (thePeople) {
                        T2FloorInfo *theFloorInfo = inDoc->GetFloorInfo();
                        int theTenantID = (thePeople->GetWorkTenant() > 1) ? thePeople->GetWorkTenant() : (thePeople->GetHomeTenant() > 1) ? thePeople->GetHomeTenant() : 1;

                        CString str;
                        T2Tenant *theTenant = theFloorInfo->GetTenant(theTenantID);
                        if (theTenant) {
                            int theRoomNumber = theTenant->GetRoomNumber(theFloorInfo);
                            UT2Utils::GetRoomNumberString(theRoomNumber, str);
                            str += "\x8D\x86\x8E\xBA"; // "号室"
                        } else {
                            str = "\x83\x65\x83\x69\x83\x93\x83\x67\x82\xC8\x82\xB5"; // "テナントなし"
                        }
                        outStr = str + mName;
                    }
                }
        }
    }
}

BOOL T2Name::operator==(const CString& str) const {
    BOOL result = false;

    if (!mName.IsEmpty())
        result = (str.Compare(mName) == 0);

    return result;
}

void T2Name::Write(T2Archive& archive) const {
    archive << (unsigned short) mType;
    archive << mID;

    unsigned char valUChar = mFavorite ? 1 : 0;
    archive << valUChar;

    int len = strlen(mName) + 1;
    archive << len;
    archive.WritePStr(mName);
}