#include "CFilePluginList.h" #include "CResFile.h" #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); worldDef->m1D0->AddObject(mModuleHandle, 100, mToolIcon); mEC = new T2BitImage(mModuleHandle, 1000, 1); mImageObj->AddObject(mModuleHandle, 1000, mEC); mToolQuietUntil = NULL; mCategoryQuietUntil = NULL; 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 (mToolQuietUntil) delete mToolQuietUntil; if (mSubPluginList) delete mSubPluginList; } /*virtual*/ int T2ToolDef::GetSortKey() { int key = mCategoryNo << 16; key += mToolNo; return key; } /*virtual*/ CURSORTYPE T2ToolDef::QueryCursor(T2TowerDoc* inDoc, POINT inPt, CString& outSpriteName, RECT& outRect, POINT& outPt, int inZoomLevel, unsigned int inValiation, int) { outSpriteName = "Csr"; inPt.x -= ((mWidth * UT2Coordinate::UnitHSize(inZoomLevel)) / 2 - UT2Coordinate::UnitHSize(inZoomLevel) / 2); inPt.y -= ((mHeight * UT2Coordinate::UnitVSize(inZoomLevel)) / 2 - UT2Coordinate::UnitVSize(inZoomLevel) / 2); UT2Coordinate::QDToUnit(inPt, inZoomLevel); SetRect(&outRect, inPt.x, inPt.y, inPt.x + mWidth, inPt.y + mHeight); outPt.x = outRect.left; outPt.y = outRect.top; UT2Coordinate::UnitToQD(outRect, inZoomLevel); 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(kToolAttrNormalMenteCost)) cost = GetOutMoney(obj->GetValiation()); return cost; } int T2ToolDef::GetOutMoney(unsigned int id) const { int money = 0; if (id < kMaxValiation) money = mOutMoney[id]; return money; } void T2ToolDef::SetOutMoney(unsigned int id, int money) { if (id < kMaxValiation) 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; }