summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2TenantMemberTableDef.cpp
blob: 10c0b820cbdc357f71aa6387499abd5b533e1a3b (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
#include "CResFile.h"
#include "T2DateTime.h"
#include "T2DayParamDef.h"
#include "T2PlaceParamDef.h"
#include "T2TenantMemberDef.h"
#include "T2TenantMemberTableDef.h"
#include "T2TowerDoc.h"
#include "UT2Utils.h"

T2TenantMemberTableDef::T2TenantMemberTableDef(HINSTANCE instance, CResFile* resFile, float f) {
    Initialize();

    *resFile >> mEconoType;
    *resFile >> mSpecialFlag;

    int resID;

    *resFile >> resID;
    if (resID)
        mDayParamDef = MakeDayParamDef(instance, resID);

    try {
        *resFile >> resID;
        if (resID)
            mPlaceParamDef = MakePlaceParamDef(instance, resID);

        *resFile >> mNumOfElem;
        if (mNumOfElem > 0) {
            mElem = new T2TenantMemberDef[mNumOfElem];
            for (int i = 0; i < mNumOfElem; i++)
                mElem[i].Initialize(resFile, f);
        }
    } catch (CException &exc) {
        delete this;
    }
}

T2TenantMemberTableDef::T2TenantMemberTableDef(const char* path, CResFile* resFile, float f) {
    Initialize();

    *resFile >> mEconoType;
    *resFile >> mSpecialFlag;

    int resID;

    *resFile >> resID;
    if (resID)
        mDayParamDef = MakeDayParamDef(path, resID);

    try {
        *resFile >> resID;
        if (resID)
            mPlaceParamDef = MakePlaceParamDef(path, resID);

        *resFile >> mNumOfElem;
        if (mNumOfElem > 0) {
            mElem = new T2TenantMemberDef[mNumOfElem];
            for (int i = 0; i < mNumOfElem; i++)
                mElem[i].Initialize(resFile, f);
        }
    } catch (CException &exc) {
        delete this;
    }
}

/*virtual*/ T2TenantMemberTableDef::~T2TenantMemberTableDef() {
    if (mDayParamDef)
        delete mDayParamDef;
    if (mPlaceParamDef)
        delete mPlaceParamDef;
    delete[] mElem;
}

void T2TenantMemberTableDef::Initialize() {
    mEconoType = 0;
    mSpecialFlag = 0;
    mDayParamDef = NULL;
    mPlaceParamDef = NULL;
    mNumOfElem = 0;
    mElem = NULL;
}

int T2TenantMemberTableDef::GetEconoType() const {
    int type = mEconoType;
    if (mEconoType != -1)
        type &= ~0x10;
    return type;
}

BOOL T2TenantMemberTableDef::IsCheckOnlyFirstEconoType() const {
    BOOL result = false;
    if (mEconoType != -1)
        result = (mEconoType & 0x10) != 0;
    return result;
}

T2TenantMemberDef* T2TenantMemberTableDef::GetElem(int i) const {
    T2TenantMemberDef *result = NULL;
    if (i >= 0 && i < mNumOfElem)
        result = &mElem[i];
    return result;
}

int T2TenantMemberTableDef::GetScore(T2PlaceParamDef::EPlace place) const {
    int result = 0;
    if (mPlaceParamDef) {
        result = mPlaceParamDef->GetScore(place);
    } else if (place == T2PlaceParamDef::Place_0) {
        result = 1000;
    }
    return result;
}

BOOL T2TenantMemberTableDef::IsCollectFromFloor() const {
    BOOL result = false;
    if (mPlaceParamDef) {
        float rate = mPlaceParamDef->GetRate(T2PlaceParamDef::Place_2);
        if (UT2Utils::Float2Int(rate) > 0)
            result = true;
    }
    return result;
}

BOOL T2TenantMemberTableDef::IsCollectFromPool(T2TowerDoc* towerDoc) const {
    BOOL result = true;

    if (mPlaceParamDef) {
        float theRate = mPlaceParamDef->GetRate(T2PlaceParamDef::Place_0);
        if (UT2Utils::Float2Int(theRate) == 0)
            result = false;
    }

    if (result && mDayParamDef) {
        T2DayParamDef::EDay theDay = T2DayParamDef::Day_0;
        T2DayParamDef::EWhether theWhether = T2DayParamDef::Whether_0;

        T2DateTime *theNow = towerDoc->towerDoc_vf120();
        if (theNow->IsHoliday(towerDoc))
            theDay = T2DayParamDef::Day_1;

        float theRate = mDayParamDef->GetRate(theDay, theWhether);
        if (UT2Utils::Float2Int(theRate) == 0)
            result = false;
    }

    return result;
}

BOOL T2TenantMemberTableDef::IsCollectFromTenant() const {
    BOOL result = false;
    if (mPlaceParamDef) {
        float rate = mPlaceParamDef->GetRate(T2PlaceParamDef::Place_1);
        if (UT2Utils::Float2Int(rate) > 0)
            result = true;
    }
    return result;
}

T2DayParamDef* T2TenantMemberTableDef::MakeDayParamDef(HINSTANCE instance, int resID) {
    T2DayParamDef *theDef = NULL;

    CResFile resFile;
    if (resFile.OpenResource(instance, resID, 'DpDf')) {
        theDef = new T2DayParamDef(resFile);
        resFile.End();
    }

    return theDef;
}

T2DayParamDef* T2TenantMemberTableDef::MakeDayParamDef(const char* path, int resID) {
    T2DayParamDef *theDef = NULL;

    CResFile resFile;
    if (resFile.OpenResource(path, resID, 'DPDF')) {
        theDef = new T2DayParamDef(resFile);
        resFile.End();
    }

    return theDef;
}

T2PlaceParamDef* T2TenantMemberTableDef::MakePlaceParamDef(HINSTANCE instance, int resID) {
    T2PlaceParamDef *theDef = NULL;

    CResFile resFile;
    if (resFile.OpenResource(instance, resID, 'PlDf')) {
        theDef = new T2PlaceParamDef(resFile);
        resFile.End();
    }

    return theDef;
}

T2PlaceParamDef* T2TenantMemberTableDef::MakePlaceParamDef(const char* path, int resID) {
    T2PlaceParamDef *theDef = NULL;

    CResFile resFile;
    if (resFile.OpenResource(path, resID, 'PLDF')) {
        theDef = new T2PlaceParamDef(resFile);
        resFile.End();
    }

    return theDef;
}