#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); }