From 5c6a48b2ff362a70416a6a00fda7d06e0f276f2d Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Sat, 1 Jul 2023 02:43:29 +0100 Subject: i am in hell --- src/T2DLL/T2FInfoPtIterator.cpp | 147 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/T2DLL/T2FInfoPtIterator.cpp (limited to 'src/T2DLL/T2FInfoPtIterator.cpp') diff --git a/src/T2DLL/T2FInfoPtIterator.cpp b/src/T2DLL/T2FInfoPtIterator.cpp new file mode 100644 index 0000000..f3f2872 --- /dev/null +++ b/src/T2DLL/T2FInfoPtIterator.cpp @@ -0,0 +1,147 @@ +#include "GlobalFunc.h" +#include "T2FInfoPtIterator.h" +#include "T2FloorInfo.h" +#include "T2MoverArrayList.h" +#include "T2RequestArrayList.h" +#include "T2TenantArrayList.h" +#include "T2UnitInfo.h" + +T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo& inFloorInfo, POINT inPt) + : mFloorInfo(inFloorInfo) + , mLeftBound(mFloorInfo.mBuildArea.left) + , mRightBound(mFloorInfo.mBuildArea.right - 1) +{ + if (PtInRect(&mFloorInfo.mBuildArea, inPt)) { + mCurrH = inPt.x; + mCurrUnitInfo = mFloorInfo.GetUnitInfo(inPt.y, mCurrH); + mLastIDSeen = 0; + } else { + mCurrH = -2; + } +} + +/*virtual*/ T2FInfoPtIterator::~T2FInfoPtIterator() { +} + +BOOL T2FInfoPtIterator::CurrentH(int& outH) const { + BOOL result = true; + + if (IsValidPosition()) + outH = mCurrH; + else + result = false; + + return result; +} + +BOOL T2FInfoPtIterator::CalcRightUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + if (mCurrH < mRightBound) { + mCurrH++; + mCurrUnitInfo++; + } else { + mCurrH = -2; + result = false; + } + } else { + mCurrH = mLeftBound; + } + } else { + result = false; + } + + return result; +} + +BOOL T2FInfoPtIterator::CalcLeftUnitInfo() { + BOOL result = true; + + if (mCurrH != -2) { + if (mCurrH != -1) { + if (mCurrH > mLeftBound) { + mCurrH--; + mCurrUnitInfo--; + } else { + result = false; + } + } else { + mCurrH = mRightBound; + } + } else { + result = false; + } + + return result; +} + +BOOL T2FInfoPtIterator::Current(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (IsValidPosition()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; +} + +BOOL T2FInfoPtIterator::Right(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcRightUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; +} + +BOOL T2FInfoPtIterator::Left(T2UnitInfo*& outUnitInfo) { + BOOL result = true; + + if (CalcLeftUnitInfo()) + outUnitInfo = mCurrUnitInfo; + else + result = false; + + return result; +} + +BOOL T2FInfoPtIterator::RightTenant(T2Tenant*& outTenant) { + BOOL found; + T2UnitInfo *unitInfo; + + for (found = Right(unitInfo); found; found = Right(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return found; +} + +BOOL T2FInfoPtIterator::LeftTenant(T2Tenant*& outTenant) { + BOOL found; + T2UnitInfo *unitInfo; + + for (found = Left(unitInfo); found; found = Left(unitInfo)) { + unsigned int tenantID = unitInfo->GetTenantID(); + if (tenantID != mLastIDSeen) { + mLastIDSeen = tenantID; + if (tenantID != 0) { + outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); + break; + } + } + } + + return found; +} -- cgit v1.2.3