#include "StdAfx.h" #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* 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* 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* 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* inMover, BOOL inFlag) { for (int n = 0; n < kMaxRouteType; n++) { if (mRoutingTables[n]) mRoutingTables[n]->MoverAdded(inMover, inFlag); } } 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* 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(); } } 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; } BOOL T2RouteNavigator::IsConnectRouteFromLobby(POINT inPt) const { BOOL result = false; if (mRoutingTables[kRouteType0]) result = mRoutingTables[kRouteType0]->IsConnectRouteFromLobby(inPt); return result; } 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 inPt, unsigned int inSearchScore) const { T2Tenant *result = NULL; if (mRoutingTables[kRouteType0]) result = mRoutingTables[kRouteType0]->SelectNearTenant(inPt, inSearchScore); return result; } 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; }