diff options
Diffstat (limited to 'src/T2DLL/T2TenantDef.cpp')
-rw-r--r-- | src/T2DLL/T2TenantDef.cpp | 266 |
1 files changed, 250 insertions, 16 deletions
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; } |