diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2FloorInfo.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2FloorInfo.cpp | 950 |
1 files changed, 894 insertions, 56 deletions
diff --git a/src/T2DLL/T2FloorInfo.cpp b/src/T2DLL/T2FloorInfo.cpp index cfbd45b..7ab47a6 100644 --- a/src/T2DLL/T2FloorInfo.cpp +++ b/src/T2DLL/T2FloorInfo.cpp @@ -1,187 +1,1025 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2FInfoAreaIterator.h" #include "T2FloorInfo.h" +#include "T2Mover.h" +#include "T2MoverArray.h" +#include "T2MoverArrayList.h" +#include "T2MoverDef.h" +#include "T2MoverModule.h" +#include "T2MoverModuleList.h" +#include "T2OutObjArrayList.h" +#include "T2OutsideInfo.h" +#include "T2RegistedTenantDB.h" +#include "T2Request.h" +#include "T2RequestArrayList.h" +#include "T2Tenant.h" +#include "T2TenantArrayList.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2UnitInfo.h" +#include "T2WorldDef.h" -T2FloorInfo::T2FloorInfo(const T2WorldDef*) { +T2FloorInfo::T2FloorInfo(const T2WorldDef* inWorldDef) { + mVRange = inWorldDef->GetHeight(); + mHRange = inWorldDef->GetWidth(); + mGroundLine = inWorldDef->mGroundLine; + mTopFloorLine = inWorldDef->mTopFloorLine; + mBottomFloorLine = inWorldDef->mBottomFloorLine; + mEntranceWidth = 7; + + inWorldDef->GetBuildArea(mBuildArea); + mFloorArea = mBuildArea; + mFloorArea.top = mTopFloorLine; + mFloorArea.bottom = mBottomFloorLine; + + mUnitInfo = NULL; + mTenantArrayList = NULL; + mMoverArrayList = NULL; + mRequestArrayList = NULL; + mOutObjArrayList = NULL; + mTenantNumber = NULL; + + mUnitInfo = new T2UnitInfo[mHRange * mVRange]; + + mTenantArrayList = new T2TenantArrayList; + mMoverArrayList = new T2MoverArrayList; + mRequestArrayList = new T2RequestArrayList; + mOutObjArrayList = new T2OutObjArrayList; + + mOutsideInfo = new T2OutsideInfo(*this); + mTenantNumber = new unsigned int[mVRange]; + memset(mTenantNumber, 0, sizeof(unsigned int) * mVRange); } /*virtual*/ T2FloorInfo::~T2FloorInfo() { + if (mUnitInfo) + delete[] mUnitInfo; + + if (mTenantArrayList) + delete mTenantArrayList; + if (mMoverArrayList) + delete mMoverArrayList; + if (mRequestArrayList) + delete mRequestArrayList; + if (mOutObjArrayList) + delete mOutObjArrayList; + + if (mOutsideInfo) + delete mOutsideInfo; + + if (mTenantNumber) + delete[] mTenantNumber; } -int T2FloorInfo::UnitToFloor(int) const { +int T2FloorInfo::UnitToFloor(int unit) const { + return (unit < mGroundLine) ? (mGroundLine - unit) : ((mGroundLine - unit) - 1); } -void T2FloorInfo::InitMask(CResFile&) { +void T2FloorInfo::InitMask(CResFile& inResFile) { + int vcheck; + int hcheck; + inResFile >> vcheck; + inResFile >> hcheck; + +#line 211 + _ASSERT((vcheck == mVRange) && (hcheck == mHRange)); + + int tmp; + RECT tmpRect; + inResFile >> tmp; + inResFile >> tmpRect; + + for (int i = 0; i < (mVRange * mHRange); i++) + mUnitInfo[i].InitMask(inResFile); } -void T2FloorInfo::Read(T2Archive&, T2TowerDoc*) { +void T2FloorInfo::Read(T2Archive& inArchive, T2TowerDoc* inDoc) { + int vcheck; + int hcheck; + inArchive >> vcheck; + inArchive >> hcheck; + + if (vcheck != mVRange || hcheck != mHRange) + return; + +#line 234 + _ASSERT((vcheck == mVRange) && (hcheck == mHRange)); + + DWORD code; + inArchive >> code; +#line 239 + _ASSERT(code == 'UntI'); + + for (int i = 0; i < (mVRange * mHRange); i++) + mUnitInfo[i].Read(inArchive, inDoc); + + inArchive >> code; + if (code == 'TntA') { + mTenantArrayList->Read(inArchive, inDoc); + T2RegistedTenantDB *theDB = inDoc->towerDoc_vf174(); + theDB->Init(mTenantArrayList); + mTenantArrayList->RecoverRelatedTenantList(theDB); + inArchive >> code; + } + if (code == 'MvrA') { + mMoverArrayList->Read(inArchive, inDoc); + inArchive >> code; + } + if (code == 'ReqA') { + mRequestArrayList->Read(inArchive, inDoc); + inArchive >> code; + } + if (code == 'OObA') { + mOutObjArrayList->Read(inArchive, inDoc); + inArchive >> code; + } + if (code == 'OutI') + mOutsideInfo->Read(inArchive); } -void T2FloorInfo::Write(T2Archive&) { +void T2FloorInfo::Write(T2Archive& inArchive) { + inArchive << mVRange; + inArchive << mHRange; + + DWORD code = 'UntI'; + inArchive << code; + for (int i = 0; i < (mVRange * mHRange); i++) + mUnitInfo[i].Write(inArchive); + + code = 'TntA'; + inArchive << code; + mTenantArrayList->Write(inArchive); + + code = 'MvrA'; + inArchive << code; + mMoverArrayList->Write(inArchive); + + code = 'ReqA'; + inArchive << code; + mRequestArrayList->Write(inArchive); + + code = 'OObA'; + inArchive << code; + mOutObjArrayList->Write(inArchive); + + code = 'OutI'; + inArchive << code; + mOutsideInfo->Write(inArchive); } -int T2FloorInfo::IsValidRange(const RECT&) const { +BOOL T2FloorInfo::IsValidRange(const RECT& inRect) const { + BOOL result = true; + + if (mBuildArea.top > inRect.top || mBuildArea.bottom < inRect.bottom || mBuildArea.left > inRect.left || mBuildArea.right < inRect.right) + result = false; + + return result; } -int T2FloorInfo::IsAreaBuildable(const RECT&) { +BOOL T2FloorInfo::IsAreaBuildable(const RECT& inRect) { + BOOL result = false; + + if (IsValidRange(inRect)) { + result = true; + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *unitInfo; + while (iterator.Next(unitInfo) && result == true) { + if (!unitInfo->IsBuildable()) + result = false; + } + } + + return result; } -int T2FloorInfo::IsAllTenant(const RECT&) { +BOOL T2FloorInfo::IsAllTenant(const RECT& inRect) { + BOOL result = true; + + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *unitInfo; + + while (iterator.Next(unitInfo)) { + if (unitInfo->GetTenantID() < 1000) { + result = false; + break; + } + } + + return result; } -int T2FloorInfo::IsThereNoFloorTenant(const RECT&) { +BOOL T2FloorInfo::IsThereNoFloorTenant(const RECT& inRect) { + BOOL result = false; + + T2FInfoAreaIterator iterator(*this, inRect); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) { + if (!theTenant->IsFloor()) { + result = true; + break; + } + } + + return result; } -int T2FloorInfo::IsThereMover(const RECT&) { +BOOL T2FloorInfo::IsThereMover(const RECT& inRect) { + BOOL result = false; + + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) { + if (theUnitInfo->GetMoverID()) { + result = true; + break; + } + } + + return result; } -int T2FloorInfo::IsThereOtherKindMover(const RECT&, int) { +BOOL T2FloorInfo::IsThereOtherKindMover(const RECT& inRect, int inType) { + BOOL result = false; + unsigned int zero = 0; + + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) { + unsigned int moverID = theUnitInfo->GetMoverID(); + if (moverID != 0 && moverID != zero) { + T2Mover *theMover = GetMover(moverID); + if (theMover && theMover->GetEquipType() != inType) { + result = true; + break; + } + } + } + + return result; } -int T2FloorInfo::IsEnoughSideSpace(const RECT&) { +BOOL T2FloorInfo::IsEnoughSideSpace(const RECT& inRect) { + BOOL result = true; + + RECT rect = inRect; + rect.right = rect.left; + rect.left -= T2MoverDef::GetRequiredRequestSpace() * 2; + result = !IsThereMover(rect); + + if (result) { + rect = inRect; + rect.right = rect.left; + rect.left += T2MoverDef::GetRequiredRequestSpace() * 2; + result = !IsThereMover(rect); + } + + return result; } -T2Tenant* T2FloorInfo::GetTenant(unsigned int) const { +T2Tenant* T2FloorInfo::GetTenant(unsigned int inTenantID) const { + T2Tenant *result = NULL; + + if (inTenantID >= 1000) + result = mTenantArrayList->GetTenantByID(inTenantID); + + return result; } -T2Tenant* T2FloorInfo::GetTenant(int, int) const { +T2Tenant* T2FloorInfo::GetTenant(int inV, int inH) const { + T2Tenant *result = NULL; + + unsigned int tenantID = GetTenantID(inV, inH); + if (tenantID) + result = mTenantArrayList->GetTenantByID(tenantID); + + return result; } T2Tenant* T2FloorInfo::GetPoolTenant() const { + return GetTenant(1000); } -T2Tenant* T2FloorInfo::GetFloor(int, int) const { +T2Tenant* T2FloorInfo::GetFloor(int inV, int inH) const { + T2Tenant *result = NULL; + + T2Tenant *theTenant = GetTenant(inV, inH); + if (theTenant) { + if (theTenant->IsFloor()) { + result = theTenant; + } else { + unsigned int floorID = theTenant->GetFloorID(inV); + result = GetTenant(floorID); + } + } + + return result; } -T2Mover* T2FloorInfo::GetMover(unsigned int) { +T2Mover* T2FloorInfo::GetMover(unsigned int inMoverID) { + return mMoverArrayList->GetMoverByID(inMoverID); } -T2Mover* T2FloorInfo::GetMover(int, int) { +T2Mover* T2FloorInfo::GetMover(int inV, int inH) { + T2Mover *result = NULL; + + unsigned int moverID = GetMoverID(inV, inH); + if (moverID) + result = mMoverArrayList->GetMoverByID(moverID); + + return result; } -T2MoverModule* T2FloorInfo::GetModule(unsigned int) const { +T2MoverModule* T2FloorInfo::GetModule(unsigned int inModuleID) const { + LArrayIterator arrayIterator(*mMoverArrayList); + T2MoverArray *theArray; + + while (arrayIterator.Next(&theArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + T2Mover *theMover = theArray->GetIndexMover(i); + + if (theMover->IsUsed() && theMover->GetModuleList()) { + LArrayIterator moduleIterator(*theMover->GetModuleList()); + T2MoverModule *theModule; + + while (moduleIterator.Next(&theModule)) { + if (theModule->GetModuleID() == inModuleID) + return theModule; + } + } + } + } + + return NULL; } -T2Request* T2FloorInfo::GetRequest(unsigned int) const { +T2Request* T2FloorInfo::GetRequest(unsigned int inRequestID) const { + return mRequestArrayList->GetRequestByID(inRequestID); } -T2Request* T2FloorInfo::GetRequest(int, int) const { +T2Request* T2FloorInfo::GetRequest(int inV, int inH) const { + T2Request *result = NULL; + + unsigned int requestID = GetRequestID(inV, inH); + if (requestID) + result = mRequestArrayList->GetRequestByID(requestID); + + return result; } -T2People* T2FloorInfo::FindPeople(int, int) const { +T2People* T2FloorInfo::FindPeople(int inV, int inH) const { + T2People *result = NULL; + + T2Tenant *theFloor = GetFloor(inV, inH); + if (theFloor) { + POINT pt; + pt.x = inH; + pt.y = inV; + result = theFloor->FindPeople(pt); + } + + if (!result) { + T2Request *theRequest = GetRequest(inV, inH); + if (theRequest) + result = theRequest->FindPeople(inH); + } + + return result; } -T2OutObj* T2FloorInfo::GetOutObj(int, int) const { +T2OutObj* T2FloorInfo::GetOutObj(int inV, int inH) const { + return mOutObjArrayList->GetOutObjByID(GetOutObjID(inV, inH)); } -T2OutObj* T2FloorInfo::GetIndOutObj(unsigned int) const { +T2OutObj* T2FloorInfo::GetIndOutObj(unsigned int inIndex) const { + return mOutObjArrayList->GetIndOutObj(inIndex); } T2Tenant* T2FloorInfo::FindUnusedTenant() { + return mTenantArrayList->FindUnusedTenant(); } T2Mover* T2FloorInfo::FindUnusedMover() { + return mMoverArrayList->FindUnusedMover(); } T2Request* T2FloorInfo::FindUnusedRequest() { + return mRequestArrayList->FindUnusedRequest(); } T2OutObj* T2FloorInfo::FindUnusedOutObj() { + return mOutObjArrayList->FindUnusedOutObj(); } -unsigned int T2FloorInfo::GetTenantID(int, int) const { +unsigned int T2FloorInfo::GetTenantID(int inV, int inH) const { + unsigned int result = 0; + + T2UnitInfo *theUnitInfo = GetUnitInfo(inV, inH); + if (theUnitInfo) + result = theUnitInfo->GetTenantID(); + + return result; } -unsigned int T2FloorInfo::GetFloorID(int, int) { +unsigned int T2FloorInfo::GetFloorID(int inV, int inH) { + unsigned int result = 0; + + T2Tenant *theTenant = GetTenant(inV, inH); + if (theTenant) + result = theTenant->GetFloorID(inV); + + return result; } -unsigned int T2FloorInfo::GetEntranceFloorID(unsigned int) { +unsigned int T2FloorInfo::GetEntranceFloorID(unsigned int inTenantID) { + unsigned int result = 0; + + if (inTenantID == 1 || inTenantID == 2) { + result = 1000; + } else { + T2Tenant *theTenant = GetTenant(inTenantID); + if (theTenant) + result = theTenant->GetEntranceFloorID(); + } + + return result; } -POINT T2FloorInfo::GetEntrancePt(unsigned int) { +POINT T2FloorInfo::GetEntrancePt(unsigned int inTenantID) { + POINT result; + result.x = -1; + result.y = -1; + + if (inTenantID == 1 || inTenantID == 2) { + unsigned int id = 1000; + T2Tenant *theTenant = GetTenant(id); + if (theTenant) { + RECT area; + theTenant->GetEquipArea(area); + + result.y = area.bottom - 1; + if (inTenantID == 1) + result.x = area.left; + else + result.x = area.right - 2; + } + } else { + T2Tenant *theTenant = GetTenant(inTenantID); + if (theTenant) + result = theTenant->GetEntrancePt(); + } + + return result; } -unsigned int T2FloorInfo::GetMoverID(int, int) { +unsigned int T2FloorInfo::GetMoverID(int inV, int inH) { + unsigned int result = 0; + + T2UnitInfo *theUnitInfo = GetUnitInfo(inV, inH); + if (theUnitInfo) + result = theUnitInfo->GetMoverID(); + + return result; } -unsigned int T2FloorInfo::GetRequestID(int, int) const { +unsigned int T2FloorInfo::GetRequestID(int inV, int inH) const { + unsigned int result = 0; + + T2UnitInfo *theUnitInfo = GetUnitInfo(inV, inH); + if (theUnitInfo) + result = theUnitInfo->GetRequestID(); + + return result; } -unsigned int T2FloorInfo::GetOutObjID(int, int) const { +unsigned int T2FloorInfo::GetOutObjID(int inV, int inH) const { + unsigned int result = 0; + + if (mOutsideInfo) + result = mOutsideInfo->GetOutObjID(inV, inH); + + return result; } -T2UnitInfo* T2FloorInfo::GetUnitInfo(int, int) const { +T2UnitInfo* T2FloorInfo::GetUnitInfo(int inV, int inH) const { + T2UnitInfo *result = NULL; + +#line 829 + _ASSERT((inV >= 0) && (inV < mVRange)); + _ASSERT((inH >= 0) && (inH < mHRange)); + + if (inV >= 0 && inV < mVRange && inH >= 0 && inH < mHRange) + result = &mUnitInfo[mHRange * inV + inH]; + + return result; } -void T2FloorInfo::FillTenantID(const RECT&, unsigned int) { +void T2FloorInfo::FillTenantID(const RECT& inRect, unsigned int inTenantID) { + if (IsValidRange(inRect)) { + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) + theUnitInfo->FillTenantID(inTenantID); + } } -void T2FloorInfo::ReplaceFloorID(const RECT&, unsigned int, unsigned int) { +void T2FloorInfo::ReplaceFloorID(const RECT& inRect, unsigned int inOldID, unsigned int inNewID) { + if (IsValidRange(inRect)) { + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) { + if (theUnitInfo->GetTenantID() == inOldID) + theUnitInfo->FillTenantID(inNewID); + } + } } -void T2FloorInfo::FillMoverID(const RECT&, unsigned int) { +void T2FloorInfo::FillMoverID(const RECT& inRect, unsigned int inMoverID) { + if (IsValidRange(inRect)) { + T2FInfoAreaIterator iterator(*this, inRect); + T2UnitInfo *theUnitInfo; + + while (iterator.Next(theUnitInfo)) + theUnitInfo->FillMoverID(inMoverID); + } } -void T2FloorInfo::FillRequestID(const RECT&, unsigned int) { +void T2FloorInfo::FillRequestID(const RECT& inRect, unsigned int inRequestID) { + FillMoverID(inRect, inRequestID); } -int T2FloorInfo::FillRequestID(POINT, ERequestUpDown, unsigned int) { +int T2FloorInfo::FillRequestID(POINT inPt, ERequestUpDown inUpDown, unsigned int inRequestID) { + int result = 0; + POINT pt = inPt; + + if (inUpDown == ERequestUpDown_1) { + pt.x += 2; + + T2Request *theRequest = GetRequest(pt.y, pt.x); + if (theRequest) { + POINT head = theRequest->GetHeadPosition(); + result = ((head.x - inPt.x) / 2) - 2; + int width = result + ((head.x - inPt.x) % 2); + theRequest->SetDrawWidth(width); + } else { + T2Tenant *theFloor = GetFloor(pt.y, pt.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + result = CalcRequestRightEnd(pt, floorArea.right) - inPt.x - 2; + } + } + } else { + pt.x -= 3; + + T2Request *theRequest = GetRequest(pt.y, pt.x); + if (theRequest) { + POINT head = theRequest->GetHeadPosition(); + int width = ((inPt.x - head.x) / 2) - 2; + theRequest->SetDrawWidth(width); + result = width + ((inPt.x - head.x) % 2); + } else { + T2Tenant *theFloor = GetFloor(pt.y, pt.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + result = inPt.x - CalcRequestLeftEnd(pt, floorArea.left) - 2; + } + } + } + + RECT area; + area.top = inPt.y; + area.bottom = inPt.y + 1; + area.left = area.right = inPt.x; + + if (inUpDown == ERequestUpDown_1) + area.right = inPt.x + result + 2; + else + area.left = inPt.x - result - 2; + + FillRequestID(area, inRequestID); + return result; } -void T2FloorInfo::RemoveRequestID(ERequestUpDown, const RECT&) { +void T2FloorInfo::RemoveRequestID(ERequestUpDown inUpDown, const RECT& inRect) { + FillRequestID(inRect, 0); + + if (inUpDown == ERequestUpDown_0) { + T2Request *theRequest = GetRequest(inRect.top, inRect.left - 1); + if (theRequest) { + RECT rect = inRect; + rect.right -= 2; + theRequest->SetDrawWidth(theRequest->GetDrawWidth() + (rect.right - rect.left)); + FillRequestID(rect, theRequest->GetRequestID()); + } + } else { + T2Request *theRequest = GetRequest(inRect.top, inRect.right); + if (theRequest) { + RECT rect = inRect; + rect.left += 2; + theRequest->SetDrawWidth(theRequest->GetDrawWidth() + (rect.right - rect.left)); + FillRequestID(rect, theRequest->GetRequestID()); + } + } } -void T2FloorInfo::FillOutObjID(const RECT&, unsigned int) { +void T2FloorInfo::FillOutObjID(const RECT& inRect, unsigned int inOutObjID) { + if (IsValidRange(inRect)) + mOutsideInfo->FillOutObjID(inRect, inOutObjID); } -unsigned int T2FloorInfo::FindTenantID(int, int, int, int, unsigned int) { +unsigned int T2FloorInfo::FindTenantID(int inV, int inH, BOOL inRight, int inMaxDistance, unsigned int inExclTenantID) { + unsigned int result = 0; + + POINT pt; + SetPt(&pt, inH, inV); + T2FInfoPtIterator iterator(*this, pt); + + int distance = 0; + T2UnitInfo *theUnitInfo; + unsigned int checkID; + + if (!inRight) { + while (iterator.Left(theUnitInfo) && distance < inMaxDistance) { + checkID = theUnitInfo->GetTenantID(); + if (checkID != 0 && checkID != inExclTenantID) { + result = checkID; + break; + } + distance++; + } + } else { + while (iterator.Right(theUnitInfo) && distance < inMaxDistance) { + checkID = theUnitInfo->GetTenantID(); + if (checkID != 0 && checkID != inExclTenantID) { + result = checkID; + break; + } + distance++; + } + } + + return result; } -int T2FloorInfo::CalcRequestRightEnd(POINT, int) { +int T2FloorInfo::CalcRequestRightEnd(POINT inPt, int inMaxH) { + int h = inPt.x + 1; + + T2FInfoPtIterator iterator(*this, inPt); + T2UnitInfo *theUnitInfo; + + while (iterator.Right(theUnitInfo) && h < inMaxH) { + if (theUnitInfo->GetMoverID() != 0) { + h -= 2; + break; + } + h++; + } + + return h; } -int T2FloorInfo::CalcRequestLeftEnd(POINT, int) { +int T2FloorInfo::CalcRequestLeftEnd(POINT inPt, int inMinH) { + int h = inPt.x; + + T2FInfoPtIterator iterator(*this, inPt); + T2UnitInfo *theUnitInfo; + + while (iterator.Left(theUnitInfo) && h > inMinH) { + if (theUnitInfo->GetMoverID() != 0) { + h += 2; + break; + } + h--; + } + + return h; } -int T2FloorInfo::GetLeftMoverID(POINT, int) const { +int T2FloorInfo::GetLeftMoverID(POINT inPt, int inMinH) const { + int result = 0; + int h = inPt.x; + + T2FInfoPtIterator iterator(*this, inPt); + T2UnitInfo *theUnitInfo; + + while (iterator.Left(theUnitInfo) && h > inMinH && result == 0) { + result = theUnitInfo->GetMoverID(); + h--; + } + + return result; } -void T2FloorInfo::UpdeteRequestByUnionFloor(T2Tenant*, POINT) { +void T2FloorInfo::UpdeteRequestByUnionFloor(T2Tenant* inTenant, POINT inPt) { + POINT rightPt = inPt; + rightPt.x++; + + T2Request *theLeftRequest = GetRequest(inPt.y, inPt.x); + T2Request *theRightRequest = GetRequest(rightPt.y, rightPt.x); + + if (theLeftRequest) { + POINT leftHeadPt = theLeftRequest->GetHeadPosition(); + if (theRightRequest) { + POINT rightHeadPt = theRightRequest->GetHeadPosition(); + + int width = ((rightHeadPt.x - leftHeadPt.x) / 2) - 2; + theLeftRequest->SetDrawWidth(width); + theRightRequest->SetDrawWidth(width + ((rightHeadPt.x - leftHeadPt.x) % 2)); + + RECT rightArea; + theRightRequest->CalcArea(rightArea); + FillRequestID(rightArea, theRightRequest->GetRequestID()); + } else { + RECT floorArea; + inTenant->GetEquipArea(floorArea); + theLeftRequest->SetDrawWidth(CalcRequestRightEnd(inPt, floorArea.right) - leftHeadPt.x - 2); + } + + RECT leftArea; + theLeftRequest->CalcArea(leftArea); + FillRequestID(leftArea, theLeftRequest->GetRequestID()); + } else if (theRightRequest) { + POINT rightHeadPt = theRightRequest->GetHeadPosition(); + + RECT floorArea; + inTenant->GetEquipArea(floorArea); + theRightRequest->SetDrawWidth(rightHeadPt.x - CalcRequestLeftEnd(rightPt, floorArea.left) - 2); + + RECT rightArea; + theRightRequest->CalcArea(rightArea); + FillRequestID(rightArea, theRightRequest->GetRequestID()); + } } -void T2FloorInfo::MoverAreaAdded(const RECT&, unsigned int) { +void T2FloorInfo::MoverAreaAdded(const RECT& inRect, unsigned int inMoverID) { + UpdeteRequestByBuildMover(inRect); + FillMoverID(inRect, inMoverID); } -void T2FloorInfo::MoverAreaRemoved(const RECT&) { +void T2FloorInfo::MoverAreaRemoved(const RECT& inRect) { + FillMoverID(inRect, 0); + UpdeteRequestByRemoveMover(inRect); } -void T2FloorInfo::UpdeteRequestByBuildMover(const RECT&) { +void T2FloorInfo::UpdeteRequestByBuildMover(const RECT& inRect) { + POINT pt; + pt.x = inRect.left; + pt.y = inRect.top; + + for (int v = inRect.top; v < inRect.bottom; v++, pt.y++) { + T2Request *theRequest = GetRequest(pt.y, pt.x); + if (theRequest) { + POINT headPt = theRequest->GetHeadPosition(); + int width = theRequest->GetDrawWidth() + 2; + + RECT area; + area.top = v; + area.bottom = v + 1; + + if (theRequest->GetUpDown() == ERequestUpDown_1) { + POINT pt2 = pt; + + area.left = inRect.left - 2; + area.right = headPt.x + width; + theRequest->SetDrawWidth(area.left - headPt.x - 2); + FillRequestID(area, 0); + + pt2.x = area.right; + T2Request *theOtherRequest = GetRequest(pt2.y, pt2.x); + if (theOtherRequest) { + POINT headPt2 = theOtherRequest->GetHeadPosition(); + if (pt2.x < (inRect.right + 2)) { + area.left = pt2.x; + area.right = inRect.right + 2; + theOtherRequest->SetDrawWidth(headPt2.x - area.right - 2); + FillRequestID(area, 0); + } else if (pt2.x > (inRect.right + 2)) { + area.left = inRect.right + 2; + area.right = pt2.x; + theOtherRequest->SetDrawWidth(headPt.x - area.left - 2); + FillRequestID(area, theOtherRequest->GetRequestID()); + } + } + } else { + POINT pt2 = pt; + + area.left = headPt.x - width; + area.right = inRect.right + 2; + theRequest->SetDrawWidth(headPt.x - area.right - 2); + FillRequestID(area, 0); + + pt2.x = area.left - 1; + T2Request *theOtherRequest = GetRequest(pt2.y, pt2.x); + if (theOtherRequest) { + POINT headPt2 = theOtherRequest->GetHeadPosition(); + area.left = pt2.x + 1; + area.right = inRect.left - 2; + theOtherRequest->SetDrawWidth(area.right - headPt2.x - 2); + FillRequestID(area, theOtherRequest->GetRequestID()); + } + } + } + } } -void T2FloorInfo::UpdeteRequestByRemoveMover(const RECT&) { +void T2FloorInfo::UpdeteRequestByRemoveMover(const RECT& inRect) { + POINT pt1; + POINT pt2; + + pt2.y = pt1.y = inRect.top; + + pt1.x = inRect.left - 3; + pt2.x = inRect.right + 2; + + for (; pt1.y < inRect.bottom; pt1.y++, pt2.y++) { + T2Request *theRequest1 = GetRequest(pt1.y, pt1.x); + T2Request *theRequest2 = GetRequest(pt2.y, pt2.x); + + if (theRequest1) { + POINT headPt1 = theRequest1->GetHeadPosition(); + if (theRequest2) { + POINT headPt2 = theRequest2->GetHeadPosition(); + + int width = ((headPt2.x - headPt1.x) / 2) - 2; + theRequest1->SetDrawWidth(width); + theRequest2->SetDrawWidth(width + ((headPt2.x - headPt1.x) % 2)); + + RECT area2; + theRequest2->CalcArea(area2); + FillRequestID(area2, theRequest2->GetRequestID()); + } else { + T2Tenant *theFloor = GetFloor(pt1.y, pt1.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + theRequest1->SetDrawWidth(CalcRequestRightEnd(pt1, floorArea.right) - headPt1.x - 2); + } + } + + RECT area1; + theRequest1->CalcArea(area1); + FillRequestID(area1, theRequest1->GetRequestID()); + } else if (theRequest2) { + POINT headPt2 = theRequest2->GetHeadPosition(); + + T2Tenant *theFloor = GetFloor(pt1.y, pt1.x); + if (theFloor) { + RECT floorArea; + theFloor->GetEquipArea(floorArea); + theRequest2->SetDrawWidth(headPt2.x - CalcRequestLeftEnd(pt2, floorArea.left) - 2); + } + + RECT area2; + theRequest2->CalcArea(area2); + FillRequestID(area2, theRequest2->GetRequestID()); + } + } } -unsigned int T2FloorInfo::GetNextTenantNumber(int) { +unsigned int T2FloorInfo::GetNextTenantNumber(int inV) { +#line 1364 + _ASSERT((inV >= 0) && (inV < mVRange)); + + unsigned int result = mTenantNumber[inV]; + do { + result++; + if (result >= 1000) + result = 1; + } while (FindNumberredTenant(inV, result)); + + mTenantNumber[inV] = result; + return result; } -void T2FloorInfo::SetTenantNumber(int, unsigned int) { +void T2FloorInfo::SetTenantNumber(int inV, unsigned int inTenantNumber) { +#line 1387 + _ASSERT((inV >= 0) && (inV < mVRange)); + + mTenantNumber[inV] = inTenantNumber; } -T2Tenant* T2FloorInfo::FindNumberredTenant(int, unsigned int) { +T2Tenant* T2FloorInfo::FindNumberredTenant(int inV, unsigned int inTenantNumber) { +#line 1399 + _ASSERT((inV >= 0) && (inV < mVRange)); + + POINT pt; + SetPt(&pt, mBuildArea.left, inV); + + T2FInfoPtIterator iterator(*this, pt); + T2Tenant *theTenant = NULL; + + while (iterator.RightTenant(theTenant)) { + if (theTenant->GetTenantNumber() == inTenantNumber) + break; + + theTenant = NULL; + } + + return theTenant; } -void T2FloorInfo::FinishBuildFloor(T2TowerDoc*, const RECT&) { +void T2FloorInfo::FinishBuildFloor(T2TowerDoc* inDoc, const RECT& inRect) { + T2FInfoAreaIterator iterator(*this, inRect); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) { + if (!theTenant->IsBuildFinish()) + theTenant->Idle(inDoc); + } } -void T2FloorInfo::SetTenantDrawModeByRect(const RECT&, int) { +void T2FloorInfo::SetTenantDrawModeByRect(const RECT& inRect, int inDrawMode) { + RECT rect = inRect; + int actualMode; + + switch (inDrawMode) { + case DrawMode1: + { + RECT rect2 = inRect; + rect2.bottom = rect2.top + 1; + + T2FInfoAreaIterator iterator(*this, rect2); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) + theTenant->SetDrawMode(inDrawMode); + + rect.top++; + actualMode = DrawMode2; + break; + } + case DrawMode3: + actualMode = DrawMode1; + break; + case DrawMode2: + actualMode = inDrawMode; + break; + } + + T2FInfoAreaIterator iterator(*this, rect); + T2Tenant *theTenant; + + while (iterator.NextTenant(theTenant)) + theTenant->SetDrawMode(actualMode); } -void T2FloorInfo::UpdateFloorCEArray(const RECT&, unsigned int, unsigned int) { +void T2FloorInfo::UpdateFloorCEArray(const RECT& inRect, unsigned int inOldID, unsigned int inNewID) { + POINT pt; + + pt.x = inRect.left; + for (pt.y = inRect.top; pt.y < inRect.bottom; pt.y++) { + T2Tenant *theFloor = GetFloor(pt.y, pt.x); + if (theFloor) + theFloor->ReplaceCEID(inOldID, inNewID); + } } -int T2FloorInfo::CalcMentenanceCost(T2TowerDoc*) const { +int T2FloorInfo::CalcMentenanceCost(T2TowerDoc* inDoc) const { + int cost = 0; + +#line 1502 + _ASSERT(mTenantArrayList != NULL); + cost += mTenantArrayList->CalcMentenanceCost(inDoc); + _ASSERT(mMoverArrayList != NULL); + cost += mMoverArrayList->CalcMentenanceCost(inDoc); + + cost += mOutObjArrayList->CalcMentenanceCost(inDoc); + + return cost; } -T2Tenant* T2FloorInfo::GetTenantByPID(unsigned long) { +T2Tenant* T2FloorInfo::GetTenantByPID(DWORD inPluginID) { + T2Tenant *result = NULL; + + if (mTenantArrayList) + result = mTenantArrayList->GetTenantByPID(inPluginID); + + return result; } -int T2FloorInfo::BuildFinishForce(const RECT&) { +BOOL T2FloorInfo::BuildFinishForce(const RECT& inRect) { + BOOL result = false; + POINT pt; + + for (pt.y = inRect.top; pt.y < inRect.bottom; pt.y++) { + for (pt.x = inRect.left; pt.x < inRect.right; pt.x++) { + T2Tenant *theTenant = GetTenant(pt.y, pt.x); + if (theTenant && theTenant->GetStatus() < kTenantStatus10) { + theTenant->SetStatus(kTenantStatus9); + theTenant->Idle(GetCurrentT2TowerDoc()); + GetCurrentT2TowerDoc()->mTowerMainView->tmv_vf128(theTenant->mArea); + result = true; + } + } + } + + return result; } |