summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2PeopleArrayList.cpp
blob: 25e5984719480d47dcdb08a5bab21ca2820b889b (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
#include "T2Archive.h"
#include "T2PeopleArray.h"
#include "T2PeopleArrayList.h"

T2PeopleArrayList::T2PeopleArrayList() {
    mCounter = 0;
    T2PeopleArray *peopleArray = new T2PeopleArray;
    Add(peopleArray);
}

/*virtual*/ T2PeopleArrayList::~T2PeopleArrayList() {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

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

void T2PeopleArrayList::Add(T2PeopleArray* peopleArray) {
    LArray::Add(&peopleArray);
}

unsigned int T2PeopleArrayList::GetItemCount() {
    return GetCount();
}

T2PeopleArray* T2PeopleArrayList::GetItemAt(int index) {
    T2PeopleArray *peopleArray;
    FetchItemAt(index, &peopleArray);
    return peopleArray;
}

T2People* T2PeopleArrayList::FindPeople(unsigned int peopleID) {
    LArrayIterator iterator(*this);
    T2People *people;
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray)) {
        people = peopleArray->FindPeople(peopleID);
        if (people)
            return people;
    }

    return NULL;
}

T2People* T2PeopleArrayList::FindUnusedPeople() {
    T2People *result = NULL;
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray = NULL;

    while (!result && iterator.Next(&peopleArray)) {
        result = peopleArray->FindUnusedPeople();
    }

    if (!result) {
        unsigned int newStartID = 1;
        if (peopleArray)
            newStartID = peopleArray->GetStartID() + 256;

        peopleArray = new T2PeopleArray(newStartID);
        if (peopleArray) {
            Add(peopleArray);
            result = peopleArray->FindUnusedPeople();
        }
    }

    return result;
}

void T2PeopleArrayList::DispatchIdle(T2TowerDoc* towerDoc) {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray))
        peopleArray->DispatchIdle(towerDoc, mCounter);

    mCounter++;
    if (mCounter >= 8)
        mCounter = 0;
}

void T2PeopleArrayList::DrawSearchedPerson(T2TowerDoc* towerDoc) {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray))
        peopleArray->DrawSearchedPerson(towerDoc);
}

void T2PeopleArrayList::SetWalkPeople(int v) {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray))
        peopleArray->SetWalkPeople(v);
}

void T2PeopleArrayList::TenantRemoved(unsigned int v) {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray))
        peopleArray->TenantRemoved(v);
}

void T2PeopleArrayList::AddStress(int v) {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray))
        peopleArray->AddStress(v);
}

void T2PeopleArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
    int numOfPeopleArrays;
    archive >> numOfPeopleArrays;

    RemoveItemsAt(GetCount(), 1);
    unsigned int startID = 1;

    for (int i = 0; i < numOfPeopleArrays; i++) {
        Add(new T2PeopleArray(startID));
        startID += 256;
    }

    T2PeopleArray *thePeopleArray;

    LArrayIterator iter(*this);
    while (iter.Next(&thePeopleArray))
        thePeopleArray->Read(archive, towerDoc);

    LArrayIterator iter2(*this);
    while (iter2.Next(&thePeopleArray))
        thePeopleArray->ResolveLink(this);
}

void T2PeopleArrayList::Write(T2Archive& archive) {
    int numOfPeopleArrays = GetItemCount();
    archive << numOfPeopleArrays;

    LArrayIterator iterator(*this);
    T2PeopleArray *thePeopleArray;

    while (iterator.Next(&thePeopleArray))
        thePeopleArray->Write(archive);
}

void T2PeopleArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) {
    LArrayIterator iterator(*this);
    T2PeopleArray *peopleArray;

    while (iterator.Next(&peopleArray))
        peopleArray->BreakoutEmergency(towerDoc);
}