diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2Equip.cpp | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/src/T2DLL/T2Equip.cpp b/src/T2DLL/T2Equip.cpp new file mode 100644 index 0000000..b6af51b --- /dev/null +++ b/src/T2DLL/T2Equip.cpp @@ -0,0 +1,215 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2CrossEquipArray.h" +#include "T2DateTime.h" +#include "T2Equip.h" +#include "T2SoundPlayer.h" +#include "T2TowerDoc.h" + +T2Equip::T2Equip() { + mEquipID = 0; + SetRect(&mArea, 0, 0, 0, 0); + mEquipType = 0; + mDrawMode = 0; + mPatIndex = 0; + mCapacity = 0; + m44 = 0; + mInMoneyIndex = 0; + m48 = 0; + mBuildDay = 0; + mAttribute = 0; + mCEArray = NULL; + m58 = 0; +} + +/*virtual*/ T2Equip::~T2Equip() { + if (mCEArray) + delete mCEArray; +} + +int T2Equip::InitEquip(T2EquipDef* def, const RECT& area, unsigned int valiation) { + if (def) { + mEquipType = def->GetEquipType(); + mCapacity = def->GetCapacity(); + mAttribute = def->GetAttribute(); + mToolDef = def; + } + mValiation = valiation; + mArea = area; + + mDrawMode = 0; + m44 = 0; + m48 = 0; + mPatIndex = 0; + + T2TowerDoc *towerDoc = GetCurrentT2TowerDoc(); + if (towerDoc) + mBuildDay = towerDoc->towerDoc_vf120()->CalcTotalDays(); + else + mBuildDay = 0; + + mInMoneyIndex = (GetEquipDef()->GetNumOfInMoney() > 1) ? (GetEquipDef()->GetNumOfInMoney() / 2) : 0; + + SetUsed(true); + return true; +} + +/*virtual*/ void T2Equip::SetUsed(int used) { + if (!used && mCEArray) { + delete mCEArray; + mCEArray = NULL; + } + T2HaveOutViewObject::SetUsed(used); +} + +int T2Equip::DaysSinceBuilt(const T2TowerDoc* towerDoc) const { + return towerDoc->towerDoc_vf120()->CalcLapseDays(mBuildDay); +} + +void T2Equip::SetEquipArea(const RECT& rect) { + mArea = rect; +} + +/*virtual*/ int T2Equip::GetOutMoney() const { + int cost = 0; + cost = GetEquipDef()->GetOutMoney(0); + return cost; +} + +/*virtual*/ int T2Equip::GetInMoney() const { + int cost = 0; + cost = GetEquipDef()->GetInMoney(mInMoneyIndex); + return cost; +} + +/*virtual*/ PARTCODE T2Equip::GetClickPart(T2TowerDoc* towerDoc, CPoint pt, int* val) { + return GetEquipDef()->GetPartFromPoint(towerDoc, this, pt, val); +} + +/*virtual*/ PROCCODE T2Equip::DoDestruct(T2TowerDoc*, POINT, RECT&) { + if (mCEArray) + delete mCEArray; + return ProcCode_2; +} + +void T2Equip::InsertCEID(int a, int b) { + if (mCEArray) + mCEArray->Insert(a, b); +} + +void T2Equip::RemoveCEID(int id) { + if (mCEArray) + mCEArray->Remove(&id); +} + +void T2Equip::ReplaceCEID(unsigned int oldID, unsigned int newID) { + if (mCEArray) + mCEArray->ReplaceID(oldID, newID); +} + +/*virtual*/ PARTCODE T2Equip::GetPartFromPoint(T2TowerDoc* towerDoc, POINT pt, int* val) { + return GetEquipDef()->GetPartFromPoint(towerDoc, this, pt, val); +} + +/*virtual*/ void T2Equip::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + T2Object::LoadSelf(archive, towerDoc); + + if (IsUsed()) { + unsigned short us; + short s; + unsigned char uc; + + archive >> us; + mEquipID = us; + + archive.ReadSRect(mArea); + + archive >> s; + mEquipType = s; + archive >> s; + mDrawMode = s; + archive >> uc; + mPatIndex = uc; + archive >> s; + m44 = s; + archive >> s; + mInMoneyIndex = s; + archive >> s; + m48 = s; + + archive >> mBuildDay; + mCEArray = (T2RouteCEArray *) T2CrossEquipArray::ReadCEArray(archive); + archive >> mValiation; + } +} + +/*virtual*/ void T2Equip::SaveSelf(T2Archive& archive) { + T2Object::SaveSelf(archive); + + if (IsUsed()) { + unsigned short us; + short s; + unsigned char uc; + + us = mEquipID; + archive << us; + + archive.WriteSRect(mArea); + + s = mEquipType; + archive << s; + s = mDrawMode; + archive << s; + uc = mPatIndex; + archive << uc; + s = m44; + archive << s; + s = mInMoneyIndex; + archive << s; + s = m48; + archive << s; + + archive << mBuildDay; + T2CrossEquipArray::WriteCEArray(mCEArray, archive); + archive << mValiation; + } +} + +/*virtual*/ T2InfoDialog* T2Equip::ShowInfoDialog(T2TowerDoc* towerDoc) { + return GetEquipDef()->ShowInfoDialog(towerDoc, this); +} + +/*virtual*/ void T2Equip::PlaySound(T2TowerDoc* towerDoc, int id, unsigned int a, unsigned int b) const { + if (towerDoc->towerDoc_vf15C(mArea)) { + T2EquipDef *equipDef = GetEquipDef(); + T2SoundPlayer *soundPlayer = towerDoc->towerDoc_vf134(); + if (equipDef && soundPlayer) { + CRect rect; + GetEquipArea(rect); + CPoint pt = rect.CenterPoint(); + CString name = equipDef->CalcSoundID(id); + soundPlayer->Play( + name, + a, + b, + &pt, + PlayMode_0, + 100 + ); + } + } +} + +/*virtual*/ void T2Equip::DrawHitMask(T2TowerDoc* towerDoc) { + m58 = true; + if (mToolDef->DrawHitMask(towerDoc, this) == ProcCode_0) { + RECT rect; + GetEquipArea(rect); + Draw(towerDoc, rect); + } + m58 = false; +} + +void T2Equip::GetTypicalName(CString& outStr) const { + GetEquipDef()->GetName(outStr, GetValiation()); +} |