summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2EventItem.cpp
blob: 302752f9fd53b8947c6653a5d2800d5adad197ed (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "CResFile.h"
#include "T2Archive.h"
#include "T2DlgItemAnimation.h"
#include "T2EventDialog.h"
#include "T2EventItem.h"
#include "T2SoundPlayer.h"
#include "T2TowerDoc.h"
#include "T2TowerEvent.h"
#include "T2TowerMainView.h"
#include "T2WorldDef.h"

T2EventItem::T2EventItem(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) {
    mSubID = inSubID;
    mTowerEvent = inTowerEvent;
    mStatus = 0;

    *inResFile >> mLevelBit;

    int v;
    *inResFile >> v;
    mExclusive = (v != 0);

    *inResFile >> v;
    mCycleDay = max(1, v);

    *inResFile >> mBeginTime;
    *inResFile >> mEndTime;

    mOriginalDef = this;
    _4 = 0;
}

T2EventItem::T2EventItem(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime) {
    mSubID = inSubID;
    mTowerEvent = inTowerEvent;
    mLevelBit = inLevelBit;
    mExclusive = inExclusive;
    mCycleDay = inCycleDay;
    mBeginTime = inBeginTime;
    mEndTime = inEndTime;

    mStatus = 0;
    mOriginalDef = NULL;
    _4 = 0;
}

T2EventItem::T2EventItem(T2EventItem* inItem, int inSubID) {
    mSubID = inSubID;

    mTowerEvent = inItem->mTowerEvent;
    mLevelBit = inItem->mLevelBit;
    mExclusive = inItem->mExclusive;
    mCycleDay = inItem->mCycleDay;
    mBeginTime = inItem->mBeginTime;
    mEndTime = inItem->mEndTime;

    mStatus = 0;
    mOriginalDef = inItem;
    _4 = 0;
}

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

/*virtual*/ void T2EventItem::Init(T2TowerDoc* inDoc) {
}

/*virtual*/ BOOL T2EventItem::Start(T2TowerDoc* inDoc) {
    return true;
}

/*virtual*/ int T2EventItem::ReStart(T2TowerDoc* inDoc) {
    return 1;
}

/*virtual*/ void T2EventItem::StopEvent(T2TowerDoc* inDoc) {
}

T2WorldDef* T2EventItem::GetWorldDef() {
    return mTowerEvent->mWorldDef;
}

T2TowerDoc* T2EventItem::GetTowerDoc() const {
    return mTowerEvent->mDocument;
}

T2TowerEvent* T2EventItem::GetTowerEvent() {
    return mTowerEvent;
}

int T2EventItem::GetLevelBit() {
    return mLevelBit;
}

BOOL T2EventItem::IsExclusive() {
    return mExclusive;
}

int T2EventItem::GetCycleDay() {
    return mCycleDay;
}

int T2EventItem::GetBeginTime() {
    return mBeginTime;
}

void T2EventItem::SetBeginTime(int inTime) {
    mBeginTime = inTime;
}

int T2EventItem::GetEndTime() {
    return mEndTime;
}

/*virtual*/ BOOL T2EventItem::IsBeginTime(unsigned int inTime) {
    return (mBeginTime == inTime);
}

/*virtual*/ BOOL T2EventItem::IsBeginDay(int inDay) {
    return (inDay % mCycleDay) == 0;
}

int T2EventItem::GetStatus() {
    return mStatus;
}

void T2EventItem::SetStatus(int inStatus) {
    mStatus = inStatus;
}

T2EventItem* T2EventItem::GetOriginalDef() {
    return mOriginalDef;
}

/*virtual*/ unsigned int T2EventItem::DoDialog(T2TowerDoc* inDoc, int inDlgResID, int inAnimResID, int inAnimUnk, const char* inText) {
    T2WorldDef *theWorldDef = GetWorldDef();
    inDoc->GetTowerMainView()->tmv_vf154();
    inDoc->towerDoc_vf290(true);

    unsigned int result = 0;

    while (result == 0) {
        T2EventDialog *theDialog = T2EventDialog::Show(this, inDoc, theWorldDef->mModuleHandle, inDlgResID);
        mEventDialog = theDialog;
        SetupDialog(theDialog);

        CWnd *theLabel = theDialog->GetDlgItem(100);
        if (theLabel) {
            CString str = inText;
            str = "l" + str;
            theLabel->SetWindowText(str);
        }

        T2DlgItemAnimation *animation = (T2DlgItemAnimation *) theDialog->GetDlgItem(101);
        if (animation)
            animation->SetAnimation(theWorldDef->mModuleHandle, inAnimResID, inAnimUnk);

        result = theDialog->DoModal();
        result = DialogHook(theDialog, result, inDoc);
    }

    inDoc->towerDoc_vf290(false);
    inDoc->GetTowerMainView()->tmv_vf150();
    return result;
}

/*virtual*/ void T2EventItem::DoAlert(T2TowerDoc* inDoc, CString& inText, int inSoundID) {
    T2WorldDef *theWorldDef = GetWorldDef();
    inDoc->GetTowerMainView()->tmv_vf154();
    inDoc->towerDoc_vf290(true);

    T2EventDialog *theDialog = T2EventDialog::Show(this, inDoc, theWorldDef->mModuleHandle, 8000);

    CWnd *theLabel = theDialog->GetDlgItem(100);
    if (theLabel) {
        theLabel->SetWindowText("l" + inText);
    }

    T2DlgItemAnimation *animation = (T2DlgItemAnimation *) theDialog->GetDlgItem(101);
    if (animation)
        animation->SetAnimation(theWorldDef->mModuleHandle, 9000, 0);

    if (inSoundID) {
        inDoc->mSoundPlayer->FadeOut();
        inDoc->mSoundPlayer->AddSound("EVENT:Voice", SoundPriority_1, inSoundID, theWorldDef->mModuleHandle);
        inDoc->mSoundPlayer->Play("EVENT:Voice", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100);
    }

    theDialog->DoModal();

    if (inSoundID) {
        inDoc->mSoundPlayer->Stop("EVENT:Voice");
        inDoc->mSoundPlayer->DeleteSound("EVENT:Voice");
        inDoc->mSoundPlayer->FadeIn();
    }

    inDoc->towerDoc_vf294();
    inDoc->GetTowerMainView()->tmv_vf150();
}

/*virtual*/ void T2EventItem::Write(T2Archive& inArchive) {
    unsigned int len = 0;
    inArchive << len;
}

/*virtual*/ void T2EventItem::Read(T2Archive& inArchive) {
    unsigned char tmp;
    unsigned int len;
    inArchive >> len;

    for (unsigned int i = 0; i < len; i++)
        inArchive >> tmp;
}