summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2TemplatePluginList.cpp
blob: d67a81c0ba5f15713fb831a77e52d660cff2df9a (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "T2MoverDef.h"
#include "T2OuterObjDef.h"
#include "T2PeopleDef.h"
#include "T2SilhouetteDef.h"
#include "T2TemplatePluginList.h"
#include "T2TempPluginComparator.h"
#include "T2TenantDef.h"

T2TemplatePluginList::T2TemplatePluginList(DWORD pluginType)
    : LArray(sizeof(T2TemplatePlugin *))
{
    mPluginType = pluginType;
    SetComparator(T2TempPluginComparator::GetComparator());
    mOwnsComparator = false;
    SetKeepSorted(true);
}

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

void T2TemplatePluginList::AllClear() {
    RemoveItemsAt(mItemCount, 1);
}

void T2TemplatePluginList::Regist(T2TemplatePlugin* plugin) {
    if (!plugin)
        return;

    InsertItemsAt(1, mItemCount + 1, &plugin);
}

void T2TemplatePluginList::Add(T2TemplatePlugin* plugin) {
    if (!plugin)
        return;

    InsertItemsAt(1, mItemCount + 1, &plugin);
}

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

T2TemplatePlugin* T2TemplatePluginList::GetItemAt(int index) {
    T2TemplatePlugin *plugin;
    if (FetchItemAt(index, &plugin))
        return plugin;
    else
        return NULL;
}

T2TenantDef* T2TemplatePluginList::FindFloor() {
    if (mPluginType != 'TnDf')
        return NULL;

    LArrayIterator iterator(*this);
    T2TenantDef *theTenantDef;
    while (iterator.Next(&theTenantDef)) {
        if (theTenantDef->IsFloor())
            return theTenantDef;
    }

    return NULL;
}

T2TenantDef* T2TemplatePluginList::FindTenantDef(int equipType) {
    if (mPluginType != 'TnDf')
        return NULL;

    LArrayIterator iter(*this);
    T2TenantDef *theTemplatePlugin;
    while (iter.Next(&theTemplatePlugin)) {
        if (theTemplatePlugin->GetEquipType() == equipType)
            return theTemplatePlugin;
    }

    return NULL;
}

T2MoverDef* T2TemplatePluginList::FindMoverDef(int equipType) {
    if (mPluginType != 'MvDf')
        return NULL;

    LArrayIterator iter(*this);
    T2MoverDef *theTemplatePlugin;
    while (iter.Next(&theTemplatePlugin)) {
        if (theTemplatePlugin->GetEquipType() == equipType)
            return theTemplatePlugin;
    }

    return NULL;
}

T2OuterObjDef* T2TemplatePluginList::FindOutObjDef(int toolType) {
    if (mPluginType != 'OODf')
        return NULL;

    LArrayIterator iter(*this);
    T2OuterObjDef *theTemplatePlugin;
    while (iter.Next(&theTemplatePlugin)) {
        if (theTemplatePlugin->GetToolType() == toolType)
            return theTemplatePlugin;
    }

    return NULL;
}

T2PeopleDef* T2TemplatePluginList::FindPeopleDef(int peopleType) {
    if (mPluginType != 'PPDf')
        return NULL;

    LArrayIterator iter(*this);
    T2PeopleDef *theTemplatePlugin;
    while (iter.Next(&theTemplatePlugin)) {
        if (theTemplatePlugin->GetPeopleType() == peopleType)
            return theTemplatePlugin;
    }

    return NULL;
}

T2SilhouetteDef* T2TemplatePluginList::FindSilhouette(int silhouetteType) {
    if (mPluginType != 'SlDf')
        return NULL;

    LArrayIterator iter(*this);
    T2SilhouetteDef *theTemplatePlugin;
    while (iter.Next(&theTemplatePlugin)) {
        if (theTemplatePlugin->GetSilhouetteType() == silhouetteType)
            return theTemplatePlugin;
    }

    return NULL;
}

int T2TemplatePluginList::CalcCategoryCount() {
    int numCategory = 0;
    LArray categoryIDs(sizeof(int));
    LArrayIterator theDefIterator(*this);
    T2ToolDef *def;

    while (theDefIterator.Next(&def)) {
        int toolCategoryNo = def->mCategoryNo;
        BOOL done = false;

        LArrayIterator theCategoryIterator(categoryIDs);
        int theCategory;
        while (theCategoryIterator.Next(&theCategory)) {
            if (theCategory == toolCategoryNo) {
                done = true;
                break;
            }
        }

        if (!done) {
            categoryIDs.InsertItemsAt(1, categoryIDs.GetCount() + 1, &toolCategoryNo);
            numCategory++;
        }
    }

    return numCategory;
}

void T2TemplatePluginList::DispatchIdle(T2TowerDoc* towerDoc) {
    if (mPluginType != 'OODf' && mPluginType != 'MvDf' && mPluginType != 'TnDf')
        return;

    LArrayIterator iter(*this);
    T2ToolDef *theTemplatePlugin;

    while (iter.Next(&theTemplatePlugin))
        theTemplatePlugin->DefIdleProc(towerDoc);
}