diff options
Diffstat (limited to '')
484 files changed, 35456 insertions, 4996 deletions
diff --git a/src/256CheckDialog.cpp b/src/256CheckDialog.cpp new file mode 100644 index 0000000..b8e0fe8 --- /dev/null +++ b/src/256CheckDialog.cpp @@ -0,0 +1,2 @@ +#include "256CheckDialog.h" + diff --git a/src/256CheckDialog.h b/src/256CheckDialog.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/256CheckDialog.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/CT2App.h b/src/CT2App.h index da554ca..ab22fa3 100644 --- a/src/CT2App.h +++ b/src/CT2App.h @@ -5,9 +5,29 @@ class CT2App : public CWinApp { public: // stuff will go here later - virtual void app_vfA4(BOOL); // modifies a counter - virtual void app_vfA8(CWnd *); // sets field E8 - virtual void app_vfAC(); // clears field E8 - virtual T2GlobalData *app_vfB0(); // gets global data - virtual void app_vfB4(); // runs a message loop + // modifies counter _DC - called from T2MoverModuleTable ctor + // also called on Debug Step Run + virtual void app_vfA4(BOOL); + + // sets mMessage + virtual void app_vfA8(T2Message *); + + // clears mMessage + virtual void app_vfAC(); + + // gets global data + virtual T2GlobalData *app_vfB0(); + + // runs a message loop - called from T2PluginLoader + virtual void app_vfB4(); + + T2GlobalData *mGlobalData; + T2PluginLoader *mPluginLoader; + T2ToolWindow *mToolWindow; + T2TowerDoc *mDocument; + T2MainWindow *mMainWindow; + int _DC; + CString mStrE0; + int _E4; + T2Message *mMessage; }; diff --git a/src/DbgEquipInfo.cpp b/src/DbgEquipInfo.cpp new file mode 100644 index 0000000..43ee079 --- /dev/null +++ b/src/DbgEquipInfo.cpp @@ -0,0 +1,2 @@ +#include "DbgEquipInfo.h" + diff --git a/src/DbgEquipInfo.h b/src/DbgEquipInfo.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/DbgEquipInfo.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/DbgEventList.cpp b/src/DbgEventList.cpp new file mode 100644 index 0000000..e1548e1 --- /dev/null +++ b/src/DbgEventList.cpp @@ -0,0 +1,2 @@ +#include "DbgEventList.h" + diff --git a/src/DbgEventList.h b/src/DbgEventList.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/DbgEventList.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/DbgIPS.cpp b/src/DbgIPS.cpp new file mode 100644 index 0000000..1ff48bd --- /dev/null +++ b/src/DbgIPS.cpp @@ -0,0 +1,2 @@ +#include "DbgIPS.h" + diff --git a/src/DbgIPS.h b/src/DbgIPS.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/DbgIPS.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/DbgPeopleView.cpp b/src/DbgPeopleView.cpp new file mode 100644 index 0000000..84682a1 --- /dev/null +++ b/src/DbgPeopleView.cpp @@ -0,0 +1,2 @@ +#include "DbgPeopleView.h" + diff --git a/src/DbgPeopleView.h b/src/DbgPeopleView.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/DbgPeopleView.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/DbgStepRun.cpp b/src/DbgStepRun.cpp new file mode 100644 index 0000000..f268da2 --- /dev/null +++ b/src/DbgStepRun.cpp @@ -0,0 +1,2 @@ +#include "DbgStepRun.h" + diff --git a/src/DbgStepRun.h b/src/DbgStepRun.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/DbgStepRun.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2.cpp b/src/T2.cpp new file mode 100644 index 0000000..076e990 --- /dev/null +++ b/src/T2.cpp @@ -0,0 +1,2 @@ +#include "T2.h" + diff --git a/src/T2.h b/src/T2.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2CtrlPalette.cpp b/src/T2CtrlPalette.cpp new file mode 100644 index 0000000..ee01d9a --- /dev/null +++ b/src/T2CtrlPalette.cpp @@ -0,0 +1,233 @@ +#include "T2CtrlPalette.h" +#include "T2ImageObj.h" +#include "T2MWControl.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" + +// T2.exe 44795C +/*static*/ int T2CtrlPalette::sUnknown = 0; + +T2CtrlPalette::T2CtrlPalette() { +#line 19 + mPauseControl = DEBUG_NEW T2MWControl; + mInViewControl = DEBUG_NEW T2MWControl; + mOutViewControl = DEBUG_NEW T2MWControl; + mMaintControl = DEBUG_NEW T2MWControl; + mEvalControl = DEBUG_NEW T2MWControl; + mTransControl = DEBUG_NEW T2MWControl; + mPriceControl = DEBUG_NEW T2MWControl; + mSliderControl = DEBUG_NEW T2MWControl; + + mDocument = NULL; + mWorldDef = NULL; + sUnknown = 0; + mIsSetUp = false; +} + +/*virtual*/ T2CtrlPalette::~T2CtrlPalette() { + delete mPauseControl; + delete mInViewControl; + delete mOutViewControl; + delete mMaintControl; + delete mEvalControl; + delete mTransControl; + delete mPriceControl; + delete mSliderControl; +} + +BEGIN_MESSAGE_MAP(T2CtrlPalette, CFrameWnd) + ON_WM_CREATE() + ON_WM_QUERYNEWPALETTE() + ON_WM_ERASEBKGND() + ON_WM_CLOSE() +END_MESSAGE_MAP() + +/*virtual*/ void T2CtrlPalette::Setup(T2TowerDoc *inDoc) { + mDocument = inDoc; + mWorldDef = inDoc->mWorldDef; + + mE4 = AfxRegisterWndClass(CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); + + RECT rect; + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("Pause", 0), rect); + mPauseControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2000); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("InView", 0), rect); + mInViewControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2001); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("OutView", 0), rect); + mOutViewControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2006); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("Maint", 0), rect); + mMaintControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2004); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("Eval", 0), rect); + mEvalControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2003); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("Trans", 0), rect); + mTransControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2005); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("Price", 0), rect); + mPriceControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2002); + + mWorldDef->mImageObj->GetObjectImage(mWorldDef->mImageObj->FindObject("Slider", 0), rect); + mSliderControl->Create(mE4, "", WS_CHILD | WS_VISIBLE, rect, this, 2007); + + mPauseControl->Setup(inDoc); + mInViewControl->Setup(inDoc); + mOutViewControl->Setup(inDoc); + mMaintControl->Setup(inDoc); + mEvalControl->Setup(inDoc); + mTransControl->Setup(inDoc); + mPriceControl->Setup(inDoc); + mSliderControl->Setup(inDoc); + + mIsSetUp = true; + InvalidateRect(NULL); +} + +/*virtual*/ void T2CtrlPalette::vf100(int which) { + mInViewControl->SetData(0); + mOutViewControl->SetData(0); + mMaintControl->SetData(0); + mEvalControl->SetData(0); + mTransControl->SetData(0); + mPriceControl->SetData(0); + + int walkRate = mDocument->towerDoc_vf148(); + if (walkRate == -1) + walkRate = 0; + else + walkRate = 7 - walkRate; + mSliderControl->SetData(walkRate); + + switch (which) { + case 0: + mInViewControl->SetData(100); + break; + case 1: + mOutViewControl->SetData(100); + break; + case 4: + mMaintControl->SetData(100); + break; + case 2: + mEvalControl->SetData(100); + break; + case 5: + mTransControl->SetData(100); + break; + case 3: + mPriceControl->SetData(100); + break; + } + + InvalidateRect(NULL); +} + +/*virtual*/ void T2CtrlPalette::vf104(int which) { + RECT windowRect; + RECT clientRect; + int flag = 0; + int y; + + switch (which) { + case 0: + case 6: + y = 0; + break; + case 1: + y = 0; + flag = 1; + break; + case 4: + y = 21; + mE0 = "Maint"; + break; + case 2: + y = 21; + mE0 = "Eval"; + break; + case 5: + y = 21; + mE0 = "Trans"; + break; + case 3: + y = 21; + mE0 = "Price"; + break; + } + + GetWindowRect(&windowRect); + GetClientRect(&clientRect); + + SetWindowPos( + NULL, + 0, 0, + windowRect.right - windowRect.left - clientRect.right + 123, + windowRect.bottom - windowRect.top - clientRect.bottom + 51 + y, + SWP_NOMOVE | SWP_NOZORDER + ); + InvalidateRect(NULL); +} + +afx_msg int T2CtrlPalette::OnCreate(LPCREATESTRUCT lpCreateStruct) { + if (CFrameWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + RECT windowRect; + RECT clientRect; + + GetWindowRect(&windowRect); + GetClientRect(&clientRect); + + SetWindowPos( + NULL, + 0, 0, + windowRect.right - windowRect.left - clientRect.right + 123, + windowRect.bottom - windowRect.top - clientRect.bottom + 51, + SWP_NOMOVE | SWP_NOZORDER + ); + + return 0; +} + +afx_msg BOOL T2CtrlPalette::OnQueryNewPalette() { + return CFrameWnd::OnQueryNewPalette(); +} + +afx_msg BOOL T2CtrlPalette::OnEraseBkgnd(CDC* pDC) { + if (!mDocument) + return CFrameWnd::OnEraseBkgnd(pDC); + + pDC->SaveDC(); + pDC->SelectPalette(mWorldDef->GetPalette(), false); + + RECT rect; + + int objectID = mWorldDef->mImageObj->FindObject("CtrlPal"); + SetRect(&rect, 0, 0, 123, 51); + mWorldDef->mImageObj->DrawObject(pDC, objectID, rect); + + objectID = mWorldDef->mImageObj->FindObject(mE0, 1000); + if (objectID >= 0) { + SetRect(&rect, 0, 51, 123, 72); + mWorldDef->mImageObj->DrawObject(pDC, objectID, rect); + } + + pDC->RealizePalette(); + pDC->RestoreDC(-1); + + return true; +} + +afx_msg void T2CtrlPalette::OnClose() { + if (!mDocument) + return; + + mDocument->towerDoc_vf198(kTowerDocWindowType0); +} + +/*virtual*/ void T2CtrlPalette::vf108() { +} diff --git a/src/T2CtrlPalette.h b/src/T2CtrlPalette.h new file mode 100644 index 0000000..78a2806 --- /dev/null +++ b/src/T2CtrlPalette.h @@ -0,0 +1,37 @@ +#pragma once +#include "common.h" + +class T2CtrlPalette : public CFrameWnd { + DECLARE_MESSAGE_MAP() + +public: + T2CtrlPalette(); + virtual ~T2CtrlPalette(); + + virtual void Setup(T2TowerDoc *inDoc); + virtual void vf100(int which); + virtual void vf104(int which); + virtual void vf108(int what); // SetViewModeInternally? + + T2MWControl *mPauseControl; + T2MWControl *mInViewControl; + T2MWControl *mOutViewControl; + T2MWControl *mMaintControl; + T2MWControl *mEvalControl; + T2MWControl *mTransControl; + T2MWControl *mPriceControl; + T2MWControl *mSliderControl; + CString mE0; + CString mE4; + T2TowerDoc *mDocument; + T2WorldDef *mWorldDef; + BOOL mIsSetUp; + +protected: + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg BOOL OnQueryNewPalette(); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnClose(); + + static int sUnknown; +}; diff --git a/src/T2DLL/CDefRsrcPlugin.h b/src/T2DLL/CDefRsrcPlugin.h index 00b6df2..bdfb255 100644 --- a/src/T2DLL/CDefRsrcPlugin.h +++ b/src/T2DLL/CDefRsrcPlugin.h @@ -2,13 +2,12 @@ #include "common.h" #include "CPlugin.h" -class DLL_EXPORT CDefRsrcPlugin : public CPlugin { +class AFX_EXT_CLASS CDefRsrcPlugin : public CPlugin { public: CDefRsrcPlugin(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile); virtual ~CDefRsrcPlugin(); virtual DWORD GetPluginStyle() { return 'RPlg'; } -protected: CString mStr48; }; diff --git a/src/T2DLL/CEditWFocus.cpp b/src/T2DLL/CEditWFocus.cpp new file mode 100644 index 0000000..d2ad220 --- /dev/null +++ b/src/T2DLL/CEditWFocus.cpp @@ -0,0 +1,22 @@ +#include "CEditWFocus.h" + +CEditWFocus::CEditWFocus() { +} + +/*virtual*/ CEditWFocus::~CEditWFocus() { +} + +BEGIN_MESSAGE_MAP(CEditWFocus, CWnd) + ON_WM_KILLFOCUS() + ON_WM_SETFOCUS() +END_MESSAGE_MAP() + +afx_msg void CEditWFocus::OnKillFocus(CWnd* pNewWnd) { + CWnd::OnKillFocus(pNewWnd); + GetParent()->SendMessage(WM_KILLFOCUS); +} + +afx_msg void CEditWFocus::OnSetFocus(CWnd* pOldWnd) { + CWnd::OnSetFocus(pOldWnd); + GetParent()->SendMessage(WM_SETFOCUS); +} diff --git a/src/T2DLL/CEditWFocus.h b/src/T2DLL/CEditWFocus.h new file mode 100644 index 0000000..5c385cf --- /dev/null +++ b/src/T2DLL/CEditWFocus.h @@ -0,0 +1,14 @@ +#pragma once +#include "common.h" + +class CEditWFocus : public CEdit { + DECLARE_MESSAGE_MAP() + +public: + CEditWFocus(); + virtual ~CEditWFocus(); + +protected: + afx_msg void OnKillFocus(CWnd* pNewWnd); + afx_msg void OnSetFocus(CWnd* pOldWnd); +}; diff --git a/src/T2DLL/CFilePlugin.h b/src/T2DLL/CFilePlugin.h index 6cb909f..8aa69ff 100644 --- a/src/T2DLL/CFilePlugin.h +++ b/src/T2DLL/CFilePlugin.h @@ -4,7 +4,7 @@ class CPluginInfo; -class DLL_EXPORT CFilePlugin : public CPlugin { +class AFX_EXT_CLASS CFilePlugin : public CPlugin { public: CFilePlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~CFilePlugin(); diff --git a/src/T2DLL/CFilePluginDB.h b/src/T2DLL/CFilePluginDB.h index 02aba0b..f707b95 100644 --- a/src/T2DLL/CFilePluginDB.h +++ b/src/T2DLL/CFilePluginDB.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class DLL_EXPORT CFilePluginDB : public LArray { +class AFX_EXT_CLASS CFilePluginDB : public LArray { public: CFilePluginDB(); virtual ~CFilePluginDB(); diff --git a/src/T2DLL/CFilePluginList.h b/src/T2DLL/CFilePluginList.h index a4bc776..3fbbb39 100644 --- a/src/T2DLL/CFilePluginList.h +++ b/src/T2DLL/CFilePluginList.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT CFilePluginList : public CList<CFilePlugin *, CFilePlugin *> { +class AFX_EXT_CLASS CFilePluginList : public CList<CFilePlugin *, CFilePlugin *> { public: CFilePluginList(DWORD pluginType); virtual ~CFilePluginList(); diff --git a/src/T2DLL/CLink.h b/src/T2DLL/CLink.h index 3e8988b..abb7ca5 100644 --- a/src/T2DLL/CLink.h +++ b/src/T2DLL/CLink.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT CLink { +class AFX_EXT_CLASS CLink { public: CLink(); CLink(CLink* prev); @@ -16,14 +16,15 @@ public: void SetNext(CLink* l) { mNext = l; } void SetPrev(CLink* l) { mPrev = l; } -private: +protected: CLink *mNext; CLink *mPrev; friend class CLinkIterator; + friend class T2PeopleLinkIterator; }; -class DLL_EXPORT CLinkIterator { +class AFX_EXT_CLASS CLinkIterator { public: CLinkIterator(CLink* start); virtual ~CLinkIterator(); diff --git a/src/T2DLL/CObjectList.h b/src/T2DLL/CObjectList.h index ed66dd1..0ea922b 100644 --- a/src/T2DLL/CObjectList.h +++ b/src/T2DLL/CObjectList.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class DLL_EXPORT CObjectList : public LArray { +class AFX_EXT_CLASS CObjectList : public LArray { public: CObjectList(); virtual ~CObjectList(); diff --git a/src/T2DLL/CPEFile.h b/src/T2DLL/CPEFile.h index e27a1fa..4dbc31d 100644 --- a/src/T2DLL/CPEFile.h +++ b/src/T2DLL/CPEFile.h @@ -9,7 +9,7 @@ struct RESTRACKERWORK { IMAGE_RESOURCE_DIRECTORY_ENTRY entry; }; -class DLL_EXPORT CPEFile { +class AFX_EXT_CLASS CPEFile { public: CPEFile(const CPEFile&); CPEFile& operator=(const CPEFile&); diff --git a/src/T2DLL/CPieChartView.cpp b/src/T2DLL/CPieChartView.cpp index cc00bf4..890aab5 100644 --- a/src/T2DLL/CPieChartView.cpp +++ b/src/T2DLL/CPieChartView.cpp @@ -1,16 +1,127 @@ #include "CPieChartView.h" +#include "T2Archive.h" +#include "URect.h" -/*static*/ CPieChartView* CPieChartView::CreateCPieChartViewStream(T2Archive*) { +/*static*/ CPieChartView* CPieChartView::CreateCPieChartViewStream(T2Archive* inStream) { + return new CPieChartView(inStream); } -CPieChartView::CPieChartView(T2Archive*) { +CPieChartView::CPieChartView(T2Archive* inStream) + : mPie(NULL) +{ + inStream->Read(&mTextTraits, sizeof(mTextTraits)); + inStream->Read(&mBorderWidth, sizeof(mBorderWidth)); } /*virtual*/ CPieChartView::~CPieChartView() { } void CPieChartView::DrawSelf() { + double pi = 3.14159265358979; + + CRect theFrameRect; + GetClientRect(theFrameRect); + + if (!theFrameRect.IsRectEmpty()) { +#line 47 + _ASSERT(URect::Width(theFrameRect) == URect::Height(theFrameRect)); + + int unknownValue = 0; // not used for anything + + CWnd *parent = GetParent(); + CDC *parentDC = parent->GetDC(); + COLORREF theBackColor = parentDC->GetBkColor(); + parent->ReleaseDC(parentDC); + + CDC *pDC = GetDC(); + + CPen thePen(PS_SOLID, 1, RGB(0, 0, 0)); + CBrush theBrush(theBackColor); + + CPen *oldPen = (CPen *) pDC->SelectStockObject(NULL_PEN); + CBrush *oldBrush = pDC->SelectObject(&theBrush); + pDC->Ellipse(theFrameRect); + + CRect pieArea = theFrameRect; + pieArea.DeflateRect(mBorderWidth, mBorderWidth); + + CPoint center = pieArea.CenterPoint(); + + if (mPie && mPie->totalValue != 0) { + int i; + int sumOfValue = 0; + CPoint ptStart(center.x, pieArea.top); + + for (i = 0; i < mPie->sliceCount; i++) { + if (mPie->slices[i].value == 0) + continue; + + sumOfValue += mPie->slices[i].value; + int angleEnd = (sumOfValue * 360) / mPie->totalValue; + + CPoint ptEnd = center; + CSize size( + cos((angleEnd * pi) / 180.0), + sin((angleEnd * pi) / 180.0) + ); + ptEnd += size; + + CBrush brush(mPie->slices[i].color); + pDC->SelectObject(brush); + pDC->Pie(pieArea, ptStart, ptEnd); + ptStart = ptEnd; + } + + CSize textExtent = pDC->GetTextExtent("100%", 4); + SIZE maxNumberSize = textExtent; + int percentagePos = (URect::Width(pieArea) - maxNumberSize.cx) / 2; + CPoint anotherCenter = center; + + pDC->SetTextColor(RGB(0, 0, 0)); + pDC->SetBkMode(TRANSPARENT); + + int currAngle = 0; + sumOfValue = 0; + + for (i = 0; i < mPie->sliceCount; i++) { + if (mPie->slices[i].value == 0) + continue; + + sumOfValue += mPie->slices[i].value; + int endAngle = (sumOfValue * 360) / mPie->totalValue; + int midAngle = (currAngle + endAngle) / 2; + + CString str((mPie->slices[i].value * 100) / mPie->totalValue, 1); + str += '%'; + + CPoint textCenter = center; + CSize sliceSize( + percentagePos * cos((midAngle * pi) / 180.0), + percentagePos * sin((midAngle * pi) / 180.0) + ); + textCenter += sliceSize; + + CRect drawRect(textCenter.x - maxNumberSize.cx / 2, textCenter.y - maxNumberSize.cy / 2, textCenter.x + maxNumberSize.cx / 2, textCenter.y + maxNumberSize.cy / 2); + pDC->DrawText(str, drawRect, DT_CENTER); + + currAngle = endAngle; + } + } + + pDC->SelectStockObject(BLACK_PEN); + pDC->SelectStockObject(NULL_BRUSH); + pDC->Ellipse(pieArea); + pDC->SelectObject(oldPen); + pDC->SelectObject(oldBrush); + + ReleaseDC(pDC); + } } -void CPieChartView::CutPie(const CPieChartView::Pie*) { +void CPieChartView::CutPie(const Pie* inPie) { + mPie = inPie; + + CRect rect; + GetClientRect(rect); + InvalidateRect(rect); } diff --git a/src/T2DLL/CPieChartView.h b/src/T2DLL/CPieChartView.h index 8980203..0150e59 100644 --- a/src/T2DLL/CPieChartView.h +++ b/src/T2DLL/CPieChartView.h @@ -1,11 +1,27 @@ #pragma once #include "common.h" -class CPieChartView { +class AFX_EXT_CLASS CPieChartView : public CWnd { public: - static CPieChartView* CreateCPieChartViewStream(T2Archive*); - CPieChartView(T2Archive*); + struct PieSlice { + unsigned int value; + COLORREF color; + }; + + struct Pie { + unsigned int totalValue; + unsigned int sliceCount; + PieSlice *slices; + }; + + static CPieChartView* CreateCPieChartViewStream(T2Archive* inStream); + CPieChartView(T2Archive* inStream); virtual ~CPieChartView(); void DrawSelf(); - void CutPie(const CPieChartView::Pie*); + void CutPie(const Pie* inPie); + +protected: + int mTextTraits; + int mBorderWidth; + const Pie *mPie; }; diff --git a/src/T2DLL/CPiledMultiBarChartView.cpp b/src/T2DLL/CPiledMultiBarChartView.cpp index 16b602e..b39450a 100644 --- a/src/T2DLL/CPiledMultiBarChartView.cpp +++ b/src/T2DLL/CPiledMultiBarChartView.cpp @@ -1,25 +1,122 @@ #include "CPiledMultiBarChartView.h" +#include "T2Archive.h" -/*static*/ CPiledMultiBarChartView* CPiledMultiBarChartView::CreateCPiledMultiBarChartViewStream(T2Archive*) { +/*static*/ CPiledMultiBarChartView* CPiledMultiBarChartView::CreateCPiledMultiBarChartViewStream(T2Archive* inStream) { + return new CPiledMultiBarChartView(inStream); } -CPiledMultiBarChartView::CPiledMultiBarChartView(T2Archive*) { +CPiledMultiBarChartView::CPiledMultiBarChartView(T2Archive* inStream) + : mPixelPerValue(1) + , mColorOfPiles(NULL) + , mGraphData(NULL) +{ + inStream->Read(&mSkipDrawing, sizeof(mSkipDrawing)); + inStream->Read(&mPiles, sizeof(mPiles)); + inStream->Read(&mBars, sizeof(mBars)); + inStream->Read(&mBarWidth, sizeof(mBarWidth)); + inStream->Read(&mXOffset, sizeof(mXOffset)); + inStream->Read(&mBarInterval, sizeof(mBarInterval)); +#line 40 + _ASSERT(mPiles > 0 && mBars > 0 && mBarWidth > 0 && mBarInterval >= 0); + inStream->Read(&mLines, sizeof(mLines)); + inStream->Read(&mLineInterval, sizeof(mLineInterval)); + inStream->Read(&mLineLength, sizeof(mLineLength)); } /*virtual*/ CPiledMultiBarChartView::~CPiledMultiBarChartView() { + if (mColorOfPiles) + delete[] mColorOfPiles; } -void CPiledMultiBarChartView::SetGraphData(const CPiledMultiBarChartView::GraphData*) { +void CPiledMultiBarChartView::SetGraphData(const GraphData* inData) { + mGraphData = inData; + Refresh(); } -void CPiledMultiBarChartView::SetPixelPerValue(int, int) { +void CPiledMultiBarChartView::SetPixelPerValue(int inPixelPerValue, BOOL inRefresh) { + mPixelPerValue = inPixelPerValue; + if (inRefresh) + Refresh(); } -void CPiledMultiBarChartView::SetColorOfPiles(int, const unsigned long*, int) { +void CPiledMultiBarChartView::SetColorOfPiles(int inCount, const COLORREF* inColors, BOOL inRefresh) { + if (inColors) { + if (!mColorOfPiles) + mColorOfPiles = new COLORREF[mPiles]; + + memset(mColorOfPiles, 0, mPiles * sizeof(COLORREF)); + memmove(mColorOfPiles, inColors, min(inCount, mPiles) * sizeof(COLORREF)); + + if (inRefresh) + Refresh(); + } } void CPiledMultiBarChartView::Refresh() { + CRect rect; + GetClientRect(rect); + InvalidateRect(rect); } void CPiledMultiBarChartView::DrawSelf() { + CRect theFrameRect; + GetClientRect(theFrameRect); + + if (!theFrameRect.IsRectEmpty()) { + CDC *pDC = GetDC(); + int unknownValue = 0; + + CPen *theOldPen = (CPen *) pDC->SelectStockObject(BLACK_PEN); + CBrush *oldBrush = (CBrush *) pDC->SelectStockObject(NULL_BRUSH); + + pDC->MoveTo(theFrameRect.left, theFrameRect.top); + pDC->LineTo(theFrameRect.left, theFrameRect.bottom - 1); + pDC->LineTo(theFrameRect.right - 1, theFrameRect.bottom - 1); + + BOOL drawBars = (mGraphData != NULL) && (mColorOfPiles != NULL) && (mPixelPerValue != 0); + BOOL drawLines = (mLines > 0) && (mLineInterval > 0) && (mLineLength > 0); + + if (mSkipDrawing) + goto skip; + + if (drawLines) { + int y = theFrameRect.bottom - 1; + for (int i = 0; i < mLines; i++) { + y -= mLineInterval; + pDC->MoveTo(theFrameRect.left, y); + pDC->LineTo(theFrameRect.left + mLineLength, y); + } + } + + if (drawBars) { + int numOfBars = min(mBars, mGraphData->bars); + int x = mXOffset; + + for (int currentBar = 0; currentBar < numOfBars; currentBar++) { + int y = 0; + int numOfPiles = min(mPiles, mGraphData->piles); + + for (int currentPile = 0; currentPile < numOfPiles; currentPile++) { + int rawValue = mGraphData->data[mGraphData->piles * currentBar + currentPile]; + int value = rawValue / mPixelPerValue; + if (value > 0) { + CRect pileRect(x, -(y + value), x + mBarWidth, -y); + pileRect.OffsetRect(theFrameRect.left, theFrameRect.bottom); + y += value; + + CBrush pileBrush(mColorOfPiles[currentPile]); + pDC->SelectObject(pileBrush); + pDC->Rectangle(pileRect); + } + } + + x += mBarInterval; + } + } + + skip: + pDC->SelectObject(oldBrush); + pDC->SelectObject(theOldPen); + ReleaseDC(pDC); + } } diff --git a/src/T2DLL/CPiledMultiBarChartView.h b/src/T2DLL/CPiledMultiBarChartView.h index 4a54d23..4beb180 100644 --- a/src/T2DLL/CPiledMultiBarChartView.h +++ b/src/T2DLL/CPiledMultiBarChartView.h @@ -1,14 +1,33 @@ #pragma once #include "common.h" -class CPiledMultiBarChartView { +class AFX_EXT_CLASS CPiledMultiBarChartView : public CWnd { public: - static CPiledMultiBarChartView* CreateCPiledMultiBarChartViewStream(T2Archive*); - CPiledMultiBarChartView(T2Archive*); + struct GraphData { + int piles, bars; + int *data; + }; + + static CPiledMultiBarChartView* CreateCPiledMultiBarChartViewStream(T2Archive* inStream); + CPiledMultiBarChartView(T2Archive* inStream); virtual ~CPiledMultiBarChartView(); - void SetGraphData(const CPiledMultiBarChartView::GraphData*); - void SetPixelPerValue(int, int); - void SetColorOfPiles(int, const unsigned long*, int); + void SetGraphData(const GraphData* inData); + void SetPixelPerValue(int inPixelPerValue, BOOL inRefresh); + void SetColorOfPiles(int inCount, const COLORREF* inColors, BOOL inRefresh); void Refresh(); void DrawSelf(); + +protected: + BOOL mSkipDrawing; + int mPiles; + int mBars; + int mBarWidth; + int mBarInterval; + int mXOffset; + int mLines; + int mLineInterval; + int mLineLength; + int mPixelPerValue; + COLORREF *mColorOfPiles; + const GraphData *mGraphData; }; diff --git a/src/T2DLL/CPlugin.h b/src/T2DLL/CPlugin.h index 866157c..b63028e 100644 --- a/src/T2DLL/CPlugin.h +++ b/src/T2DLL/CPlugin.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2PluginSpecifier.h" -class DLL_EXPORT CPlugin { +class AFX_EXT_CLASS CPlugin { public: CPlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~CPlugin(); @@ -17,9 +17,11 @@ public: protected: BOOL mIsLoaded; DWORD mType; - T2PluginSpecifier mSpecifier; public: + // this gets accessed by T2TenantDef::SetCustomerTable without an inline + T2PluginSpecifier mSpecifier; + // this gets accessed by T2PaletteAnime without an inline HINSTANCE mModuleHandle; T2ImageObj *mImageObj; diff --git a/src/T2DLL/CPluginInfo.h b/src/T2DLL/CPluginInfo.h index c47cdd5..704c707 100644 --- a/src/T2DLL/CPluginInfo.h +++ b/src/T2DLL/CPluginInfo.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT CPluginInfo { +class AFX_EXT_CLASS CPluginInfo { public: static CPluginInfo* ReadPluginInfo(T2Archive& archive); protected: diff --git a/src/T2DLL/CPluginInfoArray.h b/src/T2DLL/CPluginInfoArray.h index e9fb2bb..c07d6ff 100644 --- a/src/T2DLL/CPluginInfoArray.h +++ b/src/T2DLL/CPluginInfoArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class DLL_EXPORT CPluginInfoArray : public LArray { +class AFX_EXT_CLASS CPluginInfoArray : public LArray { public: CPluginInfoArray(BOOL ownsPluginInfo = true); virtual ~CPluginInfoArray(); diff --git a/src/T2DLL/CPluginInfoComparator.h b/src/T2DLL/CPluginInfoComparator.h index e2408de..c37f6ba 100644 --- a/src/T2DLL/CPluginInfoComparator.h +++ b/src/T2DLL/CPluginInfoComparator.h @@ -2,7 +2,7 @@ #include "common.h" #include "LComparator.h" -class DLL_EXPORT CPluginInfoComparator : public LComparator { +class AFX_EXT_CLASS CPluginInfoComparator : public LComparator { public: virtual ~CPluginInfoComparator() { } virtual int Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const; diff --git a/src/T2DLL/CProgramPlugin.h b/src/T2DLL/CProgramPlugin.h index 902cee1..2781a08 100644 --- a/src/T2DLL/CProgramPlugin.h +++ b/src/T2DLL/CProgramPlugin.h @@ -2,7 +2,7 @@ #include "common.h" #include "CFilePlugin.h" -class DLL_EXPORT CProgramPlugin : public CFilePlugin { +class AFX_EXT_CLASS CProgramPlugin : public CFilePlugin { public: CProgramPlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~CProgramPlugin(); diff --git a/src/T2DLL/CResFile.h b/src/T2DLL/CResFile.h index 5c10f21..24966a8 100644 --- a/src/T2DLL/CResFile.h +++ b/src/T2DLL/CResFile.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT CResFile { +class AFX_EXT_CLASS CResFile { public: CResFile(); virtual ~CResFile(); diff --git a/src/T2DLL/CResourcePlugin.h b/src/T2DLL/CResourcePlugin.h index a253742..9a7243e 100644 --- a/src/T2DLL/CResourcePlugin.h +++ b/src/T2DLL/CResourcePlugin.h @@ -2,7 +2,7 @@ #include "common.h" #include "CFilePlugin.h" -class DLL_EXPORT CResourcePlugin : public CFilePlugin { +class AFX_EXT_CLASS CResourcePlugin : public CFilePlugin { public: CResourcePlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~CResourcePlugin(); diff --git a/src/T2DLL/CToggleButtonDisabled.cpp b/src/T2DLL/CToggleButtonDisabled.cpp index e31ae08..f69f8cc 100644 --- a/src/T2DLL/CToggleButtonDisabled.cpp +++ b/src/T2DLL/CToggleButtonDisabled.cpp @@ -10,7 +10,7 @@ CToggleButtonDisabled::CToggleButtonDisabled(T2TowerDoc* towerDoc, T2ImageObj* i CRect rect1 = rect; CRect rect2; - if (GetObjectImage(rect2, windowName, -1, 0, 0, 255)) { + if (GetObjectImage(rect2, windowName)) { rect1.right = rect1.left + rect2.Width(); rect1.bottom = rect1.top + rect2.Height(); } else { @@ -58,7 +58,7 @@ void CToggleButtonDisabled::Disable() { GetWindowText(text); RECT imageRect; - T2BitImage *image = GetObjectImage(imageRect, text, GetPattern(), 0, 0, 255); + T2BitImage *image = GetObjectImage(imageRect, text, GetPattern()); if (image) image->CopyImage(dc, imageRect, clientRect, 0, NULL); diff --git a/src/T2DLL/CToggleButtonDisabled.h b/src/T2DLL/CToggleButtonDisabled.h index 5604257..45be553 100644 --- a/src/T2DLL/CToggleButtonDisabled.h +++ b/src/T2DLL/CToggleButtonDisabled.h @@ -2,9 +2,9 @@ #include "common.h" #include "T2DlgItem.h" -class DLL_EXPORT CToggleButtonDisabled : public T2DlgItem { +class AFX_EXT_CLASS CToggleButtonDisabled : public T2DlgItem { public: - CToggleButtonDisabled(T2TowerDoc*, T2ImageObj*, CPalette*); + CToggleButtonDisabled(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual BOOL Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId); virtual void SetValue(int value); void Enable(); diff --git a/src/T2DLL/CTokenizer.h b/src/T2DLL/CTokenizer.h index 3ad28a5..fe4475f 100644 --- a/src/T2DLL/CTokenizer.h +++ b/src/T2DLL/CTokenizer.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT CTokenizer { +class AFX_EXT_CLASS CTokenizer { public: CTokenizer(char *str, const char *newLineChars = NULL, const char *spaceChars = NULL); virtual ~CTokenizer(); diff --git a/src/T2DLL/GlobalFunc.cpp b/src/T2DLL/GlobalFunc.cpp index b210cc6..754f5cd 100644 --- a/src/T2DLL/GlobalFunc.cpp +++ b/src/T2DLL/GlobalFunc.cpp @@ -1,82 +1,423 @@ +#include "CResFile.h" #include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2OptionPluginList.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" -char *strtokEx(char *, const char *, char **) { +T2SoundPlayer *Sounds; +CT2App *gT2App; +int gCommonColor[20]; +BOOL FFEnable; +DWORD FFBaseForce; +IDirectInput *FFgpdi; +IDirectInputDevice2W *FFJoystick; +IDirectInputEffect *FFBuild; +IDirectInputEffect *FFStatic; +T2TowerDoc *g_TowerDoc; + +char *strtokEx(char * inStr, const char * inSep, char ** ioLast) { +#line 11 + _ASSERT(!inStr || !*ioLast); + + if (inStr) { + *ioLast = NULL; + inStr += _mbsspn((const unsigned char *) inStr, (const unsigned char *) inSep); + } + + if (*ioLast) + inStr = *ioLast; + + char *work = inStr; + + if (inStr) { + work = inStr; + inStr = (char *) _mbspbrk((const unsigned char *) inStr, (const unsigned char *) inSep); + if (inStr) { + *inStr = 0; + inStr++; + inStr += _mbsspn((const unsigned char *) inStr, (const unsigned char *) inSep); + if (*inStr == 0) + inStr = NULL; + } + + *ioLast = inStr; + } + + return work; } -void InsetRect(RECT *, int, int) { +void InsetRect(RECT * ioRect, int inX, int inY) { + ioRect->top += inY; + ioRect->bottom -= inY; + ioRect->left += inX; + ioRect->right -= inX; } -void SetPt(POINT *, int, int) { +void SetPt(POINT * outPt, int inX, int inY) { + outPt->x = inX; + outPt->y = inY; } -HBITMAP Create256DIBitmap(HDC, int, int) { +HBITMAP Create256DIBitmap(HDC inDC, int inWidth, int inHeight) { + HBITMAP theBitmap = NULL; + + if (GetDeviceCaps(inDC, BITSPIXEL) == 8) { + theBitmap = CreateBitmap(inWidth, inHeight, 1, 8, NULL); + } else { + Bitmap *bitmap = (Bitmap *) malloc(sizeof(Bitmap)); + memset(&bitmap->header, 0, sizeof(BITMAPINFOHEADER)); + + bitmap->header.biSize = sizeof(BITMAPINFOHEADER); + bitmap->header.biWidth = inWidth; + bitmap->header.biHeight = inHeight; + bitmap->header.biBitCount = 8; + bitmap->header.biPlanes = 1; + bitmap->header.biClrUsed = 256; + bitmap->header.biClrImportant = 256; + + for (int i = 0; i < 256; i++) + bitmap->palette[i] = i; + + void *bits; + theBitmap = CreateDIBSection(inDC, (const BITMAPINFO *) bitmap, DIB_PAL_COLORS, &bits, NULL, 0); + + free(bitmap); + } + + return theBitmap; } -LOGPALETTE *ConvACTPalette(ACTPALETTEENTRY *) { +LOGPALETTE *ConvACTPalette(ACTPALETTEENTRY * inPalette) { + LOGPALETTE *pal = (LOGPALETTE *) malloc(sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)); + + for (int i = 0; i < 256; i++) { + pal->palPalEntry[i].peRed = inPalette[i].red; + pal->palPalEntry[i].peGreen = inPalette[i].green; + pal->palPalEntry[i].peBlue = inPalette[i].blue; + pal->palPalEntry[i].peFlags = 0; + } + + pal->palVersion = 0x300; + pal->palNumEntries = 256; + return pal; } -LOGPALETTE *LoadACTPaletteEntries(HINSTANCE, int) { +LOGPALETTE *LoadACTPaletteEntries(HINSTANCE inModule, int inResID) { + HRSRC theRes = FindResource(inModule, MAKEINTRESOURCE(inResID), "PALETTE"); + if (!theRes) + return NULL; + + HGLOBAL theResHandle = LoadResource(inModule, theRes); + if (SizeofResource(inModule, theRes) == 0x300) { + ACTPALETTEENTRY *act = (ACTPALETTEENTRY *) LockResource(theResHandle); + return ConvACTPalette(act); + } + + unsigned char *data = (unsigned char *) LockResource(theResHandle); + DWORD theResSize = sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY); + LOGPALETTE *theLogPalette = (LOGPALETTE *) malloc(theResSize); + memset(theLogPalette, 0, theResSize); + + theLogPalette->palVersion = 0x300; + theLogPalette->palNumEntries = 256; + + if (data[0] == 0 && data[1] == 0) { + data += 6; + + int entryCount = (data[0] << 8) + data[1]; + data += 2; + + for (int i = 0; i < entryCount; i++) { + theLogPalette->palPalEntry[data[1]].peRed = data[2]; + theLogPalette->palPalEntry[data[1]].peGreen = data[4]; + theLogPalette->palPalEntry[data[1]].peBlue = data[6]; + theLogPalette->palPalEntry[data[1]].peFlags = 0; + data += 8; + } + } else { + int entryCount = (data[0] << 8) + data[1]; + data += 16; + + for (int i = 0; i < entryCount; i++) { + theLogPalette->palPalEntry[i].peRed = data[0]; + theLogPalette->palPalEntry[i].peGreen = data[2]; + theLogPalette->palPalEntry[i].peBlue = data[4]; + theLogPalette->palPalEntry[i].peFlags = 0; + data += 16; + } + } + + return theLogPalette; } -void FFSetStaticForce(int, int) { +// 1001719C, not exported lmao +CPalette *LoadPaletteUnkName(HINSTANCE inModule, int inResID) { + LOGPALETTE *logPalette = LoadACTPaletteEntries(inModule, inResID); + if (!logPalette) + return NULL; + + logPalette->palPalEntry[253].peFlags = PC_RESERVED; + logPalette->palPalEntry[254].peFlags = PC_RESERVED; + + CPalette *thePalette = new CPalette; + thePalette->CreatePalette(logPalette); + free(logPalette); + + return thePalette; +} + +void FFSetStaticForce(int inX, int inY) { + if (!FFEnable) + return; + + LONG rglDirection[2] = { inX, inY }; + DICONSTANTFORCE cf; + cf.lMagnitude = (DWORD) sqrt((double)inX * (double)inX + (double)inY * (double)inY); + + DIEFFECT eff; + eff.dwSize = sizeof(DIEFFECT); + eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; + eff.cAxes = 2; + eff.rglDirection = rglDirection; + eff.lpEnvelope = NULL; + eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); + eff.lpvTypeSpecificParams = &cf; + + FFStatic->SetParameters(&eff, DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS | DIEP_START); } CString GetInstallSource() { + return GetMachineProfileString("Install", "Source", "Z:\\"); } CString GetInstallSourceDrive() { + CString path = GetMachineProfileString("Install", "Source", "Z:\\"); + return path.Left(1); } T2TowerDoc *GetCurrentT2TowerDoc() { + return g_TowerDoc; } HINSTANCE GetWorldModuleHandle() { + return GetCurrentT2TowerDoc()->towerDoc_vf170()->mModuleHandle; } -CString GetModuleName(HINSTANCE) { +CString GetModuleName(HINSTANCE inModule) { + char buf[512]; + GetModuleFileName(inModule, buf, 512); + + CString theName = _mbsrchr((const unsigned char *) buf, '\\') + 1; + return theName; } unsigned int TickCount() { + return (GetTickCount() * 60) / 1000; } -int DispatchOptionEvent(OPTIONEVENTTYPE, void *) { +BOOL DispatchOptionEvent(OPTIONEVENTTYPE inEventType, void * inData) { + return GetCurrentT2TowerDoc()->mOptionPluginList->DispatchEvent(inEventType, GetCurrentT2TowerDoc(), inData); } -CFile *OpenSubPluginFS(const char *, int, int, SUBPLUGINFSENTRY *) { +CFile *OpenSubPluginFS(const char * inPath, int inID1, int inID2, SUBPLUGINFSENTRY * outEntry) { + CFile *file = new CFile; + + if (!file->Open(inPath, CFile::modeRead)) { + delete file; + return NULL; + } + + char magic[2]; + file->Read(magic, 2); +#line 229 + _ASSERT(memcmp(magic, "SP", 2) == 0); + + unsigned int curEntry, count; + SUBPLUGINFSENTRY fsEntry; + file->Read(&count, sizeof(count)); + + for (curEntry = 0; curEntry < count; curEntry++) { + file->Read(&fsEntry, sizeof(fsEntry)); + if (fsEntry.spfse_m0 == inID2 && fsEntry.spfse_m4 == inID1) + break; + } + + if (curEntry == count) { + file->Close(); + delete file; + + CString err; + err.Format("CResFile::OpenResource(SubPlugin FS) ERROR : %s,%d,%d\n", inPath, inID2, inID1); + OutputDebugString(err); + return NULL; + } + + *outEntry = fsEntry; + file->Seek(fsEntry.spfse_m8, CFile::begin); + return file; } -void __Rep0(const char *, int, const char *) { +void __Rep0(const char * inFileName, int inLineNum, const char * inMessage) { + CString err; + err.Format("%s (%d)\n\n%s", inFileName, inLineNum, inMessage); + MessageBox(NULL, err, "ERROR", MB_ICONERROR); + _CrtDbgBreak(); } -void __Rep1(const char *, int, const char *, unsigned long) { +void __Rep1(const char * inFileName, int inLineNum, const char * inMessage, unsigned long inArg1) { + CString err; + err.Format(inMessage, inArg1); + __Rep0(inFileName, inLineNum, err); } -void __Rep2(const char *, int, const char *, unsigned long, unsigned long) { +void __Rep2(const char * inFileName, int inLineNum, const char * inMessage, unsigned long inArg1, unsigned long inArg2) { + CString err; + err.Format(inMessage, inArg1, inArg2); + __Rep0(inFileName, inLineNum, err); } -void GetTowerDirectory(char *) { +void GetTowerDirectory(char * outStr) { + GetModuleFileName(NULL, outStr, 1000); + *strrchr(outStr, '\\') = 0; + + char *p = strrchr(outStr, '\\'); + if (p && !_stricmp(p, "\\debug")) + *p = 0; + else if (p && !_stricmp(p, "\\release")) + *p = 0; + + strcat(outStr, "\\"); } CString GetTowerDirectory() { + char *buffer = (char *) malloc(1000); + GetTowerDirectory(buffer); + CString thePath = buffer; + free(buffer); + return thePath; } -CString LoadStringA(HINSTANCE, int, int) { +CString LoadString(HINSTANCE inModule, int inID, int inMaxSize) { + if (inModule == INSTANCE_EXE) + inModule = AfxGetInstanceHandle(); + else if (inModule == INSTANCE_WORLD) + inModule = GetWorldModuleHandle(); + + CString str; + char *buffer = (char *) malloc(inMaxSize + 1); + buffer[0] = 0; + + if (inModule != INSTANCE_ANY) { + str.Format("%d@%s", inID, GetModuleName(inModule)); + LoadString(inModule, inID, buffer, inMaxSize + 1); + } else { + str.Format("%d", inID); + if (!LoadString(GetWorldModuleHandle(), inID, buffer, inMaxSize + 1)) + LoadString(AfxGetInstanceHandle(), inID, buffer, inMaxSize + 1); + } + + if (buffer[0] != 0) + str = buffer; + + free(buffer); + return str; } -CString LoadStringTable(HINSTANCE, int, int) { +CString LoadStringTable(HINSTANCE inModule, int inID1, int inID2) { + if (inModule == INSTANCE_EXE) + inModule = AfxGetInstanceHandle(); + else if (inModule == INSTANCE_WORLD) + inModule = GetWorldModuleHandle(); + + CString str; + + if (inModule != INSTANCE_ANY) { + str.Format("%d-%d@%s", inID1, inID2, GetModuleName(inModule)); + CResFile theResFile; + if (theResFile.OpenResource(inModule, inID1, "STRTABLE")) { + int count; + theResFile >> count; + if (inID2 <= count) { + for (int i = 1; i <= inID2; i++) + theResFile >> str; + } + } + } else { + str.Format("%d-%d@%s", inID1, inID2); + + BOOL isOpen = false; + CResFile theResFile; + if (theResFile.OpenResource(GetWorldModuleHandle(), inID1, "STRTABLE")) + isOpen = true; + else if (theResFile.OpenResource(AfxGetInstanceHandle(), inID1, "STRTABLE")) + isOpen = true; + + if (isOpen) { + int count; + theResFile >> count; + if (inID2 <= count) { + for (int i = 1; i <= inID2; i++) + theResFile >> str; + } + } + } + + return str; } -void CopyPalette(LOGPALETTE *, LOGPALETTE *, int, int, int) { +void CopyPalette(LOGPALETTE *inSrc, LOGPALETTE *inDst, int inSrcIndex, int inDstIndex, int inCount) { + for (int i = 0; i < inCount; i++) { + inDst->palPalEntry[inDstIndex + i].peRed = inSrc->palPalEntry[inSrcIndex + i].peRed; + inDst->palPalEntry[inDstIndex + i].peGreen = inSrc->palPalEntry[inSrcIndex + i].peGreen; + inDst->palPalEntry[inDstIndex + i].peBlue = inSrc->palPalEntry[inSrcIndex + i].peBlue; + } } -void WriteMachineProfileString(const char *, const char *, const char *) { +void WriteMachineProfileString(const char * inKey, const char * inName, const char * inValue) { + CString subKey = "SOFTWARE\\OPeNBooK9003\\T2\\"; + subKey += inKey; + + HKEY key; + RegCreateKey(HKEY_LOCAL_MACHINE, subKey, &key); + RegSetValueEx(key, inName, 0, REG_SZ, (LPBYTE) inValue, strlen(inValue)); + RegCloseKey(key); } -void WriteMachineProfileInt(const char *, const char *, int) { +void WriteMachineProfileInt(const char * inKey, const char * inName, int inValue) { + CString value; + value.Format("%d", inValue); + WriteMachineProfileString(inKey, inName, value); } -CString GetMachineProfileString(const char *, const char *, const char *) { +CString GetMachineProfileString(const char * inKey, const char * inName, const char * inDefaultValue) { + CString subKey = "SOFTWARE\\OPeNBooK9003\\T2\\"; + subKey += inKey; + + CString result; + + HKEY key; + if (RegOpenKey(HKEY_LOCAL_MACHINE, subKey, &key) == ERROR_SUCCESS) { + DWORD type = REG_SZ; + DWORD bufferSize = 0x400; + char *buffer = (char *) malloc(bufferSize); + if (RegQueryValueEx(key, inName, NULL, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS) + result = buffer; + else + result = inDefaultValue; + + RegCloseKey(key); + free(buffer); + } else { + result = inDefaultValue; + } + + return result; } -int GetMachineProfileInt(const char *, const char *, int) { +int GetMachineProfileInt(const char * inKey, const char * inName, int inDefaultValue) { + CString value; + value.Format("%d", inDefaultValue); + value = GetMachineProfileString(inKey, inName, value); + return atoi(value); } diff --git a/src/T2DLL/GlobalFunc.h b/src/T2DLL/GlobalFunc.h index 9375677..0b8fd2f 100644 --- a/src/T2DLL/GlobalFunc.h +++ b/src/T2DLL/GlobalFunc.h @@ -1,7 +1,15 @@ #pragma once #include "common.h" -struct ACTPALETTEENTRY; +// these are horrible kludges used by LoadStringTable +#define INSTANCE_EXE ((HINSTANCE) 1) +#define INSTANCE_WORLD ((HINSTANCE) 2) +#define INSTANCE_ANY ((HINSTANCE) 3) + +struct ACTPALETTEENTRY { + BYTE red, green, blue; +}; + struct SUBPLUGINFSENTRY { int spfse_m0; int spfse_m4; @@ -9,32 +17,41 @@ struct SUBPLUGINFSENTRY { int spfse_mC; // size? }; -char *strtokEx(char *, const char *, char **); -void InsetRect(RECT *, int, int); -void SetPt(POINT *, int, int); -HBITMAP Create256DIBitmap(HDC, int, int); -LOGPALETTE *ConvACTPalette(ACTPALETTEENTRY *); -LOGPALETTE *LoadACTPaletteEntries(HINSTANCE, int); -void FFSetStaticForce(int, int); -CString GetInstallSource(); -CString GetInstallSourceDrive(); -T2TowerDoc *GetCurrentT2TowerDoc(); -HINSTANCE GetWorldModuleHandle(); -CString GetModuleName(HINSTANCE); -unsigned int TickCount(); -int DispatchOptionEvent(OPTIONEVENTTYPE, void *); -CFile *OpenSubPluginFS(const char *, int, int, SUBPLUGINFSENTRY *); -void __Rep0(const char *, int, const char *); -void __Rep1(const char *, int, const char *, unsigned long); -void __Rep2(const char *, int, const char *, unsigned long, unsigned long); -void GetTowerDirectory(char *); -CString GetTowerDirectory(); -CString LoadStringA(HINSTANCE, int, int); -CString LoadStringTable(HINSTANCE, int, int); -void CopyPalette(LOGPALETTE *, LOGPALETTE *, int, int, int); -void WriteMachineProfileString(const char *, const char *, const char *); -void WriteMachineProfileInt(const char *, const char *, int); -CString GetMachineProfileString(const char *, const char *, const char *); -int GetMachineProfileInt(const char *, const char *, int); +char *AFX_EXT_API strtokEx(char * inStr, const char * inSep, char ** ioLast); +void AFX_EXT_API InsetRect(RECT * ioRect, int inX, int inY); +void AFX_EXT_API SetPt(POINT * outPt, int inX, int inY); +HBITMAP AFX_EXT_API Create256DIBitmap(HDC inDC, int inWidth, int inHeight); +LOGPALETTE *AFX_EXT_API ConvACTPalette(ACTPALETTEENTRY * inPalette); +LOGPALETTE *AFX_EXT_API LoadACTPaletteEntries(HINSTANCE inModule, int inResID); +void AFX_EXT_API FFSetStaticForce(int inX, int inY); +CString AFX_EXT_API GetInstallSource(); +CString AFX_EXT_API GetInstallSourceDrive(); +T2TowerDoc *AFX_EXT_API GetCurrentT2TowerDoc(); +HINSTANCE AFX_EXT_API GetWorldModuleHandle(); +CString AFX_EXT_API GetModuleName(HINSTANCE inModule); +unsigned int AFX_EXT_API TickCount(); +BOOL AFX_EXT_API DispatchOptionEvent(OPTIONEVENTTYPE inEventType, void * inData); +CFile *AFX_EXT_API OpenSubPluginFS(const char * inPath, int inID1, int inID2, SUBPLUGINFSENTRY * outEntry); +void AFX_EXT_API __Rep0(const char * inFileName, int inLineNum, const char * inMessage); +void AFX_EXT_API __Rep1(const char * inFileName, int inLineNum, const char * inMessage, unsigned long inArg1); +void AFX_EXT_API __Rep2(const char * inFileName, int inLineNum, const char * inMessage, unsigned long inArg1, unsigned long inArg2); +void AFX_EXT_API GetTowerDirectory(char * outStr); +CString AFX_EXT_API GetTowerDirectory(); +CString AFX_EXT_API LoadString(HINSTANCE inModule, int inID, int inMaxSize); +CString AFX_EXT_API LoadStringTable(HINSTANCE inModule, int inID1, int inID2); +void AFX_EXT_API CopyPalette(LOGPALETTE *inSrc, LOGPALETTE *inDst, int inSrcIndex, int inDstIndex, int inCount); +void AFX_EXT_API WriteMachineProfileString(const char * inKey, const char * inName, const char * inValue); +void AFX_EXT_API WriteMachineProfileInt(const char * inKey, const char * inName, int inValue); +CString AFX_EXT_API GetMachineProfileString(const char * inKey, const char * inName, const char * inDefaultValue); +int AFX_EXT_API GetMachineProfileInt(const char * inKey, const char * inName, int inDefaultValue); -DLL_EXPORT CT2App *gT2App; +extern AFX_EXT_DATA T2SoundPlayer *Sounds; +extern AFX_EXT_DATA CT2App *gT2App; +extern AFX_EXT_DATA int gCommonColor[20]; +extern AFX_EXT_DATA BOOL FFEnable; +extern AFX_EXT_DATA DWORD FFBaseForce; +extern AFX_EXT_DATA IDirectInput *FFgpdi; +extern AFX_EXT_DATA IDirectInputDevice2W *FFJoystick; +extern AFX_EXT_DATA IDirectInputEffect *FFBuild; +extern AFX_EXT_DATA IDirectInputEffect *FFStatic; +extern AFX_EXT_DATA T2TowerDoc *g_TowerDoc; diff --git a/src/T2DLL/LArray.cpp b/src/T2DLL/LArray.cpp index 647162f..da569e0 100644 --- a/src/T2DLL/LArray.cpp +++ b/src/T2DLL/LArray.cpp @@ -122,7 +122,7 @@ void LArray::SetKeepSorted(int keepSorted) { return 0; } -/*virtual*/ int LArray::FetchItemAt(int index, void* outItem) const { +/*virtual*/ BOOL LArray::FetchItemAt(int index, void* outItem) const { #line 123 _ASSERT(index > 0); diff --git a/src/T2DLL/LArray.h b/src/T2DLL/LArray.h index 110e3bc..223e6a2 100644 --- a/src/T2DLL/LArray.h +++ b/src/T2DLL/LArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "LComparator.h" -class DLL_EXPORT LArray { +class AFX_EXT_CLASS LArray { public: LArray(); LArray(int size, LComparator* comparator = NULL, BOOL keepSorted = false); @@ -18,15 +18,15 @@ public: virtual void RemoveItemsAt(int count, int where); virtual void Remove(const void* item); virtual int FetchIndexOf(const void* item) const; - virtual int FetchItemAt(int index, void* outItem) const; + virtual BOOL FetchItemAt(int index, void* outItem) const; virtual void AssignItemsAt(int count, int where, void* data); virtual void Add(const void* item); void SetComparator(LComparator* comparator); virtual void ReadAsWord(T2Archive& archive); virtual void WriteAsWord(T2Archive& archive); virtual void ReadAsDWord(T2Archive& archive); + virtual void WriteAsDWord(T2Archive& archive); virtual void ReadAsChar(T2Archive& archive); - virtual void WriteAsDWord(T2Archive& archive); virtual void WriteAsChar(T2Archive& archive); protected: @@ -39,7 +39,7 @@ protected: BOOL mKeepSorted; }; -class DLL_EXPORT LArrayIterator { +class AFX_EXT_CLASS LArrayIterator { public: LArrayIterator(const LArray& array, int index = 1); LArrayIterator(const LArrayIterator& iter); diff --git a/src/T2DLL/LAttachable.h b/src/T2DLL/LAttachable.h index f06bbd9..97e2633 100644 --- a/src/T2DLL/LAttachable.h +++ b/src/T2DLL/LAttachable.h @@ -1,12 +1,12 @@ #pragma once #include "common.h" -class DLL_EXPORT LAttachable { +class AFX_EXT_CLASS LAttachable { public: LAttachable(); LAttachable(const LAttachable& other); virtual ~LAttachable(); - virtual void AddAttachment(LAttachment* attachment, LAttachment* before, BOOL setAsOwner); + virtual void AddAttachment(LAttachment* attachment, LAttachment* before = NULL, BOOL setAsOwner = true); virtual void RemoveAttachment(LAttachment* attachment); virtual void RemoveAllAttachments(); virtual BOOL ExecuteAttachments(unsigned int message, void* data); diff --git a/src/T2DLL/LAttachment.h b/src/T2DLL/LAttachment.h index 10b8c66..f457808 100644 --- a/src/T2DLL/LAttachment.h +++ b/src/T2DLL/LAttachment.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT LAttachment { +class AFX_EXT_CLASS LAttachment { public: LAttachment(unsigned int message = 0, BOOL executeHost = true); virtual ~LAttachment(); diff --git a/src/T2DLL/LBroadcaster.h b/src/T2DLL/LBroadcaster.h index f439df3..2987d54 100644 --- a/src/T2DLL/LBroadcaster.h +++ b/src/T2DLL/LBroadcaster.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class DLL_EXPORT LBroadcaster { +class AFX_EXT_CLASS LBroadcaster { public: LBroadcaster(); LBroadcaster(const LBroadcaster& other); diff --git a/src/T2DLL/LListener.h b/src/T2DLL/LListener.h index 4632ff2..17ca949 100644 --- a/src/T2DLL/LListener.h +++ b/src/T2DLL/LListener.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class DLL_EXPORT LListener { +class AFX_EXT_CLASS LListener { public: LListener(); LListener(const LListener& other); diff --git a/src/T2DLL/LPeriodical.h b/src/T2DLL/LPeriodical.h index ca66d6d..e686357 100644 --- a/src/T2DLL/LPeriodical.h +++ b/src/T2DLL/LPeriodical.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT LPeriodical { +class AFX_EXT_CLASS LPeriodical { public: LPeriodical(); virtual ~LPeriodical(); diff --git a/src/T2DLL/MMIO.h b/src/T2DLL/MMIO.h index 11303fa..b3993fe 100644 --- a/src/T2DLL/MMIO.h +++ b/src/T2DLL/MMIO.h @@ -1,54 +1,296 @@ -#pragma once +/* + * The provenance of this file is really confusing. + * OPeNBooK9003 didn't write it, it came from some form of tutorial or + * example, and I've found some copies, but none that make sense here. + * + * - "Sam's Teach Yourself DirectX 7 Programming in 24 Hours" + * A book from 1999 - a year too new, and a DirectX version too new. + * - "DirectSound Wrapper Classes" + * https://www.codeproject.com/articles/12076/directsound-wrapper-classes + * Published in 2006 - 7 years too new. + * - "Chicken Tournament" + * https://github.com/shlusiak/Chicken-Tournament/blob/master/src/Resources/MMIO.h + * A game from 2003. + */ + +//----------------------------------------------------------------- +// MMIO Objects +// C++ Header - MMIO.h +//----------------------------------------------------------------- +#ifndef __MMIO_H__ +#define __MMIO_H__ + +//----------------------------------------------------------------- +// Inclusions +//----------------------------------------------------------------- #include "common.h" +#include <MMSystem.h> -class CMMChunk { +//----------------------------------------------------------------- +// CMMChunk Class - Multimedia RIFF Chunk Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CMMChunk : public MMCKINFO +{ + // Protected Constructor(s)/Destructor protected: - CMMChunk(); -public: - CMMChunk& operator=(const CMMChunk&); + CMMChunk() { }; }; -class CMMIdChunk { + +//----------------------------------------------------------------- +// CMMIdChunk Class - Multimedia RIFF Id Chunk Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CMMIdChunk : public CMMChunk +{ + // Public Constructor(s)/Destructor public: - CMMIdChunk& operator=(const CMMIdChunk&); - CMMIdChunk(char, char, char, char); - CMMIdChunk(const char*, unsigned int); + CMMIdChunk(char c0, char c1, char c2, char c3); + CMMIdChunk(LPCSTR psz, UINT uiFlags = 0u); }; -class CMMTypeChunk { + +//----------------------------------------------------------------- +// CMMTypeChunk Class - Multimedia RIFF Type Chunk Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CMMTypeChunk : public CMMChunk +{ + // Public Constructor(s)/Destructor public: - CMMTypeChunk& operator=(const CMMTypeChunk&); - CMMTypeChunk(char, char, char, char); - CMMTypeChunk(const char*, unsigned int); + CMMTypeChunk(char c0, char c1, char c2, char c3); + CMMTypeChunk(LPCSTR psz, UINT uiFlags = 0u); }; -class CMMIOInfo { + +//----------------------------------------------------------------- +// CMMIOInfo Class - Multimedia RIFF I/O Info Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CMMIOInfo : public MMIOINFO +{ + // Public Constructor(s)/Destructor public: - CMMIOInfo& operator=(const CMMIOInfo&); - CMMIOInfo(); + CMMIOInfo(); }; -class CMMMemoryIOInfo { + +//----------------------------------------------------------------- +// CMMMemoryIOInfo Class - Multimedia RIFF Memory I/O Info Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CMMMemoryIOInfo : public CMMIOInfo +{ + // Public Constructor(s)/Destructor public: - CMMMemoryIOInfo& operator=(const CMMMemoryIOInfo&); - CMMMemoryIOInfo(long, unsigned long); - CMMMemoryIOInfo(char*, long, unsigned long); + CMMMemoryIOInfo(LONG lBuffer, DWORD dwMinExpansion = 0); + CMMMemoryIOInfo(HPSTR pBuffer, LONG lBuffer, DWORD + dwMinExpansion = 0); }; -class CMMIO { + +//----------------------------------------------------------------- +// CMMIO Class - Multimedia RIFF I/O Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CMMIO : public CObject +{ + // Public Constructor(s)/Destructor +public: + CMMIO(); + CMMIO(HMMIO hmmio); + CMMIO(const char* pszFileName, DWORD dwOpenFlag = + MMIO_READ); + CMMIO(CMMMemoryIOInfo& mmioinfo); + + // Public Methods +public: + void Open(const char* pszFileName, + DWORD dwOpenFlags = MMIO_READ); + void Open(CMMMemoryIOInfo &mmioinfo); + MMRESULT Close(UINT uiFlags = 0u); + + MMRESULT Ascend(CMMChunk &mmckInfo, UINT uiFlags = 0u); + MMRESULT Descend(CMMChunk &mmckInfo, UINT uiFlags = 0u); + MMRESULT Descend(CMMChunk &mmckInfo, CMMChunk &mmckParent, + UINT uiFlags = 0u); + + LONG Read(HPSTR pData, LONG lLen); + LONG Write(const char* pData, LONG lLen); + LONG Seek(LONG lOffset, int iOrigin); + + LRESULT SendMessage(UINT uiMsg, LPARAM lParam1, + LPARAM lParam2); + MMRESULT SetBuffer(LPSTR pBuffer, LONG lBuffer, + UINT uiFlags = 0u); + + MMRESULT GetInfo(CMMIOInfo &, UINT uiFlags = 0); + MMRESULT SetInfo(CMMIOInfo &, UINT uiFlags = 0); + MMRESULT Advance(CMMIOInfo &, UINT uiFlags); + + // Public Data public: - virtual ~CMMIO(); - CMMIO(); - CMMIO(HMMIO); - CMMIO(const char*, unsigned long); - CMMIO(CMMMemoryIOInfo&); - unsigned int Close(unsigned int); - long Read(char*, long); - unsigned int Ascend(CMMChunk&, unsigned int); - unsigned int Descend(CMMChunk&, unsigned int); - unsigned int Descend(CMMChunk&, CMMChunk&, unsigned int); - long Seek(long, int); - long SendMessageA(unsigned int, long, long); - unsigned int SetBuffer(char*, long, unsigned int); - long Write(const char*, long); - unsigned int GetInfo(CMMIOInfo&, unsigned int); - unsigned int SetInfo(CMMIOInfo&, unsigned int); - unsigned int Advance(CMMIOInfo&, unsigned int); - void Open(const char*, unsigned long); - void Open(CMMMemoryIOInfo&); + HMMIO m_hmmio; }; + + +//----------------------------------------------------------------- +// CMMIdChunk Inline Public Constructor(s)/Destructor +//----------------------------------------------------------------- +inline CMMIdChunk::CMMIdChunk(char c0, char c1, char c2, char c3) +{ + ckid = mmioFOURCC(c0, c1, c2, c3); +} + +inline CMMIdChunk::CMMIdChunk(LPCSTR psz, UINT uiFlags) +{ + ckid = ::mmioStringToFOURCC(psz, uiFlags); +} + +//----------------------------------------------------------------- +// CMMTypeChunk Inline Public Constructor(s)/Destructor +//----------------------------------------------------------------- +inline CMMTypeChunk::CMMTypeChunk(char c0, char c1, char c2, char c3) +{ + fccType = mmioFOURCC(c0, c1, c2, c3); +} + +inline CMMTypeChunk::CMMTypeChunk(LPCSTR psz, UINT uiFlags) +{ + fccType = ::mmioStringToFOURCC(psz, uiFlags); +} + +//----------------------------------------------------------------- +// CMMIOInfo Inline Public Constructor(s)/Destructor +//----------------------------------------------------------------- +inline CMMIOInfo::CMMIOInfo() +{ + ::ZeroMemory(this, sizeof(MMIOINFO)); +} + +//----------------------------------------------------------------- +// CMMMemoryIOInfo Inline Public Constructor(s)/Destructor +//----------------------------------------------------------------- +inline CMMMemoryIOInfo::CMMMemoryIOInfo(LONG lBuffer, + DWORD dwMinExpansion) +{ + pIOProc = NULL; + fccIOProc = FOURCC_MEM; + pchBuffer = NULL; + cchBuffer = lBuffer; + adwInfo[0] = dwMinExpansion; +} + +inline CMMMemoryIOInfo::CMMMemoryIOInfo(HPSTR pBuffer, LONG cchBuf, + DWORD dwMinExpansion) +{ + pIOProc = NULL; + fccIOProc = FOURCC_MEM; + pchBuffer = pBuffer; + cchBuffer = cchBuf; + adwInfo[0] = dwMinExpansion; +} + +//----------------------------------------------------------------- +// CMMIO Inline Public Constructor(s)/Destructor +//----------------------------------------------------------------- +inline CMMIO::CMMIO() : m_hmmio(NULL) +{ +} + +inline +CMMIO::CMMIO(HMMIO hmmio) : m_hmmio(hmmio) +{ +} + +inline CMMIO::CMMIO(const char* pszFileName, DWORD dwOpenFlag) +{ + Open(pszFileName, dwOpenFlag); +} + +inline CMMIO::CMMIO(CMMMemoryIOInfo &mmioinfo) +{ + Open(mmioinfo); +} + +//----------------------------------------------------------------- +// CMMIO Inline Public Methods +//----------------------------------------------------------------- +inline MMRESULT CMMIO::Close(UINT uiFlags) +{ + ASSERT(m_hmmio); + + MMRESULT mmr = ::mmioClose(m_hmmio, uiFlags); + m_hmmio = NULL; + return mmr; +} + +inline LONG CMMIO::Read(HPSTR pData, LONG lLen) +{ + ASSERT(m_hmmio); + + return ::mmioRead(m_hmmio, pData, lLen); +} + +inline MMRESULT CMMIO::Ascend(CMMChunk &mmckInfo, UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioAscend(m_hmmio, &mmckInfo, uiFlags); +} + +inline MMRESULT CMMIO::Descend(CMMChunk &mmckInfo, UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioDescend(m_hmmio, &mmckInfo, 0, uiFlags); +} + +inline MMRESULT CMMIO::Descend(CMMChunk &mmckInfo, + CMMChunk &mmckParent, UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioDescend(m_hmmio, &mmckInfo, &mmckParent, uiFlags); +} + +inline LONG CMMIO::Seek(LONG lOffset, int iOrigin) +{ + ASSERT(m_hmmio); + return ::mmioSeek(m_hmmio, lOffset, iOrigin); +} + +inline LRESULT CMMIO::SendMessage(UINT uiMsg, LPARAM lParam1, + LPARAM lParam2) +{ + ASSERT(m_hmmio); + return ::mmioSendMessage(m_hmmio, uiMsg, lParam1, lParam2); +} + +inline MMRESULT CMMIO::SetBuffer(LPSTR pBuffer, LONG lBuffer, + UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioSetBuffer(m_hmmio, pBuffer, lBuffer, uiFlags); +} + +inline LONG CMMIO::Write(const char* pData, LONG lLen) +{ + ASSERT(m_hmmio); + + return ::mmioWrite(m_hmmio, pData, lLen); +} + +inline MMRESULT CMMIO::GetInfo(CMMIOInfo &Info, UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioGetInfo(m_hmmio, &Info, uiFlags); +} + +inline MMRESULT CMMIO::SetInfo(CMMIOInfo &Info, UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioSetInfo(m_hmmio, &Info, uiFlags); +} + +inline MMRESULT CMMIO::Advance(CMMIOInfo &Info, UINT uiFlags) +{ + ASSERT(m_hmmio); + + return ::mmioAdvance(m_hmmio, &Info, uiFlags); +} + +#endif diff --git a/src/T2DLL/Mmio.cpp b/src/T2DLL/Mmio.cpp index 5a11e85..8e77810 100644 --- a/src/T2DLL/Mmio.cpp +++ b/src/T2DLL/Mmio.cpp @@ -1,97 +1,35 @@ +//----------------------------------------------------------------- +// MMIO Objects +// C++ Source - MMIO.cpp +//----------------------------------------------------------------- + +//----------------------------------------------------------------- +// Inclusions +//----------------------------------------------------------------- +#include "common.h" +//----------------------------------------------------------------- #include "MMIO.h" -CMMChunk::CMMChunk() { -} - -CMMChunk& CMMChunk::operator=(const CMMChunk&) { -} - -CMMIdChunk& CMMIdChunk::operator=(const CMMIdChunk&) { -} - -CMMIdChunk::CMMIdChunk(char, char, char, char) { -} - -CMMIdChunk::CMMIdChunk(const char*, unsigned int) { -} - -CMMTypeChunk& CMMTypeChunk::operator=(const CMMTypeChunk&) { -} - -CMMTypeChunk::CMMTypeChunk(char, char, char, char) { -} - -CMMTypeChunk::CMMTypeChunk(const char*, unsigned int) { -} - -CMMIOInfo& CMMIOInfo::operator=(const CMMIOInfo&) { -} - -CMMIOInfo::CMMIOInfo() { -} - -CMMMemoryIOInfo& CMMMemoryIOInfo::operator=(const CMMMemoryIOInfo&) { -} - -CMMMemoryIOInfo::CMMMemoryIOInfo(long, unsigned long) { -} - -CMMMemoryIOInfo::CMMMemoryIOInfo(char*, long, unsigned long) { -} - -/*virtual*/ CMMIO::~CMMIO() { -} - -CMMIO::CMMIO() { -} +//----------------------------------------------------------------- +// MFC Debugging Support +//----------------------------------------------------------------- +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif -CMMIO::CMMIO(HMMIO) { -} - -CMMIO::CMMIO(const char*, unsigned long) { -} - -CMMIO::CMMIO(CMMMemoryIOInfo&) { -} - -unsigned int CMMIO::Close(unsigned int) { -} - -long CMMIO::Read(char*, long) { -} - -unsigned int CMMIO::Ascend(CMMChunk&, unsigned int) { -} - -unsigned int CMMIO::Descend(CMMChunk&, unsigned int) { -} - -unsigned int CMMIO::Descend(CMMChunk&, CMMChunk&, unsigned int) { -} - -long CMMIO::Seek(long, int) { -} - -long CMMIO::SendMessageA(unsigned int, long, long) { -} - -unsigned int CMMIO::SetBuffer(char*, long, unsigned int) { -} - -long CMMIO::Write(const char*, long) { -} - -unsigned int CMMIO::GetInfo(CMMIOInfo&, unsigned int) { -} - -unsigned int CMMIO::SetInfo(CMMIOInfo&, unsigned int) { -} - -unsigned int CMMIO::Advance(CMMIOInfo&, unsigned int) { -} +//----------------------------------------------------------------- +// CMMIO Public Methods +//----------------------------------------------------------------- +void CMMIO::Open(const char* pszFileName, DWORD dwOpenFlags) +{ -void CMMIO::Open(const char*, unsigned long) { + ASSERT(AfxIsValidString(pszFileName)); + m_hmmio = mmioOpen((char*)pszFileName, NULL, dwOpenFlags); } -void CMMIO::Open(CMMMemoryIOInfo&) { +void CMMIO::Open(CMMMemoryIOInfo &mmioinfo) +{ + m_hmmio = mmioOpen(NULL, &mmioinfo, MMIO_READWRITE); } diff --git a/src/T2DLL/MoverSearchDlg.cpp b/src/T2DLL/MoverSearchDlg.cpp new file mode 100644 index 0000000..f6501ed --- /dev/null +++ b/src/T2DLL/MoverSearchDlg.cpp @@ -0,0 +1,84 @@ +#include "MoverSearchDlg.h" +#include "T2DlgItemListBox.h" +#include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2MoverArrayList.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "UT2Utils.h" + +MoverSearchDlg::MoverSearchDlg() { + mDeleteOnClose = true; +} + +/*virtual*/ MoverSearchDlg::~MoverSearchDlg() { +} + +void MoverSearchDlg::Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt) { + mDocument = inDoc; + + T2DLGTEMPLATE tmpl; + tmpl.resID = 7130; + tmpl.pt = inPt; + tmpl.moduleHandle = inInstance; + + Realize(inParentWnd, &tmpl, inDoc, NULL, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 112, true); + ShowWindow(SW_HIDE); +} + +void MoverSearchDlg::DoFind() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + + int curSel = theListBox->GetCurSel(); + if (curSel == -1) + return; + + T2Name *theName = (T2Name *) theListBox->GetItemDataPtr(curSel); + mDocument->towerDoc_vf238(theName); +} + +void MoverSearchDlg::DoDelete() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + + int curSel = theListBox->GetCurSel(); + if (curSel == -1) + return; + + T2Name *theName = (T2Name *) theListBox->GetItemDataPtr(curSel); + mDocument->mNameDB->RemoveName(theName); + theListBox->DeleteString(curSel); +} + +/*virtual*/ void MoverSearchDlg::OnT2Create() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + T2MoverArrayList *theList = mDocument->mFloorInfo->GetMoverArrayList(); + + if (!theListBox) + return; + if (!theList) + return; + + HFONT theFont = GetFont(); + if (theFont) + theListBox->SetFont(theFont); + + theListBox->ResetContent(); + + T2NameList *theNameDB = mDocument->mNameDB; + T2Name *theName; + LArrayIterator iterator(*theNameDB); + + while (iterator.Next(&theName)) { + int type = theName->GetType(); + if (type == kMoverNameType) { + CString nameStr; + unsigned int moverID; + theName->GetName(nameStr, moverID); + + int theIndex = theListBox->AddString(nameStr); + theListBox->SetItemDataPtr(theIndex, theName); + } + } +} diff --git a/src/T2DLL/MoverSearchDlg.h b/src/T2DLL/MoverSearchDlg.h new file mode 100644 index 0000000..8fb181b --- /dev/null +++ b/src/T2DLL/MoverSearchDlg.h @@ -0,0 +1,17 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class MoverSearchDlg : public T2Dialog { +public: + MoverSearchDlg(); + virtual ~MoverSearchDlg(); + void Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt); + void DoFind(); + void DoDelete(); + +protected: + virtual void OnT2Create(); + + T2TowerDoc *mDocument; +}; diff --git a/src/T2DLL/PeopleSearchDlg.cpp b/src/T2DLL/PeopleSearchDlg.cpp new file mode 100644 index 0000000..1e73ef2 --- /dev/null +++ b/src/T2DLL/PeopleSearchDlg.cpp @@ -0,0 +1,102 @@ +#include "PeopleSearchDlg.h" +#include "T2DlgItemListBox.h" +#include "T2FloorInfo.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "UT2Utils.h" + +PeopleSearchDlg::PeopleSearchDlg() { + mDeleteOnClose = true; +} + +/*virtual*/ PeopleSearchDlg::~PeopleSearchDlg() { +} + +void PeopleSearchDlg::Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt) { + mDocument = inDoc; + + T2DLGTEMPLATE tmpl; + tmpl.resID = 7110; + tmpl.pt = inPt; + tmpl.moduleHandle = inInstance; + + Realize(inParentWnd, &tmpl, inDoc, NULL, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 110, true); + ShowWindow(SW_HIDE); +} + +void PeopleSearchDlg::DoFind() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + if (!theListBox) + return; + + int curSel = theListBox->GetCurSel(); + if (curSel == -1) + return; + + T2Name *theName = (T2Name *) theListBox->GetItemDataPtr(curSel); + mDocument->towerDoc_vf238(theName); +} + +void PeopleSearchDlg::DoDelete() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + if (!theListBox) + return; + + int curSel = theListBox->GetCurSel(); + if (curSel == -1) + return; + + T2Name *theName = (T2Name *) theListBox->GetItemDataPtr(curSel); + mDocument->mNameDB->RemoveName(theName); + theListBox->DeleteString(curSel); +} + +/*virtual*/ void PeopleSearchDlg::OnT2Create() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + + if (!theListBox) + return; + + HFONT theFont = GetFont(); + if (theFont) + theListBox->SetFont(theFont); + + theListBox->ResetContent(); + + T2NameList *theNameDB = mDocument->mNameDB; + T2Name *theName; + LArrayIterator iterator(*theNameDB); + + while (iterator.Next(&theName)) { + int type = theName->GetType(); + if (type == kPeopleNameType) { + CString nameStr; + unsigned int peopleID; + theName->GetName(nameStr, peopleID); + + T2People *thePeople = mDocument->mPeopleArrayList->FindPeople(peopleID); + if (thePeople) { + CString roomNumberStr; + CString str; + + if (thePeople->GetWorkTenant() > 1) { + T2Tenant *theTenant = mDocument->mFloorInfo->GetTenant(thePeople->GetWorkTenant()); + if (theTenant) + UT2Utils::GetRoomNumberString(theTenant->GetRoomNumber(mDocument->mFloorInfo), roomNumberStr); + } + + roomNumberStr += " "; + str = roomNumberStr.Left(7); + str += nameStr; + + int theIndex = theListBox->AddString(str); + theListBox->SetItemDataPtr(theIndex, theName); + } + } + } +} diff --git a/src/T2DLL/PeopleSearchDlg.h b/src/T2DLL/PeopleSearchDlg.h new file mode 100644 index 0000000..4462912 --- /dev/null +++ b/src/T2DLL/PeopleSearchDlg.h @@ -0,0 +1,17 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class PeopleSearchDlg : public T2Dialog { +public: + PeopleSearchDlg(); + virtual ~PeopleSearchDlg(); + void Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt); + void DoFind(); + void DoDelete(); + +protected: + virtual void OnT2Create(); + + T2TowerDoc *mDocument; +}; diff --git a/src/T2DLL/SoundDlg.cpp b/src/T2DLL/SoundDlg.cpp new file mode 100644 index 0000000..858f906 --- /dev/null +++ b/src/T2DLL/SoundDlg.cpp @@ -0,0 +1,127 @@ +#include "SoundDlg.h" +#include "CT2App.h" +#include "T2DlgItem.h" +#include "T2DlgItemText.h" +#include "T2MainWindow.h" +#include "T2MWControl.h" +#include "T2SoundPlayer.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" + +SoundDlg::SoundDlg() { + mDeleteOnClose = true; +} + +/*virtual*/ SoundDlg::~SoundDlg() { +} + +void SoundDlg::Setup(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt, T2ImageObj *inImageObj) { + mDocument = inDoc; + + T2DLGTEMPLATE tmpl; + tmpl.resID = 7020; + tmpl.pt = inPt; + tmpl.moduleHandle = inInstance; + + Realize(inParentWnd, &tmpl, inDoc, inImageObj, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 201, true); + ShowWindow(SW_HIDE); +} + +void SoundDlg::Revert() { + T2DlgItem *theCheck = GetT2DlgItem(100); + theCheck->SetValue(1); + + for (int i = 0; i < 4; i++) { + T2DlgItem *theICheck = GetT2DlgItem(101 + i); + theICheck->SetValue(1); + + T2DlgItemText *theText = (T2DlgItemText *) GetT2DlgItem(111 + i); + theText->SetTextColor(RGB(0, 0, 0)); + } + + Invalidate(); +} + +// T2DLL.dll 100DBC20 +static const unsigned int masks[4] = { + 9, 2, 0x30, 4 +}; + +void SoundDlg::Save() { + T2SoundPlayer *theSoundPlayer = mDocument->towerDoc_vf134(); + + T2DlgItem *theCheck = GetT2DlgItem(100); + if (theCheck->GetValue()) + theSoundPlayer->SetSoundOn(true); + else + theSoundPlayer->SetSoundOn(false); + + unsigned int theMask = theSoundPlayer->GetSEMask(); + for (int i = 0; i < 4; i++) { + T2DlgItem *theICheck = GetT2DlgItem(101 + i); + if (theICheck->GetValue()) + theMask |= masks[i]; + else + theMask &= ~masks[i]; + } + theSoundPlayer->SetSEMask(theMask); +} + +/*virtual*/ void SoundDlg::OnT2Create() { + T2SoundPlayer *theSoundPlayer = mDocument->towerDoc_vf134(); + T2DlgItem *theCheck = GetT2DlgItem(100); + + if (theSoundPlayer->IsSoundOn()) { + theCheck->SetValue(1); + } else { + theCheck->SetValue(0); + for (int i = 0; i < 4; i++) { + T2DlgItemText *theText = (T2DlgItemText *) GetT2DlgItem(111 + i); + theText->SetTextColor(RGB(128, 128, 128)); + } + } + + unsigned int theMask = theSoundPlayer->GetSEMask(); + for (int i = 0; i < 4; i++) { + T2DlgItem *theICheck = GetT2DlgItem(101 + i); + if (theMask & masks[i]) + theICheck->SetValue(1); + else + theICheck->SetValue(0); + } +} + +/*virtual*/ int SoundDlg::OnT2DialogCommand(UINT cmd, long data) { + int result = 1; + T2DlgItem *theCheck = GetT2DlgItem(100); + BOOL isSoundOn = theCheck->GetValue(); + WORD w = LOWORD(cmd); + + if (w == 100) { + COLORREF col; + if (isSoundOn) + col = RGB(0, 0, 0); + else + col = RGB(128, 128, 128); + + for (int i = 0; i < 4; i++) { + T2DlgItemText *theText = (T2DlgItemText *) GetT2DlgItem(111 + i); + theText->SetTextColor(col); + } + + Invalidate(); + } else if (w >= 101 && w < 105) { + if (!isSoundOn) { + T2DlgItem *theICheck = GetT2DlgItem(w); + int oldValue = theICheck->GetValue(); + if (oldValue) + theICheck->SetValue(0); + else + theICheck->SetValue(1); + } + } else { + result = T2Dialog::OnT2DialogCommand(cmd, data); + } + + return result; +} diff --git a/src/T2DLL/SoundDlg.h b/src/T2DLL/SoundDlg.h new file mode 100644 index 0000000..157d004 --- /dev/null +++ b/src/T2DLL/SoundDlg.h @@ -0,0 +1,18 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class SoundDlg : public T2Dialog { +public: + SoundDlg(); + virtual ~SoundDlg(); + void Setup(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt, T2ImageObj *inImageObj); + void Revert(); + void Save(); + +protected: + virtual int OnT2DialogCommand(UINT cmd, long data); + virtual void OnT2Create(); + + T2TowerDoc *mDocument; +}; diff --git a/src/T2DLL/SpeedDlg.cpp b/src/T2DLL/SpeedDlg.cpp new file mode 100644 index 0000000..ba623bf --- /dev/null +++ b/src/T2DLL/SpeedDlg.cpp @@ -0,0 +1,110 @@ +#include "SpeedDlg.h" +#include "CT2App.h" +#include "T2DlgItem.h" +#include "T2MainWindow.h" +#include "T2MWControl.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" + +SpeedDlg::SpeedDlg() { + mDeleteOnClose = true; +} + +/*virtual*/ SpeedDlg::~SpeedDlg() { +} + +void SpeedDlg::Setup(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt, T2ImageObj *inImageObj) { + mDocument = inDoc; + mCurrentSpeed = mDocument->towerDoc_vf2A4(); + + T2DLGTEMPLATE tmpl; + tmpl.resID = 7010; + tmpl.pt = inPt; + tmpl.moduleHandle = inInstance; + + Realize(inParentWnd, &tmpl, inDoc, inImageObj, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 200, true); + ShowWindow(SW_HIDE); +} + +static const int speedValues[] = {125, 25, 20, 5, 1}; + +void SpeedDlg::Revert() { + T2DlgItem *theRadio; + + if (mCurrentIndex != -1) { + theRadio = GetT2DlgItem(105 + mCurrentIndex); + theRadio->SetValue(0); + } + + mCurrentIndex = 1; + mCurrentSpeed = speedValues[mCurrentIndex]; + + theRadio = GetT2DlgItem(105 + mCurrentIndex); + theRadio->SetValue(1); +} + +void SpeedDlg::Save() { + mDocument->towerDoc_vf2A8(mCurrentSpeed); +} + +/*virtual*/ void SpeedDlg::OnT2Create() { + mCurrentIndex = -1; + + T2DlgItem *theRadio; + T2DlgItem *theText; + + for (int i = 0; i < 5; i++) { + if (mCurrentSpeed == speedValues[i]) { + mCurrentIndex = i; + theRadio = GetT2DlgItem(105 + mCurrentIndex); + theRadio->SetValue(1); + break; + } + } + + if (mCurrentIndex != 4) { + theText = GetT2DlgItem(104); + theRadio = GetT2DlgItem(109); + + theText->ShowWindow(SW_HIDE); + theRadio->ShowWindow(SW_HIDE); + } +} + +/*virtual*/ int SpeedDlg::OnT2DialogCommand(UINT cmd, long data) { + int result = 1; + WORD w = LOWORD(cmd); + + T2DlgItem *theRadio; + T2DlgItem *theText; + + switch (w) { + case 105: + case 106: + case 107: + case 108: + case 109: + mCurrentSpeed = speedValues[w - 105]; + if (mCurrentIndex != -1) { + theRadio = GetT2DlgItem(105 + mCurrentIndex); + theRadio->SetValue(0); + } + mCurrentIndex = w - 105; + theRadio = GetT2DlgItem(105 + mCurrentIndex); + theRadio->SetValue(1); + break; + + case 110: + theText = GetT2DlgItem(104); + theRadio = GetT2DlgItem(109); + + theText->ShowWindow(SW_SHOW); + theRadio->ShowWindow(SW_SHOW); + break; + + default: + result = T2Dialog::OnT2DialogCommand(cmd, data); + } + + return result; +} diff --git a/src/T2DLL/SpeedDlg.h b/src/T2DLL/SpeedDlg.h new file mode 100644 index 0000000..79588c2 --- /dev/null +++ b/src/T2DLL/SpeedDlg.h @@ -0,0 +1,20 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class SpeedDlg : public T2Dialog { +public: + SpeedDlg(); + virtual ~SpeedDlg(); + void Setup(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt, T2ImageObj *inImageObj); + void Revert(); + void Save(); + +protected: + virtual int OnT2DialogCommand(UINT cmd, long data); + virtual void OnT2Create(); + + T2TowerDoc *mDocument; + int mCurrentSpeed; + int mCurrentIndex; +}; diff --git a/src/T2DLL/T2AdvertisePlugin.cpp b/src/T2DLL/T2AdvertisePlugin.cpp index 8486955..5b10df3 100644 --- a/src/T2DLL/T2AdvertisePlugin.cpp +++ b/src/T2DLL/T2AdvertisePlugin.cpp @@ -30,9 +30,9 @@ T2AdvertisePlugin::T2AdvertisePlugin(DWORD type, T2PluginSpecifier& specifier) void T2AdvertisePlugin::UnfoldPluginSelf() { if (mCC != 0) { - mBitImage = new T2BitImage(mSpecifier.mPath, mCC, 1); + mImage = new T2BitImage(mSpecifier.mPath, mCC, 1); mImageObj = new T2ImageObj; - mImageObj->AddObject("BILL", -1, *mBitImage, NULL, 0, 0); + mImageObj->AddObject("BILL", -1, *mImage, NULL, 0, 0); } } diff --git a/src/T2DLL/T2AdvertisePlugin.h b/src/T2DLL/T2AdvertisePlugin.h index 289e3f8..7775772 100644 --- a/src/T2DLL/T2AdvertisePlugin.h +++ b/src/T2DLL/T2AdvertisePlugin.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2SubPlugin.h" -class DLL_EXPORT T2AdvertisePlugin : public T2SubPlugin { +class AFX_EXT_CLASS T2AdvertisePlugin : public T2SubPlugin { public: T2AdvertisePlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~T2AdvertisePlugin(); diff --git a/src/T2DLL/T2AdvertiseTable.cpp b/src/T2DLL/T2AdvertiseTable.cpp index 5362e34..0f353bf 100644 --- a/src/T2DLL/T2AdvertiseTable.cpp +++ b/src/T2DLL/T2AdvertiseTable.cpp @@ -1,34 +1,165 @@ +#include "CFilePluginList.h" +#include "T2AdvertisePlugin.h" #include "T2AdvertiseTable.h" -/*virtual*/ int T2AdvertiseTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2AdvertiseTable::OnT2DlgItemCreate(CREATESTRUCT* cs) { + T2DlgItemTable::SetColWidth(cs->cx, 0, 0); + return T2DlgItemTable::OnT2DlgItemCreate(cs); } -T2AdvertiseTable::T2AdvertiseTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2AdvertiseTable::T2AdvertiseTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2VerticalTable(inDoc, inImageObj, inPalette) +{ + mClearBackground = true; + SetCellDataSize(sizeof(T2AdvertisePlugin *)); + InsertCols(1, 0, NULL); + SetHScrollerStyle(AlwaysHide); + SetVScrollerStyle(AlwaysShow); } -void T2AdvertiseTable::Add(T2AdvertisePlugin*, int) { +void T2AdvertiseTable::Add(T2AdvertisePlugin* inPlugin, BOOL inSelect) { + unsigned int theRowIndex = mRows; + InsertRows(1, theRowIndex, &inPlugin); + + if (mCols == 1) + InsertCols(1, mCols, NULL); + + SetMark(mRows, inSelect); + if (inSelect) { + TableCellT cell; + cell.row = mRows; + cell.col = 1; + SelectCell(cell); + } } -void T2AdvertiseTable::Add(CFilePluginList*) { +void T2AdvertiseTable::Add(CFilePluginList* inPluginList) { + int theSubType = GetUserCon(); + POSITION pos = inPluginList->GetHeadPosition(); + + while (pos) { + T2AdvertisePlugin *thePlugin = (T2AdvertisePlugin *) inPluginList->GetNext(pos); + if (thePlugin->GetSubType() == theSubType && !thePlugin->IsTieupFinish()) + Add(thePlugin, false); + } } -/*virtual*/ void T2AdvertiseTable::DrawCell(CDC*, const TableCellT&) { +/*virtual*/ void T2AdvertiseTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CFont font; + CPen pen; + CBrush brush; + + RECT cellRect; + if (FetchLocalCellFrame(inCell, cellRect) && inCell.col == 1) { + T2AdvertisePlugin *thePlugin; + GetCellData(inCell, &thePlugin); + if (thePlugin) { + DWORD theSubType = GetUserCon(); + int x = cellRect.left + 4; + int y = cellRect.bottom - 12; + + font.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + pDC->SelectObject(&font); + pDC->SetBkMode(TRANSPARENT); + + if (theSubType == 'CFPI') { + if (IsMark(inCell.row)) { + RECT rect; + rect.left = x; + rect.top = y; + rect.right = x + 4; + rect.bottom = y + 4; + + pen.CreateStockObject(BLACK_PEN); + brush.CreateStockObject(WHITE_BRUSH); + pDC->SelectObject(&pen); + pDC->SelectObject(&brush); + + pDC->MoveTo(rect.left + 2, rect.top + 3); + pDC->LineTo((rect.right + rect.left) / 2 - 2, rect.bottom - 1); + pDC->LineTo(rect.right - 1, rect.top - 1); + } + + x = cellRect.left + 20; + y = cellRect.bottom - 12; + } + + CString text; + thePlugin->GetName(text); + pDC->TextOutA(x, y, text, strlen(text)); + } + } + + pDC->RestoreDC(save); } -void T2AdvertiseTable::ClickCell(const TableCellT&, const CPoint&) { +void T2AdvertiseTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) { + T2DlgItemTable::ClickCell(inCell, inPt); + + if (IsValidCell(mSelectedCell) && mSelectedCell.col == 1) { + T2AdvertisePlugin *thePlugin; + GetCellData(mSelectedCell, &thePlugin); + if (thePlugin) + BroadcastMessage(GetDlgCtrlID(), thePlugin); + } } -int T2AdvertiseTable::IsMark(unsigned int) { +BOOL T2AdvertiseTable::IsMark(unsigned int inRow) { + void *data = NULL; + + TableCellT cell; + cell.row = inRow; + cell.col = 2; + GetCellData(cell, &data); + + return (data != NULL); } -void T2AdvertiseTable::SetMark(unsigned int, int) { +void T2AdvertiseTable::SetMark(unsigned int inRow, BOOL inValue) { + void *data = inValue ? this : NULL; + + TableCellT cell; + cell.row = inRow; + cell.col = 2; + SetCellData(cell, &data); + + InvalidateRect(NULL); } -/*virtual*/ void T2AdvertiseTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2AdvertiseTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + POINT pt = inPt; + ClientToView(&inPt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + + if (IsValidCell(cell)) + ClickCell(cell, inPt); } -/*virtual*/ int T2AdvertiseTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2AdvertiseTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC); + + unsigned int rows, cols; + GetTableSize(rows, cols); + + for (unsigned int col = 1; col <= cols; col++) { + for (unsigned int row = 1; row <= rows; row++) { + TableCellT cell; + cell.row = row; + cell.col = col; + DrawCell(pDC, cell); + } + } + + T2DlgItemTable::HiliteCell(pDC, mSelectedCell); + return true; } -/*virtual*/ void T2AdvertiseTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2AdvertiseTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + DrawCell(pDC, inCell); } diff --git a/src/T2DLL/T2AdvertiseTable.h b/src/T2DLL/T2AdvertiseTable.h index 4895db0..483df91 100644 --- a/src/T2DLL/T2AdvertiseTable.h +++ b/src/T2DLL/T2AdvertiseTable.h @@ -1,27 +1,27 @@ #pragma once #include "common.h" +#include "T2VerticalTable.h" -class T2AdvertiseTable { -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); -public: - T2AdvertiseTable(T2TowerDoc*, T2ImageObj*, CPalette*); - void Add(T2AdvertisePlugin*, int); - void Add(CFilePluginList*); -protected: - virtual void DrawCell(CDC*, const TableCellT&); - void ClickCell(const TableCellT&, const CPoint&); +class AFX_EXT_CLASS T2AdvertiseTable : public T2VerticalTable { public: - int IsMark(unsigned int); - void SetMark(unsigned int, int); -protected: - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void DrawCellSelf(CDC*, const TableCellT&, int); + T2AdvertiseTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual ~T2AdvertiseTable() {} + + void Add(T2AdvertisePlugin* inPlugin, BOOL inSelect); + void Add(CFilePluginList* inPluginList); + BOOL IsMark(unsigned int inRow); + void SetMark(unsigned int inRow, BOOL inValue); -public: - virtual ~T2AdvertiseTable() {} protected: - int GetUserCon() {} - void SetUserCon(int) {} + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + void ClickCell(const TableCellT& inCell, const CPoint& inPt); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + + int GetUserCon() { return mUserCon; } + void SetUserCon(int v) { mUserCon = v; } + + int mUserCon; }; diff --git a/src/T2DLL/T2Animation.cpp b/src/T2DLL/T2Animation.cpp index 5b4aea4..88f6abe 100644 --- a/src/T2DLL/T2Animation.cpp +++ b/src/T2DLL/T2Animation.cpp @@ -1,34 +1,144 @@ +#include "GlobalFunc.h" #include "T2Animation.h" +#include "T2BitImage.h" +#include "T2ImageObj.h" +#include "T2PluginSpecifier.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" -void T2Animation::Rewind() { -} +T2Animation::T2Animation(T2TowerDoc* inDoc, short inNumOfFrame, short inNumOfSprite, const SpriteDef* inSpriteDef, const AnimationDef* inAnimationDef, T2Sprite::ELayer inLayer) { + mDocument = inDoc; + mNumOfFrame = inNumOfFrame; + mNumOfSprite = inNumOfSprite; + mAnimationDef = inAnimationDef; -int T2Animation::HasNextStep() const { -} + mFrame = 0; + SetPt(&mPoint, 0, 0); -int T2Animation::SetFrame(int) { -} + int i; -int T2Animation::GetFrame() const { -} + short maxCount = 0; + for (i = 0; i < mNumOfSprite; i++) { + if (maxCount < inSpriteDef[i].count) + maxCount = inSpriteDef[i].count; + } + + HINSTANCE theModuleHandle = inDoc->mWorldPluginSpecifier->mInstance; + + mSpriteIndices = new int[inNumOfSprite]; +#line 41 + _ASSERT(mSpriteIndices != NULL); + + mImageObjs = (T2ImageObj **) malloc(sizeof(T2ImageObj *) * inNumOfSprite); +#line 43 + _ASSERT(mImageObjs != NULL); + + mImages = (T2BitImage **) malloc(sizeof(T2BitImage *) * inNumOfSprite); +#line 45 + _ASSERT(mImages != NULL); + + for (i = 0; i < mNumOfSprite; i++) { + CString name; + name.Format("__Anime__%d", i); + + T2ImageObj *theImageObj = new T2ImageObj; + mImageObjs[i] = theImageObj; + + T2BitImage *theImage = new T2BitImage(theModuleHandle, inSpriteDef[i].resID, true); + mImages[i] = theImage; -T2Animation::T2Animation(T2TowerDoc*, short, short, const SpriteDef*, const AnimationDef*, T2Sprite::ELayer) { + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = inSpriteDef[i].width; + rect.bottom = inSpriteDef[i].height; + + for (short j = 0; j < inSpriteDef[i].count; j++) { + theImageObj->AddObject(name, j + 1, *theImage, &rect, true, false); + OffsetRect(&rect, 0, inSpriteDef[i].height); + } + + mSpriteIndices[i] = mDocument->mSprite.NewSprite(*theImageObj, name, inLayer); + } } T2Animation::~T2Animation() { + for (int i = 0; i < mNumOfSprite; i++) + mDocument->mSprite.DeleteSprite(mSpriteIndices[i]); + delete[] mSpriteIndices; + + if (mImageObjs) { + for (int i = 0; i < mNumOfSprite; i++) { + if (mImageObjs[i]) + delete mImageObjs[i]; + } + free(mImageObjs); + } + + if (mImages) { + for (int i = 0; i < mNumOfSprite; i++) { + if (mImages[i]) + delete mImages[i]; + } + free(mImages); + } } -int T2Animation::Start(POINT, int) { +BOOL T2Animation::Start(POINT inPt, int inLen) { + mPoint = inPt; + mInterval = 60 / inLen; + mTickCount = GetTickCount(); + + Draw(); + return HasNextStep(); } -int T2Animation::Idle() { +BOOL T2Animation::Idle() { + int newFrame = (GetTickCount() - mTickCount) / mInterval; + if (newFrame != mFrame) { + mFrame = newFrame; + Draw(); + } + + return HasNextStep(); } -void T2Animation::Play(POINT, int) { +void T2Animation::Play(POINT inPt, int inLen) { + mPoint = inPt; + + int delay = 60 / inLen; + int endTick = GetTickCount() + delay; + BOOL playing = mFrame < mNumOfFrame; + + while (playing) { + playing = Step(); + mDocument->GetTowerMainView()->tmv_vf120(); + + int now; + for (now = GetTickCount(); now < endTick; now = GetTickCount()) { + // nothing there! + } + + endTick = now + delay; + } } -int T2Animation::Step() { +BOOL T2Animation::Step() { + Draw(); + mFrame++; + return (mFrame < mNumOfFrame); } void T2Animation::Draw() { + if (HasNextStep()) { + for (int i = 0; i < mNumOfSprite; i++) { + const AnimationDef *def = mAnimationDef + (mFrame * mNumOfSprite) + i; + + CPoint pt = mPoint; + pt.Offset(def->position); + mDocument->mSprite.MoveSprite(mSpriteIndices[i], pt); + mDocument->mSprite.ChangePattern(mSpriteIndices[i], def->pattern); + mDocument->mSprite.ShowSprite(mSpriteIndices[i], true); + } + } } diff --git a/src/T2DLL/T2Animation.h b/src/T2DLL/T2Animation.h index 410a449..a7bd371 100644 --- a/src/T2DLL/T2Animation.h +++ b/src/T2DLL/T2Animation.h @@ -1,18 +1,50 @@ #pragma once #include "common.h" +#include "T2Sprite.h" -class T2Animation { +struct AnimationDef { + POINT position; + short pattern; +}; + +struct SpriteDef { + unsigned int resID; + short count; + short width; + short height; +}; + +class AFX_EXT_CLASS T2Animation { public: - void Rewind(); - int HasNextStep() const; - int SetFrame(int); - int GetFrame() const; - T2Animation(T2TowerDoc*, short, short, const SpriteDef*, const AnimationDef*, T2Sprite::ELayer); + T2Animation(T2TowerDoc* inDoc, short inNumOfFrame, short inNumOfSprite, const SpriteDef* inSpriteDef, const AnimationDef* inAnimationDef, T2Sprite::ELayer inLayer); ~T2Animation(); - int Start(POINT, int); - int Idle(); - void Play(POINT, int); - int Step(); + BOOL Start(POINT inPt, int inLen); + BOOL Idle(); + void Play(POINT inPt, int inLen); + BOOL Step(); + + void Rewind() { SetFrame(0); } + BOOL HasNextStep() const { + return (mFrame >= 0) && (mFrame < mNumOfFrame); + } + BOOL SetFrame(int inFrame) { + mFrame = inFrame; + return HasNextStep(); + } + int GetFrame() const { return mFrame; } + protected: void Draw(); + + T2TowerDoc *mDocument; + short mNumOfFrame; + short mNumOfSprite; + const AnimationDef *mAnimationDef; + int *mSpriteIndices; + T2ImageObj **mImageObjs; + T2BitImage **mImages; + POINT mPoint; + short mFrame; + int mInterval; + DWORD mTickCount; }; diff --git a/src/T2DLL/T2Archive.h b/src/T2DLL/T2Archive.h index f24a386..d387180 100644 --- a/src/T2DLL/T2Archive.h +++ b/src/T2DLL/T2Archive.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2Archive { +class AFX_EXT_CLASS T2Archive { public: T2Archive(); virtual ~T2Archive(); diff --git a/src/T2DLL/T2ArrowWnd.cpp b/src/T2DLL/T2ArrowWnd.cpp index 495f0b9..0271881 100644 --- a/src/T2DLL/T2ArrowWnd.cpp +++ b/src/T2DLL/T2ArrowWnd.cpp @@ -1,13 +1,13 @@ +#include "GlobalFunc.h" #include "T2ArrowWnd.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" -/*static*/ CObject* __stdcall T2ArrowWnd::CreateObject() { -} - -/*static*/ CRuntimeClass* __stdcall T2ArrowWnd::_GetBaseClass() { -} - -/*virtual*/ CRuntimeClass* T2ArrowWnd::GetRuntimeClass() const { +CObject* PASCAL T2ArrowWnd::CreateObject() { +#line 33 + return DEBUG_NEW T2ArrowWnd; } +IMPLEMENT_DYNAMIC(T2ArrowWnd, CFrameWnd); T2ArrowWnd::T2ArrowWnd() { } @@ -15,29 +15,87 @@ T2ArrowWnd::T2ArrowWnd() { /*virtual*/ T2ArrowWnd::~T2ArrowWnd() { } -void T2ArrowWnd::Show(int, int, T2TowerDoc*) { -} +static POINT rgnPoints[7] = { + {20,35}, + {0, 15}, + {10,15}, + {10,0}, + {30,0}, + {30,15}, + {40,15} +}; -/*static*/ const AFX_MSGMAP* __stdcall T2ArrowWnd::_GetBaseMessageMap() { -} +void T2ArrowWnd::Show(int inX, int inY, T2TowerDoc* inDoc) { + mWndClass = AfxRegisterWndClass(CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); -/*virtual*/ const AFX_MSGMAP* T2ArrowWnd::GetMessageMap() const { -} + CRect rect1(0, 0, 50, 50); + Create(mWndClass, "ArrowWnd", WS_CHILD, rect1, inDoc->GetTowerMainView(), NULL, WS_EX_TOPMOST); -int T2ArrowWnd::OnEraseBkgnd(CDC*) { -} + mRgn.CreatePolygonRgn(rgnPoints, 7, ALTERNATE); -void T2ArrowWnd::OnTimer(unsigned int) { -} + CRect rect2; + GetClientRect(rect2); + + CPoint pt; + pt.x = ((rect1.right - rect1.left) - (rect2.right - rect2.left)) / 2; + pt.y = ((rect1.bottom - rect1.top) - (rect2.bottom - rect2.top)) / 2; + + CRgn rgn; + rgn.CreateRectRgn(0, 0, 1, 1); + rgn.CopyRgn(&mRgn); + rgn.OffsetRgn(pt.x, pt.y); + SetWindowRgn(rgn, true); + rgn.Detach(); + SetWindowPos(NULL, inX - 20, inY - 45, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); + + GetCurrentT2TowerDoc()->towerDoc_vf290(true); + GetCurrentT2TowerDoc()->towerDoc_vf1A0(true); -void T2ArrowWnd::OnDestroy() { + mCounter = 0; + SetTimer(1, 50, NULL); } -/*static*/ const CRuntimeClass T2ArrowWnd::classT2ArrowWnd { +BEGIN_MESSAGE_MAP(T2ArrowWnd, CFrameWnd) + ON_WM_ERASEBKGND() + ON_WM_TIMER() + ON_WM_DESTROY() +END_MESSAGE_MAP() + +afx_msg BOOL T2ArrowWnd::OnEraseBkgnd(CDC* pDC) { + int save = pDC->SaveDC(); + { + CRect rect; + GetClientRect(rect); + + pDC->FillSolidRect(rect, (mCounter & 1) ? RGB(255, 0, 0) : RGB(255, 255, 0)); + + CBrush brush; + brush.CreateStockObject(BLACK_BRUSH); + pDC->FrameRgn(&mRgn, &brush, 1, 1); + } + pDC->RestoreDC(save); + return true; } -/*static*/ const AFX_MSGMAP T2ArrowWnd::messageMap { +afx_msg void T2ArrowWnd::OnTimer(UINT nIDEvent) { + if (nIDEvent == 1) { + if (mCounter == 0) + ShowWindow(SW_SHOWNA); + + mCounter++; + if (mCounter > 30) { + ShowWindow(SW_HIDE); + DestroyWindow(); + } else { + InvalidateRect(NULL); + } + } } -/*static*/ const AFX_MSGMAP_ENTRY* const T2ArrowWnd::_messageEntries { +afx_msg void T2ArrowWnd::OnDestroy() { + CFrameWnd::OnDestroy(); + DeleteObject(mRgn); + GetCurrentT2TowerDoc()->towerDoc_vf294(); + GetCurrentT2TowerDoc()->towerDoc_vf1A0(false); + KillTimer(1); } diff --git a/src/T2DLL/T2ArrowWnd.h b/src/T2DLL/T2ArrowWnd.h index 23c08d7..6c699b6 100644 --- a/src/T2DLL/T2ArrowWnd.h +++ b/src/T2DLL/T2ArrowWnd.h @@ -1,26 +1,20 @@ #pragma once #include "common.h" -class T2ArrowWnd { -public: - static CObject* __stdcall CreateObject(); -protected: - static CRuntimeClass* __stdcall _GetBaseClass(); +class AFX_EXT_CLASS T2ArrowWnd : public CFrameWnd { + DECLARE_DYNCREATE(T2ArrowWnd) + DECLARE_MESSAGE_MAP() + public: - virtual CRuntimeClass* GetRuntimeClass() const; T2ArrowWnd(); virtual ~T2ArrowWnd(); - void Show(int, int, T2TowerDoc*); -protected: - static const AFX_MSGMAP* __stdcall _GetBaseMessageMap(); - virtual const AFX_MSGMAP* GetMessageMap() const; - int OnEraseBkgnd(CDC*); - void OnTimer(unsigned int); - void OnDestroy(); -public: - static const CRuntimeClass classT2ArrowWnd; + void Show(int inX, int inY, T2TowerDoc* inDoc); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnTimer(UINT nIDEvent); + afx_msg void OnDestroy(); + protected: - static const AFX_MSGMAP messageMap; -private: - static const AFX_MSGMAP_ENTRY* const _messageEntries; + CString mWndClass; + CRgn mRgn; + unsigned short mCounter; }; diff --git a/src/T2DLL/T2Balloon.cpp b/src/T2DLL/T2Balloon.cpp index 100918f..d8815da 100644 --- a/src/T2DLL/T2Balloon.cpp +++ b/src/T2DLL/T2Balloon.cpp @@ -1,10 +1,242 @@ +#include "GlobalFunc.h" #include "T2Balloon.h" +#include "T2BitImage.h" +#include "T2ImageObj.h" +#include "T2Sprite.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" T2Balloon::T2Balloon() { + mImage = NULL; + mImageObj = NULL; + mDoPause = false; } /*virtual*/ T2Balloon::~T2Balloon() { + if (mDoPause) + GetCurrentT2TowerDoc()->towerDoc_vf290(true); + + T2Sprite *theSprite = &GetCurrentT2TowerDoc()->mSprite; + theSprite->ShowSprite(mSpriteID, false); + theSprite->DeleteSprite(mSpriteID); + + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; } -void T2Balloon::Show(int, int, const CString&, int) { +#pragma var_order(rect4, rect8, rect5, brush3, rect6, font, theSprite, bits, rect1, save, rect7, dc, rgn, rgn4, rect2, var, brush1, dib, thePalette, topLeft, rect3, brush2) +void T2Balloon::Show(int inX, int inY, const CString& inText, BOOL inDoPause) { + CFont font; + CRect rect1; + CRect rect2; + CRgn rgn; + CRect rect3(0, 0, 0, 0); + + mDoPause = inDoPause; + + font.CreateFontA(-12, 0, 0, 0, FW_NORMAL, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"); + + CDC dc; + dc.CreateCompatibleDC(NULL); + int save = dc.SaveDC(); + + dc.SelectObject(font); + rect1.SetRectEmpty(); + // 123456789012345 + dc.DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54", &rect1, DT_SINGLELINE | DT_CALCRECT); + dc.DrawText(inText, &rect1, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); + + rect1.NormalizeRect(); + rect1.OffsetRect(-rect1.left, -rect1.top); + + rect2.SetRect(10, 10, 10, 10); + rect1.OffsetRect(rect2.left, rect2.top); + + CRect rect4; + GetCurrentT2TowerDoc()->GetTowerMainView()->tmv_vf140(rect4); + UT2Coordinate::UnitToQD(rect4, 0); + + CRect rect5; + rect5 = rect1; + rect5 += rect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX, inY - rect5.Height()); + int var = 1; + + CRect rect6; + if (rect6.SubtractRect(rect5, rect4)) { + rect5 = rect1; + rect5 += rect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX - rect5.Width(), inY - rect5.Height()); + var = 0; + + if (rect6.SubtractRect(rect5, rect4)) { + rect5 = rect1; + rect5 += rect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX, inY); + var = 3; + + if (rect6.SubtractRect(rect5, rect4)) { + rect5 = rect1; + rect5 += rect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX - rect5.Width(), inY); + var = 2; + } + } + } + + rect5 += rect3; + POINT topLeft = rect5.TopLeft(); + rect5 -= rect3; + + rect5.OffsetRect(-rect5.left, -rect5.top); + + CRect rect7(1, 1, 1, 1); + rect5 -= rect7; + + if (var == 1) { + rgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom - 16, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.left + 10; + arrowPoints[0].y = rect5.bottom - 18; + arrowPoints[1].x = rect5.left; + arrowPoints[1].y = rect5.bottom; + arrowPoints[2].x = rect5.left + 21; + arrowPoints[2].y = rect5.bottom - 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + rgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else if (var == 0) { + rgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom - 16, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.right - 10; + arrowPoints[0].y = rect5.bottom - 18; + arrowPoints[1].x = rect5.right; + arrowPoints[1].y = rect5.bottom; + arrowPoints[2].x = rect5.right - 21; + arrowPoints[2].y = rect5.bottom - 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + rgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else if (var == 3) { + rect1.OffsetRect(0, 16); + rgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top + 16, rect5.right, rect5.bottom, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.left + 10; + arrowPoints[0].y = rect5.top + 18; + arrowPoints[1].x = rect5.left; + arrowPoints[1].y = rect5.top; + arrowPoints[2].x = rect5.left + 21; + arrowPoints[2].y = rect5.top + 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + rgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else if (var == 2) { + rect1.OffsetRect(0, 16); + rgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top + 16, rect5.right, rect5.bottom, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.right - 10; + arrowPoints[0].y = rect5.top + 18; + arrowPoints[1].x = rect5.right; + arrowPoints[1].y = rect5.top; + arrowPoints[2].x = rect5.right - 21; + arrowPoints[2].y = rect5.top + 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + rgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else { + rgn.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom, 20, 20); + } + + CRgn rgn4; + rgn4.CreateRectRgn(0, 0, 1, 1); + rgn4.CopyRgn(&rgn); + rgn4.OffsetRgn(rect3.left, rect3.top); + + CRect rect8; + rect8.top = 0; + rect8.left = 0; + rect8.bottom = ((rect5.Height() + 3) / 4) * 4; + rect8.right = ((rect5.Width() + 3) / 4) * 4; + +#line 201 + mImage = DEBUG_NEW T2BitImage(rect8); + mImage->Clear(0); + + CPalette *thePalette = GetCurrentT2TowerDoc()->towerDoc_vf170()->GetPalette(); + dc.SelectPalette(thePalette, false); + dc.RealizePalette(); + + mImage->mBitmap.header.biHeight = -mImage->mBitmap.header.biHeight; + void *bits; + HBITMAP dib = CreateDIBSection(dc.m_hDC, (BITMAPINFO *) &mImage->mBitmap.header, DIB_PAL_COLORS, &bits, NULL, 0); + mImage->mBitmap.header.biHeight = -mImage->mBitmap.header.biHeight; + + dc.SelectObject(dib); + + CBrush brush1; + CBrush brush2; + CBrush brush3; + brush3.CreateSolidBrush(PALETTEINDEX(0)); + brush1.CreateSolidBrush(PALETTEINDEX(255)); + brush2.CreateSolidBrush(PALETTEINDEX(1)); + + dc.FillRect(rect8, &brush3); + dc.FillRgn(&rgn, &brush2); + dc.FrameRgn(&rgn, &brush1, 2, 2); + + dc.SetBkMode(TRANSPARENT); + dc.SetTextColor(PALETTEINDEX(255)); + dc.SelectObject(font); + dc.DrawText(inText, &rect1, DT_WORDBREAK | DT_NOPREFIX); + dc.RestoreDC(save); + + memcpy(mImage->mData, bits, mImage->mBitmap.header.biSizeImage); + DeleteObject(dib); + +#line 233 + mImageObj = DEBUG_NEW T2ImageObj; + mImageObj->AddObject("BAL", 0, *mImage, rect8, true, false); + + T2Sprite *theSprite = &GetCurrentT2TowerDoc()->mSprite; + mSpriteID = theSprite->NewSprite(*mImageObj, "BAL", T2Sprite::ELayer_6); + + theSprite->MoveSprite(mSpriteID, POINT(topLeft)); + theSprite->ShowSprite(mSpriteID, true); + + if (mDoPause) + GetCurrentT2TowerDoc()->towerDoc_vf290(true); + + mEndTime = GetTickCount() + 1500; } diff --git a/src/T2DLL/T2Balloon.h b/src/T2DLL/T2Balloon.h index e7c0bc1..6b0d17c 100644 --- a/src/T2DLL/T2Balloon.h +++ b/src/T2DLL/T2Balloon.h @@ -1,12 +1,18 @@ #pragma once #include "common.h" -class T2Balloon { +class AFX_EXT_CLASS T2Balloon { public: T2Balloon(); virtual ~T2Balloon(); - void Show(int, int, const CString&, int); + void Show(int inX, int inY, const CString& inText, BOOL inDoPause); - T2Balloon(const T2Balloon&) {} - T2Balloon& operator=(const T2Balloon&) {} +protected: + friend class T2TowerMessage; + + DWORD mEndTime; + BOOL mDoPause; + T2BitImage *mImage; + T2ImageObj *mImageObj; + int mSpriteID; }; diff --git a/src/T2DLL/T2BalloonWnd.cpp b/src/T2DLL/T2BalloonWnd.cpp index a17dc4f..df8285f 100644 --- a/src/T2DLL/T2BalloonWnd.cpp +++ b/src/T2DLL/T2BalloonWnd.cpp @@ -1,52 +1,288 @@ +#include "GlobalFunc.h" #include "T2BalloonWnd.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" -/*static*/ CObject* __stdcall T2BalloonWnd::CreateObject() { -} - -/*static*/ CRuntimeClass* __stdcall T2BalloonWnd::_GetBaseClass() { -} - -/*virtual*/ CRuntimeClass* T2BalloonWnd::GetRuntimeClass() const { +CObject* PASCAL T2BalloonWnd::CreateObject() { +#line 16 + return DEBUG_NEW T2BalloonWnd; } +IMPLEMENT_DYNAMIC(T2BalloonWnd, CFrameWnd); T2BalloonWnd::T2BalloonWnd() { + mVisible = false; } /*virtual*/ T2BalloonWnd::~T2BalloonWnd() { } -/*static*/ const AFX_MSGMAP* __stdcall T2BalloonWnd::_GetBaseMessageMap() { -} +BEGIN_MESSAGE_MAP(T2BalloonWnd, CFrameWnd) + ON_WM_ERASEBKGND() + ON_WM_LBUTTONDOWN() + ON_WM_RBUTTONDOWN() + ON_WM_MOUSEMOVE() + ON_WM_TIMER() + ON_WM_DESTROY() +END_MESSAGE_MAP() -/*virtual*/ const AFX_MSGMAP* T2BalloonWnd::GetMessageMap() const { -} +#pragma var_order(rect4, rect5, rect1, save, rect7, rgn4, rect2, rect3, pDC) +void T2BalloonWnd::Show(int inX, int inY, const CString& inText, BOOL inIsPause) { + mIsPause = inIsPause; -void T2BalloonWnd::Show(int, int, const CString&, int) { -} + mFont.CreatePointFont(100, "\x82\x6C\x82\x72 \x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"); -int T2BalloonWnd::OnEraseBkgnd(CDC*) { -} + mWndClass = AfxRegisterWndClass(CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); -void T2BalloonWnd::OnLButtonDown(unsigned int, CPoint) { -} + CRect rect1(0, 0, 50, 50); + Create(mWndClass, inText, WS_POPUP, rect1, AfxGetMainWnd(), NULL, WS_EX_TOPMOST); + + CRect rect2; + GetClientRect(rect2); + ClientToScreen(rect2); + + CRect rect3; + rect3.top = rect2.top - rect1.top; + rect3.left = rect2.left - rect1.left; + rect3.bottom = rect1.bottom - rect2.bottom; + rect3.right = rect1.right - rect2.right; + + CDC *pDC = GetDC(); + int save = pDC->SaveDC(); + pDC->SelectObject(mFont); + + mRect1.SetRectEmpty(); + // 123456789012345 + pDC->DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54", &mRect1, DT_SINGLELINE | DT_CALCRECT); + pDC->DrawText(inText, &mRect1, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); + + mRect1.NormalizeRect(); + mRect1.OffsetRect(-mRect1.left, -mRect1.top); + + mRect2.SetRect(10, 10, 10, 10); + mRect1.OffsetRect(mRect2.left, mRect2.top); + + CRect rect4; + GetDesktopWindow()->GetClientRect(rect4); + + CRect rect5; + rect5 = mRect1; + rect5 += mRect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX, inY - rect5.Height()); + mDirection = 1; + + if (rect1.SubtractRect(rect5, rect4)) { + rect5 = mRect1; + rect5 += mRect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX - rect5.Width(), inY - rect5.Height()); + mDirection = 0; + + if (rect1.SubtractRect(rect5, rect4)) { + rect5 = mRect1; + rect5 += mRect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX, inY); + mDirection = 3; + + if (rect1.SubtractRect(rect5, rect4)) { + rect5 = mRect1; + rect5 += mRect2; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(inX - rect5.Width(), inY); + mDirection = 2; + } + } + } + + rect5 += rect3; + SetWindowPos(NULL, rect5.left, rect5.top, rect5.Width(), rect5.Height(), SWP_NOZORDER | SWP_NOACTIVATE); + rect5 -= rect3; + + rect5.OffsetRect(-rect5.left, -rect5.top); + + CRect rect7(1, 1, 1, 1); + rect5 -= rect7; + + if (mDirection == 1) { + mRgn.CreateRectRgn(0, 0, 1, 1); -void T2BalloonWnd::OnRButtonDown(unsigned int, CPoint) { + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom - 16, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.left + 10; + arrowPoints[0].y = rect5.bottom - 18; + arrowPoints[1].x = rect5.left; + arrowPoints[1].y = rect5.bottom; + arrowPoints[2].x = rect5.left + 21; + arrowPoints[2].y = rect5.bottom - 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else if (mDirection == 0) { + mRgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom - 16, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.right - 10; + arrowPoints[0].y = rect5.bottom - 18; + arrowPoints[1].x = rect5.right; + arrowPoints[1].y = rect5.bottom; + arrowPoints[2].x = rect5.right - 21; + arrowPoints[2].y = rect5.bottom - 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else if (mDirection == 3) { + mRect1.OffsetRect(0, 16); + mRgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top + 16, rect5.right, rect5.bottom, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.left + 10; + arrowPoints[0].y = rect5.top + 18; + arrowPoints[1].x = rect5.left; + arrowPoints[1].y = rect5.top; + arrowPoints[2].x = rect5.left + 21; + arrowPoints[2].y = rect5.top + 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else if (mDirection == 2) { + mRect1.OffsetRect(0, 16); + mRgn.CreateRectRgn(0, 0, 1, 1); + + CRgn baseRegion; + baseRegion.CreateRoundRectRgn(rect5.left, rect5.top + 16, rect5.right, rect5.bottom, 20, 20); + + CRgn arrowRegion; + POINT arrowPoints[3]; + arrowPoints[0].x = rect5.right - 10; + arrowPoints[0].y = rect5.top + 18; + arrowPoints[1].x = rect5.right; + arrowPoints[1].y = rect5.top; + arrowPoints[2].x = rect5.right - 21; + arrowPoints[2].y = rect5.top + 18; + arrowRegion.CreatePolygonRgn(arrowPoints, 3, ALTERNATE); + mRgn.CombineRgn(&baseRegion, &arrowRegion, RGN_OR); + } else { + mRgn.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom, 20, 20); + } + + CRgn rgn4; + rgn4.CreateRectRgn(0, 0, 1, 1); + rgn4.CopyRgn(&mRgn); + rgn4.OffsetRgn(rect3.left, rect3.top); + ::SetWindowRgn(m_hWnd, rgn4, true); + + rgn4.Detach(); + pDC->RestoreDC(save); + ReleaseDC(pDC); + + ShowWindow(SW_SHOWNA); + SetCapture(); + + mVisible = true; + GetCursorPos(&mStartCursorPos); + + if (mIsPause) + GetCurrentT2TowerDoc()->towerDoc_vf290(true); + + SetTimer(1, 1500, NULL); } -void T2BalloonWnd::OnMouseMove(unsigned int, CPoint) { +#pragma var_order(brush, text, save, clientRect) +afx_msg BOOL T2BalloonWnd::OnEraseBkgnd(CDC* pDC) { + int save = pDC->SaveDC(); + + CRect clientRect; + GetClientRect(clientRect); + pDC->FillSolidRect(clientRect, RGB(255, 255, 255)); + + CBrush brush; + brush.CreateStockObject(BLACK_BRUSH); + pDC->FrameRgn(&mRgn, &brush, 1, 1); + + pDC->SetBkMode(TRANSPARENT); + pDC->SetTextColor(RGB(0, 0, 0)); + pDC->SelectObject(mFont); + + CString text; + GetWindowText(text); + pDC->DrawText(text, &mRect1, DT_WORDBREAK | DT_NOPREFIX); + + pDC->RestoreDC(save); + + return true; } -void T2BalloonWnd::OnTimer(unsigned int) { +afx_msg void T2BalloonWnd::OnLButtonDown(UINT nFlags, CPoint point) { + ClientToScreen(&point); + ShowWindow(SW_HIDE); + ReleaseCapture(); + mVisible = false; + DestroyWindow(); + + CWnd *belowWindow = WindowFromPoint(point); + if (belowWindow->m_hWnd == ((CFrameWnd *) AfxGetMainWnd())->GetActiveView()->m_hWnd) { + belowWindow->ScreenToClient(&point); + belowWindow->SendMessage(WM_LBUTTONDOWN, nFlags, MAKELONG(point.x, point.y)); + } } -void T2BalloonWnd::OnDestroy() { +afx_msg void T2BalloonWnd::OnRButtonDown(UINT nFlags, CPoint point) { + ClientToScreen(&point); + ShowWindow(SW_HIDE); + ReleaseCapture(); + mVisible = false; + DestroyWindow(); + + CWnd *belowWindow = WindowFromPoint(point); + if (belowWindow->m_hWnd == ((CFrameWnd *) AfxGetMainWnd())->GetActiveView()->m_hWnd) { + belowWindow->ScreenToClient(&point); + belowWindow->SendMessage(WM_RBUTTONDOWN, nFlags, MAKELONG(point.x, point.y)); + } } -/*static*/ const CRuntimeClass T2BalloonWnd::classT2BalloonWnd { +afx_msg void T2BalloonWnd::OnMouseMove(UINT nFlags, CPoint point) { + POINT cursor; + GetCursorPos(&cursor); + + if (abs(mStartCursorPos.x - cursor.x) > 3 || abs(mStartCursorPos.y - cursor.y) > 3) { + ShowWindow(SW_HIDE); + ReleaseCapture(); + mVisible = false; + DestroyWindow(); + } } -/*static*/ const AFX_MSGMAP T2BalloonWnd::messageMap { +afx_msg void T2BalloonWnd::OnTimer(UINT nIDEvent) { + if (nIDEvent == 1) { + ShowWindow(SW_HIDE); + ReleaseCapture(); + mVisible = false; + DestroyWindow(); + } } -/*static*/ const AFX_MSGMAP_ENTRY* const T2BalloonWnd::_messageEntries { +afx_msg void T2BalloonWnd::OnDestroy() { + CFrameWnd::OnDestroy(); + + if (mIsPause) + GetCurrentT2TowerDoc()->towerDoc_vf294(); + + KillTimer(1); } diff --git a/src/T2DLL/T2BalloonWnd.h b/src/T2DLL/T2BalloonWnd.h index 35cd1a2..b69302e 100644 --- a/src/T2DLL/T2BalloonWnd.h +++ b/src/T2DLL/T2BalloonWnd.h @@ -1,31 +1,30 @@ #pragma once #include "common.h" -class T2BalloonWnd { -public: - static CObject* __stdcall CreateObject(); -protected: - static CRuntimeClass* __stdcall _GetBaseClass(); +class AFX_EXT_CLASS T2BalloonWnd : public CFrameWnd { + DECLARE_DYNCREATE(T2BalloonWnd) + DECLARE_MESSAGE_MAP() + public: - virtual CRuntimeClass* GetRuntimeClass() const; T2BalloonWnd(); virtual ~T2BalloonWnd(); + void Show(int inX, int inY, const CString& inText, BOOL inIsPause); + protected: - static const AFX_MSGMAP* __stdcall _GetBaseMessageMap(); - virtual const AFX_MSGMAP* GetMessageMap() const; -public: - void Show(int, int, const CString&, int); -protected: - int OnEraseBkgnd(CDC*); - void OnLButtonDown(unsigned int, CPoint); - void OnRButtonDown(unsigned int, CPoint); - void OnMouseMove(unsigned int, CPoint); - void OnTimer(unsigned int); - void OnDestroy(); -public: - static const CRuntimeClass classT2BalloonWnd; -protected: - static const AFX_MSGMAP messageMap; -private: - static const AFX_MSGMAP_ENTRY* const _messageEntries; + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnLButtonDown(UINT nFlags, CPoint point); + afx_msg void OnRButtonDown(UINT nFlags, CPoint point); + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg void OnTimer(UINT nIDEvent); + afx_msg void OnDestroy(); + + CFont mFont; + CString mWndClass; + CRect mRect1; + CRect mRect2; + int mDirection; + CRgn mRgn; + BOOL mVisible; + POINT mStartCursorPos; + BOOL mIsPause; }; diff --git a/src/T2DLL/T2BitImage.h b/src/T2DLL/T2BitImage.h index 5e23a62..8486bda 100644 --- a/src/T2DLL/T2BitImage.h +++ b/src/T2DLL/T2BitImage.h @@ -7,7 +7,7 @@ struct Bitmap { short palette[256]; }; -class DLL_EXPORT T2BitImage { +class AFX_EXT_CLASS T2BitImage { public: T2BitImage(const char* path, unsigned int id, BOOL flip); T2BitImage(HINSTANCE path, unsigned int id, BOOL flip); @@ -17,8 +17,8 @@ public: BOOL BeginDrawing(); void EndDrawing(); - void CopyImage(T2BitImage&, const RECT&, const RECT&, int, CRgn*); - void CopyImage(CDC*, const RECT&, const RECT&, int, CRgn*); + void CopyImage(T2BitImage&, const RECT&, const RECT&, int unk = 0, CRgn* rgn = NULL); + void CopyImage(CDC*, const RECT&, const RECT&, int unk = 0, CRgn* rgn = NULL); void Clear(int); void SetBackGndColor(int); void SetForeGndColor(int); @@ -35,14 +35,6 @@ public: int GetParam() { return mParam; } void SetParam(int v) { mParam = v; } -protected: - friend class T2ImageObj; - - void SetupBitmap(BITMAPINFO* info, BOOL flip); - void DrawFocusRect2(RECT); - void DrawFocusLine(int, int, int, int); - void DrawFrameLine(int, int, int, int, int); - Bitmap mBitmap; unsigned char *mData; POINT mOrigin; @@ -53,4 +45,10 @@ protected: BOOL mHasClipRect; BOOL mHalftoneMode; int mParam; + +protected: + void SetupBitmap(BITMAPINFO* info, BOOL flip); + void DrawFocusRect2(RECT); + void DrawFocusLine(int, int, int, int); + void DrawFrameLine(int, int, int, int, int); }; diff --git a/src/T2DLL/T2BlackOut.cpp b/src/T2DLL/T2BlackOut.cpp index c80bafb..7194f16 100644 --- a/src/T2DLL/T2BlackOut.cpp +++ b/src/T2DLL/T2BlackOut.cpp @@ -1,49 +1,261 @@ +#include "CFilePluginList.h" +#include "CProgramPlugin.h" +#include "CResFile.h" +#include "T2Archive.h" #include "T2BlackOut.h" +#include "T2DateTime.h" +#include "T2MainWindow.h" +#include "T2PeopleArrayList.h" +#include "T2TemplatePlugin.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2TowerMessage.h" -T2BlackOut::T2BlackOut(T2TowerEvent*, CResFile*, int) { +T2BlackOut::T2BlackOut(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + *inResFile >> mDefSupply; + *inResFile >> mAddSupply; + *inResFile >> mTransforPrice; + + mConsumptionPower = 0; + mSupplyPower = mDefSupply; + m44 = 0; + m48 = 0; + mAttach = NULL; } /*virtual*/ T2BlackOut::~T2BlackOut() { } -/*virtual*/ int T2BlackOut::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2BlackOut::Start(T2TowerDoc* inDoc) { + mStatus = kBlackOutStatus0; + + if (mConsumptionPower > mSupplyPower) { + mStatus = kBlackOutStatus1; + + T2TowerMainView *theView = inDoc->GetTowerMainView(); + if (theView) { + inDoc->towerDoc_vf284(); + + mAttach = new T2BlackOutAttach(this, 0, true); + theView->AddAttachment(mAttach, NULL, true); + } + + // "停電です\r\n" - Blackout + CString text = "\x92\xE2\x93\x64\x82\xC5\x82\xB7\r\n"; + + if (mSupplyPower == mDefSupply) { + // "ビル内の電力供給がこのままでは間に合いません。" + // The power supply in the building will not be in time as it is. + text += "\x83\x72\x83\x8B\x93\xE0\x82\xCC\x93\x64\x97\xCD\x8B\x9F\x8B\x8B\x82\xAA\x82\xB1\x82\xCC\x82\xDC\x82\xDC\x82\xC5\x82\xCD\x8A\xD4\x82\xC9\x8D\x87\x82\xA2\x82\xDC\x82\xB9\x82\xF1\x81\x42"; + + // "至急変電室を設置" + // Set up an emergency substation room + text += "\x8E\x8A\x8B\x7D\x95\xCF\x93\x64\x8E\xBA\x82\xF0\x90\xDD\x92\x75"; + } else { + // "変電室にあるブレーカーを全てオンにすれば一時的に停電は回復しますが、" + // If you turn on all the breakers in the substation room, the power + // outage will be restored temporarily, + text += "\x95\xCF\x93\x64\x8E\xBA\x82\xC9\x82\xA0\x82\xE9\x83\x75\x83\x8C\x81\x5B\x83\x4A\x81\x5B\x82\xF0\x91\x53\x82\xC4\x83\x49\x83\x93\x82\xC9\x82\xB7\x82\xEA\x82\xCE\x88\xEA\x8E\x9E\x93\x49\x82\xC9\x92\xE2\x93\x64\x82\xCD\x89\xF1\x95\x9C\x82\xB5\x82\xDC\x82\xB7\x82\xAA\x81\x41"; + + // "変圧器を増設" + // Add a transformer + text += "\x95\xCF\x88\xB3\x8A\xED\x82\xF0\x91\x9D\x90\xDD"; + } + + // "するかテナントを撤去する等の対処が必要です。" + // It is necessary to take measures such as removing the tenant + // or removing the tenant. + text += "\x82\xB7\x82\xE9\x82\xA9\x83\x65\x83\x69\x83\x93\x83\x67\x82\xF0\x93\x50\x8B\x8E\x82\xB7\x82\xE9\x93\x99\x82\xCC\x91\xCE\x8F\x88\x82\xAA\x95\x4B\x97\x76\x82\xC5\x82\xB7\x81\x42"; + + DoDialog(inDoc, 8400, 8400, 2, text); + inDoc->mPeopleArrayList->AddStress(30); + } + + return (mStatus != kBlackOutStatus0); } -/*virtual*/ int T2BlackOut::Exec(T2TowerDoc*) { +/*virtual*/ int T2BlackOut::Exec(T2TowerDoc* inDoc) { + int resultCode = IsExclusive() ? 1 : 0; + T2DateTime *theNow = inDoc->towerDoc_vf120(); + unsigned int theNowMinutes = theNow->GetRawMinutes(); + T2TowerMainView *theMainView; + T2TowerMessage *theTowerMsg; + + if (m44 != theNowMinutes) { + switch (mStatus) { + case kBlackOutStatus1: + if (theNowMinutes == mEndTime) + mStatus = kBlackOutStatus2; + case kBlackOutStatus3: + if (mConsumptionPower < mSupplyPower) + mStatus = kBlackOutStatus4; + break; + + case kBlackOutStatus2: + inDoc->towerDoc_vf284(); + + theTowerMsg = inDoc->mTowerMessage; + if (theTowerMsg) { + // "住人は全て非常階段で避難しました。エレーベーターに閉じ込められた人も救出されました。" + // All residents evacuated using emergency stairs. + // People trapped in elevators were also rescued. + CString text = "\x8F\x5A\x90\x6C\x82\xCD\x91\x53\x82\xC4\x94\xF1\x8F\xED\x8A\x4B\x92\x69\x82\xC5\x94\xF0\x93\xEF\x82\xB5\x82\xDC\x82\xB5\x82\xBD\x81\x42\x83\x47\x83\x8C\x81\x5B\x83\x78\x81\x5B\x83\x5E\x81\x5B\x82\xC9\x95\xC2\x82\xB6\x8D\x9E\x82\xDF\x82\xE7\x82\xEA\x82\xBD\x90\x6C\x82\xE0\x8B\x7E\x8F\x6F\x82\xB3\x82\xEA\x82\xDC\x82\xB5\x82\xBD\x81\x42"; + theTowerMsg->AleatMessage(text, kAlertType1); + } + + inDoc->mPeopleArrayList->AddStress(300); + mStatus = kBlackOutStatus3; + break; + + case kBlackOutStatus4: + mStatus = kBlackOutStatus0; + + theMainView = inDoc->GetTowerMainView(); + if (theMainView) { + inDoc->towerDoc_vf284(); + if (mAttach) { + theMainView->RemoveAttachment(mAttach); + delete mAttach; + mAttach = NULL; + } + } + + resultCode = 3; + break; + } + + m44 = theNowMinutes; + } + + return resultCode; } -void T2BlackOut::AddConsumptionPower(int) { +void T2BlackOut::AddConsumptionPower(int inPower) { + mConsumptionPower += inPower; + T2TowerDoc *theDoc; + + int shortfall = mSupplyPower - mConsumptionPower - 50; + if (shortfall < 0) { + // "電力が不足しています。至急" - Insufficient power. Urgent + CString text = "\x93\x64\x97\xCD\x82\xAA\x95\x73\x91\xAB\x82\xB5\x82\xC4\x82\xA2\x82\xDC\x82\xB7\x81\x42\x8E\x8A\x8B\x7D"; + + theDoc = mTowerEvent->mDocument; + T2TowerMessage *theTowerMsg = theDoc ? theDoc->mTowerMessage : NULL; + + if (mSupplyPower > mDefSupply) { + // "変圧器を増設" - Add a transformer + text += "\x95\xCF\x88\xB3\x8A\xED\x82\xF0\x91\x9D\x90\xDD"; + } else { + CFilePlugin *plugin = theDoc->mTenantPluginsListOther->GetItem('HEND'); + if (plugin) { + // "変電室を設置" - Install substation room + text += "\x95\xCF\x93\x64\x8E\xBA\x82\xF0\x90\xDD\x92\x75"; + } else { + // "不要なテナントを撤去" - Remove unnecessary tenants + text += "\x95\x73\x97\x76\x82\xC8\x83\x65\x83\x69\x83\x93\x83\x67\x82\xF0\x93\x50\x8B\x8E"; + } + } + + // "してください。" - please. + text += "\x82\xB5\x82\xC4\x82\xAD\x82\xBE\x82\xB3\x82\xA2\x81\x42"; + + if (theTowerMsg && (m48 + 360) < GetTickCount()) { + theTowerMsg->InfoBarMessage(text, 360, NULL); + m48 = GetTickCount(); + } + } } -void T2BlackOut::SubConsumptionPower(int) { +void T2BlackOut::SubConsumptionPower(int inPower) { + mConsumptionPower -= inPower; } -void T2BlackOut::AddSupplyPower(int) { +void T2BlackOut::AddSupplyPower(int inPower) { + mSupplyPower = mDefSupply + mAddSupply * inPower; } void T2BlackOut::SubSupplyPower() { + mSupplyPower = mDefSupply; } void T2BlackOut::BreakerOn() { + if (mStatus != kBlackOutStatus0) + mStatus = kBlackOutStatus4; } int T2BlackOut::GetConsumptionPower() { + return mConsumptionPower; } int T2BlackOut::GetSupplyPower() { + return mSupplyPower; } int T2BlackOut::GetDefSupply() { + return mDefSupply; } int T2BlackOut::GetAddSupply() { + return mAddSupply; } int T2BlackOut::GetTransforPrice() { + return mTransforPrice; } -/*virtual*/ void T2BlackOut::Write(T2Archive&) { +/*virtual*/ void T2BlackOut::Write(T2Archive& inArchive) { + unsigned int len = 6; + inArchive << len; + + inArchive << (short) mStatus; + inArchive << (short) mConsumptionPower; + inArchive << (short) mSupplyPower; +} + +/*virtual*/ void T2BlackOut::Read(T2Archive& inArchive) { + unsigned int len; + inArchive >> len; + + short v; + inArchive >> v; + mStatus = v; + inArchive >> v; + mConsumptionPower = v; + inArchive >> v; + mSupplyPower = v; } -/*virtual*/ void T2BlackOut::Read(T2Archive&) { + + +T2BlackOutAttach::T2BlackOutAttach(T2BlackOut *inBlackOut, unsigned int inMessage, BOOL inExecuteHost) + : LAttachment(inMessage, inExecuteHost) +{ + mBlackOut = inBlackOut; +} + +T2BlackOutAttach::~T2BlackOutAttach() { +} + +void T2BlackOutAttach::ExecuteSelf(unsigned int inMessage, void *ioData) { + BOOL newExecuteHost = true; + + if (inMessage == 0x201) { + int sel = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetSel(); + CString *theToolName = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconName(sel); + T2TemplatePlugin *theDef = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconPlugin(sel); + CProgramPlugin *thePlugin = theDef->GetPlugin(); + unsigned int theValiation = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconValiation(sel); + DWORD theOption = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconOption(sel); + + if (theOption == 0) + newExecuteHost = true; + else + newExecuteHost = (thePlugin && thePlugin->GetID() == 'HEND'); + } + + SetExecuteHost(newExecuteHost); } diff --git a/src/T2DLL/T2BlackOut.h b/src/T2DLL/T2BlackOut.h index 7d06eb5..14f3709 100644 --- a/src/T2DLL/T2BlackOut.h +++ b/src/T2DLL/T2BlackOut.h @@ -1,15 +1,30 @@ #pragma once #include "common.h" +#include "LAttachment.h" +#include "T2EventItem.h" -class T2BlackOut { +class T2BlackOutAttach; + +enum { + kBlackOutStatus0 = 0, + kBlackOutStatus1 = 1, + kBlackOutStatus2 = 2, + kBlackOutStatus3 = 3, + kBlackOutStatus4 = 4 +}; + +class AFX_EXT_CLASS T2BlackOut : public T2EventItem { public: - T2BlackOut(T2TowerEvent*, CResFile*, int); + T2BlackOut(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); virtual ~T2BlackOut(); - virtual int Start(T2TowerDoc*); - virtual int Exec(T2TowerDoc*); - void AddConsumptionPower(int); - void SubConsumptionPower(int); - void AddSupplyPower(int); + virtual DWORD GetID() { return 'BOEv'; } + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc* inDoc); + virtual void Write(T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); + void AddConsumptionPower(int inPower); + void SubConsumptionPower(int inPower); + void AddSupplyPower(int inPower); void SubSupplyPower(); void BreakerOn(); int GetConsumptionPower(); @@ -17,11 +32,26 @@ public: int GetDefSupply(); int GetAddSupply(); int GetTransforPrice(); - virtual void Write(T2Archive&); - virtual void Read(T2Archive&); + BOOL IsBlackOut() { return mStatus != kBlackOutStatus0; } + +protected: + int mDefSupply; + int mAddSupply; + int mTransforPrice; + int mConsumptionPower; + int mSupplyPower; + unsigned int m44; + DWORD m48; + T2BlackOutAttach *mAttach; +}; + +class T2BlackOutAttach : public LAttachment { +public: + T2BlackOutAttach(T2BlackOut *inBlackOut, unsigned int inMessage, BOOL inExecuteHost); + virtual ~T2BlackOutAttach(); + +protected: + virtual void ExecuteSelf(unsigned int inMessage, void *ioData); - virtual unsigned long GetID() {} - int IsBlackOut() {} - T2BlackOut(const T2BlackOut&) {} - T2BlackOut& operator=(const T2BlackOut&) {} + T2BlackOut *mBlackOut; }; diff --git a/src/T2DLL/T2ClassFactory.cpp b/src/T2DLL/T2ClassFactory.cpp index cff2ee9..92764a6 100644 --- a/src/T2DLL/T2ClassFactory.cpp +++ b/src/T2DLL/T2ClassFactory.cpp @@ -1,25 +1,53 @@ +#include "T2Archive.h" +#include "T2Balloon.h" #include "T2ClassFactory.h" +#include "T2Dialog.h" +#include "T2SoundPlayer.h" /*static*/ void T2ClassFactory::Initialize() { + CLASSFACTORY_CLASSINFO info; + + info.x0 = 1; + + info.id = 1; + info.newFunc = (void *) &new_T2Archive; + Register(&info); + + info.id = 2; + info.newFunc = (void *) &new_T2Dialog; + Register(&info); + + info.id = 3; + info.newFunc = (void *) &new_T2Balloon; + Register(&info); + + info.id = 4; + info.newFunc = (void *) &new_T2SoundPlayer; + Register(&info); } /*static*/ void T2ClassFactory::Discard() { } -/*static*/ void T2ClassFactory::Register(CLASSFACTORY_CLASSINFO*) { +/*static*/ void T2ClassFactory::Register(CLASSFACTORY_CLASSINFO* inClassInfo) { } -/*static*/ void* T2ClassFactory::Query(int) { +/*static*/ void* T2ClassFactory::Query(int inID) { + return NULL; } /*static*/ void* T2ClassFactory::new_T2Archive() { + return new T2Archive; } /*static*/ void* T2ClassFactory::new_T2Dialog() { + return new T2Dialog; } /*static*/ void* T2ClassFactory::new_T2Balloon() { + return new T2Balloon; } -/*static*/ void* T2ClassFactory::new_T2SoundPlayer(CWnd*, IDirectSound*) { +/*static*/ void* T2ClassFactory::new_T2SoundPlayer(CWnd* inArg1, IDirectSound* inArg2) { + return new T2SoundPlayer(inArg1, inArg2); } diff --git a/src/T2DLL/T2ClassFactory.h b/src/T2DLL/T2ClassFactory.h index 4df7068..bd88d4f 100644 --- a/src/T2DLL/T2ClassFactory.h +++ b/src/T2DLL/T2ClassFactory.h @@ -1,18 +1,21 @@ #pragma once #include "common.h" -class T2ClassFactory { +struct CLASSFACTORY_CLASSINFO { + int x0; + int id; + void *newFunc; +}; + +class AFX_EXT_CLASS T2ClassFactory { public: static void Initialize(); static void Discard(); - static void Register(CLASSFACTORY_CLASSINFO*); - static void* Query(int); + static void Register(CLASSFACTORY_CLASSINFO* inClassInfo); + static void* Query(int inID); private: static void* new_T2Archive(); static void* new_T2Dialog(); static void* new_T2Balloon(); - static void* new_T2SoundPlayer(CWnd*, IDirectSound*); - -public: - T2ClassFactory& operator=(const T2ClassFactory&) {} + static void* new_T2SoundPlayer(CWnd* inArg1, IDirectSound* inArg2); }; diff --git a/src/T2DLL/T2ColdTableDef.cpp b/src/T2DLL/T2ColdTableDef.cpp new file mode 100644 index 0000000..3af5ca7 --- /dev/null +++ b/src/T2DLL/T2ColdTableDef.cpp @@ -0,0 +1,20 @@ +#include "CResFile.h" +#include "T2ColdTableDef.h" + +T2ColdTableDef::T2ColdTableDef(CResFile &inResFile) { + inResFile >> mVar; + for (unsigned int i = 0; i < 12; i++) + inResFile >> mEntries[i]; +} + +/*virtual*/ T2ColdTableDef::~T2ColdTableDef() { +} + +unsigned int T2ColdTableDef::GetDenomi(unsigned int inA, unsigned int inB) const { + unsigned int result = 0; + + if (inA >= mVar && inB < 12) + result = mEntries[inB]; + + return result; +} diff --git a/src/T2DLL/T2ColdTableDef.h b/src/T2DLL/T2ColdTableDef.h new file mode 100644 index 0000000..087402a --- /dev/null +++ b/src/T2DLL/T2ColdTableDef.h @@ -0,0 +1,13 @@ +#pragma once +#include "common.h" + +class T2ColdTableDef { +public: + T2ColdTableDef(CResFile &inResFile); + virtual ~T2ColdTableDef(); + unsigned int GetDenomi(unsigned int inA, unsigned int inB) const; + +protected: + unsigned int mVar; + unsigned int mEntries[12]; +}; diff --git a/src/T2DLL/T2CrossEquipArray.h b/src/T2DLL/T2CrossEquipArray.h index 016ea88..870d994 100644 --- a/src/T2DLL/T2CrossEquipArray.h +++ b/src/T2DLL/T2CrossEquipArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class T2CrossEquipArray : public LArray { +class AFX_EXT_CLASS T2CrossEquipArray : public LArray { public: T2CrossEquipArray(); virtual ~T2CrossEquipArray(); diff --git a/src/T2DLL/T2CustomerTableIterator.cpp b/src/T2DLL/T2CustomerTableIterator.cpp index 4e3fd46..ad7e872 100644 --- a/src/T2DLL/T2CustomerTableIterator.cpp +++ b/src/T2DLL/T2CustomerTableIterator.cpp @@ -1,13 +1,58 @@ #include "T2CustomerTableIterator.h" +#include "T2TenantMemberDef.h" +#include "T2TenantMemberTableDef.h" +#include "UT2Utils.h" -T2CustomerTableIterator::T2CustomerTableIterator(const T2TenantMemberTableDef*) { +T2CustomerTableIterator::T2CustomerTableIterator(const T2TenantMemberTableDef* inTable) { + mTable = inTable; + + if (mTable) { + mLastNum = mTable->GetNumOfElem(); + mBound = UT2Utils::Randomize(mLastNum); + mNextIndex = -1; + } else { + mNextIndex = -2; + } } T2CustomerTableIterator::~T2CustomerTableIterator() { } -int T2CustomerTableIterator::Next(T2TenantMemberDef*&, unsigned int&) { +BOOL T2CustomerTableIterator::Next(T2TenantMemberDef*& outMemberDef, unsigned int& outRate) { + BOOL result = false; + BOOL done = false; + + while (!done) { + CalcNextIndex(); + if (mNextIndex != -2) { + T2TenantMemberDef *theMember = mTable->GetElem(mNextIndex); + if (theMember) { + unsigned int rate = UT2Utils::Float2Int(theMember->GetRate()); + if (rate > 0) { + outMemberDef = theMember; + outRate = rate; + done = true; + result = true; + } + } else { + done = true; + } + } else { + done = true; + } + } + + return result; } void T2CustomerTableIterator::CalcNextIndex() { + if (mNextIndex == -1) { + mNextIndex = mBound; + } else if (mNextIndex != -2) { + mNextIndex++; + if (mNextIndex >= mLastNum) + mNextIndex = 0; + if (mNextIndex == mBound) + mNextIndex = -2; + } } diff --git a/src/T2DLL/T2CustomerTableIterator.h b/src/T2DLL/T2CustomerTableIterator.h index ba07778..57c804e 100644 --- a/src/T2DLL/T2CustomerTableIterator.h +++ b/src/T2DLL/T2CustomerTableIterator.h @@ -1,14 +1,17 @@ #pragma once #include "common.h" -class T2CustomerTableIterator { +class AFX_EXT_CLASS T2CustomerTableIterator { public: - T2CustomerTableIterator(const T2TenantMemberTableDef*); + T2CustomerTableIterator(const T2TenantMemberTableDef* inTable); ~T2CustomerTableIterator(); - int Next(T2TenantMemberDef*&, unsigned int&); + BOOL Next(T2TenantMemberDef*& outMemberDef, unsigned int& outRate); + protected: void CalcNextIndex(); -public: - T2CustomerTableIterator& operator=(const T2CustomerTableIterator&) {} + const T2TenantMemberTableDef *mTable; + int mLastNum; + int mBound; + int mNextIndex; }; diff --git a/src/T2DLL/T2DateTime.cpp b/src/T2DLL/T2DateTime.cpp index 5cb704d..023fb98 100644 --- a/src/T2DLL/T2DateTime.cpp +++ b/src/T2DLL/T2DateTime.cpp @@ -45,11 +45,11 @@ int T2DateTime::GetTimeZone() { return 9; } -/*static*/ int T2DateTime::IsEqualDate(T2DateTime* a, T2DateTime* b) { +/*static*/ BOOL T2DateTime::IsEqualDate(T2DateTime* a, T2DateTime* b) { return (a->mYear == b->mYear) && (a->mMonth == b->mMonth); } -/*static*/ int T2DateTime::IsEqualDateTime(T2DateTime* a, T2DateTime* b) { +/*static*/ BOOL T2DateTime::IsEqualDateTime(T2DateTime* a, T2DateTime* b) { return IsEqualDate(a, b) && (a->mRawMinutes == b->mRawMinutes); } @@ -58,8 +58,8 @@ void T2DateTime::AddMinutes(unsigned int m) { Validate(); } -int T2DateTime::IsIncDateTime() { - int result = false; +BOOL T2DateTime::IsIncDateTime() { + BOOL result = false; mSeconds++; if (mSeconds >= 4) { @@ -95,12 +95,12 @@ unsigned int T2DateTime::CalcLapseYears(unsigned int d) const { return (CalcTotalDays() - d) / 12; } -int T2DateTime::WithinHour(int a, int b) const { +BOOL T2DateTime::WithinHour(int a, int b) const { return WithinMinutes(a * 60, b * 60); } -int T2DateTime::WithinMinutes(int a, int b) const { - int ret = true; +BOOL T2DateTime::WithinMinutes(int a, int b) const { + BOOL ret = true; int minA = AdjustMinutes(a); int minB = AdjustMinutes(b); @@ -136,7 +136,7 @@ int T2DateTime::AdjustMinutes(int m) const { archive << v; } -int T2DateTime::IsHoliday(T2TowerDoc* doc) { +BOOL T2DateTime::IsHoliday(T2TowerDoc* doc) { // TODO virt return false; } diff --git a/src/T2DLL/T2DateTime.h b/src/T2DLL/T2DateTime.h index 288ef9b..faf02fe 100644 --- a/src/T2DLL/T2DateTime.h +++ b/src/T2DLL/T2DateTime.h @@ -1,30 +1,28 @@ #pragma once #include "common.h" -class T2DateTime { +class AFX_EXT_CLASS T2DateTime { public: T2DateTime(); T2DateTime(int year, int month, int hours, int minutes, int seconds); T2DateTime(T2Archive& archive); virtual ~T2DateTime(); + virtual void Write(T2Archive& archive); + int GetTimeZone(); - static int IsEqualDate(T2DateTime* a, T2DateTime* b); - static int IsEqualDateTime(T2DateTime* a, T2DateTime* b); void AddMinutes(unsigned int m); - int IsIncDateTime(); + BOOL IsIncDateTime(); void IncDate(); unsigned int CalcLapseDays(unsigned int d) const; unsigned int CalcLapseYears(unsigned int d) const; - int WithinHour(int a, int b) const; - int WithinMinutes(int a, int b) const; -protected: - int AdjustMinutes(int m) const; -public: - virtual void Write(T2Archive& archive); - int IsHoliday(T2TowerDoc* doc); + BOOL WithinHour(int a, int b) const; + BOOL WithinMinutes(int a, int b) const; + BOOL IsHoliday(T2TowerDoc* doc); void Validate(); - //T2DateTime(const T2DateTime&) {} + static BOOL IsEqualDate(T2DateTime* a, T2DateTime* b); + static BOOL IsEqualDateTime(T2DateTime* a, T2DateTime* b); + unsigned int GetYear() const { return mYear; } unsigned int GetQuarter() const { return mMonth / 3 + 1; } unsigned int GetSeason() const { return mMonth / 3 + 1; } @@ -35,25 +33,32 @@ public: unsigned int GetMinutes() const { return mRawMinutes % 60; } unsigned int GetRawMinutes() const { return mRawMinutes; } int CalcTotalDays() const { return (mYear - 1) * 12 + mMonth; } - int IsWeekday(T2TowerDoc* doc) { return !IsHoliday(doc); } - int IsDay() const { - return (mRawMinutes >= 360 && mRawMinutes <= 1079); + BOOL IsWeekday(T2TowerDoc* doc) { return !IsHoliday(doc); } + BOOL IsDay() const { + return (mRawMinutes >= 360 && mRawMinutes < 1080); } - int IsMidNight() const { + BOOL IsMidNight() const { return mRawMinutes < 360; } - int IsOclock24(unsigned int hour) const { + BOOL IsOclock24(unsigned int hour) const { return (Get24Hour() == hour) && (GetMinutes() == 0) && (mSeconds == 0); } + + unsigned int mYear; + unsigned int mMonth; + unsigned int mRawMinutes; + unsigned int mSeconds; + protected: + int AdjustMinutes(int m) const; + + friend BOOL operator>=(const T2DateTime &a, const T2DateTime &b); + unsigned int CalcTotalCount() const { return mSeconds + ((mYear * 12 + mMonth) * 1440 + mRawMinutes) * 4; } -//public: - //T2DateTime& operator=(const T2DateTime&) {} - - unsigned int mYear; - unsigned int mMonth; - unsigned int mRawMinutes; - unsigned int mSeconds; }; + +inline BOOL operator>=(const T2DateTime &a, const T2DateTime &b) { + return a.CalcTotalCount() >= b.CalcTotalCount(); +} diff --git a/src/T2DLL/T2DayLightFilter.h b/src/T2DLL/T2DayLightFilter.h index 727bd54..d0ca924 100644 --- a/src/T2DLL/T2DayLightFilter.h +++ b/src/T2DLL/T2DayLightFilter.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class T2DayLightFilter { +class AFX_EXT_CLASS T2DayLightFilter { public: T2DayLightFilter(); ~T2DayLightFilter(); diff --git a/src/T2DLL/T2DayParamDef.h b/src/T2DLL/T2DayParamDef.h index 50c7666..02007cb 100644 --- a/src/T2DLL/T2DayParamDef.h +++ b/src/T2DLL/T2DayParamDef.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class T2DayParamDef { +class AFX_EXT_CLASS T2DayParamDef { public: enum EDay { Day_0, diff --git a/src/T2DLL/T2Dialog.cpp b/src/T2DLL/T2Dialog.cpp index c00b5d7..f990466 100644 --- a/src/T2DLL/T2Dialog.cpp +++ b/src/T2DLL/T2Dialog.cpp @@ -1,5 +1,40 @@ +#include "CToggleButtonDisabled.h" #include "CTokenizer.h" +#include "T2AdvertiseTable.h" #include "T2Dialog.h" +#include "T2DlgItem.h" +#include "T2DlgItemAnimation.h" +#include "T2DlgItemArrows.h" +#include "T2DlgItemBelongGage.h" +#include "T2DlgItemBox.h" +#include "T2DlgItemCANCEL.h" +#include "T2DlgItemCheck.h" +#include "T2DlgItemCustomerGage.h" +#include "T2DlgItemEdit.h" +#include "T2DlgItemHScr.h" +#include "T2DlgItemIButton.h" +#include "T2DlgItemICheck.h" +#include "T2DlgItemIRepeater.h" +#include "T2DlgItemImage.h" +#include "T2DlgItemListBox.h" +#include "T2DlgItemMerchandiseField.h" +#include "T2DlgItemMovie.h" +#include "T2DlgItemOK.h" +#include "T2DlgItemPPLEvalGage.h" +#include "T2DlgItemPeopleView.h" +#include "T2DlgItemPopup.h" +#include "T2DlgItemProfitsGage.h" +#include "T2DlgItemProgress.h" +#include "T2DlgItemRadioButton.h" +#include "T2DlgItemRadioText.h" +#include "T2DlgItemSTimeTbl.h" +#include "T2DlgItemStressGage.h" +#include "T2DlgItemTButton.h" +#include "T2DlgItemTable.h" +#include "T2DlgItemText.h" +#include "T2DlgItemVScr.h" +#include "T2MovieTable.h" +#include "T2PluginInfoTable.h" #include "T2TowerDoc.h" #include "T2WorldDef.h" @@ -9,7 +44,7 @@ T2Dialog::T2Dialog() { mInModalLoop = false; mUserCon = 0; mDeleteOnClose = false; - mFontName = "�l�r �o�S�V�b�N"; + mFontName = "\x82\x6C\x82\x72 \x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"; for (int i = 0; i < 10; i++) mFontNums[i] = 0; @@ -22,10 +57,10 @@ T2Dialog::T2Dialog() { } } -void T2Dialog::Realize(void* a, T2DLGTEMPLATE* tmpl, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette, int b, CWnd* parentWnd, UINT nID, int d) { +void T2Dialog::Realize(void* a, T2DLGTEMPLATE* tmpl, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette, BOOL isToolWindow, CWnd* parentWnd, UINT nID, BOOL autoShow) { mEC = a; mTowerDoc = towerDoc; - mF4 = d; + mAutoShow = autoShow; mTemplate = *tmpl; mImageObj = imageObj; @@ -57,10 +92,10 @@ void T2Dialog::Realize(void* a, T2DLGTEMPLATE* tmpl, T2TowerDoc* towerDoc, T2Ima NULL); CreateEx( - b ? WS_EX_TOOLWINDOW : 0, + isToolWindow ? WS_EX_TOOLWINDOW : 0, wndClass, "", - b ? (WS_POPUP | WS_CAPTION) : WS_CHILD, + isToolWindow ? (WS_POPUP | WS_CAPTION) : WS_CHILD, rect, parentWnd, nID @@ -84,28 +119,29 @@ int T2Dialog::OnCreate(CREATESTRUCT* cs) { HRSRC rsrc = FindResource(mTemplate.moduleHandle, MAKEINTATOM(mTemplate.resID), "T2DLG"); if (!rsrc) { - MessageBox("�_�C�A���O������܂���B"); + // "ダイアログがありません。" - No dialog. + MessageBox("\x83\x5F\x83\x43\x83\x41\x83\x8D\x83\x4F\x82\xAA\x82\xA0\x82\xE8\x82\xDC\x82\xB9\x82\xF1\x81\x42"); return 0; } #line 90 _ASSERT(rsrc); - HGLOBAL hglobal = LoadResource(mTemplate.moduleHandle, rsrc); + HGLOBAL theResHandle = LoadResource(mTemplate.moduleHandle, rsrc); #line 92 - _ASSERT(hglobal); + _ASSERT(theResHandle); - void *resData = LockResource(hglobal); + void *theRes = LockResource(theResHandle); #line 94 - _ASSERT(resData); + _ASSERT(theRes); - DWORD resSize = SizeofResource(mTemplate.moduleHandle, rsrc); - char *buffer = (char *) malloc(resSize + 1); - memcpy(buffer, resData, resSize); - buffer[resSize] = 0; + DWORD theResSize = SizeofResource(mTemplate.moduleHandle, rsrc); + char *data = (char *) malloc(theResSize + 1); + memcpy(data, theRes, theResSize); + data[theResSize] = 0; - DoOnCreate(buffer); - free(buffer); + DoOnCreate(data); + free(data); OnT2Create(); @@ -116,7 +152,7 @@ int T2Dialog::OnCreate(CREATESTRUCT* cs) { mTowerDoc->towerDoc_vf290(1); } - if (mF4 && !(cs->style & WS_CHILD)) + if (mAutoShow && !(cs->style & WS_CHILD)) ShowWindow(SW_SHOW); return 0; @@ -128,7 +164,7 @@ T2Dialog::T2DialogDef::T2DialogDef() , modal(1) , title(NULL) , center(true) - , flags(0x50000000) // is this a style? + , flags(WS_VISIBLE | WS_CHILD) { } @@ -139,25 +175,25 @@ T2Dialog::T2DialogDef::T2DialogDef() mModal = def.modal; SetWindowText(def.title); - CRect windowRect, clientRect, desktopRect; + CRect windowRect, clientRect, theDesktopRect; GetWindowRect(windowRect); GetClientRect(clientRect); - GetDesktopWindow()->GetClientRect(desktopRect); + GetDesktopWindow()->GetClientRect(theDesktopRect); def.width += (windowRect.Width() - clientRect.Width()); def.height += (windowRect.Height() - clientRect.Height()); int cx = def.center ? (mTemplate.pt.x - def.width / 2) : mTemplate.pt.x; - if (cx < desktopRect.left) - cx = desktopRect.left; - if (cx + def.width >= desktopRect.right) - cx = desktopRect.right - def.width; + if (cx < theDesktopRect.left) + cx = theDesktopRect.left; + if (cx + def.width >= theDesktopRect.right) + cx = theDesktopRect.right - def.width; int cy = def.center ? (mTemplate.pt.y - def.height / 2) : mTemplate.pt.y; - if (cy < desktopRect.top) - cy = desktopRect.top; - if (cy + def.height >= desktopRect.bottom) - cy = desktopRect.bottom - def.height; + if (cy < theDesktopRect.top) + cy = theDesktopRect.top; + if (cy + def.height >= theDesktopRect.bottom) + cy = theDesktopRect.bottom - def.height; SetWindowPos(NULL, cx, cy, def.width, def.height, SWP_NOZORDER); } @@ -179,8 +215,512 @@ void T2Dialog::CreateDlgItemLoop(T2DialogDef& def, char* data) { } } -/*virtual*/ void T2Dialog::CreateDlgItem(CTokenizer& tokenizer, T2DialogDef& def) { - // TODO: this requires like 500 other classes lmfao +/*virtual*/ void T2Dialog::CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef) { + const char *token = inTokenizer.Current(); + + if (!_stricmp(token, "WIDTH")) { + inDef.width = inTokenizer.NextInteger(); + } else if (!_stricmp(token, "HEIGHT")) { + inDef.height = inTokenizer.NextInteger(); + } else if (!_stricmp(token, "MODAL")) { + inDef.modal = 1; + } else if (!_stricmp(token, "MODALESS")) { + inDef.modal = 0; + } else if (!_stricmp(token, "TMODAL")) { + inDef.modal = 2; + } else if (!_stricmp(token, "TITLE")) { + inDef.title = inTokenizer.NextString(); + } else if (!_stricmp(token, "FONTNAME")) { + mFontName = inTokenizer.NextString(); + } else if (!_stricmp(token, "FONT")) { + int fontNum = inTokenizer.NextInteger(); + int i; + for (i = 0; i < 10; i++) { + if (mFonts[i] && mFontNums[i] == fontNum) + break; + } + + if (i == 10) { + mFontNums[mFontCount] = fontNum; +#line 228 + mFonts[mFontCount] = DEBUG_NEW CFont; + + CString str; + if (mFontName[0] == '!') { + str = mFontName.Mid(1); + mFonts[mFontCount]->CreateFont(-abs(fontNum), 0, 0, 0, (fontNum > 0) ? FW_NORMAL : FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, DEFAULT_PITCH, str); + } else { + mFonts[mFontCount]->CreateFont(-abs(fontNum), 0, 0, 0, (fontNum > 0) ? FW_NORMAL : FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, mFontName); + } + + mCurrentFont = mFontCount; + mFontCount++; + } else { + mCurrentFont = i; + } + } else if (!_stricmp(token, "VISIBLE")) { + inDef.flags |= WS_VISIBLE; + } else if (!_stricmp(token, "INVISIBLE")) { + inDef.flags &= ~WS_VISIBLE; + } else if (!_stricmp(token, "CENTER")) { + inDef.center = true; + } else if (!_stricmp(token, "LEFTTOP")) { + inDef.center = false; + } else if (!_stricmp(token, "OK")) { + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); +#line 263 + T2DlgItemOK *item = DEBUG_NEW T2DlgItemOK(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, 1); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "CANCEL")) { + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); +#line 274 + T2DlgItemCANCEL *item = DEBUG_NEW T2DlgItemCANCEL(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, 2); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "BUTTON")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 289 + T2DlgItemTButton *item = DEBUG_NEW T2DlgItemTButton(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "IBUTTON")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 304 + T2DlgItemIButton *item = DEBUG_NEW T2DlgItemIButton(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "CHECK")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); +#line 316 + T2DlgItemCheck *item = DEBUG_NEW T2DlgItemCheck(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "IBUTTON")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); +#line 329 + T2DlgItemICheck *item = DEBUG_NEW T2DlgItemICheck(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "IREPEAT")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 344 + T2DlgItemIRepeater *item = DEBUG_NEW T2DlgItemIRepeater(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "RADIO")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); +#line 357 + T2DlgItemRadioButton *item = DEBUG_NEW T2DlgItemRadioButton(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(inTokenizer.Current(), "TXRADIO")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 371 + T2DlgItemRadioText *item = DEBUG_NEW T2DlgItemRadioText(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "EDIT")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); + int maxChars = inTokenizer.NextInteger(); +#line 386 + T2DlgItemEdit *item = DEBUG_NEW T2DlgItemEdit(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + item->CreateSubItem(&maxChars); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "HSCROLL")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 400 + T2DlgItemHScr *item = DEBUG_NEW T2DlgItemHScr(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "VSCROLL")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 414 + T2DlgItemVScr *item = DEBUG_NEW T2DlgItemVScr(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "BOX")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 428 + T2DlgItemBox *item = DEBUG_NEW T2DlgItemBox(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "TEXT")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 443 + T2DlgItemText *item = DEBUG_NEW T2DlgItemText(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "DIALOG")) { + UINT id = inTokenizer.NextInteger(); + T2DLGTEMPLATE theTemplate; + theTemplate.resID = inTokenizer.NextInteger(); + theTemplate.pt.x = inTokenizer.NextInteger(); + theTemplate.pt.y = inTokenizer.NextInteger(); + theTemplate.moduleHandle = mTemplate.moduleHandle; +#line 457 + T2Dialog *theDialog = DEBUG_NEW T2Dialog; + theDialog->Realize(this, &theTemplate, mTowerDoc, mImageObj, NULL, false, this, id, true); + } else if (!_stricmp(token, "PPVIEW")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 468 + T2DlgItemPeopleView *item = DEBUG_NEW T2DlgItemPeopleView(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "PGAGE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 482 + T2DlgItemProfitsGage *item = DEBUG_NEW T2DlgItemProfitsGage(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "CGAGE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 496 + T2DlgItemCustomerGage *item = DEBUG_NEW T2DlgItemCustomerGage(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "SGAGE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 510 + T2DlgItemStressGage *item = DEBUG_NEW T2DlgItemStressGage(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "EGAGE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 524 + T2DlgItemPPLEvalGage *item = DEBUG_NEW T2DlgItemPPLEvalGage(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "BGAGE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 538 + T2DlgItemBelongGage *item = DEBUG_NEW T2DlgItemBelongGage(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "TABLE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 552 + T2DlgItemTable *item = DEBUG_NEW T2DlgItemTable(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "POPUP")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 566 + T2DlgItemPopup *item = DEBUG_NEW T2DlgItemPopup(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "PINFTBL")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 580 + T2PluginInfoTable *item = DEBUG_NEW T2PluginInfoTable(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "IMAGE")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 594 + T2DlgItemImage *item = DEBUG_NEW T2DlgItemImage(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "MERF")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); + int maxChars = inTokenizer.NextInteger(); +#line 608 + T2DlgItemMerchandiseField *item = DEBUG_NEW T2DlgItemMerchandiseField(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + item->CreateSubItem(&maxChars); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "ARROWS")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); +#line 619 + T2DlgItemArrows *item = DEBUG_NEW T2DlgItemArrows(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "LISTBOX")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 634 + T2DlgItemListBox *item = DEBUG_NEW T2DlgItemListBox(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + item->CreateSubItem(); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "TBDISABLED")) { + UINT id = inTokenizer.NextInteger(); + CString text = inTokenizer.NextString(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 649 + CToggleButtonDisabled *item = DEBUG_NEW CToggleButtonDisabled(mTowerDoc, mImageObj, mPalette); + item->Create(text, inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "STIMETBL")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 662 + T2DlgItemSTimeTbl *item = DEBUG_NEW T2DlgItemSTimeTbl(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "MOVIE")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 676 + T2DlgItemMovie *item = DEBUG_NEW T2DlgItemMovie(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "MOVTBL")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 690 + T2MovieTable *item = DEBUG_NEW T2MovieTable(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "ANIM")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 705 + T2DlgItemAnimation *item = DEBUG_NEW T2DlgItemAnimation(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "PROG")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 719 + T2DlgItemProgress *item = DEBUG_NEW T2DlgItemProgress(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags | WS_CLIPCHILDREN, rect, this, id); + item->CreateSubItem(); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(token, "ATZTBL")) { + UINT id = inTokenizer.NextInteger(); + RECT rect; + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); +#line 733 + T2AdvertiseTable *item = DEBUG_NEW T2AdvertiseTable(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else { + // "ダイアログテキスト内に見知らぬトークンがあります:" + CString err = "\x83\x5F\x83\x43\x83\x41\x83\x8D\x83\x4F\x83\x65\x83\x4C\x83\x58\x83\x67\x93\xE0\x82\xC9\x8C\xA9\x92\x6D\x82\xE7\x82\xCA\x83\x67\x81\x5B\x83\x4E\x83\x93\x82\xAA\x82\xA0\x82\xE8\x82\xDC\x82\xB7\x81\x46"; + err += token; + MessageBox(err, NULL, MB_ICONEXCLAMATION); + } } void T2Dialog::OnDestroy() { @@ -195,25 +735,25 @@ void T2Dialog::OnDestroy() { } } -int T2Dialog::OnQueryNewPalette() { +BOOL T2Dialog::OnQueryNewPalette() { return CWnd::OnQueryNewPalette(); } -int T2Dialog::OnEraseBkgnd(CDC* dc) { - int result = true; +BOOL T2Dialog::OnEraseBkgnd(CDC* dc) { + BOOL result = true; if (!OnT2PreEraseBkgnd(dc)) { - int savedDC = dc->SaveDC(); + int saved = dc->SaveDC(); dc->SelectPalette(mPalette, false); dc->RealizePalette(); - CBrush brush; - brush.CreateStockObject(LTGRAY_BRUSH); + CBrush theBrush; + theBrush.CreateStockObject(LTGRAY_BRUSH); CRect rect1; GetClientRect(rect1); - dc->FillRect(rect1, &brush); + dc->FillRect(rect1, &theBrush); CPen pen1; pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); @@ -234,7 +774,7 @@ int T2Dialog::OnEraseBkgnd(CDC* dc) { dc->LineTo(rect2.right - 1, rect2.bottom - 1); dc->LineTo(rect2.left, rect2.bottom - 1); - dc->RestoreDC(savedDC); + dc->RestoreDC(saved); result = OnT2EraseBkgnd(dc); } @@ -242,20 +782,20 @@ int T2Dialog::OnEraseBkgnd(CDC* dc) { return result; } -/*virtual*/ int T2Dialog::OnCommand(UINT cmd, long data) { - int result = true; +/*virtual*/ BOOL T2Dialog::OnCommand(WPARAM wParam, LPARAM lParam) { + BOOL result = true; - WORD hi = HIWORD(cmd); - WORD lo = LOWORD(cmd); + WORD code = HIWORD(wParam); + WORD id = LOWORD(wParam); - if ((lo == 1 || lo == 2) && (hi == 0)) { - if (lo == 1) + if ((id == 1 || id == 2) && (code == 0)) { + if (id == 1) OnT2OK(); else OnT2Cancel(); - DoClose(lo); + DoClose(id); } else { - result = OnT2DialogCommand(cmd, data); + result = OnT2DialogCommand(wParam, lParam); } return result; @@ -284,17 +824,20 @@ void T2Dialog::DoClose(int nResult) { return 1; } -void T2Dialog::MakeRadioGroup(int, int, int) { - // TODO - depends on vfCC of something +void T2Dialog::MakeRadioGroup(int inBaseID, int inCount, int inSelected) { + for (unsigned short i = 1; i <= inCount; i++) { + unsigned short id = inBaseID + i; + ((T2DlgItem *) GetDlgItem(id))->SetValue(i == inSelected); + } } -void T2Dialog::MakeTabPanel(int baseID1, int baseID2, int count, int currentIndex) { - for (unsigned short i = 1; i <= count; i++) { - unsigned short id2 = baseID2 + i; - unsigned short id1 = baseID1 + i; - GetDlgItem(id2)->EnableWindow(i != currentIndex); - if (baseID1 != 0) - GetDlgItem(id1)->ShowWindow((i != currentIndex) ? SW_HIDE : SW_SHOW); +void T2Dialog::MakeTabPanel(int inBaseID1, int inBaseID2, int inCount, int inSelected) { + for (unsigned short i = 1; i <= inCount; i++) { + unsigned short id2 = inBaseID2 + i; + unsigned short id1 = inBaseID1 + i; + GetDlgItem(id2)->EnableWindow(i != inSelected); + if (inBaseID1 != 0) + GetDlgItem(id1)->ShowWindow((i != inSelected) ? SW_HIDE : SW_SHOW); } } diff --git a/src/T2DLL/T2Dialog.h b/src/T2DLL/T2Dialog.h index 48a35da..952e1b5 100644 --- a/src/T2DLL/T2Dialog.h +++ b/src/T2DLL/T2Dialog.h @@ -8,20 +8,20 @@ struct T2DLGTEMPLATE { int resID; }; -class T2Dialog : public CWnd, public LListener { +class AFX_EXT_CLASS T2Dialog : public CWnd, public LListener { DECLARE_DYNAMIC(T2Dialog) DECLARE_MESSAGE_MAP() public: T2Dialog(); virtual ~T2Dialog(); - void Realize(void*, T2DLGTEMPLATE*, T2TowerDoc*, T2ImageObj*, CPalette*, int, CWnd* parentWnd, UINT nID, int); + void Realize(void*, T2DLGTEMPLATE*, T2TowerDoc*, T2ImageObj*, CPalette*, BOOL isToolWindow, CWnd* parentWnd, UINT nID, BOOL autoShow); int DoModal(); void DoClose(int nResult); virtual int PreTranslateMessage(MSG*); - void MakeRadioGroup(int, int, int); - void MakeTabPanel(int, int, int, int); + void MakeRadioGroup(int inBaseID, int inCount, int inSelected); + void MakeTabPanel(int inBaseID1, int inBaseID2, int inCount, int inSelected); HFONT GetFont(); T2TowerDoc* GetDocument() const { return mTowerDoc; } @@ -39,12 +39,28 @@ public: int width; int height; int modal; - char *title; + const char *title; int _14; int center; int flags; }; + int mDeleteOnClose; + T2DLGTEMPLATE mTemplate; + long mUserCon; + T2TowerDoc *mTowerDoc; + T2ImageObj *mImageObj; + CPalette *mPalette; + int mModal; + int mInModalLoop; + CFont *mFonts[10]; + int mFontNums[10]; + int mFontCount; + int mCurrentFont; + void *mEC; + CString mFontName; + BOOL mAutoShow; + protected: int OnCreate(CREATESTRUCT*); void OnLButtonDblClk(UINT nFlags, CPoint pt); @@ -52,19 +68,19 @@ protected: void OnLButtonUp(UINT nFlags, CPoint pt); void OnActivateApp(BOOL bActive, HTASK hTask); void OnDestroy(); - int OnQueryNewPalette(); - int OnEraseBkgnd(CDC*); + BOOL OnQueryNewPalette(); + BOOL OnEraseBkgnd(CDC* pDC); virtual int PreCreateWindow(CREATESTRUCT&); - virtual int OnCommand(UINT cmd, long data); + virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); virtual void PostNcDestroy(); virtual void AfterBurner(T2DialogDef& def); virtual void DoOnCreate(char* data); void CreateDlgItemLoop(T2DialogDef& def, char* data); - virtual void CreateDlgItem(CTokenizer& tokenizer, T2DialogDef& def); - virtual int OnT2DialogCommand(UINT cmd, long data) { return 1; } - virtual int OnT2EraseBkgnd(CDC* dc) { return 1; } - virtual int OnT2PreEraseBkgnd(CDC* dc) { return 0; } + virtual void CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef); + virtual BOOL OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) { return true; } + virtual BOOL OnT2EraseBkgnd(CDC* dc) { return true; } + virtual BOOL OnT2PreEraseBkgnd(CDC* dc) { return false; } virtual void OnT2Create() {} virtual void OnT2Destroy() {} virtual void OnT2DlgLButtonDown(UINT nFlags, CPoint pt) {} @@ -72,20 +88,4 @@ protected: virtual void OnT2DlgLButtonDblClk(UINT nFlags, CPoint pt) {} virtual void OnT2OK() {} virtual void OnT2Cancel() {} - - int mDeleteOnClose; - T2DLGTEMPLATE mTemplate; - long mUserCon; - T2TowerDoc *mTowerDoc; - T2ImageObj *mImageObj; - CPalette *mPalette; - int mModal; - int mInModalLoop; - CFont *mFonts[10]; - int mFontNums[10]; - int mFontCount; - int mCurrentFont; - void *mEC; - CString mFontName; - int mF4; }; diff --git a/src/T2DLL/T2DlgItem.cpp b/src/T2DLL/T2DlgItem.cpp index f7b7b7e..ac4a70b 100644 --- a/src/T2DLL/T2DlgItem.cpp +++ b/src/T2DLL/T2DlgItem.cpp @@ -1,4 +1,7 @@ #include "T2DlgItem.h" +#include "T2ImageObj.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" T2DlgItem::T2DlgItem() { } @@ -32,19 +35,33 @@ BEGIN_MESSAGE_MAP(T2DlgItem, CWnd) ON_WM_CLOSE() END_MESSAGE_MAP() -/*virtual*/ BOOL T2DlgItem::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { - CRect crect = rect; +/*virtual*/ BOOL T2DlgItem::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { + CRect crect = inRect; CString className = AfxRegisterWndClass( WS_EX_CLIENTEDGE, LoadCursor(NULL, IDC_ARROW), (HBRUSH) GetStockObject(WHITE_BRUSH), NULL); - return CWnd::Create(className, windowName, style, crect, parentWnd, nId); + return CWnd::Create(className, inWindowName, inStyle, crect, inParentWnd, inID); } -/*virtual*/ T2BitImage* T2DlgItem::GetObjectImage(RECT&, const char*, int, int, int, int) const { - // TODO T2ImageObj, T2TowerDoc, T2WorldDef - return 0; +/*virtual*/ T2BitImage* T2DlgItem::GetObjectImage(RECT& outRect, const char* inName, int inPattern, int inGrade, int inSpan, int inOffset) const { + T2BitImage *theImage = NULL; + int index; + + if (mImageObj) { + index = mImageObj->FindObject(inName, inPattern, inGrade, inSpan, inOffset); + if (index != -1) + theImage = mImageObj->GetObjectImage(index, outRect); + } + + if (!theImage && mTowerDoc && mTowerDoc->mWorldDef) { + index = mTowerDoc->mWorldDef->mImageObj->FindObject(inName, inPattern, inGrade, inSpan, inOffset); + if (index != -1) + theImage = mTowerDoc->mWorldDef->mImageObj->GetObjectImage(index, outRect); + } + + return theImage; } /*virtual*/ void T2DlgItem::PostNcDestroy() { @@ -55,7 +72,7 @@ END_MESSAGE_MAP() delete this; } -/*virtual*/ int T2DlgItem::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItem::OnT2DlgItemEraseBkgnd(CDC*) { return false; } @@ -82,8 +99,8 @@ END_MESSAGE_MAP() return false; } -int T2DlgItem::OnEraseBkgnd(CDC* dc) { - return OnT2DlgItemEraseBkgnd(dc); +BOOL T2DlgItem::OnEraseBkgnd(CDC* pDC) { + return OnT2DlgItemEraseBkgnd(pDC); } void T2DlgItem::OnLButtonDown(UINT nFlags, CPoint pt) { diff --git a/src/T2DLL/T2DlgItem.h b/src/T2DLL/T2DlgItem.h index ee0ffdf..939ae9f 100644 --- a/src/T2DLL/T2DlgItem.h +++ b/src/T2DLL/T2DlgItem.h @@ -2,14 +2,13 @@ #include "common.h" #include "LBroadcaster.h" -class T2DlgItem : public CWnd, private LBroadcaster { +class AFX_EXT_CLASS T2DlgItem : public CWnd, public LBroadcaster { protected: T2DlgItem(); public: - T2DlgItem(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItem(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItem(); -public: - virtual BOOL Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId); + virtual BOOL Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); virtual void SetFont(HFONT font); virtual void CreateSubItem(void*); virtual void SetValue(int value); @@ -19,9 +18,9 @@ public: protected: virtual void PostNcDestroy(); virtual void DestroySelf(); - virtual T2BitImage* GetObjectImage(RECT&, const char*, int, int, int, int) const; + virtual T2BitImage* GetObjectImage(RECT& outRect, const char* inName, int inPattern = -1, int inGrade = 0, int inSpan = 0, int inOffset = 255) const; - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); virtual void OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt); virtual void OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt); virtual void OnT2DlgItemRButtonDown(UINT nFlags, CPoint pt); @@ -35,7 +34,7 @@ protected: virtual void OnT2Timer(UINT id); virtual void OnT2Close(); - int OnEraseBkgnd(CDC*); + BOOL OnEraseBkgnd(CDC* pDC); void OnLButtonDown(UINT nFlags, CPoint pt); void OnLButtonUp(UINT nFlags, CPoint pt); void OnRButtonDown(UINT nFlags, CPoint pt); diff --git a/src/T2DLL/T2DlgItemAPTable.cpp b/src/T2DLL/T2DlgItemAPTable.cpp index 7e042f2..11282ff 100644 --- a/src/T2DLL/T2DlgItemAPTable.cpp +++ b/src/T2DLL/T2DlgItemAPTable.cpp @@ -1,31 +1,64 @@ #include "T2DlgItemAPTable.h" -TableCellT T2DlgItemAPTable::GetClickedCell() { +T2DlgItemAPTable::T2DlgItemAPTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemImageTable(inDoc, inImageObj, inPalette) +{ + mClickPoint = CPoint(-1, -1); + mClickedCell.row = 0; + mClickedCell.col = 0; } -CPoint T2DlgItemAPTable::GetClickPoint() { +T2DlgItemAPTable::T2DlgItemAPTable(int inRows, int inCols, int inRowHeight, int inColWidth, int inCellDataSize, T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemImageTable(inRows, inCols, inRowHeight, inColWidth, inCellDataSize, inDoc, inImageObj, inPalette) +{ } -/*virtual*/ T2DlgItemAPTable::~T2DlgItemAPTable() { +/*virtual*/ void T2DlgItemAPTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + if (EqualCell(inCell, mSelectedCell)) + DrawCellSelf(pDC, inCell, true); + else + DrawCellSelf(pDC, inCell, false); } -T2DlgItemAPTable::T2DlgItemAPTable(T2TowerDoc*, T2ImageObj*, CPalette*) { -} +/*virtual*/ void T2DlgItemAPTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL selected) { + CRect rect; + if (FetchLocalCellFrame(inCell, rect)) { + int save = pDC->SaveDC(); -T2DlgItemAPTable::T2DlgItemAPTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*) { -} + CBrush brush; + brush.CreateSolidBrush(PALETTEINDEX(0)); -/*virtual*/ void T2DlgItemAPTable::DrawCell(CDC*, const TableCellT&) { -} + CPen pen; + pen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + pDC->SelectObject(&brush); + pDC->SelectObject(&pen); + pDC->SetBkMode(TRANSPARENT); + + pDC->Rectangle(rect); + + char *text = new char[128]; + GetCellData(inCell, text); + pDC->DrawText(text, rect, DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + delete[] text; -/*virtual*/ void T2DlgItemAPTable::DrawCellSelf(CDC*, const TableCellT&, int) { + pDC->RestoreDC(save); + } } -/*virtual*/ void T2DlgItemAPTable::HiliteCell(CDC*, const TableCellT&) { +/*virtual*/ void T2DlgItemAPTable::HiliteCell(CDC* pDC, const TableCellT& inCell) { + T2DlgItemImageTable::HiliteCell(pDC, inCell); } -/*virtual*/ void T2DlgItemAPTable::UnhiliteCell(CDC*, const TableCellT&) { +/*virtual*/ void T2DlgItemAPTable::UnhiliteCell(CDC* pDC, const TableCellT& inCell) { + T2DlgItemImageTable::UnhiliteCell(pDC, inCell); } -/*virtual*/ void T2DlgItemAPTable::ClickCell(const TableCellT&, const POINT&) { +/*virtual*/ void T2DlgItemAPTable::ClickCell(const TableCellT& inCell, const POINT& inPt) { + CRect rect; + if (FetchLocalCellFrame(inCell, rect)) { + mClickPoint = inPt; + mClickedCell = inCell; + Notify(GetDlgCtrlID(), 0, (void *) &inPt); + } } diff --git a/src/T2DLL/T2DlgItemAPTable.h b/src/T2DLL/T2DlgItemAPTable.h index 3f80516..9fb6223 100644 --- a/src/T2DLL/T2DlgItemAPTable.h +++ b/src/T2DLL/T2DlgItemAPTable.h @@ -1,17 +1,22 @@ #pragma once #include "common.h" +#include "T2DlgItemImageTable.h" -class T2DlgItemAPTable { +class AFX_EXT_CLASS T2DlgItemAPTable : public T2DlgItemImageTable { public: - TableCellT GetClickedCell(); - CPoint GetClickPoint(); - virtual ~T2DlgItemAPTable(); - T2DlgItemAPTable(T2TowerDoc*, T2ImageObj*, CPalette*); - T2DlgItemAPTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemAPTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + T2DlgItemAPTable(int inRows, int inCols, int inRowHeight, int inColWidth, int inCellDataSize, T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + + TableCellT GetClickedCell() { return mClickedCell; } + CPoint GetClickPoint() { return mClickPoint; } + protected: - virtual void DrawCell(CDC*, const TableCellT&); - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual void HiliteCell(CDC*, const TableCellT&); - virtual void UnhiliteCell(CDC*, const TableCellT&); - virtual void ClickCell(const TableCellT&, const POINT&); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL selected); + virtual void HiliteCell(CDC* pDC, const TableCellT& inCell); + virtual void UnhiliteCell(CDC* pDC, const TableCellT& inCell); + virtual void ClickCell(const TableCellT& inCell, const POINT& inPt); + + CPoint mClickPoint; + TableCellT mClickedCell; }; diff --git a/src/T2DLL/T2DlgItemAllPurpose.cpp b/src/T2DLL/T2DlgItemAllPurpose.cpp index ae98b03..9a947f0 100644 --- a/src/T2DLL/T2DlgItemAllPurpose.cpp +++ b/src/T2DLL/T2DlgItemAllPurpose.cpp @@ -1,28 +1,89 @@ #include "T2DlgItemAllPurpose.h" -T2DlgItemAllPurpose::T2DlgItemAllPurpose(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemAllPurpose::T2DlgItemAllPurpose(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ +#line 16 + mDownPoint = DEBUG_NEW CPoint(-1, -1); + mUpPoint = DEBUG_NEW CPoint(-1, -1); + mButton = -1; } /*virtual*/ T2DlgItemAllPurpose::~T2DlgItemAllPurpose() { + delete mDownPoint; + delete mUpPoint; } -/*virtual*/ int T2DlgItemAllPurpose::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemAllPurpose::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen whitePen; + whitePen.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + CPen greyPen; + greyPen.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + + pDC->SelectObject(greyPen); + pDC->MoveTo(rect.right - 1, rect.top); + pDC->LineTo(rect.left, rect.top); + pDC->LineTo(rect.left, rect.bottom); + + pDC->SelectObject(whitePen); + pDC->MoveTo(rect.right - 1, rect.top + 1); + pDC->LineTo(rect.right - 1, rect.bottom - 1); + pDC->LineTo(rect.left, rect.bottom - 1); + + pDC->RestoreDC(save); + + return true; } -/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemLButtonDown(UINT, CPoint inPt) { + *mDownPoint = inPt; + mButton = 0; } -/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemLButtonUp(UINT, CPoint inPt) { + *mUpPoint = inPt; + + if (mButton == 0) { + mButton = 0; + + CSize delta = *mDownPoint - *mUpPoint; + if (abs(delta.cx) < 2 && abs(delta.cy) < 2) + Notify(GetDlgCtrlID(), 0, &mButton); + } else { + mButton = 0; + } } -/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemRButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemRButtonDown(UINT, CPoint inPt) { + *mDownPoint = inPt; + mButton = 1; } -/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemRButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemAllPurpose::OnT2DlgItemRButtonUp(UINT, CPoint inPt) { + *mUpPoint = inPt; + + if (mButton == 1) { + mButton = 1; + + CSize delta = *mDownPoint - *mUpPoint; + if (abs(delta.cx) < 2 && abs(delta.cy) < 2) + Notify(GetDlgCtrlID(), 0, &mButton); + } else { + mButton = 1; + } } CPoint T2DlgItemAllPurpose::GetUpPoint() { + return *mUpPoint; } CPoint T2DlgItemAllPurpose::GetDownPoint() { + return *mDownPoint; } diff --git a/src/T2DLL/T2DlgItemAllPurpose.h b/src/T2DLL/T2DlgItemAllPurpose.h index 3797e11..6aef4c6 100644 --- a/src/T2DLL/T2DlgItemAllPurpose.h +++ b/src/T2DLL/T2DlgItemAllPurpose.h @@ -1,17 +1,22 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemAllPurpose { +class AFX_EXT_CLASS T2DlgItemAllPurpose : public T2DlgItem { public: - T2DlgItemAllPurpose(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemAllPurpose(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemAllPurpose(); -protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemRButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemRButtonUp(unsigned int, CPoint); -public: CPoint GetUpPoint(); CPoint GetDownPoint(); + +protected: + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + virtual void OnT2DlgItemLButtonDown(UINT, CPoint); + virtual void OnT2DlgItemLButtonUp(UINT, CPoint); + virtual void OnT2DlgItemRButtonDown(UINT, CPoint); + virtual void OnT2DlgItemRButtonUp(UINT, CPoint); + + CPoint *mDownPoint; + CPoint *mUpPoint; + int mButton; }; diff --git a/src/T2DLL/T2DlgItemAnimation.cpp b/src/T2DLL/T2DlgItemAnimation.cpp index ae5ff6b..b2f8589 100644 --- a/src/T2DLL/T2DlgItemAnimation.cpp +++ b/src/T2DLL/T2DlgItemAnimation.cpp @@ -1,25 +1,91 @@ +#include "GlobalFunc.h" +#include "T2BitImage.h" #include "T2DlgItemAnimation.h" +#include "T2ImageObj.h" -T2DlgItemAnimation::T2DlgItemAnimation(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemAnimation::T2DlgItemAnimation(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ + mBitImage = NULL; + mImageObj = NULL; + mStartFrame = 0; + mDelay = 500; + mTimerCreated = false; } /*virtual*/ T2DlgItemAnimation::~T2DlgItemAnimation() { + if (mBitImage) + delete mBitImage; + if (mImageObj) + delete mImageObj; } -/*virtual*/ int T2DlgItemAnimation::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemAnimation::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (mImageObj) { + int objID; + retry: + objID = mImageObj->FindObject("ANIM", mCurrentFrame); + if (objID == -1) { + mCurrentFrame = mStartFrame; + goto retry; + } + + mImageObj->DrawObject(pDC, objID, rect); + } + + pDC->RestoreDC(save); + + return true; } -void T2DlgItemAnimation::SetAnimation(HINSTANCE, int, int) { +void T2DlgItemAnimation::SetAnimation(HINSTANCE inModule, int inResID, int unk) { + if (mBitImage) + delete mBitImage; + if (mImageObj) + delete mImageObj; + +#line 60 + mBitImage = DEBUG_NEW T2BitImage(GetWorldModuleHandle(), inResID, true); + mImageObj = DEBUG_NEW T2ImageObj; + mImageObj->AddObject(GetWorldModuleHandle(), inResID, mBitImage); + + mStartFrame = 0; + mCurrentFrame = 0; } -void T2DlgItemAnimation::SetAnimationParam(int, int) { +void T2DlgItemAnimation::SetAnimationParam(int inDelay, int inStartFrame) { + mDelay = inDelay; + mStartFrame = inStartFrame; + + if (mTimerCreated) { + KillTimer(100); + SetTimer(100, mDelay, NULL); + } } -/*virtual*/ int T2DlgItemAnimation::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2DlgItemAnimation::OnT2DlgItemCreate(CREATESTRUCT*) { + SetTimer(100, mDelay, NULL); + mTimerCreated = true; + return 0; } /*virtual*/ void T2DlgItemAnimation::OnT2Close() { + KillTimer(100); + mTimerCreated = false; } -/*virtual*/ void T2DlgItemAnimation::OnT2Timer(unsigned int) { +/*virtual*/ void T2DlgItemAnimation::OnT2Timer(UINT id) { + if (id == 100) { + mCurrentFrame++; + InvalidateRect(NULL); + } else { + T2DlgItem::OnT2Timer(id); + } } diff --git a/src/T2DLL/T2DlgItemAnimation.h b/src/T2DLL/T2DlgItemAnimation.h index e3ac516..613bf65 100644 --- a/src/T2DLL/T2DlgItemAnimation.h +++ b/src/T2DLL/T2DlgItemAnimation.h @@ -1,17 +1,24 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemAnimation { +class AFX_EXT_CLASS T2DlgItemAnimation : public T2DlgItem { public: - T2DlgItemAnimation(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemAnimation(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemAnimation(); + void SetAnimation(HINSTANCE inModule, int inResID, int unk); + void SetAnimationParam(int inDelay, int inStartFrame); + protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); -public: - void SetAnimation(HINSTANCE, int, int); - void SetAnimationParam(int, int); -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + virtual int OnT2DlgItemCreate(CREATESTRUCT*); virtual void OnT2Close(); - virtual void OnT2Timer(unsigned int); + virtual void OnT2Timer(UINT); + + T2BitImage *mBitImage; + T2ImageObj *mImageObj; + int mCurrentFrame; + int mStartFrame; + int mDelay; + BOOL mTimerCreated; }; diff --git a/src/T2DLL/T2DlgItemArrows.cpp b/src/T2DLL/T2DlgItemArrows.cpp new file mode 100644 index 0000000..64c9ae3 --- /dev/null +++ b/src/T2DLL/T2DlgItemArrows.cpp @@ -0,0 +1,139 @@ +#include "T2BitImage.h" +#include "T2DlgItemArrows.h" + +T2DlgItemArrows::T2DlgItemArrows(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mMinimum(0) + , mMaximum(0) + , mIsClicked(false) +{ +} + +/*virtual*/ T2DlgItemArrows::~T2DlgItemArrows() { +} + +/*virtual*/ BOOL T2DlgItemArrows::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { + CRect rectToUse = rect; + CRect imageRect; + T2BitImage *image = GetObjectImage(imageRect, "DLGITEM:Arrows"); + if (image) { + rectToUse.right = rectToUse.left + imageRect.Width(); + rectToUse.bottom = rectToUse.top + imageRect.Height(); + } + return T2DlgItem::Create(windowName, style, rectToUse, parentWnd, nId); +} + +/*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt) { + CRect clientRect; + GetClientRect(clientRect); + + CRect imageRect; + if (GetObjectImage(imageRect, "DLGITEM:Arrows")) { + CRect upRect = imageRect; + upRect.bottom = upRect.top + (imageRect.Height() / 2); + upRect.OffsetRect(-upRect.left + clientRect.left, -upRect.top + clientRect.top); + + CRect dnRect = imageRect; + dnRect.OffsetRect(-dnRect.left + clientRect.left, -dnRect.top + clientRect.top + upRect.Height() + 1); + + if (upRect.PtInRect(pt)) { + SetPattern(100); + mMouseRect = upRect; + } else if (dnRect.PtInRect(pt)) { + SetPattern(101); + mMouseRect = dnRect; + } + } + + if (GetPattern() != 0) { + SetCapture(); + m74 = true; + mIsClicked = true; + InvalidateRect(mMouseRect); + + SetValue(GetValue() + (GetPattern() == 100 ? 1 : -1)); + Notify(GetDlgCtrlID(), 0, NULL); + mTimerID = SetTimer(999, 100, NULL); + } +} + +/*virtual*/ void T2DlgItemArrows::OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt) { + if (mIsClicked) { + if (mTimerID) + KillTimer(mTimerID); + + SetPattern(0); + ReleaseCapture(); + mIsClicked = false; + + if (m74) { + m74 = false; + InvalidateRect(mMouseRect); + } + } +} + +/*virtual*/ void T2DlgItemArrows::OnT2DlgItemMouseMove(UINT nFlags, CPoint pt) { + if (mIsClicked) { + BOOL inRect = mMouseRect.PtInRect(pt); + if (inRect != m74) { + m74 = inRect; + InvalidateRect(mMouseRect); + } + } +} + +/*virtual*/ BOOL T2DlgItemArrows::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect clientRect; + GetClientRect(clientRect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CRect imageRect; + int pattern; + if (!m74) + pattern = 0; + else + pattern = GetPattern(); + T2BitImage *image = GetObjectImage(imageRect, "DLGITEM:Arrows", pattern); + + if (image) { + CRect drawRect = imageRect; + drawRect.OffsetRect(-drawRect.left + clientRect.left, -drawRect.top + clientRect.top); + image->CopyImage(pDC, imageRect, drawRect, 0, NULL); + } + + pDC->RestoreDC(save); + + return true; +} + +/*virtual*/ void T2DlgItemArrows::OnT2Timer(UINT id) { + if (id == mTimerID && m74) { + SetValue(GetValue() + (GetPattern() == 100 ? 1 : -1)); + Notify(GetDlgCtrlID(), 0, NULL); + } +} + +/*virtual*/ void T2DlgItemArrows::SetMinValue(int inValue) { + mMinimum = inValue; + if (mValue < inValue) + SetValue(inValue); +} + +/*virtual*/ void T2DlgItemArrows::SetMaxValue(int inValue) { + mMaximum = inValue; + if (mValue > inValue) + SetValue(inValue); +} + +/*virtual*/ void T2DlgItemArrows::SetValue(int inValue) { + if (inValue < mMinimum) + inValue = mMinimum; + else if (inValue > mMaximum) + inValue = mMaximum; + + T2DlgItem::SetValue(inValue); +} diff --git a/src/T2DLL/T2DlgItemArrows.h b/src/T2DLL/T2DlgItemArrows.h new file mode 100644 index 0000000..7836c35 --- /dev/null +++ b/src/T2DLL/T2DlgItemArrows.h @@ -0,0 +1,26 @@ +#pragma once +#include "common.h" +#include "T2DlgItem.h" + +class T2DlgItemArrows : public T2DlgItem { +public: + T2DlgItemArrows(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual ~T2DlgItemArrows(); + virtual BOOL Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId); + virtual void SetMinValue(int inValue); + virtual void SetMaxValue(int inValue); + virtual void SetValue(int value); + +protected: + virtual void OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt); + virtual void OnT2DlgItemLButtonUp(UINT nFlags, CPoint pt); + virtual void OnT2DlgItemMouseMove(UINT nFlags, CPoint pt); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + virtual void OnT2Timer(UINT id); + + int mTimerID; + CRect mMouseRect; + int mMinimum; + int mMaximum; + BOOL mIsClicked; +}; diff --git a/src/T2DLL/T2DlgItemBelongGage.cpp b/src/T2DLL/T2DlgItemBelongGage.cpp index 7553062..81dcec7 100644 --- a/src/T2DLL/T2DlgItemBelongGage.cpp +++ b/src/T2DLL/T2DlgItemBelongGage.cpp @@ -1,28 +1,47 @@ #include "T2DlgItemBelongGage.h" +#include "T2Tenant.h" -T2DlgItemBelongGage::T2DlgItemBelongGage(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemBelongGage::T2DlgItemBelongGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemGageBase(towerDoc, imageObj, palette) + , mTenant(NULL) +{ } /*virtual*/ int T2DlgItemBelongGage::GetMinValue() { + return 1; } /*virtual*/ int T2DlgItemBelongGage::GetMaxValue() { + return 300; } /*virtual*/ int T2DlgItemBelongGage::GetValue() { + int value = GetMinValue(); + if (mTenant) { + mTenant->UpdateResidencialEstimate(mTowerDoc); + value = mTenant->GetEstimate(); + } + return value; } /*virtual*/ int T2DlgItemBelongGage::GetBlueValue() { + return 200; } /*virtual*/ int T2DlgItemBelongGage::GetYellowValue() { + return 70; } -/*virtual*/ unsigned long T2DlgItemBelongGage::GetGageColor(int) { +/*virtual*/ COLORREF T2DlgItemBelongGage::GetGageColor(int value) { + return (value <= GetYellowValue()) ? PALETTERGB(255, 0, 0) : + (value <= GetBlueValue()) ? PALETTERGB(255, 255, 0) : + PALETTERGB(0, 0, 255); } -void T2DlgItemBelongGage::SetTenant(T2Tenant*) { +void T2DlgItemBelongGage::SetTenant(T2Tenant* tenant) { + mTenant = tenant; } -/*virtual*/ int T2DlgItemBelongGage::IsDrawInterior() { +/*virtual*/ BOOL T2DlgItemBelongGage::IsDrawInterior() { + return (mTenant != NULL); } diff --git a/src/T2DLL/T2DlgItemBelongGage.h b/src/T2DLL/T2DlgItemBelongGage.h index 3080f88..213f724 100644 --- a/src/T2DLL/T2DlgItemBelongGage.h +++ b/src/T2DLL/T2DlgItemBelongGage.h @@ -1,21 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItemGageBase.h" -class T2DlgItemBelongGage { +class AFX_EXT_CLASS T2DlgItemBelongGage : public T2DlgItemGageBase { public: - T2DlgItemBelongGage(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemBelongGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); + void SetTenant(T2Tenant* tenant); + protected: virtual int GetMinValue(); virtual int GetMaxValue(); virtual int GetValue(); virtual int GetBlueValue(); virtual int GetYellowValue(); - virtual unsigned long GetGageColor(int); -public: - void SetTenant(T2Tenant*); -protected: - virtual int IsDrawInterior(); + virtual COLORREF GetGageColor(int value); + virtual BOOL IsDrawInterior(); -public: - virtual ~T2DlgItemBelongGage() {} + T2Tenant *mTenant; }; diff --git a/src/T2DLL/T2DlgItemBox.cpp b/src/T2DLL/T2DlgItemBox.cpp index f1dfe3b..514b300 100644 --- a/src/T2DLL/T2DlgItemBox.cpp +++ b/src/T2DLL/T2DlgItemBox.cpp @@ -1,7 +1,40 @@ #include "T2DlgItemBox.h" -T2DlgItemBox::T2DlgItemBox(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemBox::T2DlgItemBox(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemBox::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemBox::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + CPen whitePen; + whitePen.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + CPen greyPen; + greyPen.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + CBrush brush; + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (IsWindowEnabled()) { + pDC->SelectObject(greyPen); + pDC->MoveTo(rect.right - 1, rect.top); + pDC->LineTo(rect.left, rect.top); + pDC->LineTo(rect.left, rect.bottom); + + pDC->SelectObject(whitePen); + pDC->MoveTo(rect.right - 1, rect.top + 1); + pDC->LineTo(rect.right - 1, rect.bottom - 1); + pDC->LineTo(rect.left, rect.bottom - 1); + } else { + brush.CreateSolidBrush(PALETTERGB(179, 179, 179)); + pDC->FrameRect(rect, &brush); + } + + pDC->RestoreDC(save); + + return true; } diff --git a/src/T2DLL/T2DlgItemBox.h b/src/T2DLL/T2DlgItemBox.h index f240321..90bcd14 100644 --- a/src/T2DLL/T2DlgItemBox.h +++ b/src/T2DLL/T2DlgItemBox.h @@ -1,12 +1,10 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemBox { +class AFX_EXT_CLASS T2DlgItemBox : public T2DlgItem { public: - T2DlgItemBox(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemBox(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - -public: - virtual ~T2DlgItemBox() {} + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); }; diff --git a/src/T2DLL/T2DlgItemButtonBase.cpp b/src/T2DLL/T2DlgItemButtonBase.cpp index 24fd54c..2ef7362 100644 --- a/src/T2DLL/T2DlgItemButtonBase.cpp +++ b/src/T2DLL/T2DlgItemButtonBase.cpp @@ -1,16 +1,98 @@ #include "T2DlgItemButtonBase.h" -T2DlgItemButtonBase::T2DlgItemButtonBase(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemButtonBase::T2DlgItemButtonBase(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mIsClicked(false) +{ } -/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemLButtonDown(UINT, CPoint) { + SetCapture(); + mIsClicked = true; + m74 = true; + SetPattern(100); + Invalidate(); } -/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemLButtonUp(UINT, CPoint) { + if (mIsClicked) { + ReleaseCapture(); + mIsClicked = false; + + if (m74) { + m74 = false; + SetPattern(0); + Invalidate(); + Notify(GetDlgCtrlID(), 0, NULL); + } + } } -/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemMouseMove(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemButtonBase::OnT2DlgItemMouseMove(UINT, CPoint inPt) { + if (mIsClicked) { + CRect rect; + GetClientRect(rect); + BOOL inRect = rect.PtInRect(inPt); + if (inRect != m74) { + m74 = inRect; + SetPattern(m74 ? 100 : 0); + Invalidate(); + } + } } -/*virtual*/ void T2DlgItemButtonBase::DrawButtonBase(CDC*, const RECT&, int) { +/*virtual*/ void T2DlgItemButtonBase::DrawButtonBase(CDC* pDC, const RECT& inRect, BOOL flag) { + if (IsWindowEnabled() && flag) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen penA; + penA.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + CBrush brush; + brush.CreateSolidBrush(PALETTERGB(179, 179, 179)); + + pDC->SelectObject(penA); + pDC->SelectObject(brush); + pDC->Rectangle(&inRect); + + CPen penB; + penB.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + pDC->SelectObject(penB); + pDC->MoveTo(inRect.right - 2, inRect.top + 1); + pDC->LineTo(inRect.left + 1, inRect.top + 1); + pDC->LineTo(inRect.left + 1, inRect.bottom - 1); + + pDC->RestoreDC(save); + } else { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen penA; + penA.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + CBrush brush; + brush.CreateSolidBrush(PALETTERGB(204, 204, 204)); + + pDC->SelectObject(penA); + pDC->SelectObject(brush); + pDC->Rectangle(&inRect); + + CPen penB; + penB.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + CPen penC; + penC.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + + pDC->SelectObject(penB); + pDC->MoveTo(inRect.right - 2, inRect.top + 1); + pDC->LineTo(inRect.left + 1, inRect.top + 1); + pDC->LineTo(inRect.left + 1, inRect.bottom - 1); + + pDC->SelectObject(penC); + pDC->MoveTo(inRect.right - 2, inRect.top + 2); + pDC->LineTo(inRect.right - 2, inRect.bottom - 2); + pDC->LineTo(inRect.left + 1, inRect.bottom - 2); + + pDC->RestoreDC(save); + } } diff --git a/src/T2DLL/T2DlgItemButtonBase.h b/src/T2DLL/T2DlgItemButtonBase.h index cba8156..868340b 100644 --- a/src/T2DLL/T2DlgItemButtonBase.h +++ b/src/T2DLL/T2DlgItemButtonBase.h @@ -1,15 +1,15 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemButtonBase { +class AFX_EXT_CLASS T2DlgItemButtonBase : public T2DlgItem { public: - T2DlgItemButtonBase(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemButtonBase(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemMouseMove(unsigned int, CPoint); + virtual void OnT2DlgItemLButtonDown(UINT, CPoint); + virtual void OnT2DlgItemLButtonUp(UINT, CPoint); + virtual void OnT2DlgItemMouseMove(UINT, CPoint); virtual void DrawButtonBase(CDC*, const RECT&, int); -public: - virtual ~T2DlgItemButtonBase() {} + BOOL mIsClicked; }; diff --git a/src/T2DLL/T2DlgItemCANCEL.cpp b/src/T2DLL/T2DlgItemCANCEL.cpp index 4c5d193..8b0a197 100644 --- a/src/T2DLL/T2DlgItemCANCEL.cpp +++ b/src/T2DLL/T2DlgItemCANCEL.cpp @@ -1,7 +1,16 @@ #include "T2DlgItemCANCEL.h" -T2DlgItemCANCEL::T2DlgItemCANCEL(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemCANCEL::T2DlgItemCANCEL(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemIButton(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemCANCEL::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemCANCEL::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { + CRect rectToUse = rect; + CRect imageRect; + GetObjectImage(imageRect, "DLGITEM:Cancel"); + + rectToUse.right = rectToUse.left + imageRect.Width(); + rectToUse.bottom = rectToUse.top + imageRect.Height(); + return T2DlgItem::Create("DLGITEM:Cancel", style, rectToUse, parentWnd, nId); } diff --git a/src/T2DLL/T2DlgItemCANCEL.h b/src/T2DLL/T2DlgItemCANCEL.h index a4c4489..42132c7 100644 --- a/src/T2DLL/T2DlgItemCANCEL.h +++ b/src/T2DLL/T2DlgItemCANCEL.h @@ -1,10 +1,9 @@ #pragma once #include "common.h" +#include "T2DlgItemIButton.h" -class T2DlgItemCANCEL { +class AFX_EXT_CLASS T2DlgItemCANCEL : public T2DlgItemIButton { public: - T2DlgItemCANCEL(T2TowerDoc*, T2ImageObj*, CPalette*); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - - virtual ~T2DlgItemCANCEL() {} + T2DlgItemCANCEL(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual BOOL Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId); }; diff --git a/src/T2DLL/T2DlgItemCheck.cpp b/src/T2DLL/T2DlgItemCheck.cpp index a84b9a6..19dd269 100644 --- a/src/T2DLL/T2DlgItemCheck.cpp +++ b/src/T2DLL/T2DlgItemCheck.cpp @@ -1,7 +1,10 @@ #include "T2DlgItemCheck.h" -T2DlgItemCheck::T2DlgItemCheck(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemCheck::T2DlgItemCheck(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemICheck(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemCheck::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemCheck::Create(const char* windowName, DWORD style, const RECT& inRect, CWnd* parentWnd, UINT nId) { + return T2DlgItemICheck::Create("DLGITEM:Check", style, inRect, parentWnd, nId); } diff --git a/src/T2DLL/T2DlgItemCheck.h b/src/T2DLL/T2DlgItemCheck.h index 856b77b..4764725 100644 --- a/src/T2DLL/T2DlgItemCheck.h +++ b/src/T2DLL/T2DlgItemCheck.h @@ -1,10 +1,9 @@ #pragma once #include "common.h" +#include "T2DlgItemICheck.h" -class T2DlgItemCheck { +class AFX_EXT_CLASS T2DlgItemCheck : public T2DlgItemICheck { public: - T2DlgItemCheck(T2TowerDoc*, T2ImageObj*, CPalette*); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - - virtual ~T2DlgItemCheck() {} + T2DlgItemCheck(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual BOOL Create(const char* windowName, DWORD style, const RECT& inRect, CWnd* parentWnd, UINT nId); }; diff --git a/src/T2DLL/T2DlgItemCustomerGage.cpp b/src/T2DLL/T2DlgItemCustomerGage.cpp index 42cd0a7..1a829cc 100644 --- a/src/T2DLL/T2DlgItemCustomerGage.cpp +++ b/src/T2DLL/T2DlgItemCustomerGage.cpp @@ -1,28 +1,47 @@ #include "T2DlgItemCustomerGage.h" +#include "T2Tenant.h" -T2DlgItemCustomerGage::T2DlgItemCustomerGage(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemCustomerGage::T2DlgItemCustomerGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemGageBase(towerDoc, imageObj, palette) + , mTenant(NULL) +{ } /*virtual*/ int T2DlgItemCustomerGage::GetMinValue() { + return 1; } /*virtual*/ int T2DlgItemCustomerGage::GetMaxValue() { + return 300; } /*virtual*/ int T2DlgItemCustomerGage::GetValue() { + int value = GetMinValue(); + if (mTenant) { + mTenant->UpdateResidencialEstimate(mTowerDoc); + value = mTenant->GetEstimate(); + } + return value; } /*virtual*/ int T2DlgItemCustomerGage::GetBlueValue() { + return 200; } /*virtual*/ int T2DlgItemCustomerGage::GetYellowValue() { + return 70; } -/*virtual*/ unsigned long T2DlgItemCustomerGage::GetGageColor(int) { +/*virtual*/ COLORREF T2DlgItemCustomerGage::GetGageColor(int value) { + return (value <= GetYellowValue()) ? PALETTERGB(255, 0, 0) : + (value <= GetBlueValue()) ? PALETTERGB(255, 255, 0) : + PALETTERGB(0, 0, 255); } -void T2DlgItemCustomerGage::SetTenant(T2Tenant*) { +void T2DlgItemCustomerGage::SetTenant(T2Tenant* tenant) { + mTenant = tenant; } -/*virtual*/ int T2DlgItemCustomerGage::IsDrawInterior() { +/*virtual*/ BOOL T2DlgItemCustomerGage::IsDrawInterior() { + return (mTenant != NULL); } diff --git a/src/T2DLL/T2DlgItemCustomerGage.h b/src/T2DLL/T2DlgItemCustomerGage.h index 2cb8780..2293b71 100644 --- a/src/T2DLL/T2DlgItemCustomerGage.h +++ b/src/T2DLL/T2DlgItemCustomerGage.h @@ -1,21 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItemGageBase.h" -class T2DlgItemCustomerGage { +class AFX_EXT_CLASS T2DlgItemCustomerGage : public T2DlgItemGageBase { public: - T2DlgItemCustomerGage(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemCustomerGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); + void SetTenant(T2Tenant*); + protected: virtual int GetMinValue(); virtual int GetMaxValue(); virtual int GetValue(); virtual int GetBlueValue(); virtual int GetYellowValue(); - virtual unsigned long GetGageColor(int); -public: - void SetTenant(T2Tenant*); -protected: - virtual int IsDrawInterior(); + virtual COLORREF GetGageColor(int value); + virtual BOOL IsDrawInterior(); -public: - virtual ~T2DlgItemCustomerGage() {} + T2Tenant *mTenant; }; diff --git a/src/T2DLL/T2DlgItemEdit.cpp b/src/T2DLL/T2DlgItemEdit.cpp index f906c49..d614890 100644 --- a/src/T2DLL/T2DlgItemEdit.cpp +++ b/src/T2DLL/T2DlgItemEdit.cpp @@ -1,40 +1,136 @@ +#include "CEditWFocus.h" #include "T2DlgItemEdit.h" -T2DlgItemEdit::T2DlgItemEdit(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemEdit::T2DlgItemEdit(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mSubItem(NULL) +{ } /*virtual*/ T2DlgItemEdit::~T2DlgItemEdit() { + delete mSubItem; } -/*virtual*/ void T2DlgItemEdit::SetFont(HFONT) { +/*virtual*/ void T2DlgItemEdit::SetFont(HFONT inFont) { + T2DlgItem::SetFont(inFont); + + if (mSubItem) + mSubItem->SetFont(CFont::FromHandle(inFont)); } -/*virtual*/ void T2DlgItemEdit::CreateSubItem(void*) { +/*virtual*/ void T2DlgItemEdit::CreateSubItem(void* inData) { + mSubItem = new CEditWFocus; + + int value = *((int *) inData); + + CRect rect; + GetClientRect(rect); + + if (rect.Height() < (value + 4)) + value = rect.Height() - 4; + + rect.top += (rect.Height() - value) / 2; + rect.left += 2; + rect.bottom = rect.top + value; + rect.right -= 2; + mSubItem->Create(WS_VISIBLE | WS_CHILD, rect, this, 0); } -/*virtual*/ int T2DlgItemEdit::OnT2DlgItemEraseBkgnd(CDC*) { +#pragma var_order(brush3, brush2, rect, pen1, pen2, save, pen3, brush1) +/*virtual*/ BOOL T2DlgItemEdit::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + CPen pen1; + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + + CPen pen2; + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + + CPen pen3; + pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + CBrush brush1; + CBrush brush2; + CBrush brush3; + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (IsWindowEnabled()) { + pDC->SelectObject(pen2); + pDC->MoveTo(rect.right - 1, rect.top); + pDC->LineTo(rect.left, rect.top); + pDC->LineTo(rect.left, rect.bottom); + + pDC->SelectObject(pen1); + pDC->MoveTo(rect.right - 1, rect.top + 1); + pDC->LineTo(rect.right - 1, rect.bottom - 1); + pDC->LineTo(rect.left, rect.bottom - 1); + + rect.DeflateRect(1, 1); + + brush2.CreateSolidBrush(PALETTERGB(255, 255, 255)); + pDC->SelectObject(brush2); + pDC->SelectObject(pen3); + pDC->Rectangle(rect); + + brush3.CreateSolidBrush(PALETTEINDEX(255)); + pDC->FrameRect(rect, &brush3); + } else { + brush1.CreateSolidBrush(PALETTERGB(179, 179, 179)); + pDC->FrameRect(rect, &brush1); + } + + pDC->RestoreDC(save); + return true; } -/*virtual*/ void T2DlgItemEdit::GetDescriptor(CString&) const { +/*virtual*/ void T2DlgItemEdit::GetDescriptor(CString& outStr) const { + if (mSubItem) + mSubItem->GetWindowText(outStr); } -/*virtual*/ void T2DlgItemEdit::SetDescriptor(const CString&) { +/*virtual*/ void T2DlgItemEdit::SetDescriptor(const CString& inStr) { + if (mSubItem) + mSubItem->SetWindowText(inStr); } /*virtual*/ int T2DlgItemEdit::GetValue() { + int value = 0; + CString str; + + GetDescriptor(str); + if (str.GetLength() > 0) { + value = atoi(str); + mValue = value; + } + + return value; } -/*virtual*/ void T2DlgItemEdit::SetValue(int) { +/*virtual*/ void T2DlgItemEdit::SetValue(int inValue) { + T2DlgItem::SetValue(inValue); + + CString str; + str.Format("%d", T2DlgItem::GetValue()); + SetDescriptor(str); } void T2DlgItemEdit::SelectAll() { + if (mSubItem) + mSubItem->SetSel(0, -1); } -/*virtual*/ void T2DlgItemEdit::OnT2SetFocus(CWnd*) { +/*virtual*/ void T2DlgItemEdit::OnT2SetFocus(CWnd* inWnd) { } -/*virtual*/ void T2DlgItemEdit::OnT2KillFocus(CWnd*) { +/*virtual*/ void T2DlgItemEdit::OnT2KillFocus(CWnd* inWnd) { } -/*virtual*/ void T2DlgItemEdit::OnT2DlgItemEnable(int) { +/*virtual*/ void T2DlgItemEdit::OnT2DlgItemEnable(BOOL inEnable) { + if (mSubItem) + mSubItem->EnableWindow(inEnable); + T2DlgItem::OnT2DlgItemEnable(inEnable); } diff --git a/src/T2DLL/T2DlgItemEdit.h b/src/T2DLL/T2DlgItemEdit.h index 5553e6e..8981724 100644 --- a/src/T2DLL/T2DlgItemEdit.h +++ b/src/T2DLL/T2DlgItemEdit.h @@ -1,21 +1,23 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemEdit { +class AFX_EXT_CLASS T2DlgItemEdit : public T2DlgItem { public: - T2DlgItemEdit(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemEdit(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemEdit(); - virtual void SetFont(HFONT); - virtual void CreateSubItem(void*); -protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); -public: - virtual void GetDescriptor(CString&) const; - virtual void SetDescriptor(const CString&); + virtual void SetFont(HFONT inFont); + virtual void CreateSubItem(void* inData); + virtual void GetDescriptor(CString& outStr) const; + virtual void SetDescriptor(const CString& inStr); virtual int GetValue(); - virtual void SetValue(int); + virtual void SetValue(int inValue); + virtual void OnT2SetFocus(CWnd* inWnd); + virtual void OnT2KillFocus(CWnd* inWnd); + virtual void OnT2DlgItemEnable(BOOL inEnable); void SelectAll(); - virtual void OnT2SetFocus(CWnd*); - virtual void OnT2KillFocus(CWnd*); - virtual void OnT2DlgItemEnable(int); +protected: + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + + CEditWFocus *mSubItem; }; diff --git a/src/T2DLL/T2DlgItemGageBase.cpp b/src/T2DLL/T2DlgItemGageBase.cpp index 4ef48e2..faa140a 100644 --- a/src/T2DLL/T2DlgItemGageBase.cpp +++ b/src/T2DLL/T2DlgItemGageBase.cpp @@ -1,19 +1,104 @@ #include "T2DlgItemGageBase.h" -T2DlgItemGageBase::T2DlgItemGageBase(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemGageBase::T2DlgItemGageBase(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItem(towerDoc, imageObj, palette) +{ } -/*virtual*/ int T2DlgItemGageBase::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemGageBase::OnT2DlgItemEraseBkgnd(CDC* dc) { + CRect clientRect; + GetClientRect(clientRect); + + int save = dc->SaveDC(); + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); + + CRect interior = clientRect; + if (IsDrawInterior()) + DrawInterior(dc, interior); + + dc->RestoreDC(save); + return true; } -/*virtual*/ void T2DlgItemGageBase::DrawInterior(CDC*, const CRect&) { +/*virtual*/ void T2DlgItemGageBase::DrawInterior(CDC* dc, const CRect& rect) { + dc->FillSolidRect(rect, RGB(255, 255, 255)); + + int pos = CalcPos(rect, GetMinValue(), GetMaxValue(), GetValue()); + CRect rect2(rect.left, rect.top, rect.left + pos, rect.bottom); + dc->FillSolidRect(rect2, GetGageColor(GetValue())); + + DrawBorderLines(dc, rect); } -void T2DlgItemGageBase::DrawBorderLines(CDC*, const CRect&) { +void T2DlgItemGageBase::DrawBorderLines(CDC* dc, const CRect& rect) { + CPen pen; + pen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + HPEN prevPen = *dc->SelectObject(&pen); + + int bluePos = CalcPos(rect, GetMinValue(), GetMaxValue(), GetBlueValue()); + dc->MoveTo(bluePos, rect.top); + dc->LineTo(bluePos, rect.bottom - 1); + + int yellowPos = CalcPos(rect, GetMinValue(), GetMaxValue(), GetYellowValue()); + dc->MoveTo(yellowPos, rect.top); + dc->LineTo(yellowPos, rect.bottom - 1); + + dc->MoveTo(rect.left, rect.top); + dc->LineTo(rect.left, rect.bottom - 1); + dc->LineTo(rect.right - 1, rect.bottom - 1); + dc->LineTo(rect.right - 1, rect.top); + dc->LineTo(rect.left, rect.top); + + dc->SelectObject(prevPen); } -void T2DlgItemGageBase::DrawValueByText(CDC*, const CRect&) { +void T2DlgItemGageBase::DrawValueByText(CDC* dc, const CRect& rect) { + CRect smallerRect = rect; + smallerRect.DeflateRect(2, 0); + + CString text; + text.Format("%d", GetValue()); + + CFont font; + font.CreateFont( + -(rect.Height() - 4), + 0, + 0, + 0, + FW_BOLD, + false, + false, + false, + DEFAULT_CHARSET, + OUT_TT_PRECIS, + CLIP_TT_ALWAYS, + PROOF_QUALITY, + DEFAULT_PITCH, + "Arial" + ); + + HFONT prevFont = *dc->SelectObject(&font); + dc->SetBkMode(TRANSPARENT); + dc->SetTextColor(PALETTERGB(255, 255, 255)); + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++) { + CRect shadowRect = smallerRect; + shadowRect.OffsetRect(x, y); + dc->DrawText(text, shadowRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); + } + } + + CRect textRect = smallerRect; + dc->SetTextColor(PALETTEINDEX(255)); + dc->DrawText(text, textRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE); + + dc->SelectObject(prevFont); } -int T2DlgItemGageBase::CalcPos(const CRect&, int, int, int) { +int T2DlgItemGageBase::CalcPos(const CRect& rect, int minValue, int maxValue, int value) { + return (minValue < maxValue) + ? (rect.left + ((rect.Width() * (value - minValue)) / (maxValue - minValue))) + : 0; } diff --git a/src/T2DLL/T2DlgItemGageBase.h b/src/T2DLL/T2DlgItemGageBase.h index f1e18d8..d2471a1 100644 --- a/src/T2DLL/T2DlgItemGageBase.h +++ b/src/T2DLL/T2DlgItemGageBase.h @@ -1,16 +1,21 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemGageBase { +class AFX_EXT_CLASS T2DlgItemGageBase : public T2DlgItem { public: - T2DlgItemGageBase(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemGageBase(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void DrawInterior(CDC*, const CRect&); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + virtual int GetMinValue() = 0; // 118 + virtual int GetMaxValue() = 0; // 11C + virtual int GetBlueValue() = 0; // 120 + virtual int GetYellowValue() = 0; // 124 + virtual COLORREF GetGageColor(int value) = 0; // 128 + virtual BOOL IsDrawInterior() = 0; // 12C + virtual void DrawInterior(CDC*, const CRect&); // 130 + void DrawBorderLines(CDC*, const CRect&); void DrawValueByText(CDC*, const CRect&); int CalcPos(const CRect&, int, int, int); - -public: - virtual ~T2DlgItemGageBase() {} }; diff --git a/src/T2DLL/T2DlgItemHScr.cpp b/src/T2DLL/T2DlgItemHScr.cpp index e282124..add3d0c 100644 --- a/src/T2DLL/T2DlgItemHScr.cpp +++ b/src/T2DLL/T2DlgItemHScr.cpp @@ -1,22 +1,149 @@ +#include "T2BitImage.h" #include "T2DlgItemHScr.h" -T2DlgItemHScr::T2DlgItemHScr(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemHScr::T2DlgItemHScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemScr(towerDoc, imageObj, palette) +{ } -/*virtual*/ int T2DlgItemHScr::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemHScr::OnT2DlgItemEraseBkgnd(CDC* dc) { + CRect rect; + GetClientRect(rect); + + int savedDC = dc->SaveDC(); + + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); + + CPen pen1; + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + + CPen pen2; + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + + CPen pen3; + pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + CBrush brush; + brush.CreateSolidBrush(PALETTERGB(204, 204, 204)); + + dc->SelectObject(pen2); + dc->MoveTo(rect.right - 1, rect.top); + dc->LineTo(rect.left, rect.top); + dc->LineTo(rect.left, rect.bottom); + + dc->SelectObject(pen1); + dc->MoveTo(rect.right - 1, rect.top + 1); + dc->LineTo(rect.right - 1, rect.bottom - 1); + dc->LineTo(rect.left, rect.bottom - 1); + + int thumbPosition, thumbSize; + CalcScrollBarThumb(&thumbPosition, &thumbSize); + + RECT imgRect; + T2BitImage *image = GetObjectImage( + imgRect, + "DLGITEM:LArrow", + !IsScrollable() ? 200 : (mUpImage == 100) ? 100 : 0); + + RECT destRect = rect; + destRect.left = 0; + destRect.right = imgRect.right - imgRect.left; + dc->Rectangle(&destRect); + image->CopyImage(dc, imgRect, destRect, 0, NULL); + + image = GetObjectImage( + imgRect, + "DLGITEM:LArrow", + !IsScrollable() ? 200 : (mDownImage == 100) ? 100 : 0); + + destRect = rect; + destRect.left = destRect.right - (imgRect.right - imgRect.left); + dc->Rectangle(&destRect); + image->CopyImage(dc, imgRect, destRect, 0, NULL); + + destRect.left = 16; + destRect.top = rect.top + 1; + destRect.right = thumbPosition; + destRect.bottom = rect.bottom - 1; + if (destRect.left < destRect.right) + dc->FillRect(&destRect, &brush); + + destRect.left = thumbPosition + thumbSize; + destRect.top = rect.top + 1; + destRect.right = rect.right - 16; + destRect.bottom = rect.bottom - 1; + if (destRect.left < destRect.right) + dc->FillRect(&destRect, &brush); + + if (thumbSize > 0) { + destRect.left = thumbPosition; + destRect.top = rect.top + 1; + destRect.right = thumbPosition + thumbSize; + destRect.bottom = rect.bottom - 1; + dc->FillRect(&destRect, &brush); + + dc->SelectObject(pen3); + dc->MoveTo(destRect.right - 1, destRect.top); + dc->LineTo(destRect.right - 1, destRect.bottom - 1); + dc->LineTo(destRect.left, destRect.bottom - 1); + dc->LineTo(destRect.left, destRect.top); + dc->LineTo(destRect.right - 1, destRect.top); + + dc->SelectObject(pen2); + dc->MoveTo(destRect.right - 2, destRect.top + 1); + dc->LineTo(destRect.right - 2, destRect.bottom - 2); + dc->LineTo(destRect.left + 1, destRect.bottom - 2); + + dc->SelectObject(pen1); + dc->MoveTo(destRect.right - 2, destRect.top + 1); + dc->LineTo(destRect.left + 1, destRect.top + 1); + dc->LineTo(destRect.left + 1, destRect.bottom - 1); + } + + dc->RestoreDC(savedDC); + + return true; } -/*virtual*/ int T2DlgItemHScr::ScrollBarHittest(CPoint) const { +/*virtual*/ int T2DlgItemHScr::ScrollBarHittest(CPoint pt) const { + if (!IsScrollable()) + return 0; + + CRect theCRect; + GetClientRect(theCRect); + + int area = 0; + + int theThumbPosition, theThumbSize; + CalcScrollBarThumb(&theThumbPosition, &theThumbSize); + + if (theCRect.left <= pt.x && pt.x < (theCRect.left + 16)) + area = Area_Up; + else if ((theCRect.left + 16) <= pt.x && pt.x < theThumbPosition) + area = Area_PageUp; + else if (theThumbPosition <= pt.x && pt.x < (theThumbPosition + theThumbSize)) + area = Area_Thumb; + else if ((theThumbPosition + theThumbSize) <= pt.x && pt.x < (theCRect.right - 16)) + area = Area_PageDown; + else if ((theCRect.right - 16) <= pt.x && pt.x < theCRect.right) + area = Area_Down; + + return area; } -/*virtual*/ void T2DlgItemHScr::GetUpButtonRect(const CRect&, CRect&) const { +/*virtual*/ void T2DlgItemHScr::GetUpButtonRect(const CRect& clientRect, CRect& buttonRect) const { + buttonRect = CRect(clientRect.left, clientRect.top, clientRect.left + 16, clientRect.bottom); } -/*virtual*/ void T2DlgItemHScr::GetDnButtonRect(const CRect&, CRect&) const { +/*virtual*/ void T2DlgItemHScr::GetDnButtonRect(const CRect& clientRect, CRect& buttonRect) const { + buttonRect = CRect(clientRect.right - 16, clientRect.top, clientRect.right, clientRect.bottom); } -/*virtual*/ int T2DlgItemHScr::PositionToValue(const CPoint&) const { +/*virtual*/ int T2DlgItemHScr::PositionToValue(const CPoint& pt) const { + return pt.x; } -/*virtual*/ int T2DlgItemHScr::PositionToValue(const CRect&) const { +/*virtual*/ int T2DlgItemHScr::PositionToValue(const CRect& rect) const { + return rect.Width(); } diff --git a/src/T2DLL/T2DlgItemHScr.h b/src/T2DLL/T2DlgItemHScr.h index 010cf80..67f56a4 100644 --- a/src/T2DLL/T2DlgItemHScr.h +++ b/src/T2DLL/T2DlgItemHScr.h @@ -1,17 +1,15 @@ #pragma once #include "common.h" +#include "T2DlgItemScr.h" -class T2DlgItemHScr { +class AFX_EXT_CLASS T2DlgItemHScr : public T2DlgItemScr { public: - T2DlgItemHScr(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemHScr(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); virtual int ScrollBarHittest(CPoint) const; virtual void GetUpButtonRect(const CRect&, CRect&) const; virtual void GetDnButtonRect(const CRect&, CRect&) const; virtual int PositionToValue(const CPoint&) const; virtual int PositionToValue(const CRect&) const; - -public: - virtual ~T2DlgItemHScr() {} }; diff --git a/src/T2DLL/T2DlgItemIButton.cpp b/src/T2DLL/T2DlgItemIButton.cpp index e3bd91f..3aa923a 100644 --- a/src/T2DLL/T2DlgItemIButton.cpp +++ b/src/T2DLL/T2DlgItemIButton.cpp @@ -1,7 +1,68 @@ +#include "GlobalFunc.h" +#include "T2BitImage.h" #include "T2DlgItemIButton.h" -T2DlgItemIButton::T2DlgItemIButton(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemIButton::T2DlgItemIButton(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemButtonBase(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemIButton::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemIButton::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect clientRect; + GetClientRect(clientRect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + DrawButtonBase(pDC, clientRect, GetPattern() == 100); + + CString text; + GetWindowText(text); + + CRect imageRect; + T2BitImage *image = GetObjectImage(imageRect, text); + + CRect rect30; + rect30.left = (clientRect.Width() - imageRect.Width()) / 2; + rect30.top = (clientRect.Height() - imageRect.Height()) / 2; + rect30.right = rect30.left + imageRect.Width(); + rect30.bottom = rect30.bottom + imageRect.Height(); + + int save2 = pDC->SaveDC(); + CRect rect74 = imageRect; + OffsetRect(&rect74, -imageRect.left, -imageRect.top); + + CDC newDC; + newDC.CreateCompatibleDC(pDC); + + int save3 = newDC.SaveDC(); + newDC.SelectPalette(mPalette, false); + newDC.RealizePalette(); + + HBITMAP hbitmap = Create256DIBitmap(newDC.m_hDC, rect74.right, rect74.bottom); + SelectObject(newDC.m_hDC, hbitmap); + + CBitmap bitmap; + CBrush brush; + image->CopyImage(&newDC, imageRect, rect74); + + if (!IsWindowEnabled()) { + bitmap.LoadBitmap(170); + brush.CreatePatternBrush(&bitmap); + pDC->SelectObject(brush); + pDC->BitBlt(rect30.left, rect30.top, rect30.Width(), rect30.Height(), &newDC, 0, 0, /*DPSDxax*/ 0xCA0749); + } else { + if (GetPattern() == 100) + rect30.OffsetRect(1, 1); + pDC->BitBlt(rect30.left, rect30.top, rect30.Width(), rect30.Height(), &newDC, 0, 0, SRCCOPY); + } + + newDC.RestoreDC(save3); + newDC.DeleteDC(); + DeleteObject(hbitmap); + + pDC->RestoreDC(save2); + pDC->RestoreDC(save); + + return true; } diff --git a/src/T2DLL/T2DlgItemIButton.h b/src/T2DLL/T2DlgItemIButton.h index 6529e0b..46a4391 100644 --- a/src/T2DLL/T2DlgItemIButton.h +++ b/src/T2DLL/T2DlgItemIButton.h @@ -1,12 +1,10 @@ #pragma once #include "common.h" +#include "T2DlgItemButtonBase.h" -class T2DlgItemIButton { +class AFX_EXT_CLASS T2DlgItemIButton : public T2DlgItemButtonBase { public: - T2DlgItemIButton(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemIButton(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - -public: - virtual ~T2DlgItemIButton() {} + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); }; diff --git a/src/T2DLL/T2DlgItemICheck.cpp b/src/T2DLL/T2DlgItemICheck.cpp index b138e73..e4c4900 100644 --- a/src/T2DLL/T2DlgItemICheck.cpp +++ b/src/T2DLL/T2DlgItemICheck.cpp @@ -1,22 +1,86 @@ +#include "T2BitImage.h" #include "T2DlgItemICheck.h" -T2DlgItemICheck::T2DlgItemICheck(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemICheck::T2DlgItemICheck(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemICheck::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemICheck::Create(const char* windowName, DWORD style, const RECT& inRect, CWnd* parentWnd, UINT nId) { + CRect rect = inRect; + CRect imageRect; + + if (GetObjectImage(imageRect, windowName)) { + rect.right = rect.left + imageRect.Width(); + rect.bottom = rect.top + imageRect.Height(); + } else { + rect.right = rect.left + 20; + rect.bottom = rect.top + 20; + } + + return T2DlgItem::Create(windowName, style, rect, parentWnd, nId); } -/*virtual*/ void T2DlgItemICheck::SetValue(int) { +/*virtual*/ void T2DlgItemICheck::SetValue(int inValue) { + T2DlgItem::SetValue(inValue); + + if (mValue == 0) + SetPattern(0); + else if (mValue == 1) + SetPattern(100); } -/*virtual*/ int T2DlgItemICheck::OnT2DlgItemEraseBkgnd(CDC*) { +#pragma var_order(pen, imageRect, brush, clientRect, theImage, text, save) +/*virtual*/ BOOL T2DlgItemICheck::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect clientRect; + GetClientRect(clientRect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen pen; + CBrush brush; + + CString text; + GetWindowText(text); + + RECT imageRect; + T2BitImage *theImage = GetObjectImage(imageRect, text, GetPattern()); + if (theImage) { + theImage->CopyImage(pDC, imageRect, clientRect); + } else { + pen.CreateStockObject(BLACK_PEN); + brush.CreateStockObject(WHITE_BRUSH); + pDC->SelectObject(&pen); + pDC->SelectObject(&brush); + + pDC->Rectangle(clientRect); + if (GetPattern() == 100) { + pDC->MoveTo(clientRect.left, clientRect.top); + pDC->LineTo(clientRect.right, clientRect.bottom); + + pDC->MoveTo(clientRect.left, clientRect.bottom - 1); + pDC->LineTo(clientRect.right, clientRect.top - 1); + } + } + + pDC->RestoreDC(save); + return true; } -/*virtual*/ void T2DlgItemICheck::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemICheck::OnT2DlgItemLButtonDown(UINT, CPoint) { + SetCapture(); + m74 = true; + + SetValue(!mValue); + Notify(mValue ? 2 : 3, NULL); } -/*virtual*/ void T2DlgItemICheck::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemICheck::OnT2DlgItemLButtonUp(UINT, CPoint) { + ReleaseCapture(); + m74 = false; } -/*virtual*/ void T2DlgItemICheck::OnT2DlgItemMouseMove(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemICheck::OnT2DlgItemMouseMove(UINT, CPoint) { } diff --git a/src/T2DLL/T2DlgItemICheck.h b/src/T2DLL/T2DlgItemICheck.h index 9c29d3a..ec0302b 100644 --- a/src/T2DLL/T2DlgItemICheck.h +++ b/src/T2DLL/T2DlgItemICheck.h @@ -1,17 +1,15 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemICheck { +class AFX_EXT_CLASS T2DlgItemICheck : public T2DlgItem { public: - T2DlgItemICheck(T2TowerDoc*, T2ImageObj*, CPalette*); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - virtual void SetValue(int); + T2DlgItemICheck(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual BOOL Create(const char* windowName, DWORD style, const RECT& inRect, CWnd* parentWnd, UINT nId); + virtual void SetValue(int inValue); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemMouseMove(unsigned int, CPoint); - -public: - virtual ~T2DlgItemICheck() {} + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT, CPoint); + virtual void OnT2DlgItemLButtonUp(UINT, CPoint); + virtual void OnT2DlgItemMouseMove(UINT, CPoint); }; diff --git a/src/T2DLL/T2DlgItemIRepeater.cpp b/src/T2DLL/T2DlgItemIRepeater.cpp new file mode 100644 index 0000000..40c8a2a --- /dev/null +++ b/src/T2DLL/T2DlgItemIRepeater.cpp @@ -0,0 +1,42 @@ +#include "T2DlgItemIRepeater.h" + +T2DlgItemIRepeater::T2DlgItemIRepeater(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette) + : T2DlgItemIButton(inDoc, inImageObj, inPalette) +{ +} + +T2DlgItemIRepeater::~T2DlgItemIRepeater() { +} + +/*virtual*/ void T2DlgItemIRepeater::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + SetCapture(); + + mIsClicked = true; + m74 = true; + SetPattern(100); + Invalidate(); + + Notify(GetDlgCtrlID(), 0, NULL); + mTimerID = SetTimer(999, 100, NULL); +} + +/*virtual*/ void T2DlgItemIRepeater::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) { + if (mIsClicked) { + if (mTimerID) + KillTimer(mTimerID); + + SetPattern(0); + ReleaseCapture(); + mIsClicked = false; + + if (m74) { + m74 = false; + Invalidate(); + } + } +} + +/*virtual*/ void T2DlgItemIRepeater::OnT2Timer(UINT inID) { + if (inID == mTimerID && m74) + Notify(GetDlgCtrlID(), 0, NULL); +} diff --git a/src/T2DLL/T2DlgItemIRepeater.h b/src/T2DLL/T2DlgItemIRepeater.h new file mode 100644 index 0000000..c27e943 --- /dev/null +++ b/src/T2DLL/T2DlgItemIRepeater.h @@ -0,0 +1,16 @@ +#pragma once +#include "common.h" +#include "T2DlgItemIButton.h" + +class T2DlgItemIRepeater : public T2DlgItemIButton { +public: + T2DlgItemIRepeater(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette); + ~T2DlgItemIRepeater(); + +protected: + virtual void OnT2Timer(UINT inID); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt); + + UINT mTimerID; +}; diff --git a/src/T2DLL/T2DlgItemImage.cpp b/src/T2DLL/T2DlgItemImage.cpp index 499e1dd..23db042 100644 --- a/src/T2DLL/T2DlgItemImage.cpp +++ b/src/T2DLL/T2DlgItemImage.cpp @@ -1,16 +1,57 @@ +#include "T2BitImage.h" #include "T2DlgItemImage.h" -T2DlgItemImage::T2DlgItemImage(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemImage::T2DlgItemImage(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemImage::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ int T2DlgItemImage::Create(const char* inName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { +#pragma var_order(clientRect, image, imageRect) + CRect imageRect; + mValue = -1; + T2BitImage *image = GetObjectImage(imageRect, inName, mValue); + + CRect clientRect = inRect; + if (image) { + clientRect.right = clientRect.left + imageRect.Width(); + clientRect.bottom = clientRect.top + imageRect.Height(); + } + + return T2DlgItem::Create(inName, inStyle, clientRect, inParentWnd, inID); } -/*virtual*/ int T2DlgItemImage::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemImage::OnT2DlgItemEraseBkgnd(CDC* pDC) { +#pragma var_order(imageRect, clientRect, image) + CRect clientRect; + CRect imageRect; + + GetClientRect(clientRect); + T2BitImage *image = GetDrawImage(imageRect); + + if (image) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + SetStretchBltMode(pDC->m_hDC, COLORONCOLOR); + StretchDIBits(pDC->m_hDC, clientRect.left, clientRect.top, clientRect.Width(), clientRect.Height(), imageRect.left, imageRect.bottom + 1, imageRect.Width(), -imageRect.Height(), image->mData, (BITMAPINFO *) &image->mBitmap, DIB_PAL_COLORS, SRCCOPY); + + pDC->RestoreDC(save); + } + + return true; } void T2DlgItemImage::AdjustSize() { + CRect imageRect; + + if (GetDrawImage(imageRect)) + SetWindowPos(NULL, 0, 0, imageRect.Width(), imageRect.Height(), SWP_NOMOVE | SWP_NOZORDER); } -T2BitImage* T2DlgItemImage::GetDrawImage(CRect&) const { +T2BitImage* T2DlgItemImage::GetDrawImage(CRect& outRect) const { + CString text; + GetDescriptor(text); + return GetObjectImage(outRect, text, mValue); } diff --git a/src/T2DLL/T2DlgItemImage.h b/src/T2DLL/T2DlgItemImage.h index 96f16c9..c07c21d 100644 --- a/src/T2DLL/T2DlgItemImage.h +++ b/src/T2DLL/T2DlgItemImage.h @@ -1,17 +1,13 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemImage { -public: - T2DlgItemImage(T2TowerDoc*, T2ImageObj*, CPalette*); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); -protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); +class AFX_EXT_CLASS T2DlgItemImage : public T2DlgItem { public: + T2DlgItemImage(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual int Create(const char* inName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); void AdjustSize(); protected: - T2BitImage* GetDrawImage(CRect&) const; - -public: - virtual ~T2DlgItemImage() {} + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + T2BitImage* GetDrawImage(CRect& outRect) const; }; diff --git a/src/T2DLL/T2DlgItemImageTable.cpp b/src/T2DLL/T2DlgItemImageTable.cpp index a54eb46..e4b8b21 100644 --- a/src/T2DLL/T2DlgItemImageTable.cpp +++ b/src/T2DLL/T2DlgItemImageTable.cpp @@ -1,12 +1,20 @@ #include "T2DlgItemImageTable.h" -T2DlgItemImageTable::T2DlgItemImageTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemImageTable::T2DlgItemImageTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemTable(towerDoc, imageObj, palette) +{ } -T2DlgItemImageTable::T2DlgItemImageTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemImageTable::T2DlgItemImageTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemTable(rows, cols, rowHeight, colWidth, cellDataSize, towerDoc, imageObj, palette) +{ } -/*virtual*/ void T2DlgItemImageTable::DrawCell(CDC*, const TableCellT&) { +/*virtual*/ void T2DlgItemImageTable::DrawCell(CDC* dc, const TableCellT& cell) { + if (EqualCell(cell, mSelectedCell)) + DrawCellSelf(dc, cell, true); + else + DrawCellSelf(dc, cell, false); } /*virtual*/ void T2DlgItemImageTable::HiliteCell(CDC*, const TableCellT&) { diff --git a/src/T2DLL/T2DlgItemImageTable.h b/src/T2DLL/T2DlgItemImageTable.h index ab768ba..78c2966 100644 --- a/src/T2DLL/T2DlgItemImageTable.h +++ b/src/T2DLL/T2DlgItemImageTable.h @@ -1,15 +1,14 @@ #pragma once #include "common.h" +#include "T2DlgItemTable.h" -class T2DlgItemImageTable { +class AFX_EXT_CLASS T2DlgItemImageTable : public T2DlgItemTable { public: - T2DlgItemImageTable(T2TowerDoc*, T2ImageObj*, CPalette*); - T2DlgItemImageTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemImageTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); + T2DlgItemImageTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); protected: virtual void DrawCell(CDC*, const TableCellT&); virtual void HiliteCell(CDC*, const TableCellT&); virtual void UnhiliteCell(CDC*, const TableCellT&); - -public: - virtual ~T2DlgItemImageTable() {} + virtual void DrawCellSelf(CDC *dc, const TableCellT& cell, BOOL isSelected) = 0; }; diff --git a/src/T2DLL/T2DlgItemListBox.cpp b/src/T2DLL/T2DlgItemListBox.cpp index d476f33..66ad24e 100644 --- a/src/T2DLL/T2DlgItemListBox.cpp +++ b/src/T2DLL/T2DlgItemListBox.cpp @@ -1,40 +1,109 @@ #include "T2DlgItemListBox.h" -T2DlgItemListBox::T2DlgItemListBox(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemListBox::T2DlgItemListBox(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mListBox(NULL) +{ } /*virtual*/ T2DlgItemListBox::~T2DlgItemListBox() { + delete mListBox; } -/*virtual*/ void T2DlgItemListBox::SetFont(HFONT) { +/*virtual*/ void T2DlgItemListBox::SetFont(HFONT inFont) { + T2DlgItem::SetFont(inFont); + if (mListBox) + mListBox->SetFont(CFont::FromHandle(inFont)); } /*virtual*/ void T2DlgItemListBox::CreateSubItem() { + mListBox = new CListBox; + + CRect rect; + GetClientRect(rect); + mListBox->Create(LBS_NOTIFY | WS_VSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD, rect, this, 0); } /*virtual*/ int T2DlgItemListBox::GetCount() { + int result = -1; + if (mListBox) { + result = mListBox->GetCount(); + if (result == -1) + result = -1; // very useful + } + return result; } /*virtual*/ int T2DlgItemListBox::ResetContent() { + int result = -1; + if (mListBox) + mListBox->ResetContent(); + return result; } -/*virtual*/ int T2DlgItemListBox::AddString(CString&) { +/*virtual*/ int T2DlgItemListBox::AddString(CString& inString) { + int result = -1; + if (mListBox) { + result = mListBox->AddString(inString); + if (result == -1) + result = -1; // still very useful + } + return result; } -/*virtual*/ int T2DlgItemListBox::DeleteString(unsigned int) { +/*virtual*/ int T2DlgItemListBox::DeleteString(unsigned int inIndex) { + int result = -1; + if (mListBox) { + result = mListBox->DeleteString(inIndex); + if (result == -1) + result = -1; // quite useful + } + return result; } /*virtual*/ int T2DlgItemListBox::GetCurSel() { + int result = -1; + if (mListBox) { + result = mListBox->GetCurSel(); + if (result == -1) + result = -1; // yep, you guessed it, useful + } + return result; } -/*virtual*/ int T2DlgItemListBox::SetItemData(int, unsigned long) { +/*virtual*/ int T2DlgItemListBox::SetItemData(int inIndex, DWORD inData) { + int result = -1; + if (mListBox) { + result = mListBox->SetItemData(inIndex, inData); + if (result == -1) + result = -1; // not very useful + } + return result; } -/*virtual*/ unsigned long T2DlgItemListBox::GetItemData(int) { +/*virtual*/ DWORD T2DlgItemListBox::GetItemData(int inIndex) { + DWORD result = (DWORD) -1; + if (mListBox) { + result = mListBox->GetItemData(inIndex); + if (result == (DWORD) -1) + result = (DWORD) -1; // hmmm + } + return result; } -/*virtual*/ int T2DlgItemListBox::SetItemDataPtr(int, void*) { +/*virtual*/ int T2DlgItemListBox::SetItemDataPtr(int inIndex, void* inData) { + int result = -1; + if (mListBox) { + result = mListBox->SetItemDataPtr(inIndex, inData); + if (result == -1) + result = -1; // also of questionable utility + } + return result; } -/*virtual*/ void* T2DlgItemListBox::GetItemDataPtr(int) { +/*virtual*/ void* T2DlgItemListBox::GetItemDataPtr(int inIndex) { + void *result = (void *) -1; + if (mListBox) + result = mListBox->GetItemDataPtr(inIndex); + return result; } diff --git a/src/T2DLL/T2DlgItemListBox.h b/src/T2DLL/T2DlgItemListBox.h index ac69209..5c1bf48 100644 --- a/src/T2DLL/T2DlgItemListBox.h +++ b/src/T2DLL/T2DlgItemListBox.h @@ -1,19 +1,23 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemListBox { +class AFX_EXT_CLASS T2DlgItemListBox : public T2DlgItem { public: - T2DlgItemListBox(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemListBox(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemListBox(); virtual void SetFont(HFONT); virtual void CreateSubItem(); virtual int GetCount(); virtual int ResetContent(); - virtual int AddString(CString&); - virtual int DeleteString(unsigned int); + virtual int AddString(CString& inString); + virtual int DeleteString(unsigned int inIndex); virtual int GetCurSel(); - virtual int SetItemData(int, unsigned long); - virtual unsigned long GetItemData(int); - virtual int SetItemDataPtr(int, void*); - virtual void* GetItemDataPtr(int); + virtual int SetItemData(int inIndex, DWORD inData); + virtual DWORD GetItemData(int inIndex); + virtual int SetItemDataPtr(int inIndex, void* inData); + virtual void* GetItemDataPtr(int inIndex); + +protected: + CListBox *mListBox; }; diff --git a/src/T2DLL/T2DlgItemMerchandiseField.cpp b/src/T2DLL/T2DlgItemMerchandiseField.cpp new file mode 100644 index 0000000..11247d1 --- /dev/null +++ b/src/T2DLL/T2DlgItemMerchandiseField.cpp @@ -0,0 +1,43 @@ +#include "CEditWFocus.h" +#include "T2Dialog.h" +#include "T2DlgItemMerchandiseField.h" + +T2DlgItemMerchandiseField::T2DlgItemMerchandiseField(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette) + : T2DlgItemEdit(inDoc, inImageObj, inPalette) +{ +} + +/*virtual*/ T2DlgItemMerchandiseField::~T2DlgItemMerchandiseField() { +} + +/*virtual*/ void T2DlgItemMerchandiseField::CreateSubItem(void *inData) { + T2DlgItemEdit::CreateSubItem(inData); + if (mSubItem) + mSubItem->SetReadOnly(); +} + +/*virtual*/ void T2DlgItemMerchandiseField::OnT2SetFocus(CWnd *inWnd) { + T2DlgItemEdit::OnT2SetFocus(inWnd); + + T2DlgItem *theField1 = ((T2Dialog *) GetParent())->GetT2DlgItem(GetDlgCtrlID() + 1); + if (theField1) { + theField1->SetValue(GetValue()); + theField1->ShowWindow(SW_SHOWNORMAL); + } + + T2DlgItem *theField2 = ((T2Dialog *) GetParent())->GetT2DlgItem(GetDlgCtrlID() + 2); + if (theField2) + theField2->ShowWindow(SW_HIDE); +} + +/*virtual*/ void T2DlgItemMerchandiseField::OnT2KillFocus(CWnd *inWnd) { + T2DlgItemEdit::OnT2KillFocus(inWnd); + + T2DlgItem *theField1 = ((T2Dialog *) GetParent())->GetT2DlgItem(GetDlgCtrlID() + 1); + if (theField1) + theField1->ShowWindow(SW_HIDE); + + T2DlgItem *theField2 = ((T2Dialog *) GetParent())->GetT2DlgItem(GetDlgCtrlID() + 2); + if (theField2) + theField2->ShowWindow(SW_SHOWNORMAL); +} diff --git a/src/T2DLL/T2DlgItemMerchandiseField.h b/src/T2DLL/T2DlgItemMerchandiseField.h new file mode 100644 index 0000000..7b42004 --- /dev/null +++ b/src/T2DLL/T2DlgItemMerchandiseField.h @@ -0,0 +1,13 @@ +#pragma once +#include "common.h" +#include "T2DlgItemEdit.h" + +class T2DlgItemMerchandiseField : public T2DlgItemEdit { +public: + T2DlgItemMerchandiseField(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette); + ~T2DlgItemMerchandiseField(); + + void CreateSubItem(void *inData); + void OnT2SetFocus(CWnd *inWnd); + void OnT2KillFocus(CWnd *inWnd); +}; diff --git a/src/T2DLL/T2DlgItemMovie.cpp b/src/T2DLL/T2DlgItemMovie.cpp index 4644fe2..2a66e80 100644 --- a/src/T2DLL/T2DlgItemMovie.cpp +++ b/src/T2DLL/T2DlgItemMovie.cpp @@ -1,30 +1,212 @@ +#include "GlobalFunc.h" +#include "T2BitImage.h" #include "T2DlgItemMovie.h" +#include "T2ImageObj.h" -T2DlgItemMovie::T2DlgItemMovie(T2TowerDoc*, T2ImageObj*, CPalette*) { +// love how this is obviously based off player/playfile/playfile.cpp +// from the DirectX SDK + +#define WM_GRAPHNOTIFY WM_USER+13 +#define HELPER_RELEASE(x) { if (x) x->Release(); x = NULL; } + +T2DlgItemMovie::T2DlgItemMovie(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ + mImage = NULL; + mImageObj = NULL; + mPlaying = false; + + mUnusedInterface = NULL; + mGraph = NULL; + mMediaControl = NULL; + mMediaEvent = NULL; + mVideoWindow = NULL; + mMediaPosition = NULL; } /*virtual*/ T2DlgItemMovie::~T2DlgItemMovie() { + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; } -/*virtual*/ int T2DlgItemMovie::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2DlgItemMovie::OnT2DlgItemCreate(CREATESTRUCT* cs) { + return T2DlgItem::OnT2DlgItemCreate(cs); } -/*virtual*/ int T2DlgItemMovie::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemMovie::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (mImageObj) { + int objectID = mImageObj->FindObject("STIL"); + mImageObj->DrawObject(pDC, objectID, rect); + } + + pDC->RestoreDC(save); + return true; } -void T2DlgItemMovie::SetStillScreenID(const char*, int) { +void T2DlgItemMovie::SetStillScreenID(const char* inName, int inResID) { + if (mPlaying) + CloseMovie(); + mPlaying = false; + + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; + + InvalidateRect(NULL); + +#line 76 + mImage = DEBUG_NEW T2BitImage(inName, inResID, true); + mImageObj = DEBUG_NEW T2ImageObj; + mImageObj->AddObject("STIL", -1, *mImage, NULL, false, false); } -void T2DlgItemMovie::SetQTMovieName(CString&) { +void T2DlgItemMovie::SetQTMovieName(CString& inName) { + CString dirName = "MOVIE"; + + if (inName.GetLength()) { + CString str = ""; + + if (str == "") { +#pragma var_order(path, ofStruct, towerDir) + char towerDir[512]; + GetTowerDirectory(towerDir); + + CString path = towerDir; + path = path + dirName + "\\" + inName; + OFSTRUCT ofStruct; + if (OpenFile(path, &ofStruct, OF_EXIST) != HFILE_ERROR) + str = path; + } + + if (str == "") { +#pragma var_order(volName, root, fsFlags) + CString root = GetInstallSourceDrive(); + root += ":\\"; + + char volName[256]; + volName[0] = 0; + DWORD fsFlags; + GetVolumeInformation(root, volName, 256, NULL, 0, &fsFlags, NULL, 0); + + if (!strcmp(volName, "TheTower2")) { + CString path = root + dirName + "\\" + inName; + OFSTRUCT ofStruct; + if (OpenFile(path, &ofStruct, OF_EXIST) != HFILE_ERROR) + str = path; + } + } + + if (str != "") + PlayMovie(str); + } } -void T2DlgItemMovie::PlayMovie(const char*) { +void T2DlgItemMovie::PlayMovie(const char* inName) { + if (mPlaying) + CloseMovie(); + + WCHAR *wFile = (WCHAR *) malloc(1024); + // bug: this passes 1024 and not 512 as cchWideChar + MultiByteToWideChar(CP_ACP, 0, inName, -1, wFile, 1024); + + HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) &mGraph); + if (SUCCEEDED(hr)) { + mGraph->QueryInterface(IID_IMediaControl, (void **) &mMediaControl); + mGraph->QueryInterface(IID_IMediaEventEx, (void **) &mMediaEvent); + mGraph->QueryInterface(IID_IVideoWindow, (void **) &mVideoWindow); + mGraph->QueryInterface(IID_IMediaPosition, (void **) &mMediaPosition); + + hr = mGraph->RenderFile(wFile, NULL); + mVideoWindow->put_Owner((OAHWND) m_hWnd); + mVideoWindow->put_WindowStyle(WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD); + mMediaEvent->SetNotifyWindow((OAHWND) m_hWnd, WM_GRAPHNOTIFY, 0); + mVideoWindow->put_BackgroundPalette(-1); + + CRect videoRect; + mVideoWindow->GetWindowPosition(&videoRect.left, &videoRect.top, &videoRect.right, &videoRect.bottom); + videoRect.left = 0; + videoRect.top = 0; + + CRect clientRect; + GetClientRect(clientRect); + + SIZE sz; + + sz.cy = videoRect.Height(); + videoRect.top = (clientRect.Height() - sz.cy) / 2; + videoRect.bottom = videoRect.top + sz.cy; + + sz.cx = videoRect.Width(); + videoRect.left = (clientRect.Width() - sz.cx) / 2; + videoRect.right = videoRect.left + sz.cx; + + mVideoWindow->SetWindowPosition(videoRect.left, videoRect.top, videoRect.Width(), videoRect.Height()); + + if (SUCCEEDED(hr)) { + mMediaControl->Run(); + mPlaying = true; + } + } + + if (FAILED(hr)) { + // "Active Movieの初期化に失敗しました。" - Failed to initialize Active Movie. + MessageBox( + "Active Movie\x82\xCC\x8F\x89\x8A\xFA\x89\xBB\x82\xC9\x8E\xB8\x94\x73\x82\xB5\x82\xDC\x82\xB5\x82\xBD\x81\x42"); + } + + free(wFile); } void T2DlgItemMovie::CloseMovie() { + if (mMediaControl) + mMediaControl->Stop(); + + if (mVideoWindow) { + mVideoWindow->put_Visible(0); + mVideoWindow->put_Owner(NULL); + HELPER_RELEASE(mVideoWindow); + } + + HELPER_RELEASE(mUnusedInterface); + HELPER_RELEASE(mGraph); + HELPER_RELEASE(mMediaControl); + HELPER_RELEASE(mMediaEvent); + HELPER_RELEASE(mMediaPosition); } -/*virtual*/ long T2DlgItemMovie::WindowProc(unsigned int, unsigned int, long) { +/*virtual*/ LRESULT T2DlgItemMovie::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { + switch (message) { + case WM_GRAPHNOTIFY: + { + HRESULT hr; + LONG evCode; + LONG evParam1; + LONG evParam2; + while (SUCCEEDED(mMediaEvent->GetEvent(&evCode, &evParam1, &evParam2, 0))) { + hr = mMediaEvent->FreeEventParams(evCode, evParam1, evParam2); + if (evCode == EC_COMPLETE && mVideoWindow) { + mMediaPosition->put_CurrentPosition(0); + mMediaControl->Run(); + } + } + break; + } + case WM_DESTROY: + CloseMovie(); + break; + } + + return CWnd::WindowProc(message, wParam, lParam); } /*virtual*/ void T2DlgItemMovie::OnT2Close() { diff --git a/src/T2DLL/T2DlgItemMovie.h b/src/T2DLL/T2DlgItemMovie.h index 48b8dd7..3d2c2dc 100644 --- a/src/T2DLL/T2DlgItemMovie.h +++ b/src/T2DLL/T2DlgItemMovie.h @@ -1,21 +1,33 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" +// DirectShow +#include <strmif.h> +#include <control.h> +#include <uuids.h> +#include <evcode.h> -class T2DlgItemMovie { +class AFX_EXT_CLASS T2DlgItemMovie : public T2DlgItem { public: - T2DlgItemMovie(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemMovie(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemMovie(); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + void SetStillScreenID(const char* inName, int inResID); + void SetQTMovieName(CString& inName); protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); - virtual int OnT2DlgItemEraseBkgnd(CDC*); -public: - void SetStillScreenID(const char*, int); - void SetQTMovieName(CString&); -protected: - void PlayMovie(const char*); - void CloseMovie(); -public: - virtual long WindowProc(unsigned int, unsigned int, long); -protected: + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + void PlayMovie(const char* inName); + void CloseMovie(); virtual void OnT2Close(); + + T2BitImage *mImage; + T2ImageObj *mImageObj; + BOOL mPlaying; + IUnknown *mUnusedInterface; + IGraphBuilder *mGraph; + IMediaControl *mMediaControl; + IMediaEventEx *mMediaEvent; + IVideoWindow *mVideoWindow; + IMediaPosition *mMediaPosition; }; diff --git a/src/T2DLL/T2DlgItemOK.cpp b/src/T2DLL/T2DlgItemOK.cpp index 287d992..3f1cdf6 100644 --- a/src/T2DLL/T2DlgItemOK.cpp +++ b/src/T2DLL/T2DlgItemOK.cpp @@ -1,7 +1,16 @@ #include "T2DlgItemOK.h" -T2DlgItemOK::T2DlgItemOK(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemOK::T2DlgItemOK(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemIButton(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemOK::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemOK::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { + CRect rectToUse = rect; + CRect imageRect; + GetObjectImage(imageRect, "DLGITEM:OK"); + + rectToUse.right = rectToUse.left + imageRect.Width(); + rectToUse.bottom = rectToUse.top + imageRect.Height(); + return T2DlgItem::Create("DLGITEM:OK", style, rectToUse, parentWnd, nId); } diff --git a/src/T2DLL/T2DlgItemOK.h b/src/T2DLL/T2DlgItemOK.h index 4296ec1..37a1712 100644 --- a/src/T2DLL/T2DlgItemOK.h +++ b/src/T2DLL/T2DlgItemOK.h @@ -1,10 +1,9 @@ #pragma once #include "common.h" +#include "T2DlgItemIButton.h" -class T2DlgItemOK { +class AFX_EXT_CLASS T2DlgItemOK : public T2DlgItemIButton { public: - T2DlgItemOK(T2TowerDoc*, T2ImageObj*, CPalette*); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - - virtual ~T2DlgItemOK() {} + T2DlgItemOK(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual BOOL Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId); }; diff --git a/src/T2DLL/T2DlgItemPPLEvalGage.cpp b/src/T2DLL/T2DlgItemPPLEvalGage.cpp index 27e821b..164a3ab 100644 --- a/src/T2DLL/T2DlgItemPPLEvalGage.cpp +++ b/src/T2DLL/T2DlgItemPPLEvalGage.cpp @@ -1,28 +1,43 @@ #include "T2DlgItemPPLEvalGage.h" +#include "T2People.h" +#include "T2PeopleDef.h" -T2DlgItemPPLEvalGage::T2DlgItemPPLEvalGage(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemPPLEvalGage::T2DlgItemPPLEvalGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemGageBase(towerDoc, imageObj, palette) + , mPeople(NULL) +{ } /*virtual*/ int T2DlgItemPPLEvalGage::GetMinValue() { + return 0; } /*virtual*/ int T2DlgItemPPLEvalGage::GetMaxValue() { + return (mPeople && mPeople->GetMatterDef()) ? ((T2PeopleDef *) mPeople->GetMatterDef())->GetStressMax() : GetMinValue(); } /*virtual*/ int T2DlgItemPPLEvalGage::GetValue() { + return mPeople ? mPeople->GetAverageStress() : GetMinValue(); } /*virtual*/ int T2DlgItemPPLEvalGage::GetBlueValue() { + return (mPeople && mPeople->GetMatterDef()) ? ((T2PeopleDef *) mPeople->GetMatterDef())->GetStressBlueLimit() : GetMinValue(); } /*virtual*/ int T2DlgItemPPLEvalGage::GetYellowValue() { + return (mPeople && mPeople->GetMatterDef()) ? ((T2PeopleDef *) mPeople->GetMatterDef())->GetStressYellowLimit() : GetMinValue(); } -void T2DlgItemPPLEvalGage::SetPeople(T2People*) { +void T2DlgItemPPLEvalGage::SetPeople(T2People* people) { + mPeople = people; } -/*virtual*/ unsigned long T2DlgItemPPLEvalGage::GetGageColor(int) { +/*virtual*/ COLORREF T2DlgItemPPLEvalGage::GetGageColor(int value) { + return (value <= GetBlueValue()) ? PALETTERGB(0, 0, 255) : + (value <= GetYellowValue()) ? PALETTERGB(255, 255, 0) : + PALETTERGB(255, 0, 0); } -/*virtual*/ int T2DlgItemPPLEvalGage::IsDrawInterior() { +/*virtual*/ BOOL T2DlgItemPPLEvalGage::IsDrawInterior() { + return (mPeople != NULL); } diff --git a/src/T2DLL/T2DlgItemPPLEvalGage.h b/src/T2DLL/T2DlgItemPPLEvalGage.h index fc61f9b..4252a22 100644 --- a/src/T2DLL/T2DlgItemPPLEvalGage.h +++ b/src/T2DLL/T2DlgItemPPLEvalGage.h @@ -1,21 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItemGageBase.h" -class T2DlgItemPPLEvalGage { +class AFX_EXT_CLASS T2DlgItemPPLEvalGage : public T2DlgItemGageBase { public: - T2DlgItemPPLEvalGage(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemPPLEvalGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); + void SetPeople(T2People* people); + protected: virtual int GetMinValue(); virtual int GetMaxValue(); virtual int GetValue(); virtual int GetBlueValue(); virtual int GetYellowValue(); -public: - void SetPeople(T2People*); -protected: - virtual unsigned long GetGageColor(int); - virtual int IsDrawInterior(); + virtual COLORREF GetGageColor(int value); + virtual BOOL IsDrawInterior(); -public: - virtual ~T2DlgItemPPLEvalGage() {} + T2People *mPeople; }; diff --git a/src/T2DLL/T2DlgItemPeopleView.cpp b/src/T2DLL/T2DlgItemPeopleView.cpp index ff64ccc..d0689a5 100644 --- a/src/T2DLL/T2DlgItemPeopleView.cpp +++ b/src/T2DLL/T2DlgItemPeopleView.cpp @@ -1,49 +1,214 @@ +#include "LArray.h" +#include "T2BitImage.h" +#include "T2DlgItemHScr.h" #include "T2DlgItemPeopleView.h" +#include "T2InfoDialog.h" +#include "T2People.h" +#include "T2PeopleLinkIterator.h" +#include "UT2Coordinate.h" -T2DlgItemPeopleView::T2DlgItemPeopleView(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemPeopleView::T2DlgItemPeopleView(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ +#line 20 + mArray = DEBUG_NEW LArray(sizeof(T2People *)); + mImage = NULL; } /*virtual*/ T2DlgItemPeopleView::~T2DlgItemPeopleView() { + delete mArray; + if (mImage) + delete mImage; } -/*virtual*/ int T2DlgItemPeopleView::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemPeopleView::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { + mParent = inParentWnd; + return T2DlgItem::Create(inWindowName, inStyle, inRect, inParentWnd, inID); } -/*virtual*/ int T2DlgItemPeopleView::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2DlgItemPeopleView::OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct) { + T2DlgItem::OnT2DlgItemCreate(inCreateStruct); + + CRect rect; + GetClientRect(&rect); + if (rect.Height() >= (36 - (UT2Coordinate::CalcRoofThick(0) + UT2Coordinate::CalcFloorThick(0)) + 16)) { + CRect scrollerRect = rect; + scrollerRect.top = scrollerRect.bottom - 16; + +#line 47 + T2DlgItemHScr *theScroller = DEBUG_NEW T2DlgItemHScr(mTowerDoc, mImageObj, mPalette); + theScroller->Create("", WS_VISIBLE | WS_CHILD, scrollerRect, this, 100); + } + + return 0; } -/*virtual*/ int T2DlgItemPeopleView::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemPeopleView::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2DlgItemHScr *theScr = (T2DlgItemHScr *) GetDlgItem(100); + int theScrollPos = theScr ? theScr->GetValue() : 0; + + CRect rect; + GetClientRect(rect); + if (theScr) + rect.bottom -= 15; + + int saved = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen thePen; + thePen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + pDC->SelectObject(thePen); + pDC->SelectObject(CBrush::FromHandle((HBRUSH) GetStockObject(WHITE_BRUSH))); + pDC->Rectangle(rect); + + rect.DeflateRect(1, 1); + pDC->IntersectClipRect(rect); + + if (mImage) { + CRect rect2(0, UT2Coordinate::CalcRoofThick(0), mImage->mBitmap.header.biWidth, mImage->mBitmap.header.biHeight - UT2Coordinate::CalcFloorThick(0)); + StretchDIBits(pDC->m_hDC, rect.left - theScrollPos, rect.top, mFullWidth, mFullHeight, rect2.left, rect2.bottom + 1, rect2.Width(), -rect2.Height(), mImage->mData, (const BITMAPINFO *) &mImage->mBitmap, DIB_PAL_COLORS, SRCCOPY); + } + + pDC->RestoreDC(saved); + return true; } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + if (mArray) { + T2DlgItemHScr *scroll = (T2DlgItemHScr *) GetDlgItem(100); + int theScrollValue = scroll ? scroll->GetValue() : 0; + + int theClickH = ((inPt.x + theScrollValue - 1) * (36 - (UT2Coordinate::CalcFloorThick(0) + UT2Coordinate::CalcRoofThick(0)))) / mFullHeight; + int h = 0; + + LArrayIterator iterator(*mArray); + T2People *thePeople; + + while (iterator.Next(&thePeople)) { + h += thePeople->GetWidth() * 8; + if (theClickH < h) { + mParent->EnableWindow(false); + + T2InfoDialog *theInfoDialog = thePeople->ShowInfoDialog(mTowerDoc); + theInfoDialog->DoModal(); + FinishAdd(); + + Invalidate(); + mParent->EnableWindow(true); + break; + } + } + } + + SetMouseCursor(183); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) { + SetMouseCursor(193); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonDown(UINT inFlags, CPoint inPt) { + SetMouseCursor(193); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemRButtonUp(UINT inFlags, CPoint inPt) { + SetMouseCursor(193); } -/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemMouseMove(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPeopleView::OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt) { + if (inFlags & MK_LBUTTON) + SetMouseCursor(183); + else + SetMouseCursor(193); } -void T2DlgItemPeopleView::SetMouseCursor(unsigned int) { +void T2DlgItemPeopleView::SetMouseCursor(UINT inCursor) { + CWinApp *theApp = AfxGetApp(); + HCURSOR cursor = theApp->LoadCursor(inCursor); + if (cursor) + SetCursor(cursor); } -/*virtual*/ int T2DlgItemPeopleView::OnCommand(unsigned int, long) { +/*virtual*/ BOOL T2DlgItemPeopleView::OnCommand(WPARAM inWParam, LPARAM inLParam) { + BOOL result = false; + + if (LOWORD(inWParam) == 100) { + InvalidateRect(NULL); + result = true; + } + + return result; } -void T2DlgItemPeopleView::SetPeople(T2People*) { +void T2DlgItemPeopleView::SetPeople(T2People* inPeople) { + if (inPeople) { + StartAdd(); + + T2PeopleLinkIterator iterator(inPeople); + T2People *thePeople; + + while (iterator.Next(&thePeople)) + AddOne(thePeople); + + FinishAdd(); + } } void T2DlgItemPeopleView::StartAdd() { -} + if (mArray && mArray->GetCount() > 0) + mArray->RemoveItemsAt(mArray->GetCount(), 1); -void T2DlgItemPeopleView::FinishAdd() { + delete mImage; + mImage = NULL; } -void T2DlgItemPeopleView::AddOne(T2People*) { +void T2DlgItemPeopleView::FinishAdd() { + if (mArray) { +#pragma var_order(imageRect, rect, width, theScroller, iterator2, thePeople, h, iterator1) + delete mImage; + mImage = NULL; + + T2DlgItemHScr *theScroller = (T2DlgItemHScr *) GetDlgItem(100); + T2People *thePeople; + + int width = 0; + LArrayIterator iterator1(*mArray); + while (iterator1.Next(&thePeople)) + width += thePeople->GetWidth() * 8; + + CRect rect; + GetClientRect(rect); + if (theScroller) + rect.bottom -= 15; + + rect.DeflateRect(1, 1); + mFullHeight = rect.Height(); + mFullWidth = (width * mFullHeight) / (36 - (UT2Coordinate::CalcFloorThick(0) + UT2Coordinate::CalcRoofThick(0))); + + CRect imageRect(0, 0, width, 36); +#line 214 + mImage = DEBUG_NEW T2BitImage(imageRect); + mImage->Clear(0); + + int h = 0; + LArrayIterator iterator2(*mArray); + while (iterator2.Next(&thePeople)) { + int w = thePeople->GetWidth() * 8; + CRect drawRect(0, 0, w, 36); + drawRect.OffsetRect(h, 0); + thePeople->Draw(mImage, drawRect); + h += w; + } + + if (theScroller) { + theScroller->SetPage(rect.Width()); + theScroller->SetRange(mFullWidth); + } + } +} + +void T2DlgItemPeopleView::AddOne(T2People* inPeople) { + if (inPeople) + mArray->Add(&inPeople); } diff --git a/src/T2DLL/T2DlgItemPeopleView.h b/src/T2DLL/T2DlgItemPeopleView.h index baed885..1f60517 100644 --- a/src/T2DLL/T2DlgItemPeopleView.h +++ b/src/T2DLL/T2DlgItemPeopleView.h @@ -1,24 +1,32 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemPeopleView { +class AFX_EXT_CLASS T2DlgItemPeopleView : public T2DlgItem { public: - T2DlgItemPeopleView(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemPeopleView(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemPeopleView(); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); + virtual BOOL Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); + void SetPeople(T2People* inPeople); + void StartAdd(); + void FinishAdd(); + void AddOne(T2People* inPeople); + protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemRButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemRButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemMouseMove(unsigned int, CPoint); - void SetMouseCursor(unsigned int); - virtual int OnCommand(unsigned int, long); -public: - void SetPeople(T2People*); - void StartAdd(); - void FinishAdd(); - void AddOne(T2People*); + virtual int OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemRButtonDown(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemRButtonUp(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt); + virtual BOOL OnCommand(WPARAM inWParam, LPARAM inLParam); + void SetMouseCursor(UINT inCursor); + + int mFullHeight; + int mFullWidth; + LArray *mArray; + T2BitImage *mImage; + int _98; + CWnd *mParent; }; diff --git a/src/T2DLL/T2DlgItemPopup.cpp b/src/T2DLL/T2DlgItemPopup.cpp index 97129b7..0ace311 100644 --- a/src/T2DLL/T2DlgItemPopup.cpp +++ b/src/T2DLL/T2DlgItemPopup.cpp @@ -1,25 +1,180 @@ +#include "CTokenizer.h" #include "T2DlgItemPopup.h" -T2DlgItemPopup::T2DlgItemPopup(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemPopup::T2DlgItemPopup(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mMenu(NULL) + , mMenuClicked(false) +{ +#line 21 + mMenu = DEBUG_NEW CMenu; + mMenu->CreatePopupMenu(); } /*virtual*/ T2DlgItemPopup::~T2DlgItemPopup() { + delete mMenu; } -/*virtual*/ int T2DlgItemPopup::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2DlgItemPopup::OnT2DlgItemCreate(CREATESTRUCT* cs) { + T2DlgItem::OnT2DlgItemCreate(cs); + + char *buf = (char *) calloc(GetWindowTextLength() + 1, 1); + GetWindowText(buf, GetWindowTextLength()); + + if (strlen(buf) != 0 && buf[0] != '-') { + CTokenizer theTokenizer(buf, "|\r\n"); + const char *text = theTokenizer.NextString(); + int i = 0; + + while (text) { + CString title = text; + i++; + mMenu->AppendMenuA(0, i, title); + text = theTokenizer.NextString(); + } + } + + free(buf); + return 0; } -/*virtual*/ int T2DlgItemPopup::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemPopup::OnT2DlgItemEraseBkgnd(CDC* pDC) { +#pragma var_order(pen1, rect1, rect2, pen4, i, y1, x, rect3, pen2, save, brush1, pen3, brush2, clientRect, text, y2) + CRect clientRect; + GetClientRect(clientRect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CRect rect1 = clientRect; + + CBrush brush1, brush2; + CPen pen1, pen2, pen3, pen4; + + if (IsWindowEnabled()) { + brush1.CreateSolidBrush(PALETTEINDEX(255)); + pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + if (mMenuClicked) { + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + brush2.CreateSolidBrush(PALETTERGB(179, 179, 179)); + pen4.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + } else { + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + brush2.CreateSolidBrush(PALETTERGB(204, 204, 204)); + pen4.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + } + } else { + brush1.CreateSolidBrush(PALETTERGB(179, 179, 179)); + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(204, 204, 204)); + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(204, 204, 204)); + brush2.CreateSolidBrush(PALETTERGB(204, 204, 204)); + pen4.CreatePen(PS_SOLID, 0, PALETTERGB(179, 179, 179)); + } + + pDC->FrameRect(clientRect, &brush1); + + rect1.DeflateRect(1, 1); + + CRect rect2 = rect1; + rect2.left = rect2.right - 16; + + pDC->SelectObject(pen1); + pDC->MoveTo(rect2.right - 1, rect2.top); + pDC->LineTo(rect2.left, rect2.top); + pDC->LineTo(rect2.left, rect2.bottom); + + pDC->SelectObject(pen2); + pDC->MoveTo(rect2.right - 1, rect2.top + 1); + pDC->LineTo(rect2.right - 1, rect2.bottom - 1); + pDC->LineTo(rect2.left, rect2.bottom - 1); + + rect2.DeflateRect(1, 1); + + pDC->SelectObject(pen1); + pDC->MoveTo(rect2.right - 1, rect2.top); + pDC->LineTo(rect2.left, rect2.top); + pDC->LineTo(rect2.left, rect2.bottom); + + pDC->SelectObject(pen2); + pDC->MoveTo(rect2.right - 1, rect2.top + 1); + pDC->LineTo(rect2.right - 1, rect2.bottom - 1); + pDC->LineTo(rect2.left, rect2.bottom - 1); + + rect2.DeflateRect(1, 1); + pDC->FillRect(rect2, &brush2); + + int x = rect2.left + (rect2.Width() - 7) / 2; + int y1 = rect2.top + (rect2.Height() - 10) / 2; + int y2 = y1 + 9; + + pDC->SelectObject(pen4); + for (int i = 0; i < 4; i++) { + pDC->MoveTo(x + (4 - i) - 1, y1 + i); + pDC->LineTo(x + (4 + i), y1 + i); + + pDC->MoveTo(x + (4 - i) - 1, y2 - i); + pDC->LineTo(x + (4 + i), y2 - i); + } + + CRect rect3 = rect1; + rect3.right -= 16; + + pDC->SelectObject(pen1); + pDC->MoveTo(rect3.right - 1, rect3.top); + pDC->LineTo(rect3.left, rect3.top); + pDC->LineTo(rect3.left, rect3.bottom); + + pDC->SelectObject(pen2); + pDC->MoveTo(rect3.right - 1, rect3.top + 1); + pDC->LineTo(rect3.right - 1, rect3.bottom - 1); + pDC->LineTo(rect3.left, rect3.bottom - 1); + + rect3.DeflateRect(1, 1); + pDC->FillRect(rect3, &brush2); + + pDC->SetTextColor(PALETTEINDEX(255)); + pDC->SetBkMode(TRANSPARENT); + pDC->SelectObject(mFont); + + rect3.DeflateRect(3, 0); + CString text; + mMenu->GetMenuString(GetValue() - 1, text, MF_BYPOSITION); + pDC->DrawText(text, rect3, DT_LEFT | DT_VCENTER | DT_SINGLELINE); + + pDC->RestoreDC(save); + return true; } -/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + POINT menuPos; + menuPos.x = 0; + menuPos.y = 0; + ClientToScreen(&menuPos); + + mMenuClicked = true; + Invalidate(); + + int tracked = mMenu->TrackPopupMenu(TPM_NONOTIFY | TPM_RETURNCMD, menuPos.x, menuPos.y, this); + if (tracked && tracked > 0 && tracked <= (int) mMenu->GetMenuItemCount()) { + SetValue(tracked); + Notify(GetDlgCtrlID(), 0, NULL); + } + + mMenuClicked = false; + Invalidate(); } -/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2DlgItemPopup::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) { } -/*virtual*/ int T2DlgItemPopup::OnCommand(unsigned int, long) { +/*virtual*/ BOOL T2DlgItemPopup::OnCommand(WPARAM wParam, LPARAM lParam) { + return true; } -void T2DlgItemPopup::AppendItem(const CString&) { +void T2DlgItemPopup::AppendItem(const CString& inName) { + mMenu->AppendMenu(0, mMenu->GetMenuItemCount() + 1, inName); } diff --git a/src/T2DLL/T2DlgItemPopup.h b/src/T2DLL/T2DlgItemPopup.h index 8b95cb2..f7d3247 100644 --- a/src/T2DLL/T2DlgItemPopup.h +++ b/src/T2DLL/T2DlgItemPopup.h @@ -1,16 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemPopup { +class AFX_EXT_CLASS T2DlgItemPopup : public T2DlgItem { public: - T2DlgItemPopup(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemPopup(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemPopup(); + void AppendItem(const CString& inName); + protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual int OnCommand(unsigned int, long); -public: - void AppendItem(const CString&); + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt); + virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); + + CMenu *mMenu; + BOOL mMenuClicked; }; diff --git a/src/T2DLL/T2DlgItemProfitsGage.cpp b/src/T2DLL/T2DlgItemProfitsGage.cpp index 9479e65..b5181f1 100644 --- a/src/T2DLL/T2DlgItemProfitsGage.cpp +++ b/src/T2DLL/T2DlgItemProfitsGage.cpp @@ -1,34 +1,75 @@ #include "T2DlgItemProfitsGage.h" +#include "T2Tenant.h" -T2DlgItemProfitsGage::T2DlgItemProfitsGage(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemProfitsGage::T2DlgItemProfitsGage(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemGageBase(inDoc, inImageObj, inPalette) + , mTenant(NULL) +{ } void T2DlgItemProfitsGage::CalcCost() { + mCost = mTenant->GetOutMoney(); } /*virtual*/ int T2DlgItemProfitsGage::GetMinValue() { + int val = mCost * -1; + if (mCost == 0) + val = 0; + return val; } /*virtual*/ int T2DlgItemProfitsGage::GetMaxValue() { + int val; + + if (mCost == 0) + val = 4; + else + val = (mCost * 230) / 70; + + return val; } /*virtual*/ int T2DlgItemProfitsGage::GetValue() { + int val = GetMinValue(); + if (mTenant) + val = mTenant->CalcInMoney(); + return val; } /*virtual*/ int T2DlgItemProfitsGage::GetBlueValue() { + int val; + + if (mCost == 0) + val = 2; + else + val = (mCost * 130) / 70; + + return val; } /*virtual*/ int T2DlgItemProfitsGage::GetYellowValue() { + int val = 0; + + if (mCost == 0) + val = 1; + + return val; } -/*virtual*/ unsigned long T2DlgItemProfitsGage::GetGageColor(int) { +/*virtual*/ DWORD T2DlgItemProfitsGage::GetGageColor(int inValue) { + return (inValue < GetYellowValue()) ? PALETTERGB(255, 0, 0) : (inValue < GetBlueValue()) ? PALETTERGB(255, 255, 0) : PALETTERGB(0, 0, 255); } -void T2DlgItemProfitsGage::SetTenant(T2Tenant*) { +void T2DlgItemProfitsGage::SetTenant(T2Tenant* inTenant) { + mTenant = inTenant; + CalcCost(); } -/*virtual*/ void T2DlgItemProfitsGage::DrawInterior(CDC*, const CRect&) { +/*virtual*/ void T2DlgItemProfitsGage::DrawInterior(CDC* pDC, const CRect& inRect) { + T2DlgItemGageBase::DrawInterior(pDC, inRect); + DrawValueByText(pDC, inRect); } -/*virtual*/ int T2DlgItemProfitsGage::IsDrawInterior() { +/*virtual*/ BOOL T2DlgItemProfitsGage::IsDrawInterior() { + return (mTenant != NULL); } diff --git a/src/T2DLL/T2DlgItemProfitsGage.h b/src/T2DLL/T2DlgItemProfitsGage.h index 6b555b7..f07cb95 100644 --- a/src/T2DLL/T2DlgItemProfitsGage.h +++ b/src/T2DLL/T2DlgItemProfitsGage.h @@ -1,23 +1,23 @@ #pragma once #include "common.h" +#include "T2DlgItemGageBase.h" -class T2DlgItemProfitsGage { +class AFX_EXT_CLASS T2DlgItemProfitsGage : public T2DlgItemGageBase { public: - T2DlgItemProfitsGage(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemProfitsGage(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + void SetTenant(T2Tenant* inTenant); + protected: - void CalcCost(); virtual int GetMinValue(); virtual int GetMaxValue(); virtual int GetValue(); virtual int GetBlueValue(); virtual int GetYellowValue(); - virtual unsigned long GetGageColor(int); -public: - void SetTenant(T2Tenant*); -protected: - virtual void DrawInterior(CDC*, const CRect&); - virtual int IsDrawInterior(); + virtual COLORREF GetGageColor(int inValue); + virtual void DrawInterior(CDC* pDC, const CRect& inRect); + virtual BOOL IsDrawInterior(); + void CalcCost(); -public: - virtual ~T2DlgItemProfitsGage() {} + int mCost; + T2Tenant *mTenant; }; diff --git a/src/T2DLL/T2DlgItemProgress.cpp b/src/T2DLL/T2DlgItemProgress.cpp index 75bf2ac..d82088a 100644 --- a/src/T2DLL/T2DlgItemProgress.cpp +++ b/src/T2DLL/T2DlgItemProgress.cpp @@ -1,28 +1,67 @@ #include "T2DlgItemProgress.h" -T2DlgItemProgress::T2DlgItemProgress(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemProgress::T2DlgItemProgress(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mSubItem(NULL) +{ } /*virtual*/ T2DlgItemProgress::~T2DlgItemProgress() { + delete mSubItem; } -/*virtual*/ void T2DlgItemProgress::SetFont(HFONT) { +/*virtual*/ void T2DlgItemProgress::SetFont(HFONT inFont) { + T2DlgItem::SetFont(inFont); + + if (mSubItem) + mSubItem->SetFont(CFont::FromHandle(inFont)); } /*virtual*/ void T2DlgItemProgress::CreateSubItem() { + mSubItem = new CProgressCtrl; + + CRect rect; + GetClientRect(rect); + mSubItem->Create(WS_VISIBLE | WS_CHILD, rect, this, 0); } -/*virtual*/ void T2DlgItemProgress::SetRange(int, int) { +/*virtual*/ void T2DlgItemProgress::SetRange(int inLower, int inUpper) { + if (mSubItem) + mSubItem->SetRange(inLower, inUpper); } -/*virtual*/ int T2DlgItemProgress::SetPos(int) { +/*virtual*/ int T2DlgItemProgress::SetPos(int inPos) { + int result; + if (mSubItem) + result = mSubItem->SetPos(inPos); + else + result = 0; + return result; } -/*virtual*/ int T2DlgItemProgress::OffsetPos(int) { +/*virtual*/ int T2DlgItemProgress::OffsetPos(int inOffset) { + int result; + if (mSubItem) + result = mSubItem->OffsetPos(inOffset); + else + result = 0; + return result; } -/*virtual*/ int T2DlgItemProgress::SetStep(int) { +/*virtual*/ int T2DlgItemProgress::SetStep(int inStep) { + int result; + if (mSubItem) + result = mSubItem->SetStep(inStep); + else + result = 0; + return result; } /*virtual*/ int T2DlgItemProgress::StepIt() { + int result; + if (mSubItem) + result = mSubItem->StepIt(); + else + result = 0; + return result; } diff --git a/src/T2DLL/T2DlgItemProgress.h b/src/T2DLL/T2DlgItemProgress.h index 7f35b86..1ced46c 100644 --- a/src/T2DLL/T2DlgItemProgress.h +++ b/src/T2DLL/T2DlgItemProgress.h @@ -1,15 +1,19 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemProgress { +class AFX_EXT_CLASS T2DlgItemProgress : public T2DlgItem { public: - T2DlgItemProgress(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemProgress(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemProgress(); - virtual void SetFont(HFONT); + virtual void SetFont(HFONT inFont); virtual void CreateSubItem(); - virtual void SetRange(int, int); - virtual int SetPos(int); - virtual int OffsetPos(int); - virtual int SetStep(int); + virtual void SetRange(int inLower, int inUpper); + virtual int SetPos(int inPos); + virtual int OffsetPos(int inOffset); + virtual int SetStep(int inStep); virtual int StepIt(); + +protected: + CProgressCtrl *mSubItem; }; diff --git a/src/T2DLL/T2DlgItemRadioButton.cpp b/src/T2DLL/T2DlgItemRadioButton.cpp new file mode 100644 index 0000000..6213f43 --- /dev/null +++ b/src/T2DLL/T2DlgItemRadioButton.cpp @@ -0,0 +1,14 @@ +#include "T2DlgItemRadioButton.h" + +T2DlgItemRadioButton::T2DlgItemRadioButton(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette) + : T2DlgItemICheck(inDoc, inImageObj, inPalette) +{ +} + +/*virtual*/ T2DlgItemRadioButton::~T2DlgItemRadioButton() { +} + +/*virtual*/ void T2DlgItemRadioButton::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + if (!GetValue()) + T2DlgItemICheck::OnT2DlgItemLButtonDown(inFlags, inPt); +} diff --git a/src/T2DLL/T2DlgItemRadioButton.h b/src/T2DLL/T2DlgItemRadioButton.h new file mode 100644 index 0000000..8e67088 --- /dev/null +++ b/src/T2DLL/T2DlgItemRadioButton.h @@ -0,0 +1,12 @@ +#pragma once +#include "common.h" +#include "T2DlgItemICheck.h" + +class T2DlgItemRadioButton : public T2DlgItemICheck { +public: + T2DlgItemRadioButton(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette); + ~T2DlgItemRadioButton(); + +protected: + void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); +};
\ No newline at end of file diff --git a/src/T2DLL/T2DlgItemRadioText.cpp b/src/T2DLL/T2DlgItemRadioText.cpp new file mode 100644 index 0000000..bba4937 --- /dev/null +++ b/src/T2DLL/T2DlgItemRadioText.cpp @@ -0,0 +1,71 @@ +#include "T2BitImage.h" +#include "T2DlgItemRadioText.h" + +/*virtual*/ BOOL T2DlgItemRadioText::Create(const char *inWindowName, DWORD inStyle, const RECT &inRect, CWnd *inParentWnd, UINT inID) { + CRect rect = inRect; + CRect imageRect; + + strcpy(mText, inWindowName); + GetObjectImage(imageRect, "DLGITEM:TxRadio"); + + return T2DlgItem::Create("DLGITEM:TxRadio", inStyle, rect, inParentWnd, inID); +} + +T2DlgItemRadioText::T2DlgItemRadioText(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette) + : T2DlgItemICheck(inDoc, inImageObj, inPalette) +{ + mText[0] = 0; +} + +/*virtual*/ T2DlgItemRadioText::~T2DlgItemRadioText() { +} + +/*virtual*/ BOOL T2DlgItemRadioText::OnT2DlgItemEraseBkgnd(CDC *pDC) { + CRect drawRect; + GetClientRect(drawRect); + + int saved = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + RECT imageRect; + T2BitImage *theImage = GetObjectImage(imageRect, "DLGITEM:TxRadio", GetPattern()); + drawRect.right = (drawRect.left + imageRect.right) - imageRect.left; + drawRect.bottom = (drawRect.top + imageRect.bottom) - imageRect.top; + theImage->CopyImage(pDC, imageRect, drawRect); + + GetClientRect(drawRect); + drawRect.left += (drawRect.bottom - drawRect.top); + + char config = mText[0]; + const char *text = &mText[1]; + DWORD theFormat = DT_WORDBREAK | DT_NOPREFIX; + + if (isupper(config)) { + theFormat |= DT_VCENTER | DT_SINGLELINE; + config = tolower(config); + } + + switch (config) { + case 'c': + theFormat |= DT_CENTER; + break; + case 'l': + theFormat |= DT_LEFT; + break; + case 'r': + theFormat |= DT_RIGHT; + break; + } + + pDC->SetBkMode(TRANSPARENT); + pDC->DrawText(text, drawRect, theFormat); + + pDC->RestoreDC(saved); + return true; +} + +/*virtual*/ void T2DlgItemRadioText::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + if (!GetValue()) + T2DlgItemICheck::OnT2DlgItemLButtonDown(inFlags, inPt); +} diff --git a/src/T2DLL/T2DlgItemRadioText.h b/src/T2DLL/T2DlgItemRadioText.h new file mode 100644 index 0000000..6a99861 --- /dev/null +++ b/src/T2DLL/T2DlgItemRadioText.h @@ -0,0 +1,16 @@ +#pragma once +#include "common.h" +#include "T2DlgItemICheck.h" + +class T2DlgItemRadioText : public T2DlgItemICheck { +public: + T2DlgItemRadioText(T2TowerDoc *inDoc, T2ImageObj *inImageObj, CPalette *inPalette); + ~T2DlgItemRadioText(); + virtual BOOL Create(const char *inWindowName, DWORD inStyle, const RECT &inRect, CWnd *inParentWnd, UINT inID); + +protected: + virtual BOOL OnT2DlgItemEraseBkgnd(CDC *pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + + char mText[256]; +}; diff --git a/src/T2DLL/T2DlgItemSTimeTbl.cpp b/src/T2DLL/T2DlgItemSTimeTbl.cpp index a837aa5..e82ab91 100644 --- a/src/T2DLL/T2DlgItemSTimeTbl.cpp +++ b/src/T2DLL/T2DlgItemSTimeTbl.cpp @@ -1,19 +1,77 @@ #include "T2DlgItemSTimeTbl.h" +#include "T2MetroRailway.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" -T2DlgItemSTimeTbl::T2DlgItemSTimeTbl(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemSTimeTbl::T2DlgItemSTimeTbl(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ + mCFont = NULL; } /*virtual*/ T2DlgItemSTimeTbl::~T2DlgItemSTimeTbl() { + delete mCFont; } -/*virtual*/ int T2DlgItemSTimeTbl::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemSTimeTbl::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { + BOOL result = T2DlgItem::Create(windowName, style, rect, parentWnd, nId); + + if (result) { +#line 34 + mCFont = DEBUG_NEW CFont; + mCFont->CreateFont(-abs(9), 0, 0, 0, FW_NORMAL, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"); + SetFont(*mCFont); + } + + return result; } -void T2DlgItemSTimeTbl::SetGrade(int) { +void T2DlgItemSTimeTbl::SetGrade(int inGrade) { + mGrade = inGrade; } -/*virtual*/ int T2DlgItemSTimeTbl::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemSTimeTbl::OnT2DlgItemEraseBkgnd(CDC* pDC) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CString str; + + T2MetroRailway *theMetroRailway = mTowerDoc->mWorldDef->GetMetroRailway(); + if (theMetroRailway) { + CRect timeRect, clientRect; + GetClientRect(clientRect); + + SIZE timeSize; + timeSize.cx = (clientRect.right - clientRect.left) / (theMetroRailway->GetNofTimeTable() / 2); + timeSize.cy = (clientRect.bottom - clientRect.top) / 2; + + pDC->SelectObject(mFont); + pDC->SetBkMode(TRANSPARENT); + + for (int i = 0; i < theMetroRailway->GetNofTimeTable(); i++) { + timeRect.left = timeSize.cx * (i % (theMetroRailway->GetNofTimeTable() / 2)); + timeRect.right = timeRect.left + timeSize.cx; + timeRect.top = timeSize.cy * (i / (theMetroRailway->GetNofTimeTable() / 2)); + timeRect.bottom = timeRect.top + timeSize.cy; + + DrawTime(pDC, theMetroRailway->GetArriveTime(i), theMetroRailway->GetTrainType(i) < mGrade, timeRect); + } + } + + pDC->RestoreDC(save); + return true; } -void T2DlgItemSTimeTbl::DrawTime(CDC*, unsigned int, int, CRect&) { +void T2DlgItemSTimeTbl::DrawTime(CDC* pDC, unsigned int inArriveTime, BOOL isGrade, CRect& inRect) { + int hour = inArriveTime / 60; + int minute = inArriveTime % 60; + + UINT flag = DT_LEFT | DT_VCENTER | DT_WORDBREAK | DT_NOPREFIX; + + CString str; + str.Format("%2d:%02d", hour, minute); + + pDC->SetTextColor(isGrade ? PALETTEINDEX(255) : PALETTERGB(179, 179, 179)); + pDC->DrawText(str, inRect, flag); } diff --git a/src/T2DLL/T2DlgItemSTimeTbl.h b/src/T2DLL/T2DlgItemSTimeTbl.h index c4c65e6..ebfaff1 100644 --- a/src/T2DLL/T2DlgItemSTimeTbl.h +++ b/src/T2DLL/T2DlgItemSTimeTbl.h @@ -1,14 +1,18 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemSTimeTbl { +class AFX_EXT_CLASS T2DlgItemSTimeTbl : public T2DlgItem { public: - T2DlgItemSTimeTbl(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemSTimeTbl(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemSTimeTbl(); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - void SetGrade(int); + virtual BOOL Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId); + void SetGrade(int inGrade); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); private: - void DrawTime(CDC*, unsigned int, int, CRect&); + void DrawTime(CDC* pDC, unsigned int inArriveTime, BOOL isGrade, CRect& inRect); + + CFont *mCFont; + int mGrade; }; diff --git a/src/T2DLL/T2DlgItemScr.cpp b/src/T2DLL/T2DlgItemScr.cpp index 692c9a6..9f4cb21 100644 --- a/src/T2DLL/T2DlgItemScr.cpp +++ b/src/T2DLL/T2DlgItemScr.cpp @@ -48,7 +48,7 @@ T2DlgItemScr::T2DlgItemScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* mClickedArea = ScrollBarHittest(pt); if (mClickedArea != 0) { - if (mClickedArea == Area_SetAbsolute) { + if (mClickedArea == Area_Thumb) { mMouseDownPoint = pt; mMouseDownValue = mValue; } else { @@ -82,17 +82,17 @@ T2DlgItemScr::T2DlgItemScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* GetClientRect(clientRect); switch (mClickedArea) { - case Area_SetAbsolute: { - int a, b; + case Area_Thumb: { + int thumbPosition, thumbSize; clientRect.DeflateRect(0, 16); - CalcScrollBarThumb(&a, &b); + CalcScrollBarThumb(&thumbPosition, &thumbSize); - int val = PositionToValue(clientRect) - b; + int val = PositionToValue(clientRect) - thumbSize; if (val == 0) val = 1; ScrollBarAction( - Area_SetAbsolute, + Area_Thumb, mMouseDownValue + ((PositionToValue(pt) - PositionToValue(mMouseDownPoint)) * (mRange - mPage)) / val ); break; @@ -123,10 +123,10 @@ T2DlgItemScr::T2DlgItemScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* } } -void T2DlgItemScr::CalcScrollBarThumb(int* a, int* b) const { +void T2DlgItemScr::CalcScrollBarThumb(int* thumbPosition, int* thumbSize) const { if (!IsScrollable()) { - *a = 16; - *b = 0; + *thumbPosition = 16; + *thumbSize = 0; } else { CRect clientRect; GetClientRect(clientRect); @@ -134,10 +134,10 @@ void T2DlgItemScr::CalcScrollBarThumb(int* a, int* b) const { int value = PositionToValue(clientRect); value -= 32; - *b = (value * mPage) / mRange; - if (*b < 10) - *b = 10; - *a = (((value - *b) * mValue) / (mRange - mPage)) + 16; + *thumbSize = (value * mPage) / mRange; + if (*thumbSize < 10) + *thumbSize = 10; + *thumbPosition = (((value - *thumbSize) * mValue) / (mRange - mPage)) + 16; } } @@ -152,7 +152,7 @@ void T2DlgItemScr::ScrollBarAction(int area, int arg) { case Area_PageUp: mValue -= mPage / 2; break; - case Area_SetAbsolute: + case Area_Thumb: mValue = arg; break; case Area_PageDown: diff --git a/src/T2DLL/T2DlgItemScr.h b/src/T2DLL/T2DlgItemScr.h index 55698bb..0337b46 100644 --- a/src/T2DLL/T2DlgItemScr.h +++ b/src/T2DLL/T2DlgItemScr.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2DlgItem.h" -class DLL_EXPORT T2DlgItemScr : public T2DlgItem { +class AFX_EXT_CLASS T2DlgItemScr : public T2DlgItem { public: T2DlgItemScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); virtual void SetValue(int); @@ -13,7 +13,7 @@ public: enum { Area_Up = 1, Area_PageUp = 2, - Area_SetAbsolute = 3, + Area_Thumb = 3, Area_PageDown = 4, Area_Down = 5 }; @@ -30,7 +30,7 @@ protected: virtual int PositionToValue(const CPoint&) const = 0; virtual int PositionToValue(const CRect&) const = 0; - void CalcScrollBarThumb(int*, int*) const; + void CalcScrollBarThumb(int* thumbPosition, int* thumbSize) const; void ScrollBarAction(int, int); BOOL IsScrollable() const; diff --git a/src/T2DLL/T2DlgItemStressGage.cpp b/src/T2DLL/T2DlgItemStressGage.cpp index 098f8fb..f685e31 100644 --- a/src/T2DLL/T2DlgItemStressGage.cpp +++ b/src/T2DLL/T2DlgItemStressGage.cpp @@ -1,28 +1,43 @@ #include "T2DlgItemStressGage.h" +#include "T2People.h" +#include "T2PeopleDef.h" -T2DlgItemStressGage::T2DlgItemStressGage(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemStressGage::T2DlgItemStressGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemGageBase(towerDoc, imageObj, palette) + , mPeople(NULL) +{ } /*virtual*/ int T2DlgItemStressGage::GetMinValue() { + return 0; } /*virtual*/ int T2DlgItemStressGage::GetMaxValue() { + return (mPeople && mPeople->GetMatterDef()) ? ((T2PeopleDef *) mPeople->GetMatterDef())->GetStressMax() : GetMinValue(); } /*virtual*/ int T2DlgItemStressGage::GetValue() { + return mPeople ? mPeople->GetStress() : GetMinValue(); } /*virtual*/ int T2DlgItemStressGage::GetBlueValue() { + return (mPeople && mPeople->GetMatterDef()) ? ((T2PeopleDef *) mPeople->GetMatterDef())->GetStressBlueLimit() : GetMinValue(); } /*virtual*/ int T2DlgItemStressGage::GetYellowValue() { + return (mPeople && mPeople->GetMatterDef()) ? ((T2PeopleDef *) mPeople->GetMatterDef())->GetStressYellowLimit() : GetMinValue(); } -void T2DlgItemStressGage::SetPeople(T2People*) { +void T2DlgItemStressGage::SetPeople(T2People* people) { + mPeople = people; } -/*virtual*/ unsigned long T2DlgItemStressGage::GetGageColor(int) { +/*virtual*/ COLORREF T2DlgItemStressGage::GetGageColor(int value) { + return (value <= GetBlueValue()) ? PALETTERGB(0, 0, 255) : + (value <= GetYellowValue()) ? PALETTERGB(255, 255, 0) : + PALETTERGB(255, 0, 0); } -/*virtual*/ int T2DlgItemStressGage::IsDrawInterior() { +/*virtual*/ BOOL T2DlgItemStressGage::IsDrawInterior() { + return (mPeople != NULL); } diff --git a/src/T2DLL/T2DlgItemStressGage.h b/src/T2DLL/T2DlgItemStressGage.h index 8e90fa0..9240f30 100644 --- a/src/T2DLL/T2DlgItemStressGage.h +++ b/src/T2DLL/T2DlgItemStressGage.h @@ -1,21 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItemGageBase.h" -class T2DlgItemStressGage { +class AFX_EXT_CLASS T2DlgItemStressGage : public T2DlgItemGageBase { public: - T2DlgItemStressGage(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemStressGage(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); + void SetPeople(T2People*); + protected: virtual int GetMinValue(); virtual int GetMaxValue(); virtual int GetValue(); virtual int GetBlueValue(); virtual int GetYellowValue(); -public: - void SetPeople(T2People*); -protected: - virtual unsigned long GetGageColor(int); - virtual int IsDrawInterior(); + virtual COLORREF GetGageColor(int value); + virtual BOOL IsDrawInterior(); -public: - virtual ~T2DlgItemStressGage() {} + T2People *mPeople; }; diff --git a/src/T2DLL/T2DlgItemTButton.cpp b/src/T2DLL/T2DlgItemTButton.cpp index e81b41d..11818a6 100644 --- a/src/T2DLL/T2DlgItemTButton.cpp +++ b/src/T2DLL/T2DlgItemTButton.cpp @@ -1,7 +1,40 @@ #include "T2DlgItemTButton.h" -T2DlgItemTButton::T2DlgItemTButton(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemTButton::T2DlgItemTButton(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemButtonBase(inDoc, inImageObj, inPalette) +{ } -/*virtual*/ int T2DlgItemTButton::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemTButton::OnT2DlgItemEraseBkgnd(CDC* pDC) { +#pragma var_order(rect, save, text) + CString text; + GetWindowText(text); + + if (text == "NULL") + return true; + + CRect rect; + GetClientRect(rect); + + DrawButtonBase(pDC, rect, GetPattern() == 100); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + pDC->SelectObject(mFont); + pDC->SetBkMode(TRANSPARENT); + + if (!IsWindowEnabled()) + pDC->SetTextColor(PALETTERGB(179, 179, 179)); + else if (GetPattern() == 100) + rect.OffsetRect(1, 1); + else + pDC->SetTextColor(RGB(0, 0, 0)); + + pDC->DrawText(text, -1, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + + pDC->RestoreDC(save); + + return true; } diff --git a/src/T2DLL/T2DlgItemTButton.h b/src/T2DLL/T2DlgItemTButton.h index 3b79f2c..7ab2852 100644 --- a/src/T2DLL/T2DlgItemTButton.h +++ b/src/T2DLL/T2DlgItemTButton.h @@ -1,12 +1,10 @@ #pragma once #include "common.h" +#include "T2DlgItemButtonBase.h" -class T2DlgItemTButton { +class AFX_EXT_CLASS T2DlgItemTButton : public T2DlgItemButtonBase { public: - T2DlgItemTButton(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemTButton(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - -public: - virtual ~T2DlgItemTButton() {} + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); }; diff --git a/src/T2DLL/T2DlgItemTab.cpp b/src/T2DLL/T2DlgItemTab.cpp index f9989b0..fdf0d2f 100644 --- a/src/T2DLL/T2DlgItemTab.cpp +++ b/src/T2DLL/T2DlgItemTab.cpp @@ -1,22 +1,168 @@ +#include "CTokenizer.h" #include "T2DlgItemTab.h" -T2DlgItemTab::T2DlgItemTab(T2TowerDoc*, T2ImageObj*, CPalette*) { +// oops, no name for this lad +class CustomTabControl : public CTabCtrl { + DECLARE_MESSAGE_MAP() + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + +public: + CPalette *mPalette; +}; + +T2DlgItemTab::T2DlgItemTab(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mSubItem(NULL) +{ } /*virtual*/ T2DlgItemTab::~T2DlgItemTab() { + delete mSubItem; +} + +/*virtual*/ int T2DlgItemTab::OnT2DlgItemCreate(CREATESTRUCT* cs) { + T2DlgItem::OnT2DlgItemCreate(cs); + return 0; } -/*virtual*/ int T2DlgItemTab::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ void T2DlgItemTab::SetFont(HFONT inFont) { + T2DlgItem::SetFont(inFont); + + if (mSubItem) + mSubItem->SetFont(CFont::FromHandle(inFont)); +} + +/*virtual*/ void T2DlgItemTab::CreateSubItem(void* inData) { + mSubItem = new CustomTabControl; + mSubItem->mPalette = mPalette; + + CRect clientRect; + GetClientRect(clientRect); + clientRect.bottom = clientRect.top + 20; + mSubItem->Create(WS_VISIBLE | WS_CHILD, clientRect, this, 0); + + char *buf = (char *) calloc(GetWindowTextLength() + 1, 1); + GetWindowText(buf, GetWindowTextLength()); + + if (strlen(buf) != 0 && buf[0] != '-') { + CTokenizer theTokenizer(buf, "|\r\n"); + const char *itemText = theTokenizer.NextString(); + int i = 0; + + while (itemText) { + TCITEM item; + item.mask = TCIF_TEXT | TCIF_PARAM; + item.pszText = (LPSTR) itemText; + item.cchTextMax = strlen(itemText); + item.lParam = i; + mSubItem->InsertItem(i, &item); + i++; + itemText = theTokenizer.NextString(); + } + } + + free(buf); } -/*virtual*/ void T2DlgItemTab::SetFont(HFONT) { +/*virtual*/ BOOL T2DlgItemTab::OnT2DlgItemEraseBkgnd(CDC* pDC) { +#pragma var_order(rect, pen1, pen2, save, brush, pen3, pen4) + CRect rect; + GetClientRect(rect); + rect.top += 20; + + CPen pen1; + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + CPen pen2; + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + CPen pen3; + pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + CPen pen4; + pen4.CreatePen(PS_SOLID, 0, PALETTERGB(224, 224, 224)); + + CBrush brush; + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (IsWindowEnabled()) { + pDC->SelectObject(pen3); + + pDC->MoveTo(rect.right - 2, rect.top - 2); + pDC->LineTo(rect.right - 2, rect.top - 1); + + pDC->MoveTo(rect.right - 1, rect.top - 1); + pDC->LineTo(rect.right - 1, rect.bottom - 1); + pDC->LineTo(rect.left, rect.bottom - 1); + + pDC->SelectObject(pen2); + + pDC->MoveTo(rect.right - 2, rect.top + 1); + pDC->LineTo(rect.right - 2, rect.bottom - 2); + pDC->LineTo(rect.left + 1, rect.bottom - 2); + + pDC->SelectObject(pen1); + + pDC->MoveTo(rect.left, rect.bottom - 1); + pDC->LineTo(rect.left, rect.top); + + pDC->SelectObject(pen4); + + pDC->MoveTo(rect.left + 1, rect.bottom - 2); + pDC->LineTo(rect.left + 1, rect.top); + } else { + brush.CreateSolidBrush(PALETTERGB(179, 179, 179)); + pDC->FrameRect(rect, &brush); + } + + pDC->RestoreDC(save); + return true; } -/*virtual*/ void T2DlgItemTab::CreateSubItem(void*) { +/*virtual*/ LRESULT T2DlgItemTab::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { + if (mSubItem) { + switch (message) { + case WM_NOTIFY: { + NMHDR *hdr = (NMHDR *) lParam; + if (hdr->code == TCN_SELCHANGE) { + int num = mSubItem->GetCurSel() + 1; + BroadcastMessage(-GetDlgCtrlID(), &num); + return 0; + } + break; + } + + default: + return CWnd::WindowProc(message, wParam, lParam); + } + } + + return CWnd::WindowProc(message, wParam, lParam); } -/*virtual*/ int T2DlgItemTab::OnT2DlgItemEraseBkgnd(CDC*) { + + +/*virtual*/ LRESULT CustomTabControl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { + switch (message) { + default: + return CWnd::WindowProc(message, wParam, lParam); + } } -/*virtual*/ long T2DlgItemTab::WindowProc(unsigned int, unsigned int, long) { +BEGIN_MESSAGE_MAP(CustomTabControl, CTabCtrl) + ON_WM_ERASEBKGND() +END_MESSAGE_MAP() + +afx_msg BOOL CustomTabControl::OnEraseBkgnd(CDC* pDC) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CRect clientRect; + GetClientRect(clientRect); + pDC->FillSolidRect(clientRect, PALETTERGB(204, 204, 204)); + + pDC->RestoreDC(save); + return true; } diff --git a/src/T2DLL/T2DlgItemTab.h b/src/T2DLL/T2DlgItemTab.h index 234cd0a..f728837 100644 --- a/src/T2DLL/T2DlgItemTab.h +++ b/src/T2DLL/T2DlgItemTab.h @@ -1,15 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemTab { +class CustomTabControl; + +class AFX_EXT_CLASS T2DlgItemTab : public T2DlgItem { public: - T2DlgItemTab(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemTab(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2DlgItemTab(); - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); - virtual void SetFont(HFONT); - virtual void CreateSubItem(void*); + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual void SetFont(HFONT inFont); + virtual void CreateSubItem(void* inData); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); -public: - virtual long WindowProc(unsigned int, unsigned int, long); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + + CustomTabControl *mSubItem; }; diff --git a/src/T2DLL/T2DlgItemTable.cpp b/src/T2DLL/T2DlgItemTable.cpp index a550c75..4382ef4 100644 --- a/src/T2DLL/T2DlgItemTable.cpp +++ b/src/T2DLL/T2DlgItemTable.cpp @@ -1,172 +1,679 @@ +#include "T2DlgItemHScr.h" #include "T2DlgItemTable.h" +#include "T2DlgItemVScr.h" +#include <MINMAX.H> -T2DlgItemTable::T2DlgItemTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemTable::T2DlgItemTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItem(towerDoc, imageObj, palette) +{ + InitTable(0, 0, 16, 100, 0); } -T2DlgItemTable::T2DlgItemTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemTable::T2DlgItemTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItem(towerDoc, imageObj, palette) +{ + InitTable(rows, cols, rowHeight, colWidth, cellDataSize); } /*virtual*/ T2DlgItemTable::~T2DlgItemTable() { + delete mCellData; + delete mMultiSelectedCells; } -void T2DlgItemTable::InitTable(int, int, int, int, int) { +void T2DlgItemTable::InitTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize) { + mVScrollerStyle = ShowIfNeeded; + mHScrollerStyle = ShowIfNeeded; + + mScrollOffset.x = 0; + mScrollOffset.y = 0; + + mShowHScroller = false; + mShowVScroller = false; + + mResizeCount = 0; + + mRowHeight = rowHeight; + mColWidth = colWidth; + + mCellData = NULL; + mMultiSelectedCells = NULL; + + mSelectedCell.col = 0; + mSelectedCell.row = 0; + + mClickedCell.col = 1; + mClickedCell.row = 1; + + mCols = 0; + mRows = 0; + + InsertRows(rows, 0, NULL); + InsertCols(cols, 0, NULL); + SetCellDataSize(cellDataSize); } -/*virtual*/ int T2DlgItemTable::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2DlgItemTable::Create(const char* windowName, DWORD style, const RECT& rect, CWnd* parentWnd, UINT nId) { + return T2DlgItem::Create(windowName, style | WS_CLIPCHILDREN, rect, parentWnd, nId); } -/*virtual*/ int T2DlgItemTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ BOOL T2DlgItemTable::OnT2DlgItemCreate(CREATESTRUCT*) { + CRect rect; + + GetClientRect(rect); + rect.left = rect.right - 16; + mVScroller = new T2DlgItemVScr(mTowerDoc, mImageObj, mPalette); + mVScroller->Create("", WS_CHILD, rect, this, 100); + + GetClientRect(rect); + rect.top = rect.bottom - 16; + mHScroller = new T2DlgItemHScr(mTowerDoc, mImageObj, mPalette); + mHScroller->Create("", WS_CHILD, rect, this, 101); + + return false; } -void T2DlgItemTable::GetTableSize(unsigned int&, unsigned int&) const { +void T2DlgItemTable::GetTableSize(UINT& outRows, UINT& outCols) const { + outRows = mRows; + outCols = mCols; } -int T2DlgItemTable::IsMultiSelectable() const { +BOOL T2DlgItemTable::IsMultiSelectable() const { + return (mMultiSelectedCells != NULL); } -void T2DlgItemTable::EnableMultiSelect(int) { +void T2DlgItemTable::EnableMultiSelect(BOOL enabled) { + if (IsMultiSelectable()) { + if (!enabled) { + delete mMultiSelectedCells; + mMultiSelectedCells = NULL; + } + } else { + if (enabled) { + mMultiSelectedCells = new LArray(sizeof(TableCellT)); + } + } } /*virtual*/ void T2DlgItemTable::ClearSelectedCells() { -} + if (IsValidCell(mSelectedCell)) + InvalidateCell(mSelectedCell); -int T2DlgItemTable::IsValidCell(const TableCellT&) const { -} + mSelectedCell.col = 0; + mSelectedCell.row = 0; -int T2DlgItemTable::EqualCell(const TableCellT&, const TableCellT&) const { -} + if (IsMultiSelectable()) { + LArrayIterator iter(*mMultiSelectedCells); + TableCellT iterCell; + while (iter.Next(&iterCell)) + InvalidateCell(iterCell); -/*virtual*/ void T2DlgItemTable::InsertRows(int, unsigned int, void*) { + mMultiSelectedCells->RemoveItemsAt(mMultiSelectedCells->GetCount(), 1); + } } -/*virtual*/ void T2DlgItemTable::InsertCols(int, unsigned int, void*) { +BOOL T2DlgItemTable::IsValidCell(const TableCellT& cell) const { + return (cell.row > 0) && (cell.row <= mRows) && (cell.col > 0) && (cell.col <= mCols); } -/*virtual*/ void T2DlgItemTable::RemoveRows(int, unsigned int) { +BOOL T2DlgItemTable::EqualCell(const TableCellT& a, const TableCellT& b) const { + return (a.row == b.row) && (a.col == b.col); } -/*virtual*/ void T2DlgItemTable::RemoveCols(int, unsigned int) { -} +/*virtual*/ void T2DlgItemTable::InsertRows(int count, UINT where, void* data) { + if (mCellData) + mCellData->InsertItemsAt(count * mCols, where * mCols + 1, data); -/*virtual*/ void T2DlgItemTable::SetRowHeight(int, unsigned int, unsigned int) { + mRows += count; + ClearSelectedCells(); + Resized(); } -/*virtual*/ void T2DlgItemTable::SetColWidth(int, unsigned int, unsigned int) { -} +/*virtual*/ void T2DlgItemTable::InsertCols(int count, UINT where, void* data) { + if (mCellData) { + UINT index = where + 1; + for (UINT i = 1; i <= mRows; i++) { + mCellData->InsertItemsAt(count, index, data); + index += (mCols + count); + } + } -void T2DlgItemTable::SetCellDataSize(int) { + mCols += count; + ClearSelectedCells(); + Resized(); } -/*virtual*/ void T2DlgItemTable::SetCellData(const TableCellT&, void*) { -} +/*virtual*/ void T2DlgItemTable::RemoveRows(int count, UINT where) { + if (mCellData) + mCellData->RemoveItemsAt(count * mCols, (where - 1) * mCols + 1); -/*virtual*/ void T2DlgItemTable::GetCellData(const TableCellT&, void*) { + mRows -= count; + ClearSelectedCells(); + Resized(); } -/*virtual*/ int T2DlgItemTable::FetchLocalCellFrame(const TableCellT&, RECT&) { -} +/*virtual*/ void T2DlgItemTable::RemoveCols(int count, UINT where) { + if (mCellData) { + UINT index = where; + for (UINT n = 1; n <= mRows; n++) { + mCellData->RemoveItemsAt(count, index); + index += (mCols - count); + } + } -/*virtual*/ void T2DlgItemTable::FetchCellHitBy(const POINT&, TableCellT&) { + mCols -= count; + ClearSelectedCells(); + Resized(); } -int T2DlgItemTable::FetchCellDataIndex(const TableCellT&) { +/*virtual*/ void T2DlgItemTable::SetRowHeight(int height, unsigned int, unsigned int) { + mRowHeight = height; } -/*virtual*/ void T2DlgItemTable::ClickSelf(const POINT&, unsigned int) { +/*virtual*/ void T2DlgItemTable::SetColWidth(int width, unsigned int, unsigned int) { + mColWidth = width; } -/*virtual*/ int T2DlgItemTable::OnT2DlgItemEraseBkgnd(CDC*) { +void T2DlgItemTable::SetCellDataSize(int size) { + if (!mCellData && size > 0) { + mCellData = new LArray(size); + mCellData->InsertItemsAt(mRows * mCols, 1, NULL); + } } -/*virtual*/ void T2DlgItemTable::HiliteCell(CDC*, const TableCellT&) { +/*virtual*/ void T2DlgItemTable::SetCellData(const TableCellT& cell, void* data) { + if (mCellData) + mCellData->AssignItemsAt(1, FetchCellDataIndex(cell), data); } -/*virtual*/ void T2DlgItemTable::UnhiliteCell(CDC*, const TableCellT&) { +/*virtual*/ void T2DlgItemTable::GetCellData(const TableCellT& cell, void* data) { + if (mCellData) + mCellData->FetchItemAt(FetchCellDataIndex(cell), data); } -/*virtual*/ void T2DlgItemTable::HiliteCells(CDC*, LArrayIterator&) { +/*virtual*/ BOOL T2DlgItemTable::FetchLocalCellFrame(const TableCellT& cell, RECT& rect) { + rect.left = (cell.col - 1) * mColWidth; + rect.top = (cell.row - 1) * mRowHeight; + ViewToClient((POINT *) &rect.left, 1); + rect.right = rect.left + mColWidth; + rect.bottom = rect.top + mRowHeight; + return true; } -/*virtual*/ void T2DlgItemTable::UnhiliteCells(CDC*, LArrayIterator&) { +/*virtual*/ void T2DlgItemTable::FetchCellHitBy(const POINT& pt, TableCellT& cell) { + cell.row = pt.y / mRowHeight + 1; + cell.col = pt.x / mColWidth + 1; } -/*virtual*/ void T2DlgItemTable::ClickCell(const TableCellT&, const POINT&) { +int T2DlgItemTable::FetchCellDataIndex(const TableCellT& cell) { + return (cell.row - 1) * mCols + cell.col; } -/*virtual*/ void T2DlgItemTable::DrawCell(CDC*, const TableCellT&) { -} +TableCellIterator::TableCellIterator(const TableCellT& start, const TableCellT& end) { + mLastRow = (start.row > end.row) ? start.row : end.row; + mFirstCol = (start.col < end.col) ? start.col : end.col; + mLastCol = (start.col > end.col) ? start.col : end.col; -/*virtual*/ void T2DlgItemTable::SelectCell(const TableCellT&) { + mCurrentRow = ((start.row < end.row) ? start.row : end.row) - 1; + mCurrentCol = mLastCol; } -/*virtual*/ void T2DlgItemTable::ToggleCell(const TableCellT&) { -} +BOOL TableCellIterator::Next(TableCellT& newCurrent) { + mCurrentCol++; + if (mCurrentCol > mLastCol) { + mCurrentRow++; + mCurrentCol = mFirstCol; + } -int T2DlgItemTable::IsSelected(const TableCellT&) const { + BOOL isValid = (mCurrentRow <= mLastRow); + if (isValid) { + newCurrent.row = mCurrentRow; + newCurrent.col = mCurrentCol; + } + return isValid; } -void T2DlgItemTable::GetSelectedCell(TableCellT&) const { -} +/*virtual*/ void T2DlgItemTable::ClickSelf(const POINT& pt, UINT nFlags) { + UINT keyFlags = IsMultiSelectable() ? (nFlags & (MK_SHIFT | MK_CONTROL)) : 0; + POINT ptView = pt; + ClientToView(&ptView, 1); -void T2DlgItemTable::InvalidateCell(const TableCellT&) { -} + TableCellT cellClicked; + FetchCellHitBy(ptView, cellClicked); -int T2DlgItemTable::Resized() { + if (IsValidCell(cellClicked)) { + switch (keyFlags) { + case MK_SHIFT: + ClearSelectedCells(); + case (MK_SHIFT | MK_CONTROL): + { + TableCellIterator cellIterator(mClickedCell, cellClicked); + TableCellT cell; + while (cellIterator.Next(cell)) + SelectCell(cell); + } + break; + case MK_CONTROL: + ToggleCell(cellClicked); + mClickedCell = cellClicked; + break; + default: + ClickCell(cellClicked, pt); + mClickedCell = cellClicked; + break; + } + } } -void T2DlgItemTable::ViewToClient(POINT*, int) { -} +/*virtual*/ BOOL T2DlgItemTable::OnT2DlgItemEraseBkgnd(CDC* dc) { + int save = dc->SaveDC(); -void T2DlgItemTable::ClientToView(POINT*, int) { -} + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); -/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { -} + CPen pen; + pen.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); -/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonUp(unsigned int, CPoint) { -} + if (mShowHScroller && mShowVScroller) { + CRect insideRect; + GetClientRect(insideRect); + insideRect.right -= 16; + insideRect.bottom -= 16; -/*virtual*/ void T2DlgItemTable::OnT2DlgItemMouseMove(unsigned int, CPoint) { -} + dc->SelectObject(pen); + dc->MoveTo(insideRect.right - 1, insideRect.top); + dc->LineTo(insideRect.right - 1, insideRect.bottom - 1); + dc->LineTo(insideRect.left, insideRect.bottom - 1); + insideRect.right -= 1; + insideRect.bottom -= 1; + dc->FillSolidRect(&insideRect, PALETTERGB(204, 204, 204)); + } -/*virtual*/ int T2DlgItemTable::OnCommand(unsigned int, long) { -} + CRect clipRect; + dc->GetClipBox(clipRect); -/*virtual*/ void T2DlgItemTable::OnT2Size(unsigned int, int, int) { -} + CRect clientRect; + GetClientRect(clientRect); -void T2DlgItemTable::DoScroll() { -} + clientRect.right -= mShowVScroller ? 16 : 0; + clientRect.bottom -= mShowHScroller ? 16 : 0; + + clipRect.bottom = min(clipRect.bottom, clientRect.bottom); + clipRect.right = min(clipRect.right, clientRect.right); + + dc->IntersectClipRect(&clientRect); -/*virtual*/ void T2DlgItemTable::ListenToMessage(unsigned int, void*) { + CPoint topLeft; + topLeft = clipRect.TopLeft(); + ClientToView(&topLeft, 1); + + TableCellT topLeftCell; + FetchCellHitBy(topLeft, topLeftCell); + + if (topLeftCell.row < 1) + topLeftCell.row = 1; + if (topLeftCell.col < 1) + topLeftCell.col = 1; + + CPoint bottomRight = clipRect.BottomRight(); + ClientToView(&bottomRight, 1); + + TableCellT bottomRightCell; + FetchCellHitBy(bottomRight, bottomRightCell); + + if (bottomRightCell.row > mRows) + bottomRightCell.row = mRows; + if (bottomRightCell.col > mCols) + bottomRightCell.col = mCols; + + TableCellT i; + for (i.row = topLeftCell.row; i.row <= bottomRightCell.row; i.row++) { + for (i.col = topLeftCell.col; i.col <= bottomRightCell.col; i.col++) { + DrawCell(dc, i); + } + } + + if (IsMultiSelectable()) { + LArrayIterator iter(*mMultiSelectedCells); + HiliteCells(dc, iter); + } else { + HiliteCell(dc, mSelectedCell); + } + + dc->RestoreDC(save); + return true; +} + +/*virtual*/ void T2DlgItemTable::HiliteCell(CDC* dc, const TableCellT& cell) { + RECT cellFrameRect; + if (IsValidCell(cell) && FetchLocalCellFrame(cell, cellFrameRect)) + dc->InvertRect(&cellFrameRect); } -T2DlgItemHScr* T2DlgItemTable::GetHScroller() const { +/*virtual*/ void T2DlgItemTable::UnhiliteCell(CDC* dc, const TableCellT& cell) { + RECT cellFrameRect; + if (IsValidCell(cell) && FetchLocalCellFrame(cell, cellFrameRect)) + dc->InvertRect(&cellFrameRect); } -T2DlgItemVScr* T2DlgItemTable::GetVScroller() const { +/*virtual*/ void T2DlgItemTable::HiliteCells(CDC* dc, LArrayIterator& iterator) { + TableCellT cell; + + while (iterator.Next(&cell)) + HiliteCell(dc, cell); } -void T2DlgItemTable::AttachHScroller(T2DlgItemHScr*, int) { +/*virtual*/ void T2DlgItemTable::UnhiliteCells(CDC* dc, LArrayIterator& iterator) { + TableCellT cell; + + while (iterator.Next(&cell)) + UnhiliteCell(dc, cell); } -void T2DlgItemTable::AttachVScroller(T2DlgItemVScr*, int) { +/*virtual*/ void T2DlgItemTable::ClickCell(const TableCellT& cell, const POINT&) { + ClearSelectedCells(); + SelectCell(cell); } -void T2DlgItemTable::SetHScrollerStyle(T2DlgItemTable::ScrollerStyle) { +/*virtual*/ void T2DlgItemTable::DrawCell(CDC* dc, const TableCellT& cell) { + CRect rect; + if (FetchLocalCellFrame(cell, rect)) { + int save = dc->SaveDC(); + + CBrush brush; + brush.CreateSolidBrush(PALETTEINDEX(0)); + + CPen pen0; + pen0.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + dc->SelectObject(&brush); + dc->SelectObject(&pen0); + dc->SetBkMode(TRANSPARENT); + dc->Rectangle(rect); + + CString text; + text.Format("%d,%d", cell.row, cell.col); + dc->DrawText(text, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + + dc->RestoreDC(save); + } +} + +/*virtual*/ void T2DlgItemTable::SelectCell(const TableCellT& cell) { + if (IsMultiSelectable()) { + if (!IsSelected(cell)) { + mSelectedCell = cell; + InvalidateCell(mSelectedCell); + mMultiSelectedCells->Add(&cell); + } + } else { + if (!EqualCell(cell, mSelectedCell)) { + InvalidateCell(mSelectedCell); + mSelectedCell = cell; + InvalidateCell(mSelectedCell); + Notify(0, &mSelectedCell); + } + } +} + +/*virtual*/ void T2DlgItemTable::ToggleCell(const TableCellT& cell) { + if (IsSelected(cell)) { + mMultiSelectedCells->Remove(&cell); + if (EqualCell(cell, mSelectedCell)) { + mSelectedCell.col = 0; + mSelectedCell.row = 0; + mMultiSelectedCells->FetchItemAt(1, &mSelectedCell); + } + } else { + mMultiSelectedCells->Add(&cell); + } + InvalidateCell(cell); +} + +BOOL T2DlgItemTable::IsSelected(const TableCellT& cell) const { + return IsMultiSelectable() + ? (mMultiSelectedCells->FetchIndexOf(&cell) != 0) + : EqualCell(mSelectedCell, cell); +} + +void T2DlgItemTable::GetSelectedCell(TableCellT& cell) const { + cell = mSelectedCell; +} + +void T2DlgItemTable::InvalidateCell(const TableCellT& cell) { + CRect rect; + if (FetchLocalCellFrame(cell, rect)) + InvalidateRect(rect); +} + +BOOL T2DlgItemTable::Resized() { + if (!m_hWnd) + return false; + + BOOL changed = false; + mResizeCount++; + + CRect clientRect; + GetClientRect(clientRect); + clientRect.right -= mShowVScroller ? 16 : 0; + clientRect.bottom -= mShowHScroller ? 16 : 0; + + CRect tableRect; + tableRect.left = 0; + tableRect.top = 0; + tableRect.right = mColWidth * mCols; + tableRect.right = mRowHeight * mRows; + + if ( + (mHScrollerStyle == ShowIfNeeded && tableRect.Width() > clientRect.Width()) || + mHScrollerStyle == AlwaysShow + ) + { + if (!mShowHScroller && !changed) { + mShowHScroller = true; + changed = true; + } + } + + if ( + (mHScrollerStyle == ShowIfNeeded && tableRect.Width() <= clientRect.Width()) || + (mHScrollerStyle != ShowIfNeeded && mHScrollerStyle != AlwaysShow) + ) + { + if (mShowHScroller && !changed) { + mShowHScroller = false; + changed = true; + } + } + + if ( + (mVScrollerStyle == ShowIfNeeded && tableRect.Height() > clientRect.Height()) || + mVScrollerStyle == AlwaysShow + ) + { + if (!mShowVScroller && !changed) { + mShowVScroller = true; + changed = true; + } + } + + if ( + (mVScrollerStyle == ShowIfNeeded && tableRect.Height() <= clientRect.Height()) || + (mVScrollerStyle != ShowIfNeeded && mVScrollerStyle != AlwaysShow) + ) + { + if (mShowVScroller && !changed) { + mShowVScroller = false; + changed = true; + } + } + + if (changed) + Resized(); + + mResizeCount--; + + GetClientRect(clientRect); + clientRect.right -= mShowVScroller ? 16 : 0; + clientRect.bottom -= mShowHScroller ? 16 : 0; + + if (mHScrollerStyle != AttachedNoUpdates) { + mHScroller->SetPage(clientRect.Width() / ((mColWidth > 0) ? mColWidth : 1)); + mHScroller->SetRange(mCols); + } + if (mVScrollerStyle != AttachedNoUpdates) { + mVScroller->SetPage(clientRect.Height() / ((mRowHeight > 0) ? mRowHeight : 1)); + mVScroller->SetRange(mRows); + } + + if (IsOwnHScroller()) + mHScroller->SetWindowPos(NULL, 0, 0, clientRect.Width(), 16, SWP_NOMOVE | SWP_NOZORDER); + if (IsOwnVScroller()) + mVScroller->SetWindowPos(NULL, 0, 0, 16, clientRect.Height(), SWP_NOMOVE | SWP_NOZORDER); + + if (mResizeCount == 0 && changed) { + if ((mHScrollerStyle == ShowIfNeeded && !mShowHScroller) || (mHScrollerStyle == AlwaysHide)) + mHScroller->ShowWindow(SW_HIDE); + if ((mVScrollerStyle == ShowIfNeeded && !mShowVScroller) || (mVScrollerStyle == AlwaysHide)) + mVScroller->ShowWindow(SW_HIDE); + + if ((mHScrollerStyle == ShowIfNeeded && mShowHScroller) || (mHScrollerStyle == AlwaysShow)) + mHScroller->ShowWindow(SW_SHOW); + if ((mVScrollerStyle == ShowIfNeeded && mShowVScroller) || (mVScrollerStyle == AlwaysShow)) + mVScroller->ShowWindow(SW_SHOW); + } + + return changed; +} + +void T2DlgItemTable::ViewToClient(POINT* pt, int n) { + for (int i = 0; i < n; i++) { + pt->x -= mScrollOffset.x; + pt->y -= mScrollOffset.y; + pt++; + } +} + +void T2DlgItemTable::ClientToView(POINT* pt, int n) { + for (int i = 0; i < n; i++) { + pt->x += mScrollOffset.x; + pt->y += mScrollOffset.y; + pt++; + } +} + +/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonDown(UINT nFlags, CPoint pt) { + ClickSelf(pt, nFlags); +} + +/*virtual*/ void T2DlgItemTable::OnT2DlgItemLButtonUp(UINT, CPoint) { +} + +/*virtual*/ void T2DlgItemTable::OnT2DlgItemMouseMove(UINT, CPoint) { +} + +/*virtual*/ BOOL T2DlgItemTable::OnCommand(UINT, long) { + DoScroll(); + return true; } -void T2DlgItemTable::SetVScrollerStyle(T2DlgItemTable::ScrollerStyle) { +/*virtual*/ void T2DlgItemTable::OnT2Size(unsigned int, int, int) { + Resized(); } -int T2DlgItemTable::IsOwnHScroller() const { +void T2DlgItemTable::DoScroll() { + POINT prevOffset = mScrollOffset; + mScrollOffset.x = mHScroller->GetValue() * ((mColWidth > 0) ? mColWidth : 1); + mScrollOffset.y = mVScroller->GetValue() * ((mRowHeight > 0) ? mRowHeight : 1); + + CRect clientRect; + GetClientRect(clientRect); + clientRect.right -= mShowVScroller ? 16 : 0; + clientRect.bottom -= mShowHScroller ? 16 : 0; + ScrollWindowEx(prevOffset.x - mScrollOffset.x, prevOffset.y - mScrollOffset.y, &clientRect, NULL, NULL, NULL, SW_INVALIDATE | SW_ERASE); } -int T2DlgItemTable::IsOwnVScroller() const { +/*virtual*/ void T2DlgItemTable::ListenToMessage(unsigned int msg, void*) { + if ( + (!IsOwnHScroller() && msg == mHScroller->GetDlgCtrlID()) || + (!IsOwnVScroller() && msg == mVScroller->GetDlgCtrlID()) + ) + DoScroll(); } -TableCellIterator::TableCellIterator(const TableCellT&, const TableCellT&) { +T2DlgItemHScr* T2DlgItemTable::GetHScroller() const { + return mHScroller; } -int TableCellIterator::Next(TableCellT&) { +T2DlgItemVScr* T2DlgItemTable::GetVScroller() const { + return mVScroller; +} + +void T2DlgItemTable::AttachHScroller(T2DlgItemHScr* scroller, BOOL flag) { + if (scroller) { + if (IsOwnHScroller()) + delete mHScroller; + + mHScroller = scroller; + mHScrollerStyle = flag ? AttachedNoUpdates : Attached; + mHScroller->AddListener(this); + Resized(); + } +} + +void T2DlgItemTable::AttachVScroller(T2DlgItemVScr* scroller, BOOL flag) { + if (scroller) { + if (IsOwnVScroller()) + delete mVScroller; + + mVScroller = scroller; + mVScrollerStyle = flag ? AttachedNoUpdates : Attached; + mVScroller->AddListener(this); + Resized(); + } +} + +void T2DlgItemTable::SetHScrollerStyle(ScrollerStyle style) { + switch (style) { + case ShowIfNeeded: + case AlwaysHide: + case AlwaysShow: + if (IsOwnHScroller() && mHScrollerStyle != style) { + mHScrollerStyle = style; + Resized(); + } + } +} + +void T2DlgItemTable::SetVScrollerStyle(ScrollerStyle style) { + switch (style) { + case ShowIfNeeded: + case AlwaysHide: + case AlwaysShow: + if (IsOwnVScroller() && mVScrollerStyle != style) { + mVScrollerStyle = style; + Resized(); + } + } +} + +BOOL T2DlgItemTable::IsOwnHScroller() const { + BOOL result = false; + switch (mHScrollerStyle) { + case ShowIfNeeded: + case AlwaysHide: + case AlwaysShow: + result = true; + } + return result; +} + +BOOL T2DlgItemTable::IsOwnVScroller() const { + BOOL result = false; + switch (mVScrollerStyle) { + case ShowIfNeeded: + case AlwaysHide: + case AlwaysShow: + result = true; + } + return result; } diff --git a/src/T2DLL/T2DlgItemTable.h b/src/T2DLL/T2DlgItemTable.h index 577fb52..5b294cf 100644 --- a/src/T2DLL/T2DlgItemTable.h +++ b/src/T2DLL/T2DlgItemTable.h @@ -3,21 +3,25 @@ #include "LListener.h" #include "T2DlgItem.h" -class DLL_EXPORT T2DlgItemTable : public T2DlgItem, public LListener { +class AFX_EXT_CLASS T2DlgItemTable : public T2DlgItem, public LListener { public: enum ScrollerStyle { - ScrollerStyle_0 + ShowIfNeeded, + AlwaysHide, + AlwaysShow, + Attached, + AttachedNoUpdates }; - T2DlgItemTable(T2TowerDoc*, T2ImageObj*, CPalette*); - T2DlgItemTable(int, int, int, int, int, T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); + T2DlgItemTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize, T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); virtual ~T2DlgItemTable(); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - virtual void InsertRows(int, unsigned int, void*); - virtual void InsertCols(int, unsigned int, void*); - virtual void RemoveRows(int, unsigned int); - virtual void RemoveCols(int, unsigned int); + virtual BOOL Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); + virtual void InsertRows(int, UINT, void*); + virtual void InsertCols(int, UINT, void*); + virtual void RemoveRows(int, UINT); + virtual void RemoveCols(int, UINT); virtual void SetRowHeight(int, unsigned int, unsigned int); virtual void SetColWidth(int, unsigned int, unsigned int); virtual void SetCellData(const TableCellT&, void*); @@ -26,39 +30,39 @@ public: virtual void ToggleCell(const TableCellT&); virtual void ClearSelectedCells(); - void GetTableSize(unsigned int&, unsigned int&) const; - int IsMultiSelectable() const; - void EnableMultiSelect(int); - int IsValidCell(const TableCellT&) const; - int EqualCell(const TableCellT&, const TableCellT&) const; + void GetTableSize(UINT& outRows, UINT& outCols) const; + BOOL IsMultiSelectable() const; + void EnableMultiSelect(BOOL); + BOOL IsValidCell(const TableCellT&) const; + BOOL EqualCell(const TableCellT&, const TableCellT&) const; void SetCellDataSize(int); - int IsSelected(const TableCellT&) const; + BOOL IsSelected(const TableCellT&) const; void GetSelectedCell(TableCellT&) const; virtual void ListenToMessage(unsigned int, void*); T2DlgItemHScr* GetHScroller() const; T2DlgItemVScr* GetVScroller() const; - void AttachHScroller(T2DlgItemHScr*, int); - void AttachVScroller(T2DlgItemVScr*, int); - void SetHScrollerStyle(ScrollerStyle); - void SetVScrollerStyle(ScrollerStyle); + void AttachHScroller(T2DlgItemHScr* scroller, BOOL flag); + void AttachVScroller(T2DlgItemVScr* scroller, BOOL flag); + void SetHScrollerStyle(ScrollerStyle style); + void SetVScrollerStyle(ScrollerStyle style); protected: - virtual int OnCommand(unsigned int, long); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnCommand(UINT, long); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); virtual void OnT2DlgItemLButtonDown(UINT, CPoint); virtual void OnT2DlgItemLButtonUp(UINT, CPoint); virtual void OnT2DlgItemMouseMove(UINT, CPoint); - virtual int OnT2DlgItemCreate(CREATESTRUCT*); + virtual BOOL OnT2DlgItemCreate(CREATESTRUCT*); virtual void OnT2Size(unsigned int, int, int); - virtual void ClickSelf(const POINT&, unsigned int); + virtual void ClickSelf(const POINT&, UINT nFlags); virtual void HiliteCells(CDC*, LArrayIterator&); virtual void UnhiliteCells(CDC*, LArrayIterator&); virtual void HiliteCell(CDC*, const TableCellT&); virtual void UnhiliteCell(CDC*, const TableCellT&); virtual void ClickCell(const TableCellT&, const POINT&); virtual void DrawCell(CDC*, const TableCellT&); - virtual int FetchLocalCellFrame(const TableCellT&, RECT&); + virtual BOOL FetchLocalCellFrame(const TableCellT&, RECT&); virtual void FetchCellHitBy(const POINT&, TableCellT&); int FetchCellDataIndex(const TableCellT&); @@ -66,16 +70,40 @@ protected: void ViewToClient(POINT*, int); void ClientToView(POINT*, int); void DoScroll(); - int IsOwnHScroller() const; - int IsOwnVScroller() const; + BOOL IsOwnHScroller() const; + BOOL IsOwnVScroller() const; + + UINT mRows; + UINT mCols; + int mRowHeight; + int mColWidth; + LArray *mCellData; + TableCellT mClickedCell; + TableCellT mSelectedCell; + LArray *mMultiSelectedCells; + POINT mScrollOffset; + T2DlgItemHScr *mHScroller; + T2DlgItemVScr *mVScroller; + BOOL mShowHScroller; + BOOL mShowVScroller; + int mResizeCount; + ScrollerStyle mVScrollerStyle; + ScrollerStyle mHScrollerStyle; private: - void InitTable(int, int, int, int, int); - int Resized(); + void InitTable(int rows, int cols, int rowHeight, int colWidth, int cellDataSize); + BOOL Resized(); }; -class DLL_EXPORT TableCellIterator { +class AFX_EXT_CLASS TableCellIterator { public: - TableCellIterator(const TableCellT&, const TableCellT&); - int Next(TableCellT&); + TableCellIterator(const TableCellT& start, const TableCellT& end); + BOOL Next(TableCellT& newCurrent); + +protected: + UINT mCurrentRow; + UINT mCurrentCol; + UINT mLastRow; + UINT mFirstCol; + UINT mLastCol; }; diff --git a/src/T2DLL/T2DlgItemText.cpp b/src/T2DLL/T2DlgItemText.cpp index 71f9242..e8bd018 100644 --- a/src/T2DLL/T2DlgItemText.cpp +++ b/src/T2DLL/T2DlgItemText.cpp @@ -1,28 +1,100 @@ #include "T2DlgItemText.h" -T2DlgItemText::T2DlgItemText(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2DlgItemText::T2DlgItemText(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) + , mHasTextColor(false) +{ } -void T2DlgItemText::SetTextColor(unsigned long) { +void T2DlgItemText::SetTextColor(COLORREF inColor) { + mTextColor = inColor; + mHasTextColor = true; } -/*virtual*/ void T2DlgItemText::GetDescriptor(CString&) const { +/*virtual*/ void T2DlgItemText::GetDescriptor(CString& outStr) const { + GetContentText(outStr); } -/*virtual*/ void T2DlgItemText::SetDescriptor(const CString&) { +/*virtual*/ void T2DlgItemText::SetDescriptor(const CString& inStr) { + CString str(GetJustification()); + str += inStr; + SetWindowText(str); + + CRect rect; + GetClientRect(rect); + MapWindowPoints(GetParent(), rect); + GetParent()->InvalidateRect(rect); } -/*virtual*/ int T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemText::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + int save = pDC->SaveDC(); + + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + pDC->SetTextColor(mHasTextColor ? mTextColor : PALETTEINDEX(255)); + pDC->SetBkMode(TRANSPARENT); + pDC->SelectObject(mFont); + + CString str; + GetContentText(str); + + char justification = GetJustification(); + UINT flags = DT_WORDBREAK | DT_NOPREFIX; + + if (isupper(justification)) { + flags |= DT_VCENTER; + justification = tolower(justification); + } + + switch (justification) { + case 'c': flags |= DT_CENTER; break; + case 'l': flags |= DT_LEFT; break; + case 'r': flags |= DT_RIGHT; break; + } + + pDC->DrawText(str, rect, flags); + + pDC->RestoreDC(save); + + return true; } char T2DlgItemText::GetJustification() const { + char result = 'l'; + + CString text; + GetWindowText(text); + if (text.GetLength() > 0) + result = text[0]; + + return result; } -void T2DlgItemText::GetContentText(CString&) const { +void T2DlgItemText::GetContentText(CString& outStr) const { + GetWindowText(outStr); + + if (outStr.GetLength() > 0) + outStr = outStr.Mid(1); } -void T2DlgItemText::InfoDialogMessage(CString&, long) { +void T2DlgItemText::InfoDialogMessage(CString& inStr, long inTime) { + if (inTime != -1) { + GetDescriptor(mPreviousString); + mTimerID = SetTimer(1000, inTime, NULL); + } else { + mPreviousString.Empty(); + mTimerID = 0; + } + SetDescriptor(inStr); } -/*virtual*/ void T2DlgItemText::OnT2Timer(unsigned int) { +/*virtual*/ void T2DlgItemText::OnT2Timer(UINT id) { + if (id == mTimerID && mPreviousString.GetLength() > 0) { + SetDescriptor(mPreviousString); + mPreviousString.Empty(); + KillTimer(mTimerID); + } } diff --git a/src/T2DLL/T2DlgItemText.h b/src/T2DLL/T2DlgItemText.h index 83fa1f6..687e5a8 100644 --- a/src/T2DLL/T2DlgItemText.h +++ b/src/T2DLL/T2DlgItemText.h @@ -1,21 +1,23 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2DlgItemText { +class AFX_EXT_CLASS T2DlgItemText : public T2DlgItem { public: - T2DlgItemText(T2TowerDoc*, T2ImageObj*, CPalette*); - void SetTextColor(unsigned long); + T2DlgItemText(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual void GetDescriptor(CString&) const; virtual void SetDescriptor(const CString&); + void SetTextColor(COLORREF); + void InfoDialogMessage(CString&, long); + protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + virtual void OnT2Timer(UINT); char GetJustification() const; void GetContentText(CString&) const; -public: - void InfoDialogMessage(CString&, long); -protected: - virtual void OnT2Timer(unsigned int); -public: - virtual ~T2DlgItemText() {} + BOOL mHasTextColor; + COLORREF mTextColor; + CString mPreviousString; + UINT mTimerID; }; diff --git a/src/T2DLL/T2DlgItemVScr.cpp b/src/T2DLL/T2DlgItemVScr.cpp index 3b4b55a..e852793 100644 --- a/src/T2DLL/T2DlgItemVScr.cpp +++ b/src/T2DLL/T2DlgItemVScr.cpp @@ -1,3 +1,4 @@ +#include "T2BitImage.h" #include "T2DlgItemVScr.h" T2DlgItemVScr::T2DlgItemVScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) @@ -5,20 +6,150 @@ T2DlgItemVScr::T2DlgItemVScr(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalett { } -/*virtual*/ int T2DlgItemVScr::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemVScr::OnT2DlgItemEraseBkgnd(CDC* dc) { + CRect rect; + GetClientRect(rect); + + int savedDC = dc->SaveDC(); + + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); + + CPen pen1; + pen1.CreatePen(PS_SOLID, 0, PALETTERGB(255, 255, 255)); + + CPen pen2; + pen2.CreatePen(PS_SOLID, 0, PALETTERGB(133, 133, 133)); + + CPen pen3; + pen3.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + + CBrush brush; + brush.CreateSolidBrush(PALETTERGB(204, 204, 204)); + + dc->SelectObject(pen2); + dc->MoveTo(rect.right - 1, rect.top); + dc->LineTo(rect.left, rect.top); + dc->LineTo(rect.left, rect.bottom); + + dc->SelectObject(pen1); + dc->MoveTo(rect.right - 1, rect.top + 1); + dc->LineTo(rect.right - 1, rect.bottom - 1); + dc->LineTo(rect.left, rect.bottom - 1); + + int thumbPosition, thumbSize; + CalcScrollBarThumb(&thumbPosition, &thumbSize); + + int upImg; + if (!IsScrollable()) + upImg = 200; + else + upImg = (mUpImage == 100) ? 100 : 0; + + RECT imgRect; + T2BitImage *image = GetObjectImage(imgRect, "DLGITEM:UArrow", upImg); + + RECT destRect = rect; + destRect.top = 0; + destRect.bottom = imgRect.bottom - imgRect.top; + dc->Rectangle(&destRect); + image->CopyImage(dc, imgRect, destRect, 0, NULL); + + int dnImg; + if (!IsScrollable()) + dnImg = 200; + else + dnImg = (mDownImage == 100) ? 100 : 0; + + image = GetObjectImage(imgRect, "DLGITEM:UArrow", dnImg); + + destRect = rect; + destRect.top = destRect.bottom - (imgRect.bottom - imgRect.top); + dc->Rectangle(&destRect); + image->CopyImage(dc, imgRect, destRect, 0, NULL); + + destRect.left = rect.left + 1; + destRect.top = 16; + destRect.right = rect.right - 1; + destRect.bottom = thumbPosition; + if (destRect.top < destRect.bottom) + dc->FillRect(&destRect, &brush); + + destRect.left = rect.left + 1; + destRect.top = thumbPosition + thumbSize; + destRect.right = rect.right - 1; + destRect.bottom = rect.bottom - 16; + if (destRect.top < destRect.bottom) + dc->FillRect(&destRect, &brush); + + if (thumbSize > 0) { + destRect.left = rect.left + 1; + destRect.top = thumbPosition; + destRect.right = rect.right - 1; + destRect.bottom = thumbPosition + thumbSize; + dc->FillRect(&destRect, &brush); + + dc->SelectObject(pen3); + dc->MoveTo(destRect.right - 1, destRect.top); + dc->LineTo(destRect.right - 1, destRect.bottom - 1); + dc->LineTo(destRect.left, destRect.bottom - 1); + dc->LineTo(destRect.left, destRect.top); + dc->LineTo(destRect.right - 1, destRect.top); + + dc->SelectObject(pen2); + dc->MoveTo(destRect.right - 2, destRect.top + 1); + dc->LineTo(destRect.right - 2, destRect.bottom - 2); + dc->LineTo(destRect.left + 1, destRect.bottom - 2); + + dc->SelectObject(pen1); + dc->MoveTo(destRect.right - 2, destRect.top + 1); + dc->LineTo(destRect.left + 1, destRect.top + 1); + dc->LineTo(destRect.left + 1, destRect.bottom - 1); + } + + dc->RestoreDC(savedDC); + + return true; } -/*virtual*/ int T2DlgItemVScr::ScrollBarHittest(CPoint) const { +/*virtual*/ int T2DlgItemVScr::ScrollBarHittest(CPoint pt) const { + if (!IsScrollable()) + return 0; + + CRect theCRect; + GetClientRect(theCRect); + + int area = 0; + + int theThumbPosition, theThumbSize; + CalcScrollBarThumb(&theThumbPosition, &theThumbSize); + + if (theCRect.top <= pt.y && pt.y < (theCRect.top + 16)) + area = Area_Up; + else if ((theCRect.top + 16) <= pt.y && pt.y < theThumbPosition) + area = Area_PageUp; + else if (theThumbPosition <= pt.y && pt.y < (theThumbPosition + theThumbSize)) + area = Area_Thumb; + else if ((theThumbPosition + theThumbSize) <= pt.y && pt.y < (theCRect.bottom - 16)) + area = Area_PageDown; + else if ((theCRect.bottom - 16) <= pt.y && pt.y < theCRect.bottom) + area = Area_Down; + + return area; } -/*virtual*/ void T2DlgItemVScr::GetUpButtonRect(const CRect&, CRect&) const { +/*virtual*/ void T2DlgItemVScr::GetUpButtonRect(const CRect& clientRect, CRect& buttonRect) const { + buttonRect = CRect(clientRect.left, clientRect.top, clientRect.right, clientRect.top + 16); } -/*virtual*/ void T2DlgItemVScr::GetDnButtonRect(const CRect&, CRect&) const { +/*virtual*/ void T2DlgItemVScr::GetDnButtonRect(const CRect& clientRect, CRect& buttonRect) const { + buttonRect = CRect(clientRect.left, clientRect.bottom - 16, clientRect.right, clientRect.bottom); } -/*virtual*/ int T2DlgItemVScr::PositionToValue(const CPoint&) const { +/*virtual*/ int T2DlgItemVScr::PositionToValue(const CPoint& pt) const { + return pt.y; } -/*virtual*/ int T2DlgItemVScr::PositionToValue(const CRect&) const { +/*virtual*/ int T2DlgItemVScr::PositionToValue(const CRect& rect) const { + return rect.Height(); } diff --git a/src/T2DLL/T2DlgItemVScr.h b/src/T2DLL/T2DlgItemVScr.h index 4b44052..564aec6 100644 --- a/src/T2DLL/T2DlgItemVScr.h +++ b/src/T2DLL/T2DlgItemVScr.h @@ -2,11 +2,11 @@ #include "common.h" #include "T2DlgItemScr.h" -class DLL_EXPORT T2DlgItemVScr : public T2DlgItemScr { +class AFX_EXT_CLASS T2DlgItemVScr : public T2DlgItemScr { public: - T2DlgItemVScr(T2TowerDoc*, T2ImageObj*, CPalette*); + T2DlgItemVScr(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); virtual int ScrollBarHittest(CPoint) const; virtual void GetUpButtonRect(const CRect&, CRect&) const; virtual void GetDnButtonRect(const CRect&, CRect&) const; diff --git a/src/T2DLL/T2DrawableObject.h b/src/T2DLL/T2DrawableObject.h index bb66edc..06a2ac8 100644 --- a/src/T2DLL/T2DrawableObject.h +++ b/src/T2DLL/T2DrawableObject.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2Object.h" -class T2DrawableObject : public T2Object { +class AFX_EXT_CLASS T2DrawableObject : public T2Object { public: T2DrawableObject(); virtual ~T2DrawableObject(); diff --git a/src/T2DLL/T2ElevatorModule.cpp b/src/T2DLL/T2ElevatorModule.cpp index 5159c69..33fc3af 100644 --- a/src/T2DLL/T2ElevatorModule.cpp +++ b/src/T2DLL/T2ElevatorModule.cpp @@ -1,100 +1,644 @@ +#include "T2Archive.h" #include "T2ElevatorModule.h" - -T2ElevatorModule::T2ElevatorModule(int) { +#include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2MoverDef.h" +#include "T2MoverModuleList.h" +#include "T2People.h" +#include "T2PeopleLinkIterator.h" +#include "T2Request.h" +#include "T2StopInfoArray.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "UT2Coordinate.h" + +T2ElevatorModule::T2ElevatorModule(int index) { + mIndex = index; + mStatus = kElevatorStatus0; + mHomePosition = 0; + mOffsetPos = 0; + mNextStop = 0; + mRequestCount = 0; + mTopTurn = 0; + mBottomTurn = 0; + + mStopInfoArray = new T2StopInfoArray; +#line 18 + _ASSERT(mStopInfoArray); } /*virtual*/ T2ElevatorModule::~T2ElevatorModule() { + if (mStopInfoArray) + delete mStopInfoArray; } -void T2ElevatorModule::Init(int, int) { -} +void T2ElevatorModule::Init(int count, int position) { + SetUsed(true); -/*virtual*/ void T2ElevatorModule::SetUsed(int) { -} + mPosition = position; + mDirection = kElevatorDirection0; + mWaitCounter = 0; + mPatIndex = 0; + mNumPeople = 0; + _4C = 0; + mLink1 = NULL; + mLink2 = NULL; + mStatus = kElevatorStatus0; + mHomePosition = position; + mOffsetPos = 0; + mNextStop = position; + mRequestCount = 0; + mTopTurn = position; + mBottomTurn = position; + + mStopInfoArray->Init(count); +} + +/*virtual*/ void T2ElevatorModule::SetUsed(BOOL used) { + T2MoverModule::SetUsed(used); + + if (!used && mStopInfoArray) + mStopInfoArray->AllClear(); +} + +BOOL T2ElevatorModule::IsPtInArea(POINT pt, const RECT& area) const { + BOOL result = false; + + if (mUsed) { + RECT myArea = area; + OffsetRect(&myArea, 0, -(UT2Coordinate::UnitVSize(0) * mPosition + mOffsetPos)); + + if (PtInRect(&myArea, pt)) + result = true; + } + + return result; +} + +/*virtual*/ void T2ElevatorModule::StopAdded(T2TowerDoc*, T2Mover* mover, int position) { + if (!mover->IsStopPosition(mHomePosition)) { + mHomePosition = position; + StartToHomePos(); + } +} + +/*virtual*/ void T2ElevatorModule::StopRemoved(T2TowerDoc* towerDoc, T2Mover* mover, int position) { +#line 103 + ASSERT(mStopInfoArray != NULL); + + if (IsOffStopPos(position, ERequestUpDown_0) || IsOffStopPos(position, ERequestUpDown_1)) { + RemoveContents(towerDoc, mover, position); + mStopInfoArray->ClearOffStop(position, ERequestUpDown_0); + mStopInfoArray->ClearOffStop(position, ERequestUpDown_1); + } + + if (IsOnStopPos(position, ERequestUpDown_0)) { + mRequestCount--; + mStopInfoArray->ClearOnStop(position, ERequestUpDown_0); + } + if (IsOnStopPos(position, ERequestUpDown_1)) { + mRequestCount--; + mStopInfoArray->ClearOnStop(position, ERequestUpDown_1); + } + +#line 124 + ASSERT(mRequestCount >= 0); + + if (mRequestCount < 0) + mRequestCount = 0; + + BOOL flag = false; + + if (position == mHomePosition) { + flag = !HomePosRemoved(mover, position); + if (!flag && !towerDoc->towerDoc_vf16C() && mover->IsShaftVisible()) { + RECT area; + CalcUintArea(mover, mHomePosition, area); + + T2TowerMainView *theView = towerDoc->GetTowerMainView(); +#line 142 + ASSERT(theView != NULL); + + theView->tmv_vf128(area); + } + } + + if (!flag) { + if (position == mTopTurn) + TopTurnPosRemoved(position); + if (position == mBottomTurn) + BottomTurnPosRemoved(position); + if (position == mNextStop) + NextStopRemoved(); + } +} + +void T2ElevatorModule::Remove(T2TowerDoc* towerDoc, T2Mover* mover) { + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + T2People *people = NULL; + BOOL flag = true; + T2Request *theRequest; + + switch (mStatus) { + case kElevatorStatus1: + flag = false; + case kElevatorStatus2: + theRequest = mover->GetRequest(theFloorInfo, mPosition, flag); +#line 183 + ASSERT(theRequest != NULL); + people = theRequest->RemoveOffPeople(); + break; + case kElevatorStatus3: + theRequest = GetAppointRequest(theFloorInfo, mover); +#line 189 + ASSERT(theRequest != NULL); + people = theRequest->RemoveOnPeople(); + break; + } + + if (people) { + POINT curPosition = people->GetCurPosition(); + T2Tenant *theFloor = theFloorInfo->GetFloor(curPosition.y, curPosition.x); +#line 199 + ASSERT(theFloor != NULL); + theFloor->Enter(people); + } + + T2MoverModule::RemoveContents(towerDoc); + SetUsed(false); +} + +void T2ElevatorModule::RemoveContents(T2TowerDoc* towerDoc, T2Mover* mover, int position) { + BOOL flag = false; + + if (mLink1) { + POINT stopPt = mover->PositionToStopPt(position, ERequestUpDown_0); + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); +#line 221 + ASSERT(theFloorInfo != NULL); + + T2Tenant *theDstFloor = theFloorInfo->GetFloor(stopPt.y, stopPt.x); +#line 224 + ASSERT(theDstFloor != NULL); + + T2PeopleLinkIterator iterator((T2People *) mLink1); + T2People *people = NULL; + T2People *nextPeople = NULL; + iterator.Next(&people); + while (people) { + iterator.Next(&nextPeople); + + POINT destPos = people->GetCurrDestPos(); + if (destPos.y == stopPt.y) { + Leave(people); + theDstFloor->Enter(people); + people->IncEstimate(-100); + flag = true; + } + + people = nextPeople; + nextPeople = NULL; + } + + if (flag && IsPatChanged(mover)) { + RECT rect; + CalcUintArea(mover, rect); + + T2TowerMainView *theView = towerDoc->GetTowerMainView(); +#line 251 + ASSERT(theView != NULL); + + theView->tmv_vf128(rect); + } + } +} + +BOOL T2ElevatorModule::HomePosRemoved(T2Mover* mover, int position) { + BOOL done = false; + int length = mover->GetLength(); + + for (unsigned int i = position + 1; !done && i < length; i++) { + if (mover->IsStopPosition(i)) { + mHomePosition = i; + done = true; + } + } + + if (!done) { + for (int i = position - 1; !done && i >= 0; i--) { + if (mover->IsStopPosition(i)) { + mHomePosition = i; + done = true; + } + } + } + + return done; +} + +void T2ElevatorModule::TopTurnPosRemoved(int position) { + if (mDirection != kElevatorDirection0 && mTopTurn != mBottomTurn) { + BOOL done = false; + + for (int i = position; !done && i > mBottomTurn; i--) { + if (IsStopPos(i, ERequestUpDown_0) || IsStopPos(i, ERequestUpDown_1)) { + mTopTurn = i; + done = true; + } + } + + if (!done) + mTopTurn = mBottomTurn; + } else { + StartToHomePos(); + } +} + +void T2ElevatorModule::BottomTurnPosRemoved(int position) { + BOOL done = false; + + for (int i = position; !done && i < mTopTurn; i++) { + if (IsStopPos(i, ERequestUpDown_0) || IsStopPos(i, ERequestUpDown_1)) { + mBottomTurn = i; + done = true; + } + } -int T2ElevatorModule::IsPtInArea(POINT, const RECT&) const { + if (!done) + mBottomTurn = mTopTurn; } -/*virtual*/ void T2ElevatorModule::StopAdded(T2TowerDoc*, T2Mover*, int) { +void T2ElevatorModule::NextStopRemoved() { + switch (mStatus) { + case kElevatorStatus1: + case kElevatorStatus2: + case kElevatorStatus3: + case kElevatorStatus4: + mStatus = kElevatorStatus0; + } + + SetNextStop(); + + if (mNextStop != mPosition || mOffsetPos != 0) { + switch (mDirection) { + case kElevatorDirection1: + if (mNextStop <= mPosition) { + mDirection = kElevatorDirection2; + mStatus = kElevatorStatus5; + } + break; + case kElevatorDirection2: + if (mNextStop > mPosition) { + mDirection = kElevatorDirection1; + mStatus = kElevatorStatus5; + } + break; + } + } else { + mStatus = kElevatorStatus0; + } +} + +void T2ElevatorModule::MoverExpanded(T2Mover* mover, EEquipPos pos, int count) { +#line 383 + ASSERT(mStopInfoArray != NULL); + + mStopInfoArray->Expand(pos, count); + + int length = mover->GetLength(); + BOOL flag1 = false; + BOOL flag2 = false; + + switch (pos) { + case EEquipPos_2: + if (count < 0) { + if (mPosition > (length - 1)) { + mOffsetPos = 0; + mPosition = length - 1; + flag1 = true; + } else if (mPosition == (length - 1) && mOffsetPos > 0) { + mOffsetPos = 0; + flag1 = true; + } + + if (mHomePosition > (length - 1)) { + mHomePosition = length - 1; + flag2 = true; + } + } + break; + + case EEquipPos_3: + mPosition += count; + mHomePosition += count; + mNextStop += count; + mTopTurn += count; + mBottomTurn += count; + + if (count < 0) { + if (mPosition < 0) { + mOffsetPos = 0; + mPosition = 0; + flag1 = true; + } + + if (mHomePosition < 0) { + mHomePosition = 0; + flag2 = true; + } + } + break; + } + + if (flag1) { + if (mPosition != mNextStop || mNumPeople == 0) { + mStatus = kElevatorStatus0; + } else { + mWaitCounter = 6; + mStatus = kElevatorStatus1; + } + } + + if (flag2) { + mTopTurn = mBottomTurn = mNextStop = mHomePosition; + StartToHomePos(); + } +} + +BOOL T2ElevatorModule::IsStopPos(int position, ERequestUpDown upDown) const { + BOOL result = false; + if (mStopInfoArray) + result = mStopInfoArray->IsStopPos(position, upDown); + return result; +} + +BOOL T2ElevatorModule::IsOnStopPos(int position, ERequestUpDown upDown) const { + BOOL result = false; + if (mStopInfoArray) + result = mStopInfoArray->IsOnStopPos(position, upDown); + return result; +} + +BOOL T2ElevatorModule::IsOffStopPos(int position, ERequestUpDown upDown) const { + BOOL result = false; + if (mStopInfoArray) + result = mStopInfoArray->IsOffStopPos(position, upDown); + return result; +} + +void T2ElevatorModule::SetOnStop(int position, ERequestUpDown upDown) { + if (mStopInfoArray) { + mStopInfoArray->SetOnStop(position, upDown); + mRequestCount++; + + if (mTopTurn < position) + mTopTurn = position; + if (mBottomTurn > position) + mBottomTurn = position; + + if (mDirection == kElevatorDirection0) { + if (upDown == ERequestUpDown_0) + mDirection = kElevatorDirection1; + else + mDirection = kElevatorDirection2; + } + } +} + +void T2ElevatorModule::SetOffStop(int position, ERequestUpDown upDown) { + if (mStopInfoArray) { + mStopInfoArray->SetOffStop(position, upDown); + + if (mBottomTurn > position) + mBottomTurn = position; + if (mTopTurn < position) + mTopTurn = position; + } +} + +void T2ElevatorModule::ClearOnStop(T2Request* request) { + if (mStopInfoArray) { + mStopInfoArray->ClearOnStop(mPosition, request->GetUpDown()); + mRequestCount--; + request->mModuleIndex = -1; + } +} + +void T2ElevatorModule::ClearOffStop(T2Request* request) { + if (mStopInfoArray) + mStopInfoArray->ClearOffStop(mPosition, request->GetUpDown()); } -/*virtual*/ void T2ElevatorModule::StopRemoved(T2TowerDoc*, T2Mover*, int) { +void T2ElevatorModule::SetNextStop() { + if (mStopInfoArray) { + switch (mDirection) { + case kElevatorDirection1: { + BOOL done = false; + for (int i = mPosition + 1; i < mTopTurn && !done; i++) { + if (IsStopPos(i, ERequestUpDown_0)) { + mNextStop = i; + done = true; + } + } + + if (!done) + mNextStop = mTopTurn; + break; + } + case kElevatorDirection2: { + BOOL done = false; + for (int i = mPosition - 1; i > mBottomTurn && !done; i--) { + if (IsStopPos(i, ERequestUpDown_1)) { + mNextStop = i; + done = true; + } + } + + if (!done) + mNextStop = mBottomTurn; + break; + } + } + } } -void T2ElevatorModule::Remove(T2TowerDoc*, T2Mover*) { +void T2ElevatorModule::ChangeTurnPos() { + if (mStopInfoArray) { + switch (mDirection) { + case kElevatorDirection1: + if (mBottomTurn == mPosition) { + BOOL done = false; + for (int i = mPosition; i < mNextStop && !done; i++) { + if (IsStopPos(i, ERequestUpDown_0) || IsStopPos(i, ERequestUpDown_1)) { + mBottomTurn = i; + done = true; + } + } + + if (!done) + mBottomTurn = mNextStop; + } + break; + + case kElevatorDirection2: + if (mTopTurn == mPosition) { + BOOL done = false; + for (int i = mPosition; i > mNextStop && !done; i--) { + if (IsStopPos(i, ERequestUpDown_0) || IsStopPos(i, ERequestUpDown_1)) { + mTopTurn = i; + done = true; + } + } + + if (!done) + mTopTurn = mNextStop; + } + break; + } + } } -void T2ElevatorModule::RemoveContents(T2TowerDoc*, T2Mover*, int) { -} +void T2ElevatorModule::StartToHomePos() { + if (mPosition == mHomePosition) { + mDirection = kElevatorDirection0; + mStatus = kElevatorStatus0; + } else { + if (mPosition < mHomePosition) + mDirection = kElevatorDirection1; + else + mDirection = kElevatorDirection2; -int T2ElevatorModule::HomePosRemoved(T2Mover*, int) { + mNextStop = mHomePosition; + mTopTurn = mHomePosition; + mBottomTurn = mHomePosition; + mStatus = kElevatorStatus5; + } } -void T2ElevatorModule::TopTurnPosRemoved(int) { -} +T2Request* T2ElevatorModule::GetAppointRequest(T2FloorInfo* floorInfo, T2Mover* mover) { + T2Request *request = NULL; -void T2ElevatorModule::BottomTurnPosRemoved(int) { -} + if (mDirection == kElevatorDirection1) + request = mover->GetRequest(floorInfo, mPosition, 0); + else + request = mover->GetRequest(floorInfo, mPosition, 1); -void T2ElevatorModule::NextStopRemoved() { -} + if (request && request->mModuleIndex != mIndex) + request = NULL; -void T2ElevatorModule::MoverExpanded(T2Mover*, EEquipPos, int) { + return request; } -int T2ElevatorModule::IsStopPos(int, ERequestUpDown) const { -} +T2Request* T2ElevatorModule::GetAnyRequest(T2FloorInfo* floorInfo, T2Mover* mover) { + T2Request *request = NULL; -int T2ElevatorModule::IsOnStopPos(int, ERequestUpDown) const { -} + if (mDirection == kElevatorDirection1) + request = mover->GetRequest(floorInfo, mPosition, 0); + else + request = mover->GetRequest(floorInfo, mPosition, 1); -int T2ElevatorModule::IsOffStopPos(int, ERequestUpDown) const { + return request; } -void T2ElevatorModule::SetOnStop(int, ERequestUpDown) { +void T2ElevatorModule::CalcUintArea(const T2Mover* mover, RECT& outRect) const { + CalcUintArea(mover, mPosition, outRect); + if (mOffsetPos > 0) + outRect.top--; } -void T2ElevatorModule::SetOffStop(int, ERequestUpDown) { -} +void T2ElevatorModule::CalcUintArea(const T2Mover* mover, int position, RECT& outRect) const { + T2MoverModuleList *theList = mover->GetModuleList(); +#line 787 + ASSERT(theList != NULL); -void T2ElevatorModule::ClearOnStop(T2Request*) { + theList->GetBaseRect(outRect); + OffsetRect(&outRect, 0, -position); } -void T2ElevatorModule::ClearOffStop(T2Request*) { -} +BOOL T2ElevatorModule::IsPatChanged(T2Mover* mover) { + BOOL changed = false; -void T2ElevatorModule::SetNextStop() { -} + T2MoverDef *def = (T2MoverDef *) mover->GetEquipDef(); + if (def) { + int newIndex = def->CalcModulePatIndex(mNumPeople); + if (mPatIndex != newIndex) { + mPatIndex = newIndex; + changed = true; + } + } -void T2ElevatorModule::ChangeTurnPos() { -} + if (changed) { + T2MoverModuleMessageData data; + data.moverModule = this; + data.value = GetPosition(); + BroadcastMessage(1001, &data); + } -void T2ElevatorModule::StartToHomePos() { + return changed; } -T2Request* T2ElevatorModule::GetAppointRequest(T2FloorInfo*, T2Mover*) { -} +T2People* T2ElevatorModule::LeaveToDstFloor(int y) { + T2People *result = NULL; -T2Request* T2ElevatorModule::GetAnyRequest(T2FloorInfo*, T2Mover*) { -} + if (mLink1) { + T2PeopleLinkIterator iterator((T2People *) mLink1); + T2People *people; -void T2ElevatorModule::CalcUintArea(const T2Mover*, RECT&) const { -} + while (iterator.Next(&people)) { + if (people->mCurrDestPos.y == y) { + Leave(people); + result = people; + break; + } + } + } -void T2ElevatorModule::CalcUintArea(const T2Mover*, int, RECT&) const { + return result; } -int T2ElevatorModule::IsPatChanged(T2Mover*) { +/*virtual*/ void T2ElevatorModule::Enter(T2Mover* mover, T2People* people) { + people->FlipDirection(); + T2MoverModule::Enter(mover, people); } -T2People* T2ElevatorModule::LeaveToDstFloor(int) { -} +/*virtual*/ void T2ElevatorModule::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + T2MoverModule::LoadSelf(archive, towerDoc); -/*virtual*/ void T2ElevatorModule::Enter(T2Mover*, T2People*) { -} + if (IsUsed()) { + short v; -/*virtual*/ void T2ElevatorModule::LoadSelf(T2Archive&, T2TowerDoc*) { + archive >> v; + mIndex = v; + archive >> v; + mHomePosition = v; + archive >> v; + mOffsetPos = v; + archive >> v; + mNextStop = v; + archive >> v; + mRequestCount = v; + archive >> v; + mTopTurn = v; + archive >> v; + mBottomTurn = v; + + mStopInfoArray = T2StopInfoArray::ReadStopInfoArray(archive); + } } -/*virtual*/ void T2ElevatorModule::SaveSelf(T2Archive&) { +/*virtual*/ void T2ElevatorModule::SaveSelf(T2Archive& archive) { + T2MoverModule::SaveSelf(archive); + + if (IsUsed()) { + archive << (short) mIndex; + archive << (short) mHomePosition; + archive << (short) mOffsetPos; + archive << (short) mNextStop; + archive << (short) mRequestCount; + archive << (short) mTopTurn; + archive << (short) mBottomTurn; + + T2StopInfoArray::WriteStopInfoArray(mStopInfoArray, archive); + } } diff --git a/src/T2DLL/T2ElevatorModule.h b/src/T2DLL/T2ElevatorModule.h index 66438d9..78b737d 100644 --- a/src/T2DLL/T2ElevatorModule.h +++ b/src/T2DLL/T2ElevatorModule.h @@ -1,29 +1,43 @@ #pragma once #include "common.h" +#include "T2MoverModule.h" -class T2ElevatorModule { +enum { + kElevatorStatus0 = 0, + kElevatorStatus1, + kElevatorStatus2, + kElevatorStatus3, + kElevatorStatus4, + kElevatorStatus5, +}; + +enum { + // no direction set + kElevatorDirection0 = 0, + // moving up + kElevatorDirection1, + // moving down + kElevatorDirection2 +}; + +class AFX_EXT_CLASS T2ElevatorModule : public T2MoverModule { public: - T2ElevatorModule(int); + T2ElevatorModule(int index); virtual ~T2ElevatorModule(); - void Init(int, int); - virtual void SetUsed(int); - int IsPtInArea(POINT, const RECT&) const; - virtual void StopAdded(T2TowerDoc*, T2Mover*, int); - virtual void StopRemoved(T2TowerDoc*, T2Mover*, int); + virtual void SetUsed(BOOL used); + virtual void Enter(T2Mover*, T2People*); + virtual void StopAdded(T2TowerDoc*, T2Mover*, int); + virtual void StopRemoved(T2TowerDoc*, T2Mover*, int); + + void Init(int count, int position); + BOOL IsPtInArea(POINT, const RECT&) const; void Remove(T2TowerDoc*, T2Mover*); -protected: - void RemoveContents(T2TowerDoc*, T2Mover*, int); - int HomePosRemoved(T2Mover*, int); - void TopTurnPosRemoved(int); - void BottomTurnPosRemoved(int); - void NextStopRemoved(); -public: void MoverExpanded(T2Mover*, EEquipPos, int); - int IsStopPos(int, ERequestUpDown) const; - int IsOnStopPos(int, ERequestUpDown) const; - int IsOffStopPos(int, ERequestUpDown) const; - void SetOnStop(int, ERequestUpDown); - void SetOffStop(int, ERequestUpDown); + BOOL IsStopPos(int position, ERequestUpDown upDown) const; + BOOL IsOnStopPos(int position, ERequestUpDown upDown) const; + BOOL IsOffStopPos(int position, ERequestUpDown upDown) const; + void SetOnStop(int position, ERequestUpDown upDown); + void SetOffStop(int position, ERequestUpDown upDown); void ClearOnStop(T2Request*); void ClearOffStop(T2Request*); void SetNextStop(); @@ -32,26 +46,41 @@ public: T2Request* GetAppointRequest(T2FloorInfo*, T2Mover*); T2Request* GetAnyRequest(T2FloorInfo*, T2Mover*); void CalcUintArea(const T2Mover*, RECT&) const; + BOOL IsPatChanged(T2Mover*); + T2People* LeaveToDstFloor(int y); + + int GetIndex() const { return mIndex; } + void SetHomePosition(int v) { mHomePosition = v; } + int GetOffsetPos() { return mOffsetPos; } + void SetOffsetPos(int v) { mOffsetPos = v; } + void AddOffsetPos(int v) { mOffsetPos += v; } + int GetNextStop() const { return mNextStop; } + int GetTopTurn() const { return mTopTurn; } + int GetBottomTurn() const { return mBottomTurn; } + int GetHomePosition() const { + int result = -1; + if (mUsed) + result = mHomePosition; + return result; + } + protected: + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); + + void RemoveContents(T2TowerDoc*, T2Mover*, int); + BOOL HomePosRemoved(T2Mover*, int); + void TopTurnPosRemoved(int); + void BottomTurnPosRemoved(int); + void NextStopRemoved(); void CalcUintArea(const T2Mover*, int, RECT&) const; -public: - int IsPatChanged(T2Mover*); - T2People* LeaveToDstFloor(int); - virtual void Enter(T2Mover*, T2People*); -protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); -public: - int GetIndex() const {} - void SetHomePosition(int) {} - int GetOffsetPos() {} - void SetOffsetPos(int) {} - void AddOffsetPos(int) {} - int GetNextStop() const {} - int GetTopTurn() const {} - int GetBottomTurn() const {} - T2ElevatorModule(const T2ElevatorModule&) {} - T2ElevatorModule& operator=(const T2ElevatorModule&) {} - int GetHomePosition() const {} + int mIndex; + int mHomePosition; + int mOffsetPos; + int mNextStop; + int mRequestCount; + int mTopTurn; + int mBottomTurn; + T2StopInfoArray *mStopInfoArray; }; diff --git a/src/T2DLL/T2ElvModuleList.cpp b/src/T2DLL/T2ElvModuleList.cpp index 69a087e..d1f2224 100644 --- a/src/T2DLL/T2ElvModuleList.cpp +++ b/src/T2DLL/T2ElvModuleList.cpp @@ -1,43 +1,169 @@ +#include "T2Archive.h" +#include "T2ElevatorModule.h" #include "T2ElvModuleList.h" +#include "T2MoverDef.h" +#include "T2TowerDoc.h" +#include "UT2Coordinate.h" T2ElvModuleList::T2ElvModuleList() { + SetRect(&mModuleInset, 0, 0, 0, 0); } /*virtual*/ T2ElvModuleList::~T2ElvModuleList() { } -/*virtual*/ int T2ElvModuleList::Init(T2MoverDef*, const RECT&) { +/*virtual*/ BOOL T2ElvModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) { + BOOL success = T2MoverModuleList::Init(moverDef, baseRect); + + if (success) { + moverDef->GetModuleInset(mModuleInset); + for (int i = 0; i < mMaxModule; i++) { + T2ElevatorModule *elevatorModule = new T2ElevatorModule(i); + if (elevatorModule) + success = InsertModuleAt(mItemCount + 1, elevatorModule); + else + success = false; + } + } + + return success; } -void T2ElvModuleList::AddModule(T2TowerDoc*, int, int) { +void T2ElvModuleList::AddModule(T2TowerDoc* towerDoc, int count, int position) { + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule; + + while (iterator.Next(&elevatorModule)) { + if (!elevatorModule->IsUsed()) { + elevatorModule->Init(count, position); + elevatorModule->SetModuleID(towerDoc); + mModuleCount++; + break; + } + } } -/*virtual*/ void T2ElvModuleList::Destruct(T2TowerDoc*) { +/*virtual*/ void T2ElvModuleList::Destruct(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule = NULL; + + while (iterator.Next(&elevatorModule)) { + if (elevatorModule) + RemoveModule(towerDoc, elevatorModule); + } } /*virtual*/ T2MoverModule* T2ElvModuleList::ConstructModule() { + return new T2ElevatorModule(0); } -void T2ElvModuleList::CalcBaseQDRect(RECT&) { +void T2ElvModuleList::CalcBaseQDRect(RECT& outRect) { + UT2Coordinate::UnitToQD(mBaseRect, outRect, 0, true); + UT2Coordinate::AddRect(outRect, mModuleInset); } -int T2ElvModuleList::DestructModule(T2TowerDoc*, T2Mover*, POINT) { +int T2ElvModuleList::DestructModule(T2TowerDoc* towerDoc, T2Mover* mover, POINT inPt) { + int result = -1; + int zoomLevel = towerDoc->towerDoc_vf108(); + + POINT pt = inPt; + RECT baseQDRect; + CalcBaseQDRect(baseQDRect); + + T2ElevatorModule *foundModule = NULL; + LArrayIterator iterator(*this, GetCount() + 1); + T2ElevatorModule *elevatorModule; + + while (!foundModule && iterator.Previous(&elevatorModule)) { + if (elevatorModule->IsPtInArea(pt, baseQDRect)) + foundModule = elevatorModule; + } + + if (foundModule) { + result = foundModule->GetIndex(); + foundModule->Remove(towerDoc, mover); + mModuleCount--; + } + + return result; } -int T2ElvModuleList::IsHomePosition(int) { +BOOL T2ElvModuleList::IsHomePosition(int position) { + BOOL result = false; + + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule = NULL; + + while (iterator.Next(&elevatorModule) && !result) { + if (elevatorModule && elevatorModule->GetHomePosition() == position) + result = true; + } + + return result; } -void T2ElvModuleList::MoverExpanded(T2Mover*, EEquipPos, int) { +void T2ElvModuleList::MoverExpanded(T2Mover* mover, EEquipPos pos, int count) { + if (pos == EEquipPos_3) + OffsetRect(&mBaseRect, 0, count); + + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule; + + while (iterator.Next(&elevatorModule)) { + if (elevatorModule->IsUsed()) + elevatorModule->MoverExpanded(mover, pos, count); + } } -/*virtual*/ void T2ElvModuleList::StopAdded(T2TowerDoc*, T2Mover*, int) { +/*virtual*/ void T2ElvModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover* mover, int position) { + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule; + + while (iterator.Next(&elevatorModule)) { + if (elevatorModule->IsUsed()) + elevatorModule->StopAdded(towerDoc, mover, position); + } } -/*virtual*/ void T2ElvModuleList::StopRemoved(T2TowerDoc*, T2Mover*, int) { +/*virtual*/ void T2ElvModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover* mover, int position) { + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule; + + while (iterator.Next(&elevatorModule)) { + if (elevatorModule->IsUsed()) + elevatorModule->StopRemoved(towerDoc, mover, position); + } } -/*virtual*/ void T2ElvModuleList::Read(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2ElvModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + T2MoverModuleList::Read(archive, towerDoc); + + int count; + archive >> count; + mMaxModule = count; + + BOOL ok = true; + + for (int i = 0; i < count && ok; i++) { + T2ElevatorModule *elevatorModule = new T2ElevatorModule(i); + if (elevatorModule) { + elevatorModule->Load(archive, towerDoc); + ok = InsertModuleAt(mItemCount + 1, elevatorModule); + } + } + + LArrayIterator iterator(*this); + T2ElevatorModule *elevatorModule; + + while (iterator.Next(&elevatorModule)) { + if (elevatorModule->IsUsed()) + mModuleCount++; + } + + archive.ReadSRect(mModuleInset); } -/*virtual*/ void T2ElvModuleList::Write(T2Archive&) { +/*virtual*/ void T2ElvModuleList::Write(T2Archive& archive) { + T2MoverModuleList::Write(archive); + archive.WriteSRect(mModuleInset); } diff --git a/src/T2DLL/T2ElvModuleList.h b/src/T2DLL/T2ElvModuleList.h index 894af22..122b335 100644 --- a/src/T2DLL/T2ElvModuleList.h +++ b/src/T2DLL/T2ElvModuleList.h @@ -1,28 +1,27 @@ #pragma once #include "common.h" +#include "T2MoverModuleList.h" -class T2ElvModuleList { +class AFX_EXT_CLASS T2ElvModuleList : public T2MoverModuleList { public: T2ElvModuleList(); virtual ~T2ElvModuleList(); - virtual int Init(T2MoverDef*, const RECT&); - void AddModule(T2TowerDoc*, int, int); + virtual BOOL Init(T2MoverDef* moverDef, const RECT& baseRect); virtual void Destruct(T2TowerDoc*); virtual T2MoverModule* ConstructModule(); -protected: - void CalcBaseQDRect(RECT&); -public: - int DestructModule(T2TowerDoc*, T2Mover*, POINT); - int IsHomePosition(int); - void MoverExpanded(T2Mover*, EEquipPos, int); - virtual void StopAdded(T2TowerDoc*, T2Mover*, int); - virtual void StopRemoved(T2TowerDoc*, T2Mover*, int); - virtual void Read(T2Archive&, T2TowerDoc*); - virtual void Write(T2Archive&); + virtual void StopAdded(T2TowerDoc*, T2Mover*, int); + virtual void StopRemoved(T2TowerDoc*, T2Mover*, int); + virtual void Read(T2Archive&, T2TowerDoc*); + virtual void Write(T2Archive&); + + void AddModule(T2TowerDoc* towerDoc, int count, int position); + int DestructModule(T2TowerDoc* towerDoc, T2Mover* mover, POINT pt); + BOOL IsHomePosition(int position); + void MoverExpanded(T2Mover*, EEquipPos pos, int count); protected: - virtual unsigned long GetMMClassID() {} -public: - T2ElvModuleList(const T2ElvModuleList&) {} - T2ElvModuleList& operator=(const T2ElvModuleList&) {} + virtual DWORD GetMMClassID() { return 'ElML'; } + void CalcBaseQDRect(RECT&); + + RECT mModuleInset; }; diff --git a/src/T2DLL/T2Equip.cpp b/src/T2DLL/T2Equip.cpp index b6af51b..4d43a2b 100644 --- a/src/T2DLL/T2Equip.cpp +++ b/src/T2DLL/T2Equip.cpp @@ -10,7 +10,7 @@ T2Equip::T2Equip() { mEquipID = 0; SetRect(&mArea, 0, 0, 0, 0); mEquipType = 0; - mDrawMode = 0; + mDrawMode = DrawMode0; mPatIndex = 0; mCapacity = 0; m44 = 0; @@ -37,7 +37,7 @@ int T2Equip::InitEquip(T2EquipDef* def, const RECT& area, unsigned int valiation mValiation = valiation; mArea = area; - mDrawMode = 0; + mDrawMode = DrawMode0; m44 = 0; m48 = 0; mPatIndex = 0; @@ -179,7 +179,7 @@ void T2Equip::ReplaceCEID(unsigned int oldID, unsigned int newID) { return GetEquipDef()->ShowInfoDialog(towerDoc, this); } -/*virtual*/ void T2Equip::PlaySound(T2TowerDoc* towerDoc, int id, unsigned int a, unsigned int b) const { +/*virtual*/ void T2Equip::PlaySound(T2TowerDoc* towerDoc, int id, unsigned int inMask, unsigned int inFlags) const { if (towerDoc->towerDoc_vf15C(mArea)) { T2EquipDef *equipDef = GetEquipDef(); T2SoundPlayer *soundPlayer = towerDoc->towerDoc_vf134(); @@ -190,8 +190,8 @@ void T2Equip::ReplaceCEID(unsigned int oldID, unsigned int newID) { CString name = equipDef->CalcSoundID(id); soundPlayer->Play( name, - a, - b, + inMask, + inFlags, &pt, PlayMode_0, 100 diff --git a/src/T2DLL/T2Equip.h b/src/T2DLL/T2Equip.h index 7e4c914..1ed1c00 100644 --- a/src/T2DLL/T2Equip.h +++ b/src/T2DLL/T2Equip.h @@ -4,7 +4,7 @@ #include "T2HaveOutViewObject.h" #include "T2RouteCEArray.h" -class T2Equip : public T2HaveOutViewObject { +class AFX_EXT_CLASS T2Equip : public T2HaveOutViewObject { public: T2Equip(); virtual ~T2Equip(); @@ -24,7 +24,7 @@ public: mDrawMode = drawMode; } virtual void ClearDrawMode() { - mDrawMode = 0; + mDrawMode = DrawMode0; } virtual void PlaySound(T2TowerDoc*, int, unsigned int, unsigned int) const; @@ -38,8 +38,8 @@ public: unsigned int GetAttribute() const { return mAttribute; } int IsSetAttribute(unsigned int a) const { return (mAttribute & a) != 0; } - int IsMover() const { return IsSetAttribute(2); } - int IsNormalMenteCost() const { return IsSetAttribute(0x100); } + int IsMover() const { return IsSetAttribute(kToolAttrIsMover); } + int IsNormalMenteCost() const { return IsSetAttribute(kToolAttrNormalMenteCost); } unsigned int GetEquipID() const { return mEquipID; } void SetEquipDef(T2EquipDef* equipDef) { SetToolDef(equipDef); @@ -60,12 +60,6 @@ public: int GetPatIndex() const { return mPatIndex; } void SetPatIndex(int i) { mPatIndex = i; } -protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); - - friend class T2EquipDef; - unsigned int mEquipID; RECT mArea; int mEquipType; @@ -76,7 +70,11 @@ protected: int m48; int mBuildDay; unsigned int mAttribute; - T2RouteCEArray *mCEArray; + T2CrossEquipArray *mCEArray; int m58; int mInMoneyIndex; + +protected: + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); }; diff --git a/src/T2DLL/T2EquipDef.cpp b/src/T2DLL/T2EquipDef.cpp index bb694d6..6084b5c 100644 --- a/src/T2DLL/T2EquipDef.cpp +++ b/src/T2DLL/T2EquipDef.cpp @@ -8,7 +8,9 @@ #include "T2InfoDialog.h" #include "T2People.h" #include "T2PeopleLinkIterator.h" +#include "T2Tenant.h" #include "T2TowerDoc.h" +#include "T2WordDefArray.h" #include "T2WorldDef.h" #include "UT2Coordinate.h" @@ -82,7 +84,7 @@ T2EquipDef::T2EquipDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFi delete mWordDefArray; } -/*virtual*/ int T2EquipDef::InitObject(T2Object* object) { +/*virtual*/ BOOL T2EquipDef::InitObject(T2Object* object) { object->SetUsed(true); ((T2Equip *) object)->mEquipType = GetEquipType(); ((T2Equip *) object)->mCapacity = mCapacity; @@ -148,13 +150,14 @@ T2EquipDef::T2EquipDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFi return new T2InfoDialog(equip); } -/*virtual*/ void T2EquipDef::DrawPeople(T2TowerDoc* towerDoc, T2Equip* equip) { - //T2People *people = (T2People *) equip; - //T2PeopleLinkIterator iter(people); - //T2People *i; - //while (iter.Next(&i)) - // i->Draw(towerDoc, people); - // TODO: which subclass is this...? +/*virtual*/ void T2EquipDef::DrawPeople(T2TowerDoc* inDoc, T2Equip* inEquip) { + T2Tenant *theTenant = (T2Tenant *) inEquip; + + T2PeopleLinkIterator iterator(theTenant->mFirstPeople); + T2People *thePeople; + + while (iterator.Next(&thePeople)) + thePeople->Draw(inDoc, inEquip); } int T2EquipDef::GetInMoney(int i) { @@ -164,23 +167,23 @@ int T2EquipDef::GetInMoney(int i) { return cost; } -/*virtual*/ void T2EquipDef::LoadExtraData(T2Archive& archive, T2TowerDoc*, T2HaveOutViewObject*) { - int len; - archive >> len; +/*virtual*/ void T2EquipDef::LoadExtraData(T2Archive& inArchive, T2TowerDoc*, T2HaveOutViewObject*) { + int size; + inArchive >> size; - for (int i = 0; i < len; i++) { + for (int i = 0; i < size; i++) { unsigned char b; - archive >> b; + inArchive >> b; } } -/*virtual*/ void T2EquipDef::SaveExtraData(T2Archive& archive, T2HaveOutViewObject*) { - int len = 0; - archive << len; +/*virtual*/ void T2EquipDef::SaveExtraData(T2Archive& inArchive, T2HaveOutViewObject*) { + int size = 0; + inArchive << size; } T2WordDefArray* T2EquipDef::MakeWordDefArray() { - return 0; // TODO + return new T2WordDefArray(mModuleHandle); } void T2EquipDef::GetWords(T2People*, CString&) const { diff --git a/src/T2DLL/T2EquipDef.h b/src/T2DLL/T2EquipDef.h index de66a3c..aed9a66 100644 --- a/src/T2DLL/T2EquipDef.h +++ b/src/T2DLL/T2EquipDef.h @@ -2,14 +2,14 @@ #include "common.h" #include "T2ToolDef.h" -class T2EquipDef : public T2ToolDef { +class AFX_EXT_CLASS T2EquipDef : public T2ToolDef { public: T2EquipDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2EquipPlugin* plugin); virtual ~T2EquipDef(); - virtual int InitObject(T2Object*); - virtual int IsMover() { return IsSetAttribute(2); } - virtual void LoadExtraData(T2Archive&, T2TowerDoc*, T2HaveOutViewObject*); - virtual void SaveExtraData(T2Archive&, T2HaveOutViewObject*); + virtual BOOL InitObject(T2Object*); + virtual BOOL IsMover() { return IsSetAttribute(kToolAttrIsMover); } + virtual void LoadExtraData(T2Archive& inArchive, T2TowerDoc*, T2HaveOutViewObject*); + virtual void SaveExtraData(T2Archive& inArchive, T2HaveOutViewObject*); virtual AREACHECKCODE AreaCheck(T2TowerDoc*, RECT&, unsigned int, int); virtual int ClickProc(T2TowerDoc*, RECT*, unsigned int&); virtual int GetDestructPartProc(int, POINT, POINT, T2Equip*); @@ -20,7 +20,7 @@ public: virtual int FingerToolProc(T2TowerDoc*, T2Equip*, const POINT&, MOUSEEVENT); virtual void BuildFinish(T2TowerDoc*, T2Equip*); virtual unsigned long OptionProc(T2TowerDoc*, T2Equip*, void*); - virtual void DrawPeople(T2TowerDoc*, T2Equip*); + virtual void DrawPeople(T2TowerDoc* inDoc, T2Equip* inEquip); virtual int GetInfoDialogID(T2TowerDoc*, const T2Equip*) const; virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*, T2Equip*); virtual T2InfoDialog* ConstructInfoDialog(T2Equip*); @@ -35,10 +35,10 @@ public: int GetInMoney(int); void GetWords(T2People*, CString&) const; - int IsSetAttribute(unsigned int a) { + BOOL IsSetAttribute(unsigned int a) { return (mAttribute & a) != 0; } - int IsAbleDragMaking() { return IsSetAttribute(0x80); } + BOOL IsAbleDragMaking() { return IsSetAttribute(kEquipAttrIsAbleDragMaking); } int GetNumOfInMoney() const { return mNumOfInMoney; } int GetEquipType() const { return mToolType; } void CalcEquipRect(RECT& rect) const { @@ -53,6 +53,8 @@ public: protected: T2WordDefArray* MakeWordDefArray(); + friend class T2People; + int mCapacity; int mStress; T2BitImage *m124; diff --git a/src/T2DLL/T2EquipInfoDialog.cpp b/src/T2DLL/T2EquipInfoDialog.cpp index 7fd307a..7476149 100644 --- a/src/T2DLL/T2EquipInfoDialog.cpp +++ b/src/T2DLL/T2EquipInfoDialog.cpp @@ -1,6 +1,12 @@ +#include "T2EquipDef.h" #include "T2EquipInfoDialog.h" -T2EquipInfoDialog::T2EquipInfoDialog(T2Equip*) { +T2EquipInfoDialog::T2EquipInfoDialog(T2Equip* inEquip) + : T2InfoDialog(inEquip) +{ + mEquipDef = GetEquip()->GetEquipDef(); +#line 11 + _ASSERT(mEquipDef != NULL); } /*virtual*/ T2EquipInfoDialog::~T2EquipInfoDialog() { diff --git a/src/T2DLL/T2EquipInfoDialog.h b/src/T2DLL/T2EquipInfoDialog.h index cc6ce0b..751e222 100644 --- a/src/T2DLL/T2EquipInfoDialog.h +++ b/src/T2DLL/T2EquipInfoDialog.h @@ -1,11 +1,16 @@ #pragma once #include "common.h" +#include "T2Equip.h" +#include "T2InfoDialog.h" -class T2EquipInfoDialog { +class AFX_EXT_CLASS T2EquipInfoDialog : public T2InfoDialog { public: - T2EquipInfoDialog(T2Equip*); + T2EquipInfoDialog(T2Equip* inEquip); virtual ~T2EquipInfoDialog(); - T2Equip* GetEquip() const {} - T2EquipDef* GetEquipDef() const {} + T2Equip* GetEquip() const { return (T2Equip *) mObject; } + T2EquipDef* GetEquipDef() const { return mEquipDef; } + +protected: + T2EquipDef *mEquipDef; }; diff --git a/src/T2DLL/T2EquipPlugin.h b/src/T2DLL/T2EquipPlugin.h index 1c60f38..24b13af 100644 --- a/src/T2DLL/T2EquipPlugin.h +++ b/src/T2DLL/T2EquipPlugin.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2ToolPlugin.h" -class T2EquipPlugin : public T2ToolPlugin { +class AFX_EXT_CLASS T2EquipPlugin : public T2ToolPlugin { public: T2EquipPlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~T2EquipPlugin(); diff --git a/src/T2DLL/T2EquipPtrList.cpp b/src/T2DLL/T2EquipPtrList.cpp index 472790a..913bb51 100644 --- a/src/T2DLL/T2EquipPtrList.cpp +++ b/src/T2DLL/T2EquipPtrList.cpp @@ -1,28 +1,67 @@ +#include "T2Equip.h" #include "T2EquipPtrList.h" +#include "T2Tenant.h" -T2EquipPtrList::T2EquipPtrList(unsigned int) { +T2EquipPtrList::T2EquipPtrList(unsigned int attribute) + : LArray(sizeof(T2Equip *)) +{ + mAttribute = attribute; } /*virtual*/ T2EquipPtrList::~T2EquipPtrList() { } -void T2EquipPtrList::AddItem(T2Equip*) { +void T2EquipPtrList::AddItem(T2Equip* equip) { + InsertItemsAt(1, mItemCount + 1, &equip); } -void T2EquipPtrList::RemoveItem(T2Equip*) { +void T2EquipPtrList::RemoveItem(T2Equip* equip) { + Remove(&equip); } -void T2EquipPtrList::RemoveItem(int) { +void T2EquipPtrList::RemoveItem(int index) { + RemoveItemsAt(1, index); } -int T2EquipPtrList::GetIndex(T2Equip*) { +int T2EquipPtrList::GetIndex(T2Equip* equip) { + int index = 0; + if (equip) + index = FetchIndexOf(&equip); + return index; } -int T2EquipPtrList::GetIndex(unsigned int) { +int T2EquipPtrList::GetIndex(unsigned int equipID) { + int result = 0; + LArrayIterator iterator(*this); + BOOL found = false; + int i = 1; + + T2Equip *equip; + + while (!found && iterator.Next(&equip)) { + if (equip->GetEquipID() == equipID) { + result = i; + found = true; + } else { + i++; + } + } + + return result; } -T2Equip* T2EquipPtrList::GetItem(int) { +T2Equip* T2EquipPtrList::GetItem(int index) { + T2Equip *equip = NULL; + FetchItemAt(index, &equip); + return equip; } -void T2EquipPtrList::SetRelatedTenantID(unsigned int) { +void T2EquipPtrList::SetRelatedTenantID(unsigned int id) { + LArrayIterator iterator(*this); + T2Tenant *tenant; + + while (iterator.Next(&tenant)) { + if (!tenant->IsSetRelatedTenantID()) + tenant->SetRelatedTenantID(id); + } } diff --git a/src/T2DLL/T2EquipPtrList.h b/src/T2DLL/T2EquipPtrList.h index 01241b0..2c1edc9 100644 --- a/src/T2DLL/T2EquipPtrList.h +++ b/src/T2DLL/T2EquipPtrList.h @@ -1,20 +1,21 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2EquipPtrList { +class AFX_EXT_CLASS T2EquipPtrList : public LArray { public: - T2EquipPtrList(unsigned int); + T2EquipPtrList(unsigned int attribute = 0); virtual ~T2EquipPtrList(); - void AddItem(T2Equip*); - void RemoveItem(T2Equip*); - void RemoveItem(int); - int GetIndex(T2Equip*); - int GetIndex(unsigned int); - T2Equip* GetItem(int); - void SetRelatedTenantID(unsigned int); + void AddItem(T2Equip* equip); + void RemoveItem(T2Equip* equip); + void RemoveItem(int index); + int GetIndex(T2Equip* equip); + int GetIndex(unsigned int equipID); + T2Equip* GetItem(int index); + void SetRelatedTenantID(unsigned int id); - unsigned int GetAttribute() const {} - T2EquipPtrList(const T2EquipPtrList&) {} - T2EquipPtrList& operator=(const T2EquipPtrList&) {} - void `default constructor closure'() {} + unsigned int GetAttribute() const { return mAttribute; } + +protected: + unsigned int mAttribute; }; diff --git a/src/T2DLL/T2EventDialog.cpp b/src/T2DLL/T2EventDialog.cpp new file mode 100644 index 0000000..e57a608 --- /dev/null +++ b/src/T2DLL/T2EventDialog.cpp @@ -0,0 +1,44 @@ +#include "CTokenizer.h" +#include "T2DlgItemAnimation.h" +#include "T2EventDialog.h" + +/*static*/ T2EventDialog *T2EventDialog::Show(void *a, T2TowerDoc *inDoc, HINSTANCE inModule, int inResID) { + T2EventDialog *theDialog = new T2EventDialog; + + CRect rect; + AfxGetMainWnd()->GetWindowRect(rect); + + T2DLGTEMPLATE tmpl; + tmpl.pt = rect.CenterPoint(); + tmpl.moduleHandle = inModule; + tmpl.resID = inResID; + theDialog->Realize(a, &tmpl, inDoc, NULL, NULL, true, NULL, 0, true); + + return theDialog; +} + +T2EventDialog::T2EventDialog() { +} + +/*virtual*/ void T2EventDialog::CreateDlgItem(CTokenizer& tokenizer, T2DialogDef& def) { + if (!_stricmp(tokenizer.Current(), "ANIM")) { + RECT rect; + UINT id = tokenizer.NextInteger(); + rect.left = tokenizer.NextInteger(); + rect.top = tokenizer.NextInteger(); + rect.right = tokenizer.NextInteger(); + rect.bottom = tokenizer.NextInteger(); + + T2DlgItemAnimation *anim = new T2DlgItemAnimation(mTowerDoc, mImageObj, mPalette); + anim->Create("", def.flags, rect, this, id); + anim->CreateSubItem(NULL); + if (mCurrentFont >= 0) + anim->SetFont(*mFonts[mCurrentFont]); + } else { + T2Dialog::CreateDlgItem(tokenizer, def); + } +} + +/*virtual*/ void T2EventDialog::ListenToMessage(unsigned int msg, void* data) { + DoClose(msg); +} diff --git a/src/T2DLL/T2EventDialog.h b/src/T2DLL/T2EventDialog.h new file mode 100644 index 0000000..886c14d --- /dev/null +++ b/src/T2DLL/T2EventDialog.h @@ -0,0 +1,14 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class T2EventDialog : public T2Dialog { +public: + T2EventDialog(); + virtual void ListenToMessage(unsigned int msg, void* data); + + static T2EventDialog *Show(void *a, T2TowerDoc *inDoc, HINSTANCE inModule, int inResID); + +protected: + virtual void CreateDlgItem(CTokenizer& tokenizer, T2DialogDef& def); +}; diff --git a/src/T2DLL/T2EventItem.cpp b/src/T2DLL/T2EventItem.cpp index 3a83cbb..302752f 100644 --- a/src/T2DLL/T2EventItem.cpp +++ b/src/T2DLL/T2EventItem.cpp @@ -1,79 +1,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*, CResFile*, int) { +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*, int, int, int, int, int, int) { +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*, int) { +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*) { +/*virtual*/ void T2EventItem::Init(T2TowerDoc* inDoc) { } -/*virtual*/ int T2EventItem::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2EventItem::Start(T2TowerDoc* inDoc) { + return true; } -/*virtual*/ int T2EventItem::ReStart(T2TowerDoc*) { +/*virtual*/ int T2EventItem::ReStart(T2TowerDoc* inDoc) { + return 1; } -/*virtual*/ void T2EventItem::StopEvent(T2TowerDoc*) { +/*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; } -int T2EventItem::IsExclusive() { +BOOL T2EventItem::IsExclusive() { + return mExclusive; } int T2EventItem::GetCycleDay() { + return mCycleDay; } int T2EventItem::GetBeginTime() { + return mBeginTime; } -void T2EventItem::SetBeginTime(int) { +void T2EventItem::SetBeginTime(int inTime) { + mBeginTime = inTime; } int T2EventItem::GetEndTime() { + return mEndTime; } -/*virtual*/ int T2EventItem::IsBeginTime(unsigned int) { +/*virtual*/ BOOL T2EventItem::IsBeginTime(unsigned int inTime) { + return (mBeginTime == inTime); } -/*virtual*/ int T2EventItem::IsBeginDay(int) { +/*virtual*/ BOOL T2EventItem::IsBeginDay(int inDay) { + return (inDay % mCycleDay) == 0; } int T2EventItem::GetStatus() { + return mStatus; } -void T2EventItem::SetStatus(int) { +void T2EventItem::SetStatus(int inStatus) { + mStatus = inStatus; } T2EventItem* T2EventItem::GetOriginalDef() { + return mOriginalDef; } -/*virtual*/ unsigned int T2EventItem::DoDialog(T2TowerDoc*, int, int, int, const char*) { +/*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*, CString&, int) { +/*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&) { +/*virtual*/ void T2EventItem::Write(T2Archive& inArchive) { + unsigned int len = 0; + inArchive << len; } -/*virtual*/ void T2EventItem::Read(T2Archive&) { +/*virtual*/ void T2EventItem::Read(T2Archive& inArchive) { + unsigned char tmp; + unsigned int len; + inArchive >> len; + + for (unsigned int i = 0; i < len; i++) + inArchive >> tmp; } diff --git a/src/T2DLL/T2EventItem.h b/src/T2DLL/T2EventItem.h index e166c22..f4db346 100644 --- a/src/T2DLL/T2EventItem.h +++ b/src/T2DLL/T2EventItem.h @@ -1,46 +1,55 @@ #pragma once #include "common.h" -class T2EventItem { +class AFX_EXT_CLASS T2EventItem { public: - T2EventItem(T2TowerEvent*, CResFile*, int); - T2EventItem(T2TowerEvent*, int, int, int, int, int, int); - T2EventItem(T2EventItem*, int); + T2EventItem(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); + T2EventItem(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime); + T2EventItem(T2EventItem* inItem, int inSubID); virtual ~T2EventItem(); - virtual void Init(T2TowerDoc*); - virtual int Start(T2TowerDoc*); - virtual int ReStart(T2TowerDoc*); - virtual void StopEvent(T2TowerDoc*); + virtual void Init(T2TowerDoc* inDoc); + virtual DWORD GetID() { return 0; } + int GetSubID() { return mSubID; } + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int ReStart(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc *inDoc) = 0; + virtual void StopEvent(T2TowerDoc* inDoc); + virtual void ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE) {} + virtual DWORD OptionProc(DWORD, void*) { return 0; } + virtual BOOL IsBeginTime(unsigned int inTime); + virtual BOOL IsBeginDay(int inDay); + virtual void Write(T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); + virtual BOOL IsXEvent() { return false; } + T2WorldDef* GetWorldDef(); T2TowerDoc* GetTowerDoc() const; T2TowerEvent* GetTowerEvent(); int GetLevelBit(); - int IsExclusive(); + BOOL IsExclusive(); int GetCycleDay(); int GetBeginTime(); - void SetBeginTime(int); + void SetBeginTime(int inTime); int GetEndTime(); - virtual int IsBeginTime(unsigned int); - virtual int IsBeginDay(int); int GetStatus(); - void SetStatus(int); + void SetStatus(int inStatus); T2EventItem* GetOriginalDef(); -protected: - virtual unsigned int DoDialog(T2TowerDoc*, int, int, int, const char*); - virtual void DoAlert(T2TowerDoc*, CString&, int); -public: - virtual void Write(T2Archive&); - virtual void Read(T2Archive&); - virtual unsigned long GetID() {} - int GetSubID() {} - virtual void ViewModeChanged(T2TowerDoc*, VIEWMODE) {} - virtual unsigned long OptionProc(unsigned long, void*) {} - virtual int IsXEvent() {} + int _4; + int mSubID; + T2TowerEvent *mTowerEvent; + int mStatus; + int mLevelBit; + BOOL mExclusive; + int mCycleDay; + int mBeginTime; + int mEndTime; + T2EventItem *mOriginalDef; + T2EventDialog *mEventDialog; + protected: - virtual unsigned int DialogHook(T2EventDialog*, unsigned int, T2TowerDoc*) {} + virtual unsigned int DoDialog(T2TowerDoc* inDoc, int inDlgResID, int inAnimResID, int inAnimUnk, const char* inText); + virtual void DoAlert(T2TowerDoc* inDoc, CString& inText, int inSoundID); + virtual UINT DialogHook(T2EventDialog*, unsigned int inResult, T2TowerDoc* inDoc) { return inResult; } virtual void SetupDialog(T2Dialog*) {} -public: - T2EventItem(const T2EventItem&) {} - T2EventItem& operator=(const T2EventItem&) {} }; diff --git a/src/T2DLL/T2FInfoAreaIterator.cpp b/src/T2DLL/T2FInfoAreaIterator.cpp index c7452ab..5d81af0 100644 --- a/src/T2DLL/T2FInfoAreaIterator.cpp +++ b/src/T2DLL/T2FInfoAreaIterator.cpp @@ -1,64 +1,313 @@ +#include "GlobalFunc.h" #include "T2FInfoAreaIterator.h" +#include "T2FloorInfo.h" +#include "T2MoverArrayList.h" +#include "T2RequestArrayList.h" +#include "T2TenantArrayList.h" +#include "T2UnitInfo.h" -T2FInfoAreaIterator::T2FInfoAreaIterator(const T2FloorInfo&, const RECT&) { +T2FInfoAreaIterator::T2FInfoAreaIterator(const T2FloorInfo& inFloorInfo, const RECT& inRect) + : mFloorInfo(inFloorInfo) +{ + mRect = mFloorInfo.mBuildArea; + InsetRect(&mRect, -1, 0); + + if (mRect.left < 0) + mRect.left = 0; + if (mRect.right > inFloorInfo.mHRange) + mRect.right = inFloorInfo.mHRange; + + IntersectRect(&mRect, &inRect, &mRect); + + mSkipAmount = mFloorInfo.mHRange - (mRect.right - mRect.left) + 1; + Reset(); } /*virtual*/ T2FInfoAreaIterator::~T2FInfoAreaIterator() { } void T2FInfoAreaIterator::Reset() { + mCurrV = mRect.top; + + if (!IsRectEmpty(&mRect)) { + mCurrH = -1; + mCurrUnitInfo = mFloorInfo.GetUnitInfo(mCurrV, mRect.left); +#line 68 + _ASSERT(mCurrUnitInfo != NULL); + } else { + mCurrH = -2; + } + + mLastIDSeen = 0; } -int T2FInfoAreaIterator::CalcNextUnitInfo() { +BOOL T2FInfoAreaIterator::CalcNextUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + mCurrH++; + if (mCurrH < mRect.right) { + mCurrUnitInfo++; + } else { + mCurrH = mRect.left; + mCurrV++; + if (mCurrV < mRect.bottom) { + mCurrUnitInfo += mSkipAmount; + } else { + mCurrH = -2; + result = false; + } + } + } else { + mCurrH = mRect.left; + } + } else { + result = false; + } + + return result; } -int T2FInfoAreaIterator::CurrentV(int&) const { +BOOL T2FInfoAreaIterator::CurrentV(int& outV) const { + BOOL result = true; + + if (IsValidPosition()) + outV = mCurrV; + else + result = false; + + return result; } -int T2FInfoAreaIterator::Current(T2UnitInfo*&) { +BOOL T2FInfoAreaIterator::Current(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (IsValidPosition()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoAreaIterator::Next(T2UnitInfo*&) { +BOOL T2FInfoAreaIterator::Next(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcNextUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoAreaIterator::NextTenant(T2Tenant*&) { +BOOL T2FInfoAreaIterator::NextTenant(T2Tenant*& outTenant) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Next(unitInfo); result; result = Next(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return result; } -void T2FInfoAreaIterator::GetTenantRect(RECT&) { +void T2FInfoAreaIterator::GetTenantRect(RECT& outRect) { + outRect.left = mCurrH; + outRect.right = outRect.left; + + if (IsValidPosition()) { + outRect.right++; + T2UnitInfo *unitInfo = mCurrUnitInfo + 1; + while (unitInfo->GetTenantID() == mLastIDSeen) { + outRect.right++; + unitInfo++; + } + } } -int T2FInfoAreaIterator::NextRequest(T2Request*&) { +BOOL T2FInfoAreaIterator::NextRequest(T2Request*& outRequest) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Next(unitInfo); result; result = Next(unitInfo)) { + unsigned int requestID = unitInfo->GetRequestID(); + if (requestID != mLastIDSeen) { + mLastIDSeen = requestID; + if (requestID != 0) { + outRequest = mFloorInfo.mRequestArrayList->GetRequestByID(requestID); + break; + } + } + } + + return result; } -int T2FInfoAreaIterator::NextMover(T2Mover*&) { +BOOL T2FInfoAreaIterator::NextMover(T2Mover*& outMover) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Next(unitInfo); result; result = Next(unitInfo)) { + unsigned int moverID = unitInfo->GetMoverID(); + if (moverID != mLastIDSeen) { + mLastIDSeen = moverID; + if (moverID != 0) { + outMover = mFloorInfo.mMoverArrayList->GetMoverByID(moverID); + break; + } + } + } + + return result; } -T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo&, POINT) { + + +T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo& inFloorInfo, POINT inPt) + : mFloorInfo(inFloorInfo) + , mLeftBound(mFloorInfo.mBuildArea.left) + , mRightBound(mFloorInfo.mBuildArea.right - 1) +{ + if (PtInRect(&mFloorInfo.mBuildArea, inPt)) { + mCurrH = inPt.x; + mCurrUnitInfo = mFloorInfo.GetUnitInfo(inPt.y, mCurrH); + mLastIDSeen = 0; + } else { + mCurrH = -2; + } } /*virtual*/ T2FInfoPtIterator::~T2FInfoPtIterator() { } -int T2FInfoPtIterator::CurrentH(int&) const { +BOOL T2FInfoPtIterator::CurrentH(int& outH) const { + BOOL result = true; + + if (IsValidPosition()) + outH = mCurrH; + else + result = false; + + return result; } -int T2FInfoPtIterator::CalcRightUnitInfo() { +BOOL T2FInfoPtIterator::CalcRightUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + if (mCurrH < mRightBound) { + mCurrH++; + mCurrUnitInfo++; + } else { + mCurrH = -2; + result = false; + } + } else { + mCurrH = mLeftBound; + } + } else { + result = false; + } + + return result; } -int T2FInfoPtIterator::CalcLeftUnitInfo() { +BOOL T2FInfoPtIterator::CalcLeftUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + if (mCurrH > mLeftBound) { + mCurrH--; + mCurrUnitInfo--; + } else { + result = false; + } + } else { + mCurrH = mRightBound; + } + } else { + result = false; + } + + return result; } -int T2FInfoPtIterator::Current(T2UnitInfo*&) { +BOOL T2FInfoPtIterator::Current(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (IsValidPosition()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoPtIterator::Right(T2UnitInfo*&) { +BOOL T2FInfoPtIterator::Right(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcRightUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoPtIterator::Left(T2UnitInfo*&) { +BOOL T2FInfoPtIterator::Left(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcLeftUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; } -int T2FInfoPtIterator::RightTenant(T2Tenant*&) { +BOOL T2FInfoPtIterator::RightTenant(T2Tenant*& outTenant) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Right(unitInfo); result; result = Right(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return result; } -int T2FInfoPtIterator::LeftTenant(T2Tenant*&) { +BOOL T2FInfoPtIterator::LeftTenant(T2Tenant*& outTenant) { + BOOL result; + T2UnitInfo *unitInfo; + + for (result = Left(unitInfo); result; result = Left(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return result; } diff --git a/src/T2DLL/T2FInfoAreaIterator.h b/src/T2DLL/T2FInfoAreaIterator.h index 59ab38e..fcd389a 100644 --- a/src/T2DLL/T2FInfoAreaIterator.h +++ b/src/T2DLL/T2FInfoAreaIterator.h @@ -1,42 +1,58 @@ #pragma once #include "common.h" -class T2FInfoAreaIterator { +class AFX_EXT_CLASS T2FInfoAreaIterator { public: - T2FInfoAreaIterator(const T2FloorInfo&, const RECT&); + T2FInfoAreaIterator(const T2FloorInfo& inFloorInfo, const RECT&); virtual ~T2FInfoAreaIterator(); + void Reset(); + BOOL CurrentV(int& outV) const; + BOOL Current(T2UnitInfo*& outUnitInfo); + BOOL Next(T2UnitInfo*& outUnitInfo); + BOOL NextTenant(T2Tenant*& outTenant); + void GetTenantRect(RECT& outRect); + BOOL NextRequest(T2Request*& outRequest); + BOOL NextMover(T2Mover*& outMover); + protected: - int CalcNextUnitInfo(); -public: - int CurrentV(int&) const; - int Current(T2UnitInfo*&); - int Next(T2UnitInfo*&); - int NextTenant(T2Tenant*&); - void GetTenantRect(RECT&); - int NextRequest(T2Request*&); - int NextMover(T2Mover*&); - - T2FInfoAreaIterator(const T2FInfoAreaIterator&) {} -protected: - int IsValidPosition() const {} + BOOL CalcNextUnitInfo(); + BOOL IsValidPosition() const { + return (mCurrH > -1); + } + + const T2FloorInfo &mFloorInfo; + RECT mRect; + int mSkipAmount; + int mCurrV; + int mCurrH; + T2UnitInfo *mCurrUnitInfo; + unsigned int mLastIDSeen; }; -class T2FInfoPtIterator { + +class AFX_EXT_CLASS T2FInfoPtIterator { public: - T2FInfoPtIterator(const T2FloorInfo&, POINT); + T2FInfoPtIterator(const T2FloorInfo& inFloorInfo, POINT inPt); virtual ~T2FInfoPtIterator(); - int CurrentH(int&) const; -protected: - int CalcRightUnitInfo(); - int CalcLeftUnitInfo(); -public: - int Current(T2UnitInfo*&); - int Right(T2UnitInfo*&); - int Left(T2UnitInfo*&); - int RightTenant(T2Tenant*&); - int LeftTenant(T2Tenant*&); - T2FInfoPtIterator(const T2FInfoPtIterator&) {} + BOOL CurrentH(int& outH) const; + BOOL Current(T2UnitInfo*& outUnitInfo); + BOOL Right(T2UnitInfo*& outUnitInfo); + BOOL Left(T2UnitInfo*& outUnitInfo); + BOOL RightTenant(T2Tenant*& outTenant); + BOOL LeftTenant(T2Tenant*& outTenant); + protected: - int IsValidPosition() const {} + BOOL CalcRightUnitInfo(); + BOOL CalcLeftUnitInfo(); + BOOL IsValidPosition() const { + return (mCurrH > -1); + } + + const T2FloorInfo &mFloorInfo; + int mLeftBound; + int mRightBound; + int mCurrH; + T2UnitInfo *mCurrUnitInfo; + unsigned int mLastIDSeen; }; diff --git a/src/T2DLL/T2FireBurning.cpp b/src/T2DLL/T2FireBurning.cpp index b07e3c9..b8cc60d 100644 --- a/src/T2DLL/T2FireBurning.cpp +++ b/src/T2DLL/T2FireBurning.cpp @@ -1,82 +1,820 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2CtrlPalette.h" +#include "T2DateTime.h" +#include "T2Dialog.h" +#include "T2DlgItem.h" +#include "T2EquipPtrList.h" #include "T2FireBurning.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2MainWindow.h" +#include "T2People.h" +#include "T2PeoplePtrList.h" +#include "T2RegistedTenantDB.h" +#include "T2Settlement.h" +#include "T2SoundPlayer.h" +#include "T2Sprite.h" +#include "T2Tenant.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2TowerMessage.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" +#include "UT2Utils.h" -T2FireBurning::T2FireBurning(T2TowerEvent*, CResFile*, int) { +T2FireBurning::T2FireBurning(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + mFightAction = kFireFightNull; + mFireArray = NULL; + mHelicopter = NULL; + mAttach = NULL; + mImage = NULL; + mImageObj = NULL; + + *inResFile >> mHelicopterPrice; + *inResFile >> m40; + if (inResFile->IsBinaryMode()) { + int tmp; + for (int i = 0; i < m40; i++) + *inResFile >> tmp; + } + + mPeopleList = new T2PeoplePtrList; } /*virtual*/ T2FireBurning::~T2FireBurning() { + if (mStatus == kFireBurningStatus1) + StopEvent(mTowerEvent->mDocument); + delete mPeopleList; } -/*virtual*/ int T2FireBurning::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2FireBurning::Start(T2TowerDoc* inDoc) { + BOOL started = false; + + CPoint pt; + T2Tenant *theTenant; + if (IsBreakoutFire(inDoc, pt, theTenant)) { + mStatus = kFireBurningStatus1; + StartEvent(inDoc, pt, theTenant); + inDoc->towerDoc_vf2B0(true); + + switch (mFightAction) { + case kFireFightHelicopter: + { + CString text = LoadStringTable(GetWorldModuleHandle(), 8100, 1); + DoAlert(inDoc, text, 0); + inDoc->towerDoc_vf270(mHelicopterPrice, kFundGroup2); + inDoc->towerDoc_vf2A8(25); + Sounds->Play("FIREBURNING:HELI", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_3, 100); + break; + } + case kFireFightFireman: + inDoc->towerDoc_vf2A8(25); + break; + } + + mTimePassed = 0; + started = true; + } + + return started; } -/*virtual*/ int T2FireBurning::Exec(T2TowerDoc*) { +/*virtual*/ int T2FireBurning::Exec(T2TowerDoc* inDoc) { + CString str; + + switch (mStatus) { + case kFireBurningStatus1: + if (mFightAction != kFireFightNull) { + if (mHelicopter) + mHelicopter->Move(inDoc); + mTimePassed++; + IdleEvent(inDoc); + + T2DateTime *theNow = inDoc->towerDoc_vf120(); + if (!mFireArray || mFireArray->GetCount() == 0 || theNow->GetRawMinutes() == mEndTime) + mStatus = kFireBurningStatus2; + } + + return IsExclusive() ? 1 : 0; + + case kFireBurningStatus2: + StopEvent(inDoc); + str = LoadStringTable(GetWorldModuleHandle(), 8100, 2); + DoAlert(inDoc, str, 0); + return 3; + } + + return 0; } -/*virtual*/ void T2FireBurning::StartEvent(T2TowerDoc*, POINT, const T2Tenant*) { +/*virtual*/ void T2FireBurning::StartEvent(T2TowerDoc* inDoc, POINT inPt, const T2Tenant* inTenant) { + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + mFightAction = kFireFightNull; + mFireArray = new LArray; + + inDoc->towerDoc_vf144(ViewMode_0); + inDoc->towerDoc_vf2A8(25); + inDoc->SetFireBurning(true); + inDoc->towerDoc_vf1A0(true); + inDoc->towerDoc_vf2A0()->EnableIcon(false); + inDoc->GetTowerMainView()->tmv_vf154(); + inDoc->towerDoc_vf1B4(); + + Sounds->FadeOut(); + Sounds->AddSound("FIREBURNING:", SoundPriority_1, 8100, GetWorldModuleHandle()); + Sounds->AddSound("FIREBURNING:HELI", SoundPriority_1, 8101, GetWorldModuleHandle()); + Sounds->AddSound("FIREBURNING:FIRE", SoundPriority_1, 8102, GetWorldModuleHandle()); + Sounds->Play("FIREBURNING:", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); + + CString dialogText; + dialogText.Format("%d", inDoc->towerDoc_vf12C()->UnitToFloor(inPt.y)); + dialogText += LoadStringTable(GetWorldModuleHandle(), 8100, 3); + DoDialog(inDoc, 8100, 5100, 3, dialogText); + + if (!mImage) + mImage = new T2BitImage(inDoc->mWorldDef->mModuleHandle, 5000, true); + + if (!mImageObj) { + mImageObj = new T2ImageObj; + mImageObj->AddObject(inDoc->mWorldDef->mModuleHandle, 5000, mImage); + + SIZE size; + mImageObj->GetObjectSize(mImageObj->FindObject("FIRE", 0), &size); + mFireWidth = size.cx / 8; + } + + MakeFire(inPt, inDoc); + + T2TowerMainView *theTowerMainView = inDoc->GetTowerMainView(); + + CRect area; + inTenant->GetEquipArea(area); + theTowerMainView->tmv_vf15C(area); + + ((T2MainWindow *) AfxGetMainWnd())->mCtrlPalette->vf108(0); + + Sounds->Play("FIREBURNING:FIRE", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_3, 100); + + dialogText = LoadStringTable(GetWorldModuleHandle(), 8100, 4); + switch (DoDialog(inDoc, 8110, 5101, 1, dialogText)) { + case 8114: + mHelicopter = new T2Helicopter(inDoc, inTenant); + mFightAction = kFireFightHelicopter; + break; + case 8115: + CallFireman(inDoc, inTenant); + mFightAction = kFireFightFireman; + break; + case 8116: + mFightAction = kFireFightDoNothing; + break; + } + + mAttach = new T2FireAttach(this, 0, true); + theTowerMainView->AddAttachment(mAttach, NULL, true); + + if (mFightAction == kFireFightHelicopter) + theTowerMainView->SetTimer(100, 55, NULL); } -/*virtual*/ void T2FireBurning::SetupDialog(T2Dialog*) { +/*virtual*/ void T2FireBurning::SetupDialog(T2Dialog* inDialog) { + if (inDialog->mTemplate.resID == 8100) + return; + + ((T2DlgItem *) inDialog->GetDlgItem(8114))->AddListener(inDialog); + ((T2DlgItem *) inDialog->GetDlgItem(8115))->AddListener(inDialog); + ((T2DlgItem *) inDialog->GetDlgItem(8116))->AddListener(inDialog); } -/*virtual*/ unsigned int T2FireBurning::DialogHook(T2EventDialog*, unsigned int, T2TowerDoc*) { +/*virtual*/ unsigned int T2FireBurning::DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc) { + CString theString; + T2TowerMessage *theTowerMsg = inDoc->mTowerMessage; + T2FloorInfo *theFloorInfo; + T2Tenant *theTenant; + + switch (inResult) { + case 8114: + if (inDoc->towerDoc_vf26C() < mHelicopterPrice) { + theString = LoadStringTable(GetWorldModuleHandle(), 8100, 5); + DoAlert(inDoc, theString, 9000); + inResult = 0; + } + break; + + case 8115: + theFloorInfo = inDoc->towerDoc_vf12C(); + theTenant = theFloorInfo ? theFloorInfo->GetTenantByPID('KEBI') : NULL; + if (!theTenant) { + theString = LoadStringTable(GetWorldModuleHandle(), 8100, 6); + DoAlert(inDoc, theString, 9000); + inResult = 0; + } + break; + } + + return inResult; } -/*virtual*/ void T2FireBurning::IdleEvent(T2TowerDoc*) { +/*virtual*/ void T2FireBurning::IdleEvent(T2TowerDoc* inDoc) { + if (mFireArray) { + if (mFightAction == kFireFightFireman) { + T2Fire *fire = NULL; + if (mFireArray->GetCount() > 0) + mFireArray->FetchItemAt(mFireArray->GetCount(), &fire); + + LArrayIterator iterator(*mPeopleList); + T2People *people; + + while (iterator.Next(&people)) { + if (people->GetStatus() == kStatus15) { + if (fire) { + people->SetDestination(fire->GetArsonTenant()->GetEquipID()); + people->ChangeStyle(kPeopleStyle2); + people->ChangeStatus(kStatus3); + } else { + people->ChangeStyle(kPeopleStyle1); + } + } + } + } + + T2Fire *theFire; + int index = 1; + while (mFireArray->FetchItemAt(index, &theFire)) { + BOOL flag = false; + if ((mTimePassed % 1) == 0) + flag = theFire->Move(); + + if (!flag && mFightAction == kFireFightFireman && theFire->ExtinguishByFireman(inDoc, mPeopleList)) { + flag = true; + Extinguish(theFire); + } + + if (!flag) + index++; + } + } } -/*virtual*/ void T2FireBurning::StopEvent(T2TowerDoc*) { +/*virtual*/ void T2FireBurning::StopEvent(T2TowerDoc* inDoc) { + T2TowerMainView *theView = inDoc->GetTowerMainView(); + theView->KillTimer(100); + + if (mFireArray) { + LArrayIterator iterator(*mFireArray); + T2Fire *theFire; + + while (iterator.Next(&theFire)) + delete theFire; + + delete mFireArray; + mFireArray = NULL; + + delete mImageObj; + mImageObj = NULL; + + delete mImage; + mImage = NULL; + } + + if (mHelicopter) { + delete mHelicopter; + mHelicopter = NULL; + } + + if (theView && mAttach) { + theView->RemoveAttachment(mAttach); + delete mAttach; + mAttach = NULL; + + theView->tmv_vf124(true); + theView->tmv_vf120(); + } + + mStatus = kFireBurningStatus0; + mFightAction = kFireFightNull; + + LArrayIterator iterator(*mPeopleList); + T2People *theFireman; + + while (iterator.Next(&theFireman)) { + theFireman->ChangeStyle(kPeopleStyle1); + theFireman->SetReturnToDestination(); + theFireman->SetStatus(kStatus3); + theFireman->ClearSpecialFlag(kSpecialFlag20 | kSpecialFlag40); + theFireman->ClearColor(); + } + + mPeopleList->RemoveItemsAt(mPeopleList->GetCount(), 1); + + inDoc->towerDoc_vf2B0(false); + + Sounds->Stop("FIREBURNING:"); + Sounds->Stop("FIREBURNING:HELI"); + Sounds->Stop("FIREBURNING:FIRE"); + Sounds->DeleteSound("FIREBURNING:"); + Sounds->DeleteSound("FIREBURNING:HELI"); + Sounds->DeleteSound("FIREBURNING:FIRE"); + Sounds->FadeIn(); + + inDoc->towerDoc_vf1A0(false); + inDoc->SetFireBurning(false); + + if (inDoc->GetTowerMainView()) + inDoc->GetTowerMainView()->tmv_vf150(); + if (inDoc->towerDoc_vf2A0()) + inDoc->towerDoc_vf2A0()->EnableIcon(true); } -int T2FireBurning::MakeFire(POINT, T2TowerDoc*) { +BOOL T2FireBurning::MakeFire(POINT inPt, T2TowerDoc* inDoc) { + BOOL createdFire = false; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2Tenant *theTenant = theFloorInfo->GetTenant(inPt.y, inPt.x); + + if (theTenant && !theTenant->IsFire() && !theTenant->IsFireproof()) { + CRect rect; + if (AdjustFirePos(theFloorInfo, inPt, rect)) { + for (unsigned int i = 0; i < 2; i++) { + T2Fire *theFire = new T2Fire(rect.TopLeft(), inDoc, i ? -1 : 1, mImageObj); + mFireArray->Add(&theFire); + } + + for (int h = rect.left; h < rect.right; h++) { + T2Tenant *tenant = theFloorInfo->GetTenant(rect.top, h); + if (tenant && !tenant->IsFireproof() && !tenant->IsFire()) + tenant->BurntDown(inDoc); + } + + createdFire = true; + } + } + + return createdFire; } -int T2FireBurning::AdjustFirePos(T2FloorInfo*, POINT&, RECT&) const { +BOOL T2FireBurning::AdjustFirePos(T2FloorInfo* inFloorInfo, POINT& inPt, RECT& outRect) const { + BOOL success = false; + + int distance = mFireWidth / 2; + SetRect(&outRect, inPt.x - distance, inPt.y, inPt.x + distance, inPt.y + 1); + + int dir = 0; + for (unsigned int i = 0; i <= distance; i++) { + if (inFloorInfo->GetTenant(outRect.top, outRect.left)) { + if (inFloorInfo->GetTenant(outRect.top, outRect.right - 1)) { + if (inFloorInfo->IsAllTenant(outRect)) { + success = true; + break; + } + break; + } + + if (dir <= 0) { + dir = -1; + OffsetRect(&outRect, dir, 0); + } else { + break; + } + } else if (inFloorInfo->GetTenant(outRect.top, outRect.right - 1)) { + if (dir >= 0) { + dir = 1; + OffsetRect(&outRect, dir, 0); + } else { + break; + } + } + } + + return success; } -void T2FireBurning::Extinguish(T2Fire*) { +void T2FireBurning::Extinguish(T2Fire* inFire) { + mFireArray->Remove(&inFire); + + T2People *theFireman = inFire->GetFireman(); + if (theFireman) { + theFireman->ChangeStyle(kPeopleStyle1); + theFireman->ChangeStatus(kStatus15); + mPeopleList->InsertItemsAt(1, 1, &theFireman); + } + + delete inFire; } -int T2FireBurning::DoExtinguish(CPoint&) { +BOOL T2FireBurning::DoExtinguish(CPoint& inPt) { + LArrayIterator iterator(*mFireArray); + CRect rect; + T2Fire *theFire; + + while (iterator.Next(&theFire)) { + if (theFire->HitTest(inPt, rect)) { + Extinguish(theFire); + return true; + } + } + + return false; } -void T2FireBurning::CallFireman(T2TowerDoc*, const T2Tenant*) { +void T2FireBurning::CallFireman(T2TowerDoc* inDoc, const T2Tenant* inTenant) { + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + T2EquipPtrList *theList = theDB->GetList(kTenantRegistID5); + + if (theList) { + LArrayIterator iterator(*theList); + unsigned int numFiremen = 0; + unsigned int nowMinutes = inDoc->towerDoc_vf120()->GetRawMinutes(); + T2Tenant *theFireStation; + + while (numFiremen < 6 && iterator.Next(&theFireStation)) { + while (numFiremen < 6 && theFireStation->GetFirstPeople()) { + T2People *thePeople = theFireStation->GetFirstPeople(); + thePeople->ChangeStyle(kPeopleStyle2); + thePeople->SetSpecialFlag(kSpecialFlag20 | kSpecialFlag40); + thePeople->SetReturn(theFireStation->GetEquipID()); + thePeople->SetDestination(inTenant->GetEquipID()); + thePeople->mColor = 11; + theFireStation->PushOutPeople(inDoc, thePeople); + mPeopleList->InsertItemsAt(1, 1, &thePeople); + numFiremen++; + } + } + } } -int T2FireBurning::IsBreakoutFire(const T2TowerDoc*, POINT&, T2Tenant*&) const { +BOOL T2FireBurning::IsBreakoutFire(const T2TowerDoc* inDoc, POINT& outPt, T2Tenant*& outTenant) const { + BOOL done = false; + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + + unsigned int curAttempt = 0; + unsigned int numAttempt = _4 ? 100000 : 100; + + while (!done && curAttempt < numAttempt) { + curAttempt++; + + POINT pt; + pt.x = UT2Utils::Randomize(theFloorInfo->GetHRange()); + pt.y = UT2Utils::Randomize(theFloorInfo->GetGroundLine() - 2); + T2Tenant *theTn = theFloorInfo->GetTenant(pt.y, pt.x); + + if (theTn && !theTn->IsFire() && !theTn->IsFireproof()) { + RECT rect; + rect.left = pt.x - (mFireWidth / 2 + 1); + rect.top = pt.y; + rect.right = pt.x + (mFireWidth / 2 + 1); + rect.bottom = pt.y + 1; + + if (theFloorInfo->IsAllTenant(rect)) { + outPt = pt; + outTenant = theTn; + done = true; + } + } + } + + return done; } -T2Fire::T2Fire(POINT&, T2TowerDoc*, int, T2ImageObj*) { + + +T2Fire::T2Fire(POINT& inPt, T2TowerDoc* inDoc, int inVar, T2ImageObj* inImageObj) { + CRect junkRect; + CRect theRect; + + inImageObj->GetObjectImage(inImageObj->FindObject("FIRE", 0), theRect); + theRect.OffsetRect(-theRect.left, -theRect.top); + + x0 = 0; + x4 = 0; + mDocument = inDoc; + xC = inVar; + x18 = (theRect.right - theRect.left) / 2; + x1C = (theRect.right - theRect.left) / 8; + + mSprite = &mDocument->mSprite; + mArsonTenant = NULL; + mFireman = NULL; + + for (unsigned int h = 0; h < x1C; h++) { + T2Tenant *theTenant = inDoc->towerDoc_vf12C()->GetTenant(inPt.y, inPt.x + h); + if (theTenant && !theTenant->IsFireproof() && !theTenant->IsFire()) { + if (xC > 0) { + if (mArsonTenant != theTenant) + mArsonTenant = theTenant; + } else { + if (mArsonTenant == NULL) + mArsonTenant = theTenant; + } + } + } + + if (mSprite) { + mFireSpriteID = mSprite->NewSprite(*inImageObj, "FIRE", T2Sprite::ELayer_4); + + POINT spritePt = inPt; + UT2Coordinate::UnitToQD(spritePt, 0, true); + mSprite->MoveSprite(mFireSpriteID, spritePt); + mSprite->ShowSprite(mFireSpriteID, true); + } } T2Fire::~T2Fire() { + if (mSprite) { + mSprite->ShowSprite(mFireSpriteID, false); + mSprite->DeleteSprite(mFireSpriteID); + } } -void T2Fire::SetFireman(T2People*) { +void T2Fire::SetFireman(T2People* inPeople) { + mFireman = inPeople; + mFireman->SetDestination(mArsonTenant->GetEquipID()); + mFireman->ChangeStyle(kPeopleStyle2); + mFireman->ChangeStatus(kStatus3); } -int T2Fire::Move() { +BOOL T2Fire::Move() { + BOOL done = false; + + mSprite->ChangePattern(mFireSpriteID, x0 % 4); + + CRect rect; + mSprite->GetSpriteRect(mFireSpriteID, rect); + + CPoint p = rect.TopLeft(); + + if (x4 == 0) { + p.x = (xC > 0) ? (rect.right + 1) : (rect.left - 1); + UT2Coordinate::QDToUnit(p, 0); + + T2Tenant *theTenant = mDocument->towerDoc_vf12C()->GetTenant(p.y, p.x); + if (theTenant && !theTenant->IsFireproof() && (!theTenant->IsFire() || mArsonTenant == theTenant)) { + p.y = rect.top; + p.x = rect.left + xC; + mSprite->MoveSprite(mFireSpriteID, p); + theTenant->SetStatus(kTenantStatus10000); + mArsonTenant = theTenant; + } else { + x4 = 1; + } + } else { + x4++; + T2TowerMainView *theView = mDocument->GetTowerMainView(); + if (theView) { + CRect unitRect = rect; + UT2Coordinate::QDToUnit(unitRect.TopLeft(), 0); + UT2Coordinate::QDToUnit(unitRect.BottomRight(), 0); + unitRect.right++; + theView->tmv_vf128(unitRect, true); + } + } + + if (x18 != 0) { + x0++; + if ((x0 % x18) == 0) { + T2FireBurning *theFireBurning = mDocument->mWorldDef->GetFireBurning(); + + p.y = rect.top; + p.x = rect.left + x18; + p.x = (xC > 0) ? rect.left : rect.right; + UT2Coordinate::QDToUnit(p, 0); + p.y--; + + for (unsigned int i = 0; i < x1C; i++) { + if (theFireBurning->MakeFire(p, mDocument)) + break; + if (x4 == 0) + break; + + p.x += xC; + } + + if (x4 > x18) { + theFireBurning->Extinguish(this); + done = true; + } + } + } + + return done; } -int T2Fire::HitTest(CPoint&, CRect&) { +BOOL T2Fire::HitTest(CPoint& inPt, CRect& outRect) { + CRect rect; + mSprite->GetSpriteRect(mFireSpriteID, rect); + + BOOL success = rect.PtInRect(inPt); + if (success) + outRect = rect; + + return success; } -int T2Fire::ExtinguishByFireman(T2TowerDoc*, T2PeoplePtrList*) { +BOOL T2Fire::ExtinguishByFireman(T2TowerDoc* inDoc, T2PeoplePtrList* inPeopleList) { + BOOL result = false; + + if (!mFireman) { + T2People *fireman; + if (inPeopleList->FetchItemAt(1, &fireman)) { + inPeopleList->Remove(&fireman); + SetFireman(fireman); + } + } else { + if (mFireman->GetWalkStyle() != 2) { + switch (mFireman->GetStatus()) { + case kStatus14: + case kStatus15: + { + CRect rect; + mSprite->GetSpriteRect(mFireSpriteID, rect); + + CPoint theFirePos = rect.TopLeft(); + theFirePos.x += rect.Width() / 2; + UT2Coordinate::QDToUnit(theFirePos, 0); + + CPoint theFiremanPos = mFireman->GetCurPosition(); + if (theFiremanPos.x != theFirePos.x) { + if (mFireman->GetCurrDestPos().x != theFirePos.x) { + mFireman->SetCurrDestPos(theFirePos); + switch (mFireman->GetDirection()) { + case 0: + if (theFiremanPos.x > theFirePos.x) + mFireman->FlipDirection(); + break; + case 1: + if (theFiremanPos.x < theFirePos.x) + mFireman->FlipDirection(); + break; + } + mFireman->SetStatus(kStatus14); + } + } else { + if (x4 < (x18 - 4) || x4 == 0) { + x4 = x18 - 4; + if (x4 <= 0) + x4 = 1; + } + + mFireman->SetStatus(kStatus15); + mFireman->ChangeWalkStyle(2); + } + } + } + } else { + if (x4 > x18) + result = true; + } + } + + return result; } -T2Helicopter::T2Helicopter(T2TowerDoc*, const T2Tenant*) { + + +T2Helicopter::T2Helicopter(T2TowerDoc* inDoc, const T2Tenant* inTenant) { + mDocument = inDoc; + mSprite = &mDocument->mSprite; + + mHeliSpriteID = 0; + mWaterSpriteID = 0; + + mTimePassed = 0; + mSpeed = 1; + mWaterVisible = false; + + mImage = new T2BitImage(mDocument->mWorldDef->mModuleHandle, 5001, true); + mImageObj = new T2ImageObj; + mImageObj->AddObject(inDoc->mWorldDef->mModuleHandle, 5001, mImage); + + mHeliSpriteID = mSprite->NewSprite(*mImageObj, "HELI", T2Sprite::ELayer_4); + mWaterSpriteID = mSprite->NewSprite(*mImageObj, "WATER", T2Sprite::ELayer_4); + + if (inTenant) { + CRect unitRect, qdRect; + inTenant->GetEquipArea(unitRect); + unitRect.top -= 5; + unitRect.left += 10; + UT2Coordinate::UnitToQD(unitRect, qdRect, 0, true); + + mSprite->MoveSprite(mHeliSpriteID, qdRect.TopLeft()); + mSprite->ShowSprite(mHeliSpriteID, true); + } } T2Helicopter::~T2Helicopter() { + mDocument->mSprite.DeleteSprite(mHeliSpriteID); + mDocument->mSprite.DeleteSprite(mWaterSpriteID); + delete mImage; + delete mImageObj; } -void T2Helicopter::Move(T2TowerDoc*) { +void T2Helicopter::Move(T2TowerDoc* inDoc) { + T2TowerMainView *theMainView = inDoc->GetTowerMainView(); + CRect rect; + CPoint cursorPt, p; + + GetCursorPos(&cursorPt); + theMainView->ScreenToClient(&cursorPt); + + cursorPt += theMainView->m64; + + UT2Coordinate::QDToUnit(cursorPt, mDocument->towerDoc_vf108()); + cursorPt.y -= 1; + cursorPt.x += 1; + UT2Coordinate::UnitToQD(cursorPt, 0, true); + cursorPt.y -= 4; + + mSprite->GetSpriteRect(mHeliSpriteID, rect); + p = rect.TopLeft(); + + float h = cursorPt.x - p.x; + float v = cursorPt.y - p.y; + float dst = sqrt(h * h + v * v); + + if (dst < 36.0f) + mSpeed -= (mSpeed > 1); + else + mSpeed += (mSpeed < 8); + + float ratio = dst / mSpeed; + if (ratio > 1.0f) { + p.x += (int) (h / ratio); + p.y += (int) (v / ratio); + } else { + p.y--; + p.x++; + } + + mTimePassed++; + mSprite->ChangePattern(mHeliSpriteID, mTimePassed & 1); + mSprite->MoveSprite(mHeliSpriteID, p); + + if (GetAsyncKeyState(GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON) < 0) { + p.y += rect.Height(); + mSprite->GetSpriteRect(mWaterSpriteID, rect); + p.x -= rect.Width(); + + mSprite->ChangePattern(mWaterSpriteID, mTimePassed & 1); + mSprite->MoveSprite(mWaterSpriteID, p); + if (!mWaterVisible) { + mSprite->ShowSprite(mWaterSpriteID, true); + mWaterVisible = true; + } + + p.y += rect.Height(); + + T2FireBurning *theFireBurning = mDocument->mWorldDef->GetFireBurning(); + theFireBurning->DoExtinguish(p); + } else if (mWaterVisible) { + p.x = p.y = 0; + mSprite->MoveSprite(mWaterSpriteID, p); + mSprite->ShowSprite(mWaterSpriteID, false); + mWaterVisible = false; + } } -T2FireAttach::T2FireAttach(T2EventItem*, unsigned int, int) { + + +T2FireAttach::T2FireAttach(T2EventItem* inOwner, unsigned int inMessage, BOOL inExecuteHost) + : LAttachment(inMessage, inExecuteHost) +{ + mOwner = inOwner; } /*virtual*/ T2FireAttach::~T2FireAttach() { } -/*virtual*/ void T2FireAttach::ExecuteSelf(unsigned int, void*) { +/*virtual*/ void T2FireAttach::ExecuteSelf(unsigned int inMessage, void* ioData) { + MSG *pMsg; + BOOL newExecuteHost = true; + + if (mOwner->mStatus != 0) { + switch (inMessage) { + case WM_SETCURSOR: + pMsg = (MSG *) ioData; + if (LOWORD(pMsg->lParam) == HTCLIENT) { + SetCursor(LoadCursor(NULL, IDC_ARROW)); + newExecuteHost = false; + } + break; + + case WM_LBUTTONDOWN: + newExecuteHost = false; + break; + + case WM_TIMER: + pMsg = (MSG *) ioData; + if (pMsg->wParam == 100) + newExecuteHost = false; + break; + } + } + + SetExecuteHost(newExecuteHost); } diff --git a/src/T2DLL/T2FireBurning.h b/src/T2DLL/T2FireBurning.h index 6db462c..6e5f3da 100644 --- a/src/T2DLL/T2FireBurning.h +++ b/src/T2DLL/T2FireBurning.h @@ -1,67 +1,107 @@ #pragma once #include "common.h" +#include "LAttachment.h" +#include "T2EventItem.h" -class T2FireBurning { +enum { + kFireBurningStatus0 = 0, + kFireBurningStatus1 = 1, + kFireBurningStatus2 = 2, +}; + +enum { + kFireFightNull = 0, + kFireFightHelicopter = 1, + kFireFightFireman = 2, + kFireFightDoNothing = 3, +}; + +class AFX_EXT_CLASS T2FireBurning : public T2EventItem { public: - T2FireBurning(T2TowerEvent*, CResFile*, int); + T2FireBurning(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); virtual ~T2FireBurning(); - virtual int Start(T2TowerDoc*); - virtual int Exec(T2TowerDoc*); - virtual void StartEvent(T2TowerDoc*, POINT, const T2Tenant*); -protected: - virtual void SetupDialog(T2Dialog*); -public: - virtual unsigned int DialogHook(T2EventDialog*, unsigned int, T2TowerDoc*); - virtual void IdleEvent(T2TowerDoc*); - virtual void StopEvent(T2TowerDoc*); - int MakeFire(POINT, T2TowerDoc*); -protected: - int AdjustFirePos(T2FloorInfo*, POINT&, RECT&) const; -public: - void Extinguish(T2Fire*); - int DoExtinguish(CPoint&); + virtual DWORD GetID() { return 'FBEv'; } + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc* inDoc); + virtual void StopEvent(T2TowerDoc* inDoc); + virtual unsigned int DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc); + virtual void StartEvent(T2TowerDoc* inDoc, POINT inPt, const T2Tenant* inTenant); + virtual void IdleEvent(T2TowerDoc* inDoc); + BOOL MakeFire(POINT inPt, T2TowerDoc* inDoc); + void Extinguish(T2Fire* inFire); + BOOL DoExtinguish(CPoint& inPt); + BOOL IsEmergency() { return mStatus != kFireBurningStatus0; } + protected: - void CallFireman(T2TowerDoc*, const T2Tenant*); - int IsBreakoutFire(const T2TowerDoc*, POINT&, T2Tenant*&) const; + virtual void SetupDialog(T2Dialog* inDialog); + BOOL AdjustFirePos(T2FloorInfo* inFloorInfo, POINT& inPt, RECT& outRect) const; + void CallFireman(T2TowerDoc* inDoc, const T2Tenant* inTenant); + BOOL IsBreakoutFire(const T2TowerDoc* inDoc, POINT& outPt, T2Tenant*& outTenant) const; -public: - virtual unsigned long GetID() {} - int IsEmergency() {} - T2FireBurning(const T2FireBurning&) {} - T2FireBurning& operator=(const T2FireBurning&) {} + int mFightAction; + unsigned int mTimePassed; + int mHelicopterPrice; + LArray *mFireArray; + int m40; + T2BitImage *mImage; + T2ImageObj *mImageObj; + int mFireWidth; + int _50; + T2FireAttach *mAttach; + int _58; + T2Helicopter *mHelicopter; + T2PeoplePtrList *mPeopleList; }; -class T2Fire { + +class AFX_EXT_CLASS T2Fire { public: - T2Fire(POINT&, T2TowerDoc*, int, T2ImageObj*); + T2Fire(POINT& inPt, T2TowerDoc* inDoc, int inVar, T2ImageObj* inImageObj); ~T2Fire(); + BOOL Move(); + BOOL HitTest(CPoint& inPt, CRect& outRect); + BOOL ExtinguishByFireman(T2TowerDoc* inDoc, T2PeoplePtrList* inPeopleList); + + void SetArsonTenant(T2Tenant* inTenant) { mArsonTenant = inTenant; } + T2Tenant* GetArsonTenant() { return mArsonTenant; } + T2People* GetFireman() const { return mFireman; } + protected: - void SetFireman(T2People*); -public: - int Move(); - int HitTest(CPoint&, CRect&); - int ExtinguishByFireman(T2TowerDoc*, T2PeoplePtrList*); + void SetFireman(T2People* inPeople); - void SetArsonTenant(T2Tenant*) {} - T2Tenant* GetArsonTenant() {} - T2People* GetFireman() const {} - T2Fire& operator=(const T2Fire&) {} + unsigned int x0; + unsigned int x4; + T2TowerDoc *mDocument; + int xC; + T2Sprite *mSprite; + int mFireSpriteID; + unsigned int x18; + unsigned int x1C; + T2Tenant *mArsonTenant; + T2People *mFireman; }; -class T2Helicopter { + +class AFX_EXT_CLASS T2Helicopter { public: - T2Helicopter(T2TowerDoc*, const T2Tenant*); + T2Helicopter(T2TowerDoc* inDoc, const T2Tenant* inTenant); ~T2Helicopter(); - void Move(T2TowerDoc*); + void Move(T2TowerDoc* inDoc); - T2Helicopter& operator=(const T2Helicopter&) {} + T2TowerDoc *mDocument; + T2Sprite *mSprite; + T2BitImage *mImage; + T2ImageObj *mImageObj; + int mHeliSpriteID; + int mTimePassed; + int mSpeed; + int mWaterSpriteID; + BOOL mWaterVisible; }; -class T2FireAttach { + +class AFX_EXT_CLASS T2FireAttach : public LAttachment { public: - T2FireAttach(T2EventItem*, unsigned int, int); + T2FireAttach(T2EventItem* inOwner, unsigned int inMessage, BOOL inExecuteHost); virtual ~T2FireAttach(); protected: - virtual void ExecuteSelf(unsigned int, void*); - -public: - T2FireAttach(const T2FireAttach&) {} - T2FireAttach& operator=(const T2FireAttach&) {} + virtual void ExecuteSelf(unsigned int inMessage, void* ioData); + T2EventItem *mOwner; }; diff --git a/src/T2DLL/T2FireWork.cpp b/src/T2DLL/T2FireWork.cpp index abddcf4..38a27a5 100644 --- a/src/T2DLL/T2FireWork.cpp +++ b/src/T2DLL/T2FireWork.cpp @@ -1,28 +1,366 @@ +#include "GlobalFunc.h" +#include "T2BitImage.h" #include "T2FireWork.h" +#include "T2SoundPlayer.h" -T2FireWork::T2FireWork(int, int, CPalette*) { +T2FireWork::T2FireWork(int inWidth, int inHeight, CPalette* inPalette) { + Sounds->AddSound("Firework:Don", SoundPriority_0, 1000, AfxGetResourceHandle()); + + RECT rect; + rect.top = 0; + rect.left = 0; + rect.bottom = inHeight; + rect.right = inWidth; + + mImage = new T2BitImage(rect); + memset(mImage->mData, 0, mImage->mBitmap.header.biSizeImage); +#define ALIGN_ROW_SIZE(s) ((((s) + 3) / 4) * 4) + mRowSize = ALIGN_ROW_SIZE(inWidth); + + SetRect(&mRect, 0, 0, inWidth, inHeight); + + mIsActive = false; + + int i; + for (i = 0; i < 5; i++) { + for (int j = 0; j < 8; j++) { + int r, g, b; + if (i == 0) { + r = ((j + 1) * 255) / 8; + g = ((j + 1) * 255) / 8; + b = ((j + 1) * 100) / 8; + } else if (i == 1) { + r = ((j + 1) * 255) / 8; + g = ((j + 1) * 186) / 8; + b = ((j + 1) * 100) / 8; + } else if (i == 2) { + r = ((j + 1) * 255) / 8; + g = ((j + 1) * 50) / 8; + b = ((j + 1) * 50) / 8; + } else if (i == 3) { + r = ((j + 1) * 80) / 8; + g = ((j + 1) * 80) / 8; + b = ((j + 1) * 255) / 8; + } else if (i == 4) { + r = ((j + 1) * 255) / 8; + g = ((j + 1) * 255) / 8; + b = ((j + 1) * 200) / 8; + } + + mPalettes[i][j] = inPalette->GetNearestPaletteIndex(RGB(r, g, b)); + } + } + + for (i = 0; i < 20; i++) + mUsed[i] = false; } T2FireWork::~T2FireWork() { + delete mImage; + + for (int i = 0; i < 20; i++) { + if (mUsed[i]) + free(mStarInfo[i]); + } } T2BitImage* T2FireWork::GetBitImage() { + return mImage; } void T2FireWork::Start() { + mIsActive = true; } void T2FireWork::Stop() { + mIsActive = false; } -int T2FireWork::IsDisposable() { +BOOL T2FireWork::IsDisposable() { + if (mIsActive) + return false; + + for (int i = 0; i < 20; i++) { + if (mUsed[i]) + return false; + } + + return true; } -int T2FireWork::Idle() { +BOOL T2FireWork::Idle() { + static DWORD lastUpdate; + static DWORD counter; + + BOOL anyChange = false; + DWORD now = GetTickCount(); + int ind, ind2; + + if (mIsActive && lastUpdate != now) { + if ((counter % 35) == 0 || (rand() % 80) == 0) { + for (ind = 0; ind < 20; ind++) { + if (!mUsed[ind]) { +#pragma var_order(var24, var28, var2C, bufferSize, var34, var38) + float var24 = (((rand() % 40) - 20) / 100.0f) + 0.0f; + float var38 = var24; + float var28 = int((var38 * 6.283186) / 0.18) / 4; + int var34 = 1; + + for (float var2C = 0.0f; var2C <= var28; var2C += 1.0f) { +#pragma var_order(var3C, var40, var44) + float var3C = var38 * cos((var2C * 1.5707965) / var28); + float var40 = int((var3C * 6.283186) / 0.095); + + for (float var44 = 0.0f; var44 < var40 || var40 == 0.0f; var44 += 1.0f) { + var34++; + if (var40 == 0.0f) + break; + } + } + +#pragma var_order(var24, var28, var2C, bufferSize, var34, var38) + mUsed[ind] = true; + + int bufferSize = (var34 + 2) * sizeof(FIREWORK_STARINFO); + mStarInfo[ind] = (FIREWORK_STARINFO *) malloc(bufferSize); + memset(mStarInfo[ind], 0, bufferSize); + + mStarInfo[ind]->m0 = (rand() % 200) / 100.0f - 1.0f; + mStarInfo[ind]->m4 = (rand() % 400) / 200.0f + -9.5f - 2.0f; + mStarInfo[ind]->m8 = ((mRect.right / 2) + (rand() % (mRect.right / 3))) - (mRect.right / 6); + mStarInfo[ind]->mC = mRect.bottom; + mStarInfo[ind]->m10 = 0.0f; + mStarInfo[ind]->m14 = 0.01f; + mStarInfo[ind]->m18 = 50.0f; + mStarInfo[ind]->m1C = 15.0f; + mStarInfo[ind]->m24 = var24; + mStarInfo[ind]->mFlags = 0x101; + break; + } + } + } + counter++; + } + + lastUpdate = now; + + for (ind = 0; ind < 20; ind++) { + if (mUsed[ind]) { + FIREWORK_STARINFO *info = mStarInfo[ind]; + BOOL changed = false; + + for (ind2 = 0; info[ind2].mFlags != 0; ind2++) { +#pragma var_order(x, y, star, size, pixel) + FIREWORK_STARINFO *star = info + ind2; + int x, y, pixel, size; + + if (CalcStarData(star, star->m10 - star->m1C, &x, &y, &pixel, &size)) { + PutDot(x, y, size, 0); + changed = true; + } + + if (CalcStarData(star, star->m10, &x, &y, &pixel, &size)) { + PutDot(x, y, size, mPalettes[HIBYTE(pixel)][LOBYTE(pixel)]); + changed = true; + } + + star->m10 += 1.0f; + } + + if (!(info->mFlags & 0x8000) && (info->m10 >= info->m18)) { +#pragma var_order(var64, var68, var6C, var70, var74, origInfo, var7C, var80, var84, var88) + Sounds->Play("Firework:Don", SoundMask_10, SoundFlags_10, NULL, PlayMode_2, 100); + + FIREWORK_STARINFO *origInfo = info; + origInfo->mFlags |= 0x8000; + + unsigned short var88 = 0; + float var74 = 10.0f; + float var64 = 0.0f; + float var6C = rand() % 10 + 25; + float var84 = mStarInfo[ind]->m24; + switch (rand() % 10) { + case 0: + var88 = 8; + break; + case 1: + var88 = 0xC8; + break; + case 2: + var88 = 0x84; + break; + case 3: + var88 = 0x88; + break; + case 4: + var88 = 4; + break; + case 5: + var88 = 2; + break; + case 6: + var88 = 0x10; + break; + case 7: + case 8: + var88 = 0x28; + break; + case 9: + var88 = 0xD0; + break; + } + + float var68 = int((var84 * 6.283186) / 0.18) / 4; + int var80 = 1; + float var7C = mRect.bottom * 0.016; + + for (float var70 = 0.0f; var70 <= var68; var70 += 1.0f) { +#pragma var_order(var8C, var90, var94) + float var8C = var84 * cos((var70 * 1.5707965) / var68); + float var90 = int((var8C * 6.283186) / 0.095); + + for (float var94 = 0.0f; var94 < var90 || var90 == 0.0f; var94 += 1.0f) { +#pragma var_order(var98, var9C, varA0, varA4, varA8, varAC, varB0) + float var98 = (var94 * 6.283186) / ((var90 != 0.0f) ? var90 : 1.0f); + float varA0 = float(cos(var98)) * var8C * var7C; + float varA4 = float(sin(var98)) * var8C * var7C; + int var9C, varA8, varB0, varAC; + CalcStarData(origInfo, origInfo->m10 - 1.0f, &var9C, &varA8, &varB0, &varAC); + + info[var80].m0 = varA0; + info[var80].m4 = varA4; + info[var80].m8 = var9C; + info[var80].mC = varA8; + info[var80].m10 = 0.0f; + info[var80].m14 = var64; + info[var80].m18 = var6C; + info[var80].m1C = var74; + info[var80].mFlags = var88; + var80++; + + if (var90 == 0.0f) + break; + } + } + } + + anyChange |= changed; + + if (!changed) { + free(mStarInfo[ind]); + mUsed[ind] = false; + } + } + } + + return anyChange; } -int T2FireWork::CalcStarData(FIREWORK_STARINFO*, float, int*, int*, int*, int*) { +BOOL T2FireWork::CalcStarData(FIREWORK_STARINFO* inInfo, float inTime, int* outX, int* outY, int* outPixel, int* outSize) { + if (inTime >= 0.0f && inTime < inInfo->m18) { + float blend = 0.01f; + blend = 1.0f - (1.0f / ((inTime / 8.0f) + 1.0f)); + + float mult = inInfo->m0 * 30.0f; + *outX = (mult * blend) + inInfo->m8; + + mult = inInfo->m4 * 30.0f; + *outY = (mult * blend) + inInfo->mC + (inInfo->m14 * inTime * inTime); + + int group = 0; + int color = 7; + + if (inInfo->mFlags & 2) + group = 0; + else if (inInfo->mFlags & 4) + group = 1; + else if (inInfo->mFlags & 8) + group = 2; + else if (inInfo->mFlags & 0x10) + group = 3; + else if (inInfo->mFlags & 1) + group = 4; + + if (inInfo->mFlags & 0x20) { + if ((inInfo->m18 / 2.0f) < inTime) + group++; + } else if (inInfo->mFlags & 0x40) { + if ((inInfo->m18 - 2.0f) < inTime) + group++; + } + + while (group >= 5) + group -= 5; + + if (inInfo->mFlags & 0x100) { + color = (inTime * 10.0f) / inInfo->m18; + if (color >= 8) + color = 7; + } else if (inInfo->mFlags & 0x200) { + if ((inInfo->m18 / 2.0f) < inTime) + color = ((inInfo->m18 - inTime) * 8.0f) / (inInfo->m18 / 2.0f); + if (inTime >= 8.0f) + inTime = 7.0f; + } else { + color = (((inTime * 8.0f) / 2.0f) / inInfo->m18) + 4.0f; + } + + *outPixel = (group << 8) | color; + + if (inInfo->mFlags & 0x40) { + if (inTime > (inInfo->m18 - 2.0f)) + *outSize = 3; + else + *outSize = 1; + } else { + *outSize = 1; + } + + return true; + } + + return false; } -void T2FireWork::PutDot(int, int, int, unsigned char) { +void T2FireWork::PutDot(int inX, int inY, int inSize, unsigned char inCol) { + RECT theDotRect, theSubRect; + + if (inSize == 1) + SetRect(&theDotRect, inX, inY, inX + 1, inY + 1); + else if (inSize == 2) + SetRect(&theDotRect, inX, inY, inX + 2, inY + 2); + else if (inSize == 3 || inSize == 4) + SetRect(&theDotRect, inX - 1, inY - 1, inX + 2, inY + 2); + + SubtractRect(&theSubRect, &theDotRect, &mRect); + if (!IsRectEmpty(&theSubRect)) + return; + + int p = inX + (mRowSize * inY); + unsigned char *theData = mImage->mData; + + if (inSize == 1) { + theData[p] = inCol; + } else if (inSize == 2) { + theData[p] = inCol; + theData[p + 1] = inCol; + theData[p + mRowSize] = inCol; + theData[p + mRowSize + 1] = inCol; + } else if (inSize == 3) { + theData[p - 1] = inCol; + theData[p] = inCol; + theData[p + 1] = inCol; + theData[p - mRowSize] = inCol; + theData[p + mRowSize] = inCol; + } else if (inSize == 4) { + theData[p - mRowSize - 1] = inCol; + theData[p - mRowSize] = inCol; + theData[p - mRowSize + 1] = inCol; + theData[p - 1] = inCol; + theData[p] = inCol; + theData[p + 1] = inCol; + theData[p + mRowSize - 1] = inCol; + theData[p + mRowSize] = inCol; + theData[p + mRowSize + 1] = inCol; + } } diff --git a/src/T2DLL/T2FireWork.h b/src/T2DLL/T2FireWork.h index e9e5215..37b3fc0 100644 --- a/src/T2DLL/T2FireWork.h +++ b/src/T2DLL/T2FireWork.h @@ -1,19 +1,37 @@ #pragma once #include "common.h" -class T2FireWork { +struct FIREWORK_STARINFO { + float m0; + float m4; + float m8; + float mC; + float m10; + float m14; + float m18; + float m1C; + unsigned short mFlags; + float m24; +}; + +class AFX_EXT_CLASS T2FireWork { public: - T2FireWork(int, int, CPalette*); + T2FireWork(int inWidth, int inHeight, CPalette* inPalette); ~T2FireWork(); T2BitImage* GetBitImage(); void Start(); void Stop(); - int IsDisposable(); - int Idle(); + BOOL IsDisposable(); + BOOL Idle(); protected: - int CalcStarData(FIREWORK_STARINFO*, float, int*, int*, int*, int*); - void PutDot(int, int, int, unsigned char); + BOOL CalcStarData(FIREWORK_STARINFO* inInfo, float inT, int* outX, int* outY, int* outPixel, int* outSize); + void PutDot(int inX, int inY, int inSize, unsigned char inCol); -public: - T2FireWork& operator=(const T2FireWork&) {} + BOOL mIsActive; + T2BitImage *mImage; + int mRowSize; + RECT mRect; + unsigned char mPalettes[5][8]; + FIREWORK_STARINFO *mStarInfo[20]; + BOOL mUsed[20]; }; diff --git a/src/T2DLL/T2FloorCEArray.h b/src/T2DLL/T2FloorCEArray.h index c8a6610..da267a7 100644 --- a/src/T2DLL/T2FloorCEArray.h +++ b/src/T2DLL/T2FloorCEArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2RouteCEArray.h" -class T2FloorCEArray : public T2RouteCEArray { +class AFX_EXT_CLASS T2FloorCEArray : public T2RouteCEArray { public: T2FloorCEArray(); virtual ~T2FloorCEArray(); diff --git a/src/T2DLL/T2FloorInfo.cpp b/src/T2DLL/T2FloorInfo.cpp index cfbd45b..7ab47a6 100644 --- a/src/T2DLL/T2FloorInfo.cpp +++ b/src/T2DLL/T2FloorInfo.cpp @@ -1,187 +1,1025 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2FInfoAreaIterator.h" #include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2MoverArray.h" +#include "T2MoverArrayList.h" +#include "T2MoverDef.h" +#include "T2MoverModule.h" +#include "T2MoverModuleList.h" +#include "T2OutObjArrayList.h" +#include "T2OutsideInfo.h" +#include "T2RegistedTenantDB.h" +#include "T2Request.h" +#include "T2RequestArrayList.h" +#include "T2Tenant.h" +#include "T2TenantArrayList.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2UnitInfo.h" +#include "T2WorldDef.h" -T2FloorInfo::T2FloorInfo(const T2WorldDef*) { +T2FloorInfo::T2FloorInfo(const T2WorldDef* inWorldDef) { + mVRange = inWorldDef->GetHeight(); + mHRange = inWorldDef->GetWidth(); + mGroundLine = inWorldDef->mGroundLine; + mTopFloorLine = inWorldDef->mTopFloorLine; + mBottomFloorLine = inWorldDef->mBottomFloorLine; + mEntranceWidth = 7; + + inWorldDef->GetBuildArea(mBuildArea); + mFloorArea = mBuildArea; + mFloorArea.top = mTopFloorLine; + mFloorArea.bottom = mBottomFloorLine; + + mUnitInfo = NULL; + mTenantArrayList = NULL; + mMoverArrayList = NULL; + mRequestArrayList = NULL; + mOutObjArrayList = NULL; + mTenantNumber = NULL; + + mUnitInfo = new T2UnitInfo[mHRange * mVRange]; + + mTenantArrayList = new T2TenantArrayList; + mMoverArrayList = new T2MoverArrayList; + mRequestArrayList = new T2RequestArrayList; + mOutObjArrayList = new T2OutObjArrayList; + + mOutsideInfo = new T2OutsideInfo(*this); + mTenantNumber = new unsigned int[mVRange]; + memset(mTenantNumber, 0, sizeof(unsigned int) * mVRange); } /*virtual*/ T2FloorInfo::~T2FloorInfo() { + if (mUnitInfo) + delete[] mUnitInfo; + + if (mTenantArrayList) + delete mTenantArrayList; + if (mMoverArrayList) + delete mMoverArrayList; + if (mRequestArrayList) + delete mRequestArrayList; + if (mOutObjArrayList) + delete mOutObjArrayList; + + if (mOutsideInfo) + delete mOutsideInfo; + + if (mTenantNumber) + delete[] mTenantNumber; } -int T2FloorInfo::UnitToFloor(int) const { +int T2FloorInfo::UnitToFloor(int unit) const { + return (unit < mGroundLine) ? (mGroundLine - unit) : ((mGroundLine - unit) - 1); } -void T2FloorInfo::InitMask(CResFile&) { +void T2FloorInfo::InitMask(CResFile& inResFile) { + int vcheck; + int hcheck; + inResFile >> vcheck; + inResFile >> hcheck; + +#line 211 + _ASSERT((vcheck == mVRange) && (hcheck == mHRange)); + + int tmp; + RECT tmpRect; + inResFile >> tmp; + inResFile >> tmpRect; + + for (int i = 0; i < (mVRange * mHRange); i++) + mUnitInfo[i].InitMask(inResFile); } -void T2FloorInfo::Read(T2Archive&, T2TowerDoc*) { +void T2FloorInfo::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + int vcheck; + int hcheck; + inArchive >> vcheck; + inArchive >> hcheck; + + if (vcheck != mVRange || hcheck != mHRange) + return; + +#line 234 + _ASSERT((vcheck == mVRange) && (hcheck == mHRange)); + + DWORD code; + inArchive >> code; +#line 239 + _ASSERT(code == 'UntI'); + + for (int i = 0; i < (mVRange * mHRange); i++) + mUnitInfo[i].Read(inArchive, inDoc); + + inArchive >> code; + if (code == 'TntA') { + mTenantArrayList->Read(inArchive, inDoc); + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + theDB->Init(mTenantArrayList); + mTenantArrayList->RecoverRelatedTenantList(theDB); + inArchive >> code; + } + if (code == 'MvrA') { + mMoverArrayList->Read(inArchive, inDoc); + inArchive >> code; + } + if (code == 'ReqA') { + mRequestArrayList->Read(inArchive, inDoc); + inArchive >> code; + } + if (code == 'OObA') { + mOutObjArrayList->Read(inArchive, inDoc); + inArchive >> code; + } + if (code == 'OutI') + mOutsideInfo->Read(inArchive); } -void T2FloorInfo::Write(T2Archive&) { +void T2FloorInfo::Write(T2Archive& inArchive) { + inArchive << mVRange; + inArchive << mHRange; + + DWORD code = 'UntI'; + inArchive << code; + for (int i = 0; i < (mVRange * mHRange); i++) + mUnitInfo[i].Write(inArchive); + + code = 'TntA'; + inArchive << code; + mTenantArrayList->Write(inArchive); + + code = 'MvrA'; + inArchive << code; + mMoverArrayList->Write(inArchive); + + code = 'ReqA'; + inArchive << code; + mRequestArrayList->Write(inArchive); + + code = 'OObA'; + inArchive << code; + mOutObjArrayList->Write(inArchive); + + code = 'OutI'; + inArchive << code; + mOutsideInfo->Write(inArchive); } -int T2FloorInfo::IsValidRange(const RECT&) const { +BOOL T2FloorInfo::IsValidRange(const RECT& inRect) const { + BOOL result = true; + + if (mBuildArea.top > inRect.top || mBuildArea.bottom < inRect.bottom || mBuildArea.left > inRect.left || mBuildArea.right < inRect.right) + result = false; + + return result; } -int T2FloorInfo::IsAreaBuildable(const RECT&) { +BOOL T2FloorInfo::IsAreaBuildable(const RECT& inRect) { + BOOL result = false; + + if (IsValidRange(inRect)) { + result = true; + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *unitInfo; + while (iterator.Next(unitInfo) && result == true) { + if (!unitInfo->IsBuildable()) + result = false; + } + } + + return result; } -int T2FloorInfo::IsAllTenant(const RECT&) { +BOOL T2FloorInfo::IsAllTenant(const RECT& inRect) { + BOOL result = true; + + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *unitInfo; + + while (iterator.Next(unitInfo)) { + if (unitInfo->GetTenantID() < 1000) { + result = false; + break; + } + } + + return result; } -int T2FloorInfo::IsThereNoFloorTenant(const RECT&) { +BOOL T2FloorInfo::IsThereNoFloorTenant(const RECT& inRect) { + BOOL result = false; + + T2FInfoAreaIterator iterator(*this, inRect); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) { + if (!theTenant->IsFloor()) { + result = true; + break; + } + } + + return result; } -int T2FloorInfo::IsThereMover(const RECT&) { +BOOL T2FloorInfo::IsThereMover(const RECT& inRect) { + BOOL result = false; + + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) { + if (theUnitInfo->GetMoverID()) { + result = true; + break; + } + } + + return result; } -int T2FloorInfo::IsThereOtherKindMover(const RECT&, int) { +BOOL T2FloorInfo::IsThereOtherKindMover(const RECT& inRect, int inType) { + BOOL result = false; + unsigned int zero = 0; + + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) { + unsigned int moverID = theUnitInfo->GetMoverID(); + if (moverID != 0 && moverID != zero) { + T2Mover *theMover = GetMover(moverID); + if (theMover && theMover->GetEquipType() != inType) { + result = true; + break; + } + } + } + + return result; } -int T2FloorInfo::IsEnoughSideSpace(const RECT&) { +BOOL T2FloorInfo::IsEnoughSideSpace(const RECT& inRect) { + BOOL result = true; + + RECT rect = inRect; + rect.right = rect.left; + rect.left -= T2MoverDef::GetRequiredRequestSpace() * 2; + result = !IsThereMover(rect); + + if (result) { + rect = inRect; + rect.right = rect.left; + rect.left += T2MoverDef::GetRequiredRequestSpace() * 2; + result = !IsThereMover(rect); + } + + return result; } -T2Tenant* T2FloorInfo::GetTenant(unsigned int) const { +T2Tenant* T2FloorInfo::GetTenant(unsigned int inTenantID) const { + T2Tenant *result = NULL; + + if (inTenantID >= 1000) + result = mTenantArrayList->GetTenantByID(inTenantID); + + return result; } -T2Tenant* T2FloorInfo::GetTenant(int, int) const { +T2Tenant* T2FloorInfo::GetTenant(int inV, int inH) const { + T2Tenant *result = NULL; + + unsigned int tenantID = GetTenantID(inV, inH); + if (tenantID) + result = mTenantArrayList->GetTenantByID(tenantID); + + return result; } T2Tenant* T2FloorInfo::GetPoolTenant() const { + return GetTenant(1000); } -T2Tenant* T2FloorInfo::GetFloor(int, int) const { +T2Tenant* T2FloorInfo::GetFloor(int inV, int inH) const { + T2Tenant *result = NULL; + + T2Tenant *theTenant = GetTenant(inV, inH); + if (theTenant) { + if (theTenant->IsFloor()) { + result = theTenant; + } else { + unsigned int floorID = theTenant->GetFloorID(inV); + result = GetTenant(floorID); + } + } + + return result; } -T2Mover* T2FloorInfo::GetMover(unsigned int) { +T2Mover* T2FloorInfo::GetMover(unsigned int inMoverID) { + return mMoverArrayList->GetMoverByID(inMoverID); } -T2Mover* T2FloorInfo::GetMover(int, int) { +T2Mover* T2FloorInfo::GetMover(int inV, int inH) { + T2Mover *result = NULL; + + unsigned int moverID = GetMoverID(inV, inH); + if (moverID) + result = mMoverArrayList->GetMoverByID(moverID); + + return result; } -T2MoverModule* T2FloorInfo::GetModule(unsigned int) const { +T2MoverModule* T2FloorInfo::GetModule(unsigned int inModuleID) const { + LArrayIterator arrayIterator(*mMoverArrayList); + T2MoverArray *theArray; + + while (arrayIterator.Next(&theArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + T2Mover *theMover = theArray->GetIndexMover(i); + + if (theMover->IsUsed() && theMover->GetModuleList()) { + LArrayIterator moduleIterator(*theMover->GetModuleList()); + T2MoverModule *theModule; + + while (moduleIterator.Next(&theModule)) { + if (theModule->GetModuleID() == inModuleID) + return theModule; + } + } + } + } + + return NULL; } -T2Request* T2FloorInfo::GetRequest(unsigned int) const { +T2Request* T2FloorInfo::GetRequest(unsigned int inRequestID) const { + return mRequestArrayList->GetRequestByID(inRequestID); } -T2Request* T2FloorInfo::GetRequest(int, int) const { +T2Request* T2FloorInfo::GetRequest(int inV, int inH) const { + T2Request *result = NULL; + + unsigned int requestID = GetRequestID(inV, inH); + if (requestID) + result = mRequestArrayList->GetRequestByID(requestID); + + return result; } -T2People* T2FloorInfo::FindPeople(int, int) const { +T2People* T2FloorInfo::FindPeople(int inV, int inH) const { + T2People *result = NULL; + + T2Tenant *theFloor = GetFloor(inV, inH); + if (theFloor) { + POINT pt; + pt.x = inH; + pt.y = inV; + result = theFloor->FindPeople(pt); + } + + if (!result) { + T2Request *theRequest = GetRequest(inV, inH); + if (theRequest) + result = theRequest->FindPeople(inH); + } + + return result; } -T2OutObj* T2FloorInfo::GetOutObj(int, int) const { +T2OutObj* T2FloorInfo::GetOutObj(int inV, int inH) const { + return mOutObjArrayList->GetOutObjByID(GetOutObjID(inV, inH)); } -T2OutObj* T2FloorInfo::GetIndOutObj(unsigned int) const { +T2OutObj* T2FloorInfo::GetIndOutObj(unsigned int inIndex) const { + return mOutObjArrayList->GetIndOutObj(inIndex); } T2Tenant* T2FloorInfo::FindUnusedTenant() { + return mTenantArrayList->FindUnusedTenant(); } T2Mover* T2FloorInfo::FindUnusedMover() { + return mMoverArrayList->FindUnusedMover(); } T2Request* T2FloorInfo::FindUnusedRequest() { + return mRequestArrayList->FindUnusedRequest(); } T2OutObj* T2FloorInfo::FindUnusedOutObj() { + return mOutObjArrayList->FindUnusedOutObj(); } -unsigned int T2FloorInfo::GetTenantID(int, int) const { +unsigned int T2FloorInfo::GetTenantID(int inV, int inH) const { + unsigned int result = 0; + + T2UnitInfo *theUnitInfo = GetUnitInfo(inV, inH); + if (theUnitInfo) + result = theUnitInfo->GetTenantID(); + + return result; } -unsigned int T2FloorInfo::GetFloorID(int, int) { +unsigned int T2FloorInfo::GetFloorID(int inV, int inH) { + unsigned int result = 0; + + T2Tenant *theTenant = GetTenant(inV, inH); + if (theTenant) + result = theTenant->GetFloorID(inV); + + return result; } -unsigned int T2FloorInfo::GetEntranceFloorID(unsigned int) { +unsigned int T2FloorInfo::GetEntranceFloorID(unsigned int inTenantID) { + unsigned int result = 0; + + if (inTenantID == 1 || inTenantID == 2) { + result = 1000; + } else { + T2Tenant *theTenant = GetTenant(inTenantID); + if (theTenant) + result = theTenant->GetEntranceFloorID(); + } + + return result; } -POINT T2FloorInfo::GetEntrancePt(unsigned int) { +POINT T2FloorInfo::GetEntrancePt(unsigned int inTenantID) { + POINT result; + result.x = -1; + result.y = -1; + + if (inTenantID == 1 || inTenantID == 2) { + unsigned int id = 1000; + T2Tenant *theTenant = GetTenant(id); + if (theTenant) { + RECT area; + theTenant->GetEquipArea(area); + + result.y = area.bottom - 1; + if (inTenantID == 1) + result.x = area.left; + else + result.x = area.right - 2; + } + } else { + T2Tenant *theTenant = GetTenant(inTenantID); + if (theTenant) + result = theTenant->GetEntrancePt(); + } + + return result; } -unsigned int T2FloorInfo::GetMoverID(int, int) { +unsigned int T2FloorInfo::GetMoverID(int inV, int inH) { + unsigned int result = 0; + + T2UnitInfo *theUnitInfo = GetUnitInfo(inV, inH); + if (theUnitInfo) + result = theUnitInfo->GetMoverID(); + + return result; } -unsigned int T2FloorInfo::GetRequestID(int, int) const { +unsigned int T2FloorInfo::GetRequestID(int inV, int inH) const { + unsigned int result = 0; + + T2UnitInfo *theUnitInfo = GetUnitInfo(inV, inH); + if (theUnitInfo) + result = theUnitInfo->GetRequestID(); + + return result; } -unsigned int T2FloorInfo::GetOutObjID(int, int) const { +unsigned int T2FloorInfo::GetOutObjID(int inV, int inH) const { + unsigned int result = 0; + + if (mOutsideInfo) + result = mOutsideInfo->GetOutObjID(inV, inH); + + return result; } -T2UnitInfo* T2FloorInfo::GetUnitInfo(int, int) const { +T2UnitInfo* T2FloorInfo::GetUnitInfo(int inV, int inH) const { + T2UnitInfo *result = NULL; + +#line 829 + _ASSERT((inV >= 0) && (inV < mVRange)); + _ASSERT((inH >= 0) && (inH < mHRange)); + + if (inV >= 0 && inV < mVRange && inH >= 0 && inH < mHRange) + result = &mUnitInfo[mHRange * inV + inH]; + + return result; } -void T2FloorInfo::FillTenantID(const RECT&, unsigned int) { +void T2FloorInfo::FillTenantID(const RECT& inRect, unsigned int inTenantID) { + if (IsValidRange(inRect)) { + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) + theUnitInfo->FillTenantID(inTenantID); + } } -void T2FloorInfo::ReplaceFloorID(const RECT&, unsigned int, unsigned int) { +void T2FloorInfo::ReplaceFloorID(const RECT& inRect, unsigned int inOldID, unsigned int inNewID) { + if (IsValidRange(inRect)) { + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) { + if (theUnitInfo->GetTenantID() == inOldID) + theUnitInfo->FillTenantID(inNewID); + } + } } -void T2FloorInfo::FillMoverID(const RECT&, unsigned int) { +void T2FloorInfo::FillMoverID(const RECT& inRect, unsigned int inMoverID) { + if (IsValidRange(inRect)) { + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) + theUnitInfo->FillMoverID(inMoverID); + } } -void T2FloorInfo::FillRequestID(const RECT&, unsigned int) { +void T2FloorInfo::FillRequestID(const RECT& inRect, unsigned int inRequestID) { + FillMoverID(inRect, inRequestID); } -int T2FloorInfo::FillRequestID(POINT, ERequestUpDown, unsigned int) { +int T2FloorInfo::FillRequestID(POINT inPt, ERequestUpDown inUpDown, unsigned int inRequestID) { + int result = 0; + POINT pt = inPt; + + if (inUpDown == ERequestUpDown_1) { + pt.x += 2; + + T2Request *theRequest = GetRequest(pt.y, pt.x); + if (theRequest) { + POINT head = theRequest->GetHeadPosition(); + result = ((head.x - inPt.x) / 2) - 2; + int width = result + ((head.x - inPt.x) % 2); + theRequest->SetDrawWidth(width); + } else { + T2Tenant *theFloor = GetFloor(pt.y, pt.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + result = CalcRequestRightEnd(pt, floorArea.right) - inPt.x - 2; + } + } + } else { + pt.x -= 3; + + T2Request *theRequest = GetRequest(pt.y, pt.x); + if (theRequest) { + POINT head = theRequest->GetHeadPosition(); + int width = ((inPt.x - head.x) / 2) - 2; + theRequest->SetDrawWidth(width); + result = width + ((inPt.x - head.x) % 2); + } else { + T2Tenant *theFloor = GetFloor(pt.y, pt.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + result = inPt.x - CalcRequestLeftEnd(pt, floorArea.left) - 2; + } + } + } + + RECT area; + area.top = inPt.y; + area.bottom = inPt.y + 1; + area.left = area.right = inPt.x; + + if (inUpDown == ERequestUpDown_1) + area.right = inPt.x + result + 2; + else + area.left = inPt.x - result - 2; + + FillRequestID(area, inRequestID); + return result; } -void T2FloorInfo::RemoveRequestID(ERequestUpDown, const RECT&) { +void T2FloorInfo::RemoveRequestID(ERequestUpDown inUpDown, const RECT& inRect) { + FillRequestID(inRect, 0); + + if (inUpDown == ERequestUpDown_0) { + T2Request *theRequest = GetRequest(inRect.top, inRect.left - 1); + if (theRequest) { + RECT rect = inRect; + rect.right -= 2; + theRequest->SetDrawWidth(theRequest->GetDrawWidth() + (rect.right - rect.left)); + FillRequestID(rect, theRequest->GetRequestID()); + } + } else { + T2Request *theRequest = GetRequest(inRect.top, inRect.right); + if (theRequest) { + RECT rect = inRect; + rect.left += 2; + theRequest->SetDrawWidth(theRequest->GetDrawWidth() + (rect.right - rect.left)); + FillRequestID(rect, theRequest->GetRequestID()); + } + } } -void T2FloorInfo::FillOutObjID(const RECT&, unsigned int) { +void T2FloorInfo::FillOutObjID(const RECT& inRect, unsigned int inOutObjID) { + if (IsValidRange(inRect)) + mOutsideInfo->FillOutObjID(inRect, inOutObjID); } -unsigned int T2FloorInfo::FindTenantID(int, int, int, int, unsigned int) { +unsigned int T2FloorInfo::FindTenantID(int inV, int inH, BOOL inRight, int inMaxDistance, unsigned int inExclTenantID) { + unsigned int result = 0; + + POINT pt; + SetPt(&pt, inH, inV); + T2FInfoPtIterator iterator(*this, pt); + + int distance = 0; + T2UnitInfo *theUnitInfo; + unsigned int checkID; + + if (!inRight) { + while (iterator.Left(theUnitInfo) && distance < inMaxDistance) { + checkID = theUnitInfo->GetTenantID(); + if (checkID != 0 && checkID != inExclTenantID) { + result = checkID; + break; + } + distance++; + } + } else { + while (iterator.Right(theUnitInfo) && distance < inMaxDistance) { + checkID = theUnitInfo->GetTenantID(); + if (checkID != 0 && checkID != inExclTenantID) { + result = checkID; + break; + } + distance++; + } + } + + return result; } -int T2FloorInfo::CalcRequestRightEnd(POINT, int) { +int T2FloorInfo::CalcRequestRightEnd(POINT inPt, int inMaxH) { + int h = inPt.x + 1; + + T2FInfoPtIterator iterator(*this, inPt); + T2UnitInfo *theUnitInfo; + + while (iterator.Right(theUnitInfo) && h < inMaxH) { + if (theUnitInfo->GetMoverID() != 0) { + h -= 2; + break; + } + h++; + } + + return h; } -int T2FloorInfo::CalcRequestLeftEnd(POINT, int) { +int T2FloorInfo::CalcRequestLeftEnd(POINT inPt, int inMinH) { + int h = inPt.x; + + T2FInfoPtIterator iterator(*this, inPt); + T2UnitInfo *theUnitInfo; + + while (iterator.Left(theUnitInfo) && h > inMinH) { + if (theUnitInfo->GetMoverID() != 0) { + h += 2; + break; + } + h--; + } + + return h; } -int T2FloorInfo::GetLeftMoverID(POINT, int) const { +int T2FloorInfo::GetLeftMoverID(POINT inPt, int inMinH) const { + int result = 0; + int h = inPt.x; + + T2FInfoPtIterator iterator(*this, inPt); + T2UnitInfo *theUnitInfo; + + while (iterator.Left(theUnitInfo) && h > inMinH && result == 0) { + result = theUnitInfo->GetMoverID(); + h--; + } + + return result; } -void T2FloorInfo::UpdeteRequestByUnionFloor(T2Tenant*, POINT) { +void T2FloorInfo::UpdeteRequestByUnionFloor(T2Tenant* inTenant, POINT inPt) { + POINT rightPt = inPt; + rightPt.x++; + + T2Request *theLeftRequest = GetRequest(inPt.y, inPt.x); + T2Request *theRightRequest = GetRequest(rightPt.y, rightPt.x); + + if (theLeftRequest) { + POINT leftHeadPt = theLeftRequest->GetHeadPosition(); + if (theRightRequest) { + POINT rightHeadPt = theRightRequest->GetHeadPosition(); + + int width = ((rightHeadPt.x - leftHeadPt.x) / 2) - 2; + theLeftRequest->SetDrawWidth(width); + theRightRequest->SetDrawWidth(width + ((rightHeadPt.x - leftHeadPt.x) % 2)); + + RECT rightArea; + theRightRequest->CalcArea(rightArea); + FillRequestID(rightArea, theRightRequest->GetRequestID()); + } else { + RECT floorArea; + inTenant->GetEquipArea(floorArea); + theLeftRequest->SetDrawWidth(CalcRequestRightEnd(inPt, floorArea.right) - leftHeadPt.x - 2); + } + + RECT leftArea; + theLeftRequest->CalcArea(leftArea); + FillRequestID(leftArea, theLeftRequest->GetRequestID()); + } else if (theRightRequest) { + POINT rightHeadPt = theRightRequest->GetHeadPosition(); + + RECT floorArea; + inTenant->GetEquipArea(floorArea); + theRightRequest->SetDrawWidth(rightHeadPt.x - CalcRequestLeftEnd(rightPt, floorArea.left) - 2); + + RECT rightArea; + theRightRequest->CalcArea(rightArea); + FillRequestID(rightArea, theRightRequest->GetRequestID()); + } } -void T2FloorInfo::MoverAreaAdded(const RECT&, unsigned int) { +void T2FloorInfo::MoverAreaAdded(const RECT& inRect, unsigned int inMoverID) { + UpdeteRequestByBuildMover(inRect); + FillMoverID(inRect, inMoverID); } -void T2FloorInfo::MoverAreaRemoved(const RECT&) { +void T2FloorInfo::MoverAreaRemoved(const RECT& inRect) { + FillMoverID(inRect, 0); + UpdeteRequestByRemoveMover(inRect); } -void T2FloorInfo::UpdeteRequestByBuildMover(const RECT&) { +void T2FloorInfo::UpdeteRequestByBuildMover(const RECT& inRect) { + POINT pt; + pt.x = inRect.left; + pt.y = inRect.top; + + for (int v = inRect.top; v < inRect.bottom; v++, pt.y++) { + T2Request *theRequest = GetRequest(pt.y, pt.x); + if (theRequest) { + POINT headPt = theRequest->GetHeadPosition(); + int width = theRequest->GetDrawWidth() + 2; + + RECT area; + area.top = v; + area.bottom = v + 1; + + if (theRequest->GetUpDown() == ERequestUpDown_1) { + POINT pt2 = pt; + + area.left = inRect.left - 2; + area.right = headPt.x + width; + theRequest->SetDrawWidth(area.left - headPt.x - 2); + FillRequestID(area, 0); + + pt2.x = area.right; + T2Request *theOtherRequest = GetRequest(pt2.y, pt2.x); + if (theOtherRequest) { + POINT headPt2 = theOtherRequest->GetHeadPosition(); + if (pt2.x < (inRect.right + 2)) { + area.left = pt2.x; + area.right = inRect.right + 2; + theOtherRequest->SetDrawWidth(headPt2.x - area.right - 2); + FillRequestID(area, 0); + } else if (pt2.x > (inRect.right + 2)) { + area.left = inRect.right + 2; + area.right = pt2.x; + theOtherRequest->SetDrawWidth(headPt.x - area.left - 2); + FillRequestID(area, theOtherRequest->GetRequestID()); + } + } + } else { + POINT pt2 = pt; + + area.left = headPt.x - width; + area.right = inRect.right + 2; + theRequest->SetDrawWidth(headPt.x - area.right - 2); + FillRequestID(area, 0); + + pt2.x = area.left - 1; + T2Request *theOtherRequest = GetRequest(pt2.y, pt2.x); + if (theOtherRequest) { + POINT headPt2 = theOtherRequest->GetHeadPosition(); + area.left = pt2.x + 1; + area.right = inRect.left - 2; + theOtherRequest->SetDrawWidth(area.right - headPt2.x - 2); + FillRequestID(area, theOtherRequest->GetRequestID()); + } + } + } + } } -void T2FloorInfo::UpdeteRequestByRemoveMover(const RECT&) { +void T2FloorInfo::UpdeteRequestByRemoveMover(const RECT& inRect) { + POINT pt1; + POINT pt2; + + pt2.y = pt1.y = inRect.top; + + pt1.x = inRect.left - 3; + pt2.x = inRect.right + 2; + + for (; pt1.y < inRect.bottom; pt1.y++, pt2.y++) { + T2Request *theRequest1 = GetRequest(pt1.y, pt1.x); + T2Request *theRequest2 = GetRequest(pt2.y, pt2.x); + + if (theRequest1) { + POINT headPt1 = theRequest1->GetHeadPosition(); + if (theRequest2) { + POINT headPt2 = theRequest2->GetHeadPosition(); + + int width = ((headPt2.x - headPt1.x) / 2) - 2; + theRequest1->SetDrawWidth(width); + theRequest2->SetDrawWidth(width + ((headPt2.x - headPt1.x) % 2)); + + RECT area2; + theRequest2->CalcArea(area2); + FillRequestID(area2, theRequest2->GetRequestID()); + } else { + T2Tenant *theFloor = GetFloor(pt1.y, pt1.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + theRequest1->SetDrawWidth(CalcRequestRightEnd(pt1, floorArea.right) - headPt1.x - 2); + } + } + + RECT area1; + theRequest1->CalcArea(area1); + FillRequestID(area1, theRequest1->GetRequestID()); + } else if (theRequest2) { + POINT headPt2 = theRequest2->GetHeadPosition(); + + T2Tenant *theFloor = GetFloor(pt1.y, pt1.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + theRequest2->SetDrawWidth(headPt2.x - CalcRequestLeftEnd(pt2, floorArea.left) - 2); + } + + RECT area2; + theRequest2->CalcArea(area2); + FillRequestID(area2, theRequest2->GetRequestID()); + } + } } -unsigned int T2FloorInfo::GetNextTenantNumber(int) { +unsigned int T2FloorInfo::GetNextTenantNumber(int inV) { +#line 1364 + _ASSERT((inV >= 0) && (inV < mVRange)); + + unsigned int result = mTenantNumber[inV]; + do { + result++; + if (result >= 1000) + result = 1; + } while (FindNumberredTenant(inV, result)); + + mTenantNumber[inV] = result; + return result; } -void T2FloorInfo::SetTenantNumber(int, unsigned int) { +void T2FloorInfo::SetTenantNumber(int inV, unsigned int inTenantNumber) { +#line 1387 + _ASSERT((inV >= 0) && (inV < mVRange)); + + mTenantNumber[inV] = inTenantNumber; } -T2Tenant* T2FloorInfo::FindNumberredTenant(int, unsigned int) { +T2Tenant* T2FloorInfo::FindNumberredTenant(int inV, unsigned int inTenantNumber) { +#line 1399 + _ASSERT((inV >= 0) && (inV < mVRange)); + + POINT pt; + SetPt(&pt, mBuildArea.left, inV); + + T2FInfoPtIterator iterator(*this, pt); + T2Tenant *theTenant = NULL; + + while (iterator.RightTenant(theTenant)) { + if (theTenant->GetTenantNumber() == inTenantNumber) + break; + + theTenant = NULL; + } + + return theTenant; } -void T2FloorInfo::FinishBuildFloor(T2TowerDoc*, const RECT&) { +void T2FloorInfo::FinishBuildFloor(T2TowerDoc* inDoc, const RECT& inRect) { + T2FInfoAreaIterator iterator(*this, inRect); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) { + if (!theTenant->IsBuildFinish()) + theTenant->Idle(inDoc); + } } -void T2FloorInfo::SetTenantDrawModeByRect(const RECT&, int) { +void T2FloorInfo::SetTenantDrawModeByRect(const RECT& inRect, int inDrawMode) { + RECT rect = inRect; + int actualMode; + + switch (inDrawMode) { + case DrawMode1: + { + RECT rect2 = inRect; + rect2.bottom = rect2.top + 1; + + T2FInfoAreaIterator iterator(*this, rect2); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) + theTenant->SetDrawMode(inDrawMode); + + rect.top++; + actualMode = DrawMode2; + break; + } + case DrawMode3: + actualMode = DrawMode1; + break; + case DrawMode2: + actualMode = inDrawMode; + break; + } + + T2FInfoAreaIterator iterator(*this, rect); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) + theTenant->SetDrawMode(actualMode); } -void T2FloorInfo::UpdateFloorCEArray(const RECT&, unsigned int, unsigned int) { +void T2FloorInfo::UpdateFloorCEArray(const RECT& inRect, unsigned int inOldID, unsigned int inNewID) { + POINT pt; + + pt.x = inRect.left; + for (pt.y = inRect.top; pt.y < inRect.bottom; pt.y++) { + T2Tenant *theFloor = GetFloor(pt.y, pt.x); + if (theFloor) + theFloor->ReplaceCEID(inOldID, inNewID); + } } -int T2FloorInfo::CalcMentenanceCost(T2TowerDoc*) const { +int T2FloorInfo::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int cost = 0; + +#line 1502 + _ASSERT(mTenantArrayList != NULL); + cost += mTenantArrayList->CalcMentenanceCost(inDoc); + _ASSERT(mMoverArrayList != NULL); + cost += mMoverArrayList->CalcMentenanceCost(inDoc); + + cost += mOutObjArrayList->CalcMentenanceCost(inDoc); + + return cost; } -T2Tenant* T2FloorInfo::GetTenantByPID(unsigned long) { +T2Tenant* T2FloorInfo::GetTenantByPID(DWORD inPluginID) { + T2Tenant *result = NULL; + + if (mTenantArrayList) + result = mTenantArrayList->GetTenantByPID(inPluginID); + + return result; } -int T2FloorInfo::BuildFinishForce(const RECT&) { +BOOL T2FloorInfo::BuildFinishForce(const RECT& inRect) { + BOOL result = false; + POINT pt; + + for (pt.y = inRect.top; pt.y < inRect.bottom; pt.y++) { + for (pt.x = inRect.left; pt.x < inRect.right; pt.x++) { + T2Tenant *theTenant = GetTenant(pt.y, pt.x); + if (theTenant && theTenant->GetStatus() < kTenantStatus10) { + theTenant->SetStatus(kTenantStatus9); + theTenant->Idle(GetCurrentT2TowerDoc()); + GetCurrentT2TowerDoc()->mTowerMainView->tmv_vf128(theTenant->mArea); + result = true; + } + } + } + + return result; } diff --git a/src/T2DLL/T2FloorInfo.h b/src/T2DLL/T2FloorInfo.h index b292900..d76eac9 100644 --- a/src/T2DLL/T2FloorInfo.h +++ b/src/T2DLL/T2FloorInfo.h @@ -1,86 +1,100 @@ #pragma once #include "common.h" -class T2FloorInfo { +class AFX_EXT_CLASS T2FloorInfo { public: - T2FloorInfo(const T2WorldDef*); + T2FloorInfo(const T2WorldDef* inWorldDef); virtual ~T2FloorInfo(); - int UnitToFloor(int) const; - void InitMask(CResFile&); - void Read(T2Archive&, T2TowerDoc*); - void Write(T2Archive&); -protected: - int IsValidRange(const RECT&) const; -public: - int IsAreaBuildable(const RECT&); - int IsAllTenant(const RECT&); - int IsThereNoFloorTenant(const RECT&); - int IsThereMover(const RECT&); - int IsThereOtherKindMover(const RECT&, int); - int IsEnoughSideSpace(const RECT&); - T2Tenant* GetTenant(unsigned int) const; - T2Tenant* GetTenant(int, int) const; + int UnitToFloor(int unit) const; + void InitMask(CResFile& inResFile); + void Read(T2Archive& inArchive, T2TowerDoc* inDoc); + void Write(T2Archive& inArchive); + BOOL IsAreaBuildable(const RECT& inRect); + BOOL IsAllTenant(const RECT& inRect); + BOOL IsThereNoFloorTenant(const RECT& inRect); + BOOL IsThereMover(const RECT& inRect); + BOOL IsThereOtherKindMover(const RECT& inRect, int inType); + BOOL IsEnoughSideSpace(const RECT& inRect); + T2Tenant* GetTenant(unsigned int inTenantID) const; + T2Tenant* GetTenant(int inV, int inH) const; T2Tenant* GetPoolTenant() const; - T2Tenant* GetFloor(int, int) const; - T2Mover* GetMover(unsigned int); - T2Mover* GetMover(int, int); - T2MoverModule* GetModule(unsigned int) const; - T2Request* GetRequest(unsigned int) const; - T2Request* GetRequest(int, int) const; - T2People* FindPeople(int, int) const; - T2OutObj* GetOutObj(int, int) const; - T2OutObj* GetIndOutObj(unsigned int) const; + T2Tenant* GetFloor(int inV, int inH) const; + T2Mover* GetMover(unsigned int inMoverID); + T2Mover* GetMover(int inV, int inH); + T2MoverModule* GetModule(unsigned int inModuleID) const; + T2Request* GetRequest(unsigned int inRequestID) const; + T2Request* GetRequest(int inV, int inH) const; + T2People* FindPeople(int inV, int inH) const; + T2OutObj* GetOutObj(int inV, int inH) const; + T2OutObj* GetIndOutObj(unsigned int inIndex) const; T2Tenant* FindUnusedTenant(); T2Mover* FindUnusedMover(); T2Request* FindUnusedRequest(); T2OutObj* FindUnusedOutObj(); - unsigned int GetTenantID(int, int) const; - unsigned int GetFloorID(int, int); - unsigned int GetEntranceFloorID(unsigned int); - POINT GetEntrancePt(unsigned int); - unsigned int GetMoverID(int, int); - unsigned int GetRequestID(int, int) const; - unsigned int GetOutObjID(int, int) const; - T2UnitInfo* GetUnitInfo(int, int) const; - void FillTenantID(const RECT&, unsigned int); - void ReplaceFloorID(const RECT&, unsigned int, unsigned int); - void FillMoverID(const RECT&, unsigned int); - void FillRequestID(const RECT&, unsigned int); - int FillRequestID(POINT, ERequestUpDown, unsigned int); - void RemoveRequestID(ERequestUpDown, const RECT&); - void FillOutObjID(const RECT&, unsigned int); - unsigned int FindTenantID(int, int, int, int, unsigned int); -protected: - int CalcRequestRightEnd(POINT, int); - int CalcRequestLeftEnd(POINT, int); -public: - int GetLeftMoverID(POINT, int) const; - void UpdeteRequestByUnionFloor(T2Tenant*, POINT); - void MoverAreaAdded(const RECT&, unsigned int); - void MoverAreaRemoved(const RECT&); - void UpdeteRequestByBuildMover(const RECT&); - void UpdeteRequestByRemoveMover(const RECT&); - unsigned int GetNextTenantNumber(int); - void SetTenantNumber(int, unsigned int); - T2Tenant* FindNumberredTenant(int, unsigned int); - void FinishBuildFloor(T2TowerDoc*, const RECT&); - void SetTenantDrawModeByRect(const RECT&, int); - void UpdateFloorCEArray(const RECT&, unsigned int, unsigned int); - int CalcMentenanceCost(T2TowerDoc*) const; - T2Tenant* GetTenantByPID(unsigned long); - int BuildFinishForce(const RECT&); + unsigned int GetTenantID(int inV, int inH) const; + unsigned int GetFloorID(int inV, int inH); + unsigned int GetEntranceFloorID(unsigned int inTenantID); + POINT GetEntrancePt(unsigned int inTenantID); + unsigned int GetMoverID(int inV, int inH); + unsigned int GetRequestID(int inV, int inH) const; + unsigned int GetOutObjID(int inV, int inH) const; + T2UnitInfo* GetUnitInfo(int inV, int inH) const; + void FillTenantID(const RECT& inRect, unsigned int inTenantID); + void ReplaceFloorID(const RECT& inRect, unsigned int inOldID, unsigned int inNewID); + void FillMoverID(const RECT& inRect, unsigned int inMoverID); + void FillRequestID(const RECT& inRect, unsigned int inRequestID); + int FillRequestID(POINT inPt, ERequestUpDown inUpDown, unsigned int inRequestID); + void RemoveRequestID(ERequestUpDown inUpDown, const RECT& inRect); + void FillOutObjID(const RECT& inRect, unsigned int inOutObjID); + unsigned int FindTenantID(int inV, int inH, BOOL inRight, int inMaxDistance, unsigned int inExclTenantID); + int GetLeftMoverID(POINT inPt, int inMinH) const; + void UpdeteRequestByUnionFloor(T2Tenant* inTenant, POINT inPt); + void MoverAreaAdded(const RECT& inRect, unsigned int inMoverID); + void MoverAreaRemoved(const RECT& inRect); + void UpdeteRequestByBuildMover(const RECT& inRect); + void UpdeteRequestByRemoveMover(const RECT& inRect); + unsigned int GetNextTenantNumber(int inV); + void SetTenantNumber(int inV, unsigned int inTenantNumber); + T2Tenant* FindNumberredTenant(int inV, unsigned int inTenantNumber); + void FinishBuildFloor(T2TowerDoc* inDoc, const RECT& inRect); + void SetTenantDrawModeByRect(const RECT& inRect, int inDrawMode); + void UpdateFloorCEArray(const RECT& inRect, unsigned int inOldID, unsigned int inNewID); + int CalcMentenanceCost(T2TowerDoc* inDoc) const; + T2Tenant* GetTenantByPID(DWORD inPluginID); + BOOL BuildFinishForce(const RECT& inRect); - int GetVRange() const {} - int GetHRange() const {} - int GetGroundLine() const {} - int GetTopFloorLine() const {} - int GetBottomFloorLine() const {} - int GetEntranceWidth() const {} - void GetBuildArea(RECT&) const {} - void GetFloorArea(RECT&) const {} - T2TenantArrayList* GetTenantArrayList() const {} - T2MoverArrayList* GetMoverArrayList() const {} - T2RequestArrayList* GetRequestArrayList() const {} - T2OutObjArrayList* GetOutObjArrayList() const {} - T2OutsideInfo* GetOutsideInfo() const {} + int GetVRange() const { return mVRange; } + int GetHRange() const { return mHRange; } + int GetGroundLine() const { return mGroundLine; } + int GetTopFloorLine() const { return mTopFloorLine; } + int GetBottomFloorLine() const { return mBottomFloorLine; } + int GetEntranceWidth() const { return mEntranceWidth; } + void GetBuildArea(RECT& outRect) const { outRect = mBuildArea; } + void GetFloorArea(RECT& outRect) const { outRect = mFloorArea; } + T2TenantArrayList* GetTenantArrayList() const { return mTenantArrayList; } + T2MoverArrayList* GetMoverArrayList() const { return mMoverArrayList; } + T2RequestArrayList* GetRequestArrayList() const { return mRequestArrayList; } + T2OutObjArrayList* GetOutObjArrayList() const { return mOutObjArrayList; } + T2OutsideInfo* GetOutsideInfo() const { return mOutsideInfo; } + + int mVRange; + int mHRange; + int mGroundLine; + int mTopFloorLine; + int mBottomFloorLine; + int mEntranceWidth; + RECT mBuildArea; + RECT mFloorArea; + T2UnitInfo *mUnitInfo; + unsigned int *mTenantNumber; + T2TenantArrayList *mTenantArrayList; + T2MoverArrayList *mMoverArrayList; + T2RequestArrayList *mRequestArrayList; + T2OutObjArrayList *mOutObjArrayList; + T2OutsideInfo *mOutsideInfo; + +protected: + BOOL IsValidRange(const RECT& inRect) const; + int CalcRequestRightEnd(POINT inPt, int inMaxH); + int CalcRequestLeftEnd(POINT inPt, int inMinH); }; diff --git a/src/T2DLL/T2FloorNumberTable.cpp b/src/T2DLL/T2FloorNumberTable.cpp index 4a49252..41bd585 100644 --- a/src/T2DLL/T2FloorNumberTable.cpp +++ b/src/T2DLL/T2FloorNumberTable.cpp @@ -1,40 +1,146 @@ +#include "GlobalFunc.h" +#include "T2FloorInfo.h" #include "T2FloorNumberTable.h" +#include "T2Mover.h" +#include "T2MoverModuleTable.h" +#include "T2TowerDoc.h" -T2FloorNumberTable::T2FloorNumberTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2FloorNumberTable::T2FloorNumberTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemImageTable(inDoc, inImageObj, inPalette) + , mMover(NULL) + , mMoverModuleTable(NULL) +{ + SetRect(&mRect, 0, 0, 0, 0); + _10C = 0; + _110 = 0; } /*virtual*/ T2FloorNumberTable::~T2FloorNumberTable() { } -/*virtual*/ int T2FloorNumberTable::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2FloorNumberTable::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { + return T2DlgItem::Create(inWindowName, inStyle, inRect, inParentWnd, inID); } -void T2FloorNumberTable::SetMover(T2Mover*) { +void T2FloorNumberTable::SetMover(T2Mover* inMover) { + mMover = inMover; + InsertRows(mMover->GetLength(), 0, NULL); } -void T2FloorNumberTable::SetMoverModuleTable(T2MoverModuleTable*) { +void T2FloorNumberTable::SetMoverModuleTable(T2MoverModuleTable* inTable) { + mMoverModuleTable = inTable; } int T2FloorNumberTable::GetVScrValue() { + if (mMoverModuleTable) + return mMoverModuleTable->GetVScrValue(); + else + return 0; } -void T2FloorNumberTable::ClickCell(const TableCellT&, POINT) { +void T2FloorNumberTable::ClickCell(const TableCellT& inCell, POINT inPt) { + if (mMover) { + StflNotification info; + info.floorNumber = mRows - inCell.row; + info.theTable = this; + BroadcastMessage('stfl', &info); + } } -void T2FloorNumberTable::RefreshCell(int) { +void T2FloorNumberTable::RefreshCell(int inFloor) { + TableCellT theCell; + theCell.row = mRows - inFloor; + theCell.col = 1; + + RECT cellRect; + if (FetchLocalCellFrame(theCell, cellRect)) + InvalidateRect(&cellRect); } -/*virtual*/ void T2FloorNumberTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2FloorNumberTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + if (mMover) { + RECT cellRect; + if (FetchLocalCellFrame(inCell, cellRect)) { + RECT theDrawArea = mRect; + OffsetRect(&theDrawArea, cellRect.left, cellRect.top); + + T2FloorInfo *theFloorInfo = GetCurrentT2TowerDoc()->towerDoc_vf12C(); + RECT moverArea; + mMover->GetEquipArea(moverArea); + + int floor = mRows - inCell.row; + int floorNum = theFloorInfo->UnitToFloor(moverArea.top + inCell.row); + + char buffer[256]; + sprintf(buffer, "%d", floorNum); + + int saveDC = pDC->SaveDC(); + + CBrush baseBrush; + baseBrush.CreateSolidBrush(RGB(255, 255, 255)); + pDC->SelectObject(baseBrush); + + pDC->SelectStockObject(BLACK_PEN); + + pDC->Rectangle(&moverArea); + pDC->MoveTo(cellRect.left, cellRect.bottom - 1); + pDC->LineTo(cellRect.right - 1, cellRect.bottom - 1); + + InflateRect(&theDrawArea, 1, 1); + pDC->DrawText(buffer, strlen(buffer), &theDrawArea, DT_CENTER | DT_VCENTER | DT_SINGLELINE); + + if (!mMover->IsStopPosition(floor)) { + pDC->SetTextColor(_110); + pDC->MoveTo(theDrawArea.left, theDrawArea.top); + pDC->LineTo(theDrawArea.right - 1, theDrawArea.bottom - 1); + pDC->MoveTo(theDrawArea.left, theDrawArea.bottom - 1); + pDC->LineTo(theDrawArea.right - 1, theDrawArea.top); + } + + pDC->RestoreDC(saveDC); + } + } } -/*virtual*/ int T2FloorNumberTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2FloorNumberTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + RECT theTableRect, cellFrame; + GetClientRect(&theTableRect); + + unsigned int height, width; + GetTableSize(height, width); + + int position = GetVScrValue() * mRowHeight; + + for (unsigned int x = 1; x <= width; x++) { + for (unsigned int y = 1; y <= height; y++) { + TableCellT cell; + cell.row = y; + cell.col = x; + + if (FetchLocalCellFrame(cell, cellFrame)) { + OffsetRect(&cellFrame, 0, -position); + BOOL isVisible = IntersectRect(&cellFrame, &cellFrame, &theTableRect); + if (isVisible) + DrawCellSelf(pDC, cell, false); + } + } + } + + InvalidateRect(&cellFrame); + return true; } -/*virtual*/ void T2FloorNumberTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2FloorNumberTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + POINT pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + ClickCell(cell, inPt); } -/*virtual*/ void T2FloorNumberTable::OnT2DlgItemLButtonUp(unsigned int, CPoint) { +/*virtual*/ void T2FloorNumberTable::OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) { } -/*virtual*/ void T2FloorNumberTable::OnT2DlgItemMouseMove(unsigned int, CPoint) { +/*virtual*/ void T2FloorNumberTable::OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt) { } diff --git a/src/T2DLL/T2FloorNumberTable.h b/src/T2DLL/T2FloorNumberTable.h index cd4d18f..d1a3059 100644 --- a/src/T2DLL/T2FloorNumberTable.h +++ b/src/T2DLL/T2FloorNumberTable.h @@ -1,22 +1,34 @@ #pragma once #include "common.h" +#include "T2DlgItemImageTable.h" -class T2FloorNumberTable { +struct StflNotification { + int floorNumber; + T2FloorNumberTable *theTable; +}; + +class AFX_EXT_CLASS T2FloorNumberTable : public T2DlgItemImageTable { public: - T2FloorNumberTable(T2TowerDoc*, T2ImageObj*, CPalette*); + T2FloorNumberTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2FloorNumberTable(); - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - void SetMover(T2Mover*); - void SetMoverModuleTable(T2MoverModuleTable*); + virtual BOOL Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); + void SetMover(T2Mover* inMover); + void SetMoverModuleTable(T2MoverModuleTable* inTable); + void ClickCell(const TableCellT& inCell, POINT inPt); + void RefreshCell(int inFloor); + protected: + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt); + int GetVScrValue(); -public: - void ClickCell(const TableCellT&, POINT); - void RefreshCell(int); -protected: - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemMouseMove(unsigned int, CPoint); + + RECT mRect; + int _10C; + COLORREF _110; + T2Mover *mMover; + T2MoverModuleTable *mMoverModuleTable; }; diff --git a/src/T2DLL/T2FloorPtrList.cpp b/src/T2DLL/T2FloorPtrList.cpp index b72c96f..f716e76 100644 --- a/src/T2DLL/T2FloorPtrList.cpp +++ b/src/T2DLL/T2FloorPtrList.cpp @@ -1,10 +1,38 @@ #include "T2FloorPtrList.h" +#include "T2Tenant.h" +#include "T2TenantArray.h" +#include "T2TenantArrayList.h" -T2FloorPtrList::T2FloorPtrList(T2TenantArrayList*) { +T2FloorPtrList::T2FloorPtrList(T2TenantArrayList* inList) { + LArrayIterator iterator(*inList); + T2TenantArray *theArray; + + while (iterator.Next(&theArray)) { + for (int i = 0; i < T2TenantArray::kGroupSize; i++) { + T2Tenant *theTenant = theArray->GetIndexTenant(i); + if (theTenant->IsUsed() && theTenant->IsFloor() && theTenant->IsBuildFinish()) + AddItem(theTenant); + } + } } /*virtual*/ T2FloorPtrList::~T2FloorPtrList() { } -int T2FloorPtrList::CalcDistance(int, int) { +int T2FloorPtrList::CalcDistance(int inIndexA, int inIndexB) { + int distance = -1; + T2Tenant *theFloorA = (T2Tenant *) GetItem(inIndexA); + T2Tenant *theFloorB = (T2Tenant *) GetItem(inIndexB); + + if (theFloorA && theFloorB) { + RECT rectA, rectB; + theFloorA->GetEquipArea(rectA); + theFloorB->GetEquipArea(rectB); + + distance = (rectA.bottom - 1) - (rectB.bottom - 1); + if (distance < 0) + distance *= -1; + } + + return distance; } diff --git a/src/T2DLL/T2FloorPtrList.h b/src/T2DLL/T2FloorPtrList.h index 43eb021..4dd02a5 100644 --- a/src/T2DLL/T2FloorPtrList.h +++ b/src/T2DLL/T2FloorPtrList.h @@ -1,12 +1,10 @@ #pragma once #include "common.h" +#include "T2EquipPtrList.h" -class T2FloorPtrList { +class AFX_EXT_CLASS T2FloorPtrList : public T2EquipPtrList { public: - T2FloorPtrList(T2TenantArrayList*); + T2FloorPtrList(T2TenantArrayList* inList); virtual ~T2FloorPtrList(); - int CalcDistance(int, int); - - T2FloorPtrList(const T2FloorPtrList&) {} - T2FloorPtrList& operator=(const T2FloorPtrList&) {} + int CalcDistance(int inIndexA, int inIndexB); }; diff --git a/src/T2DLL/T2GlobalData.cpp b/src/T2DLL/T2GlobalData.cpp index 549230d..2f8c15a 100644 --- a/src/T2DLL/T2GlobalData.cpp +++ b/src/T2DLL/T2GlobalData.cpp @@ -1,28 +1,368 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" #include "T2GlobalData.h" +#include "T2MovieParamArray.h" +#include "T2SerialDialog.h" T2GlobalData::T2GlobalData() { + mChanged = false; + m1stCinemaDate = 0; + mMovieParamArray = NULL; + for (int i = 0; i < 20; i++) + mSerial[i] = 0; + + T2Archive archive; + CString filename = GetTowerDirectory() + "T2Pref.dat"; + if (archive.OpenAsReadMode(filename)) { + Read(archive); + archive.Close(); + } else { + T2SerialDialog *theSerialDialog = new T2SerialDialog(NULL); + if (theSerialDialog->DoModal() == 1) { + theSerialDialog->GetSerial(mSerial); + if (IsCheckSerial()) { + archive.OpenAsWriteMode(filename); + Write(archive); + archive.Close(); + } + } + delete theSerialDialog; + } } /*virtual*/ T2GlobalData::~T2GlobalData() { + if (mChanged) { + T2Archive archive; + CString filename = GetTowerDirectory() + "T2Pref.dat"; + archive.OpenAsWriteMode(filename); + Write(archive); + archive.Close(); + } } -void T2GlobalData::Set1stCinemaDate(int) { +void T2GlobalData::Set1stCinemaDate(int inDate) { + if (m1stCinemaDate == 0) { + m1stCinemaDate = inDate; + mChanged = true; + } } -void T2GlobalData::RegistMovie(unsigned long, int) { +void T2GlobalData::RegistMovie(DWORD inCode, int inValue) { + if (!mMovieParamArray) { + mMovieParamArray = new T2MovieParamArray; + mChanged = true; + } + + if (mMovieParamArray->Regist(inCode, inValue)) + mChanged = true; } -int T2GlobalData::GetMovieParam(unsigned long) { +int T2GlobalData::GetMovieParam(DWORD inCode) { + if (!mMovieParamArray) + return 0; + + return mMovieParamArray->GetParam(inCode); } -void T2GlobalData::Read(T2Archive&) { +void T2GlobalData::Read(T2Archive& inArchive) { + for (int i = 0; i < 20; i++) + inArchive >> mSerial[i]; + + inArchive >> m1stCinemaDate; + mMovieParamArray = T2MovieParamArray::ReadMovieParamArray(inArchive); } -void T2GlobalData::Write(T2Archive&) { +void T2GlobalData::Write(T2Archive& inArchive) { + for (int i = 0; i < 20; i++) + inArchive << mSerial[i]; + + inArchive << m1stCinemaDate; + T2MovieParamArray::WriteMovieParamArray(mMovieParamArray, inArchive); } -int T2GlobalData::IsCheckSerial() { +BOOL T2GlobalData::IsCheckSerial() { + return Check_Serial(mSerial); } -int T2GlobalData::Check_Serial(char*) { +BOOL T2GlobalData::Check_Serial(char* inSerial) { + unsigned short table[256]; + table[0] = 0; + table[1] = 0x1189; + table[2] = 0x2312; + table[3] = 0x329b; + table[4] = 0x4624; + table[5] = 0x57ad; + table[6] = 0x6536; + table[7] = 0x74bf; + table[8] = 0x8c48; + table[9] = 0x9dc1; + table[10] = 0xaf5a; + table[11] = 0xbed3; + table[12] = 0xca6c; + table[13] = 0xdbe5; + table[14] = 0xe97e; + table[15] = 0xf8f7; + table[16] = 0x1081; + table[17] = 0x0108; + table[18] = 0x3393; + table[19] = 0x221a; + table[20] = 0x56a5; + table[21] = 0x472c; + table[22] = 0x75b7; + table[23] = 0x643e; + table[24] = 0x9cc9; + table[25] = 0x8d40; + table[26] = 0xbfdb; + table[27] = 0xae52; + table[28] = 0xdaed; + table[29] = 0xcb64; + table[30] = 0xf9ff; + table[31] = 0xe876; + table[32] = 0x2102; + table[33] = 0x308b; + table[34] = 0x0210; + table[35] = 0x1399; + table[36] = 0x6726; + table[37] = 0x76af; + table[38] = 0x4434; + table[39] = 0x55bd; + table[40] = 0xad4a; + table[41] = 0xbcc3; + table[42] = 0x8e58; + table[43] = 0x9fd1; + table[44] = 0xeb6e; + table[45] = 0xfae7; + table[46] = 0xc87c; + table[47] = 0xd9f5; + table[48] = 0x3183; + table[49] = 0x200a; + table[50] = 0x1291; + table[51] = 0x0318; + table[52] = 0x77a7; + table[53] = 0x662e; + table[54] = 0x54b5; + table[55] = 0x453c; + table[56] = 0xbdcb; + table[57] = 0xac42; + table[58] = 0x9ed9; + table[59] = 0x8f50; + table[60] = 0xfbef; + table[61] = 0xea66; + table[62] = 0xd8fd; + table[63] = 0xc974; + table[64] = 0x4204; + table[65] = 0x538d; + table[66] = 0x6116; + table[67] = 0x709f; + table[68] = 0x0420; + table[69] = 0x15a9; + table[70] = 0x2732; + table[71] = 0x36bb; + table[72] = 0xce4c; + table[73] = 0xdfc5; + table[74] = 0xed5e; + table[75] = 0xfcd7; + table[76] = 0x8868; + table[77] = 0x99e1; + table[78] = 0xab7a; + table[79] = 0xbaf3; + table[80] = 0x5285; + table[81] = 0x430c; + table[82] = 0x7197; + table[83] = 0x601e; + table[84] = 0x14a1; + table[85] = 0x0528; + table[86] = 0x37b3; + table[87] = 0x263a; + table[88] = 0xdecd; + table[89] = 0xcf44; + table[90] = 0xfddf; + table[91] = 0xec56; + table[92] = 0x98e9; + table[93] = 0x8960; + table[94] = 0xbbfb; + table[95] = 0xaa72; + table[96] = 0x6306; + table[97] = 0x728f; + table[98] = 0x4014; + table[99] = 0x519d; + table[100] = 0x2522; + table[101] = 0x34ab; + table[102] = 0x0630; + table[103] = 0x17b9; + table[104] = 0xef4e; + table[105] = 0xfec7; + table[106] = 0xcc5c; + table[107] = 0xddd5; + table[108] = 0xa96a; + table[109] = 0xb8e3; + table[110] = 0x8a78; + table[111] = 0x9bf1; + table[112] = 0x7387; + table[113] = 0x620e; + table[114] = 0x5095; + table[115] = 0x411c; + table[116] = 0x35a3; + table[117] = 0x242a; + table[118] = 0x16b1; + table[119] = 0x0738; + table[120] = 0xffcf; + table[121] = 0xee46; + table[122] = 0xdcdd; + table[123] = 0xcd54; + table[124] = 0xb9eb; + table[125] = 0xa862; + table[126] = 0x9af9; + table[127] = 0x8b70; + table[128] = 0x8408; + table[129] = 0x9581; + table[130] = 0xa71a; + table[131] = 0xb693; + table[132] = 0xc22c; + table[133] = 0xd3a5; + table[134] = 0xe13e; + table[135] = 0xf0b7; + table[136] = 0x0840; + table[137] = 0x19c9; + table[138] = 0x2b52; + table[139] = 0x3adb; + table[140] = 0x4e64; + table[141] = 0x5fed; + table[142] = 0x6d76; + table[143] = 0x7cff; + table[144] = 0x9489; + table[145] = 0x8500; + table[146] = 0xb79b; + table[147] = 0xa612; + table[148] = 0xd2ad; + table[149] = 0xc324; + table[150] = 0xf1bf; + table[151] = 0xe036; + table[152] = 0x18c1; + table[153] = 0x0948; + table[154] = 0x3bd3; + table[155] = 0x2a5a; + table[156] = 0x5ee5; + table[157] = 0x4f6c; + table[158] = 0x7df7; + table[159] = 0x6c7e; + table[160] = 0xa50a; + table[161] = 0xb483; + table[162] = 0x8618; + table[163] = 0x9791; + table[164] = 0xe32e; + table[165] = 0xf2a7; + table[166] = 0xc03c; + table[167] = 0xd1b5; + table[168] = 0x2942; + table[169] = 0x38cb; + table[170] = 0x0a50; + table[171] = 0x1bd9; + table[172] = 0x6f66; + table[173] = 0x7eef; + table[174] = 0x4c74; + table[175] = 0x5dfd; + table[176] = 0xb58b; + table[177] = 0xa402; + table[178] = 0x9699; + table[179] = 0x8710; + table[180] = 0xf3af; + table[181] = 0xe226; + table[182] = 0xd0bd; + table[183] = 0xc134; + table[184] = 0x39c3; + table[185] = 0x284a; + table[186] = 0x1ad1; + table[187] = 0x0b58; + table[188] = 0x7fe7; + table[189] = 0x6e6e; + table[190] = 0x5cf5; + table[191] = 0x4d7c; + table[192] = 0xc60c; + table[193] = 0xd785; + table[194] = 0xe51e; + table[195] = 0xf497; + table[196] = 0x8028; + table[197] = 0x91a1; + table[198] = 0xa33a; + table[199] = 0xb2b3; + table[200] = 0x4a44; + table[201] = 0x5bcd; + table[202] = 0x6956; + table[203] = 0x78df; + table[204] = 0x0c60; + table[205] = 0x1de9; + table[206] = 0x2f72; + table[207] = 0x3efb; + table[208] = 0xd68d; + table[209] = 0xc704; + table[210] = 0xf59f; + table[211] = 0xe416; + table[212] = 0x90a9; + table[213] = 0x8120; + table[214] = 0xb3bb; + table[215] = 0xa232; + table[216] = 0x5ac5; + table[217] = 0x4b4c; + table[218] = 0x79d7; + table[219] = 0x685e; + table[220] = 0x1ce1; + table[221] = 0x0d68; + table[222] = 0x3ff3; + table[223] = 0x2e7a; + table[224] = 0xe70e; + table[225] = 0xf687; + table[226] = 0xc41c; + table[227] = 0xd595; + table[228] = 0xa12a; + table[229] = 0xb0a3; + table[230] = 0x8238; + table[231] = 0x93b1; + table[232] = 0x6b46; + table[233] = 0x7acf; + table[234] = 0x4854; + table[235] = 0x59dd; + table[236] = 0x2d62; + table[237] = 0x3ceb; + table[238] = 0x0e70; + table[239] = 0x1ff9; + table[240] = 0xf78f; + table[241] = 0xe606; + table[242] = 0xd49d; + table[243] = 0xc514; + table[244] = 0xb1ab; + table[245] = 0xa022; + table[246] = 0x92b9; + table[247] = 0x8330; + table[248] = 0x7bc7; + table[249] = 0x6a4e; + table[250] = 0x58d5; + table[251] = 0x495c; + table[252] = 0x3de3; + table[253] = 0x2c6a; + table[254] = 0x1ef1; + table[255] = 0x0f78; + + BOOL isValid = false; + char *start = inSerial; + if (strlen(inSerial) != 16) + return false; + + if (memcmp(inSerial, "1320", 4) != 0) + return false; + + int i = strlen(inSerial) - 4; + unsigned short work = 0xFFFF; + + while (--i >= 0) { + work = (work >> 8) ^ table[((unsigned char) work & 0xFF) ^ *inSerial]; + inSerial++; + } + + if (((work ^ 0xFFFF) % 10000) == atoi(&start[12])) + isValid = true; + else + isValid = false; + + return isValid; } diff --git a/src/T2DLL/T2GlobalData.h b/src/T2DLL/T2GlobalData.h index 5f4f8a3..ae6edce 100644 --- a/src/T2DLL/T2GlobalData.h +++ b/src/T2DLL/T2GlobalData.h @@ -1,23 +1,23 @@ #pragma once #include "common.h" -class T2GlobalData { +class AFX_EXT_CLASS T2GlobalData { public: T2GlobalData(); virtual ~T2GlobalData(); - void Set1stCinemaDate(int); - void RegistMovie(unsigned long, int); - int GetMovieParam(unsigned long); -protected: - void Read(T2Archive&); - void Write(T2Archive&); -public: - int IsCheckSerial(); + void Set1stCinemaDate(int inDate); + void RegistMovie(DWORD inCode, int inValue); + int GetMovieParam(DWORD inCode); + BOOL IsCheckSerial(); + int Get1stCinemaDate() { return m1stCinemaDate; } + protected: - int Check_Serial(char*); + void Read(T2Archive& inArchive); + void Write(T2Archive& inArchive); + BOOL Check_Serial(char* inSerial); -public: - int Get1stCinemaDate() {} - T2GlobalData(const T2GlobalData&) {} - T2GlobalData& operator=(const T2GlobalData&) {} + BOOL mChanged; + int m1stCinemaDate; + T2MovieParamArray *mMovieParamArray; + char mSerial[20]; }; diff --git a/src/T2DLL/T2GuestroomTable.cpp b/src/T2DLL/T2GuestroomTable.cpp index e7dbf5b..4458d0f 100644 --- a/src/T2DLL/T2GuestroomTable.cpp +++ b/src/T2DLL/T2GuestroomTable.cpp @@ -1,115 +1,420 @@ #include "T2GuestroomTable.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" -/*virtual*/ int T2GuestroomTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2GuestroomTable::OnT2DlgItemCreate(CREATESTRUCT* cs) { + return T2DlgItemTable::OnT2DlgItemCreate(cs); } -T2GuestroomTable::T2GuestroomTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2GuestroomTable::T2GuestroomTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2VerticalTable(inDoc, inImageObj, inPalette) +{ + mClearBackground = true; + + SetCellDataSize(sizeof(T2GuestroomItem *)); + InsertCols(1, 0, NULL); + SetHScrollerStyle(AlwaysHide); + SetVScrollerStyle(AlwaysShow); + + mClickTime = 0; } /*virtual*/ T2GuestroomTable::~T2GuestroomTable() { + T2GuestroomItem *item; + + while (mArray.FetchItemAt(1, &item)) { + delete item; + mArray.RemoveItemsAt(1, 1); + } +} + +/*virtual*/ void T2GuestroomTable::Add(T2GuestroomItem* inItem) { + unsigned int index = mRows; + InsertRows(1, index, &inItem); +} + +/*virtual*/ void T2GuestroomTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + DrawCell(pDC, inCell); +} + +/*virtual*/ void T2GuestroomTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + CFont numberFont; + CFont statusFont; + + int savedDC = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + RECT cellRect; + if (FetchLocalCellFrame(inCell, cellRect)) { + T2GuestroomItem *item; + GetCellData(inCell, &item); + if (item) { + CString str; + + int numberFontWeight = FW_DONTCARE; + if (item->IsRelation()) + numberFontWeight = FW_BOLD; + + numberFont.CreateFont(-9, 0, 0, 0, numberFontWeight, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, DEFAULT_PITCH, "Terminal"); + pDC->SelectObject(&numberFont); + pDC->SetBkMode(TRANSPARENT); + + int roomNum = item->GetRoomNumber(); + if (roomNum < 0) + str.Format("B%d", 0 - roomNum); + else + str.Format("%d", roomNum); + + pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, str, strlen(str)); + + COLORREF colorArray[4]; + colorArray[0] = RGB(29, 29, 255); + colorArray[1] = RGB(255, 0, 0); + colorArray[2] = RGB(235, 0, 235); + colorArray[3] = RGB(0, 0, 0); + int col = 3; + + if (item->IsFreeRelation()) { + // "未接続" - disconnected + str = "\x96\xA2\x90\xDA\x91\xB1"; + } else { + switch (item->GetRoomStatus()) { + case kTenantStatus31: + col = 0; + // "予約済み" - Reserved + str = "\x97\x5C\x96\xF1\x8D\xCF\x82\xDD"; + break; + case kTenantStatus32: + case kTenantStatus33: + case kTenantStatus34: + col = 0; + // "宿泊中" - staying + str = "\x8F\x68\x94\x91\x92\x86"; + break; + case kTenantStatus35: + case kTenantStatus36: + case kTenantStatus37: + col = 1; + // "未メンテ" - unmaintained + str = "\x96\xA2\x83\x81\x83\x93\x83\x65"; + break; + case kTenantStatus38: + col = 2; + // "ゴキブリ" - cockroach + str = "\x83\x53\x83\x4C\x83\x75\x83\x8A"; + break; + default: + str = ""; + } + } + + statusFont.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + pDC->SelectObject(&statusFont); + pDC->SetTextColor(colorArray[col]); + pDC->SetBkMode(TRANSPARENT); + pDC->TextOut(cellRect.left + 40, cellRect.bottom - 12, str, strlen(str)); + } + } + + pDC->RestoreDC(savedDC); +} + +/*virtual*/ void T2GuestroomTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) { + T2DlgItemTable::ClickCell(inCell, inPt); + + if (IsValidCell(mSelectedCell)) { + T2GuestroomItem *item; + GetCellData(mSelectedCell, &item); + if (item) { + DWORD time = GetTickCount(); + if ((time - mClickTime) < GetDoubleClickTime()) + BroadcastMessage(0xFFFFE40C, NULL); + else + BroadcastMessage(-GetDlgCtrlID(), item); + mClickTime = time; + } + } +} + +/*virtual*/ void T2GuestroomTable::AddList(T2Tenant* inTenant, int inRoomNumber) { + T2GuestroomItem *item = new T2GuestroomItem(inTenant, mFront, inRoomNumber); + if (item) + mArray.InsertItemsAt(1, mArray.GetCount() + 1, &item); } -/*virtual*/ void T2GuestroomTable::Add(T2GuestroomItem*) { -} +/*virtual*/ void T2GuestroomTable::ValidRelation() { + LArrayIterator iterator(mArray); + T2GuestroomItem *item; -/*virtual*/ void T2GuestroomTable::DrawCellSelf(CDC*, const TableCellT&, int) { + while (iterator.Next(&item)) { + if (item->IsRelation()) + item->ValidRelation(); + else if (item->WasRelation()) + item->InvalidRelation(); + } } -/*virtual*/ void T2GuestroomTable::DrawCell(CDC*, const TableCellT&) { -} +/*virtual*/ void T2GuestroomTable::RevertRelation() { + LArrayIterator iterator(mArray); + T2GuestroomItem *item; -/*virtual*/ void T2GuestroomTable::ClickCell(const TableCellT&, const CPoint&) { + while (iterator.Next(&item)) { + item->RevertRelation(); + } } -/*virtual*/ void T2GuestroomTable::AddList(T2Tenant*, int) { -} +/*virtual*/ void T2GuestroomTable::ResetRoomList(int inRoomType) { + Clear(); -/*virtual*/ void T2GuestroomTable::ValidRelation() { -} + int what = (inRoomType == 0) ? 1 : (inRoomType * 2); -/*virtual*/ void T2GuestroomTable::RevertRelation() { -} + LArrayIterator iterator(mArray); + T2GuestroomItem *item; -/*virtual*/ void T2GuestroomTable::ResetRoomList(int) { + while (iterator.Next(&item)) { + if (item->GetRoomType() == inRoomType) + Add(item); + } + + Invalidate(false); } -/*virtual*/ int T2GuestroomTable::CountRooms(int, int) { +/*virtual*/ int T2GuestroomTable::CountRooms(int inRoomType, int inRoomStatus) { + int count = 0; + LArrayIterator iterator(mArray); + T2GuestroomItem *item; + + while (iterator.Next(&item)) { + if (item->IsRelation() && item->GetRoomType() == inRoomType) { + if (inRoomStatus == 0 || item->GetRoomStatus() == inRoomStatus) + count++; + } + } + + return count; } -/*virtual*/ void T2GuestroomTable::ToggleRelation(const TableCellT&, int) { +/*virtual*/ void T2GuestroomTable::ToggleRelation(const TableCellT& inCell, int inMoneyIndex) { + T2GuestroomItem *item; + GetCellData(inCell, &item); + + if (item) + item->ToggleRelation(inMoneyIndex); } -/*virtual*/ void T2GuestroomTable::SetInMoneyIndex(int) { +/*virtual*/ void T2GuestroomTable::SetInMoneyIndex(int inMoneyIndex) { + T2GuestroomItem *item; + TableCellT theCell; + theCell.row = 1; + theCell.col = 1; + + for (unsigned int i = 1; i <= mRows; i++) { + theCell.row = i; + GetCellData(theCell, &item); + + if (item && item->IsRelation() && !item->IsStay()) + item->SetInMoneyIndex(inMoneyIndex); + } } -/*virtual*/ int T2GuestroomTable::GetInMoneyIndex(int) { +/*virtual*/ int T2GuestroomTable::GetInMoneyIndex(int inRoomType) { + int moneyIndex = 0; + LArrayIterator iterator(mArray); + T2GuestroomItem *item; + + while (iterator.Next(&item)) { + if (item->GetRoomType() == inRoomType) { + if (item->IsRelation()) + return item->GetInMoneyIndex(); + + if (moneyIndex == 0) { + T2Tenant *theTenant = item->GetTenant(); + T2EquipDef *theDef = theTenant ? theTenant->GetEquipDef() : NULL; + if (theDef) { + moneyIndex = theDef->GetNumOfInMoney(); + moneyIndex = (moneyIndex > 1) ? ((moneyIndex / 2) + 1) : 1; + } + } + } + } + + return (moneyIndex > 0) ? moneyIndex : 1; } -/*virtual*/ int T2GuestroomTable::CalcInMoney(int) { +/*virtual*/ int T2GuestroomTable::CalcInMoney(int inRoomType) { + int result = 0; + LArrayIterator iterator(mArray); + T2GuestroomItem *item; + + while (iterator.Next(&item)) { + if (item->IsRelation() && item->GetRoomType() == inRoomType) { + switch (item->GetRoomStatus()) { + case kTenantStatus31: + case kTenantStatus32: + case kTenantStatus33: + case kTenantStatus34: + result += item->GetInMoney(); + break; + } + } + } + + return result; } -void T2GuestroomTable::UpdateTenantEstimation(T2TowerDoc*, int) { +void T2GuestroomTable::UpdateTenantEstimation(T2TowerDoc* inDoc, int inRoomType) { + LArrayIterator iterator(mArray); + T2GuestroomItem *item; + + while (iterator.Next(&item)) { + if (inRoomType == -1 || item->GetRoomType() == inRoomType) + item->UpdateTenantEstimation(inDoc); + } } -/*virtual*/ void T2GuestroomTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2GuestroomTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + CPoint pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + + if (IsValidCell(cell)) + ClickCell(cell, inPt); } -/*virtual*/ int T2GuestroomTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2GuestroomTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC); + + unsigned int numOfRows, numOfColumns, theRow, theColumn; + + GetTableSize(numOfRows, numOfColumns); + for (theColumn = 1; theColumn <= numOfColumns; theColumn++) { + for (theRow = 1; theRow <= numOfRows; theRow++) { + TableCellT cell; + cell.row = theRow; + cell.col = theColumn; + DrawCell(pDC, cell); + } + } + + T2DlgItemTable::HiliteCell(pDC, mSelectedCell); + return true; } -T2GuestroomItem::T2GuestroomItem(T2Tenant*, int, long) { + + +T2GuestroomItem::T2GuestroomItem(T2Tenant* inTenant, int inSaveTenantID, long inRoomNumber) { + mTenant = inTenant; + mSaveTenantID = inSaveTenantID; + mRoomNumber = inRoomNumber; + mRelation = WasRelation(); + mDefaultInMoneyIndex = inTenant->GetInMoneyIndex() + 1; } int T2GuestroomItem::GetRoomNumber() { + return mRoomNumber; } int T2GuestroomItem::GetRoomStatus() { + return mTenant->GetStatus(); } int T2GuestroomItem::GetCapacity() { + return mTenant->GetCapacity(); } int T2GuestroomItem::GetRoomType() { + return GetRoomType(mTenant); } -/*static*/ int T2GuestroomItem::GetRoomType(T2Tenant*) { +/*static*/ int T2GuestroomItem::GetRoomType(T2Tenant* inTenant) { + int result = -1; + + T2EquipDef *theEquipDef = inTenant->GetEquipDef(); + if (theEquipDef) { + switch (theEquipDef->GetToolType()) { + case 1401: + result = 0; + break; + case 1402: + result = 1; + break; + case 1403: + result = 2; + break; + case 1481: + result = 0; + break; + case 1482: + result = 1; + break; + } + } + + return result; } -void T2GuestroomItem::ToggleRelation(int) { +void T2GuestroomItem::ToggleRelation(int inMoneyIndex) { + mRelation = !mRelation; + SetInMoneyIndex(mRelation ? inMoneyIndex : mDefaultInMoneyIndex); } -int T2GuestroomItem::IsRelation() { +BOOL T2GuestroomItem::IsRelation() { + return mRelation; } -int T2GuestroomItem::WasRelation() { +BOOL T2GuestroomItem::WasRelation() { + return mTenant->GetRelatedTenantID() == mSaveTenantID; } void T2GuestroomItem::ValidRelation() { + mTenant->SetRelatedTenantID(mSaveTenantID); } void T2GuestroomItem::InvalidRelation() { + mTenant->SetRelatedTenantID(0); } void T2GuestroomItem::RevertRelation() { + SetInMoneyIndex(mDefaultInMoneyIndex); } -int T2GuestroomItem::IsFreeRelation() { +BOOL T2GuestroomItem::IsFreeRelation() { + return !IsRelation() && (WasRelation() || mTenant->GetRelatedTenantID() == 0); } -int T2GuestroomItem::IsStay() { +BOOL T2GuestroomItem::IsStay() { + return mTenant->GetTotalBelong() > 0; } -void T2GuestroomItem::SetInMoneyIndex(int) { +void T2GuestroomItem::SetInMoneyIndex(int inIndex) { + mTenant->SetInMoneyIndex((inIndex < 1) ? 0 : (inIndex - 1)); } int T2GuestroomItem::GetInMoneyIndex() { + return mTenant->GetInMoneyIndex() + 1; } int T2GuestroomItem::GetInMoney() { + return mTenant->IsTherePeople() ? mTenant->GetInMoney() : 0; } int T2GuestroomItem::GetOutMoney() { + return mTenant->GetOutMoney(); } -void T2GuestroomItem::UpdateTenantEstimation(T2TowerDoc*) { +void T2GuestroomItem::UpdateTenantEstimation(T2TowerDoc* inDoc) { + BOOL isChanged = mTenant->UpdateResidencialEstimate(inDoc); + int viewMode = inDoc->towerDoc_vf140(); + if ((viewMode == ViewMode_2 && isChanged) || (viewMode == ViewMode_3)) { + mTenant->SetDrawMode(DrawMode1); + + RECT rect; + mTenant->GetEquipArea(rect); + inDoc->GetTowerMainView()->tmv_vf128(rect); + } } diff --git a/src/T2DLL/T2GuestroomTable.h b/src/T2DLL/T2GuestroomTable.h index 5b515da..621cf9d 100644 --- a/src/T2DLL/T2GuestroomTable.h +++ b/src/T2DLL/T2GuestroomTable.h @@ -1,57 +1,66 @@ #pragma once #include "common.h" +#include "LArray.h" +#include "T2VerticalTable.h" -class T2GuestroomTable { -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); +class AFX_EXT_CLASS T2GuestroomTable : T2VerticalTable { public: - T2GuestroomTable(T2TowerDoc*, T2ImageObj*, CPalette*); + T2GuestroomTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2GuestroomTable(); - virtual void Add(T2GuestroomItem*); -protected: - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual void DrawCell(CDC*, const TableCellT&); - virtual void ClickCell(const TableCellT&, const CPoint&); -public: - virtual void AddList(T2Tenant*, int); + virtual void Add(T2GuestroomItem* inItem); + virtual void AddList(T2Tenant* inTenant, int inRoomNumber); + virtual void SetFront(unsigned int inFront) { mFront = inFront; } + virtual void ResetRoomList(int inRoomType); virtual void ValidRelation(); virtual void RevertRelation(); - virtual void ResetRoomList(int); - virtual int CountRooms(int, int); - virtual void ToggleRelation(const TableCellT&, int); - virtual void SetInMoneyIndex(int); - virtual int GetInMoneyIndex(int); - virtual int CalcInMoney(int); - void UpdateTenantEstimation(T2TowerDoc*, int); + virtual int CountRooms(int inRoomType, int inRoomStatus); + virtual void ToggleRelation(const TableCellT& inCell, int inMoneyIndex); + virtual void SetInMoneyIndex(int inMoneyIndex); + virtual int GetInMoneyIndex(int inRoomType); + virtual int CalcInMoney(int inRoomType); + void UpdateTenantEstimation(T2TowerDoc* inDoc, int inRoomType); + protected: - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + virtual void ClickCell(const TableCellT& inCell, const CPoint& inPt); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); -public: - virtual void SetFront(unsigned int) {} + unsigned int mFront; + LArray mArray; + DWORD mClickTime; }; -class T2GuestroomItem { + +class AFX_EXT_CLASS T2GuestroomItem { public: - T2GuestroomItem(T2Tenant*, int, long); + T2GuestroomItem(T2Tenant* inTenant, int inSaveTenantID, long inRoomNumber); int GetRoomNumber(); int GetRoomStatus(); int GetCapacity(); int GetRoomType(); - static int GetRoomType(T2Tenant*); - void ToggleRelation(int); - int IsRelation(); - int WasRelation(); + static int GetRoomType(T2Tenant* inTenant); + void ToggleRelation(int inMoneyIndex); + BOOL IsRelation(); + BOOL WasRelation(); void ValidRelation(); void InvalidRelation(); void RevertRelation(); - int IsFreeRelation(); - int IsStay(); - void SetInMoneyIndex(int); + BOOL IsFreeRelation(); + BOOL IsStay(); + void SetInMoneyIndex(int inIndex); int GetInMoneyIndex(); int GetInMoney(); int GetOutMoney(); - void UpdateTenantEstimation(T2TowerDoc*); + void UpdateTenantEstimation(T2TowerDoc* inDoc); - T2Tenant* GetTenant() {} - T2GuestroomItem& operator=(const T2GuestroomItem&) {} + T2Tenant* GetTenant() { return mTenant; } + +protected: + T2Tenant *mTenant; + unsigned int mSaveTenantID; + int mRoomNumber; + BOOL mRelation; + int mDefaultInMoneyIndex; }; diff --git a/src/T2DLL/T2HallEventPlugin.cpp b/src/T2DLL/T2HallEventPlugin.cpp index 8001663..b75e4ff 100644 --- a/src/T2DLL/T2HallEventPlugin.cpp +++ b/src/T2DLL/T2HallEventPlugin.cpp @@ -1,16 +1,72 @@ +#include "CResFile.h" +#include "T2BitImage.h" #include "T2HallEventPlugin.h" +#include "T2ImageObj.h" -T2HallEventPlugin::T2HallEventPlugin(unsigned long, T2PluginSpecifier&) { +T2HallEventPlugin::T2HallEventPlugin(DWORD inType, T2PluginSpecifier& inSpecifier) + : T2SubPlugin(inType, inSpecifier) +{ + mCC = 0; + mD0 = 0; + _F0 = 0; + mF4 = 0; + mResID = 0; } /*virtual*/ T2HallEventPlugin::~T2HallEventPlugin() { } -/*virtual*/ void T2HallEventPlugin::LoadRsrcFromStream(CResFile&) { +/*virtual*/ void T2HallEventPlugin::LoadRsrcFromStream(CResFile& inResFile) { + T2SubPlugin::LoadRsrcFromStream(inResFile); + + inResFile >> mResID; + inResFile >> mCC; + inResFile >> mD0; + inResFile >> mOpenTime; + inResFile >> mCloseTime; + inResFile >> mD4; + inResFile >> mD8; + + unsigned short us; + inResFile >> us; + mDupCustomerTableDefRes = us; + + inResFile >> mDC; + inResFile >> mE0; + inResFile >> mE4; + inResFile >> mBindTime; + inResFile >> mF4; + inResFile >> mF8; + inResFile >> mEC; } void T2HallEventPlugin::UnfoldPluginSelf() { + if (mResID) { + mImage = new T2BitImage(mSpecifier.mPath, mResID, true); + mImageObj = new T2ImageObj; + + int width = mImage->mBitmap.header.biWidth; + int height = mImage->mBitmap.header.biHeight; + if (height < 0) + height = 0 - height; + height /= 4; + + CRect rect(0, 0, width, height); + for (int n = 0; n < 4; n++) { + mImageObj->AddObject("SCRE", 200 + n, *mImage, &rect, false, false); + rect.OffsetRect(0, height); + } + } } -/*virtual*/ unsigned long T2HallEventPlugin::LoadSelf() { +/*virtual*/ DWORD T2HallEventPlugin::LoadSelf() { + DWORD result = 0; + CResFile resFile; + + if (resFile.OpenResource(mSpecifier.mPath, 128, 'HEDF')) + LoadRsrcFromStream(resFile); + else + result = 0xFFFFFFFF; + + return result; } diff --git a/src/T2DLL/T2HallEventPlugin.h b/src/T2DLL/T2HallEventPlugin.h index 61cafdd..29e6859 100644 --- a/src/T2DLL/T2HallEventPlugin.h +++ b/src/T2DLL/T2HallEventPlugin.h @@ -1,17 +1,45 @@ #pragma once #include "common.h" +#include "T2SubPlugin.h" -class T2HallEventPlugin { +class AFX_EXT_CLASS T2HallEventItem { public: - T2HallEventPlugin(unsigned long, T2PluginSpecifier&); - virtual ~T2HallEventPlugin(); -protected: - virtual void LoadRsrcFromStream(CResFile&); + T2HallEventItem(T2HallEventPlugin *inPlugin, const char *inStr) { + mPlugin = inPlugin; + if (inStr) + strcpy(mStr, inStr); + else + mStr[0] = 0; + } + virtual ~T2HallEventItem() {} + + T2HallEventPlugin *mPlugin; + char mStr[64]; +}; + +class AFX_EXT_CLASS T2HallEventPlugin : public T2SubPlugin { public: + T2HallEventPlugin(DWORD inType, T2PluginSpecifier& inSpecifier); + virtual ~T2HallEventPlugin(); void UnfoldPluginSelf(); - virtual unsigned long LoadSelf(); + unsigned int GetRsrcType() { return 'HeDf'; } + virtual int GetBindTime() { return mBindTime; } + virtual DWORD LoadSelf(); + +protected: + virtual void LoadRsrcFromStream(CResFile& inResFile); - unsigned int GetRsrcType() {} - virtual int GetBindTime() {} - T2HallEventPlugin& operator=(T2HallEventPlugin&) {} + unsigned short mResID; + unsigned int mCC; + unsigned int mD0; + unsigned int mD4; + int mD8; + int mDC; + int mE0; + int mE4; + int mBindTime; + CString mEC; + int _F0; + int mF4; + CString mF8; }; diff --git a/src/T2DLL/T2HallEventTable.cpp b/src/T2DLL/T2HallEventTable.cpp index d77a1a9..b522ed2 100644 --- a/src/T2DLL/T2HallEventTable.cpp +++ b/src/T2DLL/T2HallEventTable.cpp @@ -1,64 +1,273 @@ +#include "CFilePluginList.h" +#include "T2DateTime.h" #include "T2HallEventTable.h" +#include "T2HallEventPlugin.h" +#include "T2TowerDoc.h" -/*virtual*/ int T2HallEventTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2HallEventTable::OnT2DlgItemCreate(CREATESTRUCT* cs) { + T2DlgItemTable::SetColWidth(cs->cx, 0, 0); + return T2DlgItemTable::OnT2DlgItemCreate(cs); } -T2HallEventTable::T2HallEventTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2HallEventTable::T2HallEventTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2VerticalTable(inDoc, inImageObj, inPalette) +{ + mClearBackground = true; + mUserCon = 0; + + SetCellDataSize(sizeof(T2HallEventItem *)); + InsertCols(1, 0, NULL); + SetHScrollerStyle(AlwaysHide); + SetVScrollerStyle(AlwaysHide); } /*virtual*/ T2HallEventTable::~T2HallEventTable() { + T2HallEventItem *item; + TableCellT theCell; + theCell.row = 0; + theCell.col = 1; + + for (unsigned int i = 1; i <= mRows; i++) { + theCell.row = i; + GetCellData(theCell, &item); + delete item; + } } -/*virtual*/ void T2HallEventTable::Add(T2HallEventPlugin*) { +/*virtual*/ void T2HallEventTable::Add(T2HallEventPlugin* inPlugin) { + unsigned int index = mRows; + T2HallEventItem *item = new T2HallEventItem(inPlugin, NULL); + InsertRows(1, index, &item); } -/*virtual*/ void T2HallEventTable::Add(const char*) { +/*virtual*/ void T2HallEventTable::Add(const char* inStr) { + unsigned int index = mRows; + T2HallEventItem *item = new T2HallEventItem(NULL, inStr); + InsertRows(1, index, &item); + + if (mUserCon) + SetVScrollerStyle(AlwaysShow); } -/*virtual*/ void T2HallEventTable::Add(CFilePluginList*) { +/*virtual*/ void T2HallEventTable::Add(CFilePluginList* inList) { + T2HallEventPlugin *thePlugin; + T2HallEventItem *item; + unsigned int index = mRows; + POSITION pos = inList->GetHeadPosition(); + + while (pos) { + thePlugin = (T2HallEventPlugin *) inList->GetNext(pos); + item = new T2HallEventItem(thePlugin, NULL); + InsertRows(1, index, &item); + index++; + } } -/*virtual*/ void T2HallEventTable::SetCellData(const TableCellT&, T2HallEventPlugin*, const char*) { +/*virtual*/ void T2HallEventTable::SetCellData(const TableCellT& inCell, T2HallEventPlugin* inPlugin, const char* inStr) { + T2HallEventItem *item; + GetCellData(inCell, &item); + + if (item) { + item->mPlugin = inPlugin; + strcpy(item->mStr, inStr); + } } -/*virtual*/ void T2HallEventTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2HallEventTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + DrawCell(pDC, inCell); } -/*virtual*/ void T2HallEventTable::DrawCell(CDC*, const TableCellT&) { +/*virtual*/ void T2HallEventTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CFont font; + RECT cellRect; + + if (FetchLocalCellFrame(inCell, cellRect)) { + CString title; + T2HallEventItem *item; + T2HallEventPlugin *thePlugin; + GetCellData(inCell, &item); + if (item) { + thePlugin = item->mPlugin; + if (thePlugin) + thePlugin->GetTitle(title); + else + title = item->mStr; + } + + font.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + pDC->SelectObject(&font); + pDC->SetBkMode(TRANSPARENT); + pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, title, strlen(title)); + + if (GetUserCon() == 0) { + if (inCell.row < 12) + cellRect.bottom++; + + CBrush brush; + brush.CreateSolidBrush(RGB(0, 0, 0)); + pDC->FrameRect(&cellRect, &brush); + } + } + + pDC->RestoreDC(save); } -/*virtual*/ void T2HallEventTable::ClickCell(const TableCellT&, const CPoint&) { +/*virtual*/ void T2HallEventTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) { + T2DlgItemTable::ClickCell(inCell, inPt); + + if (IsValidCell(mSelectedCell)) { + T2HallEventItem *item; + GetCellData(mSelectedCell, &item); + + T2HallEventPlugin *thePlugin = item ? item->mPlugin : NULL; + BroadcastMessage(-GetDlgCtrlID(), thePlugin); + } } -/*virtual*/ void T2HallEventTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2HallEventTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + CPoint pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + + if (IsValidCell(cell)) + ClickCell(cell, inPt); } -/*virtual*/ int T2HallEventTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2HallEventTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC); + + unsigned int numOfRows, numOfColumns, theRow, theColumn; + + GetTableSize(numOfRows, numOfColumns); + for (theColumn = 1; theColumn <= numOfColumns; theColumn++) { + for (theRow = 1; theRow <= numOfRows; theRow++) { + TableCellT cell; + cell.row = theRow; + cell.col = theColumn; + DrawCell(pDC, cell); + } + } + + T2DlgItemTable::HiliteCell(pDC, mSelectedCell); + return true; } -/*virtual*/ int T2MonthlyTable::OnT2DlgItemCreate(CREATESTRUCTA*) { + + +/*virtual*/ int T2MonthlyTable::OnT2DlgItemCreate(CREATESTRUCT* cs) { + return T2DlgItemTable::OnT2DlgItemCreate(cs); } -T2MonthlyTable::T2MonthlyTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2MonthlyTable::T2MonthlyTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2VerticalTable(inDoc, inImageObj, inPalette) +{ + mStartMonth = 1; + + SetCellDataSize(sizeof(int)); + InsertCols(1, 0, NULL); + int zero = 0; + InsertRows(12, mRows, &zero); + + SetHScrollerStyle(AlwaysHide); + SetVScrollerStyle(AlwaysHide); } /*virtual*/ T2MonthlyTable::~T2MonthlyTable() { } -void T2MonthlyTable::SetStartMonth(T2TowerDoc*, int) { +void T2MonthlyTable::SetStartMonth(T2TowerDoc* inDoc, int inMonth) { + mStartMonth = inMonth; + + T2DateTime *theNow = inDoc->towerDoc_vf120(); + T2DateTime date = *theNow; + + int months = 12; + for (int month = 0; month < 12; month++) { + date.mMonth = month + mStartMonth - 1; + if (date.mMonth >= 12) { + date.mYear = theNow->mYear + 1; + date.mMonth -= 12; + } + + mIsHoliday[month] = date.IsHoliday(inDoc); + } } -/*virtual*/ void T2MonthlyTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2MonthlyTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + DrawCell(pDC, inCell); } -/*virtual*/ void T2MonthlyTable::DrawCell(CDC*, const TableCellT&) { +/*virtual*/ void T2MonthlyTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CFont font; + RECT cellRect; + + if (FetchLocalCellFrame(inCell, cellRect)) { + int n = (inCell.row - 1) + mStartMonth; + CString str; + str.Format("%d", (n > 12) ? (n - 12) : n); + + if (mIsHoliday[inCell.row - 1]) + pDC->FillSolidRect(&cellRect, RGB(255, 152, 152)); + + font.CreateFont(-9, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + pDC->SelectObject(&font); + pDC->SetBkMode(TRANSPARENT); + pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, str, strlen(str)); + + if (inCell.row < 12) + cellRect.bottom++; + + CBrush brush; + brush.CreateSolidBrush(RGB(0, 0, 0)); + pDC->FrameRect(&cellRect, &brush); + } + + pDC->RestoreDC(save); } -void T2MonthlyTable::ClickCell(const TableCellT&, const CPoint&) { +void T2MonthlyTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) { + TableCellT cell; + cell.row = 0; + cell.col = 0; + SelectCell(cell); } -/*virtual*/ void T2MonthlyTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2MonthlyTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + CPoint pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + + if (IsValidCell(cell)) + ClickCell(cell, inPt); } -/*virtual*/ int T2MonthlyTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2MonthlyTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC); + + unsigned int numOfRows, numOfColumns, theRow, theColumn; + + GetTableSize(numOfRows, numOfColumns); + for (theColumn = 1; theColumn <= numOfColumns; theColumn++) { + for (theRow = 1; theRow <= numOfRows; theRow++) { + TableCellT cell; + cell.row = theRow; + cell.col = theColumn; + DrawCell(pDC, cell); + } + } + + return true; } diff --git a/src/T2DLL/T2HallEventTable.h b/src/T2DLL/T2HallEventTable.h index d46219f..99ec0bf 100644 --- a/src/T2DLL/T2HallEventTable.h +++ b/src/T2DLL/T2HallEventTable.h @@ -1,39 +1,42 @@ #pragma once #include "common.h" +#include "T2VerticalTable.h" -class T2HallEventTable { -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); +class AFX_EXT_CLASS T2HallEventTable : public T2VerticalTable { public: - T2HallEventTable(T2TowerDoc*, T2ImageObj*, CPalette*); + T2HallEventTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2HallEventTable(); - virtual void Add(T2HallEventPlugin*); - virtual void Add(const char*); - virtual void Add(CFilePluginList*); - virtual void SetCellData(const TableCellT&, T2HallEventPlugin*, const char*); + virtual void Add(T2HallEventPlugin* inPlugin); + virtual void Add(CFilePluginList* inList); + virtual void Add(const char* inStr); + virtual void SetCellData(const TableCellT& inCell, T2HallEventPlugin* inPlugin, const char* inStr); + void SetUserCon(int inUserCon) { mUserCon = inUserCon; } protected: - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual void DrawCell(CDC*, const TableCellT&); - virtual void ClickCell(const TableCellT&, const CPoint&); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + virtual void ClickCell(const TableCellT& inCell, const CPoint& inPt); + int GetUserCon() { return mUserCon; } -public: - void SetUserCon(int) {} -protected: - int GetUserCon() {} + int mUserCon; }; -class T2MonthlyTable { -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); + +class AFX_EXT_CLASS T2MonthlyTable : public T2VerticalTable { public: - T2MonthlyTable(T2TowerDoc*, T2ImageObj*, CPalette*); + T2MonthlyTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2MonthlyTable(); - void SetStartMonth(T2TowerDoc*, int); + void SetStartMonth(T2TowerDoc* inDoc, int inMonth); + protected: - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual void DrawCell(CDC*, const TableCellT&); - void ClickCell(const TableCellT&, const CPoint&); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + void ClickCell(const TableCellT& inCell, const CPoint& inPt); + + int mStartMonth; + BOOL mIsHoliday[12]; }; diff --git a/src/T2DLL/T2HaveOutViewObject.cpp b/src/T2DLL/T2HaveOutViewObject.cpp index 992d575..1b24415 100644 --- a/src/T2DLL/T2HaveOutViewObject.cpp +++ b/src/T2DLL/T2HaveOutViewObject.cpp @@ -39,11 +39,11 @@ void T2HaveOutViewObject::SetToolDef(T2ToolDef* toolDef) { /*virtual*/ void T2HaveOutViewObject::DrawOutView(T2TowerDoc*, const RECT&) { } -/*virtual*/ void T2HaveOutViewObject::SetUsed(int used) { - T2Object::SetUsed(used); +/*virtual*/ void T2HaveOutViewObject::SetUsed(BOOL inUsed) { + T2Object::SetUsed(inUsed); if (GetToolDef()) { - if (used) + if (inUsed) GetToolDef()->DoStartUse(); else GetToolDef()->DoEndUse(); diff --git a/src/T2DLL/T2HaveOutViewObject.h b/src/T2DLL/T2HaveOutViewObject.h index f0508a5..a035fa1 100644 --- a/src/T2DLL/T2HaveOutViewObject.h +++ b/src/T2DLL/T2HaveOutViewObject.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2DrawableObject.h" -class T2HaveOutViewObject : public T2DrawableObject { +class AFX_EXT_CLASS T2HaveOutViewObject : public T2DrawableObject { public: T2HaveOutViewObject(); virtual ~T2HaveOutViewObject(); @@ -18,12 +18,12 @@ public: unsigned int GetValiation() const { return mValiation; } -protected: - virtual void SetUsed(int); - virtual void InitLoaded(); - T2ToolDef *mToolDef; int mRefCon; CResourcePlugin *mSubPlugin; unsigned int mValiation; + +protected: + virtual void SetUsed(BOOL inUsed); + virtual void InitLoaded(); }; diff --git a/src/T2DLL/T2ImageObj.cpp b/src/T2DLL/T2ImageObj.cpp index cea6308..08ae773 100644 --- a/src/T2DLL/T2ImageObj.cpp +++ b/src/T2DLL/T2ImageObj.cpp @@ -286,7 +286,7 @@ void T2ImageObj::EnumParts(int index, int width, PARTSLIST* outParts, int* outCo } else if (mData[index].subParts[i].flags & SPD_PARTS_BY_ID) { // Search for an object and include its part list int prevCount = *outCount; - EnumParts(FindObject(mData[index].subParts[i].objectID, -1, 0, 0, 255), width, outParts, outCount); + EnumParts(FindObject(mData[index].subParts[i].objectID), width, outParts, outCount); for (; prevCount < *outCount; prevCount++) width -= (outParts[prevCount].rect.right - outParts[prevCount].rect.left); } diff --git a/src/T2DLL/T2ImageObj.h b/src/T2DLL/T2ImageObj.h index b954df8..a2cde9d 100644 --- a/src/T2DLL/T2ImageObj.h +++ b/src/T2DLL/T2ImageObj.h @@ -46,20 +46,20 @@ struct ObjectData { SubPartData subParts[4]; }; -class DLL_EXPORT T2ImageObj { +class AFX_EXT_CLASS T2ImageObj { public: T2ImageObj(); virtual ~T2ImageObj(); void AddObject(HINSTANCE instance, unsigned int resourceID, T2BitImage* image); void AddObject(const char* name, int pattern, T2BitImage& image, const RECT* rect, BOOL transparent, BOOL halftoneMode); void AddObject(int id, int pattern, T2BitImage& image, const RECT* rect, BOOL transparent, BOOL halftoneMode); - int FindObject(int id, int pattern, int grade, int span, int offset); - int FindObject(const char* name, int pattern, int grade, int span, int offset); + int FindObject(int id, int pattern = -1, int grade = 0, int span = 0, int offset = 255); + int FindObject(const char* name, int pattern = -1, int grade = 0, int span = 0, int offset = 255); void EnumParts(int, int, PARTSLIST*, int*); BOOL WithRoof(int index); BOOL WithFloor(int index); - void DrawObject(T2BitImage* image, int index, RECT rect, int factor, int foreGndColor); - void DrawObject(CDC* dc, int index, RECT rect, int factor, int foreGndColor); + void DrawObject(T2BitImage* image, int index, RECT rect, int factor = 0, int foreGndColor = -1); + void DrawObject(CDC* dc, int index, RECT rect, int factor = 0, int foreGndColor = -1); BOOL GetObjectSize(int index, SIZE* outSize); T2BitImage* GetObjectImage(int index, RECT& outRect); diff --git a/src/T2DLL/T2InfoDialog.h b/src/T2DLL/T2InfoDialog.h index f7e41c3..702340e 100644 --- a/src/T2DLL/T2InfoDialog.h +++ b/src/T2DLL/T2InfoDialog.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2Dialog.h" -class T2InfoDialog : public T2Dialog { +class AFX_EXT_CLASS T2InfoDialog : public T2Dialog { public: T2InfoDialog(T2DrawableObject* object); virtual ~T2InfoDialog(); diff --git a/src/T2DLL/T2Maru_Reggae.cpp b/src/T2DLL/T2Maru_Reggae.cpp index fe26eeb..612dc62 100644 --- a/src/T2DLL/T2Maru_Reggae.cpp +++ b/src/T2DLL/T2Maru_Reggae.cpp @@ -1,43 +1,677 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2EquipPtrList.h" +#include "T2FloorInfo.h" #include "T2Maru_Reggae.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleDef.h" +#include "T2PeopleLinkIterator.h" +#include "T2Pool.h" +#include "T2RegistedTenantDB.h" +#include "T2RouteNavigator.h" +#include "T2SoundPlayer.h" +#include "T2TemplatePluginList.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2TowerMessage.h" +#include "T2WorldDef.h" +#include "URect.h" +#include "UT2Coordinate.h" +#include "UT2Utils.h" -T2Maru_Reggae::T2Maru_Reggae(T2TowerEvent*, CResFile*, int) { +T2Maru_Reggae::T2Maru_Reggae(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + int subResID; + + *inResFile >> mAnimResID; + *inResFile >> subResID; + *inResFile >> mTargetTenantCategory; + *inResFile >> m3C; + *inResFile >> mReggaeName; + mIsReggae = (mReggaeName.GetLength() > 0); + + CResFile subResFile; + if (subResFile.OpenResource(GetWorldDef()->mModuleHandle, subResID, 'VIPL')) + subResFile >> mSilhouetteType; + else + mSilhouetteType = 0; + + mStatus = kMaruReggaeStatus0; + mReggaeManID = 0; + mVisitTenantID = 0; + mLastMinutes = 0; + mDidSetSilhouetteDef = false; + mDidChangeDirection = false; + mCounter = 0; + mGuardman = NULL; + + Sounds->AddSound("MR:Maru", SoundPriority_1, 9003, GetWorldModuleHandle()); + Sounds->AddSound("MR:Rege", SoundPriority_1, 9004, GetWorldModuleHandle()); } /*virtual*/ T2Maru_Reggae::~T2Maru_Reggae() { + if (Sounds) { + Sounds->DeleteSound("MR:Maru"); + Sounds->DeleteSound("MR:Rege"); + } + + if (mGuardman) + delete mGuardman; } -/*virtual*/ int T2Maru_Reggae::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2Maru_Reggae::Start(T2TowerDoc* inDoc) { + mStatus = kMaruReggaeStatus0; + mReggaeManID = 0; + mVisitTenantID = 0; + mDidChangeDirection = false; + mLastMinutes = 0; + + T2Tenant *theTenant = FindTargetTenant(inDoc); + if (theTenant) { + T2Pool *thePool = inDoc->towerDoc_vf130(); +#line 85 + _ASSERT(thePool != NULL); + + T2People *thePeople = thePool->BornVIP(mSilhouetteType, 0); + if (thePeople) { + CString nameStr; + thePeople->GetName(nameStr); + + T2Name *theName = inDoc->mNameDB->Search(thePeople); + if (theName) { + theName->SetName(nameStr); + } else { + T2Name *theNewName = new T2Name(nameStr, thePeople, false); + inDoc->mNameDB->Add(theNewName); + } + + T2MatterDef *theMatterDef = thePeople->GetMatterDef(); + T2TemplatePluginList *thePluginList = inDoc->towerDoc_vf128(); + T2SilhouetteDef *theSilhouetteDef = thePluginList ? thePluginList->FindSilhouette(theMatterDef->mSilhouetteID + 1) : NULL; + + if (theSilhouetteDef) { + thePeople->SetSilhouetteDef(kPeopleStyle1, theSilhouetteDef); + mDidSetSilhouetteDef = true; + } else { + mDidSetSilhouetteDef = false; + } + + thePeople->mColor = 11; + thePeople->SetDestination(theTenant->mEquipID); + thePeople->SetSpecialFlag(kSpecialFlag20 | kSpecialFlag40); + + mReggaeManID = thePeople->GetPeopleID(); + mVisitTenantID = theTenant->GetEquipID(); + mLastMinutes = GetEndTime(); + mLastStatus = thePeople->GetStatus(); + + mStatus = kMaruReggaeStatus1; + } + } + + return (mStatus != kMaruReggaeStatus0); } -/*virtual*/ int T2Maru_Reggae::Exec(T2TowerDoc*) { +/*virtual*/ int T2Maru_Reggae::Exec(T2TowerDoc* inDoc) { + int result = 0; + + switch (mStatus) { + case kMaruReggaeStatus0: + case kMaruReggaeStatus9: + mStatus = kMaruReggaeStatus0; + result = 3; + break; + } + + if (DoReception(inDoc)) + result = 3; + else + result = IsExclusive() ? 1 : 0; + + return result; } -int T2Maru_Reggae::DoReception(T2TowerDoc*) { +BOOL T2Maru_Reggae::DoReception(T2TowerDoc* inDoc) { + if (mGuardman && !mGuardman->DoReception(inDoc)) { + delete mGuardman; + mGuardman = NULL; + mLastMinutes = 0; + } + + T2People *thePeople = GetReggaeMan(); + T2Tenant *theTenant; + int pplStatus; + + if (thePeople) { + T2DateTime *theNow = inDoc->mNow; + pplStatus = thePeople->GetStatus(); + + if (pplStatus != mLastStatus || theNow->GetRawMinutes() > mLastMinutes) { + mLastMinutes = theNow->GetRawMinutes(); + + switch (pplStatus) { + case kStatus12: + if (mStatus != kMaruReggaeStatus11 && mLastMinutes < GetEndTime()) { + theTenant = FindTargetTenant(inDoc); + if (theTenant) { + thePeople->SetDestination(theTenant->GetEquipID()); + thePeople->ChangeStatus(kStatus3); + mStatus = kMaruReggaeStatus1; + mLastMinutes = GetEndTime(); + } else { + mStatus = kMaruReggaeStatus11; + } + } + break; + + case kStatus1: + if (mStatus != kMaruReggaeStatus8) { + T2Name *theName = inDoc->mNameDB->Search(thePeople); + if (theName) { + inDoc->mNameDB->RemoveName(theName); + delete theName; + } + mStatus = kMaruReggaeStatus8; + } else if (mGuardman == NULL) { + T2Pool *thePool = inDoc->towerDoc_vf130(); +#line 208 + _ASSERT(thePool != NULL); + + thePool->DeadVIP(thePeople); + return true; + } + break; + + case kStatus9: + thePeople->UpdateEstimation(); + mLastMinutes = GetEndTime(); + break; + + case kStatus15: + { + unsigned int theNextTenant; + switch (mStatus) { + case kMaruReggaeStatus1: + theTenant = inDoc->towerDoc_vf12C()->GetTenant(mVisitTenantID); + if (theTenant) { + T2EquipDef *theDef = theTenant->GetEquipDef(); + if (theTenant->IsTherePeople() && !theTenant->IsFireproof()) { + if (mTargetTenantCategory == 0 || (theDef && theDef->GetCategory() == mTargetTenantCategory)) { + if (mIsReggae) + ReggaeReception(inDoc, thePeople); + else + MaruReception(inDoc, thePeople); + break; + } + } + } + + theNextTenant = FindNextTenant(inDoc); + if (theNextTenant) { + mVisitTenantID = theNextTenant; + thePeople->SetDestination(mVisitTenantID); + thePeople->ChangeStatus(kStatus3); + mLastMinutes = GetEndTime(); + break; + } + + case kMaruReggaeStatus5: + theTenant = FindTargetTenant(inDoc); + if (mLastMinutes >= GetEndTime() || theTenant == NULL) { + mVisitTenantID = 1; + mStatus = kMaruReggaeStatus11; + } else { + mVisitTenantID = theTenant->GetEquipID(); + mStatus = kMaruReggaeStatus1; + } + thePeople->ChangeStatus(kStatus3); + thePeople->ChangeStyle(kPeopleStyle0); + thePeople->SetDestination(mVisitTenantID); + mDidChangeDirection = false; + mLastMinutes = GetEndTime(); + break; + + case kMaruReggaeStatus2: + case kMaruReggaeStatus3: + case kMaruReggaeStatus4: + MaruReception(inDoc, thePeople); + break; + + case kMaruReggaeStatus6: + case kMaruReggaeStatus7: + ReggaeReception(inDoc, thePeople); + break; + } + break; + } + + default: + mLastMinutes = GetEndTime(); + } + + mLastStatus = thePeople->GetStatus(); + } + } + + return false; } -void T2Maru_Reggae::MaruReception(T2TowerDoc*, T2People*) { +void T2Maru_Reggae::MaruReception(T2TowerDoc* inDoc, T2People* inPeople) { + switch (mStatus) { + case kMaruReggaeStatus1: + inPeople->SetDestination(0); + inPeople->UpdateEstimation(); + if (mDidSetSilhouetteDef) + inPeople->ChangeStyle(kPeopleStyle1); + inPeople->ChangeWalkStyle(0); + inPeople->ChangeStatus(kStatus14); + mLastMinutes = GetEndTime(); + mStatus = kMaruReggaeStatus2; + break; + + case kMaruReggaeStatus2: + mLastMinutes += 30; + if (mLastMinutes > GetEndTime()) + mLastMinutes = GetEndTime(); + mStatus = kMaruReggaeStatus3; + break; + + case kMaruReggaeStatus3: + case kMaruReggaeStatus4: + { + POINT curPos = inPeople->GetCurPosition(); + + CRect theRect; + T2TowerMainView *theView = inDoc->GetTowerMainView(); + theView->GetClientRect(theRect); + theRect.OffsetRect(theView->m64); + + UT2Coordinate::QDToUnit(theRect, inDoc->towerDoc_vf108()); + + if (theRect.PtInRect(curPos) && inDoc->towerDoc_vf140() != ViewMode_1) { + UT2Coordinate::MakeRect(theRect, curPos, 2, 1); + theView->tmv_vf128(theRect, true); + } else { + mStatus = kMaruReggaeStatus4; + } + + mStatus++; + if (mStatus < kMaruReggaeStatus5) { + Sounds->Play("MR:Maru", SoundMask_10, SoundFlags_10, &curPos, PlayMode_0, 100); + inPeople->ChangeWalkStyle(2); + mLastMinutes += 8; + } else { + inPeople->ChangeWalkStyle(0); + mLastMinutes += 30; + if (mLastMinutes > GetEndTime()) + mLastMinutes = GetEndTime(); + } + break; + } + } } -void T2Maru_Reggae::ReggaeReception(T2TowerDoc*, T2People*) { +void T2Maru_Reggae::ReggaeReception(T2TowerDoc* inDoc, T2People* inPeople) { + POINT curPos; + T2Tenant *theTenant; + + switch (mStatus) { + case kMaruReggaeStatus1: + inPeople->SetDestination(0); + inPeople->UpdateEstimation(); + + theTenant = inDoc->towerDoc_vf12C()->GetTenant(mVisitTenantID); + if (theTenant) { + CRect rect; + theTenant->GetEquipArea(rect); + rect.left += URect::Width(rect) / 2; + + POINT curPos = inPeople->GetCurPosition(); + if ( + (curPos.x > rect.left && inPeople->GetDirection() == 0) || + (curPos.x < rect.left && inPeople->GetDirection() == 1) + ) + inPeople->FlipDirection(); + + inPeople->SetCurrDestPos(rect.TopLeft()); + inPeople->ChangeStatus(kStatus14); + mLastMinutes = GetEndTime(); + mCounter = 0; + mStatus = kMaruReggaeStatus6; + } else { + mStatus = kMaruReggaeStatus5; + } + break; + + case kMaruReggaeStatus6: + curPos = inPeople->GetCurPosition(); + theTenant = inDoc->towerDoc_vf12C()->GetTenant(curPos.y, curPos.x); + if (theTenant && !theTenant->IsFloor() && mLastMinutes < GetEndTime()) { + CRect theRect; + T2TowerMainView *theView = inDoc->GetTowerMainView(); + theView->GetClientRect(&theRect); + theRect.OffsetRect(theView->m64); + + UT2Coordinate::QDToUnit(theRect, inDoc->towerDoc_vf108()); + + if (theRect.PtInRect(curPos) && inDoc->towerDoc_vf140() != ViewMode_1) { + UT2Coordinate::MakeRect(theRect, curPos, 2, 1); + theView->tmv_vf128(theRect, true); + + if (inPeople->GetWalkStyle() == 0) + inPeople->ChangeWalkStyle(1); + else + inPeople->ChangeWalkStyle(0); + + Sounds->Play("MR:Rege", SoundMask_10, SoundFlags_10, &curPos, PlayMode_0, 100); + } + + mCounter++; + if ((mCounter % 60) == 0) { + CString message; + MakeClaimMessage(inDoc, theTenant, message); + inDoc->towerDoc_vf13C()->InfoBarMessage(message, 180, NULL); + + if (!mGuardman) + mGuardman = new T2Guardman(this, inDoc, theTenant); + } + + if ((mCounter % 10) == 0 && theTenant->GetFirstPeople()) { + T2PeopleLinkIterator iterator(theTenant->GetFirstPeople()); + T2People *people; + while (iterator.Next(&people)) { + if (people) + people->IncStress(10); + } + } + + mLastMinutes += 3; + } else { + mStatus = kMaruReggaeStatus5; + } + break; + + case kMaruReggaeStatus7: + int anims[3] = {2, 0, 0}; + anims[1] = mAnimResID; + anims[2] = mAnimResID + 1; + CString message; + + curPos = inPeople->GetCurPosition(); + theTenant = inDoc->towerDoc_vf12C()->GetTenant(curPos.y, curPos.x); + MakeClaimMessage(inDoc, theTenant, message); + inDoc->towerDoc_vf13C()->CancelInfoBarMessage(message); + + // "レゲエのおじさんは警備員につかまりました。" + // Uncle Reggae was caught by a security guard. + message = "\x83\x8C\x83\x51\x83\x47\x82\xCC\x82\xA8\x82\xB6\x82\xB3\x82\xF1\x82\xCD\x8C\x78\x94\xF5\x88\xF5\x82\xC9\x82\xC2\x82\xA9\x82\xDC\x82\xE8\x82\xDC\x82\xB5\x82\xBD\x81\x42"; + DoDialog(inDoc, 9200, mAnimResID, 2, message); + + mVisitTenantID = 1; + mStatus = kMaruReggaeStatus11; + + inPeople->ChangeStatus(kStatus3); + inPeople->SetDestination(mVisitTenantID); + + mDidChangeDirection = false; + mLastMinutes = GetEndTime(); + + if (mGuardman) + mGuardman->GoHome(); + break; + } } -void T2Maru_Reggae::MakeClaimMessage(T2TowerDoc*, T2Tenant*, CString&) { +void T2Maru_Reggae::MakeClaimMessage(T2TowerDoc* inDoc, T2Tenant* inTenant, CString& outStr) { + CString floorStr, roomStr, nameStr; + + int floorNum = inTenant->GetFloorNumber(inDoc->towerDoc_vf12C()); + if (floorNum < 0) + floorStr.Format("B%d", -floorNum); + else + floorStr.Format("%d", floorNum); + + int roomNum = inTenant->GetRoomNumber(inDoc->towerDoc_vf12C()); + if (roomNum < 0) + roomStr.Format("B%d", -roomNum); + else + roomStr.Format("%d", roomNum); + + T2EquipDef *theTenantDef = inTenant->GetEquipDef(); + if (theTenantDef) + theTenantDef->GetName(nameStr, 0); + + // "%sと%s階%s号室%sから苦情です" + // Complaints from %s and %s Floor %s Room %s + outStr.Format( + "%s\x82\xC6%s\x8A\x4B%s\x8D\x86\x8E\xBA%s\x82\xA9\x82\xE7\x8B\xEA\x8F\xEE\x82\xC5\x82\xB7", + mReggaeName, floorStr, roomStr, nameStr); } -T2Tenant* T2Maru_Reggae::FindTargetTenant(T2TowerDoc*) { +T2Tenant* T2Maru_Reggae::FindTargetTenant(T2TowerDoc* inDoc) { + T2RouteNavigator *theNavi = inDoc->towerDoc_vf124(); +#line 521 + _ASSERT(theNavi != NULL); + + POINT theTargetPos; + int theHRange = GetWorldDef()->GetWidth(); + int theVRange = GetWorldDef()->mGroundLine - 2; + int theTotal = theHRange * theVRange; + + T2Tenant *theTenant; + T2EquipDef *theEquipDef; + + do { + theTotal--; + if (theTotal <= 0) + return NULL; + + theTargetPos.y = UT2Utils::Randomize(theHRange); + theTargetPos.x = UT2Utils::Randomize(theVRange); + theTenant = inDoc->mFloorInfo->GetTenant(theTargetPos.x, theTargetPos.y); + theEquipDef = theTenant ? theTenant->GetEquipDef() : NULL; + } while ( + !theTenant || + !theNavi->IsConnectRouteFromLobby(theTenant->GetEntrancePt()) || + theTenant->IsFireproof() || + theTenant->GetEquipID() == mVisitTenantID || + !theEquipDef || + (mTargetTenantCategory != 0 && theEquipDef->GetCategory() != mTargetTenantCategory) + ); + + return theTenant; } -unsigned int T2Maru_Reggae::FindNextTenant(T2TowerDoc*) { +unsigned int T2Maru_Reggae::FindNextTenant(T2TowerDoc* inDoc) { + unsigned int theNextTenantID = 0; + + T2FloorInfo *fInfo = inDoc->towerDoc_vf12C(); +#line 550 + _ASSERT(fInfo != NULL); + T2People *thePeople = GetReggaeMan(); +#line 552 + _ASSERT(thePeople != NULL); + + T2Tenant *theTenant = fInfo->GetTenant(mVisitTenantID); + if (theTenant) { + RECT rect; + theTenant->GetEquipArea(rect); + + do { + rect.left += thePeople->GetDirection() ? -1 : 1; + theNextTenantID = fInfo->GetTenantID(rect.bottom - 1, rect.left); + } while (theNextTenantID == mVisitTenantID); + + if (theNextTenantID == 0 && !mDidChangeDirection) { + mDidChangeDirection = true; + thePeople->FlipDirection(); + theNextTenantID = mVisitTenantID; + } + } + + return theNextTenantID; } T2People* T2Maru_Reggae::GetReggaeMan() { + return GetTowerDoc()->mPeopleArrayList->FindPeople(mReggaeManID); } T2Tenant* T2Maru_Reggae::GetVisitTenant() { + return (mStatus == kMaruReggaeStatus6) ? GetTowerDoc()->towerDoc_vf12C()->GetTenant(mVisitTenantID) : NULL; +} + +/*virtual*/ void T2Maru_Reggae::Write(T2Archive& inArchive) { + unsigned int len = 14; + inArchive << len; + + inArchive << (short) mStatus; + inArchive << mReggaeManID; + inArchive << (unsigned short) mVisitTenantID; + + unsigned char flag = (mDidChangeDirection != 0); + inArchive << flag; + flag = (mDidSetSilhouetteDef != 0); + inArchive << flag; + + inArchive << mCounter; } -/*virtual*/ void T2Maru_Reggae::Write(T2Archive&) { +/*virtual*/ void T2Maru_Reggae::Read(T2Archive& inArchive) { + unsigned int len; + unsigned short theUInt16; + short theSInt16; + unsigned char theChar; + + inArchive >> len; + + inArchive >> theSInt16; + mStatus = theSInt16; + + inArchive >> mReggaeManID; + + inArchive >> theUInt16; + mVisitTenantID = theUInt16; + + inArchive >> theChar; + mDidChangeDirection = (theChar != 0); + inArchive >> theChar; + mDidSetSilhouetteDef = (theChar != 0); + + inArchive >> mCounter; +} + + + +T2Guardman::T2Guardman(T2Maru_Reggae *inOwner, T2TowerDoc *inDoc, T2Tenant *inTenant) { + mOwner = inOwner; + mPeople = NULL; + + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); +#line 647 + _ASSERT(theDB != NULL); + + T2EquipPtrList *theList = theDB->GetList(kTenantRegistID5); + if (theList) { + T2Tenant *theTenant; + theList->FetchItemAt(1, &theTenant); + + if (theTenant) { + T2RouteNavigator *theNavi = inDoc->towerDoc_vf124(); +#line 656 + _ASSERT(theNavi != NULL); + + POINT theNextPt = inTenant->GetEntrancePt(); + T2Tenant *selectedTenant = NULL; + LArrayIterator iterator(*theList); + for (int score = theTenant->GetEmployeeSearchScore(); score > 0; score--) { + int found = 0; + iterator.ResetTo(0); + + while (iterator.Next(&theTenant)) { + POINT exitPt = theTenant->GetExitPt(); + if (theNavi->CheckRoute(exitPt, theNextPt, score)) { + selectedTenant = theTenant; + found++; + if (found > 1) + break; + } + } + + if (found <= 1) + break; + } + + if (selectedTenant && selectedTenant->GetFirstPeople()) { + mPeople = selectedTenant->GetFirstPeople(); + mPeople->SetDestination(inTenant->GetEquipID()); + mPeople->SetSpecialFlag(kSpecialFlag20 | kSpecialFlag40); + mPeople->SetReturn(selectedTenant->GetEquipID()); + mPeople->mColor = 11; + selectedTenant->PushOutPeople(inDoc, mPeople); + } + } + } +} + +T2Guardman::~T2Guardman() { + if (mPeople) { + mPeople->UpdateEstimation(); + mPeople->ClearSpecialFlag(kSpecialFlag20 | kSpecialFlag40); + mPeople->ClearColor(); + } +} + +BOOL T2Guardman::DoReception(T2TowerDoc *inDoc) { + BOOL result = true; + + if (mPeople) { + switch (mPeople->GetStatus()) { + case kStatus15: + { + CPoint curPos = mPeople->GetCurPosition(); + T2Tenant *theTenant = inDoc->towerDoc_vf12C()->GetTenant(curPos.y, curPos.x); + T2People *theReggaeMan = mOwner->GetReggaeMan(); + if (theTenant && theReggaeMan && mOwner->mStatus == kMaruReggaeStatus6) { + CPoint reggaeManPos = theReggaeMan->GetCurPosition(); + if (theTenant == inDoc->towerDoc_vf12C()->GetTenant(reggaeManPos.y, reggaeManPos.x)) { + if (reggaeManPos == curPos) { + mOwner->mStatus = kMaruReggaeStatus7; + } else { + if ( + (curPos.x > reggaeManPos.x && mPeople->GetDirection() == 0) || + (curPos.x < reggaeManPos.x && mPeople->GetDirection() == 1) + ) + mPeople->FlipDirection(); + + mPeople->SetCurrDestPos(reggaeManPos); + mPeople->ChangeStatus(kStatus14); + } + } + } + break; + } + + case kStatus11: + result = false; + break; + } + } else { + result = false; + } + + return result; } -/*virtual*/ void T2Maru_Reggae::Read(T2Archive&) { +void T2Guardman::GoHome() { + mPeople->SetReturnToDestination(); + mPeople->SetStatus(kStatus3); + mPeople->ClearSpecialFlag(kSpecialFlag40); } diff --git a/src/T2DLL/T2Maru_Reggae.h b/src/T2DLL/T2Maru_Reggae.h index 502b042..4184c9a 100644 --- a/src/T2DLL/T2Maru_Reggae.h +++ b/src/T2DLL/T2Maru_Reggae.h @@ -1,27 +1,69 @@ #pragma once #include "common.h" +#include "T2EventItem.h" -class T2Maru_Reggae { +class T2Guardman; + +enum { + kMaruReggaeStatus0 = 0, + kMaruReggaeStatus1 = 1, + kMaruReggaeStatus2 = 2, + kMaruReggaeStatus3 = 3, + kMaruReggaeStatus4 = 4, + kMaruReggaeStatus5 = 5, + kMaruReggaeStatus6 = 6, + kMaruReggaeStatus7 = 7, + kMaruReggaeStatus8 = 8, + kMaruReggaeStatus9 = 9, + kMaruReggaeStatus10 = 10, + kMaruReggaeStatus11 = 11, +}; + +class AFX_EXT_CLASS T2Maru_Reggae : public T2EventItem { public: - T2Maru_Reggae(T2TowerEvent*, CResFile*, int); + T2Maru_Reggae(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); virtual ~T2Maru_Reggae(); - virtual int Start(T2TowerDoc*); - virtual int Exec(T2TowerDoc*); -private: - int DoReception(T2TowerDoc*); - void MaruReception(T2TowerDoc*, T2People*); - void ReggaeReception(T2TowerDoc*, T2People*); - void MakeClaimMessage(T2TowerDoc*, T2Tenant*, CString&); - T2Tenant* FindTargetTenant(T2TowerDoc*); - unsigned int FindNextTenant(T2TowerDoc*); -public: + virtual DWORD GetID() { return 'MaEv'; } + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc* inDoc); + virtual void Write(T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); T2People* GetReggaeMan(); T2Tenant* GetVisitTenant(); - virtual void Write(T2Archive&); - virtual void Read(T2Archive&); - virtual unsigned long GetID() {} - int IsReggae() {} - T2Maru_Reggae(const T2Maru_Reggae&) {} - T2Maru_Reggae& operator=(const T2Maru_Reggae&) {} + BOOL IsReggae() { return mIsReggae; } + +private: + BOOL DoReception(T2TowerDoc* inDoc); + void MaruReception(T2TowerDoc* inDoc, T2People* inPeople); + void ReggaeReception(T2TowerDoc* inDoc, T2People* inPeople); + void MakeClaimMessage(T2TowerDoc* inDoc, T2Tenant* inTenant, CString& outStr); + T2Tenant* FindTargetTenant(T2TowerDoc* inDoc); + unsigned int FindNextTenant(T2TowerDoc* inDoc); + + int mAnimResID; + int mSilhouetteType; + int mTargetTenantCategory; + int m3C; + CString mReggaeName; + unsigned int mReggaeManID; + unsigned int mVisitTenantID; + int mLastStatus; + unsigned int mLastMinutes; + unsigned int mCounter; + BOOL mDidSetSilhouetteDef; + BOOL mDidChangeDirection; + BOOL mIsReggae; + T2Guardman *mGuardman; +}; + +class T2Guardman { +public: + T2Guardman(T2Maru_Reggae *inOwner, T2TowerDoc *inDoc, T2Tenant *inTenant); + ~T2Guardman(); + BOOL DoReception(T2TowerDoc *inDoc); + void GoHome(); + + T2Maru_Reggae *mOwner; + T2People *mPeople; }; diff --git a/src/T2DLL/T2Matter.h b/src/T2DLL/T2Matter.h index 60caed3..4c7b9df 100644 --- a/src/T2DLL/T2Matter.h +++ b/src/T2DLL/T2Matter.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2DrawableObject.h" -class T2Matter : public T2DrawableObject { +class AFX_EXT_CLASS T2Matter : public T2DrawableObject { public: T2Matter(); @@ -10,14 +10,14 @@ public: virtual void SetUsed(BOOL); void Initialize(T2MatterDef*); void FlipDirection(); - void SetDestination(unsigned int, unsigned int); + void SetDestination(unsigned int dstTenant, unsigned int startTime = 0); void ClearDestination(); BOOL IsStartTime(unsigned int) const; BOOL IsSetReturn() const; BOOL IsSetReturnTime() const; unsigned int GetReturnTime() const; unsigned int GetReturn() const; - BOOL SetReturn(unsigned int tenant, unsigned int time); + BOOL SetReturn(unsigned int tenant, unsigned int time = 0); void SetReturnTime(unsigned int); BOOL PopReturn(unsigned int& outTenant, unsigned int& outTime); BOOL SetReturnToDestination(); @@ -48,21 +48,13 @@ public: return mCurPosition.y == mCurrDestPos.y; } BOOL IsGoDown() const { - return mCurrDestPos.y > mCurPosition.y; + return (mCurrDestPos.y - mCurPosition.y) > 0; } BOOL IsSetStartTime() const { return mStartTime > -1; } BOOL IsSetDestination() const { return mDstTenant != 0; } unsigned int GetDestination() const { return mDstTenant; } void SetStartTime(unsigned int v) { mStartTime = v; } -private: - void Initialize(); - -protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); - - friend class T2MatterArray; unsigned int mMatterID; T2MatterDef *mMatterDef; int m18; @@ -78,4 +70,11 @@ protected: int m48; int mDirection; int mWalkStyle; + +private: + void Initialize(); + +protected: + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); }; diff --git a/src/T2DLL/T2MatterArray.cpp b/src/T2DLL/T2MatterArray.cpp index 2dee1cc..42adf1b 100644 --- a/src/T2DLL/T2MatterArray.cpp +++ b/src/T2DLL/T2MatterArray.cpp @@ -6,12 +6,12 @@ T2MatterArray::T2MatterArray(unsigned int jobType, unsigned int validRange, unsi mJobType = jobType; mValidRange = validRange; - for (unsigned int i = 0; i < 448; i++) + for (unsigned int i = 0; i < kGroupSize; i++) mMatter[i].mMatterID = mStartID + i; } void T2MatterArray::SetValidRange(unsigned int validRange) { - if (validRange <= 448) + if (validRange <= kGroupSize) mValidRange = validRange; } @@ -24,8 +24,8 @@ T2Matter* T2MatterArray::FindUnusedMatter(unsigned int arg) { if (arg > 0) { unsigned int start = mValidRange; unsigned int end = mValidRange + arg; - if (end > 448) - end = 448; + if (end > kGroupSize) + end = kGroupSize; mValidRange = end; for (unsigned int i = start; i < mValidRange; i++) { diff --git a/src/T2DLL/T2MatterArray.h b/src/T2DLL/T2MatterArray.h index a7defaa..f19cc44 100644 --- a/src/T2DLL/T2MatterArray.h +++ b/src/T2DLL/T2MatterArray.h @@ -3,9 +3,11 @@ #include "T2Matter.h" #include "T2ObjectArray.h" -class DLL_EXPORT T2MatterArray : public T2ObjectArray { +class AFX_EXT_CLASS T2MatterArray : public T2ObjectArray { public: - T2MatterArray(unsigned int jobType, unsigned int validRange, unsigned int startID); + enum { kGroupSize = 448 }; + + T2MatterArray(unsigned int jobType, unsigned int validRange, unsigned int startID); virtual ~T2MatterArray() { } void SetValidRange(unsigned int validRange); @@ -13,11 +15,13 @@ public: unsigned int GetJobType() { return mJobType; } unsigned int GetValidRange() { return mValidRange; } - unsigned int GetSpare() { return 448 - mValidRange; } + unsigned int GetSpare() { return kGroupSize - mValidRange; } T2Matter* GetIndexMatter(int i) { return &mMatter[i]; } protected: + friend class T2MatterArrayList; + unsigned int mJobType; unsigned int mValidRange; - T2Matter mMatter[448]; + T2Matter mMatter[kGroupSize]; }; diff --git a/src/T2DLL/T2MatterArrayList.cpp b/src/T2DLL/T2MatterArrayList.cpp index d53785e..5611373 100644 --- a/src/T2DLL/T2MatterArrayList.cpp +++ b/src/T2DLL/T2MatterArrayList.cpp @@ -1,25 +1,59 @@ +#include "T2MatterArray.h" #include "T2MatterArrayList.h" -T2MatterArrayList::T2MatterArrayList(const T2MatterArrayList&) { -} - -T2MatterArrayList& T2MatterArrayList::operator=(const T2MatterArrayList&) { -} - -T2MatterArrayList::T2MatterArrayList() { +T2MatterArrayList::T2MatterArrayList() + : LArray(sizeof(T2MatterArray *)) +{ + T2MatterArray *theArray = new T2MatterArray(0, T2MatterArray::kGroupSize, 1); + Add(theArray); } /*virtual*/ T2MatterArrayList::~T2MatterArrayList() { + LArrayIterator iterator(*this); + T2MatterArray *theArray; + + while (iterator.Next(&theArray)) + delete theArray; } -void T2MatterArrayList::Add(T2MatterArray*) { +void T2MatterArrayList::Add(T2MatterArray* inArray) { + InsertItemsAt(1, mItemCount + 1, &inArray); } unsigned int T2MatterArrayList::GetItemCount() { + return GetCount(); } -T2MatterArray* T2MatterArrayList::GetItemAt(long) { +T2MatterArray* T2MatterArrayList::GetItemAt(long inIndex) { + T2MatterArray *theArray; + if (FetchItemAt(inIndex, &theArray)) + return theArray; + return NULL; } -T2Matter* T2MatterArrayList::FindUnusedMatter(unsigned int, unsigned int) { +T2Matter* T2MatterArrayList::FindUnusedMatter(unsigned int inJobType, unsigned int inValidRange) { + LArrayIterator iterator(*this); + unsigned int lastStartID = 1; + T2MatterArray *theArray; + + while (iterator.Next(&theArray)) { + if (theArray->GetJobType() == inJobType) { + T2Matter *theMatter = theArray->FindUnusedMatter(inValidRange); + if (theMatter) + return theMatter; + + lastStartID = theArray->mStartID; + } + } + + if (inValidRange > 0) { + theArray = new T2MatterArray(inJobType, inValidRange, lastStartID + T2MatterArray::kGroupSize); + if (theArray) { + Add(theArray); + return theArray->FindUnusedMatter(0); + } + return NULL; + } + + return NULL; } diff --git a/src/T2DLL/T2MatterArrayList.h b/src/T2DLL/T2MatterArrayList.h index bf6fed3..d2a33e6 100644 --- a/src/T2DLL/T2MatterArrayList.h +++ b/src/T2DLL/T2MatterArrayList.h @@ -1,14 +1,13 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2MatterArrayList { +class AFX_EXT_CLASS T2MatterArrayList : public LArray { public: - T2MatterArrayList(const T2MatterArrayList&); - T2MatterArrayList& operator=(const T2MatterArrayList&); T2MatterArrayList(); virtual ~T2MatterArrayList(); - void Add(T2MatterArray*); + void Add(T2MatterArray* inArray); unsigned int GetItemCount(); - T2MatterArray* GetItemAt(long); - T2Matter* FindUnusedMatter(unsigned int, unsigned int); + T2MatterArray* GetItemAt(long inIndex); + T2Matter* FindUnusedMatter(unsigned int inJobType, unsigned int inValidRange); }; diff --git a/src/T2DLL/T2MatterDef.h b/src/T2DLL/T2MatterDef.h index f23d58a..62cf41c 100644 --- a/src/T2DLL/T2MatterDef.h +++ b/src/T2DLL/T2MatterDef.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2TemplatePlugin.h" -class T2MatterDef : public T2TemplatePlugin { +class AFX_EXT_CLASS T2MatterDef : public T2TemplatePlugin { public: T2MatterDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile); virtual ~T2MatterDef(); @@ -13,7 +13,6 @@ public: int GetAttribute() const { return mAttribute; } virtual T2SilhouetteDef* GetSilhouetteDef() const { return mSilhouetteDef; } -protected: int mSortKey; int mAttribute; int mSilhouetteID; diff --git a/src/T2DLL/T2Message.cpp b/src/T2DLL/T2Message.cpp index e089c1b..73850eb 100644 --- a/src/T2DLL/T2Message.cpp +++ b/src/T2DLL/T2Message.cpp @@ -1,49 +1,289 @@ +#include "CT2App.h" #include "T2Message.h" +static BOOL s100E3E08; + +// unknown name - 100E3E0C +static BOOL sVisible; + T2Message::T2Message() { } -void T2Message::ShowMessage(const CString&) { -} +void T2Message::ShowMessage(const CString& str) { + if (!sVisible) { + sVisible = true; + s100E3E08 = true; -/*virtual*/ T2Message::~T2Message() { -} + // "MS Pゴシック" + mFont.CreatePointFont(100, "\x82\x6C\x82\x72 \x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"); + + void *buffer = malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + 8 * 8); + + BITMAPINFOHEADER *bmi = (BITMAPINFOHEADER *) buffer; + memset(bmi, 0, sizeof(BITMAPINFOHEADER)); + bmi->biSize = sizeof(BITMAPINFOHEADER); + bmi->biWidth = 8; + bmi->biHeight = 8; + bmi->biPlanes = 1; + bmi->biBitCount = 8; + bmi->biClrUsed = 2; + bmi->biClrImportant = 2; + + RGBQUAD *cols = (RGBQUAD *) (((char *) buffer) + sizeof(BITMAPINFOHEADER)); + cols[0].rgbRed = 0; + cols[0].rgbGreen = 0; + cols[0].rgbBlue = 0; + cols[1].rgbRed = 255; + cols[1].rgbGreen = 255; + cols[1].rgbBlue = 0; -/*static*/ const AFX_MSGMAP* __stdcall T2Message::_GetBaseMessageMap() { + unsigned char *pixels = ((unsigned char *) buffer) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2; + unsigned char row[8]; + row[0] = 1; + row[1] = 1; + row[2] = 1; + row[3] = 1; + row[4] = 0; + row[5] = 0; + row[6] = 0; + row[7] = 0; + + for (int y = 0; y < 8; y++) { + for (int x = 0; x < 8; x++) { + pixels[x + y * 8] = row[(x + y) % 8]; + } + } + + int result = mBrush.CreateDIBPatternBrush((const void *) buffer, DIB_RGB_COLORS); + free(buffer); +#line 64 + _ASSERT(result != 0); + + mString = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW | CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); + + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = 100; + rect.bottom = 50; + + CreateEx(0, mString, str, WS_POPUP, rect, AfxGetMainWnd(), 0); + } else { + delete this; + } } -/*virtual*/ const AFX_MSGMAP* T2Message::GetMessageMap() const { +/*virtual*/ T2Message::~T2Message() { } +BEGIN_MESSAGE_MAP(T2Message, CWnd) + ON_WM_CREATE() + ON_WM_TIMER() + ON_WM_LBUTTONDOWN() + ON_WM_RBUTTONDOWN() + ON_WM_KEYDOWN() + ON_WM_DESTROY() + ON_WM_ERASEBKGND() + ON_MESSAGE(WM_USER + 10, OnHookMessage) +END_MESSAGE_MAP() + /*virtual*/ void T2Message::PostNcDestroy() { + sVisible = false; + delete this; + ((CT2App *) AfxGetApp())->app_vfAC(); } -int T2Message::OnCreate(CREATESTRUCTA*) { +int T2Message::OnCreate(CREATESTRUCT* cs) { + if (CWnd::OnCreate(cs) == -1) + return -1; + + CString str; + GetWindowText(str); + + CRect desktopRect; + GetDesktopWindow()->GetClientRect(desktopRect); + + CDC *dc = GetDC(); + int save = dc->SaveDC(); + + dc->SelectObject(&mFont); + + mRect2.SetRect(0, 0, (desktopRect.right * 2) / 5, desktopRect.bottom); + dc->DrawText(str, mRect2, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); + mRect2.InflateRect(0, 0, 20, 20); + + dc->RestoreDC(save); + ReleaseDC(dc); + + CRect clientRect; + + GetWindowRect(mRect1); + GetClientRect(clientRect); + mRect1.OffsetRect(-mRect1.left, -mRect1.top); + mRect1.right = mRect1.Width() - clientRect.Width() + mRect2.Width(); + mRect1.bottom = mRect1.Height() - clientRect.Height() + mRect2.Height(); + + CPoint cursorPos; + GetCursorPos(&cursorPos); + + if ((cursorPos.x - mRect1.right) >= 0) + mRect1.OffsetRect(cursorPos.x - mRect1.right, 0); + else + mRect1.OffsetRect(cursorPos.x, 0); + + if ((cursorPos.y - mRect1.bottom) >= 0) + mRect1.OffsetRect(0, cursorPos.y - mRect1.bottom); + else + mRect1.OffsetRect(0, cursorPos.y); + + m78 = false; + + SetTimer(1, 50, NULL); + + m74 = GetTickCount(); + + ((CT2App *) AfxGetApp())->app_vfA8(this); + + return 0; } -void T2Message::OnTimer(unsigned int) { +void T2Message::OnTimer(UINT) { + unsigned int counter; + DWORD tickCount = GetTickCount(); + + if (m74 <= tickCount) + counter = tickCount - m74; + else + counter = -1 - m74 + tickCount; + + if (counter >= 250) { + if (counter >= 1250) { + DestroyWindow(); + return; + } + + if (s100E3E08 == true) { + KillTimer(1); + SetTimer(1, 200, NULL); + s100E3E08 = false; + } + + counter = 250; + m78 = true; + } + + CRect rect; + CPoint pt = mRect1.CenterPoint(); + + if (counter <= 80) { + rect.left = pt.x - 10; + rect.right = pt.x + 10; + + rect.top = pt.y - (((pt.y - mRect1.top) * counter) / 80); + rect.bottom = pt.y + (((mRect1.bottom - pt.y) * counter) / 80); + } else { + counter -= 80; + + rect.top = mRect1.top; + rect.bottom = mRect1.bottom; + + rect.left = pt.x - (((pt.x - mRect1.left - 10) * counter) / 170) - 10; + rect.right = pt.x + (((mRect1.right - pt.x - 10) * counter) / 170) + 10; + } + + SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER); + ShowWindow(SW_SHOWNA); } -long T2Message::OnHookMessage(unsigned int, long) { +LONG T2Message::OnHookMessage(UINT, LONG arg) { + MSG *pMsg = (MSG *) arg; + + if (pMsg->hwnd != m_hWnd) { + if (pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_RBUTTONDOWN || pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) + DestroyWindow(); + } + + return 0; } -void T2Message::OnLButtonDown(unsigned int, CPoint) { +void T2Message::OnLButtonDown(UINT, CPoint) { + DestroyWindow(); } -void T2Message::OnRButtonDown(unsigned int, CPoint) { +void T2Message::OnRButtonDown(UINT, CPoint) { + DestroyWindow(); } -void T2Message::OnKeyDown(unsigned int, unsigned int, unsigned int) { +void T2Message::OnKeyDown(UINT, UINT, UINT) { + DestroyWindow(); } void T2Message::OnDestroy() { + CWnd::OnDestroy(); + KillTimer(1); } -int T2Message::OnEraseBkgnd(CDC*) { -} +int T2Message::OnEraseBkgnd(CDC* dc) { + CRect rect1; + GetClientRect(rect1); -/*static*/ const AFX_MSGMAP T2Message::messageMap { -} + int save = dc->SaveDC(); + + CBrush brush; + brush.CreateStockObject(NULL_BRUSH); + + CPen pen; + pen.CreateStockObject(BLACK_PEN); + + dc->SelectObject(brush); + dc->SelectObject(pen); + dc->Rectangle(rect1); + + rect1.top++; + rect1.left++; + rect1.bottom--; + rect1.right--; + + CRect rect2; + + rect2 = rect1; + rect2.right = rect2.left + 5; + dc->FillRect(rect2, &mBrush); + + rect2 = rect1; + rect2.bottom = rect2.top + 5; + dc->FillRect(rect2, &mBrush); + + rect2 = rect1; + rect2.left = rect2.right - 5; + dc->FillRect(rect2, &mBrush); + + rect2 = rect1; + rect2.top = rect2.bottom - 5; + dc->FillRect(rect2, &mBrush); + + CBrush brush2; + brush2.CreateStockObject(WHITE_BRUSH); + + rect2.top = rect1.top + 5; + rect2.left = rect1.left + 5; + rect2.bottom = rect1.bottom - 5; + rect2.right = rect1.right - 5; + dc->FillRect(rect2, &brush2); + + if (m78) { + dc->SetTextColor(RGB(128, 0, 0)); + dc->SetBkMode(TRANSPARENT); + dc->SelectObject(mFont); + + CString str; + GetWindowText(str); + + CRect textRect = mRect2; + textRect.InflateRect(-10, -10, -10, -10); + dc->DrawText(str, textRect, DT_WORDBREAK | DT_NOPREFIX); + } -/*static*/ const AFX_MSGMAP_ENTRY* const T2Message::_messageEntries { + dc->RestoreDC(save); + return 1; } diff --git a/src/T2DLL/T2Message.h b/src/T2DLL/T2Message.h index 816cc61..7b16240 100644 --- a/src/T2DLL/T2Message.h +++ b/src/T2DLL/T2Message.h @@ -1,24 +1,29 @@ #pragma once #include "common.h" -class T2Message { +class AFX_EXT_CLASS T2Message : public CWnd { + DECLARE_MESSAGE_MAP() public: T2Message(); void ShowMessage(const CString&); protected: virtual ~T2Message(); - static const AFX_MSGMAP* __stdcall _GetBaseMessageMap(); - virtual const AFX_MSGMAP* GetMessageMap() const; virtual void PostNcDestroy(); - int OnCreate(CREATESTRUCTA*); + int OnCreate(CREATESTRUCT*); void OnTimer(unsigned int); - long OnHookMessage(unsigned int, long); - void OnLButtonDown(unsigned int, CPoint); - void OnRButtonDown(unsigned int, CPoint); - void OnKeyDown(unsigned int, unsigned int, unsigned int); + long OnHookMessage(UINT, LONG); + void OnLButtonDown(UINT, CPoint); + void OnRButtonDown(UINT, CPoint); + void OnKeyDown(UINT, UINT, UINT); void OnDestroy(); int OnEraseBkgnd(CDC*); - static const AFX_MSGMAP messageMap; -private: - static const AFX_MSGMAP_ENTRY* const _messageEntries; + +protected: + CString mString; + CFont mFont; + CBrush mBrush; + CRect mRect1; + CRect mRect2; + int m74; + BOOL m78; }; diff --git a/src/T2DLL/T2MetroRailway.cpp b/src/T2DLL/T2MetroRailway.cpp new file mode 100644 index 0000000..246012f --- /dev/null +++ b/src/T2DLL/T2MetroRailway.cpp @@ -0,0 +1,234 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2DateTime.h" +#include "T2ImageObj.h" +#include "T2MetroRailway.h" +#include "T2SoundPlayer.h" +#include "T2Sprite.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" + +static CString spriteNames[4] = { + "MET1", + "MET2", + "MET3", + "MET4" +}; + +T2MetroRailway::T2MetroRailway(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + *inResFile >> m74; + + int count; + *inResFile >> count; + + mCurrentSprite = -1; + for (int i = 0; i < count; i++) { + T2MetroRailway *obj = (i == 0) ? this : new T2MetroRailway(mTowerEvent, inSubID + i, mLevelBit, mExclusive, mCycleDay, mBeginTime, mEndTime); + if (obj) { + obj->Init(this, inResFile); + AddTransport(obj); + if (obj != this) + mTowerEvent->AppendStandby(obj); + } + } + + CString s; + + s.Format("METRO:%d", 0); + Sounds->AddSound(s, SoundPriority_1, 8000, GetWorldModuleHandle()); + s.Format("METRO:%d", 1); + Sounds->AddSound(s, SoundPriority_1, 8001, GetWorldModuleHandle()); + s.Format("METRO:%d", 2); + Sounds->AddSound(s, SoundPriority_1, 8002, GetWorldModuleHandle()); +} + +T2MetroRailway::T2MetroRailway(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime) + : T2EventItem(inTowerEvent, inSubID, inLevelBit, inExclusive, inCycleDay, inBeginTime, inEndTime) +{ +} + +/*virtual*/ T2MetroRailway::~T2MetroRailway() { + if (mParent == this) { + for (int i = 0; i <= 3; i++) + GetTowerDoc()->mSprite.DeleteSprite(mTrainSpriteIndices[i]); + + delete mImage; + delete mImageObj; + } + + if (Sounds) { + CString s; + for (int i = 0; i < 3; i++) { + s.Format("METRO:%d", i); + Sounds->Stop(s); + Sounds->DeleteSound(s); + } + } +} + +void T2MetroRailway::Init(T2Transport* inParent, CResFile* inResFile) { + T2Transport::Init(inParent, inResFile); + + mCurrentSprite = -1; + mTrainSpriteIndices[3] = 0; + mTrainSpriteIndices[2] = 0; + mTrainSpriteIndices[1] = 0; + mTrainSpriteIndices[0] = 0; + + mImage = NULL; + mImageObj = NULL; + + for (int i = 0; i <= 3; i++) { + if (inParent == this) { + if (i == 0) { + mImage = new T2BitImage(GetWorldDef()->mModuleHandle, 8000, true); + mImageObj = new T2ImageObj; + if (mImageObj && mImage) + mImageObj->AddObject(GetWorldDef()->mModuleHandle, 8000, mImage); + } + + mTrainSpriteIndices[i] = GetCurrentT2TowerDoc()->mSprite.NewSprite(*mImageObj, spriteNames[i], T2Sprite::ELayer_2); + } else { + mTrainSpriteIndices[i] = ((T2MetroRailway *) inParent)->mTrainSpriteIndices[i]; + } + } + + mVisible = false; + + m74 = ((T2MetroRailway *) mParent)->m74; + _24 = mWidth / 4; + mBeginTime = mArriveTime - _24; + _2C = 8; +} + +/*virtual*/ BOOL T2MetroRailway::IsBeginTime(unsigned int inTime) { + int diff = inTime - mBeginTime; + return (diff >= 0 && diff < (int) (mWidth / 4)); +} + +/*virtual*/ int T2MetroRailway::Exec(T2TowerDoc *inDoc) { + if (inDoc) { + int whichSound = -1; + T2DateTime *theNow = inDoc->mNow; + unsigned int minutes = theNow->GetRawMinutes(); + int var1C; + + if ((mArriveTime + _24) > 1440 && minutes < mBeginTime) + minutes += 1440; + + if (minutes < mArriveTime) { + var1C = 0 - (((mArriveTime - minutes) * 4) - theNow->mSeconds); + if ((var1C + 16) == 0 && mFlag && mVisible) + whichSound = 0; + } else { + var1C = mFlag ? (mArriveTime + _2C) : mArriveTime; + var1C = minutes - var1C; + if (var1C < 0) { + if ((_2C + var1C) == (_2C / 2) && mFlag && mVisible) + whichSound = 1; + var1C = 0; + } else { + var1C += theNow->mSeconds * 4; + } + } + + var1C += mStation; + + if (var1C < GetWorldDef()->GetWidth()) { + T2TowerMainView *theMainView = inDoc->GetTowerMainView(); + if (theMainView) { + POINT p; + RECT metroRect; + + p.y = GetWorldDef()->mBottomFloorLine; + p.x = var1C; + UT2Coordinate::MakeRect(metroRect, p, 40, 1); + UT2Coordinate::UnitToQD(metroRect, 0); + OffsetRect(&metroRect, 0, -8); + + p.y = metroRect.top; + p.x = metroRect.left; + UT2Coordinate::ZoomOut(metroRect, inDoc->towerDoc_vf108()); + + CRect visibleRect; + theMainView->GetClientRect(&visibleRect); + visibleRect.OffsetRect(theMainView->m64); + visibleRect.right += UT2Coordinate::UnitHSize(inDoc->towerDoc_vf108()); + + RECT intersection; + if (IntersectRect(&intersection, &metroRect, &visibleRect)) { + if (mCurrentSprite == -1) { + CreateSpriteObj(inDoc); + whichSound = 2; + } + + inDoc->mSprite.MoveSprite(mCurrentSprite, p); + Show(); + + if (whichSound >= 0) { + CString name; + name.Format("METRO:%d", whichSound); + Sounds->Play(name, SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_2, 100); + } + } else { + Hide(); + } + + return 0; + } + } + } + + StopEvent(inDoc); + return 3; +} + +/*virtual*/ void T2MetroRailway::StopEvent(T2TowerDoc* inDoc) { + Hide(); + + mCurrentSprite = -1; + mVisible = false; + + T2Transport::Stop(inDoc); +} + +/*virtual*/ int T2MetroRailway::Start(T2TowerDoc* inDoc) { + SetStatus(1); + return 1; +} + +BOOL T2MetroRailway::CreateSpriteObj(T2TowerDoc *inDoc) { + if (mCurrentSprite == -1) { + mCurrentSprite = mTrainSpriteIndices[mTrainType]; + mVisible = false; + } + return mCurrentSprite != -1; +} + +void T2MetroRailway::Show() { + if (GetTowerDoc() && !mVisible && mCurrentSprite != -1) { + GetTowerDoc()->mSprite.ShowSprite(mCurrentSprite, true); + mVisible = true; + } +} + +void T2MetroRailway::Hide() { + if (GetTowerDoc() && mVisible && mCurrentSprite != -1) { + GetTowerDoc()->mSprite.ShowSprite(mCurrentSprite, false); + mVisible = false; + } +} + +/*virtual*/ void T2MetroRailway::Read(T2Archive& inArchive) { + T2Transport::Read(inArchive); +} + +/*virtual*/ void T2MetroRailway::Write(T2Archive& inArchive) { + T2Transport::Write(inArchive); +} diff --git a/src/T2DLL/T2MetroRailway.h b/src/T2DLL/T2MetroRailway.h new file mode 100644 index 0000000..40a7277 --- /dev/null +++ b/src/T2DLL/T2MetroRailway.h @@ -0,0 +1,35 @@ +#pragma once +#include "common.h" +#include "T2EventItem.h" +#include "T2Transport.h" + +class T2MetroRailway : public T2EventItem, public T2Transport { +public: + T2MetroRailway(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); + T2MetroRailway(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime); + virtual ~T2MetroRailway(); + virtual DWORD GetID() { return 'MREv'; } + virtual int Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc *inDoc); + virtual void StopEvent(T2TowerDoc* inDoc); + virtual BOOL IsBeginTime(unsigned int inTime); + virtual void Write(T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); + virtual void DoSetStatus(int inStatus) { SetStatus(inStatus); } + virtual T2TowerDoc *DoGetTowerDoc() const { return GetTowerDoc(); } + virtual int DoGetBeginTime() { return GetBeginTime(); } + virtual T2WorldDef *DoGetWorldDef() { return GetWorldDef(); } + + void Init(T2Transport* inParent, CResFile* inResFile); + BOOL CreateSpriteObj(T2TowerDoc *inDoc); + void Show(); + void Hide(); + +protected: + int m74; + int mCurrentSprite; + int mTrainSpriteIndices[4]; + T2BitImage *mImage; + T2ImageObj *mImageObj; + BOOL mVisible; +}; diff --git a/src/T2DLL/T2Mover.cpp b/src/T2DLL/T2Mover.cpp index 9472651..df3d264 100644 --- a/src/T2DLL/T2Mover.cpp +++ b/src/T2DLL/T2Mover.cpp @@ -1,139 +1,771 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2ElvModuleList.h" +#include "T2FloorInfo.h" #include "T2Mover.h" +#include "T2MoverCEArray.h" +#include "T2MoverDef.h" +#include "T2MoverModule.h" +#include "T2MoverModuleList.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleLinkIterator.h" +#include "T2Request.h" +#include "T2RequestIDArray.h" +#include "T2RouteNavigator.h" +#include "T2StairModuleList.h" +#include "T2TemplatePluginList.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "UT2Coordinate.h" T2Mover::T2Mover() { + mShowShaft = true; + mLength = 0; + mReqIDArray = NULL; + mShowShaft = true; + mCheckRequest = false; + mWaitCount = 0; + mCapacity = 0; + mMaxModule = 0; + mModuleList = NULL; + + mReqIDArray = new T2RequestIDArray; +#line 27 + _ASSERT(mReqIDArray != NULL); } /*virtual*/ T2Mover::~T2Mover() { + if (mReqIDArray) + delete mReqIDArray; + if (mModuleList) + delete mModuleList; } -/*virtual*/ void T2Mover::SetUsed(int) { +/*virtual*/ void T2Mover::SetUsed(BOOL used) { + if (!used) { + T2TowerDoc *theTowerDoc = GetCurrentT2TowerDoc(); +#line 48 + _ASSERT(theTowerDoc != NULL); + + T2NameList *theNameDB = theTowerDoc->mNameDB; +#line 51 + _ASSERT(theNameDB != NULL); + + T2Name *theName = theNameDB->Search(this, true); + if (theName) { + theNameDB->RemoveName(theName); + delete theName; + } + + theName = theNameDB->Search(this, false); + if (theName) { + theNameDB->RemoveName(theName); + delete theName; + } + + if (IsStair() && mModuleList) { + LArrayIterator iterator(*mModuleList); + T2MoverModule *theModule; + while (iterator.Next(&theModule)) { + theName = theNameDB->Search(theModule, true); + if (theName) { + theNameDB->RemoveName(theName); + delete theName; + } + + theName = theNameDB->Search(theModule, false); + if (theName) { + theNameDB->RemoveName(theName); + delete theName; + } + } + } + + if (mModuleList) { + delete mModuleList; + mModuleList = NULL; + } + + if (mReqIDArray) + mReqIDArray->AllClear(); + } + + T2Equip::SetUsed(used); } -int T2Mover::InitMover(T2MoverDef*, const RECT&, unsigned int) { +BOOL T2Mover::InitMover(T2MoverDef* moverDef, const RECT& baseRect, unsigned int valiation) { + BOOL result = true; + + T2Equip::InitEquip(moverDef, baseRect, valiation); + + mStatus = kMoverStatus0; + mCEArray = new T2MoverCEArray; + mMaxModule = moverDef->GetMaxModule(); + mLength = moverDef->mHeight; + mWaitCount = moverDef->GetDefaultWait(); + mShowShaft = true; + + if (mReqIDArray) { + mReqIDArray->Init(baseRect); + + RECT addSize; + moverDef->GetAddSize(addSize); + UT2Coordinate::AddRect(mArea, addSize); + } else { + result = false; + } + + return result; } -int T2Mover::InitStair(T2MoverDef*, const RECT&, unsigned int) { +BOOL T2Mover::InitStair(T2MoverDef* moverDef, const RECT& baseRect, unsigned int valiation) { + BOOL result = true; + + InitMover(moverDef, baseRect, 0); + + mModuleList = new T2StairModuleList; + if (mModuleList) { + result = mModuleList->Init(moverDef, baseRect); + } else { + result = false; + } + + return result; } -int T2Mover::InitElevator(T2MoverDef*, const RECT&, unsigned int) { +BOOL T2Mover::InitElevator(T2MoverDef* moverDef, const RECT& baseRect, unsigned int valiation) { + BOOL result = true; + + InitMover(moverDef, baseRect, valiation); + + mModuleList = new T2ElvModuleList; + if (mModuleList) { + result = mModuleList->Init(moverDef, baseRect); + } else { + result = false; + } + + return result; } -void T2Mover::GetTypicalName(CString&) const { +void T2Mover::GetTypicalName(CString& outStr) const { + T2EquipDef *equipDef = GetEquipDef(); + if (equipDef) + equipDef->GetName(outStr, 0); + else + outStr = ""; } -/*virtual*/ PROCCODE T2Mover::DoDestruct(T2TowerDoc*, POINT, RECT&) { +/*virtual*/ PROCCODE T2Mover::DoDestruct(T2TowerDoc* towerDoc, POINT pt, RECT& rect) { + PROCCODE result = GetEquipDef()->DoDestructProc(towerDoc, this, pt, rect); + + if (result == ProcCode_0) { + PARTCODE partCode = GetPartFromPoint(towerDoc, pt, NULL); + if (partCode == PartCode_2) { + GetEquipArea(rect); + T2FloorInfo *theFloorInfo = towerDoc->mFloorInfo; + + for (int i = 0; i < mLength; i++) { + if (IsStopPosition(i)) + RemoveStopBoth(towerDoc, i); + } + + theFloorInfo->FillMoverID(rect, 0); + theFloorInfo->UpdeteRequestByRemoveMover(rect); + + GetEquipDef()->DestructFinish(towerDoc, this); + SetUsed(false); + return ProcCode_1; + } else if (partCode == PartCode_4) { + GetEquipArea(rect); + return ProcCode_1; + } else { + return ProcCode_1; + } + } + + return result; } -/*virtual*/ int T2Mover::Destruct(T2TowerDoc*, CRect&) { +/*virtual*/ BOOL T2Mover::Destruct(T2TowerDoc* towerDoc, CRect& rect) { + GetEquipArea(rect); + + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + mModuleList->Destruct(towerDoc); + + for (int i = 0; i < mLength; i++) { + if (IsStopPosition(i)) + RemoveStopBoth(towerDoc, i); + } + + theFloorInfo->FillMoverID(rect, 00); + theFloorInfo->UpdeteRequestByRemoveMover(rect); + + SetUsed(false); + + BOOL result = true; + + towerDoc->towerDoc_vf124()->MoverRemoved(this, 1); + + return result; } -/*virtual*/ void T2Mover::Draw(T2TowerDoc*, const RECT&) { +/*virtual*/ void T2Mover::Draw(T2TowerDoc* towerDoc, const RECT& rect) { + if (GetEquipDef()) + GetEquipDef()->DrawProc(this, mArea, towerDoc); } int T2Mover::GetNumStop() const { + int count = 0; + + for (int i = 0; i < mLength; i++) { + if (IsStopPosition(i)) + count++; + } + + return count; } -void T2Mover::AddStopBoth(T2TowerDoc*, int) { +void T2Mover::AddStopBoth(T2TowerDoc* towerDoc, int position) { + BOOL ok = false; + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + + ok |= AddStop(theFloorInfo, position, ERequestUpDown_0); + ok |= AddStop(theFloorInfo, position, ERequestUpDown_1); + + if (mModuleList && ok) + mModuleList->StopAdded(towerDoc, this, position); } -int T2Mover::AddStop(T2FloorInfo*, int, ERequestUpDown) { +BOOL T2Mover::AddStop(T2FloorInfo* floorInfo, int position, ERequestUpDown upDown) { + BOOL result = false; + + POINT stopPt = PositionToStopPt(position, upDown); + T2Tenant *theFloor = floorInfo->GetFloor(stopPt.y, stopPt.x); + + if (theFloor) { + CRect rect; + GetEquipArea(rect); + + if (rect.Height() == 1 || stopPt.y == (rect.bottom - 1)) { + if (!IsStopPosition(position)) + AddCrossEquipID(floorInfo, position); + + if (mReqIDArray) { + T2Request *theRequest = floorInfo->FindUnusedRequest(); + if (theRequest) { + mReqIDArray->SetRequestIDAt(position, upDown, theRequest->GetRequestID()); + POINT stopPt2 = PositionToStopPt(position, upDown); + theRequest->InitRequest(floorInfo, mEquipID, stopPt2, upDown); + } + } + + result = true; + } + } + + return result; } -void T2Mover::RemoveStopBoth(T2TowerDoc*, int) { +void T2Mover::RemoveStopBoth(T2TowerDoc* towerDoc, int position) { + RemoveStop(towerDoc, position, ERequestUpDown_0); + RemoveStop(towerDoc, position, ERequestUpDown_1); + + RemoveCrossEquipID(towerDoc->towerDoc_vf12C(), position); + mReqIDArray->StopRemoved(towerDoc, PositionToUnit(position)); + + if (mModuleList) + mModuleList->StopRemoved(towerDoc, this, position); } -void T2Mover::RemoveStop(T2TowerDoc*, int, ERequestUpDown) { +void T2Mover::RemoveStop(T2TowerDoc* towerDoc, int position, ERequestUpDown upDown) { + if (mReqIDArray) + mReqIDArray->RemoveRequest(towerDoc, position, upDown); } -void T2Mover::RemoveCrossEquipID(T2FloorInfo*, int) { +void T2Mover::RemoveCrossEquipID(T2FloorInfo* floorInfo, int position) { + POINT stopPt = PositionToStopPt(position, ERequestUpDown_0); + T2Tenant *theFloor = floorInfo->GetFloor(stopPt.y, stopPt.x); + + if (theFloor) { + RemoveCEID(theFloor->GetEquipID()); + theFloor->RemoveCEID(mEquipID); + } } -void T2Mover::RemoveUnstoppable(T2TowerDoc*) { +void T2Mover::RemoveUnstoppable(T2TowerDoc* towerDoc) { + T2MoverDef *theMoverDef = (T2MoverDef *) GetEquipDef(); + BOOL changed = false; + + for (int i = 0; i < mLength; i++) { + if (IsStopPosition(i) && !theMoverDef->IsaKindOfStopProc(towerDoc, this, i, 0)) { + RemoveStopBoth(towerDoc, i); + changed = true; + } + } + + if (changed) + towerDoc->GetTowerMainView()->tmv_vf128(mArea); } -void T2Mover::AddCrossEquipID(T2FloorInfo*, int) { +void T2Mover::AddCrossEquipID(T2FloorInfo* floorInfo, int position) { + POINT stopPt = PositionToStopPt(position, ERequestUpDown_0); + T2Tenant *theFloor = floorInfo->GetFloor(stopPt.y, stopPt.x); + + if (theFloor) + theFloor->AddCEMoverID(floorInfo, stopPt, mEquipID); + AddCEFloorID(floorInfo, position); } -void T2Mover::AddCEFloorID(T2FloorInfo*, int) { +void T2Mover::AddCEFloorID(T2FloorInfo* floorInfo, int position) { + POINT stopPt = PositionToStopPt(position, ERequestUpDown_0); + unsigned int floorID = floorInfo->GetFloorID(stopPt.y, stopPt.x); + + if (floorID != 0) { + int i; + for (i = position - 1; i >= 0; i--) { + if (IsStopPosition(i)) + break; + } + + unsigned int idA = 0; + if (i >= 0) + floorInfo->GetFloorID(stopPt.y, stopPt.x - (position - i)); + + InsertCEID(idA, floorID); + } } -void T2Mover::ReplaceID(T2FloorInfo*, unsigned int) { +void T2Mover::ReplaceID(T2FloorInfo* floorInfo, unsigned int id) { + floorInfo->UpdateFloorCEArray(mArea, mEquipID, id); + floorInfo->FillMoverID(mArea, id); } -POINT T2Mover::PositionToStopPt(int, ERequestUpDown) { +POINT T2Mover::PositionToStopPt(int position, ERequestUpDown upDown) { + POINT result; + result.x = 0; + result.y = 0; + + T2MoverDef *theMoverDef = (T2MoverDef *) GetEquipDef(); + if (theMoverDef) { + RECT addSize; + theMoverDef->GetAddSize(addSize); + + result.y = mArea.bottom - 1 - addSize.bottom - position; + if (upDown == ERequestUpDown_0) + result.x = mArea.left; + else + result.x = mArea.right; + } + + return result; } -int T2Mover::UnitToPosition(int) const { +int T2Mover::UnitToPosition(int unit) const { + int result; + T2MoverDef *theMoverDef = (T2MoverDef *) GetEquipDef(); +#line 495 + _ASSERT(theMoverDef != NULL); + + RECT addSize; + theMoverDef->GetAddSize(addSize); + return mArea.bottom - 1 - addSize.bottom - unit; } -int T2Mover::PositionToUnit(int) const { +int T2Mover::PositionToUnit(int position) const { + int result = mArea.bottom - 1 - position; + + T2MoverDef *theMoverDef = (T2MoverDef *) GetEquipDef(); + if (theMoverDef) { + RECT addSize; + theMoverDef->GetAddSize(addSize); + result -= addSize.bottom; + } + + return result; } -int T2Mover::IsStopPosition(int) const { +BOOL T2Mover::IsStopPosition(int position) const { + BOOL result = false; + + if (position >= 0 && mCEArray && mReqIDArray->IsStopPosition(position)) + result = true; + + return result; } -int T2Mover::IsStopPosition(int, ERequestUpDown) { +BOOL T2Mover::IsStopPosition(int position, ERequestUpDown upDown) { + BOOL result = false; + + if (position >= 0 && mCEArray && mReqIDArray->GetRequestIDAt(position, upDown)) + result = true; + + return result; } -int T2Mover::AddModule(T2TowerDoc*, int) { +BOOL T2Mover::AddModule(T2TowerDoc* towerDoc, int position) { + BOOL result = false; + + if (GetModuleCount() < mMaxModule && mModuleList) { + ((T2ElvModuleList *) mModuleList)->AddModule(towerDoc, mLength, position); + result = true; + } + + return result; } -void T2Mover::AddStairModule(T2TowerDoc*, const RECT&, int) { +void T2Mover::AddStairModule(T2TowerDoc* towerDoc, const RECT& rect, BOOL insertAtEnd) { + if (mModuleList) + ((T2StairModuleList *) mModuleList)->AddModule(towerDoc, rect, insertAtEnd); } -unsigned int T2Mover::GetRequestID(int, int) const { +unsigned int T2Mover::GetRequestID(int position, BOOL isDown) const { + unsigned int result = 0; + + ERequestUpDown upDown = ERequestUpDown_0; + if (isDown) + upDown = ERequestUpDown_1; + + result = mReqIDArray->GetRequestIDAt(position, upDown); + return result; } int T2Mover::GetModuleCount() const { -} + int result = 0; -int T2Mover::FindStairModule(T2TowerDoc*, POINT, T2MoverModule*&, T2MoverModule*&) { -} + if (mModuleList) + result = mModuleList->GetModuleCount(); -int T2Mover::CalcModuleRect(const T2MoverModule*, RECT&, int&) const { + return result; } -T2MoverModule* T2Mover::FindPeople(const T2People*) const { -} +BOOL T2Mover::FindStairModule(T2TowerDoc* towerDoc, POINT pt, T2MoverModule*& module1, T2MoverModule*& module2) { + int var; + PARTCODE partCode = GetPartFromPoint(towerDoc, pt, &var); + BOOL result = (partCode == PartCode_2 && var >= 0); -void T2Mover::CalcMachineArea(EEquipPos, RECT&) const { -} + if (result) { + if (!mModuleList->FetchItemAt(var, &module1) || !mModuleList->FetchItemAt(var + 1, &module2)) + result = false; + } -void T2Mover::AdjustLength() { + return result; } -T2Request* T2Mover::GetRequest(T2FloorInfo*, int, int) const { +int T2Mover::CalcModuleRect(const T2MoverModule* module, RECT& rect, int& unk) const { + return ((T2MoverDef *) GetEquipDef())->CalcModuleRectProc(this, module, rect, unk); } -int T2Mover::CalcScore(int) const { -} +T2MoverModule* T2Mover::FindPeople(const T2People* inPeople) const { + T2MoverModule *result = NULL; + T2MoverModuleList *theList = GetModuleList(); -int T2Mover::ExpandArea(T2TowerDoc*, EEquipPos, int) { -} + if (theList) { + LArrayIterator moduleIterator(*theList); + T2MoverModule *moverModule; + + while (!result && moduleIterator.Next(&moverModule)) { + if (moverModule->IsUsed() && moverModule->mLink1) { + T2PeopleLinkIterator peopleIterator((T2People *) moverModule->mLink1); + T2People *people; -int T2Mover::IsHomePosition(int) const { + while (peopleIterator.Next(&people)) { + if (people == inPeople) { + result = moverModule; + break; + } + } + } + } + } + + return result; } -void T2Mover::CalcBodyArea(RECT&) const { +void T2Mover::CalcMachineArea(EEquipPos pos, RECT& rect) const { + rect = mArea; + +#line 672 + _ASSERT(mToolDef != NULL); + + RECT addSize; + ((T2MoverDef *) mToolDef)->GetAddSize(addSize); + + switch (pos) { + case EEquipPos_0: + rect.right = rect.left - addSize.left; + break; + case EEquipPos_1: + rect.left = rect.right - addSize.right; + break; + case EEquipPos_2: + rect.bottom = rect.top - addSize.top; + break; + case EEquipPos_3: + rect.top = rect.bottom - addSize.bottom; + break; + } } -int T2Mover::CalcModulePos(T2MoverModule*, ERequestUpDown) { +void T2Mover::AdjustLength() { + CRect rect; + CalcBodyArea(rect); + + mLength = rect.Height(); +} + +T2Request* T2Mover::GetRequest(T2FloorInfo* floorInfo, int position, BOOL isDown) const { + T2Request *result = NULL; + + unsigned int requestID = GetRequestID(position, isDown); + if (requestID) + result = floorInfo->GetRequest(requestID); + + return result; +} + +int T2Mover::CalcScore(int multiplier) const { + int result = 0x7FFF; + + if (GetEquipDef()) { + if (multiplier < 0) + multiplier *= -1; + + result = ((T2MoverDef *) GetEquipDef())->GetScore() * multiplier; + } + + return result; +} + +int T2Mover::ExpandArea(T2TowerDoc* towerDoc, EEquipPos pos, int count) { + int result = 0; + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + + RECT area = mArea; + + RECT addSize; + ((T2MoverDef *) mToolDef)->GetAddSize(addSize); + + switch (pos) { + case EEquipPos_2: + if (count < 0) { + for (int i = 0; i < -count; i++) { + int position = mLength - 1 - i; + if (IsStopPosition(position)) { + RemoveStopBoth(towerDoc, position); + result = 2; + } + } + } + + mArea.top -= count; + mLength += count; + mReqIDArray->Expand(ReqIDArrayPos_1, count); + ((T2ElvModuleList *) mModuleList)->MoverExpanded(this, EEquipPos_2, count); + + if (count > 0) { + area.bottom = area.top; + area.top -= count; + theFloorInfo->MoverAreaAdded(area, mEquipID); + area.bottom += -addSize.top; + } else { + area.bottom = area.top - count; + theFloorInfo->MoverAreaRemoved(area); + area.bottom += -addSize.top + 1; + } + + if (count > 0) { + RemoveUnstoppable(towerDoc); + T2MoverDef *theMoverDef = (T2MoverDef *) GetEquipDef(); + for (int i = 0; i < count; i++) { + int position = mLength - 1 - i; + if (theMoverDef->GetMaxStop() == 0 || GetNumStop() < theMoverDef->GetMaxStop()) { + if (theMoverDef->IsaKindOfStopProc(towerDoc, this, position, 1) && !IsStopPosition(position)) { + AddStopBoth(towerDoc, position); + result = 1; + } + } + } + } + + break; + + case EEquipPos_3: + if (count < 0) { + for (int position = 0; position < -count; position++) { + if (IsStopPosition(position)) { + RemoveStopBoth(towerDoc, position); + result = 2; + } + } + } + + mArea.bottom += count; + mLength += count; + mReqIDArray->Expand(ReqIDArrayPos_0, count); + ((T2ElvModuleList *) mModuleList)->MoverExpanded(this, EEquipPos_3, count); + + if (count > 0) { + area.top = area.bottom; + area.bottom += count; + theFloorInfo->MoverAreaAdded(area, mEquipID); + area.top -= addSize.bottom; + } else { + area.top = area.bottom + count; + theFloorInfo->MoverAreaRemoved(area); + area.top -= addSize.bottom + 1; + } + + if (count > 0) { + RemoveUnstoppable(towerDoc); + T2MoverDef *theMoverDef = (T2MoverDef *) GetEquipDef(); + for (int position = 0; position < count; position++) { + if (theMoverDef->GetMaxStop() == 0 || GetNumStop() < theMoverDef->GetMaxStop()) { + if (theMoverDef->IsaKindOfStopProc(towerDoc, this, position, 1) && !IsStopPosition(position)) { + AddStopBoth(towerDoc, position); + result = 1; + } + } + } + } + + break; + } + + if (count != 0) + towerDoc->GetTowerMainView()->tmv_vf128(area, true); + + return result; +} + +BOOL T2Mover::IsHomePosition(int position) const { + BOOL result = false; + + if (mModuleList) + result = ((T2ElvModuleList *) mModuleList)->IsHomePosition(position); + + return result; +} + +void T2Mover::CalcBodyArea(RECT& rect) const { + rect = mArea; + + if (GetEquipDef()) { + RECT addSize; + ((T2MoverDef *) GetEquipDef())->GetAddSize(addSize); + + rect.top -= addSize.top; + rect.left -= addSize.left; + rect.bottom -= addSize.bottom; + rect.right -= addSize.right; + } +} + +int T2Mover::CalcModulePos(T2MoverModule* module, ERequestUpDown upDown) { + return ((T2MoverDef *) GetEquipDef())->CalcModulePosProc(this, module, upDown); } void T2Mover::ShowShaft() { + if (!mShowShaft) { + mShowShaft = true; + + T2TowerDoc *theTowerDoc = GetCurrentT2TowerDoc(); + theTowerDoc->GetTowerMainView()->tmv_vf128(mArea); + } } void T2Mover::HideShaft() { + if (mShowShaft) { + mShowShaft = false; + + T2TowerDoc *theTowerDoc = GetCurrentT2TowerDoc(); + theTowerDoc->GetTowerMainView()->tmv_vf128(mArea); + theTowerDoc->towerDoc_vf12C()->SetTenantDrawModeByRect(mArea, DrawMode2); + } } -/*virtual*/ unsigned int T2Mover::Idle(T2TowerDoc*) { +/*virtual*/ unsigned int T2Mover::Idle(T2TowerDoc* towerDoc) { + unsigned int result = 0xFFFFFFFF; + result = ((T2MoverDef *) GetEquipDef())->IdleProc(this, towerDoc); + return result; } -/*virtual*/ void T2Mover::LoadSelf(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2Mover::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + DWORD code; + archive >> code; +#line 1193 + _ASSERT(code == '<MV>'); + + T2Equip::LoadSelf(archive, towerDoc); + + if (IsUsed()) { + mToolDef = towerDoc->mMoverTemplates->FindMoverDef(mEquipType); + if (mToolDef) { + mAttribute = mToolDef->GetAttribute(); + mCapacity = GetEquipDef()->GetCapacity(); + } + + unsigned char uc; + short s; + + archive >> uc; + mShowShaft = (uc != 0); + + mCheckRequest = true; + + archive >> s; + mLength = s; + + mReqIDArray = T2RequestIDArray::ReadReqIDArray(archive); + + archive >> s; + mWaitCount = s; + archive >> s; + mMaxModule = s; + + mModuleList = T2MoverModuleList::ReadMMList(archive, towerDoc); + + archive >> mRefCon; + + if (GetEquipDef()) { + GetEquipDef()->LoadExtraData(archive, towerDoc, this); + } else { + int count; + archive >> count; + + for (int i = 0; i < count; i++) { + unsigned char tmp; + archive >> tmp; + } + } + } } -/*virtual*/ void T2Mover::SaveSelf(T2Archive&) { +/*virtual*/ void T2Mover::SaveSelf(T2Archive& archive) { + DWORD code = '<MV>'; + archive << code; + + T2Equip::SaveSelf(archive); + + if (IsUsed()) { + unsigned char uc; + uc = mShowShaft ? 1 : 0; + archive << uc; + + archive << (short) mLength; + T2RequestIDArray::WriteReqIDArray(mReqIDArray, archive); + archive << (short) mWaitCount; + archive << (short) mMaxModule; + T2MoverModuleList::WriteMMList(mModuleList, archive); + archive << mRefCon; + + GetEquipDef()->SaveExtraData(archive, this); + } } -/*virtual*/ T2InfoDialog* T2Mover::ShowInfoDialog(T2TowerDoc*, CPoint) { +/*virtual*/ T2InfoDialog* T2Mover::ShowInfoDialog(T2TowerDoc* towerDoc, CPoint pt) { + return ((T2MoverDef *) GetEquipDef())->ShowInfoDialog(towerDoc, this, pt); } diff --git a/src/T2DLL/T2Mover.h b/src/T2DLL/T2Mover.h index 18326bd..f4979dd 100644 --- a/src/T2DLL/T2Mover.h +++ b/src/T2DLL/T2Mover.h @@ -1,71 +1,86 @@ #pragma once #include "common.h" +#include "T2Equip.h" -class T2Mover { +enum { + kMoverStatus0 = 0, + kMoverStatus9 = 9 +}; + +class AFX_EXT_CLASS T2Mover : public T2Equip { public: T2Mover(); virtual ~T2Mover(); - virtual void SetUsed(int); - int InitMover(T2MoverDef*, const RECT&, unsigned int); - int InitStair(T2MoverDef*, const RECT&, unsigned int); - int InitElevator(T2MoverDef*, const RECT&, unsigned int); + virtual void SetUsed(BOOL); + virtual BOOL Enter(CLink*) { return false; } + virtual BOOL Leave(CLink*) { return false; } + virtual unsigned int Idle(T2TowerDoc*); + virtual void Draw(T2TowerDoc*, const RECT&); + virtual BOOL IsBuildFinish() { return mStatus >= kMoverStatus9; } + virtual PROCCODE DoDestruct(T2TowerDoc*, POINT, RECT&); + virtual BOOL Destruct(T2TowerDoc*, CRect&); + virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*, CPoint); + + BOOL InitMover(T2MoverDef* moverDef, const RECT& baseRect, unsigned int valiation); + BOOL InitStair(T2MoverDef* moverDef, const RECT& baseRect, unsigned int valiation); + BOOL InitElevator(T2MoverDef* moverDef, const RECT& baseRect, unsigned int valiation); void GetTypicalName(CString&) const; - virtual PROCCODE DoDestruct(T2TowerDoc*, POINT, RECT&); - virtual int Destruct(T2TowerDoc*, CRect&); - virtual void Draw(T2TowerDoc*, const RECT&); int GetNumStop() const; - void AddStopBoth(T2TowerDoc*, int); - int AddStop(T2FloorInfo*, int, ERequestUpDown); - void RemoveStopBoth(T2TowerDoc*, int); - void RemoveStop(T2TowerDoc*, int, ERequestUpDown); - void RemoveCrossEquipID(T2FloorInfo*, int); - void RemoveUnstoppable(T2TowerDoc*); - void AddCrossEquipID(T2FloorInfo*, int); - void AddCEFloorID(T2FloorInfo*, int); - void ReplaceID(T2FloorInfo*, unsigned int); - POINT PositionToStopPt(int, ERequestUpDown); - int UnitToPosition(int) const; - int PositionToUnit(int) const; - int IsStopPosition(int) const; - int IsStopPosition(int, ERequestUpDown); - int AddModule(T2TowerDoc*, int); - void AddStairModule(T2TowerDoc*, const RECT&, int); - unsigned int GetRequestID(int, int) const; + void AddStopBoth(T2TowerDoc* towerDoc, int position); + BOOL AddStop(T2FloorInfo* floorInfo, int position, ERequestUpDown upDown); + void RemoveStopBoth(T2TowerDoc* towerDoc, int position); + void RemoveStop(T2TowerDoc* towerDoc, int position, ERequestUpDown upDown); + void RemoveCrossEquipID(T2FloorInfo* floorInfo, int position); + void RemoveUnstoppable(T2TowerDoc* towerDoc); + void AddCrossEquipID(T2FloorInfo* floorInfo, int position); + void AddCEFloorID(T2FloorInfo* floorInfo, int position); + void ReplaceID(T2FloorInfo* floorInfo, unsigned int); + POINT PositionToStopPt(int position, ERequestUpDown upDown); + int UnitToPosition(int unit) const; + int PositionToUnit(int position) const; + BOOL IsStopPosition(int position) const; + BOOL IsStopPosition(int position, ERequestUpDown upDown); + BOOL AddModule(T2TowerDoc* towerDoc, int position); + void AddStairModule(T2TowerDoc* towerDoc, const RECT& rect, BOOL insertAtEnd); + unsigned int GetRequestID(int position, BOOL isDown) const; int GetModuleCount() const; int FindStairModule(T2TowerDoc*, POINT, T2MoverModule*&, T2MoverModule*&); int CalcModuleRect(const T2MoverModule*, RECT&, int&) const; T2MoverModule* FindPeople(const T2People*) const; void CalcMachineArea(EEquipPos, RECT&) const; void AdjustLength(); - T2Request* GetRequest(T2FloorInfo*, int, int) const; + T2Request* GetRequest(T2FloorInfo* floorInfo, int position, BOOL isDown) const; int CalcScore(int) const; - int ExpandArea(T2TowerDoc*, EEquipPos, int); - int IsHomePosition(int) const; + int ExpandArea(T2TowerDoc* towerDoc, EEquipPos pos, int count); + BOOL IsHomePosition(int) const; void CalcBodyArea(RECT&) const; int CalcModulePos(T2MoverModule*, ERequestUpDown); void ShowShaft(); void HideShaft(); - virtual unsigned int Idle(T2TowerDoc*); + + void SetShowShaft(BOOL v) { mShowShaft = v; } + void StartBuild() { mStatus = kMoverStatus0; } + BOOL IsStair() const { return IsSetAttribute(kMoverAttrIsStair); } + BOOL IsElevator() const { return IsSetAttribute(kMoverAttrIsElevator); } + BOOL IsCheckRequest() const { return mCheckRequest; } + void SetCheckRequest(BOOL v) { mCheckRequest = v; } + int GetLength() const { return mLength; } + int GetWaitCount() const { return mWaitCount; } + T2RequestIDArray* GetReqIDArray() const { return mReqIDArray; } + T2MoverModuleList* GetModuleList() const { return mModuleList; } + BOOL IsShaftVisible() const { return mShowShaft; } + protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); -public: - virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*, CPoint); + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); + + friend class T2MoverDef; - void SetShowShaft(int) {} - void StartBuild() {} - virtual int IsBuildFinish() {} - virtual int Enter(CLink*) {} - virtual int Leave(CLink*) {} - T2Mover(const T2Mover&) {} - T2Mover& operator=(const T2Mover&) {} - int IsStair() const {} - int IsElevator() const {} - int IsCheckRequest() const {} - void SetCheckRequest(int) {} - int GetLength() const {} - int GetWaitCount() const {} - T2RequestIDArray* GetReqIDArray() const {} - T2MoverModuleList* GetModuleList() const {} - int IsShaftVisible() const {} + int mLength; + T2RequestIDArray *mReqIDArray; + int mWaitCount; + int mMaxModule; + T2MoverModuleList *mModuleList; + BOOL mShowShaft; + BOOL mCheckRequest; }; diff --git a/src/T2DLL/T2MoverArray.cpp b/src/T2DLL/T2MoverArray.cpp index 9ecffac..4f98a81 100644 --- a/src/T2DLL/T2MoverArray.cpp +++ b/src/T2DLL/T2MoverArray.cpp @@ -1,25 +1,61 @@ #include "T2MoverArray.h" -T2MoverArray::T2MoverArray(unsigned int) { +T2MoverArray::T2MoverArray(unsigned int inStartID) + : T2ObjectArray(inStartID) +{ + for (unsigned int i = 0; i < kGroupSize; i++) + mMover[i].mEquipID = mStartID + i; } /*virtual*/ T2MoverArray::~T2MoverArray() { } T2Mover* T2MoverArray::FindUnusedMover() { + for (int i = 0; i < kGroupSize; i++) { + if (!mMover[i].IsUsed()) + return &mMover[i]; + } + + return NULL; } -void T2MoverArray::DrawMoverAll(T2TowerDoc*, const RECT&) { +void T2MoverArray::DrawMoverAll(T2TowerDoc* inDoc, const RECT& inRect) { + for (int i = 0; i < kGroupSize; i++) { + T2Mover *theMover = &mMover[i]; + if (theMover->IsUsed()) { + RECT moverArea; + RECT intersection; + theMover->GetEquipArea(moverArea); + if (IntersectRect(&intersection, &moverArea, &inRect)) + theMover->Draw(inDoc, inRect); + } + } } -/*virtual*/ void T2MoverArray::DispatchIdle(T2TowerDoc*, int) { +/*virtual*/ void T2MoverArray::DispatchIdle(T2TowerDoc* inDoc, int) { + for (int i = 0; i < kGroupSize; i++) { + if (mMover[i].IsUsed()) + mMover[i].Idle(inDoc); + } } -int T2MoverArray::CalcMentenanceCost(T2TowerDoc*) const { +int T2MoverArray::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int cost = 0; + + for (int i = 0; i < kGroupSize; i++) { + if (mMover[i].IsUsed()) + cost += mMover[i].CalcMentenanceCost(inDoc); + } + + return cost; } -void T2MoverArray::Read(T2Archive&, T2TowerDoc*) { +void T2MoverArray::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + for (int i = 0; i < kGroupSize; i++) + mMover[i].Load(inArchive, inDoc); } -void T2MoverArray::Write(T2Archive&) { +void T2MoverArray::Write(T2Archive& inArchive) { + for (int i = 0; i < kGroupSize; i++) + mMover[i].Save(inArchive); } diff --git a/src/T2DLL/T2MoverArray.h b/src/T2DLL/T2MoverArray.h index 794f8ee..4018dba 100644 --- a/src/T2DLL/T2MoverArray.h +++ b/src/T2DLL/T2MoverArray.h @@ -1,19 +1,25 @@ #pragma once #include "common.h" +#include "T2Mover.h" +#include "T2ObjectArray.h" -class T2MoverArray { +class AFX_EXT_CLASS T2MoverArray : public T2ObjectArray { public: - T2MoverArray(unsigned int); + enum { kGroupSize = 32 }; + + T2MoverArray(unsigned int inStartID = 1); virtual ~T2MoverArray(); + virtual void DispatchIdle(T2TowerDoc* inDoc, int); T2Mover* FindUnusedMover(); - void DrawMoverAll(T2TowerDoc*, const RECT&); - virtual void DispatchIdle(T2TowerDoc*, int); - int CalcMentenanceCost(T2TowerDoc*) const; - void Read(T2Archive&, T2TowerDoc*); - void Write(T2Archive&); + void DrawMoverAll(T2TowerDoc* inDoc, const RECT& inRect); + int CalcMentenanceCost(T2TowerDoc* inDoc) const; + void Read(T2Archive& inArchive, T2TowerDoc* inDoc); + void Write(T2Archive& inArchive); + + T2Mover* GetIndexMover(int i) { return &mMover[i]; } + +protected: + friend class T2MoverArrayList; - T2Mover* GetIndexMover(int) {} - T2MoverArray(const T2MoverArray&) {} - T2MoverArray& operator=(const T2MoverArray&) {} - void `default constructor closure'() {} + T2Mover mMover[kGroupSize]; }; diff --git a/src/T2DLL/T2MoverArrayList.cpp b/src/T2DLL/T2MoverArrayList.cpp index 09894aa..d36c2de 100644 --- a/src/T2DLL/T2MoverArrayList.cpp +++ b/src/T2DLL/T2MoverArrayList.cpp @@ -1,40 +1,148 @@ +#include "T2Archive.h" +#include "T2MoverArray.h" #include "T2MoverArrayList.h" -T2MoverArrayList::T2MoverArrayList() { +T2MoverArrayList::T2MoverArrayList() + : LArray(sizeof(T2MoverArray *)) +{ + T2MoverArray *theArray = new T2MoverArray; + Add(theArray); } /*virtual*/ T2MoverArrayList::~T2MoverArrayList() { + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + delete theArray; } -void T2MoverArrayList::Add(T2MoverArray*) { +void T2MoverArrayList::Add(T2MoverArray* inArray) { + InsertItemsAt(1, mItemCount + 1, &inArray); } unsigned int T2MoverArrayList::GetItemCount() { + return GetCount(); } -T2MoverArray* T2MoverArrayList::GetItemAt(int) { +T2MoverArray* T2MoverArrayList::GetItemAt(int inIndex) { + T2MoverArray *theArray; + FetchItemAt(inIndex, &theArray); + return theArray; } -T2Mover* T2MoverArrayList::GetMoverByID(unsigned int) { +T2Mover* T2MoverArrayList::GetMoverByID(unsigned int inMoverID) { + if (inMoverID == 0) + return NULL; + + int groupID = (inMoverID - 1) / T2MoverArray::kGroupSize; + int indexInGroup = (inMoverID - 1) % T2MoverArray::kGroupSize; + if (GetCount() > groupID) + return GetItemAt(groupID + 1)->GetIndexMover(indexInGroup); + else + return NULL; } T2Mover* T2MoverArrayList::FindUnusedMover() { + T2Mover *result = NULL; + LArrayIterator iterator(*this); + T2MoverArray *theArray = NULL; + + while (!result && iterator.Next(&theArray)) + result = theArray->FindUnusedMover(); + + if (!result) { + unsigned int startID = 1; + if (theArray) + startID = theArray->GetStartID() + T2MoverArray::kGroupSize; + + if ((startID + T2MoverArray::kGroupSize) < 1000) { + theArray = new T2MoverArray(startID); + if (theArray) { + Add(theArray); + result = theArray->FindUnusedMover(); + } + } + } + + return result; } -void T2MoverArrayList::DrawMoverAll(T2TowerDoc*, const RECT&) { +void T2MoverArrayList::DrawMoverAll(T2TowerDoc* inDoc, const RECT& inRect) { + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->DrawMoverAll(inDoc, inRect); } -void T2MoverArrayList::DispatchIdle(T2TowerDoc*) { +void T2MoverArrayList::DispatchIdle(T2TowerDoc* inDoc) { + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->DispatchIdle(inDoc, 0); } -void T2MoverArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2MoverArrayList::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + int groupCount; + inArchive >> groupCount; + + RemoveItemsAt(GetCount(), 1); + + unsigned int startID = 1; + for (int i = 0; i < groupCount; i++) { + Add(new T2MoverArray(startID)); + startID += T2MoverArray::kGroupSize; + } + + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->Read(inArchive, inDoc); } -void T2MoverArrayList::Write(T2Archive&) { +void T2MoverArrayList::Write(T2Archive& inArchive) { + int groupCount = GetItemCount(); + inArchive << groupCount; + + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + theArray->Write(inArchive); } -int T2MoverArrayList::CalcMentenanceCost(T2TowerDoc*) const { +int T2MoverArrayList::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int cost = 0; + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) + cost += theArray->CalcMentenanceCost(inDoc); + + return cost; } -LArray* T2MoverArrayList::MakeMoverList(int) { +LArray* T2MoverArrayList::MakeMoverList(int inType) { + LArray *result = new LArray(sizeof(T2Mover *)); + + LArrayIterator iterator(*this); + T2MoverArray *theArray; + + while (iterator.Next(&theArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + T2Mover *theMover = &theArray->mMover[i]; + if (theMover->IsUsed() && theMover->GetEquipType() == inType) + result->Add(&theMover); + } + } + + if (result->GetCount() > 0) { + return result; + } else { + delete result; + return NULL; + } } diff --git a/src/T2DLL/T2MoverArrayList.h b/src/T2DLL/T2MoverArrayList.h index 8f944bb..8d69581 100644 --- a/src/T2DLL/T2MoverArrayList.h +++ b/src/T2DLL/T2MoverArrayList.h @@ -1,22 +1,20 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2MoverArrayList { +class AFX_EXT_CLASS T2MoverArrayList : public LArray { public: T2MoverArrayList(); virtual ~T2MoverArrayList(); - void Add(T2MoverArray*); + void Add(T2MoverArray* inArray); unsigned int GetItemCount(); - T2MoverArray* GetItemAt(int); - T2Mover* GetMoverByID(unsigned int); + T2MoverArray* GetItemAt(int inIndex); + T2Mover* GetMoverByID(unsigned int inMoverID); T2Mover* FindUnusedMover(); - void DrawMoverAll(T2TowerDoc*, const RECT&); - void DispatchIdle(T2TowerDoc*); - void Read(T2Archive&, T2TowerDoc*); - void Write(T2Archive&); - int CalcMentenanceCost(T2TowerDoc*) const; - LArray* MakeMoverList(int); - - T2MoverArrayList(const T2MoverArrayList&) {} - T2MoverArrayList& operator=(const T2MoverArrayList&) {} + void DrawMoverAll(T2TowerDoc* inDoc, const RECT& inRect); + void DispatchIdle(T2TowerDoc* inDoc); + void Read(T2Archive& inArchive, T2TowerDoc* inDoc); + void Write(T2Archive& inArchive); + int CalcMentenanceCost(T2TowerDoc* inDoc) const; + LArray* MakeMoverList(int inType); }; diff --git a/src/T2DLL/T2MoverCEArray.h b/src/T2DLL/T2MoverCEArray.h index c0be283..34be7dd 100644 --- a/src/T2DLL/T2MoverCEArray.h +++ b/src/T2DLL/T2MoverCEArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2RouteCEArray.h" -class T2MoverCEArray : public T2RouteCEArray { +class AFX_EXT_CLASS T2MoverCEArray : public T2RouteCEArray { public: T2MoverCEArray(); virtual ~T2MoverCEArray(); diff --git a/src/T2DLL/T2MoverDef.cpp b/src/T2DLL/T2MoverDef.cpp index 7352822..3928cfb 100644 --- a/src/T2DLL/T2MoverDef.cpp +++ b/src/T2DLL/T2MoverDef.cpp @@ -1,58 +1,213 @@ +#include "CResFile.h" +#include "T2BitImage.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2InfoDialog.h" +#include "T2Mover.h" #include "T2MoverDef.h" - -T2MoverDef::T2MoverDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2MoverPlugin*) { +#include "T2MoverModuleList.h" +#include "T2MoverPlugin.h" +#include "T2TowerDoc.h" +#include "UT2Coordinate.h" + +T2MoverDef::T2MoverDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2MoverPlugin* plugin) + : T2EquipDef(type, specifier, resFile, worldDef, plugin) +{ + *resFile >> mAddSize; + *resFile >> mMaxLength; + *resFile >> mMinLength; + *resFile >> mMaxStop; + *resFile >> mScore; + *resFile >> mDefaultWait; + + for (int i = 0; i < 3; i++) + *resFile >> mSpeed[i]; + + *resFile >> mMaxModule; + *resFile >> m188; + *resFile >> m18C; + *resFile >> m190; + *resFile >> m194; + *resFile >> mModuleInset; + + m1AC = 5; + m1B0[0] = 3; + m1B0[1] = 10; + m1B0[2] = 15; + + DWORD tmp; + *resFile >> tmp; + *resFile >> tmp; + *resFile >> tmp; + *resFile >> tmp; + + mOffBitMap = NULL; + mOffBitMap = new T2BitImage(mModuleHandle, 200, true); + mImageObj->AddObject(mModuleHandle, 200, mOffBitMap); + + mIsLoaded = true; } /*virtual*/ T2MoverDef::~T2MoverDef() { + if (mOffBitMap) + delete mOffBitMap; } -/*virtual*/ void T2MoverDef::GetName(CString&) { +/*virtual*/ void T2MoverDef::GetName(CString& outStr) { + outStr = "MOVER"; } -int T2MoverDef::InitObject(T2Mover*, const POINT&) { +BOOL T2MoverDef::InitObject(T2Mover* mover, const POINT&) { + T2EquipDef::InitObject(mover); + return true; } -/*virtual*/ AREACHECKCODE T2MoverDef::AreaCheck(T2TowerDoc*, RECT&, unsigned int, int) { +/*virtual*/ AREACHECKCODE T2MoverDef::AreaCheck(T2TowerDoc* towerDoc, RECT& rect, unsigned int, int) { + if (!towerDoc->mFloorInfo->IsThereMover(rect)) + return AreaCheckCode_1; + + RECT adjRect = rect; + adjRect.top++; + adjRect.bottom--; + + if (adjRect.top < adjRect.bottom && !towerDoc->mFloorInfo->IsThereMover(adjRect)) + return AreaCheckCode_0; + + if (!towerDoc->mFloorInfo->IsThereOtherKindMover(rect, GetEquipType())) + return AreaCheckCode_2; + + return AreaCheckCode_0; } /*virtual*/ int T2MoverDef::ClickProc(T2TowerDoc*, RECT*, unsigned int&) { + return 0; } /*virtual*/ int T2MoverDef::MakeRequestProc(T2TowerDoc*, T2Equip*) { + return -1; } /*virtual*/ PROCCODE T2MoverDef::AddModuleProc(T2TowerDoc*, T2Equip*, RECT*) { + return ProcCode_0; } /*virtual*/ int T2MoverDef::GetMinMaxRangeProc(T2TowerDoc*, T2Equip*, int) { + return -1; } -/*virtual*/ int T2MoverDef::HandleUpProc(T2TowerDoc*, T2Equip*, POINT) { +/*virtual*/ int T2MoverDef::HandleUpProc(T2TowerDoc*, T2Equip*, POINT pt) { + return -1; } -/*virtual*/ int T2MoverDef::HandleDownProc(T2TowerDoc*, T2Equip*, POINT) { +/*virtual*/ int T2MoverDef::HandleDownProc(T2TowerDoc*, T2Equip*, POINT pt) { + return -1; } -/*virtual*/ int T2MoverDef::ClickShaftProc(T2TowerDoc*, T2Equip*, POINT) { +/*virtual*/ int T2MoverDef::ClickShaftProc(T2TowerDoc*, T2Equip*, POINT pt) { + return -1; } -/*virtual*/ int T2MoverDef::CalcModulePatIndex(int) { +/*virtual*/ int T2MoverDef::CalcModulePatIndex(int numPeople) { + int result = 0; + + if (numPeople > 0) { + if (numPeople == mCapacity) { + result = m1AC - 1; + } else { + BOOL done = false; + for (int i = 0; i < 3 && !done; i++) { + if (numPeople < m1B0[i]) { + result = i + 1; + done = true; + } + } + + if (!done) + result = 3; + } + } + + return result; } -/*virtual*/ CURSORTYPE T2MoverDef::QueryCursor(T2TowerDoc*, POINT, CString&, RECT&, POINT&, int, unsigned int, int) { +/*virtual*/ CURSORTYPE T2MoverDef::QueryCursor(T2TowerDoc* towerDoc, POINT pt, CString& outStr, RECT& ioRect, POINT& outPt, int factor, unsigned int, int) { + outStr = "Csr"; + + pt.x -= (mWidth * (UT2Coordinate::UnitHSize(factor)) / 2 - UT2Coordinate::UnitHSize(factor) / 2); + pt.y -= (mHeight * (UT2Coordinate::UnitVSize(factor)) / 2 - UT2Coordinate::UnitVSize(factor) / 2); + + UT2Coordinate::QDToUnit(pt, factor); + SetRect(&ioRect, pt.x, pt.y, pt.x + mWidth, pt.y + mHeight); + + outPt.x = ioRect.left; + outPt.y = ioRect.top; + + ioRect.top += mAddSize.top; + ioRect.left += mAddSize.left; + ioRect.right += mAddSize.right; + ioRect.bottom += mAddSize.bottom; + + UT2Coordinate::UnitToQD(ioRect, factor); + + return CursorType_0; } -/*virtual*/ int T2MoverDef::IsaKindOfStopProc(T2TowerDoc*, T2Equip*, int, int) const { +/*virtual*/ int T2MoverDef::IsaKindOfStopProc(T2TowerDoc* towerDoc, T2Equip*, int, int unk) const { + int result = 0; + + switch (unk) { + case 0: + result = 1; + break; + case 1: + result = 1; + break; + } + + return result; } -/*virtual*/ int T2MoverDef::CalcMentenanceCostProc(const T2HaveOutViewObject*) const { +/*virtual*/ int T2MoverDef::CalcMentenanceCostProc(const T2HaveOutViewObject* obj) const { + int result = 0; + + T2ToolDef *otherDef = obj->GetToolDef(); + if (otherDef->IsSetAttribute(kToolAttrNormalMenteCost)) { + result = otherDef->GetOutMoney(0); + + int moduleCount = ((T2Mover *) obj)->mModuleList->GetModuleCount(); + if (((T2Mover *) obj)->IsStair()) + moduleCount /= 2; + + result = result * moduleCount; + } + + return result; } -/*virtual*/ T2InfoDialog* T2MoverDef::ShowInfoDialog(T2TowerDoc*, T2Mover*, CPoint) { +/*virtual*/ T2InfoDialog* T2MoverDef::ShowInfoDialog(T2TowerDoc* towerDoc, T2Mover* mover, CPoint pt) { + int var = 0; + PARTCODE partCode = GetPartFromPoint(towerDoc, mover, pt, &var); + T2InfoDialog *dialog = NULL; + + if (partCode != PartCode_0) { + CRect rect; + AfxGetMainWnd()->GetWindowRect(rect); + + T2DLGTEMPLATE tmpl; + tmpl.pt = rect.CenterPoint(); + tmpl.moduleHandle = mModuleHandle; + tmpl.resID = GetInfoDialogID(towerDoc, mover, partCode, var); + dialog = ConstructInfoDialog(mover, partCode, var); + dialog->Realize(this, &tmpl, towerDoc, mImageObj, NULL, true, NULL, 0, true); + } + + return dialog; } -/*virtual*/ int T2MoverDef::GetInfoDialogID(T2TowerDoc*, const T2Mover*, PARTCODE, int) const { +/*virtual*/ int T2MoverDef::GetInfoDialogID(T2TowerDoc* towerDoc, const T2Mover* mover, PARTCODE, int) const { + return T2EquipDef::GetInfoDialogID(towerDoc, mover); } -/*virtual*/ T2InfoDialog* T2MoverDef::ConstructInfoDialog(T2Mover*, PARTCODE, int) { +/*virtual*/ T2InfoDialog* T2MoverDef::ConstructInfoDialog(T2Mover* mover, PARTCODE, int) { + return T2EquipDef::ConstructInfoDialog(mover); } diff --git a/src/T2DLL/T2MoverDef.h b/src/T2DLL/T2MoverDef.h index 32960c6..381d8b3 100644 --- a/src/T2DLL/T2MoverDef.h +++ b/src/T2DLL/T2MoverDef.h @@ -1,43 +1,65 @@ #pragma once #include "common.h" +#include "T2EquipDef.h" -class T2MoverDef { +class AFX_EXT_CLASS T2MoverDef : public T2EquipDef { public: - T2MoverDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2MoverPlugin*); + T2MoverDef(DWORD, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2MoverPlugin*); virtual ~T2MoverDef(); virtual void GetName(CString&); - int InitObject(T2Mover*, const POINT&); + virtual BOOL InitObject(T2Object*) { return false; } + virtual BOOL IsMover() { return true; } + virtual CURSORTYPE QueryCursor(T2TowerDoc*, POINT, CString&, RECT&, POINT&, int, unsigned int, int); + virtual int CalcMentenanceCostProc(const T2HaveOutViewObject*) const; virtual AREACHECKCODE AreaCheck(T2TowerDoc*, RECT&, unsigned int, int); virtual int ClickProc(T2TowerDoc*, RECT*, unsigned int&); - virtual int MakeRequestProc(T2TowerDoc*, T2Equip*); + virtual BOOL MakeRequestProc(T2TowerDoc*, T2Equip*); virtual PROCCODE AddModuleProc(T2TowerDoc*, T2Equip*, RECT*); virtual int GetMinMaxRangeProc(T2TowerDoc*, T2Equip*, int); virtual int HandleUpProc(T2TowerDoc*, T2Equip*, POINT); virtual int HandleDownProc(T2TowerDoc*, T2Equip*, POINT); virtual int ClickShaftProc(T2TowerDoc*, T2Equip*, POINT); - virtual int CalcModulePatIndex(int); - virtual CURSORTYPE QueryCursor(T2TowerDoc*, POINT, CString&, RECT&, POINT&, int, unsigned int, int); + virtual int CalcModulePatIndex(int numPeople); + virtual int CalcModulePosProc(T2Equip*, T2MoverModule*, ERequestUpDown) { return -1; } + virtual int CalcModuleRectProc(const T2Mover*, const T2MoverModule*, RECT&, int&) const { return 0; } virtual int IsaKindOfStopProc(T2TowerDoc*, T2Equip*, int, int) const; - virtual int CalcMentenanceCostProc(const T2HaveOutViewObject*) const; virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*, T2Mover*, CPoint); virtual int GetInfoDialogID(T2TowerDoc*, const T2Mover*, PARTCODE, int) const; virtual T2InfoDialog* ConstructInfoDialog(T2Mover*, PARTCODE, int); - int GetMinLength() const {} - int GetMaxLength() const {} - virtual int IsMover() {} - virtual int InitObject(T2Object*) {} - virtual int CalcModulePosProc(T2Equip*, T2MoverModule*, ERequestUpDown) {} - virtual int CalcModuleRectProc(const T2Mover*, const T2MoverModule*, RECT&, int&) const {} - int GetSpeed(int) const {} - T2MoverDef& operator=(T2MoverDef&) {} - int IsStair() {} - void GetAddSize(RECT&) const {} - int GetDefaultWait() const {} - int GetMaxModule() const {} - void GetModuleInset(RECT&) const {} - int GetMaxStop() const {} - T2BitImage* GetOffBitMap() const {} - int GetScore() const {} - static unsigned int GetRequiredRequestSpace() {} + BOOL InitObject(T2Mover*, const POINT&); + + int GetMinLength() const { return mMinLength; } + int GetMaxLength() const { return mMaxLength; } + int GetSpeed(int i) const { + return (i >= 0 && i < 3) ? mSpeed[i] : 0; + } + BOOL IsStair() { return IsSetAttribute(kMoverAttrIsStair); } + void GetAddSize(RECT& r) const { r = mAddSize; } + int GetDefaultWait() const { return mDefaultWait; } + int GetMaxModule() const { return mMaxModule; } + void GetModuleInset(RECT& r) const { r = mModuleInset; } + int GetMaxStop() const { return mMaxStop; } + T2BitImage* GetOffBitMap() const { return mOffBitMap; } + int GetScore() const { return mScore; } + + static unsigned int GetRequiredRequestSpace() { return 4; } + +protected: + RECT mAddSize; + int mMaxLength; + int mMinLength; + int mMaxStop; + int mDefaultWait; + int mSpeed[3]; + int mMaxModule; + int m188; + int m18C; + int m190; + int m194; + RECT mModuleInset; + int mScore; + int m1AC; + int m1B0[3]; + T2BitImage *mOffBitMap; }; diff --git a/src/T2DLL/T2MoverModule.cpp b/src/T2DLL/T2MoverModule.cpp index 358c1f2..d4a267b 100644 --- a/src/T2DLL/T2MoverModule.cpp +++ b/src/T2DLL/T2MoverModule.cpp @@ -1,15 +1,70 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2Mover.h" #include "T2MoverModule.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" T2MoverModule::T2MoverModule() { + mPosition = 0; + mDirection = 0; + mWaitCounter = 0; + mPatIndex = 0; + mNumPeople = 0; + _4C = 0; + mLink1 = NULL; + mLink2 = NULL; + mModuleID = 0; } /*virtual*/ T2MoverModule::~T2MoverModule() { } -/*virtual*/ void T2MoverModule::SetUsed(int) { +/*virtual*/ void T2MoverModule::SetUsed(BOOL used) { + if (!used) { + T2TowerDoc *towerDoc = GetCurrentT2TowerDoc(); +#line 35 + ASSERT(towerDoc); + + T2NameList *nameList = towerDoc->mNameDB; +#line 38 + ASSERT(nameList); + + T2Name *name = nameList->Search(this, true); + if (name) { + nameList->RemoveName(name); + delete name; + } + + name = nameList->Search(this, false); + if (name) { + nameList->RemoveName(name); + delete name; + } + } + + T2Object::SetUsed(used); } -/*virtual*/ void T2MoverModule::RemoveContents(T2TowerDoc*) { +/*virtual*/ void T2MoverModule::RemoveContents(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->mFloorInfo; + + while (mLink1) { + T2People *people = (T2People *) mLink1; + Leave(people); + + POINT destPos = people->GetCurrDestPos(); + T2Tenant *floor = floorInfo->GetFloor(destPos.y, destPos.x); + if (floor) { + floor->Enter(people); + people->IncEstimate(-100); + } + } } /*virtual*/ void T2MoverModule::StopAdded(T2TowerDoc*, T2Mover*, int) { @@ -18,32 +73,164 @@ T2MoverModule::T2MoverModule() { /*virtual*/ void T2MoverModule::StopRemoved(T2TowerDoc*, T2Mover*, int) { } -/*virtual*/ void T2MoverModule::Enter(T2Mover*, T2People*) { +/*virtual*/ void T2MoverModule::Enter(T2Mover* mover, T2People* people) { + people->mCurrEquipID = mover->GetEquipID(); + + RECT area; + mover->GetEquipArea(area); + people->mCurPosition.x = (area.left + area.right) / 2; + + people->ChangeStatus(kStatus8); + Enter(people); +} + +/*virtual*/ BOOL T2MoverModule::Enter(CLink* link) { + mNumPeople++; + + if (!mLink1) { + mLink1 = link; + mLink2 = link; + link->SetPrev(NULL); + return true; + } + + if (mLink2) { + mLink2->InsertAt(link); + mLink2 = link; + return true; + } + + return false; +} + +/*virtual*/ BOOL T2MoverModule::Leave(CLink* link) { + mNumPeople--; + + if (mLink1) { + if (mLink1 == link) { + mLink1 = link->GetNext(); + if (mLink1 == NULL) + mLink2 = NULL; + else if (mLink1->GetNext() == NULL) + mLink2 = mLink1; + link->Remove(); + return true; + } + + if (mLink2 != link) { + link->Remove(); + } else if (mLink2 == link) { + mLink2 = link->GetPrev(); + link->Remove(); + if (mLink2 == NULL) + mLink1 = NULL; + return true; + } + } + + return false; } -/*virtual*/ int T2MoverModule::Enter(CLink*) { -} +/*virtual*/ void T2MoverModule::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + T2Object::LoadSelf(archive, towerDoc); -/*virtual*/ int T2MoverModule::Leave(CLink*) { -} + if (IsUsed()) { + short s; -/*virtual*/ void T2MoverModule::LoadSelf(T2Archive&, T2TowerDoc*) { -} + archive >> s; + mPosition = s; + archive >> s; + mDirection = s; + archive >> s; + mWaitCounter = s; + archive >> s; + mPatIndex = s; + archive >> s; + mNumPeople = s; + archive >> s; + _4C = s; -/*virtual*/ void T2MoverModule::SaveSelf(T2Archive&) { -} + unsigned int peopleID; -void T2MoverModule::SetDirection(int) { -} + archive >> peopleID; + if (peopleID) + mLink1 = towerDoc->mPeopleArrayList->FindPeople(peopleID); + else + mLink1 = NULL; -void T2MoverModule::AddPosition(int) { + archive >> peopleID; + if (peopleID) + mLink2 = towerDoc->mPeopleArrayList->FindPeople(peopleID); + else + mLink2 = NULL; + } } -/*static*/ unsigned int T2MoverModule::GetNewModuleID(T2TowerDoc*) { -} +/*virtual*/ void T2MoverModule::SaveSelf(T2Archive& archive) { + T2Object::SaveSelf(archive); + + if (IsUsed()) { + short s; + + s = mPosition; + archive << s; + s = mDirection; + archive << s; + s = mWaitCounter; + archive << s; + s = mPatIndex; + archive << s; + s = mNumPeople; + archive << s; + s = _4C; + archive << s; + + unsigned int peopleID; + + if (mLink1) + peopleID = ((T2People *) mLink1)->GetPeopleID(); + else + peopleID = 0; + archive << peopleID; + + if (mLink2) + peopleID = ((T2People *) mLink2)->GetPeopleID(); + else + peopleID = 0; + archive << peopleID; + } +} + +void T2MoverModule::SetDirection(int direction) { + mDirection = direction; + + T2MoverModuleMessageData data; + data.moverModule = this; + data.value = mPosition; + BroadcastMessage(1000, &data); +} + +void T2MoverModule::AddPosition(int value) { + int oldPosition = mPosition; + mPosition += value; + + T2MoverModuleMessageData data; + data.moverModule = this; + data.value = oldPosition; + BroadcastMessage(1000, &data); +} + +/*static*/ unsigned int T2MoverModule::sModuleID; + +/*static*/ unsigned int T2MoverModule::GetNewModuleID(T2TowerDoc* towerDoc) { +incAgain: + sModuleID++; + if (towerDoc->towerDoc_vf12C()->GetModule(sModuleID)) + goto incAgain; -void T2MoverModule::SetModuleID(T2TowerDoc*) { + return sModuleID; } -/*static*/ unsigned int T2MoverModule::sModuleID { +void T2MoverModule::SetModuleID(T2TowerDoc* towerDoc) { + mModuleID = GetNewModuleID(towerDoc); } diff --git a/src/T2DLL/T2MoverModule.h b/src/T2DLL/T2MoverModule.h index f9ce786..75a3626 100644 --- a/src/T2DLL/T2MoverModule.h +++ b/src/T2DLL/T2MoverModule.h @@ -1,40 +1,59 @@ #pragma once #include "common.h" +#include "LBroadcaster.h" +#include "T2DrawableObject.h" -class T2MoverModule { +// unknown name +struct T2MoverModuleMessageData { + T2MoverModule *moverModule; + int value; +}; + +class AFX_EXT_CLASS T2MoverModule : public T2DrawableObject, public LBroadcaster { public: T2MoverModule(); virtual ~T2MoverModule(); - virtual void SetUsed(int); + virtual void SetUsed(BOOL used); virtual void RemoveContents(T2TowerDoc*); virtual void StopAdded(T2TowerDoc*, T2Mover*, int); virtual void StopRemoved(T2TowerDoc*, T2Mover*, int); - virtual void Enter(T2Mover*, T2People*); - virtual int Enter(CLink*); - virtual int Leave(CLink*); + virtual void Enter(T2Mover*, T2People*); + virtual BOOL Enter(CLink* link); + virtual BOOL Leave(CLink* link); + + void SetDirection(int); + void AddPosition(int); + void SetModuleID(T2TowerDoc*); + + unsigned int GetModuleID() const { return mModuleID; } + int GetPosition() const { return mPosition; } + int GetDirection() const { return mDirection; } + int GetWaitCounter() const { return mWaitCounter; } + void SetWaitCounter(int v) { mWaitCounter = v; } + void SubWaitCounter(int v) { mWaitCounter -= v; } + int GetPatIndex() const { return mPatIndex; } + void SetPatIndex(int v) { mPatIndex = v; } + int GetNumPeople() const { return mNumPeople; } + protected: virtual void LoadSelf(T2Archive&, T2TowerDoc*); virtual void SaveSelf(T2Archive&); -public: - void SetDirection(int); - void AddPosition(int); -private: - static unsigned int GetNewModuleID(T2TowerDoc*); -public: - void SetModuleID(T2TowerDoc*); + + friend class T2StairModuleList; + friend class T2Mover; + + int mPosition; + int mDirection; + int mWaitCounter; + int mPatIndex; + int mNumPeople; + int _4C; + unsigned int mModuleID; + // which one of these is first and which one is last? + CLink *mLink1; + CLink *mLink2; + private: + static unsigned int GetNewModuleID(T2TowerDoc*); static unsigned int sModuleID; - -public: - unsigned int GetModuleID() const {} - int GetPosition() const {} - int GetDirection() const {} - int GetWaitCounter() const {} - void SetWaitCounter(int) {} - void SubWaitCounter(int) {} - int GetPatIndex() const {} - void SetPatIndex(int) {} - int GetNumPeople() const {} - T2MoverModule(const T2MoverModule&) {} - T2MoverModule& operator=(const T2MoverModule&) {} }; diff --git a/src/T2DLL/T2MoverModuleList.cpp b/src/T2DLL/T2MoverModuleList.cpp index a0262cd..0629242 100644 --- a/src/T2DLL/T2MoverModuleList.cpp +++ b/src/T2DLL/T2MoverModuleList.cpp @@ -1,49 +1,129 @@ +#include "T2Archive.h" +#include "T2ElvModuleList.h" +#include "T2MoverDef.h" +#include "T2MoverModule.h" #include "T2MoverModuleList.h" +#include "T2StairModuleList.h" -T2MoverModuleList::T2MoverModuleList() { +T2MoverModuleList::T2MoverModuleList() + : LArray(sizeof(T2MoverModule *)) +{ + mMaxModule = 0; + mModuleCount = 0; + SetRect(&mBaseRect, 0, 0, 0, 0); } /*virtual*/ T2MoverModuleList::~T2MoverModuleList() { + LArrayIterator iterator(*this); + T2MoverModule *moverModule = NULL; + + while (iterator.Next(&moverModule)) { + if (moverModule) + delete moverModule; + } + + RemoveItemsAt(mItemCount, 1); } -/*virtual*/ int T2MoverModuleList::Init(T2MoverDef*, const RECT&) { +/*virtual*/ BOOL T2MoverModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) { + mMaxModule = moverDef->GetMaxModule(); + mModuleCount = 0; + mBaseRect = baseRect; + return true; } -int T2MoverModuleList::InsertModuleAt(int, T2MoverModule*) { +BOOL T2MoverModuleList::InsertModuleAt(int where, T2MoverModule* module) { + InsertItemsAt(1, where, &module); + return true; } void T2MoverModuleList::AllClear() { + RemoveItemsAt(mItemCount, 1); } -/*virtual*/ void T2MoverModuleList::Destruct(T2TowerDoc*) { +/*virtual*/ void T2MoverModuleList::Destruct(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2MoverModule *moverModule = NULL; + + while (iterator.Next(&moverModule)) { + if (moverModule) + RemoveModule(towerDoc, moverModule); + } } -/*virtual*/ void T2MoverModuleList::RemoveModule(T2TowerDoc*, T2MoverModule*) { +/*virtual*/ void T2MoverModuleList::RemoveModule(T2TowerDoc* towerDoc, T2MoverModule* moverModule) { + moverModule->RemoveContents(towerDoc); + Remove(&moverModule); + moverModule->SetUsed(false); + delete moverModule; } -/*virtual*/ void T2MoverModuleList::Read(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2MoverModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + AllClear(); + + short v; + archive >> v; + mMaxModule = v; + + archive.ReadSRect(mBaseRect); } -/*virtual*/ void T2MoverModuleList::Write(T2Archive&) { +/*virtual*/ void T2MoverModuleList::Write(T2Archive& archive) { + archive << (short) mMaxModule; + archive.WriteSRect(mBaseRect); + + archive << mItemCount; + + LArrayIterator iterator(*this); + T2MoverModule *moverModule = NULL; + + while (iterator.Next(&moverModule)) + moverModule->Save(archive); } /*virtual*/ T2MoverModule* T2MoverModuleList::ConstructModule() { + return new T2MoverModule; } -/*virtual*/ void T2MoverModuleList::StopAdded(T2TowerDoc*, T2Mover*, int) { +/*virtual*/ void T2MoverModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover*, int) { } -/*virtual*/ void T2MoverModuleList::StopRemoved(T2TowerDoc*, T2Mover*, int) { +/*virtual*/ void T2MoverModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover*, int) { } unsigned int T2MoverModuleList::GetItemCount() { + return GetCount(); } -/*static*/ T2MoverModuleList* T2MoverModuleList::ReadMMList(T2Archive&, T2TowerDoc*) { +/*static*/ T2MoverModuleList* T2MoverModuleList::ReadMMList(T2Archive& archive, T2TowerDoc* towerDoc) { + T2MoverModuleList *list = NULL; + + DWORD code; + archive >> code; + + if (code == '_MML') + list = new T2MoverModuleList; + else if (code == 'ElML') + list = new T2ElvModuleList; + else if (code == 'StML') + list = new T2StairModuleList; + + if (list) + list->Read(archive, towerDoc); + + return list; } -/*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList*, T2Archive&) { +/*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList* list, T2Archive& archive) { + if (!list) { + DWORD code = 'xMML'; + archive << code; + } else { + archive << list->GetMMClassID(); + list->Write(archive); + } } /*virtual*/ int T2MoverModuleList::GetModuleCount() const { + return mModuleCount; } diff --git a/src/T2DLL/T2MoverModuleList.h b/src/T2DLL/T2MoverModuleList.h index de55200..515872a 100644 --- a/src/T2DLL/T2MoverModuleList.h +++ b/src/T2DLL/T2MoverModuleList.h @@ -1,29 +1,34 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2MoverModuleList { +class AFX_EXT_CLASS T2MoverModuleList : public LArray { public: T2MoverModuleList(); virtual ~T2MoverModuleList(); - virtual int Init(T2MoverDef*, const RECT&); - int InsertModuleAt(int, T2MoverModule*); + virtual BOOL Init(T2MoverDef* moverDef, const RECT& baseRect); + virtual void Destruct(T2TowerDoc* towerDoc); + virtual void RemoveModule(T2TowerDoc* towerDoc, T2MoverModule*); + virtual void StopAdded(T2TowerDoc* towerDoc, T2Mover*, int); + virtual void StopRemoved(T2TowerDoc* towerDoc, T2Mover*, int); + virtual int GetModuleCount() const; + virtual T2MoverModule* ConstructModule(); + virtual void Read(T2Archive&, T2TowerDoc* towerDoc); + virtual void Write(T2Archive&); + + BOOL InsertModuleAt(int where, T2MoverModule* module); void AllClear(); - virtual void Destruct(T2TowerDoc*); - virtual void RemoveModule(T2TowerDoc*, T2MoverModule*); - virtual void Read(T2Archive&, T2TowerDoc*); - virtual void Write(T2Archive&); - virtual T2MoverModule* ConstructModule(); - virtual void StopAdded(T2TowerDoc*, T2Mover*, int); - virtual void StopRemoved(T2TowerDoc*, T2Mover*, int); unsigned int GetItemCount(); - static T2MoverModuleList* ReadMMList(T2Archive&, T2TowerDoc*); + + void GetBaseRect(RECT& r) const { r = mBaseRect; } + + static T2MoverModuleList* ReadMMList(T2Archive&, T2TowerDoc* towerDoc); static void WriteMMList(T2MoverModuleList*, T2Archive&); - virtual int GetModuleCount() const; - void GetBaseRect(RECT&) const {} protected: - virtual unsigned long GetMMClassID() {} -public: - T2MoverModuleList(const T2MoverModuleList&) {} - T2MoverModuleList& operator=(const T2MoverModuleList&) {} + virtual DWORD GetMMClassID() { return '_MML'; } + + int mMaxModule; + int mModuleCount; + RECT mBaseRect; }; diff --git a/src/T2DLL/T2MoverModuleTable.cpp b/src/T2DLL/T2MoverModuleTable.cpp new file mode 100644 index 0000000..f025e6e --- /dev/null +++ b/src/T2DLL/T2MoverModuleTable.cpp @@ -0,0 +1,358 @@ +#include "CT2App.h" +#include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2DlgItemVScr.h" +#include "T2ElevatorModule.h" +#include "T2FloorNumberTable.h" +#include "T2Mover.h" +#include "T2MoverModuleList.h" +#include "T2MoverModuleTable.h" + +/*virtual*/ BOOL T2MoverModuleTable::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { + return T2DlgItem::Create(inWindowName, inStyle, inRect, inParentWnd, inID); +} + +T2MoverModuleTable::T2MoverModuleTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemImageTable(inDoc, inImageObj, inPalette) + , mMover(NULL) + , mMoverModuleList(NULL) +{ + mImage = NULL; + SetRect(&mRect, 0, 0, 0, 0); + ((CT2App *) AfxGetApp())->app_vfA4(true); +} + +/*virtual*/ T2MoverModuleTable::~T2MoverModuleTable() { + LArrayIterator iterator(*mMoverModuleList); + T2MoverModule *theModule; + + while (iterator.Next(&theModule)) + theModule->RemoveListener(this); + + if (mImage) + delete mImage; +} + +/*virtual*/ BOOL T2MoverModuleTable::OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct) { + T2DlgItem::OnT2DlgItemCreate(inCreateStruct); + + GetClientRect(&mRect); + + RECT rect; + rect.left = mRect.right - 16; + rect.top = mRect.top; + rect.right = mRect.right; + rect.bottom = mRect.bottom; + + T2DlgItemVScr *theScr = new T2DlgItemVScr(mTowerDoc, mImageObj, mPalette); + theScr->Create("", WS_VISIBLE | WS_CHILD, rect, this, 100); + + rect.left = mRect.left; + rect.top = mRect.top; + rect.right = mRect.left + 24; + rect.bottom = mRect.bottom; + + T2FloorNumberTable *theTable = new T2FloorNumberTable(mTowerDoc, mImageObj, mPalette); + theTable->Create("", WS_VISIBLE | WS_CHILD, rect, this, 101); + + mImage = new T2BitImage(mRect); + mImage->Clear(0); + return false; +} + +/*virtual*/ void T2MoverModuleTable::SpendTime() { +} + +void T2MoverModuleTable::SetMover(T2Mover* inMover) { + mMover = inMover; + if (!mMover) + return; + + mMoverModuleList = mMover->GetModuleList(); + if (mMoverModuleList) { + LArrayIterator iterator(*mMoverModuleList); + T2MoverModule *theModule; + + while (iterator.Next(&theModule)) + theModule->AddListener(this); + + InsertCols(mMoverModuleList->GetItemCount(), 0, NULL); + InsertRows(mMover->GetLength(), 0, NULL); + } +} + +T2ElevatorModule* T2MoverModuleTable::GetModule(int inIndex) { + T2ElevatorModule *theModule = NULL; + LArrayIterator iterator(*mMoverModuleList); + int index = 0; + + while (iterator.Next(&theModule)) { + if (theModule->IsUsed()) { + index++; + if (index >= inIndex) + return theModule; + } + } + + return NULL; +} + +int T2MoverModuleTable::GetCellContent(const TableCellT& inCell) { + int result = 0; + + if (mMoverModuleList) { + T2ElevatorModule *theModule = GetModule(inCell.col); + if (theModule) { + int floor = mRows - inCell.row; + + if (result == 0 && theModule->GetPosition() == floor) + result = 3010 + theModule->GetPatIndex(); + + if (result == 0) { + if (theModule->GetDirection() == kElevatorDirection1) { + if (theModule->GetTopTurn() == floor) + result = 3007; + } else if (theModule->GetDirection() == kElevatorDirection2) { + if (theModule->GetBottomTurn() == floor) + result = 3006; + } + } + + if (result == 0) { + if (theModule->GetDirection() == kElevatorDirection1) { + if (theModule->IsOnStopPos(floor, ERequestUpDown_0)) + result = 3004; + else if (theModule->IsOnStopPos(floor, ERequestUpDown_1)) + result = 3005; + } else if (theModule->GetDirection() == kElevatorDirection2) { + if (theModule->IsOnStopPos(floor, ERequestUpDown_1)) + result = 3005; + else if (theModule->IsOnStopPos(floor, ERequestUpDown_0)) + result = 3004; + } + } + + if (result == 0) { + if (theModule->GetDirection() == kElevatorDirection1) { + if (theModule->IsOffStopPos(floor, ERequestUpDown_0)) + result = 3002; + else if (theModule->IsOffStopPos(floor, ERequestUpDown_1)) + result = 3003; + } else if (theModule->GetDirection() == kElevatorDirection2) { + if (theModule->IsOffStopPos(floor, ERequestUpDown_1)) + result = 3003; + else if (theModule->IsOffStopPos(floor, ERequestUpDown_0)) + result = 3002; + } + } + + if (result == 0) { + if (theModule->GetHomePosition() == floor) + result = 3001; + } + + if (result == 0) + result = 3000; + } + } + + return result; +} + +int T2MoverModuleTable::GetVScrValue() { + T2DlgItemVScr *theScr = (T2DlgItemVScr *) GetDlgItem(100); + return theScr->GetValue(); +} + +/*virtual*/ void T2MoverModuleTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + RECT cellRect; + if (FetchLocalCellFrame(inCell, cellRect)) { + int content = GetCellContent(inCell); + if (content != 0) { + int y = GetVScrValue() * mRowHeight; + OffsetRect(&cellRect, 24, -y); + BOOL doesIntersect = IntersectRect(&cellRect, &cellRect, &mRect); + + T2BitImage *theImage = new T2BitImage(AfxGetResourceHandle(), content, true); + RECT theSrcRect; + theSrcRect.left = 0; + theSrcRect.top = 0; + theSrcRect.right = theImage->mBitmap.header.biWidth; + theSrcRect.bottom = theImage->mBitmap.header.biHeight; + + if (doesIntersect) { + theImage->CopyImage(*mImage, theSrcRect, cellRect, SRCCOPY); + if (inSelected) + InvalidateRect(NULL); + } + + // memory leak??? + } + } +} + +/*virtual*/ void T2MoverModuleTable::ListenToMessage(UINT inMessage, void *ioData) { + switch (inMessage) { + case 1000: + case 1001: + HomeNotification *info = (HomeNotification *) ioData; + T2MoverModule *module = NULL; + int i = 0; + LArrayIterator theIter(*mMoverModuleList); + + while (theIter.Next(&module)) { + if (module->IsUsed()) { + i++; + if (module == info->theModule) { + int position = -1; + switch (inMessage) { + case 1000: + break; + case 1001: + position = module->GetPosition(); + break; + } + + RefreshMoverCell(position, i); + break; + } + } + } + break; + } +} + +void T2MoverModuleTable::RefreshMoverCell(int inFloor, unsigned int inIndex) { + if (mMover) { + if (inFloor < 0) { + TableCellT topCell, bottomCell; + RECT topFrame, bottomFrame; + topCell.row = 1; + topCell.col = inIndex; + bottomCell.row = mRows; + bottomCell.col = inIndex; + if (FetchLocalCellFrame(topCell, topFrame) && FetchLocalCellFrame(bottomCell, bottomFrame)) { + RECT rect; + SetRect(&rect, topFrame.left, topFrame.top, bottomFrame.right, bottomFrame.bottom); + + BOOL isVisible = IntersectRect(&rect, &rect, &mRect); + if (isVisible) + InvalidateRect(&rect); + } + } else { + TableCellT theCell; + RECT frame; + theCell.row = mRows - inFloor; + theCell.col = inIndex; + if (FetchLocalCellFrame(theCell, frame)) { + BOOL isVisible = IntersectRect(&frame, &frame, &mRect); + if (isVisible) + InvalidateRect(&frame); + } + } + } +} + +void T2MoverModuleTable::DrawMoverCellByIndex(unsigned int inIndex) { + TableCellT cell; + cell.col = inIndex; + + for (unsigned int i = 1; i <= mRows; i++) { + cell.row = i; + DrawCellSelf(NULL, cell, false); + } +} + +/*virtual*/ void T2MoverModuleTable::ClickCell(const TableCellT& inCell, const POINT& inPt) { + T2TowerDoc *theDoc = GetCurrentT2TowerDoc(); + if (mMoverModuleList && theDoc) { + int moverIndex = inCell.col; + T2ElevatorModule *theModule = GetModule(moverIndex); + + if (theModule) { + HomeNotification info; + info.theModule = theModule; + info.whichMover = moverIndex; + info.whichFloor = mRows - inCell.row; + info.theTable = this; + BroadcastMessage('home', &info); + } + } +} + +/*virtual*/ BOOL T2MoverModuleTable::OnCommand(WPARAM inWParam, LPARAM inLParam) { + BOOL result = false; + + if (LOWORD(inWParam) == 100 || LOWORD(inWParam) == 101) { + InvalidateRect(NULL); + result = true; + } + + return result; +} + +/*virtual*/ BOOL T2MoverModuleTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect theRect; + GetClientRect(theRect); + theRect.right -= 15; + theRect.left += 23; + + int saved = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CPen thePen; + CBrush theBrush, theNullBrush; + + if (!mMoverModuleList) { + thePen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + theBrush.CreateSolidBrush(RGB(255, 255, 255)); + pDC->SelectObject(theBrush); + pDC->SelectObject(thePen); + pDC->Rectangle(theRect); + } else { + thePen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255)); + theNullBrush.CreateStockObject(NULL_BRUSH); + pDC->SelectObject(theNullBrush); + pDC->SelectObject(thePen); + pDC->Rectangle(theRect); + + theRect.top++; + theRect.left++; + theRect.right--; + theRect.bottom--; + + unsigned int height, width; + GetTableSize(height, width); + + for (unsigned int x = 1; x <= width; x++) { + for (unsigned int y = 1; y <= height; y++) { + TableCellT cell; + cell.row = y; + cell.col = x; + DrawCellSelf(pDC, cell, false); + } + } + + pDC->IntersectClipRect(theRect); + StretchDIBits(pDC->m_hDC, theRect.left, theRect.bottom, theRect.right - theRect.left, theRect.bottom - theRect.top, 0, 0, mImage->mBitmap.header.biWidth, mImage->mBitmap.header.biHeight, mImage->mData, (BITMAPINFO *) &mImage->mBitmap, DIB_PAL_COLORS, SRCCOPY); + + theRect.top--; + theRect.left--; + theRect.right++; + theRect.bottom++; + InvalidateRect(&theRect); + } + + pDC->RestoreDC(saved); + return true; +} + +/*virtual*/ void T2MoverModuleTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + POINT pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + ClickCell(cell, inPt); +} diff --git a/src/T2DLL/T2MoverModuleTable.h b/src/T2DLL/T2MoverModuleTable.h new file mode 100644 index 0000000..d45c08c --- /dev/null +++ b/src/T2DLL/T2MoverModuleTable.h @@ -0,0 +1,43 @@ +#pragma once +#include "common.h" +#include "T2DlgItemImageTable.h" + +struct HomeNotification { + T2ElevatorModule *theModule; + int whichMover; + int whichFloor; + T2MoverModuleTable *theTable; +}; + +class AFX_EXT_CLASS T2MoverModuleTable : public T2DlgItemImageTable { +public: + T2MoverModuleTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual ~T2MoverModuleTable(); + virtual BOOL Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); + virtual void SpendTime(); + virtual void ListenToMessage(UINT inMessage, void *ioData); + void SetMover(T2Mover* inMover); + void RefreshMoverCell(int inFloor, unsigned int inIndex); + void DrawMoverCellByIndex(unsigned int inIndex); + +protected: + virtual BOOL OnCommand(WPARAM inWParam, LPARAM inLParam); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual void OnT2DlgItemLButtonUp(UINT inFlags, CPoint inPt) {} + virtual void OnT2DlgItemMouseMove(UINT inFlags, CPoint inPt) {} + virtual BOOL OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct); + virtual void ClickCell(const TableCellT& inCell, const POINT& inPt); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + + friend class T2FloorNumberTable; + + T2ElevatorModule* GetModule(int inIndex); + int GetCellContent(const TableCellT& inCell); + int GetVScrValue(); + + T2Mover *mMover; + T2MoverModuleList *mMoverModuleList; + T2BitImage *mImage; + RECT mRect; +}; diff --git a/src/T2DLL/T2MoverNumberTable.cpp b/src/T2DLL/T2MoverNumberTable.cpp deleted file mode 100644 index 2034d98..0000000 --- a/src/T2DLL/T2MoverNumberTable.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "T2MoverNumberTable.h" - -/*virtual*/ void T2MoverModuleTable::OnT2DlgItemLButtonUp(unsigned int, CPoint) { -} - -/*virtual*/ void T2MoverModuleTable::OnT2DlgItemMouseMove(unsigned int, CPoint) { -} - -/*virtual*/ int T2MoverModuleTable::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { -} - -T2MoverModuleTable::T2MoverModuleTable(T2TowerDoc*, T2ImageObj*, CPalette*) { -} - -/*virtual*/ T2MoverModuleTable::~T2MoverModuleTable() { -} - -/*virtual*/ int T2MoverModuleTable::OnT2DlgItemCreate(CREATESTRUCTA*) { -} - -/*virtual*/ void T2MoverModuleTable::SpendTime() { -} - -void T2MoverModuleTable::SetMover(T2Mover*) { -} - -T2ElevatorModule* T2MoverModuleTable::GetModule(int) { -} - -int T2MoverModuleTable::GetCellContent(const TableCellT&) { -} - -int T2MoverModuleTable::GetVScrValue() { -} - -/*virtual*/ void T2MoverModuleTable::DrawCellSelf(CDC*, const TableCellT&, int) { -} - -/*virtual*/ void T2MoverModuleTable::ListenToMessage(unsigned int, void*) { -} - -void T2MoverModuleTable::RefreshMoverCell(int, unsigned int) { -} - -void T2MoverModuleTable::DrawMoverCellByIndex(unsigned int) { -} - -/*virtual*/ void T2MoverModuleTable::ClickCell(const TableCellT&, const POINT&) { -} - -/*virtual*/ int T2MoverModuleTable::OnCommand(unsigned int, long) { -} - -/*virtual*/ int T2MoverModuleTable::OnT2DlgItemEraseBkgnd(CDC*) { -} - -/*virtual*/ void T2MoverModuleTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { -} diff --git a/src/T2DLL/T2MoverNumberTable.h b/src/T2DLL/T2MoverNumberTable.h deleted file mode 100644 index a28ec31..0000000 --- a/src/T2DLL/T2MoverNumberTable.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "common.h" - -class T2MoverModuleTable { -protected: - virtual void OnT2DlgItemLButtonUp(unsigned int, CPoint); - virtual void OnT2DlgItemMouseMove(unsigned int, CPoint); -public: - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - T2MoverModuleTable(T2TowerDoc*, T2ImageObj*, CPalette*); - virtual ~T2MoverModuleTable(); -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); -public: - virtual void SpendTime(); - void SetMover(T2Mover*); -protected: - T2ElevatorModule* GetModule(int); - int GetCellContent(const TableCellT&); - int GetVScrValue(); - virtual void DrawCellSelf(CDC*, const TableCellT&, int); -public: - virtual void ListenToMessage(unsigned int, void*); - void RefreshMoverCell(int, unsigned int); - void DrawMoverCellByIndex(unsigned int); -protected: - virtual void ClickCell(const TableCellT&, const POINT&); - virtual int OnCommand(unsigned int, long); - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); -}; diff --git a/src/T2DLL/T2MoverPlugin.cpp b/src/T2DLL/T2MoverPlugin.cpp index a2a5a3a..0b38037 100644 --- a/src/T2DLL/T2MoverPlugin.cpp +++ b/src/T2DLL/T2MoverPlugin.cpp @@ -1,13 +1,29 @@ +#include "CResFile.h" #include "T2MoverPlugin.h" -T2MoverPlugin::T2MoverPlugin(unsigned long, T2PluginSpecifier&) { +T2MoverPlugin::T2MoverPlugin(DWORD type, T2PluginSpecifier& specifier) + : T2EquipPlugin(type, specifier) +{ } /*virtual*/ T2MoverPlugin::~T2MoverPlugin() { } -int T2MoverPlugin::LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*) { +BOOL T2MoverPlugin::LoadAllTemplatePlugin(T2WorldDef* worldDef, T2TemplatePluginDB*) { + LoadT2MoverDef(worldDef); + return true; } -void T2MoverPlugin::LoadT2MoverDef(T2WorldDef*) { +typedef T2TemplatePlugin *(MSVC_STDCALL* ConstructTemplatePluginType) (T2PluginSpecifier *, CResFile *, T2WorldDef *, T2MoverPlugin *); + +void T2MoverPlugin::LoadT2MoverDef(T2WorldDef* worldDef) { + ConstructTemplatePluginType func = (ConstructTemplatePluginType) GetProcAddress((HMODULE) mModuleHandle, "ConstructTemplatePlugin"); +#line 26 + _ASSERT(func); + + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, 'MvDf'); + T2TemplatePlugin *plugin = func(&mSpecifier, &resFile, worldDef, this); + + mTemplatePlugin = plugin; } diff --git a/src/T2DLL/T2MoverPlugin.h b/src/T2DLL/T2MoverPlugin.h index 4d8c8ec..aaa4f8f 100644 --- a/src/T2DLL/T2MoverPlugin.h +++ b/src/T2DLL/T2MoverPlugin.h @@ -1,14 +1,12 @@ #pragma once #include "common.h" +#include "T2EquipPlugin.h" -class T2MoverPlugin { +class AFX_EXT_CLASS T2MoverPlugin : public T2EquipPlugin { public: - T2MoverPlugin(unsigned long, T2PluginSpecifier&); + T2MoverPlugin(DWORD, T2PluginSpecifier&); virtual ~T2MoverPlugin(); - int LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*); + BOOL LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*); private: void LoadT2MoverDef(T2WorldDef*); - -public: - T2MoverPlugin& operator=(T2MoverPlugin&) {} }; diff --git a/src/T2DLL/T2MoverRoutingTable.cpp b/src/T2DLL/T2MoverRoutingTable.cpp index 7ee928c..dd791e4 100644 --- a/src/T2DLL/T2MoverRoutingTable.cpp +++ b/src/T2DLL/T2MoverRoutingTable.cpp @@ -1,49 +1,246 @@ +#include "T2CrossEquipArray.h" +#include "T2FloorInfo.h" +#include "T2FloorPtrList.h" +#include "T2Mover.h" #include "T2MoverRoutingTable.h" +#include "T2Request.h" +#include "T2RoutingTable.h" +#include "T2Tenant.h" -T2MoverRoutingTable::T2MoverRoutingTable(T2FloorInfo*, T2FloorPtrList*, T2Mover*) { +T2MoverRoutingTable::T2MoverRoutingTable(T2FloorInfo* inFloorInfo, T2FloorPtrList* inFloorPtrList, T2Mover* inMover) + : LArray(sizeof(T2RoutingTableElem)) +{ + mMover = inMover; + mFloorPtrList = inFloorPtrList; + mFloorInfo = inFloorInfo; + + RECT rect; + inMover->GetEquipArea(rect); + mMoverHPos = (rect.left + rect.right) / 2; + + AddItems(mFloorPtrList->GetCount()); } /*virtual*/ T2MoverRoutingTable::~T2MoverRoutingTable() { } -void T2MoverRoutingTable::AddItems(int) { +void T2MoverRoutingTable::AddItems(int inCount) { + T2RoutingTableElem elem; + InsertItemsAt(inCount, mItemCount + 1, &elem); } -void T2MoverRoutingTable::RemoveItem(int) { +void T2MoverRoutingTable::RemoveItem(int inIndex) { + RemoveItemsAt(1, inIndex); } void T2MoverRoutingTable::ClearData() { + T2RoutingTableElem elem; + AssignItemsAt(GetCount(), 1, &elem); } -int T2MoverRoutingTable::GetItem(int, T2RoutingTableElem&) { +BOOL T2MoverRoutingTable::GetItem(int inIndex, T2RoutingTableElem& outItem) { + return FetchItemAt(inIndex, &outItem); } -int T2MoverRoutingTable::IsStopFloor(int) { +BOOL T2MoverRoutingTable::IsStopFloor(int inIndex) { + BOOL res = false; + T2RoutingTableElem item; + + if (FetchItemAt(inIndex, &item)) + res = item.IsStopFloor(); + + return res; } void T2MoverRoutingTable::SetStopFloor() { + LArrayIterator iterator(*mMover->GetCEArray()); + unsigned int id; + + while (iterator.Next(&id)) { + int index = mFloorPtrList->GetIndex(id); + T2RoutingTableElem item; + item.SetTable(id, mMoverHPos); + AssignItemsAt(1, index, &item); + } } -int T2MoverRoutingTable::Update(T2MoverRoutingTable*) { +BOOL T2MoverRoutingTable::Update(T2MoverRoutingTable* inTable) { + BOOL set = false; + unsigned int numOfFloor = mFloorPtrList->GetCount(); + + for (unsigned int prevFloor = 1; prevFloor <= numOfFloor; prevFloor++) { + if (!IsStopFloor(prevFloor) && inTable->IsStopFloor(prevFloor)) { + for (unsigned int nextFloor = 1; nextFloor <= numOfFloor; nextFloor++) { + if (nextFloor != prevFloor && inTable->IsStopFloor(nextFloor)) { + T2RoutingTableElem elem; + GetItem(nextFloor, elem); + + if (elem.HasRoute()) + set |= IsUpdate(inTable, nextFloor, prevFloor, elem); + } + } + } + } + + return set; } -int T2MoverRoutingTable::IsUpdate(const T2MoverRoutingTable*, unsigned int, unsigned int, T2RoutingTableElem&) { +BOOL T2MoverRoutingTable::IsUpdate(const T2MoverRoutingTable* inTable, unsigned int inNextFloorID, unsigned int inPrevFloorID, T2RoutingTableElem& inElem) { + BOOL set = false; + + unsigned int hScore = CalcHScore(inTable->GetMoverHPos() - inElem.GetFinalHPos()); + if (hScore < 120) { + T2Mover *theMover = inTable->GetMover(); + unsigned int vScore = theMover->CalcScore(mFloorPtrList->CalcDistance(inNextFloorID, inPrevFloorID)); + unsigned int totalScore = hScore + vScore + inElem.GetScore(); + + if (theMover->IsElevator()) + totalScore += 120; + + if (totalScore <= 1000) + set = IsSetTable(inPrevFloorID, inElem.GetNextFloorID(), totalScore, 0, inTable->GetMoverHPos()); + } + + return set; } -int T2MoverRoutingTable::IsSetTable(unsigned int, unsigned int, unsigned int, int, int) { +BOOL T2MoverRoutingTable::IsSetTable(unsigned int inPrevFloorID, unsigned int inNextFloorID, unsigned int inScore, int inTime, int inFinalHPos) { + BOOL set = false; + T2RoutingTableElem item; + + if (FetchItemAt(inPrevFloorID, &item)) { + if (item.IsSetTable(inNextFloorID, inScore, inTime, inFinalHPos)) { + AssignItemsAt(1, inPrevFloorID, &item); + set = true; + } + } + + return set; } -int T2MoverRoutingTable::CalcHScore(int) { +int T2MoverRoutingTable::CalcHScore(int inDistance) { + if (inDistance < 0) + inDistance *= -1; + return inDistance; } -int T2MoverRoutingTable::IsConnectRoute(int) { +BOOL T2MoverRoutingTable::IsConnectRoute(int inFloorID) { + BOOL result = false; + T2RoutingTableElem item; + + if (FetchItemAt(inFloorID, &item)) + result = item.HasRoute(); + + return result; } -int T2MoverRoutingTable::GetNextRoute(POINT, unsigned int, POINT&, unsigned int, unsigned int&) { +BOOL T2MoverRoutingTable::GetNextRoute(POINT inPt, unsigned int inFloorID, POINT& ioPt, unsigned int inFloorID2, unsigned int& outScore) { + BOOL ok = false; + + T2RoutingTableElem item; + FetchItemAt(inFloorID2, &item); + + if (item.HasNextRoute(inFloorID)) { + outScore = CalcScore(inPt, ioPt, &item); + ok = true; + } + + return ok; } -unsigned int T2MoverRoutingTable::CalcScore(POINT, POINT&, T2RoutingTableElem*) { +unsigned int T2MoverRoutingTable::CalcScore(POINT inPt, POINT& ioPt, T2RoutingTableElem* inElem) { +#pragma var_order(theNextFloor, nextFloorArea, score, moverArea, theRequest, lobby, pt, isDown) + T2Tenant *theNextFloor = mFloorInfo->GetTenant(inElem->GetNextFloorID()); +#line 377 + _ASSERT(theNextFloor != NULL); + + RECT nextFloorArea; + theNextFloor->GetEquipArea(nextFloorArea); + + POINT pt; + pt.y = nextFloorArea.bottom - 1; + + BOOL isDown = (pt.y - inPt.y) > 0; + + RECT moverArea; + mMover->GetEquipArea(moverArea); + + if (isDown) + pt.x = moverArea.right + 2; + else + pt.x = moverArea.left - 4; + + unsigned int score = inElem->GetScore() + mMover->CalcScore(pt.y - inPt.y); + + int lobby = mFloorInfo->GetGroundLine() - 1; + if (inPt.y != lobby) + score += CalcHScore(pt.x - inPt.x); + if (ioPt.y != lobby) + score += CalcHScore(ioPt.x - inElem->GetFinalHPos()); + + if (mMover->IsElevator()) + score += 120; + + T2Request *theRequest = mMover->GetRequest(mFloorInfo, mMover->UnitToPosition(inPt.y), isDown); + if (theRequest) + score += theRequest->GetNumOfContent() * 10; + + ioPt = pt; + return score; } -T2Tenant* T2MoverRoutingTable::SelectNearFloor(POINT, int&, unsigned int&) { +T2Tenant* T2MoverRoutingTable::SelectNearFloor(POINT inPt, int& outFinalHPos, unsigned int& ioScore) { + T2Tenant *result = NULL; + ioScore -= CalcHScore(mMoverHPos - inPt.x); + + if (ioScore > 0) { + LArrayIterator iterator(*this); + T2RoutingTableElem item; + int numOfFloor = 0; + + while (iterator.Next(&item)) { + if (item.HasRoute() && ioScore > item.GetScore()) { + int scoreThreshold = ioScore - item.GetScore(); + T2Tenant *theNextFloor = mFloorInfo->GetTenant(item.GetNextFloorID()); + if (theNextFloor) { + RECT area; + theNextFloor->GetEquipArea(area); + + int v = area.bottom - 1; + if (scoreThreshold > mMover->CalcScore(v - inPt.y)) + numOfFloor++; + } + } + } + + if (numOfFloor > 0) { + int randFloor = rand() % numOfFloor; + int index = 0; + iterator.ResetTo(0); + + while (!result && iterator.Next(&item)) { + if (item.HasRoute() && ioScore > item.GetScore()) { + int scoreThreshold = ioScore - item.GetScore(); + T2Tenant *theNextFloor = mFloorInfo->GetTenant(item.GetNextFloorID()); + if (theNextFloor) { + RECT area; + theNextFloor->GetEquipArea(area); + + int v = area.bottom - 1; + if (scoreThreshold > mMover->CalcScore(v - inPt.y)) { + if (index == randFloor) { + result = theNextFloor; + outFinalHPos = item.GetFinalHPos(); + ioScore = scoreThreshold; + } else { + index++; + } + } + } + } + } + } + } + + return result; } diff --git a/src/T2DLL/T2MoverRoutingTable.h b/src/T2DLL/T2MoverRoutingTable.h index 3621ae9..4ea411a 100644 --- a/src/T2DLL/T2MoverRoutingTable.h +++ b/src/T2DLL/T2MoverRoutingTable.h @@ -1,33 +1,33 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2MoverRoutingTable { +class AFX_EXT_CLASS T2MoverRoutingTable : private LArray { public: - T2MoverRoutingTable(T2FloorInfo*, T2FloorPtrList*, T2Mover*); + T2MoverRoutingTable(T2FloorInfo* inFloorInfo, T2FloorPtrList* inFloorPtrList, T2Mover* inMover); virtual ~T2MoverRoutingTable(); - void AddItems(int); - void RemoveItem(int); + void AddItems(int inCount); + void RemoveItem(int inIndex); void ClearData(); - int GetItem(int, T2RoutingTableElem&); -protected: - int IsStopFloor(int); -public: + BOOL GetItem(int inIndex, T2RoutingTableElem& outItem); void SetStopFloor(); - int Update(T2MoverRoutingTable*); -protected: - int IsUpdate(const T2MoverRoutingTable*, unsigned int, unsigned int, T2RoutingTableElem&); - int IsSetTable(unsigned int, unsigned int, unsigned int, int, int); - int CalcHScore(int); -public: - int IsConnectRoute(int); - int GetNextRoute(POINT, unsigned int, POINT&, unsigned int, unsigned int&); + BOOL Update(T2MoverRoutingTable* inTable); + BOOL IsConnectRoute(int inFloorID); + BOOL GetNextRoute(POINT inPt, unsigned int inFloorID, POINT& ioPt, unsigned int inFloorID2, unsigned int& outScore); + T2Tenant* SelectNearFloor(POINT inPt, int& outFinalHPos, unsigned int& ioScore); + + T2Mover* GetMover() const { return mMover; } + int GetMoverHPos() const { return mMoverHPos; } + protected: - unsigned int CalcScore(POINT, POINT&, T2RoutingTableElem*); -public: - T2Tenant* SelectNearFloor(POINT, int&, unsigned int&); + BOOL IsStopFloor(int inIndex); + BOOL IsUpdate(const T2MoverRoutingTable* inTable, unsigned int inNextFloorID, unsigned int inPrevFloorID, T2RoutingTableElem& inElem); + BOOL IsSetTable(unsigned int inPrevFloorID, unsigned int inNextFloorID, unsigned int inScore, int inTime, int inFinalHPos); + int CalcHScore(int inDistance); + unsigned int CalcScore(POINT inPt, POINT& ioPt, T2RoutingTableElem* inElem); - T2MoverRoutingTable(const T2MoverRoutingTable&) {} - T2MoverRoutingTable& operator=(const T2MoverRoutingTable&) {} - T2Mover* GetMover() const {} - int GetMoverHPos() const {} + T2Mover *mMover; + int mMoverHPos; + T2FloorPtrList *mFloorPtrList; + T2FloorInfo *mFloorInfo; }; diff --git a/src/T2DLL/T2MovieParamArray.cpp b/src/T2DLL/T2MovieParamArray.cpp index 325b4cd..787301d 100644 --- a/src/T2DLL/T2MovieParamArray.cpp +++ b/src/T2DLL/T2MovieParamArray.cpp @@ -1,25 +1,83 @@ +#include "T2Archive.h" #include "T2MovieParamArray.h" -T2MovieParamArray::T2MovieParamArray() { +// unknown name +struct MovieParam { + DWORD code; + int value; +}; + +T2MovieParamArray::T2MovieParamArray() + : LArray(sizeof(MovieParam)) +{ } /*virtual*/ T2MovieParamArray::~T2MovieParamArray() { } -int T2MovieParamArray::Regist(unsigned long, int) { +BOOL T2MovieParamArray::Regist(DWORD inCode, int inValue) { + LArrayIterator iterator(*this); + MovieParam entry; + + while (iterator.Next(&entry)) { + if (entry.code == inCode) + return false; + } + + entry.code = inCode; + entry.value = inValue; + InsertItemsAt(1, mItemCount + 1, &entry); + return true; } -int T2MovieParamArray::GetParam(unsigned long) { +int T2MovieParamArray::GetParam(DWORD inCode) { + LArrayIterator iterator(*this); + MovieParam entry; + + while (iterator.Next(&entry)) { + if (entry.code == inCode) + return entry.value; + } + + return 0; } -/*static*/ T2MovieParamArray* T2MovieParamArray::ReadMovieParamArray(T2Archive&) { +/*static*/ T2MovieParamArray* T2MovieParamArray::ReadMovieParamArray(T2Archive& inArchive) { + T2MovieParamArray *theArray = NULL; + + DWORD code; + inArchive >> code; + + if (code == 'mvPA') + theArray = new T2MovieParamArray; + + if (theArray) + theArray->Read(inArchive); + + return theArray; } -/*static*/ void T2MovieParamArray::WriteMovieParamArray(T2MovieParamArray*, T2Archive&) { +/*static*/ void T2MovieParamArray::WriteMovieParamArray(T2MovieParamArray* inArray, T2Archive& inArchive) { + DWORD code; + + if (!inArray) { + code = 'xmPA'; + inArchive << code; + } else { + code = 'mvPA'; + inArchive << code; + inArray->Write(inArchive); + } } -/*virtual*/ void T2MovieParamArray::Read(T2Archive&) { +/*virtual*/ void T2MovieParamArray::Read(T2Archive& inArchive) { + inArchive >> mItemSize; + inArchive >> mItemCount; + inArchive.Read(mBuffer, mItemSize * mItemCount); } -/*virtual*/ void T2MovieParamArray::Write(T2Archive&) { +/*virtual*/ void T2MovieParamArray::Write(T2Archive& inArchive) { + inArchive << mItemSize; + inArchive << mItemCount; + inArchive.Write(mBuffer, mItemSize * mItemCount); } diff --git a/src/T2DLL/T2MovieParamArray.h b/src/T2DLL/T2MovieParamArray.h index 70993b8..d642f5e 100644 --- a/src/T2DLL/T2MovieParamArray.h +++ b/src/T2DLL/T2MovieParamArray.h @@ -1,17 +1,15 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2MovieParamArray { +class AFX_EXT_CLASS T2MovieParamArray : private LArray { public: T2MovieParamArray(); virtual ~T2MovieParamArray(); - int Regist(unsigned long, int); - int GetParam(unsigned long); - static T2MovieParamArray* ReadMovieParamArray(T2Archive&); - static void WriteMovieParamArray(T2MovieParamArray*, T2Archive&); - virtual void Read(T2Archive&); - virtual void Write(T2Archive&); - - T2MovieParamArray(const T2MovieParamArray&) {} - T2MovieParamArray& operator=(const T2MovieParamArray&) {} + BOOL Regist(DWORD inCode, int inValue); + int GetParam(DWORD inCode); + static T2MovieParamArray* ReadMovieParamArray(T2Archive& inArchive); + static void WriteMovieParamArray(T2MovieParamArray* inArray, T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); + virtual void Write(T2Archive& inArchive); }; diff --git a/src/T2DLL/T2MoviePlugin.cpp b/src/T2DLL/T2MoviePlugin.cpp index 2d9250d..213e849 100644 --- a/src/T2DLL/T2MoviePlugin.cpp +++ b/src/T2DLL/T2MoviePlugin.cpp @@ -1,58 +1,290 @@ +#include "CResFile.h" +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2DateTime.h" +#include "T2GlobalData.h" +#include "T2ImageObj.h" #include "T2MoviePlugin.h" -T2MoviePlugin::T2MoviePlugin(unsigned long, T2PluginSpecifier&) { +T2MoviePlugin::T2MoviePlugin(DWORD inType, T2PluginSpecifier& inSpecifier) + : T2SubPlugin(inType, inSpecifier) +{ + mInfo.mCC_0 = 0; + mInfo.mCC_1 = 0; + mInfo.mCC_2 = 0; + mInfo.mCC_3 = 0; + mInfo.mCC_4 = 0; + mInfo.mCC_5 = 0; + mE4 = ""; + _E8 = 0; + mEC = ""; + mF0 = ""; + mF4 = ""; + mBindTime = 0; + mFC = 0; + m100 = ""; + mNOPersonsR = -1; + mNOPersonsF = -1; + mAttribute = 0; + mRemakeCount = 1; + m104 = 0; + m108 = 0; + m10C = 0; + m110 = 0; + mNamingScheme = 0; + m11C = 0; + m118 = 0; + mCustomTitleCount = 0; + mCustomTitles = NULL; + mResID = 0; + mNewNOPersonsR = -1; + mNewNOPersonsF = -1; } /*virtual*/ T2MoviePlugin::~T2MoviePlugin() { + if (mCustomTitles) + delete[] mCustomTitles; } -/*virtual*/ void T2MoviePlugin::LoadRsrcFromStream(CResFile&) { +/*virtual*/ void T2MoviePlugin::LoadRsrcFromStream(CResFile& inResFile) { + T2SubPlugin::LoadRsrcFromStream(inResFile); + + inResFile >> mResID; + inResFile >> mInfo.mCC_0; + inResFile >> mInfo.mCC_1; + inResFile >> mInfo.mCC_2; + inResFile >> mInfo.mCC_3; + inResFile >> mInfo.mCC_4; + inResFile >> mInfo.mCC_5; + mInfo.mCC_5 = 0; + mInfo.mCC_4 = 0; + inResFile >> mEC; + inResFile >> mF0; + inResFile >> mF4; + inResFile >> mBindTime; + inResFile >> mFC; + inResFile >> m100; + + unsigned short us; + inResFile >> us; + mDupCustomerTableDefRes = us; + + inResFile >> m104; + inResFile >> m108; + inResFile >> m10C; + inResFile >> m110; + inResFile >> mNamingScheme; + inResFile >> mCustomTitleCount; + + mCustomTitles = new CString[mCustomTitleCount]; + for (int i = 0; i < mCustomTitleCount; i++) + inResFile >> mCustomTitles[i]; + + inResFile >> m118; + inResFile >> m11C; + inResFile >> mE4; } -/*virtual*/ void T2MoviePlugin::GlobalData(T2GlobalData*) { +/*virtual*/ void T2MoviePlugin::GlobalData(T2GlobalData* inGlobalData) { + inGlobalData->RegistMovie(GetID(), 0); + inGlobalData->GetMovieParam(GetID()); } -int T2MoviePlugin::GetMovieLifePhase(T2DateTime*, int) { +int T2MoviePlugin::GetMovieLifePhase(T2DateTime* inDateTime, int inStartDay) { + if (mTieup) + return IsTieupFinish() ? 4 : 1; + if (mAttribute & 0x8000) + return 4; + + int diff = (inDateTime->CalcTotalDays() - inStartDay) % mInfo.mCC_5; + if (diff < mInfo.mCC_1) + return 0; + if (diff < mInfo.mCC_2) + return 1; + if (diff < mInfo.mCC_3) + return 2; + + return 4; } void T2MoviePlugin::UnfoldPluginSelf() { + if (mResID) { + mImage = new T2BitImage(mSpecifier.mPath, mResID, true); +#line 132 + _ASSERT(mImage->mBitmap.header.biHeight == 32); + _ASSERT(mImage->mBitmap.header.biWidth == 24); + + mImageObj = new T2ImageObj; + mImageObj->AddObject("SCRE", -1, *mImage, NULL, true, false); + } + + mInfo.mCC_2 += mInfo.mCC_1; + mInfo.mCC_3 += mInfo.mCC_2; + mInfo.mCC_4 += mInfo.mCC_3; + mInfo.mCC_5 += mInfo.mCC_4; } void T2MoviePlugin::ReMake() { + if (mNOPersonsR != -1) { + if (mNOPersonsR >= m10C && mNOPersonsF == -1) { + mAttribute |= 2; + mNOPersonsF = mNOPersonsR; + } + + if (mNOPersonsR >= m110) { + mAttribute |= 1; + mNOPersonsR = -1; + mRemakeCount++; + } else { + mAttribute |= 0x8000; + } + } } -void T2MoviePlugin::GetTitle(CString&, int) { +void T2MoviePlugin::GetTitle(CString& outStr, int inNum) { + CString work; + + outStr = mTitle; + + if ((mAttribute & 1) && inNum == 1) { + int var = (mRemakeCount - 1) % 3; + switch (mNamingScheme) { + case 0: + work.Format("%d", mRemakeCount); + outStr += work; + break; + + case 2: + switch (var) { + case 1: + // "続・" - Continued + outStr = "\x91\xB1\x81\x45"; + break; + case 2: + // "新・" - New + outStr = "\x90\x56\x81\x45"; + break; + default: + outStr = ""; + break; + } + outStr += mTitle; + break; + + case 1: + switch (var) { + case 1: + outStr += "PART\x85\xA0"; + break; + case 2: + outStr += "PART\x85\xA1"; + break; + } + break; + + case 3: + var = (mRemakeCount - 1) % (mCustomTitleCount + 1); + if (var > 0) { + outStr = mCustomTitles[var - 1]; + outStr += mTitle; + } + break; + + case 4: + var = (mRemakeCount - 1) % (mCustomTitleCount + 1); + if (var > 0) + outStr += mCustomTitles[var - 1]; + break; + } + } } int T2MoviePlugin::GetNOPersonsR() { + return mNOPersonsR; } -void T2MoviePlugin::SetNOPersonsR(int) { +void T2MoviePlugin::SetNOPersonsR(int inNum) { + mNewNOPersonsR = inNum; } int T2MoviePlugin::GetNOPersonsF() { + return mNOPersonsF; } -void T2MoviePlugin::SetNOPersonsF(int) { +void T2MoviePlugin::SetNOPersonsF(int inNum) { + mNewNOPersonsF = inNum; } -int T2MoviePlugin::IsFamousFilm() { +BOOL T2MoviePlugin::IsFamousFilm() { + return (mAttribute & 2) || (mInfo.mCC_0 == 2); } -int T2MoviePlugin::IsRoadshowFilm() { +BOOL T2MoviePlugin::IsRoadshowFilm() { + return (mInfo.mCC_0 == 0); } -void T2MoviePlugin::ChkReMake(int) { +void T2MoviePlugin::ChkReMake(int inNum) { + if (mNewNOPersonsR > 0) + mNOPersonsR = mNewNOPersonsR; + mNewNOPersonsR = -1; + + if (mNewNOPersonsF > 0) + mNOPersonsF = mNewNOPersonsF; + mNewNOPersonsF = -1; + + if (mNOPersonsR != -1 && (inNum % mInfo.mCC_5) == 0 && (inNum / mInfo.mCC_5) != 0) + ReMake(); } -/*static*/ void T2MoviePlugin::sDummyRead(T2Archive&) { +/*static*/ void T2MoviePlugin::sDummyRead(T2Archive& inArchive) { + unsigned char tmp; + unsigned int i, len; + + inArchive >> len; + for (i = 0; i < len; i++) + inArchive >> tmp; } -void T2MoviePlugin::Read(T2Archive&) { +void T2MoviePlugin::Read(T2Archive& inArchive) { + short s; + unsigned int ui; + + inArchive >> ui; + + inArchive >> s; + mNOPersonsR = s; + inArchive >> s; + mNOPersonsF = s; + inArchive >> s; + mAttribute = s; + inArchive >> s; + mRemakeCount = s; + inArchive >> s; + mNewNOPersonsR = s; + inArchive >> s; + mNewNOPersonsF = s; } -void T2MoviePlugin::Write(T2Archive&) { +void T2MoviePlugin::Write(T2Archive& inArchive) { + unsigned int ui = 0xC; + inArchive << ui; + + inArchive << (short) mNOPersonsR; + inArchive << (short) mNOPersonsF; + inArchive << (short) mAttribute; + inArchive << (short) mRemakeCount; + inArchive << (short) mNewNOPersonsR; + inArchive << (short) mNewNOPersonsF; } -/*virtual*/ unsigned long T2MoviePlugin::LoadSelf() { +/*virtual*/ DWORD T2MoviePlugin::LoadSelf() { + DWORD result = 0; + CResFile resFile; + + if (resFile.OpenResource(mSpecifier.mPath, 128, 'MODF')) + LoadRsrcFromStream(resFile); + else + result = 0xFFFFFFFF; + + return result; } diff --git a/src/T2DLL/T2MoviePlugin.h b/src/T2DLL/T2MoviePlugin.h index 676ea5f..78f5b70 100644 --- a/src/T2DLL/T2MoviePlugin.h +++ b/src/T2DLL/T2MoviePlugin.h @@ -1,29 +1,63 @@ #pragma once #include "common.h" +#include "T2SubPlugin.h" -class T2MoviePlugin { +// unknown name +struct MovieInfo { + int mCC_0; + int mCC_1; + int mCC_2; + int mCC_3; + int mCC_4; + int mCC_5; +}; + +class AFX_EXT_CLASS T2MoviePlugin : public T2SubPlugin { public: - T2MoviePlugin(unsigned long, T2PluginSpecifier&); + T2MoviePlugin(DWORD inType, T2PluginSpecifier& inSpecifier); virtual ~T2MoviePlugin(); -protected: - virtual void LoadRsrcFromStream(CResFile&); -public: - virtual void GlobalData(T2GlobalData*); - int GetMovieLifePhase(T2DateTime*, int); + virtual void GlobalData(T2GlobalData* inGlobalData); + int GetMovieLifePhase(T2DateTime* inDateTime, int inStartDay); void UnfoldPluginSelf(); void ReMake(); - void GetTitle(CString&, int); + void GetTitle(CString& outStr, int inNum); int GetNOPersonsR(); - void SetNOPersonsR(int); + void SetNOPersonsR(int inNum); int GetNOPersonsF(); - void SetNOPersonsF(int); - int IsFamousFilm(); - int IsRoadshowFilm(); - void ChkReMake(int); - static void sDummyRead(T2Archive&); - void Read(T2Archive&); - void Write(T2Archive&); - virtual unsigned long LoadSelf(); + void SetNOPersonsF(int inNum); + BOOL IsFamousFilm(); + BOOL IsRoadshowFilm(); + void ChkReMake(int inNum); + static void sDummyRead(T2Archive& inArchive); + void Read(T2Archive& inArchive); + void Write(T2Archive& inArchive); + virtual DWORD LoadSelf(); +protected: + virtual void LoadRsrcFromStream(CResFile& inResFile); - T2MoviePlugin& operator=(T2MoviePlugin&) {} + unsigned short mResID; + MovieInfo mInfo; + CString mE4; + int _E8; + CString mEC; + CString mF0; + CString mF4; + int mBindTime; + int mFC; + CString m100; + int m104; + int m108; + int m10C; + int m110; + int mNamingScheme; + int m118; + int m11C; + int mCustomTitleCount; + CString *mCustomTitles; + int mNOPersonsR; + int mNOPersonsF; + unsigned int mAttribute; + int mRemakeCount; + int mNewNOPersonsR; + int mNewNOPersonsF; }; diff --git a/src/T2DLL/T2MoviePluginList.cpp b/src/T2DLL/T2MoviePluginList.cpp index 66684eb..976c00d 100644 --- a/src/T2DLL/T2MoviePluginList.cpp +++ b/src/T2DLL/T2MoviePluginList.cpp @@ -1,13 +1,45 @@ +#include "T2Archive.h" +#include "T2MoviePlugin.h" #include "T2MoviePluginList.h" -T2MoviePluginList::T2MoviePluginList() { +T2MoviePluginList::T2MoviePluginList() + : CFilePluginList('MoPl') +{ } /*virtual*/ T2MoviePluginList::~T2MoviePluginList() { } -void T2MoviePluginList::Read(T2Archive&) { +void T2MoviePluginList::Read(T2Archive& inArchive) { + unsigned int i, count; + T2MoviePlugin *thePlugin; + + inArchive >> count; + for (i = 0; i < count; i++) { + DWORD id; + inArchive >> id; + + thePlugin = (T2MoviePlugin *) GetItem(id); + if (thePlugin) + thePlugin->Read(inArchive); + else + T2MoviePlugin::sDummyRead(inArchive); + } } -void T2MoviePluginList::Write(T2Archive&) { +void T2MoviePluginList::Write(T2Archive& inArchive) { + unsigned int count; + T2MoviePlugin *thePlugin; + + count = GetCount(); + inArchive << count; + + POSITION pos = GetHeadPosition(); + while (pos) { + thePlugin = (T2MoviePlugin *) GetNext(pos); + + DWORD id = thePlugin->GetID(); + inArchive << id; + thePlugin->Write(inArchive); + } } diff --git a/src/T2DLL/T2MoviePluginList.h b/src/T2DLL/T2MoviePluginList.h index 107ca06..56586a7 100644 --- a/src/T2DLL/T2MoviePluginList.h +++ b/src/T2DLL/T2MoviePluginList.h @@ -1,10 +1,11 @@ #pragma once #include "common.h" +#include "CFilePluginList.h" -class T2MoviePluginList { +class AFX_EXT_CLASS T2MoviePluginList : public CFilePluginList { public: T2MoviePluginList(); virtual ~T2MoviePluginList(); - void Read(T2Archive&); - void Write(T2Archive&); + void Read(T2Archive& inArchive); + void Write(T2Archive& inArchive); }; diff --git a/src/T2DLL/T2MovieTable.cpp b/src/T2DLL/T2MovieTable.cpp index ff1d779..ee47421 100644 --- a/src/T2DLL/T2MovieTable.cpp +++ b/src/T2DLL/T2MovieTable.cpp @@ -1,31 +1,113 @@ +#include "T2MoviePlugin.h" +#include "T2MoviePluginList.h" #include "T2MovieTable.h" -/*virtual*/ int T2MovieTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2MovieTable::OnT2DlgItemCreate(CREATESTRUCT* cs) { + T2DlgItemTable::SetColWidth(cs->cx, 0, 0); + return T2DlgItemTable::OnT2DlgItemCreate(cs); } -T2MovieTable::T2MovieTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2MovieTable::T2MovieTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2VerticalTable(inDoc, inImageObj, inPalette) +{ + mClearBackground = true; + mMovieType = 1; + + SetCellDataSize(sizeof(T2MoviePlugin *)); + InsertCols(1, 0, NULL); + SetHScrollerStyle(AlwaysHide); + SetVScrollerStyle(AlwaysShow); } -void T2MovieTable::SetMovieType(int) { +void T2MovieTable::SetMovieType(int inType) { + mMovieType = inType; } -void T2MovieTable::Add(T2MoviePlugin*) { +void T2MovieTable::Add(T2MoviePlugin* inPlugin) { + unsigned int index = mRows; + InsertRows(1, index, &inPlugin); } -void T2MovieTable::Add(CFilePluginList*) { +void T2MovieTable::Add(CFilePluginList* inList) { + T2MoviePlugin *thePlugin; + unsigned int index = mRows; + POSITION pos = inList->GetHeadPosition(); + + while (pos) { + thePlugin = (T2MoviePlugin *) inList->GetNext(pos); + InsertRows(1, index, &thePlugin); + index++; + } } -/*virtual*/ void T2MovieTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2MovieTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + DrawCell(pDC, inCell); } -/*virtual*/ void T2MovieTable::DrawCell(CDC*, const TableCellT&) { +/*virtual*/ void T2MovieTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + CFont font; + RECT cellRect; + + if (FetchLocalCellFrame(inCell, cellRect)) { + T2MoviePlugin *thePlugin; + GetCellData(inCell, &thePlugin); + if (thePlugin) { + font.CreateFont(-12, 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + pDC->SelectObject(&font); + pDC->SetBkMode(TRANSPARENT); + + CString title; + thePlugin->GetTitle(title, mMovieType); + pDC->TextOut(cellRect.left + 4, cellRect.bottom - 12, title, strlen(title)); + } + } + + pDC->RestoreDC(save); } -void T2MovieTable::ClickCell(const TableCellT&, const CPoint&) { +void T2MovieTable::ClickCell(const TableCellT& inCell, const CPoint& inPt) { + T2DlgItemTable::ClickCell(inCell, inPt); + + if (IsValidCell(mSelectedCell)) { + T2MoviePlugin *thePlugin; + GetCellData(mSelectedCell, &thePlugin); + + if (thePlugin) + BroadcastMessage(-GetDlgCtrlID(), thePlugin); + } } -/*virtual*/ void T2MovieTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2MovieTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + CPoint pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + + if (IsValidCell(cell)) + ClickCell(cell, inPt); } -/*virtual*/ int T2MovieTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2MovieTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + T2VerticalTable::OnT2DlgItemEraseBkgnd(pDC); + + unsigned int numOfRows, numOfColumns, theRow, theColumn; + + GetTableSize(numOfRows, numOfColumns); + for (theColumn = 1; theColumn <= numOfColumns; theColumn++) { + for (theRow = 1; theRow <= numOfRows; theRow++) { + TableCellT cell; + cell.row = theRow; + cell.col = theColumn; + DrawCell(pDC, cell); + } + } + + T2DlgItemTable::HiliteCell(pDC, mSelectedCell); + return true; } diff --git a/src/T2DLL/T2MovieTable.h b/src/T2DLL/T2MovieTable.h index 4ea9416..fe3c9ae 100644 --- a/src/T2DLL/T2MovieTable.h +++ b/src/T2DLL/T2MovieTable.h @@ -1,21 +1,23 @@ #pragma once #include "common.h" +#include "T2VerticalTable.h" -class T2MovieTable { -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); +class AFX_EXT_CLASS T2MovieTable : public T2VerticalTable { public: - T2MovieTable(T2TowerDoc*, T2ImageObj*, CPalette*); - void SetMovieType(int); - void Add(T2MoviePlugin*); - void Add(CFilePluginList*); + T2MovieTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual ~T2MovieTable() {} + + void SetMovieType(int inType); + void Add(T2MoviePlugin* inPlugin); + void Add(CFilePluginList* inList); + protected: - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual void DrawCell(CDC*, const TableCellT&); - void ClickCell(const TableCellT&, const CPoint&); - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual int OnT2DlgItemCreate(CREATESTRUCT* cs); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + void ClickCell(const TableCellT& inCell, const CPoint& inPt); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); -public: - virtual ~T2MovieTable() {} + int mMovieType; }; diff --git a/src/T2DLL/T2MsgWindowCallback.cpp b/src/T2DLL/T2MsgWindowCallback.cpp index 0b5aaa4..3bc77fa 100644 --- a/src/T2DLL/T2MsgWindowCallback.cpp +++ b/src/T2DLL/T2MsgWindowCallback.cpp @@ -24,7 +24,7 @@ /*virtual*/ void T2MsgWindowCallback::CallbackEvalView() { } -/*virtual*/ void T2MsgWindowCallback::CallbackPause(int) { +/*virtual*/ void T2MsgWindowCallback::CallbackPause(BOOL) { } /*virtual*/ void T2MsgWindowCallback::CallbackCalendar() { diff --git a/src/T2DLL/T2MsgWindowCallback.h b/src/T2DLL/T2MsgWindowCallback.h index 3227093..da451e0 100644 --- a/src/T2DLL/T2MsgWindowCallback.h +++ b/src/T2DLL/T2MsgWindowCallback.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class T2MsgWindowCallback { +class AFX_EXT_CLASS T2MsgWindowCallback { public: virtual void CallbackZoomIn(); virtual void CallbackZoomOut(); @@ -11,12 +11,8 @@ public: virtual void CallbackMaintView(); virtual void CallbackTransView(); virtual void CallbackEvalView(); - virtual void CallbackPause(int); + virtual void CallbackPause(BOOL); virtual void CallbackCalendar(); virtual void CallbackFunds(); virtual void CallbackPopulation(); - - T2MsgWindowCallback() {} - T2MsgWindowCallback(const T2MsgWindowCallback&) {} - T2MsgWindowCallback& operator=(const T2MsgWindowCallback&) {} }; diff --git a/src/T2DLL/T2Name.cpp b/src/T2DLL/T2Name.cpp index ab183e3..7cee408 100644 --- a/src/T2DLL/T2Name.cpp +++ b/src/T2DLL/T2Name.cpp @@ -1,37 +1,164 @@ +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2MoverModule.h" #include "T2Name.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "UT2Utils.h" T2Name::T2Name() { + mName.Empty(); + mType = 0; + mID = 0; + mFavorite = false; } -T2Name::T2Name(T2Archive&) { +T2Name::T2Name(T2Archive& archive) { + unsigned short valUShort; + unsigned char valUChar; + int valInt; + char str[4]; + + archive >> valUShort; + mType = valUShort; + + archive >> mID; + + archive >> valUChar; + mFavorite = (valUChar != 0); + + archive >> valInt; + + if (valInt == 2 || valInt == 4) { + archive >> valUChar; + if ((valInt - 1) != valUChar) { + valInt--; + str[valInt] = 0; + valInt--; + str[valInt] = valUChar; + + while (valInt > 0) { + valInt--; + archive >> str[valInt]; + } + + char tmp; + archive >> tmp; + } else { + int i; + for (i = 0; i < (valInt - 1); i++) + archive >> str[i]; + str[i] = 0; + } + mName = str; + } else { + archive.ReadPStr(mName); + } } -T2Name::T2Name(CString, T2Tenant*, int) { +T2Name::T2Name(CString str, T2Tenant* tenant, BOOL favorite) { + mName = str; + mType = kTenantNameType; + mID = tenant->GetEquipID(); + mFavorite = favorite; } -T2Name::T2Name(CString, T2People*, int) { +T2Name::T2Name(CString str, T2People* people, BOOL favorite) { + mName = str; + mType = kPeopleNameType; + mID = people->mMatterID; + mFavorite = favorite; } -T2Name::T2Name(CString, T2Mover*, int) { +T2Name::T2Name(CString str, T2Mover* mover, BOOL favorite) { + mName = str; + mType = kMoverNameType; + mID = mover->GetEquipID(); + mFavorite = favorite; } -T2Name::T2Name(CString, T2MoverModule*, int) { +T2Name::T2Name(CString str, T2MoverModule* moverModule, BOOL favorite) { + mName = str; + mType = kMoverModuleNameType; + mID = moverModule->GetModuleID(); + mFavorite = favorite; } /*virtual*/ T2Name::~T2Name() { } -short T2Name::GetName(CString&, unsigned int&) { +short T2Name::GetName(CString& outName, unsigned int& outID) { + if (!mName.IsEmpty()) { + outName = mName; + outID = mID; + } + return mType; } -void T2Name::SetName(CString) { +void T2Name::SetName(CString name) { + mName = name; } -void T2Name::MakeFullName(T2TowerDoc*, CString&) { +void T2Name::MakeFullName(T2TowerDoc* towerDoc, CString& outStr) { + if (mName != NULL) { + switch (GetType()) { + case kTenantNameType: + if (towerDoc && towerDoc->towerDoc_vf12C()) { + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *theTenant = theFloorInfo->GetTenant(GetID()); + if (theTenant) { + CString str; + int roomNumber = theTenant->GetRoomNumber(theFloorInfo); + UT2Utils::GetRoomNumberString(roomNumber, str); + str += "\x8D\x86\x8E\xBA"; // "号室" + outStr = str + mName; + } + } + break; + + case kPeopleNameType: + if (towerDoc && towerDoc->towerDoc_vf12C() && towerDoc->mPeopleArrayList) { + T2People *thePeople = towerDoc->mPeopleArrayList->FindPeople(GetID()); + if (thePeople) { + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + int tenantID = (thePeople->GetWorkTenant() > 1) ? thePeople->GetWorkTenant() : (thePeople->GetHomeTenant() > 1) ? thePeople->GetHomeTenant() : 1; + + CString str; + T2Tenant *theTenant = theFloorInfo->GetTenant(tenantID); + if (theTenant) { + int roomNumber = theTenant->GetRoomNumber(theFloorInfo); + UT2Utils::GetRoomNumberString(roomNumber, str); + str += "\x8D\x86\x8E\xBA"; // "号室" + } else { + str = "\x83\x65\x83\x69\x83\x93\x83\x67\x82\xC8\x82\xB5"; // "テナントなし" + } + outStr = str + mName; + } + } + } + } } -int T2Name::operator==(const CString&) const { +BOOL T2Name::operator==(const CString& str) const { + BOOL result = false; + + if (!mName.IsEmpty()) + result = (str.Compare(mName) == 0); + + return result; } -void T2Name::Write(T2Archive&) const { +void T2Name::Write(T2Archive& archive) const { + archive << (unsigned short) mType; + archive << mID; + + unsigned char valUChar = mFavorite ? 1 : 0; + archive << valUChar; + + int len = strlen(mName) + 1; + archive << len; + archive.WritePStr(mName); } diff --git a/src/T2DLL/T2Name.h b/src/T2DLL/T2Name.h index 290f842..102e6a8 100644 --- a/src/T2DLL/T2Name.h +++ b/src/T2DLL/T2Name.h @@ -1,25 +1,38 @@ #pragma once #include "common.h" -class T2Name { +// assumed names +enum { + kTenantNameType = 1, + kMoverNameType = 2, + kMoverModuleNameType = 3, + // what's 4?? we may never know + kPeopleNameType = 5 +}; + +class AFX_EXT_CLASS T2Name { public: T2Name(); T2Name(T2Archive&); - T2Name(CString, T2Tenant*, int); - T2Name(CString, T2People*, int); - T2Name(CString, T2Mover*, int); - T2Name(CString, T2MoverModule*, int); + T2Name(CString, T2Tenant*, BOOL favorite); + T2Name(CString, T2People*, BOOL favorite); + T2Name(CString, T2Mover*, BOOL favorite); + T2Name(CString, T2MoverModule*, BOOL favorite); virtual ~T2Name(); - short GetName(CString&, unsigned int&); + short GetName(CString& outName, unsigned int& outID); void SetName(CString); void MakeFullName(T2TowerDoc*, CString&); - int operator==(const CString&) const; + BOOL operator==(const CString&) const; void Write(T2Archive&) const; - int GetSortKey() {} - int GetType() {} - unsigned int GetID() {} - int IsFavorite() const {} - T2Name(const T2Name&) {} - T2Name& operator=(const T2Name&) {} + int GetSortKey() { return mType; } + int GetType() { return mType; } + unsigned int GetID() { return mID; } + BOOL IsFavorite() const { return mFavorite; } + +protected: + CString mName; + int mType; + unsigned int mID; + BOOL mFavorite; }; diff --git a/src/T2DLL/T2NameComparator.cpp b/src/T2DLL/T2NameComparator.cpp new file mode 100644 index 0000000..e2b1a70 --- /dev/null +++ b/src/T2DLL/T2NameComparator.cpp @@ -0,0 +1,30 @@ +#include "T2Name.h" +#include "T2NameComparator.h" + +/*virtual*/ int T2NameComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + T2Name *a = *((T2Name **) inItemOne); + T2Name *b = *((T2Name **) inItemTwo); + + if (!b) + return -1; + else if (!a) + return 1; + + return (a->IsFavorite() != b->IsFavorite()) ? (a->IsFavorite() - b->IsFavorite()) + : (a->GetType() != b->GetType()) ? (a->GetType() - b->GetType()) + : (a->GetID() - b->GetID()); +} + +/*virtual*/ BOOL T2NameComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + T2Name *a = *((T2Name **) inItemOne); + T2Name *b = *((T2Name **) inItemTwo); + return (a->IsFavorite() == b->IsFavorite()) && (a->GetType() == b->GetType()) && (a->GetID() == b->GetID()); +} + +/*static*/ T2NameComparator* T2NameComparator::sT2NameComparator; + +/*static*/ T2NameComparator* T2NameComparator::GetComparator() { + if (!sT2NameComparator) + sT2NameComparator = new T2NameComparator; + return sT2NameComparator; +} diff --git a/src/T2DLL/T2NameComparator.h b/src/T2DLL/T2NameComparator.h new file mode 100644 index 0000000..b95097b --- /dev/null +++ b/src/T2DLL/T2NameComparator.h @@ -0,0 +1,13 @@ +#pragma once +#include "common.h" +#include "LComparator.h" + +class T2NameComparator : public LComparator { +public: + virtual ~T2NameComparator() { } + virtual int Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const; + virtual BOOL IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const; + static T2NameComparator* GetComparator(); +protected: + static T2NameComparator* sT2NameComparator; +}; diff --git a/src/T2DLL/T2NameList.cpp b/src/T2DLL/T2NameList.cpp index cee243a..44ee91f 100644 --- a/src/T2DLL/T2NameList.cpp +++ b/src/T2DLL/T2NameList.cpp @@ -1,43 +1,158 @@ +#include "T2Archive.h" +#include "T2Mover.h" +#include "T2MoverModule.h" +#include "T2Name.h" +#include "T2NameComparator.h" #include "T2NameList.h" +#include "T2People.h" +#include "T2Tenant.h" -T2NameList::T2NameList() { +T2NameList::T2NameList() + : LArray(sizeof(T2Name *)) +{ + SetComparator(T2NameComparator::GetComparator()); + mOwnsComparator = false; + + SetKeepSorted(true); } /*virtual*/ T2NameList::~T2NameList() { + LArrayIterator iterator(*this); + T2Name *name; + while (iterator.Next(&name)) + delete name; } unsigned int T2NameList::GetItemCount() { + return GetCount(); } void T2NameList::Clear() { + RemoveItemsAt(mItemCount, 1); } -void T2NameList::Add(T2Name*) { +void T2NameList::Add(T2Name* name) { + InsertItemsAt(1, mItemCount + 1, &name); } -void T2NameList::RemoveName(T2Name*) { +void T2NameList::RemoveName(T2Name* name) { + Remove(&name); } -T2Name* T2NameList::Search(const T2Tenant*, int) const { +T2Name* T2NameList::Search(const T2Tenant* tenant, BOOL isFavorite) const { + LArrayIterator iterator(*this); + T2Name *name; + + while (iterator.Next(&name)) { + if ( + name->IsFavorite() == isFavorite && + name->GetType() == kTenantNameType && + name->GetID() == tenant->GetEquipID() + ) + return name; + } + + return NULL; } -T2Name* T2NameList::Search(const T2Mover*, int) const { +T2Name* T2NameList::Search(const T2Mover* mover, BOOL isFavorite) const { + LArrayIterator iterator(*this); + T2Name *name; + + while (iterator.Next(&name)) { + if ( + name->IsFavorite() == isFavorite && + name->GetType() == kMoverNameType && + name->GetID() == mover->GetEquipID() + ) + return name; + } + + return NULL; } -T2Name* T2NameList::Search(const T2MoverModule*, int) const { +T2Name* T2NameList::Search(const T2MoverModule* moverModule, BOOL isFavorite) const { + LArrayIterator iterator(*this); + T2Name *name; + + while (iterator.Next(&name)) { + if ( + name->IsFavorite() == isFavorite && + name->GetType() == kMoverModuleNameType && + name->GetID() == moverModule->GetModuleID() + ) + return name; + } + + return NULL; } -T2Name* T2NameList::Search(const T2People*, int) const { +T2Name* T2NameList::Search(const T2People* people, BOOL isFavorite) const { + LArrayIterator iterator(*this); + T2Name *name; + + while (iterator.Next(&name)) { + if ( + name->IsFavorite() == isFavorite && + name->GetType() == kPeopleNameType && + name->GetID() == people->mMatterID + ) + return name; + } + + return NULL; } -T2Name* T2NameList::Search(const CString&, int) const { +T2Name* T2NameList::Search(const CString& str, BOOL isFavorite) const { + LArrayIterator iterator(*this); + T2Name *result = NULL; + T2Name *name = NULL; + + while (iterator.Next(&name)) { + if (name->IsFavorite() == isFavorite && *name == str) { + result = name; + break; + } + } + + return result; } -T2Name* T2NameList::FullNameSearch(T2TowerDoc*, const CString&, int) const { +T2Name* T2NameList::FullNameSearch(T2TowerDoc* towerDoc, const CString& str, BOOL isFavorite) const { + LArrayIterator iterator(*this); + T2Name *result = NULL; + T2Name *name = NULL; + + while (iterator.Next(&name)) { + CString fullName; + name->MakeFullName(towerDoc, fullName); + BOOL nameMatches = (fullName == str); + if (name->IsFavorite() == isFavorite && nameMatches) { + result = name; + break; + } + } + + return result; } -void T2NameList::Read(T2Archive&) { +void T2NameList::Read(T2Archive& archive) { + int count; + archive >> count; + + for (int i = 0; i < count; i++) { + T2Name *name = new T2Name(archive); + Add(name); + } } -void T2NameList::Write(T2Archive&) const { +void T2NameList::Write(T2Archive& archive) const { + int count = GetCount(); + archive << count; + + LArrayIterator iterator(*this); + T2Name *name; + + while (iterator.Next(&name)) + name->Write(archive); } diff --git a/src/T2DLL/T2NameList.h b/src/T2DLL/T2NameList.h index 82a3e5b..03fd23a 100644 --- a/src/T2DLL/T2NameList.h +++ b/src/T2DLL/T2NameList.h @@ -1,7 +1,8 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2NameList { +class AFX_EXT_CLASS T2NameList : public LArray { public: T2NameList(); virtual ~T2NameList(); @@ -9,15 +10,12 @@ public: void Clear(); void Add(T2Name*); void RemoveName(T2Name*); - T2Name* Search(const T2Tenant*, int) const; - T2Name* Search(const T2Mover*, int) const; - T2Name* Search(const T2MoverModule*, int) const; - T2Name* Search(const T2People*, int) const; - T2Name* Search(const CString&, int) const; - T2Name* FullNameSearch(T2TowerDoc*, const CString&, int) const; + T2Name* Search(const T2Tenant*, BOOL isFavorite = false) const; + T2Name* Search(const T2Mover*, BOOL isFavorite = false) const; + T2Name* Search(const T2MoverModule*, BOOL isFavorite = false) const; + T2Name* Search(const T2People*, BOOL isFavorite = false) const; + T2Name* Search(const CString&, BOOL isFavorite = false) const; + T2Name* FullNameSearch(T2TowerDoc*, const CString&, BOOL isFavorite = false) const; void Read(T2Archive&); void Write(T2Archive&) const; - - T2NameList(const T2NameList&) {} - T2NameList& operator=(const T2NameList&) {} }; diff --git a/src/T2DLL/T2NameTable.cpp b/src/T2DLL/T2NameTable.cpp index c68c2fd..994ab5a 100644 --- a/src/T2DLL/T2NameTable.cpp +++ b/src/T2DLL/T2NameTable.cpp @@ -1,34 +1,103 @@ +#include "T2Name.h" +#include "T2NameList.h" #include "T2NameTable.h" -/*virtual*/ int T2NameTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ BOOL T2NameTable::OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct) { + return T2DlgItemTable::OnT2DlgItemCreate(inCreateStruct); } -T2NameTable::T2NameTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2NameTable::T2NameTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2VerticalTable(inDoc, inImageObj, inPalette) +{ } T2Name* T2NameTable::GetSelectedName() { + T2Name *theName = NULL; + + if (IsValidCell(mSelectedCell)) + GetCellData(mSelectedCell, &theName); + + return theName; } -/*virtual*/ void T2NameTable::ClickSelf(POINT) { +/*virtual*/ void T2NameTable::ClickSelf(POINT inPt) { + POINT pt = inPt; + ClientToView(&pt, 1); + + TableCellT cell; + FetchCellHitBy(pt, cell); + + if (IsValidCell(cell)) { + ClickCell(cell, inPt); + + T2Name *theName; + GetCellData(cell, &theName); + BroadcastMessage(4201, theName); + } } -/*virtual*/ void T2NameTable::OnT2DlgItemLButtonDown(unsigned int, CPoint) { +/*virtual*/ void T2NameTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) { + ClickSelf(inPt); } -/*virtual*/ void T2NameTable::Add(T2NameList*) { +/*virtual*/ void T2NameTable::Add(T2NameList* inNameList) { + if (inNameList) { + LArrayIterator iterator(*inNameList); + T2Name *name; + + while (iterator.Next(&name)) + Add(name); + } } -/*virtual*/ void T2NameTable::Add(T2Name*) { +/*virtual*/ void T2NameTable::Add(T2Name* inName) { + if (inName) + InsertRows(1, mRows, &inName); } /*virtual*/ void T2NameTable::RemoveCurrentCell() { + RemoveRows(1, mSelectedCell.row); + mSelectedCell.col = 0; + mSelectedCell.row = 0; } -/*virtual*/ void T2NameTable::DrawCell(CDC*, const TableCellT&) { +/*virtual*/ void T2NameTable::DrawCell(CDC* pDC, const TableCellT& inCell) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + RECT rect; + if (FetchLocalCellFrame(inCell, rect)) { + T2Name *theName; + GetCellData(inCell, &theName); + if (theName) { + CString str; + unsigned int id; + int nameType = theName->GetName(str, id); + pDC->TextOut(rect.left + 4, rect.bottom - 2, str, strlen(str)); + } + } + + pDC->RestoreDC(save); } -/*virtual*/ void T2NameTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2NameTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + DrawCell(pDC, inCell); } -/*virtual*/ int T2NameTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2NameTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + unsigned int numOfRows, numOfColumns, theRow, theColumn; + + GetTableSize(numOfRows, numOfColumns); + for (theColumn = 1; theColumn <= numOfColumns; theColumn++) { + for (theRow = 1; theRow <= numOfRows; theRow++) { + TableCellT cell; + cell.row = theRow; + cell.col = theColumn; + DrawCell(pDC, cell); + } + } + + InvalidateRect(NULL); + return true; } diff --git a/src/T2DLL/T2NameTable.h b/src/T2DLL/T2NameTable.h index 139c611..7a47c72 100644 --- a/src/T2DLL/T2NameTable.h +++ b/src/T2DLL/T2NameTable.h @@ -1,24 +1,21 @@ #pragma once #include "common.h" +#include "T2VerticalTable.h" -class T2NameTable { -protected: - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); -public: - T2NameTable(T2TowerDoc*, T2ImageObj*, CPalette*); - T2Name* GetSelectedName(); - virtual void ClickSelf(POINT); -protected: - virtual void OnT2DlgItemLButtonDown(unsigned int, CPoint); +class AFX_EXT_CLASS T2NameTable : public T2VerticalTable { public: - virtual void Add(T2NameList*); - virtual void Add(T2Name*); + T2NameTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); + virtual ~T2NameTable() {} + virtual void ClickSelf(POINT inPt); + virtual void Add(T2NameList* inNameList); + virtual void Add(T2Name* inName); virtual void RemoveCurrentCell(); -protected: - virtual void DrawCell(CDC*, const TableCellT&); - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + T2Name* GetSelectedName(); -public: - virtual ~T2NameTable() {} +protected: + virtual BOOL OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct); + virtual void OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt); + virtual void DrawCell(CDC* pDC, const TableCellT& inCell); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); }; diff --git a/src/T2DLL/T2Object.cpp b/src/T2DLL/T2Object.cpp index 7336a5a..3c52d9a 100644 --- a/src/T2DLL/T2Object.cpp +++ b/src/T2DLL/T2Object.cpp @@ -3,7 +3,7 @@ T2Object::T2Object() { mUsed = false; - mStatus = 0; + mStatus = kStatus0; mFavorite = false; } diff --git a/src/T2DLL/T2Object.h b/src/T2DLL/T2Object.h index 8084bc7..e7c2c4b 100644 --- a/src/T2DLL/T2Object.h +++ b/src/T2DLL/T2Object.h @@ -2,14 +2,50 @@ #include "common.h" #include "CLink.h" -class DLL_EXPORT T2Object { +enum { + kStatus0, + // "out of the tower" + kStatus1, + // "just on the floor" + kStatus2, + // "on the floor" + kStatus3, + // "looking for the route" + kStatus4, + // "going to the mover" + kStatus5, + // "waiting the mover" + kStatus6, + // "on the mover" + kStatus7, + // "just taking the mover" + kStatus8, + // "just getting off the mover" + kStatus9, + // "going to the tenant" + kStatus10, + // "in the tenant" + kStatus11, + // "going out the tower" + kStatus12, + // "goint to the emergency stair" + kStatus13, + // "going to the point" + kStatus14, + // "stopping" + kStatus15, + // "on the transporter" + kStatus16, +}; + +class AFX_EXT_CLASS T2Object { public: T2Object(); virtual ~T2Object() {} virtual void SetUsed(BOOL u) { mUsed = u; } - virtual int Enter(CLink*) { return 0; } - virtual int Leave(CLink*) { return 0; } + virtual BOOL Enter(CLink*) { return false; } + virtual BOOL Leave(CLink*) { return false; } virtual unsigned int Idle(T2TowerDoc*) { return 0; } virtual void SetFavorite(BOOL v); virtual void Load(T2Archive& archive, T2TowerDoc* towerDoc); diff --git a/src/T2DLL/T2ObjectArray.h b/src/T2DLL/T2ObjectArray.h index 5c422da..1d7a6fb 100644 --- a/src/T2DLL/T2ObjectArray.h +++ b/src/T2DLL/T2ObjectArray.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2ObjectArray { +class AFX_EXT_CLASS T2ObjectArray { public: T2ObjectArray(unsigned int startID = 1); virtual ~T2ObjectArray(); diff --git a/src/T2DLL/T2ObjectArrayList.cpp b/src/T2DLL/T2ObjectArrayList.cpp index 20ccd32..906c324 100644 --- a/src/T2DLL/T2ObjectArrayList.cpp +++ b/src/T2DLL/T2ObjectArrayList.cpp @@ -6,8 +6,12 @@ T2ObjectArrayList::T2ObjectArrayList() { /*virtual*/ T2ObjectArrayList::~T2ObjectArrayList() { } -void T2ObjectArrayList::AddObjectArray(T2ObjectArray*) { +void T2ObjectArrayList::AddObjectArray(T2ObjectArray* inArray) { + Add(&inArray); } -T2ObjectArray* T2ObjectArrayList::GetObjectArrayAt(int) { +T2ObjectArray* T2ObjectArrayList::GetObjectArrayAt(int inIndex) { + T2ObjectArray *theArray; + FetchItemAt(inIndex, &theArray); + return theArray; } diff --git a/src/T2DLL/T2ObjectArrayList.h b/src/T2DLL/T2ObjectArrayList.h index 6fd379e..e9e7450 100644 --- a/src/T2DLL/T2ObjectArrayList.h +++ b/src/T2DLL/T2ObjectArrayList.h @@ -1,13 +1,11 @@ #pragma once #include "common.h" +#include "CObjectList.h" -class T2ObjectArrayList { +class AFX_EXT_CLASS T2ObjectArrayList : public CObjectList { public: T2ObjectArrayList(); virtual ~T2ObjectArrayList(); - void AddObjectArray(T2ObjectArray*); - T2ObjectArray* GetObjectArrayAt(int); - - T2ObjectArrayList(const T2ObjectArrayList&) {} - T2ObjectArrayList& operator=(const T2ObjectArrayList&) {} + void AddObjectArray(T2ObjectArray* inArray); + T2ObjectArray* GetObjectArrayAt(int inIndex); }; diff --git a/src/T2DLL/T2OptionPlugin.h b/src/T2DLL/T2OptionPlugin.h new file mode 100644 index 0000000..d02fc29 --- /dev/null +++ b/src/T2DLL/T2OptionPlugin.h @@ -0,0 +1,16 @@ +#pragma once +#include "common.h" +#include "T2PluginSpecifier.h" + +class AFX_EXT_CLASS T2OptionPlugin { + // a proper definition for this will have to wait + // as nothing seems to actually use this subsystem... +public: + virtual ~T2OptionPlugin(); + virtual CString GetName() const { return "OPTION"; } + virtual BOOL OnEvent(OPTIONEVENTTYPE eventType, T2TowerDoc *towerDoc, void *data) { return true; } + +protected: + T2PluginSpecifier mSpecifier; + int m38; +}; diff --git a/src/T2DLL/T2OptionPluginList.cpp b/src/T2DLL/T2OptionPluginList.cpp index b8d49d6..d060b95 100644 --- a/src/T2DLL/T2OptionPluginList.cpp +++ b/src/T2DLL/T2OptionPluginList.cpp @@ -1,16 +1,33 @@ +#include "T2OptionPlugin.h" #include "T2OptionPluginList.h" -T2OptionPluginList::T2OptionPluginList() { +T2OptionPluginList::T2OptionPluginList() + : LArray(sizeof(T2OptionPlugin *)) +{ } /*virtual*/ T2OptionPluginList::~T2OptionPluginList() { } -void T2OptionPluginList::Add(T2OptionPlugin*) { +void T2OptionPluginList::Add(T2OptionPlugin* plugin) { + if (!plugin) + return; + + InsertItemsAt(1, mItemCount + 1, &plugin); } -void T2OptionPluginList::OnIdle(T2TowerDoc*) { +void T2OptionPluginList::OnIdle(T2TowerDoc* towerDoc) { + DispatchEvent(OptionEventType_0, towerDoc, NULL); } -int T2OptionPluginList::DispatchEvent(OPTIONEVENTTYPE, T2TowerDoc*, void*) { +BOOL T2OptionPluginList::DispatchEvent(OPTIONEVENTTYPE eventType, T2TowerDoc* towerDoc, void* data) { + LArrayIterator iterator(*this); + T2OptionPlugin *plugin; + BOOL result = true; + + while (iterator.Next(&plugin)) { + result = result && plugin->OnEvent(eventType, towerDoc, data); + } + + return result; } diff --git a/src/T2DLL/T2OptionPluginList.h b/src/T2DLL/T2OptionPluginList.h index bb25c65..462575e 100644 --- a/src/T2DLL/T2OptionPluginList.h +++ b/src/T2DLL/T2OptionPluginList.h @@ -1,14 +1,12 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2OptionPluginList { +class T2OptionPluginList : private LArray { public: T2OptionPluginList(); virtual ~T2OptionPluginList(); - void Add(T2OptionPlugin*); - void OnIdle(T2TowerDoc*); - int DispatchEvent(OPTIONEVENTTYPE, T2TowerDoc*, void*); - - T2OptionPluginList(const T2OptionPluginList&) {} - T2OptionPluginList& operator=(const T2OptionPluginList&) {} + void Add(T2OptionPlugin* plugin); + void OnIdle(T2TowerDoc* towerDoc); + BOOL DispatchEvent(OPTIONEVENTTYPE eventType, T2TowerDoc* towerDoc, void* data); }; diff --git a/src/T2DLL/T2OutDecoration.cpp b/src/T2DLL/T2OutDecoration.cpp index ba8e432..575f0f8 100644 --- a/src/T2DLL/T2OutDecoration.cpp +++ b/src/T2DLL/T2OutDecoration.cpp @@ -1,22 +1,235 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" #include "T2OutDecoration.h" +#include "T2PaletteAnime.h" +#include "T2Sprite.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "URect.h" +#include "UT2Coordinate.h" -T2OutDecoration::T2OutDecoration(T2TowerEvent*, CResFile*, int) { +T2OutDecoration::T2OutDecoration(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + int resID; + int numOfOutDeco; + T2OutDeco *theOutDeco; + + *inResFile >> numOfOutDeco; + for (int index = 0; index < numOfOutDeco; index++) { + unsigned int frameCount; + + *inResFile >> resID; + *inResFile >> frameCount; + + theOutDeco = new T2OutDeco(this, resID, frameCount); + mArray.Add(&theOutDeco); + } + + mCurrentViewMode = -1; + mCurrentFrame = 0; } /*virtual*/ T2OutDecoration::~T2OutDecoration() { + LArrayIterator iterator(mArray); + T2OutDeco *theOutDeco; + + while (iterator.Next(&theOutDeco)) + delete theOutDeco; } -/*virtual*/ int T2OutDecoration::Exec(T2TowerDoc*) { +/*virtual*/ int T2OutDecoration::Exec(T2TowerDoc* inDoc) { + T2PaletteAnime *thePalette = inDoc->towerDoc_vf160(); + int frame = thePalette->IsSnow() ? 1 : 0; + + if (inDoc->towerDoc_vf140() != mCurrentViewMode || frame != mCurrentFrame) + DoDecoration(inDoc, (VIEWMODE) inDoc->towerDoc_vf140(), frame); + + return 0; } -void T2OutDecoration::DoDecoration(T2TowerDoc*, VIEWMODE, int) { +void T2OutDecoration::DoDecoration(T2TowerDoc* inDoc, VIEWMODE inViewMode, int inFrame) { + T2OutDeco *theOutDeco; + + if (inViewMode == ViewMode_1) { + LArray *theRoofList = MakeLoofList(); + if (theRoofList) { + T2Sprite *theSprite = &inDoc->mSprite; + BOOL isGap = false; + + LArrayIterator roofIterator(*theRoofList); + T2RoofInfo *theRoofInfo; + + while (roofIterator.Next(&theRoofInfo)) { + if (theRoofInfo->flag || isGap) { + LArrayIterator outDecoIterator(mArray); + + while (outDecoIterator.Next(&theOutDeco)) { + if (!theOutDeco->mVisible) { + CRect rect = theRoofInfo->rect; + UT2Coordinate::UnitToQD(rect, 0); + + if (URect::Width(rect) > (URect::Width(theOutDeco->mRect) + 64)) { + theOutDeco->Load(inFrame); + if (theOutDeco->mSpriteID != -1) { + OffsetRect(&rect, 42, 28 - URect::Height(theOutDeco->mRect)); + theSprite->MoveSprite(theOutDeco->mSpriteID, rect.TopLeft()); + theSprite->ShowSprite(theOutDeco->mSpriteID, true); + } + theOutDeco->mVisible = true; + break; + } + } + } + } + + isGap = !theRoofInfo->flag; + theRoofList->RemoveItemsAt(1, roofIterator.GetCurrentIndex()); + roofIterator.Reset(); + delete theRoofInfo; + } + + delete theRoofList; + } + } + + LArrayIterator outDecoIterator(mArray); + while (outDecoIterator.Next(&theOutDeco)) { + if (!theOutDeco->mVisible) + theOutDeco->Unload(); + theOutDeco->mVisible = false; + } + + mCurrentViewMode = inViewMode; + mCurrentFrame = inFrame; } -/*virtual*/ void T2OutDecoration::ViewModeChanged(T2TowerDoc*, VIEWMODE) { +/*virtual*/ void T2OutDecoration::ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE inViewMode) { + if (inViewMode != mCurrentViewMode && (inViewMode == ViewMode_1 || mCurrentViewMode == ViewMode_1)) { + T2PaletteAnime *thePalette = inDoc->towerDoc_vf160(); + int frame = thePalette->IsSnow() ? 1 : 0; + + DoDecoration(inDoc, inViewMode, frame); + } } -void T2OutDecoration::CheckRoofTop(T2Equip*) { +void T2OutDecoration::CheckRoofTop(T2Equip* inEquip) { + mCurrentViewMode = -1; } LArray* T2OutDecoration::MakeLoofList() { + LArray *theArray = new LArray; + + if (theArray) { + T2FloorInfo *theFloorInfo = GetTowerDoc()->towerDoc_vf12C(); + int curV; + int groundV = GetWorldDef()->mGroundLine - 1; + int nextH; + int v, h; + + CRect theBuildArea; + GetWorldDef()->GetBuildArea(theBuildArea); + + for (h = theBuildArea.left; h < theBuildArea.right; h++) { + if (theFloorInfo->GetTenant(groundV, h)) + break; + } + int lobbyLeftH = h; + + for (h = theBuildArea.right - 1; h > theBuildArea.left; h--) { + if (theFloorInfo->GetTenant(groundV, h)) + break; + } + int lobbyRightH = h; + + if (lobbyLeftH < lobbyRightH) { + for (h = lobbyLeftH; h <= lobbyRightH; h = nextH) { + for (v = groundV; ; v--) { + if (!theFloorInfo->GetTenant(v, h)) + break; + } + + for (nextH = h; nextH <= lobbyRightH; nextH++) { + curV = v; + if (theFloorInfo->GetTenant(curV, nextH)) + break; + + curV = v + 1; + T2Tenant *theTenant = theFloorInfo->GetTenant(curV, nextH); + if (!theTenant) + break; + if (theTenant->IsSetAttribute(kTenantAttr40000)) + break; + } + + T2RoofInfo *theRoofInfo = new T2RoofInfo(h, v, nextH, v + 1, curV == v); + theArray->Add(&theRoofInfo); + } + } + } + + return theArray; +} + + + +T2OutDeco::T2OutDeco(T2OutDecoration *inOwner, int inResID, unsigned int inFrameCount) { + mOwner = inOwner; + mSpriteID = -1; + mLoaded = false; + mResID = inResID; + mFrameCount = (inFrameCount > 0) ? inFrameCount : 1; + mCurrent = 0; + mVisible = false; + mImage = NULL; + mImageObj = NULL; + + try { + T2BitImage image(GetWorldModuleHandle(), mResID, true); + SetRect(&mRect, 0, 0, image.mBitmap.header.biWidth, image.mBitmap.header.biHeight); + mRect.bottom = mRect.top + (mRect.Height() / mFrameCount); + } catch (int err) { + SetRect(&mRect, 0, 0, 0, 0); + } +} + +T2OutDeco::~T2OutDeco() { +} + +void T2OutDeco::Load(int inID) { + if (!SetRectEmpty(&mRect) && (mSpriteID == -1 || mCurrent != inID)) { + Unload(); + + mImage = new T2BitImage(GetWorldModuleHandle(), mResID, true); + mCurrent = (inID >= 0 && inID < mFrameCount) ? inID : 0; + + T2Sprite *theSprite = &mOwner->GetTowerDoc()->mSprite; + mImageObj = new T2ImageObj; + mImageObj->AddObject("OUTDECO", 0, *mImage, NULL, false, false); + mSpriteID = theSprite->NewSprite(*mImageObj, "OUTDECO", T2Sprite::ELayer_1); + mLoaded = true; + } +} + +void T2OutDeco::Unload() { + if (mSpriteID != -1) { + T2Sprite *theSprite = &mOwner->GetTowerDoc()->mSprite; + theSprite->DeleteSprite(mSpriteID); + mSpriteID = -1; + + delete mImageObj; + delete mImage; + } + mLoaded = false; +} + + + +T2RoofInfo::T2RoofInfo(int inLeft, int inTop, int inRight, int inBottom, BOOL inFlag) { + SetRect(&rect, inLeft, inTop, inRight, inBottom); + flag = inFlag; } diff --git a/src/T2DLL/T2OutDecoration.h b/src/T2DLL/T2OutDecoration.h index c865bab..9dcc8a3 100644 --- a/src/T2DLL/T2OutDecoration.h +++ b/src/T2DLL/T2OutDecoration.h @@ -1,20 +1,52 @@ #pragma once #include "common.h" +#include "LArray.h" +#include "T2EventItem.h" -class T2OutDecoration { +class AFX_EXT_CLASS T2OutDecoration : public T2EventItem { public: - T2OutDecoration(T2TowerEvent*, CResFile*, int); + T2OutDecoration(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); virtual ~T2OutDecoration(); - virtual int Exec(T2TowerDoc*); - void DoDecoration(T2TowerDoc*, VIEWMODE, int); - virtual void ViewModeChanged(T2TowerDoc*, VIEWMODE); - void CheckRoofTop(T2Equip*); + virtual DWORD GetID() { return 'OdEv'; } + virtual BOOL IsBeginTime(unsigned int inTime) { return true; } + virtual int Exec(T2TowerDoc* inDoc); + virtual void ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE inViewMode); + void DoDecoration(T2TowerDoc* inDoc, VIEWMODE inViewMode, int inFrame); + void CheckRoofTop(T2Equip* inEquip); + private: LArray* MakeLoofList(); + LArray mArray; + int mCurrentViewMode; + int mCurrentFrame; +}; + +class T2OutDeco { public: - virtual unsigned long GetID() {} - virtual int IsBeginTime(unsigned int) {} - T2OutDecoration(const T2OutDecoration&) {} - T2OutDecoration& operator=(const T2OutDecoration&) {} + T2OutDeco(T2OutDecoration *inOwner, int inResID, unsigned int inFrameCount); + ~T2OutDeco(); + void Load(int inID); + void Unload(); + +private: + friend class T2OutDecoration; + + T2OutDecoration *mOwner; + int mSpriteID; + BOOL mLoaded; + int mResID; + int mFrameCount; + CRect mRect; + int mCurrent; + BOOL mVisible; + T2BitImage *mImage; + T2ImageObj *mImageObj; +}; + +struct T2RoofInfo { + CRect rect; + BOOL flag; + + T2RoofInfo(int inLeft, int inTop, int inRight, int inBottom, BOOL inFlag); }; diff --git a/src/T2DLL/T2OutObj.cpp b/src/T2DLL/T2OutObj.cpp index 7eb99b0..570e77c 100644 --- a/src/T2DLL/T2OutObj.cpp +++ b/src/T2DLL/T2OutObj.cpp @@ -1,40 +1,149 @@ +#include "T2Archive.h" +#include "T2FloorInfo.h" #include "T2OutObj.h" +#include "T2OuterObjDef.h" +#include "T2TemplatePluginList.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" T2OutObj::T2OutObj() { + mID = 0; + SetRect(&mOutObjArea, 0, 0, 0, 0); + mToolType = 0; + + mToolDef = NULL; + mRefCon = 0; + mSubPlugin = NULL; } /*virtual*/ T2OutObj::~T2OutObj() { } -/*virtual*/ void T2OutObj::Draw(T2TowerDoc*, const CRect&) { +/*virtual*/ void T2OutObj::Draw(T2TowerDoc* towerDoc, const CRect& rect) { + T2ToolDef *theToolDef = GetToolDef(); + theToolDef->DrawProc(this, rect, towerDoc); } -/*virtual*/ PROCCODE T2OutObj::DoDestruct(T2TowerDoc*, int, CPoint, CPoint, CRect&) { +/*virtual*/ PROCCODE T2OutObj::DoDestruct(T2TowerDoc* towerDoc, int, CPoint pt1, CPoint, CRect& rect) { + PROCCODE result = ProcCode_0; + + if (GetToolDef()) + result = GetToolDef()->DoDestructProc(towerDoc, this, pt1, rect); + else + result = Destruct(towerDoc, rect); + + return result; } -/*virtual*/ PROCCODE T2OutObj::Destruct(T2TowerDoc*, RECT&) { +/*virtual*/ PROCCODE T2OutObj::Destruct(T2TowerDoc* towerDoc, RECT& rect) { + GetOutObjArea(rect); + + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + if (theFloorInfo) { + theFloorInfo->FillOutObjID(rect, 0); + if (GetToolDef()) + GetToolDef()->DestructFinish(towerDoc, this); + } + + SetUsed(false); + + return ProcCode_1; } -/*virtual*/ void T2OutObj::GetOutObjArea(RECT&) const { +/*virtual*/ void T2OutObj::GetOutObjArea(RECT& rect) const { + rect = mOutObjArea; } -/*virtual*/ unsigned int T2OutObj::Idle(T2TowerDoc*) { +/*virtual*/ unsigned int T2OutObj::Idle(T2TowerDoc* towerDoc) { + unsigned int result = 0; + + if (GetToolDef()) + result = GetToolDef()->IdleProc(this, towerDoc); + + if (result) + towerDoc->GetTowerMainView()->tmv_vf128(mOutObjArea); + + return result; } -/*virtual*/ int T2OutObj::InitOutObj(T2OuterObjDef*, const RECT&, unsigned int) { +/*virtual*/ int T2OutObj::InitOutObj(T2OuterObjDef* def, const RECT& outObjArea, unsigned int valiation) { + int result = 0; + + mSubPlugin = NULL; + + if (def) { + mToolType = def->GetToolType(); + mToolDef = def; + } + + mOutObjArea = outObjArea; + mValiation = valiation; + mRefCon = 0; + mStatus = kOutObjStatus0; + SetUsed(true); + + return result; } -/*virtual*/ void T2OutObj::LoadSelf(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2OutObj::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + T2Object::LoadSelf(archive, towerDoc); + + if (IsUsed()) { + unsigned short us; + short s; + + archive >> us; + mID = us; + + archive.ReadSRect(mOutObjArea); + + archive >> mValiation; + + archive >> s; + mToolType = s; + + mToolDef = towerDoc->mOuterObjTemplates->FindOutObjDef(mToolType); + if (mToolDef) { + mToolDef->LoadExtraData(archive, towerDoc, this); + } else { + int count; + archive >> count; + + for (int i = 0; i < count; i++) { + char tmp; + archive >> tmp; + } + } + } } -/*virtual*/ void T2OutObj::SaveSelf(T2Archive&) { +/*virtual*/ void T2OutObj::SaveSelf(T2Archive& archive) { + T2Object::SaveSelf(archive); + + if (IsUsed()) { + archive << (unsigned short) mID; + archive.WriteSRect(mOutObjArea); + archive << mValiation; + archive << (short) mToolType; + + if (mToolDef) { + mToolDef->SaveExtraData(archive, this); + } else { + int count = 0; + archive << count; + } + } } -/*virtual*/ void T2OutObj::StartBuild(T2TowerDoc*) { +/*virtual*/ void T2OutObj::StartBuild(T2TowerDoc* towerDoc) { + mStatus = kOutObjStatus1; } -/*virtual*/ T2InfoDialog* T2OutObj::ShowInfoDialog(T2TowerDoc*) { +/*virtual*/ T2InfoDialog* T2OutObj::ShowInfoDialog(T2TowerDoc* towerDoc) { + return ((T2OuterObjDef *) mToolDef)->ShowInfoDialog(towerDoc, this); } -/*virtual*/ void T2OutObj::DrawHitMask(T2TowerDoc*) { +/*virtual*/ void T2OutObj::DrawHitMask(T2TowerDoc* towerDoc) { + CRect rect = mOutObjArea; + Draw(towerDoc, rect); } diff --git a/src/T2DLL/T2OutObj.h b/src/T2DLL/T2OutObj.h index 615895d..a3cb599 100644 --- a/src/T2DLL/T2OutObj.h +++ b/src/T2DLL/T2OutObj.h @@ -1,24 +1,41 @@ #pragma once #include "common.h" +#include "T2HaveOutViewObject.h" -class T2OutObj { +enum { + kOutObjStatus0 = 0, + kOutObjStatus1 +}; + +class AFX_EXT_CLASS T2OutObj : public T2HaveOutViewObject { public: T2OutObj(); virtual ~T2OutObj(); + virtual unsigned int Idle(T2TowerDoc*); + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); + virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*); + virtual void DrawHitMask(T2TowerDoc*); + + virtual int InitOutObj(T2OuterObjDef* def, const RECT& outObjArea, unsigned int valiation); + virtual void StartBuild(T2TowerDoc*); + virtual PROCCODE Destruct(T2TowerDoc*, RECT&); + virtual PROCCODE DoDestruct(T2TowerDoc*, int, CPoint, CPoint, CRect&); + virtual void GetOutObjArea(RECT&) const; virtual void Draw(T2TowerDoc*, const CRect&); - virtual PROCCODE DoDestruct(T2TowerDoc*, int, CPoint, CPoint, CRect&); - virtual PROCCODE Destruct(T2TowerDoc*, RECT&); - virtual void GetOutObjArea(RECT&) const; - virtual unsigned int Idle(T2TowerDoc*); - virtual int InitOutObj(T2OuterObjDef*, const RECT&, unsigned int); - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); - virtual void StartBuild(T2TowerDoc*); - virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*); - virtual void DrawHitMask(T2TowerDoc*); - T2ToolDef* GetToolDef() const {} - void SetToolDef(T2ToolDef*) {} - T2OutObj(const T2OutObj&) {} - T2OutObj& operator=(const T2OutObj&) {} + T2ToolDef* GetToolDef() const { return mToolDef; } + void SetToolDef(T2ToolDef* def) { mToolDef = def; } + +protected: + friend class T2OuterObjDef; + friend class T2OutObjArray; + friend class T2OutObjInfoDialog; + + unsigned int mID; + RECT mOutObjArea; + int mToolType; + int _38; + RECT _3C; + int _4C; }; diff --git a/src/T2DLL/T2OutObjArray.cpp b/src/T2DLL/T2OutObjArray.cpp index ef96821..b38ac82 100644 --- a/src/T2DLL/T2OutObjArray.cpp +++ b/src/T2DLL/T2OutObjArray.cpp @@ -1,22 +1,49 @@ #include "T2OutObjArray.h" -T2OutObjArray::T2OutObjArray(unsigned int) { +T2OutObjArray::T2OutObjArray(unsigned int inStartID) + : T2ObjectArray(inStartID) +{ + for (unsigned int i = 0; i < kGroupSize; i++) + mOutObj[i].mID = mStartID + i; } /*virtual*/ T2OutObjArray::~T2OutObjArray() { } T2OutObj* T2OutObjArray::FindUnusedOutObj() const { + for (int i = 0; i < kGroupSize; i++) { + if (!mOutObj[i].IsUsed()) + return (T2OutObj *) &mOutObj[i]; + } + + return NULL; } -/*virtual*/ void T2OutObjArray::DispatchIdle(T2TowerDoc*, int) { +/*virtual*/ void T2OutObjArray::DispatchIdle(T2TowerDoc* inDoc, int) { + for (int i = 0; i < kGroupSize; i++) { + if (mOutObj[i].IsUsed()) + mOutObj[i].Idle(inDoc); + } } -int T2OutObjArray::CalcMentenanceCost(T2TowerDoc*) const { +int T2OutObjArray::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int cost = 0; + const T2OutObj *theOutObj = &mOutObj[0]; + + for (unsigned int i = 0; i < kGroupSize; i++, theOutObj++) { + if (theOutObj->IsUsed()) + cost += theOutObj->CalcMentenanceCost(inDoc); + } + + return cost; } -void T2OutObjArray::Read(T2Archive&, T2TowerDoc*) { +void T2OutObjArray::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + for (int i = 0; i < kGroupSize; i++) + mOutObj[i].Load(inArchive, inDoc); } -void T2OutObjArray::Write(T2Archive&) { +void T2OutObjArray::Write(T2Archive& inArchive) { + for (int i = 0; i < kGroupSize; i++) + mOutObj[i].Save(inArchive); } diff --git a/src/T2DLL/T2OutObjArray.h b/src/T2DLL/T2OutObjArray.h index 504f1d7..b3791eb 100644 --- a/src/T2DLL/T2OutObjArray.h +++ b/src/T2DLL/T2OutObjArray.h @@ -1,18 +1,24 @@ #pragma once #include "common.h" +#include "T2ObjectArray.h" +#include "T2OutObj.h" -class T2OutObjArray { +class AFX_EXT_CLASS T2OutObjArray : public T2ObjectArray { public: - T2OutObjArray(unsigned int); + enum { kGroupSize = 64 }; + + T2OutObjArray(unsigned int inStartID = 1000); virtual ~T2OutObjArray(); + virtual void DispatchIdle(T2TowerDoc* inDoc, int); T2OutObj* FindUnusedOutObj() const; - virtual void DispatchIdle(T2TowerDoc*, int); - int CalcMentenanceCost(T2TowerDoc*) const; - void Read(T2Archive&, T2TowerDoc*); - void Write(T2Archive&); + int CalcMentenanceCost(T2TowerDoc* inDoc) const; + void Read(T2Archive& inArchive, T2TowerDoc* inDoc); + void Write(T2Archive& inArchive); + + T2OutObj* GetIndexOutObj(int i) { return &mOutObj[i]; } + +protected: + friend class T2OutObjArrayList; - T2OutObj* GetIndexOutObj(int) {} - T2OutObjArray(const T2OutObjArray&) {} - T2OutObjArray& operator=(const T2OutObjArray&) {} - void `default constructor closure'() {} + T2OutObj mOutObj[kGroupSize]; }; diff --git a/src/T2DLL/T2OutObjArrayList.cpp b/src/T2DLL/T2OutObjArrayList.cpp index 3948561..bf1b3fd 100644 --- a/src/T2DLL/T2OutObjArrayList.cpp +++ b/src/T2DLL/T2OutObjArrayList.cpp @@ -1,34 +1,114 @@ +#include "T2Archive.h" +#include "T2OutObjArray.h" #include "T2OutObjArrayList.h" -T2OutObjArrayList::T2OutObjArrayList() { +T2OutObjArrayList::T2OutObjArrayList() + : LArray(sizeof(T2OutObjArray *)) +{ + T2OutObjArray *theArray = new T2OutObjArray; + Add(theArray); } /*virtual*/ T2OutObjArrayList::~T2OutObjArrayList() { + LArrayIterator iterator(*this); + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) + delete theArray; } -void T2OutObjArrayList::Add(T2OutObjArray*) { +void T2OutObjArrayList::Add(T2OutObjArray* inArray) { + InsertItemsAt(1, mItemCount + 1, &inArray); } -T2OutObjArray* T2OutObjArrayList::GetItemAt(int) { +T2OutObjArray* T2OutObjArrayList::GetItemAt(int inIndex) { + T2OutObjArray *theArray; + if (FetchItemAt(inIndex, &theArray)) + return theArray; + return NULL; } T2OutObj* T2OutObjArrayList::FindUnusedOutObj() { + LArrayIterator iterator(*this); + unsigned int lastStartID = 1; + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) { + T2OutObj *theOutObj = theArray->FindUnusedOutObj(); + if (theOutObj) + return theOutObj; + + lastStartID = theArray->mStartID; + } + + theArray = new T2OutObjArray(lastStartID + T2OutObjArray::kGroupSize); + if (theArray) { + Add(theArray); + return theArray->FindUnusedOutObj(); + } + + return NULL; } -void T2OutObjArrayList::DispatchIdle(T2TowerDoc*) { +void T2OutObjArrayList::DispatchIdle(T2TowerDoc* inDoc) { + LArrayIterator iterator(*this); + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) + theArray->DispatchIdle(inDoc, 0); } -T2OutObj* T2OutObjArrayList::GetIndOutObj(unsigned int) { +T2OutObj* T2OutObjArrayList::GetIndOutObj(unsigned int inIndex) { + int groupNum = inIndex / T2OutObjArray::kGroupSize; + int indexInGroup = inIndex % T2OutObjArray::kGroupSize; + + T2OutObjArray *theArray = GetItemAt(groupNum + 1); + if (theArray) + return theArray->GetIndexOutObj(indexInGroup); + else + return NULL; } -T2OutObj* T2OutObjArrayList::GetOutObjByID(unsigned int) { +T2OutObj* T2OutObjArrayList::GetOutObjByID(unsigned int inOutObjID) { + if (inOutObjID == 0) + return NULL; + else + return GetIndOutObj(inOutObjID - 1000); } -int T2OutObjArrayList::CalcMentenanceCost(T2TowerDoc*) const { +int T2OutObjArrayList::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int totalCost = 0; + LArrayIterator iterator(*this); + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) + totalCost += theArray->CalcMentenanceCost(inDoc); + + return totalCost; } -void T2OutObjArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2OutObjArrayList::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + unsigned int groupCount; + inArchive >> groupCount; + + RemoveItemsAt(GetCount(), 1); + + unsigned int startID = 1000; + for (unsigned int i = 0; i < groupCount; i++) { + T2OutObjArray *theArray = new T2OutObjArray(startID); + theArray->Read(inArchive, inDoc); + Add(theArray); + startID += T2OutObjArray::kGroupSize; + } } -void T2OutObjArrayList::Write(T2Archive&) { +void T2OutObjArrayList::Write(T2Archive& inArchive) { + unsigned int groupCount = GetCount(); + inArchive << groupCount; + + LArrayIterator iterator(*this); + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) + theArray->Write(inArchive); } diff --git a/src/T2DLL/T2OutObjArrayList.h b/src/T2DLL/T2OutObjArrayList.h index 137c182..a028bdd 100644 --- a/src/T2DLL/T2OutObjArrayList.h +++ b/src/T2DLL/T2OutObjArrayList.h @@ -1,20 +1,18 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2OutObjArrayList { +class AFX_EXT_CLASS T2OutObjArrayList : public LArray { public: T2OutObjArrayList(); virtual ~T2OutObjArrayList(); - void Add(T2OutObjArray*); - T2OutObjArray* GetItemAt(int); + void Add(T2OutObjArray* inArray); + T2OutObjArray* GetItemAt(int inIndex); T2OutObj* FindUnusedOutObj(); - void DispatchIdle(T2TowerDoc*); - T2OutObj* GetIndOutObj(unsigned int); - T2OutObj* GetOutObjByID(unsigned int); - int CalcMentenanceCost(T2TowerDoc*) const; - void Read(T2Archive&, T2TowerDoc*); - void Write(T2Archive&); - - T2OutObjArrayList(const T2OutObjArrayList&) {} - T2OutObjArrayList& operator=(const T2OutObjArrayList&) {} + void DispatchIdle(T2TowerDoc* inDoc); + T2OutObj* GetIndOutObj(unsigned int inIndex); + T2OutObj* GetOutObjByID(unsigned int inOutObjID); + int CalcMentenanceCost(T2TowerDoc* inDoc) const; + void Read(T2Archive& inArchive, T2TowerDoc* inDoc); + void Write(T2Archive& inArchive); }; diff --git a/src/T2DLL/T2OutObjInfoDialog.cpp b/src/T2DLL/T2OutObjInfoDialog.cpp index fe3fce4..54cc3c0 100644 --- a/src/T2DLL/T2OutObjInfoDialog.cpp +++ b/src/T2DLL/T2OutObjInfoDialog.cpp @@ -1,6 +1,11 @@ +#include "T2OutObj.h" #include "T2OutObjInfoDialog.h" -T2OutObjInfoDialog::T2OutObjInfoDialog(T2OutObj*) { +T2OutObjInfoDialog::T2OutObjInfoDialog(T2OutObj* inOutObj) + : T2InfoDialog(inOutObj) +{ + mOutObj = inOutObj; + mUnk100 = inOutObj->_38; } /*virtual*/ T2OutObjInfoDialog::~T2OutObjInfoDialog() { diff --git a/src/T2DLL/T2OutObjInfoDialog.h b/src/T2DLL/T2OutObjInfoDialog.h index e06a0c6..a13e21c 100644 --- a/src/T2DLL/T2OutObjInfoDialog.h +++ b/src/T2DLL/T2OutObjInfoDialog.h @@ -1,8 +1,13 @@ #pragma once #include "common.h" +#include "T2InfoDialog.h" -class T2OutObjInfoDialog { +class AFX_EXT_CLASS T2OutObjInfoDialog : public T2InfoDialog { public: - T2OutObjInfoDialog(T2OutObj*); + T2OutObjInfoDialog(T2OutObj* inOutObj); virtual ~T2OutObjInfoDialog(); + +protected: + T2OutObj *mOutObj; + int mUnk100; }; diff --git a/src/T2DLL/T2OuterObjDef.cpp b/src/T2DLL/T2OuterObjDef.cpp index cefb374..5c8ec2a 100644 --- a/src/T2DLL/T2OuterObjDef.cpp +++ b/src/T2DLL/T2OuterObjDef.cpp @@ -1,28 +1,111 @@ +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2InfoDialog.h" +#include "T2Message.h" +#include "T2OutObj.h" #include "T2OuterObjDef.h" +#include "T2OuterObjList.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" -T2OuterObjDef::T2OuterObjDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2ToolPlugin*) { +T2OuterObjDef::T2OuterObjDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2ToolPlugin* plugin) + : T2ToolDef(type, specifier, resFile, worldDef, plugin) +{ + mValiationCount = 1; } /*virtual*/ T2OuterObjDef::~T2OuterObjDef() { } -/*virtual*/ CURSORTYPE T2OuterObjDef::QueryCursor(T2TowerDoc*, POINT, CString&, RECT&, POINT&, int, unsigned int, int) { +/*virtual*/ CURSORTYPE T2OuterObjDef::QueryCursor(T2TowerDoc*, POINT inPt, CString& outStr, RECT& outRect, POINT& outPt, int factor, unsigned int, int) { + outStr = "Csr"; + + inPt.x -= ((mWidth * UT2Coordinate::UnitHSize(factor)) / 2 - UT2Coordinate::UnitHSize(factor) / 2); + inPt.y -= ((mHeight * UT2Coordinate::UnitVSize(factor)) / 2 - UT2Coordinate::UnitVSize(factor) / 2); + + UT2Coordinate::QDToUnit(inPt, factor); + + SetRect(&outRect, inPt.x, inPt.y, inPt.x + mWidth, inPt.y + mHeight); + outPt.x = outRect.left; + outPt.y = outRect.top; + UT2Coordinate::UnitToQD(outRect, factor, true); + + return CursorType_0; } -/*virtual*/ void T2OuterObjDef::DrawProc(T2HaveOutViewObject*, const RECT&, T2TowerDoc*) const { +/*virtual*/ void T2OuterObjDef::DrawProc(T2HaveOutViewObject* obj, const RECT& inRect, T2TowerDoc* inDoc) const { + RECT rect = ((T2OutObj *) obj)->_3C; + UT2Coordinate::UnitToQD(rect, inDoc->towerDoc_vf108(), true); + + int objectID = mImageObj->FindObject("View"); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); } -/*virtual*/ AREACHECKCODE T2OuterObjDef::AreaCheck(T2TowerDoc*, RECT&, unsigned int, int) { +/*virtual*/ AREACHECKCODE T2OuterObjDef::AreaCheck(T2TowerDoc* inDoc, RECT& rect, unsigned int arg1, int arg2) { + LArrayIterator iterator(*inDoc->mOuterObjList); + T2OutObj *theOutObj; + + while (iterator.Next(&theOutObj)) { + RECT intersect; + if (IntersectRect(&intersect, &theOutObj->_3C, &rect)) { + if (arg2) { + // "重ねて設置できません" - cannot be placed on top of each other + CString str = "\x8F\x64\x82\xCB\x82\xC4\x90\xDD\x92\x75\x82\xC5\x82\xAB\x82\xDC\x82\xB9\x81\xF1"; + (new T2Message)->ShowMessage(str); + } + return AreaCheckCode_0; + } + } + + for (int x = rect.left; x < rect.right; x++) { + for (int y = rect.top; y < rect.bottom; y++) { + if (!inDoc->mFloorInfo->GetTenant(y, x)) { + if (arg2) { + // "はみだして設置できません" - it cannot be installed as it protrudes + CString str = "\x82\xCD\x82\xDD\x82\xBE\x82\xB5\x82\xC4\x90\xDD\x92\x75\x82\xC5\x82\xAB\x82\xDC\x82\xB9\x82\xF1"; + (new T2Message)->ShowMessage(str); + } + return AreaCheckCode_0; + } + } + } + + if (rect.bottom > (inDoc->mWorldDef->mGroundLine - inDoc->mWorldDef->mLobbyHeight)) { + if (arg2) { + // "ここには設置できません" - cannot be installed here + CString str = "\x82\xB1\x82\xB1\x82\xC9\x82\xCD\x90\xDD\x92\x75\x82\xC5\x82\xAB\x82\xDC\x82\xB9\x82\xF1"; + (new T2Message)->ShowMessage(str); + } + return AreaCheckCode_0; + } + + return AreaCheckCode_1; } -/*virtual*/ T2InfoDialog* T2OuterObjDef::ShowInfoDialog(T2TowerDoc*, T2OutObj*) { +/*virtual*/ T2InfoDialog* T2OuterObjDef::ShowInfoDialog(T2TowerDoc* inDoc, T2OutObj* inOutObj) { + CRect windowRect; + AfxGetMainWnd()->GetWindowRect(windowRect); + + T2DLGTEMPLATE tmpl; + tmpl.pt = windowRect.CenterPoint(); + tmpl.moduleHandle = mModuleHandle; + tmpl.resID = GetInfoDialogID(inDoc, inOutObj); + + T2InfoDialog *theDialog = ConstructInfoDialog(inOutObj); + theDialog->Realize(this, &tmpl, inDoc, mImageObj, NULL, true, NULL, 0, true); + return theDialog; } /*virtual*/ int T2OuterObjDef::GetInfoDialogID(T2TowerDoc*, const T2OutObj*) const { + return 1000; } /*virtual*/ T2InfoDialog* T2OuterObjDef::ConstructInfoDialog(T2OutObj*) { + return NULL; } -/*virtual*/ PROCCODE T2OuterObjDef::DoDestructProc(T2TowerDoc*, T2HaveOutViewObject*, POINT, RECT&) { +/*virtual*/ PROCCODE T2OuterObjDef::DoDestructProc(T2TowerDoc* inDoc, T2HaveOutViewObject* inObj, POINT, RECT& outRect) { + outRect = ((T2OutObj *) inObj)->_3C; + return ((T2OutObj *) inObj)->Destruct(inDoc, outRect); } diff --git a/src/T2DLL/T2OuterObjDef.h b/src/T2DLL/T2OuterObjDef.h index 1ffea45..4cb0364 100644 --- a/src/T2DLL/T2OuterObjDef.h +++ b/src/T2DLL/T2OuterObjDef.h @@ -1,19 +1,21 @@ #pragma once #include "common.h" +#include "T2ToolDef.h" -class T2OuterObjDef { +class AFX_EXT_CLASS T2OuterObjDef : public T2ToolDef { public: - T2OuterObjDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2ToolPlugin*); + T2OuterObjDef(DWORD, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2ToolPlugin*); virtual ~T2OuterObjDef(); + virtual BOOL IsOutObj() { return true; } virtual CURSORTYPE QueryCursor(T2TowerDoc*, POINT, CString&, RECT&, POINT&, int, unsigned int, int); virtual void DrawProc(T2HaveOutViewObject*, const RECT&, T2TowerDoc*) const; + virtual PROCCODE DoDestructProc(T2TowerDoc*, T2HaveOutViewObject*, POINT, RECT&); + virtual void SetTenantDef(T2TenantDef* def) { mTenantDef = def; } virtual AREACHECKCODE AreaCheck(T2TowerDoc*, RECT&, unsigned int, int); virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*, T2OutObj*); virtual int GetInfoDialogID(T2TowerDoc*, const T2OutObj*) const; virtual T2InfoDialog* ConstructInfoDialog(T2OutObj*); - virtual PROCCODE DoDestructProc(T2TowerDoc*, T2HaveOutViewObject*, POINT, RECT&); - virtual int IsOutObj() {} - virtual void SetTenantDef(T2TenantDef*) {} - T2OuterObjDef& operator=(T2OuterObjDef&) {} +protected: + T2TenantDef *mTenantDef; }; diff --git a/src/T2DLL/T2OuterObjList.h b/src/T2DLL/T2OuterObjList.h index 0ee652f..529d3b9 100644 --- a/src/T2DLL/T2OuterObjList.h +++ b/src/T2DLL/T2OuterObjList.h @@ -1,11 +1,8 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2OuterObjList { +class AFX_EXT_CLASS T2OuterObjList : public LArray { public: ~T2OuterObjList(); - - T2OuterObjList() {} - T2OuterObjList(const T2OuterObjList&) {} - T2OuterObjList& operator=(const T2OuterObjList&) {} }; diff --git a/src/T2DLL/T2OuterObjPlugin.cpp b/src/T2DLL/T2OuterObjPlugin.cpp index cc33816..0ad3022 100644 --- a/src/T2DLL/T2OuterObjPlugin.cpp +++ b/src/T2DLL/T2OuterObjPlugin.cpp @@ -1,13 +1,30 @@ +#include "CResFile.h" +#include "T2OuterObjDef.h" #include "T2OuterObjPlugin.h" -T2OuterObjPlugin::T2OuterObjPlugin(unsigned long, T2PluginSpecifier&) { +T2OuterObjPlugin::T2OuterObjPlugin(DWORD inType, T2PluginSpecifier& inSpecifier) + : T2ToolPlugin(inType, inSpecifier) +{ } /*virtual*/ T2OuterObjPlugin::~T2OuterObjPlugin() { } -int T2OuterObjPlugin::LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*) { +BOOL T2OuterObjPlugin::LoadAllTemplatePlugin(T2WorldDef* inWorldDef, T2TemplatePluginDB* inDB) { + LoadT2OuterObjDef(inWorldDef); + return true; } -void T2OuterObjPlugin::LoadT2OuterObjDef(T2WorldDef*) { +typedef T2OuterObjDef *(MSVC_STDCALL* ConstructTemplatePluginType) (T2PluginSpecifier *, CResFile *, T2WorldDef *, T2OuterObjPlugin *); + +void T2OuterObjPlugin::LoadT2OuterObjDef(T2WorldDef* inWorldDef) { + ConstructTemplatePluginType theFunc = (ConstructTemplatePluginType) GetProcAddress((HMODULE) mModuleHandle, "ConstructTemplatePlugin"); +#line 25 + _ASSERT(theFunc); + + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, 'OODf'); + T2OuterObjDef *theDef = theFunc(&mSpecifier, &resFile, inWorldDef, this); + + mTemplatePlugin = theDef; } diff --git a/src/T2DLL/T2OuterObjPlugin.h b/src/T2DLL/T2OuterObjPlugin.h index 38b4c36..eb17310 100644 --- a/src/T2DLL/T2OuterObjPlugin.h +++ b/src/T2DLL/T2OuterObjPlugin.h @@ -1,14 +1,12 @@ #pragma once #include "common.h" +#include "T2ToolPlugin.h" -class T2OuterObjPlugin { +class AFX_EXT_CLASS T2OuterObjPlugin : public T2ToolPlugin { public: - T2OuterObjPlugin(unsigned long, T2PluginSpecifier&); + T2OuterObjPlugin(DWORD inType, T2PluginSpecifier& inSpecifier); virtual ~T2OuterObjPlugin(); - int LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*); + BOOL LoadAllTemplatePlugin(T2WorldDef* inWorldDef, T2TemplatePluginDB* inDB); private: - void LoadT2OuterObjDef(T2WorldDef*); - -public: - T2OuterObjPlugin& operator=(T2OuterObjPlugin&) {} + void LoadT2OuterObjDef(T2WorldDef* inWorldDef); }; diff --git a/src/T2DLL/T2OutsideInfo.cpp b/src/T2DLL/T2OutsideInfo.cpp index e90fb10..cf1f5c0 100644 --- a/src/T2DLL/T2OutsideInfo.cpp +++ b/src/T2DLL/T2OutsideInfo.cpp @@ -1,46 +1,168 @@ +#include "LArray.h" +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2OutObjArrayList.h" #include "T2OutsideInfo.h" -T2OutsideInfo::T2OutsideInfo(const T2FloorInfo&) { +T2OutsideInfo::T2OutsideInfo(const T2FloorInfo& inFloorInfo) + : mFloorInfo(inFloorInfo) +{ + UINT zero = 0; + mUnitInfo = new LArray(sizeof(UINT)); + mUnitInfo->InsertItemsAt(mFloorInfo.mHRange * mFloorInfo.mVRange, 1, &zero); + + mNextUnitInfo = -1; + SetRect(&mArea, 0, 0, 0, 0); } /*virtual*/ T2OutsideInfo::~T2OutsideInfo() { + if (mUnitInfo) + delete mUnitInfo; } void T2OutsideInfo::Reset() { + if (IsRectEmpty(&mArea)) { + mNextUnitInfo = -1; + } else { + mCurrentPt.x = mArea.left; + mCurrentPt.y = mArea.top; + + mCurrentPt.x--; + mNextUnitInfo = mFloorInfo.mHRange * mCurrentPt.y + mCurrentPt.x; + mCurrentOutObjID = 0; + } } -void T2OutsideInfo::SetArea(const RECT&) { +void T2OutsideInfo::SetArea(const RECT& inRect) { + IntersectRect(&mArea, &inRect, &mFloorInfo.mBuildArea); + Reset(); } POINT T2OutsideInfo::CurrentPt() const { + return mCurrentPt; } -unsigned int T2OutsideInfo::GetUnitInfo(int, int) const { +unsigned int T2OutsideInfo::GetUnitInfo(int inV, int inH) const { + unsigned int unitInfo = 0; + +#line 111 + _ASSERT((inV >= 0) && (inV < mFloorInfo.mVRange)); + _ASSERT((inH >= 0) && (inH < mFloorInfo.mHRange)); + + if (inV >= 0 && inV < mFloorInfo.mVRange && inH >= 0 && inH < mFloorInfo.mHRange) { + int index = mFloorInfo.mHRange * inV + inH; + mUnitInfo->FetchItemAt(index, &unitInfo); + } + + return unitInfo; } -T2OutObj* T2OutsideInfo::GetOutObj(int, int) const { +T2OutObj* T2OutsideInfo::GetOutObj(int inV, int inH) const { + unsigned int unitInfo = GetUnitInfo(inV, inH); + if (unitInfo) + return mFloorInfo.mOutObjArrayList->GetOutObjByID(unitInfo); + else + return NULL; } -void T2OutsideInfo::FillOutObjID(const RECT&, unsigned int) { +void T2OutsideInfo::FillOutObjID(const RECT& inRect, unsigned int inID) { + SetArea(inRect); + + int index; + while (NextIndex(index)) + mUnitInfo->AssignItemsAt(1, index, &inID); } -unsigned int T2OutsideInfo::GetOutObjID(int, int) const { +unsigned int T2OutsideInfo::GetOutObjID(int inV, int inH) const { + return GetUnitInfo(inV, inH); } -int T2OutsideInfo::CalcNextUnitInfo() { +BOOL T2OutsideInfo::CalcNextUnitInfo() { + BOOL result = true; + + if (!IsRectEmpty(&mArea)) { + if (mCurrentPt.y < mArea.bottom) { + mCurrentPt.x++; + if (mCurrentPt.x < mArea.right) { + mNextUnitInfo++; + } else { + mCurrentPt.x = mArea.left; + mCurrentPt.y++; + mNextUnitInfo += mFloorInfo.mHRange - (mArea.right - mArea.left) + 1; + + if (mCurrentPt.y >= mArea.bottom) + result = false; + } + } else { + result = false; + } + } else { + result = false; + } + + return result; } -int T2OutsideInfo::NextValue(unsigned int&) { +BOOL T2OutsideInfo::NextValue(unsigned int& outValue) { + BOOL result = true; + + if (CalcNextUnitInfo()) + mUnitInfo->FetchItemAt(mNextUnitInfo, &outValue); + else + result = false; + + return result; } -int T2OutsideInfo::NextIndex(int&) { +BOOL T2OutsideInfo::NextIndex(int& outIndex) { + BOOL result = true; + + if (CalcNextUnitInfo()) + outIndex = mNextUnitInfo; + else + result = false; + + return result; } -int T2OutsideInfo::NextOutObj(T2OutObj*&) { +BOOL T2OutsideInfo::NextOutObj(T2OutObj*& outOutObj) { + unsigned int id; + BOOL result; + + for (result = NextValue(id); result; result = NextValue(id)) { + if (id != mCurrentOutObjID) { + mCurrentOutObjID = id; + if (id != 0) { + outOutObj = mFloorInfo.mOutObjArrayList->GetOutObjByID(id); + break; + } + } + } + + return result; } -void T2OutsideInfo::Read(T2Archive&) { +void T2OutsideInfo::Read(T2Archive& inArchive) { + unsigned int count; + inArchive >> count; + + for (unsigned int i = 1; i <= count; i++) { + unsigned short v; + inArchive >> v; + + unsigned int unitInfo = v; + mUnitInfo->AssignItemsAt(1, i, &unitInfo); + } } -void T2OutsideInfo::Write(T2Archive&) { +void T2OutsideInfo::Write(T2Archive& inArchive) { + unsigned int count = mFloorInfo.mHRange * mFloorInfo.mVRange; + inArchive << count; + + for (unsigned int i = 1; i <= count; i++) { + unsigned int unitInfo; + mUnitInfo->FetchItemAt(i, &unitInfo); + + inArchive << (unsigned short) unitInfo; + } } diff --git a/src/T2DLL/T2OutsideInfo.h b/src/T2DLL/T2OutsideInfo.h index 0f87d43..0ad058f 100644 --- a/src/T2DLL/T2OutsideInfo.h +++ b/src/T2DLL/T2OutsideInfo.h @@ -1,29 +1,30 @@ #pragma once #include "common.h" -class T2OutsideInfo { +class AFX_EXT_CLASS T2OutsideInfo { public: - T2OutsideInfo(const T2FloorInfo&); + T2OutsideInfo(const T2FloorInfo& inFloorInfo); virtual ~T2OutsideInfo(); + void SetArea(const RECT& inRect); + void FillOutObjID(const RECT& inRect, unsigned int inID); + unsigned int GetOutObjID(int inV, int inH) const; + BOOL NextOutObj(T2OutObj*& outOutObj); + void Read(T2Archive& inArchive); + void Write(T2Archive& inArchive); + protected: void Reset(); -public: - void SetArea(const RECT&); -protected: POINT CurrentPt() const; - unsigned int GetUnitInfo(int, int) const; - T2OutObj* GetOutObj(int, int) const; -public: - void FillOutObjID(const RECT&, unsigned int); - unsigned int GetOutObjID(int, int) const; -protected: - int CalcNextUnitInfo(); - int NextValue(unsigned int&); - int NextIndex(int&); -public: - int NextOutObj(T2OutObj*&); - void Read(T2Archive&); - void Write(T2Archive&); + unsigned int GetUnitInfo(int inV, int inH) const; + T2OutObj* GetOutObj(int inV, int inH) const; + BOOL CalcNextUnitInfo(); + BOOL NextValue(unsigned int& outValue); + BOOL NextIndex(int& outIndex); - T2OutsideInfo(const T2OutsideInfo&) {} + LArray *mUnitInfo; + RECT mArea; + POINT mCurrentPt; + int mNextUnitInfo; + unsigned int mCurrentOutObjID; + const T2FloorInfo &mFloorInfo; }; diff --git a/src/T2DLL/T2PaletteAnime.h b/src/T2DLL/T2PaletteAnime.h index fd6ef53..778834d 100644 --- a/src/T2DLL/T2PaletteAnime.h +++ b/src/T2DLL/T2PaletteAnime.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2PaletteAnime { +class AFX_EXT_CLASS T2PaletteAnime { public: T2PaletteAnime(T2WorldDef*, T2DateTime*); virtual ~T2PaletteAnime(); @@ -28,7 +28,10 @@ public: mSECount = 0; } BOOL IsFine() const { - return (mSkyState == 3) || (mSkyState == 4); + BOOL result = true; + if (mSkyState == 3 || mSkyState == 4) + result = false; + return result; } BOOL IsSnow() const { return (mSkyState == 4); } BOOL IsShininDay() const { diff --git a/src/T2DLL/T2PaletteAnimeDef.cpp b/src/T2DLL/T2PaletteAnimeDef.cpp index 98628fc..ec58110 100644 --- a/src/T2DLL/T2PaletteAnimeDef.cpp +++ b/src/T2DLL/T2PaletteAnimeDef.cpp @@ -2,7 +2,7 @@ #include "GlobalFunc.h" #include "T2PaletteAnimeDef.h" -int DLL_EXPORT gCommonColor[20]; +int AFX_EXT_CLASS gCommonColor[20]; T2PaletteAnimeDef::T2PaletteAnimeDef(HINSTANCE instance, CResFile* resFile) { int i, j; diff --git a/src/T2DLL/T2PaletteAnimeDef.h b/src/T2DLL/T2PaletteAnimeDef.h index 981c872..dac16fc 100644 --- a/src/T2DLL/T2PaletteAnimeDef.h +++ b/src/T2DLL/T2PaletteAnimeDef.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2PaletteAnimeDef { +class AFX_EXT_CLASS T2PaletteAnimeDef { public: T2PaletteAnimeDef(HINSTANCE, CResFile*); ~T2PaletteAnimeDef(); diff --git a/src/T2DLL/T2People.cpp b/src/T2DLL/T2People.cpp index c434626..a238b1c 100644 --- a/src/T2DLL/T2People.cpp +++ b/src/T2DLL/T2People.cpp @@ -1,235 +1,1479 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2DateTime.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2Mover.h" +#include "T2Name.h" +#include "T2NameList.h" #include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleDef.h" +#include "T2PeopleInfoDialog.h" +#include "T2PeopleType.h" +#include "T2Pool.h" +#include "T2RegistedTenantDB.h" +#include "T2Request.h" +#include "T2ReturnStack.h" +#include "T2RouteNavigator.h" +#include "T2SilhouetteDef.h" +#include "T2TemplatePluginList.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" +#include "T2TrafficInfo.h" +#include "T2Transport.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2TowerMessage.h" +#include "T2WordDefArray.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" + +static T2People *someGlobalPeople; // 100e3e4c T2People::T2People() { + Initialize(); + mPeopleType = new T2PeopleType; } void T2People::Initialize() { + mSpecialFlag = 0; + mWalk = false; + mAttribute = 0; + mStress = 0; + m80 = 0; + mEstimate = 0; + mStatus = kStatus0; + mColor = 1; + mFiller = 0; + mPrevTenantType = 0; + mPeopleType = NULL; + mStyle = kPeopleStyle0; + for (unsigned int i = 0; i < 3; i++) + mSilhouetteDef[i] = NULL; } /*virtual*/ T2People::~T2People() { -} - -/*virtual*/ void T2People::SetUsed(int) { -} - -void T2People::Initialize(T2PeopleDef*, T2PeopleType*) { -} - -int T2People::IsMale() const { -} - -int T2People::IsGeneral() const { -} - -int T2People::IsSpecialColor() const { -} - -void T2People::ChangeStyle(int) { + if (mPeopleType) + delete mPeopleType; +} + +/*virtual*/ void T2People::SetUsed(BOOL used) { + if (!used) { + if (IsFavorite()) { + GetCurrentT2TowerDoc()->towerDoc_vf1C4(this, true); + } else if (IsNamed()) { + T2NameList *nameDB = GetCurrentT2TowerDoc()->mNameDB; + T2Name *name = nameDB->Search(this, false); + if (name) { + nameDB->RemoveName(name); + delete name; + } + } + } + + T2Matter::SetUsed(used); +} + +void T2People::Initialize(T2PeopleDef* peopleDef, T2PeopleType* peopleType) { + T2Matter::Initialize(peopleDef); + mSpecialFlag = 0; + mAttribute = peopleDef->GetAttribute(); + mStress = 0; + m80 = 0; + mEstimate = 300; + mStatus = kStatus0; + mColor = 1; + mFiller = 0; + mPrevTenantType = 0; + *mPeopleType = *peopleType; + mStyle = kPeopleStyle0; + SetSilhouetteDef(kPeopleStyle0, peopleDef->GetSilhouetteDef()); + SetSilhouetteDef(kPeopleStyle1, NULL); + SetSilhouetteDef(kPeopleStyle2, NULL); +} + +BOOL T2People::IsMale() const { + BOOL result = true; + if (mPeopleType) + result = mPeopleType->IsMale(); + return result; +} + +BOOL T2People::IsGeneral() const { + return ( + (mHomeTenant == 1 || mHomeTenant == 2) && + (mWorkTenant == 1 || mWorkTenant == 2) + ); +} + +BOOL T2People::IsSpecialColor() const { + return (mColor >= 11); +} + +void T2People::ChangeStyle(int style) { + if (style != mStyle && style >= kPeopleStyle0 && style <= kMaxPeopleStyle) { + mStyle = style; + ChangeSilhouette(); + } } int T2People::GetWidth() const { -} + int result = 1; + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; -int T2People::GetRouteType() { -} - -int T2People::CalcWaitPersonArea(T2FloorInfo*, RECT&) { -} + if (silhouetteDef) + result = silhouetteDef->GetWidth(); -void T2People::CalcWalkingSilhouetteArea(RECT&) const { + return result; } -unsigned int T2People::GetCurTenantID() const { -} +int T2People::GetRouteType() { + int result = kRouteType0; + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; -/*virtual*/ unsigned int T2People::Idle(T2TowerDoc*) { -} + if (!IsSetSpecialFlag(kSpecialFlag80)) { + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; + if (silhouetteDef) + result = silhouetteDef->GetRouteType(); + } else { + result = kRouteTypeNeg1; + } -void T2People::IdleWaitMover(T2TowerDoc*) { + return result; } -void T2People::MoveToTowerEntrance(T2TowerDoc*) { -} +BOOL T2People::CalcWaitPersonArea(T2FloorInfo* floorInfo, RECT& rect) { + BOOL result = false; -void T2People::MoveToLobby(T2TowerDoc*) { -} + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + if (request) + result = request->CalcPersonArea(this, rect); -int T2People::MoveToParking(T2TowerDoc*) { + return result; } -int T2People::MoveToSubway(T2TowerDoc*) { -} +void T2People::CalcWalkingSilhouetteArea(RECT& rect) const { + POINT curPosition = GetCurPosition(); + rect.top = curPosition.y; + rect.left = curPosition.x; + rect.bottom = curPosition.y + 1; + rect.right = curPosition.x + 2; -int T2People::MoveToShip(T2TowerDoc*) { + if (mWalkStyle == 0 && GetWidth() < 2) { + if (mDirection == 0) + rect.left++; + else + rect.right--; + } } -void T2People::MoveByEStair(T2TowerDoc*) { -} +unsigned int T2People::GetCurTenantID() const { + unsigned int tenantID = 0; + + if (mStatus == kStatus11) + tenantID = mCurrEquipID; + + return tenantID; +} + +/*virtual*/ unsigned int T2People::Idle(T2TowerDoc* towerDoc) { + unsigned int result = 0; + + switch (mStatus) { + case kStatus1: + if (IsStartTime(towerDoc->towerDoc_vf120()->GetRawMinutes()) && IsSetDestination()) { + towerDoc->towerDoc_vf130()->Leave(this); + MoveToTowerEntrance(towerDoc); + if (towerDoc->towerDoc_vf154()) + SetSpecialFlag(kSpecialFlag2); + } + break; + + case kStatus11: + if (IsStartTime(towerDoc->towerDoc_vf120()->GetRawMinutes())) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *tenant = floorInfo->GetTenant(mCurrEquipID); + if (tenant) { + if (IsSetDestination()) + tenant->LeaveTenant(towerDoc, this); + else + tenant->PushOutPeople(towerDoc, this); + } + } + break; + + case kStatus2: + case kStatus3: + case kStatus4: + SolveNoRoute(towerDoc); + break; + + case kStatus6: + IdleWaitMover(towerDoc); + break; + + case kStatus5: + { + int what; + if (someGlobalPeople == this) + what = 1; + + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) { + if (!IsRegistRequest(towerDoc)) + ChangeStatus(kStatus3); + } + } + + break; + } + + case kStatus10: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *tenant = floorInfo->GetTenant(mDstTenant); + if (tenant) + tenant->EnterTenant(towerDoc, this); + } + } + break; + + case kStatus12: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) + GoOutTower(towerDoc); + } + break; + + case kStatus13: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) + MoveByEStair(towerDoc); + } + break; + + case kStatus14: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) + ChangeStatus(kStatus15); + } + break; + } + + return result; +} + +void T2People::IdleWaitMover(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + BOOL changed = IncStress(5); + + if (mStress >= 300) { + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + request->Leave(this); + JumpToDestination(towerDoc); + IncEstimate(-50); + changed = false; + } + + if (changed) { + RECT rect; + CalcWaitPersonArea(floorInfo, rect); + towerDoc->GetTowerMainView()->tmv_vf128(rect, false); + } +} + +void T2People::MoveToTowerEntrance(T2TowerDoc* towerDoc) { + BOOL success = true; + + switch (mPeopleType->GetTransportType()) { + case kTransportLobbyLeft: + case kTransportLobbyRight: + MoveToLobby(towerDoc); + break; + case kTransportParking: + success = MoveToParking(towerDoc); + break; + case kTransportSubway: + success = MoveToSubway(towerDoc); + break; + case kTransportShip: + success = MoveToShip(towerDoc); + break; + } + + if (!success) { + IncEstimate(-100); + MoveToLobby(towerDoc); + } +} + +void T2People::MoveToLobby(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *lobby = floorInfo->GetTenant(1000); + + if (lobby) { + lobby->Enter(this); + + RECT rect; + lobby->GetEquipArea(rect); + mCurPosition.y = rect.bottom - 1; + + if (mPeopleType->GetTransportType() == kTransportLobbyLeft) { + mCurPosition.x = rect.left; + mDirection = 0; + } else { + mCurPosition.x = rect.right - 2; + mDirection = 1; + } + + ChangeStatus(kStatus2); + } +} + +BOOL T2People::MoveToParking(T2TowerDoc* towerDoc) { + BOOL result = false; + + T2RegistedTenantDB *registedTenantDB = towerDoc->towerDoc_vf174(); + if (registedTenantDB) { + T2Tenant *parking = NULL; + if (!IsGeneral()) + parking = registedTenantDB->FindHisParking(this); + if (!parking) + parking = registedTenantDB->FindEmptyParking(); + + if (parking) { + SetDestinationToReturn(); + parking->EnterTenant(towerDoc, this); + result = true; + } + } + + return result; +} + +BOOL T2People::MoveToSubway(T2TowerDoc* towerDoc) { + // TODO: T2MetroRailway + return 0; +} + +BOOL T2People::MoveToShip(T2TowerDoc* towerDoc) { + BOOL result = false; + + T2TowerEvent *towerEvent = towerDoc->mWorldDef->GetTowerEvent(); + T2DateTime *now = towerDoc->towerDoc_vf120(); + T2Transport *transport = towerEvent->GetCruise(); + if (transport) { + T2Transport *available = transport->GetAvailable(now); + if (available) { + available->Enter(this); + result = true; + } + } + + return result; +} + +void T2People::MoveByEStair(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + + if (floorInfo) { + T2Tenant *curTenant = floorInfo->GetTenant(mCurrEquipID); + T2Tenant *dstFloor = floorInfo->GetFloor(mCurrDestPos.y, mCurrDestPos.x); + + if (curTenant && dstFloor) { + RECT dstRect; + dstFloor->GetEquipArea(dstRect); + + if (mCurrDestPos.x == dstRect.left) + mDirection = 0; + else if (mCurrDestPos.x == (dstRect.right - 2)) + mDirection = 1; + + curTenant->Leave(this); + dstFloor->Enter(this); + } else { + ChangeStatus(kStatus3); + } + + if (IsWalk()) { + T2TowerMainView *towerMainView = towerDoc->GetTowerMainView(); + if (towerMainView) { + RECT rect; + SetRect(&rect, mCurPosition.x, mCurPosition.y, mCurPosition.x + 2, mCurPosition.y + 1); + towerMainView->tmv_vf128(rect, false); + } + } + } +} + +void T2People::SolveNoRoute(T2TowerDoc* towerDoc) { + BOOL changed = false; + + int what; + if (someGlobalPeople == this) + what = 0; + + if (!FindRoute(towerDoc)) { + changed = IncStress(30) && IsWalk(); + if (mStress >= 300) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + if (IsWalk()) { + // "道がないよ~" - there is no way + CString msg = "\x93\xB9\x82\xAA\x82\xC8\x82\xA2\x82\xE6\x81\x60"; + towerDoc->towerDoc_vf13C()->PeopleBalloonMessage(msg, this); + + RECT rect; + CalcWalkingSilhouetteArea(rect); + floorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + towerDoc->GetTowerMainView()->tmv_vf128(rect, false); + } + + T2Tenant *tenant = floorInfo->GetTenant(mCurrEquipID); + tenant->Leave(this); + JumpToDestination(towerDoc); + IncEstimate(-150); + } + } + + if (changed) { + RECT rect; + CalcWalkingSilhouetteArea(rect); + towerDoc->GetTowerMainView()->tmv_vf128(rect, false); + } +} + +BOOL T2People::FindRoute(T2TowerDoc* towerDoc) { + BOOL result = false; + int status = mStatus; + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + + if (floorInfo) { + mCurrDestPos = floorInfo->GetEntrancePt(mDstTenant); + if (mCurPosition.y >= 0) { + if (mCurrEquipID == floorInfo->GetEntranceFloorID(mDstTenant)) { + if (mDstTenant == 1 || mDstTenant == 2) + status = kStatus12; + else if (!IsSetSpecialFlag(kSpecialFlag40)) + status = kStatus10; + else + status = kStatus14; + result = true; + } else { + int routeType = GetRouteType(); + if (towerDoc->towerDoc_vf124()->GetNextRoute(mCurPosition, mCurrDestPos, routeType)) { + if (routeType >= kRouteType0) + status = kStatus5; + else + status = kStatus13; + result = true; + } + } + } + } + + if (result) { + if (mCurPosition.x < mCurrDestPos.x) + mDirection = 0; + else + mDirection = 1; + + ChangeStatus(status); + + T2TrafficInfo *trafficInfo = towerDoc->towerDoc_vf150(); + if (trafficInfo) + trafficInfo->Pass(mCurPosition, mCurrDestPos, 1); + } + + return result; +} + +void T2People::JumpToDestination(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + POINT entrancePt = floorInfo->GetEntrancePt(mDstTenant); + + mCurPosition = entrancePt; + T2Tenant *tenant = floorInfo->GetFloor(mCurPosition.y, mCurPosition.x); + tenant->Enter(this); +} + +void T2People::GoOutTower(T2TowerDoc* towerDoc) { + T2Tenant *tenant = towerDoc->towerDoc_vf12C()->GetTenant(mCurrEquipID); + if (tenant) + tenant->Leave(this); + + T2Pool *pool = towerDoc->towerDoc_vf130(); + pool->Enter(this); +} + +void T2People::IdleSearchedPerson(T2TowerDoc* towerDoc) { + BOOL flag = false; + int varC; + + if (someGlobalPeople == this) + varC = 2; + + switch (mStatus) { + case kStatus5: + case kStatus10: + case kStatus12: + case kStatus13: + case kStatus14: + if (mDirection != 1) + flag = WalkSearchedPersonRight(towerDoc); + else + flag = WalkSearchedPersonLeft(towerDoc); + break; + + case kStatus2: + { + T2TowerMainView *mainView = towerDoc->GetTowerMainView(); + RECT rect; + CalcWalkingSilhouetteArea(rect); + mainView->tmv_vf128(rect, false); + mStatus = kStatus3; + break; + } + } + + if (flag) { + switch (mStatus) { + case kStatus5: + if (!IsRegistRequest(towerDoc)) + ChangeStatus(kStatus4); + break; + + case kStatus10: + { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *tenant = floorInfo->GetTenant(mDstTenant); + if (tenant) + tenant->EnterTenant(towerDoc, this); + else + ChangeStatus(kStatus4); + break; + } + + case kStatus12: + GoOutTower(towerDoc); + break; + + case kStatus13: + MoveByEStair(towerDoc); + break; + + case kStatus14: + ChangeStatus(kStatus15); + break; + } + } +} + +BOOL T2People::WalkSearchedPersonRight(T2TowerDoc* towerDoc) { + BOOL result = false; + T2FloorInfo *floorInfo = towerDoc->mFloorInfo; + T2TowerMainView *towerMainView = towerDoc->GetTowerMainView(); + + RECT rect; + SetRect(&rect, mCurPosition.x, mCurPosition.y, mCurPosition.x + 2, mCurPosition.y + 1); + floorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + towerMainView->tmv_vf128(rect, false); + + int var = 2; + + if ((mCurPosition.x + var) > mCurrDestPos.x) { + if (mWalkStyle != 1) + ChangeWalkStyle(1); + else + ChangeWalkStyle(0); + } else { + var = mCurrDestPos.x - mCurPosition.x; + ChangeWalkStyle(0); + result = true; + } + + mCurPosition.x += var; + OffsetRect(&rect, var, 0); + towerMainView->tmv_vf128(rect, false); + + if (mCurPosition.y != (floorInfo->GetGroundLine() - 1)) + IncStress(var / 4); + + return result; +} + +BOOL T2People::WalkSearchedPersonLeft(T2TowerDoc* towerDoc) { + BOOL result = false; + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2TowerMainView *towerMainView = towerDoc->GetTowerMainView(); + + RECT rect; + SetRect(&rect, mCurPosition.x, mCurPosition.y, mCurPosition.x + 2, mCurPosition.y + 1); + floorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + towerMainView->tmv_vf128(rect, false); + + int var = 2; + + if ((mCurPosition.x - var) > mCurrDestPos.x) { + if (mWalkStyle != 1) + ChangeWalkStyle(1); + else + ChangeWalkStyle(0); + } else { + var = mCurPosition.x - mCurrDestPos.x; + ChangeWalkStyle(0); + result = true; + } + +#line 809 + _ASSERT(var >= 0); + + mCurPosition.x -= var; + OffsetRect(&rect, -var, 0); + towerMainView->tmv_vf128(rect, false); + + if (mCurPosition.y != (floorInfo->GetGroundLine() - 1)) + IncStress(var / 4); + + return result; +} + +BOOL T2People::IsReachDestination(int y) { + BOOL result = false; + int var = 16; -void T2People::SolveNoRoute(T2TowerDoc*) { -} + if (mDirection != 1) { + if ((mCurPosition.x + var) >= mCurrDestPos.x) { + var = mCurrDestPos.x - mCurPosition.x; + result = true; + } + mCurPosition.x += var; + } else { + if ((mCurPosition.x - var) <= mCurrDestPos.x) { + var = mCurPosition.x - mCurrDestPos.x; + result = true; + } + mCurPosition.x -= var; + } -int T2People::FindRoute(T2TowerDoc*) { -} + if (mCurPosition.y != y) + IncStress(var / 4); -void T2People::JumpToDestination(T2TowerDoc*) { + return result; } -void T2People::GoOutTower(T2TowerDoc*) { -} +BOOL T2People::IsRegistRequest(T2TowerDoc* towerDoc) { + BOOL result = false; -void T2People::IdleSearchedPerson(T2TowerDoc*) { -} + T2FloorInfo *floorInfo = towerDoc->mFloorInfo; + T2Request *request = floorInfo->GetRequest(mCurPosition.y, mCurPosition.x); + if (request) + result = request->Regist(towerDoc, this); -int T2People::WalkSearchedPersonRight(T2TowerDoc*) { + return result; } -int T2People::WalkSearchedPersonLeft(T2TowerDoc*) { +void T2People::ChangeStatus(int status) { + SetStatus(status); + ChangeSilhouette(); } -int T2People::IsReachDestination(int) { -} +void T2People::ChangeSilhouette() { + switch (mStatus) { + case kStatus7: + mWalkStyle = 1; + break; + case kStatus9: + mWalkStyle = 2; + break; + default: + mWalkStyle = 0; + } -int T2People::IsRegistRequest(T2TowerDoc*) { + SetSilhouette(); } -void T2People::ChangeStatus(int) { -} +void T2People::SetSilhouette() { + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; -void T2People::ChangeSilhouette() { + if (silhouetteDef) { + m18 = silhouetteDef->GetSilhouette((mDirection != -1) ? mDirection : 0, mWalkStyle); + } else { + m18 = 0; + } } -void T2People::SetSilhouette() { +void T2People::ChangeWalkStyle(int style) { + mWalkStyle = style; + SetSilhouette(); } -void T2People::ChangeWalkStyle(int) { -} +void T2People::SetAnimePattern(int fillerStart, int fillerRange, int hStart, int hRange) { + if (fillerRange > 1) + mFiller = fillerStart + rand() % fillerRange; + else + mFiller = fillerStart; -void T2People::SetAnimePattern(int, int, int, int) { + if (hRange > 1) + mCurPosition.x = hStart + rand() % hRange; + else + mCurPosition.x = hStart; } -int T2People::StopOnHisWay(T2TenantMemberDef*, int, int, RECT, int, int, int, int) { -} +BOOL T2People::StopOnHisWay(T2TenantMemberDef* tenantMemberDef, int econoType, int score, RECT rect, int bindTime, int tenantType, int tenantID, int startTime) { + BOOL result = false; + BOOL negScoreFlag = false; -int T2People::CalledInTenant(T2TenantMemberDef*, int, int, int, unsigned int, unsigned int) { -} + if (score < 0) { + score *= -1; + negScoreFlag = true; + } -int T2People::CalcFreeTime(unsigned int) { -} + if (mCurPosition.x > (rect.left - score) && mCurPosition.x < (rect.right + score)) { + if (negScoreFlag || CalcFreeTime(startTime) > bindTime) { + if (mPrevTenantType != tenantType) { + if (mPeopleType->CheckWithDemand(tenantMemberDef, econoType)) { + if (SetDestinationToReturn()) { + SetDestination(tenantID, startTime); + ChangeStatus(kStatus3); + result = true; + } + } + } + } + } -int T2People::IsGoToPool() const { + return result; } -void T2People::Return() { -} +BOOL T2People::CalledInTenant(T2TenantMemberDef* tenantMemberDef, int econoType, int bindTime, int tenantType, unsigned int tenantID, unsigned int startTime) { + BOOL result = false; -void T2People::SetDestinationToOutOfTower(T2TowerDoc*) { -} + if (CalcFreeTime(startTime) > bindTime && mPrevTenantType != tenantType) { +#line 992 + _ASSERT(mPeopleType); -void T2People::ChangeDestination(unsigned int, unsigned int) { -} + if (mPeopleType->CheckWithDemand(tenantMemberDef, econoType)) { + SetDestination(tenantID, startTime); + result = true; + } + } -int T2People::CalcCurrEstimate() const { + return result; } -void T2People::IncEstimate(int) { -} +int T2People::CalcFreeTime(unsigned int time) { + int result = 0; -void T2People::UpdateEstimation() { -} + if (IsSetDestination()) { + if (mStartTime > (int) time) + result = mStartTime - time; + } else if (IsSetReturn()) { + if (GetReturnTime() > time) + result = GetReturnTime() - time; + } else { + result = 10000; + } -int T2People::GetAverageStress() const { + return result; } -int T2People::IncStress(int) { +BOOL T2People::IsGoToPool() const { + return mDstTenant <= 2 && mDstTenant >= 1; } -int T2People::StressChanged() { -} +void T2People::Return() { + if (!SetReturnToDestination()) + SetDestination(mHomeTenant); -int T2People::IsVIP() const { + if (mStatus == kStatus10) + ChangeStatus(kStatus3); } -int T2People::IsNamed() const { -} +void T2People::SetDestinationToOutOfTower(T2TowerDoc* towerDoc) { + unsigned int tenantID = 1; -void T2People::SetColor(int) { -} + switch (mPeopleType->GetTransportType()) { + case kTransportParking: + { + T2RegistedTenantDB *registedTenantDB = towerDoc->towerDoc_vf174(); + if (registedTenantDB) { + T2Tenant *parking = NULL; + if (!IsGeneral()) { + parking = registedTenantDB->FindHisParking(this); + if (parking) + tenantID = parking->GetEquipID(); + } + } + } + } -void T2People::ClearColor() { + SetDestination(tenantID); } -/*virtual*/ void T2People::SetFavorite(int) { -} +void T2People::ChangeDestination(unsigned int tenant, unsigned int startTime) { + if (mStatus == kStatus10 || mStatus == kStatus12) + ChangeStatus(kStatus3); -int T2People::VIPEstimation() { + SetDestination(tenant, startTime); } -int T2People::SearchToilet(T2TowerDoc*) { -} +int T2People::CalcCurrEstimate() const { + int result; -void T2People::DrawSearchedPerson(T2TowerDoc*) { -} + if (m80 > 0) { + if (mStatus != kStatus11 && mStatus != kStatus1) { + result = (mEstimate * m80 + (300 - mStress)) / (m80 + 1); + } else { + result = (mEstimate * m80 - mStress) / m80; + } + } else { + result = mEstimate - mStress; + } -/*virtual*/ void T2People::Draw(T2TowerDoc*, const RECT&) { -} + if (result < 1) + result = 1; -void T2People::Draw(T2BitImage*, const RECT&) { + return result; } -void T2People::Draw(T2TowerDoc*, T2Equip*) { -} +void T2People::IncEstimate(int value) { + mEstimate += value; -void T2People::DrawAt(T2TowerDoc*, T2Equip*, POINT) { + if (mEstimate < 1) + mEstimate = 1; + else if (mEstimate > 300) + mEstimate = 300; } -void T2People::Duplicate(T2TowerDoc*) { -} +void T2People::UpdateEstimation() { + mEstimate = CalcCurrEstimate(); + mStress = 0; -void T2People::Remove(T2TowerDoc*, unsigned int) { -} + if (mStatus != kStatus11 && m80 < 4) + m80++; -void T2People::TenantRemoved(unsigned int) { + StressChanged(); } -void T2People::Interview(T2TowerDoc*) { +int T2People::GetAverageStress() const { + return 300 - CalcCurrEstimate(); } -int T2People::GetInterviewWords(T2TowerDoc*, CString&) { -} +BOOL T2People::IncStress(int value) { + mStress += value; -int T2People::IsMaru() const { -} + if (mStress > 300) + mStress = 300; + else if (mStress < 0) + mStress = 0; -int T2People::IsReggae() const { + return StressChanged(); } -void T2People::BreakoutEmergency(T2TowerDoc*) { -} +BOOL T2People::StressChanged() { + BOOL changed = false; -/*virtual*/ void T2People::LoadSelf(T2Archive&, T2TowerDoc*) { -} + if (!IsSpecialColor()) { + int col = mColor; -/*virtual*/ void T2People::SaveSelf(T2Archive&) { -} + T2PeopleDef *def = (T2PeopleDef *) GetMatterDef(); + if (!def) + return false; -void T2People::ResolveLink(T2PeopleArrayList*) { -} + if (mStress < def->GetStressBlueLimit()) + col = 1; + else if (mStress < def->GetStressYellowLimit()) + col = 7; + else if (mStress < (def->GetStressMax() - 10)) + col = 9; + else + col = 9; -/*virtual*/ T2InfoDialog* T2People::ShowInfoDialog(T2TowerDoc*) { -} + if (mColor != col) { + mColor = col; + changed = true; + } + } -void T2People::GetName(CString&) { + return changed; } -/*virtual*/ int T2People::GetSilhouetteRect(RECT&) { +BOOL T2People::IsVIP() const { + return (mColor == 14); } -/*virtual*/ void T2People::DrawHitMask(T2TowerDoc*) { +BOOL T2People::IsNamed() const { + return (mColor == 13); } -void T2People::ClearSpecialFlag(unsigned int) { +void T2People::SetColor(int col) { + if (col > mColor) + mColor = col; } -void T2People::SetSpecialFlag(unsigned int) { +void T2People::ClearColor() { + if (mColor < 11) { + mColor = 1; + } else if (!IsVIP()) { + if (IsSetSpecialFlag(kSpecialFlag20 | kSpecialFlag40)) + mColor = 11; + else + mColor = 1; + + if (IsFavorite()) + mColor = max(mColor, 13); + + if (IsSetSpecialFlag(kSpecialFlag4)) + mColor = max(mColor, 17); + + if (mColor == 1) + StressChanged(); + } +} + +/*virtual*/ void T2People::SetFavorite(BOOL fav) { + T2Object::SetFavorite(fav); + if (fav) + SetColor(13); + else + ClearColor(); +} + +BOOL T2People::VIPEstimation() { + BOOL result = false; + + if (IsVIP()) + result = CalcCurrEstimate() > 200; + + return result; +} + +BOOL T2People::SearchToilet(T2TowerDoc* towerDoc) { + BOOL result = false; + + if (SetDestinationToReturn()) { + T2RegistedTenantDB *registedTenantDB = towerDoc->towerDoc_vf174(); + T2RouteNavigator *routeNavigator = towerDoc->towerDoc_vf124(); + if (registedTenantDB && routeNavigator) { + int toiletStatus; + T2Tenant *toilet = registedTenantDB->SearchToilet(routeNavigator, mCurPosition, toiletStatus); + + if (toilet) { + toilet->IncReserveCount(1); + SetDestination(toilet->GetEquipID()); + SetStatus(kStatus3); + result = true; + } else { + SetReturnToDestination(); + T2TowerMessage *towerMessage = towerDoc->towerDoc_vf13C(); + if (towerMessage) { + // "トイレが混んでいる" - toilet is crowded + CString msg = "\x83\x67\x83\x43\x83\x8C\x82\xAA\x8D\xAC\x82\xF1\x82\xC5\x82\xA2\x82\xE9"; + + switch (toiletStatus) { + case -1: + // "トイレが近くにない" - there is no toilet nearby + msg = "\x83\x67\x83\x43\x83\x8C\x82\xAA\x8B\xDF\x82\xAD\x82\xC9\x82\xC8\x82\xA2"; + case -2: + towerMessage->PeopleBalloonMessage(msg, this); + ClearSpecialFlag(kSpecialFlag2); + IncEstimate(-30); + } + } + } + } + } + + return result; +} + +void T2People::DrawSearchedPerson(T2TowerDoc* towerDoc) { + switch (mStatus) { + case kStatus3: + case kStatus4: + case kStatus5: + case kStatus10: + case kStatus12: + case kStatus13: + case kStatus14: + case kStatus15: + { + RECT rect; + rect.top = mCurPosition.y; + rect.left = mCurPosition.x; + rect.bottom = rect.top + 1; + rect.right = rect.left + 2; + Draw(towerDoc, rect); + } + } +} + +/*virtual*/ void T2People::Draw(T2TowerDoc* towerDoc, const RECT& inRect) { + if (towerDoc->towerDoc_vf108() > 0) + return; + + if (m18 != -1) { + RECT rect = inRect; + UT2Coordinate::UnitToQD(rect, 0, true); + + int objectID = mSilhouetteDef[mStyle]->mImageObj->FindObject(m18); +#line 1380 + _ASSERT(objectID != -1); + + mSilhouetteDef[mStyle]->mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objectID, rect, towerDoc->towerDoc_vf108(), T2PaletteAnimeDef::GetCommonColor(mColor)); + } +} + +void T2People::Draw(T2BitImage* image, const RECT& inRect) { + int objectID = mSilhouetteDef[mStyle]->mImageObj->FindObject(0); +#line 1388 + _ASSERT(objectID != -1); + + RECT rect = inRect; + if (mSilhouetteDef[mStyle]->GetWidth() == 1) { + rect.left -= 8; + rect.right = rect.left + 16; + } + + mSilhouetteDef[mStyle]->mImageObj->DrawObject(image, objectID, rect, 0, T2PaletteAnimeDef::GetCommonColor(mColor)); +} + +void T2People::Draw(T2TowerDoc* towerDoc, T2Equip* equip) { + if (!IsSleep() && (equip->IsMover() || !((T2Tenant *) equip)->IsFloor())) { + RECT rect; + POINT curPosition = GetCurPosition(); + SetRect(&rect, curPosition.x, curPosition.y, curPosition.x + 2, curPosition.y + 1); + + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108()); + + int objectID = equip->GetEquipDef()->mImageObj->FindObject(1003, mFiller); + if (objectID >= 0) + equip->GetEquipDef()->mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objectID, rect, towerDoc->towerDoc_vf108()); + } +} + +void T2People::DrawAt(T2TowerDoc* towerDoc, T2Equip* equip, POINT pt) { + if (!IsSleep() && (equip->IsMover() || !((T2Tenant *) equip)->IsFloor())) { + CRect rect; + SetRect(&rect, 0, 0, 2, 1); + rect.OffsetRect(mCurPosition.x - pt.x, mCurPosition.y - pt.y); + + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108()); + + int objectID = equip->GetEquipDef()->mImageObj->FindObject(1003, mFiller); + if (objectID >= 0) + equip->GetEquipDef()->mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objectID, rect); + } +} + +void T2People::Duplicate(T2TowerDoc* towerDoc) { +#line 1430 + _ASSERT(towerDoc); + + T2Pool *pool = towerDoc->mPool; + if (pool) + pool->DuplicatePeople(mPeopleType); +} + +void T2People::Remove(T2TowerDoc* towerDoc, unsigned int id) { + BOOL flag = false; + + if (mHomeTenant == id) { + mHomeTenant = 1; + flag = true; + } + if (mWorkTenant == id) { + mWorkTenant = 1; + flag |= true; + } + + if (flag && IsGeneral() && GetStatus() == kStatus1) { + T2Pool *pool = towerDoc->towerDoc_vf130(); + if (pool) + pool->RemovePeople(this); + } +} + +void T2People::TenantRemoved(unsigned int id) { + if (GetDestination() == id) { + Return(); + IncEstimate(-100); + } else if (RemoveReturn(id)) { + IncEstimate(-200); + } +} + +void T2People::Interview(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + if (floorInfo) { + CString text; + if (GetInterviewWords(towerDoc, text) && text.GetLength() != 0) { + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = 0; + rect.bottom = 0; + + if (mStatus == kStatus6) { + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + if (request) + request->CalcPersonArea(this, rect); + } else { + CalcWalkingSilhouetteArea(rect); + } + + if (!IsRectEmpty(&rect)) + towerDoc->mTowerMessage->ObjectBalloonMessage(text, rect); + } + } +} + +BOOL T2People::GetInterviewWords(T2TowerDoc* towerDoc, CString& outStr) { + OptionEvent11Data eventData; + + eventData.str = &outStr; + eventData.people = this; + if (!DispatchOptionEvent(OptionEventType_11, &eventData)) + return outStr != ""; + + unsigned int flags = 0; + + T2PeopleDef *peopleDef = (T2PeopleDef *) GetMatterDef(); + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *dstTenant = floorInfo->GetTenant(mDstTenant); + T2Tenant *workTenant = floorInfo->GetTenant(GetWorkTenant()); + + T2EquipDef *equipDef = NULL; + if (mDstTenant != 1) { + if (dstTenant) { + equipDef = dstTenant->GetEquipDef(); + if (dstTenant == workTenant) + flags |= 1; + } + } else { + flags |= 8; + equipDef = towerDoc->mTenantTemplates->FindTenantDef(mPrevTenantType); + if (workTenant && workTenant->GetEquipDef() == equipDef) + flags |= 1; + } + + if (mStyle == kPeopleStyle1) + flags |= 2; + else if (mStyle == kPeopleStyle2) + flags |= 4; + + unsigned int level = 0; + if (IsVIP()) { + if (mDstTenant == 1 && VIPEstimation()) + flags |= 0x10; + + switch (towerDoc->towerDoc_vf138()) { + case 1: + level = 3; + break; + case 2: + level = 4; + break; + case 3: + level = 5; + break; + } + } else if (IsMaru()) { + level = 6; + flags &= ~1; + } else if (IsReggae()) { + level = 7; + } else if (IsSetSpecialFlag(kSpecialFlag4) && (!dstTenant || dstTenant->GetRegistID() != kTenantRegistID4)) { + level = 1; + } else if (IsSetSpecialFlag(kSpecialFlag2) && (!dstTenant || dstTenant->GetRegistID() != kTenantRegistID7)) { + level = 2; + } + + T2WordDefArray *wordDefArray = NULL; + + if (level != 0) { + wordDefArray = towerDoc->towerDoc_vf170()->mWordDefArray; + } else { + if (mStatus == kStatus6 && peopleDef && mStress >= peopleDef->GetStressYellowLimit()) { + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + if (request) { + unsigned int moverID = request->GetMoverID(); + if (moverID) { + T2Mover *mover = floorInfo->GetMover(moverID); + equipDef = mover ? mover->GetEquipDef() : NULL; + } + } + } + + wordDefArray = equipDef ? equipDef->mWordDefArray : NULL; + } + + if (wordDefArray) + wordDefArray->GetWords(GetSex(), GetAge(), flags, level, outStr); + + eventData.str = &outStr; + eventData.people = this; + DispatchOptionEvent(OptionEventType_12, &eventData); + + return outStr != ""; +} + +BOOL T2People::IsMaru() const { + return mMatterDef && (mMatterDef->mSortKey == 4); +} + +BOOL T2People::IsReggae() const { + return mMatterDef && (mMatterDef->mSortKey == 5); +} + +void T2People::BreakoutEmergency(T2TowerDoc* towerDoc) { + mReturnStack->Init(); + switch (mStatus) { + case kStatus5: + case kStatus10: + ChangeStatus(kStatus3); + case kStatus2: + case kStatus3: + case kStatus4: + case kStatus8: + SetSpecialFlag(kSpecialFlag80); + SetDestination(1); + break; + case kStatus1: + if (IsGeneral()) + towerDoc->towerDoc_vf130()->RemovePeople(this); + break; + } +} + +/*virtual*/ void T2People::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + DWORD peopleCode; + archive >> peopleCode; + + T2Matter::LoadSelf(archive, towerDoc); + + if (IsUsed()) { + unsigned char uc; + short s; + unsigned short us; + + archive >> uc; + mSpecialFlag = uc; + + archive >> uc; + mWalk = (uc != 0); + + archive >> s; + mStress = s; + + archive >> us; + m80 = us; + + archive >> s; + mEstimate = s; + archive >> s; + mColor = s; + archive >> s; + mFiller = s; + archive >> s; + mPrevTenantType = s; + + archive >> mStyle; + + DWORD peopleTypeCode; + archive >> peopleTypeCode; + + if (peopleTypeCode == 'PTYP') { + mPeopleType->Read(archive); + mMatterDef = towerDoc->mPeopleTemplates->FindPeopleDef(mPeopleType->GetSilhouetteType()); + mAttribute = mMatterDef->GetAttribute(); + } + + for (int i = 0; i < 3; i++) { + short silhouetteType; + archive >> silhouetteType; + if (silhouetteType) + mSilhouetteDef[i] = towerDoc->mSilhouetteTemplates->FindSilhouette(silhouetteType); + else + mSilhouetteDef[i] = NULL; + } + + ChangeSilhouette(); + + DWORD linkCode; + archive >> linkCode; +#line 1727 + _ASSERT(linkCode == 'pLk>'); + + unsigned int linkID; + + archive >> linkID; + if (linkID) + mNext = (CLink *) linkID; + + archive >> linkID; + if (linkID) + mPrev = (CLink *) linkID; + } +} + +/*virtual*/ void T2People::SaveSelf(T2Archive& archive) { + DWORD peopleCode = '<PP>'; + archive << peopleCode; + + T2Matter::SaveSelf(archive); + + if (IsUsed()) { + unsigned char uc; + short s; + unsigned short us; + + uc = mSpecialFlag; + archive << uc; + + uc = (mWalk != 0); + archive << uc; + + s = mStress; + archive << s; + + us = m80; + archive << us; + + s = mEstimate; + archive << s; + s = mColor; + archive << s; + s = mFiller; + archive << s; + s = mPrevTenantType; + archive << s; + + archive << mStyle; + + DWORD peopleTypeCode; + if (mPeopleType) + peopleTypeCode = 'PTYP'; + else + peopleTypeCode = 'xPTP'; + archive << peopleTypeCode; + + if (peopleTypeCode == 'PTYP') + mPeopleType->Write(archive); + + for (int i = 0; i < 3; i++) { + short silhouetteType = 0; + if (mSilhouetteDef[i]) + silhouetteType = mSilhouetteDef[i]->GetSilhouetteType(); + archive << silhouetteType; + } + + DWORD linkCode = 'pLk>'; + archive << linkCode; + + unsigned int emptyLinkID = 0; + T2People *linkPeople; + + if (mNext) { + linkPeople = (T2People *) mNext; + unsigned int linkID = linkPeople->GetPeopleID(); + archive << linkID; + } else { + archive << emptyLinkID; + } + + if (mPrev) { + linkPeople = (T2People *) mPrev; + unsigned int linkID = linkPeople->GetPeopleID(); + archive << linkID; + } else { + archive << emptyLinkID; + } + } +} + +void T2People::ResolveLink(T2PeopleArrayList* list) { + if (mNext) { + T2People *people = list->FindPeople((unsigned int) mNext); + mNext = people; + } + if (mPrev) { + T2People *people = list->FindPeople((unsigned int) mPrev); + mPrev = people; + } +} + +/*virtual*/ T2InfoDialog* T2People::ShowInfoDialog(T2TowerDoc* towerDoc) { + CRect rect; + AfxGetMainWnd()->GetWindowRect(rect); + + T2DLGTEMPLATE tmpl; + tmpl.pt = rect.CenterPoint(); + tmpl.moduleHandle = GetWorldModuleHandle(); + tmpl.resID = 2000; + + T2PeopleInfoDialog *dialog = new T2PeopleInfoDialog(this); + dialog->Realize(this, &tmpl, towerDoc, NULL, NULL, true, NULL, 0, true); + someGlobalPeople = this; + + return dialog; +} + +void T2People::GetName(CString& outStr) { + mSilhouetteDef[mStyle]->GetName(outStr); +} + +/*virtual*/ BOOL T2People::GetSilhouetteRect(RECT& outRect) { + if ( + (mStatus == kStatus3) || + (mStatus == kStatus5) || + (mStatus == kStatus10) || + (mStatus == kStatus12) || + (mStatus == kStatus13) || + (mStatus == kStatus4) || + (mStatus == kStatus14) || + (mStatus == kStatus15) + ) + { + if (GetDirection() == 0) { + outRect.left = mCurPosition.x + (2 - GetWidth()); + outRect.top = mCurPosition.y; + outRect.right = outRect.left + GetWidth(); + outRect.bottom = outRect.top + 1; + } else { + outRect.left = mCurPosition.x; + outRect.top = mCurPosition.y; + outRect.right = outRect.left + GetWidth(); + outRect.bottom = outRect.top + 1; + } + return true; + } + + return false; +} + +/*virtual*/ void T2People::DrawHitMask(T2TowerDoc* towerDoc) { + if (IsWalk()) { + CRect rect; + if (GetSilhouetteRect(rect)) { + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108()); + towerDoc->towerDoc_vf10C()->FillRect(rect, 1); + } + } +} + +void T2People::ClearSpecialFlag(unsigned int flag) { + mSpecialFlag &= ~flag; + if ((flag & kSpecialFlag4) > 0) + mColor = 1; +} + +void T2People::SetSpecialFlag(unsigned int flag) { + mSpecialFlag |= flag; + if ((flag & kSpecialFlag4) > 0) + mColor = 17; } diff --git a/src/T2DLL/T2People.h b/src/T2DLL/T2People.h index f02058b..d1c99ec 100644 --- a/src/T2DLL/T2People.h +++ b/src/T2DLL/T2People.h @@ -1,78 +1,72 @@ #pragma once #include "common.h" +#include "CLink.h" +#include "T2Matter.h" +#include "T2PeopleType.h" -class T2People { +enum { + kSpecialFlag1 = 1, + kSpecialFlag2 = 2, // needs to use the toilet + kSpecialFlag4 = 4, + kSpecialFlag8 = 8, + kSpecialFlag10 = 0x10, + kSpecialFlag20 = 0x20, + kSpecialFlag40 = 0x40, + kSpecialFlag80 = 0x80, +}; + +enum { + kPeopleStyle0 = 0, + kPeopleStyle1 = 1, + kPeopleStyle2 = 2, + kMaxPeopleStyle = 2 +}; + +class AFX_EXT_CLASS T2People : public CLink, public T2Matter { public: T2People(); -private: - void Initialize(); -public: virtual ~T2People(); - virtual void SetUsed(int); + virtual void SetUsed(BOOL); + virtual unsigned int Idle(T2TowerDoc*); + virtual void SetFavorite(BOOL); + virtual void Draw(T2TowerDoc*, const RECT&); + virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*); + virtual void DrawHitMask(T2TowerDoc*); + virtual BOOL GetSilhouetteRect(RECT&); + void Initialize(T2PeopleDef*, T2PeopleType*); - int IsMale() const; - int IsGeneral() const; - int IsSpecialColor() const; + BOOL IsMale() const; + BOOL IsGeneral() const; + BOOL IsSpecialColor() const; void ChangeStyle(int); int GetWidth() const; int GetRouteType(); - int CalcWaitPersonArea(T2FloorInfo*, RECT&); + BOOL CalcWaitPersonArea(T2FloorInfo*, RECT&); void CalcWalkingSilhouetteArea(RECT&) const; unsigned int GetCurTenantID() const; - virtual unsigned int Idle(T2TowerDoc*); -protected: - void IdleWaitMover(T2TowerDoc*); - void MoveToTowerEntrance(T2TowerDoc*); - void MoveToLobby(T2TowerDoc*); - int MoveToParking(T2TowerDoc*); - int MoveToSubway(T2TowerDoc*); - int MoveToShip(T2TowerDoc*); - void MoveByEStair(T2TowerDoc*); - void SolveNoRoute(T2TowerDoc*); - int FindRoute(T2TowerDoc*); - void JumpToDestination(T2TowerDoc*); -public: void GoOutTower(T2TowerDoc*); void IdleSearchedPerson(T2TowerDoc*); -protected: - int WalkSearchedPersonRight(T2TowerDoc*); - int WalkSearchedPersonLeft(T2TowerDoc*); - int IsReachDestination(int); - int IsRegistRequest(T2TowerDoc*); -public: void ChangeStatus(int); -protected: - void ChangeSilhouette(); - void SetSilhouette(); -public: void ChangeWalkStyle(int); - void SetAnimePattern(int, int, int, int); - int StopOnHisWay(T2TenantMemberDef*, int, int, RECT, int, int, int, int); - int CalledInTenant(T2TenantMemberDef*, int, int, int, unsigned int, unsigned int); -protected: - int CalcFreeTime(unsigned int); -public: - int IsGoToPool() const; + void SetAnimePattern(int fillerStart, int fillerRange, int hStart, int hRange); + BOOL StopOnHisWay(T2TenantMemberDef* tenantMemberDef, int econoType, int score, RECT rect, int bindTime, int tenantType, int tenantID, int startTime); + BOOL CalledInTenant(T2TenantMemberDef* tenantMemberDef, int econoType, int bindTime, int tenantType, unsigned int tenantID, unsigned int startTime); + BOOL IsGoToPool() const; void Return(); void SetDestinationToOutOfTower(T2TowerDoc*); - void ChangeDestination(unsigned int, unsigned int); + void ChangeDestination(unsigned int tenantID, unsigned int startTime = 0); int CalcCurrEstimate() const; void IncEstimate(int); void UpdateEstimation(); int GetAverageStress() const; - int IncStress(int); -protected: - int StressChanged(); -public: - int IsVIP() const; - int IsNamed() const; + BOOL IncStress(int); + BOOL IsVIP() const; + BOOL IsNamed() const; void SetColor(int); void ClearColor(); - virtual void SetFavorite(int); - int VIPEstimation(); - int SearchToilet(T2TowerDoc*); + BOOL VIPEstimation(); + BOOL SearchToilet(T2TowerDoc*); void DrawSearchedPerson(T2TowerDoc*); - virtual void Draw(T2TowerDoc*, const RECT&); void Draw(T2BitImage*, const RECT&); void Draw(T2TowerDoc*, T2Equip*); void DrawAt(T2TowerDoc*, T2Equip*, POINT); @@ -80,43 +74,99 @@ public: void Remove(T2TowerDoc*, unsigned int); void TenantRemoved(unsigned int); void Interview(T2TowerDoc*); - int GetInterviewWords(T2TowerDoc*, CString&); - int IsMaru() const; - int IsReggae() const; + BOOL GetInterviewWords(T2TowerDoc*, CString&); + BOOL IsMaru() const; + BOOL IsReggae() const; void BreakoutEmergency(T2TowerDoc*); -protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); -public: void ResolveLink(T2PeopleArrayList*); - virtual T2InfoDialog* ShowInfoDialog(T2TowerDoc*); void GetName(CString&); - virtual int GetSilhouetteRect(RECT&); - virtual void DrawHitMask(T2TowerDoc*); void ClearSpecialFlag(unsigned int); void SetSpecialFlag(unsigned int); - unsigned int GetPeopleID() { return 0; } - T2PeopleType* GetPeopleType() const { return 0; } - unsigned int GetEconoType() { return 0; } - int IsFatSilhouette() const { return 0; } - int IsInTower() const { return 0; } - int GetColor() const { return 0; } - int IsSetSpecialFlag(unsigned int) const { return 0; } - void SetToSleep() {} - int IsSleep() const { return 0; } - int IsWalk() const { return 0; } - void SetWalk(int) {} - void SetFiller(int) {} - void SetStyle(int) {} - int GetStyle() const { return 0; } - void SetSilhouetteDef(int, T2SilhouetteDef*) {} - void SetPeopleType(T2PeopleType*) {} - void SetPrevTenantType(int) {} - int GetPrevTenantType() const { return 0; } - void InitStress() {} - int GetStress() const { return 0; } - int GetEstimate() const { return 0; } - unsigned int GetAge() const { return 0; } - unsigned int GetSex() const { return 0; } + unsigned int GetPeopleID() { return GetMatterID(); } + T2PeopleType* GetPeopleType() const { return mPeopleType; } + unsigned int GetEconoType() { return mPeopleType->GetEconoType(); } + BOOL IsFatSilhouette() const { return (mAttribute & 2) != 0; } + BOOL IsInTower() const { + return (mStatus != kStatus1) && (mStatus != kStatus16) && (mStatus != kStatus0); + } + int GetColor() const { return mColor; } + BOOL IsSetSpecialFlag(unsigned int flag) const { return (mSpecialFlag & flag) == flag; } + void SetToSleep() { mFiller = -1; } + BOOL IsSleep() const { return (mFiller == -1); } + BOOL IsWalk() const { return mWalk || IsSetSpecialFlag(kSpecialFlag20); } + void SetWalk(BOOL v) { mWalk = v; } + void SetFiller(int v) { mFiller = v; } + void SetStyle(int v) { mStyle = v; } + int GetStyle() const { return mStyle; } + void SetSilhouetteDef(int i, T2SilhouetteDef* def) { mSilhouetteDef[i] = def; } + void SetPeopleType(T2PeopleType* type) { *mPeopleType = *type; } + void SetPrevTenantType(int v) { mPrevTenantType = v; } + int GetPrevTenantType() const { return mPrevTenantType; } + void InitStress() { mStress = 0; } + int GetStress() const { return mStress; } + int GetEstimate() const { return mEstimate; } + unsigned int GetAge() const { + unsigned int age = 0; + if (mPeopleType) + age = mPeopleType->GetAge(); + return age; + } + unsigned int GetSex() const { + unsigned int sex = 1; + if (mPeopleType) + sex = !mPeopleType->IsMale(); + return sex; + } + +protected: + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); + + void IdleWaitMover(T2TowerDoc*); + void MoveToTowerEntrance(T2TowerDoc*); + void MoveToLobby(T2TowerDoc*); + BOOL MoveToParking(T2TowerDoc*); + BOOL MoveToSubway(T2TowerDoc*); + BOOL MoveToShip(T2TowerDoc*); + void MoveByEStair(T2TowerDoc*); + void SolveNoRoute(T2TowerDoc*); + BOOL FindRoute(T2TowerDoc*); + void JumpToDestination(T2TowerDoc*); + BOOL WalkSearchedPersonRight(T2TowerDoc*); + BOOL WalkSearchedPersonLeft(T2TowerDoc*); + BOOL IsReachDestination(int y); + BOOL IsRegistRequest(T2TowerDoc*); + void ChangeSilhouette(); + void SetSilhouette(); + int CalcFreeTime(unsigned int); + BOOL StressChanged(); + + friend class T2ElevatorModule; + friend class T2FireBurning; + friend class T2Guardman; + friend class T2Maru_Reggae; + friend class T2MoverModule; + friend class T2PeopleArray; + friend class T2SilhouettePane; + friend class T2StairModule; + friend class T2Tenant; + friend class T2VisitVIP; + + unsigned int mAttribute; + int mColor; + int mFiller; + int mPrevTenantType; + int m70; + BOOL mWalk; + unsigned int mSpecialFlag; + int mStress; + int m80; + int mEstimate; + T2PeopleType *mPeopleType; + int mStyle; + T2SilhouetteDef *mSilhouetteDef[3]; + +private: + void Initialize(); }; diff --git a/src/T2DLL/T2PeopleAnimeDef.cpp b/src/T2DLL/T2PeopleAnimeDef.cpp index 59e8ace..7297df0 100644 --- a/src/T2DLL/T2PeopleAnimeDef.cpp +++ b/src/T2DLL/T2PeopleAnimeDef.cpp @@ -1,25 +1,65 @@ +#include "CResFile.h" +#include "T2People.h" #include "T2PeopleAnimeDef.h" +#include "UT2Utils.h" -T2PeopleAnimeDef::T2PeopleAnimeDef(CResFile&) { +T2PeopleAnimeDef::T2PeopleAnimeDef(CResFile& resFile) { + Init(); + + resFile >> m4; + resFile >> m8; + resFile >> mNumOfElems; + + mElems = new T2PeopleAnimeDefElem[mNumOfElems]; + for (int i = 0; i < mNumOfElems; i++) + mElems[i].Initialize(resFile); } void T2PeopleAnimeDef::Init() { + m4 = 0; + m8 = 0; + mNumOfElems = 0; + mElems = NULL; } /*virtual*/ T2PeopleAnimeDef::~T2PeopleAnimeDef() { + if (mElems) + delete[] mElems; } -void T2PeopleAnimeDef::Set(T2People*, int, int) { +void T2PeopleAnimeDef::Set(T2People* people, int h, int inIndex) { + if (inIndex < mNumOfElems) { + int index = inIndex; + if (inIndex < 0) + index = UT2Utils::Randomize(mNumOfElems); + mElems[index].Set(people, h); + } } + + T2PeopleAnimeDefElem::T2PeopleAnimeDefElem() { + mFillerStart = 0; + mFillerRange = 0; + mHStart = 0; + mHRange = 0; } /*virtual*/ T2PeopleAnimeDefElem::~T2PeopleAnimeDefElem() { } -void T2PeopleAnimeDefElem::Initialize(CResFile&) { +void T2PeopleAnimeDefElem::Initialize(CResFile& resFile) { + resFile >> mFillerStart; + resFile >> mFillerRange; + resFile >> mHStart; + resFile >> mHRange; } -void T2PeopleAnimeDefElem::Set(T2People*, int) { +void T2PeopleAnimeDefElem::Set(T2People* people, int h) { + if (mFillerStart >= 0) { + people->SetFiller(mFillerStart + UT2Utils::Randomize(mFillerRange)); + people->MoveHTo(h + mHStart + UT2Utils::Randomize(mHRange)); + } else { + people->SetFiller(-1); + } } diff --git a/src/T2DLL/T2PeopleAnimeDef.h b/src/T2DLL/T2PeopleAnimeDef.h index e3c98ad..f83a77b 100644 --- a/src/T2DLL/T2PeopleAnimeDef.h +++ b/src/T2DLL/T2PeopleAnimeDef.h @@ -1,25 +1,32 @@ #pragma once #include "common.h" -class T2PeopleAnimeDef { +class AFX_EXT_CLASS T2PeopleAnimeDef { public: - T2PeopleAnimeDef(CResFile&); + T2PeopleAnimeDef(CResFile& resFile); + virtual ~T2PeopleAnimeDef(); + void Set(T2People* people, int h, int inIndex); + private: void Init(); -public: - virtual ~T2PeopleAnimeDef(); - void Set(T2People*, int, int); - T2PeopleAnimeDef(const T2PeopleAnimeDef&) {} - T2PeopleAnimeDef& operator=(const T2PeopleAnimeDef&) {} + int m4; + int m8; + int mNumOfElems; + int m10; + T2PeopleAnimeDefElem *mElems; }; -class T2PeopleAnimeDefElem { + +class AFX_EXT_CLASS T2PeopleAnimeDefElem { public: T2PeopleAnimeDefElem(); virtual ~T2PeopleAnimeDefElem(); - void Initialize(CResFile&); - void Set(T2People*, int); + void Initialize(CResFile& resFile); + void Set(T2People* people, int h); - T2PeopleAnimeDefElem(const T2PeopleAnimeDefElem&) {} - T2PeopleAnimeDefElem& operator=(const T2PeopleAnimeDefElem&) {} +private: + int mFillerStart; + int mFillerRange; + int mHStart; + int mHRange; }; diff --git a/src/T2DLL/T2PeopleArray.cpp b/src/T2DLL/T2PeopleArray.cpp index 53a56e9..91edc64 100644 --- a/src/T2DLL/T2PeopleArray.cpp +++ b/src/T2DLL/T2PeopleArray.cpp @@ -1,40 +1,123 @@ #include "T2PeopleArray.h" +#include "T2TowerDoc.h" -T2PeopleArray::T2PeopleArray(unsigned int) { +T2PeopleArray::T2PeopleArray(unsigned int startID) + : T2ObjectArray(startID) +{ + for (unsigned int i = 0; i < 256; i++) + mPeople[i].mMatterID = mStartID + i; } -T2People* T2PeopleArray::FindPeople(unsigned int) { +T2People* T2PeopleArray::FindPeople(unsigned int peopleID) { + unsigned int firstID = mPeople[0].GetPeopleID(); + + if (firstID > peopleID || (firstID + 256) < peopleID) + return NULL; + + for (int i = 0; i < 256; i++) { + if (mPeople[i].GetPeopleID() == peopleID) + return &mPeople[i]; + } + + return NULL; } -void T2PeopleArray::ResolveLink(T2PeopleArrayList*) { +void T2PeopleArray::ResolveLink(T2PeopleArrayList* list) { + for (int i = 0; i < 256; i++) { + if (mPeople[i].IsUsed()) + mPeople[i].ResolveLink(list); + } } T2People* T2PeopleArray::FindUnusedPeople() { + T2People *result = NULL; + + for (unsigned int i = 0; i < 256; i++) { + if (!mPeople[i].IsUsed()) { + result = &mPeople[i]; + break; + } + } + + return result; } -/*virtual*/ void T2PeopleArray::DispatchIdle(T2TowerDoc*, int) { +/*virtual*/ void T2PeopleArray::DispatchIdle(T2TowerDoc* towerDoc, int startIndex) { + int i; + T2People *people; + + people = &mPeople[startIndex]; + for (i = startIndex; i < 256; i += 8) { + if (people->mUsed) + people->Idle(towerDoc); + people += 8; + } + + people = mPeople; + int walkRate = towerDoc->towerDoc_vf148(); + for (i = 0; i < 256; i++) { + if (people->mUsed) { + if ((walkRate > 0 && !(i % walkRate)) || people->IsSetSpecialFlag(kSpecialFlag20)) + people->IdleSearchedPerson(towerDoc); + } + people++; + } } -void T2PeopleArray::DrawSearchedPerson(T2TowerDoc*) { +void T2PeopleArray::DrawSearchedPerson(T2TowerDoc* towerDoc) { + T2People *people = mPeople; + for (int i = 0; i < 256; i++) { + if (people->mUsed && people->IsWalk()) + people->DrawSearchedPerson(towerDoc); + people++; + } } -void T2PeopleArray::SetWalkPeople(int) { +void T2PeopleArray::SetWalkPeople(int v) { + for (int i = 0; i < 256; i++) + mPeople[i].SetWalk(false); + + if (v != -1) { + for (int i = 0; i < 256; i += v) + mPeople[i].SetWalk(true); + } } void T2PeopleArray::DayChanged() { + for (int i = 0; i < 256; i++) { + if (mPeople[i].IsUsed()) + mPeople[i].DayChanged(); + } } -void T2PeopleArray::TenantRemoved(unsigned int) { +void T2PeopleArray::TenantRemoved(unsigned int v) { + for (int i = 0; i < 256; i++) { + if (mPeople[i].IsUsed()) + mPeople[i].TenantRemoved(v); + } } -void T2PeopleArray::AddStress(int) { +void T2PeopleArray::AddStress(int v) { + for (int i = 0; i < 256; i++) { + if (mPeople[i].IsUsed()) + mPeople[i].IncStress(v); + } } -void T2PeopleArray::BreakoutEmergency(T2TowerDoc*) { +void T2PeopleArray::BreakoutEmergency(T2TowerDoc* towerDoc) { + for (int i = 0; i < 256; i++) { + T2People *people = &mPeople[i]; + if (people->IsUsed()) + people->BreakoutEmergency(towerDoc); + } } -void T2PeopleArray::Read(T2Archive&, T2TowerDoc*) { +void T2PeopleArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + for (int i = 0; i < 256; i++) + mPeople[i].Load(archive, towerDoc); } -void T2PeopleArray::Write(T2Archive&) { +void T2PeopleArray::Write(T2Archive& archive) { + for (int i = 0; i < 256; i++) + mPeople[i].Save(archive); } diff --git a/src/T2DLL/T2PeopleArray.h b/src/T2DLL/T2PeopleArray.h index 3e1521c..49dd766 100644 --- a/src/T2DLL/T2PeopleArray.h +++ b/src/T2DLL/T2PeopleArray.h @@ -1,13 +1,16 @@ #pragma once #include "common.h" +#include "T2ObjectArray.h" +#include "T2People.h" -class T2PeopleArray { +class AFX_EXT_CLASS T2PeopleArray : public T2ObjectArray { public: - T2PeopleArray(unsigned int); + T2PeopleArray(unsigned int startID = 1); + virtual ~T2PeopleArray() {} + virtual void DispatchIdle(T2TowerDoc*, int); T2People* FindPeople(unsigned int); void ResolveLink(T2PeopleArrayList*); T2People* FindUnusedPeople(); - virtual void DispatchIdle(T2TowerDoc*, int); void DrawSearchedPerson(T2TowerDoc*); void SetWalkPeople(int); void DayChanged(); @@ -17,9 +20,8 @@ public: void Read(T2Archive&, T2TowerDoc*); void Write(T2Archive&); - virtual ~T2PeopleArray() {} - T2People* GetIndexPeople(int) {} - T2PeopleArray(const T2PeopleArray&) {} - T2PeopleArray& operator=(const T2PeopleArray&) {} - void `default constructor closure'() {} + T2People* GetIndexPeople(int i) { return &mPeople[i]; } + +protected: + T2People mPeople[256]; }; diff --git a/src/T2DLL/T2PeopleArrayList.cpp b/src/T2DLL/T2PeopleArrayList.cpp index 19db7d8..91b94a6 100644 --- a/src/T2DLL/T2PeopleArrayList.cpp +++ b/src/T2DLL/T2PeopleArrayList.cpp @@ -1,46 +1,154 @@ +#include "T2Archive.h" +#include "T2PeopleArray.h" #include "T2PeopleArrayList.h" T2PeopleArrayList::T2PeopleArrayList() { + mCounter = 0; + T2PeopleArray *peopleArray = new T2PeopleArray; + Add(peopleArray); } /*virtual*/ T2PeopleArrayList::~T2PeopleArrayList() { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + delete peopleArray; } -void T2PeopleArrayList::Add(T2PeopleArray*) { +void T2PeopleArrayList::Add(T2PeopleArray* peopleArray) { + LArray::Add(&peopleArray); } unsigned int T2PeopleArrayList::GetItemCount() { + return GetCount(); } -T2PeopleArray* T2PeopleArrayList::GetItemAt(int) { +T2PeopleArray* T2PeopleArrayList::GetItemAt(int index) { + T2PeopleArray *peopleArray; + FetchItemAt(index, &peopleArray); + return peopleArray; } -T2People* T2PeopleArrayList::FindPeople(unsigned int) { +T2People* T2PeopleArrayList::FindPeople(unsigned int peopleID) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) { + T2People *people = peopleArray->FindPeople(peopleID); + if (people) + return people; + } + + return NULL; } T2People* T2PeopleArrayList::FindUnusedPeople() { + T2People *result = NULL; + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray = NULL; + + while (!result && iterator.Next(&peopleArray)) { + result = peopleArray->FindUnusedPeople(); + } + + if (!result) { + unsigned int newStartID = 1; + if (peopleArray) + newStartID = peopleArray->GetStartID() + 256; + + peopleArray = new T2PeopleArray(newStartID); + if (peopleArray) { + Add(peopleArray); + result = peopleArray->FindUnusedPeople(); + } + } + + return result; } -void T2PeopleArrayList::DispatchIdle(T2TowerDoc*) { +void T2PeopleArrayList::DispatchIdle(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->DispatchIdle(towerDoc, mCounter); + + mCounter++; + if (mCounter >= 8) + mCounter = 0; } -void T2PeopleArrayList::DrawSearchedPerson(T2TowerDoc*) { +void T2PeopleArrayList::DrawSearchedPerson(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->DrawSearchedPerson(towerDoc); } -void T2PeopleArrayList::SetWalkPeople(int) { +void T2PeopleArrayList::SetWalkPeople(int v) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->SetWalkPeople(v); } -void T2PeopleArrayList::TenantRemoved(unsigned int) { +void T2PeopleArrayList::TenantRemoved(unsigned int v) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->TenantRemoved(v); } -void T2PeopleArrayList::AddStress(int) { +void T2PeopleArrayList::AddStress(int v) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->AddStress(v); } -void T2PeopleArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2PeopleArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + int count; + archive >> count; + + RemoveItemsAt(GetCount(), 1); + unsigned int startID = 1; + + for (int i = 0; i < count; i++) { + Add(new T2PeopleArray(startID)); + startID += 256; + } + + T2PeopleArray *peopleArray; + + LArrayIterator iterator1(*this); + while (iterator1.Next(&peopleArray)) + peopleArray->Read(archive, towerDoc); + + LArrayIterator iterator2(*this); + while (iterator2.Next(&peopleArray)) + peopleArray->ResolveLink(this); } -void T2PeopleArrayList::Write(T2Archive&) { +void T2PeopleArrayList::Write(T2Archive& archive) { + int count = GetItemCount(); + archive << count; + + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->Write(archive); } -void T2PeopleArrayList::BreakoutEmergency(T2TowerDoc*) { +void T2PeopleArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2PeopleArray *peopleArray; + + while (iterator.Next(&peopleArray)) + peopleArray->BreakoutEmergency(towerDoc); } diff --git a/src/T2DLL/T2PeopleArrayList.h b/src/T2DLL/T2PeopleArrayList.h index 60c059c..88af4ae 100644 --- a/src/T2DLL/T2PeopleArrayList.h +++ b/src/T2DLL/T2PeopleArrayList.h @@ -1,7 +1,8 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2PeopleArrayList { +class AFX_EXT_CLASS T2PeopleArrayList : private LArray { public: T2PeopleArrayList(); virtual ~T2PeopleArrayList(); @@ -19,6 +20,6 @@ public: void Write(T2Archive&); void BreakoutEmergency(T2TowerDoc*); - T2PeopleArrayList(const T2PeopleArrayList&) {} - T2PeopleArrayList& operator=(const T2PeopleArrayList&) {} +protected: + int mCounter; }; diff --git a/src/T2DLL/T2PeopleDef.cpp b/src/T2DLL/T2PeopleDef.cpp index 1c07737..0049920 100644 --- a/src/T2DLL/T2PeopleDef.cpp +++ b/src/T2DLL/T2PeopleDef.cpp @@ -1,10 +1,17 @@ +#include "CResFile.h" #include "T2PeopleDef.h" -T2PeopleDef::T2PeopleDef(unsigned long, T2PluginSpecifier&, CResFile*) { +T2PeopleDef::T2PeopleDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile) + : T2MatterDef(type, specifier, resFile) +{ + *resFile >> mStressMax; + *resFile >> mStressBlueLimit; + *resFile >> mStressYellowLimit; } /*virtual*/ T2PeopleDef::~T2PeopleDef() { } -/*virtual*/ void T2PeopleDef::GetName(CString&) { +/*virtual*/ void T2PeopleDef::GetName(CString& outStr) { + outStr.Format("%d", mSortKey); } diff --git a/src/T2DLL/T2PeopleDef.h b/src/T2DLL/T2PeopleDef.h index 8f32c2c..6e0cafb 100644 --- a/src/T2DLL/T2PeopleDef.h +++ b/src/T2DLL/T2PeopleDef.h @@ -1,15 +1,20 @@ #pragma once #include "common.h" +#include "T2MatterDef.h" -class T2PeopleDef { +class AFX_EXT_CLASS T2PeopleDef : public T2MatterDef { public: - T2PeopleDef(unsigned long, T2PluginSpecifier&, CResFile*); + T2PeopleDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile); virtual ~T2PeopleDef(); virtual void GetName(CString&); - int GetPeopleType() {} - int GetStressMax() {} - int GetStressBlueLimit() {} - int GetStressYellowLimit() {} - T2PeopleDef& operator=(T2PeopleDef&) {} + int GetPeopleType() { return mSortKey; } + int GetStressMax() { return mStressMax; } + int GetStressBlueLimit() { return mStressBlueLimit; } + int GetStressYellowLimit() { return mStressYellowLimit; } + +protected: + int mStressMax; + int mStressBlueLimit; + int mStressYellowLimit; }; diff --git a/src/T2DLL/T2PeopleDemandList.cpp b/src/T2DLL/T2PeopleDemandList.cpp index 06e943c..e8def3b 100644 --- a/src/T2DLL/T2PeopleDemandList.cpp +++ b/src/T2DLL/T2PeopleDemandList.cpp @@ -1,40 +1,148 @@ +#include "T2Archive.h" #include "T2PeopleDemandList.h" +#include "T2PeopleTimeZoneList.h" +#include "T2PeopleType.h" +#include "T2PoolDef.h" +#include "T2SeasonParamDef.h" +#include "T2TenantMemberDef.h" +#include "UT2Utils.h" -T2PeopleDemandList::T2PeopleDemandList(T2PoolDef*, T2SeasonParamDef*, T2WorldDef*) { +T2PeopleDemandList::T2PeopleDemandList(T2PoolDef* inPoolDef, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef) + : LArray(sizeof(T2PeopleTimeZoneList *)) + , mSeasonParamDef(inSeasonParamDef) +{ + int count = inPoolDef->GetNumOfDemand(); + for (int i = 0; i < count; i++) { + DemandInfo *theDemandInfo = inPoolDef->GetDemandInfo(i); + T2PeopleTimeZoneList *theTimeZoneList = new T2PeopleTimeZoneList(theDemandInfo->b, theDemandInfo->a, inWorldDef); + Add(theTimeZoneList); + } } -T2PeopleDemandList::T2PeopleDemandList(T2Archive&, T2SeasonParamDef*, T2WorldDef*) { +T2PeopleDemandList::T2PeopleDemandList(T2Archive& inArchive, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef) + : LArray(sizeof(T2PeopleTimeZoneList *)) + , mSeasonParamDef(inSeasonParamDef) +{ + unsigned int count; + inArchive >> count; + + for (unsigned int i = 0; i < count; i++) { + T2PeopleTimeZoneList *theTimeZoneList = new T2PeopleTimeZoneList(inArchive, inWorldDef); + Add(theTimeZoneList); + } } /*virtual*/ T2PeopleDemandList::~T2PeopleDemandList() { + LArrayIterator iterator(*this); + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) + delete theTimeZoneList; } -void T2PeopleDemandList::Add(T2PeopleTimeZoneList*) { +void T2PeopleDemandList::Add(T2PeopleTimeZoneList* inTimeZoneList) { + InsertItemsAt(1, mItemCount + 1, &inTimeZoneList); } -void T2PeopleDemandList::Add(T2PoolGradeDef*) { +void T2PeopleDemandList::Add(T2PoolGradeDef* inGradeDef) { + LArrayIterator iterator(*this); + int demandType = 0; + T2PeopleType peopleType; + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) { + peopleType.SetDemandType(demandType); + + T2PoolDefDemandElem *theDemandElem = inGradeDef->GetDemandElem(demandType); + theTimeZoneList->Add(&peopleType, theDemandElem); + + demandType++; + } } -void T2PeopleDemandList::Init(unsigned int, unsigned int) { +void T2PeopleDemandList::Init(unsigned int inMonth, unsigned int inSomeNum) { + float rate = 0.0f; + if (mSeasonParamDef) + rate = mSeasonParamDef->GetRate(inMonth - 1); + + LArrayIterator iterator(*this); + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) + theTimeZoneList->Init(inSomeNum, rate); } -void T2PeopleDemandList::IncHour(unsigned int) { +void T2PeopleDemandList::IncHour(unsigned int inMonth) { + float rate = 0.0f; + if (mSeasonParamDef) + rate = mSeasonParamDef->GetRate(inMonth - 1); + + LArrayIterator iterator(*this); + T2PeopleTimeZoneList *theTimeZoneList; + + while (iterator.Next(&theTimeZoneList)) + theTimeZoneList->IncHour(rate); } -T2PeopleTimeZoneList* T2PeopleDemandList::GetItem(int) const { +T2PeopleTimeZoneList* T2PeopleDemandList::GetItem(int inDemandType) const { + int index = inDemandType + 1; + T2PeopleTimeZoneList *theList; + if (!FetchItemAt(index, &theList)) + theList = NULL; + return theList; } -int T2PeopleDemandList::Find(T2TenantMemberDef*, int, unsigned int, int) const { +BOOL T2PeopleDemandList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + BOOL result = false; + + T2PeopleTimeZoneList *theList = GetItem(inTenantMemberDef->GetDemandType()); + if (theList) + result = theList->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType); + + return result; } -int T2PeopleDemandList::Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&) const { +BOOL T2PeopleDemandList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) const { + BOOL result = false; + int demandType = inTenantMemberDef->GetDemandType(); + + if (demandType != -1) { + T2PeopleTimeZoneList *theList = GetItem(demandType); + if (theList) + result = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); + } else { + for (int i = UT2Utils::Randomize(mItemCount) + 1, j = 0; !result && j < mItemCount; j++, i++) { + if (i > mItemCount) + i = 1; + + T2PeopleTimeZoneList *theList = GetItem(i); + if (theList && !theList->IsFixed()) + result = theList->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); + } + } + + return result; } -void T2PeopleDemandList::DispatchRestore(T2PeopleType&) { +void T2PeopleDemandList::DispatchRestore(T2PeopleType& peopleType) { + T2PeopleTimeZoneList *theList = GetItem(peopleType.GetDemandType()); + if (theList) + theList->DispatchRestore(peopleType); } -void T2PeopleDemandList::DispatchAdd(T2PeopleType*) { +void T2PeopleDemandList::DispatchAdd(T2PeopleType* peopleType) { + T2PeopleTimeZoneList *theList = GetItem(peopleType->GetDemandType()); + if (theList) + theList->DispatchAdd(peopleType); } -void T2PeopleDemandList::Write(T2Archive&) { +void T2PeopleDemandList::Write(T2Archive& archive) { + unsigned int count = GetCount(); + archive << count; + + for (unsigned int i = 0; i < count; i++) { + T2PeopleTimeZoneList *theList = GetItem(i); + if (theList) + theList->Write(archive); + } } diff --git a/src/T2DLL/T2PeopleDemandList.h b/src/T2DLL/T2PeopleDemandList.h index 1e4ceef..e330e85 100644 --- a/src/T2DLL/T2PeopleDemandList.h +++ b/src/T2DLL/T2PeopleDemandList.h @@ -1,26 +1,25 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2PeopleDemandList { +class AFX_EXT_CLASS T2PeopleDemandList : private LArray { public: - T2PeopleDemandList(T2PoolDef*, T2SeasonParamDef*, T2WorldDef*); - T2PeopleDemandList(T2Archive&, T2SeasonParamDef*, T2WorldDef*); + T2PeopleDemandList(T2PoolDef* inPoolDef, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef); + T2PeopleDemandList(T2Archive& inArchive, T2SeasonParamDef* inSeasonParamDef, T2WorldDef* inWorldDef); virtual ~T2PeopleDemandList(); + + void Add(T2PoolGradeDef* gradeDef); + void Init(unsigned int inMonth, unsigned int inSomeNum); + void IncHour(unsigned int inMonth); + BOOL Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const; + BOOL Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) const; + void DispatchRestore(T2PeopleType& peopleType); + void DispatchAdd(T2PeopleType* peopleType); + void Write(T2Archive& archive); + protected: - void Add(T2PeopleTimeZoneList*); -public: - void Add(T2PoolGradeDef*); - void Init(unsigned int, unsigned int); - void IncHour(unsigned int); -protected: + void Add(T2PeopleTimeZoneList* timeZoneList); T2PeopleTimeZoneList* GetItem(int) const; -public: - int Find(T2TenantMemberDef*, int, unsigned int, int) const; - int Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&) const; - void DispatchRestore(T2PeopleType&); - void DispatchAdd(T2PeopleType*); - void Write(T2Archive&); - T2PeopleDemandList(const T2PeopleDemandList&) {} - T2PeopleDemandList& operator=(const T2PeopleDemandList&) {} + T2SeasonParamDef *mSeasonParamDef; }; diff --git a/src/T2DLL/T2PeopleInfoDialog.cpp b/src/T2DLL/T2PeopleInfoDialog.cpp index 1593309..c57f233 100644 --- a/src/T2DLL/T2PeopleInfoDialog.cpp +++ b/src/T2DLL/T2PeopleInfoDialog.cpp @@ -1,28 +1,286 @@ +#include "CTokenizer.h" +#include "GlobalFunc.h" +#include "T2DlgItemPPLEvalGage.h" +#include "T2DlgItemStressGage.h" +#include "T2FloorInfo.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" #include "T2PeopleInfoDialog.h" +#include "T2SilhouettePane.h" +#include "T2TemplatePluginList.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" +#include "T2ToolDef.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "UT2Utils.h" -T2PeopleInfoDialog::T2PeopleInfoDialog(T2People*) { +T2PeopleInfoDialog::T2PeopleInfoDialog(T2People* people) + : T2InfoDialog(people) +{ + mPeople = people; + m104 = 0; } /*virtual*/ T2PeopleInfoDialog::~T2PeopleInfoDialog() { } /*virtual*/ void T2PeopleInfoDialog::OnT2Create() { + T2TowerDoc *theTowerDoc = mTowerDoc; + T2WorldDef *theWorldDef = GetCurrentT2TowerDoc()->towerDoc_vf170(); + + if (mPeople) + mPeopleDef = (T2PeopleDef *) mPeople->GetMatterDef(); + else + return; + + CString str1; + CString str2; + + T2Name *theName = theTowerDoc->mNameDB->Search(mPeople, false); + unsigned int theNameID; + if (theName) + theName->GetName(m108, theNameID); + else + mPeople->GetName(m108); + + T2DlgItem *item1010 = (T2DlgItem *) GetDlgItem(1010); + T2DlgItem *item1011 = (T2DlgItem *) GetDlgItem(1011); + T2DlgItem *item1012 = (T2DlgItem *) GetDlgItem(1012); + + // 7090 - favourite button + T2DlgItem *item7090 = GetT2DlgItem(7090); + + item1010->SetDescriptor(m108); + item1012->SetDescriptor(m108); + + T2SilhouettePane *theSilhouettePane = (T2SilhouettePane *) GetDlgItem(2010); + theSilhouettePane->SetPeople(mPeople); + + // 1020 - money + T2DlgItem *item1020 = (T2DlgItem *) GetDlgItem(1020); + str1.Format("%d", theWorldDef->ExchangeMoney(theWorldDef->GetCashAmount(mPeople->GetEconoType()))); + item1020->SetDescriptor(str1); + + // 1030 - where they're going from + T2DlgItem *item1030 = (T2DlgItem *) GetDlgItem(1030); + if (mPeople->GetWorkTenant() > 1) { + T2Tenant *workTenant = theTowerDoc->mFloorInfo->GetTenant(mPeople->GetWorkTenant()); + T2Name *workTenantName = theTowerDoc->mNameDB->Search(workTenant, false); + + UT2Utils::GetRoomNumberString(workTenant->GetFloorNumber(theTowerDoc->mFloorInfo), str1); + UT2Utils::GetRoomNumberString(workTenant->GetRoomNumber(theTowerDoc->mFloorInfo), str2); + + // "階" + str + "号室\r\n" + str1 = str1 + "\x8A\x4B" + str2 + "\x8D\x86\x8E\xBA\r\n"; + + CString nameStr; + unsigned int theNameID; + if (workTenantName) + workTenantName->GetName(nameStr, theNameID); + + if (nameStr == "") { + T2ToolDef *toolDef = (T2ToolDef *) workTenant->GetEquipDef(); + if (toolDef) + toolDef->GetName(nameStr, 0); + } + + str1 += nameStr; + item1030->SetDescriptor(str1); + + T2DlgItem *item1010 = (T2DlgItem *) GetDlgItem(1010); + if (mPeople->IsVIP()) { + item1010->ShowWindow(SW_HIDE); + item7090->EnableWindow(false); + } else { + item1011->ShowWindow(SW_HIDE); + item1012->ShowWindow(SW_HIDE); + } + } else { + T2PeopleType *thePeopleType = mPeople->GetPeopleType(); + if (thePeopleType) { + if (thePeopleType->GetDemandType() == 3) { + // "観光客" - tourist + str1 = "\x8A\xCF\x8C\xF5\x8B\x71"; + } else { + // "一般客" - general customer + str1 = "\x88\xEA\x94\xCA\x8B\x71"; + } + } + item1030->SetDescriptor(str1); + item1010->ShowWindow(SW_HIDE); + item7090->EnableWindow(false); + } + + if (mPeople->IsSetDestination()) { + str1 = ""; + int prevTenantType = mPeople->GetPrevTenantType(); + if (prevTenantType == -1) { + // "ロビー から\n" - from the lobby + str1 = "\x83\x8D\x83\x72\x81\x5B \x82\xA9\x82\xE7\n"; + } else { + T2TenantDef *prevTenantDef = theTowerDoc->mTenantTemplates->FindTenantDef(prevTenantType); + if (prevTenantDef) { + str1 = prevTenantDef->mStr48; + // " から\n" - from + str1 += " \x82\xA9\x82\xE7\n"; + } + } + + str1 += GetTenantName(theTowerDoc, mPeople->GetDestination()); + // " へ移動中" - moving to + str1 += " \x82\xD6\x88\xDA\x93\xAE\x92\x86"; + } else { + // "なし" - none + str1 = "\x82\xC8\x82\xB5"; + } + + // 1040 - where they're going to + T2DlgItem *item1040 = (T2DlgItem *) GetDlgItem(1040); + item1040->SetDescriptor(str1); + + T2DlgItemStressGage *stressGage = (T2DlgItemStressGage *) GetDlgItem(110); + stressGage->SetPeople(mPeople); + + T2DlgItemPPLEvalGage *pplEvalGage = (T2DlgItemPPLEvalGage *) GetDlgItem(126); + pplEvalGage->SetPeople(mPeople); + + BOOL hasAnyName = false; + T2Name *nonFavName = mTowerDoc->mNameDB->Search(mPeople, false); + if (nonFavName) + hasAnyName = true; + T2Name *favName = mTowerDoc->mNameDB->Search(mPeople, true); + if (favName) + hasAnyName = true; + + if (hasAnyName) + item7090->EnableWindow(false); + + if (!mPeople->IsMaru() && !mPeople->IsReggae()) { + CString interview; + if (mPeople->GetInterviewWords(theTowerDoc, interview)) { + ((T2DlgItem *) GetDlgItem(1060))->SetDescriptor(interview); + } + } } -CString T2PeopleInfoDialog::GetTenantName(T2TowerDoc*, unsigned int) { +CString T2PeopleInfoDialog::GetTenantName(T2TowerDoc* towerDoc, unsigned int inTenantID) { + CString result = ""; + + unsigned int tenantID = inTenantID; + if (tenantID == 1) { + // "ロビー" - lobby + result = "\x83\x8D\x83\x72\x81\x5B"; + } else { + CString str; + T2Tenant *theTenant = towerDoc->mFloorInfo->GetTenant(tenantID); + T2Name *theName = towerDoc->mNameDB->Search(theTenant, false); + + UT2Utils::GetRoomNumberString(theTenant->GetFloorNumber(towerDoc->mFloorInfo), result); + UT2Utils::GetRoomNumberString(theTenant->GetRoomNumber(towerDoc->mFloorInfo), str); + + // "階" + str + "号室" - floor + ... + room number + result = result + "\x8A\x4B" + str + "\x8D\x86\x8E\xBA "; + + CString nameStr; + unsigned int theNameID; + if (theName) + theName->GetName(nameStr, theNameID); + + if (nameStr == "") { + T2ToolDef *toolDef = (T2ToolDef *) theTenant->GetEquipDef(); + if (toolDef) + toolDef->GetName(nameStr, 0); + } + + result += nameStr; + } + + return result; } -/*virtual*/ void T2PeopleInfoDialog::CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&) { +/*virtual*/ void T2PeopleInfoDialog::CreateDlgItem(CTokenizer& tokenizer, T2DialogDef& def) { + if (!_stricmp(tokenizer.Current(), "SILH")) { + RECT rect; + int id = tokenizer.NextInteger(); + rect.left = tokenizer.NextInteger(); + rect.top = tokenizer.NextInteger(); + rect.right = tokenizer.NextInteger(); + rect.bottom = tokenizer.NextInteger(); + + T2SilhouettePane *silhouettePane = new T2SilhouettePane(mTowerDoc, mImageObj, mPalette); + silhouettePane->Create("", def.flags, rect, this, id); + if (mCurrentFont >= 0) + silhouettePane->SetFont(*mFonts[mCurrentFont]); + } else if (!_stricmp(tokenizer.Current(), "PPLEV")) { + RECT rect; + int id = tokenizer.NextInteger(); + rect.left = tokenizer.NextInteger(); + rect.top = tokenizer.NextInteger(); + rect.right = tokenizer.NextInteger(); + rect.bottom = tokenizer.NextInteger(); + + T2DlgItemPPLEvalGage *pplEvalGage = new T2DlgItemPPLEvalGage(mTowerDoc, mImageObj, mPalette); + pplEvalGage->Create("", def.flags, rect, this, id); + if (mCurrentFont >= 0) + pplEvalGage->SetFont(*mFonts[mCurrentFont]); + } else { + T2Dialog::CreateDlgItem(tokenizer, def); + } } /*virtual*/ void T2PeopleInfoDialog::OnT2Destroy() { } -/*virtual*/ int T2PeopleInfoDialog::OnT2DialogCommand(unsigned int, long) { +/*virtual*/ BOOL T2PeopleInfoDialog::OnT2DialogCommand(UINT cmd, long data) { + WORD hi = HIWORD(cmd); + WORD lo = LOWORD(cmd); + + if (lo == 1 && hi == 0) { + // nothing + } else if (lo == 2 && hi == 0) { + // wtf is going on here? compiler uses a different register + DestroyWindow(); + } else if (lo == 7090 && hi == 0) { + m104 = true; + GetT2DlgItem(7090)->EnableWindow(false); + + T2DlgItem *item = (T2DlgItem *) GetDlgItem(1010); + CString str; + item->GetDescriptor(str); + if (str == "") + item->SetDescriptor(m108); + } + + return false; } -/*virtual*/ int T2PeopleInfoDialog::OnT2EraseBkgnd(CDC*) { +/*virtual*/ BOOL T2PeopleInfoDialog::OnT2EraseBkgnd(CDC* dc) { + return true; } /*virtual*/ void T2PeopleInfoDialog::OnT2OK() { + CString nameStr; + ((T2DlgItem *) GetDlgItem(1010))->GetDescriptor(nameStr); + + if (nameStr == "") + nameStr = m108; + + if (m108 != nameStr || m104 == 1) { + T2Name *nonFavName = mTowerDoc->mNameDB->Search(mPeople, false); + if (nonFavName) { + nonFavName->SetName(nameStr); + } else { + T2Name *newName = new T2Name(nameStr, mPeople, false); + mTowerDoc->mNameDB->Add(newName); + mPeople->SetColor(13); + } + + T2Name *favName = mTowerDoc->mNameDB->Search(mPeople, true); + if (favName) { + mTowerDoc->towerDoc_vf1C4(mPeople, false); + mTowerDoc->towerDoc_vf1B8(mPeople); + } + } } diff --git a/src/T2DLL/T2PeopleInfoDialog.h b/src/T2DLL/T2PeopleInfoDialog.h index cd970bf..6413029 100644 --- a/src/T2DLL/T2PeopleInfoDialog.h +++ b/src/T2DLL/T2PeopleInfoDialog.h @@ -1,16 +1,22 @@ #pragma once #include "common.h" +#include "T2InfoDialog.h" -class T2PeopleInfoDialog { +class AFX_EXT_CLASS T2PeopleInfoDialog : public T2InfoDialog { public: T2PeopleInfoDialog(T2People*); virtual ~T2PeopleInfoDialog(); protected: - virtual void OnT2Create(); CString GetTenantName(T2TowerDoc*, unsigned int); - virtual void CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&); + virtual void OnT2Create(); + virtual void CreateDlgItem(CTokenizer&, T2DialogDef&); virtual void OnT2Destroy(); - virtual int OnT2DialogCommand(unsigned int, long); - virtual int OnT2EraseBkgnd(CDC*); + virtual BOOL OnT2DialogCommand(UINT cmd, long data); + virtual BOOL OnT2EraseBkgnd(CDC*); virtual void OnT2OK(); + + T2People *mPeople; + T2PeopleDef *mPeopleDef; + int m104; + CString m108; }; diff --git a/src/T2DLL/T2PeopleLinkIterator.cpp b/src/T2DLL/T2PeopleLinkIterator.cpp index 96ad5d8..c0bdf00 100644 --- a/src/T2DLL/T2PeopleLinkIterator.cpp +++ b/src/T2DLL/T2PeopleLinkIterator.cpp @@ -1,15 +1,16 @@ +#include "T2People.h" #include "T2PeopleLinkIterator.h" T2PeopleLinkIterator::T2PeopleLinkIterator(T2People* people) : mFirst(people) - , mCurrent(people) + , mCurrent(NULL) { } /*virtual*/ T2PeopleLinkIterator::~T2PeopleLinkIterator() { } -int T2PeopleLinkIterator::Current(T2People** pPeople) { +BOOL T2PeopleLinkIterator::Current(T2People** pPeople) { if (mCurrent) { *pPeople = mCurrent; return true; @@ -17,12 +18,25 @@ int T2PeopleLinkIterator::Current(T2People** pPeople) { return false; } -int T2PeopleLinkIterator::Prev(T2People** pPeople) { - // TODO once T2Matter, T2People is done +BOOL T2PeopleLinkIterator::Prev(T2People** pPeople) { + if (mCurrent) { + mCurrent = (T2People *) mCurrent->mPrev; + return Current(pPeople); + } else { + return false; + } } -int T2PeopleLinkIterator::Next(T2People** pPeople) { +BOOL T2PeopleLinkIterator::Next(T2People** pPeople) { + if (mCurrent) { + mCurrent = (T2People *) mCurrent->mNext; + return Current(pPeople); + } else { + mCurrent = mFirst; + return Current(pPeople); + } } void T2PeopleLinkIterator::Reset() { + mCurrent = NULL; } diff --git a/src/T2DLL/T2PeopleLinkIterator.h b/src/T2DLL/T2PeopleLinkIterator.h index e6b15a5..5838b46 100644 --- a/src/T2DLL/T2PeopleLinkIterator.h +++ b/src/T2DLL/T2PeopleLinkIterator.h @@ -1,13 +1,13 @@ #pragma once #include "common.h" -class T2PeopleLinkIterator { +class AFX_EXT_CLASS T2PeopleLinkIterator { public: T2PeopleLinkIterator(T2People*); virtual ~T2PeopleLinkIterator(); - int Current(T2People**); - int Prev(T2People**); - int Next(T2People**); + BOOL Current(T2People**); + BOOL Prev(T2People**); + BOOL Next(T2People**); void Reset(); protected: diff --git a/src/T2DLL/T2PeopleLoader.cpp b/src/T2DLL/T2PeopleLoader.cpp index 3552889..f2e76a3 100644 --- a/src/T2DLL/T2PeopleLoader.cpp +++ b/src/T2DLL/T2PeopleLoader.cpp @@ -1,13 +1,72 @@ +#include "CResFile.h" +#include "T2PeopleDef.h" #include "T2PeopleLoader.h" +#include "T2SilhouetteDef.h" +#include "T2TemplatePluginDB.h" +#include "T2TemplatePluginList.h" -/*static*/ void T2PeopleLoader::Load(T2PluginSpecifier*, T2TemplatePluginDB*) { +/*static*/ void T2PeopleLoader::Load(T2PluginSpecifier* specifier, T2TemplatePluginDB* db) { + LoadSilhouette(specifier, db); + LoadPeople(specifier, db); } -/*static*/ void T2PeopleLoader::Unload(T2TemplatePluginDB*) { +/*static*/ void T2PeopleLoader::Unload(T2TemplatePluginDB* db) { + LArrayIterator silhouetteIterator(*db->GetTemplatePluginList('SlDf')); + T2SilhouetteDef *silhouetteDef; + while (silhouetteIterator.Next(&silhouetteDef)) + delete silhouetteDef; + + LArrayIterator peopleIterator(*db->GetTemplatePluginList('PPDf')); + T2PeopleDef *peopleDef; + while (peopleIterator.Next(&peopleDef)) + delete peopleDef; } -/*static*/ int T2PeopleLoader::LoadSilhouette(T2PluginSpecifier*, T2TemplatePluginDB*) { +/*static*/ BOOL T2PeopleLoader::LoadSilhouette(T2PluginSpecifier* specifier, T2TemplatePluginDB* db) { + CResFile resFile; + if (resFile.OpenResource(specifier->mInstance, 1, 'SlDf')) { + T2TemplatePluginList *silhouetteList = db->GetTemplatePluginList('SlDf'); + + int count; + resFile >> count; + + for (int i = 0; i < count; i++) { +#line 47 + T2SilhouetteDef *silhouetteDef = DEBUG_NEW T2SilhouetteDef('SlDf', *specifier, &resFile); + + if (!silhouetteList->FindSilhouette(silhouetteDef->GetSilhouetteType())) + silhouetteList->Add(silhouetteDef); + else + delete silhouetteDef; + } + + return true; + } + return false; } -/*static*/ int T2PeopleLoader::LoadPeople(T2PluginSpecifier*, T2TemplatePluginDB*) { +/*static*/ BOOL T2PeopleLoader::LoadPeople(T2PluginSpecifier* specifier, T2TemplatePluginDB* db) { + CResFile resFile; + if (resFile.OpenResource(specifier->mInstance, 1, 'PPDf')) { + T2TemplatePluginList *peopleList = db->GetTemplatePluginList('PPDf'); + T2TemplatePluginList *silhouetteList = db->GetTemplatePluginList('SlDf'); + + int count; + resFile >> count; + + for (int i = 0; i < count; i++) { +#line 70 + T2PeopleDef *peopleDef = DEBUG_NEW T2PeopleDef('PPDf', *specifier, &resFile); + + if (!peopleList->FindPeopleDef(peopleDef->GetPeopleType())) { + peopleDef->AssignSilhouette(silhouetteList); + peopleList->Add(peopleDef); + } else { + delete peopleDef; + } + } + + return true; + } + return false; } diff --git a/src/T2DLL/T2PeopleLoader.h b/src/T2DLL/T2PeopleLoader.h index f96a8f0..6c97936 100644 --- a/src/T2DLL/T2PeopleLoader.h +++ b/src/T2DLL/T2PeopleLoader.h @@ -1,14 +1,11 @@ #pragma once #include "common.h" -class T2PeopleLoader { +class AFX_EXT_CLASS T2PeopleLoader { public: static void Load(T2PluginSpecifier*, T2TemplatePluginDB*); static void Unload(T2TemplatePluginDB*); protected: - static int LoadSilhouette(T2PluginSpecifier*, T2TemplatePluginDB*); - static int LoadPeople(T2PluginSpecifier*, T2TemplatePluginDB*); - -public: - T2PeopleLoader& operator=(const T2PeopleLoader&) {} + static BOOL LoadSilhouette(T2PluginSpecifier*, T2TemplatePluginDB*); + static BOOL LoadPeople(T2PluginSpecifier*, T2TemplatePluginDB*); }; diff --git a/src/T2DLL/T2PeoplePtrList.cpp b/src/T2DLL/T2PeoplePtrList.cpp index cffd0fb..315d664 100644 --- a/src/T2DLL/T2PeoplePtrList.cpp +++ b/src/T2DLL/T2PeoplePtrList.cpp @@ -1,52 +1,162 @@ +#include "T2Archive.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" #include "T2PeoplePtrList.h" -T2PeoplePtrList::T2PeoplePtrList(int) { +T2PeoplePtrList::T2PeoplePtrList(int count) + : LArray(sizeof(T2People *)) +{ + Init(count); } /*virtual*/ T2PeoplePtrList::~T2PeoplePtrList() { } -void T2PeoplePtrList::Init(unsigned int) { +void T2PeoplePtrList::Init(unsigned int count) { + if (count > 0) { + AdjustAllocation(count); + T2People *zero = NULL; + InsertItemsAt(count, 1, &zero); + } } -int T2PeoplePtrList::Add(T2People*) { +BOOL T2PeoplePtrList::Add(T2People* people) { + BOOL result = false; + T2People *zero = NULL; + + int index; + if (GetPeopleIndex(zero, index)) { + AssignItemsAt(1, index, &people); + result = true; + } + + return result; } -T2People* T2PeoplePtrList::GetItemAt(int) const { +T2People* T2PeoplePtrList::GetItemAt(int index) const { + T2People *people; + + if (!FetchItemAt(index, &people)) + people = NULL; + + return people; } -int T2PeoplePtrList::GetPeopleIndex(T2People*, int&) const { +BOOL T2PeoplePtrList::GetPeopleIndex(T2People* people, int& outIndex) const { + BOOL result = false; + + outIndex = FetchIndexOf(&people); + if (outIndex != 0) + result = true; + + return result; } -int T2PeoplePtrList::HasSpace() const { +BOOL T2PeoplePtrList::HasSpace() const { + int index; + T2People *zero = NULL; + return GetPeopleIndex(zero, index); } void T2PeoplePtrList::Clear() { + T2People *zero = NULL; + AssignItemsAt(mItemCount, 1, &zero); } -void T2PeoplePtrList::Clear(T2People*) { +void T2PeoplePtrList::Clear(T2People* people) { + int index; + if (GetPeopleIndex(people, index)) { + T2People *zero = NULL; + AssignItemsAt(1, index, &zero); + } } -void T2PeoplePtrList::SetDestination(unsigned int) { +void T2PeoplePtrList::SetDestination(unsigned int tenantID) { + LArrayIterator iterator(*this); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->SetDestination(tenantID); + } } -void T2PeoplePtrList::ChangeDestination(unsigned int) { +void T2PeoplePtrList::ChangeDestination(unsigned int tenantID) { + LArrayIterator iterator(*this); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->ChangeDestination(tenantID); + } } -void T2PeoplePtrList::SetReturn(unsigned int) { +void T2PeoplePtrList::SetReturn(unsigned int tenantID) { + LArrayIterator iterator(*this); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->SetReturn(tenantID, 0); + } } -void T2PeoplePtrList::IncStress(int) { +void T2PeoplePtrList::IncStress(int value) { + LArrayIterator iterator(*this); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->IncStress(value); + } } -void T2PeoplePtrList::IncEstimate(int) { +void T2PeoplePtrList::IncEstimate(int value) { + LArrayIterator iterator(*this); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->IncEstimate(value); + } } -int T2PeoplePtrList::InSameTenant(unsigned int) const { +BOOL T2PeoplePtrList::InSameTenant(unsigned int tenantID) const { + BOOL result = true; + LArrayIterator iterator(*this); + T2People *people; + + while (result && iterator.Next(&people)) { + if (people && people->GetCurTenantID() != tenantID) + result = false; + } + + return result; } -void T2PeoplePtrList::LoadSelf(T2Archive&, T2PeopleArrayList*) { +void T2PeoplePtrList::LoadSelf(T2Archive& archive, T2PeopleArrayList* list) { + int count; + archive >> count; + Init(count); + + for (unsigned int i = 0; i < count; i++) { + unsigned int peopleID; + archive >> peopleID; + if (peopleID) + Add(list->FindPeople(peopleID)); + } } -void T2PeoplePtrList::SaveSelf(T2Archive&) const { +void T2PeoplePtrList::SaveSelf(T2Archive& archive) const { + archive << mItemCount; + + LArrayIterator iterator(*this); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + archive << people->GetPeopleID(); + else + archive << (unsigned int) 0; + } } diff --git a/src/T2DLL/T2PeoplePtrList.h b/src/T2DLL/T2PeoplePtrList.h index 8738224..6a3b198 100644 --- a/src/T2DLL/T2PeoplePtrList.h +++ b/src/T2DLL/T2PeoplePtrList.h @@ -1,29 +1,26 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2PeoplePtrList { +class AFX_EXT_CLASS T2PeoplePtrList : public LArray { public: - T2PeoplePtrList(int); + T2PeoplePtrList(int count = 0); virtual ~T2PeoplePtrList(); -protected: - void Init(unsigned int); -public: - int Add(T2People*); - T2People* GetItemAt(int) const; - int GetPeopleIndex(T2People*, int&) const; - int HasSpace() const; + BOOL Add(T2People* people); + T2People* GetItemAt(int index) const; + BOOL GetPeopleIndex(T2People* people, int& outIndex) const; + BOOL HasSpace() const; void Clear(); - void Clear(T2People*); - void SetDestination(unsigned int); - void ChangeDestination(unsigned int); - void SetReturn(unsigned int); - void IncStress(int); - void IncEstimate(int); - int InSameTenant(unsigned int) const; - void LoadSelf(T2Archive&, T2PeopleArrayList*); - void SaveSelf(T2Archive&) const; + void Clear(T2People* people); + void SetDestination(unsigned int tenantID); + void ChangeDestination(unsigned int tenantID); + void SetReturn(unsigned int tenantID); + void IncStress(int value); + void IncEstimate(int value); + BOOL InSameTenant(unsigned int tenantID) const; + void LoadSelf(T2Archive& archive, T2PeopleArrayList* list); + void SaveSelf(T2Archive& archive) const; - T2PeoplePtrList(const T2PeoplePtrList&) {} - T2PeoplePtrList& operator=(const T2PeoplePtrList&) {} - void `default constructor closure'() {} +protected: + void Init(unsigned int count); }; diff --git a/src/T2DLL/T2PeopleTimeZoneList.cpp b/src/T2DLL/T2PeopleTimeZoneList.cpp index 8cb68ee..b9601aa 100644 --- a/src/T2DLL/T2PeopleTimeZoneList.cpp +++ b/src/T2DLL/T2PeopleTimeZoneList.cpp @@ -1,43 +1,175 @@ +#include "CResFile.h" +#include "T2Archive.h" #include "T2PeopleTimeZoneList.h" +#include "T2PeopleType.h" +#include "T2PeopleTypeArray.h" +#include "T2PoolDef.h" +#include "T2WorldDef.h" -T2PeopleTimeZoneList::T2PeopleTimeZoneList(unsigned int, unsigned int, T2WorldDef*) { +T2PeopleTimeZoneList::T2PeopleTimeZoneList(unsigned int someNum, unsigned int isFixed, T2WorldDef* worldDef) + : LArray(sizeof(T2PeopleTypeArray *)) +{ + mIsFixed = isFixed; + _20 = 0; + mHoursPerItem = 0; + mCurrentItem = 0; + mCurrentHour = 0; + mWorldDef = worldDef; + + for (unsigned int i = 0; i < someNum; i++) { + T2PeopleTypeArray *array = new T2PeopleTypeArray(isFixed); + Add(array); + } + + mHoursPerItem = 24 / someNum; } -T2PeopleTimeZoneList::T2PeopleTimeZoneList(T2Archive&, T2WorldDef*) { +T2PeopleTimeZoneList::T2PeopleTimeZoneList(T2Archive& archive, T2WorldDef* worldDef) + : LArray(sizeof(T2PeopleTypeArray *)) +{ + _20 = 0; + mWorldDef = worldDef; + + int count; + archive >> count; + + unsigned char uc; + char c; + + archive >> uc; + mIsFixed = uc != 0; + + archive >> c; + mHoursPerItem = c; + archive >> c; + mCurrentItem = c; + archive >> c; + mCurrentHour = c; + + for (int i = 0; i < count; i++) { + T2PeopleTypeArray *theArray = new T2PeopleTypeArray(archive); + Add(theArray); + } } /*virtual*/ T2PeopleTimeZoneList::~T2PeopleTimeZoneList() { + LArrayIterator iterator(*this); + T2PeopleTypeArray *theArray; + + while (iterator.Next(&theArray)) + delete theArray; } -void T2PeopleTimeZoneList::Add(T2PeopleTypeArray*) { +void T2PeopleTimeZoneList::Add(T2PeopleTypeArray* inArray) { + InsertItemsAt(1, mItemCount + 1, &inArray); } -void T2PeopleTimeZoneList::Add(T2PeopleType*, T2PoolDefDemandElem*) { +void T2PeopleTimeZoneList::Add(T2PeopleType* inPeopleType, T2PoolDefDemandElem* inDemandElem) { + LArrayIterator iterator(*this); + T2PeopleTypeArray *theArray; + unsigned int timeZoneType = 0; + + while (iterator.Next(&theArray)) { + inPeopleType->SetTimeZoneType(timeZoneType); + + TimeZoneInfo *theTimeZoneInfo = inDemandElem->GetTimeZoneInfo(timeZoneType); + CResFile resFile; + if (resFile.OpenResource(mWorldDef->mModuleHandle, theTimeZoneInfo->m0, 'PzDf')) { + T2PoolTimeZoneDef *theTimeZoneDef = new T2PoolTimeZoneDef(resFile); + theArray->Add(inPeopleType, theTimeZoneDef, theTimeZoneInfo->m4); + delete theTimeZoneDef; + } else { + CString str; + str.Format("** T2PeopleTimeZoneDef not found : %d **\r\n", theTimeZoneInfo->m0); + OutputDebugString(str); + } + + timeZoneType++; + } } -void T2PeopleTimeZoneList::Init(unsigned int, float) { +void T2PeopleTimeZoneList::Init(unsigned int someNum, float limit) { + mCurrentItem = someNum / mHoursPerItem; + mCurrentHour = someNum % mHoursPerItem; + + LArrayIterator iterator(*this); + T2PeopleTypeArray *theArray; + + while (iterator.Next(&theArray)) + theArray->InitSearchLimit(limit); } -void T2PeopleTimeZoneList::IncHour(float) { +void T2PeopleTimeZoneList::IncHour(float limit) { + mCurrentHour++; + if (mCurrentHour >= mHoursPerItem) { + T2PeopleTypeArray *thePrevArray = CurrentItem(); + if (thePrevArray) + thePrevArray->AdjustLife(); + + mCurrentHour = 0; + mCurrentItem++; + if (mCurrentItem > GetCount()) + mCurrentItem = 0; + + T2PeopleTypeArray *theNewArray = CurrentItem(); + if (theNewArray) + theNewArray->InitSearchLimit(limit); + } } -T2PeopleTypeArray* T2PeopleTimeZoneList::GetItem(int) const { +T2PeopleTypeArray* T2PeopleTimeZoneList::GetItem(int inIndex) const { + T2PeopleTypeArray *theArray; + int index = inIndex + 1; + if (!FetchItemAt(index, &theArray)) + theArray = NULL; + return theArray; } T2PeopleTypeArray* T2PeopleTimeZoneList::CurrentItem() const { + return GetItem(mCurrentItem); } -int T2PeopleTimeZoneList::Find(T2TenantMemberDef*, int, unsigned int, int) const { +BOOL T2PeopleTimeZoneList::Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + T2PeopleTypeArray *theArray = CurrentItem(); + return theArray->Find(inTenantMemberDef, inEconoType, inTransportType, inCheckOnlyFirstEconoType); } -int T2PeopleTimeZoneList::Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&) { +BOOL T2PeopleTimeZoneList::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) { + T2PeopleTypeArray *theArray = CurrentItem(); + return theArray->Call(inTenantMemberDef, inEconoType, inTransportType, outPeopleType); } -void T2PeopleTimeZoneList::DispatchRestore(T2PeopleType&) { +void T2PeopleTimeZoneList::DispatchRestore(T2PeopleType& inPeopleType) { + T2PeopleTypeArray *theArray = GetItem(inPeopleType.GetTimeZoneType()); + if (theArray) + theArray->Restore(inPeopleType); } -void T2PeopleTimeZoneList::DispatchAdd(T2PeopleType*) { +void T2PeopleTimeZoneList::DispatchAdd(T2PeopleType* inPeopleType) { + T2PeopleTypeArray *theArray = GetItem(inPeopleType->GetTimeZoneType()); + if (theArray) + theArray->Add(inPeopleType, 1); } -void T2PeopleTimeZoneList::Write(T2Archive&) { +void T2PeopleTimeZoneList::Write(T2Archive& archive) { + archive << mItemCount; + + unsigned char uc; + char c; + + uc = mIsFixed ? 1 : 0; + archive << uc; + + c = mHoursPerItem; + archive << c; + c = mCurrentItem; + archive << c; + c = mCurrentHour; + archive << c; + + for (int i = 0; i < mItemCount; i++) { + T2PeopleTypeArray *theArray = GetItem(i); + if (theArray) + theArray->Write(archive); + } } diff --git a/src/T2DLL/T2PeopleTimeZoneList.h b/src/T2DLL/T2PeopleTimeZoneList.h index 918471b..59a81b7 100644 --- a/src/T2DLL/T2PeopleTimeZoneList.h +++ b/src/T2DLL/T2PeopleTimeZoneList.h @@ -1,30 +1,34 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2PeopleTimeZoneList { +class AFX_EXT_CLASS T2PeopleTimeZoneList : public LArray { public: - T2PeopleTimeZoneList(unsigned int, unsigned int, T2WorldDef*); + T2PeopleTimeZoneList(unsigned int someNum, unsigned int isFixed, T2WorldDef* worldDef); T2PeopleTimeZoneList(T2Archive&, T2WorldDef*); virtual ~T2PeopleTimeZoneList(); -protected: - void Add(T2PeopleTypeArray*); -public: - void Add(T2PeopleType*, T2PoolDefDemandElem*); - void Init(unsigned int, float); - void IncHour(float); -protected: - T2PeopleTypeArray* GetItem(int) const; - T2PeopleTypeArray* CurrentItem() const; -public: - int Find(T2TenantMemberDef*, int, unsigned int, int) const; - int Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&); + void Add(T2PeopleType* inPeopleType, T2PoolDefDemandElem* inDemandElem); + void Init(unsigned int someNum, float limit); + void IncHour(float limit); + BOOL Find(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const; + BOOL Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType); void DispatchRestore(T2PeopleType&); void DispatchAdd(T2PeopleType*); void Write(T2Archive&); - T2PeopleTimeZoneList(const T2PeopleTimeZoneList&) {} - T2PeopleTimeZoneList& operator=(const T2PeopleTimeZoneList&) {} - int IsFixed() const {} + BOOL IsFixed() const { return mIsFixed;} + protected: - int GetNumOfTimeZone() const {} + void Add(T2PeopleTypeArray* inArray); + T2PeopleTypeArray* GetItem(int index) const; + T2PeopleTypeArray* CurrentItem() const; + + int GetNumOfTimeZone() const { return GetCount(); } + + int _20; + BOOL mIsFixed; + int mHoursPerItem; + int mCurrentItem; + int mCurrentHour; + T2WorldDef *mWorldDef; }; diff --git a/src/T2DLL/T2PeopleType.cpp b/src/T2DLL/T2PeopleType.cpp index bf456c4..96a6f95 100644 --- a/src/T2DLL/T2PeopleType.cpp +++ b/src/T2DLL/T2PeopleType.cpp @@ -49,27 +49,27 @@ void T2PeopleType::Duplicate(T2PeopleType& dest) const { dest.mEconoType = econoType; } -int T2PeopleType::Check(T2TenantMemberDef* def, int var, unsigned int flags) const { - int result = (flags & (1 << mTransportType)) != 0; +BOOL T2PeopleType::Check(T2TenantMemberDef* def, int inEconoType, unsigned int inRoute) const { + BOOL result = (inRoute & (1 << mTransportType)) != 0; if (result) result = CheckSilhouetteType(def); if (result) result = CheckSilhouetteOptionType(def->GetOptionType()); - if (result && var > -1) { - if (mEconoType < var || mEconoType >= (var + 3)) + if (result && inEconoType > -1) { + if (mEconoType < inEconoType || mEconoType >= (inEconoType + 3)) result = false; } return result; } -int T2PeopleType::CheckWithDemand(T2TenantMemberDef* def, int var) const { - return (CheckDemandType(def->GetDemandType()) && Check(def, var, 0xFF)); +BOOL T2PeopleType::CheckWithDemand(T2TenantMemberDef* def, int econoType) const { + return (CheckDemandType(def->GetDemandType()) && Check(def, econoType, 0xFF)); } -int T2PeopleType::CheckDemandType(int demandType) const { - int result = true; +BOOL T2PeopleType::CheckDemandType(int demandType) const { + BOOL result = true; if (demandType != -1 && GetDemandType() != demandType) result = false; @@ -77,8 +77,8 @@ int T2PeopleType::CheckDemandType(int demandType) const { return result; } -int T2PeopleType::CheckSilhouetteType(T2TenantMemberDef* def) const { - int result = true; +BOOL T2PeopleType::CheckSilhouetteType(T2TenantMemberDef* def) const { + BOOL result = true; int start = def->GetStartSilhouetteType(); if (start < -1) { @@ -113,8 +113,8 @@ int T2PeopleType::CheckSilhouetteType(T2TenantMemberDef* def) const { return result; } -int T2PeopleType::CheckSilhouetteOptionType(int var) const { - int result = true; +BOOL T2PeopleType::CheckSilhouetteOptionType(int var) const { + BOOL result = true; if (var > -1) { if (var & 1) { diff --git a/src/T2DLL/T2PeopleType.h b/src/T2DLL/T2PeopleType.h index cc3f7ee..063e682 100644 --- a/src/T2DLL/T2PeopleType.h +++ b/src/T2DLL/T2PeopleType.h @@ -1,7 +1,20 @@ #pragma once #include "common.h" -class T2PeopleType { +// Transport types +enum { + kTransportLobbyLeft = 0, + kTransportLobbyRight, + kTransportParking, + kTransportSubway, + kTransportShip +}; + +enum { + kEconoType7 = 7, +}; + +class AFX_EXT_CLASS T2PeopleType { public: T2PeopleType(); ~T2PeopleType(); @@ -11,8 +24,8 @@ public: int GetTimeZoneType() const; void RecoverLife(); void Duplicate(T2PeopleType&) const; - int Check(T2TenantMemberDef*, int, unsigned int) const; - int CheckWithDemand(T2TenantMemberDef*, int) const; + BOOL Check(T2TenantMemberDef*, int inEconoType, unsigned int inRoute) const; + BOOL CheckWithDemand(T2TenantMemberDef*, int econoType) const; void Read(T2Archive&); void Write(T2Archive&); @@ -23,15 +36,15 @@ public: int GetSilhouetteType() const { return mSilhouetteType; } int GetTransportType() const { return mTransportType; } int GetAge() const { - return mSilhouetteType / 8; + return mSilhouetteType >> 3; } - int IsMale() const { + BOOL IsMale() const { return (mSilhouetteType % 2) == 0; } - int IsImmortal() const { + BOOL IsImmortal() const { return (mLife == 127); } - int HasLife() const { + BOOL HasLife() const { return (mLife > 0); } void DecreaseLife() { @@ -41,9 +54,9 @@ public: int GetEconoType() const { return mEconoType; } protected: - int CheckDemandType(int) const; - int CheckSilhouetteType(T2TenantMemberDef*) const; - int CheckSilhouetteOptionType(int) const; + BOOL CheckDemandType(int) const; + BOOL CheckSilhouetteType(T2TenantMemberDef*) const; + BOOL CheckSilhouetteOptionType(int) const; unsigned int mAttribute; int mSilhouetteType; diff --git a/src/T2DLL/T2PeopleTypeArray.cpp b/src/T2DLL/T2PeopleTypeArray.cpp index c05769c..5d6ddd5 100644 --- a/src/T2DLL/T2PeopleTypeArray.cpp +++ b/src/T2DLL/T2PeopleTypeArray.cpp @@ -68,25 +68,25 @@ void T2PeopleTypeArray::InitSearchLimit(float limit) { m2C = m2C * limit; } -int T2PeopleTypeArray::Find(T2TenantMemberDef* tenantMemberDef, int a, unsigned int b, int c) const { - int result = false; +BOOL T2PeopleTypeArray::Find(T2TenantMemberDef* tenantMemberDef, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + BOOL result = false; T2PeopleType peopleType; int numOfPeople = tenantMemberDef->GetNumOfPeople(); int xxx = 0; - int yyy = a; + int econoType = inEconoType; if (numOfPeople > 1 && m24 != 0) numOfPeople = 1; for (int i = m28; !result && i <= m2C; i++) { if (FetchItemAt(i, &peopleType)) { - if (peopleType.Check(tenantMemberDef, yyy, b)) { + if (peopleType.Check(tenantMemberDef, econoType, inTransportType)) { xxx++; if (xxx >= numOfPeople) { result = true; - } else if (xxx == 1 && c) { - yyy = -1; + } else if (xxx == 1 && inCheckOnlyFirstEconoType) { + econoType = -1; } } } @@ -95,13 +95,13 @@ int T2PeopleTypeArray::Find(T2TenantMemberDef* tenantMemberDef, int a, unsigned return result; } -int T2PeopleTypeArray::Call(T2TenantMemberDef* tenantMemberDef, int a, unsigned int b, T2PeopleType& outPeopleType) { - int result = false; +BOOL T2PeopleTypeArray::Call(T2TenantMemberDef* tenantMemberDef, int inEconoType, unsigned int inTransportType, T2PeopleType& outPeopleType) { + BOOL result = false; T2PeopleType peopleType; for (int i = m28; !result && i <= m2C; i++) { if (FetchItemAt(i, &peopleType)) { - if (peopleType.Check(tenantMemberDef, a, b)) { + if (peopleType.Check(tenantMemberDef, inEconoType, inTransportType)) { result = true; outPeopleType = peopleType; if (!m24) { diff --git a/src/T2DLL/T2PeopleTypeArray.h b/src/T2DLL/T2PeopleTypeArray.h index f16734c..f9156cd 100644 --- a/src/T2DLL/T2PeopleTypeArray.h +++ b/src/T2DLL/T2PeopleTypeArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "LArray.h" -class T2PeopleTypeArray : protected LArray { +class AFX_EXT_CLASS T2PeopleTypeArray : protected LArray { public: T2PeopleTypeArray(unsigned int); T2PeopleTypeArray(T2Archive&); @@ -11,8 +11,8 @@ public: void Add(T2PeopleType*, T2PoolTimeZoneDef*, unsigned int); void AdjustLife(); void InitSearchLimit(float); - int Find(T2TenantMemberDef*, int, unsigned int, int) const; - int Call(T2TenantMemberDef*, int, unsigned int, T2PeopleType&); + BOOL Find(T2TenantMemberDef*, int inEconoType, unsigned int inTransportType, BOOL) const; + BOOL Call(T2TenantMemberDef*, int inEconoType, unsigned int inTransportType, T2PeopleType&); void Restore(T2PeopleType&); void Write(T2Archive&); protected: diff --git a/src/T2DLL/T2PlaceParamDef.h b/src/T2DLL/T2PlaceParamDef.h index b3165f4..a259740 100644 --- a/src/T2DLL/T2PlaceParamDef.h +++ b/src/T2DLL/T2PlaceParamDef.h @@ -1,12 +1,12 @@ #pragma once #include "common.h" -class T2PlaceParamDef { +class AFX_EXT_CLASS T2PlaceParamDef { public: enum EPlace { - Place_0, - Place_1, - Place_2, + Place_0, // pool + Place_1, // tenant + Place_2, // floor kMaxPlace }; diff --git a/src/T2DLL/T2PluginInfoTable.cpp b/src/T2DLL/T2PluginInfoTable.cpp index 718bc5c..7755b47 100644 --- a/src/T2DLL/T2PluginInfoTable.cpp +++ b/src/T2DLL/T2PluginInfoTable.cpp @@ -1,25 +1,127 @@ +#include "CPluginInfo.h" +#include "LArray.h" #include "T2PluginInfoTable.h" +#include "T2PluginSpecifier.h" -/*virtual*/ int T2PluginInfoTable::Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int) { +/*virtual*/ BOOL T2PluginInfoTable::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) { + return T2DlgItemTable::Create(inWindowName, inStyle, inRect, inParentWnd, inID); } -T2PluginInfoTable::T2PluginInfoTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2PluginInfoTable::T2PluginInfoTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItemImageTable(inDoc, inImageObj, inPalette) +{ + mType = 0; + mCellData = new LArray; + InsertCols(1, 0, NULL); } /*virtual*/ T2PluginInfoTable::~T2PluginInfoTable() { } -void T2PluginInfoTable::Add(CPluginInfo*) { +void T2PluginInfoTable::Add(CPluginInfo* inInfo) { + InsertRows(1, mRows, &inInfo); + mType = 1; } -void T2PluginInfoTable::Add(T2PluginSpecifier*) { +void T2PluginInfoTable::Add(T2PluginSpecifier* inSpecifier) { + InsertRows(1, mRows, &inSpecifier); + mType = 2; } -/*virtual*/ void T2PluginInfoTable::DrawCellSelf(CDC*, const TableCellT&, int) { +/*virtual*/ void T2PluginInfoTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) { + int saveDC = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + pDC->SelectObject(mFont); + pDC->SetBkMode(TRANSPARENT); + + RECT drawRect, cellFrame, clientRect; + GetClientRect(&clientRect); + if (FetchLocalCellFrame(inCell, cellFrame)) { + if (IntersectRect(&drawRect, &cellFrame, &clientRect)) { + InflateRect(&drawRect, -1, -1); + + RECT textRect; + + if (mType == 1) { + CPluginInfo *theInfo; + GetCellData(inCell, &theInfo); + if (theInfo) { + CString name; + + textRect = cellFrame; + textRect.right = textRect.left + 156; + textRect.left += 26; + theInfo->GetName(name); + pDC->DrawText(name, &textRect, DT_SINGLELINE); + + textRect = cellFrame; + textRect.right = textRect.left + 275; + textRect.left += 156; + theInfo->GetFileName(name); + pDC->DrawText(name, &textRect, DT_SINGLELINE); + } + } else if (mType == 2) { + T2PluginSpecifier *theSpecifier; + GetCellData(inCell, &theSpecifier); + + textRect = cellFrame; + textRect.right = textRect.left + 105; + textRect.left += 26; + pDC->DrawText(theSpecifier->mPluginName, &textRect, DT_SINGLELINE); + + textRect = cellFrame; + textRect.right = textRect.left + 175; + textRect.left += 106; + pDC->DrawText(theSpecifier->mPath, &textRect, DT_SINGLELINE); + + CString str; + if (theSpecifier->mIsLoaded) + str = "Load"; + textRect = cellFrame; + textRect.left += 176; + pDC->DrawText(str, &textRect, DT_SINGLELINE); + } + + if (inSelected == 1) + pDC->InvertRect(&cellFrame); + } + } + + pDC->RestoreDC(saveDC); } -/*virtual*/ int T2PluginInfoTable::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ BOOL T2PluginInfoTable::OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct) { + T2DlgItemTable::OnT2DlgItemCreate(inCreateStruct); + return false; } -/*virtual*/ int T2PluginInfoTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2PluginInfoTable::OnT2DlgItemEraseBkgnd(CDC* pDC) { + int theSave = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + RECT clientArea; + GetClientRect(&clientArea); + + CBrush theBrush; + CBrush theBGBrush; + theBGBrush.CreateSolidBrush(RGB(255, 255, 255)); + pDC->FillRect(&clientArea, &theBGBrush); + + UINT height, width; + GetTableSize(height, width); + + for (UINT y = 1; y <= height; y++) { + for (UINT x = 1; x <= width; x++) { + TableCellT cell; + cell.row = y; + cell.col = x; + DrawCell(pDC, cell); + } + } + + pDC->RestoreDC(theSave); + return true; } diff --git a/src/T2DLL/T2PluginInfoTable.h b/src/T2DLL/T2PluginInfoTable.h index 244efa3..dde9bbf 100644 --- a/src/T2DLL/T2PluginInfoTable.h +++ b/src/T2DLL/T2PluginInfoTable.h @@ -1,15 +1,19 @@ #pragma once #include "common.h" +#include "T2DlgItemImageTable.h" -class T2PluginInfoTable { +class AFX_EXT_CLASS T2PluginInfoTable : public T2DlgItemImageTable { public: - virtual int Create(const char*, unsigned long, const RECT&, CWnd*, unsigned int); - T2PluginInfoTable(T2TowerDoc*, T2ImageObj*, CPalette*); + T2PluginInfoTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2PluginInfoTable(); - void Add(CPluginInfo*); - void Add(T2PluginSpecifier*); + virtual BOOL Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID); + void Add(CPluginInfo* inInfo); + void Add(T2PluginSpecifier* inSpecifier); + protected: - virtual void DrawCellSelf(CDC*, const TableCellT&, int); - virtual int OnT2DlgItemCreate(CREATESTRUCTA*); - virtual int OnT2DlgItemEraseBkgnd(CDC*); + virtual void DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected); + virtual BOOL OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + + int mType; }; diff --git a/src/T2DLL/T2PluginLoader.h b/src/T2DLL/T2PluginLoader.h index 58faf15..aa2d5a2 100644 --- a/src/T2DLL/T2PluginLoader.h +++ b/src/T2DLL/T2PluginLoader.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2PluginLoader { +class AFX_EXT_CLASS T2PluginLoader { public: T2PluginLoader(); ~T2PluginLoader(); diff --git a/src/T2DLL/T2PluginSpecifier.h b/src/T2DLL/T2PluginSpecifier.h index c6a6eb5..37fbff5 100644 --- a/src/T2DLL/T2PluginSpecifier.h +++ b/src/T2DLL/T2PluginSpecifier.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2PluginSpecifier : public CObject { +class AFX_EXT_CLASS T2PluginSpecifier : public CObject { public: T2PluginSpecifier(); virtual void operator=(T2PluginSpecifier&); diff --git a/src/T2DLL/T2Pool.cpp b/src/T2DLL/T2Pool.cpp index 1b1d709..8d280c2 100644 --- a/src/T2DLL/T2Pool.cpp +++ b/src/T2DLL/T2Pool.cpp @@ -1,58 +1,261 @@ +#include "CResFile.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleDef.h" +#include "T2PeopleDemandList.h" +#include "T2PeopleType.h" #include "T2Pool.h" +#include "T2PoolDef.h" +#include "T2SeasonParamDef.h" +#include "T2TemplatePluginList.h" +#include "T2TenantMemberDef.h" +#include "T2TenantMemberTableDef.h" +#include "T2WorldDef.h" -T2Pool::T2Pool(T2PoolDef*, T2SeasonParamDef*, T2TemplatePluginList*, T2PeopleArrayList*, int, unsigned int, unsigned int, T2WorldDef*) { +T2Pool::T2Pool(T2PoolDef* inDef, T2SeasonParamDef* inSeason, T2TemplatePluginList* inPluginList, T2PeopleArrayList* inPeopleList, int inLevel, unsigned int inIndex, unsigned int inSomeNum, T2WorldDef* inWorldDef) { + mLevel = 0; + mSpecialFlag = inDef->Get20(); + mPopulation = 0; + mLostPopulation = 0; + mPrevPopulation = 0; + + mPoolDef = inDef; + mPlugins = inPluginList; + mPeopleList = inPeopleList; + mDemandList = new T2PeopleDemandList(mPoolDef, inSeason, inWorldDef); + + for (int level = 1; level <= inLevel; level++) + GameLevelChanged(level); + + mDemandList->Init(inIndex, inSomeNum); } -T2Pool::T2Pool(T2Archive&, T2PoolDef*, T2SeasonParamDef*, T2TemplatePluginList*, T2PeopleArrayList*, T2WorldDef*) { +T2Pool::T2Pool(T2Archive& inArchive, T2PoolDef* inDef, T2SeasonParamDef* inSeason, T2TemplatePluginList* inPluginList, T2PeopleArrayList* inPeopleList, T2WorldDef* inWorldDef) { + short s; + + inArchive >> s; + mLevel = s; + + inArchive >> mPopulation; + inArchive >> mLostPopulation; + + mPrevPopulation = mPopulation; + mSpecialFlag = inDef->Get20(); + + mPoolDef = inDef; + mPlugins = inPluginList; + mPeopleList = inPeopleList; + mDemandList = new T2PeopleDemandList(inArchive, inSeason, inWorldDef); } /*virtual*/ T2Pool::~T2Pool() { + if (mDemandList) + delete mDemandList; } -void T2Pool::GameLevelChanged(int) { +void T2Pool::GameLevelChanged(int inLevel) { + BOOL changed = (mLevel < inLevel); + mLevel = inLevel; + + if (changed) { + int resID = mPoolDef->GetGradeDefResID(mLevel); + if (resID > 0) { + HMODULE theModule = mPoolDef->GetModuleHandle(); + + CResFile resFile; + resFile.OpenResource(theModule, resID, 'PgDf'); + + T2PoolGradeDef *theGradeDef = NULL; + theGradeDef = new T2PoolGradeDef(resFile); + mDemandList->Add(theGradeDef); + delete theGradeDef; + } + } } -void T2Pool::IncHour(T2DateTime*) { +void T2Pool::IncHour(T2DateTime* inDateTime) { + mDemandList->IncHour(inDateTime->GetMonth()); + + int hour = inDateTime->Get24Hour(); + if (hour == 0) + DayChanged(); } void T2Pool::DayChanged() { + mPopulation -= mLostPopulation; + mLostPopulation = 0; } -int T2Pool::IsChangePopulation() { +BOOL T2Pool::IsChangePopulation() { + BOOL changed = false; + + if (mPopulation != mPrevPopulation) { + mPrevPopulation = mPopulation; + changed = true; + } + + return changed; } -int T2Pool::Find(T2TenantMemberDef*, int, unsigned int, int) const { +BOOL T2Pool::Find(T2TenantMemberDef* inMember, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + return mDemandList->Find(inMember, inEconoType, inTransportType, inCheckOnlyFirstEconoType); } -int T2Pool::Find(T2TenantMemberTableDef*, int, unsigned int, int) const { +BOOL T2Pool::Find(T2TenantMemberTableDef* inTable, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const { + BOOL found = false; + int numOfElem = inTable->GetNumOfElem(); + + if (numOfElem > 0) { + found = true; + int econoType = inEconoType; + BOOL checkOnlyFirstEconoType = inCheckOnlyFirstEconoType; + + for (int i = 0; found && i < numOfElem; i++) { + if ((i == 1) && inCheckOnlyFirstEconoType) { + econoType = -1; + checkOnlyFirstEconoType = false; + } + + T2TenantMemberDef *theElem = inTable->GetElem(i); + if (theElem) { + if (!Find(theElem, econoType, inTransportType, checkOnlyFirstEconoType)) + found = false; + } else { + found = false; + } + } + } + + return found; } -T2People* T2Pool::Call(T2TenantMemberDef*, int, unsigned int, unsigned int) { +T2People* T2Pool::Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, unsigned int inSpecialFlag) { + T2People *thePeople = NULL; + T2PeopleType type; + + if (mDemandList->Call(inTenantMemberDef, inEconoType, inTransportType, type)) { + thePeople = RecoverPeople(&type); + if (thePeople) + thePeople->SetSpecialFlag(inSpecialFlag); + } + + return thePeople; } -void T2Pool::Enter(T2People*) { +void T2Pool::Enter(T2People* inPeople) { + if (inPeople->IsSetSpecialFlag(kSpecialFlag2)) + inPeople->IncEstimate(-30); + + inPeople->ClearDestination(); + inPeople->UpdateEstimation(); + inPeople->ChangeStatus(kStatus1); + inPeople->SetCurrEquipID(1); + + if (inPeople->IsVIP() || inPeople->IsMaru() || inPeople->IsReggae()) + return; + + if (inPeople->IsGeneral()) { + int estimate = inPeople->GetEstimate(); + T2PeopleType type; + ShrinkPeople(inPeople, type); + + if (estimate > 200) { + mDemandList->DispatchRestore(type); + DuplicatePeople(&type); + } else if (estimate > 70) { + static int counter = 0; + mDemandList->DispatchRestore(type); + counter++; + if (counter >= 5) { + DuplicatePeople(&type); + counter = 0; + } + } else if (type.IsImmortal()) { + mDemandList->DispatchRestore(type); + } + } else { + inPeople->ClearSpecialFlag(mSpecialFlag); + } } -void T2Pool::Leave(T2People*) { +void T2Pool::Leave(T2People* inPeople) { + inPeople->SetPrevTenantType(-1); } -T2People* T2Pool::RecoverPeople(T2PeopleType*) { +T2People* T2Pool::RecoverPeople(T2PeopleType* inPeopleType) { + T2People *thePeople = NULL; + T2PeopleDef *thePeopleDef = mPlugins->FindPeopleDef(inPeopleType->GetSilhouetteType()); + + if (thePeopleDef) { + thePeople = mPeopleList->FindUnusedPeople(); + if (thePeople) { + thePeople->Initialize(thePeopleDef, inPeopleType); + thePeople->SetUsed(true); + thePeople->SetStatus(kStatus1); + + unsigned int tenantID = 1; + if (inPeopleType->GetTransportType() == kTransportLobbyRight) + tenantID++; + thePeople->SetHomeTenant(tenantID); + thePeople->SetWorkTenant(tenantID); + } + } else { + CString err; + err.Format("** Undefined people type : %d **\r\n", inPeopleType->GetSilhouetteType()); + OutputDebugString(err); + } + + mPopulation++; + return thePeople; } -void T2Pool::ShrinkPeople(T2People*, T2PeopleType&) { +void T2Pool::ShrinkPeople(T2People* inPeople, T2PeopleType& outPeopleType) { +#line 293 + _ASSERT(inPeople->GetPeopleType() != NULL); + + outPeopleType = *inPeople->GetPeopleType(); + inPeople->SetUsed(false); + mLostPopulation++; } -void T2Pool::DuplicatePeople(T2PeopleType*) { +void T2Pool::DuplicatePeople(T2PeopleType* inPeopleType) { + T2PeopleType type; + inPeopleType->Duplicate(type); + mDemandList->DispatchAdd(&type); } -void T2Pool::RemovePeople(T2People*) { +void T2Pool::RemovePeople(T2People* inPeople) { + T2PeopleType type; + ShrinkPeople(inPeople, type); + if (type.IsImmortal()) + mDemandList->DispatchRestore(type); } -T2People* T2Pool::BornVIP(int, int) { +T2People* T2Pool::BornVIP(int inSilhouetteType, int inEconoType) { + T2PeopleType type; + type.SetSilhouetteType(inSilhouetteType); + type.SetTransportType(kTransportLobbyLeft); + if (inEconoType < 0) + type.SetEconoType(kEconoType7); + else + type.SetEconoType(inEconoType); + type.SetLifeCount(127); + + return RecoverPeople(&type); } -void T2Pool::DeadVIP(T2People*) { +void T2Pool::DeadVIP(T2People* inPeople) { + T2PeopleType type; + ShrinkPeople(inPeople, type); } -void T2Pool::Write(T2Archive&) { +void T2Pool::Write(T2Archive& inArchive) { + inArchive << (short) mLevel; + inArchive << mPopulation; + inArchive << mLostPopulation; + + if (mDemandList) + mDemandList->Write(inArchive); } diff --git a/src/T2DLL/T2Pool.h b/src/T2DLL/T2Pool.h index edd9020..e91e659 100644 --- a/src/T2DLL/T2Pool.h +++ b/src/T2DLL/T2Pool.h @@ -1,33 +1,40 @@ #pragma once #include "common.h" -class T2Pool { +class AFX_EXT_CLASS T2Pool { public: - T2Pool(T2PoolDef*, T2SeasonParamDef*, T2TemplatePluginList*, T2PeopleArrayList*, int, unsigned int, unsigned int, T2WorldDef*); - T2Pool(T2Archive&, T2PoolDef*, T2SeasonParamDef*, T2TemplatePluginList*, T2PeopleArrayList*, T2WorldDef*); + T2Pool(T2PoolDef* inDef, T2SeasonParamDef* inSeason, T2TemplatePluginList* inPluginList, T2PeopleArrayList* inPeopleList, int inLevel, unsigned int inIndex, unsigned int inSomeNum, T2WorldDef* inWorldDef); + T2Pool(T2Archive& inArchive, T2PoolDef* inDef, T2SeasonParamDef* inSeason, T2TemplatePluginList* inPluginList, T2PeopleArrayList* inPeopleList, T2WorldDef* inWorldDef); virtual ~T2Pool(); - void GameLevelChanged(int); - void IncHour(T2DateTime*); -protected: - void DayChanged(); -public: - int IsChangePopulation(); - int Find(T2TenantMemberDef*, int, unsigned int, int) const; - int Find(T2TenantMemberTableDef*, int, unsigned int, int) const; - T2People* Call(T2TenantMemberDef*, int, unsigned int, unsigned int); - void Enter(T2People*); - void Leave(T2People*); + void GameLevelChanged(int inLevel); + void IncHour(T2DateTime* inDateTime); + BOOL IsChangePopulation(); + BOOL Find(T2TenantMemberDef* inMember, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const; + BOOL Find(T2TenantMemberTableDef* inTable, int inEconoType, unsigned int inTransportType, BOOL inCheckOnlyFirstEconoType) const; + T2People* Call(T2TenantMemberDef* inTenantMemberDef, int inEconoType, unsigned int inTransportType, unsigned int inSpecialFlag); + void Enter(T2People* inPeople); + void Leave(T2People* inPeople); + void DuplicatePeople(T2PeopleType* inPeopleType); + void RemovePeople(T2People* inPeople); + T2People* BornVIP(int inSilhouetteType, int inEconoType = -1); + void DeadVIP(T2People* inPeople); + void Write(T2Archive& inArchive); + + int GetPopulation() const { return mPopulation; } + protected: - T2People* RecoverPeople(T2PeopleType*); - void ShrinkPeople(T2People*, T2PeopleType&); -public: - void DuplicatePeople(T2PeopleType*); - void RemovePeople(T2People*); - T2People* BornVIP(int, int); - void DeadVIP(T2People*); - void Write(T2Archive&); + void DayChanged(); + T2People* RecoverPeople(T2PeopleType* inPeopleType); + void ShrinkPeople(T2People* inPeople, T2PeopleType& outPeopleType); - T2Pool(const T2Pool&) {} - T2Pool& operator=(const T2Pool&) {} - int GetPopulation() const {} + T2PeopleDemandList *mDemandList; + int mLevel; + unsigned int mSpecialFlag; + int _10; + int mPopulation; + int mLostPopulation; + int mPrevPopulation; + T2PoolDef *mPoolDef; + T2TemplatePluginList *mPlugins; + T2PeopleArrayList *mPeopleList; }; diff --git a/src/T2DLL/T2PoolDef.cpp b/src/T2DLL/T2PoolDef.cpp index 8dba974..c60afbb 100644 --- a/src/T2DLL/T2PoolDef.cpp +++ b/src/T2DLL/T2PoolDef.cpp @@ -1,5 +1,6 @@ #include "CResFile.h" #include "T2PoolDef.h" +#include "T2WorldPlugin.h" T2PoolTimeZoneDef::T2PoolTimeZoneDef(CResFile &resFile) { Initialize(); @@ -132,8 +133,7 @@ T2PoolDef::~T2PoolDef() { } HINSTANCE T2PoolDef::GetModuleHandle() { - // TODO T2WorldPlugin - return 0; + return mWorldPlugin->mModuleHandle; } DemandInfo *T2PoolDef::GetDemandInfo(unsigned int index) const { @@ -143,10 +143,10 @@ DemandInfo *T2PoolDef::GetDemandInfo(unsigned int index) const { return info; } -int T2PoolDef::GetGradeDefResID(unsigned int index) const { - int resID = 0; - int index0 = index - 1; - if (index0 < 5) - resID = mGradeDefResID[index0]; - return resID; +int T2PoolDef::GetGradeDefResID(unsigned int inIndex) const { + int theResID = 0; + unsigned int index = inIndex - 1; + if (index < 5) + theResID = mGradeDefResID[index]; + return theResID; } diff --git a/src/T2DLL/T2PoolDef.h b/src/T2DLL/T2PoolDef.h index b999575..c7dd311 100644 --- a/src/T2DLL/T2PoolDef.h +++ b/src/T2DLL/T2PoolDef.h @@ -65,9 +65,10 @@ public: virtual ~T2PoolDef(); HINSTANCE GetModuleHandle(); DemandInfo *GetDemandInfo(unsigned int index) const; - int GetGradeDefResID(unsigned int index) const; + int GetGradeDefResID(unsigned int inIndex) const; unsigned char Get20() const { return m20; } + unsigned char GetNumOfDemand() const { return mNumOfDemand; } T2WorldPlugin *mWorldPlugin; int m8; diff --git a/src/T2DLL/T2PrefDialogBox.cpp b/src/T2DLL/T2PrefDialogBox.cpp index c476826..8f21e5c 100644 --- a/src/T2DLL/T2PrefDialogBox.cpp +++ b/src/T2DLL/T2PrefDialogBox.cpp @@ -1,25 +1,222 @@ +#include "CTokenizer.h" +#include "T2BitImage.h" +#include "T2DlgItemAllPurpose.h" +#include "T2DlgItemVScr.h" +#include "T2PluginInfoTable.h" +#include "T2PluginLoader.h" #include "T2PrefDialogBox.h" +#include "T2TowerDoc.h" T2PrefDialogBox::T2PrefDialogBox() { + mCurrentTab = -1; + mImage = NULL; + + mVScroll = NULL; + mAllPurpose = NULL; + mTopmostTab = NULL; + mCheckA = NULL; + mCheckB = NULL; + mButton1a = NULL; + mButton1b = NULL; + mButton2a = NULL; + mButton2b = NULL; + mAboutButton = NULL; + mMakePrefButton = NULL; } /*virtual*/ T2PrefDialogBox::~T2PrefDialogBox() { + if (mImage) + delete mImage; } -/*virtual*/ int T2PrefDialogBox::OnT2DialogCommand(unsigned int, long) { +/*virtual*/ BOOL T2PrefDialogBox::OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) { + BOOL result = false; + WORD code = HIWORD(inWParam); + WORD id = LOWORD(inWParam); + + if (id == 1002) { + if (mAllPurpose && mVScroll) { + RECT alppsRect, scrollRect; + + mAllPurpose->GetClientRect(&alppsRect); + mAllPurpose->ClientToScreen(&alppsRect); + ScreenToClient(&alppsRect); + + mVScroll->GetClientRect(&scrollRect); + mVScroll->ClientToScreen(&scrollRect); + ScreenToClient(&scrollRect); + + UnionRect(&alppsRect, &alppsRect, &scrollRect); + InvalidateRect(&alppsRect); + } else { + InvalidateRect(NULL); + } + result = true; + } else if (id == 1001 && code == 0 && mAllPurpose) { + RECT clientRect; + mAllPurpose->GetClientRect(&clientRect); + + POINT pt = mAllPurpose->GetUpPoint(); + if (PtInRect(&clientRect, pt)) { + int value = mVScroll->GetValue(); + pt.y += value * 72; + mCurrentTab = pt.y / 72; + if (mCurrentTab >= 0 && mCurrentTab <= 4) { + if (mTopmostTab) + mTopmostTab->ShowWindow(SW_HIDE); + + CWnd *theWindow = GetDlgItem(1003 + mCurrentTab); + theWindow->ShowWindow(SW_SHOWNORMAL); + theWindow->BringWindowToTop(); + + switch (mCurrentTab + 1003) { + case 1003: + mCheckA->BringWindowToTop(); + mCheckB->BringWindowToTop(); + break; + } + + mTopmostTab = theWindow; + } + } + + mAllPurpose->ClientToScreen(&clientRect); + ScreenToClient(&clientRect); + InvalidateRect(&clientRect); + } + + return result; } -/*virtual*/ int T2PrefDialogBox::OnT2EraseBkgnd(CDC*) { +/*virtual*/ BOOL T2PrefDialogBox::OnT2EraseBkgnd(CDC* pDC) { + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (mAllPurpose && mImage) { + // fuck it +#pragma var_order(rect3, allpsRect, var38, scrollValue, rect2, rect1) + RECT allpsRect; + mAllPurpose->GetClientRect(&allpsRect); + InflateRect(&allpsRect, -1, -1); + allpsRect.right += 1; + allpsRect.bottom += 1; + + mAllPurpose->ClientToScreen(&allpsRect); + ScreenToClient(&allpsRect); + + pDC->SelectStockObject(NULL_PEN); + pDC->SelectStockObject(WHITE_BRUSH); + pDC->Rectangle(&allpsRect); + + int scrollValue = mVScroll->GetValue(); + + RECT rect1, rect2, rect3; + SetRect(&rect1, 0, scrollValue * 32, 32, scrollValue * 32 + 32); + + SetRect(&rect2, 4, 4, 68, 68); + mAllPurpose->ClientToScreen(&rect2); + ScreenToClient(&rect2); + + int var38 = mImage->mBitmap.header.biHeight; + + while (rect2.top < allpsRect.bottom && rect1.top < var38) { + rect3 = rect2; + if (rect2.bottom > allpsRect.bottom) { + rect2.bottom = allpsRect.bottom; + rect1.bottom = rect1.top + ((rect2.bottom - rect2.top + 1) / 2) - 1; + } + + StretchDIBits(pDC->m_hDC, rect2.left, rect2.bottom - 1, rect2.right - rect2.left, rect2.top - rect2.bottom, rect1.left, rect1.top, rect1.right - rect1.left, rect1.bottom - rect1.top, mImage->mData, (BITMAPINFO *) &mImage->mBitmap, DIB_PAL_COLORS, SRCCOPY); + + if (scrollValue++ == mCurrentTab) { + CBrush brush(RGB(255, 0, 0)); + pDC->FrameRect(&rect3, &brush); + } + + OffsetRect(&rect1, 0, 32); + OffsetRect(&rect2, 0, 72); + } + } + + pDC->RestoreDC(save); + return true; } /*virtual*/ void T2PrefDialogBox::OnT2Create() { + T2TowerDoc *theDoc = mTowerDoc; +#line 146 + _ASSERT(theDoc != NULL); + + mVScroll = (T2DlgItemVScr *) GetDlgItem(1002); + mVScroll->SetPage(2); + mVScroll->SetRange(5); + mVScroll->SetValue(0); + + mAllPurpose = (T2DlgItemAllPurpose *) GetDlgItem(1001); + + HMODULE theModule = AfxGetInstanceHandle(); + mImage = new T2BitImage(theModule, 189, true); + + SetupPluginPref(); + + CWnd *theDialog = GetDlgItem(1003); + mCheckA = theDialog->GetDlgItem(1011); // check1 + mCheckB = theDialog->GetDlgItem(1012); // check2 + + theDialog = GetDlgItem(1004); + mButton1a = theDialog->GetDlgItem(1102); // button1 + mButton1b = theDialog->GetDlgItem(1103); // button2 + + theDialog = GetDlgItem(1005); + mButton2a = theDialog->GetDlgItem(1104); + mButton2b = theDialog->GetDlgItem(1105); + + theDialog = GetDlgItem(1006); + mAboutButton = theDialog->GetDlgItem(1106); + + theDialog = GetDlgItem(1007); + mMakePrefButton = theDialog->GetDlgItem(1107); } /*virtual*/ void T2PrefDialogBox::OnT2Destroy() { } -/*virtual*/ void T2PrefDialogBox::CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&) { +/*virtual*/ void T2PrefDialogBox::CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef) { + if (!_stricmp(inTokenizer.Current(), "ALPPS")) { + RECT theItemRect; + UINT theID = inTokenizer.NextInteger(); + theItemRect.left = inTokenizer.NextInteger(); + theItemRect.top = inTokenizer.NextInteger(); + theItemRect.right = inTokenizer.NextInteger(); + theItemRect.bottom = inTokenizer.NextInteger(); + + T2DlgItemAllPurpose *alpps = new T2DlgItemAllPurpose(mTowerDoc, mImageObj, mPalette); + alpps->Create("", inDef.flags, theItemRect, this, theID); + if (mCurrentFont >= 0) + alpps->SetFont(*mFonts[mCurrentFont]); + } else { + T2Dialog::CreateDlgItem(inTokenizer, inDef); + } } void T2PrefDialogBox::SetupPluginPref() { + CWnd *thePluginDialog = GetDlgItem(1006); +#line 204 + _ASSERT(thePluginDialog != NULL); + + T2PluginInfoTable *theTable = (T2PluginInfoTable *) thePluginDialog->GetDlgItem(1022); +#line 208 + _ASSERT(theTable != NULL); + + theTable->SetCellDataSize(sizeof(T2PluginSpecifier *)); + theTable->InsertCols(1, 0, NULL); + theTable->SetColWidth(500, 0, 0); + theTable->SetRowHeight(12, 0, 0); + + T2PluginSpecifier *theSpecifier; + POSITION pos; + mTowerDoc->mT2PluginLoader->SetTypeFilter(pos, 0); + while ((theSpecifier = mTowerDoc->mT2PluginLoader->GetNext(pos))) + theTable->Add(theSpecifier); } diff --git a/src/T2DLL/T2PrefDialogBox.h b/src/T2DLL/T2PrefDialogBox.h index 0fb015b..1f551d2 100644 --- a/src/T2DLL/T2PrefDialogBox.h +++ b/src/T2DLL/T2PrefDialogBox.h @@ -1,15 +1,31 @@ #pragma once #include "common.h" +#include "T2Dialog.h" -class T2PrefDialogBox { +class AFX_EXT_CLASS T2PrefDialogBox : public T2Dialog { public: T2PrefDialogBox(); virtual ~T2PrefDialogBox(); + protected: - virtual int OnT2DialogCommand(unsigned int, long); - virtual int OnT2EraseBkgnd(CDC*); + virtual BOOL OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam); + virtual BOOL OnT2EraseBkgnd(CDC* pDC); virtual void OnT2Create(); virtual void OnT2Destroy(); - virtual void CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&); + virtual void CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef); void SetupPluginPref(); + + int mCurrentTab; + T2BitImage *mImage; + T2DlgItemVScr *mVScroll; + T2DlgItemAllPurpose *mAllPurpose; + CWnd *mTopmostTab; + CWnd *mCheckA; + CWnd *mCheckB; + CWnd *mButton1a; + CWnd *mButton1b; + CWnd *mButton2a; + CWnd *mButton2b; + CWnd *mAboutButton; + CWnd *mMakePrefButton; }; diff --git a/src/T2DLL/T2PrefFile.h b/src/T2DLL/T2PrefFile.h index 1c33962..5484470 100644 --- a/src/T2DLL/T2PrefFile.h +++ b/src/T2DLL/T2PrefFile.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class T2PrefFile { +class AFX_EXT_CLASS T2PrefFile { public: T2PrefFile(const unsigned char* str1, const unsigned char* str2, int val); virtual ~T2PrefFile(); diff --git a/src/T2DLL/T2RegistedTenantDB.cpp b/src/T2DLL/T2RegistedTenantDB.cpp index 939d158..81d0339 100644 --- a/src/T2DLL/T2RegistedTenantDB.cpp +++ b/src/T2DLL/T2RegistedTenantDB.cpp @@ -1,31 +1,139 @@ +#include "T2EquipPtrList.h" #include "T2RegistedTenantDB.h" +#include "T2RouteNavigator.h" +#include "T2Tenant.h" +#include "T2TenantArray.h" +#include "T2TenantArrayList.h" -T2RegistedTenantDB::T2RegistedTenantDB() { +T2RegistedTenantDB::T2RegistedTenantDB() + : LArray(sizeof(T2EquipPtrList *)) +{ } /*virtual*/ T2RegistedTenantDB::~T2RegistedTenantDB() { + LArrayIterator iterator(*this); + T2EquipPtrList *equipPtrList; + + while (iterator.Next(&equipPtrList)) + delete equipPtrList; } -void T2RegistedTenantDB::Init(T2TenantArrayList*) { +void T2RegistedTenantDB::Init(T2TenantArrayList* tenantArrayList) { + LArrayIterator iterator(*tenantArrayList); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) { + for (int i = 0; i < 128; i++) { + T2Tenant *tenant = tenantArray->GetIndexTenant(i); + if (tenant->IsUsed() && !tenant->IsFloor()) + AddItem(tenant); + } + } } -void T2RegistedTenantDB::AddItem(T2Tenant*) { +void T2RegistedTenantDB::AddItem(T2Tenant* tenant) { + if (tenant->IsRegist()) { + unsigned int registID = tenant->GetRegistID(); + T2EquipPtrList *list = GetList(registID); + + if (list) { + list->AddItem(tenant); + } else { + list = new T2EquipPtrList(registID); +#line 55 + _ASSERT(list); + list->AddItem(tenant); + InsertItemsAt(1, mItemCount + 1, &list); + } + } } -void T2RegistedTenantDB::RemoveItem(T2Tenant*) { +void T2RegistedTenantDB::RemoveItem(T2Tenant* tenant) { + if (tenant->IsRegist()) { + unsigned int registID = tenant->GetRegistID(); + T2EquipPtrList *list = GetList(registID); + + if (list) + list->RemoveItem(tenant); + } } -T2EquipPtrList* T2RegistedTenantDB::GetList(unsigned int) const { +T2EquipPtrList* T2RegistedTenantDB::GetList(unsigned int registID) const { + T2EquipPtrList *result = NULL; + LArrayIterator iterator(*this); + + T2EquipPtrList *list; + while (!result && iterator.Next(&list)) { + if (list->GetAttribute() == registID) + result = list; + } + + return result; } -T2Tenant* T2RegistedTenantDB::GetFirstTenant(unsigned int) const { +T2Tenant* T2RegistedTenantDB::GetFirstTenant(unsigned int registID) const { + T2Tenant *tenant = NULL; + T2EquipPtrList *list = GetList(registID); + if (list) + tenant = (T2Tenant *) list->GetItem(1); + return tenant; } -T2Tenant* T2RegistedTenantDB::SearchToilet(const T2RouteNavigator*, POINT, int&) const { +T2Tenant* T2RegistedTenantDB::SearchToilet(const T2RouteNavigator* routeNav, POINT pt, int& outVar) const { + T2Tenant *result = NULL; + outVar = -1; + + T2EquipPtrList *list = GetList(kTenantRegistID7); + if (list) { + LArrayIterator iterator(*list); + T2Tenant *tenant; + while (outVar != 0 && iterator.Next(&tenant)) { + POINT entrancePt = tenant->GetEntrancePt(); + if (routeNav->CheckRoute(pt, entrancePt, tenant->GetCustomerSearchScore())) { + int status = tenant->GetStatus(); + if (status > kTenantStatus9 && status < kTenantStatus10000) { + if (!tenant->WillBeFull()) { + result = tenant; + outVar = 0; + } else { + outVar = -2; + } + } + } + } + } + + return result; } T2Tenant* T2RegistedTenantDB::FindEmptyParking() const { + T2Tenant *result = NULL; + + T2EquipPtrList *list = GetList(kTenantRegistID3); + if (list) { + LArrayIterator iterator(*list); + T2Tenant *tenant; + while (!result && iterator.Next(&tenant)) { + if (tenant->IsEmptyParking()) + result = tenant; + } + } + + return result; } -T2Tenant* T2RegistedTenantDB::FindHisParking(T2People*) const { +T2Tenant* T2RegistedTenantDB::FindHisParking(T2People* people) const { + T2Tenant *result = NULL; + + T2EquipPtrList *list = GetList(kTenantRegistID3); + if (list) { + LArrayIterator iterator(*list); + T2Tenant *tenant; + while (!result && iterator.Next(&tenant)) { + if (tenant->IsBelongPeople(people)) + result = tenant; + } + } + + return result; } diff --git a/src/T2DLL/T2RegistedTenantDB.h b/src/T2DLL/T2RegistedTenantDB.h index fbe75d9..365ab44 100644 --- a/src/T2DLL/T2RegistedTenantDB.h +++ b/src/T2DLL/T2RegistedTenantDB.h @@ -1,19 +1,17 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2RegistedTenantDB { +class AFX_EXT_CLASS T2RegistedTenantDB : private LArray { public: T2RegistedTenantDB(); virtual ~T2RegistedTenantDB(); - void Init(T2TenantArrayList*); - void AddItem(T2Tenant*); - void RemoveItem(T2Tenant*); - T2EquipPtrList* GetList(unsigned int) const; - T2Tenant* GetFirstTenant(unsigned int) const; + void Init(T2TenantArrayList* tenantArrayList); + void AddItem(T2Tenant* tenant); + void RemoveItem(T2Tenant* tenant); + T2EquipPtrList* GetList(unsigned int registID) const; + T2Tenant* GetFirstTenant(unsigned int registID) const; T2Tenant* SearchToilet(const T2RouteNavigator*, POINT, int&) const; T2Tenant* FindEmptyParking() const; T2Tenant* FindHisParking(T2People*) const; - - T2RegistedTenantDB(const T2RegistedTenantDB&) {} - T2RegistedTenantDB& operator=(const T2RegistedTenantDB&) {} }; diff --git a/src/T2DLL/T2RegistedTenantIterator.cpp b/src/T2DLL/T2RegistedTenantIterator.cpp index ee47955..c9597c0 100644 --- a/src/T2DLL/T2RegistedTenantIterator.cpp +++ b/src/T2DLL/T2RegistedTenantIterator.cpp @@ -1,13 +1,72 @@ +#include "T2EquipPtrList.h" +#include "T2RegistedTenantDB.h" #include "T2RegistedTenantIterator.h" +#include "T2RouteNavigator.h" +#include "T2Tenant.h" -T2RegistedTenantIterator::T2RegistedTenantIterator(const T2RegistedTenantDB*, unsigned int, const T2RouteNavigator*, POINT) { +T2RegistedTenantIterator::T2RegistedTenantIterator(const T2RegistedTenantDB* db, unsigned int registID, const T2RouteNavigator* routeNavigator, POINT point) { + mEquipPtrList = db->GetList(registID); + mRouteNavigator = routeNavigator; + + if (mEquipPtrList && mRouteNavigator) { + mIndex = 0; + mPoint = point; + } else { + mIndex = -2; + } } T2RegistedTenantIterator::~T2RegistedTenantIterator() { } -int T2RegistedTenantIterator::Next(T2Tenant*&) { +BOOL T2RegistedTenantIterator::Next(T2Tenant*& pTenant) { + BOOL result = false; + BOOL done = false; + T2Tenant *tenant = NULL; + + while (!done) { + mIndex++; + + if (mIndex > 0 && mEquipPtrList->FetchItemAt(mIndex, &tenant)) { + int status = tenant->GetStatus(); + if (status > 9 && status < 10000) { + POINT entrancePt = tenant->GetEntrancePt(); + if (mRouteNavigator->CheckRoute(mPoint, entrancePt, tenant->GetCustomerSearchScore())) { + pTenant = tenant; + result = true; + done = true; + } + } + } else { + done = true; + } + } + + return result; } -int T2RegistedTenantIterator::NextJob(T2Tenant*&) { +BOOL T2RegistedTenantIterator::NextJob(T2Tenant*& pTenant) { + BOOL result = false; + BOOL done = false; + T2Tenant *tenant = NULL; + + while (!done) { + mIndex++; + + if (mIndex > 0 && mEquipPtrList->FetchItemAt(mIndex, &tenant)) { + int status = tenant->GetStatus(); + if (status > 9 && status < 10000) { + POINT entrancePt = tenant->GetEntrancePt(); + if (mRouteNavigator->CheckRoute(mPoint, entrancePt, tenant->GetEmployeeSearchScore())) { + pTenant = tenant; + result = true; + done = true; + } + } + } else { + done = true; + } + } + + return result; } diff --git a/src/T2DLL/T2RegistedTenantIterator.h b/src/T2DLL/T2RegistedTenantIterator.h index 7f4a58a..61c06fb 100644 --- a/src/T2DLL/T2RegistedTenantIterator.h +++ b/src/T2DLL/T2RegistedTenantIterator.h @@ -1,12 +1,16 @@ #pragma once #include "common.h" -class T2RegistedTenantIterator { +class AFX_EXT_CLASS T2RegistedTenantIterator { public: - T2RegistedTenantIterator(const T2RegistedTenantDB*, unsigned int, const T2RouteNavigator*, POINT); + T2RegistedTenantIterator(const T2RegistedTenantDB* db, unsigned int registID, const T2RouteNavigator* routeNavigator, POINT point); ~T2RegistedTenantIterator(); - int Next(T2Tenant*&); - int NextJob(T2Tenant*&); + BOOL Next(T2Tenant*& pTenant); + BOOL NextJob(T2Tenant*& pTenant); - T2RegistedTenantIterator& operator=(const T2RegistedTenantIterator&) {} +protected: + T2EquipPtrList *mEquipPtrList; + const T2RouteNavigator *mRouteNavigator; + POINT mPoint; + int mIndex; }; diff --git a/src/T2DLL/T2RemoveFavoriteDialog.cpp b/src/T2DLL/T2RemoveFavoriteDialog.cpp index 1a64b4e..c10ea94 100644 --- a/src/T2DLL/T2RemoveFavoriteDialog.cpp +++ b/src/T2DLL/T2RemoveFavoriteDialog.cpp @@ -1,25 +1,130 @@ +#include "CTokenizer.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2NameTable.h" #include "T2RemoveFavoriteDialog.h" +#include "T2TowerDoc.h" -T2RemoveFavoriteDialog::T2RemoveFavoriteDialog() { +T2RemoveFavoriteDialog::T2RemoveFavoriteDialog() + : mNameType(0) +{ + mNameTable = NULL; + mCloseButton = NULL; + mDeleteButton = NULL; } /*virtual*/ T2RemoveFavoriteDialog::~T2RemoveFavoriteDialog() { } /*virtual*/ void T2RemoveFavoriteDialog::OnT2Create() { + mDeleteButton = GetDlgItem(1001); + mCloseButton = GetDlgItem(1002); + mNameTable = (T2NameTable *) GetDlgItem(1005); } -/*virtual*/ void T2RemoveFavoriteDialog::CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&) { +/*virtual*/ void T2RemoveFavoriteDialog::CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef) { + if (!_stricmp(inTokenizer.Current(), "NMTBL")) { + RECT rect; + UINT id = inTokenizer.NextInteger(); + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); + + T2NameTable *item = new T2NameTable(mTowerDoc, mImageObj, mPalette); + item->Create("", inDef.flags, rect, this, id); + item->CreateSubItem(NULL); + if (mCurrentFont >= 0) + item->SetFont(*mFonts[mCurrentFont]); + } else { + T2Dialog::CreateDlgItem(inTokenizer, inDef); + } } /*virtual*/ void T2RemoveFavoriteDialog::OnT2Destroy() { } -/*virtual*/ int T2RemoveFavoriteDialog::OnT2DialogCommand(unsigned int, long) { +/*virtual*/ BOOL T2RemoveFavoriteDialog::OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) { + WORD code = HIWORD(inWParam); + WORD id = LOWORD(inWParam); + BOOL result = false; + + if (id == 1002 && code == 0) { + DestroyWindow(); + result = true; + } else if (id == 1001 && code == 0) { +#line 67 + _ASSERT(mNameTable != NULL); + + T2Name *theName = mNameTable->GetSelectedName(); + if (theName) { + CString str; + unsigned int id; + theName->GetName(str, id); + switch (mNameType) { + case kPeopleNameType: + mNameTable->RemoveCurrentCell(); + break; + case kTenantNameType: + mNameTable->RemoveCurrentCell(); + break; + } + } + } else { + result = T2Dialog::OnT2DialogCommand(inWParam, inLParam); + } + + return result; } -void T2RemoveFavoriteDialog::InitializeForRemovePeople(T2TowerDoc*) { +void T2RemoveFavoriteDialog::InitializeForRemovePeople(T2TowerDoc* inDoc) { +#line 98 + _ASSERT(mNameTable != NULL); + mNameTable->InsertCols(1, 0, NULL); + +#line 100 + _ASSERT(inDoc->mNameDB != NULL); + + LArrayIterator iterator(*inDoc->mNameDB); + T2Name *name = NULL; + int o = 0; // unused + + while (iterator.Next(&name)) { + if (name->IsFavorite() && name->GetType() == kPeopleNameType) + mNameTable->Add(name); + } + + // "cお好み削除" + CString dialogText = "\x63\x82\xA8\x8D\x44\x82\xDD\x8D\xED\x8F\x9C"; + // "-人" + dialogText += "\x2D\x90\x6C"; + + SetWindowText(dialogText); + mNameType = kPeopleNameType; } -void T2RemoveFavoriteDialog::InitializeForRemoveTenant(T2TowerDoc*) { +void T2RemoveFavoriteDialog::InitializeForRemoveTenant(T2TowerDoc* inDoc) { +#line 122 + _ASSERT(mNameTable != NULL); + mNameTable->InsertCols(1, 0, NULL); + +#line 124 + _ASSERT(inDoc->mNameDB != NULL); + + LArrayIterator iterator(*inDoc->mNameDB); + T2Name *name = NULL; + int o = 0; // unused + + while (iterator.Next(&name)) { + if (name->IsFavorite() && name->GetType() == kTenantNameType) + mNameTable->Add(name); + } + + // "cお好み削除" + CString dialogText = "\x63\x82\xA8\x8D\x44\x82\xDD\x8D\xED\x8F\x9C"; + // "-テナント" + dialogText += "\x2D\x83\x65\x83\x69\x83\x93\x83\x67"; + + SetWindowText(dialogText); + mNameType = kTenantNameType; } diff --git a/src/T2DLL/T2RemoveFavoriteDialog.h b/src/T2DLL/T2RemoveFavoriteDialog.h index fbcebd3..50e1d00 100644 --- a/src/T2DLL/T2RemoveFavoriteDialog.h +++ b/src/T2DLL/T2RemoveFavoriteDialog.h @@ -1,16 +1,22 @@ #pragma once #include "common.h" +#include "T2Dialog.h" -class T2RemoveFavoriteDialog { +class AFX_EXT_CLASS T2RemoveFavoriteDialog : public T2Dialog { public: T2RemoveFavoriteDialog(); virtual ~T2RemoveFavoriteDialog(); + void InitializeForRemovePeople(T2TowerDoc* inDoc); + void InitializeForRemoveTenant(T2TowerDoc* inDoc); + protected: virtual void OnT2Create(); - virtual void CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&); + virtual void CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef); virtual void OnT2Destroy(); - virtual int OnT2DialogCommand(unsigned int, long); -public: - void InitializeForRemovePeople(T2TowerDoc*); - void InitializeForRemoveTenant(T2TowerDoc*); + virtual BOOL OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam); + + int mNameType; + CWnd *mCloseButton; + CWnd *mDeleteButton; + T2NameTable *mNameTable; }; diff --git a/src/T2DLL/T2Request.cpp b/src/T2DLL/T2Request.cpp index 7ae0b8e..a1607d0 100644 --- a/src/T2DLL/T2Request.cpp +++ b/src/T2DLL/T2Request.cpp @@ -1,118 +1,778 @@ +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleLinkIterator.h" #include "T2Request.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "UT2Coordinate.h" +#include <MINMAX.H> T2Request::T2Request() { + mRequestID = 0; + mMoverID = 0; + mIsGoDown = false; + mHeadPosition.y = 0; + mHeadPosition.x = 0; + mModuleIndex = -1; + mDrawWidth = 0; + m2C = 0; + m30 = 0; + mOnPeople = NULL; + mOffPeople = NULL; + mFirst = NULL; + mLast = NULL; + m44 = false; + mPeopleRemoved = false; + mNumOfContent = 0; } /*virtual*/ T2Request::~T2Request() { } void T2Request::InitRequest(unsigned int, int, const RECT&) { -} - -void T2Request::InitRequest(T2FloorInfo*, unsigned int, POINT, ERequestUpDown) { -} - -void T2Request::RemoveRequest(T2TowerDoc*) { -} - -void T2Request::RemoveContents(T2FloorInfo*) { -} - -/*virtual*/ void T2Request::SetUsed(int) { -} - -void T2Request::StopRemoved(T2TowerDoc*, int) { -} - -void T2Request::CalcArea(RECT&) { -} - -void T2Request::CalcOnArea(RECT&) { -} - -void T2Request::CalcOffArea(RECT&) { -} - -void T2Request::CalcPrevArea(RECT&) { -} - -int T2Request::CalcPersonArea(T2People*, RECT&) { -} - -/*virtual*/ int T2Request::Enter(CLink*) { -} - -/*virtual*/ int T2Request::Leave(CLink*) { +#line 34 + _ASSERT(0); +} + +void T2Request::InitRequest(T2FloorInfo* floorInfo, unsigned int moverID, POINT headPosition, ERequestUpDown upDown) { + SetUsed(true); + mMoverID = moverID; + mHeadPosition = headPosition; + mModuleIndex = -1; + m2C = 0; + m30 = 0; + mOnPeople = NULL; + mOffPeople = NULL; + mFirst = NULL; + mLast = NULL; + m44 = false; + mPeopleRemoved = false; + mNumOfContent = 0; + + if (upDown == ERequestUpDown_0) + mIsGoDown = false; + else + mIsGoDown = true; + + mDrawWidth = floorInfo->FillRequestID(mHeadPosition, upDown, mRequestID); +} + +void T2Request::RemoveRequest(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2TowerMainView *mainView = towerDoc->GetTowerMainView(); + + RemoveContents(floorInfo); + + CRect prevArea; + CRect area; + CalcPrevArea(area); + CalcArea(area); + + ERequestUpDown upDown; + if (mIsGoDown) + upDown = ERequestUpDown_1; + else + upDown = ERequestUpDown_0; + + floorInfo->RemoveRequestID(upDown, area); + SetUsed(false); + floorInfo->SetTenantDrawModeByRect(prevArea, DrawMode1); + + if (mainView) + mainView->tmv_vf128(area, false); +} + +void T2Request::RemoveContents(T2FloorInfo* floorInfo) { + T2Tenant *theFloor = floorInfo->GetFloor(mHeadPosition.y, mHeadPosition.x); +#line 102 + _ASSERT(theFloor != NULL); + + if (mOnPeople) { + theFloor->Enter(mOnPeople); + mOnPeople = NULL; + } + if (mOffPeople) { + theFloor->Enter(mOffPeople); + mOffPeople = NULL; + } + + while (mFirst) { + T2People *people = mFirst; + Leave(people); + theFloor->Enter(people); + } +} + +/*virtual*/ void T2Request::SetUsed(BOOL used) { + BOOL oldUsed = mUsed; + T2Object::SetUsed(used); +} + +void T2Request::StopRemoved(T2TowerDoc* towerDoc, int y) { + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *theFloor = theFloorInfo->GetFloor(mHeadPosition.y, mHeadPosition.x); +#line 138 + _ASSERT(theFloor != NULL); + + if (mOnPeople && mOnPeople->GetCurrDestPos().y == y) { + theFloor->Enter(mOnPeople); + mOnPeople = NULL; + } + if (mOffPeople && mOffPeople->GetCurrDestPos().y == y) { + theFloor->Enter(mOffPeople); + mOffPeople = NULL; + } + + T2PeopleLinkIterator iterator(mFirst); + T2People *people = NULL; + T2People *nextPeople = NULL; + iterator.Next(&people); + while (people) { + iterator.Next(&nextPeople); + if (people->GetCurrDestPos().y == y) { + Leave(people); + theFloor->Enter(people); + } + people = nextPeople; + nextPeople = NULL; + } +} + +void T2Request::CalcArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + outRect.left = outRect.right = mHeadPosition.x; + + if (mIsGoDown) + outRect.right = outRect.left + mDrawWidth + 2; + else + outRect.left = outRect.right - mDrawWidth - 2; +} + +void T2Request::CalcOnArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + + if (mIsGoDown) { + outRect.left = mHeadPosition.x; + outRect.right = outRect.left + 2; + } else { + outRect.right = mHeadPosition.x; + outRect.left = outRect.right - 2; + } +} + +void T2Request::CalcOffArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + + if (mIsGoDown) { + outRect.left = mHeadPosition.x; + outRect.right = outRect.left + 1; + } else { + outRect.right = mHeadPosition.x; + outRect.left = outRect.right - 1; + } +} + +void T2Request::CalcPrevArea(RECT& outRect) { + outRect.top = mHeadPosition.y; + outRect.bottom = outRect.top + 1; + + short width; + if (m2C < mDrawWidth) + width = m2C; + else + width = mDrawWidth; + + if (mIsGoDown) { + outRect.left = mHeadPosition.x + 2; + outRect.right = outRect.left + width; + } else { + outRect.right = mHeadPosition.x - 2; + outRect.left = outRect.right - width; + } +} + +BOOL T2Request::CalcPersonArea(T2People* inPeople, RECT& outRect) { + BOOL result = false; + + RECT area; + CalcArea(area); + + if (mIsGoDown) { + int h = area.left + 2; + if (mFirst) { + T2PeopleLinkIterator iterator(mFirst); + T2People *iterPeople; + while (iterator.Next(&iterPeople) && h < area.right) { + if (iterPeople == inPeople) { + outRect = area; + outRect.left = h; + outRect.right = h + iterPeople->GetWidth(); + result = true; + } else { + h += iterPeople->GetWidth(); + } + } + } + } else { + int h = area.right - 2; + if (mFirst) { + T2PeopleLinkIterator iterator(mFirst); + T2People *iterPeople; + while (iterator.Next(&iterPeople) && h > area.left) { + if (iterPeople == inPeople) { + outRect = area; + outRect.right = h; + outRect.left = h - iterPeople->GetWidth(); + result = true; + } else { + h -= iterPeople->GetWidth(); + } + } + } + } + + return result; +} + +/*virtual*/ BOOL T2Request::Enter(CLink* link) { + BOOL result = false; + + if (!mFirst) { + mFirst = (T2People *) link; + mLast = (T2People *) link; + link->SetPrev(NULL); + result = true; + } else if (mLast) { + mLast->InsertAt(link); + mLast = (T2People *) link; + result = true; + } + + if (result) { + m30 += ((T2People *) link)->GetWidth(); + mNumOfContent++; + } + + return result; +} + +/*virtual*/ BOOL T2Request::Leave(CLink* link) { + BOOL result = false; + + if (mFirst) { + if (mFirst == link) { + // element was at the start of the list + mFirst = (T2People *) link->GetNext(); + if (!mFirst) { + // list is now empty + mLast = NULL; + } else if (!mFirst->GetNext()) { + // mFirst is the only remaining element + mLast = mFirst; + } + link->Remove(); + } else if (mLast != link) { + // element was in the middle of the list + link->Remove(); + } else { + // element was at the end of the list + mLast = (T2People *) link->GetPrev(); + link->Remove(); + if (!mLast) { + // how can this even happen?? + mFirst = NULL; + } + } + + result = true; + + if (result) { + mNumOfContent--; + m30 -= ((T2People *) link)->GetWidth(); + m44 = true; + } + } + + return result; } T2People* T2Request::LeaveFirst() { -} - -int T2Request::Regist(T2TowerDoc*, T2People*) { -} - -void T2Request::ChangeOffPPLStatus(T2FloorInfo*, T2People*) { -} - -void T2Request::AddOnPeople(T2People*) { + T2People *people = NULL; + if (mFirst) { + people = mFirst; + Leave(people); + } + return people; +} + +BOOL T2Request::Regist(T2TowerDoc* towerDoc, T2People* people) { + BOOL result = false; + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + POINT position = mHeadPosition; + POINT curPos = people->GetCurPosition(); + + if (mIsGoDown) + position.x += 2; + else + position.x -= 4; + + if (curPos.y == position.y && curPos.x == position.x) { + POINT destPos = people->GetCurrDestPos(); + if (people->IsGoDown() == mIsGoDown) { + T2Mover *theMover = theFloorInfo->GetMover(mMoverID); + if (theMover && theMover->IsStopPosition(theMover->UnitToPosition(destPos.y))) { + T2Tenant *theTenant = theFloorInfo->GetTenant(people->GetCurrEquipID()); + if (theTenant) { + theTenant->Leave(people); + Enter(people); + people->SetCurrEquipID(mRequestID); + + if (mIsGoDown) + people->SetDirection(1); + else + people->SetDirection(0); + + people->ChangeStatus(6); + result = true; + } + } + } + } + + return result; +} + +void T2Request::ChangeOffPPLStatus(T2FloorInfo* floorInfo, T2People* people) { + if (mIsGoDown) + people->MoveHTo(mHeadPosition.x + 2); + else + people->MoveHTo(mHeadPosition.x - 4); + + POINT pt = people->GetCurPosition(); + T2Tenant *floor = floorInfo->GetFloor(pt.y, pt.x); + if (floor) { + floor->Enter(people); + people->ChangeStatus(4); + } else { + MessageBeep(0xFFFFFFFF); + } +} + +void T2Request::AddOnPeople(T2People* people) { + mOnPeople = people; + + if (mIsGoDown) { + people->MoveHTo(mHeadPosition.x); + people->SetDirection(1); + } else { + people->MoveHTo(mHeadPosition.x - 2); + people->SetDirection(0); + } + + people->ChangeStatus(7); } T2People* T2Request::RemoveOnPeople() { + T2People *people = NULL; + if (mOnPeople) { + people = mOnPeople; + mOnPeople = NULL; + mPeopleRemoved = true; + } + return people; } -void T2Request::AddOffPeople(T2People*) { -} - -T2People* T2Request::RemoveOffPeople() { -} - -/*virtual*/ unsigned int T2Request::Idle(T2TowerDoc*) { -} +void T2Request::AddOffPeople(T2People* people) { + mOffPeople = people; + people->mCurPosition.y = mHeadPosition.y; -/*virtual*/ void T2Request::Draw(T2TowerDoc*, const RECT&) { -} + if (mIsGoDown) { + people->MoveHTo(mHeadPosition.x); + people->SetDirection(0); + } else { + people->MoveHTo(mHeadPosition.x - 2); + people->SetDirection(1); + } -void T2Request::DrawUp(T2TowerDoc*, const RECT&) { + people->mCurrEquipID = mRequestID; + people->ChangeStatus(9); } -void T2Request::DrawDown(T2TowerDoc*, const RECT&) { -} - -void* T2Request::GetInfoClick(T2TowerDoc*, POINT) { +T2People* T2Request::RemoveOffPeople() { + T2People *people = NULL; + if (mOffPeople) { + people = mOffPeople; + mOffPeople = NULL; + mPeopleRemoved = true; + } + return people; +} + +/*virtual*/ unsigned int T2Request::Idle(T2TowerDoc* towerDoc) { + unsigned int result = 0; + T2FloorInfo *theFloorInfo = towerDoc->towerDoc_vf12C(); + + if (mNumOfContent > 0 && !IsModuleReserved()) { + T2Mover *theMover = theFloorInfo->GetMover(mMoverID); + if (theMover) + theMover->SetCheckRequest(true); + } + + T2TowerMainView *theView = towerDoc->GetTowerMainView(); +#line 541 + _ASSERT(theView != NULL); + + CRect rect; + + if (mPeopleRemoved) { + CalcOnArea(rect); + theFloorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + theView->tmv_vf128(rect, false); + } else if (mOnPeople || mOffPeople) { + CalcOnArea(rect); + theView->tmv_vf128(rect, false); + } + + if (m44) { + CalcPrevArea(rect); + theFloorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + theView->tmv_vf128(rect, false); + } + + if (CalcIncQueueArea(rect)) + theView->tmv_vf128(rect, false); + + return result; +} + +/*virtual*/ void T2Request::Draw(T2TowerDoc* towerDoc, const RECT& inRect) { + if (mIsGoDown) + DrawDown(towerDoc, inRect); + else + DrawUp(towerDoc, inRect); + DrawFinished(); +} + +void T2Request::DrawUp(T2TowerDoc* towerDoc, const RECT& inRect) { + RECT myRect; + SetRect(&myRect, mHeadPosition.x - 2, mHeadPosition.y, mHeadPosition.x, mHeadPosition.y + 1); + + if (myRect.left < inRect.right) { + if (mOffPeople) + mOffPeople->Draw(towerDoc, inRect); + if (mOnPeople) + mOnPeople->Draw(towerDoc, inRect); + } + + OffsetRect(&myRect, -2, 0); + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + while (iterator.Next(&people) && myRect.right > inRect.left) { + if (myRect.left < inRect.right) + people->Draw(towerDoc, inRect); + OffsetRect(&myRect, -people->GetWidth(), 0); + } +} + +void T2Request::DrawDown(T2TowerDoc* towerDoc, const RECT& inRect) { + RECT myRect; + SetRect(&myRect, mHeadPosition.x, mHeadPosition.y, mHeadPosition.x + 2, mHeadPosition.y + 1); + + if (myRect.right > inRect.left) { + if (mOffPeople) + mOffPeople->Draw(towerDoc, inRect); + if (mOnPeople) + mOnPeople->Draw(towerDoc, inRect); + } + + OffsetRect(&myRect, 2, 0); + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + while (iterator.Next(&people) && myRect.left < inRect.right) { + if (myRect.right > inRect.left) + people->Draw(towerDoc, inRect); + OffsetRect(&myRect, people->GetWidth(), 0); + } +} + +void* T2Request::GetInfoClick(T2TowerDoc* towerDoc, POINT pt) { + void *result; + + if (mIsGoDown) + result = GetInfoClickDown(towerDoc, pt); + else + result = GetInfoClickUp(towerDoc, pt); + + return result; } void* T2Request::GetInfoClickUp(T2TowerDoc*, POINT) { + return NULL; } void* T2Request::GetInfoClickDown(T2TowerDoc*, POINT) { -} - -void T2Request::BreakoutEmergency(T2TowerDoc*) { -} - -/*virtual*/ void T2Request::LoadSelf(T2Archive&, T2TowerDoc*) { -} - -/*virtual*/ void T2Request::SaveSelf(T2Archive&) { -} - -T2People* T2Request::FindPeople(int) const { -} - -int T2Request::CalcIncQueueArea(RECT&) const { + return NULL; +} + +void T2Request::BreakoutEmergency(T2TowerDoc* towerDoc) { + RemoveContents(towerDoc->towerDoc_vf12C()); +} + +/*virtual*/ void T2Request::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + DWORD code; + archive >> code; +#line 719 + _ASSERT(code == '<RQ>'); + + T2Object::LoadSelf(archive, towerDoc); + if (IsUsed()) { + unsigned int ui; + unsigned short us; + unsigned char uc; + short s; + char c; + + archive >> us; + mRequestID = us; + archive >> us; + mMoverID = us; + + archive >> uc; + mIsGoDown = (uc != 0); + + archive >> s; + mHeadPosition.x = s; + archive >> s; + mHeadPosition.y = s; + + archive >> c; + mModuleIndex = c; + + archive >> s; + mDrawWidth = s; + + archive >> ui; + if (ui) + mOnPeople = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mOnPeople = NULL; + archive >> ui; + if (ui) + mOffPeople = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mOffPeople = NULL; + archive >> ui; + if (ui) + mFirst = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mFirst = NULL; + archive >> ui; + if (ui) + mLast = towerDoc->mPeopleArrayList->FindPeople(ui); + else + mLast = NULL; + + if (mFirst) { + CLinkIterator iterator(mFirst); + CLink *link; + while (iterator.Next(&link)) { + mNumOfContent++; + m30 += ((T2People *) link)->GetWidth(); + } + } + } +} + +/*virtual*/ void T2Request::SaveSelf(T2Archive& archive) { + DWORD code = '<RQ>'; + archive << code; + + T2Object::SaveSelf(archive); + if (IsUsed()) { + unsigned int ui; + unsigned short us; + unsigned char uc; + short s; + char c; + + us = mRequestID; + archive << us; + us = mMoverID; + archive << us; + + uc = mIsGoDown ? 1 : 0; + archive << uc; + + archive << (short) mHeadPosition.x; + archive << (short) mHeadPosition.y; + + c = mModuleIndex; + archive << c; + + s = mDrawWidth; + archive << s; + + if (mOnPeople) + ui = mOnPeople->GetPeopleID(); + else + ui = 0; + archive << ui; + if (mOffPeople) + ui = mOffPeople->GetPeopleID(); + else + ui = 0; + archive << ui; + if (mFirst) + ui = mFirst->GetPeopleID(); + else + ui = 0; + archive << ui; + if (mLast) + ui = mLast->GetPeopleID(); + else + ui = 0; + archive << ui; + } +} + +T2People* T2Request::FindPeople(int inH) const { + T2People *result = NULL; + + if (mIsGoDown) + result = FindDownPeople(inH); + else + result = FindUpPeople(inH); + + return result; +} + +BOOL T2Request::CalcIncQueueArea(RECT& rect) const { + BOOL result = false; + + if (m30 > m2C && m2C < mDrawWidth) { + rect.top = mHeadPosition.y; + rect.bottom = rect.top + 1; + + int width; + if (m30 < mDrawWidth) + width = m30 - m2C; + else + width = mDrawWidth - m2C; + + if (mIsGoDown) { + rect.left = mHeadPosition.x + 2 + m2C; + rect.right = rect.left + width; + } else { + rect.right = mHeadPosition.x - 2 - m2C; + rect.left = rect.right - width; + } + + result = true; + } + + return result; } void T2Request::DrawFinished() { -} - -T2People* T2Request::FindUpPeople(int) const { -} - -T2People* T2Request::FindDownPeople(int) const { -} - -void T2Request::CalcValidArea(RECT&) { -} - -/*virtual*/ void T2Request::DrawHitMask(T2TowerDoc*) { + m2C = m30; + m44 = false; + mPeopleRemoved = false; +} + +T2People* T2Request::FindUpPeople(int inH) const { + T2People *result = NULL; + + int minH = mHeadPosition.x; + int maxH = minH - 2; + + if (inH >= maxH) { + if (mOffPeople) + result = mOffPeople; + else if (mOnPeople) + result = mOnPeople; + } + + if (!result) { + minH = maxH; + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + + while (!result && iterator.Next(&people)) { + maxH -= people->GetWidth(); + if (inH >= maxH && inH < minH) + result = people; + minH = maxH; + } + } + + return result; +} + +T2People* T2Request::FindDownPeople(int inH) const { + T2People *result = NULL; + + int minH = mHeadPosition.x; + int maxH = minH + 2; + + if (inH < maxH) { + if (mOffPeople) + result = mOffPeople; + else if (mOnPeople) + result = mOnPeople; + } + + if (!result) { + minH = maxH; + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + + while (!result && iterator.Next(&people)) { + maxH += people->GetWidth(); + if (inH < maxH && inH >= minH) + result = people; + minH = maxH; + } + } + + return result; +} + +void T2Request::CalcValidArea(RECT& rect) { + rect.top = mHeadPosition.y; + rect.bottom = rect.top + 1; + rect.right = mHeadPosition.x; + rect.left = rect.right; + + RECT area; + CalcArea(area); + + int width = 0; + + if (mFirst) { + width = 2; + T2PeopleLinkIterator iterator(mFirst); + T2People *people; + while (iterator.Next(&people) && width < (area.right - area.left)) + width += people->GetWidth(); + } + + if (mIsGoDown) + rect.right = rect.left + width; + else + rect.left = rect.right - width; +} + +/*virtual*/ void T2Request::DrawHitMask(T2TowerDoc* towerDoc) { + RECT area; + CalcValidArea(area); + UT2Coordinate::UnitToQD(area, towerDoc->towerDoc_vf108()); + towerDoc->towerDoc_vf10C()->FillRect(area, 1); } diff --git a/src/T2DLL/T2Request.h b/src/T2DLL/T2Request.h index 0657b3a..685f141 100644 --- a/src/T2DLL/T2Request.h +++ b/src/T2DLL/T2Request.h @@ -1,67 +1,81 @@ #pragma once #include "common.h" +#include "T2DrawableObject.h" -class T2Request { +class AFX_EXT_CLASS T2Request : public T2DrawableObject { public: T2Request(); virtual ~T2Request(); + virtual void SetUsed(BOOL); + virtual BOOL Enter(CLink*); + virtual BOOL Leave(CLink*); + virtual unsigned int Idle(T2TowerDoc*); + virtual void Draw(T2TowerDoc*, const RECT&); + virtual void DrawHitMask(T2TowerDoc*); + void InitRequest(unsigned int, int, const RECT&); void InitRequest(T2FloorInfo*, unsigned int, POINT, ERequestUpDown); void RemoveRequest(T2TowerDoc*); -protected: - void RemoveContents(T2FloorInfo*); -public: - virtual void SetUsed(int); void StopRemoved(T2TowerDoc*, int); void CalcArea(RECT&); void CalcOnArea(RECT&); void CalcOffArea(RECT&); void CalcPrevArea(RECT&); - int CalcPersonArea(T2People*, RECT&); - virtual int Enter(CLink*); - virtual int Leave(CLink*); + BOOL CalcPersonArea(T2People*, RECT&); T2People* LeaveFirst(); - int Regist(T2TowerDoc*, T2People*); + BOOL Regist(T2TowerDoc*, T2People*); void ChangeOffPPLStatus(T2FloorInfo*, T2People*); void AddOnPeople(T2People*); T2People* RemoveOnPeople(); void AddOffPeople(T2People*); T2People* RemoveOffPeople(); - virtual unsigned int Idle(T2TowerDoc*); - virtual void Draw(T2TowerDoc*, const RECT&); + void BreakoutEmergency(T2TowerDoc*); + T2People* FindPeople(int) const; + void CalcValidArea(RECT&); + + unsigned int GetRequestID() const { return mRequestID; } + unsigned int GetMoverID() const { return mMoverID; } + void MoverIDChanged(unsigned int id) { mMoverID = id; } + ERequestUpDown GetUpDown() const { return mIsGoDown ? ERequestUpDown_1 : ERequestUpDown_0; } + POINT GetHeadPosition() const { return mHeadPosition; } + int GetModuleIndex() const { return mModuleIndex; } + BOOL IsModuleReserved() const { return (mModuleIndex > -1); } + void CancelReservingModule() { mModuleIndex = -1; } + int GetDrawWidth() const { return mDrawWidth; } + void SetDrawWidth(int w) { mDrawWidth = w; } + int GetNumOfContent() const { return mNumOfContent; } + protected: + virtual void LoadSelf(T2Archive&, T2TowerDoc*); + virtual void SaveSelf(T2Archive&); + + void RemoveContents(T2FloorInfo*); void DrawUp(T2TowerDoc*, const RECT&); void DrawDown(T2TowerDoc*, const RECT&); void* GetInfoClick(T2TowerDoc*, POINT); void* GetInfoClickUp(T2TowerDoc*, POINT); void* GetInfoClickDown(T2TowerDoc*, POINT); -public: - void BreakoutEmergency(T2TowerDoc*); -protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); -public: - T2People* FindPeople(int) const; -protected: - int CalcIncQueueArea(RECT&) const; + BOOL CalcIncQueueArea(RECT&) const; void DrawFinished(); T2People* FindUpPeople(int) const; T2People* FindDownPeople(int) const; -public: - void CalcValidArea(RECT&); - virtual void DrawHitMask(T2TowerDoc*); - unsigned int GetRequestID() const {} - unsigned int GetMoverID() const {} - void MoverIDChanged(unsigned int) {} - ERequestUpDown GetUpDown() const {} - POINT GetHeadPosition() const {} - int GetModuleIndex() const {} - int IsModuleReserved() const {} - void CancelReservingModule() {} - int GetDrawWidth() const {} - void SetDrawWidth(int) {} - int GetNumOfContent() const {} - T2Request(const T2Request&) {} - T2Request& operator=(const T2Request&) {} + friend class T2RequestArray; + friend class T2ElevatorModule; + + unsigned int mRequestID; + unsigned int mMoverID; + POINT mHeadPosition; + BOOL mIsGoDown; + int mModuleIndex; + int mDrawWidth; + int m2C; + int m30; + T2People *mOnPeople; + T2People *mOffPeople; + T2People *mFirst; + T2People *mLast; + BOOL m44; + BOOL mPeopleRemoved; + int mNumOfContent; }; diff --git a/src/T2DLL/T2RequestArray.cpp b/src/T2DLL/T2RequestArray.cpp index ddaf603..65c34a3 100644 --- a/src/T2DLL/T2RequestArray.cpp +++ b/src/T2DLL/T2RequestArray.cpp @@ -1,22 +1,45 @@ #include "T2RequestArray.h" -T2RequestArray::T2RequestArray(unsigned int) { +T2RequestArray::T2RequestArray(unsigned int startID) + : T2ObjectArray(startID) +{ + for (unsigned int i = 0; i < 64; i++) + mRequests[i].mRequestID = mStartID + i; } /*virtual*/ T2RequestArray::~T2RequestArray() { } T2Request* T2RequestArray::FindUnusedRequest() { + for (int i = 0; i < 64; i++) { + if (!mRequests[i].IsUsed()) + return &mRequests[i]; + } + + return NULL; } -/*virtual*/ void T2RequestArray::DispatchIdle(T2TowerDoc*, int) { +/*virtual*/ void T2RequestArray::DispatchIdle(T2TowerDoc* towerDoc, int) { + for (int i = 0; i < 64; i++) { + if (mRequests[i].IsUsed()) + mRequests[i].Idle(towerDoc); + } } -void T2RequestArray::BreakoutEmergency(T2TowerDoc*) { +void T2RequestArray::BreakoutEmergency(T2TowerDoc* towerDoc) { + for (unsigned int i = 0; i < 64; i++) { + T2Request *request = &mRequests[i]; + if (request->IsUsed()) + request->BreakoutEmergency(towerDoc); + } } -void T2RequestArray::Read(T2Archive&, T2TowerDoc*) { +void T2RequestArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + for (int i = 0; i < 64; i++) + mRequests[i].Load(archive, towerDoc); } -void T2RequestArray::Write(T2Archive&) { +void T2RequestArray::Write(T2Archive& archive) { + for (int i = 0; i < 64; i++) + mRequests[i].Save(archive); } diff --git a/src/T2DLL/T2RequestArray.h b/src/T2DLL/T2RequestArray.h index 67eb51f..fb26990 100644 --- a/src/T2DLL/T2RequestArray.h +++ b/src/T2DLL/T2RequestArray.h @@ -1,18 +1,20 @@ #pragma once #include "common.h" +#include "T2ObjectArray.h" +#include "T2Request.h" -class T2RequestArray { +class AFX_EXT_CLASS T2RequestArray : public T2ObjectArray { public: - T2RequestArray(unsigned int); + T2RequestArray(unsigned int startID = 1000); virtual ~T2RequestArray(); + virtual void DispatchIdle(T2TowerDoc*, int); T2Request* FindUnusedRequest(); - virtual void DispatchIdle(T2TowerDoc*, int); void BreakoutEmergency(T2TowerDoc*); void Read(T2Archive&, T2TowerDoc*); void Write(T2Archive&); - T2Request* GetIndexRequest(int) {} - T2RequestArray(const T2RequestArray&) {} - T2RequestArray& operator=(const T2RequestArray&) {} - void `default constructor closure'() {} + T2Request* GetIndexRequest(int i) { return &mRequests[i]; } + +protected: + T2Request mRequests[64]; }; diff --git a/src/T2DLL/T2RequestArrayList.cpp b/src/T2DLL/T2RequestArrayList.cpp index 1bc4a9b..0b5acbb 100644 --- a/src/T2DLL/T2RequestArrayList.cpp +++ b/src/T2DLL/T2RequestArrayList.cpp @@ -1,34 +1,115 @@ +#include "T2Archive.h" +#include "T2RequestArray.h" #include "T2RequestArrayList.h" -T2RequestArrayList::T2RequestArrayList() { +T2RequestArrayList::T2RequestArrayList() + : LArray(sizeof(T2RequestArray *)) +{ + T2RequestArray *requestArray = new T2RequestArray(1000); + Add(requestArray); } /*virtual*/ T2RequestArrayList::~T2RequestArrayList() { + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + delete requestArray; } -void T2RequestArrayList::Add(T2RequestArray*) { +void T2RequestArrayList::Add(T2RequestArray* requestArray) { + InsertItemsAt(1, mItemCount + 1, &requestArray); } unsigned int T2RequestArrayList::GetItemCount() { + return GetCount(); } -T2RequestArray* T2RequestArrayList::GetItemAt(int) { +T2RequestArray* T2RequestArrayList::GetItemAt(int index) { + T2RequestArray *requestArray; + if (FetchItemAt(index, &requestArray)) + return requestArray; + else + return NULL; } -T2Request* T2RequestArrayList::GetRequestByID(unsigned int) { +T2Request* T2RequestArrayList::GetRequestByID(unsigned int requestID) { + if (requestID == 0) + return NULL; + if (requestID < 1000) + return NULL; + + int group = (requestID - 1000) / 64; + int indexInGroup = (requestID - 1000) % 64; + T2RequestArray *requestArray = GetItemAt(group + 1); + if (requestArray) + return requestArray->GetIndexRequest(indexInGroup); + else + return NULL; } T2Request* T2RequestArrayList::FindUnusedRequest() { + T2Request *result = NULL; + LArrayIterator iterator(*this); + T2RequestArray *requestArray = NULL; + + while (!result && iterator.Next(&requestArray)) { + result = requestArray->FindUnusedRequest(); + } + + if (!result) { + unsigned int newStartID = 1000; + if (requestArray) + newStartID = requestArray->GetStartID() + 64; + + requestArray = new T2RequestArray(newStartID); + if (requestArray) { + Add(requestArray); + result = requestArray->FindUnusedRequest(); + } + } + + return result; } -void T2RequestArrayList::BreakoutEmergency(T2TowerDoc*) { +void T2RequestArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + requestArray->BreakoutEmergency(towerDoc); } -void T2RequestArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2RequestArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + int count; + archive >> count; + + RemoveItemsAt(GetCount(), 1); + unsigned int startID = 1000; + + for (int i = 0; i < count; i++) { + T2RequestArray *requestArray = new T2RequestArray(startID); + requestArray->Read(archive, towerDoc); + Add(requestArray); + startID += 64; + } } -void T2RequestArrayList::Write(T2Archive&) { +void T2RequestArrayList::Write(T2Archive& archive) { + int count = GetItemCount(); + archive << count; + + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + requestArray->Write(archive); } -void T2RequestArrayList::DispatchIdle(T2TowerDoc*) { +void T2RequestArrayList::DispatchIdle(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2RequestArray *requestArray; + + while (iterator.Next(&requestArray)) + requestArray->DispatchIdle(towerDoc, 0); } diff --git a/src/T2DLL/T2RequestArrayList.h b/src/T2DLL/T2RequestArrayList.h index a481e8d..1c7cd5a 100644 --- a/src/T2DLL/T2RequestArrayList.h +++ b/src/T2DLL/T2RequestArrayList.h @@ -1,7 +1,8 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2RequestArrayList { +class AFX_EXT_CLASS T2RequestArrayList : private LArray { public: T2RequestArrayList(); virtual ~T2RequestArrayList(); @@ -14,7 +15,4 @@ public: void Read(T2Archive&, T2TowerDoc*); void Write(T2Archive&); void DispatchIdle(T2TowerDoc*); - - T2RequestArrayList(const T2RequestArrayList&) {} - T2RequestArrayList& operator=(const T2RequestArrayList&) {} }; diff --git a/src/T2DLL/T2RequestIDArray.cpp b/src/T2DLL/T2RequestIDArray.cpp index 5cd2209..4228bf6 100644 --- a/src/T2DLL/T2RequestIDArray.cpp +++ b/src/T2DLL/T2RequestIDArray.cpp @@ -1,4 +1,8 @@ +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2Request.h" #include "T2RequestIDArray.h" +#include "T2TowerDoc.h" T2RequestIDArray::T2RequestIDArray() { } @@ -6,47 +10,151 @@ T2RequestIDArray::T2RequestIDArray() { /*virtual*/ T2RequestIDArray::~T2RequestIDArray() { } -void T2RequestIDArray::Init(const RECT&) { +void T2RequestIDArray::Init(const RECT& rect) { + Expand(ReqIDArrayPos_1, rect.bottom - rect.top); } unsigned int T2RequestIDArray::GetItemCount() const { + return GetCount(); } void T2RequestIDArray::AllClear() { + RemoveItemsAt(mItemCount, 1); } -void T2RequestIDArray::Expand(EReqIDArrayPos, int) { +static const unsigned int zeroID = 0; + +void T2RequestIDArray::Expand(EReqIDArrayPos pos, int count) { + int where = mItemCount + 1; + if (pos == ReqIDArrayPos_0) + where = 1; + + if (count > 0) { + int actualCount = count * 2; + for (int i = 0; i < actualCount; i++) + InsertItemsAt(1, where, &zeroID); + } else { + int actualCount = -count * 2; + for (int i = 0; i < actualCount; i++) + RemoveItemsAt(1, where); + } } -void T2RequestIDArray::SetRequestIDAt(int, ERequestUpDown, unsigned int) { +void T2RequestIDArray::SetRequestIDAt(int index, ERequestUpDown upDown, unsigned int requestID) { + AssignItemsAt(1, GetIndex(index, upDown), &requestID); } -unsigned int T2RequestIDArray::GetRequestIDAt(int, ERequestUpDown) const { +unsigned int T2RequestIDArray::GetRequestIDAt(int index, ERequestUpDown upDown) const { + unsigned int requestID = 0; + FetchItemAt(GetIndex(index, upDown), &requestID); + return requestID; } -int T2RequestIDArray::GetIndex(int, ERequestUpDown) const { +int T2RequestIDArray::GetIndex(int index, ERequestUpDown upDown) const { + int index_ = 1; + index_ += index * 2; + if (upDown == ERequestUpDown_1) + index_++; + return index_; } -int T2RequestIDArray::IsStopPosition(int) const { +BOOL T2RequestIDArray::IsStopPosition(int index) const { + BOOL result = false; + + if (GetRequestIDAt(index, ERequestUpDown_0) || GetRequestIDAt(index, ERequestUpDown_1)) + result = true; + + return result; } -void T2RequestIDArray::RemoveRequest(T2TowerDoc*, int, ERequestUpDown) { +void T2RequestIDArray::RemoveRequest(T2TowerDoc* towerDoc, int index, ERequestUpDown upDown) { + unsigned int requestID = GetRequestIDAt(index, upDown); + if (requestID) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + if (floorInfo) { + T2Request *request = floorInfo->GetRequest(requestID); + if (request) + request->RemoveRequest(towerDoc); + SetRequestIDAt(index, upDown, 0); + } + } } -void T2RequestIDArray::Union(T2RequestIDArray*) { +void T2RequestIDArray::Union(T2RequestIDArray* otherArray) { + LArrayIterator iterator(*otherArray); + unsigned int requestID; + + while (iterator.Next(&requestID)) + InsertItemsAt(1, mItemCount + 1, &requestID); } -void T2RequestIDArray::MoverIDChanged(T2FloorInfo*, unsigned int) { +void T2RequestIDArray::MoverIDChanged(T2FloorInfo* floorInfo, unsigned int moverID) { + LArrayIterator iterator(*this); + unsigned int requestID; + + while (iterator.Next(&requestID)) { + T2Request *request = floorInfo->GetRequest(requestID); + if (request) + request->MoverIDChanged(moverID); + } } -void T2RequestIDArray::StopRemoved(T2TowerDoc*, int) { +void T2RequestIDArray::StopRemoved(T2TowerDoc* towerDoc, int y) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); +#line 142 + _ASSERT(floorInfo); + + LArrayIterator iterator(*this); + unsigned int requestID; + + while (iterator.Next(&requestID)) { + if (requestID) { + T2Request *request = floorInfo->GetRequest(requestID); + if (request) + request->StopRemoved(towerDoc, y); + } + } } -void T2RequestIDArray::ModuleRemoved(T2TowerDoc*, unsigned int) { +void T2RequestIDArray::ModuleRemoved(T2TowerDoc* towerDoc, unsigned int moduleIndex) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + + LArrayIterator iterator(*this); + unsigned int requestID; + + while (iterator.Next(&requestID)) { + if (requestID) { + T2Request *request = floorInfo->GetRequest(requestID); + if (request && request->GetModuleIndex() == moduleIndex) + request->CancelReservingModule(); + } + } } -/*static*/ T2RequestIDArray* T2RequestIDArray::ReadReqIDArray(T2Archive&) { +/*static*/ T2RequestIDArray* T2RequestIDArray::ReadReqIDArray(T2Archive& archive) { + T2RequestIDArray *array = NULL; + + DWORD code; + archive >> code; + + if (code == 'RIDA') + array = new T2RequestIDArray; + + if (array) + array->ReadAsWord(archive); + + return array; } -/*static*/ void T2RequestIDArray::WriteReqIDArray(T2RequestIDArray*, T2Archive&) { +/*static*/ void T2RequestIDArray::WriteReqIDArray(T2RequestIDArray* array, T2Archive& archive) { + DWORD code; + + if (!array) { + code = 'xRqA'; + archive << code; + } else { + code = 'RIDA'; + archive << code; + array->WriteAsWord(archive); + } } diff --git a/src/T2DLL/T2RequestIDArray.h b/src/T2DLL/T2RequestIDArray.h index 3351078..33d8533 100644 --- a/src/T2DLL/T2RequestIDArray.h +++ b/src/T2DLL/T2RequestIDArray.h @@ -1,7 +1,13 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2RequestIDArray { +enum EReqIDArrayPos { + ReqIDArrayPos_0 = 0, + ReqIDArrayPos_1 = 1, +}; + +class AFX_EXT_CLASS T2RequestIDArray : private LArray { public: T2RequestIDArray(); virtual ~T2RequestIDArray(); @@ -11,18 +17,16 @@ public: void Expand(EReqIDArrayPos, int); void SetRequestIDAt(int, ERequestUpDown, unsigned int); unsigned int GetRequestIDAt(int, ERequestUpDown) const; -private: - int GetIndex(int, ERequestUpDown) const; -public: - int IsStopPosition(int) const; + BOOL IsStopPosition(int) const; void RemoveRequest(T2TowerDoc*, int, ERequestUpDown); void Union(T2RequestIDArray*); void MoverIDChanged(T2FloorInfo*, unsigned int); void StopRemoved(T2TowerDoc*, int); void ModuleRemoved(T2TowerDoc*, unsigned int); + static T2RequestIDArray* ReadReqIDArray(T2Archive&); static void WriteReqIDArray(T2RequestIDArray*, T2Archive&); - T2RequestIDArray(const T2RequestIDArray&) {} - T2RequestIDArray& operator=(const T2RequestIDArray&) {} +private: + int GetIndex(int, ERequestUpDown) const; }; diff --git a/src/T2DLL/T2RouteCEArray.cpp b/src/T2DLL/T2RouteCEArray.cpp index 7a7585b..9a2de67 100644 --- a/src/T2DLL/T2RouteCEArray.cpp +++ b/src/T2DLL/T2RouteCEArray.cpp @@ -39,6 +39,6 @@ unsigned int T2RouteCEArray::GetSameID(T2RouteCEArray* other) { return result; } -int T2RouteCEArray::HasCrossEquip() const { +BOOL T2RouteCEArray::HasCrossEquip() const { return GetCount() > 0; } diff --git a/src/T2DLL/T2RouteCEArray.h b/src/T2DLL/T2RouteCEArray.h index f29482c..b4df1fc 100644 --- a/src/T2DLL/T2RouteCEArray.h +++ b/src/T2DLL/T2RouteCEArray.h @@ -2,13 +2,13 @@ #include "common.h" #include "T2CrossEquipArray.h" -class T2RouteCEArray : public T2CrossEquipArray { +class AFX_EXT_CLASS T2RouteCEArray : public T2CrossEquipArray { public: T2RouteCEArray(); virtual ~T2RouteCEArray(); void Insert(unsigned int, unsigned int); unsigned int GetSameID(T2RouteCEArray*); - int HasCrossEquip() const; + BOOL HasCrossEquip() const; virtual DWORD GetCEClassID() { return 'RCEA'; } }; diff --git a/src/T2DLL/T2RouteNavigator.cpp b/src/T2DLL/T2RouteNavigator.cpp index 8d2e5a9..d07acb8 100644 --- a/src/T2DLL/T2RouteNavigator.cpp +++ b/src/T2DLL/T2RouteNavigator.cpp @@ -1,40 +1,203 @@ +#include "T2FloorInfo.h" +#include "T2FloorPtrList.h" +#include "T2Mover.h" +#include "T2MoverArray.h" +#include "T2MoverArrayList.h" #include "T2RouteNavigator.h" +#include "T2RoutingTable.h" +#include "T2Tenant.h" +#include "URect.h" -T2RouteNavigator::T2RouteNavigator(T2FloorInfo*) { +T2RouteNavigator::T2RouteNavigator(T2FloorInfo* inFloorInfo) { + mFloorPtrList = NULL; + + for (unsigned int index = 0; index < kMaxRouteType; index++) + mRoutingTables[index] = NULL; + + mFloorPtrList = new T2FloorPtrList(inFloorInfo->GetTenantArrayList()); + mFloorInfo = inFloorInfo; + + for (int n = 0; n < kMaxRouteType; n++) + mRoutingTables[n] = new T2RoutingTable(inFloorInfo, mFloorPtrList, n); + + LArrayIterator iterator(*inFloorInfo->GetMoverArrayList()); + T2MoverArray *theMoverArray; + + while (iterator.Next(&theMoverArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + T2Mover *theMover = theMoverArray->GetIndexMover(i); + if (theMover->IsUsed()) + MoverAdded(theMover, false); + } + } + + Update(); } /*virtual*/ T2RouteNavigator::~T2RouteNavigator() { + if (mFloorPtrList) + delete mFloorPtrList; + + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + delete mRoutingTables[n]; + } } -void T2RouteNavigator::FloorAdded(T2Tenant*, int) { +void T2RouteNavigator::FloorAdded(T2Tenant* inTenant, BOOL inFlag) { + mFloorPtrList->AddItem(inTenant); + + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + mRoutingTables[n]->FloorAdded(); + } + + if (inFlag) + Update(); } -void T2RouteNavigator::FloorRemoved(T2Tenant*, int) { +void T2RouteNavigator::FloorRemoved(T2Tenant* inTenant, BOOL inFlag) { + int index = mFloorPtrList->GetIndex(inTenant); + mFloorPtrList->RemoveItem(index); + + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + mRoutingTables[n]->FloorRemoved(index); + } + + if (inFlag) + Update(); } -void T2RouteNavigator::MoverAdded(T2Mover*, int) { +void T2RouteNavigator::MoverAdded(T2Mover* inMover, BOOL inFlag) { + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + mRoutingTables[n]->MoverAdded(inMover, inFlag); + } } -void T2RouteNavigator::MoverRemoved(T2Mover*, int) { +void T2RouteNavigator::MoverRemoved(T2Mover* inMover, BOOL inFlag) { + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + mRoutingTables[n]->MoverRemoved(inMover, inFlag); + } } -void T2RouteNavigator::MoverModified(T2Mover*, int) { +void T2RouteNavigator::MoverModified(T2Mover* inMover, BOOL inFlag) { + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + mRoutingTables[n]->MoverModified(inMover, inFlag); + } } void T2RouteNavigator::Update() { + for (int n = 0; n < kMaxRouteType; n++) { + if (mRoutingTables[n]) + mRoutingTables[n]->FullUpdate(); + } } -int T2RouteNavigator::CheckRoute(POINT, POINT, unsigned int, int) const { +BOOL T2RouteNavigator::CheckRoute(POINT inFromPt, POINT inToPt, unsigned int inSearchScore, int inRouteType) const { + BOOL result = false; + + if ((inRouteType >= 0) && (inRouteType <= kMaxRouteType) && mRoutingTables[inRouteType]) + result = mRoutingTables[inRouteType]->CheckRoute(inFromPt, inToPt, inSearchScore); + + return result; } -int T2RouteNavigator::IsConnectRouteFromLobby(POINT) const { +BOOL T2RouteNavigator::IsConnectRouteFromLobby(POINT inPt) const { + BOOL result = false; + + if (mRoutingTables[kRouteType0]) + result = mRoutingTables[kRouteType0]->IsConnectRouteFromLobby(inPt); + + return result; } -int T2RouteNavigator::GetNextRoute(POINT, POINT&, int) const { +BOOL T2RouteNavigator::GetNextRoute(POINT inFromPt, POINT& ioToPt, int inRouteType) const { + BOOL result = false; + + if (inRouteType >= 0 && inRouteType <= kMaxRouteType) { + if (mRoutingTables[inRouteType]) + result = mRoutingTables[inRouteType]->GetNextRoute(inFromPt, ioToPt); + } else if (inRouteType == kRouteTypeNeg1) { + result = GetNextRouteUsingEStair(inFromPt, ioToPt); + } + + return result; } -T2Tenant* T2RouteNavigator::SelectNearTenant(POINT, unsigned int) const { +T2Tenant* T2RouteNavigator::SelectNearTenant(POINT inPt, unsigned int inSearchScore) const { + T2Tenant *result = NULL; + + if (mRoutingTables[kRouteType0]) + result = mRoutingTables[kRouteType0]->SelectNearTenant(inPt, inSearchScore); + + return result; } -int T2RouteNavigator::GetNextRouteUsingEStair(POINT, POINT&) const { +BOOL T2RouteNavigator::GetNextRouteUsingEStair(POINT inFromPt, POINT& ioToPt) const { + BOOL foundRoute = false; + + T2Tenant *fromFloor = mFloorInfo->GetFloor(inFromPt.y, inFromPt.x); + T2Tenant *toFloor = mFloorInfo->GetFloor(ioToPt.y, ioToPt.x); + + if (fromFloor && toFloor) { + RECT fromEquipArea, toEquipArea; + fromFloor->GetEquipArea(fromEquipArea); + toFloor->GetEquipArea(toEquipArea); + + RECT searchRect = toEquipArea; + OffsetRect(&searchRect, 0, fromEquipArea.top - toEquipArea.top); + + if (IntersectRect(&searchRect, &searchRect, &fromEquipArea)) { + ioToPt.x = searchRect.left; + if (fromEquipArea.top > toEquipArea.top) + ioToPt.y = inFromPt.y - URect::Height(fromEquipArea); + else + ioToPt.y = inFromPt.y + 1; + + T2Tenant *floor = mFloorInfo->GetFloor(ioToPt.y, ioToPt.x); + if (floor) { + RECT floorArea; + floor->GetEquipArea(floorArea); + ioToPt.y = floorArea.bottom - 1; + + int hDistance; + int bestScore = 10000; + + if (fromEquipArea.left >= floorArea.left) { + hDistance = abs(fromEquipArea.left - inFromPt.x); + if (hDistance < bestScore) { + bestScore = hDistance; + ioToPt.x = searchRect.left; + } + } + + if (fromEquipArea.right <= floorArea.right) { + hDistance = abs(fromEquipArea.right - 2 - inFromPt.x); + if (hDistance < bestScore) { + bestScore = hDistance; + ioToPt.x = fromEquipArea.right - 2; + } + } + + hDistance = abs(floorArea.left - inFromPt.x); + if (hDistance < bestScore) { + bestScore = hDistance; + ioToPt.x = floorArea.left; + } + + hDistance = abs(floorArea.right - 2 - inFromPt.x); + if (hDistance < bestScore) { + ioToPt.x = floorArea.right - 2; + } + + foundRoute = true; + } + } + } + + return foundRoute; } diff --git a/src/T2DLL/T2RouteNavigator.h b/src/T2DLL/T2RouteNavigator.h index eebe34d..1ba8749 100644 --- a/src/T2DLL/T2RouteNavigator.h +++ b/src/T2DLL/T2RouteNavigator.h @@ -1,25 +1,36 @@ #pragma once #include "common.h" -class T2RouteNavigator { +enum { + kRouteTypeNeg1 = -1, + kRouteType0 = 0, + kRouteType1 = 1, + kRouteType2 = 2, + kRouteType3 = 3, + kMaxRouteType = 4 +}; + +class AFX_EXT_CLASS T2RouteNavigator { public: - T2RouteNavigator(T2FloorInfo*); + T2RouteNavigator(T2FloorInfo* inFloorInfo); virtual ~T2RouteNavigator(); - void FloorAdded(T2Tenant*, int); - void FloorRemoved(T2Tenant*, int); - void MoverAdded(T2Mover*, int); - void MoverRemoved(T2Mover*, int); - void MoverModified(T2Mover*, int); + void FloorAdded(T2Tenant* inTenant, BOOL inFlag); + void FloorRemoved(T2Tenant* inTenant, BOOL inFlag); + void MoverAdded(T2Mover* inMover, BOOL inFlag); + void MoverRemoved(T2Mover* inMover, BOOL inFlag); + void MoverModified(T2Mover* inMover, BOOL inFlag); void Update(); - int CheckRoute(POINT, POINT, unsigned int, int) const; - int IsConnectRouteFromLobby(POINT) const; - int GetNextRoute(POINT, POINT&, int) const; - T2Tenant* SelectNearTenant(POINT, unsigned int) const; + BOOL CheckRoute(POINT inFromPt, POINT inToPt, unsigned int inSearchScore, int inRouteType = kRouteType0) const; + BOOL IsConnectRouteFromLobby(POINT inPt) const; + BOOL GetNextRoute(POINT inFromPt, POINT& ioToPt, int inRouteType) const; + T2Tenant* SelectNearTenant(POINT inPt, unsigned int inSearchScore) const; + + T2FloorPtrList* GetFloorPtrList() const { return mFloorPtrList; } + protected: - int GetNextRouteUsingEStair(POINT, POINT&) const; + BOOL GetNextRouteUsingEStair(POINT inFromPt, POINT&) const; -public: - T2RouteNavigator(const T2RouteNavigator&) {} - T2RouteNavigator& operator=(const T2RouteNavigator&) {} - T2FloorPtrList* GetFloorPtrList() const {} + T2FloorPtrList *mFloorPtrList; + T2FloorInfo *mFloorInfo; + T2RoutingTable *mRoutingTables[kMaxRouteType]; }; diff --git a/src/T2DLL/T2RoutingTable.cpp b/src/T2DLL/T2RoutingTable.cpp index 8380825..c6ae7fa 100644 --- a/src/T2DLL/T2RoutingTable.cpp +++ b/src/T2DLL/T2RoutingTable.cpp @@ -1,82 +1,402 @@ +#include "T2FInfoAreaIterator.h" +#include "T2FloorInfo.h" +#include "T2FloorPtrList.h" +#include "T2Mover.h" +#include "T2MoverRoutingTable.h" #include "T2RoutingTable.h" +#include "T2Tenant.h" -T2RoutingTable::T2RoutingTable(T2FloorInfo*, T2FloorPtrList*, int) { +T2RoutingTable::T2RoutingTable(T2FloorInfo* inFloorInfo, T2FloorPtrList* inFloorPtrList, int inWhichTable) + : LArray(sizeof(T2MoverRoutingTable *)) +{ + mAttributeMask = kMoverAttrRoutingTable0 << inWhichTable; + mFloorPtrList = inFloorPtrList; + mFloorInfo = inFloorInfo; } /*virtual*/ T2RoutingTable::~T2RoutingTable() { + LArrayIterator iterator(*this); + T2MoverRoutingTable *theTable; + + while (iterator.Next(&theTable)) + delete theTable; } void T2RoutingTable::FloorAdded() { + LArrayIterator iterator(*this); + T2MoverRoutingTable *theTable; + + while (iterator.Next(&theTable)) + theTable->AddItems(1); } -void T2RoutingTable::FloorRemoved(int) { +void T2RoutingTable::FloorRemoved(int inFloorID) { + LArrayIterator iterator(*this); + T2MoverRoutingTable *theTable; + + while (iterator.Next(&theTable)) + theTable->RemoveItem(inFloorID); } -int T2RoutingTable::IsRelatedMover(T2Mover*) const { +BOOL T2RoutingTable::IsRelatedMover(T2Mover* inMover) const { + return inMover->IsSetAttribute(mAttributeMask); } -void T2RoutingTable::MoverAdded(T2Mover*, int) { +void T2RoutingTable::MoverAdded(T2Mover* inMover, BOOL inFlag) { + if (IsRelatedMover(inMover)) { + AddItem(inMover); + + if (inFlag) { + T2MoverRoutingTable *theTable = GetItem(inMover); + if (theTable) { + theTable->SetStopFloor(); + Update(); + } + } + } } -void T2RoutingTable::MoverRemoved(T2Mover*, int) { +void T2RoutingTable::MoverRemoved(T2Mover* inMover, BOOL inFlag) { + if (IsRelatedMover(inMover)) { + RemoveItem(inMover); + + if (inFlag) + FullUpdate(); + } } -void T2RoutingTable::MoverModified(T2Mover*, int) { +void T2RoutingTable::MoverModified(T2Mover* inMover, BOOL inFlag) { + if (IsRelatedMover(inMover)) { + if (inFlag) { + FullUpdate(); + } else { + T2MoverRoutingTable *theTable = GetItem(inMover); + if (theTable) { + theTable->SetStopFloor(); + Update(); + } + } + } } -void T2RoutingTable::AddItem(T2Mover*) { +void T2RoutingTable::AddItem(T2Mover* inMover) { + T2MoverRoutingTable *theMoverRoutingTable = new T2MoverRoutingTable(mFloorInfo, mFloorPtrList, inMover); +#line 162 + _ASSERT(theMoverRoutingTable != NULL); + + InsertItemsAt(1, mItemCount + 1, &theMoverRoutingTable); } -void T2RoutingTable::RemoveItem(T2Mover*) { +void T2RoutingTable::RemoveItem(T2Mover* inMover) { + RemoveItemsAt(1, GetIndex(inMover)); } -T2MoverRoutingTable* T2RoutingTable::GetItem(T2Mover*) const { +T2MoverRoutingTable* T2RoutingTable::GetItem(T2Mover* inMover) const { + T2MoverRoutingTable *theMoverRoutingTable = NULL; + LArrayIterator iterator(*this); + T2MoverRoutingTable *item; + + while (!theMoverRoutingTable && iterator.Next(&item)) { + if (item->GetMover() == inMover) + theMoverRoutingTable = item; + } + + return theMoverRoutingTable; } -int T2RoutingTable::GetElem(T2Mover*, int, T2RoutingTableElem&) const { +BOOL T2RoutingTable::GetElem(T2Mover* inMover, int inFloor, T2RoutingTableElem& outElem) const { + BOOL ok = false; + + T2MoverRoutingTable *theMoverRoutingTable = GetItem(inMover); + if (theMoverRoutingTable && theMoverRoutingTable->GetItem(inFloor, outElem)) + ok = true; + + return ok; } -int T2RoutingTable::GetIndex(T2Mover*) const { +int T2RoutingTable::GetIndex(T2Mover* inMover) const { + int result = 0; + int unused = 0; + LArrayIterator iterator(*this); + int i = 1; + T2MoverRoutingTable *theMoverRoutingTable; + + while (result == 0 && iterator.Next(&theMoverRoutingTable)) { + if (theMoverRoutingTable->GetMover() == inMover) + result = i; + else + i++; + } + + return result; } void T2RoutingTable::Update() { + BOOL working = true; + + while (working) { + working = false; + + LArrayIterator iterator1(*this); + T2MoverRoutingTable *table1; + while (iterator1.Next(&table1)) { + LArrayIterator iterator2(*this); + T2MoverRoutingTable *table2; + + while (iterator2.Next(&table2)) { + if (table1 != table2) + working |= table1->Update(table2); + } + } + } } void T2RoutingTable::FullUpdate() { + ClearData(); + + LArrayIterator iterator(*this); + T2MoverRoutingTable *theMoverRoutingTable; + + while (iterator.Next(&theMoverRoutingTable)) + theMoverRoutingTable->SetStopFloor(); + + Update(); } void T2RoutingTable::ClearData() { + LArrayIterator iterator(*this); + T2MoverRoutingTable *theMoverRoutingTable; + + while (iterator.Next(&theMoverRoutingTable)) + theMoverRoutingTable->ClearData(); } -int T2RoutingTable::CheckRoute(POINT, POINT, unsigned int) const { +BOOL T2RoutingTable::CheckRoute(POINT inFromPt, POINT inToPt, unsigned int inSearchScore) const { + BOOL result = false; + + T2Tenant *nextFloor = mFloorInfo->GetFloor(inToPt.y, inToPt.x); + int nextFloorIdx = mFloorPtrList->GetIndex(nextFloor); + + if (nextFloorIdx) { + T2Tenant *prevFloor = mFloorInfo->GetFloor(inFromPt.y, inFromPt.x); + if (prevFloor) { + if (prevFloor == nextFloor) { + if (abs(inFromPt.x - inToPt.x) <= inSearchScore) + result = true; + } else { + unsigned int prevFloorID = prevFloor->GetEquipID(); + LArrayIterator iterator(*prevFloor->GetCEArray()); + unsigned int moverID; + + while (!result && iterator.Next(&moverID)) { + T2Mover *theMover = mFloorInfo->GetMover(moverID); + if (theMover && IsRelatedMover(theMover)) { + T2MoverRoutingTable *theMoverRoutingTable = GetItem(theMover); + if (theMoverRoutingTable) { + unsigned int distance; + if (theMoverRoutingTable->GetNextRoute(inFromPt, prevFloorID, inToPt, nextFloorIdx, distance)) { + if (distance <= inSearchScore) + result = true; + } + } + } + } + } + } + } + + return result; } -int T2RoutingTable::IsConnectRouteFromLobby(POINT) const { +BOOL T2RoutingTable::IsConnectRouteFromLobby(POINT inPt) const { + BOOL result = false; + + T2Tenant *floor = mFloorInfo->GetFloor(inPt.y, inPt.x); + int floorIndex = mFloorPtrList->GetIndex(floor); + + if (floorIndex) { + T2Tenant *lobby = mFloorInfo->GetTenant(1000); + if (lobby) { + LArrayIterator iterator(*lobby->GetCEArray()); + unsigned int moverID; + + while (!result && iterator.Next(&moverID)) { + T2Mover *theMover = mFloorInfo->GetMover(moverID); + if (theMover && IsRelatedMover(theMover)) { + T2MoverRoutingTable *theMoverRoutingTable = GetItem(theMover); + if (theMoverRoutingTable) + result = theMoverRoutingTable->IsConnectRoute(floorIndex); + } + } + } + } + + return result; } -int T2RoutingTable::GetNextRoute(POINT, POINT&) const { +BOOL T2RoutingTable::GetNextRoute(POINT inFromPt, POINT& ioToPt) const { + BOOL result = false; + + POINT toPt = ioToPt; + T2Tenant *destFloor = mFloorInfo->GetFloor(toPt.y, toPt.x); + int destFloorIdx = mFloorPtrList->GetIndex(destFloor); + + if (destFloorIdx) { + T2Tenant *srcFloor = mFloorInfo->GetFloor(inFromPt.y, inFromPt.x); + if (srcFloor) { + unsigned int optimalScore = 100000; + T2Mover *optimalMover = NULL; + int srcFloorIdx = srcFloor->GetEquipID(); + + LArrayIterator iterator(*srcFloor->GetCEArray()); + unsigned int theMoverID; + + while (iterator.Next(&theMoverID)) { + T2Mover *theMover = mFloorInfo->GetMover(theMoverID); + if (theMover && IsRelatedMover(theMover)) { + T2MoverRoutingTable *theMoverRoutingTable = GetItem(theMover); + if (theMoverRoutingTable) { + POINT thisPt = toPt; + unsigned int thisScore; + if (theMoverRoutingTable->GetNextRoute(inFromPt, srcFloorIdx, thisPt, destFloorIdx, thisScore)) { + if (thisScore < optimalScore) { + optimalScore = thisScore; + optimalMover = theMover; + ioToPt = thisPt; + result |= true; + } + } + } + } + } + } + } + + return result; } -T2Tenant* T2RoutingTable::SelectNearTenant(POINT, unsigned int) const { +T2Tenant* T2RoutingTable::SelectNearTenant(POINT inPt, unsigned int inSearchScore) const { + T2Tenant *selectedTenant = NULL; + + T2Tenant *theFloor = mFloorInfo->GetFloor(inPt.y, inPt.x); + if (theFloor) { + T2CrossEquipArray *theCEArray = theFloor->GetCEArray(); + if (theCEArray) { + unsigned int first; + unsigned int numOfCE = theCEArray->GetCount(); + + if (numOfCE != 0) + first = (rand() % numOfCE) + 1; + else + first = 1; + + T2Mover *theMover = NULL; + for (unsigned int i = 0; !theMover && i < numOfCE; i++) { + int index = first + i; + if (index > numOfCE) + index -= numOfCE; + + unsigned int theMoverID; + theCEArray->FetchItemAt(index, &theMoverID); + + theMover = mFloorInfo->GetMover(theMoverID); + if (theMover && !IsRelatedMover(theMover)) + theMover = NULL; + } + + T2Tenant *flr = NULL; + unsigned int maxHDistance = inSearchScore; + int hPos = inPt.x; + + if (theMover) { + T2MoverRoutingTable *theMoverRoutingTable = GetItem(theMover); + if (theMoverRoutingTable) + flr = theMoverRoutingTable->SelectNearFloor(inPt, hPos, maxHDistance); + } + + if (!flr) + flr = theFloor; + + selectedTenant = SelectNearTenant(flr, hPos, maxHDistance); + } + } + + return selectedTenant; } -T2Tenant* T2RoutingTable::SelectNearTenant(T2Tenant*, int, unsigned int) const { +T2Tenant* T2RoutingTable::SelectNearTenant(T2Tenant* inTenant, int inH, unsigned int inSearchScore) const { + T2Tenant *selectedTenant = NULL; + + RECT searchRect; + inTenant->GetEquipArea(searchRect); + searchRect.top = searchRect.bottom - 1; + searchRect.left = inH - inSearchScore; + searchRect.right = inH + inSearchScore; + + T2FInfoAreaIterator iterator(*mFloorInfo, searchRect); + T2Tenant *theTenant; + int count = 0; + + while (iterator.NextTenant(theTenant)) { + if (!theTenant->IsFloor() && !theTenant->IsBind() && theTenant->IsTherePeople()) + count++; + } + + if (count > 0) { + int randomIndex = rand() % count; + int i = 0; + iterator.Reset(); + + while (!selectedTenant && iterator.NextTenant(theTenant)) { + if (!theTenant->IsFloor() && !theTenant->IsBind() && theTenant->IsTherePeople()) { + if (i == randomIndex) + selectedTenant = theTenant; + else + i++; + } + } + } + + return selectedTenant; } + + T2RoutingTableElem::T2RoutingTableElem() { + mNextFloorID = 0; + mScore = 0; + mTime = 0; + mFinalHPos = 0; } T2RoutingTableElem::~T2RoutingTableElem() { } -int T2RoutingTableElem::IsStopFloor() const { +BOOL T2RoutingTableElem::IsStopFloor() const { + return ((mNextFloorID != 0) && (mScore == 0)); } -void T2RoutingTableElem::SetTable(unsigned int, int) { +void T2RoutingTableElem::SetTable(unsigned int inNextFloorID, int inFinalHPos) { + mNextFloorID = inNextFloorID; + mScore = 0; + mTime = 0; + mFinalHPos = inFinalHPos; } -int T2RoutingTableElem::IsSetTable(unsigned int, unsigned int, int, int) { +BOOL T2RoutingTableElem::IsSetTable(unsigned int inNextFloorID, unsigned int inScore, int inTime, int inFinalHPos) { + BOOL result = false; + + if (mNextFloorID == 0 || mScore > inScore) { + mNextFloorID = inNextFloorID; + mScore = inScore; + mTime = inTime; + mFinalHPos = inFinalHPos; + result = true; + } + + return result; } -int T2RoutingTableElem::HasNextRoute(unsigned int) const { +BOOL T2RoutingTableElem::HasNextRoute(unsigned int inFloorID) const { + return (mNextFloorID != 0) && (mNextFloorID != inFloorID); } diff --git a/src/T2DLL/T2RoutingTable.h b/src/T2DLL/T2RoutingTable.h index a5596da..d42616b 100644 --- a/src/T2DLL/T2RoutingTable.h +++ b/src/T2DLL/T2RoutingTable.h @@ -1,54 +1,56 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2RoutingTable { +class AFX_EXT_CLASS T2RoutingTable : private LArray { public: - T2RoutingTable(T2FloorInfo*, T2FloorPtrList*, int); + T2RoutingTable(T2FloorInfo* inFloorInfo, T2FloorPtrList* inFloorPtrList, int inWhichTable); virtual ~T2RoutingTable(); void FloorAdded(); - void FloorRemoved(int); -protected: - int IsRelatedMover(T2Mover*) const; -public: - void MoverAdded(T2Mover*, int); - void MoverRemoved(T2Mover*, int); - void MoverModified(T2Mover*, int); -protected: - void AddItem(T2Mover*); - void RemoveItem(T2Mover*); - T2MoverRoutingTable* GetItem(T2Mover*) const; - int GetElem(T2Mover*, int, T2RoutingTableElem&) const; - int GetIndex(T2Mover*) const; - void Update(); -public: + void FloorRemoved(int inFloorID); + void MoverAdded(T2Mover* inMover, BOOL inFlag); + void MoverRemoved(T2Mover* inMover, BOOL inFlag); + void MoverModified(T2Mover* inMover, BOOL inFlag); void FullUpdate(); + BOOL CheckRoute(POINT inFromPt, POINT inToPt, unsigned int inSearchScore) const; + BOOL IsConnectRouteFromLobby(POINT inPt) const; + BOOL GetNextRoute(POINT inFromPt, POINT& ioToPt) const; + T2Tenant* SelectNearTenant(POINT inPt, unsigned int inSearchScore) const; + protected: + BOOL IsRelatedMover(T2Mover* inMover) const; + void AddItem(T2Mover* inMover); + void RemoveItem(T2Mover* inMover); + T2MoverRoutingTable* GetItem(T2Mover* inMover) const; + BOOL GetElem(T2Mover* inMover, int inFloor, T2RoutingTableElem& outElem) const; + int GetIndex(T2Mover* inMover) const; + void Update(); void ClearData(); -public: - int CheckRoute(POINT, POINT, unsigned int) const; - int IsConnectRouteFromLobby(POINT) const; - int GetNextRoute(POINT, POINT&) const; - T2Tenant* SelectNearTenant(POINT, unsigned int) const; -protected: - T2Tenant* SelectNearTenant(T2Tenant*, int, unsigned int) const; + T2Tenant* SelectNearTenant(T2Tenant* inTenant, int inH, unsigned int inSearchScore) const; -public: - T2RoutingTable(const T2RoutingTable&) {} - T2RoutingTable& operator=(const T2RoutingTable&) {} + unsigned int mAttributeMask; + T2FloorPtrList *mFloorPtrList; + T2FloorInfo *mFloorInfo; }; -class T2RoutingTableElem { + +class AFX_EXT_CLASS T2RoutingTableElem { public: T2RoutingTableElem(); ~T2RoutingTableElem(); - int IsStopFloor() const; - void SetTable(unsigned int, int); - int IsSetTable(unsigned int, unsigned int, int, int); - int HasNextRoute(unsigned int) const; + BOOL IsStopFloor() const; + void SetTable(unsigned int inNextFloorID, int inFinalHPos); + BOOL IsSetTable(unsigned int inNextFloorID, unsigned int inScore, int inTime, int inFinalHPos); + BOOL HasNextRoute(unsigned int inFloorID) const; + + unsigned int GetNextFloorID() const { return mNextFloorID; } + unsigned int GetScore() const { return mScore; } + int GetTime() const { return mTime; } + int GetFinalHPos() const { return mFinalHPos; } + BOOL HasRoute() const { return (mNextFloorID != 0); } - T2RoutingTableElem& operator=(const T2RoutingTableElem&) {} - unsigned int GetNextFloorID() const {} - unsigned int GetScore() const {} - int GetTime() const {} - int GetFinalHPos() const {} - int HasRoute() const {} +protected: + unsigned int mNextFloorID; + unsigned int mScore; + int mTime; + int mFinalHPos; }; diff --git a/src/T2DLL/T2SantaClaus.cpp b/src/T2DLL/T2SantaClaus.cpp index df86e35..4aaa59d 100644 --- a/src/T2DLL/T2SantaClaus.cpp +++ b/src/T2DLL/T2SantaClaus.cpp @@ -1,25 +1,228 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2DateTime.h" +#include "T2ImageObj.h" +#include "T2MainWindow.h" #include "T2SantaClaus.h" +#include "T2Sprite.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" -T2SantaClaus::T2SantaClaus(T2TowerEvent*, CResFile*, int) { +T2SantaClaus::T2SantaClaus(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + *inResFile >> m30; + if (m30 == 0) + m30 = 32; + + mWidth = GetWorldDef()->GetWidth(); + + mPosition.x = mWidth; + mPosition.y = GetWorldDef()->mTopFloorLine; + + m48 = 0; + mCounter = 0; + + mSpriteID = 0; + mSprite = NULL; + mImage = NULL; + mImageObj = NULL; + + mSpriteWidth = 0; + mSpriteHeight = 0; + + mAttach = NULL; + mMainView = NULL; + + m6C = false; + mVisible = false; + + mBeginTime = 1440 - (mWidth / 2); } /*virtual*/ T2SantaClaus::~T2SantaClaus() { + StopEvent(mTowerEvent->mDocument); + + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; } -/*virtual*/ int T2SantaClaus::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2SantaClaus::Start(T2TowerDoc* inDoc) { + T2DateTime *theNow = inDoc->towerDoc_vf120(); + m48 = theNow ? (theNow->GetRawMinutes() - mBeginTime) : 0; + m4C = -6; + + mSprite = &inDoc->mSprite; + + mCounter = 0; + + if (!mImageObj) { + try { + mImage = new T2BitImage(inDoc->mWorldDef->mModuleHandle, 5003, true); + } catch (int err) { + return false; + } + mImageObj = new T2ImageObj; + mImageObj->AddObject(inDoc->mWorldDef->mModuleHandle, 5003, mImage); + } + + SIZE theSize; + mImageObj->GetObjectSize(0, &theSize); + mSpriteWidth = theSize.cx; + mSpriteHeight = theSize.cy; + mSpriteID = mSprite->NewSprite(*mImageObj, "SANTA", T2Sprite::ELayer_3); + + CPoint position = mPosition; + position.x -= m48; + UT2Coordinate::UnitToQD(position, 0); + + int yOffset = (m48 * 4) / m30; + position.y += yOffset; + + mSprite->MoveSprite(mSpriteID, position); + mSprite->ShowSprite(mSpriteID, true); + mVisible = true; + + mMainView = inDoc->GetTowerMainView(); + if (mMainView) { + mAttach = new T2SantaClausAttach(this, 0, true); + mMainView->AddAttachment(mAttach, NULL, true); + return true; + } else { + return false; + } } -/*virtual*/ int T2SantaClaus::IsBeginTime(unsigned int) { +/*virtual*/ BOOL T2SantaClaus::IsBeginTime(unsigned int inTime) { + m48 = inTime - mBeginTime; + return (m48 >= 0); } -/*virtual*/ int T2SantaClaus::Exec(T2TowerDoc*) { +/*virtual*/ int T2SantaClaus::Exec(T2TowerDoc* inDoc) { + if (!mMainView) + mMainView = inDoc->GetTowerMainView(); + + if (!mMainView) + return 0; + + if ((mCounter % 4) == 0) { + m48++; + + CPoint position = mPosition; + position.x -= m48; + UT2Coordinate::UnitToQD(position, 0); + + int vOffset = mCounter / m30; + position.y += vOffset; + position.y -= mSpriteWidth; + + CRect viewArea; + CRect spriteArea; + CRect intersect; + + mMainView->GetClientRect(viewArea); + viewArea.OffsetRect(mMainView->m64); + + spriteArea.SetRect(position.x, position.y, position.x + mSpriteHeight, position.y + mSpriteWidth); + + if (intersect.IntersectRect(viewArea, spriteArea)) { + Show(); + mSprite->MoveSprite(mSpriteID, position); + if (m6C) { + m4C = m48; + m6C = false; + } + + int pattern = (m48 & 1) + (((m48 - m4C) < 6) ? 2 : 0); + mSprite->ChangePattern(mSpriteID, pattern); + } else { + Hide(); + if (m48 > mWidth) + StopEvent(inDoc); + } + } + + mCounter++; + return mSprite ? 0 : 3; } -/*virtual*/ void T2SantaClaus::StopEvent(T2TowerDoc*) { +/*virtual*/ void T2SantaClaus::StopEvent(T2TowerDoc* inDoc) { + if (mSprite) { + mSprite->DeleteSprite(mSpriteID); + + delete mImageObj; + mImageObj = NULL; + delete mImage; + mImage = NULL; + + mSprite = NULL; + } + + if (mAttach) { + mMainView->RemoveAttachment(mAttach); + delete mAttach; + mAttach = NULL; + } } void T2SantaClaus::Show() { + if (!mVisible) { + mSprite->ShowSprite(mSpriteID, true); + mVisible = true; + } } void T2SantaClaus::Hide() { + if (mVisible) { + CPoint pt = mPosition; + UT2Coordinate::UnitToQD(pt, 0); + mSprite->MoveSprite(mSpriteID, pt); + + mSprite->ShowSprite(mSpriteID, false); + mVisible = false; + } +} + + + +T2SantaClausAttach::T2SantaClausAttach(T2SantaClaus* inOwner, unsigned int inMessage, BOOL inExecuteHost) + : LAttachment(inMessage, inExecuteHost) +{ + mOwner = inOwner; +} + +/*virtual*/ T2SantaClausAttach::~T2SantaClausAttach() { +} + +/*virtual*/ void T2SantaClausAttach::ExecuteSelf(unsigned int inMessage, void* ioData) { + if (inMessage == WM_LBUTTONDOWN) { + MSG *messagePtr = (MSG *) ioData; + + int id = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetSel(); + CString *theIconName = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconName(id); + T2TemplatePlugin *theTemplatePlugin = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconPlugin(id); + CProgramPlugin *theIconProgramPlugin = theTemplatePlugin->GetPlugin(); + unsigned int theIconValiation = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconValiation(id); + DWORD theIconOption = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconOption(id); + + if (theIconOption == 0 && *theIconName == "ToolInfo") { + CPoint pt(LOWORD(messagePtr->lParam), HIWORD(messagePtr->lParam)); + pt.Offset(GetCurrentT2TowerDoc()->GetTowerMainView()->m64); + + if (mOwner) { + CRect rect; + mOwner->mSprite->GetSpriteRect(mOwner->mSpriteID, rect); + mOwner->m6C = rect.PtInRect(pt); + } + } + } + + SetExecuteHost(true); } diff --git a/src/T2DLL/T2SantaClaus.h b/src/T2DLL/T2SantaClaus.h index 4e83282..9a47a8b 100644 --- a/src/T2DLL/T2SantaClaus.h +++ b/src/T2DLL/T2SantaClaus.h @@ -1,20 +1,49 @@ #pragma once #include "common.h" +#include "LAttachment.h" +#include "T2EventItem.h" -class T2SantaClaus { +class T2SantaClausAttach; + +class AFX_EXT_CLASS T2SantaClaus : public T2EventItem { public: - T2SantaClaus(T2TowerEvent*, CResFile*, int); + T2SantaClaus(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); virtual ~T2SantaClaus(); - virtual int Start(T2TowerDoc*); - virtual int IsBeginTime(unsigned int); - virtual int Exec(T2TowerDoc*); - virtual void StopEvent(T2TowerDoc*); + virtual BOOL Start(T2TowerDoc* inDoc); + virtual BOOL IsBeginTime(unsigned int inTime); + virtual int Exec(T2TowerDoc* inDoc); + virtual void StopEvent(T2TowerDoc* inDoc); + virtual DWORD GetID() { return 'SaEv'; } + private: void Show(); void Hide(); + friend class T2SantaClausAttach; + + int m30; + int mSpriteWidth; + int mSpriteHeight; + int mWidth; + CPoint mPosition; + int m48; + int m4C; + unsigned int mCounter; + int mSpriteID; + T2Sprite *mSprite; + T2BitImage *mImage; + T2ImageObj *mImageObj; + T2TowerMainView *mMainView; + T2SantaClausAttach *mAttach; + BOOL m6C; + BOOL mVisible; +}; + +class T2SantaClausAttach : public LAttachment { public: - virtual unsigned long GetID() {} - T2SantaClaus(const T2SantaClaus&) {} - T2SantaClaus& operator=(const T2SantaClaus&) {} + T2SantaClausAttach(T2SantaClaus* inOwner, unsigned int inMessage, BOOL inExecuteHost); + virtual ~T2SantaClausAttach(); +protected: + virtual void ExecuteSelf(unsigned int inMessage, void* ioData); + T2SantaClaus *mOwner; }; diff --git a/src/T2DLL/T2SearchDialog.cpp b/src/T2DLL/T2SearchDialog.cpp index 2c37751..5a5bd84 100644 --- a/src/T2DLL/T2SearchDialog.cpp +++ b/src/T2DLL/T2SearchDialog.cpp @@ -1,10 +1,126 @@ +#include "GlobalFunc.h" +#include "MoverSearchDlg.h" +#include "PeopleSearchDlg.h" +#include "T2BitImage.h" +#include "T2DlgItem.h" +#include "T2ImageObj.h" #include "T2SearchDialog.h" +#include "T2TowerDoc.h" +#include "TenantSearchDlg.h" -T2SearchDialog::T2SearchDialog(T2TowerDoc*) { +T2SearchDialog::T2SearchDialog(T2TowerDoc* inDoc) { + mDocument = inDoc; + + CRect theRect; + AfxGetMainWnd()->GetWindowRect(theRect); + + HMODULE moduleHandle = GetWorldModuleHandle(); + + mImageObj = new T2ImageObj; + mImage = new T2BitImage(moduleHandle, 7100, true); +#line 24 + _ASSERT(mImage != NULL); + mImageObj->AddObject(moduleHandle, 7100, mImage); + + T2DLGTEMPLATE theTemplate; + theTemplate.pt = theRect.CenterPoint(); + theTemplate.moduleHandle = moduleHandle; + theTemplate.resID = 7100; + Realize(mDocument, &theTemplate, mDocument, mImageObj, NULL, true, NULL, 0, true); + + mPeopleSearchDlg = new PeopleSearchDlg; + mTenantSearchDlg = new TenantSearchDlg; + mMoverSearchDlg = new MoverSearchDlg; + + POINT pt; + pt.x = 152; + pt.y = 128; + mPeopleSearchDlg->Create(mTowerDoc, moduleHandle, this, pt); + mTenantSearchDlg->Create(mTowerDoc, moduleHandle, this, pt); + mMoverSearchDlg->Create(mTowerDoc, moduleHandle, this, pt); + mPeopleSearchDlg->ShowWindow(SW_SHOW); + + T2DlgItem *thePeopleCheckBox = GetT2DlgItem(104); + thePeopleCheckBox->SetValue(1); + + m108 = 1; } /*virtual*/ T2SearchDialog::~T2SearchDialog() { + if (mImageObj) + delete mImageObj; + if (mImage) + delete mImage; } -/*virtual*/ int T2SearchDialog::OnT2DialogCommand(unsigned int, long) { +/*virtual*/ BOOL T2SearchDialog::OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) { + BOOL res = true; + + T2DlgItem *theCheck1 = GetT2DlgItem(104); + T2DlgItem *theCheck2 = GetT2DlgItem(105); + T2DlgItem *theCheck3 = GetT2DlgItem(106); + + WORD code = HIWORD(inWParam); + WORD id = LOWORD(inWParam); + + switch (id) { + case 104: + mPeopleSearchDlg->ShowWindow(SW_SHOW); + mTenantSearchDlg->ShowWindow(SW_HIDE); + mMoverSearchDlg->ShowWindow(SW_HIDE); + theCheck2->SetValue(0); + theCheck3->SetValue(0); + m108 = 1; + break; + case 105: + mPeopleSearchDlg->ShowWindow(SW_HIDE); + mTenantSearchDlg->ShowWindow(SW_SHOW); + mMoverSearchDlg->ShowWindow(SW_HIDE); + theCheck1->SetValue(0); + theCheck3->SetValue(0); + m108 = 2; + break; + case 106: + mPeopleSearchDlg->ShowWindow(SW_HIDE); + mTenantSearchDlg->ShowWindow(SW_HIDE); + mMoverSearchDlg->ShowWindow(SW_SHOW); + theCheck1->SetValue(0); + theCheck2->SetValue(0); + m108 = 3; + break; + case 107: + switch (m108) { + case 1: + mPeopleSearchDlg->DoDelete(); + break; + case 2: + mTenantSearchDlg->DoDelete(); + break; + case 3: + mMoverSearchDlg->DoDelete(); + break; + } + break; + case 108: + ShowWindow(SW_HIDE); + switch (m108) { + case 1: + mPeopleSearchDlg->DoFind(); + break; + case 2: + mTenantSearchDlg->DoFind(); + break; + case 3: + mMoverSearchDlg->DoFind(); + break; + } + case 109: + OnT2OK(); + DoClose(id); + break; + default: + res = T2Dialog::OnT2DialogCommand(inWParam, inLParam); + } + + return res; } diff --git a/src/T2DLL/T2SearchDialog.h b/src/T2DLL/T2SearchDialog.h index eaa3b4c..34cb975 100644 --- a/src/T2DLL/T2SearchDialog.h +++ b/src/T2DLL/T2SearchDialog.h @@ -1,9 +1,19 @@ #pragma once #include "common.h" +#include "T2Dialog.h" -class T2SearchDialog { +class AFX_EXT_CLASS T2SearchDialog : public T2Dialog { public: - T2SearchDialog(T2TowerDoc*); + T2SearchDialog(T2TowerDoc* inDoc); virtual ~T2SearchDialog(); - virtual int OnT2DialogCommand(unsigned int, long); + virtual BOOL OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam); + +protected: + T2TowerDoc *mDocument; + PeopleSearchDlg *mPeopleSearchDlg; + TenantSearchDlg *mTenantSearchDlg; + MoverSearchDlg *mMoverSearchDlg; + int m108; + T2ImageObj *mImageObj; + T2BitImage *mImage; }; diff --git a/src/T2DLL/T2SeasonParamDef.cpp b/src/T2DLL/T2SeasonParamDef.cpp new file mode 100644 index 0000000..d453eb3 --- /dev/null +++ b/src/T2DLL/T2SeasonParamDef.cpp @@ -0,0 +1,14 @@ +#include "CResFile.h" +#include "T2SeasonParamDef.h" + +T2SeasonParamDef::T2SeasonParamDef(CResFile &resFile) { + float divisor = 100.0f; + + for (unsigned int i = 0; i < 12; i++) { + resFile >> mElems[i].a; + mElems[i].mRate = mElems[i].a / divisor; + } +} + +/*virtual*/ T2SeasonParamDef::~T2SeasonParamDef() { +} diff --git a/src/T2DLL/T2SeasonParamDef.h b/src/T2DLL/T2SeasonParamDef.h new file mode 100644 index 0000000..5177238 --- /dev/null +++ b/src/T2DLL/T2SeasonParamDef.h @@ -0,0 +1,24 @@ +#pragma once +#include "common.h" + +// unknown name +struct T2SeasonParamDefElem { + unsigned int a; + float mRate; +}; + +class T2SeasonParamDef { +public: + T2SeasonParamDef(CResFile &resFile); + virtual ~T2SeasonParamDef(); + + float GetRate(unsigned int index) const { + float result = 0.0f; + if (index < 12) + result = mElems[index].mRate; + return result; + } + +protected: + T2SeasonParamDefElem mElems[12]; +}; diff --git a/src/T2DLL/T2SerialDialog.cpp b/src/T2DLL/T2SerialDialog.cpp new file mode 100644 index 0000000..b7f7ceb --- /dev/null +++ b/src/T2DLL/T2SerialDialog.cpp @@ -0,0 +1,98 @@ +#include "T2SerialDialog.h" + +T2SerialDialog::T2SerialDialog(CWnd *parent) + : CDialog(228, parent) +{ +} + +/*virtual*/ void T2SerialDialog::DoDataExchange(CDataExchange *pDX) { + CWnd::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(T2SerialDialog, CDialog) + ON_WM_PAINT() +END_MESSAGE_MAP() + +/*virtual*/ void T2SerialDialog::OnOK() { + GetDlgItemText(1000, mStrings[0]); + GetDlgItemText(1001, mStrings[1]); + GetDlgItemText(1002, mStrings[2]); + GetDlgItemText(1003, mStrings[3]); + CDialog::OnOK(); +} + +void T2SerialDialog::GetSerial(char *buf) { + memcpy(&buf[0], mStrings[0], 4); + memcpy(&buf[4], mStrings[1], 4); + memcpy(&buf[8], mStrings[2], 4); + memcpy(&buf[12], mStrings[3], 4); + buf[16] = 0; +} + +void T2SerialDialog::OnPaint() { + CPaintDC dc(this); + int save = dc.SaveDC(); + + CRect rect; + GetClientRect(rect); + + CFont font1; + font1.CreatePointFont(100, "\x82\x6C\x82\x72\x20\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"); + + CFont font2; + font2.CreatePointFont(80, "\x82\x6C\x82\x72\x20\x82\x6F\x83\x53\x83\x56\x83\x62\x83\x4E"); + + dc.SetBkMode(TRANSPARENT); + + int y = 15; + + dc.SelectObject(&font1); + // "あなたのシリアル番号を入力してください。" - Please enter your serial number. + dc.TextOut(10, y, "\x82\xA0\x82\xC8\x82\xBD\x82\xCC\x83\x56\x83\x8A\x83\x41\x83\x8B\x94\xD4\x8D\x86\x82\xF0\x93\xFC\x97\xCD\x82\xB5\x82\xC4\x82\xAD\x82\xBE\x82\xB3\x82\xA2\x81\x42"); + + // "A" + y += dc.GetTextExtent("\x82\x60").cy + 10; + + dc.SelectObject(&font2); + // "シリアル番号はユーザー登録のお願いに記載されています。" - The serial number is listed in the user registration request. + dc.TextOut(10, y, "\x83\x56\x83\x8A\x83\x41\x83\x8B\x94\xD4\x8D\x86\x82\xCD\x83\x86\x81\x5B\x83\x55\x81\x5B\x93\x6F\x98\x5E\x82\xCC\x82\xA8\x8A\xE8\x82\xA2\x82\xC9\x8B\x4C\x8D\xDA\x82\xB3\x82\xEA\x82\xC4\x82\xA2\x82\xDC\x82\xB7\x81\x42"); + + CBitmap bitmap; + bitmap.LoadBitmap(229); + + BITMAP bitmapData; + bitmap.GetObject(sizeof(bitmapData), &bitmapData); + + CDC bitmapDC; + bitmapDC.CreateCompatibleDC(&dc); + int bitmapDCSave = bitmapDC.SaveDC(); + + bitmapDC.SelectObject(&bitmap); + dc.SetTextColor(GetSysColor(COLOR_BTNSHADOW)); + dc.SetBkColor(GetSysColor(COLOR_BTNFACE)); + dc.BitBlt(0, rect.bottom - bitmapData.bmHeight, bitmapData.bmWidth, bitmapData.bmHeight, &bitmapDC, 0, 0, SRCCOPY); + + bitmapDC.RestoreDC(bitmapDCSave); + dc.RestoreDC(save); + bitmap.DeleteObject(); +} + +/*virtual*/ BOOL T2SerialDialog::OnCommand(WPARAM wParam, LPARAM lParam) { + int controlID = LOWORD(wParam); + + switch (LOWORD(controlID)) { + case 1000: + case 1001: + case 1002: + case 1003: + if (HIWORD(wParam) == EN_CHANGE && GetDlgItem(controlID)->GetWindowTextLength() >= 4) { + controlID++; + if (controlID == 1004) + controlID = 1000; + GetDlgItem(controlID)->SetFocus(); + } + break; + } + + return CWnd::OnCommand(wParam, lParam); +} diff --git a/src/T2DLL/T2SerialDialog.h b/src/T2DLL/T2SerialDialog.h new file mode 100644 index 0000000..dab8deb --- /dev/null +++ b/src/T2DLL/T2SerialDialog.h @@ -0,0 +1,18 @@ +#pragma once +#include "common.h" + +class T2SerialDialog : public CDialog { +public: + T2SerialDialog(CWnd *parent); + void GetSerial(char *buf); + + DECLARE_MESSAGE_MAP(); + +protected: + virtual void DoDataExchange(CDataExchange *pDX); + virtual void OnOK(); + virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); + void OnPaint(); + + CString mStrings[4]; +}; diff --git a/src/T2DLL/T2SettingDialog.cpp b/src/T2DLL/T2SettingDialog.cpp index ab32382..408b2af 100644 --- a/src/T2DLL/T2SettingDialog.cpp +++ b/src/T2DLL/T2SettingDialog.cpp @@ -1,10 +1,126 @@ +#include "GlobalFunc.h" +#include "SoundDlg.h" +#include "SpeedDlg.h" +#include "T2BitImage.h" +#include "T2DlgItem.h" +#include "T2ImageObj.h" #include "T2SettingDialog.h" +#include "WalkerDlg.h" -T2SettingDialog::T2SettingDialog(T2TowerDoc*) { +T2SettingDialog::T2SettingDialog(T2TowerDoc* inDoc) { + mDocument = inDoc; + + CRect rect; + AfxGetMainWnd()->GetWindowRect(rect); + + HINSTANCE theModule = GetWorldModuleHandle(); + mImageObj = new T2ImageObj; + mBitImage = new T2BitImage(theModule, 7000, true); +#line 24 + _ASSERT(mBitImage != NULL); + mImageObj->AddObject(theModule, 7000, mBitImage); + + T2DLGTEMPLATE tmpl; + tmpl.pt = rect.CenterPoint(); + tmpl.moduleHandle = theModule; + tmpl.resID = 7000; + Realize(mDocument, &tmpl, mDocument, mImageObj, NULL, true, NULL, 0, true); + + mSpeedDlg = new SpeedDlg; + mSoundDlg = new SoundDlg; + mWalkerDlg = new WalkerDlg; + + POINT pt; + pt.x = 70; + pt.y = 30; + mSpeedDlg->Setup(mTowerDoc, theModule, this, pt, mImageObj); + mSoundDlg->Setup(mTowerDoc, theModule, this, pt, mImageObj); + mWalkerDlg->Setup(mTowerDoc, theModule, this, pt, mImageObj); + + mSpeedDlg->ShowWindow(5); + + T2DlgItem *theRadio = GetT2DlgItem(108); + theRadio->SetValue(1); + + T2DlgItem *theText = GetT2DlgItem(120); + CString str; + mSpeedDlg->GetWindowText(str); + theText->SetDescriptor(str); } /*virtual*/ T2SettingDialog::~T2SettingDialog() { + if (mImageObj) + delete mImageObj; + if (mBitImage) + delete mBitImage; } -/*virtual*/ int T2SettingDialog::OnT2DialogCommand(unsigned int, long) { +/*virtual*/ int T2SettingDialog::OnT2DialogCommand(unsigned int cmd, long data) { + int result = 1; + + WORD hi = HIWORD(cmd); + WORD lo = LOWORD(cmd); + + T2DlgItem *theSpeedTabRadio = GetT2DlgItem(108); + T2DlgItem *theSoundTabRadio = GetT2DlgItem(109); + T2DlgItem *theWalkerTabRadio = GetT2DlgItem(110); + T2DlgItem *theText = GetT2DlgItem(120); + + CString str; + + switch (lo) { + case 108: + mSoundDlg->ShowWindow(SW_HIDE); + mWalkerDlg->ShowWindow(SW_HIDE); + mSpeedDlg->ShowWindow(SW_SHOW); + theSoundTabRadio->SetValue(0); + theWalkerTabRadio->SetValue(0); + mSpeedDlg->GetWindowText(str); + theText->SetDescriptor(str); + break; + + case 109: + mWalkerDlg->ShowWindow(SW_HIDE); + mSpeedDlg->ShowWindow(SW_HIDE); + mSoundDlg->ShowWindow(SW_SHOW); + theSpeedTabRadio->SetValue(0); + theWalkerTabRadio->SetValue(0); + mSoundDlg->GetWindowText(str); + theText->SetDescriptor(str); + break; + + case 110: + mSoundDlg->ShowWindow(SW_HIDE); + mSpeedDlg->ShowWindow(SW_HIDE); + mWalkerDlg->ShowWindow(SW_SHOW); + theSpeedTabRadio->SetValue(0); + theSoundTabRadio->SetValue(0); + mWalkerDlg->GetWindowText(str); + theText->SetDescriptor(str); + break; + + case 111: + mSpeedDlg->Revert(); + mSoundDlg->Revert(); + mWalkerDlg->Revert(); + break; + + case 112: + mSpeedDlg->Save(); + mSoundDlg->Save(); + mWalkerDlg->Save(); + OnT2OK(); + DoClose(lo); + break; + + case 113: + OnT2OK(); + DoClose(lo); + break; + + default: + result = T2Dialog::OnT2DialogCommand(cmd, data); + } + + return result; } diff --git a/src/T2DLL/T2SettingDialog.h b/src/T2DLL/T2SettingDialog.h index 1e5af78..7eba9ab 100644 --- a/src/T2DLL/T2SettingDialog.h +++ b/src/T2DLL/T2SettingDialog.h @@ -1,9 +1,18 @@ #pragma once #include "common.h" +#include "T2Dialog.h" -class T2SettingDialog { +class AFX_EXT_CLASS T2SettingDialog : public T2Dialog { public: - T2SettingDialog(T2TowerDoc*); + T2SettingDialog(T2TowerDoc* inDoc); virtual ~T2SettingDialog(); virtual int OnT2DialogCommand(unsigned int, long); + +protected: + T2TowerDoc *mDocument; + SpeedDlg *mSpeedDlg; + SoundDlg *mSoundDlg; + WalkerDlg *mWalkerDlg; + T2ImageObj *mImageObj; + T2BitImage *mBitImage; }; diff --git a/src/T2DLL/T2Settlement.cpp b/src/T2DLL/T2Settlement.cpp index 5b3058b..c535892 100644 --- a/src/T2DLL/T2Settlement.cpp +++ b/src/T2DLL/T2Settlement.cpp @@ -1,58 +1,442 @@ +#include "LArray.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2MoverDef.h" +#include "T2OuterObjDef.h" #include "T2Settlement.h" +#include "T2TemplatePluginList.h" +#include "T2TenantDef.h" +#include "T2TowerDoc.h" +#include "T2TowerMessage.h" -T2Settlement::T2Settlement(T2TowerDoc*, int) { +T2Settlement::T2Settlement(T2TowerDoc* towerDoc, int funds) { + Initialize(towerDoc, funds); } -T2Settlement::T2Settlement(T2TowerDoc*, T2Archive&) { +T2Settlement::T2Settlement(T2TowerDoc* towerDoc, T2Archive& archive) { + Initialize(towerDoc, 0); + + archive >> mCurrentFunds; + archive >> mPreviousFunds; + archive >> mC; + archive >> m10; + archive >> m14; + archive >> m18; + archive >> m1C; + + unsigned int i, count; + + archive >> count; + for (i = 0; i < count; i++) { + short type; + int num; + archive >> type; + archive >> num; + T2TenantDef *def = mDocument->mTenantTemplates->FindTenantDef(type); + if (def && def->IsLoaded()) + def->mSettlement = num; + } + + archive >> count; + for (i = 0; i < count; i++) { + short type; + int num; + archive >> type; + archive >> num; + T2MoverDef *def = mDocument->mMoverTemplates->FindMoverDef(type); + if (def && def->IsLoaded()) + def->mSettlement = num; + } + + archive >> count; + for (i = 0; i < count; i++) { + short type; + int num; + archive >> type; + archive >> num; + T2OuterObjDef *def = mDocument->mOuterObjTemplates->FindOutObjDef(type); + if (def && def->IsLoaded()) + def->mSettlement = num; + } } T2Settlement::~T2Settlement() { } -T2Archive& T2Settlement::Write(T2Archive&) const { +T2Archive& T2Settlement::Write(T2Archive& archive) const { + archive << mCurrentFunds; + archive << mPreviousFunds; + archive << mC; + archive << m10; + archive << m14; + archive << m18; + archive << m1C; + + archive << (unsigned int) mDocument->towerDoc_vf178()->GetCount(); + LArrayIterator tenantIterator(*mDocument->towerDoc_vf178()); + T2TenantDef *tenantDef = NULL; + while (tenantIterator.Next(&tenantDef)) { + archive << (short) tenantDef->GetToolType(); + archive << tenantDef->mSettlement; + } + + archive << (unsigned int) mDocument->towerDoc_vf17C()->GetCount(); + LArrayIterator moverIterator(*mDocument->towerDoc_vf17C()); + T2MoverDef *moverDef = NULL; + while (moverIterator.Next(&moverDef)) { + archive << (short) moverDef->GetToolType(); + archive << moverDef->mSettlement; + } + + archive << (unsigned int) mDocument->towerDoc_vf180()->GetCount(); + LArrayIterator outObjIterator(*mDocument->towerDoc_vf180()); + T2OuterObjDef *outObjDef = NULL; + while (outObjIterator.Next(&outObjDef)) { + archive << (short) outObjDef->GetToolType(); + archive << outObjDef->mSettlement; + } + + return archive; } -void T2Settlement::DoPay(int, short) { +void T2Settlement::DoPay(int funds, short fundGroup) { + mCurrentFunds -= funds; + + switch (fundGroup) { + case kFundGroup1: + m10 += funds; + break; + case kFundGroup2: + m14 += funds; + break; + case kFundGroup4: + m1C += funds; + break; + } } -void T2Settlement::DoPayTool(int, short, T2ToolDef*) { +void T2Settlement::DoPayTool(int funds, short fundGroup, T2ToolDef* inToolDef) { + mCurrentFunds -= funds; + +#line 171 + _ASSERT(inToolDef != NULL); + + switch (fundGroup) { + case kFundGroup0: + mC += funds; + inToolDef->mSettlement += funds; + break; + case kFundGroup3: + m18 += funds; + inToolDef->mSettlement += funds; + break; + } } -void T2Settlement::EmitPayToolMessage(T2TowerDoc*, T2ToolDef*, const CString&, int, int) { +void T2Settlement::EmitPayToolMessage(T2TowerDoc* towerDoc, T2ToolDef* inToolDef, const CString& str, int length, int type) { + BOOL flag = true; + + T2DateTime *theNow = towerDoc->towerDoc_vf120(); +#line 197 + _ASSERT(theNow != NULL); + + if (length && type) { + T2DateTime *theTimeLimit = GetTimeLimitOfMessage(towerDoc, inToolDef, type); + if (theTimeLimit && *theNow >= *theTimeLimit) + flag = false; + } + + if (flag) { + T2DateTime *theTimeLimit = CalcTimeLimitOfMessage(theNow, length); +#line 210 + _ASSERT(theTimeLimit != NULL); + + SetTimeLimitOfMessage(towerDoc, inToolDef, type, theTimeLimit); + delete theTimeLimit; + + towerDoc->towerDoc_vf13C()->InfoBarMessage(str, 120, "Cash"); + } } -T2DateTime* T2Settlement::GetTimeLimitOfMessage(T2TowerDoc*, T2ToolDef*, int) { +T2DateTime* T2Settlement::GetTimeLimitOfMessage(T2TowerDoc* towerDoc, T2ToolDef* inToolDef, int type) { + T2DateTime *theTimeLimit = NULL; + + switch (type) { + case kTimeLimitTypeNone: + break; + + case kTimeLimitTypeTool: + theTimeLimit = inToolDef->mToolQuietUntil; + if (!theTimeLimit) { + theTimeLimit = new T2DateTime; +#line 234 + _ASSERT(theTimeLimit != NULL); + inToolDef->mToolQuietUntil = theTimeLimit; + } + break; + + case kTimeLimitTypeCategory: + theTimeLimit = inToolDef->mCategoryQuietUntil; + if (!theTimeLimit) { + theTimeLimit = FindCategoryTimeLimit(towerDoc, inToolDef); +#line 243 + _ASSERT(theTimeLimit != NULL); + LinkCategoryTimeLimit(towerDoc, inToolDef, theTimeLimit); + } + break; + } + + return theTimeLimit; } -void T2Settlement::SetTimeLimitOfMessage(T2TowerDoc*, T2ToolDef*, int, T2DateTime*) { +void T2Settlement::SetTimeLimitOfMessage(T2TowerDoc* inDoc, T2ToolDef* inToolDef, int type, T2DateTime* inTimeLimit) { + switch (type) { + case kTimeLimitTypeNone: + break; + + case kTimeLimitTypeTool: + if (!inToolDef->mToolQuietUntil) { + inToolDef->mToolQuietUntil = new T2DateTime(*inTimeLimit); +#line 267 + _ASSERT(inToolDef->mToolQuietUntil != NULL); + } else { + *inToolDef->mToolQuietUntil = *inTimeLimit; + } + break; + + case kTimeLimitTypeCategory: + { + T2DateTime *theTimeLimit = inToolDef->mCategoryQuietUntil; + if (!theTimeLimit) { + theTimeLimit = FindCategoryTimeLimit(inDoc, inToolDef); +#line 279 + _ASSERT(theTimeLimit != NULL); + LinkCategoryTimeLimit(inDoc, inToolDef, theTimeLimit); + } + *theTimeLimit = *inTimeLimit; + break; + } + } } -T2DateTime* T2Settlement::FindCategoryTimeLimit(T2TowerDoc*, T2ToolDef*) { +T2DateTime* T2Settlement::FindCategoryTimeLimit(T2TowerDoc* inDoc, T2ToolDef* inToolDef) { + T2DateTime *theTimeLimit = NULL; + T2TemplatePluginList *theList = NULL; + int theCategory = inToolDef->GetCategory(); + + switch (theCategory) { + default: + theList = inDoc->towerDoc_vf178(); + break; + case 20: + theList = inDoc->towerDoc_vf17C(); + break; + case 200: + theList = inDoc->towerDoc_vf180(); + break; + } + + if (theList) { + LArrayIterator iterator(*theList); + T2ToolDef *theToolDef; + while (!theTimeLimit && iterator.Next(&theToolDef)) { + if (theToolDef->GetCategory() == theCategory) + theTimeLimit = theToolDef->mCategoryQuietUntil; + } + } + + if (!theTimeLimit) { + theTimeLimit = new T2DateTime; +#line 315 + _ASSERT(theTimeLimit != NULL); + mCategoryTimeLimitList->Add(&theTimeLimit); + } + + return theTimeLimit; } -void T2Settlement::LinkCategoryTimeLimit(T2TowerDoc*, T2ToolDef*, T2DateTime*) { +void T2Settlement::LinkCategoryTimeLimit(T2TowerDoc* inDoc, T2ToolDef* inToolDef, T2DateTime* inTimeLimit) { + T2TemplatePluginList *theList = NULL; + int theCategory = inToolDef->GetCategory(); + + switch (theCategory) { + default: + theList = inDoc->towerDoc_vf178(); + break; + case 20: + theList = inDoc->towerDoc_vf17C(); + break; + case 200: + theList = inDoc->towerDoc_vf180(); + break; + } + + if (theList) { + LArrayIterator iterator(*theList); + T2ToolDef *theToolDef; + while (iterator.Next(&theToolDef)) { + if (theToolDef->GetCategory() == theCategory) { +#line 344 + _ASSERT(theToolDef->mCategoryQuietUntil == NULL || theToolDef->mCategoryQuietUntil == inTimeLimit); + theToolDef->mCategoryQuietUntil = inTimeLimit; + } + } + } } -/*static*/ T2DateTime* T2Settlement::CalcTimeLimitOfMessage(T2DateTime*, int) { +/*static*/ T2DateTime* T2Settlement::CalcTimeLimitOfMessage(T2DateTime* inBaseTime, int length) { + T2DateTime *theTimeLimit = new T2DateTime(*inBaseTime); +#line 360 + _ASSERT(theTimeLimit != NULL); + + switch (length) { + case kTimeLimitLengthNone: + break; + + case kTimeLimitLength3Min: + theTimeLimit->AddMinutes(3); + break; + + case kTimeLimitLength30Min: + theTimeLimit->AddMinutes(30); + break; + + case kTimeLimitLength1Month: + theTimeLimit->mMonth += 1; + theTimeLimit->mRawMinutes = 0; + theTimeLimit->mSeconds = 0; + theTimeLimit->Validate(); + break; + } + + return theTimeLimit; } int T2Settlement::GetCurrentFunds() const { + return mCurrentFunds; } int T2Settlement::GetPreviousFunds() const { + return mPreviousFunds; } -int T2Settlement::GetTotalSettlement(short) const { +int T2Settlement::GetTotalSettlement(short fundGroup) const { + int total = 0; + + switch (fundGroup) { + case kFundGroup0: + total = mC; + break; + case kFundGroup1: + total = m10; + break; + case kFundGroup2: + total = m14; + break; + case kFundGroup3: + total = m18; + break; + case kFundGroup4: + total = m1C; + break; + case kFundGroup5: + total = m18 + mC; + break; + case kFundGroup6: + total = m1C + m14; + break; + } + + return total; } -int T2Settlement::GetToolSettlement(T2ToolDef*) const { +int T2Settlement::GetToolSettlement(T2ToolDef* inToolDef) const { + int result = 0; + + if (inToolDef) + result = inToolDef->mSettlement; + + return result; } -int T2Settlement::GetCategorySettlement(int) const { +int T2Settlement::GetCategorySettlement(int inCategory) const { + int result = 0; + + switch (inCategory) { + default: + { + LArrayIterator iterator(*mDocument->towerDoc_vf178()); + T2ToolDef *theToolDef = NULL; + while (iterator.Next(&theToolDef)) { + if (theToolDef->GetCategory() == inCategory) + result += theToolDef->mSettlement; + } + break; + } + case 20: + { + LArrayIterator iterator(*mDocument->towerDoc_vf17C()); + T2ToolDef *theToolDef = NULL; + while (iterator.Next(&theToolDef)) { + result += theToolDef->mSettlement; + } + break; + } + case 200: + { + LArrayIterator iterator(*mDocument->towerDoc_vf180()); + T2ToolDef *theToolDef = NULL; + while (iterator.Next(&theToolDef)) { + result += theToolDef->mSettlement; + } + break; + } + } + + return result; } -void T2Settlement::Initialize(T2TowerDoc*, int) { +void T2Settlement::Initialize(T2TowerDoc* towerDoc, int funds) { + mDocument = towerDoc; +#line 473 + _ASSERT(mDocument != NULL); + + mCurrentFunds = funds; + mPreviousFunds = mCurrentFunds; + mC = 0; + m10 = 0; + m14 = 0; + m18 = 0; + m1C = 0; + + mCategoryTimeLimitList = new LArray; +#line 485 + _ASSERT(mCategoryTimeLimitList != NULL); } void T2Settlement::Update() { + mPreviousFunds = mCurrentFunds; + mC = 0; + m10 = 0; + m14 = 0; + m18 = 0; + m1C = 0; + + LArrayIterator tenantIterator(*mDocument->towerDoc_vf178()); + T2TenantDef *tenantDef = NULL; + while (tenantIterator.Next(&tenantDef)) { + tenantDef->mSettlement = 0; + } + + LArrayIterator moverIterator(*mDocument->towerDoc_vf17C()); + T2MoverDef *moverDef = NULL; + while (moverIterator.Next(&moverDef)) { + moverDef->mSettlement = 0; + } + + LArrayIterator outObjIterator(*mDocument->towerDoc_vf180()); + T2OuterObjDef *outObjDef = NULL; + while (outObjIterator.Next(&outObjDef)) { + outObjDef->mSettlement = 0; + } } diff --git a/src/T2DLL/T2Settlement.h b/src/T2DLL/T2Settlement.h index dc59339..c4d41b4 100644 --- a/src/T2DLL/T2Settlement.h +++ b/src/T2DLL/T2Settlement.h @@ -1,31 +1,61 @@ #pragma once #include "common.h" -class T2Settlement { +enum { + kFundGroup0, + kFundGroup1, + kFundGroup2, + kFundGroup3, + kFundGroup4, + kFundGroup5, + kFundGroup6, +}; + +enum { + kTimeLimitTypeNone, + kTimeLimitTypeTool, + kTimeLimitTypeCategory +}; + +enum { + kTimeLimitLengthNone, + kTimeLimitLength3Min, + kTimeLimitLength30Min, + kTimeLimitLength1Month +}; + +class AFX_EXT_CLASS T2Settlement { public: - T2Settlement(T2TowerDoc*, int); - T2Settlement(T2TowerDoc*, T2Archive&); + T2Settlement(T2TowerDoc* towerDoc, int funds); + T2Settlement(T2TowerDoc* towerDoc, T2Archive&); ~T2Settlement(); T2Archive& Write(T2Archive&) const; - void DoPay(int, short); - void DoPayTool(int, short, T2ToolDef*); - void EmitPayToolMessage(T2TowerDoc*, T2ToolDef*, const CString&, int, int); -protected: - T2DateTime* GetTimeLimitOfMessage(T2TowerDoc*, T2ToolDef*, int); - void SetTimeLimitOfMessage(T2TowerDoc*, T2ToolDef*, int, T2DateTime*); - T2DateTime* FindCategoryTimeLimit(T2TowerDoc*, T2ToolDef*); - void LinkCategoryTimeLimit(T2TowerDoc*, T2ToolDef*, T2DateTime*); - static T2DateTime* CalcTimeLimitOfMessage(T2DateTime*, int); -public: + void DoPay(int funds, short fundGroup); + void DoPayTool(int funds, short fundGroup, T2ToolDef* inToolDef); + void EmitPayToolMessage(T2TowerDoc*, T2ToolDef*, const CString&, int length, int); int GetCurrentFunds() const; int GetPreviousFunds() const; int GetTotalSettlement(short) const; int GetToolSettlement(T2ToolDef*) const; int GetCategorySettlement(int) const; + void Update(); + protected: - void Initialize(T2TowerDoc*, int); -public: - void Update(); + T2DateTime* GetTimeLimitOfMessage(T2TowerDoc*, T2ToolDef*, int); + void SetTimeLimitOfMessage(T2TowerDoc*, T2ToolDef*, int, T2DateTime*); + T2DateTime* FindCategoryTimeLimit(T2TowerDoc*, T2ToolDef*); + void LinkCategoryTimeLimit(T2TowerDoc*, T2ToolDef*, T2DateTime*); + void Initialize(T2TowerDoc* towerDoc, int funds); + + static T2DateTime* CalcTimeLimitOfMessage(T2DateTime*, int); - T2Settlement& operator=(const T2Settlement&) {} + T2TowerDoc *mDocument; + int mCurrentFunds; + int mPreviousFunds; + int mC; + int m10; + int m14; + int m18; + int m1C; + LArray *mCategoryTimeLimitList; }; diff --git a/src/T2DLL/T2SilhouetteDef.cpp b/src/T2DLL/T2SilhouetteDef.cpp index 526a450..f514197 100644 --- a/src/T2DLL/T2SilhouetteDef.cpp +++ b/src/T2DLL/T2SilhouetteDef.cpp @@ -1,10 +1,32 @@ +#include "CResFile.h" +#include "T2BitImage.h" +#include "T2ImageObj.h" #include "T2SilhouetteDef.h" -T2SilhouetteDef::T2SilhouetteDef(unsigned long, T2PluginSpecifier&, CResFile*) { +T2SilhouetteDef::T2SilhouetteDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile) + : T2TemplatePlugin(type, specifier, resFile, NULL) +{ + *resFile >> mSilhouetteType; + *resFile >> mWidth; + *resFile >> mRouteType; + *resFile >> mResID; + *resFile >> mName; + + mHasImage = false; + mImage = new T2BitImage(mModuleHandle, mResID, true); + mHasImage = true; + + for (int i = 0; i < 6; i++) { + CRect rect(0, i * 36, 16, (i + 1) * 36); + mImageObj->AddObject(i, 0, *mImage, rect, true, false); + } } /*virtual*/ T2SilhouetteDef::~T2SilhouetteDef() { + if (mHasImage) + delete mImage; } -/*virtual*/ void T2SilhouetteDef::GetName(CString&) { +/*virtual*/ void T2SilhouetteDef::GetName(CString& outStr) { + outStr = mName; } diff --git a/src/T2DLL/T2SilhouetteDef.h b/src/T2DLL/T2SilhouetteDef.h index 1122af5..5675c90 100644 --- a/src/T2DLL/T2SilhouetteDef.h +++ b/src/T2DLL/T2SilhouetteDef.h @@ -1,16 +1,25 @@ #pragma once #include "common.h" +#include "T2TemplatePlugin.h" -class T2SilhouetteDef { +class AFX_EXT_CLASS T2SilhouetteDef : public T2TemplatePlugin { public: - T2SilhouetteDef(unsigned long, T2PluginSpecifier&, CResFile*); + T2SilhouetteDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile); virtual ~T2SilhouetteDef(); - virtual void GetName(CString&); + virtual void GetName(CString& outStr); - virtual int GetSortKey() {} - int GetSilhouetteType() {} - int GetSilhouette(int, int) {} - T2SilhouetteDef& operator=(T2SilhouetteDef&) {} - int GetWidth() const {} - int GetRouteType() const {} + virtual int GetSortKey() { return mSilhouetteType; } + int GetSilhouetteType() { return mSilhouetteType; } + int GetSilhouette(int a, int b) { return (a * 3) + b; } + int GetWidth() const { return mWidth; } + int GetRouteType() const { return mRouteType; } + +protected: + T2BitImage *mImage; + BOOL mHasImage; + int mSilhouetteType; + int mWidth; + int mRouteType; + int mResID; + char mName[32]; }; diff --git a/src/T2DLL/T2SilhouettePane.cpp b/src/T2DLL/T2SilhouettePane.cpp index e38e5ef..7e48810 100644 --- a/src/T2DLL/T2SilhouettePane.cpp +++ b/src/T2DLL/T2SilhouettePane.cpp @@ -1,25 +1,89 @@ +#include "T2BitImage.h" +#include "T2People.h" #include "T2SilhouettePane.h" +#include "UT2Coordinate.h" +#include <MINMAX.H> -int T2SilhouettePane::GetSilhouetteType() const { +T2SilhouettePane::T2SilhouettePane(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItem(towerDoc, imageObj, palette) +{ + mPeople = NULL; + mHasCustomColor = false; + mA0 = 0; + mSilhouetteType = 0; + m8C = 0; + m90 = 0; } -void T2SilhouettePane::SetCustomColor(const int&) { +/*virtual*/ T2SilhouettePane::~T2SilhouettePane() { } -T2SilhouettePane::T2SilhouettePane(T2TowerDoc*, T2ImageObj*, CPalette*) { -} +/*virtual*/ void T2SilhouettePane::DrawSelf(CDC* dc) { + CRect clientRect; + GetClientRect(clientRect); -/*virtual*/ T2SilhouettePane::~T2SilhouettePane() { -} + if (mPeople && !clientRect.IsRectEmpty()) { + dc->FillRect(clientRect, CBrush::FromHandle((HBRUSH) GetStockObject(WHITE_BRUSH))); + + clientRect.DeflateRect(2, 2); + + int origColor = mPeople->mColor; + if (mHasCustomColor) + mPeople->mColor = mCustomColor; + + CRect imageRect(0, 0, mPeople->GetWidth() * 8, 36); + T2BitImage *image = new T2BitImage(imageRect); + image->Clear(0); + mPeople->Draw(image, imageRect); + + CRect rect3 = imageRect; + rect3.top += UT2Coordinate::CalcRoofThick(0); + rect3.bottom -= UT2Coordinate::CalcFloorThick(0); -/*virtual*/ void T2SilhouettePane::DrawSelf(CDC*) { + float ratio = min(float(clientRect.Width()) / float(rect3.Width()), float(clientRect.Height()) / float(rect3.Height())); + if (ratio < 1.0) + ratio = 1.0f; + + CRect rect4(0, 0, rect3.Width() * ratio, rect3.Height() * ratio); + rect4.OffsetRect( + clientRect.left + (clientRect.Width() - rect4.Width()) / 2, + clientRect.top + (clientRect.Height() - rect4.Height()) / 2 + ); + + StretchDIBits( + dc->m_hDC, + rect4.left, rect4.top, + rect4.Width(), rect4.Height(), + rect3.left, rect3.bottom + 1, + rect3.Width(), -rect3.Height(), + image->mData, (BITMAPINFO *) &image->mBitmap, + DIB_PAL_COLORS, SRCCOPY); + + delete image; + + mPeople->mColor = origColor; + } } -/*virtual*/ int T2SilhouettePane::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2SilhouettePane::OnT2DlgItemEraseBkgnd(CDC* dc) { + int save = dc->SaveDC(); + dc->SelectPalette(mPalette, false); + dc->RealizePalette(); + + if (!mPeople) + return false; + + DrawSelf(dc); + dc->RestoreDC(save); + + return true; } -/*virtual*/ int T2SilhouettePane::OnCreate(CREATESTRUCTA*) { +/*virtual*/ BOOL T2SilhouettePane::OnCreate(CREATESTRUCT* cs) { + return T2DlgItem::OnCreate(cs); } -void T2SilhouettePane::SetPeople(T2People*) { +void T2SilhouettePane::SetPeople(T2People* people) { + mPeople = people; + InvalidateRect(NULL); } diff --git a/src/T2DLL/T2SilhouettePane.h b/src/T2DLL/T2SilhouettePane.h index 4e2ab4a..464ad43 100644 --- a/src/T2DLL/T2SilhouettePane.h +++ b/src/T2DLL/T2SilhouettePane.h @@ -1,16 +1,34 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2SilhouettePane { +class AFX_EXT_CLASS T2SilhouettePane : public T2DlgItem { public: - int GetSilhouetteType() const; - void SetCustomColor(const int&); - T2SilhouettePane(T2TowerDoc*, T2ImageObj*, CPalette*); + T2SilhouettePane(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2SilhouettePane(); + void SetPeople(T2People*); + + int GetSilhouetteType() const { + return mSilhouetteType; + } + void SetCustomColor(const int& v) { + mCustomColor = v; + mHasCustomColor = true; + } + protected: + virtual BOOL OnCreate(CREATESTRUCT*); virtual void DrawSelf(CDC*); - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual int OnCreate(CREATESTRUCTA*); -public: - void SetPeople(T2People*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + + T2People *mPeople; + int m8C; + int m90; + int m94; + int m98; + int m9C; + int mA0; + int mSilhouetteType; + BOOL mHasCustomColor; + int mCustomColor; }; diff --git a/src/T2DLL/T2SoundPlayer.cpp b/src/T2DLL/T2SoundPlayer.cpp index 7abc2a6..8c06ec9 100644 --- a/src/T2DLL/T2SoundPlayer.cpp +++ b/src/T2DLL/T2SoundPlayer.cpp @@ -1,74 +1,463 @@ +#include "GlobalFunc.h" #include "T2SoundPlayer.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "Wave.h" -/*static*/ const AFX_MSGMAP* __stdcall T2SoundPlayer::_GetBaseMessageMap() { -} +BEGIN_MESSAGE_MAP(T2SoundPlayer, CWnd) + ON_MESSAGE(MM_MCINOTIFY, OnMCINotify) +END_MESSAGE_MAP() -/*virtual*/ const AFX_MSGMAP* T2SoundPlayer::GetMessageMap() const { -} +T2SoundPlayer::T2SoundPlayer(CWnd* inParentWnd, IDirectSound* inDirectSound) { + mDirectSound = inDirectSound; + mItemList = new T2SoundObjItemList; + mCurrentCDTrack = 0; + + MCI_OPEN_PARMS mciParms; + memset(&mciParms, 0, sizeof(mciParms)); + + mciParms.lpstrDeviceType = (LPSTR) MCI_DEVTYPE_CD_AUDIO; + + CString theName; + theName.Format("%s:", GetInstallSourceDrive()); + CString theAlias; + theAlias = "T2CD"; -T2SoundPlayer::T2SoundPlayer(CWnd*, IDirectSound*) { + mciParms.lpstrElementName = theName; + mciParms.lpstrAlias = theAlias; + + mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_SHAREABLE | MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS | MCI_OPEN_TYPE_ID | MCI_OPEN_TYPE, (DWORD) &mciParms); + + CRect rect(0, 0, 1, 1); + CString theClass = AfxRegisterWndClass(CS_NOCLOSE); + + Create(theClass, "", WS_CHILD, rect, inParentWnd, 9999); + + mSEMask = 0xFFFFFFFF; + mIsSoundOn = true; + mIsFadeOut = false; } /*virtual*/ T2SoundPlayer::~T2SoundPlayer() { + StopCD(); + + CString cmd; + cmd.Format("close %s", "T2CD"); + mciSendString(cmd, NULL, 0, NULL); + + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + DeleteSound(item->mName); + } + + delete mItemList; } -void T2SoundPlayer::AddSound(const CString&, SOUNDPRIORITY, const CString&) { +void T2SoundPlayer::AddSound(const CString& inName, SOUNDPRIORITY inPriority, const CString& inPath) { + if (!mDirectSound) + return; + + T2SoundObjItem *item = new T2SoundObjItem; + CWave wave(inPath); + + if (LoadSound(item, inName, wave, false)) { + item->mSourceKind = T2SoundObjItem::FileSource; + item->mPath = inPath; + item->mPriority = inPriority; + mItemList->AddTail(item); + } else { + delete item; + } } -void T2SoundPlayer::AddSound(const CString&, SOUNDPRIORITY, unsigned int, HINSTANCE) { +void T2SoundPlayer::AddSound(const CString& inName, SOUNDPRIORITY inPriority, unsigned int inResID, HINSTANCE inModule) { + if (!mDirectSound) + return; + + if (FindResource(inModule, MAKEINTRESOURCE(inResID), "WAVE")) { + T2SoundObjItem *item = new T2SoundObjItem; + CWave wave(inResID, inModule); + + if (LoadSound(item, inName, wave, false)) { + item->mSourceKind = T2SoundObjItem::ResSource; + item->mResID = inResID; + item->mModuleHandle = inModule; + item->mPriority = inPriority; + mItemList->AddTail(item); + } else { + delete item; + } + } } -int T2SoundPlayer::LoadSound(T2SoundObjItem*, const CString&, CWave&, int) { +BOOL T2SoundPlayer::LoadSound(T2SoundObjItem* inItem, const CString& inName, CWave& inWave, BOOL inReloadFlag) { + if (!inReloadFlag) { + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + if (item->mName == inName) + return false; + } + } + + inItem->mName = inName; + + BYTE *waveDataPtr; + DWORD waveDataLength = inWave.GetDataLen(); + + WAVEFORMATEX waveFormat; + inWave.GetFormat(waveFormat); + + DSBUFFERDESC desc; + memset(&desc, 0, sizeof(DSBUFFERDESC)); + desc.dwSize = sizeof(DSBUFFERDESC); + desc.dwFlags = DSBCAPS_STATIC | DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLDEFAULT; + desc.dwBufferBytes = waveDataLength; + desc.lpwfxFormat = &waveFormat; + + mDirectSound->CreateSoundBuffer(&desc, &inItem->mDSBuffers[0], NULL); + + inItem->mDSBuffers[0]->Lock(0, waveDataLength, &waveDataPtr, &waveDataLength, NULL, NULL, 0); + waveDataLength = inWave.GetData(waveDataPtr, waveDataLength); + inItem->mDSBuffers[0]->Unlock(waveDataPtr, waveDataLength, NULL, 0); + + inItem->mPlayedAt[0] = GetTickCount(); + + for (int i = 1; i < 4; i++) { + mDirectSound->DuplicateSoundBuffer(inItem->mDSBuffers[0], &inItem->mDSBuffers[i]); + inItem->mPlayedAt[i] = GetTickCount(); + } + + return true; } -void T2SoundPlayer::DeleteSound(const CString&) { +void T2SoundPlayer::DeleteSound(const CString& inName) { + if (!mDirectSound) + return; + + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + POSITION prev = pos; + T2SoundObjItem *item = mItemList->GetNext(pos); + + if (item->mName == inName) { + mItemList->RemoveAt(prev); + for (int i = 3; i >= 0; i--) { + if (item->mDSBuffers[i]) + item->mDSBuffers[i]->Release(); + } + + delete item; + break; + } + } } void T2SoundPlayer::DeleteSoundAll() { + if (!mDirectSound) + return; + + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + DeleteSound(item->mName); + } + + mItemList->RemoveAll(); } -void T2SoundPlayer::Play(const CString&, unsigned int, unsigned int, POINT*, PLAYMODE, int) { +void T2SoundPlayer::Play(const CString& inName, unsigned int inMask, unsigned int inFlags, POINT* inPt, PLAYMODE inPlayMode, int inVolume) { + if (!mDirectSound) + return; + + if (!mIsSoundOn || (inMask & mSEMask) == 0) + return; + + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + if (item->mName == inName) { + DWORD currentStatus; + int index; + + if (inPlayMode == PlayMode_0 || inPlayMode == PlayMode_1 || inPlayMode == PlayMode_3) { + index = 0; + } else if (inPlayMode == PlayMode_2) { + for (index = 0; index < 4; index++) { + item->mDSBuffers[index]->GetStatus(¤tStatus); + if (!(currentStatus & DSBSTATUS_PLAYING)) + break; + } + + if (index == 4) { + // all slots full, pick the oldest sound to replace + DWORD oldest = GetTickCount(); + index = 0; + for (int i = 0; i < 4; i++) { + if (item->mPlayedAt[i] < oldest) { + index = i; + oldest = item->mPlayedAt[i]; + } + } + } + } + + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_BUFFERLOST) { + for (int i = 3; i >= 0; i--) + item->mDSBuffers[i]->Restore(); + + CWave *wave; + if (item->mSourceKind == T2SoundObjItem::FileSource) + wave = new CWave(item->mPath); + else + wave = new CWave(item->mResID, item->mModuleHandle); + + LoadSound(item, item->mName, *wave, true); + } + + int pan = 0; + if (inPt) { + CRect rect; + GetCurrentT2TowerDoc()->GetTowerMainView()->tmv_vf140(rect); + + POINT centerPt = rect.CenterPoint(); + float x = ((float) (inPt->x - centerPt.x) / (float) ((rect.right - rect.left) / 2)); + x *= 0.5; + if (x < 0.0) + pan = -10000.0f * -x; + else + pan = 10000.0f * x; + } + + BOOL play = false; + if (inPlayMode == PlayMode_0 || inPlayMode == PlayMode_3) { + if (!(currentStatus & DSBSTATUS_PLAYING)) + play = true; + } else if (inPlayMode == PlayMode_1 || inPlayMode == PlayMode_2) { + if (currentStatus & DSBSTATUS_PLAYING) { + item->mDSBuffers[index]->Stop(); + item->mDSBuffers[index]->SetCurrentPosition(0); + } + play = true; + } + + if (play) { + int volume = ((inVolume * 10000) / 100) - 10000; + if (!mIsFadeOut || (inFlags & SoundFlags_10000)) + item->mDSBuffers[index]->SetVolume(volume); + else + item->mDSBuffers[index]->SetVolume(-10000); + + item->mDSBuffers[index]->SetPan(pan); + item->mDSBuffers[index]->Play(0, 0, inPlayMode == PlayMode_3); + } + + item->mPlayedAt[index] = GetTickCount(); + break; + } + } } -void T2SoundPlayer::Stop(const CString&) { +void T2SoundPlayer::Stop(const CString& inName) { + if (!mDirectSound) + return; + + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + + if (item->mName == inName) { + for (int index = 0; index < 4; index++) { + DWORD currentStatus; + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_PLAYING) { + item->mDSBuffers[index]->Stop(); + item->mDSBuffers[index]->SetCurrentPosition(0); + } + } + } + } } void T2SoundPlayer::StopAll() { + if (!mDirectSound) + return; + + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + + for (int index = 0; index < 4; index++) { + DWORD currentStatus; + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_PLAYING) { + item->mDSBuffers[index]->Stop(); + item->mDSBuffers[index]->SetCurrentPosition(0); + } + } + } } -void T2SoundPlayer::SetVolume(const CString&, int) { +void T2SoundPlayer::SetVolume(const CString& inName, int inVolume) { + if (!mDirectSound) + return; + + int volume = ((inVolume * 10000) / 100) - 10000; + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + + if (item->mName == inName) { + for (int index = 0; index < 4; index++) { + DWORD currentStatus; + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_PLAYING) + item->mDSBuffers[index]->SetVolume(volume); + } + } + } } -void T2SoundPlayer::SetSoundOn(int) { +void T2SoundPlayer::SetSoundOn(BOOL inSoundOn) { + mIsSoundOn = inSoundOn; + + if (!inSoundOn) { + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + DWORD currentStatus; + + for (int index = 0; index < 4; index++) { + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_PLAYING) { + item->mDSBuffers[index]->Stop(); + item->mDSBuffers[index]->SetCurrentPosition(0); + } + } + } + } } void T2SoundPlayer::FadeOut() { + mIsFadeOut = true; + + DWORD time = GetTickCount(); + while (GetTickCount() == time) {} + + int i = 0; + while (i <= 10) { + int volume = 0 - ((i * 10000) / 10); + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + DWORD currentStatus; + + for (int index = 0; index < 4; index++) { + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_PLAYING) + item->mDSBuffers[index]->SetVolume(volume); + } + } + + time = GetTickCount(); + while ((GetTickCount() - time) < 50) { + MSG msg; + PeekMessage(&msg, NULL, 0, 0, 0); + } + + i++; + } } void T2SoundPlayer::FadeIn() { + mIsFadeOut = false; + + DWORD time = GetTickCount(); + while (GetTickCount() == time) {} + + int i = 0; + while (i <= 10) { + int volume = ((i * 10000) / 10) - 10000; + POSITION pos = mItemList->GetHeadPosition(); + while (pos) { + T2SoundObjItem *item = mItemList->GetNext(pos); + DWORD currentStatus; + + for (int index = 0; index < 4; index++) { + item->mDSBuffers[index]->GetStatus(¤tStatus); + + if (currentStatus & DSBSTATUS_PLAYING) + item->mDSBuffers[index]->SetVolume(volume); + } + } + + time = GetTickCount(); + while ((GetTickCount() - time) < 50) { + MSG msg; + PeekMessage(&msg, NULL, 0, 0, 0); + } + + i++; + } } -void T2SoundPlayer::PlayCDTrack(int, int) { +void T2SoundPlayer::PlayCDTrack(int inTrack, BOOL inFlag) { + if (inFlag) + mCurrentCDTrack = inTrack; + else + mCurrentCDTrack = 0; + + CString cmd; + cmd.Format("status %s length track %d", "T2CD", inTrack); + + char returnString[20]; + MCIERROR err = mciSendString(cmd, returnString, 20, NULL); + + cmd.Format("play %s from %02d:00:00:00 to %02d:%s notify", "T2CD", inTrack, inTrack, returnString); + err = mciSendString(cmd, NULL, 0, *this); } void T2SoundPlayer::StopCD() { -} + mCurrentCDTrack = 0; -long T2SoundPlayer::OnMCINotify(unsigned int, long) { + CString cmd; + cmd.Format("stop %s", "T2CD"); + mciSendString(cmd, NULL, 0, NULL); } -/*static*/ const AFX_MSGMAP T2SoundPlayer::messageMap { -} +LRESULT T2SoundPlayer::OnMCINotify(WPARAM wParam, LPARAM lParam) { + if (wParam == MCI_NOTIFY_SUCCESSFUL || wParam == MCI_NOTIFY_ABORTED) { + if (mCurrentCDTrack) + PlayCDTrack(mCurrentCDTrack, true); + } -/*static*/ const AFX_MSGMAP_ENTRY* const T2SoundPlayer::_messageEntries { + return 0; } + + T2SoundObjItem::T2SoundObjItem() { + mName = ""; + + for (int i = 0; i < 4; i++) { + mDSBuffers[i] = NULL; + mPlayedAt[i] = GetTickCount(); + } } T2SoundObjItem::~T2SoundObjItem() { } + + T2SoundObjItemList::T2SoundObjItemList() { } diff --git a/src/T2DLL/T2SoundPlayer.h b/src/T2DLL/T2SoundPlayer.h index 8d3d7c6..7e9a5b4 100644 --- a/src/T2DLL/T2SoundPlayer.h +++ b/src/T2DLL/T2SoundPlayer.h @@ -2,55 +2,84 @@ #include "common.h" enum PLAYMODE { - PlayMode_0 + PlayMode_0, + PlayMode_1, + PlayMode_2, + PlayMode_3 }; enum SOUNDPRIORITY { - SoundPriority_0 + SoundPriority_0, + SoundPriority_1 }; -class T2SoundPlayer { -//protected: -// static const AFX_MSGMAP* __stdcall _GetBaseMessageMap(); -// virtual const AFX_MSGMAP* GetMessageMap() const; +enum { + SoundMask_10 = 0x10 +}; + +enum { + SoundFlags_10 = 0x10, + SoundFlags_10000 = 0x10000 +}; + +class AFX_EXT_CLASS T2SoundPlayer : public CWnd { + DECLARE_MESSAGE_MAP() + public: - T2SoundPlayer(CWnd*, IDirectSound*); + T2SoundPlayer(CWnd* inParentWnd, IDirectSound* inDirectSound); virtual ~T2SoundPlayer(); - void AddSound(const CString&, SOUNDPRIORITY, const CString&); - void AddSound(const CString&, SOUNDPRIORITY, unsigned int, HINSTANCE); -private: - int LoadSound(T2SoundObjItem*, const CString&, CWave&, int); -public: - void DeleteSound(const CString&); + void AddSound(const CString& inName, SOUNDPRIORITY inPriority, const CString& inPath); + void AddSound(const CString& inName, SOUNDPRIORITY inPriority, unsigned int inResID, HINSTANCE inModule); + void DeleteSound(const CString& inName); void DeleteSoundAll(); - void Play(const CString&, unsigned int, unsigned int, POINT*, PLAYMODE, int); - void Stop(const CString&); + void Play(const CString& inName, unsigned int inMask, unsigned int inFlags, POINT* inPt, PLAYMODE inPlayMode, int inVolume); + void Stop(const CString& inName); void StopAll(); - void SetVolume(const CString&, int); - void SetSoundOn(int); + void SetVolume(const CString& inName, int inVolume); + void SetSoundOn(BOOL inSoundOn); void FadeOut(); void FadeIn(); - void PlayCDTrack(int, int); + void PlayCDTrack(int inTrack, BOOL inFlag); void StopCD(); + unsigned int GetSEMask() const { return mSEMask; } + void SetSEMask(unsigned int inMask) { mSEMask = inMask; } + BOOL IsSoundOn() const { return mIsSoundOn; } + protected: - long OnMCINotify(unsigned int, long); -// static const AFX_MSGMAP messageMap; -//private: -// static const AFX_MSGMAP_ENTRY* const _messageEntries; + LRESULT OnMCINotify(WPARAM wParam, LPARAM lParam); -public: - unsigned int GetSEMask() const { return 0; } - void SetSEMask(unsigned int) {} - int IsSoundOn() const { return 0; } +private: + BOOL LoadSound(T2SoundObjItem* inItem, const CString& inName, CWave& inWave, BOOL inReloadFlag); + + IDirectSound *mDirectSound; + T2SoundObjItemList *mItemList; + int mCurrentCDTrack; + unsigned int mSEMask; + BOOL mIsSoundOn; + BOOL mIsFadeOut; }; -class T2SoundObjItem { +class AFX_EXT_CLASS T2SoundObjItem { public: T2SoundObjItem(); ~T2SoundObjItem(); + + enum { + FileSource = 1, + ResSource = 2 + }; + + CString mName; + SOUNDPRIORITY mPriority; + LPDIRECTSOUNDBUFFER mDSBuffers[4]; + DWORD mPlayedAt[4]; + int mSourceKind; + CString mPath; + unsigned int mResID; + HINSTANCE mModuleHandle; }; -class T2SoundObjItemList { +class AFX_EXT_CLASS T2SoundObjItemList : public CList<T2SoundObjItem *, T2SoundObjItem *> { public: T2SoundObjItemList(); virtual ~T2SoundObjItemList(); diff --git a/src/T2DLL/T2Sprite.cpp b/src/T2DLL/T2Sprite.cpp index 6f04e24..2cbd7e8 100644 --- a/src/T2DLL/T2Sprite.cpp +++ b/src/T2DLL/T2Sprite.cpp @@ -32,7 +32,7 @@ int T2Sprite::NewSprite(T2ImageObj& imageObj, const CString& name, int layer) { obj->mIndex = index; obj->mLayer = layer; - int objIndex = imageObj.FindObject(name, -1, 0, 0, 255); + int objIndex = imageObj.FindObject(name); imageObj.GetObjectSize(objIndex, &obj->mSize); AddTail(obj); return index; @@ -141,11 +141,11 @@ void T2Sprite::DrawSprite(T2BitImage* dest, T2SpriteObj* obj, int factor) { rect.bottom = rect.bottom / (1 << factor); rect.right = rect.right / (1 << factor); - int objectID = obj->mImageObj->FindObject(obj->mName, obj->mPattern, 0, 0, 255); + int objectID = obj->mImageObj->FindObject(obj->mName, obj->mPattern); if (objectID < 0) return; - obj->mImageObj->DrawObject(dest, objectID, rect, factor, -1); + obj->mImageObj->DrawObject(dest, objectID, rect, factor); } } diff --git a/src/T2DLL/T2Sprite.h b/src/T2DLL/T2Sprite.h index 13f6372..304891b 100644 --- a/src/T2DLL/T2Sprite.h +++ b/src/T2DLL/T2Sprite.h @@ -1,11 +1,22 @@ #pragma once #include "common.h" +#include "T2SpriteObj.h" -class DLL_EXPORT T2Sprite : private CList<T2SpriteObj *, T2SpriteObj *> { +class AFX_EXT_CLASS T2Sprite : private CList<T2SpriteObj *, T2SpriteObj *> { public: T2Sprite(); virtual ~T2Sprite(); + enum ELayer { + ELayer_0, + ELayer_1, + ELayer_2, + ELayer_3, + ELayer_4, + ELayer_5, + ELayer_6 + }; + void AllClear(); int NewSprite(T2ImageObj& imageObj, const CString& name, int layer); void DeleteSprite(int index); diff --git a/src/T2DLL/T2SpriteObj.h b/src/T2DLL/T2SpriteObj.h index a32c648..0064918 100644 --- a/src/T2DLL/T2SpriteObj.h +++ b/src/T2DLL/T2SpriteObj.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2SpriteObj { +class AFX_EXT_CLASS T2SpriteObj { public: T2SpriteObj(); ~T2SpriteObj(); diff --git a/src/T2DLL/T2StairModule.cpp b/src/T2DLL/T2StairModule.cpp index 3a63e43..751943f 100644 --- a/src/T2DLL/T2StairModule.cpp +++ b/src/T2DLL/T2StairModule.cpp @@ -1,19 +1,57 @@ +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2People.h" +#include "T2PeopleLinkIterator.h" #include "T2StairModule.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" T2StairModule::T2StairModule() { + SetRectEmpty(&mModuleRect); } /*virtual*/ T2StairModule::~T2StairModule() { } -void T2StairModule::MoverIDChanged(unsigned int) { +void T2StairModule::MoverIDChanged(unsigned int moverID) { + if (mLink1) { + T2PeopleLinkIterator iterator((T2People *) mLink1); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->mCurrEquipID = moverID; + } + } } -/*virtual*/ void T2StairModule::RemoveContents(T2TowerDoc*) { +/*virtual*/ void T2StairModule::RemoveContents(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + + while (mLink1) { + T2People *people = (T2People *) mLink1; + Leave(people); + + POINT pt = mModuleRect.TopLeft(); + if (mDirection != kStairDirection1) + pt.y = mModuleRect.bottom - 1; + + T2Tenant *floor = floorInfo->GetFloor(pt.y, pt.x); + if (floor) + floor->Enter(people); + } } -/*virtual*/ void T2StairModule::LoadSelf(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2StairModule::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + T2MoverModule::LoadSelf(archive, towerDoc); + + if (IsUsed()) + archive.ReadSRect(mModuleRect); } -/*virtual*/ void T2StairModule::SaveSelf(T2Archive&) { +/*virtual*/ void T2StairModule::SaveSelf(T2Archive& archive) { + T2MoverModule::SaveSelf(archive); + + if (IsUsed()) + archive.WriteSRect(mModuleRect); } diff --git a/src/T2DLL/T2StairModule.h b/src/T2DLL/T2StairModule.h index ae2cac9..4d8c939 100644 --- a/src/T2DLL/T2StairModule.h +++ b/src/T2DLL/T2StairModule.h @@ -1,20 +1,27 @@ #pragma once #include "common.h" +#include "T2MoverModule.h" -class T2StairModule { +enum { + kStairDirection0 = 0, + kStairDirection1, + kStairDirection2 +}; + +class AFX_EXT_CLASS T2StairModule : public T2MoverModule { public: T2StairModule(); virtual ~T2StairModule(); + virtual void RemoveContents(T2TowerDoc*); void MoverIDChanged(unsigned int); - virtual void RemoveContents(T2TowerDoc*); + + void SetModuleRect(const RECT& r) { mModuleRect = r; } + void GetModuleRect(RECT& r) { r = mModuleRect; } + int GetExtraSize() { return mModuleRect.bottom - mModuleRect.top - 2; } + protected: virtual void LoadSelf(T2Archive&, T2TowerDoc*); virtual void SaveSelf(T2Archive&); -public: - void SetModuleRect(const RECT&) {} - void GetModuleRect(RECT&) {} - int GetExtraSize() {} - T2StairModule(const T2StairModule&) {} - T2StairModule& operator=(const T2StairModule&) {} + CRect mModuleRect; }; diff --git a/src/T2DLL/T2StairModuleList.cpp b/src/T2DLL/T2StairModuleList.cpp index 4f99087..876e571 100644 --- a/src/T2DLL/T2StairModuleList.cpp +++ b/src/T2DLL/T2StairModuleList.cpp @@ -1,3 +1,5 @@ +#include "T2Archive.h" +#include "T2StairModule.h" #include "T2StairModuleList.h" T2StairModuleList::T2StairModuleList() { @@ -6,23 +8,93 @@ T2StairModuleList::T2StairModuleList() { /*virtual*/ T2StairModuleList::~T2StairModuleList() { } -void T2StairModuleList::AddModule(int, const RECT&) { +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*, const RECT&, int) { +void T2StairModuleList::AddModule(T2TowerDoc* towerDoc, const RECT& rect, BOOL insertAtEnd) { + T2StairModule *module1 = new T2StairModule; + if (module1) { + module1->SetModuleRect(rect); + module1->mDirection = kStairDirection1; + module1->SetUsed(true); + module1->SetModuleID(towerDoc); + } + + T2StairModule *module2 = new T2StairModule; + if (module2) { + module2->SetModuleRect(rect); + module2->mDirection = kStairDirection2; + module2->SetUsed(true); + module2->SetModuleID(towerDoc); + } + + if (module1 && module2) { + if (insertAtEnd) { + InsertModuleAt(mItemCount + 1, module1); + InsertModuleAt(mItemCount + 1, module2); + } else { + InsertModuleAt(1, module2); + InsertModuleAt(1, module1); + } + } } -int T2StairModuleList::GetIndex(int, ERequestUpDown) const { +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*, unsigned int) { +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&, T2TowerDoc*) { +/*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; } diff --git a/src/T2DLL/T2StairModuleList.h b/src/T2DLL/T2StairModuleList.h index b93b9a5..dca1acc 100644 --- a/src/T2DLL/T2StairModuleList.h +++ b/src/T2DLL/T2StairModuleList.h @@ -1,23 +1,22 @@ #pragma once #include "common.h" +#include "T2MoverModuleList.h" -class T2StairModuleList { +class AFX_EXT_CLASS T2StairModuleList : public T2MoverModuleList { public: T2StairModuleList(); virtual ~T2StairModuleList(); - void AddModule(int, const RECT&); - void AddModule(T2TowerDoc*, const RECT&, int); -private: - int GetIndex(int, ERequestUpDown) const; -public: - void Union(T2MoverModuleList*, unsigned int); - virtual T2MoverModule* ConstructModule(); - virtual void Read(T2Archive&, T2TowerDoc*); - virtual int GetModuleCount() const; + virtual T2MoverModule* ConstructModule(); + virtual void Read(T2Archive&, T2TowerDoc*); + virtual int GetModuleCount() const; + + void AddModule(int position, const RECT& rect); + void AddModule(T2TowerDoc* towerDoc, const RECT& rect, BOOL insertAtEnd); + void Union(T2MoverModuleList* list, unsigned int moverID); protected: - virtual unsigned long GetMMClassID() {} -public: - T2StairModuleList(const T2StairModuleList&) {} - T2StairModuleList& operator=(const T2StairModuleList&) {} + virtual DWORD GetMMClassID() { return 'StML'; } + +private: + int GetIndex(int position, ERequestUpDown upDown) const; }; diff --git a/src/T2DLL/T2StewardDialog.cpp b/src/T2DLL/T2StewardDialog.cpp index 74c6b0d..bda8675 100644 --- a/src/T2DLL/T2StewardDialog.cpp +++ b/src/T2DLL/T2StewardDialog.cpp @@ -1,13 +1,78 @@ +#include "GlobalFunc.h" +#include "T2DlgItemAnimation.h" #include "T2StewardDialog.h" -T2StewardDialog::T2StewardDialog(T2TowerDoc*, HINSTANCE, CString&, int) { +T2StewardDialog::T2StewardDialog(T2TowerDoc* inDoc, HINSTANCE inModule, CString& inText, int inKind) { + mDeleteOnClose = true; + + CRect mainWndRect; + AfxGetMainWnd()->GetWindowRect(mainWndRect); + + T2DLGTEMPLATE dlg; + dlg.pt = mainWndRect.CenterPoint(); + dlg.moduleHandle = inModule; + dlg.resID = 9000; + Realize(inDoc, &dlg, inDoc, NULL, NULL, true, NULL, 0, true); + + T2DlgItem *label = GetT2DlgItem(100); + if (label) + label->SetDescriptor(inText); + + T2DlgItemAnimation *animation = (T2DlgItemAnimation *) GetT2DlgItem(101); + if (animation) + animation->SetAnimation(inModule, 9000, 0); + + if (inKind == 1) { + T2DlgItem *theOkButton = GetT2DlgItem(200); + theOkButton->ShowWindow(SW_HIDE); + } else { + T2DlgItem *theYesButton = GetT2DlgItem(201); + T2DlgItem *theNoButton = GetT2DlgItem(202); + theYesButton->ShowWindow(SW_HIDE); + theNoButton->ShowWindow(SW_HIDE); + } } -/*virtual*/ int T2StewardDialog::OnT2DialogCommand(unsigned int, long) { +/*virtual*/ BOOL T2StewardDialog::OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam) { + BOOL result = true; + WORD code = HIWORD(inWParam); + WORD id = LOWORD(inWParam); + + switch (id) { + case 200: + case 201: + OnT2OK(); + DoClose(id - 200); + break; + + case 202: + OnT2Cancel(); + DoClose(id - 200); + break; + + default: + result = T2Dialog::OnT2DialogCommand(inWParam, inLParam); + } + + return result; } -/*static*/ void T2StewardDialog::MessageBoxA(const char*, const char*) { +/*static*/ void T2StewardDialog::MessageBox(const char* inText, const char* inTitle) { + T2StewardDialog *theDialog = new T2StewardDialog(GetCurrentT2TowerDoc(), GetWorldModuleHandle(), CString(inText), 0); + if (!inTitle) { + inTitle = "\x83\x81\x83\x62\x83\x5A\x81\x5B\x83\x57"; + } + + theDialog->SetWindowText(inTitle); + theDialog->DoModal(); } -/*static*/ int T2StewardDialog::MessageBoxYN(const char*, const char*) { +/*static*/ int T2StewardDialog::MessageBoxYN(const char* inText, const char* inTitle) { + T2StewardDialog *theDialog = new T2StewardDialog(GetCurrentT2TowerDoc(), GetWorldModuleHandle(), CString(inText), 1); + if (!inTitle) { + inTitle = "\x83\x81\x83\x62\x83\x5A\x81\x5B\x83\x57"; + } + + theDialog->SetWindowText(inTitle); + return theDialog->DoModal(); } diff --git a/src/T2DLL/T2StewardDialog.h b/src/T2DLL/T2StewardDialog.h index b10d4a7..8209597 100644 --- a/src/T2DLL/T2StewardDialog.h +++ b/src/T2DLL/T2StewardDialog.h @@ -1,12 +1,11 @@ #pragma once #include "common.h" +#include "T2Dialog.h" -class T2StewardDialog { +class AFX_EXT_CLASS T2StewardDialog : public T2Dialog { public: - T2StewardDialog(T2TowerDoc*, HINSTANCE, CString&, int); - virtual int OnT2DialogCommand(unsigned int, long); - static void MessageBoxA(const char*, const char*); - static int MessageBoxYN(const char*, const char*); - - virtual ~T2StewardDialog() {} + T2StewardDialog(T2TowerDoc* inDoc, HINSTANCE inModule, CString& inText, int inKind); + virtual BOOL OnT2DialogCommand(WPARAM inWParam, LPARAM inLParam); + static void MessageBox(const char* inText, const char* inTitle); + static int MessageBoxYN(const char* inText, const char* inTitle); }; diff --git a/src/T2DLL/T2StopInfoArray.cpp b/src/T2DLL/T2StopInfoArray.cpp index 689e167..a509cbb 100644 --- a/src/T2DLL/T2StopInfoArray.cpp +++ b/src/T2DLL/T2StopInfoArray.cpp @@ -1,52 +1,117 @@ +#include "T2Archive.h" #include "T2StopInfoArray.h" -T2StopInfoArray::T2StopInfoArray() { +T2StopInfoArray::T2StopInfoArray() + : LArray(1) +{ } /*virtual*/ T2StopInfoArray::~T2StopInfoArray() { } -void T2StopInfoArray::Init(int) { +void T2StopInfoArray::Init(int count) { + Expand(EEquipPos_2, count); } void T2StopInfoArray::AllClear() { + RemoveItemsAt(mItemCount, 1); } -void T2StopInfoArray::Expand(EEquipPos, int) { +void T2StopInfoArray::Expand(EEquipPos pos, int count) { + int where; + if (pos == EEquipPos_2) + where = mItemCount + 1; + else if (pos == EEquipPos_3) + where = 1; + else + return; + + if (count > 0) { + int actualCount = count * 2; + unsigned char zero = 0; + for (int i = 0; i < actualCount; i++) + InsertItemsAt(1, where, &zero); + } else { + int actualCount = -count * 2; + for (int i = 0; i < actualCount; i++) + RemoveItemsAt(1, where); + } } -int T2StopInfoArray::IsStopPos(int, ERequestUpDown) { +BOOL T2StopInfoArray::IsStopPos(int i, ERequestUpDown upDown) { + return GetStopAt(i, upDown) > 0; } -int T2StopInfoArray::IsOnStopPos(int, ERequestUpDown) { +BOOL T2StopInfoArray::IsOnStopPos(int i, ERequestUpDown upDown) { + return (GetStopAt(i, upDown) & 2) > 0; } -int T2StopInfoArray::IsOffStopPos(int, ERequestUpDown) { +BOOL T2StopInfoArray::IsOffStopPos(int i, ERequestUpDown upDown) { + return (GetStopAt(i, upDown) & 1) > 0; } -void T2StopInfoArray::SetOnStop(int, ERequestUpDown) { +void T2StopInfoArray::SetOnStop(int i, ERequestUpDown upDown) { + char v = GetStopAt(i, upDown) | 2; + SetStopAt(i, upDown, v); } -void T2StopInfoArray::SetOffStop(int, ERequestUpDown) { +void T2StopInfoArray::SetOffStop(int i, ERequestUpDown upDown) { + char v = GetStopAt(i, upDown) | 1; + SetStopAt(i, upDown, v); } -void T2StopInfoArray::ClearOnStop(int, ERequestUpDown) { +void T2StopInfoArray::ClearOnStop(int i, ERequestUpDown upDown) { + char v = GetStopAt(i, upDown) & 1; + SetStopAt(i, upDown, v); } -void T2StopInfoArray::ClearOffStop(int, ERequestUpDown) { +void T2StopInfoArray::ClearOffStop(int i, ERequestUpDown upDown) { + char v = GetStopAt(i, upDown) & 2; + SetStopAt(i, upDown, v); } -char T2StopInfoArray::GetStopAt(int, ERequestUpDown) { +char T2StopInfoArray::GetStopAt(int i, ERequestUpDown upDown) { + char v; + FetchItemAt(GetIndex(i, upDown), &v); + return v; } -void T2StopInfoArray::SetStopAt(int, ERequestUpDown, char) { +void T2StopInfoArray::SetStopAt(int i, ERequestUpDown upDown, char v) { + AssignItemsAt(1, GetIndex(i, upDown), &v); } -int T2StopInfoArray::GetIndex(int, ERequestUpDown) const { +int T2StopInfoArray::GetIndex(int i, ERequestUpDown upDown) const { + int index = 1; + index += i * 2; + if (upDown == ERequestUpDown_1) + index++; + return index; } -/*static*/ T2StopInfoArray* T2StopInfoArray::ReadStopInfoArray(T2Archive&) { +/*static*/ T2StopInfoArray* T2StopInfoArray::ReadStopInfoArray(T2Archive& archive) { + T2StopInfoArray *array = NULL; + + DWORD code; + archive >> code; + + if (code == 'SIfA') + array = new T2StopInfoArray; + + if (array) + array->ReadAsChar(archive); + + return array; } -/*static*/ void T2StopInfoArray::WriteStopInfoArray(T2StopInfoArray*, T2Archive&) { +/*static*/ void T2StopInfoArray::WriteStopInfoArray(T2StopInfoArray* array, T2Archive& archive) { + DWORD code; + + if (!array) { + code = 'xSIA'; + archive << code; + } else { + code = 'SIfA'; + archive << code; + array->WriteAsChar(archive); + } } diff --git a/src/T2DLL/T2StopInfoArray.h b/src/T2DLL/T2StopInfoArray.h index d42ef9e..4247f40 100644 --- a/src/T2DLL/T2StopInfoArray.h +++ b/src/T2DLL/T2StopInfoArray.h @@ -1,26 +1,25 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2StopInfoArray { +class AFX_EXT_CLASS T2StopInfoArray : private LArray { public: T2StopInfoArray(); virtual ~T2StopInfoArray(); - void Init(int); + void Init(int count); void AllClear(); - void Expand(EEquipPos, int); - int IsStopPos(int, ERequestUpDown); - int IsOnStopPos(int, ERequestUpDown); - int IsOffStopPos(int, ERequestUpDown); - void SetOnStop(int, ERequestUpDown); - void SetOffStop(int, ERequestUpDown); - void ClearOnStop(int, ERequestUpDown); - void ClearOffStop(int, ERequestUpDown); - char GetStopAt(int, ERequestUpDown); - void SetStopAt(int, ERequestUpDown, char); - int GetIndex(int, ERequestUpDown) const; - static T2StopInfoArray* ReadStopInfoArray(T2Archive&); - static void WriteStopInfoArray(T2StopInfoArray*, T2Archive&); + void Expand(EEquipPos pos, int count); + BOOL IsStopPos(int i, ERequestUpDown upDown); + BOOL IsOnStopPos(int i, ERequestUpDown upDown); + BOOL IsOffStopPos(int i, ERequestUpDown upDown); + void SetOnStop(int i, ERequestUpDown upDown); + void SetOffStop(int i, ERequestUpDown upDown); + void ClearOnStop(int i, ERequestUpDown upDown); + void ClearOffStop(int i, ERequestUpDown upDown); + char GetStopAt(int i, ERequestUpDown upDown); + void SetStopAt(int i, ERequestUpDown upDown, char); + int GetIndex(int i, ERequestUpDown upDown) const; - T2StopInfoArray(const T2StopInfoArray&) {} - T2StopInfoArray& operator=(const T2StopInfoArray&) {} + static T2StopInfoArray* ReadStopInfoArray(T2Archive& archive); + static void WriteStopInfoArray(T2StopInfoArray* array, T2Archive& archive); }; diff --git a/src/T2DLL/T2SubPlugin.cpp b/src/T2DLL/T2SubPlugin.cpp index fbdbe01..4d265a7 100644 --- a/src/T2DLL/T2SubPlugin.cpp +++ b/src/T2DLL/T2SubPlugin.cpp @@ -12,21 +12,21 @@ T2SubPlugin::T2SubPlugin(DWORD type, T2PluginSpecifier& specifier) mTieup = NULL; mOpenTime = 0; mCloseTime = 0; - mBitImage = NULL; + mImage = NULL; mImageObj = NULL; } /*virtual*/ T2SubPlugin::~T2SubPlugin() { if (mTieup) delete mTieup; - if (mBitImage) - delete mBitImage; + if (mImage) + delete mImage; if (mImageObj) delete mImageObj; } -int T2SubPlugin::IsTieupFinish() { - int result = false; +BOOL T2SubPlugin::IsTieupFinish() { + BOOL result = false; if (mTieup) { CTime now = CTime::GetTickCount(); diff --git a/src/T2DLL/T2SubPlugin.h b/src/T2DLL/T2SubPlugin.h index 9b6a809..2865c92 100644 --- a/src/T2DLL/T2SubPlugin.h +++ b/src/T2DLL/T2SubPlugin.h @@ -2,18 +2,18 @@ #include "common.h" #include "CResourcePlugin.h" -class T2SubPlugin : public CResourcePlugin { +class AFX_EXT_CLASS T2SubPlugin : public CResourcePlugin { public: T2SubPlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~T2SubPlugin(); - virtual unsigned long GetPluginStyle() { return 'SPlg'; } + virtual DWORD GetPluginStyle() { return 'SPlg'; } virtual void GetTitle(CString& outStr); virtual int GetBindTime() { return 1; } virtual void GlobalData(T2GlobalData*) {} virtual unsigned long LoadSelf() { return 0; } - int IsTieupFinish(); - int IsTieup() { return mTieup != NULL; } + BOOL IsTieupFinish(); + BOOL IsTieup() { return mTieup != NULL; } unsigned int GetOpenTime() const { return mOpenTime; } void SetOpenTime(unsigned int t) { mOpenTime = t; } @@ -31,6 +31,6 @@ protected: int mDupCustomerTableDefRes; unsigned int mOpenTime; unsigned int mCloseTime; - T2BitImage *mBitImage; + T2BitImage *mImage; T2ImageObj *mImageObj; }; diff --git a/src/T2DLL/T2TempPluginComparator.cpp b/src/T2DLL/T2TempPluginComparator.cpp index e3ff485..09da5fa 100644 --- a/src/T2DLL/T2TempPluginComparator.cpp +++ b/src/T2DLL/T2TempPluginComparator.cpp @@ -1,13 +1,28 @@ +#include "T2TemplatePlugin.h" #include "T2TempPluginComparator.h" -/*virtual*/ int T2TempPluginComparator::Compare(const void*, const void*, unsigned int, unsigned int) const { -} +/*virtual*/ int T2TempPluginComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + T2TemplatePlugin *p1 = *((T2TemplatePlugin **) inItemOne); + T2TemplatePlugin *p2 = *((T2TemplatePlugin **) inItemTwo); -/*virtual*/ int T2TempPluginComparator::IsEqualTo(const void*, const void*, unsigned int, unsigned int) const { + if (!p2) + return -1; + else if (!p1) + return 1; + else + return p1->GetSortKey() - p2->GetSortKey(); } -/*static*/ T2TempPluginComparator* T2TempPluginComparator::GetComparator() { +/*virtual*/ BOOL T2TempPluginComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const { + T2TemplatePlugin *p1 = *((T2TemplatePlugin **) inItemOne); + T2TemplatePlugin *p2 = *((T2TemplatePlugin **) inItemTwo); + return p1->GetSortKey() == p2->GetSortKey(); } -/*static*/ T2TempPluginComparator* T2TempPluginComparator::sT2TempPluginComparator { +/*static*/ T2TempPluginComparator* T2TempPluginComparator::sT2TempPluginComparator; + +/*static*/ T2TempPluginComparator* T2TempPluginComparator::GetComparator() { + if (!sT2TempPluginComparator) + sT2TempPluginComparator = new T2TempPluginComparator; + return sT2TempPluginComparator; } diff --git a/src/T2DLL/T2TempPluginComparator.h b/src/T2DLL/T2TempPluginComparator.h index 028c6dd..86e9f4c 100644 --- a/src/T2DLL/T2TempPluginComparator.h +++ b/src/T2DLL/T2TempPluginComparator.h @@ -1,17 +1,13 @@ #pragma once #include "common.h" +#include "LComparator.h" -class T2TempPluginComparator { +class AFX_EXT_CLASS T2TempPluginComparator : public LComparator { public: - virtual int Compare(const void*, const void*, unsigned int, unsigned int) const; - virtual int IsEqualTo(const void*, const void*, unsigned int, unsigned int) const; + virtual ~T2TempPluginComparator() {} + virtual int Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const; + virtual BOOL IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const; static T2TempPluginComparator* GetComparator(); protected: static T2TempPluginComparator* sT2TempPluginComparator; - -public: - T2TempPluginComparator() {} - virtual ~T2TempPluginComparator() {} - T2TempPluginComparator(const T2TempPluginComparator&) {} - T2TempPluginComparator& operator=(const T2TempPluginComparator&) {} }; diff --git a/src/T2DLL/T2TemplatePlugin.cpp b/src/T2DLL/T2TemplatePlugin.cpp index 4810b87..b446eeb 100644 --- a/src/T2DLL/T2TemplatePlugin.cpp +++ b/src/T2DLL/T2TemplatePlugin.cpp @@ -9,7 +9,7 @@ T2TemplatePlugin::T2TemplatePlugin(DWORD type, T2PluginSpecifier& specifier, CRe /*virtual*/ T2TemplatePlugin::~T2TemplatePlugin() { } -/*virtual*/ int T2TemplatePlugin::InitObject(T2Object*) { +/*virtual*/ BOOL T2TemplatePlugin::InitObject(T2Object*) { return true; } diff --git a/src/T2DLL/T2TemplatePlugin.h b/src/T2DLL/T2TemplatePlugin.h index 5ea32e8..8484196 100644 --- a/src/T2DLL/T2TemplatePlugin.h +++ b/src/T2DLL/T2TemplatePlugin.h @@ -2,12 +2,12 @@ #include "common.h" #include "CDefRsrcPlugin.h" -class T2TemplatePlugin : public CDefRsrcPlugin { +class AFX_EXT_CLASS T2TemplatePlugin : public CDefRsrcPlugin { public: T2TemplatePlugin(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, CProgramPlugin* plugin); virtual ~T2TemplatePlugin(); virtual int GetSortKey() { return 0; } - virtual int InitObject(T2Object*); + virtual BOOL InitObject(T2Object*); virtual void LoadSound(T2TowerDoc*); CProgramPlugin* GetPlugin() { return mPlugin; } diff --git a/src/T2DLL/T2TemplatePluginDB.cpp b/src/T2DLL/T2TemplatePluginDB.cpp index 4a62bc5..7b7b94c 100644 --- a/src/T2DLL/T2TemplatePluginDB.cpp +++ b/src/T2DLL/T2TemplatePluginDB.cpp @@ -1,19 +1,79 @@ +#include "T2TemplatePlugin.h" #include "T2TemplatePluginDB.h" +#include "T2TemplatePluginList.h" -T2TemplatePluginDB::T2TemplatePluginDB() { +T2TemplatePluginDB::T2TemplatePluginDB() + : LArray(sizeof(T2TemplatePluginList *)) +{ } /*virtual*/ T2TemplatePluginDB::~T2TemplatePluginDB() { } -void T2TemplatePluginDB::Regist(T2TemplatePlugin*) { +void T2TemplatePluginDB::Regist(T2TemplatePlugin* plugin) { + if (!plugin) + return; + + LArrayIterator iterator(*this); + T2TemplatePluginList *list; + BOOL found = false; + + while (!found && iterator.Next(&list)) { + if (list->GetPluginType() == plugin->GetType()) { + list->Add(plugin); + found = true; + } + } + + if (!found) { + list = new T2TemplatePluginList(plugin->GetType()); + list->Add(plugin); + InsertItemsAt(1, mItemCount + 1, &list); + } } -void T2TemplatePluginDB::Add(T2TemplatePluginList*) { +void T2TemplatePluginDB::Add(T2TemplatePluginList* list) { + LArrayIterator iterator(*this); + T2TemplatePluginList *existingList; + BOOL found = false; + + while (!found && iterator.Next(&existingList)) { + if (existingList->GetPluginType() == list->GetPluginType()) { + LArrayIterator pluginIterator(*list); + T2TemplatePlugin *plugin; + + while (pluginIterator.Next(&plugin)) { + existingList->Add(plugin); + } + + found = true; + } + } + + if (!found) + InsertItemsAt(1, mItemCount + 1, &list); } -T2TemplatePluginList* T2TemplatePluginDB::GetTemplatePluginList(unsigned long) { +T2TemplatePluginList* T2TemplatePluginDB::GetTemplatePluginList(DWORD pluginType) { + LArrayIterator iterator(*this); + T2TemplatePluginList *list; + + while (iterator.Next(&list)) { + if (list->GetPluginType() == pluginType) + return list; + } + + return NULL; } T2TenantDef* T2TemplatePluginDB::FindFloor() { + LArrayIterator iterator(*this); + T2TemplatePluginList *list; + + while (iterator.Next(&list)) { + if (list->GetPluginType() == 'TnPl') + return list->FindFloor(); + } + + return NULL; } diff --git a/src/T2DLL/T2TemplatePluginDB.h b/src/T2DLL/T2TemplatePluginDB.h index ae350ff..0d53a16 100644 --- a/src/T2DLL/T2TemplatePluginDB.h +++ b/src/T2DLL/T2TemplatePluginDB.h @@ -1,15 +1,13 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2TemplatePluginDB { +class T2TemplatePluginDB : private LArray { public: T2TemplatePluginDB(); virtual ~T2TemplatePluginDB(); void Regist(T2TemplatePlugin*); void Add(T2TemplatePluginList*); - T2TemplatePluginList* GetTemplatePluginList(unsigned long); + T2TemplatePluginList* GetTemplatePluginList(DWORD pluginType); T2TenantDef* FindFloor(); - - T2TemplatePluginDB(const T2TemplatePluginDB&) {} - T2TemplatePluginDB& operator=(const T2TemplatePluginDB&) {} }; diff --git a/src/T2DLL/T2TemplatePluginList.cpp b/src/T2DLL/T2TemplatePluginList.cpp index c3063a2..1d1158f 100644 --- a/src/T2DLL/T2TemplatePluginList.cpp +++ b/src/T2DLL/T2TemplatePluginList.cpp @@ -1,46 +1,172 @@ +#include "T2MoverDef.h" +#include "T2OuterObjDef.h" +#include "T2PeopleDef.h" +#include "T2SilhouetteDef.h" #include "T2TemplatePluginList.h" +#include "T2TempPluginComparator.h" +#include "T2TenantDef.h" -T2TemplatePluginList::T2TemplatePluginList(unsigned long) { +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*) { +void T2TemplatePluginList::Regist(T2TemplatePlugin* plugin) { + if (!plugin) + return; + + InsertItemsAt(1, mItemCount + 1, &plugin); } -void T2TemplatePluginList::Add(T2TemplatePlugin*) { +void T2TemplatePluginList::Add(T2TemplatePlugin* plugin) { + if (!plugin) + return; + + InsertItemsAt(1, mItemCount + 1, &plugin); } unsigned int T2TemplatePluginList::GetItemCount() { + return GetCount(); } -T2TemplatePlugin* T2TemplatePluginList::GetItemAt(int) { +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 *plugin; + while (iterator.Next(&plugin)) { + if (plugin->IsFloor()) + return plugin; + } + + return NULL; } -T2TenantDef* T2TemplatePluginList::FindTenantDef(int) { +T2TenantDef* T2TemplatePluginList::FindTenantDef(int equipType) { + if (mPluginType != 'TnDf') + return NULL; + + LArrayIterator iterator(*this); + T2TenantDef *plugin; + while (iterator.Next(&plugin)) { + if (plugin->GetEquipType() == equipType) + return plugin; + } + + return NULL; } -T2MoverDef* T2TemplatePluginList::FindMoverDef(int) { +T2MoverDef* T2TemplatePluginList::FindMoverDef(int equipType) { + if (mPluginType != 'MvDf') + return NULL; + + LArrayIterator iterator(*this); + T2MoverDef *plugin; + while (iterator.Next(&plugin)) { + if (plugin->GetEquipType() == equipType) + return plugin; + } + + return NULL; } -T2OuterObjDef* T2TemplatePluginList::FindOutObjDef(int) { +T2OuterObjDef* T2TemplatePluginList::FindOutObjDef(int toolType) { + if (mPluginType != 'OODf') + return NULL; + + LArrayIterator iterator(*this); + T2OuterObjDef *plugin; + while (iterator.Next(&plugin)) { + if (plugin->GetToolType() == toolType) + return plugin; + } + + return NULL; } -T2PeopleDef* T2TemplatePluginList::FindPeopleDef(int) { +T2PeopleDef* T2TemplatePluginList::FindPeopleDef(int peopleType) { + if (mPluginType != 'PPDf') + return NULL; + + LArrayIterator iterator(*this); + T2PeopleDef *plugin; + while (iterator.Next(&plugin)) { + if (plugin->GetPeopleType() == peopleType) + return plugin; + } + + return NULL; } -T2SilhouetteDef* T2TemplatePluginList::FindSilhouette(int) { +T2SilhouetteDef* T2TemplatePluginList::FindSilhouette(int silhouetteType) { + if (mPluginType != 'SlDf') + return NULL; + + LArrayIterator iterator(*this); + T2SilhouetteDef *plugin; + while (iterator.Next(&plugin)) { + if (plugin->GetSilhouetteType() == silhouetteType) + return plugin; + } + + return NULL; } int T2TemplatePluginList::CalcCategoryCount() { + int count = 0; + LArray categories(sizeof(int)); + LArrayIterator toolDefIterator(*this); + T2ToolDef *toolDef; + + while (toolDefIterator.Next(&toolDef)) { + int categoryNo = toolDef->mCategoryNo; + BOOL found = false; + + LArrayIterator categoryIterator(categories); + int check; + while (categoryIterator.Next(&check)) { + if (check == categoryNo) { + found = true; + break; + } + } + + if (!found) { + categories.InsertItemsAt(1, categories.GetCount() + 1, &categoryNo); + count++; + } + } + + return count; } -void T2TemplatePluginList::DispatchIdle(T2TowerDoc*) { +void T2TemplatePluginList::DispatchIdle(T2TowerDoc* towerDoc) { + if (mPluginType != 'OODf' && mPluginType != 'MvDf' && mPluginType != 'TnDf') + return; + + LArrayIterator iterator(*this); + T2ToolDef *toolDef; + + while (iterator.Next(&toolDef)) + toolDef->DefIdleProc(towerDoc); } diff --git a/src/T2DLL/T2TemplatePluginList.h b/src/T2DLL/T2TemplatePluginList.h index c22c68b..4ca85e1 100644 --- a/src/T2DLL/T2TemplatePluginList.h +++ b/src/T2DLL/T2TemplatePluginList.h @@ -1,23 +1,32 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2TemplatePluginList { +class AFX_EXT_CLASS T2TemplatePluginList : private LArray { public: - T2TemplatePluginList(unsigned long); + T2TemplatePluginList(DWORD pluginType); virtual ~T2TemplatePluginList(); + void AllClear(); void Regist(T2TemplatePlugin*); void Add(T2TemplatePlugin*); unsigned int GetItemCount(); T2TemplatePlugin* GetItemAt(int); T2TenantDef* FindFloor(); - T2TenantDef* FindTenantDef(int); - T2MoverDef* FindMoverDef(int); - T2OuterObjDef* FindOutObjDef(int); - T2PeopleDef* FindPeopleDef(int); - T2SilhouetteDef* FindSilhouette(int); + T2TenantDef* FindTenantDef(int equipType); + T2MoverDef* FindMoverDef(int equipType); + T2OuterObjDef* FindOutObjDef(int toolType); + T2PeopleDef* FindPeopleDef(int peopleType); + T2SilhouetteDef* FindSilhouette(int silhouetteType); int CalcCategoryCount(); void DispatchIdle(T2TowerDoc*); - unsigned long GetPluginType() { return 0; } + DWORD GetPluginType() { return mPluginType; } + +protected: + friend class T2PeopleLoader; + friend class T2Settlement; + friend class T2TemplatePluginDB; + friend class T2ToolWindow; + DWORD mPluginType; }; diff --git a/src/T2DLL/T2Tenant.cpp b/src/T2DLL/T2Tenant.cpp index 5d36e88..7fb98fb 100644 --- a/src/T2DLL/T2Tenant.cpp +++ b/src/T2DLL/T2Tenant.cpp @@ -1,316 +1,1901 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2CustomerTableIterator.h" +#include "T2DateTime.h" +#include "T2EquipPtrList.h" +#include "T2FloorCEArray.h" +#include "T2FloorInfo.h" +#include "T2HallEventPlugin.h" +#include "T2MetroRailway.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleAnimeDef.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleLinkIterator.h" +#include "T2PeoplePtrList.h" +#include "T2Pool.h" +#include "T2RegistedTenantDB.h" +#include "T2RouteNavigator.h" +#include "T2SoundPlayer.h" +#include "T2SubPlugin.h" +#include "T2TemplatePluginList.h" #include "T2Tenant.h" +#include "T2TenantCEArray.h" +#include "T2TenantMemberDef.h" +#include "T2TenantMemberTableDef.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2Transport.h" +#include "T2TrafficInfo.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" +#include "UT2Utils.h" T2Tenant::T2Tenant() { + mKindIndex = 0; + mResideDay = 0; + mPeopleEstimate = 0; + mEstimate = 0; + + mFirstPeople = NULL; + m64 = NULL; + + mMark = -1; + mIsBind = true; + + mRelatedTenantID = 0; + + mReserveCount = 0; + mBelongCount = 0; + mWorkCount = 0; + mCustomerCount = 0; + mTotalCustomer = 0; + + mBelongList = NULL; + mRelatedTenantList = NULL; + + mMerchandiseCount = 0; } /*virtual*/ T2Tenant::~T2Tenant() { + if (mBelongList) + delete mBelongList; } -unsigned int T2Tenant::GetFloorID(int) { -} +unsigned int T2Tenant::GetFloorID(int inV) { + if (IsFloor()) + return GetEquipID(); + + if (!mCEArray) + return 0; + + int v = inV; + if (v == -1) + v = 1; + else + v = mArea.bottom - inV; + + unsigned int theFloorID = ((T2TenantCEArray *) mCEArray)->GetFloorID(v); + return theFloorID; +} + +void T2Tenant::SetFloorID(T2FloorInfo* inFloorInfo) { + if (inFloorInfo && mCEArray) { + for (int v = mArea.bottom - 1; v >= mArea.top; v--) { + T2Tenant *theTenant = inFloorInfo->GetTenant(v, mArea.left); +#line 64 + _ASSERT(theTenant != NULL); + + if (theTenant) { + unsigned int floorID = theTenant->GetEquipID(); + ((T2TenantCEArray *) mCEArray)->SetFloorID(floorID); + } + } + } +} + +/*virtual*/ PROCCODE T2Tenant::DoDestruct(T2TowerDoc* inDoc, POINT inPt, RECT& outRect) { + PROCCODE result = GetEquipDef()->DoDestructProc(inDoc, this, inPt, outRect); + + if (result == ProcCode_0) { + PARTCODE partCode = GetPartFromPoint(inDoc, inPt, NULL); + if (partCode == PartCode_2) { + GetEquipArea(outRect); + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; + + if (theFloorInfo) { + if (IsFloor()) { + inDoc->towerDoc_vf124()->FloorRemoved(this, false); + theFloorInfo->FillTenantID(outRect, 0); + outRect.left -= theFloorInfo->GetEntranceWidth(); + outRect.right += theFloorInfo->GetEntranceWidth(); + } else { + RemovePeople(inDoc); + inDoc->towerDoc_vf268(this); + + RECT rect = outRect; + rect.top = rect.bottom - 1; + + unsigned int tenantID; + LArrayIterator iterator(*mCEArray); + while (iterator.Next(&tenantID)) { + theFloorInfo->FillTenantID(rect, tenantID); + OffsetRect(&rect, 0, -1); + } + } + } + + if (GetEquipDef()) + GetEquipDef()->DestructFinish(inDoc, this); + + SetUsed(false); + return ProcCode_1; + } else { + return ProcCode_2; + } + } + + return result; +} + +void T2Tenant::AddPopulation(T2People* inPeople) { + if (IsBelongPeople(inPeople)) { + mBelongCount++; + } else { + if (mReserveCount > 0) + mReserveCount--; + mCustomerCount++; + } +} + +void T2Tenant::SubPopulation(T2People* inPeople) { + if (IsBelongPeople(inPeople)) + mBelongCount--; + else + mCustomerCount--; +} + +/*virtual*/ BOOL T2Tenant::Enter(CLink* inLink) { + T2People *thePeople = (T2People *) inLink; + + thePeople->SetCurrEquipID(mEquipID); + AddPopulation(thePeople); + + if (IsFloor()) { + POINT theCurPt = thePeople->GetCurPosition(); + if (theCurPt.x < mArea.left) + thePeople->MoveHTo(mArea.left); + else if (theCurPt.x > (mArea.right - 2)) + thePeople->MoveHTo(mArea.right - 2); + + thePeople->MoveVTo(mArea.bottom - 1); + thePeople->ChangeStatus(kStatus3); + } else { + POINT theEntrancePt = GetEntrancePt(); + POINT theCurPt = thePeople->GetCurPosition(); + + if (theCurPt.x != theEntrancePt.x || theCurPt.y != theEntrancePt.y) { + thePeople->MoveVTo(theEntrancePt.y); + thePeople->MoveHTo(theEntrancePt.x); + } + + thePeople->ChangeStatus(kStatus11); + } + + if (!mFirstPeople) { + mFirstPeople = (T2People *) inLink; + m64 = (T2People *) inLink; + inLink->SetPrev(NULL); + return true; + } + + if (m64) { + m64->InsertAt(inLink); + m64 = (T2People *) inLink; + return true; + } + + return false; +} + +/*virtual*/ BOOL T2Tenant::Leave(CLink* inLink) { + SubPopulation((T2People *) inLink); + + if (mFirstPeople) { + if (mFirstPeople == inLink) { + mFirstPeople = (T2People *) inLink->GetNext(); + + if (!mFirstPeople) { + m64 = NULL; + } else if (!mFirstPeople->GetNext()) { + m64 = mFirstPeople; + } + + inLink->Remove(); + return true; + } + + if (m64 != inLink) { + inLink->Remove(); + } else if (m64 == inLink) { + m64 = (T2People *) inLink->GetPrev(); + inLink->Remove(); + + if (!m64) + mFirstPeople = NULL; + + return true; + } + } + + return false; +} + +void T2Tenant::EnterTenant(T2TowerDoc* inDoc, T2People* inPeople) { + if (IsOpen() || IsBelongPeople(inPeople)) { + if (!IsNeedToilet() || !inPeople->IsSetSpecialFlag(kSpecialFlag2) || !inPeople->SearchToilet(inDoc)) { + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; + + T2Tenant *thePreviousTenant = theFloorInfo->GetTenant(inPeople->mCurrEquipID); + if (thePreviousTenant) + thePreviousTenant->Leave(inPeople); + Enter(inPeople); -void T2Tenant::SetFloorID(T2FloorInfo*) { -} + inPeople->ClearDestination(); + inPeople->UpdateEstimation(); -/*virtual*/ PROCCODE T2Tenant::DoDestruct(T2TowerDoc*, POINT, RECT&) { + T2TenantDef *theDef = (T2TenantDef *) GetEquipDef(); + if (theDef) { + inPeople->ClearSpecialFlag(theDef->GetDownFlag()); + theDef->EnterTenant(inDoc, this, inPeople); + } + } + } else { + inPeople->Return(); + inPeople->IncEstimate(-100); + } } -void T2Tenant::AddPopulation(T2People*) { -} +void T2Tenant::LeaveTenant(T2TowerDoc* inDoc, T2People* inPeople) { + Leave(inPeople); -void T2Tenant::SubPopulation(T2People*) { -} + inPeople->mPrevTenantType = mEquipType; -/*virtual*/ int T2Tenant::Enter(CLink*) { -} + POINT exitPos = GetExitPt(); + inPeople->MoveVTo(exitPos.y); + inPeople->MoveHTo(exitPos.x); -/*virtual*/ int T2Tenant::Leave(CLink*) { -} + unsigned int theFloorID = GetExitFloorID(); + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; -void T2Tenant::EnterTenant(T2TowerDoc*, T2People*) { -} + T2Tenant *theFloor = theFloorInfo->GetTenant(theFloorID); + if (theFloor) + theFloor->Enter(inPeople); -void T2Tenant::LeaveTenant(T2TowerDoc*, T2People*) { + T2TenantDef *theTenantDef = (T2TenantDef *) GetEquipDef(); + if (theTenantDef) + theTenantDef->LeaveTenant(inDoc, this, inPeople); } -/*virtual*/ void T2Tenant::Draw(T2TowerDoc*, const RECT&) { -} +/*virtual*/ void T2Tenant::Draw(T2TowerDoc* inDoc, const RECT& inRect) { + if (inDoc->mViewMode != ViewMode_1 && IsFire() && !IsFloor()) { + inDoc->towerDoc_vf170()->DrawRubble(inDoc, this); + } else { + GetEquipDef()->DrawProc(this, inRect, inDoc); + if (true) + GetEquipDef()->DrawPeople(inDoc, this); -/*virtual*/ void T2Tenant::DrawSelf(T2TowerDoc*, const RECT&) { -} + if (mMark > -1 && inDoc->towerDoc_vf140() != ViewMode_1) { + T2WorldDef *theWorldDef = inDoc->mWorldDef; + if (theWorldDef) { + RECT equipArea, qdRect; + GetEquipArea(equipArea); + UT2Coordinate::UnitToQD(equipArea, qdRect, inDoc->mZoomLevel); -/*virtual*/ unsigned int T2Tenant::Idle(T2TowerDoc*) { + theWorldDef->DrawMark(inDoc->towerDoc_vf10C(), qdRect, inDoc->towerDoc_vf108(), mMark); + } + } + } + + T2WorldDef *theWorldDef = inDoc->mWorldDef; + if (theWorldDef->IsBlackOut()) { + CRect rect = mArea; + DrawColorMesh(inDoc, rect, 1); + } else if (inDoc->towerDoc_vf140() == ViewMode_5) { + CRect rect = inRect; + DrawTrafficColor(inDoc, rect); + } else if (inDoc->towerDoc_vf140() != ViewMode_0) { + DrawViewModeColor(inDoc); + } + + unsigned int entranceFloorID = GetEntranceFloorID(); + if (!IsFloor() && mCEArray->GetCount() == 0) { + CRect rect = mArea; + DrawColorMesh(inDoc, rect, 9); + } } -/*virtual*/ void T2Tenant::AddCEMoverID(const T2FloorInfo*, POINT, unsigned int) { +/*virtual*/ void T2Tenant::DrawSelf(T2TowerDoc* inDoc, const RECT& inRect) { } -int T2Tenant::InitTenant(T2TenantDef*, const RECT&, unsigned int) { +/*virtual*/ unsigned int T2Tenant::Idle(T2TowerDoc* inDoc) { + if (mStatus != kTenantStatus0) { + unsigned int result = GetEquipDef()->IdleProc(this, inDoc); + + if (result != -1 && result > 0) { + inDoc->GetTowerMainView()->tmv_vf128(mArea); + mDrawMode = DrawMode1; + } + + return result; + } + + return 0; } -/*virtual*/ void T2Tenant::LoadSelf(T2Archive&, T2TowerDoc*) { +/*virtual*/ void T2Tenant::AddCEMoverID(const T2FloorInfo* inFloorInfo, POINT inPt, unsigned int inID) { + int moverID = inFloorInfo->GetLeftMoverID(inPt, mArea.left); + InsertCEID(moverID, inID); } -/*virtual*/ void T2Tenant::SaveSelf(T2Archive&) { +BOOL T2Tenant::InitTenant(T2TenantDef* inDef, const RECT& inRect, unsigned int inValiation) { + InitEquip(inDef, inRect, inValiation); + + mStatus = kTenantStatus0; + mDrawMode = DrawMode2; + + mFirstPeople = NULL; + m64 = NULL; + + mKindIndex = 0; + mResideDay = 0; + mPeopleEstimate = 300; + mEstimate = 0; + + mMark = -1; + mIsBind = true; + + mRelatedTenantID = 0; + + mReserveCount = 0; + mBelongCount = 0; + mCustomerCount = 0; + mWorkCount = 0; + mTotalCustomer = 0; + + mSubPlugin = NULL; + + mBelongList = NULL; + mRelatedTenantList = NULL; + + mMerchandiseCount = 0; + + if (IsFloor()) + mCEArray = new T2FloorCEArray; + else + mCEArray = new T2TenantCEArray; + + InitBelongList(); + return true; +} + +/*virtual*/ void T2Tenant::LoadSelf(T2Archive& inArchive, T2TowerDoc* inDoc) { + DWORD code; + inArchive >> code; +#line 422 + _ASSERT(code == '<TN>'); + + T2Equip::LoadSelf(inArchive, inDoc); + + if (IsUsed()) { + SetEquipDef(inDoc->mTenantTemplates->FindTenantDef(mEquipType)); + + if (mToolDef) { + mAttribute = mToolDef->GetAttribute(); + mCapacity = GetEquipDef()->GetCapacity(); + } + +#pragma var_order(ui, uc, s, pptrList, us, theLinkData, code) + unsigned char uc; + unsigned short us; + unsigned int ui; + short s; + + inArchive >> uc; + mKindIndex = uc; + + inArchive >> mResideDay; + + inArchive >> s; + mPeopleEstimate = s; + inArchive >> s; + mEstimate = s; + + inArchive >> uc; + mIsBind = (uc != 0); + + inArchive >> us; + mRelatedTenantID = us; + + inArchive >> s; + mReserveCount = s; + inArchive >> s; + mBelongCount = s; + inArchive >> s; + mCustomerCount = s; + inArchive >> s; + mWorkCount = s; + inArchive >> s; + mTotalCustomer = s; + + inArchive >> us; + mTenantNumber = us; + + inArchive >> ui; + mRelatedTenantList = (T2EquipPtrList *) ui; + + inArchive >> s; + mMerchandiseCount = s; + + if (mMerchandiseCount > 0) { + for (int i = 0; i < mMerchandiseCount; i++) { + unsigned char val; + inArchive >> val; + mMerchandise[i] = val; + } + } + + DWORD code; + inArchive >> code; + + unsigned int theLinkData; + inArchive >> theLinkData; + if (theLinkData != 0) { + T2People *thePeople = inDoc->mPeopleArrayList->FindPeople(theLinkData); + mFirstPeople = thePeople; + } + + inArchive >> theLinkData; + if (theLinkData != 0) { + T2People *thePeople = inDoc->mPeopleArrayList->FindPeople(theLinkData); + m64 = thePeople; + } + + unsigned int pptrList; + inArchive >> pptrList; + + if (pptrList != 0) { + mBelongList = new T2PeoplePtrList; + if (mBelongList) + mBelongList->LoadSelf(inArchive, inDoc->mPeopleArrayList); + } + + if (GetEquipDef()) { + GetEquipDef()->LoadExtraData(inArchive, inDoc, this); + } else { + int len; + inArchive >> len; + for (int i = 0; i < len; i++) { + char tmp; + inArchive >> tmp; + } + } + + if (GetRegistID() == kTenantRegistID1 && mStatus == kTenantStatus38) + SetMark(0); + + if (mToolDef && mToolDef->GetCategory() == 50 && mWorkCount > 2) + SetMark(1); + + mDrawMode = DrawMode2; + } +} + +/*virtual*/ void T2Tenant::SaveSelf(T2Archive& inArchive) { + DWORD code = '<TN>'; + inArchive << code; + + T2Equip::SaveSelf(inArchive); + + if (IsUsed()) { + inArchive << (unsigned char) mKindIndex; + inArchive << mResideDay; + inArchive << (short) mPeopleEstimate; + inArchive << (short) mEstimate; + inArchive << (unsigned char) (mIsBind != 0); + inArchive << (unsigned short) mRelatedTenantID; + inArchive << (short) mReserveCount; + inArchive << (short) mBelongCount; + inArchive << (short) mCustomerCount; + inArchive << (short) mWorkCount; + inArchive << (short) mTotalCustomer; + inArchive << (unsigned short) mTenantNumber; + +#pragma var_order(thePeople, relatedTenantList, zero, code) + unsigned int relatedTenantList = 0; + if (mRelatedTenantList) + relatedTenantList = mRelatedTenantList->GetAttribute(); + inArchive << relatedTenantList; + + inArchive << (short) mMerchandiseCount; + if (mMerchandiseCount > 0) { + for (int i = 0; i < mMerchandiseCount; i++) { + unsigned char val = mMerchandise[i]; + inArchive << val; + } + } + + DWORD code = 'pLk>'; + inArchive << code; + + unsigned int zero = 0; + T2People *thePeople; + + if (mFirstPeople) { + thePeople = mFirstPeople; + unsigned int id = thePeople->GetPeopleID(); + inArchive << id; + } else { + inArchive << zero; + } + + if (m64) { + thePeople = m64; + unsigned int id = thePeople->GetPeopleID(); + inArchive << id; + } else { + inArchive << zero; + } + + if (mBelongList) { + unsigned int flag = 1; + inArchive << flag; + mBelongList->SaveSelf(inArchive); + } else { + unsigned int flag = 0; + inArchive << flag; + } + + GetEquipDef()->SaveExtraData(inArchive, this); + } } /*virtual*/ unsigned int T2Tenant::GetEntranceFloorID() { + unsigned int result = 0; + + if (IsFloor()) { + result = mEquipID; + } else { + int v = 1; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) + v += def->GetEntranceV(); + + result = ((T2TenantCEArray *) mCEArray)->GetFloorID(v); + } + + return result; } POINT T2Tenant::GetEntrancePt() const { + POINT pt; + pt.y = mArea.bottom - 1; + pt.x = mArea.left; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) { + pt.y -= def->GetEntranceV(); + pt.x += def->GetEntranceH(); + } + + return pt; } /*virtual*/ unsigned int T2Tenant::GetExitFloorID() { + unsigned int result = 0; + + if (IsFloor()) { + result = mEquipID; + } else { + int v = 1; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) + v += def->GetExitV(); + + result = ((T2TenantCEArray *) mCEArray)->GetFloorID(v); + } + + return result; } POINT T2Tenant::GetExitPt() { + POINT pt; + pt.y = mArea.bottom - 1; + pt.x = mArea.left; + + T2TenantDef *def = (T2TenantDef *) GetEquipDef(); + if (def) { + pt.y -= def->GetExitV(); + pt.x += def->GetExitH(); + } + + return pt; } T2People* T2Tenant::GetFirstCustomer() const { + T2People *firstCustomer = NULL; + + T2PeopleLinkIterator iterator(GetFirstPeople()); + T2People *thePeople; + + while (!firstCustomer && iterator.Next(&thePeople)) { + if (!IsBelongPeople(thePeople)) + firstCustomer = thePeople; + } + + return firstCustomer; } int T2Tenant::GetBelongCapacity() { + int result = 0; + result = ((T2TenantDef *) GetEquipDef())->GetBelongCapacity(); + return result; } -int T2Tenant::IsTherePeople(T2People*) { +BOOL T2Tenant::IsTherePeople(T2People* inPeople) { + BOOL found = false; + + T2PeopleLinkIterator iterator(mFirstPeople); + T2People *thePeople; + + while (!found && iterator.Next(&thePeople)) { + if (thePeople == inPeople) + found = true; + } + + return found; } void T2Tenant::StartBuild() { + if (IsFloor()) { + mStatus = kTenantStatus1; + } else { + mStatus = kTenantStatus2; + mTenantNumber = GetCurrentT2TowerDoc()->towerDoc_vf27C(mArea.bottom - 1); + } + + ((T2TenantDef *) GetEquipDef())->BuildStartProc(GetCurrentT2TowerDoc(), this); } void T2Tenant::UpdatePatternIndex() { + mPatIndex = (GetNumOfPattern() * mKindIndex) + mStatus - 10; } -void T2Tenant::UpdatePatternIndex(int) { +void T2Tenant::UpdatePatternIndex(int inIndex) { + mPatIndex = (GetNumOfPattern() * mKindIndex) + inIndex; } int T2Tenant::GetNumOfPattern() const { -} + int result = 1; + result = ((T2TenantDef *) GetEquipDef())->GetNumOfPattern(); + return result; +} + +int T2Tenant::CollectCustomerFromPool(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime, T2Tenant* inTenant) { + int numCustomer = 0; + + int searchScore = inTable->GetScore(T2PlaceParamDef::Place_0); + unsigned int checkRoute = CheckRouteFromPool(inDoc, searchScore); -int T2Tenant::CollectCustomerFromPool(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int, T2Tenant*) { + if (checkRoute > 0) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + unsigned int restCapacity = CalcRestCapacity(); + int econoType = inTable->GetEconoType(); + + T2CustomerTableIterator custIterator(inTable); + + unsigned int theFloorID; + if (!inTenant) + theFloorID = mEquipID; + else + theFloorID = inTenant->GetEquipID(); + + T2TenantMemberDef *theMemberDef; + unsigned int theRate; + while (restCapacity > 0 && custIterator.Next(theMemberDef, theRate)) { + if (theRate > restCapacity) + theRate = restCapacity; + + BOOL outOfPeople = false; + for (unsigned int i = 0; !outOfPeople && i < theRate; i++) { + T2People *people = thePool->Call(theMemberDef, econoType, checkRoute, inTable->GetSpecialFlag()); + if (people) { + people->SetDestination(theFloorID, inTime + i * 2); + numCustomer++; + restCapacity--; + } else { + outOfPeople = true; + } + } + } + } + + return numCustomer; +} + +int T2Tenant::CollectCustomerFromTenant(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime) { + int numCustomer = 0; + + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); + T2Tenant *theTenant = theNavigator->SelectNearTenant(GetEntrancePt(), inTable->GetScore(T2PlaceParamDef::Place_1)); + + if (theTenant) { + unsigned int restCapacity = CalcRestCapacity(); + int econoType = inTable->GetEconoType(); + unsigned int theSpecialFlag = inTable->GetSpecialFlag(); + + T2CustomerTableIterator custTableIterator(inTable); + T2TenantMemberDef *memberDef; + unsigned int theRate; + + T2PeopleLinkIterator peopleLinkIterator(theTenant->GetFirstPeople()); + T2People *people; + + int time = GetBindTime(); + + while (restCapacity > 0 && custTableIterator.Next(memberDef, theRate)) { + if (theRate > restCapacity) + theRate = restCapacity; + + peopleLinkIterator.Reset(); + unsigned int i = 0; + while (i < theRate && peopleLinkIterator.Next(&people)) { + if (people->IsSetSpecialFlag(theSpecialFlag)) { + if (people->CalledInTenant(memberDef, econoType, time, mEquipType, mEquipID, inTime)) { + i++; + numCustomer++; + restCapacity--; + } + } + } + } + } + + return numCustomer; +} + +int T2Tenant::CollectCustomerFromFloor(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime) { + int numCustomer = 0; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + unsigned int theEntranceFloorID = GetEntranceFloorID(); + T2Tenant *theEntranceFloor = theFloorInfo->GetTenant(theEntranceFloorID); + + if (theEntranceFloor->IsTherePeople()) { + unsigned int restCapacity = CalcRestCapacity(); + int searchScore = inTable->GetScore(T2PlaceParamDef::Place_2); + int econoType = inTable->GetEconoType(); + unsigned int theSpecialFlag = inTable->GetSpecialFlag(); + + T2CustomerTableIterator custTableIterator(inTable); + T2TenantMemberDef *memberDef; + unsigned int theRate; + + T2PeopleLinkIterator peopleLinkIterator(theEntranceFloor->GetFirstPeople()); + T2People *people; + + int time = GetBindTime(); + + while (restCapacity > 0 && custTableIterator.Next(memberDef, theRate)) { + if (theRate > restCapacity) + theRate = restCapacity; + + peopleLinkIterator.Reset(); + unsigned int i = 0; + while (i < theRate && peopleLinkIterator.Next(&people)) { + if (people->IsSetSpecialFlag(theSpecialFlag)) { + T2Tenant *theTenant = theFloorInfo->GetTenant(people->GetDstTenant()); + if ((theTenant && theTenant->GetEquipType() != mEquipType) || !theTenant) { + if (people->StopOnHisWay(memberDef, econoType, searchScore, mArea, time, mEquipType, mEquipID, inTime)) { + i++; + numCustomer++; + restCapacity--; + } + } + } + } + } + } + + return numCustomer; +} + +void T2Tenant::CollectCustomer(T2TowerDoc* inDoc, T2Tenant* inTenant) { + if (!WillBeFull()) { + T2DateTime *theNow = inDoc->towerDoc_vf120(); + if (theNow->WithinMinutes(GetOpenTime(), GetCloseTime() - GetBindTime() - 60)) { + T2TenantMemberTableDef *theTable = GetCustomerTableDef(true); + if (theTable) { + int minutes = theNow->GetRawMinutes(); + + if (theTable->IsCollectFromPool(inDoc)) + mReserveCount += CollectCustomerFromPool(inDoc, theTable, minutes, inTenant); + if (theTable->IsCollectFromTenant()) + mReserveCount += CollectCustomerFromTenant(inDoc, theTable, minutes); + if (theTable->IsCollectFromFloor()) + mReserveCount += CollectCustomerFromFloor(inDoc, theTable, minutes); + } + } + } +} + +void T2Tenant::CollectCustomer(T2TowerDoc* inDoc, int inNum) { + T2TenantMemberTableDef *theTable = GetCustomerTableDef(true); + if (theTable) { + int numElem = theTable->GetNumOfElem(); + + for (int i = 0; i < numElem && inNum > 0; i++) { + T2TenantMemberDef *memberDef = theTable->GetElem(i); + if (memberDef) { + if (memberDef->GetNumOfPeople() < inNum) { + inNum -= memberDef->GetNumOfPeople(); + } else { + memberDef->SetNumOfPeople(inNum); + inNum = 0; + } + } + } + } + + CollectCustomer(inDoc, (T2Tenant *) NULL); +} + +int T2Tenant::CollectEmployee(T2TowerDoc* inDoc) { + int numEmployee = 0; + + T2TenantMemberTableDef *theTable = GetEmployeeTableDef(); + if (theTable && theTable->IsCollectFromPool(inDoc)) + numEmployee = CollectEmployeeFromPool(inDoc, theTable); + + return numEmployee; +} + +void T2Tenant::RegistBelongPeople(T2People* inPeople) { + if (mBelongList) { + mBelongList->Add(inPeople); + + if (IsHome()) + inPeople->SetHomeTenant(mEquipID); + else + inPeople->SetWorkTenant(mEquipID); + } } -int T2Tenant::CollectCustomerFromTenant(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int) { +int T2Tenant::CalcInMoney() const { + int result = 0; + result = (GetInMoney() * mTotalCustomer) / 100; + result -= GetOutMoney(); + return result; } -int T2Tenant::CollectCustomerFromFloor(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int) { +void T2Tenant::EnterCustomer(T2People* inPeople, int inBindTime) { + SetBindTime(inPeople, inBindTime); + mTotalCustomer++; } -void T2Tenant::CollectCustomer(T2TowerDoc*, T2Tenant*) { -} +BOOL T2Tenant::IsBelongPeople(T2People* inPeople) const { + BOOL result = false; -void T2Tenant::CollectCustomer(T2TowerDoc*, int) { -} + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; -int T2Tenant::CollectEmployee(T2TowerDoc*) { -} + while (!result && iterator.Next(&people)) { + if (people == inPeople) + result = true; + } + } -void T2Tenant::RegistBelongPeople(T2People*) { + return result; } -int T2Tenant::CalcInMoney() const { -} +void T2Tenant::PushOutPeople(T2TowerDoc* inDoc, T2People* inPeople) { + if (!inPeople) + inPeople = mFirstPeople; -void T2Tenant::EnterCustomer(T2People*, int) { -} + if (inPeople) { + if (!inPeople->IsSetDestination()) { + if (inPeople->IsSetReturn()) + inPeople->SetReturnToDestination(); + else + inPeople->SetDestination(inPeople->mHomeTenant, inDoc->towerDoc_vf120()->GetRawMinutes() + 180); + } -int T2Tenant::IsBelongPeople(T2People*) const { + LeaveTenant(inDoc, inPeople); + } } -void T2Tenant::PushOutPeople(T2TowerDoc*, T2People*) { +void T2Tenant::PushOutAll(T2TowerDoc* inDoc) { + while (mFirstPeople) + PushOutPeople(inDoc, mFirstPeople); } -void T2Tenant::PushOutAll(T2TowerDoc*) { -} +void T2Tenant::PushOutAllCustomer(T2TowerDoc* inDoc) { + T2PeopleLinkIterator iterator(mFirstPeople); + T2People *prevPeople = NULL; + T2People *people = NULL; + + iterator.Next(&prevPeople); + while (prevPeople) { + if (iterator.Next(&people)) + people = NULL; + + if (!IsBelongPeople(prevPeople)) + PushOutPeople(inDoc, prevPeople); -void T2Tenant::PushOutAllCustomer(T2TowerDoc*) { + prevPeople = people; + people = NULL; + } } int T2Tenant::GetPriceIndex() const { + int result = 0; + + if (GetEquipDef() && GetEquipDef()->GetNumOfInMoney() > 1) + result = GetInMoneyIndex() + 1; + + return result; } -void T2Tenant::DuplicateBelongPeople(T2TowerDoc*) { +void T2Tenant::DuplicateBelongPeople(T2TowerDoc* inDoc) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->Duplicate(inDoc); + } + } } -void T2Tenant::RemoveBelongPeople(T2TowerDoc*) { +void T2Tenant::RemoveBelongPeople(T2TowerDoc* inDoc) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + people->Remove(inDoc, mEquipID); + } + + mBelongList->Clear(); + } } -void T2Tenant::RemovePeople(T2TowerDoc*) { +void T2Tenant::RemovePeople(T2TowerDoc* inDoc) { + RemoveBelongPeople(inDoc); + + T2PeopleLinkIterator iterator(mFirstPeople); + T2People *people; + + while (iterator.Next(&people)) + people->IncEstimate(-200); + + PushOutAll(inDoc); } void T2Tenant::ClearBelongPeople() { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + if (people->mHomeTenant == mEquipID) + people->mHomeTenant = 1; + if (people->mWorkTenant == mEquipID) + people->mWorkTenant = 1; + } + } + + mBelongList->Clear(); + } } -void T2Tenant::ClearBelongPeople(T2People*) { +void T2Tenant::ClearBelongPeople(T2People* inPeople) { + if (mBelongList) { + if (inPeople->mHomeTenant == mEquipID) + inPeople->mHomeTenant = 1; + if (inPeople->mWorkTenant == mEquipID) + inPeople->mWorkTenant = 1; + + mBelongList->Clear(inPeople); + } } -void T2Tenant::CallBelongPeople(unsigned int) { +void T2Tenant::CallBelongPeople(unsigned int inTime) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + unsigned int time = inTime + (rand() * 10) % 6; + people->SetDestination(mEquipID, time); + } + } + } } -T2People* T2Tenant::GetBelongPeople(int) { +T2People* T2Tenant::GetBelongPeople(int inIndex) { + T2People *result = NULL; + + if (mBelongList) + result = mBelongList->GetItemAt(inIndex); + + return result; } -T2People* T2Tenant::GetBelongPeopleIn(int) { +T2People* T2Tenant::GetBelongPeopleIn(int inIndex) { + T2People *result = GetBelongPeople(inIndex); + + if (result && result->GetCurTenantID() != mEquipID) + result = NULL; + + return result; } void T2Tenant::SetKind() { + int num = GetNumOfKind(); + + if (num == 0) + mKindIndex = 0; + else + mKindIndex = rand() % num; } int T2Tenant::GetNumOfKind() const { + int result = 1; + result = ((T2TenantDef *) GetEquipDef())->GetNumOfKind(); + return result; } -/*virtual*/ void T2Tenant::SetUsed(int) { +/*virtual*/ void T2Tenant::SetUsed(BOOL used) { + if (!used && IsFavorite()) + GetCurrentT2TowerDoc()->towerDoc_vf1CC(this, false); + + T2Equip::SetUsed(used); + + if (used == 1) + return; + + if (mCEArray) { + delete mCEArray; + mCEArray = NULL; + } + if (mBelongList) { + delete mBelongList; + mBelongList = NULL; + } } unsigned int T2Tenant::GetRegistID() const { + unsigned int result = 0; + + if (mToolDef) + result = ((T2TenantDef *) mToolDef)->GetRegistID(); + + return result; } int T2Tenant::GetEmployeeSearchScore() const { + int searchScore = 0; + + T2TenantMemberTableDef *theTableDef = GetEmployeeTableDef(); + if (theTableDef) + searchScore = theTableDef->GetScore(T2PlaceParamDef::Place_1); + + return searchScore; } int T2Tenant::GetCustomerSearchScore() const { + int searchScore = 0; + + T2TenantMemberTableDef *theTableDef = GetCustomerTableDef(true); + if (theTableDef) + searchScore = theTableDef->GetScore(T2PlaceParamDef::Place_1); + + return searchScore; } -int T2Tenant::IsMoverAvailable() const { +BOOL T2Tenant::IsMoverAvailable() const { + BOOL result = false; + + if (IsFloor() && mCEArray) + result = ((T2RouteCEArray *) mCEArray)->HasCrossEquip(); + + return result; } void T2Tenant::RemoveBelongList() { + if (mBelongList) { + delete mBelongList; + mBelongList = NULL; + } } -int T2Tenant::GetQTMovieName(CString) { +BOOL T2Tenant::GetQTMovieName(CString str) { + BOOL result = false; + + T2TenantDef *theDef = (T2TenantDef *) GetEquipDef(); + if (theDef) + result = theDef->GetQTMovieName(this, str); + + return result; } -void T2Tenant::Destruct(T2TowerDoc*, CRect&) { +void T2Tenant::Destruct(T2TowerDoc* inDoc, CRect& outRect) { + GetEquipArea(outRect); + + T2FloorInfo *theFloorInfo = inDoc->mFloorInfo; + if (theFloorInfo) { + if (IsFloor()) { + inDoc->towerDoc_vf124()->FloorRemoved(this, false); + theFloorInfo->FillTenantID(outRect, 0); + outRect.left -= theFloorInfo->GetEntranceWidth(); + outRect.right += theFloorInfo->GetEntranceWidth(); + } else { + RemovePeople(inDoc); + inDoc->towerDoc_vf268(this); + + RECT rect = outRect; + rect.top = rect.bottom - 1; + + unsigned int tenantID; + LArrayIterator iterator(*mCEArray); + while (iterator.Next(&tenantID)) { + theFloorInfo->FillTenantID(rect, tenantID); + OffsetRect(&rect, 0, -1); + } + } + } + + if (GetEquipDef()) + GetEquipDef()->DestructFinish(inDoc, this); + + SetUsed(false); } -void T2Tenant::SetBindTime(T2People*, unsigned int) { +void T2Tenant::SetBindTime(T2People* inPeople, unsigned int inTime) { + inPeople->SetStartTime(inTime + GetBindTime()); } -int T2Tenant::SetEstimate(int) { +BOOL T2Tenant::SetEstimate(int inEstimate) { + int oldCol = CalcEstimateColor(); + + mEstimate = inEstimate; + if (mEstimate > 300) + mEstimate = 300; + else if (mEstimate < 1) + mEstimate = 1; + + return CalcEstimateColor() != oldCol; } -int T2Tenant::SetPeopleAnime() { +BOOL T2Tenant::SetPeopleAnime() { + BOOL changed = false; + + for (int i = 0; i < GetBelongCapacity(); i++) { + T2People *people = GetBelongPeopleIn(i + 1); + if (people) { + SetPeopleAnime(people, i); + changed |= true; + } + } + + return changed; } -void T2Tenant::SetPeopleAnime(T2People*, int) { +void T2Tenant::SetPeopleAnime(T2People* inPeople, int inIndex) { + if (GetEquipDef()) { + T2PeopleAnimeDef *theDef = ((T2TenantDef *) GetEquipDef())->GetPeopleAnimeDef(); + if (theDef) + theDef->Set(inPeople, mArea.left, inIndex); + } } -void T2Tenant::PushOutCustomer(T2TowerDoc*, int) { +void T2Tenant::PushOutCustomer(T2TowerDoc* inDoc, int inCount) { + T2PeopleLinkIterator iterator(GetFirstPeople()); + T2People *prevPeople = NULL; + T2People *people = NULL; + int numCustomer = 0; + + iterator.Next(&prevPeople); + while (prevPeople && numCustomer < inCount) { + iterator.Next(&people); + + if (!IsBelongPeople(prevPeople)) { + PushOutPeople(inDoc, prevPeople); + numCustomer++; + } + + prevPeople = people; + people = NULL; + } } -int T2Tenant::GetBelongPeopleIndex(T2People*, int&) const { +BOOL T2Tenant::GetBelongPeopleIndex(T2People* inPeople, int& outIndex) const { + BOOL result = false; + + if (mBelongList) + result = mBelongList->GetPeopleIndex(inPeople, outIndex); + + return result; } -int T2Tenant::SetPeopleToSleep() { +BOOL T2Tenant::SetPeopleToSleep() { + BOOL changed = false; + + if (mBelongList) { + BOOL found = false; + + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (!found && iterator.Next(&people)) { + if (people && !people->IsSleep()) { + if (!changed) { + people->SetToSleep(); + changed = true; + } else { + changed = false; + found = true; + } + } + } + } + + return changed; } void T2Tenant::SetAllPeopleToSleep() { -} + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; -void T2Tenant::UnionFloorPeople(T2Tenant*) { + while (iterator.Next(&people)) { + if (people) + people->SetToSleep(); + } + } } -int T2Tenant::IsWithinSearchRange(T2TowerDoc*, T2Tenant*) const { -} +void T2Tenant::UnionFloorPeople(T2Tenant* inTenant) { + if (inTenant->IsTherePeople()) { + T2PeopleLinkIterator iterator(inTenant->GetFirstPeople()); + T2People *people; -void T2Tenant::SetMoviePlugin(T2SubPlugin*) { -} + while (iterator.Next(&people)) + people->SetCurrEquipID(mEquipID); -void T2Tenant::SetHallEventPlugin(T2HallEventPlugin*) { -} + if (IsTherePeople()) + m64->InsertAt(inTenant->mFirstPeople); + else + mFirstPeople = inTenant->mFirstPeople; -int T2Tenant::GetFloorNumber(T2FloorInfo*) const { + m64 = inTenant->m64; + } } -int T2Tenant::GetRoomNumber(T2FloorInfo*) const { -} +BOOL T2Tenant::IsWithinSearchRange(T2TowerDoc* inDoc, T2Tenant* inTenant) const { + BOOL result = false; -void T2Tenant::GetRoomName(T2TowerDoc*, CString&) const { + if (inTenant) { + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); + T2TenantMemberTableDef *theTable = inTenant->GetCustomerTableDef(true); + + if (theTable) { + if (IsFloor()) { + if (GetValiation() == 1) { + if (theNavigator->IsConnectRouteFromLobby(inTenant->GetEntrancePt())) + result = true; + } + } else { + int score = theTable->GetScore(T2PlaceParamDef::Place_1); + if (theNavigator->CheckRoute(inTenant->GetEntrancePt(), GetEntrancePt(), score)) + result = true; + } + } + } + + return result; } -/*virtual*/ void T2Tenant::PlaySoundA(T2TowerDoc*, int, unsigned int, unsigned int) const { +void T2Tenant::SetMoviePlugin(T2SubPlugin* inPlugin) { + SetSubPlugin(inPlugin); + + if (GetEquipDef()) + ((T2TenantDef *) GetEquipDef())->SetCustomerTable(inPlugin); } -int T2Tenant::IsEmptyParking() const { +void T2Tenant::SetHallEventPlugin(T2HallEventPlugin* inPlugin) { + SetSubPlugin(inPlugin); } -T2People* T2Tenant::FindPeople(POINT) const { +int T2Tenant::GetFloorNumber(T2FloorInfo* inFloorInfo) const { + return inFloorInfo->UnitToFloor(mArea.bottom - 1); } -int T2Tenant::InitBelongList() { +int T2Tenant::GetRoomNumber(T2FloorInfo* inFloorInfo) const { + int floorNumber = GetFloorNumber(inFloorInfo); + return (floorNumber > 0) ? ((floorNumber * 1000) + mTenantNumber) : ((floorNumber * 1000) - mTenantNumber); } -void T2Tenant::DrawViewModeColor(T2TowerDoc*) const { +void T2Tenant::GetRoomName(T2TowerDoc* inDoc, CString& outStr) const { + CString roomNum; + UT2Utils::GetRoomNumberString(inDoc->towerDoc_vf12C()->UnitToFloor(mArea.bottom - 1), roomNum); + + outStr += roomNum; + outStr += "\x8A\x4B"; + outStr += (char) GetTenantNumber(); + outStr += "\x8D\x86\x8E\xBA"; + + T2Name *theName = inDoc->mNameDB->Search(this, false); + + CString nameStr; + if (theName) { + unsigned int id; + theName->GetName(nameStr, id); + } else { + GetTypicalName(nameStr); + } + outStr += nameStr; } -void T2Tenant::DrawTrafficColor(T2TowerDoc*, const CRect&) const { +/*virtual*/ void T2Tenant::PlaySound(T2TowerDoc* inDoc, int inID, unsigned int inMask, unsigned int inFlags) const { + if (inDoc->towerDoc_vf15C(mArea)) { + T2EquipDef *theDef = GetEquipDef(); + T2SoundPlayer *thePlayer = inDoc->towerDoc_vf134(); + if (theDef && thePlayer) { + CRect rect; + GetEquipArea(rect); + + CPoint pt = rect.CenterPoint(); + + CString soundName = theDef->CalcSoundID(inID); + + thePlayer->Play(soundName, inMask, inFlags, &pt, PlayMode_0, 100); + } + } } -/*static*/ void T2Tenant::DrawColorMesh(T2TowerDoc*, const CRect&, int) { +BOOL T2Tenant::IsEmptyParking() const { + BOOL result = false; + + if (mBelongList) + result = mBelongList->HasSpace(); + + return result; } -void T2Tenant::IncPeopleEstimate(int) { +T2People* T2Tenant::FindPeople(POINT inPt) const { + T2People *result = NULL; + + if (IsTherePeople()) { + T2PeopleLinkIterator iterator(GetFirstPeople()); + T2People *people; + + while (!result && iterator.Next(&people)) { + if (people->IsWalk()) { + CRect rect; + people->CalcWalkingSilhouetteArea(rect); + + if (rect.PtInRect(inPt)) + result = people; + } + } + } + + return result; +} + +BOOL T2Tenant::InitBelongList() { + BOOL result = true; + + unsigned int capacity = GetBelongCapacity(); + + if (capacity > 0) { + mBelongList = new T2PeoplePtrList(capacity); + if (!mBelongList) + result = false; + } + + return result; +} + +void T2Tenant::DrawViewModeColor(T2TowerDoc* inDoc) const { + T2Tenant *tenant; + int color = -1; + + switch (inDoc->towerDoc_vf140()) { + case ViewMode_2: + color = CalcEstimateColor(); + break; + case ViewMode_3: + switch (GetPriceIndex()) { + case 4: + color = 9; + break; + case 3: + color = 14; + break; + case 2: + color = 15; + break; + case 1: + color = 12; + break; + } + break; + case ViewMode_4: + if (GetRegistID() == kTenantRegistID1 && GetStatus() >= kTenantStatus35) + color = 9; + break; + case ViewMode_6: + tenant = inDoc->towerDoc_vf18C(); + if (tenant) { + if (this == tenant) + color = 14; + else if (IsWithinSearchRange(inDoc, tenant)) + color = 16; + } + break; + } + + if (color != -1) { + CRect rect = mArea; + DrawColorMesh(inDoc, rect, color); + } +} + +void T2Tenant::DrawTrafficColor(T2TowerDoc* inDoc, const CRect& inRect) const { + T2TrafficInfo *theTrafficInfo = inDoc->towerDoc_vf150(); + CRect rect1 = inRect; + + if (inRect.Height() > 1) { + if (IsFloor() || GetEquipDef()->GetCategory() == 100) + rect1.top = inRect.bottom - 1; + } + + for (CPoint pt = rect1.TopLeft(); pt.y < rect1.bottom; pt.y++) { + int baseline = theTrafficInfo->GetRange(pt); + while (pt.x < rect1.right) { + CRect drawRect(pt.x, pt.y, pt.x + 1, pt.y + 1); + + int range; + for (pt.x++; pt.x < rect1.right; pt.x++) { + range = theTrafficInfo->GetRange(pt); + if (range != baseline) + break; + drawRect.right++; + } + + int color; + switch (baseline) { + case 0: + color = 0; + break; + case 1: + color = 7; + break; + case 2: + color = 8; + break; + case 3: + color = 9; + break; + } + + DrawColorMesh(inDoc, drawRect, color); + baseline = range; + } + } +} + +/*static*/ void T2Tenant::DrawColorMesh(T2TowerDoc* inDoc, const CRect& inRect, int inClr) { + CRect qdRect; + UT2Coordinate::UnitToQD(inRect, qdRect, inDoc->mZoomLevel); + + inDoc->towerDoc_vf10C()->FillMesh(qdRect, T2PaletteAnimeDef::GetCommonColor(inClr)); +} + +void T2Tenant::IncPeopleEstimate(int inEstimate) { + mPeopleEstimate += inEstimate; + + if (mPeopleEstimate > 300) + mPeopleEstimate = 300; + else if (mPeopleEstimate < 0) + mPeopleEstimate = 0; } int T2Tenant::CalcEstimateColor() const { -} + int result = -1; + + if (mEstimate != 0) { + if (mEstimate > 200) + result = 12; + else if (mEstimate >= 70) + result = 14; + else + result = 9; + } -int T2Tenant::CollectEmployeeFromPool(T2TowerDoc*, T2TenantMemberTableDef*) { -} + return result; +} + +BOOL T2Tenant::CollectEmployeeFromPool(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable) { + BOOL found = false; + + int searchScore = inTable->GetScore(T2PlaceParamDef::Place_0); + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); -int T2Tenant::IsRegist() const { -} + unsigned int checkRoute = CheckRouteFromPool(inDoc, searchScore); + if (checkRoute > 0) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + int econoType = inTable->GetEconoType(); + BOOL checkOnlyFirstEconoType = inTable->IsCheckOnlyFirstEconoType(); + if (thePool->Find(inTable, econoType, checkRoute, checkOnlyFirstEconoType)) { + unsigned int numOfElem = inTable->GetNumOfElem(); + for (unsigned int i = 0; i < numOfElem; i++) { + T2TenantMemberDef *memberDef = inTable->GetElem(i); + if (memberDef) { + int numPeople = memberDef->GetNumOfPeople(); + for (int j = 0; j < numPeople; j++) { + T2People *people = thePool->Call(memberDef, econoType, checkRoute, 0); + if (people) + RegistBelongPeople(people); + } + } + } + + found = true; + + T2DateTime *theNow = inDoc->towerDoc_vf120(); + mResideDay = theNow->CalcTotalDays(); + } + } + + return found; +} + +BOOL T2Tenant::IsRegist() const { + BOOL result = false; + + if (mToolDef) + result = (((T2TenantDef *) mToolDef)->GetRegistID() > 0) && (mValiation == 0); + + return result; +} + +unsigned int T2Tenant::CheckRouteFromPool(T2TowerDoc* inDoc, unsigned int inScore) const { + unsigned int checkRoute = 0; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2RouteNavigator *theNavigator = inDoc->towerDoc_vf124(); + + POINT entrancePt = GetEntrancePt(); + + if (theNavigator->CheckRoute(theFloorInfo->GetEntrancePt(1000), entrancePt, inScore)) + checkRoute |= kTransportLobbyLeft | kTransportLobbyRight; + + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + T2Tenant *theTenant = theDB->FindEmptyParking(); + if (theTenant) { + if (theNavigator->CheckRoute(theTenant->GetExitPt(), entrancePt, inScore)) + checkRoute |= kTransportParking; + } + + T2TowerEvent *towerEvent = inDoc->towerDoc_vf170()->GetTowerEvent(); + T2DateTime *theDateTime = inDoc->towerDoc_vf120(); + theTenant = theDB->GetFirstTenant(kTenantRegistID8); + if (theTenant && theTenant->IsOpen()) { + if (theNavigator->CheckRoute(theTenant->GetExitPt(), entrancePt, inScore)) + checkRoute |= kTransportSubway; + } + + T2Transport *theTransport; + if (checkRoute & kTransportSubway) { + theTransport = towerEvent->GetMetroRailway(); + if (theTransport && !theTransport->GetAvailable(theDateTime) != NULL) + checkRoute &= ~kTransportSubway; + } -unsigned int T2Tenant::CheckRouteFromPool(T2TowerDoc*, unsigned int) const { + theTenant = theDB->GetFirstTenant(kTenantRegistID9); + if (theTenant && theTenant->IsOpen()) { + if (theNavigator->CheckRoute(theTenant->GetExitPt(), entrancePt, inScore)) + checkRoute |= kTransportShip; + } + + if (checkRoute & kTransportShip) { + theTransport = towerEvent->GetCruise(); + if (theTransport && !theTransport->GetAvailable(theDateTime) != NULL) + checkRoute &= ~kTransportShip; + } + + return checkRoute; } -T2TenantMemberTableDef* T2Tenant::GetCustomerTableDef(int) const { +T2TenantMemberTableDef* T2Tenant::GetCustomerTableDef(BOOL inFlag) const { + T2TenantMemberTableDef *result = NULL; + + if (GetEquipDef()) { + T2SubPlugin *subPlugin = (T2SubPlugin *) GetSubPlugin(); + if (subPlugin && inFlag) + ((T2TenantDef *) GetEquipDef())->SetCustomerTable(subPlugin); + result = ((T2TenantDef *) GetEquipDef())->GetCustomerTableDef(); + } + + return result; } -int T2Tenant::UpdateResidencialEstimate(T2TowerDoc*) { +BOOL T2Tenant::UpdateResidencialEstimate(T2TowerDoc* inDoc) { + int oldCol = CalcEstimateColor(); + + if (GetMark()) { + if (mBelongList) { + unsigned int totalEstimate = 0; + unsigned int numResidents = 0; + + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + totalEstimate += people->CalcCurrEstimate(); + numResidents++; + } + } + + if (numResidents > 0) + mPeopleEstimate = totalEstimate / numResidents; + } + + mEstimate = mPeopleEstimate; + + int senseOfNoise = ((T2TenantDef *) GetEquipDef())->GetSenseOfNoise(); + if (senseOfNoise != 0) { + T2TrafficInfo *theTrafficInfo = inDoc->towerDoc_vf150(); + if (theTrafficInfo) + mEstimate -= senseOfNoise * theTrafficInfo->GetRange(GetEntrancePt()); + } + + if (GetPriceIndex() != 0) + mEstimate += (GetPriceIndex() - 3) * -30; + + mEstimate += inDoc->towerDoc_vf120()->CalcLapseYears(mBuildDay) * -1; + } else { + mEstimate = 1; + } + + if (mEstimate < 1) + mEstimate = 1; + else if (mEstimate > 300) + mEstimate = 300; + + return CalcEstimateColor() != oldCol; } -void T2Tenant::BreakoutEmergency(T2TowerDoc*) { +void T2Tenant::BreakoutEmergency(T2TowerDoc* inDoc) { + if (GetRegistID() != kTenantRegistID5) { + int result = GetEquipDef()->EmergencyProc(inDoc, this); + if (result) { + SetDrawMode(result); + inDoc->GetTowerMainView()->tmv_vf128(mArea); + } + } } -void T2Tenant::BurntDown(T2TowerDoc*) { +void T2Tenant::BurntDown(T2TowerDoc* inDoc) { + if (mStatus != kTenantStatus10000) { + RemoveBelongPeople(inDoc); + mStatus = kTenantStatus10000; + +#line 2243 + _ASSERT(GetEquipDef() != NULL); + + GetEquipDef()->BurntDownProc(inDoc, this); + mDrawMode = DrawMode1; + inDoc->GetTowerMainView()->tmv_vf128(mArea); + } } -void T2Tenant::RecoverRelatedTenantList(T2RegistedTenantDB*) { +void T2Tenant::RecoverRelatedTenantList(T2RegistedTenantDB* inDB) { + if (mRelatedTenantList) + mRelatedTenantList = inDB->GetList((unsigned int) mRelatedTenantList); } int T2Tenant::GetTotalBelong() const { -} + int result = 0; -int T2Tenant::CanReplaceWorker() const { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) + result++; + } + } + + return result; } -int T2Tenant::ReplaceWorker(T2TowerDoc*, T2People*) { +BOOL T2Tenant::CanReplaceWorker() const { + BOOL result = false; + + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (!result && iterator.Next(&people)) { + if (people && people->GetHomeTenant() == 1) + result = true; + } + } + + return result; } -void T2Tenant::CallEmployee(unsigned int) { +BOOL T2Tenant::ReplaceWorker(T2TowerDoc* inDoc, T2People* inPeople) { + BOOL result = false; + + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (!result && iterator.Next(&people)) { + if (people && people->GetHomeTenant() == 1) { + mBelongList->AssignItemsAt(1, iterator.GetCurrentIndex(), &inPeople); + inPeople->SetWorkTenant(mEquipID); + people->Remove(inDoc, mEquipID); + result = true; + } + } + } + + return result; } -int T2Tenant::DecideResidencialEstimation(T2TowerDoc*) { +void T2Tenant::CallEmployee(unsigned int inTime) { + if (mBelongList) { + LArrayIterator iterator(*mBelongList); + T2People *people; + + while (iterator.Next(&people)) { + if (people) { + if (!people->IsSetSpecialFlag(kSpecialFlag4) || people->GetHomeTenant() < 1000) { + unsigned int time = inTime + UT2Utils::Randomize(6) * 10; + people->SetDestination(mEquipID, time); + } + } + } + } } -int T2Tenant::UpdateCommercialEstimate() { +BOOL T2Tenant::DecideResidencialEstimation(T2TowerDoc* inDoc) { + BOOL result = false; + + if (mEstimate < 70) { + RemovePeople(inDoc); + result = true; + } else if (mEstimate > 200) { + DuplicateBelongPeople(inDoc); + } else { + static int counter; + counter++; + if (counter >= 5) { + DuplicateBelongPeople(inDoc); + counter = 0; + } + } + + return result; } -int T2Tenant::CalcProfitEstimate() const { +BOOL T2Tenant::UpdateCommercialEstimate() { + int oldCol = CalcEstimateColor(); + mEstimate = CalcProfitEstimate(); + return CalcEstimateColor() != oldCol; } -void T2Tenant::GetMerchandise(int&, int*&) { +int T2Tenant::CalcProfitEstimate() const { + int theInMoney = CalcInMoney(); + int theOutMoney = GetOutMoney(); + int val = (theInMoney + theOutMoney) * 70; + + if (val <= 0) + val = 1; + + int theEstimate; + if (theOutMoney != 0) + theEstimate = val / theOutMoney; + else + theEstimate = val; + + if (theEstimate < 1) + theEstimate = 1; + if (theEstimate > 300) + theEstimate = 300; + + return theEstimate; +} + +void T2Tenant::GetMerchandise(int& outCount, int*& outArray) { + if (mMerchandiseCount > 0) { + outCount = mMerchandiseCount; + for (int i = 0; i < outCount; i++) + outArray[i] = mMerchandise[i]; + + } else { + outCount = 0; + if (GetEquipDef()) { + T2TenantMemberTableDef *theTable = ((T2TenantDef *) GetEquipDef())->GetCustomerTableDef(); + + if (theTable) { + outCount = theTable->GetNumOfElem(); + for (int i = 0; i < outCount; i++) { + T2TenantMemberDef *memberDef = theTable->GetElem(i); + if (memberDef) + outArray[i] = memberDef->GetPercent(); + } + } + } + } } T2TenantMemberTableDef* T2Tenant::GetMerchandiseTMT() { + T2TenantMemberTableDef *result = NULL; + + if (GetEquipDef()) { + result = ((T2TenantDef *) GetEquipDef())->GetCustomerTableDef(); + if (result && mMerchandiseCount > 0) { + for (int i = 0; i < mMerchandiseCount; i++) { + T2TenantMemberDef *memberDef = result->GetElem(i); + if (memberDef) + memberDef->SetPercent(mMerchandise[i]); + } + } + } + + return result; } -void T2Tenant::SetMerchandise(int, int*) { +void T2Tenant::SetMerchandise(int inCount, int* inArray) { + if (inCount > 0 && inCount <= 4) { + mMerchandiseCount = inCount; + for (int i = 0; i < mMerchandiseCount; i++) + mMerchandise[i] = inArray[i]; + } } -void T2Tenant::SetRelatedTenant(T2TowerDoc*, unsigned int) { +void T2Tenant::SetRelatedTenant(T2TowerDoc* inDoc, unsigned int inRegistID) { + if (!mRelatedTenantList) { + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + mRelatedTenantList = theDB->GetList(inRegistID); + } + + if (mRelatedTenantList) + mRelatedTenantList->SetRelatedTenantID(mEquipID); } -/*virtual*/ void T2Tenant::BuildStart(T2TowerDoc*) { +/*virtual*/ void T2Tenant::BuildStart(T2TowerDoc* inDoc) { + SetStatus(kTenantStatus1); + ((T2TenantDef *) GetEquipDef())->BuildStartProc(inDoc, this); } diff --git a/src/T2DLL/T2Tenant.h b/src/T2DLL/T2Tenant.h index fd2a6fa..73dd7f5 100644 --- a/src/T2DLL/T2Tenant.h +++ b/src/T2DLL/T2Tenant.h @@ -1,188 +1,258 @@ #pragma once #include "common.h" +#include "T2Equip.h" +#include "T2TenantDef.h" -class T2Tenant { +// is this specific to T2Equip maybe? +enum { + kTenantStatus0 = 0, + kTenantStatus1 = 1, + kTenantStatus2 = 2, + kTenantStatus9 = 9, + kTenantStatus10 = 10, + kTenantStatus30 = 30, + kTenantStatus9999 = 9999, + kTenantStatus10000 = 10000, + // these are used by T2GuestroomTable + kTenantStatus31 = 31, + kTenantStatus32 = 32, + kTenantStatus33 = 33, + kTenantStatus34 = 34, + kTenantStatus35 = 35, + kTenantStatus36 = 36, + kTenantStatus37 = 37, + kTenantStatus38 = 38, +}; + +enum { + kTenantRegistID1 = 1, // hotel rooms + kTenantRegistID2 = 2, // trash facilities + kTenantRegistID3 = 3, // parking + kTenantRegistID4 = 4, // hospital + kTenantRegistID5 = 5, // security + kTenantRegistID6 = 6, // school + kTenantRegistID7 = 7, // toilets + kTenantRegistID8 = 8, // metro railway + kTenantRegistID9 = 9, // boat deck + kTenantRegistID10 = 10, // ticket booth +}; + +class T2Tenant : public T2Equip { public: T2Tenant(); virtual ~T2Tenant(); - unsigned int GetFloorID(int); - void SetFloorID(T2FloorInfo*); - virtual PROCCODE DoDestruct(T2TowerDoc*, POINT, RECT&); -protected: - void AddPopulation(T2People*); - void SubPopulation(T2People*); -public: - virtual int Enter(CLink*); - virtual int Leave(CLink*); - void EnterTenant(T2TowerDoc*, T2People*); - void LeaveTenant(T2TowerDoc*, T2People*); - virtual void Draw(T2TowerDoc*, const RECT&); -protected: - virtual void DrawSelf(T2TowerDoc*, const RECT&); -public: - virtual unsigned int Idle(T2TowerDoc*); - virtual void AddCEMoverID(const T2FloorInfo*, POINT, unsigned int); - int InitTenant(T2TenantDef*, const RECT&, unsigned int); -protected: - virtual void LoadSelf(T2Archive&, T2TowerDoc*); - virtual void SaveSelf(T2Archive&); -public: + virtual void SetUsed(BOOL inUsed); + virtual BOOL Enter(CLink* inLink); + virtual BOOL Leave(CLink* inLink); + virtual unsigned int Idle(T2TowerDoc* inDoc); + virtual void Draw(T2TowerDoc* inDoc, const RECT&); + virtual void BuildStart(T2TowerDoc* inDoc); + virtual BOOL IsBuildFinish() { return mStatus > kTenantStatus9; } + virtual PROCCODE DoDestruct(T2TowerDoc* inDoc, POINT inPt, RECT& outRect); + virtual void ClearDrawMode() { mDrawMode = DrawMode0; } + virtual void PlaySound(T2TowerDoc* inDoc, int inID, unsigned int inMask, unsigned int inFlags) const; + virtual void AddCEMoverID(const T2FloorInfo* inFloorInfo, POINT inPt, unsigned int inID); virtual unsigned int GetEntranceFloorID(); - POINT GetEntrancePt() const; virtual unsigned int GetExitFloorID(); + + unsigned int GetFloorID(int inV); + void SetFloorID(T2FloorInfo* inFloorInfo); + void EnterTenant(T2TowerDoc* inDoc, T2People* inPeople); + void LeaveTenant(T2TowerDoc* inDoc, T2People* inPeople); + BOOL InitTenant(T2TenantDef* inDef, const RECT& inRect, unsigned int inValiation); + POINT GetEntrancePt() const; POINT GetExitPt(); T2People* GetFirstCustomer() const; int GetBelongCapacity(); - int IsTherePeople(T2People*); + BOOL IsTherePeople(T2People* inPeople); void StartBuild(); void UpdatePatternIndex(); - void UpdatePatternIndex(int); + void UpdatePatternIndex(int inIndex); int GetNumOfPattern() const; -protected: - int CollectCustomerFromPool(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int, T2Tenant*); - int CollectCustomerFromTenant(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int); - int CollectCustomerFromFloor(T2TowerDoc*, T2TenantMemberTableDef*, unsigned int); -public: - void CollectCustomer(T2TowerDoc*, T2Tenant*); - void CollectCustomer(T2TowerDoc*, int); - int CollectEmployee(T2TowerDoc*); - void RegistBelongPeople(T2People*); + void CollectCustomer(T2TowerDoc* inDoc, T2Tenant* inTenant); + void CollectCustomer(T2TowerDoc* inDoc, int inNum); + int CollectEmployee(T2TowerDoc* inDoc); + void RegistBelongPeople(T2People* inPeople); int CalcInMoney() const; - void EnterCustomer(T2People*, int); - int IsBelongPeople(T2People*) const; - void PushOutPeople(T2TowerDoc*, T2People*); - void PushOutAll(T2TowerDoc*); - void PushOutAllCustomer(T2TowerDoc*); + void EnterCustomer(T2People* inPeople, int inBindTime); + BOOL IsBelongPeople(T2People* inPeople) const; + void PushOutPeople(T2TowerDoc* inDoc, T2People* inPeople = NULL); + void PushOutAll(T2TowerDoc* inDoc); + void PushOutAllCustomer(T2TowerDoc* inDoc); int GetPriceIndex() const; -protected: - void DuplicateBelongPeople(T2TowerDoc*); - void RemoveBelongPeople(T2TowerDoc*); -public: - void RemovePeople(T2TowerDoc*); + void RemovePeople(T2TowerDoc* inDoc); void ClearBelongPeople(); - void ClearBelongPeople(T2People*); - void CallBelongPeople(unsigned int); - T2People* GetBelongPeople(int); - T2People* GetBelongPeopleIn(int); + void ClearBelongPeople(T2People* inPeople); + void CallBelongPeople(unsigned int inTime); + T2People* GetBelongPeople(int inIndex); + T2People* GetBelongPeopleIn(int inIndex); void SetKind(); -protected: - int GetNumOfKind() const; -public: - virtual void SetUsed(int); unsigned int GetRegistID() const; int GetEmployeeSearchScore() const; int GetCustomerSearchScore() const; - int IsMoverAvailable() const; + BOOL IsMoverAvailable() const; void RemoveBelongList(); - int GetQTMovieName(CString); - void Destruct(T2TowerDoc*, CRect&); - void SetBindTime(T2People*, unsigned int); - int SetEstimate(int); - int SetPeopleAnime(); - void SetPeopleAnime(T2People*, int); - void PushOutCustomer(T2TowerDoc*, int); - int GetBelongPeopleIndex(T2People*, int&) const; - int SetPeopleToSleep(); + BOOL GetQTMovieName(CString str); + void Destruct(T2TowerDoc* inDoc, CRect& outRect); + void SetBindTime(T2People* inPeople, unsigned int inTime); + BOOL SetEstimate(int inEstimate); + BOOL SetPeopleAnime(); + void SetPeopleAnime(T2People* inPeople, int inIndex); + void PushOutCustomer(T2TowerDoc* inDoc, int inCount); + BOOL GetBelongPeopleIndex(T2People* inPeople, int& outIndex) const; + BOOL SetPeopleToSleep(); void SetAllPeopleToSleep(); - void UnionFloorPeople(T2Tenant*); - int IsWithinSearchRange(T2TowerDoc*, T2Tenant*) const; - void SetMoviePlugin(T2SubPlugin*); - void SetHallEventPlugin(T2HallEventPlugin*); - int GetFloorNumber(T2FloorInfo*) const; - int GetRoomNumber(T2FloorInfo*) const; - void GetRoomName(T2TowerDoc*, CString&) const; - virtual void PlaySoundA(T2TowerDoc*, int, unsigned int, unsigned int) const; - int IsEmptyParking() const; - T2People* FindPeople(POINT) const; -protected: - int InitBelongList(); - void DrawViewModeColor(T2TowerDoc*) const; - void DrawTrafficColor(T2TowerDoc*, const CRect&) const; - static void DrawColorMesh(T2TowerDoc*, const CRect&, int); -public: - void IncPeopleEstimate(int); + void UnionFloorPeople(T2Tenant* inTenant); + BOOL IsWithinSearchRange(T2TowerDoc* inDoc, T2Tenant* inTenant) const; + void SetMoviePlugin(T2SubPlugin* inPlugin); + void SetHallEventPlugin(T2HallEventPlugin* inPlugin); + int GetFloorNumber(T2FloorInfo* inFloorInfo) const; + int GetRoomNumber(T2FloorInfo* inFloorInfo) const; + void GetRoomName(T2TowerDoc* inDoc, CString& outStr) const; + BOOL IsEmptyParking() const; + T2People* FindPeople(POINT inPt) const; + void IncPeopleEstimate(int inEstimate); int CalcEstimateColor() const; -protected: - int CollectEmployeeFromPool(T2TowerDoc*, T2TenantMemberTableDef*); -public: - int IsRegist() const; -protected: - unsigned int CheckRouteFromPool(T2TowerDoc*, unsigned int) const; -public: - T2TenantMemberTableDef* GetCustomerTableDef(int) const; - int UpdateResidencialEstimate(T2TowerDoc*); - void BreakoutEmergency(T2TowerDoc*); - void BurntDown(T2TowerDoc*); - void RecoverRelatedTenantList(T2RegistedTenantDB*); + BOOL IsRegist() const; + T2TenantMemberTableDef* GetCustomerTableDef(BOOL inFlag) const; + BOOL UpdateResidencialEstimate(T2TowerDoc* inDoc); + void BreakoutEmergency(T2TowerDoc* inDoc); + void BurntDown(T2TowerDoc* inDoc); + void RecoverRelatedTenantList(T2RegistedTenantDB* inDB); int GetTotalBelong() const; - int CanReplaceWorker() const; - int ReplaceWorker(T2TowerDoc*, T2People*); - void CallEmployee(unsigned int); - int DecideResidencialEstimation(T2TowerDoc*); - int UpdateCommercialEstimate(); + BOOL CanReplaceWorker() const; + BOOL ReplaceWorker(T2TowerDoc* inDoc, T2People* inPeople); + void CallEmployee(unsigned int inTime); + BOOL DecideResidencialEstimation(T2TowerDoc* inDoc); + BOOL UpdateCommercialEstimate(); int CalcProfitEstimate() const; - void GetMerchandise(int&, int*&); + void GetMerchandise(int& outCount, int*& outArray); T2TenantMemberTableDef* GetMerchandiseTMT(); - void SetMerchandise(int, int*); - void SetRelatedTenant(T2TowerDoc*, unsigned int); - virtual void BuildStart(T2TowerDoc*); + void SetMerchandise(int inCount, int* inArray); + void SetRelatedTenant(T2TowerDoc* inDoc, unsigned int inRegistID); + + unsigned int GetResideDay() const { return mResideDay; } + int GetEstimate() const { return mEstimate; } + void SetRelatedTenantID(unsigned int inID) { mRelatedTenantID = inID; } + unsigned int GetRelatedTenantID() const { return mRelatedTenantID; } + BOOL IsSetRelatedTenantID() const { return (mRelatedTenantID != 0); } + BOOL IsFloor() const { return IsSetAttribute(kTenantAttrIsFloor); } + BOOL IsPoolTenant() const { return (mEquipID == 1000); } + BOOL IsHome() const { return IsSetAttribute(kTenantAttrIsHome); } + BOOL IsConcat() const { return IsSetAttribute(kTenantAttrIsConcat); } + BOOL IsPeopleAnime() const { return IsSetAttribute(kTenantAttrIsPeopleAnime | kTenantAttrIsPeopleAnime2); } + BOOL IsNeedToilet() const { return IsSetAttribute(kTenantAttrIsNeedToilet); } + BOOL IsNeedDraw() { return mToolDef && mDrawMode; } + BOOL IsTherePeople() const { return mFirstPeople != NULL; } + BOOL IsThereCustomer() const { return mCustomerCount > 0; } + T2People* GetFirstPeople() const { return mFirstPeople; } + BOOL IsOpen() const { return mStatus >= kTenantStatus30 && mStatus <= kTenantStatus9999; } + BOOL WillBeFull() const { return (mCustomerCount + mReserveCount) >= GetCapacity(); } + int CalcRestCapacity() const { return GetCapacity() - (mCustomerCount + mReserveCount); } + void SetMark(int inMark) { mMark = inMark; } + int GetMark() const { return mMark; } + int GetBelongCount() const { return mBelongCount; } + void ClearWorkCount() { mWorkCount = 0; } + int GetTotalCustomer() const { return mTotalCustomer; } + void ClearTotalCustomer() { mTotalCustomer = 0; } + void IncTotalCustomer() { mTotalCustomer++; } + T2PeoplePtrList* GetBelongList() const { return mBelongList; } + void SetRelatedTenantList(T2EquipPtrList* inList) { mRelatedTenantList = inList; } + T2EquipPtrList* GetRelatedTenantList() const { return mRelatedTenantList; } + BOOL IsFire() { return mStatus >= kTenantStatus10000; } + BOOL IsFireproof() const { return IsSetAttribute(kTenantAttrIsFireproof); } + unsigned int GetTenantNumber() const { return mTenantNumber; } + void SetTenantNumber(unsigned int inNumber) { mTenantNumber = inNumber; } + BOOL IsBind() const { return mIsBind; } + void Bind() { mIsBind = true; } + void Unbind() { mIsBind = false; } + unsigned int GetOpenTime() const { + unsigned int time = 0; + T2TenantDef *def = (T2TenantDef *) mToolDef; + if (def) + time = def->mOpenTime; + return time; + } + unsigned int GetCloseTime() const { + unsigned int time = 0; + T2TenantDef *def = (T2TenantDef *) mToolDef; + if (def) + time = def->mCloseTime; + return time; + } + int GetBindTime() const { + int time = 0; + T2TenantDef *def = (T2TenantDef *) mToolDef; + if (def) + time = def->mBindTime; + return time; + } + T2TenantMemberTableDef* GetEmployeeTableDef() const { + T2TenantMemberTableDef *theDef = NULL; + if (mToolDef) + theDef = ((T2TenantDef *) mToolDef)->mEmployeeTableDef; + return theDef; + } + BOOL IsFull() const { return mCustomerCount > GetCapacity(); } + int GetCustomerCount() const { return mCustomerCount; } + int GetKindIndex() const { return mKindIndex; } + void SetKindIndex(int inIndex) { mKindIndex = inIndex; } + void IncWorkCount() { mWorkCount++; } + void DecWorkCount() { mWorkCount--; } + int GetWorkCount() const { return mWorkCount; } + void ClearReserveCount() { mReserveCount = 0; } + void IncReserveCount(unsigned int inAmount) { mReserveCount += inAmount; } + void DecReserveCount() { + if (mReserveCount > 0) + mReserveCount--; + } + int GetReserveCount() const { return mReserveCount; } + void CancelReserve() { + if (mReserveCount > 0) + mReserveCount--; + } - unsigned int GetResideDay() const {} - int GetEstimate() const {} - void SetRelatedTenantID(unsigned int) {} - unsigned int GetRelatedTenantID() const {} - int IsSetRelatedTenantID() const {} - int IsFloor() const {} - int IsPoolTenant() const {} - int IsHome() const {} - int IsConcat() const {} - int IsPeopleAnime() const {} - int IsNeedToilet() const {} - int IsNeedDraw() {} - int IsTherePeople() const {} - int IsThereCustomer() const {} - T2People* GetFirstPeople() const {} - int IsOpen() const {} - int WillBeFull() const {} - int CalcRestCapacity() const {} - void SetMark(int) {} - int GetMark() const {} - int GetBelongCount() const {} - void ClearWorkCount() {} - int GetTotalCustomer() const {} - void ClearTotalCustomer() {} - void IncTotalCustomer() {} - T2PeoplePtrList* GetBelongList() const {} - void SetRelatedTenantList(T2EquipPtrList*) {} - T2EquipPtrList* GetRelatedTenantList() const {} - virtual int IsBuildFinish() {} - int IsFire() {} - int IsFireproof() const {} - unsigned int GetTenantNumber() const {} - void SetTenantNumber(unsigned int) {} protected: - int GetConsumptionPower() const {} -public: - T2Tenant(const T2Tenant&) {} - T2Tenant& operator=(const T2Tenant&) {} - virtual void ClearDrawMode() {} - int IsBind() const {} - void Bind() {} - void Unbind() {} - unsigned int GetOpenTime() const {} - unsigned int GetCloseTime() const {} - int GetBindTime() const {} - T2TenantMemberTableDef* GetEmployeeTableDef() const {} - int IsFull() const {} - int GetCustomerCount() const {} - int GetKindIndex() const {} - void SetKindIndex(int) {} - void IncWorkCount() {} - void DecWorkCount() {} - int GetWorkCount() const {} - void ClearReserveCount() {} - void IncReserveCount(unsigned int) {} - void DecReserveCount() {} - int GetReserveCount() const {} - void CancelReserve() {} + virtual void LoadSelf(T2Archive& inArchive, T2TowerDoc* inDoc); + virtual void SaveSelf(T2Archive& inArchive); + virtual void DrawSelf(T2TowerDoc* inDoc, const RECT&); + + void AddPopulation(T2People* inPeople); + void SubPopulation(T2People* inPeople); + int CollectCustomerFromPool(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime, T2Tenant* inTenant); + int CollectCustomerFromTenant(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime); + int CollectCustomerFromFloor(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable, unsigned int inTime); + void DuplicateBelongPeople(T2TowerDoc* inDoc); + void RemoveBelongPeople(T2TowerDoc* inDoc); + int GetNumOfKind() const; + BOOL InitBelongList(); + void DrawViewModeColor(T2TowerDoc* inDoc) const; + void DrawTrafficColor(T2TowerDoc* inDoc, const CRect&) const; + static void DrawColorMesh(T2TowerDoc* inDoc, const CRect& inRect, int inClr); + BOOL CollectEmployeeFromPool(T2TowerDoc* inDoc, T2TenantMemberTableDef* inTable); + unsigned int CheckRouteFromPool(T2TowerDoc* inDoc, unsigned int inScore) const; + int GetConsumptionPower() const { return 0; } + + friend class T2EquipDef; + friend class T2TenantArray; + + T2People *mFirstPeople; + T2People *m64; + int mMerchandiseCount; + int mMerchandise[4]; + int mResideDay; + int mKindIndex; + int mMark; + BOOL mIsBind; + int mPeopleEstimate; + int mEstimate; + unsigned int mRelatedTenantID; + int mReserveCount; + int mBelongCount; + int mCustomerCount; + int mWorkCount; + int mTotalCustomer; + T2PeoplePtrList *mBelongList; + T2EquipPtrList *mRelatedTenantList; + unsigned int mTenantNumber; }; diff --git a/src/T2DLL/T2TenantArray.cpp b/src/T2DLL/T2TenantArray.cpp index e7dfb45..4c536e8 100644 --- a/src/T2DLL/T2TenantArray.cpp +++ b/src/T2DLL/T2TenantArray.cpp @@ -1,34 +1,101 @@ +#include "CProgramPlugin.h" +#include "T2Tenant.h" #include "T2TenantArray.h" +#include "T2TenantDef.h" +#include "T2TowerDoc.h" -T2TenantArray::T2TenantArray(unsigned int) { +T2TenantArray::T2TenantArray(unsigned int startID) + : T2ObjectArray(startID) +{ + mTenants = new T2Tenant[kGroupSize]; + + for (unsigned int i = 0; i < kGroupSize; i++) + mTenants[i].mEquipID = mStartID + i; } /*virtual*/ T2TenantArray::~T2TenantArray() { + if (mTenants) + delete[] mTenants; } T2Tenant* T2TenantArray::FindUnusedTenant() { + for (int i = 0; i < kGroupSize; i++) { + if (!mTenants[i].IsUsed()) + return &mTenants[i]; + } + + return NULL; } -/*virtual*/ void T2TenantArray::DispatchIdle(T2TowerDoc*, int) { +/*virtual*/ void T2TenantArray::DispatchIdle(T2TowerDoc* towerDoc, int startIndex) { + int counter = 0; + T2Tenant *tenant = mTenants; + + for (int i = 0; i < kGroupSize; i++) { + if (tenant->mUsed) { + if ((counter % 32) == startIndex || towerDoc->m180) + tenant->Idle(towerDoc); + counter++; + } + tenant++; + } } -int T2TenantArray::CalcMentenanceCost(T2TowerDoc*) const { +int T2TenantArray::CalcMentenanceCost(T2TowerDoc* towerDoc) const { + int cost = 0; + + for (int i = 0; i < kGroupSize; i++) { + if (mTenants[i].IsUsed()) + cost += mTenants[i].CalcMentenanceCost(towerDoc); + } + + return cost; } -void T2TenantArray::TenantRemoved(unsigned int) { +void T2TenantArray::TenantRemoved(unsigned int id) { + for (int i = 0; i < kGroupSize; i++) { + T2Tenant *tenant = &mTenants[i]; + if (tenant->IsUsed() && !tenant->IsFloor() && tenant->GetRelatedTenantID() == id) + tenant->SetRelatedTenantID(0); + } } -T2Tenant* T2TenantArray::GetTenantByPID(unsigned long) { +T2Tenant* T2TenantArray::GetTenantByPID(DWORD pluginID) { + for (int i = 0; i < kGroupSize; i++) { + if (mTenants[i].IsUsed()) { + T2EquipDef *equipDef = mTenants[i].GetEquipDef(); + CProgramPlugin *plugin = equipDef ? equipDef->GetPlugin() : NULL; + + if (plugin && plugin->GetID() == pluginID) + return &mTenants[i]; + } + } + + return NULL; } -void T2TenantArray::BreakoutEmergency(T2TowerDoc*) { +void T2TenantArray::BreakoutEmergency(T2TowerDoc* towerDoc) { + for (int i = 0; i < kGroupSize; i++) { + T2Tenant *tenant = &mTenants[i]; + if (tenant->IsUsed() && !tenant->IsFloor()) + tenant->BreakoutEmergency(towerDoc); + } } -void T2TenantArray::RecoverRelatedTenantList(T2RegistedTenantDB*) { +void T2TenantArray::RecoverRelatedTenantList(T2RegistedTenantDB* db) { + T2Tenant *tenant = mTenants; + for (unsigned int i = 0; i < kGroupSize; i++, tenant++) { + if (tenant->IsUsed()) + tenant->RecoverRelatedTenantList(db); + } } -void T2TenantArray::Read(T2Archive&, T2TowerDoc*) { +void T2TenantArray::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + for (int i = 0; i < kGroupSize; i++) + mTenants[i].Load(archive, towerDoc); } -void T2TenantArray::Write(T2Archive&) { +void T2TenantArray::Write(T2Archive& archive) { + for (int i = 0; i < kGroupSize; i++) + mTenants[i].Save(archive); } diff --git a/src/T2DLL/T2TenantArray.h b/src/T2DLL/T2TenantArray.h index a443c9f..6a2146b 100644 --- a/src/T2DLL/T2TenantArray.h +++ b/src/T2DLL/T2TenantArray.h @@ -1,22 +1,27 @@ #pragma once #include "common.h" +#include "T2ObjectArray.h" -class T2TenantArray { +class AFX_EXT_CLASS T2TenantArray : public T2ObjectArray { public: - T2TenantArray(unsigned int); + enum { kGroupSize = 128 }; + + T2TenantArray(unsigned int startID = 1000); virtual ~T2TenantArray(); + virtual void DispatchIdle(T2TowerDoc*, int); T2Tenant* FindUnusedTenant(); - virtual void DispatchIdle(T2TowerDoc*, int); int CalcMentenanceCost(T2TowerDoc*) const; void TenantRemoved(unsigned int); - T2Tenant* GetTenantByPID(unsigned long); + T2Tenant* GetTenantByPID(DWORD); void BreakoutEmergency(T2TowerDoc*); void RecoverRelatedTenantList(T2RegistedTenantDB*); void Read(T2Archive&, T2TowerDoc*); void Write(T2Archive&); - T2Tenant* GetIndexTenant(int) {} - T2TenantArray(const T2TenantArray&) {} - T2TenantArray& operator=(const T2TenantArray&) {} - void `default constructor closure'() {} + T2Tenant* GetIndexTenant(int i) { return &mTenants[i]; } + +protected: + friend class T2TenantArrayList; + + T2Tenant *mTenants; }; diff --git a/src/T2DLL/T2TenantArrayList.cpp b/src/T2DLL/T2TenantArrayList.cpp index 6383c6d..be01aeb 100644 --- a/src/T2DLL/T2TenantArrayList.cpp +++ b/src/T2DLL/T2TenantArrayList.cpp @@ -1,52 +1,206 @@ +#include "T2Archive.h" +#include "T2Tenant.h" +#include "T2TenantArray.h" #include "T2TenantArrayList.h" T2TenantArrayList::T2TenantArrayList() { + mCounter = 0; + T2TenantArray *tenantArray = new T2TenantArray; + Add(tenantArray); } /*virtual*/ T2TenantArrayList::~T2TenantArrayList() { + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + delete tenantArray; } -void T2TenantArrayList::Add(T2TenantArray*) { +void T2TenantArrayList::Add(T2TenantArray* tenantArray) { + InsertItemsAt(1, mItemCount + 1, &tenantArray); } unsigned int T2TenantArrayList::GetItemCount() { + return GetCount(); } -T2TenantArray* T2TenantArrayList::GetItemAt(int) { +T2TenantArray* T2TenantArrayList::GetItemAt(int index) { + T2TenantArray *tenantArray = NULL; + FetchItemAt(index, &tenantArray); + return tenantArray; } -T2Tenant* T2TenantArrayList::GetTenantByID(unsigned int) { +T2Tenant* T2TenantArrayList::GetTenantByID(unsigned int tenantID) { + if (tenantID == 0) + return NULL; + + int group = (tenantID - 1000) / T2TenantArray::kGroupSize; + int indexInGroup = (tenantID - 1000) % T2TenantArray::kGroupSize; + T2TenantArray *tenantArray = GetItemAt(group + 1); + if (tenantArray) + return tenantArray->GetIndexTenant(indexInGroup); + else + return NULL; } -T2Tenant* T2TenantArrayList::GetTenantByPID(unsigned long) { +T2Tenant* T2TenantArrayList::GetTenantByPID(DWORD pluginID) { + T2Tenant *tenant = NULL; + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (!tenant && iterator.Next(&tenantArray)) { + tenant = tenantArray->GetTenantByPID(pluginID); + } + + return tenant; } T2Tenant* T2TenantArrayList::FindUnusedTenant() { + T2Tenant *result = NULL; + LArrayIterator iterator(*this); + T2TenantArray *tenantArray = NULL; + + while (!result && iterator.Next(&tenantArray)) { + result = tenantArray->FindUnusedTenant(); + } + + if (!result) { + unsigned int newStartID = 1000; + if (tenantArray) + newStartID = tenantArray->GetStartID() + T2TenantArray::kGroupSize; + + tenantArray = new T2TenantArray(newStartID); + if (tenantArray) { + Add(tenantArray); + result = tenantArray->FindUnusedTenant(); + } + } + + return result; } -void T2TenantArrayList::DispatchIdle(T2TowerDoc*) { +void T2TenantArrayList::DispatchIdle(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + tenantArray->DispatchIdle(towerDoc, mCounter); + + mCounter++; + if (mCounter >= 32) + mCounter = 0; } -void T2TenantArrayList::TenantRemoved(unsigned int) { +void T2TenantArrayList::TenantRemoved(unsigned int v) { + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + tenantArray->TenantRemoved(v); } -void T2TenantArrayList::BreakoutEmergency(T2TowerDoc*) { +void T2TenantArrayList::BreakoutEmergency(T2TowerDoc* towerDoc) { + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + tenantArray->BreakoutEmergency(towerDoc); } -int T2TenantArrayList::CalcMentenanceCost(T2TowerDoc*) const { +int T2TenantArrayList::CalcMentenanceCost(T2TowerDoc* towerDoc) const { + int cost = 0; + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + cost += tenantArray->CalcMentenanceCost(towerDoc); + + return cost; } -LArray* T2TenantArrayList::MakeTenantList(int) { +LArray* T2TenantArrayList::MakeTenantList(int type) { + LArray *result = new LArray(sizeof(T2Tenant *)); + + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) { + for (int i = 0; i < T2TenantArray::kGroupSize; i++) { + T2Tenant *tenant = &tenantArray->mTenants[i]; + if (tenant->IsUsed() && tenant->GetEquipType() == type) + result->Add(&tenant); + } + } + + if (result->GetCount() > 0) { + return result; + } else { + delete result; + return NULL; + } } -LArray* T2TenantArrayList::MakeTenantList(int, (__cdecl*)(class, const T2Tenant*, )) { +LArray* T2TenantArrayList::MakeTenantList(BOOL(*func) (const T2Tenant*)) { + LArray *result = new LArray(sizeof(T2Tenant *)); + + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) { + for (int i = 0; i < T2TenantArray::kGroupSize; i++) { + T2Tenant *tenant = &tenantArray->mTenants[i]; + if (tenant->IsUsed() && func(tenant)) + result->Add(&tenant); + } + } + + if (result->GetCount() > 0) { + return result; + } else { + delete result; + return NULL; + } } -void T2TenantArrayList::Read(T2Archive&, T2TowerDoc*) { +void T2TenantArrayList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { + archive >> mCounter; + + int count; + archive >> count; + + RemoveItemsAt(GetCount(), 1); + unsigned int startID = 1000; + + for (int i = 0; i < count; i++) { + Add(new T2TenantArray(startID)); + startID += T2TenantArray::kGroupSize; + } + + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + tenantArray->Read(archive, towerDoc); } -void T2TenantArrayList::Write(T2Archive&) { +void T2TenantArrayList::Write(T2Archive& archive) { + archive << mCounter; + + int count = GetItemCount(); + archive << count; + + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + tenantArray->Write(archive); } -void T2TenantArrayList::RecoverRelatedTenantList(T2RegistedTenantDB*) { +void T2TenantArrayList::RecoverRelatedTenantList(T2RegistedTenantDB* db) { + LArrayIterator iterator(*this); + T2TenantArray *tenantArray; + + while (iterator.Next(&tenantArray)) + tenantArray->RecoverRelatedTenantList(db); } diff --git a/src/T2DLL/T2TenantArrayList.h b/src/T2DLL/T2TenantArrayList.h index 5405649..1192bc7 100644 --- a/src/T2DLL/T2TenantArrayList.h +++ b/src/T2DLL/T2TenantArrayList.h @@ -1,7 +1,8 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2TenantArrayList { +class AFX_EXT_CLASS T2TenantArrayList : public LArray { public: T2TenantArrayList(); virtual ~T2TenantArrayList(); @@ -15,12 +16,12 @@ public: void TenantRemoved(unsigned int); void BreakoutEmergency(T2TowerDoc*); int CalcMentenanceCost(T2TowerDoc*) const; - LArray* MakeTenantList(int); - LArray* MakeTenantList(int, (__cdecl*)(class, const T2Tenant*, )); + LArray* MakeTenantList(int type); + LArray* MakeTenantList(BOOL (*func) (const T2Tenant*)); void Read(T2Archive&, T2TowerDoc*); void Write(T2Archive&); void RecoverRelatedTenantList(T2RegistedTenantDB*); - T2TenantArrayList(const T2TenantArrayList&) {} - T2TenantArrayList& operator=(const T2TenantArrayList&) {} +protected: + int mCounter; }; diff --git a/src/T2DLL/T2TenantCEArray.h b/src/T2DLL/T2TenantCEArray.h index 71a00a7..addee65 100644 --- a/src/T2DLL/T2TenantCEArray.h +++ b/src/T2DLL/T2TenantCEArray.h @@ -2,7 +2,7 @@ #include "common.h" #include "T2CrossEquipArray.h" -class T2TenantCEArray : public T2CrossEquipArray { +class AFX_EXT_CLASS T2TenantCEArray : public T2CrossEquipArray { public: T2TenantCEArray(); virtual ~T2TenantCEArray(); diff --git a/src/T2DLL/T2TenantDef.cpp b/src/T2DLL/T2TenantDef.cpp index 1f3514e..6b5f40a 100644 --- a/src/T2DLL/T2TenantDef.cpp +++ b/src/T2DLL/T2TenantDef.cpp @@ -1,39 +1,213 @@ +#include "CResFile.h" +#include "T2BitImage.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2PaletteAnime.h" +#include "T2PeopleAnimeDef.h" +#include "T2SubPlugin.h" +#include "T2Tenant.h" #include "T2TenantDef.h" +#include "T2TenantMemberTableDef.h" +#include "T2TenantPlugin.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2TowerMessage.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" -T2TenantDef::T2TenantDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2TenantPlugin*) { +T2TenantDef::T2TenantDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2TenantPlugin* plugin) + : T2EquipDef(type, specifier, resFile, worldDef, plugin) +{ + DWORD tmp; + + *resFile >> mRegistID; + *resFile >> mDownFlag; + *resFile >> mNumOfKind; + *resFile >> mNumOfPattern; + *resFile >> mBelongCapacity; + *resFile >> mSenseOfNoise; + *resFile >> mEntranceV; + *resFile >> mEntranceH; + *resFile >> mExitV; + *resFile >> mExitH; + *resFile >> mOpenTime; + *resFile >> mCloseTime; + *resFile >> mBindTime; + *resFile >> mMaxBuildCount; + *resFile >> tmp; + *resFile >> tmp; + *resFile >> tmp; + *resFile >> m184; + + mEmployeeTableDef = NULL; + mCustomerTableDef = NULL; + mPeopleAnimeDef = NULL; + + CResFile subResFile; + if (subResFile.OpenResource(mModuleHandle, 1, 'TmDf')) { + mEmployeeTableDef = new T2TenantMemberTableDef(mModuleHandle, &subResFile, 0.0f); + subResFile.End(); + } + + MakeCustomerTableDef(2, NULL); + + if (subResFile.OpenResource(mModuleHandle, 1, 'PaDf')) { + mPeopleAnimeDef = new T2PeopleAnimeDef(subResFile); + subResFile.End(); + } + + m180 = 0; + m194 = (m154 == 0); + m198 = 1; + mIsLoaded = true; } /*virtual*/ T2TenantDef::~T2TenantDef() { + if (mEmployeeTableDef) + delete mEmployeeTableDef; + if (mCustomerTableDef) + delete mCustomerTableDef; + if (mPeopleAnimeDef) + delete mPeopleAnimeDef; } -/*virtual*/ void T2TenantDef::GetName(CString&) { +/*virtual*/ void T2TenantDef::GetName(CString& outStr) { + outStr = "TENANT"; } -/*virtual*/ int T2TenantDef::InitObject(T2Object*) { +/*virtual*/ BOOL T2TenantDef::InitObject(T2Object* obj) { + T2EquipDef::InitObject(obj); + ((T2Equip *) obj)->mDrawMode = DrawMode2; + return true; } -/*virtual*/ void T2TenantDef::DrawProc(T2HaveOutViewObject*, const RECT&, T2TowerDoc*) const { +/*virtual*/ void T2TenantDef::DrawProc(T2HaveOutViewObject* obj, const RECT& inRect, T2TowerDoc* towerDoc) const { + T2Tenant *tenant = (T2Tenant *) obj; + RECT rect = inRect; + + int id; + int pattern; + BOOL someFlag; + + if (towerDoc->mViewMode != 1) { + id = 100; + someFlag = true; + pattern = 0; + pattern += tenant->mValiation * 1000; + pattern += mHeight * 100; + pattern += tenant->GetPatIndex(); + } else { + id = 101; + someFlag = false; + pattern = (towerDoc->mWorldDef->GetOutViewKind() + 1) * 10000; + pattern += tenant->mValiation * 1000; + pattern += mHeight * 100; + if (tenant->IsFire()) + pattern += 2; + else if (towerDoc->towerDoc_vf160()->IsSnow()) + pattern += 1; + } + + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108(), !someFlag); + + int objIndex = mImageObj->FindObject(id, pattern); + if (objIndex >= 0) { + mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objIndex, rect, towerDoc->towerDoc_vf108()); + } else if (tenant->m58) { + towerDoc->towerDoc_vf10C()->FillRect(rect, 1); + } else { + CString err; +#ifdef _MSC_VER + err.Format("Undefined Image %d %s", pattern, mStr48); +#else + err.Format("Undefined Image %d %s", pattern, &mStr48); +#endif + MessageBox(NULL, mStr48, err, MB_OK); + } } -/*virtual*/ int T2TenantDef::DrawData(int) { +/*virtual*/ int T2TenantDef::DrawData(int y) { + return y; } -/*virtual*/ void T2TenantDef::DrawPeople(T2TowerDoc*, T2Equip*) { +/*virtual*/ void T2TenantDef::DrawPeople(T2TowerDoc* towerDoc, T2Equip* equip) { + if (towerDoc->mViewMode != 1) + T2EquipDef::DrawPeople(towerDoc, equip); } -/*virtual*/ int T2TenantDef::DrawAttribute(int) { +/*virtual*/ int T2TenantDef::DrawAttribute(int y) { + return y; } -/*virtual*/ unsigned int T2TenantDef::IdleProc(T2HaveOutViewObject*, T2TowerDoc*) { +/*virtual*/ unsigned int T2TenantDef::IdleProc(T2HaveOutViewObject* obj, T2TowerDoc* towerDoc) { + T2Equip *equip = (T2Equip *) obj; + int status = equip->GetStatus(); + unsigned int result = 0; + + if (status < kStatus10) { + if (status <= kStatus2 || status == kStatus9) + result = 1; + + status++; + equip->SetStatus(status); + + if (status == kStatus10) { + BuildFinish(towerDoc, equip); + towerDoc->mTowerMainView->tmv_vf128(equip->mArea, true); + } + } + + T2Tenant *tenant = (T2Tenant *) equip; + status = tenant->GetStatus(); + + if (status >= kStatus9 && ChangeStatusOnIdle(towerDoc, tenant, status)) { + if (status == kStatus9) + tenant->SetDrawMode(DrawMode2); + else + tenant->SetDrawMode(DrawMode1); + } + + if (tenant->GetDrawMode() != DrawMode0) + towerDoc->mTowerMainView->tmv_vf128(tenant->mArea, false); + + return result; } -/*virtual*/ int T2TenantDef::ChangeStatusOnIdle(T2TowerDoc*, T2Tenant*, int) { +/*virtual*/ BOOL T2TenantDef::ChangeStatusOnIdle(T2TowerDoc*, T2Tenant*, int) { + return false; } -/*virtual*/ AREACHECKCODE T2TenantDef::AreaCheck(T2TowerDoc*, RECT&, unsigned int, int) { +/*virtual*/ AREACHECKCODE T2TenantDef::AreaCheck(T2TowerDoc* towerDoc, RECT& rect, unsigned int a, BOOL flag) { + if (GetCategory() != 100 && rect.top <= towerDoc->mWorldDef->mTopFloorLine) { + if (flag) + towerDoc->towerDoc_vf13C()->BuildErr(68, NULL); + return AreaCheckCode_0; + } + + if (rect.bottom > towerDoc->mWorldDef->mBottomFloorLine) { + if (flag) + towerDoc->towerDoc_vf13C()->BuildErr(2, NULL); + return AreaCheckCode_0; + } + + return AreaCheckCode_1; } -/*virtual*/ int T2TenantDef::CalcPayment(T2TowerDoc*, RECT&, unsigned int) { +/*virtual*/ int T2TenantDef::CalcPayment(T2TowerDoc* towerDoc, RECT& rect, unsigned int variation) { + int result = 0; + + if (IsFloor()) { + for (int y = rect.top; y < rect.bottom; y++) { + for (int x = rect.left; x < rect.right; x++) { + if (!towerDoc->mFloorInfo->GetTenant(y, x)) + result += mPrice[variation]; + } + } + } else { + result = mPrice[variation]; + } + + return result; } /*virtual*/ void T2TenantDef::EnterTenant(T2TowerDoc*, T2Tenant*, T2People*) { @@ -48,20 +222,80 @@ T2TenantDef::T2TenantDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDe /*virtual*/ void T2TenantDef::DoPeopleAnimation(T2TowerDoc*, T2Tenant*) { } -/*virtual*/ int T2TenantDef::GetQTMovieName(T2Tenant*, CString&) { +/*virtual*/ BOOL T2TenantDef::GetQTMovieName(T2Tenant*, CString& outStr) { + outStr = ""; + return outStr != NULL; } -void T2TenantDef::SetCustomerTable(T2SubPlugin*) { +void T2TenantDef::SetCustomerTable(T2SubPlugin* subPlugin) { + if (subPlugin) { + int prevBindTime = mBindTime; + mBindTime = 1; + + int resID = subPlugin->DupCustomerTableDefRes(); + MakeCustomerTableDef(resID, subPlugin->mSpecifier.mPath); + + mBindTime = prevBindTime; + } } -void T2TenantDef::MakeCustomerTableDef(int, const char*) { +void T2TenantDef::MakeCustomerTableDef(int resID, const char* path) { + if (mCustomerTableDef) + delete mCustomerTableDef; + + mCustomerTableDef = NULL; + + if (resID) { + CResFile resFile; + if (path) { + if (resFile.OpenResource(path, resID, 'TMDF')) { + mCustomerTableDef = new T2TenantMemberTableDef(path, &resFile, CalcNumOfCustomerUnit()); + resFile.End(); + } + } else { + if (resFile.OpenResource(mModuleHandle, resID, 'TmDf')) { + mCustomerTableDef = new T2TenantMemberTableDef(mModuleHandle, &resFile, CalcNumOfCustomerUnit()); + resFile.End(); + } + } + } } float T2TenantDef::CalcNumOfCustomerUnit() { + float result = 0.0f; + + if (mBindTime > 0 && mCapacity > 0) { + if (mBindTime > 8) + result = (mCapacity * 8.0f) / mBindTime; + else + result = mCapacity; + } + + return result; } -/*virtual*/ int T2TenantDef::EmergencyProc(T2TowerDoc*, T2Equip*) { +/*virtual*/ BOOL T2TenantDef::EmergencyProc(T2TowerDoc* towerDoc, T2Equip* equip) { + ((T2Tenant *) equip)->PushOutAll(towerDoc); + ((T2Tenant *) equip)->ClearReserveCount(); + ((T2Tenant *) equip)->Bind(); + return true; } -/*virtual*/ int T2TenantDef::CalcMentenanceCostProc(const T2HaveOutViewObject*) const { +/*virtual*/ int T2TenantDef::CalcMentenanceCostProc(const T2HaveOutViewObject* obj) const { + int cost = 0; + + T2ToolDef *def = obj->GetToolDef(); + if (def->IsSetAttribute(kToolAttrNormalMenteCost)) { + if (((T2TenantDef *) def)->IsValiableLength()) { + RECT rect; + ((T2Equip *) obj)->GetEquipArea(rect); + int width = rect.right - rect.left; + cost = obj->GetToolDef()->GetOutMoney(obj->GetValiation()); + cost *= width; + } else { + cost = T2ToolDef::CalcMentenanceCostProc(obj); + } + } + + return cost; } diff --git a/src/T2DLL/T2TenantDef.h b/src/T2DLL/T2TenantDef.h index 0657566..b0984f7 100644 --- a/src/T2DLL/T2TenantDef.h +++ b/src/T2DLL/T2TenantDef.h @@ -1,51 +1,77 @@ #pragma once #include "common.h" +#include "T2EquipDef.h" -class T2TenantDef { +class AFX_EXT_CLASS T2TenantDef : public T2EquipDef { public: - T2TenantDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2TenantPlugin*); + T2TenantDef(DWORD, T2PluginSpecifier&, CResFile*, T2WorldDef*, T2TenantPlugin*); virtual ~T2TenantDef(); virtual void GetName(CString&); - virtual int InitObject(T2Object*); - virtual void DrawProc(T2HaveOutViewObject*, const RECT&, T2TowerDoc*) const; - virtual int DrawData(int); + virtual BOOL InitObject(T2Object*); + virtual BOOL IsTenant() { return true; } + virtual int CalcPayment(T2TowerDoc*, RECT& inRect, unsigned int); + virtual unsigned int IdleProc(T2HaveOutViewObject*, T2TowerDoc*); + virtual void DrawProc(T2HaveOutViewObject*, const RECT& inRect, T2TowerDoc*) const; + virtual int CalcMentenanceCostProc(const T2HaveOutViewObject*) const; + virtual AREACHECKCODE AreaCheck(T2TowerDoc*, RECT& inRect, unsigned int, BOOL); virtual void DrawPeople(T2TowerDoc*, T2Equip*); + virtual BOOL EmergencyProc(T2TowerDoc*, T2Equip*); + virtual int DrawData(int); virtual int DrawAttribute(int); - virtual unsigned int IdleProc(T2HaveOutViewObject*, T2TowerDoc*); - virtual int ChangeStatusOnIdle(T2TowerDoc*, T2Tenant*, int); - virtual AREACHECKCODE AreaCheck(T2TowerDoc*, RECT&, unsigned int, int); - virtual int CalcPayment(T2TowerDoc*, RECT&, unsigned int); + virtual BOOL ChangeStatusOnIdle(T2TowerDoc*, T2Tenant*, int); virtual void EnterTenant(T2TowerDoc*, T2Tenant*, T2People*); virtual void LeaveTenant(T2TowerDoc*, T2Tenant*, T2People*); - virtual void BuildStartProc(T2TowerDoc*, T2Tenant*); virtual void DoPeopleAnimation(T2TowerDoc*, T2Tenant*); - virtual int GetQTMovieName(T2Tenant*, CString&); + virtual void BuildStartProc(T2TowerDoc*, T2Tenant*); + virtual BOOL GetQTMovieName(T2Tenant*, CString&); + void SetCustomerTable(T2SubPlugin*); void MakeCustomerTableDef(int, const char*); + + BOOL IsFloor() { return IsSetAttribute(kTenantAttrIsFloor); } + BOOL IsValiableLength() { return IsSetAttribute(kTenantAttrIsValiableLength); } + BOOL IsHome() { return IsSetAttribute(kTenantAttrIsHome); } + BOOL IsConcat() { return IsSetAttribute(kTenantAttrIsConcat); } + BOOL IsPeopleAnime() { return IsSetAttribute(kTenantAttrIsPeopleAnime); } + int GetEntranceV() { return mEntranceV; } + int GetEntranceH() { return mEntranceH; } + int GetExitV() { return mExitV; } + int GetExitH() { return mExitH; } + int GetNumOfPattern() const { return mNumOfPattern; } + int GetNumOfKind() { return mNumOfKind; } + int GetBelongCapacity() const { return mBelongCapacity; } + unsigned int GetRegistID() const { return mRegistID; } + unsigned int GetDownFlag() const { return mDownFlag; } + int GetSenseOfNoise() const { return mSenseOfNoise; } + T2PeopleAnimeDef* GetPeopleAnimeDef() const { return mPeopleAnimeDef; } + T2TenantMemberTableDef* GetEmployeeTableDef() const { return mEmployeeTableDef; } + T2TenantMemberTableDef* GetCustomerTableDef() const { return mCustomerTableDef; } + + int mNumOfKind; + int mNumOfPattern; + int mBelongCapacity; + int mEntranceV; + int mEntranceH; + int mExitV; + int mExitH; + int mOpenTime; + int mCloseTime; + int mBindTime; + int m180; + CString m184; + int m188; + T2TenantMemberTableDef *mEmployeeTableDef; + T2TenantMemberTableDef *mCustomerTableDef; + int m194; + int m198; + unsigned int mRegistID; + unsigned int mDownFlag; + int mSenseOfNoise; + T2PeopleAnimeDef *mPeopleAnimeDef; + int m1AC; + int m1B0; + int m1B4; + protected: float CalcNumOfCustomerUnit(); -public: - virtual int EmergencyProc(T2TowerDoc*, T2Equip*); - virtual int CalcMentenanceCostProc(const T2HaveOutViewObject*) const; - - virtual int IsTenant() {} - int IsFloor() {} - int IsValiableLength() {} - int IsHome() {} - int IsConcat() {} - int IsPeopleAnime() {} - int GetEntranceV() {} - int GetEntranceH() {} - int GetExitV() {} - int GetExitH() {} - int GetNumOfPattern() const {} - int GetNumOfKind() {} - int GetBelongCapacity() const {} - unsigned int GetRegistID() const {} - unsigned int GetDownFlag() const {} - int GetSenseOfNoise() const {} - T2PeopleAnimeDef* GetPeopleAnimeDef() const {} - T2TenantMemberTableDef* GetEmployeeTableDef() const {} - T2TenantMemberTableDef* GetCustomerTableDef() const {} - T2TenantDef& operator=(T2TenantDef&) {} }; diff --git a/src/T2DLL/T2TenantInfoDialog.cpp b/src/T2DLL/T2TenantInfoDialog.cpp index 149de6c..cfe4621 100644 --- a/src/T2DLL/T2TenantInfoDialog.cpp +++ b/src/T2DLL/T2TenantInfoDialog.cpp @@ -1,6 +1,8 @@ #include "T2TenantInfoDialog.h" -T2TenantInfoDialog::T2TenantInfoDialog(T2Tenant*) { +T2TenantInfoDialog::T2TenantInfoDialog(T2Tenant* inTenant) + : T2EquipInfoDialog(inTenant) +{ } /*virtual*/ T2TenantInfoDialog::~T2TenantInfoDialog() { diff --git a/src/T2DLL/T2TenantInfoDialog.h b/src/T2DLL/T2TenantInfoDialog.h index aa68b8b..be11c0c 100644 --- a/src/T2DLL/T2TenantInfoDialog.h +++ b/src/T2DLL/T2TenantInfoDialog.h @@ -1,11 +1,14 @@ #pragma once #include "common.h" +#include "T2EquipInfoDialog.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" -class T2TenantInfoDialog { +class AFX_EXT_CLASS T2TenantInfoDialog : public T2EquipInfoDialog { public: - T2TenantInfoDialog(T2Tenant*); + T2TenantInfoDialog(T2Tenant* inTenant); virtual ~T2TenantInfoDialog(); - T2Tenant* GetTenant() const {} - T2TenantDef* GetTenantDef() const {} + T2Tenant* GetTenant() const { return (T2Tenant *) mObject; } + T2TenantDef* GetTenantDef() const { return (T2TenantDef *) mEquipDef; } }; diff --git a/src/T2DLL/T2TenantMemberDef.h b/src/T2DLL/T2TenantMemberDef.h index 215e0f4..431e830 100644 --- a/src/T2DLL/T2TenantMemberDef.h +++ b/src/T2DLL/T2TenantMemberDef.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class T2TenantMemberDef { +class AFX_EXT_CLASS T2TenantMemberDef { public: T2TenantMemberDef(); virtual ~T2TenantMemberDef(); diff --git a/src/T2DLL/T2TenantMemberTableDef.cpp b/src/T2DLL/T2TenantMemberTableDef.cpp index 37a06a1..780ea02 100644 --- a/src/T2DLL/T2TenantMemberTableDef.cpp +++ b/src/T2DLL/T2TenantMemberTableDef.cpp @@ -1,46 +1,205 @@ +#include "CResFile.h" +#include "T2DateTime.h" +#include "T2DayParamDef.h" +#include "T2PlaceParamDef.h" +#include "T2TenantMemberDef.h" #include "T2TenantMemberTableDef.h" +#include "T2TowerDoc.h" +#include "UT2Utils.h" -T2TenantMemberTableDef::T2TenantMemberTableDef(HINSTANCE, CResFile*, float) { +T2TenantMemberTableDef::T2TenantMemberTableDef(HINSTANCE instance, CResFile* resFile, float f) { + Initialize(); + + *resFile >> mEconoType; + *resFile >> mSpecialFlag; + + int resID; + + *resFile >> resID; + if (resID) + mDayParamDef = MakeDayParamDef(instance, resID); + + try { + *resFile >> resID; + if (resID) + mPlaceParamDef = MakePlaceParamDef(instance, resID); + + *resFile >> mNumOfElem; + if (mNumOfElem > 0) { + mElem = new T2TenantMemberDef[mNumOfElem]; + for (int i = 0; i < mNumOfElem; i++) + mElem[i].Initialize(resFile, f); + } + } catch (CException &exc) { + delete this; + } } -T2TenantMemberTableDef::T2TenantMemberTableDef(const char*, CResFile*, float) { +T2TenantMemberTableDef::T2TenantMemberTableDef(const char* path, CResFile* resFile, float f) { + Initialize(); + + *resFile >> mEconoType; + *resFile >> mSpecialFlag; + + int resID; + + *resFile >> resID; + if (resID) + mDayParamDef = MakeDayParamDef(path, resID); + + try { + *resFile >> resID; + if (resID) + mPlaceParamDef = MakePlaceParamDef(path, resID); + + *resFile >> mNumOfElem; + if (mNumOfElem > 0) { + mElem = new T2TenantMemberDef[mNumOfElem]; + for (int i = 0; i < mNumOfElem; i++) + mElem[i].Initialize(resFile, f); + } + } catch (CException &exc) { + delete this; + } } /*virtual*/ T2TenantMemberTableDef::~T2TenantMemberTableDef() { + if (mDayParamDef) + delete mDayParamDef; + if (mPlaceParamDef) + delete mPlaceParamDef; + delete[] mElem; } void T2TenantMemberTableDef::Initialize() { + mEconoType = 0; + mSpecialFlag = 0; + mDayParamDef = NULL; + mPlaceParamDef = NULL; + mNumOfElem = 0; + mElem = NULL; } int T2TenantMemberTableDef::GetEconoType() const { + int type = mEconoType; + if (mEconoType != -1) + type &= ~0x10; + return type; } -int T2TenantMemberTableDef::IsCheckOnlyFirstEconoType() const { +BOOL T2TenantMemberTableDef::IsCheckOnlyFirstEconoType() const { + BOOL result = false; + if (mEconoType != -1) + result = (mEconoType & 0x10) != 0; + return result; } -T2TenantMemberDef* T2TenantMemberTableDef::GetElem(int) const { +T2TenantMemberDef* T2TenantMemberTableDef::GetElem(int i) const { + T2TenantMemberDef *result = NULL; + if (i >= 0 && i < mNumOfElem) + result = &mElem[i]; + return result; } -int T2TenantMemberTableDef::GetScore(T2PlaceParamDef::EPlace) const { +int T2TenantMemberTableDef::GetScore(T2PlaceParamDef::EPlace place) const { + int result = 0; + if (mPlaceParamDef) { + result = mPlaceParamDef->GetScore(place); + } else if (place == T2PlaceParamDef::Place_0) { + result = 1000; + } + return result; } -int T2TenantMemberTableDef::IsCollectFromFloor() const { +BOOL T2TenantMemberTableDef::IsCollectFromFloor() const { + BOOL result = false; + if (mPlaceParamDef) { + float rate = mPlaceParamDef->GetRate(T2PlaceParamDef::Place_2); + if (UT2Utils::Float2Int(rate) > 0) + result = true; + } + return result; } -int T2TenantMemberTableDef::IsCollectFromPool(T2TowerDoc*) const { +BOOL T2TenantMemberTableDef::IsCollectFromPool(T2TowerDoc* towerDoc) const { + BOOL result = true; + + if (mPlaceParamDef) { + float rate = mPlaceParamDef->GetRate(T2PlaceParamDef::Place_0); + if (UT2Utils::Float2Int(rate) == 0) + result = false; + } + + if (result && mDayParamDef) { + T2DayParamDef::EDay day = T2DayParamDef::Day_0; + T2DayParamDef::EWhether whether = T2DayParamDef::Whether_0; + + T2DateTime *now = towerDoc->towerDoc_vf120(); + if (now->IsHoliday(towerDoc)) + day = T2DayParamDef::Day_1; + + float rate = mDayParamDef->GetRate(day, whether); + if (UT2Utils::Float2Int(rate) == 0) + result = false; + } + + return result; } -int T2TenantMemberTableDef::IsCollectFromTenant() const { +BOOL T2TenantMemberTableDef::IsCollectFromTenant() const { + BOOL result = false; + if (mPlaceParamDef) { + float rate = mPlaceParamDef->GetRate(T2PlaceParamDef::Place_1); + if (UT2Utils::Float2Int(rate) > 0) + result = true; + } + return result; } -T2DayParamDef* T2TenantMemberTableDef::MakeDayParamDef(HINSTANCE, int) { +T2DayParamDef* T2TenantMemberTableDef::MakeDayParamDef(HINSTANCE instance, int resID) { + T2DayParamDef *result = NULL; + + CResFile resFile; + if (resFile.OpenResource(instance, resID, 'DpDf')) { + result = new T2DayParamDef(resFile); + resFile.End(); + } + + return result; } -T2DayParamDef* T2TenantMemberTableDef::MakeDayParamDef(const char*, int) { +T2DayParamDef* T2TenantMemberTableDef::MakeDayParamDef(const char* path, int resID) { + T2DayParamDef *result = NULL; + + CResFile resFile; + if (resFile.OpenResource(path, resID, 'DPDF')) { + result = new T2DayParamDef(resFile); + resFile.End(); + } + + return result; } -T2PlaceParamDef* T2TenantMemberTableDef::MakePlaceParamDef(HINSTANCE, int) { +T2PlaceParamDef* T2TenantMemberTableDef::MakePlaceParamDef(HINSTANCE instance, int resID) { + T2PlaceParamDef *result = NULL; + + CResFile resFile; + if (resFile.OpenResource(instance, resID, 'PlDf')) { + result = new T2PlaceParamDef(resFile); + resFile.End(); + } + + return result; } -T2PlaceParamDef* T2TenantMemberTableDef::MakePlaceParamDef(const char*, int) { +T2PlaceParamDef* T2TenantMemberTableDef::MakePlaceParamDef(const char* path, int resID) { + T2PlaceParamDef *result = NULL; + + CResFile resFile; + if (resFile.OpenResource(path, resID, 'PLDF')) { + result = new T2PlaceParamDef(resFile); + resFile.End(); + } + + return result; } diff --git a/src/T2DLL/T2TenantMemberTableDef.h b/src/T2DLL/T2TenantMemberTableDef.h index e189d59..0a05bab 100644 --- a/src/T2DLL/T2TenantMemberTableDef.h +++ b/src/T2DLL/T2TenantMemberTableDef.h @@ -1,7 +1,8 @@ #pragma once #include "common.h" +#include "T2PlaceParamDef.h" -class T2TenantMemberTableDef { +class AFX_EXT_CLASS T2TenantMemberTableDef { public: T2TenantMemberTableDef(HINSTANCE, CResFile*, float); T2TenantMemberTableDef(const char*, CResFile*, float); @@ -10,21 +11,29 @@ private: void Initialize(); public: int GetEconoType() const; - int IsCheckOnlyFirstEconoType() const; + BOOL IsCheckOnlyFirstEconoType() const; T2TenantMemberDef* GetElem(int) const; int GetScore(T2PlaceParamDef::EPlace) const; - int IsCollectFromFloor() const; - int IsCollectFromPool(T2TowerDoc*) const; - int IsCollectFromTenant() const; + BOOL IsCollectFromFloor() const; + BOOL IsCollectFromPool(T2TowerDoc*) const; + BOOL IsCollectFromTenant() const; + + int GetNumOfElem() const { return mNumOfElem; } + unsigned int GetSpecialFlag() const { return mSpecialFlag; } + protected: T2DayParamDef* MakeDayParamDef(HINSTANCE, int); T2DayParamDef* MakeDayParamDef(const char*, int); T2PlaceParamDef* MakePlaceParamDef(HINSTANCE, int); T2PlaceParamDef* MakePlaceParamDef(const char*, int); -public: - T2TenantMemberTableDef(const T2TenantMemberTableDef&) {} - T2TenantMemberTableDef& operator=(const T2TenantMemberTableDef&) {} - int GetNumOfElem() const {} - unsigned int GetSpecialFlag() const {} + int m4; + int mEconoType; + unsigned int mSpecialFlag; + int m10; + T2DayParamDef *mDayParamDef; + T2PlaceParamDef *mPlaceParamDef; + int m1C; + int mNumOfElem; + T2TenantMemberDef *mElem; }; diff --git a/src/T2DLL/T2TenantPlugin.cpp b/src/T2DLL/T2TenantPlugin.cpp index 428b111..e642b84 100644 --- a/src/T2DLL/T2TenantPlugin.cpp +++ b/src/T2DLL/T2TenantPlugin.cpp @@ -1,19 +1,38 @@ +#include "CResFile.h" #include "T2TenantPlugin.h" -T2TenantPlugin::T2TenantPlugin(unsigned long, T2PluginSpecifier&) { +T2TenantPlugin::T2TenantPlugin(DWORD type, T2PluginSpecifier& specifier) + : T2EquipPlugin(type, specifier) +{ } /*virtual*/ T2TenantPlugin::~T2TenantPlugin() { } -int T2TenantPlugin::TestLoadAllDefRsrcPlugin() { +BOOL T2TenantPlugin::TestLoadAllDefRsrcPlugin() { + return true; } -int T2TenantPlugin::LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*) { +BOOL T2TenantPlugin::LoadAllTemplatePlugin(T2WorldDef* worldDef, T2TemplatePluginDB*) { + LoadT2TenantDef(worldDef); + return true; } -unsigned long T2TenantPlugin::GetShopPluginType() { +DWORD T2TenantPlugin::GetShopPluginType() { + return 0; } -void T2TenantPlugin::LoadT2TenantDef(T2WorldDef*) { +typedef T2TemplatePlugin *(MSVC_STDCALL* ConstructTemplatePluginType) (T2PluginSpecifier *, CResFile *, T2WorldDef *, T2TenantPlugin *); + +void T2TenantPlugin::LoadT2TenantDef(T2WorldDef* worldDef) { + ConstructTemplatePluginType func = (ConstructTemplatePluginType) GetProcAddress((HMODULE) mModuleHandle, "ConstructTemplatePlugin"); +#line 41 + _ASSERT(func); + + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, 'TnDf'); + T2TemplatePlugin *plugin = func(&mSpecifier, &resFile, worldDef, this); + resFile.End(); + + mTemplatePlugin = plugin; } diff --git a/src/T2DLL/T2TenantPlugin.h b/src/T2DLL/T2TenantPlugin.h index 0519a81..ff9706c 100644 --- a/src/T2DLL/T2TenantPlugin.h +++ b/src/T2DLL/T2TenantPlugin.h @@ -1,16 +1,15 @@ #pragma once #include "common.h" +#include "T2EquipPlugin.h" -class T2TenantPlugin { +class AFX_EXT_CLASS T2TenantPlugin : public T2EquipPlugin { public: - T2TenantPlugin(unsigned long, T2PluginSpecifier&); + T2TenantPlugin(DWORD, T2PluginSpecifier&); virtual ~T2TenantPlugin(); - int TestLoadAllDefRsrcPlugin(); - int LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*); - unsigned long GetShopPluginType(); + BOOL TestLoadAllDefRsrcPlugin(); + BOOL LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*); + DWORD GetShopPluginType(); + private: void LoadT2TenantDef(T2WorldDef*); - -public: - T2TenantPlugin& operator=(T2TenantPlugin&) {} }; diff --git a/src/T2DLL/T2Terrorist.cpp b/src/T2DLL/T2Terrorist.cpp index 6d3e7ac..0a082c6 100644 --- a/src/T2DLL/T2Terrorist.cpp +++ b/src/T2DLL/T2Terrorist.cpp @@ -1,28 +1,583 @@ +#include "CResFile.h" +#include "CT2App.h" +#include "GlobalFunc.h" +#include "LArray.h" +#include "T2CtrlPalette.h" +#include "T2DateTime.h" +#include "T2Dialog.h" +#include "T2DlgItem.h" +#include "T2EquipPtrList.h" +#include "T2FInfoAreaIterator.h" +#include "T2FireBurning.h" +#include "T2FloorInfo.h" +#include "T2FloorPtrList.h" +#include "T2MainWindow.h" +#include "T2People.h" +#include "T2RegistedTenantDB.h" +#include "T2RouteNavigator.h" +#include "T2Settlement.h" +#include "T2SoundPlayer.h" +#include "T2Tenant.h" #include "T2Terrorist.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "URect.h" +#include "UT2Coordinate.h" +#include "UT2Utils.h" -T2Terrorist::T2Terrorist(T2TowerEvent*, CResFile*, int) { +T2Terrorist::T2Terrorist(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + *inResFile >> mRansomFee; + *inResFile >> mDeadline; + *inResFile >> mHigherRansomFee; + + mBombHideRoomID = 0; + mLastMinute = 0; + mAttach = NULL; + + mSearcherL = new LArray; + mSearcherR = new LArray; } /*virtual*/ T2Terrorist::~T2Terrorist() { + StopEvent(GetTowerDoc()); + delete mSearcherL; + mSearcherL = NULL; + delete mSearcherR; + mSearcherR = NULL; } -/*virtual*/ int T2Terrorist::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2Terrorist::Start(T2TowerDoc* inDoc) { + mStatus = kTerroristStatus0; + + BOOL found = false; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + + RECT theIteratorArea; + int theGroundLine = theFloorInfo->GetGroundLine(); + theFloorInfo->GetFloorArea(theIteratorArea); + if (theIteratorArea.bottom > (theGroundLine - 3)) + theIteratorArea.bottom = theGroundLine - 3; + + T2FInfoAreaIterator iterator(*theFloorInfo, theIteratorArea); + T2Tenant *theTenant; + while (iterator.NextTenant(theTenant)) { + found = theTenant && !theTenant->IsFireproof() && !theTenant->IsFire(); + if (found) + break; + } + + if (!found) + return false; + + SetupSound(); + inDoc->towerDoc_vf144(ViewMode_0); + inDoc->towerDoc_vf1A0(true); + + CString text, tempStr; + text = LoadStringTable(GetWorldModuleHandle(), 8300, 1); + + tempStr.Format("%d", mRansomFee); + text += tempStr; + + text += LoadStringTable(GetWorldModuleHandle(), 8300, 2); + + tempStr.Format("%d", mDeadline / 60); + text += tempStr; + + text += LoadStringTable(GetWorldModuleHandle(), 8300, 3); + + Sounds->Play("Terrorist:", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); + + if (DoDialog(inDoc, 8300, 8300, 2, text) == 8303) { + inDoc->towerDoc_vf270(mRansomFee, kFundGroup2); + Sounds->Play("Terrorist:ThankYou", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); + + DWORD time = timeGetTime(); + while ((timeGetTime() - time) < 900) + gT2App->app_vfB4(); + + inDoc->towerDoc_vf1A0(false); + } else { + inDoc->towerDoc_vf2A8(25); + inDoc->SetFireBurning(true); + inDoc->towerDoc_vf2A0()->EnableIcon(false); + inDoc->GetTowerMainView()->tmv_vf154(); + inDoc->towerDoc_vf2B0(true); + ((T2MainWindow *) AfxGetMainWnd())->mCtrlPalette->vf108(0); + + do { + mBombHidePos.x = UT2Utils::Randomize(URect::Width(theIteratorArea)) + theIteratorArea.left; + mBombHidePos.y = UT2Utils::Randomize(URect::Height(theIteratorArea)) + theIteratorArea.top; + theTenant = theFloorInfo->GetTenant(mBombHidePos.y, mBombHidePos.x); + } while (!theTenant || theTenant->IsFire() || theTenant->IsFireproof()); + + mBombHideRoomID = theTenant->GetEquipID(); + + inDoc->towerDoc_vf1B4(); + inDoc->GetTowerMainView()->tmv_vf120(); + + T2TowerMainView *theView = inDoc->GetTowerMainView(); + + text = LoadStringTable(GetWorldModuleHandle(), 8300, 4); + DoAlert(inDoc, text, 0); + + mStatus = kTerroristStatus1; + + mAttach = new T2FireAttach(this, 0, true); + theView->AddAttachment(mAttach, NULL, true); + + inDoc->towerDoc_vf2A8(25); + + T2EquipPtrList *theList = inDoc->towerDoc_vf174()->GetList(kTenantRegistID5); + if (theList) { + T2FloorPtrList *theFloorList = inDoc->towerDoc_vf124()->GetFloorPtrList(); + LArrayIterator floorIterator(*theFloorList); + T2Tenant *theFloor; + while (floorIterator.Next(&theFloor)) + theFloor->ClearWorkCount(); + + T2Tenant *iteratorTenant; + LArrayIterator tenantIterator(*theList); + while (tenantIterator.Next(&iteratorTenant)) { + T2Tenant *theCurrFloor = inDoc->towerDoc_vf12C()->GetTenant(iteratorTenant->GetExitFloorID()); + if (theCurrFloor) { + CRect area; + theCurrFloor->GetEquipArea(area); + CPoint ptL(area.left, area.bottom - 1); + CPoint ptR(area.right - 2, area.bottom - 1); + + unsigned int capacity = iteratorTenant->GetBelongCapacity(); + BOOL flag = false; + for (unsigned int i = 1; i <= capacity; i++) { + T2People *people = iteratorTenant->GetBelongPeopleIn(i); + if (people) { + people->SetSpecialFlag(kSpecialFlag20); + if ((i % 2) == 0) { + mSearcherL->Add(&people); + iteratorTenant->PushOutPeople(inDoc, people); + people->ChangeStyle(kPeopleStyle2); + people->SetCurrDestPos(ptL); + people->SetStatus(kStatus14); + if (people->GetDirection() != 1) + people->FlipDirection(); + } else { + mSearcherR->Add(&people); + iteratorTenant->PushOutPeople(inDoc, people); + people->ChangeStyle(kPeopleStyle2); + people->SetCurrDestPos(ptR); + people->SetStatus(kStatus14); + if (people->GetDirection() != 0) + people->FlipDirection(); + } + flag |= true; + } + } + + if (flag) + theCurrFloor->IncWorkCount(); + } + } + } + + Sounds->Play("Terrorist:Tick", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_3, 100); + } + + if (mStatus == kTerroristStatus0) + DisposeSound(); + + return (mStatus != kTerroristStatus0); } void T2Terrorist::SetupSound() { + Sounds->FadeOut(); + Sounds->AddSound("Terrorist:", SoundPriority_1, 8300, GetWorldModuleHandle()); + Sounds->AddSound("Terrorist:Tick", SoundPriority_1, 8301, GetWorldModuleHandle()); + Sounds->AddSound("Terrorist:Exp", SoundPriority_1, 8302, GetWorldModuleHandle()); + Sounds->AddSound("Terrorist:ThankYou", SoundPriority_1, 8303, GetWorldModuleHandle()); } void T2Terrorist::DisposeSound() { + if (Sounds) { + Sounds->Stop("Terrorist:"); + Sounds->Stop("Terrorist:Tick"); + Sounds->Stop("Terrorist:Exp"); + Sounds->Stop("Terrorist:ThankYou"); + Sounds->DeleteSound("Terrorist:"); + Sounds->DeleteSound("Terrorist:Tick"); + Sounds->DeleteSound("Terrorist:Exp"); + Sounds->DeleteSound("Terrorist:ThankYou"); + Sounds->FadeIn(); + } } -/*virtual*/ int T2Terrorist::Exec(T2TowerDoc*) { +static void MoveNextFloor(T2TowerDoc *inDoc, T2People *inPeople, BOOL inFlag); + +/*virtual*/ int T2Terrorist::Exec(T2TowerDoc* inDoc) { + int result = IsExclusive() ? 1 : 0; + T2DateTime *theNow = inDoc->towerDoc_vf120(); + unsigned int nowMinutes = theNow->GetRawMinutes(); + + if (mStatus == kTerroristStatus1) { + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2People *theSearcher; + + LArrayIterator theIteratorL(*mSearcherL); + while (mStatus != kTerroristStatus2 && theIteratorL.Next(&theSearcher)) { + CPoint pt = theSearcher->GetCurPosition(); + T2Tenant *theTenant = theFloorInfo->GetTenant(pt.y, pt.x); + if (theTenant && IsBombHideRoom(theTenant->GetEquipID())) + mStatus = kTerroristStatus2; + + if (mStatus != kTerroristStatus2 && theSearcher->GetStatus() == kStatus15) + MoveNextFloor(inDoc, theSearcher, false); + } + + LArrayIterator theIteratorR(*mSearcherR); + while (mStatus != kTerroristStatus2 && theIteratorR.Next(&theSearcher)) { + CPoint pt = theSearcher->GetCurPosition(); + T2Tenant *theTenant = theFloorInfo->GetTenant(pt.y, pt.x); + if (theTenant && IsBombHideRoom(theTenant->GetEquipID())) + mStatus = kTerroristStatus2; + + if (mStatus != kTerroristStatus2 && theSearcher->GetStatus() == kStatus15) + MoveNextFloor(inDoc, theSearcher, true); + } + } + + if (mLastMinute != nowMinutes) { + CString text; + CString tmpStr; + + switch (mStatus) { + case kTerroristStatus1: + if (nowMinutes == mDeadline) { + text = LoadStringTable(GetWorldModuleHandle(), 8300, 5); + + tmpStr.Format("%d", mHigherRansomFee); + text += tmpStr; + + text += LoadStringTable(GetWorldModuleHandle(), 8300, 6); + + int hour = mEndTime / 60; + tmpStr.Format("%d", (hour > 12) ? (hour - 12) : hour); + text += tmpStr; + + text += LoadStringTable(GetWorldModuleHandle(), 8300, 7); + + tmpStr.Format("%d", (hour > 12) ? (hour - 12) : hour); + text += tmpStr; + + text += LoadStringTable(GetWorldModuleHandle(), 8300, 8); + + tmpStr.Format("%d", mHigherRansomFee); + text += tmpStr; + + text += LoadStringTable(GetWorldModuleHandle(), 8300, 9); + + if (DoDialog(inDoc, 8300, 8300, 2, text) == 1) { + inDoc->towerDoc_vf270(mHigherRansomFee, kFundGroup2); + result = 3; + } else { + inDoc->towerDoc_vf2A8(25); + } + } else if (nowMinutes == mEndTime) { + Sounds->Stop("Terrorist:Tick"); + Sounds->Play("Terrorist:Exp", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); + mStatus = kTerroristStatus3; + } + break; + + case kTerroristStatus3: + { + int hL, hR, vF, vA; + T2Tenant *theTenant; + hL = mBombHidePos.x; + hR = mBombHidePos.x; + for (int numOfAttempts = 0; numOfAttempts <= 40; numOfAttempts++) { + for (int hDir = 0; hDir < 2; hDir++) { + vA = vF = mBombHidePos.y; + for (int i = 0; i <= 2; i++) { + int h = (hDir == 0) ? hL : hR; + if (h > 0 && h < GetWorldDef()->GetWidth()) { + for (int vDir = 0; vDir < 2; vDir++) { + int v = (vDir == 0) ? vA : vF; + if (v > 0 && v < GetWorldDef()->mGroundLine) { + theTenant = inDoc->towerDoc_vf12C()->GetTenant(v, h); + if (theTenant && !theTenant->IsFire() && !theTenant->IsFireproof()) + theTenant->BurntDown(inDoc); + + if (vDir == 0) + vA = theTenant ? (vA - 1) : 0; + else + vF = theTenant ? (vF + 1) : 0; + } + } + + if (vA == 0 && vF == 0) + break; + } else { + break; + } + } + + if (hDir == 0) + hL = (vA == 0 && vF == 0) ? 0 : (hL - 1); + else + hR = (vA == 0 && vF == 0) ? 0 : (hR + 1); + } + + if (hL == 0 && hR == 0) + break; + } + + T2TowerMainView *theMainView = inDoc->GetTowerMainView(); + CRect theBombArea; + UT2Coordinate::MakeRect(theBombArea, mBombHidePos, 1, 1); + theMainView->tmv_vf15C(theBombArea); + + if (inDoc->towerDoc_vf140() != ViewMode_1) + inDoc->towerDoc_vf284(); + else + ((T2MainWindow *) AfxGetMainWnd())->mCtrlPalette->vf108(false); + + text = LoadStringTable(GetWorldModuleHandle(), 8300, 10); + DoAlert(inDoc, text, 0); + result = 3; + break; + } + + case kTerroristStatus2: + text = LoadStringTable(GetWorldModuleHandle(), 8300, 11); + DoAlert(inDoc, text, 0); + result = 3; + break; + } + + mLastMinute = nowMinutes; + } + + if (result == 3) + StopEvent(inDoc); + + return result; +} + +static void MoveNextFloor(T2TowerDoc *inDoc, T2People *inPeople, BOOL inFlag) { + int theNextDirection; + if (inPeople->GetDirection() == 0) + theNextDirection = 1; + else + theNextDirection = 0; + + T2Tenant *theNextFloor = NULL; + BOOL search = true; + + CRect theEquipRect; + CPoint theNextPt; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2Tenant *theCurrFloor = theFloorInfo->GetTenant(inPeople->GetCurrEquipID()); + + CRect theSearchRect; + theCurrFloor->GetEquipArea(theSearchRect); + + CPoint searchPtRight, searchPtLeft; + + int entranceH; + + while (!theNextFloor && search) { + searchPtRight.x = theSearchRect.left; + searchPtLeft.x = theSearchRect.right - 1; + if (inFlag) { + searchPtRight.y = theSearchRect.bottom; + searchPtLeft.y = theSearchRect.bottom; + } else { + searchPtRight.y = theSearchRect.top - 1; + searchPtLeft.y = theSearchRect.top - 1; + } + SetRect(&theSearchRect, searchPtRight.x, searchPtRight.y, searchPtRight.x, searchPtRight.y); + search = false; + + if (theNextDirection) { + T2FInfoPtIterator iterator(*theFloorInfo, searchPtLeft); + T2Tenant *iterTenant; + while (!theNextFloor && iterator.LeftTenant(iterTenant)) { + search |= true; + + T2Tenant *theFloor = theFloorInfo->GetTenant(iterTenant->GetFloorID(-1)); + theFloor->GetEquipArea(theEquipRect); + if (theEquipRect.right < searchPtRight.x) + break; + + UnionRect(&theSearchRect, &theEquipRect, &theSearchRect); + if (theFloor->GetWorkCount() == 0) { + theNextFloor = theFloor; + theNextPt.y = theEquipRect.bottom - 1; + entranceH = theEquipRect.right - 2; + theNextPt.x = theEquipRect.left; + } + } + } else { + T2FInfoPtIterator iterator(*theFloorInfo, searchPtRight); + T2Tenant *iterTenant; + while (!theNextFloor && iterator.RightTenant(iterTenant)) { + T2Tenant *theFloor = theFloorInfo->GetTenant(iterTenant->GetFloorID(-1)); + theFloor->GetEquipArea(theEquipRect); + if (theEquipRect.left > searchPtLeft.x) + break; + + search |= true; + + UnionRect(&theSearchRect, &theEquipRect, &theSearchRect); + if (theFloor->GetWorkCount() == 0) { + theNextFloor = theFloor; + theNextPt.y = theEquipRect.bottom - 1; + entranceH = theEquipRect.left; + theNextPt.x = theEquipRect.right - 2; + } + } + } + } + + CRect theSilhouetteArea; + inPeople->CalcWalkingSilhouetteArea(theSilhouetteArea); + theFloorInfo->SetTenantDrawModeByRect(theSilhouetteArea, DrawMode1); + inDoc->GetTowerMainView()->tmv_vf128(theSilhouetteArea); + + if (theNextFloor) { + theCurrFloor->Leave(inPeople); + inPeople->MoveVTo(theNextPt.y); + inPeople->MoveHTo(entranceH); + theNextFloor->Enter(inPeople); + + inPeople->SetCurrDestPos(theNextPt); + inPeople->SetStatus(kStatus14); + inPeople->FlipDirection(); + theNextFloor->IncWorkCount(); + } else { + inPeople->ChangeStyle(kPeopleStyle1); + inPeople->ChangeWalkStyle(0); + unsigned int theWorkID = inPeople->GetWorkTenant(); + inPeople->SetDestination(theWorkID); + inPeople->SetStatus(kStatus3); + } } -/*virtual*/ void T2Terrorist::StopEvent(T2TowerDoc*) { +/*virtual*/ void T2Terrorist::StopEvent(T2TowerDoc* inDoc) { + T2TowerMainView *theMainView = inDoc->GetTowerMainView(); + if (theMainView && mAttach) { + theMainView->RemoveAttachment(mAttach); + delete mAttach; + mAttach = NULL; + } + + CRect theSilhouetteArea; + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2People *theSecurityMan; + + LArrayIterator theIteratorL(*mSearcherL); + while (theIteratorL.Next(&theSecurityMan)) { +#line 536 + _ASSERT(theSecurityMan != NULL); + + if (theSecurityMan) { + theSecurityMan->ClearSpecialFlag(kSpecialFlag20); + if (theSecurityMan->GetStatus() == kStatus14 || theSecurityMan->GetStatus() == kStatus15) { + theSecurityMan->ChangeStyle(kPeopleStyle1); + unsigned int theWorkID = theSecurityMan->GetWorkTenant(); +#line 562 + _ASSERT(theWorkID != 0); + + theSecurityMan->SetDestination(theWorkID); + theSecurityMan->SetStatus(kStatus3); + } + + theSecurityMan->CalcWalkingSilhouetteArea(theSilhouetteArea); + theFloorInfo->SetTenantDrawModeByRect(theSilhouetteArea, DrawMode1); + theMainView->tmv_vf128(theSilhouetteArea); + } + } + + mSearcherL->RemoveItemsAt(mSearcherL->GetCount(), 1); + + LArrayIterator theIteratorR(*mSearcherR); + while (theIteratorR.Next(&theSecurityMan)) { +#line 577 + _ASSERT(theSecurityMan != NULL); + + if (theSecurityMan) { + theSecurityMan->ClearSpecialFlag(kSpecialFlag20); + if (theSecurityMan->GetStatus() == kStatus14 || theSecurityMan->GetStatus() == kStatus15) { + theSecurityMan->ChangeStyle(kPeopleStyle1); + unsigned int theWorkID = theSecurityMan->GetWorkTenant(); +#line 603 + _ASSERT(theWorkID != 0); + + theSecurityMan->SetDestination(theWorkID); + theSecurityMan->SetStatus(kStatus3); + } + + theSecurityMan->CalcWalkingSilhouetteArea(theSilhouetteArea); + theFloorInfo->SetTenantDrawModeByRect(theSilhouetteArea, DrawMode1); + theMainView->tmv_vf128(theSilhouetteArea); + } + } + + mSearcherR->RemoveItemsAt(mSearcherR->GetCount(), 1); + + DisposeSound(); + inDoc->towerDoc_vf2B0(false); + inDoc->towerDoc_vf1A0(false); + inDoc->SetFireBurning(false); + + if (inDoc->GetTowerMainView()) + inDoc->GetTowerMainView()->tmv_vf150(); + if (inDoc->towerDoc_vf2A0()) + inDoc->towerDoc_vf2A0()->EnableIcon(true); + + mStatus = kTerroristStatus0; } -/*virtual*/ unsigned int T2Terrorist::DialogHook(T2EventDialog*, unsigned int, T2TowerDoc*) { +/*virtual*/ unsigned int T2Terrorist::DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc) { + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + T2Tenant *theTenant = theFloorInfo->GetTenantByPID('KEBI'); + BOOL isMissing = (theTenant == NULL); + + switch (inResult) { + case 8303: + if (isMissing) + break; + + if (mStatus == kTerroristStatus1) { + inResult = (inDoc->towerDoc_vf26C() >= mHigherRansomFee) ? inResult : 0; + } else { + inResult = (inDoc->towerDoc_vf26C() >= mRansomFee) ? inResult : 0; + } + + if (inResult == 0) { + CString text = LoadStringTable(GetWorldModuleHandle(), 8300, 12); + DoAlert(inDoc, text, 9000); + } + break; + + case 8304: + if (isMissing) { + CString text = LoadStringTable(GetWorldModuleHandle(), 8300, 13); + DoAlert(inDoc, text, 9000); + inResult = 0; + } + break; + } + + return inResult; } -/*virtual*/ void T2Terrorist::SetupDialog(T2Dialog*) { +/*virtual*/ void T2Terrorist::SetupDialog(T2Dialog* inDialog) { + ((T2DlgItem *) inDialog->GetDlgItem(8303))->AddListener(inDialog); + ((T2DlgItem *) inDialog->GetDlgItem(8304))->AddListener(inDialog); } diff --git a/src/T2DLL/T2Terrorist.h b/src/T2DLL/T2Terrorist.h index 1549258..87b5b51 100644 --- a/src/T2DLL/T2Terrorist.h +++ b/src/T2DLL/T2Terrorist.h @@ -1,24 +1,37 @@ #pragma once #include "common.h" +#include "T2EventItem.h" -class T2Terrorist { +enum { + kTerroristStatus0 = 0, + kTerroristStatus1 = 1, + kTerroristStatus2 = 2, + kTerroristStatus3 = 3, +}; + +class AFX_EXT_CLASS T2Terrorist : public T2EventItem { public: - T2Terrorist(T2TowerEvent*, CResFile*, int); + T2Terrorist(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); virtual ~T2Terrorist(); - virtual int Start(T2TowerDoc*); + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc* inDoc); + virtual void StopEvent(T2TowerDoc* inDoc); + virtual unsigned int DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc); + virtual DWORD GetID() { return 'TrEv'; } + BOOL IsBombHideRoom(unsigned int inTenantID) { return (mBombHideRoomID == inTenantID); } + protected: + virtual void SetupDialog(T2Dialog* inDialog); void SetupSound(); void DisposeSound(); -public: - virtual int Exec(T2TowerDoc*); - virtual void StopEvent(T2TowerDoc*); - virtual unsigned int DialogHook(T2EventDialog*, unsigned int, T2TowerDoc*); -protected: - virtual void SetupDialog(T2Dialog*); -public: - virtual unsigned long GetID() {} - int IsBombHideRoom(unsigned int) {} - T2Terrorist(const T2Terrorist&) {} - T2Terrorist& operator=(const T2Terrorist&) {} + int mRansomFee; + int mDeadline; + int mHigherRansomFee; + unsigned int mBombHideRoomID; + CPoint mBombHidePos; + unsigned int mLastMinute; + T2FireAttach *mAttach; + LArray *mSearcherL; + LArray *mSearcherR; }; diff --git a/src/T2DLL/T2ToolCallback.h b/src/T2DLL/T2ToolCallback.h new file mode 100644 index 0000000..3cde218 --- /dev/null +++ b/src/T2DLL/T2ToolCallback.h @@ -0,0 +1,7 @@ +#pragma once +#include "common.h" + +class AFX_EXT_CLASS T2ToolCallback { +public: + virtual void toolCallback_vf00(int unkParam1, int unkParam2) = 0; +}; diff --git a/src/T2DLL/T2ToolDef.cpp b/src/T2DLL/T2ToolDef.cpp index c57672f..21b0a63 100644 --- a/src/T2DLL/T2ToolDef.cpp +++ b/src/T2DLL/T2ToolDef.cpp @@ -3,24 +3,25 @@ #include "CResourcePlugin.h" #include "T2AdvertisePlugin.h" #include "T2BitImage.h" +#include "T2DateTime.h" #include "T2HaveOutViewObject.h" #include "T2ImageObj.h" #include "T2ToolDef.h" #include "T2ToolPlugin.h" +#include "T2WorldDef.h" #include "UT2Coordinate.h" T2ToolDef::T2ToolDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2ToolPlugin* plugin) : T2TemplatePlugin(type, specifier, resFile, plugin) { mToolIcon = new T2BitImage(mModuleHandle, 100, 1); - // TODO: this needs to come from T2WorldDef - mImageObj->AddObject(mModuleHandle, 100, mToolIcon); + worldDef->m1D0->AddObject(mModuleHandle, 100, mToolIcon); mEC = new T2BitImage(mModuleHandle, 1000, 1); mImageObj->AddObject(mModuleHandle, 1000, mEC); - m114 = NULL; - m118 = 0; + mToolQuietUntil = NULL; + mCategoryQuietUntil = NULL; mSettlement = 0; mCurBuildCount = 0; @@ -79,8 +80,8 @@ T2ToolDef::T2ToolDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile delete mToolIcon; if (mEC) delete mEC; - if (m114) - delete m114; // what type is this? + if (mToolQuietUntil) + delete mToolQuietUntil; // what type is this? if (mSubPluginList) delete mSubPluginList; } @@ -102,7 +103,7 @@ T2ToolDef::T2ToolDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile SetRect(&outRect, inPt.x, inPt.y, inPt.x + mWidth, inPt.y + mHeight); outPt.x = outRect.left; outPt.y = outRect.top; - UT2Coordinate::UnitToQD(outRect, factor, 0); + UT2Coordinate::UnitToQD(outRect, factor); return CursorType_0; } @@ -120,7 +121,7 @@ void T2ToolDef::GetName(CString& outStr, int id) { /*virtual*/ int T2ToolDef::CalcMentenanceCostProc(const T2HaveOutViewObject* obj) const { int cost = 0; T2ToolDef *objToolDef = obj->GetToolDef(); - if (objToolDef->IsSetAttribute(0x100)) + if (objToolDef->IsSetAttribute(kToolAttrNormalMenteCost)) cost = GetOutMoney(obj->GetValiation()); return cost; } diff --git a/src/T2DLL/T2ToolDef.h b/src/T2DLL/T2ToolDef.h index f5cb467..19caf2a 100644 --- a/src/T2DLL/T2ToolDef.h +++ b/src/T2DLL/T2ToolDef.h @@ -2,14 +2,42 @@ #include "common.h" #include "T2TemplatePlugin.h" -class T2ToolDef : public T2TemplatePlugin { +enum { + kToolAttrIsMover = 2, + kEquipAttrIsAbleDragMaking = 0x80, + kToolAttrNormalMenteCost = 0x100, + + kMoverAttrIsStair = 0x2000, + kMoverAttrIsElevator = 0x8000, + kMoverAttrRoutingTable0 = 0x1000000, + kMoverAttrRoutingTable1 = 0x2000000, + kMoverAttrRoutingTable2 = 0x4000000, + kMoverAttrRoutingTable3 = 0x8000000, + + kTenantAttrIsFireproof = 0x1000, + kTenantAttrIsFloor = 0x2000, + kTenantAttrIsValiableLength = 0x4000, + kTenantAttrIsHome = 0x8000, + // 10000 + kTenantAttrIsConcat = 0x20000, + kTenantAttr40000 = 0x40000, + // 80000 + // 100000 + // 200000 + // 400000 + kTenantAttrIsPeopleAnime = 0x800000, + kTenantAttrIsPeopleAnime2 = 0x1000000, + kTenantAttrIsNeedToilet = 0x2000000, +}; + +class AFX_EXT_CLASS T2ToolDef : public T2TemplatePlugin { public: T2ToolDef(DWORD type, T2PluginSpecifier& specifier, CResFile* resFile, T2WorldDef* worldDef, T2ToolPlugin* plugin); virtual ~T2ToolDef(); virtual int GetSortKey(); - virtual int IsMover() { return 0; } - virtual int IsTenant() { return 0; } - virtual int IsOutObj() { return 0; } + virtual BOOL IsMover() { return false; } + virtual BOOL IsTenant() { return false; } + virtual BOOL IsOutObj() { return false; } virtual int CalcPayment(T2TowerDoc*, RECT&, unsigned int id) { return mPrice[id]; } @@ -49,7 +77,7 @@ public: unsigned int GetAttribute() const { return mAttribute; } T2BitImage* GetToolIcon() const { return mToolIcon; } void GetToolName(CString& outStr, int id) const { - outStr = *mNames[id]; + outStr = *mName[id]; } void GetCategoryName(CString outStr) const { // BUG: outStr should be & @@ -66,6 +94,11 @@ public: CFilePluginList* GetSubPluginList() { return mSubPluginList; } protected: + friend class T2Mover; + friend class T2Settlement; + friend class T2TemplatePluginList; + friend class T2ToolHelpWnd; + int mToolType; int mWidth; int mHeight; @@ -91,6 +124,6 @@ protected: DWORD mSubPluginType; CFilePluginList *mSubPluginList; int mSettlement; - void *m114; // TODO what am i? - int m118; + T2DateTime *mToolQuietUntil; + T2DateTime *mCategoryQuietUntil; }; diff --git a/src/T2DLL/T2ToolDefList.cpp b/src/T2DLL/T2ToolDefList.cpp index ef41d49..cb2e25b 100644 --- a/src/T2DLL/T2ToolDefList.cpp +++ b/src/T2DLL/T2ToolDefList.cpp @@ -1,79 +1,188 @@ +#include "T2TempPluginComparator.h" +#include "T2TenantDef.h" +#include "T2ToolDef.h" #include "T2ToolDefList.h" -T2ToolDefDB::T2ToolDefDB(const T2ToolDefDB&) { -} - -T2ToolDefDB& T2ToolDefDB::operator=(const T2ToolDefDB&) { -} - -T2ToolDefDB::T2ToolDefDB() { +T2ToolDefDB::T2ToolDefDB() + : LArray(sizeof(T2ToolDefList *)) +{ } /*virtual*/ T2ToolDefDB::~T2ToolDefDB() { } void T2ToolDefDB::AllClear() { + RemoveItemsAt(mItemCount, 1); } -void T2ToolDefDB::Regist(T2ToolDef*) { -} +void T2ToolDefDB::Regist(T2ToolDef* inToolDef) { + if (!inToolDef) + return; -void T2ToolDefDB::Add(T2ToolDefList*) { -} + int categoryNo = inToolDef->GetCategory(); + int n = 1; + LArrayIterator iterator(*this); + T2ToolDefList *theToolDefList; + BOOL added = false; -T2ToolDefList* T2ToolDefDB::GetToolDefList(int) { -} + while (!added && iterator.Next(&theToolDefList)) { + int thisCategory = theToolDefList->GetCategory(); + if (thisCategory == categoryNo) { + theToolDefList->Add(inToolDef); + added = true; + } else { + if (thisCategory > categoryNo) + break; + } -T2TenantDef* T2ToolDefDB::FindFloor() { -} + n++; + } -int T2ToolDefList::GetCategory() { + if (!added) { + theToolDefList = new T2ToolDefList(categoryNo); + theToolDefList->Add(inToolDef); + InsertItemsAt(1, n, &theToolDefList); + } } -int T2ToolDefList::GetCurrentItem() { -} +void T2ToolDefDB::Add(T2ToolDefList* inToolDefList) { + LArrayIterator iterator(*this); + T2ToolDefList *theToolDefList; + BOOL added = false; -void T2ToolDefList::SetCurrentItem(int) { -} + while (!added && iterator.Next(&theToolDefList)) { + if (theToolDefList->GetCategory() == inToolDefList->GetCategory()) { + LArrayIterator toolDefIterator(*inToolDefList); + T2ToolDef *theToolDef; -int T2ToolDefList::GetCurrentVariant() { -} + while (toolDefIterator.Next(&theToolDef)) + theToolDefList->Add(theToolDef); -void T2ToolDefList::SetCurrentVariant(int) { + added = true; + } + } + + if (!added) + InsertItemsAt(1, mItemCount + 1, &inToolDefList); } -T2ToolDefList::T2ToolDefList(const T2ToolDefList&) { +T2ToolDefList* T2ToolDefDB::GetToolDefList(int inCategory) { + LArrayIterator iterator(*this); + T2ToolDefList *theToolDefList; + + while (iterator.Next(&theToolDefList)) { + if (theToolDefList->GetCategory() == inCategory) + return theToolDefList; + } + + return NULL; } -T2ToolDefList& T2ToolDefList::operator=(const T2ToolDefList&) { +T2TenantDef* T2ToolDefDB::FindFloor() { + LArrayIterator iterator(*this); + T2ToolDefList *theToolDefList; + T2TenantDef *theFloor = NULL; + + while (iterator.Next(&theToolDefList)) { + theFloor = theToolDefList->FindFloor(); + if (theFloor) + return theFloor; + } + + return NULL; } -T2ToolDefList::T2ToolDefList(int) { + + +T2ToolDefList::T2ToolDefList(int inCategory) + : LArray(sizeof(T2TemplatePlugin *)) +{ + mCategory = inCategory; + + SetComparator(T2TempPluginComparator::GetComparator()); + mOwnsComparator = false; + SetKeepSorted(true); + + mCurrentItem = 1; + mCurrentVariant = 0; } /*virtual*/ T2ToolDefList::~T2ToolDefList() { } void T2ToolDefList::AllClear() { + RemoveItemsAt(mItemCount, 1); } -void T2ToolDefList::Regist(T2ToolDef*) { +void T2ToolDefList::Regist(T2ToolDef* inToolDef) { + InsertItemsAt(1, mItemCount + 1, &inToolDef); } -void T2ToolDefList::Add(T2ToolDef*) { +void T2ToolDefList::Add(T2ToolDef* inToolDef) { + if (!inToolDef) + return; + + LArrayIterator iterator(*this); + T2ToolDef *theToolDef; + BOOL done = false; + int n = 1; + + while (!done && iterator.Next(&theToolDef)) { + if (theToolDef->GetToolNo() < inToolDef->GetToolNo()) { + InsertItemsAt(1, n, &inToolDef); + done = true; + } + n++; + } + + if (!done) + InsertItemsAt(1, n, &inToolDef); } unsigned int T2ToolDefList::GetItemCount() { + return GetCount(); } -T2ToolDef* T2ToolDefList::GetItemAt(int) { +T2ToolDef* T2ToolDefList::GetItemAt(int inIndex) { + T2ToolDef *theToolDef; + if (FetchItemAt(inIndex, &theToolDef)) + return theToolDef; + else + return NULL; } T2TenantDef* T2ToolDefList::FindFloor() { + T2ToolDef *theTool; + LArrayIterator iterator(*this); + + while (iterator.Next(&theTool)) { + if (theTool->IsTenant() && ((T2TenantDef *) theTool)->IsFloor()) + return (T2TenantDef *) theTool; + } + + return NULL; } -T2TenantDef* T2ToolDefList::FindTenantDef(int) { +T2TenantDef* T2ToolDefList::FindTenantDef(int inToolType) { + T2ToolDef *theTool; + LArrayIterator iterator(*this); + + while (iterator.Next(&theTool)) { + if (theTool->IsTenant() && theTool->GetToolType() == inToolType) + return (T2TenantDef *) theTool; + } + + return NULL; } -T2MoverDef* T2ToolDefList::FindMoverDef(int) { +T2MoverDef* T2ToolDefList::FindMoverDef(int inToolType) { + T2ToolDef *theTool; + LArrayIterator iterator(*this); + + while (iterator.Next(&theTool)) { + if (theTool->IsMover() && theTool->GetToolType() == inToolType) + return (T2MoverDef *) theTool; + } + + return NULL; } diff --git a/src/T2DLL/T2ToolDefList.h b/src/T2DLL/T2ToolDefList.h index ab9d885..faa8bf3 100644 --- a/src/T2DLL/T2ToolDefList.h +++ b/src/T2DLL/T2ToolDefList.h @@ -1,35 +1,39 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2ToolDefDB { +class AFX_EXT_CLASS T2ToolDefDB : public LArray { public: - T2ToolDefDB(const T2ToolDefDB&); - T2ToolDefDB& operator=(const T2ToolDefDB&); T2ToolDefDB(); virtual ~T2ToolDefDB(); void AllClear(); - void Regist(T2ToolDef*); - void Add(T2ToolDefList*); - T2ToolDefList* GetToolDefList(int); + void Regist(T2ToolDef* inToolDef); + void Add(T2ToolDefList* inToolDefList); + T2ToolDefList* GetToolDefList(int inCategory); T2TenantDef* FindFloor(); }; -class T2ToolDefList { + +class AFX_EXT_CLASS T2ToolDefList : public LArray { public: - int GetCategory(); - int GetCurrentItem(); - void SetCurrentItem(int); - int GetCurrentVariant(); - void SetCurrentVariant(int); - T2ToolDefList(const T2ToolDefList&); - T2ToolDefList& operator=(const T2ToolDefList&); - T2ToolDefList(int); + T2ToolDefList(int inCategory); virtual ~T2ToolDefList(); void AllClear(); - void Regist(T2ToolDef*); - void Add(T2ToolDef*); + void Regist(T2ToolDef* inToolDef); + void Add(T2ToolDef* inToolDef); unsigned int GetItemCount(); - T2ToolDef* GetItemAt(int); + T2ToolDef* GetItemAt(int inIndex); T2TenantDef* FindFloor(); - T2TenantDef* FindTenantDef(int); - T2MoverDef* FindMoverDef(int); + T2TenantDef* FindTenantDef(int inToolType); + T2MoverDef* FindMoverDef(int inToolType); + + int GetCategory() { return mCategory; } + int GetCurrentItem() { return mCurrentItem; } + void SetCurrentItem(int inItem) { mCurrentItem = inItem; } + int GetCurrentVariant() { return mCurrentVariant; } + void SetCurrentVariant(int inVariant) { mCurrentVariant = inVariant; } + +protected: + int mCategory; + int mCurrentItem; + int mCurrentVariant; }; diff --git a/src/T2DLL/T2ToolHelpWnd.cpp b/src/T2DLL/T2ToolHelpWnd.cpp index f839139..19b53a9 100644 --- a/src/T2DLL/T2ToolHelpWnd.cpp +++ b/src/T2DLL/T2ToolHelpWnd.cpp @@ -1,43 +1,214 @@ +#include "T2ToolDef.h" #include "T2ToolHelpWnd.h" -/*static*/ CObject* __stdcall T2ToolHelpWnd::CreateObject() { -} - -/*static*/ CRuntimeClass* __stdcall T2ToolHelpWnd::_GetBaseClass() { -} - -/*virtual*/ CRuntimeClass* T2ToolHelpWnd::GetRuntimeClass() const { +CObject* PASCAL T2ToolHelpWnd::CreateObject() { +#line 20 + return DEBUG_NEW T2ToolHelpWnd; } +IMPLEMENT_DYNAMIC(T2ToolHelpWnd, CFrameWnd); T2ToolHelpWnd::T2ToolHelpWnd() { + mVisible = false; } /*virtual*/ T2ToolHelpWnd::~T2ToolHelpWnd() { } -/*static*/ const AFX_MSGMAP* __stdcall T2ToolHelpWnd::_GetBaseMessageMap() { -} +BEGIN_MESSAGE_MAP(T2ToolHelpWnd, CFrameWnd) + ON_WM_ERASEBKGND() + ON_WM_DESTROY() +END_MESSAGE_MAP() -/*virtual*/ const AFX_MSGMAP* T2ToolHelpWnd::GetMessageMap() const { -} +void T2ToolHelpWnd::OpenToolHelp(POINT& inPt, int inMode, const char* inStr1, const char* inStr2, T2ToolDef* inToolDef, int inValiation) { +#pragma var_order(rect5, rect, save, unit, var48, var4C, rgn, rect2, rect4, rect3, pDC) + int var48 = inPt.x; + int var4C = inPt.y; + + if (inMode == kToolHelpMode0) { + mHeader = inStr2; + mHeader = mHeader.Left(mHeader.Find("\n")); + mText = inStr2; + mText = mText.Mid(mText.Find("\n") + 1); + mComment = ""; + } else if (inMode == kToolHelpMode1) { + mHeader = inStr1; + mText = inStr2; + mComment = ""; + } else if (inMode == kToolHelpMode2) { + CString tmp; + mHeader = *inToolDef->mToolName[inValiation]; + + // "設置費:" - Installation fee: + mText = "\x90\xDD\x92\x75\x94\xEF\x81\x46"; + mText += *inToolDef->mPriceString[inValiation]; + + // "\n維持費:" - Maintenance costs: + mText += "\n\x88\xDB\x8E\x9D\x94\xEF\x81\x46"; + mText += *inToolDef->mOutMoneyString[inValiation]; + + // "\n電 力:%d" - Power: %d + tmp.Format("\n\x93\x64\x81\x40\x97\xCD\x81\x46\x25\x64", inToolDef->mConsumptionPower[inValiation]); + mText += tmp; + + // "\n設置数:%d/" - Installed number: %d/ + tmp.Format("\n\x90\xDD\x92\x75\x90\x94\x81\x46\x25\x64\x81\x5E", inToolDef->mCurBuildCount); + mText += tmp; + + if (inToolDef->mMaxBuildCount == 0) { + // "無制限" - Unlimited + mText += "\x96\xB3\x90\xA7\x8C\xC0"; + } else { + tmp.Format("%d", inToolDef->mMaxBuildCount); + mText += tmp; + } + + mComment = *inToolDef->mCommentString[inValiation]; + } + + mHeader.TrimRight(); + mText.TrimRight(); + mComment.TrimRight(); + + mFont.CreatePointFont(90, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + mWndClass = AfxRegisterWndClass(CS_NOCLOSE, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); + + CRect rect(0, 0, 50, 50); + Create(mWndClass, "", WS_POPUP, rect, AfxGetMainWnd(), NULL, WS_EX_TOPMOST); + + CRect rect2; + GetClientRect(rect2); + ClientToScreen(rect2); + + CRect rect3; + rect3.top = rect2.top - rect.top; + rect3.left = rect2.left - rect.left; + rect3.bottom = rect.bottom - rect2.bottom; + rect3.right = rect.right - rect2.right; + + CDC *pDC = GetDC(); + int save = pDC->SaveDC(); + pDC->SelectObject(mFont); + + mRect.SetRectEmpty(); + // "1234567890123456789" + pDC->DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58", &mRect, DT_SINGLELINE | DT_CALCRECT); + pDC->DrawText(mText, &mRect, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); + + if (mComment != "") { + CRect innerRect; + innerRect.SetRectEmpty(); + pDC->DrawText("\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58\x82\x4F\x82\x50\x82\x51\x82\x52\x82\x53\x82\x54\x82\x55\x82\x56\x82\x57\x82\x58", innerRect, DT_SINGLELINE | DT_CALCRECT); + pDC->DrawText(mComment, &innerRect, DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX); + + mRect.right = max(mRect.right, innerRect.right); + mRect.bottom += innerRect.bottom + 10; + } -void T2ToolHelpWnd::OpenToolHelp(POINT&, int, const char*, const char*, T2ToolDef*, int) { + if (mHeader != "") { + CRect innerRect; + innerRect.SetRectEmpty(); + pDC->DrawText(mHeader, &innerRect, DT_CALCRECT | DT_NOPREFIX); + + mRect.right = max(mRect.right, innerRect.right); + mRect.bottom += innerRect.bottom + 10; + } + + mRect.NormalizeRect(); + mRect.OffsetRect(-mRect.left, -mRect.top); + + CRect rect4; + rect4.SetRect(10, 10, 10, 10); + mRect.OffsetRect(rect4.left, rect4.top); + + CRect rect5; + rect5 = mRect; + rect5 += rect4; + rect5.InflateRect(0, 0, 0, 16); + rect5.NormalizeRect(); + rect5.OffsetRect(-rect5.left, -rect5.top); + rect5.OffsetRect(var48, var4C); + rect5 += rect3; + + SetWindowPos(NULL, rect5.left, rect5.top, rect5.Width(), rect5.Height(), SWP_NOZORDER | SWP_NOACTIVATE); + + rect5 -= rect3; + rect5.OffsetRect(-rect5.left, -rect5.top); + + CRect unit(1, 1, 1, 1); + rect5 -= unit; + + mRgn.CreateRoundRectRgn(rect5.left, rect5.top, rect5.right, rect5.bottom, 10, 10); + + CRgn rgn; + rgn.CreateRectRgn(0, 0, 1, 1); + rgn.CopyRgn(&mRgn); + rgn.OffsetRgn(rect3.left, rect3.top); + ::SetWindowRgn(m_hWnd, rgn, true); + rgn.Detach(); + + pDC->RestoreDC(save); + ReleaseDC(pDC); + + ShowWindow(SW_SHOWNA); + mVisible = true; } void T2ToolHelpWnd::CloseToolHelp() { + if (mVisible) { + ShowWindow(SW_HIDE); + DestroyWindow(); + mVisible = false; + } } -int T2ToolHelpWnd::OnEraseBkgnd(CDC*) { -} +BOOL T2ToolHelpWnd::OnEraseBkgnd(CDC* pDC) { + int saved = pDC->SaveDC(); -void T2ToolHelpWnd::OnDestroy() { -} + CRect clientRect; + GetClientRect(clientRect); + pDC->FillSolidRect(clientRect, RGB(255, 255, 255)); -/*static*/ const CRuntimeClass T2ToolHelpWnd::classT2ToolHelpWnd { -} + CBrush theBrush; + theBrush.CreateStockObject(BLACK_BRUSH); + pDC->FrameRgn(&mRgn, &theBrush, 1, 1); + + pDC->SetBkMode(TRANSPARENT); + pDC->SetTextColor(RGB(0, 0, 0)); + pDC->SelectObject(mFont); + + CRect curRect = mRect; + int curY = mRect.top; -/*static*/ const AFX_MSGMAP T2ToolHelpWnd::messageMap { + if (mHeader != "") { + curRect.top = curY; + curY += pDC->DrawText(mHeader, curRect, DT_CENTER); + curY += 5; + pDC->MoveTo(curRect.left + 15, curY); + pDC->LineTo(curRect.right - 15, curY); + curY += 5; + } + + if (mText != "") { + curRect.top = curY; + curY += pDC->DrawText(mText, curRect, DT_WORDBREAK | DT_NOPREFIX); + + if (mComment != "") { + curY += 5; + pDC->MoveTo(curRect.left + 15, curY); + pDC->LineTo(curRect.right - 15, curY); + curY += 5; + } + } + + if (mComment != "") { + curRect.top = curY; + curY += pDC->DrawText(mComment, curRect, DT_WORDBREAK | DT_NOPREFIX); + } + + pDC->RestoreDC(saved); + return true; } -/*static*/ const AFX_MSGMAP_ENTRY* const T2ToolHelpWnd::_messageEntries { +void T2ToolHelpWnd::OnDestroy() { + CFrameWnd::OnDestroy(); } diff --git a/src/T2DLL/T2ToolHelpWnd.h b/src/T2DLL/T2ToolHelpWnd.h index 13e95fa..c598b2d 100644 --- a/src/T2DLL/T2ToolHelpWnd.h +++ b/src/T2DLL/T2ToolHelpWnd.h @@ -1,28 +1,31 @@ #pragma once #include "common.h" -class T2ToolHelpWnd { -public: - static CObject* __stdcall CreateObject(); -protected: - static CRuntimeClass* __stdcall _GetBaseClass(); +enum { + kToolHelpMode0 = 0, + kToolHelpMode1 = 1, + kToolHelpMode2 = 2 +}; + +class AFX_EXT_CLASS T2ToolHelpWnd : public CFrameWnd { + DECLARE_DYNCREATE(T2ToolHelpWnd) + DECLARE_MESSAGE_MAP() public: - virtual CRuntimeClass* GetRuntimeClass() const; T2ToolHelpWnd(); virtual ~T2ToolHelpWnd(); -protected: - static const AFX_MSGMAP* __stdcall _GetBaseMessageMap(); - virtual const AFX_MSGMAP* GetMessageMap() const; -public: - void OpenToolHelp(POINT&, int, const char*, const char*, T2ToolDef*, int); + void OpenToolHelp(POINT& inPt, int inMode, const char* inStr1, const char* inStr2, T2ToolDef* inToolDef, int inValiation); void CloseToolHelp(); + protected: - int OnEraseBkgnd(CDC*); - void OnDestroy(); -public: - static const CRuntimeClass classT2ToolHelpWnd; -protected: - static const AFX_MSGMAP messageMap; -private: - static const AFX_MSGMAP_ENTRY* const _messageEntries; + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnDestroy(); + + CFont mFont; + CString mWndClass; + CRect mRect; + CRgn mRgn; + BOOL mVisible; + CString mHeader; + CString mText; + CString mComment; }; diff --git a/src/T2DLL/T2ToolPlugin.h b/src/T2DLL/T2ToolPlugin.h index 7689081..c1fc7b8 100644 --- a/src/T2DLL/T2ToolPlugin.h +++ b/src/T2DLL/T2ToolPlugin.h @@ -2,7 +2,7 @@ #include "common.h" #include "CProgramPlugin.h" -class T2ToolPlugin : public CProgramPlugin { +class AFX_EXT_CLASS T2ToolPlugin : public CProgramPlugin { public: T2ToolPlugin(DWORD type, T2PluginSpecifier& specifier); virtual ~T2ToolPlugin(); diff --git a/src/T2DLL/T2ToolWindow.cpp b/src/T2DLL/T2ToolWindow.cpp index 3601077..08ade6c 100644 --- a/src/T2DLL/T2ToolWindow.cpp +++ b/src/T2DLL/T2ToolWindow.cpp @@ -1,102 +1,440 @@ +#include "CT2App.h" +#include "GlobalFunc.h" +#include "T2ImageObj.h" +#include "T2MainWindow.h" +#include "T2TemplatePluginList.h" +#include "T2ToolDef.h" #include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" -/*static*/ CObject* __stdcall T2ToolWindow::CreateObject() { +CObject* PASCAL T2ToolWindow::CreateObject() { +#line 16 + return DEBUG_NEW T2ToolWindow; } +IMPLEMENT_DYNAMIC(T2ToolWindow, CFrameWnd); -/*static*/ CRuntimeClass* __stdcall T2ToolWindow::_GetBaseClass() { -} +T2ToolWindow::T2ToolWindow() { +#line 20 + mToolIconList = DEBUG_NEW T2ToolIconList; -/*virtual*/ CRuntimeClass* T2ToolWindow::GetRuntimeClass() const { -} + mDocument = NULL; + mWorldDef = NULL; + mSel = -1; + mListCtrl = NULL; + mTimerID = 0; -T2ToolWindow::T2ToolWindow() { + for (int i = 0; i < 16; i++) + _D8[i] = NULL; + + _118 = 1; } /*virtual*/ T2ToolWindow::~T2ToolWindow() { + delete mToolIconList; } -/*virtual*/ void T2ToolWindow::SetDocument(T2TowerDoc*) { +/*virtual*/ void T2ToolWindow::SetDocument(T2TowerDoc* inDoc) { + mDocument = inDoc; + mWorldDef = inDoc->mWorldDef; } -/*static*/ const AFX_MSGMAP* __stdcall T2ToolWindow::_GetBaseMessageMap() { -} +BEGIN_MESSAGE_MAP(T2ToolWindow, CFrameWnd) + ON_WM_QUERYNEWPALETTE() + ON_WM_ERASEBKGND() + ON_WM_CREATE() + ON_WM_LBUTTONDOWN() + ON_WM_LBUTTONUP() + ON_WM_MOUSEMOVE() + ON_WM_LBUTTONDBLCLK() + ON_WM_TIMER() + ON_WM_DESTROY() + ON_WM_CLOSE() +END_MESSAGE_MAP() -/*virtual*/ const AFX_MSGMAP* T2ToolWindow::GetMessageMap() const { -} +afx_msg BOOL T2ToolWindow::OnQueryNewPalette() { + if (!mDocument || !mDocument->mWorldDef) + return CFrameWnd::OnQueryNewPalette(); -int T2ToolWindow::OnQueryNewPalette() { + CDC *pDC = GetDC(); + pDC->SaveDC(); + pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false); + pDC->RealizePalette(); + pDC->RestoreDC(-1); + ReleaseDC(pDC); + return true; } -int T2ToolWindow::OnCreate(CREATESTRUCTA*) { +afx_msg int T2ToolWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { + if (CFrameWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + return OnCreateProc(lpCreateStruct); } /*virtual*/ int T2ToolWindow::GetSel() { + return mSel; } -/*virtual*/ void T2ToolWindow::SetSel(int) { +/*virtual*/ void T2ToolWindow::SetSel(int inID) { + if (SearchID(inID)) + SelChange(inID); } -/*virtual*/ CString* T2ToolWindow::GetIconName(int) { +/*virtual*/ CString* T2ToolWindow::GetIconName(int inID) { + static CString defaultName = ""; + + POSITION pos = SearchID(inID); + if (!pos) + return &defaultName; + + return &mToolIconList->GetAt(pos)->mName; } -/*virtual*/ T2TemplatePlugin* T2ToolWindow::GetIconPlugin(int) { +/*virtual*/ T2TemplatePlugin* T2ToolWindow::GetIconPlugin(int inID) { + POSITION pos = SearchID(inID); + if (!pos) + return NULL; + + return mToolIconList->GetAt(pos)->mPlugin; } -/*virtual*/ unsigned long T2ToolWindow::GetIconOption(int) { +/*virtual*/ DWORD T2ToolWindow::GetIconOption(int inID) { + POSITION pos = SearchID(inID); + if (!pos) + return 0; + + return mToolIconList->GetAt(pos)->mOption; } -/*virtual*/ unsigned int T2ToolWindow::GetIconValiation(int) { +/*virtual*/ unsigned int T2ToolWindow::GetIconValiation(int inID) { + POSITION pos = SearchID(inID); + if (!pos) + return 0; + + return mToolIconList->GetAt(pos)->mValiation; } -/*virtual*/ void T2ToolWindow::AddIcon(const char*, char*, unsigned int, unsigned long, T2ToolDef*, int, unsigned short, T2ToolCallback*) { +/*virtual*/ void T2ToolWindow::AddIcon(const char* inName, char* inStr2, unsigned int inValiation, DWORD inOption, T2ToolDef* inToolDef, int inFld18, unsigned short inSomeMask, T2ToolCallback* inToolCallback) { + T2ToolIconItem *theToolIconItem; + POSITION position = mToolIconList->GetHeadPosition(); + while (position) { + theToolIconItem = mToolIconList->GetNext(position); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) + return; + } + +#line 145 + T2ToolIconItem *theItem = DEBUG_NEW T2ToolIconItem; + theItem->mID = AssignNewID(); + theItem->mName = inName; + theItem->mValiation = inValiation; + theItem->mOption = inOption; + theItem->m18 = inFld18; + theItem->m1C = inSomeMask; + theItem->mToolCallback = inToolCallback; + theItem->mToolDef = inToolDef; + + unsigned short mask = 1; + if (mDocument->mViewMode == ViewMode_1) + mask = 2; + + if (inSomeMask & mask) + theItem->m30 = 1; + else + theItem->m30 = 0; + + if (inStr2) + theItem->m2C = inStr2; + + if (RefreshItem(theItem)) { + mToolIconList->AddTail(theItem); + ListUpdated(); + } } -/*virtual*/ void T2ToolWindow::AddIcon(const char*, unsigned short, char*, T2ToolCallback*) { +/*virtual*/ void T2ToolWindow::AddIcon(const char* inName, unsigned short inSomeMask, char* inStr2, T2ToolCallback* inToolCallback) { + AddIcon(inName, inStr2, 0, 0, NULL, 0, inSomeMask, inToolCallback); } -/*virtual*/ void T2ToolWindow::RemoveIcon(const char*, unsigned int) { +/*virtual*/ void T2ToolWindow::RemoveIcon(const char* inName, unsigned int inValiation) { + T2ToolIconItem *theToolIconItem; + POSITION prevPos; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + prevPos = pos; + theToolIconItem = mToolIconList->GetNext(pos); + + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) { + RemoveItem(prevPos); + mToolIconList->RemoveAt(prevPos); + delete theToolIconItem; + ListUpdated(); + break; + } + } } /*virtual*/ void T2ToolWindow::RemoveAll() { + delete mToolIconList; +#line 204 + mToolIconList = DEBUG_NEW T2ToolIconList; + + ListUpdated(); + SelChange(1); } -/*virtual*/ int T2ToolWindow::GetID(const char*, unsigned int) { +/*virtual*/ int T2ToolWindow::GetID(const char* inName, unsigned int inValiation) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) + return theToolIconItem->mID; + } + + return -1; } -/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(const char*, unsigned int) { +/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(const char* inName, unsigned int inValiation) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) + return theToolIconItem; + } + + return NULL; } -/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(int) { +/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(int inID) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mID == inID) + return theToolIconItem; + } + + return NULL; } /*virtual*/ void T2ToolWindow::Refresh() { -} + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + while (pos) { + T2ToolIconItem *theToolIconItem = mToolIconList->GetNext(pos); + if (!RefreshItem(theToolIconItem)) { + pos = mToolIconList->GetHeadPosition(); + break; + } + } + } -/*virtual*/ int T2ToolWindow::RefreshItem(T2ToolIconItem*) { + Updated(); } -/*virtual*/ T2TemplatePlugin* T2ToolWindow::SearchPlugin(T2TemplatePluginList*, CString&) { -} +/*virtual*/ BOOL T2ToolWindow::RefreshItem(T2ToolIconItem* inItem) { +#line 269 + _ASSERT(mWorldDef != NULL); + _ASSERT(mDocument != NULL); -/*virtual*/ POSITION T2ToolWindow::SearchID(int) { -} + inItem->mPlugin = NULL; -/*virtual*/ int T2ToolWindow::AssignNewID() { -} + if (mDocument->mTenantTemplates) + inItem->mPlugin = SearchPlugin(mDocument->mTenantTemplates, inItem->mName); -/*virtual*/ void T2ToolWindow::RemoveItem(POSITION) { -} + if (!inItem->mPlugin && mDocument->mMoverTemplates) + inItem->mPlugin = SearchPlugin(mDocument->mMoverTemplates, inItem->mName); -/*virtual*/ void T2ToolWindow::SelChange(int) { + if (!inItem->mPlugin && mDocument->mOuterObjTemplates) + inItem->mPlugin = SearchPlugin(mDocument->mOuterObjTemplates, inItem->mName); + + if (!inItem->mPlugin && mWorldDef->m1D0->FindObject(inItem->mName) != -1) + inItem->mPlugin = mWorldDef; + + if (!inItem->mPlugin) { + POSITION pos = mToolIconList->Find(inItem); + if (pos) { + RemoveItem(pos); + mToolIconList->RemoveAt(pos); + } + delete inItem; + return false; + } + + return true; } -/*virtual*/ int T2ToolWindow::EnableIcon(const char*, unsigned int, int) { +/*virtual*/ T2TemplatePlugin* T2ToolWindow::SearchPlugin(T2TemplatePluginList* inList, CString& inName) { + LArrayIterator iterator(*inList); + T2TemplatePlugin *thePlugin; + + while (iterator.Next(&thePlugin)) { + if (thePlugin->mStr48 == inName) + return thePlugin; + } + + return NULL; } -/*virtual*/ void T2ToolWindow::EnableIcon(int) { +/*virtual*/ POSITION T2ToolWindow::SearchID(int inID) { + T2ToolIconItem *theToolIconItem; + POSITION prevPos; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + prevPos = pos; + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mID == inID) + return prevPos; + } + + return NULL; } -/*virtual*/ T2ToolIconItem* T2ToolWindow::EnableIcon(unsigned short) { +/*virtual*/ int T2ToolWindow::AssignNewID() { + for (int id = 0; id < 10000; id++) { + if (!SearchID(id)) + return id; + } + + return -1; +} + +/*virtual*/ void T2ToolWindow::RemoveItem(POSITION inPos) { +#line 334 + _ASSERT(inPos != NULL); + + T2ToolIconItem *theToolIconItem = mToolIconList->GetAt(inPos); + if (theToolIconItem->mID == mSel) { + theToolIconItem = mToolIconList->GetAt(mToolIconList->GetHeadPosition()); + ListUpdated(); + SelChange(theToolIconItem->mID); + } +} + +/*virtual*/ void T2ToolWindow::SelChange(int inID) { + mSel = inID; + Updated(); +} + +/*virtual*/ BOOL T2ToolWindow::EnableIcon(const char* inName, unsigned int inValiation, BOOL inFlag) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) { + if (inFlag) + theToolIconItem->mEnableCount--; + else + theToolIconItem->mEnableCount++; + RedrawButton(); + return true; + } + } + + return false; +} + +/*virtual*/ void T2ToolWindow::EnableIcon(BOOL inFlag) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (inFlag) { + if (theToolIconItem->mEnableCount) + theToolIconItem->mEnableCount--; + } else { + theToolIconItem->mEnableCount++; + } + } + + RedrawButton(); +} + +/*virtual*/ T2ToolIconItem* T2ToolWindow::EnableIcon(unsigned short inMask) { + T2ToolIconItem *theToolIconItem; + T2ToolIconItem *oldSelectedItem = NULL; + T2ToolIconItem *selectedItem = NULL; + + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + unsigned int flag = 0; + if (theToolIconItem->m1C & inMask) + flag = 1; + theToolIconItem->m30 = flag; + + if (theToolIconItem->m24) { + if (theToolIconItem->mOption == 4 || theToolIconItem->mOption == 0) { + _D8[_118] = theToolIconItem; + if (!flag) + oldSelectedItem = theToolIconItem; + } + } + } + + for (unsigned short what = 1; what < 16; what++) { + if ((what & inMask) && _D8[what]) { + theToolIconItem = _D8[what]; + if (theToolIconItem->mOption == 4 || theToolIconItem->mOption == 0) { + if (theToolIconItem->m30 && !theToolIconItem->m18) { + theToolIconItem->m24 = true; + selectedItem = theToolIconItem; + if (oldSelectedItem) { + oldSelectedItem->m24 = false; + oldSelectedItem = NULL; + } + } + } + } + } + + if (oldSelectedItem && oldSelectedItem->mOption == 4) { + pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + if (theToolIconItem->m30 && theToolIconItem->mOption == 4 && !theToolIconItem->m18) { + theToolIconItem->m24 = true; + selectedItem = theToolIconItem; + oldSelectedItem->m24 = false; + oldSelectedItem = NULL; + break; + } + } + } + + if (oldSelectedItem) { + pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + if (theToolIconItem->m30 && theToolIconItem->mOption == 0) { + theToolIconItem->m24 = true; + selectedItem = theToolIconItem; + oldSelectedItem->m24 = false; + oldSelectedItem = NULL; + break; + } + } + } + + if (selectedItem) + SelChange(selectedItem->mID); + + RedrawButton(); + Updated(); + _118 = inMask & 0xF; + + return selectedItem; } /*virtual*/ void T2ToolWindow::RedrawButton() { @@ -106,85 +444,211 @@ int T2ToolWindow::OnCreate(CREATESTRUCTA*) { } /*virtual*/ void T2ToolWindow::ListUpdated() { + if (mListCtrl) { + mListCtrl->DeleteAllItems(); + + POSITION pos = mToolIconList->GetHeadPosition(); + T2ToolIconItem *theToolIconItem; + int row = 0; + CString text; + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + mListCtrl->InsertItem(row, theToolIconItem->mName); + + text.Format("%d", theToolIconItem->mValiation); + mListCtrl->SetItemText(row, 1, text); + + text.Format("%d", theToolIconItem->mID); + mListCtrl->SetItemText(row, 2, text); + + mListCtrl->SetItemText(row, 3, theToolIconItem->mPlugin->mStr48); + + mListCtrl->SetItemData(row, (DWORD) theToolIconItem->mID); + + row++; + } + } } -void T2ToolWindow::StartTimer(unsigned int) { +void T2ToolWindow::StartTimer(UINT inDelay) { + if (mTimerID) + KillTimer(mTimerID); + + mTimerID = SetTimer(1, inDelay, NULL); } void T2ToolWindow::StopTimer() { -} + if (mTimerID) + KillTimer(mTimerID); -int T2ToolWindow::OnEraseBkgnd(CDC*) { + mTimerID = 0; } -void T2ToolWindow::OnLButtonDown(unsigned int, CPoint) { +afx_msg BOOL T2ToolWindow::OnEraseBkgnd(CDC* pDC) { + return OnEraseBkgndProc(pDC); } -void T2ToolWindow::OnLButtonUp(unsigned int, CPoint) { +afx_msg void T2ToolWindow::OnLButtonDown(UINT nFlags, CPoint point) { + OnLButtonDownProc(nFlags, point); } -void T2ToolWindow::OnMouseMove(unsigned int, CPoint) { +afx_msg void T2ToolWindow::OnLButtonUp(UINT nFlags, CPoint point) { + OnLButtonUpProc(nFlags, point); } -void T2ToolWindow::OnLButtonDblClk(unsigned int, CPoint) { -} +afx_msg void T2ToolWindow::OnMouseMove(UINT nFlags, CPoint point) { + CWinApp *theApp = AfxGetApp(); + HCURSOR cursor = theApp->LoadStandardCursor(IDC_ARROW); + if (cursor) + SetCursor(cursor); -void T2ToolWindow::OnTimer(unsigned int) { + OnMouseMoveProc(nFlags, point); } -void T2ToolWindow::OnSize(unsigned int, int, int) { +afx_msg void T2ToolWindow::OnLButtonDblClk(UINT nFlags, CPoint point) { + OnLButtonDblClkProc(nFlags, point); } -void T2ToolWindow::OnDestroy() { -} +afx_msg void T2ToolWindow::OnTimer(UINT nIDEvent) { + if (nIDEvent == 1) + OnTimerProc(nIDEvent); -/*virtual*/ int T2ToolWindow::OnCreateProc(CREATESTRUCTA*) { + CWnd::OnTimer(nIDEvent); } -/*virtual*/ int T2ToolWindow::OnEraseBkgndProc(CDC*) { +afx_msg void T2ToolWindow::OnSize(UINT nType, int cx, int cy) { + OnSizeProc(nType, cx, cy); + ListUpdated(); } -/*virtual*/ void T2ToolWindow::OnLButtonDownProc(unsigned int, CPoint) { +afx_msg void T2ToolWindow::OnDestroy() { + StopTimer(); + + if (mListCtrl) { + mListCtrl->DestroyWindow(); + delete mListCtrl; + } + + if (gT2App->mMainWindow) + gT2App->mMainWindow->mToolWindow = NULL; + + CFrameWnd::OnDestroy(); } -/*virtual*/ void T2ToolWindow::OnLButtonUpProc(unsigned int, CPoint) { +/*virtual*/ int T2ToolWindow::OnCreateProc(LPCREATESTRUCT lpCreateStruct) { + CRect listArea; + listArea.SetRect(0, 0, 300, 400); + + CRect windowArea, clientArea; + GetWindowRect(windowArea); + GetClientRect(clientArea); + + SetWindowPos( + NULL, + 0, + 100, + listArea.Width() + windowArea.Width() - clientArea.Width(), + listArea.Height() + windowArea.Height() - clientArea.Height(), + SWP_NOZORDER + ); + +#line 615 + mListCtrl = DEBUG_NEW CListCtrl; + + mListCtrl->Create( + LVS_REPORT | LVS_SINGLESEL | WS_VSCROLL | WS_VISIBLE | WS_CHILD, + listArea, + this, + 100 + ); + + mListCtrl->InsertColumn(0, "Name", LVCFMT_LEFT, 100); + mListCtrl->InsertColumn(1, "Val", LVCFMT_LEFT, 40); + mListCtrl->InsertColumn(2, "ID", LVCFMT_LEFT, 40); + mListCtrl->InsertColumn(3, "Plugin", LVCFMT_LEFT, 120); + + Updated(); + + return 0; } -/*virtual*/ void T2ToolWindow::OnMouseMoveProc(unsigned int, CPoint) { +/*virtual*/ BOOL T2ToolWindow::OnEraseBkgndProc(CDC* pDC) { + return CFrameWnd::OnEraseBkgnd(pDC); } -/*virtual*/ void T2ToolWindow::OnLButtonDblClkProc(unsigned int, CPoint) { +/*virtual*/ void T2ToolWindow::OnLButtonDownProc(UINT nFlags, CPoint point) { + CWnd::OnLButtonDown(nFlags, point); } -/*virtual*/ void T2ToolWindow::OnTimerProc(unsigned int) { +/*virtual*/ void T2ToolWindow::OnLButtonUpProc(UINT nFlags, CPoint point) { + CWnd::OnLButtonUp(nFlags, point); } -/*virtual*/ void T2ToolWindow::OnSizeProc(unsigned int, int, int) { +/*virtual*/ void T2ToolWindow::OnMouseMoveProc(UINT nFlags, CPoint point) { + CWnd::OnMouseMove(nFlags, point); } -void T2ToolWindow::OnClose() { +/*virtual*/ void T2ToolWindow::OnLButtonDblClkProc(UINT nFlags, CPoint point) { + CWnd::OnLButtonDblClk(nFlags, point); } -/*virtual*/ int T2ToolWindow::OnNotify(unsigned int, long, long*) { +/*virtual*/ void T2ToolWindow::OnTimerProc(UINT nIDEvent) { } -/*static*/ const CRuntimeClass T2ToolWindow::classT2ToolWindow { +/*virtual*/ void T2ToolWindow::OnSizeProc(UINT nType, int cx, int cy) { } -/*static*/ const AFX_MSGMAP T2ToolWindow::messageMap { +afx_msg void T2ToolWindow::OnClose() { + if (!mDocument) + return; + + mDocument->towerDoc_vf198(2); } -/*static*/ const AFX_MSGMAP_ENTRY* const T2ToolWindow::_messageEntries { +/*virtual*/ BOOL T2ToolWindow::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { + if (wParam == 100 && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && mListCtrl->GetSelectedCount() == 1) { + int row, count; + + count = mListCtrl->GetItemCount(); + for (row = 0; row < count; row++) { + if (mListCtrl->GetItemState(row, LVIS_SELECTED)) + break; + } + + SelChange(row); + } + + return CWnd::OnNotify(wParam, lParam, pResult); } + + T2ToolIconItem::T2ToolIconItem() { + mPlugin = NULL; + mName = ""; + mValiation = 0; + mOption = 0; + mID = -1; + m24 = false; + mEnableCount = 0; + m30 = 1; } /*virtual*/ T2ToolIconItem::~T2ToolIconItem() { } + + T2ToolIconList::T2ToolIconList() { } /*virtual*/ T2ToolIconList::~T2ToolIconList() { + T2ToolIconItem *theToolIconItem; + POSITION pos = GetHeadPosition(); + while (pos) { + theToolIconItem = GetNext(pos); + delete theToolIconItem; + } } diff --git a/src/T2DLL/T2ToolWindow.h b/src/T2DLL/T2ToolWindow.h index 85c9bc8..b90aa6c 100644 --- a/src/T2DLL/T2ToolWindow.h +++ b/src/T2DLL/T2ToolWindow.h @@ -1,91 +1,99 @@ #pragma once #include "common.h" -class T2ToolWindow { -public: - static CObject* __stdcall CreateObject(); -protected: - static CRuntimeClass* __stdcall _GetBaseClass(); +class T2ToolIconItem; + +class AFX_EXT_CLASS T2ToolWindow : public CFrameWnd { + DECLARE_DYNCREATE(T2ToolWindow) + DECLARE_MESSAGE_MAP() public: - virtual CRuntimeClass* GetRuntimeClass() const; T2ToolWindow(); virtual ~T2ToolWindow(); - virtual void SetDocument(T2TowerDoc*); -protected: - static const AFX_MSGMAP* __stdcall _GetBaseMessageMap(); - virtual const AFX_MSGMAP* GetMessageMap() const; - int OnQueryNewPalette(); - int OnCreate(CREATESTRUCTA*); -public: + virtual void SetDocument(T2TowerDoc* inDoc); virtual int GetSel(); - virtual void SetSel(int); - virtual CString* GetIconName(int); - virtual T2TemplatePlugin* GetIconPlugin(int); - virtual unsigned long GetIconOption(int); - virtual unsigned int GetIconValiation(int); - virtual void AddIcon(const char*, char*, unsigned int, unsigned long, T2ToolDef*, int, unsigned short, T2ToolCallback*); - virtual void AddIcon(const char*, unsigned short, char*, T2ToolCallback*); - virtual void RemoveIcon(const char*, unsigned int); + virtual void SetSel(int inID); + virtual CString* GetIconName(int inID); + virtual T2TemplatePlugin* GetIconPlugin(int inID); + virtual DWORD GetIconOption(int inID); + virtual unsigned int GetIconValiation(int inID); + virtual void AddIcon(const char* inName, char* inStr2, unsigned int inValiation, DWORD inOption, T2ToolDef* inToolDef, int inFld18, unsigned short inSomeMask, T2ToolCallback* inToolCallback); + virtual void AddIcon(const char* inName, unsigned short inSomeMask, char* inStr2, T2ToolCallback* inToolCallback); + virtual void RemoveIcon(const char* inName, unsigned int inValiation); virtual void RemoveAll(); - virtual int GetID(const char*, unsigned int); - virtual T2ToolIconItem* GetItem(const char*, unsigned int); - virtual T2ToolIconItem* GetItem(int); virtual void Refresh(); + virtual int GetID(const char* inName, unsigned int inValiation); + virtual T2ToolIconItem* GetItem(const char* inName, unsigned int inValiation); + virtual T2ToolIconItem* GetItem(int inID); + virtual BOOL EnableIcon(const char* inName, unsigned int inValiation, BOOL inFlag); + virtual void EnableIcon(BOOL inFlag); + virtual T2ToolIconItem* EnableIcon(unsigned short inMask); + virtual BOOL OnEraseBkgndProc(CDC* pDC); + virtual int OnCreateProc(LPCREATESTRUCT lpCreateStruct); + virtual void OnLButtonDownProc(UINT nFlags, CPoint point); + virtual void OnLButtonUpProc(UINT nFlags, CPoint point); + virtual void OnMouseMoveProc(UINT nFlags, CPoint point); + virtual void OnLButtonDblClkProc(UINT nFlags, CPoint point); + virtual void OnTimerProc(UINT nIDEvent); + virtual void OnSizeProc(UINT nType, int cx, int cy); + void StartTimer(UINT inDelay); + void StopTimer(); + protected: - virtual int RefreshItem(T2ToolIconItem*); - virtual T2TemplatePlugin* SearchPlugin(T2TemplatePluginList*, CString&); - virtual POSITION SearchID(int); + virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); + virtual BOOL RefreshItem(T2ToolIconItem* inItem); + virtual T2TemplatePlugin* SearchPlugin(T2TemplatePluginList* inList, CString& inName); + virtual POSITION SearchID(int inID); virtual int AssignNewID(); - virtual void RemoveItem(POSITION); - virtual void SelChange(int); -public: - virtual int EnableIcon(const char*, unsigned int, int); - virtual void EnableIcon(int); - virtual T2ToolIconItem* EnableIcon(unsigned short); -protected: - virtual void RedrawButton(); + virtual void RemoveItem(POSITION inPos); + virtual void SelChange(int inID); virtual void Updated(); virtual void ListUpdated(); -public: - void StartTimer(unsigned int); - void StopTimer(); -protected: - int OnEraseBkgnd(CDC*); - void OnLButtonDown(unsigned int, CPoint); - void OnLButtonUp(unsigned int, CPoint); - void OnMouseMove(unsigned int, CPoint); - void OnLButtonDblClk(unsigned int, CPoint); - void OnTimer(unsigned int); - void OnSize(unsigned int, int, int); - void OnDestroy(); -public: - virtual int OnCreateProc(CREATESTRUCTA*); - virtual int OnEraseBkgndProc(CDC*); - virtual void OnLButtonDownProc(unsigned int, CPoint); - virtual void OnLButtonUpProc(unsigned int, CPoint); - virtual void OnMouseMoveProc(unsigned int, CPoint); - virtual void OnLButtonDblClkProc(unsigned int, CPoint); - virtual void OnTimerProc(unsigned int); - virtual void OnSizeProc(unsigned int, int, int); -protected: - void OnClose(); - virtual int OnNotify(unsigned int, long, long*); -public: - static const CRuntimeClass classT2ToolWindow; -protected: - static const AFX_MSGMAP messageMap; -private: - static const AFX_MSGMAP_ENTRY* const _messageEntries; + virtual void RedrawButton(); + + afx_msg BOOL OnQueryNewPalette(); + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnLButtonDown(UINT nFlags, CPoint point); + afx_msg void OnLButtonUp(UINT nFlags, CPoint point); + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); + afx_msg void OnTimer(UINT nIDEvent); + afx_msg void OnSize(UINT nType, int cx, int cy); + afx_msg void OnDestroy(); + afx_msg void OnClose(); + + int _C0; + T2TowerDoc *mDocument; + T2WorldDef *mWorldDef; + T2ToolIconList *mToolIconList; + int mSel; + UINT mTimerID; + T2ToolIconItem *_D8[16]; + unsigned short _118; + CListCtrl *mListCtrl; }; -class T2ToolIconItem { + +class AFX_EXT_CLASS T2ToolIconItem { public: T2ToolIconItem(); virtual ~T2ToolIconItem(); - T2ToolIconItem(const T2ToolIconItem&) {} - T2ToolIconItem& operator=(const T2ToolIconItem&) {} + int mID; + T2TemplatePlugin *mPlugin; + CString mName; + unsigned int mValiation; + DWORD mOption; + int m18; + unsigned short m1C; + T2ToolCallback *mToolCallback; + BOOL m24; + int mEnableCount; + CString m2C; + unsigned int m30; + T2ToolDef *mToolDef; }; -class T2ToolIconList { + +class AFX_EXT_CLASS T2ToolIconList : public CList<T2ToolIconItem *, T2ToolIconItem *> { public: T2ToolIconList(); virtual ~T2ToolIconList(); diff --git a/src/T2DLL/T2TowerEvent.cpp b/src/T2DLL/T2TowerEvent.cpp index 57882f2..84dc878 100644 --- a/src/T2DLL/T2TowerEvent.cpp +++ b/src/T2DLL/T2TowerEvent.cpp @@ -1,79 +1,507 @@ +#include "CProgramPlugin.h" +#include "CResFile.h" +#include "T2Archive.h" +#include "T2BlackOut.h" +#include "T2DateTime.h" +#include "T2FireBurning.h" +#include "T2ImageObj.h" +#include "T2Maru_Reggae.h" +#include "T2MetroRailway.h" +#include "T2OutDecoration.h" +#include "T2SantaClaus.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" +#include "T2Terrorist.h" +#include "T2TowerDoc.h" #include "T2TowerEvent.h" +#include "T2TowerVision.h" +#include "T2VisitVIP.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" -T2TowerEvent::T2TowerEvent(T2WorldDef*) { +T2TowerEvent::T2TowerEvent(T2WorldDef* inWorldDef) { + mWorldDef = inWorldDef; + mDocument = NULL; + _8 = 1441; + mLevel = 0; + + mFireBurning = NULL; + mMetroRailway = NULL; + mBlackOut = NULL; + mSantaClaus = NULL; + mTowerVision = NULL; + mOutDecoration = NULL; + + _88 = 0; + mLatestBuild = NULL; + + CResFile resFile; + T2EventItem *theEvent; + + if (resFile.OpenResource(inWorldDef->mModuleHandle, 1, 'T2Ev')) { + int numEvent; + resFile >> numEvent; + + DWORD theEventID; + int theEventSubID; + + for (int i = 0; i < numEvent; i++) { + resFile >> theEventID; + resFile >> theEventSubID; + + CResFile subResFile; + if (subResFile.OpenResource(inWorldDef->mModuleHandle, theEventSubID, theEventID)) { + switch (theEventID) { + case 'FBEv': + theEvent = new T2FireBurning(this, &subResFile, theEventSubID); + mFireBurning = (T2FireBurning *) theEvent; + break; + case 'TrEv': + theEvent = new T2Terrorist(this, &subResFile, theEventSubID); + break; + case 'ViEv': + theEvent = new T2VisitVIP(this, &subResFile, theEventSubID); + break; + case 'BOEv': + theEvent = new T2BlackOut(this, &subResFile, theEventSubID); + mBlackOut = (T2BlackOut *) theEvent; + break; + case 'SaEv': + theEvent = new T2SantaClaus(this, &subResFile, theEventSubID); + mSantaClaus = (T2SantaClaus *) theEvent; + break; + case 'MREv': + theEvent = new T2MetroRailway(this, &subResFile, theEventSubID); + mMetroRailway = (T2MetroRailway *) theEvent; + break; + case 'OdEv': + theEvent = new T2OutDecoration(this, &subResFile, theEventSubID); + mOutDecoration = (T2OutDecoration *) theEvent; + break; + case 'MaEv': + theEvent = new T2Maru_Reggae(this, &subResFile, theEventSubID); + break; + default: + theEvent = inWorldDef->MakeXEvent(this, &subResFile, theEventID, theEventSubID); + break; + } + + if (theEvent) { + mStandby.Add(&theEvent); + } else { + CString str; + str.Format("EVENT ITEM %c%c%c%c Undefined!\n", + ((char *) &theEventID)[3], + ((char *) &theEventID)[2], + ((char *) &theEventID)[1], + ((char *) &theEventID)[0] + ); + OutputDebugString(str); + } + } + } + } } T2TowerEvent::~T2TowerEvent() { + T2EventItem *theEvent; + + while (mStandby.FetchItemAt(1, &theEvent)) { + mStandby.RemoveItemsAt(1, 1); + delete theEvent; + } + while (mWaiting.FetchItemAt(1, &theEvent)) { + mWaiting.RemoveItemsAt(1, 1); + delete theEvent; + } + while (mRunning.FetchItemAt(1, &theEvent)) { + mRunning.RemoveItemsAt(1, 1); + delete theEvent; + } } -void T2TowerEvent::InitTowerEvent(T2TowerDoc*) { +void T2TowerEvent::InitTowerEvent(T2TowerDoc* inDoc) { + mDocument = inDoc; } T2FireBurning* T2TowerEvent::GetFireBurning() { + return mFireBurning; } T2MetroRailway* T2TowerEvent::GetMetroRailway() { + return mMetroRailway; } T2BlackOut* T2TowerEvent::GetBlackOut() { + return mBlackOut; } T2TowerVision* T2TowerEvent::GetTowerVision() { + return mTowerVision; } T2Transport* T2TowerEvent::GetCruise() { + return mWorldDef->GetCruise(this); } -int T2TowerEvent::IsBlackOut() { +BOOL T2TowerEvent::IsBlackOut() { + return mBlackOut ? mBlackOut->IsBlackOut() : false; } -void T2TowerEvent::SetLatestBuild(T2Equip*, T2ToolDef*, int) { +void T2TowerEvent::SetLatestBuild(T2Equip* inEquip, T2ToolDef* inToolDef, BOOL inFlag) { + CProgramPlugin *thePlugin = inToolDef ? inToolDef->GetPlugin() : NULL; + + if (mBlackOut) { + int consumptionPower = inToolDef ? inToolDef->GetConsumptionPower(0) : 0; + if (thePlugin) { + BOOL isHEND = (thePlugin->GetID() == 'HEND'); + if (inFlag) { + if (isHEND) + mBlackOut->AddSupplyPower(1); + mBlackOut->AddConsumptionPower(consumptionPower); + } else { + if (isHEND) + mBlackOut->SubSupplyPower(); + mBlackOut->SubConsumptionPower(consumptionPower); + } + } + } + + mLatestBuild = (inFlag && inToolDef && inToolDef->IsTenant()) ? inEquip : NULL; + + if (mOutDecoration && inEquip && inToolDef && inToolDef->IsTenant()) { + if (inFlag) + mOutDecoration->CheckRoofTop(inEquip); + else if (((T2TenantDef *) inToolDef)->IsFloor()) + mOutDecoration->CheckRoofTop(NULL); + } } T2Equip* T2TowerEvent::GetLatestBuild() { + return mLatestBuild; } -void T2TowerEvent::AppendStandby(T2EventItem*) { +void T2TowerEvent::AppendStandby(T2EventItem* inEventItem) { + mStandby.Add(&inEventItem); } -void T2TowerEvent::InsertExecute(T2EventItem*) { +void T2TowerEvent::InsertExecute(T2EventItem* inEventItem) { + if (inEventItem->IsExclusive()) + mRunning.InsertItemsAt(1, 1, &inEventItem); + else + mRunning.Add(&inEventItem); } -void T2TowerEvent::MakeTowerVisionEvent(T2OutObj*) { +void T2TowerEvent::MakeTowerVisionEvent(T2OutObj* inOutObj) { + if (!mTowerVision) { + mTowerVision = new T2TowerVision(this, 0, 0xFF, false, 1, 0, 1440, inOutObj); + if (mTowerVision) + mRunning.Add(&mTowerVision); + } } void T2TowerEvent::KillTowerVisionEvent() { + if (mTowerVision) { + mRunning.Remove(&mTowerVision); + delete mTowerVision; + mTowerVision = NULL; + } } -T2EventItem* T2TowerEvent::MakeXEvent(unsigned long) { +T2EventItem* T2TowerEvent::MakeXEvent(DWORD inID) { + T2EventItem *theEvent = NULL; + + CResFile theResFile; + if (theResFile.OpenResource(mWorldDef->mModuleHandle, 128, inID)) { + theEvent = mWorldDef->MakeXEvent(this, &theResFile, inID, 128); + StoreWaitSequence(theEvent); + } + + return theEvent; } -void T2TowerEvent::KillXEvent(unsigned long) { +void T2TowerEvent::KillXEvent(DWORD inID) { + T2EventItem *theEvent; + + LArrayIterator eventIteratorRunning(mRunning); + while (eventIteratorRunning.Next(&theEvent)) { + if (theEvent->GetID() == inID) { + mRunning.RemoveItemsAt(1, eventIteratorRunning.GetCurrentIndex()); + delete theEvent; + eventIteratorRunning.Reset(); + } + } + + LArrayIterator eventIteratorStandby(mStandby); + while (eventIteratorStandby.Next(&theEvent)) { + if (theEvent->GetID() == inID) { + mStandby.RemoveItemsAt(1, eventIteratorStandby.GetCurrentIndex()); + delete theEvent; + eventIteratorStandby.Reset(); + } + } + + LArrayIterator eventIteratorWaiting(mWaiting); + while (eventIteratorWaiting.Next(&theEvent)) { + if (theEvent->GetID() == inID) { + mWaiting.RemoveItemsAt(1, eventIteratorWaiting.GetCurrentIndex()); + delete theEvent; + eventIteratorWaiting.Reset(); + } + } } -T2EventItem* T2TowerEvent::GetEvent(unsigned long) { +T2EventItem* T2TowerEvent::GetEvent(DWORD inID) { + T2EventItem *theEvent; + + LArrayIterator eventIteratorRunning(mRunning); + while (eventIteratorRunning.Next(&theEvent)) { + if (theEvent->GetID() == inID) + return theEvent; + } + + LArrayIterator eventIteratorStandby(mStandby); + while (eventIteratorStandby.Next(&theEvent)) { + if (theEvent->GetID() == inID) + return theEvent; + } + + LArrayIterator eventIteratorWaiting(mWaiting); + while (eventIteratorWaiting.Next(&theEvent)) { + if (theEvent->GetID() == inID) + return theEvent; + } + + return NULL; } -unsigned int T2TowerEvent::GetXEvent(unsigned long) { +unsigned int T2TowerEvent::GetXEvent(DWORD inID) { + T2EventItem *theEvent = GetEvent(inID); + return (unsigned int) theEvent; // ??? } void T2TowerEvent::StopEvent() { + T2EventItem *theEvent; + + LArrayIterator iterator(mRunning); + while (iterator.Next(&theEvent)) + theEvent->StopEvent(mDocument); } -int T2TowerEvent::Idle(T2TowerDoc*) { +int T2TowerEvent::Idle(T2TowerDoc* inDoc) { + T2EventItem *theEvent; + T2DateTime *theNow = inDoc->towerDoc_vf120(); + int nowMinutes = theNow->GetRawMinutes(); + + if ((nowMinutes == 0 && _8 != nowMinutes) || mLevel != inDoc->towerDoc_vf138()) { +#pragma var_order(day, eventIteratorWaiting, eventIteratorStandby, theLevelBit) + mLevel = inDoc->towerDoc_vf138(); + unsigned int theLevelBit = (mLevel > 0) ? (1 << (mLevel - 1)) : 0; + int day = theNow->CalcLapseDays(12) + 1; + + LArrayIterator eventIteratorStandby(mStandby); + while (eventIteratorStandby.Next(&theEvent)) { + if (theEvent->_4 || ((theEvent->GetLevelBit() & theLevelBit) && theEvent->IsBeginDay(day))) { + mStandby.Remove(&theEvent); + eventIteratorStandby.Reset(); + StoreWaitSequence(theEvent); + } + } + + LArrayIterator eventIteratorWaiting(mWaiting); + while (eventIteratorWaiting.Next(&theEvent)) { + if (!theEvent->_4 && !(theEvent->GetLevelBit() & theLevelBit)) { + mWaiting.Remove(&theEvent); + eventIteratorWaiting.Reset(); + mStandby.Add(&theEvent); + } + } + } + + LArrayIterator iterator(mRunning); + while (iterator.Next(&theEvent)) { + switch (theEvent->Exec(inDoc)) { + case 1: + _8 = nowMinutes; + return 1; + + case 3: + mRunning.Remove(&theEvent); + iterator.Reset(); + if (nowMinutes <= theEvent->GetBeginTime()) { + unsigned int theLevelBit = (mLevel > 0) ? (1 << (mLevel - 1)) : 0; + int day = theNow->CalcLapseDays(12) + 1; + + if ((theEvent->GetLevelBit() & theLevelBit) && theEvent->IsBeginDay(day)) + StoreWaitSequence(theEvent); + else + mStandby.Add(&theEvent); + } else { + mStandby.Add(&theEvent); + } + break; + } + } + + if (_8 != nowMinutes) { + LArrayIterator eventIteratorWaiting(mWaiting); + while (eventIteratorWaiting.Next(&theEvent)) { + if (theEvent->GetBeginTime() > nowMinutes) + break; + + mWaiting.Remove(&theEvent); + eventIteratorWaiting.Reset(); + + if (theEvent->IsBeginTime(nowMinutes) && theEvent->Start(inDoc)) { + if (theEvent->IsExclusive()) + mRunning.InsertItemsAt(1, 1, &theEvent); + else + mRunning.Add(&theEvent); + } else { + mStandby.Add(&theEvent); + } + } + + _8 = nowMinutes; + } + + return 0; } -void T2TowerEvent::StoreWaitSequence(T2EventItem*) { +void T2TowerEvent::StoreWaitSequence(T2EventItem* inEventItem) { + LArrayIterator iterator(mWaiting); + T2EventItem *theEvent; + + while (iterator.Next(&theEvent)) { + if (inEventItem->GetBeginTime() < theEvent->GetBeginTime()) + break; + } + + if (iterator.GetCurrentIndex() == 0) + mWaiting.Add(&inEventItem); + else + mWaiting.InsertItemsAt(1, iterator.GetCurrentIndex(), &inEventItem); } -void T2TowerEvent::Write(T2Archive&) { +void T2TowerEvent::Write(T2Archive& inArchive) { +#pragma var_order(theEvent, eventIteratorStandby, eventIteratorWaiting, numOfEvent, eventIteratorRunning, isRunning, theEventSubID, theEventID) + int numOfEvent = mStandby.GetCount() + mWaiting.GetCount() + mRunning.GetCount(); + unsigned char isRunning = 0; + + inArchive << _88; + inArchive << (short) numOfEvent; + + T2EventItem *theEvent; + DWORD theEventID; + short theEventSubID; + + LArrayIterator eventIteratorStandby(mStandby); + while (eventIteratorStandby.Next(&theEvent)) { + theEventID = theEvent->GetID(); + theEventSubID = theEvent->GetSubID(); + + inArchive << theEventID; + inArchive << theEventSubID; + inArchive << isRunning; + theEvent->Write(inArchive); + } + + LArrayIterator eventIteratorWaiting(mWaiting); + while (eventIteratorWaiting.Next(&theEvent)) { + theEventID = theEvent->GetID(); + theEventSubID = theEvent->GetSubID(); + + inArchive << theEventID; + inArchive << theEventSubID; + inArchive << isRunning; + theEvent->Write(inArchive); + } + + isRunning = 1; + + LArrayIterator eventIteratorRunning(mRunning); + while (eventIteratorRunning.Next(&theEvent)) { + theEventID = theEvent->GetID(); + theEventSubID = theEvent->GetSubID(); + + inArchive << theEventID; + inArchive << theEventSubID; + inArchive << isRunning; + theEvent->Write(inArchive); + } } -void T2TowerEvent::Read(T2Archive&) { +void T2TowerEvent::Read(T2Archive& inArchive) { + short numOfEvent; + unsigned char isRunning; + T2EventItem *theEvent; + DWORD theEventID; + short theEventSubID; + + LArrayIterator iteratorStandby(mStandby); + + inArchive >> _88; + inArchive >> numOfEvent; + + for (short num = 0; num < numOfEvent; num++) { + inArchive >> theEventID; + inArchive >> theEventSubID; + inArchive >> isRunning; + BOOL eventOK = false; + iteratorStandby.ResetTo(0); + + while (!eventOK && iteratorStandby.Next(&theEvent)) { + if (theEvent->GetID() == theEventID && theEvent->GetSubID() == theEventSubID) { + theEvent->Read(inArchive); + if (isRunning) { + mStandby.RemoveItemsAt(1, iteratorStandby.GetCurrentIndex()); + if (theEvent->ReStart(mDocument)) + mRunning.InsertItemsAt(1, theEvent->IsExclusive() ? 1 : (mRunning.GetCount() + 1), &theEvent); + else + mStandby.InsertItemsAt(1, mRunning.GetCount() + 1, &theEvent); + } + eventOK = true; + } + } + + LArrayIterator iteratorWaiting(mWaiting); + while (!eventOK && iteratorWaiting.Next(&theEvent)) { + if (theEvent->GetID() == theEventID && theEvent->GetSubID() == theEventSubID) { + theEvent->Read(inArchive); + eventOK = true; + } + } + + if (!eventOK) { + unsigned char tmp; + unsigned int len; + inArchive >> len; + for (unsigned int i = 0; i < len; i++) + inArchive >> tmp; + } + } } -void T2TowerEvent::DrawRubble(T2TowerDoc*, T2Tenant*) { +void T2TowerEvent::DrawRubble(T2TowerDoc* inDoc, T2Tenant* inTenant) { + int objectID = inDoc->mWorldDef->mImageObj->FindObject("Rubble"); + if (objectID >= 0) { + CRect rect1, rect2; + + inTenant->GetEquipArea(rect1); + UT2Coordinate::UnitToQD(rect1, rect2, inDoc->towerDoc_vf108(), true); + rect2.bottom = rect2.top + UT2Coordinate::UnitVSize(inDoc->towerDoc_vf108()); + + for (int i = 0; i < rect1.Height(); i++) { + inDoc->mWorldDef->mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect2, inDoc->towerDoc_vf108()); + rect2.OffsetRect(0, UT2Coordinate::UnitVSize(inDoc->towerDoc_vf108())); + } + } } -void T2TowerEvent::ViewModeChanged(T2TowerDoc*, VIEWMODE) { +void T2TowerEvent::ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE inViewMode) { + LArrayIterator iterator(mRunning); + T2EventItem *theEvent; + + while (iterator.Next(&theEvent)) + theEvent->ViewModeChanged(inDoc, inViewMode); } diff --git a/src/T2DLL/T2TowerEvent.h b/src/T2DLL/T2TowerEvent.h index f31c0a8..becce7d 100644 --- a/src/T2DLL/T2TowerEvent.h +++ b/src/T2DLL/T2TowerEvent.h @@ -1,35 +1,50 @@ #pragma once #include "common.h" +#include "LArray.h" -class T2TowerEvent { +class AFX_EXT_CLASS T2TowerEvent { public: - T2TowerEvent(T2WorldDef*); + T2TowerEvent(T2WorldDef* inWorldDef); ~T2TowerEvent(); - void InitTowerEvent(T2TowerDoc*); + void InitTowerEvent(T2TowerDoc* inDoc); T2FireBurning* GetFireBurning(); T2MetroRailway* GetMetroRailway(); T2BlackOut* GetBlackOut(); T2TowerVision* GetTowerVision(); T2Transport* GetCruise(); - int IsBlackOut(); - void SetLatestBuild(T2Equip*, T2ToolDef*, int); + BOOL IsBlackOut(); + void SetLatestBuild(T2Equip* inEquip, T2ToolDef* inToolDef, BOOL inFlag); T2Equip* GetLatestBuild(); - void AppendStandby(T2EventItem*); - void InsertExecute(T2EventItem*); - void MakeTowerVisionEvent(T2OutObj*); + void AppendStandby(T2EventItem* inEventItem); + void InsertExecute(T2EventItem* inEventItem); + void MakeTowerVisionEvent(T2OutObj* inOutObj); void KillTowerVisionEvent(); - T2EventItem* MakeXEvent(unsigned long); - void KillXEvent(unsigned long); - T2EventItem* GetEvent(unsigned long); - unsigned int GetXEvent(unsigned long); + T2EventItem* MakeXEvent(DWORD inID); + void KillXEvent(DWORD inID); + T2EventItem* GetEvent(DWORD inID); + unsigned int GetXEvent(DWORD inID); void StopEvent(); - int Idle(T2TowerDoc*); - void StoreWaitSequence(T2EventItem*); - void Write(T2Archive&); - void Read(T2Archive&); - void DrawRubble(T2TowerDoc*, T2Tenant*); - void ViewModeChanged(T2TowerDoc*, VIEWMODE); + int Idle(T2TowerDoc* inDoc); + void StoreWaitSequence(T2EventItem* inEventItem); + void Write(T2Archive& inArchive); + void Read(T2Archive& inArchive); + void DrawRubble(T2TowerDoc* inDoc, T2Tenant* inTenant); + void ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE inViewMode); - T2TowerEvent(const T2TowerEvent&) {} - T2TowerEvent& operator=(const T2TowerEvent&) {} + T2WorldDef *mWorldDef; + T2TowerDoc *mDocument; + int _8; + int mLevel; + LArray mStandby; + LArray mWaiting; + LArray mRunning; + T2FireBurning *mFireBurning; + T2MetroRailway *mMetroRailway; + T2BlackOut *mBlackOut; + T2SantaClaus *mSantaClaus; + T2TowerVision *mTowerVision; + T2OutDecoration *mOutDecoration; + unsigned int _88; // which VIP bits have been allocated + T2Equip *mLatestBuild; + int _90; }; diff --git a/src/T2DLL/T2TowerMessage.cpp b/src/T2DLL/T2TowerMessage.cpp index 32b7815..0f6e7a7 100644 --- a/src/T2DLL/T2TowerMessage.cpp +++ b/src/T2DLL/T2TowerMessage.cpp @@ -1,61 +1,349 @@ +#include "GlobalFunc.h" +#include "LArray.h" +#include "T2Balloon.h" +#include "T2Equip.h" +#include "T2EquipDef.h" +#include "T2Message.h" +#include "T2People.h" +#include "T2SoundPlayer.h" +#include "T2StewardDialog.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" #include "T2TowerMessage.h" +#include "UT2Coordinate.h" -T2TowerMessage::T2TowerMessage(HINSTANCE, T2TowerDoc*) { +T2TowerMessage::T2TowerMessage(HINSTANCE inModuleHandle, T2TowerDoc* inDoc) { + mDocument = inDoc; + _14 = 0; + mModuleHandle = inModuleHandle; + + mInfoBarMsgItems = new LArray; + mEquipBalloonMessages = new LArray; + mObjectBalloonMessages = new LArray; + + mHasCapture = false; + + inDoc->GetTowerMainView()->AddAttachment(this); } /*virtual*/ T2TowerMessage::~T2TowerMessage() { + T2Balloon *theT2Balloon; + + LArrayIterator iterator1(*mEquipBalloonMessages); + while (iterator1.Next(&theT2Balloon)) { + mEquipBalloonMessages->Remove(&theT2Balloon); + iterator1.Reset(); + } + + LArrayIterator iterator2(*mObjectBalloonMessages); + while (iterator2.Next(&theT2Balloon)) { + mObjectBalloonMessages->Remove(&theT2Balloon); + iterator2.Reset(); + } + + if (mInfoBarMsgItems) { + InfoBarMsgItem *theItem; + while (mInfoBarMsgItems->FetchItemAt(1, &theItem)) { + mInfoBarMsgItems->RemoveItemsAt(1, 1); + delete theItem; + } + + delete mInfoBarMsgItems; + } + + delete mEquipBalloonMessages; + delete mObjectBalloonMessages; } -void T2TowerMessage::InfoBarMessage(const CString&, int, const char*) { +void T2TowerMessage::InfoBarMessage(const CString& inText, int inDelay, const char* inSoundID) { + if (mInfoBarMsgItems && mInfoBarMsgItems->GetCount() < 20) { + InfoBarMsgItem *theMsgItem = new InfoBarMsgItem(inText, (inDelay * 1000) / 60, inSoundID); + int index = mInfoBarMsgItems->GetCount() + 1; + mInfoBarMsgItems->InsertItemsAt(1, index, &theMsgItem); + } } -void T2TowerMessage::SetInfoBarMsg(InfoBarMsgItem*) { +void T2TowerMessage::SetInfoBarMsg(InfoBarMsgItem* inItem) { + CString empty; + CString *theString = inItem ? &inItem->mText : ∅ + mDocument->towerDoc_vf164(*theString); + + if (inItem && inItem->mSoundID != "") + Sounds->Play(inItem->mSoundID, SoundMask_10, SoundFlags_10, NULL, PlayMode_0, 100); + + if (inItem && inItem->mDelay != -1) + inItem->mEndTicks = GetTickCount() + inItem->mDelay; } -void T2TowerMessage::EquipBalloonMessage(const CString&, T2Equip*) { +void T2TowerMessage::EquipBalloonMessage(const CString& inText, T2Equip* inEquip) { + if (inEquip) { + RECT equipArea; + inEquip->GetEquipArea(equipArea); + + CPoint pt; + pt.y = equipArea.top + (equipArea.bottom - equipArea.top) / 2; + pt.x = equipArea.left + (equipArea.right - equipArea.left) / 2; + UT2Coordinate::UnitToQD(pt); + + EquipBalloonMessage(inText, pt); + } } -void T2TowerMessage::PeopleBalloonMessage(const CString&, T2People*) { +void T2TowerMessage::PeopleBalloonMessage(const CString& inText, T2People* inPeople) { + if (inPeople) { + CRect silhouetteArea; + inPeople->CalcWalkingSilhouetteArea(silhouetteArea); + + CPoint pt = silhouetteArea.CenterPoint(); + UT2Coordinate::UnitToQD(pt); + + EquipBalloonMessage(inText, pt); + } } -void T2TowerMessage::EquipBalloonMessage(const CString&, POINT) { +void T2TowerMessage::EquipBalloonMessage(const CString& inText, POINT inPt) { + T2Balloon *theBalloon = new T2Balloon; + theBalloon->Show(inPt.x, inPt.y, inText, false); + mEquipBalloonMessages->Add(&theBalloon); } -void T2TowerMessage::BuildErr(const CString&) { +void T2TowerMessage::BuildErr(const CString& inText) { + POINT otherPt = mDocument->GetTowerMainView()->m7C; + + (new T2Message)->ShowMessage(inText); } -void T2TowerMessage::BuildErr(unsigned int, T2EquipDef*) { +void T2TowerMessage::BuildErr(unsigned int inID, T2EquipDef* inDef) { + CString errString; + + if (GetBuildErrString(inID, errString)) { + if (inDef) { + CString nameString; + inDef->GetToolName(nameString, 0); + errString = nameString + errString; + } + BuildErr(errString); + } } -int T2TowerMessage::GetBuildErrString(unsigned int, CString&) { +BOOL T2TowerMessage::GetBuildErrString(unsigned int inID, CString& outStr) { + BOOL ok = (inID > 0 && inID < 76); + if (ok) + outStr = LoadStringTable(INSTANCE_ANY, 9999, inID); + return ok; } -void T2TowerMessage::ObjectBalloonMessage(const CString&, const RECT&) { +void T2TowerMessage::ObjectBalloonMessage(const CString& inText, const RECT& inRect) { + T2TowerMainView *theView = mDocument->GetTowerMainView(); + + CRect rect = inRect; + UT2Coordinate::UnitToQD(rect, 0, true); + CPoint pt = rect.CenterPoint(); + + T2Balloon *balloon = new T2Balloon; + balloon->Show(pt.x, pt.y, inText, false); + + SetCaptureRect(rect); + mObjectBalloonMessages->Add(&balloon); } -void T2TowerMessage::InfoDialogMessage(const CString&, int, int) { +void T2TowerMessage::InfoDialogMessage(const CString& inText, int inID, int inDelay) { + CWnd *search = CWnd::GetForegroundWindow(); + while (search) { + if (search->ContinueModal()) + break; + search = search->GetNextWindow(); + } + + if (search) { + CWnd *window = search->GetDescendantWindow(inID); + if (window) { + CString previousText; + if (inDelay != -1) + window->GetWindowText(previousText); + + window->SetWindowText(inText); + window->RedrawWindow(); + + if (inDelay != -1) { + DWORD time = GetTickCount() + inDelay; + while (time > GetTickCount()) {} + + window->SetWindowText(previousText); + window->RedrawWindow(); + } + } + } } -void T2TowerMessage::AleatMessage(const CString&, int) { +void T2TowerMessage::AleatMessage(const CString& inText, int inAlertType) { + switch (inAlertType) { + case kAlertType0: + T2StewardDialog::MessageBox(inText, "Stop"); + break; + case kAlertType1: + T2StewardDialog::MessageBox(inText, "Note"); + break; + case kAlertType2: + T2StewardDialog::MessageBox(inText, "Caution"); + break; + default: + T2StewardDialog::MessageBox(inText, "Question"); + break; + } } void T2TowerMessage::SpendTime() { + if (mInfoBarMsgItems) { + BOOL done = false; + InfoBarMsgItem *theMsgItem; + + while (mInfoBarMsgItems->GetCount() > 0) { + done = false; + if (mInfoBarMsgItems->FetchItemAt(1, &theMsgItem)) { + if (!theMsgItem->mEndTicks) + SetInfoBarMsg(theMsgItem); + + if (theMsgItem->mDelay == -1 || theMsgItem->mEndTicks < GetTickCount()) { + mInfoBarMsgItems->RemoveItemsAt(1, 1); + done = (theMsgItem->mDelay != -1); + delete theMsgItem; + } else { + break; + } + } + } + + if (done) + SetInfoBarMsg(NULL); + } } void T2TowerMessage::SpendTime2() { + T2Balloon *balloon; + DWORD time = GetTickCount(); + + // these arbitrary letter suffixes are just there + // so that the compiler puts the vars in the right order + LArrayIterator balloonIteratorM(*mEquipBalloonMessages); + while (balloonIteratorM.Next(&balloon)) { + if (balloon->mEndTime < time) { + mEquipBalloonMessages->Remove(&balloon); + delete balloon; + balloonIteratorM.ResetTo(1); + } + } + + LArrayIterator balloonIteratorP(*mObjectBalloonMessages); + while (balloonIteratorP.Next(&balloon)) { + if (balloon->mEndTime < time) { + mObjectBalloonMessages->Remove(&balloon); + delete balloon; + balloonIteratorP.ResetTo(1); + mHasCapture = false; + } + } +} + +/*virtual*/ void T2TowerMessage::ExecuteSelf(unsigned int inMessage, void* ioData) { + BOOL newExecuteHost = true; + + switch (inMessage) { + case WM_MOUSEMOVE: + if (mHasCapture) { + MSG *pMsg = (MSG *) ioData; + + CPoint pt; + pt.x = LOWORD(pMsg->lParam); + pt.y = HIWORD(pMsg->lParam); + pt += GetCurrentT2TowerDoc()->GetTowerMainView()->m64; + + if (PtInRect(&mCaptureRect, pt)) { + newExecuteHost = false; + break; + } + + mHasCapture = false; + } + + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + if (mObjectBalloonMessages->GetCount() > 0) { + T2Balloon *balloon; + LArrayIterator balloonIterator(*mObjectBalloonMessages); + + while (balloonIterator.Next(&balloon)) { + mObjectBalloonMessages->Remove(&balloon); + delete balloon; + balloonIterator.ResetTo(1); + mHasCapture = false; + } + } + break; + } + + SetExecuteHost(newExecuteHost); } -/*virtual*/ void T2TowerMessage::ExecuteSelf(unsigned int, void*) { +CWnd* T2TowerMessage::FindFloatingWindow(int inID) { + CWnd *window = CWnd::GetForegroundWindow(); + + while (window) { + if (window->IsWindowVisible() && window->GetDlgCtrlID() == inID) + break; + + window = window->GetNextWindow(); + } + + return window; +} + +void T2TowerMessage::CancelInfoBarMessage(const CString& inText) { + if (mInfoBarMsgItems) { + InfoBarMsgItem *theMsgItem = NULL; + LArrayIterator iterator(*mInfoBarMsgItems); + + while (iterator.Next(&theMsgItem)) { + if (iterator.GetCurrentIndex() > 1 && !inText.Compare(theMsgItem->mText)) { + mInfoBarMsgItems->RemoveItemsAt(1, iterator.GetCurrentIndex()); + iterator.Reset(); + delete theMsgItem; + } + } + } } -CWnd* T2TowerMessage::FindFloatingWindow(int) { +void T2TowerMessage::PassiveInfoBarMessage(const char* inText, int inDelay, const char* inSoundID) { + BOOL done = false; + + if (mInfoBarMsgItems) { + InfoBarMsgItem *theMsgItem = NULL; + LArrayIterator iterator(*mInfoBarMsgItems); + + while (!done && iterator.Next(&theMsgItem)) + done = !strcmp(inText, theMsgItem->mText); + + if (!done) + InfoBarMessage(inText, inDelay, inSoundID); + } } -void T2TowerMessage::CancelInfoBarMessage(const CString&) { +void T2TowerMessage::SetCaptureRect(RECT inRect) { + mCaptureRect = inRect; + mHasCapture = true; } -void T2TowerMessage::PassiveInfoBarMessage(const char*, int, const char*) { + + +InfoBarMsgItem::InfoBarMsgItem(const CString &inText, int inDelay, const char *inSoundID) { + mSoundID = ""; + + mText = inText; + mDelay = inDelay; + if (inSoundID) + mSoundID = inSoundID; + mEndTicks = 0; } -void T2TowerMessage::SetCaptureRect(RECT) { +InfoBarMsgItem::~InfoBarMsgItem() { } diff --git a/src/T2DLL/T2TowerMessage.h b/src/T2DLL/T2TowerMessage.h index 5dca2c6..434ff5b 100644 --- a/src/T2DLL/T2TowerMessage.h +++ b/src/T2DLL/T2TowerMessage.h @@ -1,33 +1,59 @@ #pragma once #include "common.h" +#include "LAttachment.h" -class T2TowerMessage { +class InfoBarMsgItem; + +enum { + kAlertType0 = 0, + kAlertType1 = 1, + kAlertType2 = 2, + kAlertType3 = 3 +}; + +class AFX_EXT_CLASS T2TowerMessage : public LAttachment { public: - T2TowerMessage(HINSTANCE, T2TowerDoc*); + T2TowerMessage(HINSTANCE inModuleHandle, T2TowerDoc* inDoc); virtual ~T2TowerMessage(); - void InfoBarMessage(const CString&, int, const char*); -private: - void SetInfoBarMsg(InfoBarMsgItem*); -public: - void EquipBalloonMessage(const CString&, T2Equip*); - void PeopleBalloonMessage(const CString&, T2People*); - void EquipBalloonMessage(const CString&, POINT); + virtual void ExecuteSelf(unsigned int inMessage, void* ioData); + + void InfoBarMessage(const CString& inText, int inDelay, const char* inSoundID); + void EquipBalloonMessage(const CString& inText, T2Equip* inEquip); + void PeopleBalloonMessage(const CString& inText, T2People* inPeople); + void EquipBalloonMessage(const CString& inText, POINT inPt); void BuildErr(const CString&); - void BuildErr(unsigned int, T2EquipDef*); - int GetBuildErrString(unsigned int, CString&); - void ObjectBalloonMessage(const CString&, const RECT&); - void InfoDialogMessage(const CString&, int, int); - void AleatMessage(const CString&, int); + void BuildErr(unsigned int inID, T2EquipDef* inDef); + BOOL GetBuildErrString(unsigned int inID, CString& outStr); + void ObjectBalloonMessage(const CString& inText, const RECT& inRect); + void InfoDialogMessage(const CString& inText, int inID, int inDelay); + void AleatMessage(const CString& inText, int inAlertType); void SpendTime(); void SpendTime2(); - virtual void ExecuteSelf(unsigned int, void*); + void CancelInfoBarMessage(const CString& inText); + void PassiveInfoBarMessage(const char* inText, int inDelay, const char* inSoundID); + void SetCaptureRect(RECT inRect); + private: - CWnd* FindFloatingWindow(int); + void SetInfoBarMsg(InfoBarMsgItem* inItem); + CWnd* FindFloatingWindow(int inID); + + T2TowerDoc *mDocument; + int _14; + HINSTANCE mModuleHandle; + LArray *mInfoBarMsgItems; + LArray *mEquipBalloonMessages; + LArray *mObjectBalloonMessages; + BOOL mHasCapture; + RECT mCaptureRect; +}; + +class InfoBarMsgItem { public: - void CancelInfoBarMessage(const CString&); - void PassiveInfoBarMessage(const char*, int, const char*); - void SetCaptureRect(RECT); + InfoBarMsgItem(const CString &inText, int inDelay, const char *inSoundID); + ~InfoBarMsgItem(); - T2TowerMessage(const T2TowerMessage&) {} - T2TowerMessage& operator=(const T2TowerMessage&) {} + CString mText; + int mDelay; + unsigned int mEndTicks; + CString mSoundID; }; diff --git a/src/T2DLL/T2TowerVision.cpp b/src/T2DLL/T2TowerVision.cpp index 4838242..5601487 100644 --- a/src/T2DLL/T2TowerVision.cpp +++ b/src/T2DLL/T2TowerVision.cpp @@ -1,16 +1,27 @@ +#include "T2OutObj.h" +#include "T2TowerEvent.h" #include "T2TowerVision.h" -T2TowerVision::T2TowerVision(T2TowerEvent*, int, int, int, int, int, int, T2OutObj*) { +T2TowerVision::T2TowerVision(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime, T2OutObj *inOutObj) + : T2EventItem(inTowerEvent, inSubID, inLevelBit, inExclusive, inCycleDay, inBeginTime, inEndTime) +{ + mOutObj = inOutObj; + _34 = 0; + + T2ToolDef *theDef = mOutObj->GetToolDef(); } /*virtual*/ T2TowerVision::~T2TowerVision() { + StopEvent(mTowerEvent->mDocument); } -/*virtual*/ int T2TowerVision::Exec(T2TowerDoc*) { +/*virtual*/ int T2TowerVision::Exec(T2TowerDoc* inDoc) { + return 0; } -/*virtual*/ void T2TowerVision::StopEvent(T2TowerDoc*) { +/*virtual*/ void T2TowerVision::StopEvent(T2TowerDoc* inDoc) { } -int T2TowerVision::PrepareMovie(T2TowerDoc*) { +BOOL T2TowerVision::PrepareMovie(T2TowerDoc* inDoc) { + return true; } diff --git a/src/T2DLL/T2TowerVision.h b/src/T2DLL/T2TowerVision.h index c07bc74..2fc44b2 100644 --- a/src/T2DLL/T2TowerVision.h +++ b/src/T2DLL/T2TowerVision.h @@ -1,15 +1,18 @@ #pragma once #include "common.h" +#include "T2EventItem.h" -class T2TowerVision { +class AFX_EXT_CLASS T2TowerVision : public T2EventItem { public: - T2TowerVision(T2TowerEvent*, int, int, int, int, int, int, T2OutObj*); + T2TowerVision(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime, T2OutObj *inOutObj); virtual ~T2TowerVision(); - virtual int Exec(T2TowerDoc*); - virtual void StopEvent(T2TowerDoc*); - int PrepareMovie(T2TowerDoc*); + virtual DWORD GetID() { return 'TVEv'; } + virtual int Exec(T2TowerDoc* inDoc); + virtual void StopEvent(T2TowerDoc* inDoc); + BOOL PrepareMovie(T2TowerDoc* inDoc); - virtual unsigned long GetID() {} - T2TowerVision(const T2TowerVision&) {} - T2TowerVision& operator=(const T2TowerVision&) {} +protected: + T2OutObj *mOutObj; + int _34; + int _38; }; diff --git a/src/T2DLL/T2TrafficInfo.cpp b/src/T2DLL/T2TrafficInfo.cpp index 6390c51..04722a4 100644 --- a/src/T2DLL/T2TrafficInfo.cpp +++ b/src/T2DLL/T2TrafficInfo.cpp @@ -1,34 +1,162 @@ +#include "T2Archive.h" +#include "T2FloorInfo.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" #include "T2TrafficInfo.h" +#include "URect.h" -T2TrafficInfo::T2TrafficInfo(RECT, unsigned int, unsigned int, unsigned int, unsigned int) { +T2TrafficInfo::T2TrafficInfo(RECT inArea, unsigned int inA, unsigned int inB, unsigned int inC, unsigned int inUnitSize) { + mUnitSize = inUnitSize; + if (mUnitSize == 0) + mUnitSize = 4; + + m8 = inA / 4; + mC = inB / 4; + m10 = inC / 4; + + mArea = inArea; + mHeight = URect::Height(inArea); + mWidth = URect::Width(inArea) / mUnitSize; + mUnitData = new T2TrafficUnit[mWidth * mHeight]; + + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + for (unsigned int i = 0; i < nUnits; i++, unt++) { + unt->x0 = 0; + unt->x4 = 0; + } } /*virtual*/ T2TrafficInfo::~T2TrafficInfo() { + if (mUnitData) + delete[] mUnitData; } -void T2TrafficInfo::Pass(POINT, POINT, short) { +void T2TrafficInfo::Pass(POINT inPt1, POINT inPt2, short inCost) { + POINT point1; + POINT point2; + + if (inPt1.x < inPt2.x) { + point1 = inPt1; + point2 = inPt2; + point2.y = inPt1.y; + } else { + point1 = inPt2; + point1.y = inPt1.y; + point2 = inPt1; + } + + T2TrafficUnit *un1 = GetUnit(point1); + T2TrafficUnit *un2 = GetUnit(point2); + + if (un1 && un2) { + for (T2TrafficUnit *unit = un1; unit <= un2; unit++) + unit->x0 += inCost; + } } -void T2TrafficInfo::HourChanged(T2TowerDoc*) { +void T2TrafficInfo::HourChanged(T2TowerDoc* inDoc) { + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + + for (unsigned int i = 0; i < nUnits; i++, unt++) { + unt->x4 *= 0.96875f; + if ((unt->x4 + unt->x0) > 0xFFFF) + unt->x4 = 0xFFFF; + else + unt->x4 += unt->x0; + unt->x0 = 0; + + int range = CalcRange(unt->x4); + if (range != unt->range) { + unt->range = range; + if (inDoc->towerDoc_vf140() == ViewMode_5) { + RECT area; + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + + CalcUnitArea(i, area); + theFloorInfo->SetTenantDrawModeByRect(area, DrawMode3); + inDoc->GetTowerMainView()->tmv_vf128(area); + } + } + } } -unsigned int T2TrafficInfo::CalcRange(unsigned int) const { +unsigned int T2TrafficInfo::CalcRange(unsigned int inValue) const { + short range = 3; + + if (inValue < m8) + range = 0; + else if (inValue < mC) + range = 1; + else if (inValue < m10) + range = 2; + + return range; } -void T2TrafficInfo::CalcUnitArea(unsigned int, RECT&) const { +void T2TrafficInfo::CalcUnitArea(unsigned int inIndex, RECT& outRect) const { + unsigned int h = inIndex / mWidth; + unsigned int v = (inIndex % mWidth) * mUnitSize; + SetRect(&outRect, h, v, h + mUnitSize, v + 1); + OffsetRect(&outRect, mArea.left, mArea.top); } -short T2TrafficInfo::GetRange(POINT) const { +short T2TrafficInfo::GetRange(POINT inPt) const { + short range = 0; + + T2TrafficUnit *theUnit = GetUnit(inPt); + if (theUnit) + range = theUnit->range; + + return range; } -T2TrafficUnit* T2TrafficInfo::GetUnit(POINT) const { +T2TrafficUnit* T2TrafficInfo::GetUnit(POINT inPt) const { + T2TrafficUnit *theUnit = NULL; + + if (mUnitData) { + int index = CalcUnitIndex(inPt); + if (index > 0) + theUnit = mUnitData + index; + } + + return theUnit; } -int T2TrafficInfo::CalcUnitIndex(POINT) const { +int T2TrafficInfo::CalcUnitIndex(POINT inPt) const { + int index = -1; + POINT point = inPt; + + if (PtInRect(&mArea, point)) { + int h = (inPt.x - mArea.left) / mUnitSize; + int v = inPt.y - mArea.top; + index = mWidth * v + h; + } + + return index; } -void T2TrafficInfo::Read(T2Archive&) { +void T2TrafficInfo::Read(T2Archive& inArchive) { + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + for (unsigned int i = 0; i < nUnits; i++, unt++) { + unsigned short v; + + inArchive >> v; + unt->x0 = v; + inArchive >> v; + unt->x4 = v; + + unt->range = CalcRange(unt->x4); + } } -void T2TrafficInfo::Write(T2Archive&) const { +void T2TrafficInfo::Write(T2Archive& inArchive) const { + unsigned int nUnits = mWidth * mHeight; + T2TrafficUnit *unt = mUnitData; + for (unsigned int i = 0; i < nUnits; i++, unt++) { + inArchive << (unsigned short) unt->x0; + inArchive << (unsigned short) unt->x4; + } } diff --git a/src/T2DLL/T2TrafficInfo.h b/src/T2DLL/T2TrafficInfo.h index 751f56d..422a709 100644 --- a/src/T2DLL/T2TrafficInfo.h +++ b/src/T2DLL/T2TrafficInfo.h @@ -1,24 +1,34 @@ #pragma once #include "common.h" -class T2TrafficInfo { +struct T2TrafficUnit { + int x0; + unsigned int x4; + short range; +}; + +class AFX_EXT_CLASS T2TrafficInfo { public: - T2TrafficInfo(RECT, unsigned int, unsigned int, unsigned int, unsigned int); + T2TrafficInfo(RECT inArea, unsigned int inA, unsigned int inB, unsigned int inC, unsigned int inUnitSize); virtual ~T2TrafficInfo(); - void Pass(POINT, POINT, short); - void HourChanged(T2TowerDoc*); -protected: - unsigned int CalcRange(unsigned int) const; - void CalcUnitArea(unsigned int, RECT&) const; -public: - short GetRange(POINT) const; + void Pass(POINT inPt1, POINT inPt2, short inCost); + void HourChanged(T2TowerDoc* inDoc); + short GetRange(POINT inPt) const; + void Read(T2Archive& inArchive); + void Write(T2Archive& inArchive) const; + protected: - T2TrafficUnit* GetUnit(POINT) const; - int CalcUnitIndex(POINT) const; -public: - void Read(T2Archive&); - void Write(T2Archive&) const; + unsigned int CalcRange(unsigned int inValue) const; + void CalcUnitArea(unsigned int inIndex, RECT& outRect) const; + T2TrafficUnit* GetUnit(POINT inPt) const; + int CalcUnitIndex(POINT inPt) const; - T2TrafficInfo(const T2TrafficInfo&) {} - T2TrafficInfo& operator=(const T2TrafficInfo&) {} + unsigned int mUnitSize; + unsigned int m8; + unsigned int mC; + unsigned int m10; + RECT mArea; + unsigned int mHeight; + unsigned int mWidth; + T2TrafficUnit *mUnitData; }; diff --git a/src/T2DLL/T2Transport.cpp b/src/T2DLL/T2Transport.cpp index 176c1d7..a3e1ac3 100644 --- a/src/T2DLL/T2Transport.cpp +++ b/src/T2DLL/T2Transport.cpp @@ -1,70 +1,322 @@ +#include "CResFile.h" +#include "LArray.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2Pool.h" +#include "T2TowerDoc.h" #include "T2Transport.h" +#include "T2WorldDef.h" T2Transport::T2Transport() { + Initialize(); + mCapacity = 60; } /*virtual*/ T2Transport::~T2Transport() { + delete mArray; } void T2Transport::Initialize() { + mParent = NULL; + mArray = NULL; + + _C = 0; + mWidth = 0; + _14 = 0; + mStation = 0; + mGrade = 0; + mTrainType = 0; + _24 = 0; + mArriveTime = 0; + _2C = 0; + mFlag = false; + + mCapacity = 0; + mNumOfContents = 0; + + mFirstLink = NULL; + mLastLink = NULL; } -void T2Transport::Init(T2Transport*, CResFile*) { +void T2Transport::Init(T2Transport* inParent, CResFile* inResFile) { + mWidth = DoGetWorldDef()->GetWidth(); + mStation = mWidth / 2; + + mParent = inParent; + + int v; + *inResFile >> v; + mArriveTime = v; + + *inResFile >> mTrainType; + + mArray = (mParent == this) ? new LArray : NULL; } -void T2Transport::Init(T2Transport*, int) { +void T2Transport::Init(T2Transport* inParent, int inArriveTime) { + mParent = inParent; + mArriveTime = inArriveTime; + mArray = (mParent == this) ? new LArray : NULL; } -void T2Transport::AddTransport(T2Transport*) { +void T2Transport::AddTransport(T2Transport* inTransport) { + if (mParent == this) { + if (mArray) + mArray->Add(&inTransport); + } else { + mParent->AddTransport(inTransport); + } } int T2Transport::GetNofTimeTable() { + int result = 12; + + if (mParent == this) { + if (mArray) + result = mArray->GetCount(); + } else { + result = mParent->GetNofTimeTable(); + } + + return result; } -void T2Transport::SetStation(unsigned int) { +void T2Transport::SetStation(unsigned int inStation) { + if (mParent == this) { + T2Transport *obj; + for (int i = 0; (obj = GetIndObject(i)); i++) + obj->mStation = inStation; + } else { + mParent->SetStation(inStation); + } } -void T2Transport::UpGrade(int) { +void T2Transport::UpGrade(int inGrade) { + if (mParent == this) { + T2Transport *obj; + for (int i = 0; (obj = GetIndObject(i)); i++) { + obj->mGrade = inGrade; + if (obj->mTrainType < obj->mGrade) + obj->mFlag = true; + } + } else { + mParent->UpGrade(inGrade); + } } -int T2Transport::GetTrainType(int) const { +int T2Transport::GetTrainType(int inIndex) const { + return GetIndObject(inIndex)->mTrainType; } -unsigned int T2Transport::GetArriveTime(int) const { +unsigned int T2Transport::GetArriveTime(int inIndex) const { + return GetIndObject(inIndex)->mArriveTime; } T2Transport* T2Transport::GetStoppage() const { + T2Transport *result = NULL; + + if (mParent == this) { + LArrayIterator iterator(*mArray); + T2Transport *obj; + while (!result && iterator.Next(&obj)) { + if (obj->ChkStoppage()) + result = obj; + } + } else { + result = mParent->GetStoppage(); + } + + return result; } -int T2Transport::WasStoppage() const { +BOOL T2Transport::WasStoppage() const { + if (mParent == this) { + T2Transport *obj; + for (int i = 0; (obj = GetIndObject(i)); i++) { + if (obj->ChkStoppage()) + return true; + } + + return false; + } else { + return mParent->WasStoppage(); + } } -int T2Transport::ChkStoppage() const { +BOOL T2Transport::ChkStoppage() const { + BOOL result = false; + + if (mFlag) { + T2DateTime *theNow = DoGetTowerDoc()->towerDoc_vf120(); + int nowMinutes = theNow->GetRawMinutes(); + int diff = nowMinutes - mArriveTime; + result = (diff >= 0 && diff < (_2C + 1)); + } + + return result; } -T2Transport* T2Transport::GetIndObject(int) const { +T2Transport* T2Transport::GetIndObject(int inIndex) const { + T2Transport *result = NULL; + + if (mParent == this) { + if (mArray) { + inIndex = (inIndex >= 0) ? (inIndex + 1) : mArray->GetCount(); + mArray->FetchItemAt(inIndex, &result); + } + } else { + result = mParent->GetIndObject(inIndex); + } + + return result; } -T2Transport* T2Transport::GetAvailable(T2DateTime*) const { +T2Transport* T2Transport::GetAvailable(T2DateTime* inDateTime) const { + T2Transport *result = NULL; + + if (mParent == this) { + LArrayIterator iterator(*mArray); + T2Transport *obj; + while (!result && iterator.Next(&obj)) { + if (obj->IsAvailable(inDateTime)) + result = obj; + } + } else { + result = mParent->GetAvailable(inDateTime); + } + + return result; } -int T2Transport::IsAvailable(T2DateTime*) { +BOOL T2Transport::IsAvailable(T2DateTime* inDateTime) { + BOOL result = false; + + if (mFlag && !IsFull()) { + int beginTime = DoGetBeginTime(); + result = inDateTime->WithinMinutes(beginTime - 60, beginTime); + } + + return result; } -int T2Transport::Enter(CLink*) { +BOOL T2Transport::Enter(CLink* inLink) { + mNumOfContents++; + + T2People *thePeople = (T2People *) inLink; + thePeople->ChangeStatus(kStatus16); + thePeople->SetCurrEquipID(0); + + if (!mFirstLink) { + mFirstLink = inLink; + mLastLink = inLink; + inLink->SetPrev(NULL); + return true; + } + + if (mLastLink) { + mLastLink->InsertAt(inLink); + mLastLink = inLink; + return true; + } + + return false; } -int T2Transport::Leave(CLink*) { +BOOL T2Transport::Leave(CLink* inLink) { + mNumOfContents--; + + if (mFirstLink) { + if (mFirstLink == inLink) { + mFirstLink = inLink->GetNext(); + if (mFirstLink == NULL) + mLastLink = NULL; + else if (mFirstLink->GetNext() == NULL) + mLastLink = mFirstLink; + + inLink->Remove(); + return true; + } else if (mLastLink != inLink) { + inLink->Remove(); + } else if (mLastLink == inLink) { + mLastLink = inLink->GetPrev(); + inLink->Remove(); + if (mLastLink == NULL) + mFirstLink = NULL; + + return true; + } + } + + return false; } CLink* T2Transport::LeaveFirst() { + CLink *result = NULL; + + if (mFirstLink) { + result = mFirstLink; + Leave(result); + } + + return result; } -/*virtual*/ int T2Transport::Stop(T2TowerDoc*) { +/*virtual*/ int T2Transport::Stop(T2TowerDoc* inDoc) { + T2People *thePeople = NULL; + + do { + thePeople = (T2People *) LeaveFirst(); + if (thePeople) + inDoc->towerDoc_vf130()->Enter(thePeople); + } + while (thePeople); + + DoSetStatus(0); + return 0; } -/*virtual*/ void T2Transport::Read(T2Archive&) { +/*virtual*/ void T2Transport::Read(T2Archive& inArchive) { + unsigned int theLinkData; + + inArchive >> theLinkData; + if (theLinkData) { + T2TowerDoc *theDoc = DoGetTowerDoc(); +#line 513 + _ASSERT(theDoc != NULL); + + T2PeopleArrayList *theList = theDoc->mPeopleArrayList; +#line 515 + _ASSERT(theList != NULL); + + mFirstLink = theList->FindPeople(theLinkData); +#line 517 + _ASSERT(mFirstLink != NULL); + + inArchive >> theLinkData; +#line 520 + _ASSERT(theLinkData != 0); + + mLastLink = theList->FindPeople(theLinkData); +#line 522 + _ASSERT(mLastLink != NULL); + + mNumOfContents = mFirstLink->Count(); + } } -/*virtual*/ void T2Transport::Write(T2Archive&) { +/*virtual*/ void T2Transport::Write(T2Archive& inArchive) { + unsigned int theLinkData = 0; + + if (mFirstLink) { + inArchive << ((T2People *) mFirstLink)->GetPeopleID(); + +#line 544 + _ASSERT(mLastLink != NULL); + + inArchive << ((T2People *) mLastLink)->GetPeopleID(); + } else { + inArchive << theLinkData; + } } diff --git a/src/T2DLL/T2Transport.h b/src/T2DLL/T2Transport.h index 4fc0443..b1e0640 100644 --- a/src/T2DLL/T2Transport.h +++ b/src/T2DLL/T2Transport.h @@ -1,39 +1,56 @@ #pragma once #include "common.h" -class T2Transport { +class AFX_EXT_CLASS T2Transport { public: T2Transport(); virtual ~T2Transport(); -private: - void Initialize(); -public: - void Init(T2Transport*, CResFile*); - void Init(T2Transport*, int); - void AddTransport(T2Transport*); + void Init(T2Transport* inParent, CResFile* inResFile); + void Init(T2Transport* inParent, int inArriveTime); + void AddTransport(T2Transport* inTransport); int GetNofTimeTable(); - void SetStation(unsigned int); - void UpGrade(int); - int GetTrainType(int) const; - unsigned int GetArriveTime(int) const; + void SetStation(unsigned int inStation); + void UpGrade(int inGrade); + int GetTrainType(int inIndex) const; + unsigned int GetArriveTime(int inIndex) const; T2Transport* GetStoppage() const; - int WasStoppage() const; -protected: - int ChkStoppage() const; - T2Transport* GetIndObject(int) const; -public: - T2Transport* GetAvailable(T2DateTime*) const; -protected: - int IsAvailable(T2DateTime*); -public: - int Enter(CLink*); - int Leave(CLink*); + BOOL WasStoppage() const; + T2Transport* GetAvailable(T2DateTime* inDateTime) const; + BOOL Enter(CLink* inLink); + BOOL Leave(CLink* inLink); CLink* LeaveFirst(); - virtual int Stop(T2TowerDoc*); - virtual void Read(T2Archive&); - virtual void Write(T2Archive&); + BOOL IsFull() const { return mNumOfContents >= mCapacity; } + + virtual int Stop(T2TowerDoc* inDoc); + virtual void Read(T2Archive& inArchive); + virtual void Write(T2Archive& inArchive); + +private: + void Initialize(); + virtual void DoSetStatus(int inStatus) = 0; + virtual T2TowerDoc *DoGetTowerDoc() const = 0; + virtual int DoGetBeginTime() = 0; + virtual T2WorldDef *DoGetWorldDef() = 0; + +protected: + BOOL ChkStoppage() const; + T2Transport* GetIndObject(int inIndex) const; + BOOL IsAvailable(T2DateTime* inDateTime); - int IsFull() const {} - T2Transport(const T2Transport&) {} - T2Transport& operator=(const T2Transport&) {} + T2Transport *mParent; + LArray *mArray; + int _C; + unsigned int mWidth; + int _14; + unsigned int mStation; + int mGrade; + int mTrainType; + int _24; + unsigned int mArriveTime; + unsigned int _2C; + BOOL mFlag; + unsigned int mCapacity; + unsigned int mNumOfContents; + CLink *mFirstLink; + CLink *mLastLink; }; diff --git a/src/T2DLL/T2TreasureDialog.cpp b/src/T2DLL/T2TreasureDialog.cpp index 19ddddc..55e27ec 100644 --- a/src/T2DLL/T2TreasureDialog.cpp +++ b/src/T2DLL/T2TreasureDialog.cpp @@ -1,4 +1,8 @@ +#include "CTokenizer.h" +#include "T2PluginSpecifier.h" +#include "T2TowerDoc.h" #include "T2TreasureDialog.h" +#include "T2TreasurePane.h" T2TreasureDialog::T2TreasureDialog() { } @@ -7,22 +11,59 @@ T2TreasureDialog::T2TreasureDialog() { } /*virtual*/ void T2TreasureDialog::OnT2Create() { + mTreasurePane = (T2TreasurePane *) GetDlgItem(1000); + mTextPane = (T2DlgItem *) GetDlgItem(1001); } -/*virtual*/ void T2TreasureDialog::CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&) { +/*virtual*/ void T2TreasureDialog::CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef) { + if (!_stricmp(inTokenizer.Current(), "ANIM")) { + RECT rect; + UINT id = inTokenizer.NextInteger(); + rect.left = inTokenizer.NextInteger(); + rect.top = inTokenizer.NextInteger(); + rect.right = inTokenizer.NextInteger(); + rect.bottom = inTokenizer.NextInteger(); + + T2TreasurePane *theTreasurePane = new T2TreasurePane(mTowerDoc, mImageObj, mPalette); + theTreasurePane->Create("", inDef.flags, rect, this, id); + theTreasurePane->CreateSubItem(NULL); + if (mCurrentFont >= 0) + theTreasurePane->SetFont(*mFonts[mCurrentFont]); + } else { + T2Dialog::CreateDlgItem(inTokenizer, inDef); + } } /*virtual*/ void T2TreasureDialog::OnT2Destroy() { } /*virtual*/ void T2TreasureDialog::ShowSelf() { + ShowWindow(SW_SHOWNORMAL); } /*virtual*/ void T2TreasureDialog::HideSelf() { + ShowWindow(SW_HIDE); } -/*static*/ void T2TreasureDialog::ShowTreasureDialog(T2TowerDoc*, T2TreasureStatus*) { +/*static*/ void T2TreasureDialog::ShowTreasureDialog(T2TowerDoc* inTowerDoc, T2TreasureStatus* inStatus) { +#line 69 // nice + _ASSERT(inTowerDoc != NULL); + + CRect rect; + AfxGetMainWnd()->GetWindowRect(rect); + + T2DLGTEMPLATE theTemplate; + theTemplate.pt = rect.CenterPoint(); + theTemplate.moduleHandle = inTowerDoc->mWorldPluginSpecifier->mInstance; + theTemplate.resID = 11000; + T2TreasureDialog *theDialog = new T2TreasureDialog; + + theDialog->Realize(inTowerDoc, &theTemplate, inTowerDoc, NULL, NULL, true, NULL, 0, true); + theDialog->SetTreasureInfo(inTowerDoc, inStatus); } -void T2TreasureDialog::SetTreasureInfo(T2TowerDoc*, T2TreasureStatus*) { +void T2TreasureDialog::SetTreasureInfo(T2TowerDoc* inTowerDoc, T2TreasureStatus* inStatus) { + mTreasurePane->SetAnimPics(inTowerDoc, inStatus->animID1, inStatus->animID2); + strncpy(mText, inStatus->text, 255); + mTextPane->SetWindowText(mText); } diff --git a/src/T2DLL/T2TreasureDialog.h b/src/T2DLL/T2TreasureDialog.h index 8156f23..b0fb3fe 100644 --- a/src/T2DLL/T2TreasureDialog.h +++ b/src/T2DLL/T2TreasureDialog.h @@ -1,17 +1,22 @@ #pragma once #include "common.h" +#include "T2Dialog.h" -class T2TreasureDialog { +class AFX_EXT_CLASS T2TreasureDialog : public T2Dialog { public: T2TreasureDialog(); virtual ~T2TreasureDialog(); + void SetTreasureInfo(T2TowerDoc* inTowerDoc, T2TreasureStatus* inStatus); + static void ShowTreasureDialog(T2TowerDoc* inTowerDoc, T2TreasureStatus* inStatus); + protected: virtual void OnT2Create(); - virtual void CreateDlgItem(CTokenizer&, T2Dialog::T2DialogDef&); + virtual void CreateDlgItem(CTokenizer& inTokenizer, T2DialogDef& inDef); virtual void OnT2Destroy(); virtual void ShowSelf(); virtual void HideSelf(); -public: - static void ShowTreasureDialog(T2TowerDoc*, T2TreasureStatus*); - void SetTreasureInfo(T2TowerDoc*, T2TreasureStatus*); + + T2TreasurePane *mTreasurePane; + T2DlgItem *mTextPane; + char mText[256]; }; diff --git a/src/T2DLL/T2TreasurePane.cpp b/src/T2DLL/T2TreasurePane.cpp index a6ed42c..85057c2 100644 --- a/src/T2DLL/T2TreasurePane.cpp +++ b/src/T2DLL/T2TreasurePane.cpp @@ -1,22 +1,65 @@ +#include "T2BitImage.h" +#include "T2PluginSpecifier.h" +#include "T2TowerDoc.h" #include "T2TreasurePane.h" -T2TreasurePane::T2TreasurePane(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2TreasurePane::T2TreasurePane(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ + mImages[1] = NULL; + mImages[0] = NULL; + mCurrentImage = 0; + mLastChangeAt = 0; } /*virtual*/ T2TreasurePane::~T2TreasurePane() { + if (mImages[0]) + delete mImages[0]; + if (mImages[1]) + delete mImages[1]; } -void T2TreasurePane::SetAnimPics(T2TowerDoc*, int, int) { +void T2TreasurePane::SetAnimPics(T2TowerDoc* inDoc, int inID1, int inID2) { + if (inDoc) { + HINSTANCE theModule = inDoc->mWorldPluginSpecifier->mInstance; + mImages[0] = new T2BitImage(theModule, inID1, true); + mImages[1] = new T2BitImage(theModule, inID2, true); + } } -/*virtual*/ void T2TreasurePane::DrawSelf(CDC*) { +/*virtual*/ void T2TreasurePane::DrawSelf(CDC* pDC) { + if (mImages[0]) { + int dcSave = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + RECT src, dst; + SetRect(&src, 0, 0, mImages[mCurrentImage]->mBitmap.header.biWidth, mImages[mCurrentImage]->mBitmap.header.biHeight); + dst = src; + + mImages[mCurrentImage]->CopyImage(pDC, src, dst); + + pDC->RestoreDC(dcSave); + } } /*virtual*/ void T2TreasurePane::SpendTime() { + DWORD now = GetTickCount(); + + if (mLastChangeAt == 0) { + mLastChangeAt = now; + } else if ((now - mLastChangeAt) > 30) { + mCurrentImage = !mCurrentImage; + mLastChangeAt = now; + InvalidateRect(NULL); + } } -/*virtual*/ int T2TreasurePane::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2TreasurePane::OnT2DlgItemEraseBkgnd(CDC* pDC) { + DrawSelf(pDC); + return true; } -/*virtual*/ int T2TreasurePane::OnCreate(CREATESTRUCTA*) { +/*virtual*/ int T2TreasurePane::OnCreate(CREATESTRUCT* inCreateStruct) { + return T2DlgItem::OnCreate(inCreateStruct); } diff --git a/src/T2DLL/T2TreasurePane.h b/src/T2DLL/T2TreasurePane.h index 327a3e2..1101c82 100644 --- a/src/T2DLL/T2TreasurePane.h +++ b/src/T2DLL/T2TreasurePane.h @@ -1,14 +1,20 @@ #pragma once #include "common.h" +#include "T2DlgItem.h" -class T2TreasurePane { +class AFX_EXT_CLASS T2TreasurePane : public T2DlgItem { public: - T2TreasurePane(T2TowerDoc*, T2ImageObj*, CPalette*); + T2TreasurePane(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette); virtual ~T2TreasurePane(); - void SetAnimPics(T2TowerDoc*, int, int); - virtual void DrawSelf(CDC*); virtual void SpendTime(); + virtual void DrawSelf(CDC* pDC); + void SetAnimPics(T2TowerDoc* inDoc, int inID1, int inID2); + protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - virtual int OnCreate(CREATESTRUCTA*); + virtual BOOL OnT2DlgItemEraseBkgnd(CDC* pDC); + virtual int OnCreate(CREATESTRUCT* inCreateStruct); + + T2BitImage *mImages[2]; + int mCurrentImage; + DWORD mLastChangeAt; }; diff --git a/src/T2DLL/T2UnitInfo.cpp b/src/T2DLL/T2UnitInfo.cpp index 15660b5..4b137e8 100644 --- a/src/T2DLL/T2UnitInfo.cpp +++ b/src/T2DLL/T2UnitInfo.cpp @@ -1,40 +1,94 @@ +#include "CResFile.h" +#include "T2Archive.h" #include "T2UnitInfo.h" T2UnitInfo::T2UnitInfo() { + mVarA = 0; + mVarB = 0; } T2UnitInfo::~T2UnitInfo() { } -int T2UnitInfo::IsBuildable() { +BOOL T2UnitInfo::IsBuildable() { + return ((mVarA & 0x8000) == 0); } -int T2UnitInfo::IsMoverID(unsigned int) { +BOOL T2UnitInfo::IsMoverID(unsigned int id) { + return (id > 0) && (id < 1000); } -int T2UnitInfo::IsRequestID(unsigned int) { +BOOL T2UnitInfo::IsRequestID(unsigned int id) { + return (id >= 1000); } unsigned int T2UnitInfo::GetTenantID() { + unsigned int tenantID = 0; + + if (mVarB) + tenantID = mVarB & 0x7FFF; + + return tenantID; } unsigned int T2UnitInfo::GetMoverID() { + unsigned int moverID = 0; + + if (mVarA) { + moverID = mVarA & 0x7FFF; + if (!IsMoverID(moverID)) + moverID = 0; + } + + return moverID; } unsigned int T2UnitInfo::GetRequestID() { + unsigned int requestID = 0; + + if (mVarA) { + requestID = mVarA & 0x7FFF; + if (!IsRequestID(requestID)) + requestID = 0; + } + + return requestID; } -void T2UnitInfo::FillTenantID(unsigned int) { +void T2UnitInfo::FillTenantID(unsigned int tenantID) { + mVarB &= 0x8000; + mVarB += tenantID; } -void T2UnitInfo::FillMoverID(unsigned int) { +void T2UnitInfo::FillMoverID(unsigned int moverID) { + mVarA &= 0x8000; + mVarA += moverID; } -void T2UnitInfo::InitMask(CResFile&) { +void T2UnitInfo::InitMask(CResFile& resFile) { + int v; + + resFile >> v; + if (v != 0) + mVarA |= 0x8000; + else + mVarA &= ~0x8000; } -void T2UnitInfo::Read(T2Archive&, T2TowerDoc*) { +void T2UnitInfo::Read(T2Archive& archive, T2TowerDoc*) { + unsigned short v; + + archive >> v; + mVarA = v; + archive >> v; + mVarB = v; } -void T2UnitInfo::Write(T2Archive&) { +void T2UnitInfo::Write(T2Archive& archive) { + unsigned short v; + + v = mVarA; + archive << v; + v = mVarB; + archive << v; } diff --git a/src/T2DLL/T2UnitInfo.h b/src/T2DLL/T2UnitInfo.h index 2c0835e..11242f0 100644 --- a/src/T2DLL/T2UnitInfo.h +++ b/src/T2DLL/T2UnitInfo.h @@ -1,21 +1,24 @@ #pragma once #include "common.h" -class T2UnitInfo { +class AFX_EXT_CLASS T2UnitInfo { public: T2UnitInfo(); ~T2UnitInfo(); - int IsBuildable(); - int IsMoverID(unsigned int); - int IsRequestID(unsigned int); + BOOL IsBuildable(); + BOOL IsMoverID(unsigned int tenantID); + BOOL IsRequestID(unsigned int moverID); unsigned int GetTenantID(); unsigned int GetMoverID(); unsigned int GetRequestID(); - void FillTenantID(unsigned int); - void FillMoverID(unsigned int); - void InitMask(CResFile&); - void Read(T2Archive&, T2TowerDoc*); - void Write(T2Archive&); + void FillTenantID(unsigned int tenantID); + void FillMoverID(unsigned int moverID); + void InitMask(CResFile& resFile); + void Read(T2Archive& archive, T2TowerDoc* towerDoc); + void Write(T2Archive& archive); - T2UnitInfo& operator=(const T2UnitInfo&) {} +protected: + // encodes buildable flag and a mover OR request ID + unsigned int mVarA; + unsigned int mVarB; }; diff --git a/src/T2DLL/T2VerticalTable.cpp b/src/T2DLL/T2VerticalTable.cpp index dcd2a6e..bf42d6b 100644 --- a/src/T2DLL/T2VerticalTable.cpp +++ b/src/T2DLL/T2VerticalTable.cpp @@ -1,10 +1,23 @@ #include "T2VerticalTable.h" -T2VerticalTable::T2VerticalTable(T2TowerDoc*, T2ImageObj*, CPalette*) { +T2VerticalTable::T2VerticalTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette) + : T2DlgItemImageTable(towerDoc, imageObj, palette) +{ + mClearBackground = false; } void T2VerticalTable::Clear() { + RemoveRows(mRows, 1); } -/*virtual*/ int T2VerticalTable::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2VerticalTable::OnT2DlgItemEraseBkgnd(CDC* dc) { + if (mClearBackground) { + RECT rect; + GetClientRect(&rect); + int theSavedDC = dc->SaveDC(); + dc->FillSolidRect(&rect, PALETTERGB(255, 255, 255)); + dc->RestoreDC(theSavedDC); + } + + return T2DlgItemTable::OnT2DlgItemEraseBkgnd(dc); } diff --git a/src/T2DLL/T2VerticalTable.h b/src/T2DLL/T2VerticalTable.h index f160e59..2bf1512 100644 --- a/src/T2DLL/T2VerticalTable.h +++ b/src/T2DLL/T2VerticalTable.h @@ -1,13 +1,12 @@ #pragma once #include "common.h" +#include "T2DlgItemImageTable.h" -class T2VerticalTable { +class AFX_EXT_CLASS T2VerticalTable : public T2DlgItemImageTable { public: - T2VerticalTable(T2TowerDoc*, T2ImageObj*, CPalette*); + T2VerticalTable(T2TowerDoc* towerDoc, T2ImageObj* imageObj, CPalette* palette); void Clear(); protected: - virtual int OnT2DlgItemEraseBkgnd(CDC*); - -public: - virtual ~T2VerticalTable() {} + virtual BOOL OnT2DlgItemEraseBkgnd(CDC*); + BOOL mClearBackground; }; diff --git a/src/T2DLL/T2VisitVIP.cpp b/src/T2DLL/T2VisitVIP.cpp index 9ed1e0f..caeba5f 100644 --- a/src/T2DLL/T2VisitVIP.cpp +++ b/src/T2DLL/T2VisitVIP.cpp @@ -1,37 +1,437 @@ +#include "CFilePlugin.h" +#include "CFilePluginList.h" +#include "CProgramPlugin.h" +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2DateTime.h" +#include "T2EquipPtrList.h" +#include "T2FloorInfo.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PluginLoader.h" +#include "T2PluginSpecifier.h" +#include "T2Pool.h" +#include "T2RegistedTenantDB.h" +#include "T2SoundPlayer.h" +#include "T2Tenant.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMessage.h" +#include "T2WorldDef.h" #include "T2VisitVIP.h" -T2VisitVIP::T2VisitVIP(T2TowerEvent*, CResFile*, int) { +T2VisitVIP::T2VisitVIP(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + int cycleDay = mCycleDay; + mSilhouetteType = 0; + + int numVIPs; + *inResFile >> numVIPs; + + T2VisitVIP *theVIP; + for (int i = 0; i < numVIPs; i++) { + theVIP = (i == 0) ? this : new T2VisitVIP(mTowerEvent, inSubID + i, mLevelBit, mExclusive, mCycleDay, mBeginTime, mEndTime); + if (theVIP) + theVIP->Init(inResFile); + if (theVIP != this) + mTowerEvent->AppendStandby(theVIP); + } } -T2VisitVIP::T2VisitVIP(T2TowerEvent*, int, int, int, int, int, int) { +T2VisitVIP::T2VisitVIP(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime) + : T2EventItem(inTowerEvent, inSubID, inLevelBit, inExclusive, inCycleDay, inBeginTime, inEndTime) +{ + mSilhouetteType = 0; } /*virtual*/ T2VisitVIP::~T2VisitVIP() { } -/*virtual*/ int T2VisitVIP::IsBeginDay(int) { +/*virtual*/ BOOL T2VisitVIP::IsBeginDay(int inDay) { + if (inDay > mBeginDay) + mBeginDay = inDay; + + return (mBeginDay == inDay); } -/*virtual*/ int T2VisitVIP::IsBeginTime(unsigned int) { +/*virtual*/ BOOL T2VisitVIP::IsBeginTime(unsigned int inTime) { + return (mBeginTime == inTime); } -/*virtual*/ int T2VisitVIP::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2VisitVIP::Start(T2TowerDoc* inDoc) { + BOOL mysteriousUnusedVar = true; + T2WorldDef *theWorldDef = GetWorldDef(); + + mStatus = kVisitVIPStatus0; + mCheckedIn = false; + mPeopleID = 0; + mTenantID = 0; + + if (mGrade <= theWorldDef->mNumOfGradeDef && inDoc->towerDoc_vf138() == mGrade) { + GradeDef *theGrade = &theWorldDef->mGradeDef[mGrade - 1]; + if ((theGrade->m0 & mVisitFlag) != 0 && (inDoc->mA0 & mVisitFlag) == 0) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + if (thePool && thePool->GetPopulation() > (theGrade->m4 / 2)) { + T2Tenant *theTenant = NULL; + CFilePlugin *thePlugin = NULL; + T2PluginSpecifier *theSpecifier = NULL; + + if (GetDestinationTennant(mTenantPluginID, theTenant, thePlugin, theSpecifier)) { + if (theTenant && thePool) { + T2People *theVIP = thePool->BornVIP(mSilhouetteType, -1); + if (theVIP) { + CString tmp; + CString text; + + theVIP->GetName(text); + T2Name *theName = inDoc->mNameDB->Search(theVIP); + if (theName) { + theName->SetName(text); + } else { + T2Name *newName = new T2Name(text, theVIP, false); + inDoc->mNameDB->Add(newName); + } + + theVIP->mColor = 14; + if (theTenant->GetRegistID() == kTenantRegistID1) { + theTenant->RegistBelongPeople(theVIP); + theVIP->SetDestination(theTenant->GetRelatedTenantID(), mArrivalTime); + theTenant->SetStatus(kTenantStatus31); + mCheckedIn = true; + } else { + theVIP->SetDestination(theTenant->mEquipID, mArrivalTime); + } + + // "様より" - From + text += "\x97\x6C\x82\xE6\x82\xE8"; + + RECT rect; + theTenant->GetEquipArea(rect); + + int floorNum = inDoc->towerDoc_vf12C()->UnitToFloor(rect.top); + if (floorNum < 0) { + text += 'B'; + floorNum = 0 - floorNum; + } + tmp.Format("%d", floorNum); + text += tmp; + // "階" - floor + text += "\x8A\x4B"; + + int roomNum = theTenant->GetRoomNumber(inDoc->towerDoc_vf12C()); + if (roomNum < 0) { + text += 'B'; + roomNum = 0 - roomNum; + } + tmp.Format("%d", roomNum); + text += tmp; + // "号室の" - of room number + text += "\x8D\x86\x8E\xBA\x82\xCC"; + + T2EquipDef *theTenantDef = theTenant->GetEquipDef(); + if (theTenantDef) + theTenantDef->GetName(tmp, 0); + text += tmp; + // "に、予約がはいりました。\n今日の" - I have a reservation. Today's + text += "\x82\xC9\x81\x41\x97\x5C\x96\xF1\x82\xAA\x82\xCD\x82\xA2\x82\xE8\x82\xDC\x82\xB5\x82\xBD\x81\x42\x0A\x8D\xA1\x93\xFA\x82\xCC"; + + tmp.Format("%d", mArrivalTime / 60); + text += tmp; + // "時" - Time + text += "\x8E\x9E"; + + int minute = mArrivalTime % 60; + if (minute != 0) { + // "%d分" - %d minute + tmp.Format("%d\x95\xAA", minute); + text += tmp; + } + + // "にロビーに到着する予定です。" - will arrive at the lobby on + text += "\x82\xC9\x83\x8D\x83\x72\x81\x5B\x82\xC9\x93\x9E\x92\x85\x82\xB7\x82\xE9\x97\x5C\x92\xE8\x82\xC5\x82\xB7\x81\x42"; + + Sounds->AddSound("VIP:Reserve", SoundPriority_1, 9002, GetWorldModuleHandle()); + Sounds->Play("VIP:Reserve", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); + DoDialog(inDoc, 8200, 8200, 1, text); + Sounds->Stop("VIP:Reserve"); + Sounds->DeleteSound("VIP:Reserve"); + + mPeopleID = theVIP->GetPeopleID(); + mTenantID = theTenant->GetEquipID(); + mStatus = kVisitVIPStatus1; + } + } + } else if (thePlugin) { + CString tmp; + thePlugin->GetName(tmp); + + CString str; + // "VIPを招待するには、" - To invite your VIP, + str = "\x56\x49\x50\x82\xF0\x8F\xB5\x91\xD2\x82\xB7\x82\xE9\x82\xC9\x82\xCD\x81\x41"; + str += tmp; + // "の設置が必要です。" - installation is required. + str += "\x82\xCC\x90\xDD\x92\x75\x82\xAA\x95\x4B\x97\x76\x82\xC5\x82\xB7\x81\x42"; + + inDoc->towerDoc_vf13C()->InfoBarMessage(str, 900, NULL); + } else if (!theSpecifier) { + inDoc->mA0 |= mVisitFlag; + mStatus = kVisitVIPStatus4; + } + } + } + } + + return (mStatus != kVisitVIPStatus0); } -/*virtual*/ int T2VisitVIP::Exec(T2TowerDoc*) { +/*virtual*/ int T2VisitVIP::Exec(T2TowerDoc* inDoc) { + int result = 0; + + switch (mStatus) { + case kVisitVIPStatus0: + case kVisitVIPStatus4: + case kVisitVIPStatus5: + mStatus = kVisitVIPStatus0; + result = 3; + } + + if (DoReception(inDoc)) + result = 3; + else + result = IsExclusive() ? 1 : 0; + + return result; } -void T2VisitVIP::Init(CResFile*) { +void T2VisitVIP::Init(CResFile* inResFile) { + *inResFile >> mGrade; + *inResFile >> mTenantPluginID; + *inResFile >> mArrivalTime; + *inResFile >> mArriveAnimResID; + *inResFile >> mSatisfiedSoundID; + *inResFile >> mDissatisfiedSoundID; + + int subResID; + *inResFile >> subResID; + + CResFile subResFile; + if (subResFile.OpenResource(GetWorldDef()->mModuleHandle, subResID, 'VIPL')) + subResFile >> mSilhouetteType; + + *inResFile >> mSatisfiedText; + *inResFile >> mDissatisfiedText; + + mLevelBit = 1 << (mGrade - 1); + mDaysBeforeNextVisit = mCycleDay; + mCycleDay = 1; + + mBeginDay = 0; + mPeopleID = 0; + mTenantID = 0; + + mStatus = kVisitVIPStatus0; + mCheckedIn = false; + + mVisitFlag = 1 << ((mGrade - 1) * 4); + while (mTowerEvent->_88 & mVisitFlag) + mVisitFlag <<= 1; + mTowerEvent->_88 |= mVisitFlag; } -int T2VisitVIP::DoReception(T2TowerDoc*) { +BOOL T2VisitVIP::DoReception(T2TowerDoc* inDoc) { + T2People *thePeople = inDoc->mPeopleArrayList->FindPeople(mPeopleID); + if (thePeople) { + int theSndID; + CString str; + T2Name *theName; + T2Pool *thePool; + + switch (thePeople->GetStatus()) { + case kStatus2: + case kStatus3: + case kStatus4: + if (mStatus < kVisitVIPStatus2) { + Sounds->AddSound("VIP:Arrive", SoundPriority_1, 9001, GetWorldModuleHandle()); + Sounds->Play("VIP:Arrive", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); + + thePeople->GetName(str); + // "様が今ロビーに到着しました。" - You have just arrived at the lobby. + str += "\x97\x6C\x82\xAA\x8D\xA1\x83\x8D\x83\x72\x81\x5B\x82\xC9\x93\x9E\x92\x85\x82\xB5\x82\xDC\x82\xB5\x82\xBD\x81\x42"; + DoDialog(inDoc, 8200, mArriveAnimResID, 1, str); + + Sounds->Stop("VIP:Arrive"); + Sounds->DeleteSound("VIP:Arrive"); + mStatus = kVisitVIPStatus2; + } + break; + + case kStatus1: + if (mStatus < kVisitVIPStatus2) + break; + + thePeople->GetName(str); + // "様が御帰宅なされました。\nあなたのビルに" - You have gone home. In your building + str += "\x97\x6C\x82\xAA\x8C\xE4\x8B\x41\x91\xEE\x82\xC8\x82\xB3\x82\xEA\x82\xDC\x82\xB5\x82\xBD\x81\x42\x0A\x82\xA0\x82\xC8\x82\xBD\x82\xCC\x83\x72\x83\x8B\x82\xC9"; + + theSndID = 0; + if (thePeople->VIPEstimation()) { + // "大変満足した様子です。\n\n「" - I am very satisfied. + str += "\x91\xE5\x95\xCF\x96\x9E\x91\xAB\x82\xB5\x82\xBD\x97\x6C\x8E\x71\x82\xC5\x82\xB7\x81\x42\x0A\x0A\x81\x75"; + str += mSatisfiedText; + inDoc->mA0 |= mVisitFlag; + mStatus = kVisitVIPStatus4; + theSndID = mSatisfiedSoundID; + } else { + // "不満な様子です。\n\n「" - I'm dissatisfied. + str += "\x95\x73\x96\x9E\x82\xC8\x97\x6C\x8E\x71\x82\xC5\x82\xB7\x81\x42\x0A\x0A\x81\x75"; + T2Tenant *theTenant = inDoc->towerDoc_vf12C()->GetTenant(mTenantID); + if (theTenant) { + CString tmp; + + RECT rect; + theTenant->GetEquipArea(rect); + + int floorNum = inDoc->towerDoc_vf12C()->UnitToFloor(rect.top); + if (floorNum < 0) { + str += 'B'; + floorNum = 0 - floorNum; + } + tmp.Format("%d", floorNum); + str += tmp; + // "階の - of the floor + str += "\x8A\x4B\x82\xCC"; + + T2EquipDef *theTenantDef = theTenant->GetEquipDef(); + if (theTenantDef) + theTenantDef->GetToolName(tmp, 0); + str += tmp; + // "は遠すぎる。\n" - is too far + str += "\x82\xCD\x89\x93\x82\xB7\x82\xAC\x82\xE9\x81\x42\x0A"; + } + str += mDissatisfiedText; + mBeginDay += mDaysBeforeNextVisit; + mStatus = kVisitVIPStatus6; + theSndID = mDissatisfiedSoundID; + } + + DoAlert(inDoc, str, theSndID); + + theName = inDoc->mNameDB->Search(thePeople); + if (theName) { + inDoc->mNameDB->RemoveName(theName); + delete theName; + } + + thePool = inDoc->towerDoc_vf130(); + thePool->DeadVIP(thePeople); + + return true; + + case kStatus11: + if (mCheckedIn) { + T2DateTime *theNow = inDoc->mNow; + if (theNow && theNow->GetRawMinutes() == 600) { + T2Tenant *theTenant = inDoc->towerDoc_vf12C()->GetTenant(mTenantID); + if (theTenant && theTenant->IsBelongPeople(thePeople)) { + theTenant->SetStatus(kTenantStatus34); + mCheckedIn = false; + } + } + } + break; + } + } + + return false; } -int T2VisitVIP::GetDestinationTennant(unsigned long, T2Tenant*&, CFilePlugin*&, T2PluginSpecifier*&) { +BOOL T2VisitVIP::GetDestinationTennant(DWORD inPluginID, T2Tenant*& outTenant, CFilePlugin*& outPlugin, T2PluginSpecifier*& outSpecifier) { + BOOL loaded = false; + + T2TowerDoc *theTowerDoc = GetTowerDoc(); + + T2PluginLoader *theT2PluginLoader = theTowerDoc->mT2PluginLoader; + T2PluginSpecifier *theSpecifier; + POSITION pos; + theT2PluginLoader->SetTypeFilter(pos, 'TnPl'); + + while ((theSpecifier = theT2PluginLoader->GetNext(pos))) { + if (theSpecifier->mID == inPluginID) { + outPlugin = theTowerDoc->mTenantPluginsListOther->GetItem(theSpecifier->mID); + outSpecifier = theSpecifier; + break; + } + } + + if (outPlugin) { + T2FloorInfo *theFloorInfo = theTowerDoc->towerDoc_vf12C(); + if (theFloorInfo) { + T2Tenant *theTenant = theFloorInfo->GetTenantByPID(inPluginID); + if (theTenant) { + unsigned int registID = theTenant->GetRegistID(); + if (registID == kTenantRegistID1) { + theTenant = NULL; + T2RegistedTenantDB *theDB = theTowerDoc->towerDoc_vf174(); + if (theDB) { + T2EquipPtrList *theList = theDB->GetList(kTenantRegistID1); + if (theList) { + LArrayIterator iterator(*theList); + T2Tenant *iteratorTenant; + + while (!theTenant && iterator.Next(&iteratorTenant)) { + if (theFloorInfo->GetTenant(iteratorTenant->GetRelatedTenantID())) { + CProgramPlugin *plugin = iteratorTenant->GetEquipDef()->GetPlugin(); + if (plugin) { + if (plugin->GetID() == inPluginID && iteratorTenant->GetStatus() == kTenantStatus30) + theTenant = iteratorTenant; + } + } + } + } + } + } + + outTenant = theTenant; + loaded = true; + } + } + } + + return loaded; } -/*virtual*/ void T2VisitVIP::Write(T2Archive&) { +/*virtual*/ void T2VisitVIP::Write(T2Archive& inArchive) { + unsigned int len = 14; + inArchive << len; + + inArchive << (short) mStatus; + inArchive << mPeopleID; + inArchive << (unsigned short) mTenantID; + inArchive << mVisitFlag; + inArchive << (short) mBeginDay; } -/*virtual*/ void T2VisitVIP::Read(T2Archive&) { +/*virtual*/ void T2VisitVIP::Read(T2Archive& inArchive) { + unsigned int len; + inArchive >> len; + + short s; + unsigned short su; + + inArchive >> s; + mStatus = s; + + inArchive >> mPeopleID; + + inArchive >> su; + mTenantID = su; + + inArchive >> mVisitFlag; + + inArchive >> s; + mBeginDay = s; } diff --git a/src/T2DLL/T2VisitVIP.h b/src/T2DLL/T2VisitVIP.h index 0d97c07..b2510b5 100644 --- a/src/T2DLL/T2VisitVIP.h +++ b/src/T2DLL/T2VisitVIP.h @@ -1,22 +1,48 @@ #pragma once #include "common.h" +#include "T2EventItem.h" -class T2VisitVIP { +enum { + kVisitVIPStatus0 = 0, + kVisitVIPStatus1 = 1, + kVisitVIPStatus2 = 2, + kVisitVIPStatus3 = 3, + kVisitVIPStatus4 = 4, + kVisitVIPStatus5 = 5, + kVisitVIPStatus6 = 6, +}; + +class AFX_EXT_CLASS T2VisitVIP : public T2EventItem { public: - T2VisitVIP(T2TowerEvent*, CResFile*, int); - T2VisitVIP(T2TowerEvent*, int, int, int, int, int, int); + T2VisitVIP(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID); + T2VisitVIP(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime); virtual ~T2VisitVIP(); - virtual int IsBeginDay(int); - virtual int IsBeginTime(unsigned int); - virtual int Start(T2TowerDoc*); - virtual int Exec(T2TowerDoc*); - void Init(CResFile*); - int DoReception(T2TowerDoc*); - int GetDestinationTennant(unsigned long, T2Tenant*&, CFilePlugin*&, T2PluginSpecifier*&); - virtual void Write(T2Archive&); - virtual void Read(T2Archive&); + virtual DWORD GetID() { return 'ViEv'; } + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc* inDoc); + virtual BOOL IsBeginTime(unsigned int inTime); + virtual BOOL IsBeginDay(int inDay); + virtual void Write(T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); + + void Init(CResFile* inResFile); + BOOL DoReception(T2TowerDoc* inDoc); + BOOL GetDestinationTennant(DWORD inPluginID, T2Tenant*& outTenant, CFilePlugin*& outPlugin, T2PluginSpecifier*& outSpecifier); - virtual unsigned long GetID() {} - T2VisitVIP(const T2VisitVIP&) {} - T2VisitVIP& operator=(const T2VisitVIP&) {} +protected: + int mGrade; + DWORD mTenantPluginID; + int mArrivalTime; + int mArriveAnimResID; + int mSatisfiedSoundID; + int mDissatisfiedSoundID; + int mSilhouetteType; + CString mSatisfiedText; + CString mDissatisfiedText; + unsigned int mVisitFlag; + unsigned int mPeopleID; // who the VIP is + unsigned int mTenantID; + int mDaysBeforeNextVisit; + int mBeginDay; + BOOL mCheckedIn; }; diff --git a/src/T2DLL/T2WeatherFilter.h b/src/T2DLL/T2WeatherFilter.h index 257cd2b..a1213c2 100644 --- a/src/T2DLL/T2WeatherFilter.h +++ b/src/T2DLL/T2WeatherFilter.h @@ -8,7 +8,7 @@ enum WeatherCode { WeatherCode_3 }; -class DLL_EXPORT T2WeatherFilter { +class AFX_EXT_CLASS T2WeatherFilter { public: T2WeatherFilter(); ~T2WeatherFilter(); diff --git a/src/T2DLL/T2WordDef.h b/src/T2DLL/T2WordDef.h index e3e1aa4..e6084ae 100644 --- a/src/T2DLL/T2WordDef.h +++ b/src/T2DLL/T2WordDef.h @@ -1,7 +1,7 @@ #pragma once #include "common.h" -class DLL_EXPORT T2WordDef { +class AFX_EXT_CLASS T2WordDef { public: T2WordDef(); void Read(CResFile&); diff --git a/src/T2DLL/T2WorldDef.cpp b/src/T2DLL/T2WorldDef.cpp index 9829b68..f9dbfbd 100644 --- a/src/T2DLL/T2WorldDef.cpp +++ b/src/T2DLL/T2WorldDef.cpp @@ -1,271 +1,1618 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2ColdTableDef.h" +#include "T2DateTime.h" +#include "T2DlgItemAnimation.h" +#include "T2FInfoAreaIterator.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2Message.h" +#include "T2MWControl.h" +#include "T2PaletteAnime.h" +#include "T2PaletteAnimeDef.h" +#include "T2Pool.h" +#include "T2PoolDef.h" +#include "T2SeasonParamDef.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2WordDefArray.h" #include "T2WorldDef.h" - -T2WorldDef::T2WorldDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldPlugin*) { +#include "T2WorldPlugin.h" +#include "URect.h" +#include "UT2BkgndInfo.h" +#include "UT2Coordinate.h" + +T2WorldDef::T2WorldDef(DWORD inType, T2PluginSpecifier& inSpecifier, CResFile* inResFile, T2WorldPlugin* inPlugin) + : T2TemplatePlugin(inType, inSpecifier, inResFile, inPlugin) +{ + int i; + int a; + + m1D0 = new T2ImageObj; + + *inResFile >> mWorldType; + *inResFile >> mHeight; + *inResFile >> mWidth; + *inResFile >> mGroundLine; + *inResFile >> mBuildArea; + *inResFile >> mInitPos; + *inResFile >> mTopFloorLine; + *inResFile >> mBottomFloorLine; + *inResFile >> m70; + *inResFile >> m74; + *inResFile >> mLobbyHeight; + *inResFile >> mOutViewKind; + *inResFile >> m17C; + *inResFile >> m228; + *inResFile >> mNumOfGradeDef; + + for (i = 0; i < 8; i++) { + if (i < mNumOfGradeDef) { + *inResFile >> mGradeDef[i].m0; + *inResFile >> mGradeDef[i].m4; + *inResFile >> mGradeDef[i].m8; + *inResFile >> mGradeDef[i].mC; + *inResFile >> mGradeDef[i].m10; + *inResFile >> mGradeDef[i].m14; + } else { + mGradeDef[i].m0 = 0; + mGradeDef[i].m4 = 0; + mGradeDef[i].m8 = 0; + mGradeDef[i].mC = 0; + mGradeDef[i].m10 = 0; + mGradeDef[i].m14 = 0; + } + } + + *inResFile >> mBGVUnit; + *inResFile >> mBGHUnit; + *inResFile >> mSkyVSize; + *inResFile >> mSkyHSize; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> a; + *inResFile >> m148[0]; + *inResFile >> m148[1]; + *inResFile >> m148[2]; + *inResFile >> m148[3]; + *inResFile >> m148[4]; + *inResFile >> m15C; + *inResFile >> mDustOnThreshold; + *inResFile >> mToiletVar1; + *inResFile >> mToiletVar2; + *inResFile >> a; + + memset(mCashAmount, 0, sizeof(mCashAmount)); + int numOfCashAmount; + *inResFile >> numOfCashAmount; + + for (i = 0; i < numOfCashAmount; i++) { + int v; + *inResFile >> v; + if (i < 8) + mCashAmount[i] = v; + } + + CResFile resFile; + resFile.OpenResource(mModuleHandle, 128, 'WAtr'); + + resFile >> a; + resFile >> a; + resFile >> a; + resFile >> a; + resFile >> a; + resFile >> a; + resFile >> mInitialFunds; + resFile >> mMoneyNumerator; + resFile >> mMoneyDenominator; + resFile >> mMoneyUnit; + + mSkyOffscreen = NULL; + m1A0 = NULL; + m1AC = NULL; + m1B0 = NULL; + for (i = 0; i < 2; i++) + m1A4[i] = NULL; + mImage = NULL; + m1C4 = NULL; + m1C8 = NULL; + m1CC = NULL; + + mWordDefArray = new T2WordDefArray(mModuleHandle); + mPaletteAnimeDef = MakePaletteAnimeDef(); + SetupOffscreen(mModuleHandle); + mPoolDef = MakePoolDef(); + mSeasonParamDef = MakeSeasonParamDef(); + mColdTableDef = MakeColdTableDef(); + + m190.x = 0; + m190.y = 0; + int craneObjectID = mImageObj->FindObject("OutCrane"); + if (craneObjectID >= 0) { + mImageObj->GetObjectSize(craneObjectID, (SIZE *) &m190); + UT2Coordinate::QDToUnit(m190, 0); + } + + _210 = 0; + _214 = false; + mIsLoaded = true; } T2PaletteAnimeDef* T2WorldDef::MakePaletteAnimeDef() { + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, 'PtDf'); + T2PaletteAnimeDef *theAnimeDef = new T2PaletteAnimeDef(mModuleHandle, &resFile); + return theAnimeDef; } T2PoolDef* T2WorldDef::MakePoolDef() { + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, 'PoDf'); + T2PoolDef *thePoolDef = new T2PoolDef(resFile, (T2WorldPlugin *) mPlugin); + return thePoolDef; } T2SeasonParamDef* T2WorldDef::MakeSeasonParamDef() { + CResFile resFile; + T2SeasonParamDef *theSeasonDef = NULL; + + if (resFile.OpenResource(mModuleHandle, 1, 'SpDf')) { + theSeasonDef = new T2SeasonParamDef(resFile); + resFile.End(); + } + + return theSeasonDef; } T2ColdTableDef* T2WorldDef::MakeColdTableDef() { + CResFile resFile; + T2ColdTableDef *theTableDef = NULL; + + if (resFile.OpenResource(mModuleHandle, 1, 'CoDf')) { + theTableDef = new T2ColdTableDef(resFile); + resFile.End(); + } + + return theTableDef; } /*virtual*/ T2WorldDef::~T2WorldDef() { -} + DisposePalette(); + DisposeOffscreen(); -/*virtual*/ void T2WorldDef::GetName(CString&) { -} + if (mImage) + delete mImage; -/*virtual*/ void T2WorldDef::DrawWorld(T2TowerDoc*) { -} + delete m1D0; + m1D0 = NULL; -/*virtual*/ void T2WorldDef::DrawBkgnd(unsigned int, const RECT&, T2TowerDoc*) { -} + delete mPoolDef; + delete mWordDefArray; -/*virtual*/ void T2WorldDef::DrawBkgnd(const RECT&, T2TowerDoc*) { + if (mTowerEvent) + delete mTowerEvent; } -/*virtual*/ void T2WorldDef::DrawRoofAndFloor(const RECT&, T2TowerDoc*, ROOFANDFLOOR) { +/*virtual*/ void T2WorldDef::GetName(CString& outStr) { + outStr = (char) mWorldType; } -/*virtual*/ void T2WorldDef::DrawSideObj(T2Equip*, T2TowerDoc*, SIDEOBJPATTERN) { -} +/*virtual*/ void T2WorldDef::DrawWorld(T2TowerDoc* inDoc) { + RECT srcRect; + SetRect(&srcRect, 0, 0, 64, 72); -/*virtual*/ void T2WorldDef::DrawCrane(T2TowerDoc*, const RECT&) { -} + RECT destRect = srcRect; -/*virtual*/ void T2WorldDef::CalcCranePos(T2TowerDoc*) { + mImage->CopyImage(*inDoc->towerDoc_vf10C(), srcRect, destRect); } -/*virtual*/ void T2WorldDef::ClearCranePos(T2TowerDoc*) { -} +/*virtual*/ void T2WorldDef::DrawBkgnd(unsigned int inImageIndex, const RECT& inDestRect, T2TowerDoc* inDoc) { + int width = mBGHUnit; + int height = mBGVUnit; + + RECT srcRect; + SetRect(&srcRect, 0, 0, width, height); + OffsetRect(&srcRect, 0, inImageIndex * height); + + RECT destRect = inDestRect; + UT2Coordinate::BkgndToQD(destRect, inDoc->towerDoc_vf108()); -/*virtual*/ void T2WorldDef::DrawBuild(T2Equip*, T2TowerDoc*) { + mSkyOffscreen->CopyImage(*inDoc->towerDoc_vf10C(), srcRect, destRect); } -void T2WorldDef::SetupOffscreen(HINSTANCE) { +/*virtual*/ void T2WorldDef::DrawBkgnd(const RECT& inRect, T2TowerDoc* inDoc) { + if (m228) { + BkgndInfo *infoPtr = inDoc->mBkgndInfo; + for (int v = inRect.top; v < inRect.bottom; v++) { + for (int h = inRect.left; h < inRect.right; h++) { + unsigned int imageIndex = UT2BkgndInfo::GetBkgndInfo(infoPtr, v, h); + + RECT rect; + SetRect(&rect, h, v, h + 1, v + 1); + DrawBkgnd(imageIndex, rect, inDoc); + } + } + } else { + RECT srcRect = inRect; + srcRect.top *= mBGVUnit; + srcRect.left *= mBGHUnit; + srcRect.bottom *= mBGVUnit; + srcRect.right *= mBGHUnit; + + RECT destRect; + UT2Coordinate::BkgndToQD(inRect, destRect, inDoc->towerDoc_vf108()); + + mSkyOffscreen->CopyImage(*inDoc->towerDoc_vf10C(), srcRect, destRect); + } +} + +/*virtual*/ void T2WorldDef::DrawRoofAndFloor(const RECT& inRect, T2TowerDoc* inDoc, ROOFANDFLOOR inRoofAndFloor) { + RECT unitRect = inRect; + RECT qdRect; + int id; + + if (inRoofAndFloor & RoofAndFloor_Roof) { + UT2Coordinate::UnitToQDRoof(unitRect, qdRect, inDoc->mZoomLevel); + id = mImageObj->FindObject("Roof"); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), id, qdRect, inDoc->towerDoc_vf108()); + } + + if (inRoofAndFloor & RoofAndFloor_Floor) { + UT2Coordinate::UnitToQDFloor(unitRect, qdRect, inDoc->mZoomLevel); + id = mImageObj->FindObject("Floor"); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), id, qdRect, inDoc->towerDoc_vf108()); + } +} + +/*virtual*/ void T2WorldDef::DrawSideObj(T2Equip* inEquip, T2TowerDoc* inDoc, SIDEOBJPATTERN inSideObjPattern) { + if (inSideObjPattern == SideObjPattern_0 || inSideObjPattern == SideObjPattern_1) { + CString name1, name2; + + if (((T2Tenant *) inEquip)->IsFloor() && inEquip->mValiation == 1) + name1 = "Tent"; + else + name1 = "Side"; + + if (inSideObjPattern == SideObjPattern_0) + name2 = "L"; + else + name2 = "R"; + + int numPattern = 0; + if (inDoc->towerDoc_vf140() == ViewMode_1) { + numPattern = 1; + if (inDoc->towerDoc_vf160()->IsSnow()) + numPattern = 2; + } + + int objectID = mImageObj->FindObject(name1 + name2, numPattern); + + SIZE size; + mImageObj->GetObjectSize(objectID, &size); + + size.cx = size.cx / 8; + size.cy = (size.cy + 35) / 36; + + RECT unitRect, rect; + if (inSideObjPattern == SideObjPattern_0) { + unitRect.right = inEquip->mArea.left; + unitRect.left = unitRect.right - size.cx; + } else if (inSideObjPattern == SideObjPattern_1) { + unitRect.left = inEquip->mArea.right; + unitRect.right = unitRect.left + size.cx; + } + + if (((T2Tenant *) inEquip)->IsFloor() && inEquip->mValiation == 1) { + unitRect.bottom = inEquip->mArea.bottom; + unitRect.top = unitRect.bottom - size.cy; + UT2Coordinate::UnitToQD(unitRect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + + objectID = mImageObj->FindObject("Side" + name2, numPattern); + mImageObj->GetObjectSize(objectID, &size); + + size.cx = size.cx / 8; + size.cy = (size.cy + 35) / 36; + + if (inSideObjPattern == SideObjPattern_0) { + unitRect.right = inEquip->mArea.left; + unitRect.left = unitRect.right - size.cx; + } else if (inSideObjPattern == SideObjPattern_1) { + unitRect.left = inEquip->mArea.right; + unitRect.right = unitRect.left + size.cx; + } + + unitRect.top = inEquip->mArea.top; + unitRect.bottom = unitRect.top + size.cy; + + for (int v = inEquip->mArea.top; v < (inEquip->mArea.bottom - 1); v++) { + UT2Coordinate::UnitToQD(unitRect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + + unitRect.top++; + unitRect.bottom++; + } + } else if (((T2TenantDef *) inEquip->GetEquipDef())->m198 && !((T2TenantDef *) inEquip->GetEquipDef())->m194) { + unitRect.bottom = inEquip->mArea.bottom; + unitRect.top = unitRect.bottom - size.cy; + UT2Coordinate::UnitToQD(unitRect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + } else if (!((T2TenantDef *) inEquip->GetEquipDef())->m198 && ((T2TenantDef *) inEquip->GetEquipDef())->m194) { + unitRect.top = inEquip->mArea.top; + unitRect.bottom = unitRect.top + -size.cy; + UT2Coordinate::UnitToQD(unitRect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + } else if (((T2TenantDef *) inEquip->GetEquipDef())->m198 && ((T2TenantDef *) inEquip->GetEquipDef())->m194) { + unitRect.top = inEquip->mArea.top; + unitRect.bottom = unitRect.top + size.cy; + + for (int v = inEquip->mArea.top; v < inEquip->mArea.bottom; v++) { + UT2Coordinate::UnitToQD(unitRect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + + unitRect.top++; + unitRect.bottom++; + } + } + } +} + +/*virtual*/ void T2WorldDef::DrawCrane(T2TowerDoc* inDoc, const RECT& inRect) { + T2FloorInfo *floorInfo = inDoc->towerDoc_vf12C(); + T2BitImage *theViewImage = inDoc->GetTowerMainView()->m60; + int theZoomLevel = inDoc->mZoomLevel; + + RECT craneArea; + craneArea.top = 0; + craneArea.left = 0; + craneArea.bottom = m190.y; + craneArea.right = m190.x; + + int id = mImageObj->FindObject("OutCrane"); + if (id >= 0) { + for (int i = 0; i < inDoc->mCraneCount; i++) { + RECT unitRect, qdRect, intersection; + + unitRect = craneArea; + OffsetRect(&unitRect, inDoc->mCranePosArray[i].x, inDoc->mCranePosArray[i].y); + + if (IntersectRect(&intersection, &inRect, &unitRect)) { + UT2Coordinate::UnitToQD(unitRect, qdRect, theZoomLevel, true); + mImageObj->DrawObject(theViewImage, id, qdRect, theZoomLevel); + } + } + } +} + +/*virtual*/ void T2WorldDef::CalcCranePos(T2TowerDoc* inDoc) { + int count = 0; + POINT *array = (POINT *) malloc(GetWidth() * sizeof(POINT) / m190.x); + + T2FloorInfo *floorInfo = inDoc->towerDoc_vf12C(); + + RECT rect; + SetRect(&rect, 0, 0, GetWidth(), mGroundLine); + + T2FInfoAreaIterator iterator(*floorInfo, rect); + T2Tenant *theTenant; + + ClearCranePos(inDoc); + + while (iterator.NextTenant(theTenant)) { + T2Tenant *theFloor; + if (theTenant->IsFloor()) + theFloor = theTenant; + else + theFloor = floorInfo->GetTenant(theTenant->GetFloorID(theTenant->mArea.top)); + + BOOL valid = true; + if (theTenant->mArea.top < mTopFloorLine || (theTenant->mArea.right - theTenant->mArea.left) < 6) + valid = false; + + if (valid) { + RECT rect2; + rect2.left = theFloor->mArea.left; + rect2.bottom = theFloor->mArea.top; + rect2.right = theFloor->mArea.right; + rect2.top = rect2.bottom - 1; + + T2FInfoAreaIterator iterator2(*floorInfo, rect2); + T2Tenant *theTenant2; + + while (iterator2.NextTenant(theTenant2)) { + T2Tenant *theFloor2; + if (theTenant2->IsFloor()) + theFloor2 = theTenant2; + else + theFloor2 = floorInfo->GetTenant(theTenant2->GetFloorID(-1)); + + if ((theFloor2->mArea.right - theFloor2->mArea.left) >= 6) { + valid = false; + break; + } + } + } + + if (valid) { + RECT rect2; + rect2.left = theFloor->mArea.left; + rect2.bottom = theFloor->mArea.top; + rect2.right = theFloor->mArea.left + 6; + rect2.top = rect2.bottom - 1; + + T2FInfoAreaIterator iterator2(*floorInfo, rect2); + T2Tenant *theTenant2; + if (iterator2.NextTenant(theTenant2)) + valid = false; + } + + if (valid) { + if (floorInfo->GetTenantID(theFloor->mArea.top, theFloor->mArea.left - 1)) + valid = false; + } + + if (valid) { + array[count].x = theFloor->mArea.left; + array[count].y = theFloor->mArea.top - m190.y; + count++; + } + } + + if (count) { + inDoc->mCranePosArray = (POINT *) malloc(count * sizeof(POINT)); + inDoc->mCraneCount = count; + memcpy(inDoc->mCranePosArray, array, count * sizeof(POINT)); + } + + free(array); +} + +/*virtual*/ void T2WorldDef::ClearCranePos(T2TowerDoc* inDoc) { + if (inDoc->mCranePosArray) + free(inDoc->mCranePosArray); + + inDoc->mCranePosArray = NULL; + inDoc->mCraneCount = 0; +} + +/*virtual*/ void T2WorldDef::DrawBuild(T2Equip* inEquip, T2TowerDoc* inDoc) { + RECT area; + inEquip->GetEquipArea(area); + + int pattern; + if (inEquip->GetStatus() < 2) + pattern = 0; + else + pattern = 1; + + int objIndex = mImageObj->FindObject("BuildPrc", pattern); + + for (int v = area.top; v < area.bottom; v++) { + RECT rect = area; + rect.top = v; + rect.bottom = rect.top + 1; + + UT2Coordinate::UnitToQD(rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objIndex, rect, inDoc->towerDoc_vf108()); + } +} + +void T2WorldDef::SetupOffscreen(HINSTANCE inModule) { + // background + mSkyOffscreen = new T2BitImage(inModule, 1000, true); + + // emergency stairs (side of building) + m1A4[0] = new T2BitImage(inModule, 1002, true); + mImageObj->AddObject(inModule, 1002, m1A4[0]); + + // side of lobby + m1A4[1] = new T2BitImage(inModule, 1003, true); + mImageObj->AddObject(inModule, 1003, m1A4[1]); + + // under-construction floor + m1AC = new T2BitImage(inModule, 1004, true); + mImageObj->AddObject(inModule, 1004, m1AC); + + // some person + m1B0 = new T2BitImage(inModule, 1005, true); + mImageObj->AddObject(inModule, 1005, m1B0); + + // tool buttons + m1B4 = new T2BitImage(inModule, 2000, true); + m1D0->AddObject(inModule, 2000, m1B4); + + // message window + m1B8 = new T2BitImage(inModule, 10000, true); + mImageObj->AddObject(inModule, 10000, m1B8); + + // control window + m1BC = new T2BitImage(inModule, 10001, true); + mImageObj->AddObject(inModule, 10001, m1BC); + + // dialog sprites + m1C0 = new T2BitImage(inModule, 10002, true); + mImageObj->AddObject(inModule, 10002, m1C0); + + // crane + m1C4 = new T2BitImage(inModule, 3000, true); + mImageObj->AddObject(inModule, 3000, m1C4); + + // icons shown over tenants + m1C8 = new T2BitImage(inModule, 1006, true); + mImageObj->AddObject(inModule, 1006, m1C8); + + try { + // burning floor + m1CC = new T2BitImage(inModule, 1007, true); + mImageObj->AddObject(inModule, 1007, m1CC); + } catch (int x) { + } } void T2WorldDef::DisposeOffscreen() { + if (mSkyOffscreen) + delete mSkyOffscreen; + + if (m1A0) + delete m1A0; + + for (int i = 0; i < 2; i++) { + if (m1A4[i]) + delete m1A4[i]; + } + + if (m1AC) + delete m1AC; + + if (m1B0) + delete m1B0; + + if (m1B4) + delete m1B4; + + delete m1B8; + delete m1BC; + delete m1C0; + delete m1C4; + delete m1C8; + + if (m1CC) + delete m1CC; } -void T2WorldDef::SetupPalette(HINSTANCE) { +void T2WorldDef::SetupPalette(HINSTANCE inModule) { } void T2WorldDef::DisposePalette() { } -/*virtual*/ void T2WorldDef::DoAnimate(T2TowerDoc*) { -} +/*virtual*/ void T2WorldDef::DoAnimate(T2TowerDoc* inDoc) { +} + +/*virtual*/ BOOL T2WorldDef::TenantAreaCheck(T2TowerDoc* inDoc, RECT& inRect, BOOL inShowMessage) { + if (inRect.bottom != mGroundLine) { + int v, h; + + v = mGroundLine - 1; + for (h = inRect.left; h < inRect.right; h++) { + if (!inDoc->mFloorInfo->GetTenant(v, h)) { + if (inShowMessage) { + // "1Fのフロアからはみ出して設置することはできません" + // It cannot be installed protruding from the 1F floor. + (new T2Message)->ShowMessage("\x82\x50\x82\x65\x82\xCC\x83\x74\x83\x8D\x83\x41\x82\xA9\x82\xE7\x82\xCD\x82\xDD\x8F\x6F\x82\xB5\x82\xC4\x90\xDD\x92\x75\x82\xB7\x82\xE9\x82\xB1\x82\xC6\x82\xCD\x82\xC5\x82\xAB\x82\xDC\x82\xB9\x82\xF1"); + } + + return false; + } + } + } + + return true; +} + +/*virtual*/ int T2WorldDef::IdleProc(T2TowerDoc* inDoc) { + return mTowerEvent->Idle(inDoc); +} + +/*virtual*/ void T2WorldDef::DrawCtrl(T2TowerDoc* inDoc, T2MWControl* inControl) { + T2Pool *thePool; + int population; + + switch (inControl->GetDlgCtrlID()) { + case 1000: + DrawClock(inControl, *inDoc->mNow); + break; + case 1001: + DrawCalendar(inControl, *inDoc->mNow, inDoc); + break; + case 1002: + DrawFunds(inControl, inDoc->towerDoc_vf26C()); + break; + case 2000: + DrawPauseButton(inControl); + break; + case 1004: + DrawMessage(inControl); + break; + case 1003: + thePool = inDoc->towerDoc_vf130(); +#line 755 + _ASSERT(thePool != NULL); + population = thePool->GetPopulation(); + DrawPopulation(inControl, population); + break; + case 2001: + DrawInViewButton(inControl); + break; + case 2006: + DrawOutViewButton(inControl); + break; + case 2004: + DrawMaintButton(inControl); + break; + case 2003: + DrawEvalButton(inControl); + break; + case 2002: + DrawPriceButton(inControl); + break; + case 2005: + DrawTransButton(inControl); + break; + case 2007: + DrawSlider(inControl); + break; + } +} + +/*virtual*/ void T2WorldDef::ButtonDownOnCtrl(T2TowerDoc* inDoc, T2MWControl* inControl, CPoint inPt, CWnd* inWnd) { + inControl->SetCapture(); + int pattern = inControl->GetData(); + int newValue; + + switch (inControl->GetDlgCtrlID()) { + case 1000: + case 1001: + case 1002: + case 1003: + if (pattern < 100) + inControl->SetData(pattern + 100); + break; + + case 2000: + if (pattern == 0) { + _214 = true; + inControl->SetData(100); + ClickPauseButton(inControl, inDoc); + } else { + _214 = false; + } + break; + + case 2001: + ClickInViewButton(inControl, inDoc); + goto refreshButtons; + case 2006: + ClickOutViewButton(inControl, inDoc); + goto refreshButtons; + case 2004: + ClickMaintButton(inControl, inDoc); + goto refreshButtons; + case 2003: + ClickEvalButton(inControl, inDoc); + goto refreshButtons; + case 2002: + ClickPriceButton(inControl, inDoc); + goto refreshButtons; + case 2005: + ClickTransButton(inControl, inDoc); + refreshButtons: + ((T2MWControl *) inWnd->GetDlgItem(2001))->SetData(0); + ((T2MWControl *) inWnd->GetDlgItem(2006))->SetData(0); + ((T2MWControl *) inWnd->GetDlgItem(2004))->SetData(0); + ((T2MWControl *) inWnd->GetDlgItem(2003))->SetData(0); + ((T2MWControl *) inWnd->GetDlgItem(2002))->SetData(0); + ((T2MWControl *) inWnd->GetDlgItem(2005))->SetData(0); + inControl->SetData(100); + break; + + case 2007: + newValue = SliderPointToValue(inControl, inPt); + if (newValue != inControl->GetData()) { + inControl->SetData(newValue); + if (newValue == 0) + inDoc->towerDoc_vf14C(-1); + else + inDoc->towerDoc_vf14C(7 - newValue); + } + break; + } +} + +/*virtual*/ void T2WorldDef::ButtonUpOnCtrl(T2TowerDoc* inDoc, T2MWControl* inControl, CPoint inPt, CWnd* inWnd) { + if (GetCapture() == inControl->m_hWnd) { + ReleaseCapture(); + + int pattern = inControl->GetData(); + + switch (inControl->GetDlgCtrlID()) { + case 1000: + ClickClock(inControl, inDoc); + break; + case 1001: + ClickCalendar(inControl, inDoc); + break; + case 1002: + ClickFunds(inControl, inDoc); + break; + case 1003: + ClickPopulation(inControl, inDoc); + break; + + case 2000: + if (!_214) { + inControl->SetData(0); + ClickPauseButton(inControl, inDoc); + } + break; + } + } +} + +/*virtual*/ void T2WorldDef::MouseMoveOnCtrl(T2TowerDoc* inDoc, T2MWControl* inControl, CPoint inPt, CWnd* inWnd) { + int newValue; + + if (GetCapture() == inControl->m_hWnd) { + switch (inControl->GetDlgCtrlID()) { + case 2007: + newValue = SliderPointToValue(inControl, inPt); + if (newValue != inControl->GetData()) { + inControl->SetData(newValue); + if (newValue == 0) + inDoc->towerDoc_vf14C(-1); + else + inDoc->towerDoc_vf14C(7 - newValue); + } + break; + } + } +} + +/*virtual*/ void T2WorldDef::ClickClock(T2MWControl* inControl, T2TowerDoc* inDoc) { + int value = inControl->GetData(); + if (value >= 100) + value -= 100; + inControl->SetData(value); +} + +/*virtual*/ void T2WorldDef::ClickCalendar(T2MWControl* inControl, T2TowerDoc* inDoc) { + int value = inControl->GetData(); + if (value >= 100) + value -= 100; + inControl->SetData(value); + inDoc->CallbackCalendar(); +} + +/*virtual*/ void T2WorldDef::ClickFunds(T2MWControl* inControl, T2TowerDoc* inDoc) { + int value = inControl->GetData(); + if (value >= 100) + value -= 100; + inControl->SetData(value); + inDoc->CallbackFunds(); +} + +/*virtual*/ void T2WorldDef::ClickPopulation(T2MWControl* inControl, T2TowerDoc* inDoc) { + int value = inControl->GetData(); + if (value >= 100) + value -= 100; + inControl->SetData(value); + inDoc->CallbackPopulation(); +} + +/*virtual*/ void T2WorldDef::DrawClock(T2MWControl* inControl, T2DateTime& inDateTime) { +#pragma var_order(angle, dc2, theImage, save2, save, x, hours, y, imageRect, rect2, objectID, minutes, bitmap, pDC) + int objectID = mImageObj->FindObject("Clock", 1); + + RECT imageRect; + T2BitImage *theImage = mImageObj->GetObjectImage(objectID, imageRect); + + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + CDC dc2; + dc2.CreateCompatibleDC(pDC); + int save2 = dc2.SaveDC(); + dc2.SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + dc2.RealizePalette(); + + HBITMAP bitmap = Create256DIBitmap(dc2.m_hDC, rect2.right, rect2.bottom); + SelectObject(dc2.m_hDC, bitmap); -/*virtual*/ int T2WorldDef::TenantAreaCheck(T2TowerDoc*, RECT&, int) { -} + theImage->CopyImage(&dc2, imageRect, rect2); -/*virtual*/ int T2WorldDef::IdleProc(T2TowerDoc*) { -} + float hours = inDateTime.GetHour() + inDateTime.GetMinutes() / 60.0f; + float angle = (6.283186f * hours) / 12.0f; -/*virtual*/ void T2WorldDef::DrawCtrl(T2TowerDoc*, T2MWControl*) { -} + int x = (rect2.right / 2) + (rect2.right * 0.3 * sin(angle)) + 0.5; + int y = (rect2.bottom / 2) - (rect2.bottom * 0.3 * cos(angle)) + 0.5; + dc2.MoveTo(rect2.right / 2, rect2.bottom / 2); + dc2.LineTo(x, y); -/*virtual*/ void T2WorldDef::ButtonDownOnCtrl(T2TowerDoc*, T2MWControl*, CPoint, CWnd*) { -} + float minutes = inDateTime.GetMinutes(); + angle = (6.283186f * minutes) / 60.0f; -/*virtual*/ void T2WorldDef::ButtonUpOnCtrl(T2TowerDoc*, T2MWControl*, CPoint, CWnd*) { -} + x = (rect2.right / 2) + (rect2.right * 0.4 * sin(angle)) + 0.5; + y = (rect2.bottom / 2) - (rect2.bottom * 0.4 * cos(angle)) + 0.5; + dc2.MoveTo(rect2.right / 2, rect2.bottom / 2); + dc2.LineTo(x, y); -/*virtual*/ void T2WorldDef::MouseMoveOnCtrl(T2TowerDoc*, T2MWControl*, CPoint, CWnd*) { -} + pDC->BitBlt(0, 0, rect2.right, rect2.bottom, &dc2, 0, 0, SRCCOPY); -/*virtual*/ void T2WorldDef::ClickClock(T2MWControl*, T2TowerDoc*) { -} + dc2.RestoreDC(save2); + dc2.DeleteDC(); -/*virtual*/ void T2WorldDef::ClickCalendar(T2MWControl*, T2TowerDoc*) { -} + DeleteObject(bitmap); -/*virtual*/ void T2WorldDef::ClickFunds(T2MWControl*, T2TowerDoc*) { + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::ClickPopulation(T2MWControl*, T2TowerDoc*) { -} +/*virtual*/ void T2WorldDef::DrawCalendar(T2MWControl* inControl, T2DateTime& inDateTime, T2TowerDoc* inDoc) { +#pragma var_order(year, imageRect, tempDC, theImage, save2, text, rect3, month, font, save, rect2, pattern, theBitmap, pDC) + int pattern = inControl->GetData(); -/*virtual*/ void T2WorldDef::DrawClock(T2MWControl*, T2DateTime&) { -} + RECT imageRect; + T2BitImage *theImage = mImageObj->GetObjectImage(mImageObj->FindObject("Calendar", pattern), imageRect); + + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + CDC tempDC; + tempDC.CreateCompatibleDC(pDC); + int save2 = tempDC.SaveDC(); + tempDC.SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + tempDC.RealizePalette(); + + HBITMAP theBitmap = Create256DIBitmap(tempDC.m_hDC, rect2.right, rect2.bottom); + SelectObject(tempDC.m_hDC, theBitmap); + + m1B8->CopyImage(&tempDC, imageRect, rect2); + + CRect rect3 = rect2; + rect3.top += 2; + rect3.left += 2; + rect3.bottom -= 2; + rect3.right -= 2; + + if (pattern == 100) + rect3.OffsetRect(1, 1); -/*virtual*/ void T2WorldDef::DrawCalendar(T2MWControl*, T2DateTime&, T2TowerDoc*) { + CFont font; + font.CreateFont(-rect3.Height(), 0, 0, 0, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + tempDC.SelectObject(&font); + tempDC.SetBkMode(TRANSPARENT); + + int year = inDateTime.GetYear(); + int month = inDateTime.GetMonth(); + tempDC.SetTextAlign(TA_UPDATECP); + tempDC.MoveTo(rect3.left, rect3.top); + + char text[80]; + wsprintf(text, "\x91\xE6%d\x8A\xFA %d\x8C\x8E ", year, month); + tempDC.TextOut(0, 0, text, strlen(text)); + + if (inDateTime.IsHoliday(inDoc)) { + lstrcpy(text, "\x8B\x78\x93\xFA"); + tempDC.SetTextColor(PALETTERGB(192, 0, 0)); + } else { + lstrcpy(text, "\x95\xBD\x93\xFA"); + } + tempDC.TextOut(0, 0, text, strlen(text)); + + tempDC.SetTextColor(RGB(0, 0, 0)); + tempDC.SetTextAlign(TA_NOUPDATECP); + + pDC->BitBlt(0, 0, rect2.right, rect2.bottom, &tempDC, 0, 0, SRCCOPY); + + tempDC.RestoreDC(save2); + tempDC.DeleteDC(); + + DeleteObject(theBitmap); + font.DeleteObject(); + + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::DrawFunds(T2MWControl*, int) { +/*virtual*/ void T2WorldDef::DrawFunds(T2MWControl* inControl, int inFunds) { +#pragma var_order(imageRect, tempDC, theImage, save2, text, rect3, font, save, rect2, pattern, theBitmap, pDC) + int pattern = inControl->GetData(); + + RECT imageRect; + T2BitImage *theImage = mImageObj->GetObjectImage(mImageObj->FindObject("Funds", pattern), imageRect); + + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + CDC tempDC; + tempDC.CreateCompatibleDC(pDC); + int save2 = tempDC.SaveDC(); + tempDC.SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + tempDC.RealizePalette(); + + HBITMAP theBitmap = Create256DIBitmap(tempDC.m_hDC, rect2.right, rect2.bottom); + SelectObject(tempDC.m_hDC, theBitmap); + + m1B8->CopyImage(&tempDC, imageRect, rect2); + + CRect rect3 = rect2; + rect3.top += 2; + rect3.left += 11; + rect3.bottom -= 2; + rect3.right -= 23; + + if (pattern == 100) + rect3.OffsetRect(1, 1); + + CFont font; + font.CreateFont(-rect3.Height(), 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + tempDC.SelectObject(&font); + tempDC.SetBkMode(TRANSPARENT); + + char text[80]; + wsprintf(text, "%d", inFunds); + tempDC.DrawText(text, &rect3, DT_RIGHT); + + pDC->BitBlt(0, 0, rect2.right, rect2.bottom, &tempDC, 0, 0, SRCCOPY); + + tempDC.RestoreDC(save2); + tempDC.DeleteDC(); + + DeleteObject(theBitmap); + font.DeleteObject(); + + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::DrawMessage(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawMessage(T2MWControl* inControl) { +#pragma var_order(imageRect, tempDC, theImage, save2, rect3, font, save, str, rect2, pattern, theBitmap, pDC) + int pattern = inControl->GetData(); + + RECT imageRect; + T2BitImage *theImage = mImageObj->GetObjectImage(mImageObj->FindObject("Message", pattern), imageRect); + + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + CDC tempDC; + tempDC.CreateCompatibleDC(pDC); + int save2 = tempDC.SaveDC(); + tempDC.SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + tempDC.RealizePalette(); + + HBITMAP theBitmap = Create256DIBitmap(tempDC.m_hDC, rect2.right, rect2.bottom); + SelectObject(tempDC.m_hDC, theBitmap); + + m1B8->CopyImage(&tempDC, imageRect, rect2); + + CRect rect3 = rect2; + rect3.top = rect3.top; + rect3.left = rect3.left + 4; + rect3.bottom = rect3.bottom; + rect3.right = rect3.right - 4; + + CFont font; + font.CreateFont(-rect3.Height(), 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + tempDC.SelectObject(&font); + tempDC.SetBkMode(TRANSPARENT); + + CString str; + inControl->GetWindowText(str); + tempDC.DrawText(str, &rect3, DT_SINGLELINE | DT_NOPREFIX); + + pDC->BitBlt(0, 0, rect2.right, rect2.bottom, &tempDC, 0, 0, SRCCOPY); + + tempDC.RestoreDC(save2); + tempDC.DeleteDC(); + + DeleteObject(theBitmap); + font.DeleteObject(); + + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::DrawPauseButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawPauseButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "Pause"); } -/*virtual*/ void T2WorldDef::DrawPopulation(T2MWControl*, int) { +/*virtual*/ void T2WorldDef::DrawPopulation(T2MWControl* inControl, int inPop) { +#pragma var_order(imageRect, tempDC, theImage, save2, text, rect3, font, save, rect2, pattern, theBitmap, pDC) + int pattern = inControl->GetData(); + + RECT imageRect; + T2BitImage *theImage = mImageObj->GetObjectImage(mImageObj->FindObject("Population", pattern), imageRect); + + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + CDC tempDC; + tempDC.CreateCompatibleDC(pDC); + int save2 = tempDC.SaveDC(); + tempDC.SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + tempDC.RealizePalette(); + + HBITMAP theBitmap = Create256DIBitmap(tempDC.m_hDC, rect2.right, rect2.bottom); + SelectObject(tempDC.m_hDC, theBitmap); + + m1B8->CopyImage(&tempDC, imageRect, rect2); + + CRect rect3 = rect2; + rect3.top += 2; + rect3.left += 11; + rect3.bottom -= 2; + rect3.right -= 23; + + if (pattern == 100) + rect3.OffsetRect(1, 1); + + CFont font; + font.CreateFont(-rect3.Height(), 0, 0, 0, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, DEFAULT_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + tempDC.SelectObject(&font); + tempDC.SetBkMode(TRANSPARENT); + + char text[80]; + wsprintf(text, "%d", inPop); + tempDC.DrawText(text, &rect3, DT_RIGHT); + + pDC->BitBlt(0, 0, rect2.right, rect2.bottom, &tempDC, 0, 0, SRCCOPY); + + tempDC.RestoreDC(save2); + tempDC.DeleteDC(); + + DeleteObject(theBitmap); + font.DeleteObject(); + + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::ClickPauseButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickPauseButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackPause(_214); } -/*virtual*/ void T2WorldDef::DrawInViewButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawInViewButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "InView"); } -/*virtual*/ void T2WorldDef::DrawOutViewButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawOutViewButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "OutView"); } -/*virtual*/ void T2WorldDef::DrawMaintButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawMaintButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "Maint"); } -/*virtual*/ void T2WorldDef::DrawEvalButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawEvalButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "Eval"); } -/*virtual*/ void T2WorldDef::DrawPriceButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawPriceButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "Price"); } -/*virtual*/ void T2WorldDef::DrawTransButton(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawTransButton(T2MWControl* inControl) { + DrawSimpleMWControl(inControl, "Trans"); } -/*virtual*/ void T2WorldDef::DrawSlider(T2MWControl*) { +/*virtual*/ void T2WorldDef::DrawSlider(T2MWControl* inControl) { +#pragma var_order(threadRect, theImage, x, save, theImage2, imageRect, rect4, rect2, y, objectID, value, pDC) + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + int value = inControl->GetData(); + + int objectID = mImageObj->FindObject("Slider"); + CRect imageRect; + T2BitImage *theImage = mImageObj->GetObjectImage(objectID, imageRect); + + T2BitImage *theImage2 = new T2BitImage(imageRect); + + int x = imageRect.left; + int y = imageRect.top; + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + theImage->CopyImage(*theImage2, imageRect, rect2); + + objectID = mImageObj->FindObject("SliderLever"); + theImage = mImageObj->GetObjectImage(objectID, imageRect); + + CRect threadRect; + mImageObj->GetObjectImage(mImageObj->FindObject("SliderThread"), threadRect); + threadRect.OffsetRect(-x, -y); + + CRect rect4; + rect4.left = 0; + rect4.top = 0; + rect4.right = imageRect.Width(); + rect4.bottom = imageRect.Height(); + rect4.OffsetRect( + threadRect.left + ((threadRect.Width() * value) / 6) - (imageRect.Width() / 2), + threadRect.top + (threadRect.Height() / 2) - (imageRect.Height() / 2) - 1 + ); + + theImage->SetBackGndColor(0); + theImage->CopyImage(*theImage2, imageRect, rect4); + theImage2->CopyImage(pDC, rect2, rect2); + + delete theImage2; + + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::ClickInViewButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickInViewButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackInView(); } -/*virtual*/ void T2WorldDef::ClickOutViewButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickOutViewButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackOutView(); } -/*virtual*/ void T2WorldDef::ClickMaintButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickMaintButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackMaintView(); } -/*virtual*/ void T2WorldDef::ClickEvalButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickEvalButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackEvalView(); } -/*virtual*/ void T2WorldDef::ClickPriceButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickPriceButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackPriceView(); } -/*virtual*/ void T2WorldDef::ClickTransButton(T2MWControl*, T2TowerDoc*) { +/*virtual*/ void T2WorldDef::ClickTransButton(T2MWControl* inControl, T2TowerDoc* inDoc) { + inDoc->CallbackTransView(); } -/*virtual*/ int T2WorldDef::SliderPointToValue(T2MWControl*, CPoint) { +/*virtual*/ int T2WorldDef::SliderPointToValue(T2MWControl* inControl, CPoint inPt) { + int objectIndex; + CRect sliderArea, threadArea; + + objectIndex = mImageObj->FindObject("Slider"); + mImageObj->GetObjectImage(objectIndex, sliderArea); + + objectIndex = mImageObj->FindObject("SliderThread"); + mImageObj->GetObjectImage(objectIndex, threadArea); + + threadArea.OffsetRect(-sliderArea.left, -sliderArea.top); + + int result = ((inPt.x - threadArea.left) * 7 + threadArea.Width() / 12) / threadArea.Width(); + if (result < 0) + result = 0; + else if (result >= 7) + result = 6; + + return result; } -/*virtual*/ void T2WorldDef::DrawSimpleMWControl(T2MWControl*, const char*) { +/*virtual*/ void T2WorldDef::DrawSimpleMWControl(T2MWControl* inControl, const char* inStr) { +#pragma var_order(tempDC, theImage, save2, save, imageRect, rect2, objectID, theBitmap, pDC) + RECT imageRect; + int objectID = mImageObj->FindObject(inStr, inControl->GetData()); + T2BitImage *theImage = mImageObj->GetObjectImage(objectID, imageRect); + + RECT rect2 = imageRect; + OffsetRect(&rect2, -rect2.left, -rect2.top); + + CDC *pDC = inControl->GetDC(); + int save = pDC->SaveDC(); + pDC->SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + pDC->RealizePalette(); + + CDC tempDC; + tempDC.CreateCompatibleDC(pDC); + int save2 = tempDC.SaveDC(); + tempDC.SelectPalette(GetPaletteAnimeDef()->GetTowerPalette(), false); + tempDC.RealizePalette(); + + HBITMAP theBitmap = Create256DIBitmap(tempDC.m_hDC, rect2.right, rect2.bottom); + SelectObject(tempDC.m_hDC, theBitmap); + + theImage->CopyImage(&tempDC, imageRect, rect2); + pDC->BitBlt(0, 0, rect2.right, rect2.bottom, &tempDC, 0, 0, SRCCOPY); + + tempDC.RestoreDC(save2); + tempDC.DeleteDC(); + + DeleteObject(theBitmap); + + pDC->RestoreDC(save); + inControl->ReleaseDC(pDC); } -/*virtual*/ void T2WorldDef::GetToolTipText(T2TowerDoc*, T2MWControl*, NMTTDISPINFOA*) { +/*virtual*/ void T2WorldDef::GetToolTipText(T2TowerDoc* inDoc, T2MWControl* inControl, LPNMTTDISPINFO outInfo) { + int id = inControl->GetDlgCtrlID(); + + if (id == 1000) + GetClockTip(inDoc, inControl, outInfo->szText); + else if (id == 1001) + GetCalendarTip(inDoc, inControl, outInfo->szText); + else if (id == 1002) + GetFundsTip(inDoc, inControl, outInfo->szText); + else if (id == 1003) + GetPopulationTip(inDoc, inControl, outInfo->szText); + else if (id == 2000) + GetPauseButtonTip(inDoc, inControl, outInfo->szText); } -/*virtual*/ void T2WorldDef::GetClockTip(T2TowerDoc*, T2MWControl*, char*) { +/*virtual*/ void T2WorldDef::GetClockTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr) { + strcpy(outStr, "Clock"); } -/*virtual*/ void T2WorldDef::GetCalendarTip(T2TowerDoc*, T2MWControl*, char*) { +/*virtual*/ void T2WorldDef::GetCalendarTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr) { + // "カレンダー表示" + strcpy(outStr, "\x83\x4A\x83\x8C\x83\x93\x83\x5F\x81\x5B\x95\x5C\x8E\xA6"); } -/*virtual*/ void T2WorldDef::GetFundsTip(T2TowerDoc*, T2MWControl*, char*) { +/*virtual*/ void T2WorldDef::GetFundsTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr) { + // "収支情報表示" + strcpy(outStr, "\x8E\xFB\x8E\x78\x8F\xEE\x95\xF1\x95\x5C\x8E\xA6"); } -/*virtual*/ void T2WorldDef::GetPopulationTip(T2TowerDoc*, T2MWControl*, char*) { +/*virtual*/ void T2WorldDef::GetPopulationTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr) { + // "人口情報表示" + strcpy(outStr, "\x90\x6C\x8C\xFB\x8F\xEE\x95\xF1\x95\x5C\x8E\xA6"); } -/*virtual*/ void T2WorldDef::GetPauseButtonTip(T2TowerDoc*, T2MWControl*, char*) { +/*virtual*/ void T2WorldDef::GetPauseButtonTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr) { + // 実行/停止 + strcpy(outStr, "\x8E\xC0\x8D\x73\x81\x5E\x92\xE2\x8E\x7E"); } -unsigned int T2WorldDef::GetToiletDenomi(unsigned int) const { +unsigned int T2WorldDef::GetToiletDenomi(unsigned int inVal) const { + unsigned int result = 0; + + if (mToiletVar1 > 0 && inVal >= mToiletVar1) + result = mToiletVar2; + + return result; } -unsigned int T2WorldDef::GetColdDenomi(unsigned int, unsigned int) const { +unsigned int T2WorldDef::GetColdDenomi(unsigned int inVal1, unsigned int inVal2) const { + unsigned int result = 0; + + if (mColdTableDef) + result = mColdTableDef->GetDenomi(inVal1, inVal2); + + return result; } -int T2WorldDef::IsDustOn(unsigned int) const { +BOOL T2WorldDef::IsDustOn(unsigned int inVal) const { + return (mDustOnThreshold > 0) && (inVal >= mDustOnThreshold); } T2TowerVision* T2WorldDef::GetTowerVision() { + return mTowerEvent ? mTowerEvent->GetTowerVision() : NULL; } -void T2WorldDef::SetLatestBuild(T2Equip*, int) { +void T2WorldDef::SetLatestBuild(T2Equip* inEquip, BOOL inFlag) { + if (mTowerEvent) { + T2ToolDef *theDef = inEquip->GetToolDef(); + mTowerEvent->SetLatestBuild(inEquip, theDef, inFlag); + } } -void T2WorldDef::SetLatestBuild(T2ToolDef*, int) { +void T2WorldDef::SetLatestBuild(T2ToolDef* inToolDef, BOOL inFlag) { + mTowerEvent->SetLatestBuild(NULL, inToolDef, inFlag); } -void T2WorldDef::InitTowerEvent(T2TowerDoc*) { +void T2WorldDef::InitTowerEvent(T2TowerDoc* inDoc) { + if (mTowerEvent) + mTowerEvent->InitTowerEvent(inDoc); } -void T2WorldDef::WriteTowerEvent(T2Archive&) { +void T2WorldDef::WriteTowerEvent(T2Archive& inArchive) { + if (mTowerEvent) + mTowerEvent->Write(inArchive); } -void T2WorldDef::ReadTowerEvent(T2Archive&) { +void T2WorldDef::ReadTowerEvent(T2Archive& inArchive) { + if (mTowerEvent) + mTowerEvent->Read(inArchive); } void T2WorldDef::StopEvent() { + if (mTowerEvent) + mTowerEvent->StopEvent(); } T2TowerEvent* T2WorldDef::GetTowerEvent() { + return mTowerEvent; } T2FireBurning* T2WorldDef::GetFireBurning() { + return mTowerEvent ? mTowerEvent->GetFireBurning() : NULL; } T2MetroRailway* T2WorldDef::GetMetroRailway() { + return mTowerEvent ? mTowerEvent->GetMetroRailway() : NULL; } T2BlackOut* T2WorldDef::GetBlackOut() { + return mTowerEvent ? mTowerEvent->GetBlackOut() : NULL; } -int T2WorldDef::IsBlackOut() { +BOOL T2WorldDef::IsBlackOut() { + return mTowerEvent ? mTowerEvent->IsBlackOut() : false; } -/*virtual*/ void T2WorldDef::DrawRubble(T2TowerDoc*, T2Tenant*) { +/*virtual*/ void T2WorldDef::DrawRubble(T2TowerDoc* inDoc, T2Tenant* inTenant) { + mTowerEvent->DrawRubble(inDoc, inTenant); } -/*virtual*/ void T2WorldDef::DrawMark(T2BitImage*, const RECT&, int, unsigned int) { +/*virtual*/ void T2WorldDef::DrawMark(T2BitImage* inDestImage, const RECT& inRect, int inZoomLevel, unsigned int inPattern) { + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = 3; + rect.bottom = 1; + + UT2Coordinate::UnitToQD(rect, inZoomLevel); + URect::Center(inRect, rect); + + int objectID = mImageObj->FindObject("Mark", inPattern); + mImageObj->DrawObject(inDestImage, objectID, rect, inZoomLevel); } -/*virtual*/ void T2WorldDef::InitializeBkgndInfo(BkgndInfo*) { +/*virtual*/ void T2WorldDef::InitializeBkgndInfo(BkgndInfo* inBkgndInfoPtr) { + ((T2WorldPlugin *) mPlugin)->InitBkgndInfoProc(this, inBkgndInfoPtr); } -/*virtual*/ void T2WorldDef::InitializeFloorInfo(T2FloorInfo*) { +/*virtual*/ void T2WorldDef::InitializeFloorInfo(T2FloorInfo* inFloorInfo) { + ((T2WorldPlugin *) mPlugin)->InitFloorInfoProc(this, *inFloorInfo); } -/*virtual*/ void T2WorldDef::InitializeDocument(T2TowerDoc*) { +/*virtual*/ void T2WorldDef::InitializeDocument(T2TowerDoc* inDoc) { + mTowerEvent = new T2TowerEvent(this); + ((T2WorldPlugin *) mPlugin)->InitializeDocumentProc(inDoc); } -/*virtual*/ int T2WorldDef::CheckGameLevelProc(T2TowerDoc*) { +/*virtual*/ int T2WorldDef::CheckGameLevelProc(T2TowerDoc* inDoc) { + int result = 0; + + if (inDoc->mGameLevel <= mNumOfGradeDef) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + if (thePool) { + GradeDef theDef = mGradeDef[inDoc->mGameLevel - 1]; + int population = thePool->GetPopulation(); + if ((inDoc->mA0 & theDef.m0) == theDef.m0 && population >= theDef.m4) + result = 10005; + } + } + + return result; } -/*virtual*/ int T2WorldDef::CheckTreasure(T2TowerDoc*, T2TreasureStatus*) { +/*virtual*/ BOOL T2WorldDef::CheckTreasure(T2TowerDoc* inDoc, T2TreasureStatus* inTreasureStatus) { + return false; } -/*virtual*/ void T2WorldDef::GetGradeUpMessage(int, CString&) { +/*virtual*/ void T2WorldDef::GetGradeUpMessage(int inGradeNum, CString& outStr) { + // "あなたのビルは%d星に認定されました" + // Your building has been awarded %d stars + outStr.Format("\x82\xA0\x82\xC8\x82\xBD\x82\xCC\x83\x72\x83\x8B\x82\xCD\x25\x64\x90\xAF\x82\xC9\x94\x46\x92\xE8\x82\xB3\x82\xEA\x82\xDC\x82\xB5\x82\xBD", inGradeNum); } -/*virtual*/ void T2WorldDef::CalcOptionObj(T2TowerDoc*, T2Equip*) { +/*virtual*/ void T2WorldDef::CalcOptionObj(T2TowerDoc* inDoc, T2Equip* inEquip) { + T2TowerMainView *theView = inDoc->GetTowerMainView(); + T2FloorInfo *floorInfo = inDoc->towerDoc_vf12C(); + + if (inEquip) { + RECT equipArea; + inEquip->GetEquipArea(equipArea); + if (equipArea.bottom > mTopFloorLine && !inEquip->IsMover() && ((T2Tenant *) inEquip)->IsFloor()) { + CString objectName; + if (inEquip->mValiation == 0) + objectName = "Side"; + else + objectName = "Tent"; + objectName += "L"; + + int objectIndex = mImageObj->FindObject(objectName, 0); + SIZE objectSize; + mImageObj->GetObjectSize(objectIndex, &objectSize); + + equipArea.left -= objectSize.cx; + equipArea.right += objectSize.cx; + theView->tmv_vf128(equipArea, true); + } + } } -/*virtual*/ void T2WorldDef::DrawOptionObj(T2TowerDoc*, const RECT&) { +/*virtual*/ void T2WorldDef::DrawOptionObj(T2TowerDoc* inDoc, const RECT& inRect) { +#pragma var_order(name, theFloor, tentObjectSize, rect1, rect2, v, sideObjectSize, objectID, theFloorInfo) + RECT rect1 = inRect; + if (rect1.bottom > mGroundLine) + rect1.bottom = mGroundLine; + + T2FloorInfo *theFloorInfo = inDoc->towerDoc_vf12C(); + + CString name = "Side"; + int objectID = mImageObj->FindObject(name + "L"); + SIZE sideObjectSize; + mImageObj->GetObjectSize(objectID, &sideObjectSize); + + sideObjectSize.cx /= UT2Coordinate::UnitHSize(0); + sideObjectSize.cy /= UT2Coordinate::UnitVSize(0); + + name = "Tent"; + objectID = mImageObj->FindObject(name + "L"); + SIZE tentObjectSize; + mImageObj->GetObjectSize(objectID, &tentObjectSize); + + tentObjectSize.cx /= UT2Coordinate::UnitHSize(0); + tentObjectSize.cy /= UT2Coordinate::UnitVSize(0); + + RECT rect2 = rect1; + rect2.left -= max(sideObjectSize.cx, tentObjectSize.cx); + rect2.right += max(sideObjectSize.cx, tentObjectSize.cx); + + IntersectRect(&rect2, &rect2, &mBuildArea); + rect2.top = max(rect2.top, mTopFloorLine); + + T2Tenant *theFloor; + + for (int v = rect2.top; v < rect2.bottom; v++) { + for (int h = rect2.left; h < rect2.right; h++) { + theFloor = theFloorInfo->GetFloor(v, h); + if (theFloor) { + h = theFloor->mArea.right - 1; + if (theFloor->mValiation == 0) { + if (theFloorInfo->GetTenantID(theFloor->mArea.bottom - 1, theFloor->mArea.left - 1) == 0) { + name = "Side"; + objectID = mImageObj->FindObject(name + "L", 0); + + RECT rect = theFloor->mArea; + rect.right = rect.left; + rect.left = rect.right - sideObjectSize.cx; + UT2Coordinate::UnitToQD(rect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + } + + if (theFloorInfo->GetTenantID(theFloor->mArea.bottom - 1, theFloor->mArea.right) == 0) { + name = "Side"; + objectID = mImageObj->FindObject(name + "R", 0); + + RECT rect = theFloor->mArea; + rect.left = rect.right; + rect.right = rect.left + sideObjectSize.cx; + UT2Coordinate::UnitToQD(rect, rect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, rect, inDoc->towerDoc_vf108()); + } + } else { + if (theFloorInfo->GetTenantID(theFloor->mArea.bottom - 1, theFloor->mArea.left - 1) == 0) { + name = "Side"; + objectID = mImageObj->FindObject(name + "L", 0); + + RECT baseRect = theFloor->mArea; + baseRect.right = baseRect.left; + baseRect.left = baseRect.right - sideObjectSize.cx; + baseRect.bottom = baseRect.top + 1; + + RECT workRect; + + for (int i = theFloor->mArea.top; i < (theFloor->mArea.bottom - 1); i++) { + UT2Coordinate::UnitToQD(baseRect, workRect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, workRect, inDoc->towerDoc_vf108()); + OffsetRect(&baseRect, 0, 1); + } + + name = "Tent"; + objectID = mImageObj->FindObject(name + "L", 0); + + baseRect.left = baseRect.right - tentObjectSize.cx; + UT2Coordinate::UnitToQD(baseRect, workRect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, workRect, inDoc->towerDoc_vf108()); + } + + if (theFloorInfo->GetTenantID(theFloor->mArea.bottom - 1, theFloor->mArea.right) == 0) { + name = "Side"; + objectID = mImageObj->FindObject(name + "R", 0); + + RECT baseRect = theFloor->mArea; + baseRect.left = baseRect.right; + baseRect.right = baseRect.left + sideObjectSize.cx; + baseRect.bottom = baseRect.top + 1; + + RECT workRect; + + for (int i = theFloor->mArea.top; i < (theFloor->mArea.bottom - 1); i++) { + UT2Coordinate::UnitToQD(baseRect, workRect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, workRect, inDoc->towerDoc_vf108()); + OffsetRect(&baseRect, 0, 1); + } + + name = "Tent"; + objectID = mImageObj->FindObject(name + "R", 0); + + baseRect.right = baseRect.left + tentObjectSize.cx; + UT2Coordinate::UnitToQD(baseRect, workRect, inDoc->mZoomLevel, true); + mImageObj->DrawObject(inDoc->towerDoc_vf10C(), objectID, workRect, inDoc->towerDoc_vf108()); + } + } + } + } + } } -/*virtual*/ void T2WorldDef::SetupGradeUpAnimation(T2DlgItemAnimation*, int) { +/*virtual*/ void T2WorldDef::SetupGradeUpAnimation(T2DlgItemAnimation* inAnimation, int inGradeNum) { + if (inGradeNum >= 2) { + int grade = inGradeNum - 2; + inAnimation->SetAnimation(mModuleHandle, mGradeDef[grade].m8, 0); + inAnimation->SetAnimationParam(100, mGradeDef[grade].m14); + } } -/*virtual*/ void T2WorldDef::WriteStatisticsProc(T2TowerDoc*, T2Archive&) { +/*virtual*/ void T2WorldDef::WriteStatisticsProc(T2TowerDoc* inDoc, T2Archive& inArchive) { } -/*virtual*/ void T2WorldDef::ReadStatisticsProc(T2TowerDoc*, T2Archive&) { +/*virtual*/ void T2WorldDef::ReadStatisticsProc(T2TowerDoc* inDoc, T2Archive& inArchive) { } -/*virtual*/ void T2WorldDef::ViewModeChanged(T2TowerDoc*, VIEWMODE) { +/*virtual*/ void T2WorldDef::ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE) { } -/*virtual*/ void T2WorldDef::ReplaceSkyOffscreen(int) { +/*virtual*/ void T2WorldDef::ReplaceSkyOffscreen(int inResID) { + delete mSkyOffscreen; + mSkyOffscreen = new T2BitImage(mModuleHandle, inResID, true); } -/*virtual*/ T2EventItem* T2WorldDef::MakeXEvent(T2TowerEvent*, CResFile*, unsigned long, int) { +/*virtual*/ T2EventItem* T2WorldDef::MakeXEvent(T2TowerEvent* inTowerEvent, CResFile*, unsigned long, int) { + return NULL; } diff --git a/src/T2DLL/T2WorldDef.h b/src/T2DLL/T2WorldDef.h index b80d358..d1e9092 100644 --- a/src/T2DLL/T2WorldDef.h +++ b/src/T2DLL/T2WorldDef.h @@ -1,132 +1,228 @@ #pragma once #include "common.h" +#include "T2PaletteAnimeDef.h" #include "T2TemplatePlugin.h" -class T2WorldDef : public T2TemplatePlugin { +// unknown name +struct GradeDef { + unsigned int m0; // mask of VIPs available + int m4; // minimum population + int m8; // grade up animation ID + int mC; + int m10; + int m14; // grade up animation start frame +}; + +class AFX_EXT_CLASS T2WorldDef : public T2TemplatePlugin { public: - T2WorldDef(unsigned long, T2PluginSpecifier&, CResFile*, T2WorldPlugin*); + T2WorldDef(DWORD inType, T2PluginSpecifier& inSpecifier, CResFile* inResFile, T2WorldPlugin* inPlugin); public: virtual ~T2WorldDef(); - virtual void GetName(CString&); - virtual int GetSortKey() { return 0; } - virtual int GetInitialFunds() const { return 0; } - virtual int IsHoliday(T2DateTime*) const { return 0; } - virtual int IsRainyDay(T2DateTime*) const { return 0; } - virtual int ExchangeMoney(int) const { return 0; } - virtual void DrawWorld(T2TowerDoc*); - virtual void DoAnimate(T2TowerDoc*); - virtual void DrawBkgnd(unsigned int, const RECT&, T2TowerDoc*); - virtual void DrawBkgnd(const RECT&, T2TowerDoc*); - virtual void DrawRoofAndFloor(const RECT&, T2TowerDoc*, ROOFANDFLOOR); - virtual void DrawBuild(T2Equip*, T2TowerDoc*); - virtual void DrawSideObj(T2Equip*, T2TowerDoc*, SIDEOBJPATTERN); - virtual void DrawOptionObj(T2TowerDoc*, const RECT&); - virtual void DrawRubble(T2TowerDoc*, T2Tenant*); - virtual void DrawMark(T2BitImage*, const RECT&, int, unsigned int); - virtual void DrawCrane(T2TowerDoc*, const RECT&); - virtual const char* GetMoneyUnit() { return 0; } - virtual T2EventItem* MakeXEvent(T2TowerEvent*, CResFile*, unsigned long, int); - virtual T2Transport* GetCruise(T2TowerEvent*) { return 0; } - virtual void InitializeBkgndInfo(BkgndInfo*); - virtual void InitializeFloorInfo(T2FloorInfo*); - virtual void InitializeDocument(T2TowerDoc*); - virtual int TenantAreaCheck(T2TowerDoc*, RECT&, int); - virtual void CalcOptionObj(T2TowerDoc*, T2Equip*); - virtual void CalcCranePos(T2TowerDoc*); - virtual void ClearCranePos(T2TowerDoc*); - virtual void DrawCtrl(T2TowerDoc*, T2MWControl*); - virtual void ButtonDownOnCtrl(T2TowerDoc*, T2MWControl*, CPoint, CWnd*); - virtual void ButtonUpOnCtrl(T2TowerDoc*, T2MWControl*, CPoint, CWnd*); - virtual void MouseMoveOnCtrl(T2TowerDoc*, T2MWControl*, CPoint, CWnd*); - virtual void GetToolTipText(T2TowerDoc*, T2MWControl*, NMTTDISPINFOA*); - virtual int IdleProc(T2TowerDoc*); - virtual int CheckGameLevelProc(T2TowerDoc*); - virtual void GetGradeUpMessage(int, CString&); - virtual void DayChanged(T2TowerDoc*) {} - virtual void ViewModeChanged(T2TowerDoc*, VIEWMODE); - virtual void ReplaceSkyOffscreen(int); - virtual BOOL3 ChangeFastSEProc(T2PaletteAnime*) { return BOOL3_0; } - virtual BOOL3 ChangeFastSEProc(T2PaletteAnime*, T2DateTime*) { return BOOL3_0; } - virtual BOOL3 ChangeSEProc(T2PaletteAnime*) { return BOOL3_0; } - virtual BOOL3 ChangeSkyColorProc(T2PaletteAnime*) { return BOOL3_0; } - virtual BOOL3 AdjustSkyStateProc(T2PaletteAnime*, T2DateTime*) { return BOOL3_0; } - virtual int UseOwnSkyPaletteFunction() { return 0; } - virtual void SetupGradeUpAnimation(T2DlgItemAnimation*, int); - virtual void WriteStatisticsProc(T2TowerDoc*, T2Archive&); - virtual void ReadStatisticsProc(T2TowerDoc*, T2Archive&); - virtual int CheckTreasure(T2TowerDoc*, T2TreasureStatus*); + virtual void GetName(CString& outStr); + virtual int GetSortKey() { return mWorldType; } + virtual int GetInitialFunds() const { return mInitialFunds; } + virtual BOOL IsHoliday(T2DateTime* inDateTime) const { return false; } + virtual BOOL IsRainyDay(T2DateTime* inDateTime) const { return false; } + virtual int ExchangeMoney(int v) const { + return (mMoneyNumerator == 1 && mMoneyDenominator == 1) ? v : ((v / mMoneyDenominator) * mMoneyNumerator); + } + virtual void DrawWorld(T2TowerDoc* inDoc); + virtual void DoAnimate(T2TowerDoc* inDoc); + virtual void DrawBkgnd(const RECT& inRect, T2TowerDoc* inDoc); + virtual void DrawBkgnd(unsigned int inImageIndex, const RECT& inDestRect, T2TowerDoc* inDoc); + virtual void DrawRoofAndFloor(const RECT& inRect, T2TowerDoc* inDoc, ROOFANDFLOOR inRoofAndFloor); + virtual void DrawBuild(T2Equip* inEquip, T2TowerDoc* inDoc); + virtual void DrawSideObj(T2Equip* inEquip, T2TowerDoc* inDoc, SIDEOBJPATTERN inSideObjPattern); + virtual void DrawOptionObj(T2TowerDoc* inDoc, const RECT& inRect); + virtual void DrawRubble(T2TowerDoc* inDoc, T2Tenant* inTenant); + virtual void DrawMark(T2BitImage* inDestImage, const RECT& inRect, int inZoomLevel, unsigned int inPattern); + virtual void DrawCrane(T2TowerDoc* inDoc, const RECT& inRect); + virtual const char* GetMoneyUnit() { return mMoneyUnit; } + virtual T2EventItem* MakeXEvent(T2TowerEvent* inTowerEvent, CResFile*, unsigned long, int); + virtual T2Transport* GetCruise(T2TowerEvent* inTowerEvent) { return NULL; } + virtual void InitializeBkgndInfo(BkgndInfo* inBkgndInfoPtr); + virtual void InitializeFloorInfo(T2FloorInfo* inFloorInfo); + virtual void InitializeDocument(T2TowerDoc* inDoc); + virtual BOOL TenantAreaCheck(T2TowerDoc* inDoc, RECT& inRect, BOOL inShowMessage); + virtual void CalcOptionObj(T2TowerDoc* inDoc, T2Equip* inEquip); + virtual void CalcCranePos(T2TowerDoc* inDoc); + virtual void ClearCranePos(T2TowerDoc* inDoc); + virtual void DrawCtrl(T2TowerDoc* inDoc, T2MWControl* inControl); + virtual void ButtonDownOnCtrl(T2TowerDoc* inDoc, T2MWControl* inControl, CPoint inPt, CWnd* inWnd); + virtual void ButtonUpOnCtrl(T2TowerDoc* inDoc, T2MWControl* inControl, CPoint inPt, CWnd* inWnd); + virtual void MouseMoveOnCtrl(T2TowerDoc* inDoc, T2MWControl* inControl, CPoint inPt, CWnd* inWnd); + virtual void GetToolTipText(T2TowerDoc* inDoc, T2MWControl* inControl, LPNMTTDISPINFO outInfo); + virtual int IdleProc(T2TowerDoc* inDoc); + virtual int CheckGameLevelProc(T2TowerDoc* inDoc); + virtual void GetGradeUpMessage(int inGradeNum, CString& outStr); + virtual void DayChanged(T2TowerDoc* inDoc) {} + virtual void ViewModeChanged(T2TowerDoc* inDoc, VIEWMODE); + virtual void ReplaceSkyOffscreen(int inResID); + virtual BOOL3 ChangeFastSEProc(T2PaletteAnime* inPaletteAnime) { return BOOL3_NEG1; } + virtual BOOL3 ChangeFastSEProc(T2PaletteAnime* inPaletteAnime, T2DateTime* inDateTime) { return BOOL3_NEG1; } + virtual BOOL3 ChangeSEProc(T2PaletteAnime* inPaletteAnime) { return BOOL3_NEG1; } + virtual BOOL3 ChangeSkyColorProc(T2PaletteAnime* inPaletteAnime) { return BOOL3_NEG1; } + virtual BOOL3 AdjustSkyStateProc(T2PaletteAnime* inPaletteAnime, T2DateTime* inDateTime) { return BOOL3_NEG1; } + virtual BOOL UseOwnSkyPaletteFunction() { return false; } + virtual void SetupGradeUpAnimation(T2DlgItemAnimation* inAnimation, int inGradeNum); + virtual void WriteStatisticsProc(T2TowerDoc* inDoc, T2Archive& inArchive); + virtual void ReadStatisticsProc(T2TowerDoc* inDoc, T2Archive& inArchive); + virtual BOOL CheckTreasure(T2TowerDoc* inDoc, T2TreasureStatus* inTreasureStatus); virtual unsigned long OptionProc(unsigned long, void*) { return 0; } - unsigned int GetToiletDenomi(unsigned int) const; - unsigned int GetColdDenomi(unsigned int, unsigned int) const; - int IsDustOn(unsigned int) const; + unsigned int GetToiletDenomi(unsigned int inVal) const; + unsigned int GetColdDenomi(unsigned int inVal1, unsigned int inVal2) const; + BOOL IsDustOn(unsigned int inVal) const; T2TowerVision* GetTowerVision(); - void SetLatestBuild(T2Equip*, int); - void SetLatestBuild(T2ToolDef*, int); - void InitTowerEvent(T2TowerDoc*); - void WriteTowerEvent(T2Archive&); - void ReadTowerEvent(T2Archive&); + void SetLatestBuild(T2Equip* inEquip, BOOL inFlag); + void SetLatestBuild(T2ToolDef* inToolDef, BOOL inFlag); + void InitTowerEvent(T2TowerDoc* inDoc); + void WriteTowerEvent(T2Archive& inArchive); + void ReadTowerEvent(T2Archive& inArchive); void StopEvent(); T2TowerEvent* GetTowerEvent(); T2FireBurning* GetFireBurning(); T2MetroRailway* GetMetroRailway(); T2BlackOut* GetBlackOut(); - int IsBlackOut(); + BOOL IsBlackOut(); - CPalette* GetPalette() { return 0; } - int IsUseMatterObject() const { return 0; } - int GetOutViewKind() const { return 0; } - T2PaletteAnimeDef* GetPaletteAnimeDef() const { return 0; } - T2SeasonParamDef* GetSeasonParamDef() const { return 0; } - int GetHeight() const { return 0; } - int GetWidth() const { return 0; } - void GetBuildArea(RECT&) const {} - int IsStoppableFloor(int) { return 0; } - int GetLobbyHeight() { return 0; } - T2Maru_Reggae* GetReggae() { return 0; } - int GetCashAmount(int) const { return 0; } + CPalette* GetPalette() { return GetPaletteAnimeDef()->GetTowerPalette(); } + BOOL IsUseMatterObject() const { return false; } + int GetOutViewKind() const { return mOutViewKind; } + T2PaletteAnimeDef* GetPaletteAnimeDef() const { return mPaletteAnimeDef; } + T2SeasonParamDef* GetSeasonParamDef() const { return mSeasonParamDef; } + int GetHeight() const { return mHeight; } + int GetWidth() const { return mWidth; } + void GetBuildArea(RECT& rect) const { rect = mBuildArea; } + BOOL IsStoppableFloor(int y) { + return !((y >= (mGroundLine - mLobbyHeight) && y < (mGroundLine - 1))); + } + int GetLobbyHeight() { return mLobbyHeight; } + T2Maru_Reggae* GetReggae() { return NULL; } + int GetCashAmount(int i) const { + return (i >= 0 && i < 8) ? mCashAmount[i] : 0; + } protected: - virtual void DrawClock(T2MWControl*, T2DateTime&); - virtual void DrawCalendar(T2MWControl*, T2DateTime&, T2TowerDoc*); - virtual void DrawFunds(T2MWControl*, int); - virtual void DrawPopulation(T2MWControl*, int); - virtual void DrawMessage(T2MWControl*); - virtual void DrawPauseButton(T2MWControl*); - virtual void DrawInViewButton(T2MWControl*); - virtual void DrawOutViewButton(T2MWControl*); - virtual void DrawMaintButton(T2MWControl*); - virtual void DrawEvalButton(T2MWControl*); - virtual void DrawPriceButton(T2MWControl*); - virtual void DrawTransButton(T2MWControl*); - virtual void DrawSlider(T2MWControl*); - virtual void ClickClock(T2MWControl*, T2TowerDoc*); - virtual void ClickCalendar(T2MWControl*, T2TowerDoc*); - virtual void ClickFunds(T2MWControl*, T2TowerDoc*); - virtual void ClickPopulation(T2MWControl*, T2TowerDoc*); - virtual void ClickPauseButton(T2MWControl*, T2TowerDoc*); - virtual void ClickInViewButton(T2MWControl*, T2TowerDoc*); - virtual void ClickOutViewButton(T2MWControl*, T2TowerDoc*); - virtual void ClickMaintButton(T2MWControl*, T2TowerDoc*); - virtual void ClickEvalButton(T2MWControl*, T2TowerDoc*); - virtual void ClickPriceButton(T2MWControl*, T2TowerDoc*); - virtual void ClickTransButton(T2MWControl*, T2TowerDoc*); - virtual int SliderPointToValue(T2MWControl*, CPoint); - virtual void GetClockTip(T2TowerDoc*, T2MWControl*, char*); - virtual void GetCalendarTip(T2TowerDoc*, T2MWControl*, char*); - virtual void GetFundsTip(T2TowerDoc*, T2MWControl*, char*); - virtual void GetPopulationTip(T2TowerDoc*, T2MWControl*, char*); - virtual void GetPauseButtonTip(T2TowerDoc*, T2MWControl*, char*); - virtual void DrawSimpleMWControl(T2MWControl*, const char*); + virtual void DrawClock(T2MWControl* inControl, T2DateTime& inDateTime); + virtual void DrawCalendar(T2MWControl* inControl, T2DateTime& inDateTime, T2TowerDoc* inDoc); + virtual void DrawFunds(T2MWControl* inControl, int inFunds); + virtual void DrawPopulation(T2MWControl* inControl, int inPop); + virtual void DrawMessage(T2MWControl* inControl); + virtual void DrawPauseButton(T2MWControl* inControl); + virtual void DrawInViewButton(T2MWControl* inControl); + virtual void DrawOutViewButton(T2MWControl* inControl); + virtual void DrawMaintButton(T2MWControl* inControl); + virtual void DrawEvalButton(T2MWControl* inControl); + virtual void DrawPriceButton(T2MWControl* inControl); + virtual void DrawTransButton(T2MWControl* inControl); + virtual void DrawSlider(T2MWControl* inControl); + virtual void ClickClock(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickCalendar(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickFunds(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickPopulation(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickPauseButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickInViewButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickOutViewButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickMaintButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickEvalButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickPriceButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual void ClickTransButton(T2MWControl* inControl, T2TowerDoc* inDoc); + virtual int SliderPointToValue(T2MWControl* inControl, CPoint inPt); + virtual void GetClockTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr); + virtual void GetCalendarTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr); + virtual void GetFundsTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr); + virtual void GetPopulationTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr); + virtual void GetPauseButtonTip(T2TowerDoc* inDoc, T2MWControl* inControl, char* outStr); + virtual void DrawSimpleMWControl(T2MWControl* inControl, const char* inStr); - void SetupOffscreen(HINSTANCE); + void SetupOffscreen(HINSTANCE inModule); void DisposeOffscreen(); - void SetupPalette(HINSTANCE); + void SetupPalette(HINSTANCE inModule); void DisposePalette(); -protected: T2PaletteAnimeDef* MakePaletteAnimeDef(); T2PoolDef* MakePoolDef(); T2SeasonParamDef* MakeSeasonParamDef(); T2ColdTableDef* MakeColdTableDef(); + + friend class T2FloorInfo; + friend class T2MainWindow; + friend class T2Maru_Reggae; + friend class T2MetroRailway; + friend class T2OutDecoration; + friend class T2OuterObjDef; + friend class T2People; + friend class T2SantaClaus; + friend class T2TenantDef; + friend class T2Terrorist; + friend class T2ToolDef; + friend class T2ToolWindow; + friend class T2WorldPlugin; + friend class T2VisitVIP; + + int mWorldType; + int mGroundLine; + int mLobbyHeight; + int _5C; + POINT mInitPos; + int mTopFloorLine; + int mBottomFloorLine; + int m70; + int m74; + int _78; + int _7C; + int _80; + int mNumOfGradeDef; + GradeDef mGradeDef[8]; + int m148[5]; + char m15C[20]; + unsigned int mDustOnThreshold; + unsigned int mToiletVar1; + unsigned int mToiletVar2; + int m17C; + int mBGVUnit; + int mBGHUnit; + int mSkyVSize; + int mSkyHSize; + POINT m190; + T2WordDefArray *mWordDefArray; + T2BitImage *mSkyOffscreen; + T2BitImage *m1A0; + T2BitImage *m1A4[2]; + T2BitImage *m1AC; + T2BitImage *m1B0; + T2BitImage *m1B4; + T2BitImage *m1B8; + T2BitImage *m1BC; + T2BitImage *m1C0; + T2BitImage *m1C4; + T2BitImage *m1C8; + T2BitImage *m1CC; + T2ImageObj *m1D0; + T2PoolDef *mPoolDef; + int _1D8; + int _1DC; + int _1E0; + int _1E4; + int _1E8; + int _1EC; + int _1F0; + T2BitImage *mImage; + int mHeight; + int mWidth; + RECT mBuildArea; + int _210; + BOOL _214; + int mOutViewKind; + T2PaletteAnimeDef *mPaletteAnimeDef; + T2SeasonParamDef *mSeasonParamDef; + T2ColdTableDef *mColdTableDef; + int m228; + int mCashAmount[8]; + int mInitialFunds; + int mMoneyNumerator; + int mMoneyDenominator; + CString mMoneyUnit; + T2TowerEvent *mTowerEvent; }; diff --git a/src/T2DLL/T2WorldPlugin.cpp b/src/T2DLL/T2WorldPlugin.cpp index d57e40c..afa7d1c 100644 --- a/src/T2DLL/T2WorldPlugin.cpp +++ b/src/T2DLL/T2WorldPlugin.cpp @@ -1,30 +1,80 @@ +#include "CResFile.h" +#include "T2FloorInfo.h" +#include "T2Pool.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" #include "T2WorldPlugin.h" +#include "T2XEvent.h" +#include "UT2BkgndInfo.h" -T2WorldPlugin::T2WorldPlugin(unsigned long, T2PluginSpecifier&) { +T2WorldPlugin::T2WorldPlugin(DWORD inType, T2PluginSpecifier& inSpecifier) + : CProgramPlugin(inType, inSpecifier) +{ + mNumOfClockStyle = 1; + m70 = 0; } /*virtual*/ T2WorldPlugin::~T2WorldPlugin() { } -/*virtual*/ int T2WorldPlugin::LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*) { +typedef T2WorldDef *(MSVC_STDCALL* ConstructTemplatePluginType) (T2PluginSpecifier *, CResFile *, T2WorldPlugin *); + +/*virtual*/ BOOL T2WorldPlugin::LoadAllTemplatePlugin(T2WorldDef* inWorldDef, T2TemplatePluginDB* inDB) { + return true; } /*virtual*/ T2WorldDef* T2WorldPlugin::LoadT2WorldDef() { + ConstructTemplatePluginType theFunc = (ConstructTemplatePluginType) GetProcAddress((HMODULE) mModuleHandle, "ConstructTemplatePlugin"); +#line 29 + _ASSERT(theFunc); + + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, "WorldDef"); + T2WorldDef *worldDef = theFunc(&mSpecifier, &resFile, this); + + mTemplatePlugin = worldDef; + return worldDef; } -/*virtual*/ void T2WorldPlugin::InitFloorInfoProc(T2WorldDef*, T2FloorInfo&) { +/*virtual*/ void T2WorldPlugin::InitFloorInfoProc(T2WorldDef* inWorldDef, T2FloorInfo& inFloorInfo) { + CResFile resFile; + if (resFile.OpenResource(mModuleHandle, 1, 'FInf')) + inFloorInfo.InitMask(resFile); } -/*virtual*/ void T2WorldPlugin::InitBkgndInfoProc(T2WorldDef*, BkgndInfo*) { +/*virtual*/ void T2WorldPlugin::InitBkgndInfoProc(T2WorldDef* inWorldDef, BkgndInfo* inBkgndInfoPtr) { + int vRange, hRange; + unsigned int data; + + CResFile resFile; + resFile.OpenResource(mModuleHandle, 1, 'BInf'); + resFile >> vRange; + resFile >> hRange; + +#line 53 + _ASSERT((inBkgndInfoPtr->vRange == vRange) && (inBkgndInfoPtr->hRange == hRange)); + + int notUsed; + resFile >> notUsed; + + for (int h = 0; h < hRange; h++) { + for (int v = 0; v < vRange; v++) { + unsigned int *array = inBkgndInfoPtr->arrays[v]; + resFile >> data; + array[h] = data; + } + } } -/*virtual*/ void T2WorldPlugin::InitializeDocumentProc(T2TowerDoc*) { +/*virtual*/ void T2WorldPlugin::InitializeDocumentProc(T2TowerDoc* inDoc) { } -/*virtual*/ int T2WorldPlugin::IsHoliday(T2DateTime*) const { +/*virtual*/ BOOL T2WorldPlugin::IsHoliday(T2DateTime* inDateTime) const { + return ((T2WorldDef *) mTemplatePlugin)->IsHoliday(inDateTime); } -/*virtual*/ int T2WorldPlugin::IsRainyDay(T2DateTime*) { +/*virtual*/ BOOL T2WorldPlugin::IsRainyDay(T2DateTime* inDateTime) { + return ((T2WorldDef *) mTemplatePlugin)->IsRainyDay(inDateTime); } void T2WorldPlugin::_DrawClock(CWnd*, unsigned int) { @@ -36,17 +86,33 @@ void T2WorldPlugin::_DrawCalendar(CWnd*, unsigned int) { void T2WorldPlugin::_DrawFunds(CWnd*, int) { } -/*virtual*/ int T2WorldPlugin::CheckGameLevel(T2WorldDef*, T2TowerDoc*) { +/*virtual*/ int T2WorldPlugin::CheckGameLevel(T2WorldDef* inWorldDef, T2TowerDoc* inDoc) { + int result = 0; + + if (inDoc->mGameLevel <= inWorldDef->mNumOfGradeDef) { + T2Pool *thePool = inDoc->towerDoc_vf130(); + if (thePool) { + GradeDef gradeDef = inWorldDef->mGradeDef[inDoc->mGameLevel - 1]; + int population = thePool->GetPopulation(); + + if ((inDoc->mA0 & gradeDef.m0) == gradeDef.m0 && population >= gradeDef.m4) + result = 10005; + } + } + + return result; } -/*virtual*/ int T2WorldPlugin::XEventIsBeginTime(T2XEvent*, T2TowerDoc*, unsigned int) { +/*virtual*/ int T2WorldPlugin::XEventIsBeginTime(T2XEvent* inXEvent, T2TowerDoc* inDoc, unsigned int inTime) { + return inXEvent->IsBeginTime(inDoc, inTime); } -/*virtual*/ int T2WorldPlugin::XEventIsBeginDay(T2XEvent*, T2TowerDoc*, int) { +/*virtual*/ int T2WorldPlugin::XEventIsBeginDay(T2XEvent* inXEvent, T2TowerDoc* inDoc, int inDay) { + return inXEvent->IsBeginDay(inDoc, inDay); } -/*virtual*/ void T2WorldPlugin::XEventWrite(T2XEvent*, T2Archive&) { +/*virtual*/ void T2WorldPlugin::XEventWrite(T2XEvent* inXEvent, T2Archive& inArchive) { } -/*virtual*/ void T2WorldPlugin::XEventRead(T2XEvent*, T2Archive&) { +/*virtual*/ void T2WorldPlugin::XEventRead(T2XEvent* inXEvent, T2Archive& inArchive) { } diff --git a/src/T2DLL/T2WorldPlugin.h b/src/T2DLL/T2WorldPlugin.h index 5615f75..a778481 100644 --- a/src/T2DLL/T2WorldPlugin.h +++ b/src/T2DLL/T2WorldPlugin.h @@ -1,35 +1,38 @@ #pragma once #include "common.h" +#include "CProgramPlugin.h" -class T2WorldPlugin { +class AFX_EXT_CLASS T2WorldPlugin : public CProgramPlugin { public: - T2WorldPlugin(unsigned long, T2PluginSpecifier&); + T2WorldPlugin(DWORD inType, T2PluginSpecifier& inSpecifier); virtual ~T2WorldPlugin(); - virtual int LoadAllTemplatePlugin(T2WorldDef*, T2TemplatePluginDB*); virtual T2WorldDef* LoadT2WorldDef(); - virtual void InitFloorInfoProc(T2WorldDef*, T2FloorInfo&); - virtual void InitBkgndInfoProc(T2WorldDef*, BkgndInfo*); - virtual void InitializeDocumentProc(T2TowerDoc*); - virtual int IsHoliday(T2DateTime*) const; - virtual int IsRainyDay(T2DateTime*); + virtual BOOL LoadAllTemplatePlugin(T2WorldDef* inWorldDef, T2TemplatePluginDB* inDB); + virtual void InitFloorInfoProc(T2WorldDef* inWorldDef, T2FloorInfo& inFloorInfo); + virtual void InitBkgndInfoProc(T2WorldDef* inWorldDef, BkgndInfo* inBkgndInfoPtr); + virtual void InitializeDocumentProc(T2TowerDoc* inDoc); + virtual BOOL IsHoliday(T2DateTime* inDateTime) const; + virtual BOOL IsRainyDay(T2DateTime* inDateTime); + virtual int CheckGameLevel(T2WorldDef* inWorldDef, T2TowerDoc* inDoc); + virtual int CheckTreasure(T2TowerDoc* inDoc, T2TreasureStatus*) { return 0; } + virtual int XEventInit(T2XEvent* inXEvent, CResFile*) { return 0; } + virtual int XEventDestruct(T2XEvent* inXEvent) { return 0; } + virtual int XEventStart(T2XEvent* inXEvent, T2TowerDoc* inDoc) { return 0; } + virtual int XEventExec(T2XEvent* inXEvent, T2TowerDoc* inDoc) { return 0; } + virtual int XEventStop(T2XEvent* inXEvent, T2TowerDoc* inDoc) { return 0; } + virtual int XEventIsBeginTime(T2XEvent* inXEvent, T2TowerDoc* inDoc, unsigned int inTime); + virtual int XEventIsBeginDay(T2XEvent* inXEvent, T2TowerDoc* inDoc, int inDay); + virtual void XEventWrite(T2XEvent* inXEvent, T2Archive& inArchive); + virtual void XEventRead(T2XEvent* inXEvent, T2Archive& inArchive); + virtual int XEventDlgHook(T2XEvent* inXEvent, T2TowerDoc* inDoc, T2EventDialog*, unsigned int inResult) { return inResult; } + + int GetNumOfClockStyle() { return mNumOfClockStyle; } + protected: void _DrawClock(CWnd*, unsigned int); void _DrawCalendar(CWnd*, unsigned int); void _DrawFunds(CWnd*, int); -public: - virtual int CheckGameLevel(T2WorldDef*, T2TowerDoc*); - virtual int XEventIsBeginTime(T2XEvent*, T2TowerDoc*, unsigned int); - virtual int XEventIsBeginDay(T2XEvent*, T2TowerDoc*, int); - virtual void XEventWrite(T2XEvent*, T2Archive&); - virtual void XEventRead(T2XEvent*, T2Archive&); - int GetNumOfClockStyle() {} - virtual int CheckTreasure(T2TowerDoc*, T2TreasureStatus*) {} - virtual int XEventInit(T2XEvent*, CResFile*) {} - virtual int XEventDestruct(T2XEvent*) {} - virtual int XEventStart(T2XEvent*, T2TowerDoc*) {} - virtual int XEventExec(T2XEvent*, T2TowerDoc*) {} - virtual int XEventStop(T2XEvent*, T2TowerDoc*) {} - virtual int XEventDlgHook(T2XEvent*, T2TowerDoc*, T2EventDialog*, unsigned int) {} - T2WorldPlugin& operator=(T2WorldPlugin&) {} + int mNumOfClockStyle; + int m70; }; diff --git a/src/T2DLL/T2XEvent.cpp b/src/T2DLL/T2XEvent.cpp index ed84be7..a8624a8 100644 --- a/src/T2DLL/T2XEvent.cpp +++ b/src/T2DLL/T2XEvent.cpp @@ -1,55 +1,138 @@ +#include "T2DlgItem.h" +#include "T2WorldDef.h" +#include "T2WorldPlugin.h" #include "T2XEvent.h" -T2XEvent::T2XEvent(T2TowerEvent*, CResFile*, unsigned long, int) { +T2XEvent::T2XEvent(T2TowerEvent* inTowerEvent, CResFile* inResFile, DWORD inID, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + mID = inID; + mRefCon = 0; + Init(inResFile); } -T2XEvent::T2XEvent(T2XEvent*, int) { +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*) { +/*virtual*/ void T2XEvent::Init(CResFile* inResFile) { + T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin()); + int res = thePlugin->XEventInit(this, inResFile); } -/*virtual*/ unsigned long T2XEvent::GetID() { +/*virtual*/ DWORD T2XEvent::GetID() { + return mID; } -/*virtual*/ int T2XEvent::Start(T2TowerDoc*) { +/*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*) { +/*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*) { +/*virtual*/ void T2XEvent::StopEvent(T2TowerDoc* inDoc) { + T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin()); + int res = thePlugin->XEventStop(this, inDoc); } -/*virtual*/ int T2XEvent::IsBeginTime(unsigned int) { +/*virtual*/ BOOL T2XEvent::IsBeginTime(unsigned int inTime) { + T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin()); + return thePlugin->XEventIsBeginTime(this, GetTowerDoc(), inTime); } -/*virtual*/ int T2XEvent::IsBeginTime(T2TowerDoc*, unsigned int) { +/*virtual*/ BOOL T2XEvent::IsBeginTime(T2TowerDoc* inDoc, unsigned int inTime) { + return false; } -/*virtual*/ int T2XEvent::IsBeginDay(int) { +/*virtual*/ BOOL T2XEvent::IsBeginDay(int inDay) { + T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin()); + return thePlugin->XEventIsBeginDay(this, GetTowerDoc(), inDay); } -/*virtual*/ int T2XEvent::IsBeginDay(T2TowerDoc*, int) { +/*virtual*/ BOOL T2XEvent::IsBeginDay(T2TowerDoc* inDoc, int inDay) { + return false; } -/*virtual*/ void T2XEvent::Write(T2Archive&) { +/*virtual*/ void T2XEvent::Write(T2Archive& inArchive) { + T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin()); + thePlugin->XEventWrite(this, inArchive); } -/*virtual*/ void T2XEvent::Read(T2Archive&) { +/*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) { +void T2XEvent::SetRefCon(unsigned int inRefCon) { + mRefCon = inRefCon; } -void T2XEvent::SetDialogItems(int, int, int* const, int, CString&) { +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*, unsigned int, T2TowerDoc*) { +/*virtual*/ unsigned int T2XEvent::DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc) { + T2WorldPlugin *thePlugin = ((T2WorldPlugin *) GetWorldDef()->GetPlugin()); + return thePlugin->XEventDlgHook(this, inDoc, inDialog, inResult); } diff --git a/src/T2DLL/T2XEvent.h b/src/T2DLL/T2XEvent.h index f3788a1..e556aaa 100644 --- a/src/T2DLL/T2XEvent.h +++ b/src/T2DLL/T2XEvent.h @@ -1,28 +1,37 @@ #pragma once #include "common.h" +#include "LArray.h" +#include "T2EventItem.h" -class T2XEvent { +class AFX_EXT_CLASS T2XEvent : public T2EventItem { public: - T2XEvent(T2TowerEvent*, CResFile*, unsigned long, int); - T2XEvent(T2XEvent*, int); + T2XEvent(T2TowerEvent* inTowerEvent, CResFile* inResFile, DWORD inID, int inSubID); + T2XEvent(T2XEvent* inXEvent, int inSubID); virtual ~T2XEvent(); - virtual void Init(CResFile*); - virtual unsigned long GetID(); - virtual int Start(T2TowerDoc*); - virtual int Exec(T2TowerDoc*); - virtual void StopEvent(T2TowerDoc*); - virtual int IsBeginTime(unsigned int); - virtual int IsBeginTime(T2TowerDoc*, unsigned int); - virtual int IsBeginDay(int); - virtual int IsBeginDay(T2TowerDoc*, int); - virtual void Write(T2Archive&); - virtual void Read(T2Archive&); + virtual DWORD GetID(); + virtual void Init(CResFile* inResFile); + virtual BOOL IsBeginTime(unsigned int inTime); + virtual BOOL IsBeginDay(int inDay); + virtual BOOL Start(T2TowerDoc* inDoc); + virtual int Exec(T2TowerDoc* inDoc); + virtual void StopEvent(T2TowerDoc* inDoc); + virtual void Write(T2Archive& inArchive); + virtual void Read(T2Archive& inArchive); + virtual BOOL IsXEvent() { return true; } + virtual unsigned int DialogHook(T2EventDialog* inDialog, unsigned int inResult, T2TowerDoc* inDoc); + virtual BOOL IsBeginTime(T2TowerDoc* inDoc, unsigned int inTime); + virtual BOOL IsBeginDay(T2TowerDoc* inDoc, int inDay); + unsigned int GetRefCon(); - void SetRefCon(unsigned int); - void SetDialogItems(int, int, int* const, int, CString&); - virtual unsigned int DialogHook(T2EventDialog*, unsigned int, T2TowerDoc*); + void SetRefCon(unsigned int inRefCon); + void SetDialogItems(int inItem1, int inItem2, int* const inItemArray, int inItem4, CString& inText); - virtual int IsXEvent() {} - T2XEvent(const T2XEvent&) {} - T2XEvent& operator=(const T2XEvent&) {} +protected: + DWORD mID; + unsigned int mRefCon; + int mDlgItem1; + int mDlgItem2; + LArray mDlgItemArray; + int mDlgItem4; + CString mDlgText; }; diff --git a/src/T2DLL/TenantSearchDlg.cpp b/src/T2DLL/TenantSearchDlg.cpp new file mode 100644 index 0000000..5ff4c03 --- /dev/null +++ b/src/T2DLL/TenantSearchDlg.cpp @@ -0,0 +1,99 @@ +#include "T2DlgItemListBox.h" +#include "T2FloorInfo.h" +#include "T2Name.h" +#include "T2NameList.h" +#include "T2Tenant.h" +#include "T2TenantArrayList.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "TenantSearchDlg.h" +#include "UT2Utils.h" + +TenantSearchDlg::TenantSearchDlg() { + mDeleteOnClose = true; +} + +/*virtual*/ TenantSearchDlg::~TenantSearchDlg() { +} + +void TenantSearchDlg::Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt) { + mDocument = inDoc; + + T2DLGTEMPLATE tmpl; + tmpl.resID = 7120; + tmpl.pt = inPt; + tmpl.moduleHandle = inInstance; + + Realize(inParentWnd, &tmpl, inDoc, NULL, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 111, true); + ShowWindow(SW_HIDE); +} + +void TenantSearchDlg::DoFind() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + if (!theListBox) + return; + + int curSel = theListBox->GetCurSel(); + if (curSel == -1) + return; + + T2Name *theName = (T2Name *) theListBox->GetItemDataPtr(curSel); + mDocument->towerDoc_vf238(theName); +} + +void TenantSearchDlg::DoDelete() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + if (!theListBox) + return; + + int curSel = theListBox->GetCurSel(); + if (curSel == -1) + return; + + T2Name *theName = (T2Name *) theListBox->GetItemDataPtr(curSel); + mDocument->mNameDB->RemoveName(theName); + theListBox->DeleteString(curSel); +} + +/*virtual*/ void TenantSearchDlg::OnT2Create() { + T2DlgItemListBox *theListBox = (T2DlgItemListBox *) GetDlgItem(1000); + T2TenantArrayList *theList = mDocument->mFloorInfo->GetTenantArrayList(); + + if (!theListBox) + return; + if (!theList) + return; + + HFONT theFont = GetFont(); + if (theFont) + theListBox->SetFont(theFont); + + theListBox->ResetContent(); + + T2NameList *theNameDB = mDocument->mNameDB; + T2Name *theName; + LArrayIterator iterator(*theNameDB); + + while (iterator.Next(&theName)) { + int type = theName->GetType(); + if (type == kTenantNameType) { + CString nameStr; + unsigned int tenantID; + theName->GetName(nameStr, tenantID); + + CString str; + CString roomNumberStr; + + T2Tenant *theTenant = theList->GetTenantByID(tenantID); + if (theTenant) + UT2Utils::GetRoomNumberString(theTenant->GetRoomNumber(mDocument->mFloorInfo), roomNumberStr); + + roomNumberStr += " "; + str = roomNumberStr.Left(7); + str += nameStr; + + int theIndex = theListBox->AddString(str); + theListBox->SetItemDataPtr(theIndex, theName); + } + } +} diff --git a/src/T2DLL/TenantSearchDlg.h b/src/T2DLL/TenantSearchDlg.h new file mode 100644 index 0000000..93be296 --- /dev/null +++ b/src/T2DLL/TenantSearchDlg.h @@ -0,0 +1,17 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class TenantSearchDlg : public T2Dialog { +public: + TenantSearchDlg(); + virtual ~TenantSearchDlg(); + void Create(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt); + void DoFind(); + void DoDelete(); + +protected: + virtual void OnT2Create(); + + T2TowerDoc *mDocument; +}; diff --git a/src/T2DLL/UPoint.cpp b/src/T2DLL/UPoint.cpp index 0c93ea5..79aeea5 100644 --- a/src/T2DLL/UPoint.cpp +++ b/src/T2DLL/UPoint.cpp @@ -1,7 +1,15 @@ #include "UPoint.h" -/*static*/ void UPoint::MappingInRect(Point&, const RECT&) { +/*static*/ void UPoint::MappingInRect(Point& ioPt, const RECT& inRect) { + ioPt.h = (ioPt.h < inRect.right) ? ioPt.h : inRect.right; + ioPt.h = (ioPt.h >= inRect.left) ? ioPt.h : inRect.left; + ioPt.v = (ioPt.v < inRect.bottom) ? ioPt.v : inRect.bottom; + ioPt.v = (ioPt.v >= inRect.top) ? ioPt.v : inRect.top; } -/*static*/ void UPoint::MappingInRect(POINT&, const RECT&) { +/*static*/ void UPoint::MappingInRect(POINT& ioPt, const RECT& inRect) { + ioPt.x = (ioPt.x < inRect.right) ? ioPt.x : inRect.right; + ioPt.x = (ioPt.x >= inRect.left) ? ioPt.x : inRect.left; + ioPt.y = (ioPt.y < inRect.bottom) ? ioPt.y : inRect.bottom; + ioPt.y = (ioPt.y >= inRect.top) ? ioPt.y : inRect.top; } diff --git a/src/T2DLL/UPoint.h b/src/T2DLL/UPoint.h index 4ba16df..dd4c619 100644 --- a/src/T2DLL/UPoint.h +++ b/src/T2DLL/UPoint.h @@ -1,10 +1,8 @@ #pragma once #include "common.h" -class UPoint { +class AFX_EXT_CLASS UPoint { public: - static void MappingInRect(Point&, const RECT&); - static void MappingInRect(POINT&, const RECT&); - - UPoint& operator=(const UPoint&) {} + static void MappingInRect(Point& ioPt, const RECT& inRect); + static void MappingInRect(POINT& ioPt, const RECT& inRect); }; diff --git a/src/T2DLL/URect.cpp b/src/T2DLL/URect.cpp index 8b4aa21..ad2b552 100644 --- a/src/T2DLL/URect.cpp +++ b/src/T2DLL/URect.cpp @@ -1,19 +1,56 @@ #include "URect.h" -/*static*/ void URect::SetEmpty(RECT&) { +/*static*/ void URect::SetEmpty(RECT& outRect) { + ::SetRect(&outRect, 0, 0, 0, 0); } -/*static*/ void URect::Center(const RECT&, RECT&, int) { +/*static*/ void URect::Center(const RECT& inRect, RECT& ioRect, BOOL inFlag) { +#pragma var_order(yOffset, xRatio, xOffset, ratio, width1, height1, yRatio, width2, height2) + int width1 = Width(inRect); + int height1 = Height(inRect); + int width2 = Width(ioRect); + int height2 = Height(ioRect); + int xRatio, yRatio, ratio; + + if (inFlag) { + xRatio = width1 / width2; + yRatio = height1 / height2; + ratio = (xRatio > yRatio) ? yRatio : xRatio; + width2 *= ratio; + height2 *= ratio; + } + + int xOffset = inRect.left + ((width1 - width2) / 2); + int yOffset = inRect.top + ((height1 - height2) / 2); + ioRect.left = xOffset; + ioRect.top = yOffset; + ioRect.right = ioRect.left + width2; + ioRect.bottom = ioRect.top + height2; } -/*static*/ int URect::Width(const RECT&) { +/*static*/ int URect::Width(const RECT& inRect) { + return inRect.right - inRect.left; } -/*static*/ int URect::Height(const RECT&) { +/*static*/ int URect::Height(const RECT& inRect) { + return inRect.bottom - inRect.top; } -/*static*/ void URect::Union(const RECT&, const RECT&, RECT&) { +/*static*/ void URect::Union(const RECT& inRect1, const RECT& inRect2, RECT& outRect) { + if (::IsRectEmpty(&inRect1)) { + outRect = inRect2; + } else if (::IsRectEmpty(&inRect2)) { + outRect = inRect1; + } else { + CRect result; + result.IntersectRect(&inRect1, &inRect2); + ::SetRect(&outRect, result.left, result.top, result.right, result.bottom); + } } -/*static*/ POINT URect::Center(const RECT&) { +/*static*/ POINT URect::Center(const RECT& inRect) { + POINT pt; + pt.x = (inRect.left + inRect.right) / 2; + pt.y = (inRect.top + inRect.bottom) / 2; + return pt; } diff --git a/src/T2DLL/URect.h b/src/T2DLL/URect.h index 2b9b047..f2fdaaa 100644 --- a/src/T2DLL/URect.h +++ b/src/T2DLL/URect.h @@ -1,15 +1,12 @@ #pragma once #include "common.h" -class URect { +class AFX_EXT_CLASS URect : public CRect { public: - static void SetEmpty(RECT&); - static void Center(const RECT&, RECT&, int); - static int Width(const RECT&); - static int Height(const RECT&); - static void Union(const RECT&, const RECT&, RECT&); - static POINT Center(const RECT&); - - URect() {} - URect& operator=(const URect&) {} + static void SetEmpty(RECT& outRect); + static void Center(const RECT& inRect, RECT& ioRect, BOOL inFlag = false); + static int Width(const RECT& inRect); + static int Height(const RECT& inRect); + static void Union(const RECT& inRect1, const RECT& inRect2, RECT& outRect); + static POINT Center(const RECT& inRect); }; diff --git a/src/T2DLL/UT2BkgndInfo.h b/src/T2DLL/UT2BkgndInfo.h index 4786100..13c614d 100644 --- a/src/T2DLL/UT2BkgndInfo.h +++ b/src/T2DLL/UT2BkgndInfo.h @@ -8,7 +8,7 @@ struct BkgndInfo { unsigned int *arrays[1]; }; -class DLL_EXPORT UT2BkgndInfo { +class AFX_EXT_CLASS UT2BkgndInfo { public: static BkgndInfo* SetupBkgndInfo(const RECT&, int); static void DisposeBkgndInfo(BkgndInfo*&); diff --git a/src/T2DLL/UT2Coordinate.cpp b/src/T2DLL/UT2Coordinate.cpp index 4c1323e..caecdb1 100644 --- a/src/T2DLL/UT2Coordinate.cpp +++ b/src/T2DLL/UT2Coordinate.cpp @@ -1,94 +1,226 @@ #include "UT2Coordinate.h" -/*static*/ void UT2Coordinate::UnitToQD(int&, int&, int) { +/*static*/ void UT2Coordinate::UnitToQD(int& ioV, int& ioH, int inZoomLevel) { + ioV *= UnitVSize(inZoomLevel); + ioH <<= (3 - inZoomLevel); } -/*static*/ void UT2Coordinate::UnitToQD(POINT&, int, int) { +/*static*/ void UT2Coordinate::UnitToQD(POINT& ioPoint, int inZoomLevel, BOOL inExcludeRoof) { + ioPoint.y *= UnitVSize(inZoomLevel); + ioPoint.x <<= (3 - inZoomLevel); + if (!inExcludeRoof) + ioPoint.y += CalcRoofThick(inZoomLevel); } -/*static*/ void UT2Coordinate::UnitToQD(RECT&, int, int) { +/*static*/ void UT2Coordinate::UnitToQD(RECT& ioRect, int inZoomLevel, BOOL inExcludeRoofAndFloor) { + ioRect.top *= UnitVSize(inZoomLevel); + ioRect.left <<= (3 - inZoomLevel); + ioRect.bottom *= UnitVSize(inZoomLevel); + ioRect.right <<= (3 - inZoomLevel); + if (!inExcludeRoofAndFloor) { + ioRect.top += CalcRoofThick(inZoomLevel); + ioRect.bottom -= CalcFloorThick(inZoomLevel); + } } -/*static*/ void UT2Coordinate::UnitToQD(const RECT&, RECT&, int, int) { +/*static*/ void UT2Coordinate::UnitToQD(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel, BOOL inExcludeRoofAndFloor) { + outQDRect.top = inUnitRect.top * UnitVSize(inZoomLevel); + outQDRect.left = inUnitRect.left << (3 - inZoomLevel); + outQDRect.bottom = inUnitRect.bottom * UnitVSize(inZoomLevel); + outQDRect.right = inUnitRect.right << (3 - inZoomLevel); + if (!inExcludeRoofAndFloor) { + outQDRect.top += CalcRoofThick(inZoomLevel); + outQDRect.bottom -= CalcFloorThick(inZoomLevel); + } } -/*static*/ void UT2Coordinate::UnitToQDRoof(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::UnitToQDRoof(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel) { + outQDRect.top = inUnitRect.top * UnitVSize(inZoomLevel); + outQDRect.left = inUnitRect.left << (3 - inZoomLevel); + outQDRect.bottom = outQDRect.top + CalcRoofThick(inZoomLevel); + outQDRect.right = inUnitRect.right << (3 - inZoomLevel); } -/*static*/ void UT2Coordinate::UnitToQDFloor(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::UnitToQDFloor(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel) { + outQDRect.left = inUnitRect.left << (3 - inZoomLevel); + outQDRect.bottom = inUnitRect.bottom * UnitVSize(inZoomLevel); + outQDRect.right = inUnitRect.right << (3 - inZoomLevel); + outQDRect.top = outQDRect.bottom - CalcFloorThick(inZoomLevel); } -/*static*/ void UT2Coordinate::UnitToOffRect(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::UnitToOffRect(const RECT& inUnitRect, RECT& outQDRect, int inHeight) { + UnitToQD(inUnitRect, outQDRect); + OffsetRect(&outQDRect, 0, -outQDRect.top); + int var = outQDRect.bottom; + OffsetRect(&outQDRect, 0, var * inHeight); } -/*static*/ void UT2Coordinate::QDToUnit(int&, int&, int) { +/*static*/ void UT2Coordinate::QDToUnit(int& ioV, int& ioH, int inZoomLevel) { + ioV /= UnitVSize(inZoomLevel); + ioH >>= (3 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToUnit(POINT&, int) { +/*static*/ void UT2Coordinate::QDToUnit(POINT& ioPoint, int inZoomLevel) { + ioPoint.y /= UnitVSize(inZoomLevel); + ioPoint.x >>= (3 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToUnit(SDimension16&, int) { +/*static*/ void UT2Coordinate::QDToUnit(SDimension16& ioSize, int inZoomLevel) { + ioSize.height /= UnitVSize(inZoomLevel); + ioSize.width >>= (3 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToUnit(RECT&, int) { +/*static*/ void UT2Coordinate::QDToUnit(RECT& ioRect, int inZoomLevel) { + RECT orig = ioRect; + ioRect.top /= UnitVSize(inZoomLevel); + ioRect.left >>= (3 - inZoomLevel); + ioRect.bottom /= UnitVSize(inZoomLevel); + ioRect.right >>= (3 - inZoomLevel); + + if ((orig.bottom % UnitVSize(inZoomLevel)) != 0) + ioRect.bottom++; + if ((orig.right % UnitHSize(inZoomLevel)) != 0) + ioRect.right++; } -/*static*/ void UT2Coordinate::QDToUnit(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::QDToUnit(const RECT& inQDRect, RECT& outUnitRect, int inZoomLevel) { + outUnitRect.top = inQDRect.top / UnitVSize(inZoomLevel); + outUnitRect.left = inQDRect.left >> (3 - inZoomLevel); + outUnitRect.bottom = inQDRect.bottom / UnitVSize(inZoomLevel); + outUnitRect.right = inQDRect.right >> (3 - inZoomLevel); + + if ((inQDRect.bottom % UnitVSize(inZoomLevel)) != 0) + outUnitRect.bottom++; + if ((inQDRect.right % UnitHSize(inZoomLevel)) != 0) + outUnitRect.right++; } -/*static*/ void UT2Coordinate::NoRoofQDToUnit(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::NoRoofQDToUnit(const RECT& inQDRect, RECT& outUnitRect, int inZoomLevel) { + outUnitRect.top = inQDRect.top / UnitVSize(inZoomLevel); + outUnitRect.left = inQDRect.left >> (3 - inZoomLevel); + outUnitRect.bottom = (inQDRect.bottom + CalcRoofThick(inZoomLevel) + CalcFloorThick(inZoomLevel)) / UnitVSize(inZoomLevel); + outUnitRect.right = inQDRect.right >> (3 - inZoomLevel); } -/*static*/ void UT2Coordinate::BkgndToQD(int&, int&, int) { +/*static*/ void UT2Coordinate::BkgndToQD(int& ioV, int& ioH, int inZoomLevel) { + ioV *= BkgndVSize(inZoomLevel); + ioH <<= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::BkgndToQD(POINT&, int) { +/*static*/ void UT2Coordinate::BkgndToQD(POINT& ioPoint, int inZoomLevel) { + ioPoint.y *= BkgndVSize(inZoomLevel); + ioPoint.x <<= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::BkgndToQD(RECT&, int) { +/*static*/ void UT2Coordinate::BkgndToQD(RECT& ioRect, int inZoomLevel) { + ioRect.top *= BkgndVSize(inZoomLevel); + ioRect.left <<= (6 - inZoomLevel); + ioRect.bottom *= BkgndVSize(inZoomLevel); + ioRect.right <<= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::BkgndToQD(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::BkgndToQD(const RECT& inBkgndRect, RECT& outQDRect, int inZoomLevel) { + outQDRect.top = inBkgndRect.top * BkgndVSize(inZoomLevel); + outQDRect.left = inBkgndRect.left << (6 - inZoomLevel); + outQDRect.bottom = inBkgndRect.bottom * BkgndVSize(inZoomLevel); + outQDRect.right = inBkgndRect.right << (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToBkgnd(int&, int&, int) { +/*static*/ void UT2Coordinate::QDToBkgnd(int& ioV, int& ioH, int inZoomLevel) { + ioV /= BkgndVSize(inZoomLevel); + ioH >>= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToBkgnd(POINT&, int) { +/*static*/ void UT2Coordinate::QDToBkgnd(POINT& ioPoint, int inZoomLevel) { + ioPoint.y /= BkgndVSize(inZoomLevel); + ioPoint.x >>= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToBkgnd(SDimension16&, int) { +/*static*/ void UT2Coordinate::QDToBkgnd(SDimension16& ioSize, int inZoomLevel) { + ioSize.height /= BkgndVSize(inZoomLevel); + ioSize.width >>= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToBkgnd(RECT&, int) { +/*static*/ void UT2Coordinate::QDToBkgnd(RECT& ioRect, int inZoomLevel) { + ioRect.top /= BkgndVSize(inZoomLevel); + ioRect.left >>= (6 - inZoomLevel); + ioRect.bottom /= BkgndVSize(inZoomLevel); + ioRect.right >>= (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::QDToBkgnd(const RECT&, RECT&, int) { +/*static*/ void UT2Coordinate::QDToBkgnd(const RECT& inQDRect, RECT& outBkgndRect, int inZoomLevel) { + outBkgndRect.top = inQDRect.top / BkgndVSize(inZoomLevel); + outBkgndRect.left = inQDRect.left >> (6 - inZoomLevel); + outBkgndRect.bottom = inQDRect.bottom / BkgndVSize(inZoomLevel); + outBkgndRect.right = inQDRect.right >> (6 - inZoomLevel); } -/*static*/ void UT2Coordinate::UnitToBkgnd(const RECT&, RECT&) { +/*static*/ void UT2Coordinate::UnitToBkgnd(const RECT& inUnitRect, RECT& outBkgndRect) { + outBkgndRect.top = inUnitRect.top >> 1; + outBkgndRect.left = inUnitRect.left >> 3; + outBkgndRect.bottom = inUnitRect.bottom >> 1; + outBkgndRect.right = inUnitRect.right >> 3; + + if ((inUnitRect.bottom % 2) != 0) + outBkgndRect.bottom++; + if ((inUnitRect.right % 8) != 0) + outBkgndRect.right++; } -/*static*/ void UT2Coordinate::BkgndToUnit(const RECT&, RECT&) { +/*static*/ void UT2Coordinate::BkgndToUnit(const RECT& inBkgndRect, RECT& outUnitRect) { + outUnitRect.top = inBkgndRect.top << 1; + outUnitRect.left = inBkgndRect.left << 3; + outUnitRect.bottom = inBkgndRect.bottom << 1; + outUnitRect.right = inBkgndRect.right << 3; } -/*static*/ void UT2Coordinate::MakeRect(RECT&, const POINT&, const SDimension16&) { +/*static*/ void UT2Coordinate::MakeRect(RECT& outRect, const POINT& inPoint, const SDimension16& inSize) { + outRect.top = inPoint.y; + outRect.left = inPoint.x; + outRect.bottom = outRect.top + inSize.height; + outRect.right = outRect.left + inSize.width; } -/*static*/ void UT2Coordinate::MakeRect(RECT&, const POINT&, int, int) { +/*static*/ void UT2Coordinate::MakeRect(RECT& outRect, const POINT& inPoint, int inWidth, int inHeight) { + outRect.top = inPoint.y; + outRect.left = inPoint.x; + outRect.bottom = outRect.top + inHeight; + outRect.right = outRect.left + inWidth; } -/*static*/ void UT2Coordinate::MakeRect(RECT&, int, int) { +/*static*/ void UT2Coordinate::MakeRect(RECT& outRect, int inWidth, int inHeight) { + outRect.top = 0; + outRect.left = 0; + outRect.bottom = inHeight; + outRect.right = inWidth; } -/*static*/ void UT2Coordinate::MakeCenterRect(RECT&, const POINT&, int, int) { +/*static*/ void UT2Coordinate::MakeCenterRect(RECT& outRect, const POINT& inPoint, int inWidth, int inHeight) { + int xDist = inWidth >> 1; + int yDist = inHeight >> 1; + outRect.top = inPoint.y - yDist; + outRect.left = inPoint.x - xDist; + outRect.bottom = outRect.top + inHeight; + outRect.right = outRect.left + inWidth; } -/*static*/ void UT2Coordinate::AddRect(RECT&, const RECT&) { +/*static*/ void UT2Coordinate::AddRect(RECT& ioRectA, const RECT& inRectB) { + ioRectA.top += inRectB.top; + ioRectA.left += inRectB.left; + ioRectA.bottom += inRectB.bottom; + ioRectA.right += inRectB.right; } -/*static*/ void UT2Coordinate::SubRect(RECT&, const RECT&) { +/*static*/ void UT2Coordinate::SubRect(RECT& ioRectA, const RECT& inRectB) { + ioRectA.top -= inRectB.top; + ioRectA.left -= inRectB.left; + ioRectA.bottom -= inRectB.bottom; + ioRectA.right -= inRectB.right; } -/*static*/ void UT2Coordinate::ZoomOut(RECT&, int) { +/*static*/ void UT2Coordinate::ZoomOut(RECT& ioRect, int inZoomLevel) { + ioRect.top >>= inZoomLevel; + ioRect.left >>= inZoomLevel; + ioRect.bottom >>= inZoomLevel; + ioRect.right >>= inZoomLevel; } diff --git a/src/T2DLL/UT2Coordinate.h b/src/T2DLL/UT2Coordinate.h index a9e3586..d3cfbcb 100644 --- a/src/T2DLL/UT2Coordinate.h +++ b/src/T2DLL/UT2Coordinate.h @@ -1,47 +1,49 @@ #pragma once #include "common.h" -class UT2Coordinate { +class AFX_EXT_CLASS UT2Coordinate { public: - static void UnitToQD(int&, int&, int); - static void UnitToQD(POINT&, int, int); - static void UnitToQD(RECT&, int, int); - static void UnitToQD(const RECT&, RECT&, int, int); - static void UnitToQDRoof(const RECT&, RECT&, int); - static void UnitToQDFloor(const RECT&, RECT&, int); - static void UnitToOffRect(const RECT&, RECT&, int); - static void QDToUnit(int&, int&, int); - static void QDToUnit(POINT&, int); - static void QDToUnit(SDimension16&, int); - static void QDToUnit(RECT&, int); - static void QDToUnit(const RECT&, RECT&, int); - static void NoRoofQDToUnit(const RECT&, RECT&, int); - static void BkgndToQD(int&, int&, int); - static void BkgndToQD(POINT&, int); - static void BkgndToQD(RECT&, int); - static void BkgndToQD(const RECT&, RECT&, int); - static void QDToBkgnd(int&, int&, int); - static void QDToBkgnd(POINT&, int); - static void QDToBkgnd(SDimension16&, int); - static void QDToBkgnd(RECT&, int); - static void QDToBkgnd(const RECT&, RECT&, int); - static void UnitToBkgnd(const RECT&, RECT&); - static void BkgndToUnit(const RECT&, RECT&); - static void MakeRect(RECT&, const POINT&, const SDimension16&); - static void MakeRect(RECT&, const POINT&, int, int); - static void MakeRect(RECT&, int, int); - static void MakeCenterRect(RECT&, const POINT&, int, int); - static void AddRect(RECT&, const RECT&); - static void SubRect(RECT&, const RECT&); - static void ZoomOut(RECT&, int); + static void UnitToQD(int& ioV, int& ioH, int inZoomLevel = 0); + static void UnitToQD(POINT& ioPoint, int inZoomLevel = 0, BOOL inExcludeRoof = false); + static void UnitToQD(RECT& ioRect, int inZoomLevel = 0, BOOL inExcludeRoofAndFloor = false); + static void UnitToQD(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel = 0, BOOL inExcludeRoofAndFloor = false); + static void UnitToQDRoof(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel = 0); + static void UnitToQDFloor(const RECT& inUnitRect, RECT& outQDRect, int inZoomLevel = 0); + static void UnitToOffRect(const RECT& inUnitRect, RECT& outQDRect, int inHeight = 0); + static void QDToUnit(int& ioV, int& ioH, int inZoomLevel = 0); + static void QDToUnit(POINT& ioPoint, int inZoomLevel = 0); + static void QDToUnit(SDimension16& ioSize, int inZoomLevel = 0); + static void QDToUnit(RECT& ioRect, int inZoomLevel = 0); + static void QDToUnit(const RECT& inQDRect, RECT& outUnitRect, int inZoomLevel = 0); + static void NoRoofQDToUnit(const RECT& inQDRect, RECT& outUnitRect, int inZoomLevel = 0); + static void BkgndToQD(int& ioV, int& ioH, int inZoomLevel = 0); + static void BkgndToQD(POINT& ioPoint, int inZoomLevel = 0); + static void BkgndToQD(RECT& ioRect, int inZoomLevel = 0); + static void BkgndToQD(const RECT& inBkgndRect, RECT& outQDRect, int inZoomLevel = 0); + static void QDToBkgnd(int& ioV, int& ioH, int inZoomLevel = 0); + static void QDToBkgnd(POINT& ioPoint, int inZoomLevel = 0); + static void QDToBkgnd(SDimension16& ioSize, int inZoomLevel = 0); + static void QDToBkgnd(RECT& ioRect, int inZoomLevel = 0); + static void QDToBkgnd(const RECT& inQDRect, RECT& outBkgndRect, int inZoomLevel = 0); + static void UnitToBkgnd(const RECT& inUnitRect, RECT& outBkgndRect); + static void BkgndToUnit(const RECT& inBkgndRect, RECT& outUnitRect); + static void MakeRect(RECT& outRect, const POINT& inPoint, const SDimension16& inSize); + static void MakeRect(RECT& outRect, const POINT& inPoint, int inWidth, int inHeight); + static void MakeRect(RECT& outRect, int inWidth, int inHeight); + static void MakeCenterRect(RECT& outRect, const POINT& inPoint, int inWidth, int inHeight); + static void AddRect(RECT& ioRectA, const RECT& inRectB); + static void SubRect(RECT& ioRectA, const RECT& inRectB); + static void ZoomOut(RECT& ioRect, int inZoomLevel); - // fixme - static int UnitVSize(int) { return 0; } - static int UnitHSize(int) { return 0; } - static int BkgndVSize(int) { return 0; } - static int BkgndHSize(int) { return 0; } - static int CalcRoofThick(int) { return 0; } - static int CalcFloorThick(int) { return 0; } - static void QDToOff(POINT&, int) {} - static int RectWidth(const RECT&) { return 0; } + static int UnitVSize(int inZoomLevel) { return 36 >> inZoomLevel; } + static int UnitHSize(int inZoomLevel) { return 8 >> inZoomLevel; } + static int BkgndVSize(int inZoomLevel) { return 72 >> inZoomLevel; } + static int BkgndHSize(int inZoomLevel) { return 64 >> inZoomLevel; } + static int CalcRoofThick(int inZoomLevel) { return 8U >> inZoomLevel; } + static int CalcFloorThick(int inZoomLevel) { return 4U >> inZoomLevel; } + static void QDToOff(POINT& ioPt, int inZoomLevel) { + ioPt.y <<= inZoomLevel; + ioPt.x <<= inZoomLevel; + } + static int RectWidth(const RECT& inRect) { return inRect.right - inRect.left; } }; diff --git a/src/T2DLL/UT2Utils.cpp b/src/T2DLL/UT2Utils.cpp index 281ec30..3af844f 100644 --- a/src/T2DLL/UT2Utils.cpp +++ b/src/T2DLL/UT2Utils.cpp @@ -1,13 +1,53 @@ #include "UT2Utils.h" -/*static*/ unsigned int UT2Utils::Float2Int(float) { +/*static*/ unsigned int UT2Utils::Float2Int(float inValue) { + unsigned int result = 0; + + if (inValue > 0.0f) { + result = inValue; + unsigned int decimal = (inValue - result) * 10.0f; + if (decimal > 0 && Randomize(10) < decimal) + result++; + } + + return result; } -/*static*/ void UT2Utils::GetRoomNumberString(int, CString&) { +/*static*/ void UT2Utils::GetRoomNumberString(int inNumber, CString& outStr) { + outStr.Format("%d", inNumber); + if (outStr.GetAt(0) == '-') + outStr.SetAt(0, 'B'); } -/*static*/ void UT2Utils::GetHourMinute(int, int&, int&) { +/*static*/ void UT2Utils::GetHourMinute(int inValue, int& outHour, int& outMinute) { + outHour = inValue / 60; + outMinute = inValue % 60; } -/*static*/ void UT2Utils::GetMonetaryString(int, CString&) { +/*static*/ void UT2Utils::GetMonetaryString(int inValue, CString& outStr) { + BOOL isNegative = false; + if (inValue < 0) { + isNegative = true; + inValue = -inValue; + } + + outStr.Format("%d", inValue); + + int len = outStr.GetLength(); + if (len > 3) { + int numExtraDigits = len % 3; + int numGroups = len / 3; + if (numExtraDigits == 0) { + numExtraDigits = 3; + numGroups--; + } + + for (int i = 0; i < numGroups; i++) { + int offset = numExtraDigits + (i * 3) + i; + outStr = outStr.Left(offset) + "," + outStr.Mid(offset); + } + } + + if (isNegative) + outStr = "-" + outStr; } diff --git a/src/T2DLL/UT2Utils.h b/src/T2DLL/UT2Utils.h index df542ac..37bc43b 100644 --- a/src/T2DLL/UT2Utils.h +++ b/src/T2DLL/UT2Utils.h @@ -1,12 +1,14 @@ #pragma once #include "common.h" -class UT2Utils { +class AFX_EXT_CLASS UT2Utils { public: - static unsigned int Float2Int(float); - static void GetRoomNumberString(int, CString&); - static void GetHourMinute(int, int&, int&); - static void GetMonetaryString(int, CString&); + static unsigned int Float2Int(float inValue); + static void GetRoomNumberString(int inNumber, CString& outStr); + static void GetHourMinute(int inValue, int& outHour, int& outMinute); + static void GetMonetaryString(int inValue, CString& outStr); - static int Randomize(int) { return 1; } + static int Randomize(int inRange) { + return (inRange == 0) ? 0 : (rand() % inRange); + } }; diff --git a/src/T2DLL/WalkerDlg.cpp b/src/T2DLL/WalkerDlg.cpp new file mode 100644 index 0000000..f93a376 --- /dev/null +++ b/src/T2DLL/WalkerDlg.cpp @@ -0,0 +1,87 @@ +#include "CT2App.h" +#include "T2CtrlPalette.h" +#include "T2DlgItem.h" +#include "T2MainWindow.h" +#include "T2MWControl.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" +#include "WalkerDlg.h" + +WalkerDlg::WalkerDlg() { + mDeleteOnClose = true; +} + +/*virtual*/ WalkerDlg::~WalkerDlg() { +} + +void WalkerDlg::Setup(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt, T2ImageObj *inImageObj) { + mDocument = inDoc; + + T2DLGTEMPLATE tmpl; + tmpl.resID = 7030; + tmpl.pt = inPt; + tmpl.moduleHandle = inInstance; + + Realize(inParentWnd, &tmpl, inDoc, inImageObj, inDoc->mWorldDef->GetPalette(), false, inParentWnd, 202, true); + ShowWindow(SW_HIDE); +} + +void WalkerDlg::Revert() { + if (mFC != 1) { + T2DlgItem *item = GetT2DlgItem(107 + mFC); + item->SetValue(0); + + mFC = 1; + + item = GetT2DlgItem(107 + mFC); + item->SetValue(1); + } +} + +void WalkerDlg::Save() { + T2CtrlPalette *theCtrlPalette = ((CT2App *) AfxGetApp())->mMainWindow->mCtrlPalette; + if (!theCtrlPalette) + return; + + T2MWControl *theSlider = theCtrlPalette->mSliderControl; + if (!theSlider) + return; + + int value = 0; + if (mFC != 0) + value = 7 - mFC; + theSlider->SetData(value); + + if (mFC == 0) + mDocument->towerDoc_vf14C(-1); + else + mDocument->towerDoc_vf14C(mFC); +} + +/*virtual*/ void WalkerDlg::OnT2Create() { + mFC = mDocument->towerDoc_vf148(); + if (mFC == -1) + mFC = 0; + + T2DlgItem *item = GetT2DlgItem(107 + mFC); + item->SetValue(1); +} + +/*virtual*/ int WalkerDlg::OnT2DialogCommand(UINT cmd, long data) { + int result = 1; + WORD w = LOWORD(cmd); + + if (w >= 107 && w <= 113) { + T2DlgItem *item = GetT2DlgItem(107 + mFC); + item->SetValue(0); + + mFC = w - 107; + + item = GetT2DlgItem(w); + item->SetValue(1); + } else { + result = T2Dialog::OnT2DialogCommand(cmd, data); + } + + return result; +} diff --git a/src/T2DLL/WalkerDlg.h b/src/T2DLL/WalkerDlg.h new file mode 100644 index 0000000..9b04fc1 --- /dev/null +++ b/src/T2DLL/WalkerDlg.h @@ -0,0 +1,19 @@ +#pragma once +#include "common.h" +#include "T2Dialog.h" + +class WalkerDlg : public T2Dialog { +public: + WalkerDlg(); + virtual ~WalkerDlg(); + void Setup(T2TowerDoc *inDoc, HINSTANCE inInstance, CWnd *inParentWnd, const POINT &inPt, T2ImageObj *inImageObj); + void Revert(); + void Save(); + +protected: + virtual int OnT2DialogCommand(UINT cmd, long data); + virtual void OnT2Create(); + + T2TowerDoc *mDocument; + int mFC; +}; diff --git a/src/T2DLL/Wave.cpp b/src/T2DLL/Wave.cpp index 021583b..5523057 100644 --- a/src/T2DLL/Wave.cpp +++ b/src/T2DLL/Wave.cpp @@ -1,34 +1,229 @@ +//----------------------------------------------------------------- +// Wave Object +// C++ Source - Wave.cpp +//----------------------------------------------------------------- + +//----------------------------------------------------------------- +// Inclusions +//----------------------------------------------------------------- +#include "common.h" +#include "GlobalFunc.h" +//----------------------------------------------------------------- #include "Wave.h" +#include "MMIO.h" + +//----------------------------------------------------------------- +// MFC Debugging Support +//----------------------------------------------------------------- +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif -CWave::CWave() { + +//----------------------------------------------------------------- +// CWave Public Constructor(s)/Destructor +//----------------------------------------------------------------- +CWave::CWave() : m_dwImageLen(0), m_bResource(FALSE), + m_pImageData(NULL) +{ } -CWave::CWave(const CString&) { +CWave::CWave(const CString &str) : m_dwImageLen(0), + m_bResource(FALSE), m_pImageData(NULL) +{ + Create(str); } -CWave::CWave(unsigned int, HINSTANCE) { +CWave::CWave(UINT uiResID, HMODULE hmod) : m_dwImageLen(0), + m_bResource(TRUE), m_pImageData(NULL) +{ + Create(uiResID, hmod); } -/*virtual*/ CWave::~CWave() { +CWave::~CWave() { + // Free the wave image data + Free(); } -int CWave::Create(const CString&) { +//----------------------------------------------------------------- +// CWave Public Methods +//----------------------------------------------------------------- +BOOL CWave::Create(const CString &str) +{ + // Free any previous wave image data + Free(); + + // Flag as regular memory + m_bResource = FALSE; + + // Open the wave file + CFile file; + if (!file.Open(str, CFile::modeRead)) + return FALSE; + + // Get the file length + m_dwImageLen = file.GetLength(); + + // Allocate and lock memory for the image data + m_pImageData = (BYTE*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | + GMEM_SHARE, m_dwImageLen)); + if (!m_pImageData) + return FALSE; + + // Read the image data from the file + file.Read(m_pImageData, m_dwImageLen); + + return TRUE; } -int CWave::Create(unsigned int, HINSTANCE) { +BOOL CWave::Create(UINT uiResID, HMODULE hmod) +{ + // Free any previous wave image data + Free(); + + // Flag as resource memory + m_bResource = TRUE; + + // Find the wave resource + HRSRC hresInfo; + hresInfo = FindResource(hmod, MAKEINTRESOURCE(uiResID), + "WAVE"); + if (!hresInfo) { + CString idStr; + idStr.Format("%d", uiResID); + + CString error = "CWave::Create ERROR : " + idStr + " " + GetModuleName(hmod) + "\n"; + OutputDebugString(error); + _ASSERT(0); + } + + // Load the wave resource + HGLOBAL hgmemWave = LoadResource(hmod, hresInfo); + + if (hgmemWave) + { + // Get pointer to and length of the wave image data + m_pImageData= (BYTE*)LockResource(hgmemWave); + m_dwImageLen = SizeofResource(hmod, hresInfo); + } + + return (m_pImageData ? TRUE : FALSE); } -int CWave::Play(int, int) const { +BOOL CWave::Play(BOOL bAsync, BOOL bLooped) const +{ + // Check validity + if (!IsValid()) + return FALSE; + + // Play the wave + return PlaySound((LPCSTR)m_pImageData, NULL, SND_MEMORY | + SND_NODEFAULT | (bAsync ? SND_ASYNC : SND_SYNC) | + (bLooped ? (SND_LOOP | SND_ASYNC) : 0)); } -int CWave::GetFormat(WAVEFORMATEX&) const { +BOOL CWave::GetFormat(WAVEFORMATEX& wfFormat) const +{ + // Check validity + if (!IsValid()) + return FALSE; + + // Setup and open the MMINFO structure + CMMMemoryIOInfo mmioInfo((HPSTR)m_pImageData, m_dwImageLen); + CMMIO mmio(mmioInfo); + + // Find the WAVE chunk + CMMTypeChunk mmckParent('W','A','V','E'); + mmio.Descend(mmckParent, MMIO_FINDRIFF); + + // Find and read the format subchunk + CMMIdChunk mmckSubchunk('f','m','t',' '); + mmio.Descend(mmckSubchunk, mmckParent, MMIO_FINDCHUNK); + mmio.Read((HPSTR)&wfFormat, sizeof(WAVEFORMATEX)); + mmio.Ascend(mmckSubchunk); + + return TRUE; } -unsigned long CWave::GetDataLen() const { +DWORD CWave::GetDataLen() const +{ + // Check validity + if (!IsValid()) + return (DWORD)0; + + // Setup and open the MMINFO structure + CMMMemoryIOInfo mmioInfo((HPSTR)m_pImageData, m_dwImageLen); + CMMIO mmio(mmioInfo); + + // Find the WAVE chunk + CMMTypeChunk mmckParent('W','A','V','E'); + mmio.Descend(mmckParent, MMIO_FINDRIFF); + + // Find and get the size of the data subchunk + CMMIdChunk mmckSubchunk('d','a','t','a'); + mmio.Descend(mmckSubchunk, mmckParent, MMIO_FINDCHUNK); + return mmckSubchunk.cksize; } -unsigned long CWave::GetData(unsigned char*&, unsigned long) const { +DWORD CWave::GetData(BYTE*& pWaveData, DWORD dwMaxLen) const +{ + // Check validity + if (!IsValid()) + return (DWORD)0; + + // Setup and open the MMINFO structure + CMMMemoryIOInfo mmioInfo((HPSTR)m_pImageData, m_dwImageLen); + CMMIO mmio(mmioInfo); + + // Find the WAVE chunk + CMMTypeChunk mmckParent('W','A','V','E'); + mmio.Descend(mmckParent, MMIO_FINDRIFF); + + // Find and get the size of the data subchunk + CMMIdChunk mmckSubchunk('d','a','t','a'); + mmio.Descend(mmckSubchunk, mmckParent, MMIO_FINDCHUNK); + DWORD dwLenToCopy = mmckSubchunk.cksize; + + // Allocate memory if the passed in pWaveData was NULL + if (pWaveData == NULL) + pWaveData = (BYTE*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE, + dwLenToCopy)); + else + // If we didn't allocate our own memory, honor dwMaxLen + if (dwMaxLen < dwLenToCopy) + dwLenToCopy = dwMaxLen; + if (pWaveData) + // Read waveform data into the buffer + mmio.Read((HPSTR)pWaveData, dwLenToCopy); + + return dwLenToCopy; } -int CWave::Free() { +//----------------------------------------------------------------- +// CWave Protected Methods +//----------------------------------------------------------------- +BOOL CWave::Free() +{ + // Free any previous wave data + if (m_pImageData) { + HGLOBAL hgmemWave = GlobalHandle(m_pImageData); + + if (hgmemWave) { + if (m_bResource) + // Free resource + FreeResource(hgmemWave); + else { + // Unlock and free memory + GlobalUnlock(hgmemWave); + GlobalFree(hgmemWave); + } + + m_pImageData = NULL; + m_dwImageLen = 0; + return TRUE; + } + } + return FALSE; } diff --git a/src/T2DLL/Wave.h b/src/T2DLL/Wave.h index 18ae45e..4febc3b 100644 --- a/src/T2DLL/Wave.h +++ b/src/T2DLL/Wave.h @@ -1,21 +1,48 @@ -#pragma once +//----------------------------------------------------------------- +// Wave Object +// C++ Header - Wave.h +//----------------------------------------------------------------- + +#ifndef __WAVE_H__ +#define __WAVE_H__ + +//----------------------------------------------------------------- +// Inclusions +//----------------------------------------------------------------- #include "common.h" +#include <MMSystem.h> -class CWave { +//----------------------------------------------------------------- +// CWave Class - Wave Object +//----------------------------------------------------------------- +class AFX_EXT_CLASS CWave : public CObject { + // Public Constructor(s)/Destructor public: - CWave(); - CWave(const CString&); - CWave(unsigned int, HINSTANCE); - virtual ~CWave(); - int Create(const CString&); - int Create(unsigned int, HINSTANCE); - int Play(int, int) const; - int GetFormat(WAVEFORMATEX&) const; - unsigned long GetDataLen() const; - unsigned long GetData(unsigned char*&, unsigned long) const; -protected: - int Free(); + CWave(); + CWave(const CString &str); + CWave(UINT uiResID, HMODULE hmod); + virtual ~CWave(); + // Public Methods public: - int IsValid() const {} + BOOL Create(const CString &str); + BOOL Create(UINT uiResID, HMODULE hmod); + BOOL IsValid() const { return (m_pImageData ? TRUE : + FALSE); }; + BOOL Play(BOOL bAsync = TRUE, BOOL bLooped = FALSE) const; + BOOL GetFormat(WAVEFORMATEX& wfFormat) const; + DWORD GetDataLen() const; + DWORD GetData(BYTE*& pWaveData, DWORD dwMaxToCopy) const; + + // Protected Methods +protected: + BOOL Free(); + + // Private Data +private: + BYTE* m_pImageData; + DWORD m_dwImageLen; + BOOL m_bResource; }; + +#endif diff --git a/src/T2FilePreview.cpp b/src/T2FilePreview.cpp new file mode 100644 index 0000000..9f6b616 --- /dev/null +++ b/src/T2FilePreview.cpp @@ -0,0 +1,2 @@ +#include "T2FilePreview.h" + diff --git a/src/T2FilePreview.h b/src/T2FilePreview.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2FilePreview.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2GraphWindow.cpp b/src/T2GraphWindow.cpp new file mode 100644 index 0000000..5e076b1 --- /dev/null +++ b/src/T2GraphWindow.cpp @@ -0,0 +1,2 @@ +#include "T2GraphWindow.h" + diff --git a/src/T2GraphWindow.h b/src/T2GraphWindow.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2GraphWindow.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2MWControl.cpp b/src/T2MWControl.cpp new file mode 100644 index 0000000..a6527f1 --- /dev/null +++ b/src/T2MWControl.cpp @@ -0,0 +1,69 @@ +#include "T2MWControl.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" + +#line 19 +IMPLEMENT_DYNCREATE(T2MWControl, CWnd) + +T2MWControl::T2MWControl() { + mDocument = NULL; + mWorldDef = NULL; + mData = 0; +} + +/*virtual*/ T2MWControl::~T2MWControl() { +} + +BEGIN_MESSAGE_MAP(T2MWControl, CWnd) + ON_WM_ERASEBKGND() + ON_WM_QUERYNEWPALETTE() + ON_WM_LBUTTONDOWN() + ON_WM_LBUTTONUP() + ON_WM_MOUSEMOVE() +END_MESSAGE_MAP() + +/*virtual*/ void T2MWControl::Setup(T2TowerDoc *inDoc) { + mDocument = inDoc; + mWorldDef = inDoc->mWorldDef; + + InvalidateRect(NULL); +} + +afx_msg BOOL T2MWControl::OnEraseBkgnd(CDC* pDC) { + if (mWorldDef) + mWorldDef->DrawCtrl(mDocument, this); + return true; +} + +afx_msg BOOL T2MWControl::OnQueryNewPalette() { + return CWnd::OnQueryNewPalette(); +} + +/*virtual*/ void T2MWControl::SetData(int data) { + mData = data; + InvalidateRect(NULL); +} + +/*virtual*/ int T2MWControl::GetData() const { + return mData; +} + +afx_msg void T2MWControl::OnLButtonDown(UINT nFlags, CPoint point) { + if (mWorldDef) + mWorldDef->ButtonDownOnCtrl(mDocument, this, point, GetParent()); +} + +afx_msg void T2MWControl::OnLButtonUp(UINT nFlags, CPoint point) { + if (mWorldDef) + mWorldDef->ButtonUpOnCtrl(mDocument, this, point, GetParent()); +} + +afx_msg void T2MWControl::OnMouseMove(UINT nFlags, CPoint point) { + if (mWorldDef) { + HCURSOR cursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); + if (cursor) + SetCursor(cursor); + + mWorldDef->MouseMoveOnCtrl(mDocument, this, point, GetParent()); + } +} diff --git a/src/T2MWControl.h b/src/T2MWControl.h new file mode 100644 index 0000000..005cde5 --- /dev/null +++ b/src/T2MWControl.h @@ -0,0 +1,26 @@ +#pragma once +#include "common.h" + +class T2MWControl : public CWnd { + DECLARE_DYNCREATE(T2MWControl) + DECLARE_MESSAGE_MAP() + +public: + T2MWControl(); + virtual ~T2MWControl(); + + virtual void Setup(T2TowerDoc *inDoc); + virtual void SetData(int data); // type? + virtual int GetData() const; // type? + +protected: + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg BOOL OnQueryNewPalette(); + afx_msg void OnLButtonDown(UINT nFlags, CPoint point); + afx_msg void OnLButtonUp(UINT nFlags, CPoint point); + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + + T2TowerDoc *mDocument; + T2WorldDef *mWorldDef; + int mData; +}; diff --git a/src/T2MainWindow.cpp b/src/T2MainWindow.cpp new file mode 100644 index 0000000..4f590ab --- /dev/null +++ b/src/T2MainWindow.cpp @@ -0,0 +1,601 @@ +#include "CT2App.h" +#include "GlobalFunc.h" +#include "T2MainWindow.h" +#include "T2MsgWindow.h" +#include "T2SoundPlayer.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" + +#line 22 +IMPLEMENT_DYNCREATE(T2MainWindow, CFrameWnd) + +BEGIN_MESSAGE_MAP(T2MainWindow, CFrameWnd) + ON_WM_CREATE() + ON_WM_DESTROY() + ON_WM_CLOSE() + ON_WM_SIZE() + ON_WM_VSCROLL() + ON_WM_HSCROLL() + ON_WM_ERASEBKGND() + ON_WM_ACTIVATE() + ON_WM_ACTIVATEAPP() + ON_COMMAND(0x8018, OnCmdDebugEvent) + ON_UPDATE_COMMAND_UI(0x8018, OnUpdateCmdDebugEvent) + ON_COMMAND(0x8023, OnCmdDebugMode) +END_MESSAGE_MAP() + +T2MainWindow::T2MainWindow() { + _EC = 0; + _F0 = 0; + mSoundPlayer = NULL; + mDirectSound = NULL; + mToolWindow = NULL; + mMsgWindow = NULL; + mCtrlPalette = NULL; + + ((CT2App *) AfxGetApp())->mMainWindow = this; +} + +/*virtual*/ T2MainWindow::~T2MainWindow() { + if (mSoundPlayer) { + delete mSoundPlayer; + Sounds = NULL; + } + + DeinitSound(); +} + +void T2MainWindow::InitSound() { + mDirectSound = NULL; + + if (DirectSoundCreate(NULL, &mDirectSound, NULL) != S_OK) { + DeinitSound(); + return; + } + +#ifdef _WIN32 + DSCAPS caps; + memset(&caps, 0, sizeof(DSCAPS)); + caps.dwSize = sizeof(DSCAPS); + + HRESULT result = mDirectSound->GetCaps(&caps); +#line 80 + _ASSERT(result == S_OK); + + if (mDirectSound->SetCooperativeLevel(GetSafeHwnd(), DSSCL_NORMAL) != S_OK) { + DeinitSound(); + return; + } + + DSBUFFERDESC bufferDesc; + memset(&bufferDesc, 0, sizeof(DSBUFFERDESC)); + bufferDesc.dwSize = sizeof(DSBUFFERDESC); + bufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; + + LPDIRECTSOUNDBUFFER buffer = NULL; + + if (mDirectSound->CreateSoundBuffer(&bufferDesc, &buffer, NULL) != S_OL) { + DeinitSound(); + } +#endif +} + +void T2MainWindow::DeinitSound() { + if (mDirectSound) { +#ifdef _WIN32 + mDirectSound->Release(); +#endif + mDirectSound = NULL; + } +} + +/*virtual*/ BOOL T2MainWindow::PreCreateWindow(CREATESTRUCT& cs) { + cs.style |= WS_TABSTOP | WS_GROUP | WS_VSCROLL; + return CFrameWnd::PreCreateWindow(cs); +} + +afx_msg int T2MainWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { +#line 123 + // mDbgStepRun = DEBUG_NEW DbgStepRun; + // mDbgIPS = DEBUG_NEW DbgIPS; + + if (CFrameWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + InitSound(); +#line 130 + mSoundPlayer = DEBUG_NEW T2SoundPlayer(this, mDirectSound); + + SetWindowRgn(CreateRectRgn(100, 100, 100, 100), true); + return 0; +} + +afx_msg void T2MainWindow::OnDestroy() { + gT2App->mMainWindow = NULL; + // ffCalledFromDestroy(); + + CFrameWnd::OnDestroy(); + + // mDbgStepRun->DestroyWindow(); + // delete mDbgStepRun; + // mDbgIPS->DestroyWindow(); + // delete mDbgIPS; +} + +void T2MainWindow::Setup() { + RECT windowRect; + GetWindowRect(&windowRect); + SetWindowRgn(CreateRectRgn(0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top), true); + + mWndClassA = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); + + RECT rect; + SetRect(&rect, 100, 100, 300, 300); + mToolWindow = ((CT2App *) AfxGetApp())->mToolWindow; + mToolWindow->Create(mWndClassA, "Tools", WS_SYSMENU | WS_CAPTION | WS_CLIPCHILDREN | WS_VISIBLE | WS_POPUP, rect, this, NULL, WS_EX_TOOLWINDOW); + + mWndClassB = AfxRegisterWndClass(0, NULL, (HBRUSH) GetStockObject(WHITE_BRUSH)); + + SetRect(&rect, 0, 0, 520, 50); + // ... + // more stuff here. +} + +void T2MainWindow::Teardown() { + delete mToolWindow; + delete mMsgWindow; + delete mCtrlPalette; + + mToolWindow = NULL; + mMsgWindow = NULL; + mCtrlPalette = NULL; +} + +/*virtual*/ void T2MainWindow::AssertValid() const { + CFrameWnd::AssertValid(); +} + +/*virtual*/ void T2MainWindow::Dump(CDumpContext& dc) const { + CFrameWnd::Dump(dc); +} + +afx_msg void T2MainWindow::OnSize(UINT nType, int cx, int cy) { + T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + if (!_EC) { + CFrameWnd::OnSize(nType, cx, cy); + } else if (theView) { + CRect rect; + GetClientRect(rect); + rect.top += 16; + rect.left += 16; + theView->SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER); + } + + x4144FA(); + + if (theView) + theView->tmv_vf144(); +} + +void T2MainWindow::x414445() { + T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + x4144FA(); + + CRect rect; + GetWindowRect(rect); + int width = rect.Width(); + int height = rect.Height(); + + if (width && height && theTowerDoc && theView && theTowerDoc->mWorldDef) { + theView->tmv_vf138(theTowerDoc->mWorldDef->mInitPos, 0x102); + _F0 = 1; + theView->ShowWindow(SW_SHOW); + } +} + +void T2MainWindow::x4144FA() { + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); + + if (theTowerDoc && theView && theTowerDoc->mWorldDef) { + RECT clientRect; + GetClientRect(&clientRect); + + RECT unitRect; + SetRect(&unitRect, 0, 0, theTowerDoc->mWorldDef->GetWidth(), theTowerDoc->mWorldDef->GetHeight()); + UT2Coordinate::UnitToQD(unitRect, theTowerDoc->mZoomLevel, true); + + SCROLLINFO info; + info.cbSize = sizeof(SCROLLINFO); + info.fMask = SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL; + info.nMin = 0; + + info.nMax = unitRect.bottom; + info.nPage = clientRect.bottom; + SetScrollInfo(SB_VERT, &info); + + info.nMax = unitRect.right; + info.nPage = clientRect.right; + SetScrollInfo(SB_HORZ, &info); + + InvalidateRect(NULL); + } +} + +afx_msg void T2MainWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + if (theTowerDoc) { + RECT clientRect; + GetClientRect(&clientRect); + + int scrollLimit = GetScrollLimit(SB_VERT); + int origScrollPos = GetScrollPos(SB_VERT); + int scrollPos = origScrollPos; + + switch (nSBCode) { + case SB_BOTTOM: + scrollPos = scrollLimit; + break; + case SB_LINEDOWN: + scrollPos += UT2Coordinate::UnitVSize(theTowerDoc->mZoomLevel); + break; + case SB_LINEUP: + scrollPos -= UT2Coordinate::UnitVSize(theTowerDoc->mZoomLevel); + break; + case SB_PAGEDOWN: + scrollPos += clientRect.bottom / 2; + break; + case SB_PAGEUP: + scrollPos -= clientRect.bottom / 2; + break; + case SB_THUMBTRACK: + scrollPos = nPos; + break; + case SB_TOP: + scrollPos = 0; + break; + } + + if (scrollPos < 0) + scrollPos = 0; + else if (scrollPos > scrollLimit) + scrollPos = scrollLimit; + + SetScrollPos(SB_VERT, scrollPos); + + CRect myClientRect; + GetClientRect(myClientRect); + myClientRect.left = 1; + + CView *activeView = GetActiveView(); + + CRect activeClientRect; + activeView->GetClientRect(activeClientRect); + activeView->MapWindowPoints(this, activeClientRect); + + myClientRect.top = activeClientRect.top; + + ScrollWindow(0, scrollPos - origScrollPos, myClientRect, myClientRect); + UpdateWindow(); + + T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); + if (theView) { + theView->tmv_vf130(scrollPos); + theView->tmv_vf120(); + } + } +} + +afx_msg void T2MainWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + if (theTowerDoc) { + RECT clientRect; + GetClientRect(&clientRect); + + int scrollLimit = GetScrollLimit(SB_HORZ); + int origScrollPos = GetScrollPos(SB_HORZ); + int scrollPos = origScrollPos; + + switch (nSBCode) { + case SB_RIGHT: + scrollPos = scrollLimit; + break; + case SB_LINERIGHT: + scrollPos += UT2Coordinate::UnitHSize(theTowerDoc->mZoomLevel); + break; + case SB_LINELEFT: + scrollPos -= UT2Coordinate::UnitHSize(theTowerDoc->mZoomLevel); + break; + case SB_PAGERIGHT: + scrollPos += clientRect.right / 2; + break; + case SB_PAGELEFT: + scrollPos -= clientRect.right / 2; + break; + case SB_THUMBTRACK: + scrollPos = nPos; + break; + case SB_LEFT: + scrollPos = 0; + break; + } + + if (scrollPos < 0) + scrollPos = 0; + else if (scrollPos > scrollLimit) + scrollPos = scrollLimit; + + SetScrollPos(SB_HORZ, scrollPos); + + CRect myClientRect; + GetClientRect(myClientRect); + myClientRect.top = 1; + + CView *activeView = GetActiveView(); + + CRect activeClientRect; + activeView->GetClientRect(activeClientRect); + activeView->MapWindowPoints(this, activeClientRect); + + myClientRect.top = activeClientRect.top; + + ScrollWindow(scrollPos - origScrollPos, 0, myClientRect, myClientRect); + UpdateWindow(); + + T2TowerMainView *theView = (T2TowerMainView *) GetActiveView(); + if (theView) { + theView->tmv_vf134(scrollPos); + theView->tmv_vf120(); + } + } +} + +afx_msg BOOL T2MainWindow::OnEraseBkgnd(CDC* pDC) { + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + if (!theTowerDoc || !theTowerDoc->mWorldDef || !theTowerDoc->Get22C()) { + CRect clientRect; + GetClientRect(clientRect); + + CBrush brush(GetSysColor(COLOR_BTNFACE)); + pDC->FillRect(clientRect, &brush); + + return true; + } + + int save = pDC->SaveDC(); + + CRect clientRect; + GetClientRect(clientRect); + + CBrush brush(GetSysColor(COLOR_BTNFACE)); + pDC->FillRect(clientRect, &brush); + + CPen shadowPen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); + CPen highlightPen(PS_SOLID, 0, GetSysColor(COLOR_BTNHIGHLIGHT)); + + CFont bigFont; + bigFont.CreateFont(-14, 0, 900, 900, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + CFont smallFont; + smallFont.CreateFont(-14, 0, 0, 0, FW_BOLD, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + pDC->SelectObject(shadowPen); + pDC->MoveTo(clientRect.right, 0); + pDC->LineTo(0, 0); + pDC->LineTo(0, clientRect.bottom); + + pDC->SetBkMode(TRANSPARENT); + + CView *theView = GetActiveView(); + + if (_F0 && theTowerDoc && theView) { + CRect viewRect; + theView->GetClientRect(viewRect); + theView->MapWindowPoints(this, viewRect); + + T2TowerMainView *theTowerMainView = (T2TowerMainView *) theView; + viewRect.left += theTowerMainView->m84; + viewRect.right += theTowerMainView->m84; + viewRect.top += theTowerMainView->m88; + viewRect.bottom += theTowerMainView->m88; + + pDC->SelectObject(shadowPen); + pDC->MoveTo(viewRect.left - 1, 0); + pDC->LineTo(viewRect.left - 1, viewRect.top - 1); + pDC->LineTo(-1, viewRect.top - 1); + + pDC->ExcludeClipRect(0, 0, viewRect.left, viewRect.top); + + SCROLLINFO scrollInfoH; + SCROLLINFO scrollInfoV; + GetScrollInfo(SB_HORZ, &scrollInfoH); + GetScrollInfo(SB_VERT, &scrollInfoV); + + pDC->SetWindowOrg(scrollInfoH.nPos, 0); + + CRect anotherRect; + int hRange = scrollInfoH.nMax - scrollInfoH.nMin; + + pDC->SelectObject(smallFont); + + int i; + int x; + int y; + char str[4]; + POINT textPos; + + for (i = 0; i < 10; i++) { + x = viewRect.left + (hRange * i) / 10; + anotherRect.SetRect(x, 1, viewRect.left + (hRange * (i + 1)) / 10, 16); + + pDC->SelectObject(shadowPen); + pDC->MoveTo(x - 1, 1); + pDC->LineTo(x - 1, 16); + + pDC->SelectObject(highlightPen); + pDC->MoveTo(x, 1); + pDC->LineTo(x, 16); + + str[0] = "\x82\x60"[0]; + str[1] = "\x82\x60"[1] + i; + str[2] = 0; + + textPos.y = 2; + textPos.x = ((anotherRect.left + anotherRect.right) / 2) - (pDC->GetTextExtent(str, 2).cx / 2); + + pDC->SetTextColor(GetSysColor(COLOR_BTNHIGHLIGHT)); + pDC->TextOut(textPos.x + 1, textPos.y + 1, str, 2); + + pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW)); + pDC->TextOut(textPos.x - 1, textPos.y - 1, str, 2); + + pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); + pDC->TextOut(textPos.x, textPos.y, str, 2); + } + + x = viewRect.left + hRange; + anotherRect.SetRect(x, 1, viewRect.left + (hRange * 11) / 10, 16); + + pDC->SelectObject(shadowPen); + pDC->MoveTo(x - 1, 1); + pDC->LineTo(x - 1, 16); + + pDC->SelectObject(highlightPen); + pDC->MoveTo(x, 1); + pDC->LineTo(x, 16); + + pDC->SetWindowOrg(0, scrollInfoV.nPos); + int vRange = scrollInfoV.nMax - scrollInfoV.nMin; + int height = theTowerDoc->mWorldDef->GetHeight(); + + pDC->SelectObject(bigFont); + + for (i = 0; i <= height; i++) { + y = viewRect.top + (vRange * i) / height; + anotherRect.SetRect(0, y, 14, viewRect.top + (vRange * (i + 1)) / height); + + pDC->SelectObject(shadowPen); + pDC->MoveTo(1, y - 1); + pDC->LineTo(16, y - 1); + + pDC->SelectObject(highlightPen); + pDC->MoveTo(1, y); + pDC->LineTo(16, y); + } + + BOOL showAllNumbers = (theTowerDoc->towerDoc_vf108() == 0); + + for (i = 0; i <= height; i++) { + y = viewRect.top + (vRange * i) / height; + anotherRect.SetRect(0, y, 14, viewRect.top + (vRange * (i + 1)) / height); + + int number = theTowerDoc->mWorldDef->mGroundLine - i; + BOOL show = showAllNumbers; + + if (number > 1 && (number % 5 == 0)) + show = true; + if (number == 1) + show = true; + if (number < 1 && ((number - 1) % 5 == 0)) + show = true; + + if (show) { + if (number >= 1) + wsprintf(str, "%d", number); + else + wsprintf(str, "B%d", 1 - number); + + int textLen = strlen(str); + + textPos.x = 2; + textPos.y = ((anotherRect.top + anotherRect.bottom) / 2) - (pDC->GetTextExtent(str, 2).cx / 2); + + pDC->SetTextColor(GetSysColor(COLOR_BTNHIGHLIGHT)); + pDC->TextOut(textPos.x + 1, textPos.y + 1, str, 2); + + pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW)); + pDC->TextOut(textPos.x - 1, textPos.y - 1, str, 2); + + pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); + pDC->TextOut(textPos.x, textPos.y, str, 2); + } + } + } + + pDC->RestoreDC(save); + return false; +} + +afx_msg void T2MainWindow::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) { + CFrameWnd::OnActivate(nState, pWndOther, bMinimized); +} + +afx_msg void T2MainWindow::OnActivateApp(BOOL bActive, HTASK hTask) { + CWnd::OnActivateApp(bActive, hTask); + + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + if (theTowerDoc && theTowerDoc->mWorldDef) { + CDC *pDC = GetDC(); + pDC->SaveDC(); + pDC->SelectPalette(theTowerDoc->mWorldDef->GetPalette(), false); + pDC->RealizePalette(); + pDC->RestoreDC(-1); + ReleaseDC(pDC); + + InvalidateRect(NULL); + + T2TowerMainView *theTowerMainView = theTowerDoc->GetTowerMainView(); + if (theTowerMainView) + theTowerMainView->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); + + DWORD processID; + GetWindowThreadProcessId(this, &processID); + + CWnd *window = GetDesktopWindow()->GetWindow(GW_CHILD); + while (window) { + DWORD checkProcessID; + GetWindowThreadProcessId(window, &checkProcessID); + + if (processID == checkProcessID) + window->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_ERASENOW); + + window = window->GetWindow(GW_HWNDNEXT); + } + } +} + +afx_msg void T2MainWindow::OnCmdDebugEvent() { + // TODO: DbgEventList +} + +afx_msg void T2MainWindow::OnUpdateCmdDebugEvent(CCmdUI *pCmdUI) { + pCmdUI->Enable(); +} + +afx_msg void T2MainWindow::OnClose() { + T2TowerDoc *theTowerDoc = (T2TowerDoc *) GetActiveDocument(); + + if (theTowerDoc->towerDoc_vf1A4()) + return; + + CFrameWnd::OnClose(); +} + +afx_msg void T2MainWindow::OnCmdDebugMode() { + HMENU oldMenu = GetMenu(this); + HMENU newMenu = LoadMenu(AfxGetInstanceHandle(), 130); + m_hMenuDefault = newMenu; + SetMenu(this, newMenu); + DestroyMenu(oldMenu); +} diff --git a/src/T2MainWindow.h b/src/T2MainWindow.h new file mode 100644 index 0000000..b84d81f --- /dev/null +++ b/src/T2MainWindow.h @@ -0,0 +1,48 @@ +#pragma once +#include "common.h" + +class T2MainWindow : public CFrameWnd { + DECLARE_DYNCREATE(T2MainWindow) + DECLARE_MESSAGE_MAP() + +public: + T2MainWindow(); + virtual ~T2MainWindow(); + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + virtual void AssertValid() const; + virtual void Dump(CDumpContext& dc) const; + void Setup(); + void Teardown(); + void x414445(); + void x4144FA(); + + LPDIRECTSOUND mDirectSound; + T2SoundPlayer *mSoundPlayer; + T2MsgWindow *mMsgWindow; + T2CtrlPalette *mCtrlPalette; + CString mWndClassB; + T2ToolWindow *mToolWindow; + CString mWndClassA; + int _DC; + CString mWndClassC; + DbgStepRun *mDbgStepRun; + DbgIPS *mDbgIPS; + int _EC; + int _F0; + +protected: + void InitSound(); + void DeinitSound(); + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg void OnDestroy(); + afx_msg void OnSize(UINT nType, int cx, int cy); + afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); + afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized); + afx_msg void OnActivateApp(BOOL bActive, HTASK hTask); + afx_msg void OnCmdDebugEvent(); + afx_msg void OnUpdateCmdDebugEvent(CCmdUI *pCmdUI); + afx_msg void OnClose(); + afx_msg void OnCmdDebugMode(); +}; diff --git a/src/T2MsgWindow.cpp b/src/T2MsgWindow.cpp new file mode 100644 index 0000000..1394f19 --- /dev/null +++ b/src/T2MsgWindow.cpp @@ -0,0 +1,2 @@ +#include "T2MsgWindow.h" + diff --git a/src/T2MsgWindow.h b/src/T2MsgWindow.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2MsgWindow.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2NewDlg.cpp b/src/T2NewDlg.cpp new file mode 100644 index 0000000..3f8284d --- /dev/null +++ b/src/T2NewDlg.cpp @@ -0,0 +1,2 @@ +#include "T2NewDlg.h" + diff --git a/src/T2NewDlg.h b/src/T2NewDlg.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2NewDlg.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2NewDlgTmp.cpp b/src/T2NewDlgTmp.cpp new file mode 100644 index 0000000..1c8b940 --- /dev/null +++ b/src/T2NewDlgTmp.cpp @@ -0,0 +1,2 @@ +#include "T2NewDlgTmp.h" + diff --git a/src/T2NewDlgTmp.h b/src/T2NewDlgTmp.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2NewDlgTmp.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2OpenFileDialog.cpp b/src/T2OpenFileDialog.cpp new file mode 100644 index 0000000..4fef5f2 --- /dev/null +++ b/src/T2OpenFileDialog.cpp @@ -0,0 +1,2 @@ +#include "T2OpenFileDialog.h" + diff --git a/src/T2OpenFileDialog.h b/src/T2OpenFileDialog.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2OpenFileDialog.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2OpenSelectDlg.cpp b/src/T2OpenSelectDlg.cpp new file mode 100644 index 0000000..1a86321 --- /dev/null +++ b/src/T2OpenSelectDlg.cpp @@ -0,0 +1,2 @@ +#include "T2OpenSelectDlg.h" + diff --git a/src/T2OpenSelectDlg.h b/src/T2OpenSelectDlg.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2OpenSelectDlg.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2OpenningWindow.cpp b/src/T2OpenningWindow.cpp new file mode 100644 index 0000000..d16135f --- /dev/null +++ b/src/T2OpenningWindow.cpp @@ -0,0 +1,2 @@ +#include "T2OpenningWindow.h" + diff --git a/src/T2OpenningWindow.h b/src/T2OpenningWindow.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2OpenningWindow.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2PoolView.cpp b/src/T2PoolView.cpp new file mode 100644 index 0000000..13cfae6 --- /dev/null +++ b/src/T2PoolView.cpp @@ -0,0 +1,2 @@ +#include "T2PoolView.h" + diff --git a/src/T2PoolView.h b/src/T2PoolView.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2PoolView.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2SysInfoDlg.cpp b/src/T2SysInfoDlg.cpp new file mode 100644 index 0000000..b77a596 --- /dev/null +++ b/src/T2SysInfoDlg.cpp @@ -0,0 +1,2 @@ +#include "T2SysInfoDlg.h" + diff --git a/src/T2SysInfoDlg.h b/src/T2SysInfoDlg.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2SysInfoDlg.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/T2TowerDoc.h b/src/T2TowerDoc.h index db42bc4..2af4ff0 100644 --- a/src/T2TowerDoc.h +++ b/src/T2TowerDoc.h @@ -1,9 +1,16 @@ #pragma once #include "common.h" +#include "T2MsgWindowCallback.h" +#include "T2Sprite.h" +#include "T2ToolCallback.h" -// TODO: this lad also inherits T2MsgWindowCallback, T2ToolCallback +enum { + kTowerDocWindowType0 = 0, + kTowerDocWindowType1, + kTowerDocWindowType2 +}; -class T2TowerDoc : public CDocument { +class T2TowerDoc : public CDocument, public T2MsgWindowCallback, public T2ToolCallback { public: virtual int IsDustOn() const; virtual void LoadsWorldPlugin(); @@ -30,8 +37,8 @@ public: // 100 virtual void towerDoc_vf100(); virtual void towerDoc_vf104(); - virtual void towerDoc_vf108(); - virtual void towerDoc_vf10C(); + virtual int towerDoc_vf108() const; // get zoom level + virtual T2BitImage *towerDoc_vf10C() const; // 110 virtual T2TowerMainView *GetTowerMainView(); virtual void towerDoc_vf114(); @@ -39,59 +46,59 @@ public: virtual void towerDoc_vf11C(int startIndex, int count, PALETTEENTRY *entries); // updates palette // 120 virtual T2DateTime *towerDoc_vf120() const; - virtual void towerDoc_vf124(); - virtual void towerDoc_vf128(); - virtual void towerDoc_vf12C(); + virtual T2RouteNavigator *towerDoc_vf124(); + virtual T2TemplatePluginList *towerDoc_vf128(); + virtual T2FloorInfo *towerDoc_vf12C() const; // 130 - virtual void towerDoc_vf130(); + virtual T2Pool *towerDoc_vf130(); virtual T2SoundPlayer *towerDoc_vf134(); - virtual void towerDoc_vf138(); - virtual void towerDoc_vf13C(); + virtual int towerDoc_vf138() const; // game level? + virtual T2TowerMessage *towerDoc_vf13C(); // 140 - virtual void towerDoc_vf140(); - virtual void towerDoc_vf144(); - virtual void towerDoc_vf148(); - virtual void towerDoc_vf14C(); + virtual int towerDoc_vf140(); // get view mode? + virtual void towerDoc_vf144(int); + virtual int towerDoc_vf148() const; // get walk rate? + virtual void towerDoc_vf14C(int walkRate); // 150 - virtual void towerDoc_vf150(); - virtual void towerDoc_vf154(); + virtual T2TrafficInfo *towerDoc_vf150() const; + virtual BOOL towerDoc_vf154(); // IsToiletFlagOn? virtual void towerDoc_vf158(); - virtual int towerDoc_vf15C(const RECT &rect); + virtual int towerDoc_vf15C(const RECT &rect); // returns bool maybe? // 160 - virtual void towerDoc_vf160(); - virtual void towerDoc_vf164(); + virtual T2PaletteAnime *towerDoc_vf160() const; + virtual void towerDoc_vf164(const char *inText); // sets infobar message virtual void towerDoc_vf168(); - virtual void towerDoc_vf16C(); + virtual BOOL towerDoc_vf16C() const; // GetElevTransparent // 170 virtual T2WorldDef *towerDoc_vf170(); - virtual void towerDoc_vf174(); - virtual void towerDoc_vf178(); - virtual void towerDoc_vf17C(); + virtual T2RegistedTenantDB *towerDoc_vf174(); + virtual T2TemplatePluginList *towerDoc_vf178(); // get tenant templates + virtual T2TemplatePluginList *towerDoc_vf17C(); // get mover templates // 180 - virtual void towerDoc_vf180(); + virtual T2TemplatePluginList *towerDoc_vf180(); // get outobj templates virtual void towerDoc_vf184(); virtual void towerDoc_vf188(); - virtual void towerDoc_vf18C(); + virtual T2Tenant *towerDoc_vf18C(); // 190 virtual void towerDoc_vf190(); virtual void towerDoc_vf194(); - virtual void towerDoc_vf198(); + virtual void towerDoc_vf198(int); virtual void towerDoc_vf19C(); // 1A0 virtual void towerDoc_vf1A0(int); - virtual void towerDoc_vf1A4(); + virtual BOOL towerDoc_vf1A4() const; // called from T2MainWindow::OnClose virtual void towerDoc_vf1A8(); virtual void towerDoc_vf1AC(); // 1B0 virtual void towerDoc_vf1B0(); virtual void towerDoc_vf1B4(); - virtual void towerDoc_vf1B8(); + virtual void towerDoc_vf1B8(T2People *); virtual void towerDoc_vf1BC(); // 1C0 virtual void towerDoc_vf1C0(); - virtual void towerDoc_vf1C4(); + virtual void towerDoc_vf1C4(T2People *, BOOL); virtual void towerDoc_vf1C8(); - virtual void towerDoc_vf1CC(); + virtual void towerDoc_vf1CC(T2Tenant *, BOOL); // 1D0 virtual void towerDoc_vf1D0(); virtual void towerDoc_vf1D4(); @@ -125,7 +132,7 @@ public: // 230 virtual void towerDoc_vf230(); virtual void towerDoc_vf234(); - virtual void towerDoc_vf238(); + virtual void towerDoc_vf238(T2Name *); // find tenant from search dialog virtual void towerDoc_vf23C(); // 240 virtual void towerDoc_vf240(); @@ -140,13 +147,13 @@ public: // 260 virtual void towerDoc_vf260(); virtual void towerDoc_vf264(); - virtual void towerDoc_vf268(); - virtual void towerDoc_vf26C(); + virtual void towerDoc_vf268(T2Tenant *inTenant); // TenantRemoved + virtual int towerDoc_vf26C() const; // GetCurrentFunds? // 270 - virtual void towerDoc_vf270(); + virtual void towerDoc_vf270(int, short); // DoPay virtual void towerDoc_vf274(); virtual void DoPayTool(int cost, short unk, T2ToolDef *toolDef); - virtual void towerDoc_vf27C(); + virtual int towerDoc_vf27C(int inV); // GetNextTenantNumber // 280 virtual void towerDoc_vf280(); virtual void towerDoc_vf284(); @@ -158,18 +165,128 @@ public: virtual void towerDoc_vf298(); virtual void towerDoc_vf29C(); // 2A0 - virtual void towerDoc_vf2A0(); - virtual void towerDoc_vf2A4(); - virtual void towerDoc_vf2A8(); + virtual T2ToolWindow *towerDoc_vf2A0(); + virtual int towerDoc_vf2A4() const; // get speed + virtual void towerDoc_vf2A8(int); // SetDrawSpeed virtual void towerDoc_vf2AC(); // 2B0 - virtual void towerDoc_vf2B0(); + virtual void towerDoc_vf2B0(BOOL); // SetVolatile maybe? virtual void towerDoc_vf2B4(); virtual void towerDoc_vf2B8(); virtual void towerDoc_vf2BC(); // 2C0 virtual void towerDoc_vf2C0(); + // this might be SetVolatile actually + void SetFireBurning(BOOL flag) { m208 = flag; } + + int Get22C() { return _22C; } + + T2PluginLoader *mT2PluginLoader; + T2WorldPlugin *mWorldPlugin; + T2PluginSpecifier *mWorldPluginSpecifier; + T2PluginSpecifier *mToPluginSpecifier; + DWORD mWorldPluginID; + DWORD mToPluginID; + T2WorldDef *mWorldDef; + int _78; + int _7C; int mZoomLevel; - T2WorldDef *mWorldDef; + int _84; + BOOL mPause; + int mGameLevel; + int _90; + int _94; + int _98; + int m9C; + DWORD mA0; // VIPs that have been satisfied + int mViewMode; + int _A8; + int _AC; + int _B0; + int _B4; + int _B8; + int mBC; + DWORD mC0; + T2DateTime *mNow; + T2TowerMessage *mTowerMessage; + CString mCC; + T2FloorInfo *mFloorInfo; + BkgndInfo *mBkgndInfo; + T2TrafficInfo *mTrafficInfo; + T2Sprite mSprite; + T2SoundPlayer *mSoundPlayer; + CFilePluginList *mTenantPluginsListOther; + CFilePluginList *mMoverPluginsListOther; + CFilePluginList *mOoPluginsListOther; + T2MoviePluginList *mMoviePluginList; + CFilePluginList *mHePluginsListOther; + CFilePluginList *mAdPluginsListOther; + T2TemplatePluginList *mTenantTemplates; + T2TemplatePluginList *mMoverTemplates; + T2TemplatePluginList *mMatterTemplates; + T2TemplatePluginList *mPeopleTemplates; + T2TemplatePluginList *mSilhouetteTemplates; + T2TemplatePluginList *mOuterObjTemplates; + T2TemplatePluginDB *mTemplatePluginDB; + T2OptionPluginList *mOptionPluginList; + T2OuterObjList *mOuterObjList; + T2Settlement *mSettlement; + T2NameList *mNameDB; + T2PeopleArrayList *mPeopleArrayList; + T2Pool *mPool; + T2RegistedTenantDB *mRegistedTenantDB; + int _15C; + T2RouteNavigator *mRouteNavigator; + T2Equip *mSearchRangeFrom; + int mCraneCount; + POINT *mCranePosArray; + int _170; + int _174; + T2PaletteAnime *mPaletteAnime; + int _17C; + int m180; + int m184; + int _188; + int _18C; + BOOL mErrorFlag; + BOOL mNewDocFlag; + BOOL mIsStuffLoadedFlag; + T2TowerMainView *mTowerMainView; + T2TenantDef *m1A0; + int _1A4; + int _1A8; + int _1AC; + int _1B0; + int _1B4; + CObjectQueue *mObjectQueue; + int _1BC; + int _1C0; + T2Equip *m1C4; + int _1C8; + int m1CC; + BOOL mElevTransparent; + int isDustOn; + int mToiletDenomi; + unsigned int mColdDenomi; + int mWalkRate; + int _1E4; + int _1E8; + int _1EC; + int m1F0; + int _1F4; + int _1F8; + int _1FC; + int _200; + int m204; + int m208; + int m20C; + int m210; + int m214; + int m218; + unsigned int m21C; + unsigned int m220; // speed? + int _224; + int m228; + int _22C; }; diff --git a/src/T2TowerMainView.h b/src/T2TowerMainView.h index fc0547d..d611989 100644 --- a/src/T2TowerMainView.h +++ b/src/T2TowerMainView.h @@ -8,21 +8,56 @@ public: virtual void tmv_vf114(); virtual void tmv_vf118(); virtual void tmv_vf11C(); - virtual void tmv_vf120(); + virtual void tmv_vf120(); // DrawSimulation? virtual void tmv_vf124(BOOL); // some invalidator - virtual void tmv_vf128(); + virtual void tmv_vf128(const RECT &, BOOL flag = false); // updates various rects virtual void tmv_vf12C(); - virtual void tmv_vf130(); - virtual void tmv_vf134(); - virtual void tmv_vf138(); + virtual void tmv_vf130(int); // set scroll Y? + virtual void tmv_vf134(int); // set scroll X: + virtual void tmv_vf138(const POINT &, WPARAM); virtual void tmv_vf13C(); - virtual void tmv_vf140(); + virtual void tmv_vf140(RECT &); // gets visible rect in unit coords? virtual void tmv_vf144(); virtual void tmv_vf148(); virtual void tmv_vf14C(); virtual void tmv_vf150(); virtual void tmv_vf154(); virtual void tmv_vf158(); - virtual void tmv_vf15C(); + virtual void tmv_vf15C(const RECT *); // CenterOnView? virtual void tmv_vf160(); + + T2TowerDoc *mDocument; + RECT m50; + T2BitImage *m60; + POINT m64; + RECT m6C; + POINT m7C; + int m84; + int m88; + RECT m8C; + RECT m9C; + RECT mAC; + RECT mBC; + CPoint mCC; + int _D4; + int mD8; + int mDC; + int _E0; + int _E4; + int _E8; + int _EC; + BOOL mDebugMode; + BOOL mF4; + int _F8; + int mFC; + int mSomeSpriteIndex; + CString mSomeSpriteName; + int _108; + int _10C; + int _110; + int _114; + T2Equip *mDbgEquip; + int _11C; + int _120; + CPoint m124; }; diff --git a/src/T2WorldSelectDlg.cpp b/src/T2WorldSelectDlg.cpp new file mode 100644 index 0000000..411e041 --- /dev/null +++ b/src/T2WorldSelectDlg.cpp @@ -0,0 +1,2 @@ +#include "T2WorldSelectDlg.h" + diff --git a/src/T2WorldSelectDlg.h b/src/T2WorldSelectDlg.h new file mode 100644 index 0000000..fcaf1ff --- /dev/null +++ b/src/T2WorldSelectDlg.h @@ -0,0 +1,3 @@ +#pragma once +#include "common.h" + diff --git a/src/common.h b/src/common.h index b0b92ef..138c326 100644 --- a/src/common.h +++ b/src/common.h @@ -6,104 +6,192 @@ #include <MBSTRING.H> #include <CRTDBG.H> #include <MMSYSTEM.H> -#include <DSOUND.H> +#include <OBJBASE.H> +#include <dsound.h> +#include <dinput.h> #include <math.h> +class CEditWFocus; class CFilePlugin; class CFilePluginList; +class CLink; +class CObjectQueue; +class CPluginInfo; class CProgramPlugin; class CResFile; class CResourcePlugin; class CT2App; class CTokenizer; class CWave; +class DbgIPS; +class DbgStepRun; class LArray; class LArrayIterator; class LAttachable; class LAttachment; class LBroadcaster; class LListener; +class MoverSearchDlg; +class PeopleSearchDlg; +class SoundDlg; +class SpeedDlg; class T2AdvertisePlugin; class T2Archive; class T2BitImage; class T2BlackOut; class T2ColdTableDef; class T2CrossEquipArray; +class T2CtrlPalette; class T2DateTime; class T2DayLightFilter; +class T2DayParamDef; +class T2Dialog; class T2DlgItem; +class T2DlgItemAllPurpose; class T2DlgItemAnimation; class T2DlgItemHScr; class T2DlgItemVScr; class T2DrawableObject; +class T2ElevatorModule; class T2Equip; class T2EquipDef; class T2EquipPlugin; +class T2EquipPtrList; +class T2EventDialog; class T2EventItem; +class T2Fire; +class T2FireAttach; class T2FireBurning; class T2FloorInfo; +class T2FloorNumberTable; +class T2FloorPtrList; class T2GlobalData; +class T2GuestroomItem; +class T2GuestroomTable; +class T2HallEventItem; +class T2HallEventPlugin; class T2HaveOutViewObject; +class T2Helicopter; class T2ImageObj; class T2InfoDialog; +class T2MainWindow; class T2Maru_Reggae; class T2Matter; +class T2MatterArray; +class T2MatterArrayList; class T2MatterDef; +class T2Message; class T2MetroRailway; class T2Mover; +class T2MoverArray; class T2MoverArrayList; class T2MoverDef; class T2MoverModule; +class T2MoverModuleList; +class T2MoverModuleTable; +class T2MoverPlugin; +class T2MoverRoutingTable; +class T2MovieParamArray; +class T2MoviePlugin; +class T2MoviePluginList; +class T2MsgWindow; class T2MWControl; +class T2Name; +class T2NameList; class T2Object; +class T2ObjectArray; +class T2ObjectArrayList; +class T2OptionPlugin; +class T2OptionPluginList; +class T2OutDeco; +class T2OutDecoration; +class T2OuterObjList; class T2OutObj; +class T2OutObjArray; class T2OutObjArrayList; class T2OuterObjDef; class T2OutsideInfo; class T2PaletteAnime; class T2PaletteAnimeDef; class T2People; -class T2PeopleDef; +class T2PeopleArray; class T2PeopleArrayList; +class T2PeopleAnimeDef; +class T2PeopleAnimeDefElem; +class T2PeopleDef; +class T2PeoplePtrList; +class T2PeopleTimeZoneList; class T2PeopleType; +class T2PeopleTypeArray; +class T2PlaceParamDef; +class T2PluginLoader; class T2PluginSpecifier; class T2Pool; class T2PoolDef; +class T2PoolDefDemandElem; +class T2PoolGradeDef; class T2PoolTimeZoneDef; +class T2RegistedTenantDB; class T2Request; +class T2RequestArray; class T2RequestArrayList; +class T2RequestIDArray; class T2ReturnStack; class T2RouteCEArray; +class T2RouteNavigator; +class T2RoutingTable; +class T2RoutingTableElem; +class T2SantaClaus; class T2SeasonParamDef; +class T2Settlement; class T2SilhouetteDef; class T2SoundObjItem; +class T2SoundObjItemList; class T2SoundPlayer; class T2Sprite; class T2SpriteObj; +class T2StopInfoArray; +class T2SubPlugin; class T2TemplatePlugin; class T2TemplatePluginDB; class T2TemplatePluginList; class T2Tenant; +class T2TenantArray; class T2TenantArrayList; class T2TenantDef; class T2TenantMemberDef; +class T2TenantMemberTableDef; +class T2TenantPlugin; +class T2ToolCallback; class T2ToolDef; +class T2ToolDefDB; +class T2ToolDefList; +class T2ToolIconItem; +class T2ToolIconList; class T2ToolPlugin; class T2ToolWindow; class T2TowerDoc; class T2TowerEvent; class T2TowerMainView; +class T2TowerMessage; class T2TowerVision; +class T2TrafficInfo; class T2Transport; -class T2TreasureStatus; +class T2TreasureDialog; +class T2TreasurePane; class T2UnitInfo; class T2WeatherFilter; class T2WordDefArray; class T2WorldDef; class T2WorldPlugin; +class T2XEvent; +class TenantSearchDlg; +class WalkerDlg; enum AREACHECKCODE { - AreaCheckCode_0 + AreaCheckCode_0, + AreaCheckCode_1, + AreaCheckCode_2 }; enum CURSORTYPE { @@ -115,13 +203,32 @@ enum MOUSEEVENT { }; enum OPTIONEVENTTYPE { - OptionEventType_0 + OptionEventType_0, // idle - no data + OptionEventType_1, + OptionEventType_2, + OptionEventType_3, + OptionEventType_4, + OptionEventType_5, + OptionEventType_6, + OptionEventType_7, + OptionEventType_8, + OptionEventType_9, + OptionEventType_10, + OptionEventType_11, // start of GetInterviewWords + OptionEventType_12, // end of GetInterviewWords +}; + +struct OptionEvent11Data { + T2People *people; + CString *str; }; enum PARTCODE { PartCode_0, PartCode_1, - PartCode_2 + PartCode_2, + PartCode_3, + PartCode_4 }; enum PROCCODE { @@ -131,15 +238,23 @@ enum PROCCODE { }; enum ROOFANDFLOOR { - RoofAndFloor_0 + RoofAndFloor_Roof = 1, + RoofAndFloor_Floor = 2 }; enum SIDEOBJPATTERN { - SideObjPattern_0 + SideObjPattern_0, + SideObjPattern_1 }; enum VIEWMODE { - ViewMode_0 + ViewMode_0, + ViewMode_1, + ViewMode_2, + ViewMode_3, + ViewMode_4, + ViewMode_5, + ViewMode_6, }; enum BOOL3 { @@ -148,13 +263,35 @@ enum BOOL3 { BOOL3_1 = 1 }; -enum ERequestUpDown; +enum EEquipPos { + EEquipPos_0, + EEquipPos_1, + EEquipPos_2, + EEquipPos_3 +}; + +enum ERequestUpDown { + ERequestUpDown_0, + ERequestUpDown_1 +}; struct BkgndInfo; +struct T2RoofInfo; // not sure if this is a struct or a class + +struct T2TreasureStatus { + int _0; + char text[256]; + int animID1; + int animID2; +}; +struct Point { + int v; + int h; +}; struct SDimension16 { - short width; short height; + short width; }; struct TableCellT { @@ -162,12 +299,18 @@ struct TableCellT { UINT col; }; +enum { + DrawMode0 = 0, + DrawMode1, + DrawMode2, + DrawMode3, + DrawMode4 +}; + #ifdef _MSC_VER #define MSVC_STDCALL __stdcall -#define DLL_EXPORT __declspec(dllexport) #else #define MSVC_STDCALL -#define DLL_EXPORT #endif // why is this necessary? |