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
|
#include "T2Archive.h"
#include "T2PeopleDemandList.h"
#include "T2PeopleTimeZoneList.h"
#include "T2PeopleType.h"
#include "T2PoolDef.h"
#include "T2SeasonParamDef.h"
#include "T2TenantMemberDef.h"
#include "UT2Utils.h"
T2PeopleDemandList::T2PeopleDemandList(T2PoolDef* inPoolDef, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef)
: LArray(sizeof(T2PeopleTimeZoneList *))
, mSeasonParamDef(inSeasonParamDef)
{
int numDemand = inPoolDef->GetNumOfDemand();
for (int i = 0; i < numDemand; i++) {
DemandInfo *theDemand = inPoolDef->GetDemandInfo(i);
T2PeopleTimeZoneList *list = new T2PeopleTimeZoneList(theDemand->b, theDemand->a, inWorldDef);
Add(list);
}
}
T2PeopleDemandList::T2PeopleDemandList(T2Archive& inArchive, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef)
: LArray(sizeof(T2PeopleTimeZoneList *))
, mSeasonParamDef(inSeasonParamDef)
{
unsigned int count;
inArchive >> count;
for (unsigned int i = 0; i < count; i++) {
T2PeopleTimeZoneList *theTimeZoneList = new T2PeopleTimeZoneList(inArchive, inWorldDef);
Add(theTimeZoneList);
}
}
/*virtual*/ T2PeopleDemandList::~T2PeopleDemandList() {
LArrayIterator iterator(*this);
T2PeopleTimeZoneList *theTimeZoneList;
while (iterator.Next(&theTimeZoneList))
delete theTimeZoneList;
}
void T2PeopleDemandList::Add(T2PeopleTimeZoneList* inTimeZoneList) {
InsertItemsAt(1, mItemCount + 1, &inTimeZoneList);
}
void T2PeopleDemandList::Add(T2PoolGradeDef* inGradeDef) {
T2PeopleTimeZoneList *theTimeZoneList;
LArrayIterator iterator(*this);
int theDemandType = kDemandType0;
T2PeopleType peopleType;
while (iterator.Next(&theTimeZoneList)) {
peopleType.SetDemandType(theDemandType);
T2PoolDefDemandElem *theDemandElem = inGradeDef->GetDemandElem(theDemandType);
theTimeZoneList->Add(&peopleType, theDemandElem);
theDemandType++;
}
}
void T2PeopleDemandList::Init(unsigned int inMonth, unsigned int inHour) {
float theRate = 0.0f;
if (mSeasonParamDef)
theRate = mSeasonParamDef->GetRate(inMonth - 1);
LArrayIterator iterator(*this);
T2PeopleTimeZoneList *theTimeZoneList;
while (iterator.Next(&theTimeZoneList))
theTimeZoneList->Init(inHour, theRate);
}
void T2PeopleDemandList::IncHour(unsigned int inMonth) {
float theRate = 1.0f;
if (mSeasonParamDef)
theRate = mSeasonParamDef->GetRate(inMonth - 1);
LArrayIterator iterator(*this);
T2PeopleTimeZoneList *theTimeZoneList;
while (iterator.Next(&theTimeZoneList))
theTimeZoneList->IncHour(theRate);
}
T2PeopleTimeZoneList* T2PeopleDemandList::GetItem(int inDemandType) const {
int index = inDemandType + 1;
T2PeopleTimeZoneList *theList;
if (!FetchItemAt(index, &theList))
theList = NULL;
return theList;
}
BOOL T2PeopleDemandList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const {
BOOL found = false;
T2PeopleTimeZoneList *theList = GetItem(inTenantMemberDef->GetDemandType());
if (theList)
found = theList->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType);
return found;
}
BOOL T2PeopleDemandList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) const {
BOOL found = false;
int theDemandType = inTenantMemberDef->GetDemandType();
if (theDemandType != -1) {
T2PeopleTimeZoneList *theList = GetItem(theDemandType);
if (theList)
found = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType);
} else {
for (int i = UT2Utils::Randomize(mItemCount) + 1, j = 0; !found && j < mItemCount; j++, i++) {
if (i > mItemCount)
i = 1;
T2PeopleTimeZoneList *theList = GetItem(i);
if (theList && !theList->IsFixed())
found = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType);
}
}
return found;
}
void T2PeopleDemandList::DispatchRestore(T2PeopleType& peopleType) {
T2PeopleTimeZoneList *theList = GetItem(peopleType.GetDemandType());
if (theList)
theList->DispatchRestore(peopleType);
}
void T2PeopleDemandList::DispatchAdd(T2PeopleType* peopleType) {
T2PeopleTimeZoneList *theList = GetItem(peopleType->GetDemandType());
if (theList)
theList->DispatchAdd(peopleType);
}
void T2PeopleDemandList::Write(T2Archive& archive) {
unsigned int count = GetCount();
archive << count;
for (unsigned int i = 0; i < count; i++) {
T2PeopleTimeZoneList *theList = GetItem(i);
if (theList)
theList->Write(archive);
}
}
|