From 37e364b2c6cc7487a1c888d256a73e5337bb7189 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 14 Jun 2023 00:50:34 +0100 Subject: initial commit --- src/T2DLL/T2ToolDef.cpp | 166 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 src/T2DLL/T2ToolDef.cpp (limited to 'src/T2DLL/T2ToolDef.cpp') diff --git a/src/T2DLL/T2ToolDef.cpp b/src/T2DLL/T2ToolDef.cpp new file mode 100644 index 0000000..c57672f --- /dev/null +++ b/src/T2DLL/T2ToolDef.cpp @@ -0,0 +1,166 @@ +#include "CFilePluginList.h" +#include "CResFile.h" +#include "CResourcePlugin.h" +#include "T2AdvertisePlugin.h" +#include "T2BitImage.h" +#include "T2HaveOutViewObject.h" +#include "T2ImageObj.h" +#include "T2ToolDef.h" +#include "T2ToolPlugin.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); + + mEC = new T2BitImage(mModuleHandle, 1000, 1); + mImageObj->AddObject(mModuleHandle, 1000, mEC); + + m114 = NULL; + m118 = 0; + + mSettlement = 0; + mCurBuildCount = 0; + mMaxBuildCount = 0; + mSubPluginList = NULL; + + unsigned long tmp; + + *resFile >> mToolType; + *resFile >> mWidth; + *resFile >> mHeight; + *resFile >> mLevel; + *resFile >> mAttribute; + *resFile >> mCategoryCommentString; + *resFile >> mCategoryName; + *resFile >> mCategoryNo; + *resFile >> mToolNo; + *resFile >> tmp; // mAfterCategoryNo + *resFile >> tmp; // mAfterToolNo + *resFile >> mSubPluginType; + *resFile >> tmp; // mCategoryIcon res ID + *resFile >> tmp; // mCategoryHelpResID + *resFile >> mValiationCount; + + for (int i = 0; i < mValiationCount; i++) { + mPriceString[i] = new CString; + *resFile >> *mPriceString[i]; + mOutMoneyString[i] = new CString; + *resFile >> *mOutMoneyString[i]; + mCommentString[i] = new CString; + *resFile >> *mCommentString[i]; + mToolName[i] = new CString; + *resFile >> *mToolName[i]; + mName[i] = new CString; + *resFile >> *mName[i]; + + *resFile >> mPrice[i]; + *resFile >> mOutMoney[i]; + *resFile >> tmp; // id2 + *resFile >> tmp; // offscreen res ID + *resFile >> tmp; // tool help res ID + *resFile >> mConsumptionPower[i]; + } +} + +/*virtual*/ T2ToolDef::~T2ToolDef() { + for (int i = 0; i < mValiationCount; i++) { + delete mPriceString[i]; + delete mOutMoneyString[i]; + delete mCommentString[i]; + delete mToolName[i]; + delete mName[i]; + } + + if (mToolIcon) + delete mToolIcon; + if (mEC) + delete mEC; + if (m114) + delete m114; // what type is this? + if (mSubPluginList) + delete mSubPluginList; +} + +/*virtual*/ int T2ToolDef::GetSortKey() { + int key = mCategoryNo << 16; + key += mToolNo; + return key; +} + +/*virtual*/ CURSORTYPE T2ToolDef::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, 0); + + return CursorType_0; +} + +CString T2ToolDef::CalcSoundID(int id) const { + CString s; + s.Format("%d:%d", mToolType, id); + return s; +} + +void T2ToolDef::GetName(CString& outStr, int id) { + outStr = *mName[id]; +} + +/*virtual*/ int T2ToolDef::CalcMentenanceCostProc(const T2HaveOutViewObject* obj) const { + int cost = 0; + T2ToolDef *objToolDef = obj->GetToolDef(); + if (objToolDef->IsSetAttribute(0x100)) + cost = GetOutMoney(obj->GetValiation()); + return cost; +} + +int T2ToolDef::GetOutMoney(unsigned int id) const { + int money = 0; + if (id < 4) + money = mOutMoney[id]; + return money; +} + +void T2ToolDef::SetOutMoney(unsigned int id, int money) { + if (id < 4) + mOutMoney[id] = money; +} + +/*virtual*/ void T2ToolDef::Add(CResourcePlugin* plugin) { + DWORD type = GetSubPluginType(); + + if (plugin->GetType() == type) { + if (!mSubPluginList) + mSubPluginList = new CFilePluginList(type); + + if (mSubPluginList) + mSubPluginList->Add(plugin); + } +} + +/*virtual*/ void T2ToolDef::Add(T2AdvertisePlugin* plugin) { + DWORD type = GetSubPluginType(); + + if (plugin->GetSubType() == type) { + if (!mSubPluginList) + mSubPluginList = new CFilePluginList(type); + + if (mSubPluginList) + mSubPluginList->Add(plugin); + } +} + +/*virtual*/ PROCCODE T2ToolDef::DoDestructProc(T2TowerDoc*, T2HaveOutViewObject*, POINT, RECT&) { + return ProcCode_0; +} -- cgit v1.2.3