summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2PeopleArray.cpp
blob: 91edc6443441ee5afbbe0266023ff7c788f0971d (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
#include "T2PeopleArray.h"
#include "T2TowerDoc.h"

T2PeopleArray::T2PeopleArray(unsigned int startID)
    : T2ObjectArray(startID)
{
    for (unsigned int i = 0; i < 256; i++)
        mPeople[i].mMatterID = mStartID + i;
}

T2People* T2PeopleArray::FindPeople(unsigned int peopleID) {
    unsigned int firstID = mPeople[0].GetPeopleID();

    if (firstID > peopleID || (firstID + 256) < peopleID)
        return NULL;

    for (int i = 0; i < 256; i++) {
        if (mPeople[i].GetPeopleID() == peopleID)
            return &mPeople[i];
    }

    return NULL;
}

void T2PeopleArray::ResolveLink(T2PeopleArrayList* list) {
    for (int i = 0; i < 256; i++) {
        if (mPeople[i].IsUsed())
            mPeople[i].ResolveLink(list);
    }
}

T2People* T2PeopleArray::FindUnusedPeople() {
    T2People *result = NULL;

    for (unsigned int i = 0; i < 256; i++) {
        if (!mPeople[i].IsUsed()) {
            result = &mPeople[i];
            break;
        }
    }

    return result;
}

/*virtual*/ void T2PeopleArray::DispatchIdle(T2TowerDoc* towerDoc, int startIndex) {
    int i;
    T2People *people;

    people = &mPeople[startIndex];
    for (i = startIndex; i < 256; i += 8) {
        if (people->mUsed)
            people->Idle(towerDoc);
        people += 8;
    }

    people = mPeople;
    int walkRate = towerDoc->towerDoc_vf148();
    for (i = 0; i < 256; i++) {
        if (people->mUsed) {
            if ((walkRate > 0 && !(i % walkRate)) || people->IsSetSpecialFlag(kSpecialFlag20))
                people->IdleSearchedPerson(towerDoc);
        }
        people++;
    }
}

void T2PeopleArray::DrawSearchedPerson(T2TowerDoc* towerDoc) {
    T2People *people = mPeople;
    for (int i = 0; i < 256; i++) {
        if (people->mUsed && people->IsWalk())
            people->DrawSearchedPerson(towerDoc);
        people++;
    }
}

void T2PeopleArray::SetWalkPeople(int v) {
    for (int i = 0; i < 256; i++)
        mPeople[i].SetWalk(false);

    if (v != -1) {
        for (int i = 0; i < 256; i += v)
            mPeople[i].SetWalk(true);
    }
}

void T2PeopleArray::DayChanged() {
    for (int i = 0; i < 256; i++) {
        if (mPeople[i].IsUsed())
            mPeople[i].DayChanged();
    }
}

void T2PeopleArray::TenantRemoved(unsigned int v) {
    for (int i = 0; i < 256; i++) {
        if (mPeople[i].IsUsed())
            mPeople[i].TenantRemoved(v);
    }
}

void T2PeopleArray::AddStress(int v) {
    for (int i = 0; i < 256; i++) {
        if (mPeople[i].IsUsed())
            mPeople[i].IncStress(v);
    }
}

void T2PeopleArray::BreakoutEmergency(T2TowerDoc* towerDoc) {
    for (int i = 0; i < 256; i++) {
        T2People *people = &mPeople[i];
        if (people->IsUsed())
            people->BreakoutEmergency(towerDoc);
    }
}

void T2PeopleArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
    for (int i = 0; i < 256; i++)
        mPeople[i].Load(archive, towerDoc);
}

void T2PeopleArray::Write(T2Archive& archive) {
    for (int i = 0; i < 256; i++)
        mPeople[i].Save(archive);
}