summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2XEvent.cpp
blob: 8728ebc8a434d02ee3dde1b7acd9b7d842220a63 (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
#include "StdAfx.h"
#include "T2DlgItem.h"
#include "T2WorldDef.h"
#include "T2WorldPlugin.h"
#include "T2XEvent.h"

T2XEvent::T2XEvent(T2TowerEvent* inTowerEvent, CResFile* inResFile, DWORD inID, int inSubID)
    : T2EventItem(inTowerEvent, inResFile, inSubID)
{
    mID = inID;
    mRefCon = 0;
    Init(inResFile);
}

T2XEvent::T2XEvent(T2XEvent* inXEvent, int inSubID)
    : T2EventItem(inXEvent, inSubID)
{
    mID = inXEvent->mID;
    mRefCon = 0;
}

/*virtual*/ T2XEvent::~T2XEvent() {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    int res = thePlugin->XEventDestruct(this);

    int *item;
    while (mDlgItemArray.FetchItemAt(1, &item)) {
        mDlgItemArray.RemoveItemsAt(1, 1);
        delete item;
    }
}

/*virtual*/ void T2XEvent::Init(CResFile* inResFile) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    int res = thePlugin->XEventInit(this, inResFile);
}

/*virtual*/ DWORD T2XEvent::GetID() {
    return mID;
}

/*virtual*/ BOOL T2XEvent::Start(T2TowerDoc* inDoc) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    int res = thePlugin->XEventStart(this, inDoc);
    return res != 0;
}

/*virtual*/ int T2XEvent::Exec(T2TowerDoc* inDoc) {
    int res = 3;
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());

    int r = thePlugin->XEventExec(this, inDoc);
    if (r == 2) {
        int *array = new int[mDlgItemArray.GetCount() + 1];
        array[0] = mDlgItemArray.GetCount();

        LArrayIterator iterator(mDlgItemArray);
        int *item;
        for (int i = 0; i < array[0]; i++) {
            mDlgItemArray.FetchItemAt(i + 1, &item);
            array[i + 1] = *item;
        }

        delete[] array;

        res = IsExclusive() ? 1 : 0;
    } else {
        res = r;
    }

    return res;
}

/*virtual*/ void T2XEvent::StopEvent(T2TowerDoc* inDoc) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    int res = thePlugin->XEventStop(this, inDoc);
}

/*virtual*/ BOOL T2XEvent::IsBeginTime(unsigned int inTime) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    return thePlugin->XEventIsBeginTime(this, GetTowerDoc(), inTime);
}

/*virtual*/ BOOL T2XEvent::IsBeginTime(T2TowerDoc* inDoc, unsigned int inTime) {
    return false;
}

/*virtual*/ BOOL T2XEvent::IsBeginDay(int inDay) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    return thePlugin->XEventIsBeginDay(this, GetTowerDoc(), inDay);
}

/*virtual*/ BOOL T2XEvent::IsBeginDay(T2TowerDoc* inDoc, int inDay) {
    return false;
}

/*virtual*/ void T2XEvent::Write(T2Archive& inArchive) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    thePlugin->XEventWrite(this, inArchive);
}

/*virtual*/ void T2XEvent::Read(T2Archive& inArchive) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    thePlugin->XEventRead(this, inArchive);
}

unsigned int T2XEvent::GetRefCon() {
    return mRefCon;
}

void T2XEvent::SetRefCon(unsigned int inRefCon) {
    mRefCon = inRefCon;
}

void T2XEvent::SetDialogItems(int inItem1, int inItem2, int* const inItemArray, int inItem4, CString& inText) {
    mDlgItem1 = inItem1;
    mDlgItem2 = inItem2;

    int *item;

    while (mDlgItemArray.FetchItemAt(1, &item)) {
        mDlgItemArray.RemoveItemsAt(1, 1);
        delete item;
    }

    for (int i = 0; i < inItemArray[0]; i++) {
        item = new int;
        *item = inItemArray[i + 1];
        mDlgItemArray.Add(&item);
    }

    mDlgItem4 = inItem4;
    mDlgText = inText;
}

/*virtual*/ unsigned int T2XEvent::DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc) {
    T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin());
    return thePlugin->XEventDlgHook(this, inDoc, inDialog, inResult);
}