summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2PeopleTimeZoneList.cpp
blob: 1b3578adcd554471ccca11d0e42ec7f776802651 (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
#include "CResFile.h"
#include "T2Archive.h"
#include "T2PeopleTimeZoneList.h"
#include "T2PeopleType.h"
#include "T2PeopleTypeArray.h"
#include "T2PoolDef.h"
#include "T2WorldDef.h"

T2PeopleTimeZoneList::T2PeopleTimeZoneList(unsigned int someNum, unsigned int isFixed, T2WorldDef* worldDef)
    : LArray(sizeof(T2PeopleTypeArray *))
{
    mIsFixed = isFixed;
    _20 = 0;
    mHoursPerItem = 0;
    mCurrentItem = 0;
    mCurrentHour = 0;
    mWorldDef = worldDef;

    for (unsigned int i = 0; i < someNum; i++) {
        T2PeopleTypeArray *array = new T2PeopleTypeArray(isFixed);
        Add(array);
    }

    mHoursPerItem = 24 / someNum;
}

T2PeopleTimeZoneList::T2PeopleTimeZoneList(T2Archive& archive, T2WorldDef* worldDef)
    : LArray(sizeof(T2PeopleTypeArray *))
{
#pragma var_order(uc, c, i, count)
    _20 = 0;
    mWorldDef = worldDef;

    int count;
    archive >> count;

    unsigned char uc;
    char c;

    archive >> uc;
    mIsFixed = uc != 0;

    archive >> c;
    mHoursPerItem = c;
    archive >> c;
    mCurrentItem = c;
    archive >> c;
    mCurrentHour = c;

    for (int i = 0; i < count; i++) {
        T2PeopleTypeArray *array = new T2PeopleTypeArray(archive);
        Add(array);
    }
}

/*virtual*/ T2PeopleTimeZoneList::~T2PeopleTimeZoneList() {
    T2PeopleTypeArray *array;
    LArrayIterator iterator(*this);

    while (iterator.Next(&array))
        delete array;
}

void T2PeopleTimeZoneList::Add(T2PeopleTypeArray* inArray) {
    InsertItemsAt(1, mItemCount + 1, &inArray);
}

void T2PeopleTimeZoneList::Add(T2PeopleType* inPeopleType, T2PoolDefDemandElem* inDemandElem) {
    T2PeopleTypeArray *array;
    LArrayIterator iterator(*this);
    unsigned int timeZoneType = 0;

    while (iterator.Next(&array)) {
        inPeopleType->SetTimeZoneType(timeZoneType);

        TimeZoneInfo *theTimeZoneInfo = inDemandElem->GetTimeZoneInfo(timeZoneType);
        CResFile resFile;
        if (resFile.OpenResource(mWorldDef->mModuleHandle, theTimeZoneInfo->m0, 'PzDf')) {
            T2PoolTimeZoneDef *theTimeZoneDef = new T2PoolTimeZoneDef(resFile);
            array->Add(inPeopleType, theTimeZoneDef, theTimeZoneInfo->m4);
            delete theTimeZoneDef;
        } else {
            CString str;
            str.Format("** T2PeopleTimeZoneDef not found : %d **\r\n", theTimeZoneInfo->m0);
            OutputDebugString(str);
        }

        timeZoneType++;
    }
}

void T2PeopleTimeZoneList::Init(unsigned int someNum, float limit) {
    mCurrentItem = someNum / mHoursPerItem;
    mCurrentHour = someNum % mHoursPerItem;

    T2PeopleTypeArray *array;
    LArrayIterator iterator(*this);

    while (iterator.Next(&array))
        array->InitSearchLimit(limit);
}

void T2PeopleTimeZoneList::IncHour(float limit) {
    mCurrentHour++;
    if (mCurrentHour >= mHoursPerItem) {
        T2PeopleTypeArray *thePrevArray = CurrentItem();
        if (thePrevArray)
            thePrevArray->AdjustLife();

        mCurrentHour = 0;
        mCurrentItem++;
        if (mCurrentItem >= GetCount())
            mCurrentItem = 0;

        T2PeopleTypeArray *theNewArray = CurrentItem();
        if (theNewArray)
            theNewArray->InitSearchLimit(limit);
    }
}

T2PeopleTypeArray* T2PeopleTimeZoneList::GetItem(int inIndex) const {
    T2PeopleTypeArray *array;
    int index = inIndex + 1;
    if (!FetchItemAt(index, &array))
        array = NULL;
    return array;
}

T2PeopleTypeArray* T2PeopleTimeZoneList::CurrentItem() const {
    return GetItem(mCurrentItem);
}

BOOL T2PeopleTimeZoneList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const {
    T2PeopleTypeArray *array = CurrentItem();
    return array->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType);
}

BOOL T2PeopleTimeZoneList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) {
    T2PeopleTypeArray *array = CurrentItem();
    return array->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType);
}

void T2PeopleTimeZoneList::DispatchRestore(T2PeopleType& inPeopleType) {
    T2PeopleTypeArray *array = GetItem(inPeopleType.GetTimeZoneType());
    if (array)
        array->Restore(inPeopleType);
}

void T2PeopleTimeZoneList::DispatchAdd(T2PeopleType* inPeopleType) {
    T2PeopleTypeArray *array = GetItem(inPeopleType->GetTimeZoneType());
    if (array)
        array->Add(inPeopleType, 1);
}

void T2PeopleTimeZoneList::Write(T2Archive& archive) {
#pragma var_order(uc, c, i)
    archive << mItemCount;

    unsigned char uc;
    char c;

    uc = mIsFixed ? 1 : 0;
    archive << uc;

    c = mHoursPerItem;
    archive << c;
    c = mCurrentItem;
    archive << c;
    c = mCurrentHour;
    archive << c;

    for (int i = 0; i < mItemCount; i++) {
        T2PeopleTypeArray *array = GetItem(i);
        if (array)
            array->Write(archive);
    }
}