summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2StairModuleList.cpp
blob: 278b088851f141fbe2061e332a43574960708ee5 (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
#include "T2Archive.h"
#include "T2StairModule.h"
#include "T2StairModuleList.h"

T2StairModuleList::T2StairModuleList() {
}

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

void T2StairModuleList::AddModule(int position, const RECT& rect) {
    T2StairModule *module = new T2StairModule;
    if (module) {
        InsertModuleAt(GetIndex(position, ERequestUpDown_0), module);
        module->SetModuleRect(rect);
        module->mDirection = kStairDirection1;
        module->SetUsed(true);
    }

    module = new T2StairModule;
    if (module) {
        InsertModuleAt(GetIndex(position, ERequestUpDown_1), module);
        module->SetModuleRect(rect);
        module->mDirection = kStairDirection2;
        module->SetUsed(true);
    }
}

void T2StairModuleList::AddModule(T2TowerDoc* towerDoc, const RECT& rect, BOOL insertAtEnd) {
    T2StairModule *theUpModule = new T2StairModule;
    if (theUpModule) {
        theUpModule->SetModuleRect(rect);
        theUpModule->mDirection = kStairDirection1;
        theUpModule->SetUsed(true);
        theUpModule->SetModuleID(towerDoc);
    }

    T2StairModule *theDownModule = new T2StairModule;
    if (theDownModule) {
        theDownModule->SetModuleRect(rect);
        theDownModule->mDirection = kStairDirection2;
        theDownModule->SetUsed(true);
        theDownModule->SetModuleID(towerDoc);
    }

    if (theUpModule && theDownModule) {
        if (insertAtEnd) {
            InsertModuleAt(mItemCount + 1, theUpModule);
            InsertModuleAt(mItemCount + 1, theDownModule);
        } else {
            InsertModuleAt(1, theDownModule);
            InsertModuleAt(1, theUpModule);
        }
    }
}

int T2StairModuleList::GetIndex(int position, ERequestUpDown upDown) const {
    int index = 1;
    index += position * 2;
    if (upDown == ERequestUpDown_1)
        index++;
    return index;
}

void T2StairModuleList::Union(T2MoverModuleList* list, unsigned int moverID) {
    LArrayIterator iterator(*list);
    T2StairModule *stairModule;

    while (iterator.Next(&stairModule)) {
        stairModule->MoverIDChanged(moverID);
        InsertItemsAt(1, mItemCount + 1, &stairModule);
    }

    list->AllClear();
}

/*virtual*/ T2MoverModule* T2StairModuleList::ConstructModule() {
    return new T2StairModule;
}

/*virtual*/ void T2StairModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) {
    T2MoverModuleList::Read(archive, towerDoc);

    int count;
    archive >> count;

    BOOL failed = false;

    for (int i = 0; i < count && !failed; i++) {
        T2StairModule *stairModule = new T2StairModule;
        if (stairModule) {
            stairModule->Load(archive, towerDoc);
            failed = !InsertModuleAt(mItemCount + 1, stairModule);
        }
    }
}

/*virtual*/ int T2StairModuleList::GetModuleCount() const {
    return mItemCount;
}