summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2FInfoPtIterator.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-07-01 02:43:29 +0100
committerAsh Wolf <ninji@wuffs.org>2023-07-01 02:43:29 +0100
commit5c6a48b2ff362a70416a6a00fda7d06e0f276f2d (patch)
tree62cf542c68d91aa6f7a4e3bfa9eddca4ab352970 /src/T2DLL/T2FInfoPtIterator.cpp
parentc0c336500955a23e344651e5412c9d9d441ef4ee (diff)
downloadt2win-5c6a48b2ff362a70416a6a00fda7d06e0f276f2d.tar.gz
t2win-5c6a48b2ff362a70416a6a00fda7d06e0f276f2d.zip
i am in hell
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2FInfoPtIterator.cpp147
1 files changed, 147 insertions, 0 deletions
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;
+}