summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2OutObjArray.cpp
blob: 02bac2cb84a48e5b1e8e7e83e29c189da22c9c71 (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
#include "StdAfx.h"
#include "T2OutObjArray.h"

T2OutObjArray::T2OutObjArray(unsigned int inStartID)
    : T2ObjectArray(inStartID)
{
    for (unsigned int i = 0; i < kGroupSize; i++)
        mOutObj[i].mID = mStartID + i;
}

/*virtual*/ T2OutObjArray::~T2OutObjArray() {
}

T2OutObj* T2OutObjArray::FindUnusedOutObj() const {
    for (int i = 0; i < kGroupSize; i++) {
        if (!mOutObj[i].IsUsed())
            return (T2OutObj *) &mOutObj[i];
    }

    return NULL;
}

/*virtual*/ void T2OutObjArray::DispatchIdle(T2TowerDoc* inDoc, int) {
    for (int i = 0; i < kGroupSize; i++) {
        if (mOutObj[i].IsUsed())
            mOutObj[i].Idle(inDoc);
    }
}

int T2OutObjArray::CalcMentenanceCost(T2TowerDoc* inDoc) const {
    int cost = 0;
    const T2OutObj *theOutObj = &mOutObj[0];

    for (unsigned int i = 0; i < kGroupSize; i++, theOutObj++) {
        if (theOutObj->IsUsed())
            cost += theOutObj->CalcMentenanceCost(inDoc);
    }

    return cost;
}

void T2OutObjArray::Read(T2Archive& inArchive, T2TowerDoc* inDoc) {
    for (int i = 0; i < kGroupSize; i++)
        mOutObj[i].Load(inArchive, inDoc);
}

void T2OutObjArray::Write(T2Archive& inArchive) {
    for (int i = 0; i < kGroupSize; i++)
        mOutObj[i].Save(inArchive);
}