summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2RouteNavigator.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
commitc0c336500955a23e344651e5412c9d9d441ef4ee (patch)
tree790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2RouteNavigator.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2RouteNavigator.cpp185
1 files changed, 174 insertions, 11 deletions
diff --git a/src/T2DLL/T2RouteNavigator.cpp b/src/T2DLL/T2RouteNavigator.cpp
index 8d2e5a9..d07acb8 100644
--- a/src/T2DLL/T2RouteNavigator.cpp
+++ b/src/T2DLL/T2RouteNavigator.cpp
@@ -1,40 +1,203 @@
+#include "T2FloorInfo.h"
+#include "T2FloorPtrList.h"
+#include "T2Mover.h"
+#include "T2MoverArray.h"
+#include "T2MoverArrayList.h"
#include "T2RouteNavigator.h"
+#include "T2RoutingTable.h"
+#include "T2Tenant.h"
+#include "URect.h"
-T2RouteNavigator::T2RouteNavigator(T2FloorInfo*) {
+T2RouteNavigator::T2RouteNavigator(T2FloorInfo* inFloorInfo) {
+ mFloorPtrList = NULL;
+
+ for (unsigned int index = 0; index < kMaxRouteType; index++)
+ mRoutingTables[index] = NULL;
+
+ mFloorPtrList = new T2FloorPtrList(inFloorInfo->GetTenantArrayList());
+ mFloorInfo = inFloorInfo;
+
+ for (int n = 0; n < kMaxRouteType; n++)
+ mRoutingTables[n] = new T2RoutingTable(inFloorInfo, mFloorPtrList, n);
+
+ LArrayIterator iterator(*inFloorInfo->GetMoverArrayList());
+ T2MoverArray *theMoverArray;
+
+ while (iterator.Next(&theMoverArray)) {
+ for (int i = 0; i < T2MoverArray::kGroupSize; i++) {
+ T2Mover *theMover = theMoverArray->GetIndexMover(i);
+ if (theMover->IsUsed())
+ MoverAdded(theMover, false);
+ }
+ }
+
+ Update();
}
/*virtual*/ T2RouteNavigator::~T2RouteNavigator() {
+ if (mFloorPtrList)
+ delete mFloorPtrList;
+
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ delete mRoutingTables[n];
+ }
}
-void T2RouteNavigator::FloorAdded(T2Tenant*, int) {
+void T2RouteNavigator::FloorAdded(T2Tenant* inTenant, BOOL inFlag) {
+ mFloorPtrList->AddItem(inTenant);
+
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ mRoutingTables[n]->FloorAdded();
+ }
+
+ if (inFlag)
+ Update();
}
-void T2RouteNavigator::FloorRemoved(T2Tenant*, int) {
+void T2RouteNavigator::FloorRemoved(T2Tenant* inTenant, BOOL inFlag) {
+ int index = mFloorPtrList->GetIndex(inTenant);
+ mFloorPtrList->RemoveItem(index);
+
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ mRoutingTables[n]->FloorRemoved(index);
+ }
+
+ if (inFlag)
+ Update();
}
-void T2RouteNavigator::MoverAdded(T2Mover*, int) {
+void T2RouteNavigator::MoverAdded(T2Mover* inMover, BOOL inFlag) {
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ mRoutingTables[n]->MoverAdded(inMover, inFlag);
+ }
}
-void T2RouteNavigator::MoverRemoved(T2Mover*, int) {
+void T2RouteNavigator::MoverRemoved(T2Mover* inMover, BOOL inFlag) {
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ mRoutingTables[n]->MoverRemoved(inMover, inFlag);
+ }
}
-void T2RouteNavigator::MoverModified(T2Mover*, int) {
+void T2RouteNavigator::MoverModified(T2Mover* inMover, BOOL inFlag) {
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ mRoutingTables[n]->MoverModified(inMover, inFlag);
+ }
}
void T2RouteNavigator::Update() {
+ for (int n = 0; n < kMaxRouteType; n++) {
+ if (mRoutingTables[n])
+ mRoutingTables[n]->FullUpdate();
+ }
}
-int T2RouteNavigator::CheckRoute(POINT, POINT, unsigned int, int) const {
+BOOL T2RouteNavigator::CheckRoute(POINT inFromPt, POINT inToPt, unsigned int inSearchScore, int inRouteType) const {
+ BOOL result = false;
+
+ if ((inRouteType >= 0) && (inRouteType <= kMaxRouteType) && mRoutingTables[inRouteType])
+ result = mRoutingTables[inRouteType]->CheckRoute(inFromPt, inToPt, inSearchScore);
+
+ return result;
}
-int T2RouteNavigator::IsConnectRouteFromLobby(POINT) const {
+BOOL T2RouteNavigator::IsConnectRouteFromLobby(POINT inPt) const {
+ BOOL result = false;
+
+ if (mRoutingTables[kRouteType0])
+ result = mRoutingTables[kRouteType0]->IsConnectRouteFromLobby(inPt);
+
+ return result;
}
-int T2RouteNavigator::GetNextRoute(POINT, POINT&, int) const {
+BOOL T2RouteNavigator::GetNextRoute(POINT inFromPt, POINT& ioToPt, int inRouteType) const {
+ BOOL result = false;
+
+ if (inRouteType >= 0 && inRouteType <= kMaxRouteType) {
+ if (mRoutingTables[inRouteType])
+ result = mRoutingTables[inRouteType]->GetNextRoute(inFromPt, ioToPt);
+ } else if (inRouteType == kRouteTypeNeg1) {
+ result = GetNextRouteUsingEStair(inFromPt, ioToPt);
+ }
+
+ return result;
}
-T2Tenant* T2RouteNavigator::SelectNearTenant(POINT, unsigned int) const {
+T2Tenant* T2RouteNavigator::SelectNearTenant(POINT inPt, unsigned int inSearchScore) const {
+ T2Tenant *result = NULL;
+
+ if (mRoutingTables[kRouteType0])
+ result = mRoutingTables[kRouteType0]->SelectNearTenant(inPt, inSearchScore);
+
+ return result;
}
-int T2RouteNavigator::GetNextRouteUsingEStair(POINT, POINT&) const {
+BOOL T2RouteNavigator::GetNextRouteUsingEStair(POINT inFromPt, POINT& ioToPt) const {
+ BOOL foundRoute = false;
+
+ T2Tenant *fromFloor = mFloorInfo->GetFloor(inFromPt.y, inFromPt.x);
+ T2Tenant *toFloor = mFloorInfo->GetFloor(ioToPt.y, ioToPt.x);
+
+ if (fromFloor && toFloor) {
+ RECT fromEquipArea, toEquipArea;
+ fromFloor->GetEquipArea(fromEquipArea);
+ toFloor->GetEquipArea(toEquipArea);
+
+ RECT searchRect = toEquipArea;
+ OffsetRect(&searchRect, 0, fromEquipArea.top - toEquipArea.top);
+
+ if (IntersectRect(&searchRect, &searchRect, &fromEquipArea)) {
+ ioToPt.x = searchRect.left;
+ if (fromEquipArea.top > toEquipArea.top)
+ ioToPt.y = inFromPt.y - URect::Height(fromEquipArea);
+ else
+ ioToPt.y = inFromPt.y + 1;
+
+ T2Tenant *floor = mFloorInfo->GetFloor(ioToPt.y, ioToPt.x);
+ if (floor) {
+ RECT floorArea;
+ floor->GetEquipArea(floorArea);
+ ioToPt.y = floorArea.bottom - 1;
+
+ int hDistance;
+ int bestScore = 10000;
+
+ if (fromEquipArea.left >= floorArea.left) {
+ hDistance = abs(fromEquipArea.left - inFromPt.x);
+ if (hDistance < bestScore) {
+ bestScore = hDistance;
+ ioToPt.x = searchRect.left;
+ }
+ }
+
+ if (fromEquipArea.right <= floorArea.right) {
+ hDistance = abs(fromEquipArea.right - 2 - inFromPt.x);
+ if (hDistance < bestScore) {
+ bestScore = hDistance;
+ ioToPt.x = fromEquipArea.right - 2;
+ }
+ }
+
+ hDistance = abs(floorArea.left - inFromPt.x);
+ if (hDistance < bestScore) {
+ bestScore = hDistance;
+ ioToPt.x = floorArea.left;
+ }
+
+ hDistance = abs(floorArea.right - 2 - inFromPt.x);
+ if (hDistance < bestScore) {
+ ioToPt.x = floorArea.right - 2;
+ }
+
+ foundRoute = true;
+ }
+ }
+ }
+
+ return foundRoute;
}