#include "StdAfx.h" #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(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; mDrawRoof = (m154 == 0); mDrawFloor = true; mIsLoaded = true; } /*virtual*/ T2TenantDef::~T2TenantDef() { if (mEmployeeTableDef) delete mEmployeeTableDef; if (mCustomerTableDef) delete mCustomerTableDef; if (mPeopleAnimeDef) delete mPeopleAnimeDef; } /*virtual*/ void T2TenantDef::GetName(CString& outStr) { outStr = "TENANT"; } /*virtual*/ BOOL T2TenantDef::InitObject(T2Object* obj) { T2EquipDef::InitObject(obj); ((T2Equip *) obj)->mDrawMode = DrawMode2; return true; } /*virtual*/ void T2TenantDef::DrawProc(T2HaveOutViewObject* obj, const RECT& inRect, T2TowerDoc* towerDoc) const { T2Tenant *tenant = (T2Tenant *) obj; RECT tenantRect = inRect; int objID; int pattern; BOOL includeRoofAndFloor; if (towerDoc->mViewMode != 1) { objID = 100; includeRoofAndFloor = true; pattern = 0; pattern += tenant->mValiation * 1000; pattern += mHeight * 100; pattern += tenant->GetPatIndex(); } else { objID = 101; includeRoofAndFloor = false; pattern = (towerDoc->mWorldDef->GetOutViewKind() + 1) * 10000; pattern += tenant->mValiation * 1000; pattern += mHeight * 100; if (tenant->IsFire()) pattern += 2; else if (towerDoc->GetPaletteAnime()->IsSnow()) pattern += 1; } UT2Coordinate::UnitToQD(tenantRect, towerDoc->GetZoomLevel(), !includeRoofAndFloor); int objectIndex = mImageObj->FindObject(objID, pattern); if (objectIndex >= 0) { mImageObj->DrawObject(towerDoc->GetImage(), objectIndex, tenantRect, towerDoc->GetZoomLevel()); } else if (tenant->m58) { towerDoc->GetImage()->FillRect(tenantRect, 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 y) { return y; } /*virtual*/ void T2TenantDef::DrawPeople(T2TowerDoc* towerDoc, T2Equip* equip) { if (towerDoc->mViewMode != 1) T2EquipDef::DrawPeople(towerDoc, equip); } /*virtual*/ int T2TenantDef::DrawAttribute(int y) { return y; } /*virtual*/ unsigned int T2TenantDef::IdleProc(T2HaveOutViewObject* obj, T2TowerDoc* towerDoc) { T2Equip *theEquip = (T2Equip *) obj; int status = theEquip->GetStatus(); unsigned int result = 0; if (status < kTenantStatus10) { if (status <= kTenantStatus2 || status == kTenantStatus9) result = 1; status++; theEquip->SetStatus(status); if (status == kTenantStatus10) { BuildFinish(towerDoc, theEquip); towerDoc->mTowerMainView->InvalUnitRect(theEquip->mArea, true); } } T2Tenant *theTenant = (T2Tenant *) theEquip; status = theTenant->GetStatus(); if (status >= kTenantStatus9 && ChangeStatusOnIdle(towerDoc, theTenant, status)) { if (status == kTenantStatus9) theTenant->SetDrawMode(DrawMode2); else theTenant->SetDrawMode(DrawMode1); } if (theTenant->GetDrawMode() != DrawMode0) towerDoc->mTowerMainView->InvalUnitRect(theTenant->mArea, false); return result; } /*virtual*/ BOOL T2TenantDef::ChangeStatusOnIdle(T2TowerDoc*, T2Tenant*, int) { return false; } /*virtual*/ AREACHECKCODE T2TenantDef::AreaCheck(T2TowerDoc* towerDoc, RECT& rect, unsigned int a, BOOL inShowError) { if (GetCategory() != 100 && rect.top <= towerDoc->mWorldDef->mTopFloorLine) { if (inShowError) { // EN: Only Final item can be placed on the top floor of building. towerDoc->GetTowerMessage()->BuildErr(68, NULL); } return AreaCheckCode_0; } if (rect.bottom > towerDoc->mWorldDef->mBottomFloorLine) { if (inShowError) { // EN: Can not place items beyond the edges of the floor below. towerDoc->GetTowerMessage()->BuildErr(2, NULL); } return AreaCheckCode_0; } return AreaCheckCode_1; } /*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*) { } /*virtual*/ void T2TenantDef::LeaveTenant(T2TowerDoc*, T2Tenant*, T2People*) { } /*virtual*/ void T2TenantDef::BuildStartProc(T2TowerDoc*, T2Tenant*) { } /*virtual*/ void T2TenantDef::DoPeopleAnimation(T2TowerDoc*, T2Tenant*) { } /*virtual*/ BOOL T2TenantDef::GetQTMovieName(T2Tenant*, CString& outStr) { outStr = ""; return outStr != NULL; } 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 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*/ 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* 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; }