blob: bd970e16727b5e82db1eb084958f236b89693050 (
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
|
#include "StdAfx.h"
#include "CProgramPlugin.h"
#include "T2Tenant.h"
#include "T2TenantArray.h"
#include "T2TenantDef.h"
#include "../T2TowerDoc.h"
T2TenantArray::T2TenantArray(unsigned int startID)
: T2ObjectArray(startID)
{
mTenants = new T2Tenant[kGroupSize];
for (unsigned int i = 0; i < kGroupSize; i++)
mTenants[i].mEquipID = mStartID + i;
}
/*virtual*/ T2TenantArray::~T2TenantArray() {
if (mTenants)
delete[] mTenants;
}
T2Tenant* T2TenantArray::FindUnusedTenant() {
for (int i = 0; i < kGroupSize; i++) {
if (!mTenants[i].IsUsed())
return &mTenants[i];
}
return NULL;
}
/*virtual*/ void T2TenantArray::DispatchIdle(T2TowerDoc* towerDoc, int startIndex) {
int counter = 0;
T2Tenant *tenant = mTenants;
for (int i = 0; i < kGroupSize; i++) {
if (tenant->mUsed) {
if ((counter % 32) == startIndex || towerDoc->mDebugStepRunEnabled)
tenant->Idle(towerDoc);
counter++;
}
tenant++;
}
}
int T2TenantArray::CalcMentenanceCost(T2TowerDoc* towerDoc) const {
int cost = 0;
for (int i = 0; i < kGroupSize; i++) {
if (mTenants[i].IsUsed())
cost += mTenants[i].CalcMentenanceCost(towerDoc);
}
return cost;
}
void T2TenantArray::TenantRemoved(unsigned int id) {
for (int i = 0; i < kGroupSize; i++) {
T2Tenant *tenant = &mTenants[i];
if (tenant->IsUsed() && !tenant->IsFloor() && tenant->GetRelatedTenantID() == id)
tenant->SetRelatedTenantID(0);
}
}
T2Tenant* T2TenantArray::GetTenantByPID(DWORD pluginID) {
T2EquipDef *theDef;
CProgramPlugin *thePlugin;
for (int i = 0; i < kGroupSize; i++) {
if (mTenants[i].IsUsed()) {
theDef = mTenants[i].GetEquipDef();
thePlugin = theDef ? theDef->GetPlugin() : NULL;
if (thePlugin && thePlugin->GetID() == pluginID)
return &mTenants[i];
}
}
return NULL;
}
void T2TenantArray::BreakoutEmergency(T2TowerDoc* towerDoc) {
for (int i = 0; i < kGroupSize; i++) {
T2Tenant *tenant = &mTenants[i];
if (tenant->IsUsed() && !tenant->IsFloor())
tenant->BreakoutEmergency(towerDoc);
}
}
void T2TenantArray::RecoverRelatedTenantList(T2RegistedTenantDB* db) {
T2Tenant *tenant = mTenants;
for (unsigned int i = 0; i < kGroupSize; i++, tenant++) {
if (tenant->IsUsed())
tenant->RecoverRelatedTenantList(db);
}
}
void T2TenantArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
for (int i = 0; i < kGroupSize; i++)
mTenants[i].Load(archive, towerDoc);
}
void T2TenantArray::Write(T2Archive& archive) {
for (int i = 0; i < kGroupSize; i++)
mTenants[i].Save(archive);
}
|