2019-05-15 14:52:37 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
#include "General.h"
|
|
|
|
#include "FileMgr.h" // only needed for empty function
|
|
|
|
#include "Camera.h"
|
|
|
|
#include "Vehicle.h"
|
|
|
|
#include "World.h"
|
2020-04-10 16:36:39 +00:00
|
|
|
#include "Lines.h" // for debug
|
2019-05-15 14:52:37 +00:00
|
|
|
#include "PathFind.h"
|
|
|
|
|
2020-04-10 16:36:39 +00:00
|
|
|
bool gbShowPedPaths;
|
|
|
|
bool gbShowCarPaths;
|
|
|
|
bool gbShowCarPathsLinks;
|
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
CPathFind ThePaths;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-03-25 14:13:06 +00:00
|
|
|
#define MAX_DIST INT16_MAX-1
|
2020-04-14 18:32:15 +00:00
|
|
|
#define MIN_PED_ROUTE_DISTANCE 23.8f
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
|
|
|
|
#ifdef MIAMI
|
|
|
|
#define NUMTEMPNODES 5000
|
|
|
|
#define NUMDETACHED_CARS 1024
|
|
|
|
#define NUMDETACHED_PEDS 1214
|
|
|
|
#define NUMTEMPEXTERNALNODES 4600
|
|
|
|
#else
|
|
|
|
#define NUMTEMPNODES 4000
|
|
|
|
#define NUMDETACHED_CARS 100
|
|
|
|
#define NUMDETACHED_PEDS 50
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
// object flags:
|
2020-03-25 14:13:06 +00:00
|
|
|
// 1 UseInRoadBlock
|
2019-05-15 14:52:37 +00:00
|
|
|
// 2 east/west road(?)
|
|
|
|
|
2020-04-17 05:54:14 +00:00
|
|
|
CPathInfoForObject *InfoForTileCars;
|
|
|
|
CPathInfoForObject *InfoForTilePeds;
|
2020-05-03 13:57:57 +00:00
|
|
|
|
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
// unused
|
2020-04-17 05:54:14 +00:00
|
|
|
CTempDetachedNode *DetachedNodesCars;
|
|
|
|
CTempDetachedNode *DetachedNodesPeds;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
CPathInfoForObject *DetachedInfoForTileCars;
|
|
|
|
CPathInfoForObject *DetachedInfoForTilePeds;
|
|
|
|
CTempNodeExternal *TempExternalNodes;
|
|
|
|
int32 NumTempExternalNodes;
|
|
|
|
int32 NumDetachedPedNodeGroups;
|
|
|
|
int32 NumDetachedCarNodeGroups;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-04-14 10:45:47 +00:00
|
|
|
bool
|
|
|
|
CPedPath::CalcPedRoute(int8 pathType, CVector position, CVector destination, CVector *pointPoses, int16 *pointsFound, int16 maxPoints)
|
|
|
|
{
|
|
|
|
*pointsFound = 0;
|
|
|
|
CVector vecDistance = destination - position;
|
2020-04-14 18:32:15 +00:00
|
|
|
if (Abs(vecDistance.x) > MIN_PED_ROUTE_DISTANCE || Abs(vecDistance.y) > MIN_PED_ROUTE_DISTANCE || Abs(vecDistance.z) > MIN_PED_ROUTE_DISTANCE)
|
2020-04-14 10:45:47 +00:00
|
|
|
return false;
|
|
|
|
CVector vecPos = (position + destination) * 0.5f;
|
|
|
|
CVector vecSectorStartPos (vecPos.x - 14.0f, vecPos.y - 14.0f, vecPos.z);
|
|
|
|
CVector2D vecSectorEndPos (vecPos.x + 28.0f, vecPos.x + 28.0f);
|
2020-04-14 11:57:28 +00:00
|
|
|
const int16 nodeStartX = (position.x - vecSectorStartPos.x) / 0.7f;
|
|
|
|
const int16 nodeStartY = (position.y - vecSectorStartPos.y) / 0.7f;
|
|
|
|
const int16 nodeEndX = (destination.x - vecSectorStartPos.x) / 0.7f;
|
|
|
|
const int16 nodeEndY = (destination.y - vecSectorStartPos.y) / 0.7f;
|
2020-04-14 10:45:47 +00:00
|
|
|
if (nodeStartX == nodeEndX && nodeStartY == nodeEndY)
|
|
|
|
return false;
|
|
|
|
CPedPathNode pathNodes[40][40];
|
|
|
|
CPedPathNode pathNodesList[416];
|
|
|
|
for (int32 x = 0; x < 40; x++) {
|
|
|
|
for (int32 y = 0; y < 40; y++) {
|
|
|
|
pathNodes[x][y].bBlockade = false;
|
2020-04-14 18:32:15 +00:00
|
|
|
pathNodes[x][y].id = INT16_MAX;
|
2020-04-14 10:45:47 +00:00
|
|
|
pathNodes[x][y].nodeIdX = x;
|
|
|
|
pathNodes[x][y].nodeIdY = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CWorld::AdvanceCurrentScanCode();
|
|
|
|
if (pathType != ROUTE_NO_BLOCKADE) {
|
2020-04-19 16:34:08 +00:00
|
|
|
const int32 nStartX = Max(CWorld::GetSectorIndexX(vecSectorStartPos.x), 0);
|
|
|
|
const int32 nStartY = Max(CWorld::GetSectorIndexY(vecSectorStartPos.y), 0);
|
|
|
|
const int32 nEndX = Min(CWorld::GetSectorIndexX(vecSectorEndPos.x), NUMSECTORS_X - 1);
|
|
|
|
const int32 nEndY = Min(CWorld::GetSectorIndexY(vecSectorEndPos.y), NUMSECTORS_Y - 1);
|
2020-04-14 10:45:47 +00:00
|
|
|
for (int32 y = nStartY; y <= nEndY; y++) {
|
|
|
|
for (int32 x = nStartX; x <= nEndX; x++) {
|
|
|
|
CSector *pSector = CWorld::GetSector(x, y);
|
|
|
|
AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_VEHICLES], pathNodes, &vecSectorStartPos);
|
|
|
|
AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_VEHICLES_OVERLAP], pathNodes, &vecSectorStartPos);
|
|
|
|
AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_OBJECTS], pathNodes, &vecSectorStartPos);
|
|
|
|
AddBlockadeSectorList(pSector->m_lists[ENTITYLIST_OBJECTS_OVERLAP], pathNodes, &vecSectorStartPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int32 i = 0; i < 416; i++) {
|
|
|
|
pathNodesList[i].prev = nil;
|
|
|
|
pathNodesList[i].next = nil;
|
|
|
|
}
|
|
|
|
CPedPathNode *pStartPathNode = &pathNodes[nodeStartX][nodeStartY];
|
|
|
|
CPedPathNode *pEndPathNode = &pathNodes[nodeEndX][nodeEndY];
|
|
|
|
pEndPathNode->bBlockade = false;
|
|
|
|
pEndPathNode->id = 0;
|
|
|
|
pEndPathNode->prev = nil;
|
|
|
|
pEndPathNode->next = pathNodesList;
|
|
|
|
pathNodesList[0].prev = pEndPathNode;
|
|
|
|
int32 pathNodeIndex = 0;
|
|
|
|
CPedPathNode *pPreviousNode = nil;
|
|
|
|
for (; pathNodeIndex < 414; pathNodeIndex++)
|
|
|
|
{
|
|
|
|
pPreviousNode = pathNodesList[pathNodeIndex].prev;
|
|
|
|
while (pPreviousNode && pPreviousNode != pStartPathNode) {
|
|
|
|
const uint8 nodeIdX = pPreviousNode->nodeIdX;
|
|
|
|
const uint8 nodeIdY = pPreviousNode->nodeIdY;
|
|
|
|
if (nodeIdX > 0) {
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX - 1][nodeIdY], pathNodeIndex + 5, pathNodesList);
|
|
|
|
if (nodeIdY > 0)
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX - 1][nodeIdY - 1], pathNodeIndex + 7, pathNodesList);
|
|
|
|
if (nodeIdY < 39)
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX - 1][nodeIdY + 1], pathNodeIndex + 7, pathNodesList);
|
|
|
|
}
|
|
|
|
if (nodeIdX < 39) {
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX + 1][nodeIdY], pathNodeIndex + 5, pathNodesList);
|
|
|
|
if (nodeIdY > 0)
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX + 1][nodeIdY - 1], pathNodeIndex + 7, pathNodesList);
|
|
|
|
if (nodeIdY < 39)
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX + 1][nodeIdY + 1], pathNodeIndex + 7, pathNodesList);
|
|
|
|
}
|
|
|
|
if (nodeIdY > 0)
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX][nodeIdY - 1], pathNodeIndex + 5, pathNodesList);
|
|
|
|
if (nodeIdY < 39)
|
|
|
|
AddNodeToPathList(&pathNodes[nodeIdX][nodeIdY + 1], pathNodeIndex + 5, pathNodesList);
|
|
|
|
pPreviousNode = pPreviousNode->prev;
|
|
|
|
if (!pPreviousNode)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pPreviousNode && pPreviousNode == pStartPathNode)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pathNodeIndex == 414)
|
|
|
|
return false;
|
|
|
|
CPedPathNode *pPathNode = pStartPathNode;
|
|
|
|
for (*pointsFound = 0; pPathNode != pEndPathNode && *pointsFound < maxPoints; ++ *pointsFound) {
|
|
|
|
const uint8 nodeIdX = pPathNode->nodeIdX;
|
|
|
|
const uint8 nodeIdY = pPathNode->nodeIdY;
|
2020-04-14 11:57:28 +00:00
|
|
|
if (nodeIdX > 0 && pathNodes[nodeIdX - 1][nodeIdY].id + 5 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX - 1][nodeIdY];
|
|
|
|
else if (nodeIdX > 39 && pathNodes[nodeIdX + 1][nodeIdY].id + 5 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX + 1][nodeIdY];
|
|
|
|
else if (nodeIdY > 0 && pathNodes[nodeIdX][nodeIdY - 1].id + 5 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX][nodeIdY - 1];
|
|
|
|
else if (nodeIdY > 39 && pathNodes[nodeIdX][nodeIdY + 1].id + 5 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX][nodeIdY + 1];
|
|
|
|
else if (nodeIdX > 0 && nodeIdY > 0 && pathNodes[nodeIdX - 1][nodeIdY - 1].id + 7 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX - 1][nodeIdY - 1];
|
|
|
|
else if (nodeIdX > 0 && nodeIdY < 39 && pathNodes[nodeIdX - 1][nodeIdY + 1].id + 7 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX - 1][nodeIdY + 1];
|
|
|
|
else if (nodeIdX < 39 && nodeIdY > 0 && pathNodes[nodeIdX + 1][nodeIdY - 1].id + 7 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX + 1][nodeIdY - 1];
|
|
|
|
else if (nodeIdX < 39 && nodeIdY < 39 && pathNodes[nodeIdX + 1][nodeIdY + 1].id + 7 == pPathNode->id)
|
|
|
|
pPathNode = &pathNodes[nodeIdX + 1][nodeIdY + 1];
|
2020-04-14 10:45:47 +00:00
|
|
|
pointPoses[*pointsFound] = vecSectorStartPos;
|
2020-04-14 12:05:51 +00:00
|
|
|
pointPoses[*pointsFound].x += pPathNode->nodeIdX * 0.7f;
|
|
|
|
pointPoses[*pointsFound].y += pPathNode->nodeIdY * 0.7f;
|
2020-04-14 10:45:47 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedPath::AddNodeToPathList(CPedPathNode *pNodeToAdd, int16 id, CPedPathNode *pNodeList)
|
|
|
|
{
|
|
|
|
if (!pNodeToAdd->bBlockade && id < pNodeToAdd->id) {
|
2020-04-14 18:32:15 +00:00
|
|
|
if (pNodeToAdd->id != INT16_MAX)
|
2020-04-14 10:45:47 +00:00
|
|
|
RemoveNodeFromList(pNodeToAdd);
|
|
|
|
AddNodeToList(pNodeToAdd, id, pNodeList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedPath::RemoveNodeFromList(CPedPathNode *pNode)
|
|
|
|
{
|
|
|
|
pNode->next->prev = pNode->prev;
|
|
|
|
if (pNode->prev)
|
|
|
|
pNode->prev->next = pNode->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedPath::AddNodeToList(CPedPathNode *pNode, int16 index, CPedPathNode *pList)
|
|
|
|
{
|
|
|
|
pNode->prev = pList[index].prev;
|
|
|
|
pNode->next = &pList[index];
|
|
|
|
if (pList[index].prev)
|
|
|
|
pList[index].prev->next = pNode;
|
|
|
|
pList[index].prev = pNode;
|
|
|
|
pNode->id = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedPath::AddBlockadeSectorList(CPtrList& list, CPedPathNode(*pathNodes)[40], CVector *pPosition)
|
|
|
|
{
|
|
|
|
CPtrNode* listNode = list.first;
|
|
|
|
while (listNode) {
|
|
|
|
CEntity* pEntity = (CEntity*)listNode->item;
|
|
|
|
if (pEntity->m_scanCode != CWorld::GetCurrentScanCode() && pEntity->bUsesCollision) {
|
|
|
|
pEntity->m_scanCode = CWorld::GetCurrentScanCode();
|
|
|
|
AddBlockade(pEntity, pathNodes, pPosition);
|
|
|
|
}
|
|
|
|
listNode = listNode->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPedPath::AddBlockade(CEntity *pEntity, CPedPathNode(*pathNodes)[40], CVector *pPosition)
|
|
|
|
{
|
|
|
|
const CColBox& boundingBox = pEntity->GetColModel()->boundingBox;
|
|
|
|
const float fBoundMaxY = boundingBox.max.y + 0.3f;
|
|
|
|
const float fBoundMinY = boundingBox.min.y - 0.3f;
|
|
|
|
const float fBoundMaxX = boundingBox.max.x + 0.3f;
|
|
|
|
const float fDistanceX = pPosition->x - pEntity->m_matrix.GetPosition().x;
|
|
|
|
const float fDistanceY = pPosition->y - pEntity->m_matrix.GetPosition().y;
|
|
|
|
const float fBoundRadius = pEntity->GetBoundRadius();
|
|
|
|
CVector vecBoundCentre;
|
|
|
|
pEntity->GetBoundCentre(vecBoundCentre);
|
|
|
|
if (vecBoundCentre.x + fBoundRadius >= pPosition->x &&
|
|
|
|
vecBoundCentre.y + fBoundRadius >= pPosition->y &&
|
|
|
|
vecBoundCentre.x - fBoundRadius <= pPosition->x + 28.0f &&
|
|
|
|
vecBoundCentre.y - fBoundRadius <= pPosition->y + 28.0f) {
|
|
|
|
for (int16 x = 0; x < 40; x++) {
|
2020-04-14 12:05:51 +00:00
|
|
|
const float pointX = x * 0.7f + fDistanceX;
|
2020-04-14 10:45:47 +00:00
|
|
|
for (int16 y = 0; y < 40; y++) {
|
|
|
|
if (!pathNodes[x][y].bBlockade) {
|
2020-04-14 12:05:51 +00:00
|
|
|
const float pointY = y * 0.7f + fDistanceY;
|
2020-04-14 10:45:47 +00:00
|
|
|
CVector2D point(pointX, pointY);
|
|
|
|
if (fBoundMaxX > Abs(DotProduct2D(point, pEntity->m_matrix.GetRight()))) {
|
|
|
|
float fDotProduct = DotProduct2D(point, pEntity->m_matrix.GetForward());
|
|
|
|
if (fBoundMaxY > fDotProduct && fBoundMinY < fDotProduct)
|
|
|
|
pathNodes[x][y].bBlockade = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
// Make sure all externals link TO an internal
|
|
|
|
void
|
|
|
|
CPathInfoForObject::SwapConnectionsToBeRightWayRound(void)
|
|
|
|
{
|
|
|
|
int e, i;
|
|
|
|
CPathInfoForObject *tile = this;
|
|
|
|
|
|
|
|
for(e = 0; e < 12; e++)
|
|
|
|
if(tile[e].type == NodeTypeExtern && tile[e].next < 0)
|
|
|
|
for(i = 0; i < 12; i++)
|
|
|
|
if(tile[i].type == NodeTypeIntern && tile[i].next == e){
|
|
|
|
tile[e].next = i;
|
|
|
|
tile[i].next = -1;
|
|
|
|
bool tmp = !!tile[e].crossing;
|
|
|
|
tile[e].crossing = tile[i].crossing;
|
|
|
|
tile[i].crossing = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//--MIAMI: done
|
2019-06-17 08:30:02 +00:00
|
|
|
void
|
2019-08-09 17:42:18 +00:00
|
|
|
CPathFind::Init(void)
|
2019-06-17 08:30:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
m_numPathNodes = 0;
|
|
|
|
m_numMapObjects = 0;
|
|
|
|
m_numConnections = 0;
|
|
|
|
m_numCarPathLinks = 0;
|
|
|
|
unk = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
NumTempExternalNodes = 0;
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
|
|
|
for(i = 0; i < NUM_PATHNODES; i++)
|
|
|
|
m_pathNodes[i].distance = MAX_DIST;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::AllocatePathFindInfoMem(int16 numPathGroups)
|
|
|
|
{
|
|
|
|
delete[] InfoForTileCars;
|
|
|
|
InfoForTileCars = nil;
|
|
|
|
delete[] InfoForTilePeds;
|
|
|
|
InfoForTilePeds = nil;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
// NB: MIAMI doesn't use numPathGroups here but hardcodes 4500
|
2019-08-09 17:42:18 +00:00
|
|
|
InfoForTileCars = new CPathInfoForObject[12*numPathGroups];
|
|
|
|
memset(InfoForTileCars, 0, 12*numPathGroups*sizeof(CPathInfoForObject));
|
|
|
|
InfoForTilePeds = new CPathInfoForObject[12*numPathGroups];
|
|
|
|
memset(InfoForTilePeds, 0, 12*numPathGroups*sizeof(CPathInfoForObject));
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
// unused
|
|
|
|
delete[] DetachedNodesCars;
|
|
|
|
DetachedNodesCars = nil;
|
|
|
|
delete[] DetachedNodesPeds;
|
|
|
|
DetachedNodesPeds = nil;
|
2020-05-03 13:57:57 +00:00
|
|
|
DetachedNodesCars = new CTempDetachedNode[NUMDETACHED_CARS];
|
|
|
|
memset(DetachedNodesCars, 0, NUMDETACHED_CARS*sizeof(CTempDetachedNode));
|
|
|
|
DetachedNodesPeds = new CTempDetachedNode[NUMDETACHED_PEDS];
|
|
|
|
memset(DetachedNodesPeds, 0, NUMDETACHED_PEDS*sizeof(CTempDetachedNode));
|
|
|
|
#else
|
|
|
|
delete[] DetachedInfoForTileCars;
|
|
|
|
DetachedInfoForTileCars = nil;
|
|
|
|
delete[] DetachedInfoForTilePeds;
|
|
|
|
DetachedInfoForTilePeds = nil;
|
|
|
|
DetachedInfoForTileCars = new CPathInfoForObject[12*NUMDETACHED_CARS];
|
|
|
|
memset(DetachedInfoForTileCars, 0, 12*NUMDETACHED_CARS*sizeof(CPathInfoForObject));
|
|
|
|
DetachedInfoForTilePeds = new CPathInfoForObject[12*NUMDETACHED_PEDS];
|
|
|
|
memset(DetachedInfoForTilePeds, 0, 12*NUMDETACHED_PEDS*sizeof(CPathInfoForObject));
|
|
|
|
|
|
|
|
TempExternalNodes = new CTempNodeExternal[NUMTEMPEXTERNALNODES];
|
|
|
|
memset(TempExternalNodes, 0, NUMTEMPEXTERNALNODES*sizeof(CTempNodeExternal));
|
|
|
|
NumTempExternalNodes = 0;
|
|
|
|
NumDetachedPedNodeGroups = 0;
|
|
|
|
NumDetachedCarNodeGroups = 0;
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::RegisterMapObject(CTreadable *mapObject)
|
|
|
|
{
|
|
|
|
m_mapObjects[m_numMapObjects++] = mapObject;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: TODO: implement all the arguments once we can load the VC map
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::StoreNodeInfoPed(int16 id, int16 node, int8 type, int8 next, int16 x, int16 y, int16 z, int16 width, bool crossing)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2019-06-17 08:30:02 +00:00
|
|
|
i = id*12 + node;
|
|
|
|
InfoForTilePeds[i].type = type;
|
|
|
|
InfoForTilePeds[i].next = next;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-06-17 08:30:02 +00:00
|
|
|
InfoForTilePeds[i].x = x;
|
|
|
|
InfoForTilePeds[i].y = y;
|
|
|
|
InfoForTilePeds[i].z = z;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
InfoForTilePeds[i].x = x/16.0f;
|
|
|
|
InfoForTilePeds[i].y = y/16.0f;
|
|
|
|
InfoForTilePeds[i].z = z/16.0f;
|
|
|
|
#endif
|
2019-06-17 08:30:02 +00:00
|
|
|
InfoForTilePeds[i].numLeftLanes = 0;
|
|
|
|
InfoForTilePeds[i].numRightLanes = 0;
|
|
|
|
InfoForTilePeds[i].crossing = crossing;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
InfoForTilePeds[i].flag02 = false;
|
|
|
|
InfoForTilePeds[i].roadBlock = false;
|
|
|
|
InfoForTilePeds[i].disabled = false;
|
|
|
|
InfoForTilePeds[i].waterPath = false;
|
|
|
|
InfoForTilePeds[i].betweenLevels = false;
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type)
|
|
|
|
for(i = 0; i < node; i++){
|
|
|
|
j = id*12 + i;
|
|
|
|
if(x == InfoForTilePeds[j].x && y == InfoForTilePeds[j].y){
|
|
|
|
printf("^^^^^^^^^^^^^ AARON IS TOO CHICKEN TO EAT MEAT!\n");
|
|
|
|
printf("Several ped nodes on one road segment have identical coordinates (%d==%d && %d==%d)\n",
|
|
|
|
x, InfoForTilePeds[j].x, y, InfoForTilePeds[j].y);
|
|
|
|
printf("Modelindex of cullprit: %d\n\n", id);
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(node == 11)
|
|
|
|
InfoForTilePeds[id*12].SwapConnectionsToBeRightWayRound();
|
|
|
|
#endif
|
2019-06-17 08:30:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: TODO: implement all the arguments once we can load the VC map
|
2019-06-17 08:30:02 +00:00
|
|
|
void
|
|
|
|
CPathFind::StoreNodeInfoCar(int16 id, int16 node, int8 type, int8 next, int16 x, int16 y, int16 z, int16 width, int8 numLeft, int8 numRight)
|
|
|
|
{
|
2019-08-09 17:42:18 +00:00
|
|
|
int i, j;
|
2019-06-17 08:30:02 +00:00
|
|
|
|
|
|
|
i = id*12 + node;
|
|
|
|
InfoForTileCars[i].type = type;
|
|
|
|
InfoForTileCars[i].next = next;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-06-17 08:30:02 +00:00
|
|
|
InfoForTileCars[i].x = x;
|
|
|
|
InfoForTileCars[i].y = y;
|
|
|
|
InfoForTileCars[i].z = z;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
InfoForTileCars[i].x = x/16.0f;
|
|
|
|
InfoForTileCars[i].y = y/16.0f;
|
|
|
|
InfoForTileCars[i].z = z/16.0f;
|
|
|
|
#endif
|
2019-06-17 08:30:02 +00:00
|
|
|
InfoForTileCars[i].numLeftLanes = numLeft;
|
|
|
|
InfoForTileCars[i].numRightLanes = numRight;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
InfoForTileCars[i].crossing = false;
|
|
|
|
InfoForTileCars[i].flag02 = false;
|
|
|
|
InfoForTileCars[i].roadBlock = false;
|
|
|
|
InfoForTileCars[i].disabled = false;
|
|
|
|
InfoForTileCars[i].waterPath = false;
|
|
|
|
InfoForTileCars[i].betweenLevels = false;
|
|
|
|
#endif
|
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type)
|
|
|
|
for(i = 0; i < node; i++){
|
|
|
|
j = id*12 + i;
|
|
|
|
if(x == InfoForTileCars[j].x && y == InfoForTileCars[j].y){
|
|
|
|
printf("^^^^^^^^^^^^^ AARON IS TOO CHICKEN TO EAT MEAT!\n");
|
|
|
|
printf("Several car nodes on one road segment have identical coordinates (%d==%d && %d==%d)\n",
|
|
|
|
x, InfoForTileCars[j].x, y, InfoForTileCars[j].y);
|
|
|
|
printf("Modelindex of cullprit: %d\n\n", id);
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(node == 11)
|
|
|
|
InfoForTileCars[id*12].SwapConnectionsToBeRightWayRound();
|
|
|
|
#endif
|
2019-06-17 08:30:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-06-18 07:50:26 +00:00
|
|
|
void
|
2019-08-09 17:42:18 +00:00
|
|
|
CPathFind::CalcNodeCoors(int16 x, int16 y, int16 z, int id, CVector *out)
|
2019-06-18 07:50:26 +00:00
|
|
|
{
|
2019-08-09 17:42:18 +00:00
|
|
|
CVector pos;
|
|
|
|
pos.x = x / 16.0f;
|
|
|
|
pos.y = y / 16.0f;
|
|
|
|
pos.z = z / 16.0f;
|
|
|
|
*out = m_mapObjects[id]->GetMatrix() * pos;
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
void
|
|
|
|
CPathFind::CalcNodeCoors(float x, float y, float z, int id, CVector *out)
|
|
|
|
{
|
|
|
|
CVector pos;
|
|
|
|
pos.x = x;
|
|
|
|
pos.y = y;
|
|
|
|
pos.z = z;
|
|
|
|
*out = m_mapObjects[id]->GetMatrix() * pos;
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
bool
|
|
|
|
CPathFind::LoadPathFindData(void)
|
|
|
|
{
|
|
|
|
CFileMgr::SetDir("");
|
|
|
|
return false;
|
2019-06-18 07:50:26 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-05-15 14:52:37 +00:00
|
|
|
void
|
|
|
|
CPathFind::PreparePathData(void)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
int numExtern, numIntern, numLanes;
|
|
|
|
float maxX, maxY;
|
|
|
|
CTempNode *tempNodes;
|
|
|
|
|
|
|
|
printf("PreparePathData\n");
|
2019-08-09 17:42:18 +00:00
|
|
|
if(!CPathFind::LoadPathFindData() && // empty
|
|
|
|
InfoForTileCars && InfoForTilePeds &&
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
|
|
|
DetachedNodesCars && DetachedNodesPeds
|
|
|
|
#else
|
|
|
|
DetachedInfoForTileCars && DetachedInfoForTilePeds && TempExternalNodes
|
|
|
|
#endif
|
|
|
|
){
|
|
|
|
tempNodes = new CTempNode[NUMTEMPNODES];
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2019-05-15 20:15:49 +00:00
|
|
|
m_numConnections = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
|
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
for(i = 0; i < PATHNODESIZE; i++)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_pathNodes[i].unkBits = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
for(i = 0; i < PATHNODESIZE; i++){
|
|
|
|
numExtern = 0;
|
|
|
|
numIntern = 0;
|
|
|
|
for(j = 0; j < 12; j++){
|
|
|
|
if(InfoForTileCars[i*12 + j].type == NodeTypeExtern)
|
|
|
|
numExtern++;
|
|
|
|
if(InfoForTileCars[i*12 + j].type == NodeTypeIntern)
|
|
|
|
numIntern++;
|
|
|
|
}
|
|
|
|
if(numIntern > 1 && numExtern != 2)
|
|
|
|
printf("ILLEGAL BLOCK. MORE THAN 1 INTERNALS AND NOT 2 EXTERNALS (Modelindex:%d)\n", i);
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
int numExternDetached, numInternDetached;
|
|
|
|
for(i = 0; i < NUMDETACHED_CARS; i++){
|
|
|
|
numExternDetached = 0;
|
|
|
|
numInternDetached = 0;
|
|
|
|
for(j = 0; j < 12; j++){
|
|
|
|
if(DetachedInfoForTileCars[i*12 + j].type == NodeTypeExtern)
|
|
|
|
numExternDetached++;
|
|
|
|
if(DetachedInfoForTilePeds[i*12 + j].type == NodeTypeIntern)
|
|
|
|
numInternDetached++;
|
|
|
|
}
|
|
|
|
// no diagnostic here
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
for(i = 0; i < PATHNODESIZE; i++)
|
|
|
|
for(j = 0; j < 12; j++)
|
|
|
|
if(InfoForTileCars[i*12 + j].type == NodeTypeExtern){
|
2020-05-03 13:57:57 +00:00
|
|
|
// MIAMI has MI:%d here but no argument for it
|
2019-05-15 14:52:37 +00:00
|
|
|
if(InfoForTileCars[i*12 + j].numLeftLanes < 0)
|
|
|
|
printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i);
|
|
|
|
if(InfoForTileCars[i*12 + j].numRightLanes < 0)
|
|
|
|
printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i);
|
|
|
|
if(InfoForTileCars[i*12 + j].numLeftLanes + InfoForTileCars[i*12 + j].numRightLanes <= 0)
|
|
|
|
printf("ILLEGAL BLOCK. NO LANES IN NODE (Obj:%d)\n", i);
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
for(i = 0; i < NUMDETACHED_CARS; i++)
|
|
|
|
for(j = 0; j < 12; j++)
|
|
|
|
if(DetachedInfoForTilePeds[i*12 + j].type == NodeTypeExtern){
|
|
|
|
// MI:%d here but no argument for it
|
|
|
|
if(DetachedInfoForTilePeds[i*12 + j].numLeftLanes < 0)
|
|
|
|
printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i);
|
|
|
|
if(DetachedInfoForTilePeds[i*12 + j].numRightLanes < 0)
|
|
|
|
printf("ILLEGAL BLOCK. NEGATIVE NUMBER OF LANES (Obj:%d)\n", i);
|
|
|
|
if(DetachedInfoForTilePeds[i*12 + j].numLeftLanes + DetachedInfoForTilePeds[i*12 + j].numRightLanes <= 0)
|
|
|
|
printf("ILLEGAL BLOCK. NO LANES IN NODE (Obj:%d)\n", i);
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
m_numPathNodes = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
|
|
|
PreparePathDataForType(PATH_CAR, tempNodes, InfoForTileCars, 1.0f, DetachedNodesCars, NUMDETACHED_CARS);
|
|
|
|
m_numCarPathNodes = m_numPathNodes;
|
|
|
|
PreparePathDataForType(PATH_PED, tempNodes, InfoForTilePeds, 1.0f, DetachedNodesPeds, NUMDETACHED_PEDS);
|
|
|
|
#else
|
|
|
|
PreparePathDataForType(PATH_CAR, tempNodes, InfoForTileCars, 1.0f, DetachedInfoForTileCars, NumDetachedCarNodeGroups);
|
2019-05-15 14:52:37 +00:00
|
|
|
m_numCarPathNodes = m_numPathNodes;
|
2020-05-03 13:57:57 +00:00
|
|
|
PreparePathDataForType(PATH_PED, tempNodes, InfoForTilePeds, 1.0f, DetachedInfoForTilePeds, NumDetachedPedNodeGroups);
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
m_numPedPathNodes = m_numPathNodes - m_numCarPathNodes;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
// TODO: figure out what exactly is going on here
|
|
|
|
// Some roads seem to get a west/east flag
|
|
|
|
for(i = 0; i < m_numMapObjects; i++){
|
|
|
|
numExtern = 0;
|
|
|
|
numIntern = 0;
|
|
|
|
numLanes = 0;
|
|
|
|
maxX = 0.0f;
|
|
|
|
maxY = 0.0f;
|
|
|
|
for(j = 0; j < 12; j++){
|
|
|
|
k = i*12 + j;
|
|
|
|
if(InfoForTileCars[k].type == NodeTypeExtern){
|
|
|
|
numExtern++;
|
|
|
|
if(InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes > numLanes)
|
|
|
|
numLanes = InfoForTileCars[k].numLeftLanes + InfoForTileCars[k].numRightLanes;
|
2020-04-19 16:34:08 +00:00
|
|
|
maxX = Max(maxX, Abs(InfoForTileCars[k].x));
|
|
|
|
maxY = Max(maxY, Abs(InfoForTileCars[k].y));
|
2019-05-15 14:52:37 +00:00
|
|
|
}else if(InfoForTileCars[k].type == NodeTypeIntern)
|
|
|
|
numIntern++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(numIntern == 1 && numExtern == 2){
|
|
|
|
if(numLanes < 4){
|
|
|
|
if((i & 7) == 4){ // WHAT?
|
2020-03-25 14:13:06 +00:00
|
|
|
m_objectFlags[i] |= UseInRoadBlock;
|
2019-05-15 14:52:37 +00:00
|
|
|
if(maxX > maxY)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_objectFlags[i] |= ObjectEastWest;
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
2019-08-09 17:42:18 +00:00
|
|
|
m_objectFlags[i] &= ~ObjectEastWest;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}else{
|
2020-03-25 14:13:06 +00:00
|
|
|
m_objectFlags[i] |= UseInRoadBlock;
|
2019-05-15 14:52:37 +00:00
|
|
|
if(maxX > maxY)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_objectFlags[i] |= ObjectEastWest;
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
2019-08-09 17:42:18 +00:00
|
|
|
m_objectFlags[i] &= ~ObjectEastWest;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
delete[] tempNodes;
|
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
CountFloodFillGroups(PATH_CAR);
|
|
|
|
CountFloodFillGroups(PATH_PED);
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
delete[] InfoForTileCars;
|
|
|
|
InfoForTileCars = nil;
|
|
|
|
delete[] InfoForTilePeds;
|
|
|
|
InfoForTilePeds = nil;
|
2020-05-03 13:57:57 +00:00
|
|
|
|
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
delete[] DetachedNodesCars;
|
|
|
|
DetachedNodesCars = nil;
|
|
|
|
delete[] DetachedNodesPeds;
|
|
|
|
DetachedNodesPeds = nil;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
delete[] DetachedInfoForTileCars;
|
|
|
|
DetachedInfoForTileCars = nil;
|
|
|
|
delete[] DetachedInfoForTilePeds;
|
|
|
|
DetachedInfoForTilePeds = nil;
|
|
|
|
delete[] TempExternalNodes;
|
|
|
|
TempExternalNodes = nil;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
printf("Done with PreparePathData\n");
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-05-15 14:52:37 +00:00
|
|
|
/* String together connected nodes in a list by a flood fill algorithm */
|
|
|
|
void
|
|
|
|
CPathFind::CountFloodFillGroups(uint8 type)
|
|
|
|
{
|
|
|
|
int start, end;
|
|
|
|
int i, l;
|
|
|
|
uint16 n;
|
|
|
|
CPathNode *node, *prev;
|
|
|
|
|
|
|
|
switch(type){
|
2019-08-09 17:42:18 +00:00
|
|
|
case PATH_CAR:
|
2019-05-15 14:52:37 +00:00
|
|
|
start = 0;
|
|
|
|
end = m_numCarPathNodes;
|
|
|
|
break;
|
2019-08-09 17:42:18 +00:00
|
|
|
case PATH_PED:
|
2019-05-15 14:52:37 +00:00
|
|
|
start = m_numCarPathNodes;
|
|
|
|
end = start + m_numPedPathNodes;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = start; i < end; i++)
|
|
|
|
m_pathNodes[i].group = 0;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for(;;){
|
|
|
|
n++;
|
|
|
|
if(n > 1500){
|
|
|
|
for(i = start; m_pathNodes[i].group && i < end; i++);
|
|
|
|
printf("NumNodes:%d Accounted for:%d\n", end - start, i - start);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look for unvisited node
|
|
|
|
for(i = start; m_pathNodes[i].group && i < end; i++);
|
|
|
|
if(i == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
node = &m_pathNodes[i];
|
2020-05-03 13:57:57 +00:00
|
|
|
node->SetNext(nil);
|
2019-05-15 14:52:37 +00:00
|
|
|
node->group = n;
|
|
|
|
|
|
|
|
if(node->numLinks == 0){
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR)
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
printf("Single car node: %f %f %f (%d)\n",
|
2020-05-05 11:48:35 +00:00
|
|
|
node->GetX(), node->GetY(), node->GetZ(), m_mapObjects[node->objectIndex]->GetModelIndex());
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
printf("Single car node: %f %f %f\n",
|
|
|
|
node->GetX(), node->GetY(), node->GetZ());
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
|
|
|
printf("Single ped node: %f %f %f\n",
|
2020-05-03 13:57:57 +00:00
|
|
|
node->GetX(), node->GetY(), node->GetZ());
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while(node){
|
|
|
|
prev = node;
|
2020-05-03 13:57:57 +00:00
|
|
|
node = node->GetNext();
|
2019-05-15 14:52:37 +00:00
|
|
|
for(i = 0; i < prev->numLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
l = ConnectedNode(prev->firstLink + i);
|
2019-05-15 14:52:37 +00:00
|
|
|
if(m_pathNodes[l].group == 0){
|
|
|
|
m_pathNodes[l].group = n;
|
|
|
|
if(m_pathNodes[l].group == 0)
|
2019-12-26 22:15:27 +00:00
|
|
|
m_pathNodes[l].group = INT8_MIN;
|
2020-05-03 13:57:57 +00:00
|
|
|
m_pathNodes[l].SetNext(node);
|
2019-05-15 14:52:37 +00:00
|
|
|
node = &m_pathNodes[l];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_numGroups[type] = n-1;
|
|
|
|
printf("GraphType:%d. FloodFill groups:%d\n", type, n);
|
|
|
|
}
|
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
int32 TempListLength;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-05-15 14:52:37 +00:00
|
|
|
void
|
|
|
|
CPathFind::PreparePathDataForType(uint8 type, CTempNode *tempnodes, CPathInfoForObject *objectpathinfo,
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
|
|
|
float maxdist, CTempDetachedNode *detachednodes, int numDetached)
|
|
|
|
#else
|
|
|
|
float maxdist, CPathInfoForObject *detachednodes, int numDetached)
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
{
|
|
|
|
static CVector CoorsXFormed;
|
|
|
|
int i, j, k, l;
|
|
|
|
int l1, l2;
|
2019-08-09 17:42:18 +00:00
|
|
|
int start;
|
2019-05-15 14:52:37 +00:00
|
|
|
float posx, posy;
|
|
|
|
float dx, dy, mag;
|
|
|
|
float nearestDist;
|
|
|
|
int nearestId;
|
|
|
|
int next;
|
|
|
|
int oldNumPathNodes, oldNumLinks;
|
2020-05-03 13:57:57 +00:00
|
|
|
float dist;
|
2019-05-15 14:52:37 +00:00
|
|
|
int iseg, jseg;
|
|
|
|
int istart, jstart;
|
|
|
|
int done, cont;
|
2020-05-03 13:57:57 +00:00
|
|
|
int tileStart;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
oldNumPathNodes = m_numPathNodes;
|
2019-05-15 20:15:49 +00:00
|
|
|
oldNumLinks = m_numConnections;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
|
|
|
#define OBJECTINDEX(n) (m_pathNodes[(n)].objectIndex)
|
2019-05-15 14:52:37 +00:00
|
|
|
// Initialize map objects
|
|
|
|
for(i = 0; i < m_numMapObjects; i++)
|
|
|
|
for(j = 0; j < 12; j++)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_mapObjects[i]->m_nodeIndices[type][j] = -1;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
#define OBJECTINDEX(n) (mapObjIndices[(n)])
|
|
|
|
int16 *mapObjIndices = new int16[NUM_PATHNODES];
|
|
|
|
NumTempExternalNodes = 0;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
// Calculate internal nodes, store them and connect them to defining object
|
|
|
|
for(i = 0; i < m_numMapObjects; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
tileStart = m_numPathNodes;
|
2020-05-05 11:48:35 +00:00
|
|
|
start = 12 * m_mapObjects[i]->GetModelIndex();
|
2019-05-15 14:52:37 +00:00
|
|
|
for(j = 0; j < 12; j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
if(objectpathinfo[start + j].type == NodeTypeIntern){
|
|
|
|
CalcNodeCoors(
|
|
|
|
objectpathinfo[start + j].x,
|
|
|
|
objectpathinfo[start + j].y,
|
|
|
|
objectpathinfo[start + j].z,
|
|
|
|
i,
|
|
|
|
&CoorsXFormed);
|
|
|
|
m_pathNodes[m_numPathNodes].SetPosition(CoorsXFormed);
|
|
|
|
OBJECTINDEX(m_numPathNodes) = i;
|
|
|
|
#ifndef MIAMI
|
|
|
|
m_pathNodes[m_numPathNodes].unkBits = 1;
|
|
|
|
m_mapObjects[i]->m_nodeIndices[type][j] = m_numPathNodes;
|
|
|
|
#else
|
|
|
|
m_pathNodes[m_numPathNodes].width = objectpathinfo[start + j].width;
|
|
|
|
m_pathNodes[m_numPathNodes].speedLimit = objectpathinfo[start + j].speedLimit;
|
|
|
|
m_pathNodes[m_numPathNodes].spawnRate = objectpathinfo[start + j].spawnRate;
|
|
|
|
m_pathNodes[m_numPathNodes].bUseInRoadBlock = objectpathinfo[start + j].roadBlock;
|
|
|
|
m_pathNodes[m_numPathNodes].bDisabled = objectpathinfo[start + j].disabled;
|
|
|
|
m_pathNodes[m_numPathNodes].bWaterPath = objectpathinfo[start + j].waterPath;
|
|
|
|
m_pathNodes[m_numPathNodes].flagB2 = objectpathinfo[start + j].flag02;
|
|
|
|
m_pathNodes[m_numPathNodes].bBetweenLevels = objectpathinfo[start + j].betweenLevels;
|
|
|
|
#endif
|
|
|
|
m_numPathNodes++;
|
|
|
|
}
|
|
|
|
#ifdef MIAMI
|
|
|
|
else if(objectpathinfo[start + j].type == NodeTypeExtern){
|
|
|
|
CalcNodeCoors(
|
|
|
|
objectpathinfo[start + j].x,
|
|
|
|
objectpathinfo[start + j].y,
|
|
|
|
objectpathinfo[start + j].z,
|
|
|
|
i,
|
|
|
|
&CoorsXFormed);
|
|
|
|
TempExternalNodes[NumTempExternalNodes].pos = CoorsXFormed;
|
|
|
|
assert(objectpathinfo[start + j].next >= 0);
|
|
|
|
TempExternalNodes[NumTempExternalNodes].next = tileStart + objectpathinfo[start + j].next;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].numLeftLanes = objectpathinfo[start + j].numLeftLanes;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].numRightLanes = objectpathinfo[start + j].numRightLanes;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].width = objectpathinfo[start + j].width;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].isCross = !!objectpathinfo[start + j].crossing;
|
|
|
|
NumTempExternalNodes++;
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
// Same thing for detached nodes
|
|
|
|
for(i = 0; i < numDetached; i++){
|
|
|
|
tileStart = m_numPathNodes;
|
|
|
|
start = 12*i;
|
|
|
|
for(j = 0; j < 12; j++){
|
|
|
|
if(detachednodes[start + j].type == NodeTypeIntern){
|
|
|
|
CVector pos;
|
|
|
|
pos.x = detachednodes[start + j].x;
|
|
|
|
pos.y = detachednodes[start + j].y;
|
|
|
|
pos.z = detachednodes[start + j].z;
|
|
|
|
m_pathNodes[m_numPathNodes].SetPosition(pos);
|
|
|
|
mapObjIndices[m_numPathNodes] = -(i+1);
|
|
|
|
m_pathNodes[m_numPathNodes].width = detachednodes[start + j].width;
|
|
|
|
m_pathNodes[m_numPathNodes].speedLimit = detachednodes[start + j].speedLimit;
|
|
|
|
m_pathNodes[m_numPathNodes].spawnRate = detachednodes[start + j].spawnRate;
|
|
|
|
m_pathNodes[m_numPathNodes].bUseInRoadBlock = detachednodes[start + j].roadBlock;
|
|
|
|
m_pathNodes[m_numPathNodes].bDisabled = detachednodes[start + j].disabled;
|
|
|
|
m_pathNodes[m_numPathNodes].bWaterPath = detachednodes[start + j].waterPath;
|
|
|
|
m_pathNodes[m_numPathNodes].flagB2 = detachednodes[start + j].flag02;
|
|
|
|
m_pathNodes[m_numPathNodes].bBetweenLevels = detachednodes[start + j].betweenLevels;
|
|
|
|
m_numPathNodes++;
|
|
|
|
}else if(detachednodes[start + j].type == NodeTypeExtern){
|
|
|
|
TempExternalNodes[NumTempExternalNodes].pos.x = detachednodes[start + j].x;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].pos.y = detachednodes[start + j].y;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].pos.z = detachednodes[start + j].z;
|
|
|
|
assert(detachednodes[start + j].next >= 0);
|
|
|
|
TempExternalNodes[NumTempExternalNodes].next = tileStart + detachednodes[start + j].next;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].numLeftLanes = detachednodes[start + j].numLeftLanes;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].numRightLanes = detachednodes[start + j].numRightLanes;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].width = detachednodes[start + j].width;
|
|
|
|
TempExternalNodes[NumTempExternalNodes].isCross = !!detachednodes[start + j].crossing;
|
|
|
|
NumTempExternalNodes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
// Insert external nodes into TempList
|
|
|
|
TempListLength = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
for(i = 0; i < m_numMapObjects; i++){
|
2020-05-05 11:48:35 +00:00
|
|
|
start = 12 * m_mapObjects[i]->GetModelIndex();
|
2019-05-15 14:52:37 +00:00
|
|
|
for(j = 0; j < 12; j++){
|
|
|
|
if(objectpathinfo[start + j].type != NodeTypeExtern)
|
|
|
|
continue;
|
|
|
|
CalcNodeCoors(
|
|
|
|
objectpathinfo[start + j].x,
|
|
|
|
objectpathinfo[start + j].y,
|
|
|
|
objectpathinfo[start + j].z,
|
|
|
|
i,
|
|
|
|
&CoorsXFormed);
|
|
|
|
|
|
|
|
// find closest unconnected node
|
|
|
|
nearestId = -1;
|
|
|
|
nearestDist = maxdist;
|
|
|
|
for(k = 0; k < TempListLength; k++){
|
|
|
|
if(tempnodes[k].linkState != 1)
|
|
|
|
continue;
|
|
|
|
dx = tempnodes[k].pos.x - CoorsXFormed.x;
|
2019-07-10 15:18:26 +00:00
|
|
|
if(Abs(dx) < nearestDist){
|
2019-05-15 14:52:37 +00:00
|
|
|
dy = tempnodes[k].pos.y - CoorsXFormed.y;
|
2019-07-10 15:18:26 +00:00
|
|
|
if(Abs(dy) < nearestDist){
|
2020-04-19 16:34:08 +00:00
|
|
|
nearestDist = Max(Abs(dx), Abs(dy));
|
2019-05-15 14:52:37 +00:00
|
|
|
nearestId = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nearestId < 0){
|
|
|
|
// None found, add this one to temp list
|
|
|
|
tempnodes[TempListLength].pos = CoorsXFormed;
|
|
|
|
next = objectpathinfo[start + j].next;
|
|
|
|
if(next < 0){
|
|
|
|
// no link from this node, find link to this node
|
|
|
|
next = 0;
|
|
|
|
for(k = start; j != objectpathinfo[k].next; k++)
|
|
|
|
next++;
|
|
|
|
}
|
|
|
|
// link to connecting internal node
|
2019-08-09 17:42:18 +00:00
|
|
|
tempnodes[TempListLength].link1 = m_mapObjects[i]->m_nodeIndices[type][next];
|
|
|
|
if(type == PATH_CAR){
|
2019-05-15 14:52:37 +00:00
|
|
|
tempnodes[TempListLength].numLeftLanes = objectpathinfo[start + j].numLeftLanes;
|
|
|
|
tempnodes[TempListLength].numRightLanes = objectpathinfo[start + j].numRightLanes;
|
|
|
|
}
|
|
|
|
tempnodes[TempListLength++].linkState = 1;
|
|
|
|
}else{
|
|
|
|
// Found nearest, connect it to our neighbour
|
|
|
|
next = objectpathinfo[start + j].next;
|
|
|
|
if(next < 0){
|
|
|
|
// no link from this node, find link to this node
|
|
|
|
next = 0;
|
|
|
|
for(k = start; j != objectpathinfo[k].next; k++)
|
|
|
|
next++;
|
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
tempnodes[nearestId].link2 = m_mapObjects[i]->m_nodeIndices[type][next];
|
2019-05-15 14:52:37 +00:00
|
|
|
tempnodes[nearestId].linkState = 2;
|
|
|
|
|
|
|
|
// collapse this node with nearest we found
|
2020-05-03 13:57:57 +00:00
|
|
|
dx = m_pathNodes[tempnodes[nearestId].link1].GetX() - m_pathNodes[tempnodes[nearestId].link2].GetX();
|
|
|
|
dy = m_pathNodes[tempnodes[nearestId].link1].GetY() - m_pathNodes[tempnodes[nearestId].link2].GetY();
|
2019-05-17 19:38:15 +00:00
|
|
|
tempnodes[nearestId].pos = (tempnodes[nearestId].pos + CoorsXFormed)*0.5f;
|
2019-07-10 15:18:26 +00:00
|
|
|
mag = Sqrt(dx*dx + dy*dy);
|
2019-05-15 14:52:37 +00:00
|
|
|
tempnodes[nearestId].dirX = dx/mag;
|
|
|
|
tempnodes[nearestId].dirY = dy/mag;
|
|
|
|
// do something when number of lanes doesn't agree
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR)
|
2019-05-15 14:52:37 +00:00
|
|
|
if(tempnodes[nearestId].numLeftLanes != 0 && tempnodes[nearestId].numRightLanes != 0 &&
|
|
|
|
(objectpathinfo[start + j].numLeftLanes == 0 || objectpathinfo[start + j].numRightLanes == 0)){
|
2019-05-17 19:38:15 +00:00
|
|
|
// why switch left and right here?
|
|
|
|
tempnodes[nearestId].numLeftLanes = objectpathinfo[start + j].numRightLanes;
|
|
|
|
tempnodes[nearestId].numRightLanes = objectpathinfo[start + j].numLeftLanes;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
for(i = 0; i < NumTempExternalNodes; i++){
|
|
|
|
// find closest unconnected node
|
|
|
|
nearestId = -1;
|
|
|
|
nearestDist = maxdist;
|
|
|
|
for(k = 0; k < TempListLength; k++){
|
|
|
|
if(tempnodes[k].linkState != 1)
|
|
|
|
continue;
|
|
|
|
dx = tempnodes[k].pos.x - TempExternalNodes[i].pos.x;
|
|
|
|
if(Abs(dx) < nearestDist){
|
|
|
|
dy = tempnodes[k].pos.y - TempExternalNodes[i].pos.y;
|
|
|
|
if(Abs(dy) < nearestDist){
|
|
|
|
nearestDist = Max(Abs(dx), Abs(dy));
|
|
|
|
nearestId = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nearestId < 0){
|
|
|
|
// None found, add this one to temp list
|
|
|
|
tempnodes[TempListLength].pos = TempExternalNodes[i].pos;
|
|
|
|
// link to connecting internal node
|
|
|
|
tempnodes[TempListLength].link1 = TempExternalNodes[i].next;
|
|
|
|
if(type == PATH_CAR){
|
|
|
|
tempnodes[TempListLength].numLeftLanes = TempExternalNodes[i].numLeftLanes;
|
|
|
|
tempnodes[TempListLength].numRightLanes = TempExternalNodes[i].numRightLanes;
|
|
|
|
}
|
|
|
|
tempnodes[TempListLength].width = TempExternalNodes[i].width;
|
|
|
|
tempnodes[TempListLength].isCross = TempExternalNodes[i].isCross;
|
|
|
|
tempnodes[TempListLength++].linkState = 1;
|
|
|
|
}else{
|
|
|
|
// Found nearest, connect it to our neighbour
|
|
|
|
tempnodes[nearestId].link2 = TempExternalNodes[i].next;
|
|
|
|
tempnodes[nearestId].linkState = 2;
|
|
|
|
|
|
|
|
// collapse this node with nearest we found
|
|
|
|
dx = m_pathNodes[tempnodes[nearestId].link1].GetX() - m_pathNodes[tempnodes[nearestId].link2].GetX();
|
|
|
|
dy = m_pathNodes[tempnodes[nearestId].link1].GetY() - m_pathNodes[tempnodes[nearestId].link2].GetY();
|
|
|
|
tempnodes[nearestId].pos = (tempnodes[nearestId].pos + TempExternalNodes[i].pos)*0.5f;
|
|
|
|
mag = Sqrt(dx*dx + dy*dy);
|
|
|
|
tempnodes[nearestId].dirX = dx/mag * 100;
|
|
|
|
tempnodes[nearestId].dirY = dy/mag * 100;
|
|
|
|
tempnodes[nearestId].width = Max(tempnodes[nearestId].width, TempExternalNodes[i].width);
|
|
|
|
if(TempExternalNodes[i].isCross)
|
|
|
|
tempnodes[nearestId].isCross = true; // TODO: is this guaranteed to be false otherwise?
|
|
|
|
// do something when number of lanes doesn't agree
|
|
|
|
if(type == PATH_CAR)
|
|
|
|
if(tempnodes[nearestId].numLeftLanes != 0 && tempnodes[nearestId].numRightLanes != 0 &&
|
|
|
|
(TempExternalNodes[i].numLeftLanes == 0 || TempExternalNodes[i].numRightLanes == 0)){
|
|
|
|
// why switch left and right here?
|
|
|
|
tempnodes[nearestId].numLeftLanes = TempExternalNodes[i].numRightLanes;
|
|
|
|
tempnodes[nearestId].numRightLanes = TempExternalNodes[i].numLeftLanes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
// Loop through previously added internal nodes and link them
|
|
|
|
for(i = oldNumPathNodes; i < m_numPathNodes; i++){
|
|
|
|
// Init link
|
|
|
|
m_pathNodes[i].numLinks = 0;
|
2019-05-15 20:15:49 +00:00
|
|
|
m_pathNodes[i].firstLink = m_numConnections;
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
// See if node connects to external nodes
|
|
|
|
for(j = 0; j < TempListLength; j++){
|
|
|
|
if(tempnodes[j].linkState != 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Add link to other side of the external
|
2020-05-03 13:57:57 +00:00
|
|
|
// NB this clears the flags in MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
if(tempnodes[j].link1 == i)
|
2019-05-15 20:15:49 +00:00
|
|
|
m_connections[m_numConnections] = tempnodes[j].link2;
|
2019-05-15 14:52:37 +00:00
|
|
|
else if(tempnodes[j].link2 == i)
|
2019-05-15 20:15:49 +00:00
|
|
|
m_connections[m_numConnections] = tempnodes[j].link1;
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
dist = (m_pathNodes[i].GetPosition() - m_pathNodes[ConnectedNode(m_numConnections)].GetPosition()).Magnitude();
|
|
|
|
#ifndef MIAMI
|
|
|
|
m_distances[m_numConnections] = dist;
|
2019-08-09 17:42:18 +00:00
|
|
|
m_connectionFlags[m_numConnections].flags = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
m_distances[m_numConnections] = Min(dist, 255);
|
|
|
|
if(tempnodes[j].isCross)
|
|
|
|
m_connections[j] |= 0x8000; // crosses road flag
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR){
|
2019-05-15 14:52:37 +00:00
|
|
|
// IMPROVE: use a goto here
|
2019-05-15 20:15:49 +00:00
|
|
|
// Find existing car path link
|
|
|
|
for(k = 0; k < m_numCarPathLinks; k++){
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2020-04-10 16:36:39 +00:00
|
|
|
if(m_carPathLinks[k].dir.x == tempnodes[j].dirX &&
|
|
|
|
m_carPathLinks[k].dir.y == tempnodes[j].dirY &&
|
|
|
|
m_carPathLinks[k].pos.x == tempnodes[j].pos.x &&
|
|
|
|
m_carPathLinks[k].pos.y == tempnodes[j].pos.y){
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(m_carPathLinks[k].dirX == tempnodes[j].dirX &&
|
|
|
|
m_carPathLinks[k].dirY == tempnodes[j].dirY &&
|
|
|
|
m_carPathLinks[k].x == (int)(tempnodes[j].pos.x*8.0f) &&
|
|
|
|
m_carPathLinks[k].y == (int)(tempnodes[j].pos.y*8.0f)){
|
|
|
|
#endif
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathConnections[m_numConnections] = k;
|
|
|
|
k = m_numCarPathLinks;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 20:15:49 +00:00
|
|
|
// k is m_numCarPathLinks+1 if we found one
|
|
|
|
if(k == m_numCarPathLinks){
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2020-04-10 16:36:39 +00:00
|
|
|
m_carPathLinks[m_numCarPathLinks].dir.x = tempnodes[j].dirX;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].dir.y = tempnodes[j].dirY;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].pos.x = tempnodes[j].pos.x;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].pos.y = tempnodes[j].pos.y;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
m_carPathLinks[m_numCarPathLinks].dirX = tempnodes[j].dirX;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].dirY = tempnodes[j].dirY;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].x = tempnodes[j].pos.x*8.0f;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].y = tempnodes[j].pos.y*8.0f;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].flag1 = false;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].width = tempnodes[j].width;
|
|
|
|
#endif
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[m_numCarPathLinks].pathNodeIndex = i;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].numLeftLanes = tempnodes[j].numLeftLanes;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].numRightLanes = tempnodes[j].numRightLanes;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].trafficLightType = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
assert(m_numCarPathLinks <= NUM_CARPATHLINKS);
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathConnections[m_numConnections] = m_numCarPathLinks++;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pathNodes[i].numLinks++;
|
2019-05-15 20:15:49 +00:00
|
|
|
m_numConnections++;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
CPathInfoForObject *tile;
|
|
|
|
if(mapObjIndices[i] < 0){
|
|
|
|
if(type == PATH_CAR)
|
|
|
|
tile = &DetachedInfoForTileCars[12 * (-1 - mapObjIndices[i])];
|
|
|
|
else
|
|
|
|
tile = &DetachedInfoForTilePeds[12 * (-1 - mapObjIndices[i])];
|
|
|
|
}else{
|
|
|
|
if(type == PATH_CAR)
|
|
|
|
tile = &InfoForTileCars[12 * m_mapObjects[mapObjIndices[i]]->GetModelIndex()];
|
|
|
|
else
|
|
|
|
tile = &InfoForTilePeds[12 * m_mapObjects[mapObjIndices[i]]->GetModelIndex()];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
// Find i inside path segment
|
|
|
|
iseg = 0;
|
2020-04-19 16:34:08 +00:00
|
|
|
for(j = Max(oldNumPathNodes, i-12); j < i; j++)
|
2020-05-03 13:57:57 +00:00
|
|
|
if(OBJECTINDEX(j) == OBJECTINDEX(i))
|
2019-05-15 14:52:37 +00:00
|
|
|
iseg++;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2020-05-05 11:48:35 +00:00
|
|
|
istart = 12 * m_mapObjects[m_pathNodes[i].objectIndex]->GetModelIndex();
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
// Add links to other internal nodes
|
2020-04-19 16:34:08 +00:00
|
|
|
for(j = Max(oldNumPathNodes, i-12); j < Min(m_numPathNodes, i+12); j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
if(OBJECTINDEX(i) != OBJECTINDEX(j) || i == j)
|
2019-05-15 14:52:37 +00:00
|
|
|
continue;
|
|
|
|
// N.B.: in every path segment, the externals have to be at the end
|
|
|
|
jseg = j-i + iseg;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2020-05-05 11:48:35 +00:00
|
|
|
jstart = 12 * m_mapObjects[m_pathNodes[j].objectIndex]->GetModelIndex();
|
2019-05-15 14:52:37 +00:00
|
|
|
if(objectpathinfo[istart + iseg].next == jseg ||
|
|
|
|
objectpathinfo[jstart + jseg].next == iseg){
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(tile[iseg].next == jseg ||
|
|
|
|
tile[jseg].next == iseg){
|
|
|
|
#endif
|
|
|
|
// Found a link between i and jConnectionSetCrossesRoad
|
|
|
|
// NB this clears the flags in MIAMI
|
2019-05-15 20:15:49 +00:00
|
|
|
m_connections[m_numConnections] = j;
|
2020-05-03 13:57:57 +00:00
|
|
|
dist = (m_pathNodes[i].GetPosition() - m_pathNodes[j].GetPosition()).Magnitude();
|
|
|
|
#ifndef MIAMI
|
|
|
|
m_distances[m_numConnections] = dist;
|
|
|
|
#else
|
|
|
|
m_distances[m_numConnections] = Min(dist, 255);
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR){
|
2020-05-03 13:57:57 +00:00
|
|
|
posx = (m_pathNodes[i].GetX() + m_pathNodes[j].GetX())*0.5f;
|
|
|
|
posy = (m_pathNodes[i].GetY() + m_pathNodes[j].GetY())*0.5f;
|
|
|
|
dx = m_pathNodes[j].GetX() - m_pathNodes[i].GetX();
|
|
|
|
dy = m_pathNodes[j].GetY() - m_pathNodes[i].GetY();
|
2019-07-10 15:18:26 +00:00
|
|
|
mag = Sqrt(dx*dx + dy*dy);
|
2019-05-15 14:52:37 +00:00
|
|
|
dx /= mag;
|
|
|
|
dy /= mag;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
int width = Max(m_pathNodes[i].width, m_pathNodes[j].width);
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
if(i < j){
|
|
|
|
dx = -dx;
|
|
|
|
dy = -dy;
|
|
|
|
}
|
|
|
|
// IMPROVE: use a goto here
|
2019-05-15 20:15:49 +00:00
|
|
|
// Find existing car path link
|
|
|
|
for(k = 0; k < m_numCarPathLinks; k++){
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2020-04-10 16:36:39 +00:00
|
|
|
if(m_carPathLinks[k].dir.x == dx &&
|
|
|
|
m_carPathLinks[k].dir.y == dy &&
|
|
|
|
m_carPathLinks[k].pos.x == posx &&
|
|
|
|
m_carPathLinks[k].pos.y == posy){
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(m_carPathLinks[k].dirX == (int)(dx*100.0f) &&
|
|
|
|
m_carPathLinks[k].dirY == (int)(dy*100.0f) &&
|
|
|
|
m_carPathLinks[k].x == (int)(posx*8.0f) &&
|
|
|
|
m_carPathLinks[k].y == (int)(posy*8.0f)){
|
|
|
|
#endif
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathConnections[m_numConnections] = k;
|
|
|
|
k = m_numCarPathLinks;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 20:15:49 +00:00
|
|
|
// k is m_numCarPathLinks+1 if we found one
|
|
|
|
if(k == m_numCarPathLinks){
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2020-04-10 16:36:39 +00:00
|
|
|
m_carPathLinks[m_numCarPathLinks].dir.x = dx;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].dir.y = dy;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].pos.x = posx;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].pos.y = posy;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
m_carPathLinks[m_numCarPathLinks].dirX = dx*100.0f;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].dirY = dy*100.0f;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].x = posx*8.0f;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].y = posy*8.0f;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].flag1 = false;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].width = width;
|
|
|
|
#endif
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[m_numCarPathLinks].pathNodeIndex = i;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].numLeftLanes = -1;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].numRightLanes = -1;
|
|
|
|
m_carPathLinks[m_numCarPathLinks].trafficLightType = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
assert(m_numCarPathLinks <= NUM_CARPATHLINKS);
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathConnections[m_numConnections] = m_numCarPathLinks++;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
// Crosses road
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-06-17 08:30:02 +00:00
|
|
|
if(objectpathinfo[istart + iseg].next == jseg && objectpathinfo[istart + iseg].crossing ||
|
|
|
|
objectpathinfo[jstart + jseg].next == iseg && objectpathinfo[jstart + jseg].crossing)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_connectionFlags[m_numConnections].bCrossesRoad = true;
|
2019-05-15 14:52:37 +00:00
|
|
|
else
|
2019-08-09 17:42:18 +00:00
|
|
|
m_connectionFlags[m_numConnections].bCrossesRoad = false;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(tile[iseg].next == jseg && tile[iseg].crossing ||
|
|
|
|
tile[jseg].next == iseg && tile[jseg].crossing)
|
|
|
|
m_connections[m_numConnections] |= 0x8000; // crosses road flag
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_pathNodes[i].numLinks++;
|
2019-05-15 20:15:49 +00:00
|
|
|
m_numConnections++;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR){
|
2019-05-15 14:52:37 +00:00
|
|
|
done = 0;
|
|
|
|
// Set number of lanes for all nodes somehow
|
|
|
|
// very strange code
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
for(k = 0; !done && k < 10; k++){
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
for(k = 0; !done && k < 12; k++){
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
done = 1;
|
|
|
|
for(i = 0; i < m_numPathNodes; i++){
|
|
|
|
if(m_pathNodes[i].numLinks != 2)
|
|
|
|
continue;
|
2019-05-15 20:15:49 +00:00
|
|
|
l1 = m_carPathConnections[m_pathNodes[i].firstLink];
|
|
|
|
l2 = m_carPathConnections[m_pathNodes[i].firstLink+1];
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 20:15:49 +00:00
|
|
|
if(m_carPathLinks[l1].numLeftLanes == -1 &&
|
|
|
|
m_carPathLinks[l2].numLeftLanes != -1){
|
2019-05-15 14:52:37 +00:00
|
|
|
done = 0;
|
2019-05-15 20:15:49 +00:00
|
|
|
if(m_carPathLinks[l2].pathNodeIndex == i){
|
2019-05-15 14:52:37 +00:00
|
|
|
// why switch left and right here?
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[l1].numLeftLanes = m_carPathLinks[l2].numRightLanes;
|
|
|
|
m_carPathLinks[l1].numRightLanes = m_carPathLinks[l2].numLeftLanes;
|
2019-05-15 14:52:37 +00:00
|
|
|
}else{
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[l1].numLeftLanes = m_carPathLinks[l2].numLeftLanes;
|
|
|
|
m_carPathLinks[l1].numRightLanes = m_carPathLinks[l2].numRightLanes;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[l1].pathNodeIndex = i;
|
|
|
|
}else if(m_carPathLinks[l1].numLeftLanes != -1 &&
|
|
|
|
m_carPathLinks[l2].numLeftLanes == -1){
|
2019-05-15 14:52:37 +00:00
|
|
|
done = 0;
|
2019-05-15 20:15:49 +00:00
|
|
|
if(m_carPathLinks[l1].pathNodeIndex == i){
|
2019-05-15 14:52:37 +00:00
|
|
|
// why switch left and right here?
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[l2].numLeftLanes = m_carPathLinks[l1].numRightLanes;
|
|
|
|
m_carPathLinks[l2].numRightLanes = m_carPathLinks[l1].numLeftLanes;
|
2019-05-15 14:52:37 +00:00
|
|
|
}else{
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[l2].numLeftLanes = m_carPathLinks[l1].numLeftLanes;
|
|
|
|
m_carPathLinks[l2].numRightLanes = m_carPathLinks[l1].numRightLanes;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
2019-05-15 20:15:49 +00:00
|
|
|
m_carPathLinks[l2].pathNodeIndex = i;
|
|
|
|
}else if(m_carPathLinks[l1].numLeftLanes == -1 &&
|
|
|
|
m_carPathLinks[l2].numLeftLanes == -1)
|
2019-05-15 14:52:37 +00:00
|
|
|
done = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
int8 l1Left = m_carPathLinks[l1].numLeftLanes;
|
|
|
|
int8 l1Right = m_carPathLinks[l1].numRightLanes;
|
|
|
|
int8 l2Left = m_carPathLinks[l2].numLeftLanes;
|
|
|
|
int8 l2Right = m_carPathLinks[l2].numRightLanes;
|
|
|
|
int8 *l1Leftp, *l1Rightp;
|
|
|
|
int8 *l2Leftp, *l2Rightp;
|
|
|
|
if(m_carPathLinks[l1].pathNodeIndex == i){
|
|
|
|
l1Leftp = &l1Left;
|
|
|
|
l1Rightp = &l1Right;
|
|
|
|
}else{
|
|
|
|
l1Leftp = &l1Right;
|
|
|
|
l1Rightp = &l1Left;
|
|
|
|
}
|
|
|
|
if(m_carPathLinks[l2].pathNodeIndex == i){
|
|
|
|
l2Leftp = &l2Left;
|
|
|
|
l2Rightp = &l2Right;
|
|
|
|
}else{
|
|
|
|
l2Leftp = &l2Right;
|
|
|
|
l2Rightp = &l2Left;
|
|
|
|
}
|
|
|
|
if(*l1Leftp == -1 && *l2Rightp != -1){
|
|
|
|
*l1Leftp = *l2Rightp;
|
|
|
|
done = 0;
|
|
|
|
}
|
|
|
|
if(*l1Rightp == -1 && *l2Leftp != -1){
|
|
|
|
*l1Rightp = *l2Leftp;
|
|
|
|
done = 0;
|
|
|
|
}
|
|
|
|
if(*l2Leftp == -1 && *l1Rightp != -1){
|
|
|
|
*l2Leftp = *l1Rightp;
|
|
|
|
done = 0;
|
|
|
|
}
|
|
|
|
if(*l2Rightp == -1 && *l1Leftp != -1){
|
|
|
|
*l2Rightp = *l1Leftp;
|
|
|
|
done = 0;
|
|
|
|
}
|
|
|
|
if(*l1Leftp == -1 && *l2Rightp == -1)
|
|
|
|
done = 0;
|
|
|
|
if(*l2Leftp == -1 && *l1Rightp == -1)
|
|
|
|
done = 0;
|
|
|
|
m_carPathLinks[l1].numLeftLanes = l1Left;
|
|
|
|
m_carPathLinks[l1].numRightLanes = l1Right;
|
|
|
|
m_carPathLinks[l2].numLeftLanes = l2Left;
|
|
|
|
m_carPathLinks[l2].numRightLanes = l2Right;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to default values for number of lanes
|
|
|
|
for(i = 0; i < m_numPathNodes; i++)
|
|
|
|
for(j = 0; j < m_pathNodes[i].numLinks; j++){
|
2019-05-15 20:15:49 +00:00
|
|
|
k = m_carPathConnections[m_pathNodes[i].firstLink + j];
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 20:15:49 +00:00
|
|
|
if(m_carPathLinks[k].numLeftLanes < 0)
|
|
|
|
m_carPathLinks[k].numLeftLanes = 1;
|
|
|
|
if(m_carPathLinks[k].numRightLanes < 0)
|
|
|
|
m_carPathLinks[k].numRightLanes = 1;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(m_carPathLinks[k].numLeftLanes == -1)
|
|
|
|
m_carPathLinks[k].numLeftLanes = 0;
|
|
|
|
if(m_carPathLinks[k].numRightLanes == -1)
|
|
|
|
m_carPathLinks[k].numRightLanes = 0;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set flags for car nodes
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR){
|
2019-05-15 14:52:37 +00:00
|
|
|
do{
|
|
|
|
cont = 0;
|
|
|
|
for(i = 0; i < m_numPathNodes; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
m_pathNodes[i].bDisabled = false;
|
|
|
|
m_pathNodes[i].bBetweenLevels = false;
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
// See if node is a dead end, if so, we're not done yet
|
2019-08-09 17:42:18 +00:00
|
|
|
if(!m_pathNodes[i].bDeadEnd){
|
2019-05-15 14:52:37 +00:00
|
|
|
k = 0;
|
|
|
|
for(j = 0; j < m_pathNodes[i].numLinks; j++)
|
2020-05-03 13:57:57 +00:00
|
|
|
if(!m_pathNodes[ConnectedNode(m_pathNodes[i].firstLink + j)].bDeadEnd)
|
2019-05-15 14:52:37 +00:00
|
|
|
k++;
|
|
|
|
if(k < 2){
|
2019-08-09 17:42:18 +00:00
|
|
|
m_pathNodes[i].bDeadEnd = true;
|
2019-05-15 14:52:37 +00:00
|
|
|
cont = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}while(cont);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove isolated ped nodes
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_PED)
|
2019-05-15 14:52:37 +00:00
|
|
|
for(i = oldNumPathNodes; i < m_numPathNodes; i++){
|
|
|
|
if(m_pathNodes[i].numLinks != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Remove node
|
|
|
|
for(j = i; j < m_numPathNodes-1; j++)
|
|
|
|
m_pathNodes[j] = m_pathNodes[j+1];
|
|
|
|
|
|
|
|
// Fix links
|
2020-05-03 13:57:57 +00:00
|
|
|
for(j = oldNumLinks; j < m_numConnections; j++){
|
|
|
|
int node = ConnectedNode(j);
|
|
|
|
if(node >= i)
|
|
|
|
m_connections[j] = node-1;
|
|
|
|
}
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-05-15 14:52:37 +00:00
|
|
|
// Also in treadables
|
|
|
|
for(j = 0; j < m_numMapObjects; j++)
|
|
|
|
for(k = 0; k < 12; k++){
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_mapObjects[j]->m_nodeIndices[PATH_PED][k] == i){
|
2019-05-15 14:52:37 +00:00
|
|
|
// remove this one
|
|
|
|
for(l = k; l < 12-1; l++)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_mapObjects[j]->m_nodeIndices[PATH_PED][l] = m_mapObjects[j]->m_nodeIndices[PATH_PED][l+1];
|
|
|
|
m_mapObjects[j]->m_nodeIndices[PATH_PED][11] = -1;
|
|
|
|
}else if(m_mapObjects[j]->m_nodeIndices[PATH_PED][k] > i)
|
|
|
|
m_mapObjects[j]->m_nodeIndices[PATH_PED][k]--;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
|
|
|
i--;
|
|
|
|
m_numPathNodes--;
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
delete[] mapObjIndices;
|
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
float
|
|
|
|
CPathFind::CalcRoadDensity(float x, float y)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
float density = 0.0f;
|
|
|
|
|
|
|
|
for(i = 0; i < m_numCarPathNodes; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
if(Abs(m_pathNodes[i].GetX() - x) < 80.0f &&
|
|
|
|
Abs(m_pathNodes[i].GetY() - y) < 80.0f &&
|
2019-08-09 17:42:18 +00:00
|
|
|
m_pathNodes[i].numLinks > 0){
|
|
|
|
for(j = 0; j < m_pathNodes[i].numLinks; j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
int next = ConnectedNode(m_pathNodes[i].firstLink + j);
|
|
|
|
float dist = (m_pathNodes[i].GetPosition() - m_pathNodes[next].GetPosition()).Magnitude2D();
|
2019-08-09 17:42:18 +00:00
|
|
|
next = m_carPathConnections[m_pathNodes[i].firstLink + j];
|
|
|
|
density += m_carPathLinks[next].numLeftLanes * dist;
|
|
|
|
density += m_carPathLinks[next].numRightLanes * dist;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_carPathLinks[next].numLeftLanes < 0)
|
|
|
|
printf("Link from object %d to %d (MIs)\n",
|
|
|
|
m_mapObjects[m_pathNodes[i].objectIndex]->GetModelIndex(),
|
2020-05-03 13:57:57 +00:00
|
|
|
m_mapObjects[m_pathNodes[ConnectedNode(m_pathNodes[i].firstLink + j)].objectIndex]->GetModelIndex());
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_carPathLinks[next].numRightLanes < 0)
|
|
|
|
printf("Link from object %d to %d (MIs)\n",
|
|
|
|
m_mapObjects[m_pathNodes[i].objectIndex]->GetModelIndex(),
|
2020-05-03 13:57:57 +00:00
|
|
|
m_mapObjects[m_pathNodes[ConnectedNode(m_pathNodes[i].firstLink + j)].objectIndex]->GetModelIndex());
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return density/2500.0f;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
bool
|
|
|
|
CPathFind::TestForPedTrafficLight(CPathNode *n1, CPathNode *n2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < n1->numLinks; i++)
|
2020-05-03 13:57:57 +00:00
|
|
|
if(&m_pathNodes[ConnectedNode(n1->firstLink + i)] == n2)
|
|
|
|
return ConnectionHasTrafficLight(n1->firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
bool
|
|
|
|
CPathFind::TestCrossesRoad(CPathNode *n1, CPathNode *n2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < n1->numLinks; i++)
|
2020-05-03 13:57:57 +00:00
|
|
|
if(&m_pathNodes[ConnectedNode(n1->firstLink + i)] == n2)
|
|
|
|
return ConnectionCrossesRoad(n1->firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-05-15 14:52:37 +00:00
|
|
|
void
|
2019-08-09 17:42:18 +00:00
|
|
|
CPathFind::AddNodeToList(CPathNode *node, int32 listId)
|
2019-05-15 14:52:37 +00:00
|
|
|
{
|
2019-08-09 17:42:18 +00:00
|
|
|
int i = listId & 0x1FF;
|
2020-05-03 13:57:57 +00:00
|
|
|
node->SetNext(m_searchNodes[i].GetNext());
|
|
|
|
node->SetPrev(&m_searchNodes[i]);
|
|
|
|
if(m_searchNodes[i].GetNext())
|
|
|
|
m_searchNodes[i].GetNext()->SetPrev(node);
|
|
|
|
m_searchNodes[i].SetNext(node);
|
2019-08-09 17:42:18 +00:00
|
|
|
node->distance = listId;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::RemoveNodeFromList(CPathNode *node)
|
|
|
|
{
|
2020-05-03 13:57:57 +00:00
|
|
|
node->GetPrev()->SetNext(node->GetNext());
|
|
|
|
if(node->GetNext())
|
|
|
|
node->GetNext()->SetPrev(node->GetPrev());
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::RemoveBadStartNode(CVector pos, CPathNode **nodes, int16 *n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if(*n < 2)
|
|
|
|
return;
|
2020-05-03 13:57:57 +00:00
|
|
|
if(DotProduct2D(nodes[1]->GetPosition() - pos, nodes[0]->GetPosition() - pos) < 0.0f){
|
2019-08-09 17:42:18 +00:00
|
|
|
(*n)--;
|
|
|
|
for(i = 0; i < *n; i++)
|
|
|
|
nodes[i] = nodes[i+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:28:54 +00:00
|
|
|
#ifdef GTA_BRIDGE
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::SetLinksBridgeLights(float x1, float x2, float y1, float y2, bool enable)
|
|
|
|
{
|
|
|
|
int i;
|
2020-05-03 13:57:57 +00:00
|
|
|
for(i = 0; i < m_numCarPathLinks; i++){
|
|
|
|
CVector2D pos = m_carPathLinks[i].GetPosition();
|
|
|
|
if(x1 < pos.x && pos.x < x2 &&
|
|
|
|
y1 < pos.y && pos.y < y2)
|
2019-08-09 17:42:18 +00:00
|
|
|
m_carPathLinks[i].bBridgeLights = enable;
|
2020-05-03 13:57:57 +00:00
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
2020-05-03 15:28:54 +00:00
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::SwitchOffNodeAndNeighbours(int32 nodeId, bool disable)
|
|
|
|
{
|
|
|
|
int i, next;
|
|
|
|
|
|
|
|
m_pathNodes[nodeId].bDisabled = disable;
|
|
|
|
if(m_pathNodes[nodeId].numLinks < 3)
|
|
|
|
for(i = 0; i < m_pathNodes[nodeId].numLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
next = ConnectedNode(m_pathNodes[nodeId].firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_pathNodes[next].bDisabled != disable &&
|
|
|
|
m_pathNodes[next].numLinks < 3)
|
|
|
|
SwitchOffNodeAndNeighbours(next, disable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::SwitchRoadsOffInArea(float x1, float x2, float y1, float y2, float z1, float z2, bool disable)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
for(i = 0; i < m_numCarPathNodes; i++){
|
|
|
|
CVector pos = m_pathNodes[i].GetPosition();
|
|
|
|
if(x1 <= pos.x && pos.x <= x2 &&
|
|
|
|
y1 <= pos.y && pos.y <= y2 &&
|
|
|
|
z1 <= pos.z && pos.z <= z2 &&
|
2019-10-14 18:13:23 +00:00
|
|
|
disable != m_pathNodes[i].bDisabled)
|
2019-08-09 17:42:18 +00:00
|
|
|
SwitchOffNodeAndNeighbours(i, disable);
|
2020-05-03 13:57:57 +00:00
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::SwitchPedRoadsOffInArea(float x1, float x2, float y1, float y2, float z1, float z2, bool disable)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
for(i = m_numCarPathNodes; i < m_numPathNodes; i++){
|
|
|
|
CVector pos = m_pathNodes[i].GetPosition();
|
|
|
|
if(x1 <= pos.x && pos.x <= x2 &&
|
|
|
|
y1 <= pos.y && pos.y <= y2 &&
|
|
|
|
z1 <= pos.z && pos.z <= z2 &&
|
2019-10-14 18:13:23 +00:00
|
|
|
disable != m_pathNodes[i].bDisabled)
|
2019-08-09 17:42:18 +00:00
|
|
|
SwitchOffNodeAndNeighbours(i, disable);
|
2020-05-03 13:57:57 +00:00
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: unused (still needed for script here)
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
2019-10-14 18:13:23 +00:00
|
|
|
CPathFind::SwitchRoadsInAngledArea(float x1, float y1, float z1, float x2, float y2, float z2, float length, uint8 type, uint8 mode)
|
2019-08-09 17:42:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int firstNode, lastNode;
|
|
|
|
|
2019-10-14 19:58:22 +00:00
|
|
|
// this is NOT PATH_CAR
|
|
|
|
if(type != 0){
|
2019-08-09 17:42:18 +00:00
|
|
|
firstNode = 0;
|
|
|
|
lastNode = m_numCarPathNodes;
|
|
|
|
}else{
|
|
|
|
firstNode = m_numCarPathNodes;
|
|
|
|
lastNode = m_numPathNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(z1 > z2){
|
2019-10-14 19:58:22 +00:00
|
|
|
float tmp = z2;
|
|
|
|
z2 = z1;
|
|
|
|
z1 = tmp;
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// angle of vector from p2 to p1
|
|
|
|
float angle = CGeneral::GetRadianAngleBetweenPoints(x1, y1, x2, y2) + HALFPI;
|
2019-10-14 18:13:23 +00:00
|
|
|
while(angle < 0.0f) angle += TWOPI;
|
2019-08-09 17:42:18 +00:00
|
|
|
while(angle > TWOPI) angle -= TWOPI;
|
|
|
|
// vector from p1 to p2
|
|
|
|
CVector2D v12(x2 - x1, y2 - y1);
|
|
|
|
float len12 = v12.Magnitude();
|
2019-10-14 18:13:23 +00:00
|
|
|
v12 /= len12;
|
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
// vector from p2 to new point p3
|
2019-10-14 18:13:23 +00:00
|
|
|
CVector2D v23(Sin(angle)*length, -(Cos(angle)*length));
|
|
|
|
v23 /= v23.Magnitude(); // obivously just 'length' but whatever
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2019-10-14 18:13:23 +00:00
|
|
|
bool disable = mode == SWITCH_OFF;
|
2019-08-09 17:42:18 +00:00
|
|
|
for(i = firstNode; i < lastNode; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector pos = m_pathNodes[i].GetPosition();
|
|
|
|
if(pos.z < z1 || pos.z > z2)
|
2019-08-09 17:42:18 +00:00
|
|
|
continue;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector2D d(pos.x - x1, pos.y - y1);
|
2019-08-09 17:42:18 +00:00
|
|
|
float dot = DotProduct2D(d, v12);
|
|
|
|
if(dot < 0.0f || dot > len12)
|
|
|
|
continue;
|
|
|
|
dot = DotProduct2D(d, v23);
|
2019-10-14 18:13:23 +00:00
|
|
|
if(dot < 0.0f || dot > length)
|
2019-08-09 17:42:18 +00:00
|
|
|
continue;
|
|
|
|
if(m_pathNodes[i].bDisabled != disable)
|
|
|
|
SwitchOffNodeAndNeighbours(i, disable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: unused (still needed for script here)
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::MarkRoadsBetweenLevelsNodeAndNeighbours(int32 nodeId)
|
|
|
|
{
|
|
|
|
int i, next;
|
|
|
|
|
|
|
|
m_pathNodes[nodeId].bBetweenLevels = true;
|
|
|
|
if(m_pathNodes[nodeId].numLinks < 3)
|
|
|
|
for(i = 0; i < m_pathNodes[nodeId].numLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
next = ConnectedNode(m_pathNodes[nodeId].firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(!m_pathNodes[next].bBetweenLevels &&
|
|
|
|
m_pathNodes[next].numLinks < 3)
|
|
|
|
MarkRoadsBetweenLevelsNodeAndNeighbours(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: unused (still needed for script here)
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::MarkRoadsBetweenLevelsInArea(float x1, float x2, float y1, float y2, float z1, float z2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
for(i = 0; i < m_numPathNodes; i++){
|
|
|
|
CVector pos = m_pathNodes[i].GetPosition();
|
|
|
|
if(x1 < pos.x && pos.x < x2 &&
|
|
|
|
y1 < pos.y && pos.y < y2 &&
|
|
|
|
z1 < pos.z && pos.z < z2)
|
2019-08-09 17:42:18 +00:00
|
|
|
MarkRoadsBetweenLevelsNodeAndNeighbours(i);
|
2020-05-03 13:57:57 +00:00
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: unused (still needed for script here)
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
2020-02-16 20:08:54 +00:00
|
|
|
CPathFind::PedMarkRoadsBetweenLevelsInArea(float x1, float x2, float y1, float y2, float z1, float z2)
|
2019-08-09 17:42:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
for(i = m_numCarPathNodes; i < m_numPathNodes; i++){
|
|
|
|
CVector pos = m_pathNodes[i].GetPosition();
|
|
|
|
if(x1 < pos.x && pos.x < x2 &&
|
|
|
|
y1 < pos.y && pos.y < y2 &&
|
|
|
|
z1 < pos.z && pos.z < z2)
|
2019-08-09 17:42:18 +00:00
|
|
|
MarkRoadsBetweenLevelsNodeAndNeighbours(i);
|
2020-05-03 13:57:57 +00:00
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
int32
|
|
|
|
CPathFind::FindNodeClosestToCoors(CVector coors, uint8 type, float distLimit, bool ignoreDisabled, bool ignoreBetweenLevels)
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
int32
|
|
|
|
CPathFind::FindNodeClosestToCoors(CVector coors, uint8 type, float distLimit, bool ignoreDisabled, bool ignoreBetweenLevels, bool ignoreFlagB4, bool bWaterPath)
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int firstNode, lastNode;
|
|
|
|
float dist;
|
|
|
|
float closestDist = 10000.0f;
|
|
|
|
int closestNode = 0;
|
|
|
|
|
|
|
|
switch(type){
|
|
|
|
case PATH_CAR:
|
|
|
|
firstNode = 0;
|
|
|
|
lastNode = m_numCarPathNodes;
|
|
|
|
break;
|
|
|
|
case PATH_PED:
|
|
|
|
firstNode = m_numCarPathNodes;
|
|
|
|
lastNode = m_numPathNodes;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = firstNode; i < lastNode; i++){
|
|
|
|
if(ignoreDisabled && m_pathNodes[i].bDisabled) continue;
|
|
|
|
if(ignoreBetweenLevels && m_pathNodes[i].bBetweenLevels) continue;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
switch(m_pathNodes[i].unkBits){
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(ignoreFlagB4 && m_pathNodes[i].flagB4) continue;
|
|
|
|
if(bWaterPath != m_pathNodes[i].bWaterPath) continue;
|
|
|
|
#endif
|
|
|
|
dist = Abs(m_pathNodes[i].GetX() - coors.x) +
|
|
|
|
Abs(m_pathNodes[i].GetY() - coors.y) +
|
|
|
|
3.0f*Abs(m_pathNodes[i].GetZ() - coors.z);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(dist < closestDist){
|
|
|
|
closestDist = dist;
|
|
|
|
closestNode = i;
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
return closestDist < distLimit ? closestNode : -1;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
int32
|
|
|
|
CPathFind::FindNodeClosestToCoorsFavourDirection(CVector coors, uint8 type, float dirX, float dirY)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int firstNode, lastNode;
|
|
|
|
float dist, dX, dY;
|
|
|
|
NormalizeXY(dirX, dirY);
|
|
|
|
float closestDist = 10000.0f;
|
|
|
|
int closestNode = 0;
|
|
|
|
|
|
|
|
switch(type){
|
|
|
|
case PATH_CAR:
|
|
|
|
firstNode = 0;
|
|
|
|
lastNode = m_numCarPathNodes;
|
|
|
|
break;
|
|
|
|
case PATH_PED:
|
|
|
|
firstNode = m_numCarPathNodes;
|
|
|
|
lastNode = m_numPathNodes;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = firstNode; i < lastNode; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
switch(m_pathNodes[i].unkBits){
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
|
|
|
dX = m_pathNodes[i].GetX() - coors.x;
|
|
|
|
dY = m_pathNodes[i].GetY() - coors.y;
|
2019-08-09 17:42:18 +00:00
|
|
|
dist = Abs(dX) + Abs(dY) +
|
2020-05-03 13:57:57 +00:00
|
|
|
3.0f*Abs(m_pathNodes[i].GetZ() - coors.z);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(dist < closestDist){
|
|
|
|
NormalizeXY(dX, dY);
|
|
|
|
dist -= (dX*dirX + dY*dirY - 1.0f)*20.0f;
|
|
|
|
if(dist < closestDist){
|
|
|
|
closestDist = dist;
|
|
|
|
closestNode = i;
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
return closestNode;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
float
|
|
|
|
CPathFind::FindNodeOrientationForCarPlacement(int32 nodeId)
|
|
|
|
{
|
|
|
|
if(m_pathNodes[nodeId].numLinks == 0)
|
2020-02-25 19:01:56 +00:00
|
|
|
return 0.0f;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector dir = m_pathNodes[ConnectedNode(m_pathNodes[nodeId].firstLink)].GetPosition() - m_pathNodes[nodeId].GetPosition();
|
2019-08-09 17:42:18 +00:00
|
|
|
dir.z = 0.0f;
|
|
|
|
dir.Normalise();
|
|
|
|
return RADTODEG(dir.Heading());
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: unused (still needed for script here)
|
2019-08-09 17:42:18 +00:00
|
|
|
float
|
|
|
|
CPathFind::FindNodeOrientationForCarPlacementFacingDestination(int32 nodeId, float x, float y, bool towards)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector targetDir(x - m_pathNodes[nodeId].GetX(), y - m_pathNodes[nodeId].GetY(), 0.0f);
|
2019-08-09 17:42:18 +00:00
|
|
|
targetDir.Normalise();
|
|
|
|
CVector dir;
|
|
|
|
|
|
|
|
if(m_pathNodes[nodeId].numLinks == 0)
|
2020-02-25 19:01:56 +00:00
|
|
|
return 0.0f;
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
int bestNode = ConnectedNode(m_pathNodes[nodeId].firstLink);
|
2019-08-09 17:42:18 +00:00
|
|
|
#ifdef FIX_BUGS
|
|
|
|
float bestDot = towards ? -2.0f : 2.0f;
|
|
|
|
#else
|
|
|
|
int bestDot = towards ? -2 : 2; // why int?
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(i = 0; i < m_pathNodes[nodeId].numLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
dir = m_pathNodes[ConnectedNode(m_pathNodes[nodeId].firstLink + i)].GetPosition() - m_pathNodes[nodeId].GetPosition();
|
2019-08-09 17:42:18 +00:00
|
|
|
dir.z = 0.0f;
|
|
|
|
dir.Normalise();
|
|
|
|
float angle = DotProduct2D(dir, targetDir);
|
|
|
|
if(towards){
|
|
|
|
if(angle > bestDot){
|
|
|
|
bestDot = angle;
|
2020-05-03 13:57:57 +00:00
|
|
|
bestNode = ConnectedNode(m_pathNodes[nodeId].firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(angle < bestDot){
|
|
|
|
bestDot = angle;
|
2020-05-03 13:57:57 +00:00
|
|
|
bestNode = ConnectedNode(m_pathNodes[nodeId].firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
dir = m_pathNodes[bestNode].GetPosition() - m_pathNodes[nodeId].GetPosition();
|
2019-08-09 17:42:18 +00:00
|
|
|
dir.z = 0.0f;
|
|
|
|
dir.Normalise();
|
|
|
|
return RADTODEG(dir.Heading());
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
// no "New" in MIAMI
|
|
|
|
//--MIAMI: TODO
|
2019-08-09 17:42:18 +00:00
|
|
|
bool
|
|
|
|
CPathFind::NewGenerateCarCreationCoors(float x, float y, float dirX, float dirY, float spawnDist, float angleLimit, bool forward, CVector *pPosition, int32 *pNode1, int32 *pNode2, float *pPositionBetweenNodes, bool ignoreDisabled)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int node1, node2;
|
|
|
|
float dist1, dist2, d1, d2;
|
|
|
|
|
|
|
|
if(m_numCarPathNodes == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(i = 0; i < 500; i++){
|
|
|
|
node1 = (CGeneral::GetRandomNumber()>>3) % m_numCarPathNodes;
|
|
|
|
if(m_pathNodes[node1].bDisabled && !ignoreDisabled)
|
|
|
|
continue;
|
2020-05-03 13:57:57 +00:00
|
|
|
dist1 = Distance2D(m_pathNodes[node1].GetPosition(), x, y);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(dist1 < spawnDist + 60.0f){
|
|
|
|
d1 = dist1 - spawnDist;
|
|
|
|
for(j = 0; j < m_pathNodes[node1].numLinks; j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
node2 = ConnectedNode(m_pathNodes[node1].firstLink + j);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_pathNodes[node2].bDisabled && !ignoreDisabled)
|
|
|
|
continue;
|
2020-05-03 13:57:57 +00:00
|
|
|
dist2 = Distance2D(m_pathNodes[node2].GetPosition(), x, y);
|
2019-08-09 17:42:18 +00:00
|
|
|
d2 = dist2 - spawnDist;
|
|
|
|
if(d1*d2 < 0.0f){
|
|
|
|
// nodes are on different sides of spawn distance
|
|
|
|
float f2 = Abs(d1)/(Abs(d1) + Abs(d2));
|
|
|
|
float f1 = 1.0f - f2;
|
|
|
|
*pPositionBetweenNodes = f2;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector pos = m_pathNodes[node1].GetPosition()*f1 + m_pathNodes[node2].GetPosition()*f2;
|
2019-08-09 17:42:18 +00:00
|
|
|
CVector2D dist2d(pos.x - x, pos.y - y);
|
|
|
|
dist2d.Normalise(); // done manually in the game
|
|
|
|
float dot = DotProduct2D(dist2d, CVector2D(dirX, dirY));
|
|
|
|
if(forward){
|
|
|
|
if(dot > angleLimit){
|
|
|
|
*pNode1 = node1;
|
|
|
|
*pNode2 = node2;
|
|
|
|
*pPosition = pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(dot <= angleLimit){
|
|
|
|
*pNode1 = node1;
|
|
|
|
*pNode2 = node2;
|
|
|
|
*pPosition = pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: TODO
|
2019-08-09 17:42:18 +00:00
|
|
|
bool
|
|
|
|
CPathFind::GeneratePedCreationCoors(float x, float y, float minDist, float maxDist, float minDistOffScreen, float maxDistOffScreen, CVector *pPosition, int32 *pNode1, int32 *pNode2, float *pPositionBetweenNodes, CMatrix *camMatrix)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int node1, node2;
|
|
|
|
|
|
|
|
if(m_numPedPathNodes == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(i = 0; i < 400; i++){
|
|
|
|
node1 = m_numCarPathNodes + CGeneral::GetRandomNumber() % m_numPedPathNodes;
|
2020-05-03 13:57:57 +00:00
|
|
|
if(DistanceSqr2D(m_pathNodes[node1].GetPosition(), x, y) < sq(maxDist+30.0f)){
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_pathNodes[node1].numLinks == 0)
|
|
|
|
continue;
|
|
|
|
int link = m_pathNodes[node1].firstLink + CGeneral::GetRandomNumber() % m_pathNodes[node1].numLinks;
|
2020-05-03 13:57:57 +00:00
|
|
|
if(ConnectionCrossesRoad(link))
|
2019-08-09 17:42:18 +00:00
|
|
|
continue;
|
2020-05-03 13:57:57 +00:00
|
|
|
node2 = ConnectedNode(link);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_pathNodes[node1].bDisabled || m_pathNodes[node2].bDisabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
float f2 = (CGeneral::GetRandomNumber()&0xFF)/256.0f;
|
|
|
|
float f1 = 1.0f - f2;
|
|
|
|
*pPositionBetweenNodes = f2;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector pos = m_pathNodes[node1].GetPosition()*f1 + m_pathNodes[node2].GetPosition()*f2;
|
2019-08-09 17:42:18 +00:00
|
|
|
if(Distance2D(pos, x, y) < maxDist+20.0f){
|
|
|
|
pos.x += ((CGeneral::GetRandomNumber()&0xFF)-128)*0.01f;
|
|
|
|
pos.y += ((CGeneral::GetRandomNumber()&0xFF)-128)*0.01f;
|
|
|
|
float dist = Distance2D(pos, x, y);
|
|
|
|
|
|
|
|
bool visible;
|
|
|
|
if(camMatrix)
|
|
|
|
visible = TheCamera.IsSphereVisible(pos, 2.0f, camMatrix);
|
|
|
|
else
|
|
|
|
visible = TheCamera.IsSphereVisible(pos, 2.0f);
|
|
|
|
if(!visible){
|
|
|
|
minDist = minDistOffScreen;
|
|
|
|
maxDist = maxDistOffScreen;
|
|
|
|
}
|
|
|
|
if(minDist < dist && dist < maxDist){
|
|
|
|
*pNode1 = node1;
|
|
|
|
*pNode2 = node2;
|
|
|
|
*pPosition = pos;
|
|
|
|
|
|
|
|
bool found;
|
|
|
|
float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z+2.0f, &found);
|
|
|
|
if(!found)
|
|
|
|
return false;
|
|
|
|
if(Abs(groundZ - pos.z) > 3.0f)
|
|
|
|
return false;
|
|
|
|
pPosition->z = groundZ;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
CTreadable*
|
|
|
|
CPathFind::FindRoadObjectClosestToCoors(CVector coors, uint8 type)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
int node1, node2;
|
|
|
|
CTreadable *closestMapObj = nil;
|
|
|
|
float closestDist = 10000.0f;
|
|
|
|
|
|
|
|
for(i = 0; i < m_numMapObjects; i++){
|
|
|
|
CTreadable *mapObj = m_mapObjects[i];
|
|
|
|
if(mapObj->m_nodeIndices[type][0] < 0)
|
|
|
|
continue;
|
|
|
|
CVector vDist = mapObj->GetPosition() - coors;
|
|
|
|
float fDist = Abs(vDist.x) + Abs(vDist.y) + Abs(vDist.z);
|
|
|
|
if(fDist < 200.0f || fDist < closestDist)
|
|
|
|
for(j = 0; j < 12; j++){
|
|
|
|
node1 = mapObj->m_nodeIndices[type][j];
|
|
|
|
if(node1 < 0)
|
|
|
|
break;
|
|
|
|
// FIX: game uses ThePaths here explicitly
|
|
|
|
for(k = 0; k < m_pathNodes[node1].numLinks; k++){
|
2020-05-03 13:57:57 +00:00
|
|
|
node2 = ConnectedNode(m_pathNodes[node1].firstLink + k);
|
|
|
|
float lineDist = CCollision::DistToLine(&m_pathNodes[node1].GetPosition(), &m_pathNodes[node2].GetPosition(), &coors);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(lineDist < closestDist){
|
|
|
|
closestDist = lineDist;
|
2020-05-03 13:57:57 +00:00
|
|
|
if((coors - m_pathNodes[node1].GetPosition()).MagnitudeSqr() < (coors - m_pathNodes[node2].GetPosition()).MagnitudeSqr())
|
2019-08-09 17:42:18 +00:00
|
|
|
closestMapObj = m_mapObjects[m_pathNodes[node1].objectIndex];
|
|
|
|
else
|
|
|
|
closestMapObj = m_mapObjects[m_pathNodes[node2].objectIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return closestMapObj;
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#endif
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
|
|
|
CPathFind::FindNextNodeWandering(uint8 type, CVector coors, CPathNode **lastNode, CPathNode **nextNode, uint8 curDir, uint8 *nextDir)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CPathNode *node;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
if(lastNode == nil || (node = *lastNode) == nil || (coors - (*lastNode)->GetPosition()).MagnitudeSqr() > 7.0f){
|
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
// need to find the node we're coming from
|
|
|
|
node = nil;
|
|
|
|
CTreadable *obj = FindRoadObjectClosestToCoors(coors, type);
|
|
|
|
float nodeDist = 1000000000.0f;
|
|
|
|
for(i = 0; i < 12; i++){
|
2019-10-13 21:33:18 +00:00
|
|
|
if(obj->m_nodeIndices[type][i] < 0)
|
2019-08-09 17:42:18 +00:00
|
|
|
break;
|
2020-05-03 13:57:57 +00:00
|
|
|
float dist = (coors - m_pathNodes[obj->m_nodeIndices[type][i]].GetPosition()).MagnitudeSqr();
|
2019-08-09 17:42:18 +00:00
|
|
|
if(dist < nodeDist){
|
|
|
|
nodeDist = dist;
|
|
|
|
node = &m_pathNodes[obj->m_nodeIndices[type][i]];
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
int32 nodeIdx = FindNodeClosestToCoors(coors, type, 999999.88f);
|
|
|
|
node = &m_pathNodes[nodeIdx];
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2019-10-13 21:33:18 +00:00
|
|
|
CVector2D vCurDir(Sin(curDir*PI/4.0f), Cos(curDir * PI / 4.0f));
|
2019-08-09 17:42:18 +00:00
|
|
|
*nextNode = 0;
|
|
|
|
float bestDot = -999999.0f;
|
|
|
|
for(i = 0; i < node->numLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
int next = ConnectedNode(node->firstLink+i);
|
2019-10-13 21:33:18 +00:00
|
|
|
if(!node->bDisabled && m_pathNodes[next].bDisabled)
|
2019-08-09 17:42:18 +00:00
|
|
|
continue;
|
|
|
|
CVector pedCoors = coors;
|
|
|
|
pedCoors.z += 1.0f;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector nodeCoors = m_pathNodes[next].GetPosition();
|
2019-08-09 17:42:18 +00:00
|
|
|
nodeCoors.z += 1.0f;
|
|
|
|
if(!CWorld::GetIsLineOfSightClear(pedCoors, nodeCoors, true, false, false, false, false, false))
|
|
|
|
continue;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector2D nodeDir = m_pathNodes[next].GetPosition() - node->GetPosition();
|
2019-10-13 21:33:18 +00:00
|
|
|
nodeDir.Normalise();
|
2019-08-09 17:42:18 +00:00
|
|
|
float dot = DotProduct2D(nodeDir, vCurDir);
|
2019-10-13 21:33:18 +00:00
|
|
|
if(dot >= bestDot){
|
2019-08-09 17:42:18 +00:00
|
|
|
*nextNode = &m_pathNodes[next];
|
|
|
|
bestDot = dot;
|
|
|
|
|
|
|
|
// direction is 0, 2, 4, 6 for north, east, south, west
|
2020-05-03 13:57:57 +00:00
|
|
|
// this could be done simpler...
|
2019-08-09 17:42:18 +00:00
|
|
|
if(nodeDir.x < 0.0f){
|
|
|
|
if(2.0f*Abs(nodeDir.y) < -nodeDir.x)
|
|
|
|
*nextDir = 6; // west
|
|
|
|
else if(-2.0f*nodeDir.x < nodeDir.y)
|
|
|
|
*nextDir = 0; // north
|
|
|
|
else if(2.0f*nodeDir.x > nodeDir.y)
|
|
|
|
*nextDir = 4; // south
|
|
|
|
else if(nodeDir.y > 0.0f)
|
|
|
|
*nextDir = 7; // north west
|
|
|
|
else
|
|
|
|
*nextDir = 5; // south west`
|
|
|
|
}else{
|
|
|
|
if(2.0f*Abs(nodeDir.y) < nodeDir.x)
|
|
|
|
*nextDir = 2; // east
|
|
|
|
else if(2.0f*nodeDir.x < nodeDir.y)
|
|
|
|
*nextDir = 0; // north
|
|
|
|
else if(-2.0f*nodeDir.x > nodeDir.y)
|
|
|
|
*nextDir = 4; // south
|
|
|
|
else if(nodeDir.y > 0.0f)
|
|
|
|
*nextDir = 1; // north east
|
|
|
|
else
|
|
|
|
*nextDir = 3; // south east`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(*nextNode == nil){
|
|
|
|
*nextDir = 0;
|
|
|
|
*nextNode = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
static CPathNode *apNodesToBeCleared[4995];
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
static CPathNode *apNodesToBeCleared[6525];
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
2020-05-03 13:57:57 +00:00
|
|
|
CPathFind::DoPathSearch(uint8 type, CVector start, int32 startNodeId, CVector target, CPathNode **nodes, int16 *pNumNodes, int16 maxNumNodes, CVehicle *vehicle, float *pDist, float distLimit, int32 targetNodeId)
|
2019-08-09 17:42:18 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
// Find target
|
2020-05-03 13:57:57 +00:00
|
|
|
if(targetNodeId < 0)
|
|
|
|
targetNodeId = FindNodeClosestToCoors(target, type, distLimit);
|
|
|
|
if(targetNodeId < 0) {
|
2020-04-19 16:34:08 +00:00
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 100000.0f;
|
|
|
|
return;
|
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
|
|
|
|
// Find start
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
int numPathsToTry;
|
|
|
|
CTreadable *startObj;
|
2019-10-12 22:35:01 +00:00
|
|
|
if(startNodeId < 0){
|
2019-08-09 17:42:18 +00:00
|
|
|
if(vehicle == nil || (startObj = vehicle->m_treadable[type]) == nil)
|
|
|
|
startObj = FindRoadObjectClosestToCoors(start, type);
|
|
|
|
numPathsToTry = 0;
|
2019-10-12 22:35:01 +00:00
|
|
|
for(i = 0; i < 12; i++){
|
|
|
|
if(startObj->m_nodeIndices[type][i] < 0)
|
|
|
|
break;
|
2020-05-03 13:57:57 +00:00
|
|
|
if(m_pathNodes[startObj->m_nodeIndices[type][i]].group == m_pathNodes[targetNodeId].group)
|
2019-08-09 17:42:18 +00:00
|
|
|
numPathsToTry++;
|
|
|
|
}
|
2019-10-12 22:35:01 +00:00
|
|
|
}else{
|
2019-08-09 17:42:18 +00:00
|
|
|
numPathsToTry = 1;
|
|
|
|
startObj = m_mapObjects[m_pathNodes[startNodeId].objectIndex];
|
|
|
|
}
|
2020-04-19 16:34:08 +00:00
|
|
|
if(numPathsToTry == 0) {
|
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 100000.0f;
|
|
|
|
return;
|
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2019-10-12 22:35:01 +00:00
|
|
|
if(startNodeId < 0){
|
2019-08-09 17:42:18 +00:00
|
|
|
// why only check node 0?
|
2020-04-19 16:34:08 +00:00
|
|
|
if(m_pathNodes[startObj->m_nodeIndices[type][0]].group !=
|
2020-05-03 13:57:57 +00:00
|
|
|
m_pathNodes[targetNodeId].group) {
|
2020-04-19 16:34:08 +00:00
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 100000.0f;
|
|
|
|
return;
|
|
|
|
}
|
2019-10-12 22:35:01 +00:00
|
|
|
}else{
|
2020-05-03 13:57:57 +00:00
|
|
|
if(m_pathNodes[startNodeId].group != m_pathNodes[targetNodeId].group) {
|
2020-04-19 16:34:08 +00:00
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 100000.0f;
|
|
|
|
return;
|
|
|
|
}
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(startNodeId < 0)
|
|
|
|
startNodeId = FindNodeClosestToCoors(start, type, 999999.88f);
|
|
|
|
if(startNodeId < 0) {
|
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 100000.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(startNodeId == targetNodeId){
|
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 0.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_pathNodes[startNodeId].group != m_pathNodes[targetNodeId].group) {
|
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist) *pDist = 100000.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
for(i = 0; i < ARRAY_SIZE(m_searchNodes); i++)
|
|
|
|
m_searchNodes[i].SetNext(nil);
|
|
|
|
AddNodeToList(&m_pathNodes[targetNodeId], 0);
|
2019-08-09 17:42:18 +00:00
|
|
|
int numNodesToBeCleared = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
apNodesToBeCleared[numNodesToBeCleared++] = &m_pathNodes[targetNodeId];
|
2019-08-09 17:42:18 +00:00
|
|
|
|
|
|
|
// Dijkstra's algorithm
|
|
|
|
// Find distances
|
|
|
|
int numPathsFound = 0;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
|
|
|
if(startNodeId < 0 && m_mapObjects[m_pathNodes[targetNodeId].objectIndex] == startObj)
|
2019-08-09 17:42:18 +00:00
|
|
|
numPathsFound++;
|
|
|
|
for(i = 0; numPathsFound < numPathsToTry; i = (i+1) & 0x1FF){
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
for(i = 0; numPathsFound == 0; i = (i+1) & 0x1FF){
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
CPathNode *node;
|
2020-05-03 13:57:57 +00:00
|
|
|
for(node = m_searchNodes[i].GetNext(); node; node = node->GetNext()){
|
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_mapObjects[node->objectIndex] == startObj &&
|
|
|
|
(startNodeId < 0 || node == &m_pathNodes[startNodeId]))
|
|
|
|
numPathsFound++;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
if(node == &m_pathNodes[startNodeId])
|
|
|
|
numPathsFound = 1;
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
|
|
|
|
for(j = 0; j < node->numLinks; j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
int next = ConnectedNode(node->firstLink + j);
|
2019-08-09 17:42:18 +00:00
|
|
|
int dist = node->distance + m_distances[node->firstLink + j];
|
|
|
|
if(dist < m_pathNodes[next].distance){
|
|
|
|
if(m_pathNodes[next].distance != MAX_DIST)
|
|
|
|
RemoveNodeFromList(&m_pathNodes[next]);
|
|
|
|
if(m_pathNodes[next].distance == MAX_DIST)
|
|
|
|
apNodesToBeCleared[numNodesToBeCleared++] = &m_pathNodes[next];
|
|
|
|
AddNodeToList(&m_pathNodes[next], dist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveNodeFromList(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find out whence to start tracing back
|
|
|
|
CPathNode *curNode;
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
if(startNodeId < 0){
|
|
|
|
int minDist = MAX_DIST;
|
|
|
|
*pNumNodes = 1;
|
|
|
|
for(i = 0; i < 12; i++){
|
|
|
|
if(startObj->m_nodeIndices[type][i] < 0)
|
|
|
|
break;
|
2020-05-03 13:57:57 +00:00
|
|
|
int dist = (m_pathNodes[startObj->m_nodeIndices[type][i]].GetPosition() - start).Magnitude();
|
2019-08-09 17:42:18 +00:00
|
|
|
if(m_pathNodes[startObj->m_nodeIndices[type][i]].distance + dist < minDist){
|
|
|
|
minDist = m_pathNodes[startObj->m_nodeIndices[type][i]].distance + dist;
|
|
|
|
curNode = &m_pathNodes[startObj->m_nodeIndices[type][i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(maxNumNodes == 0){
|
|
|
|
*pNumNodes = 0;
|
|
|
|
}else{
|
|
|
|
nodes[0] = curNode;
|
|
|
|
*pNumNodes = 1;
|
|
|
|
}
|
|
|
|
if(pDist)
|
|
|
|
*pDist = minDist;
|
2020-05-03 13:57:57 +00:00
|
|
|
}else
|
|
|
|
#endif
|
|
|
|
{
|
2019-08-09 17:42:18 +00:00
|
|
|
curNode = &m_pathNodes[startNodeId];
|
|
|
|
*pNumNodes = 0;
|
|
|
|
if(pDist)
|
|
|
|
*pDist = m_pathNodes[startNodeId].distance;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifdef MIAMI
|
|
|
|
nodes[(*pNumNodes)++] = curNode;
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
// Trace back to target and update list of nodes
|
2020-05-03 13:57:57 +00:00
|
|
|
while(*pNumNodes < maxNumNodes && curNode != &m_pathNodes[targetNodeId])
|
2019-08-09 17:42:18 +00:00
|
|
|
for(i = 0; i < curNode->numLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
int next = ConnectedNode(curNode->firstLink + i);
|
2019-08-09 17:42:18 +00:00
|
|
|
if(curNode->distance - m_distances[curNode->firstLink + i] == m_pathNodes[next].distance){
|
|
|
|
curNode = &m_pathNodes[next];
|
|
|
|
nodes[(*pNumNodes)++] = curNode;
|
|
|
|
i = 29030; // could have used a break...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < numNodesToBeCleared; i++)
|
|
|
|
apNodesToBeCleared[i]->distance = MAX_DIST;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CPathNode *pNodeList[32];
|
|
|
|
static int16 DummyResult;
|
|
|
|
static int16 DummyResult2;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
bool
|
|
|
|
CPathFind::TestCoorsCloseness(CVector target, uint8 type, CVector start)
|
|
|
|
{
|
|
|
|
float dist;
|
2020-05-03 13:57:57 +00:00
|
|
|
|
2019-08-09 17:42:18 +00:00
|
|
|
if(type == PATH_CAR)
|
|
|
|
DoPathSearch(type, start, -1, target, pNodeList, &DummyResult, 32, nil, &dist, 999999.88f, -1);
|
|
|
|
else
|
|
|
|
DoPathSearch(type, start, -1, target, nil, &DummyResult2, 0, nil, &dist, 50.0f, -1);
|
|
|
|
if(type == PATH_CAR)
|
2020-05-03 13:57:57 +00:00
|
|
|
#ifndef MIAMI
|
2019-08-09 17:42:18 +00:00
|
|
|
return dist < 160.0f;
|
2020-05-03 13:57:57 +00:00
|
|
|
#else
|
|
|
|
return dist < 150.0f;
|
|
|
|
#endif
|
2019-08-09 17:42:18 +00:00
|
|
|
else
|
|
|
|
return dist < 100.0f;
|
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
2019-10-08 20:07:11 +00:00
|
|
|
CPathFind::Save(uint8 *buf, uint32 *size)
|
2019-08-09 17:42:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n = m_numPathNodes/8 + 1;
|
|
|
|
|
2019-10-08 20:07:11 +00:00
|
|
|
*size = 2*n;
|
2019-08-09 17:42:18 +00:00
|
|
|
|
|
|
|
for(i = 0; i < m_numPathNodes; i++)
|
|
|
|
if(m_pathNodes[i].bDisabled)
|
2019-10-08 20:07:11 +00:00
|
|
|
buf[i/8] |= 1 << i%8;
|
2019-08-09 17:42:18 +00:00
|
|
|
else
|
2019-10-08 20:07:11 +00:00
|
|
|
buf[i/8] &= ~(1 << i%8);
|
2019-08-09 17:42:18 +00:00
|
|
|
|
|
|
|
for(i = 0; i < m_numPathNodes; i++)
|
|
|
|
if(m_pathNodes[i].bBetweenLevels)
|
2019-10-08 20:07:11 +00:00
|
|
|
buf[i/8 + n] |= 1 << i%8;
|
2019-08-09 17:42:18 +00:00
|
|
|
else
|
2019-10-08 20:07:11 +00:00
|
|
|
buf[i/8 + n] &= ~(1 << i%8);
|
2019-08-09 17:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
//--MIAMI: done
|
2019-08-09 17:42:18 +00:00
|
|
|
void
|
2019-10-08 20:07:11 +00:00
|
|
|
CPathFind::Load(uint8 *buf, uint32 size)
|
2019-08-09 17:42:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int n = m_numPathNodes/8 + 1;
|
|
|
|
|
|
|
|
for(i = 0; i < m_numPathNodes; i++)
|
2019-10-08 20:07:11 +00:00
|
|
|
if(buf[i/8] & (1 << i%8))
|
2019-08-09 17:42:18 +00:00
|
|
|
m_pathNodes[i].bDisabled = true;
|
|
|
|
else
|
|
|
|
m_pathNodes[i].bDisabled = false;
|
|
|
|
|
|
|
|
for(i = 0; i < m_numPathNodes; i++)
|
2019-10-08 20:07:11 +00:00
|
|
|
if(buf[i/8 + n] & (1 << i%8))
|
2019-08-09 17:42:18 +00:00
|
|
|
m_pathNodes[i].bBetweenLevels = true;
|
|
|
|
else
|
|
|
|
m_pathNodes[i].bBetweenLevels = false;
|
|
|
|
}
|
2019-07-04 11:04:34 +00:00
|
|
|
|
2020-04-10 16:36:39 +00:00
|
|
|
void
|
|
|
|
CPathFind::DisplayPathData(void)
|
|
|
|
{
|
|
|
|
// Not the function from mobm_carPathLinksile but my own!
|
|
|
|
|
|
|
|
int i, j, k;
|
|
|
|
// Draw 50 units around camera
|
|
|
|
CVector pos = TheCamera.GetPosition();
|
|
|
|
const float maxDist = 50.0f;
|
|
|
|
|
|
|
|
// Render car path nodes
|
|
|
|
if(gbShowCarPaths)
|
|
|
|
for(i = 0; i < m_numCarPathNodes; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
if((m_pathNodes[i].GetPosition() - pos).MagnitudeSqr() > SQR(maxDist))
|
2020-04-10 16:36:39 +00:00
|
|
|
continue;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector n1 = m_pathNodes[i].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
n1.z += 0.3f;
|
|
|
|
|
|
|
|
// Draw node itself
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
n1.x, n1.y, n1.z + 1.0f,
|
|
|
|
0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
for(j = 0; j < m_pathNodes[i].numLinks; j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
k = ConnectedNode(m_pathNodes[i].firstLink + j);
|
|
|
|
CVector n2 = m_pathNodes[k].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
n2.z += 0.3f;
|
|
|
|
// Draw links to neighbours
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
n2.x, n2.y, n2.z,
|
|
|
|
0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render car path nodes
|
|
|
|
if(gbShowCarPathsLinks)
|
|
|
|
for(i = 0; i < m_numCarPathLinks; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector2D n1_2d = m_carPathLinks[i].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
if((n1_2d - pos).MagnitudeSqr() > SQR(maxDist))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int ni = m_carPathLinks[i].pathNodeIndex;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector pn1 = m_pathNodes[ni].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
pn1.z += 0.3f;
|
|
|
|
CVector n1(n1_2d.x, n1_2d.y, pn1.z);
|
|
|
|
n1.z += 0.3f;
|
|
|
|
|
|
|
|
// Draw car node itself
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
n1.x, n1.y, n1.z + 1.0f,
|
|
|
|
0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z + 0.5f,
|
2020-05-03 13:57:57 +00:00
|
|
|
n1.x+m_carPathLinks[i].GetDirX(), n1.y+m_carPathLinks[i].GetDirY(), n1.z + 0.5f,
|
2020-04-10 16:36:39 +00:00
|
|
|
0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
// Draw connection to car path node
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
pn1.x, pn1.y, pn1.z,
|
|
|
|
0xFF0000FF, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
// traffic light type
|
|
|
|
uint32 col = 0xFF;
|
|
|
|
if((m_carPathLinks[i].trafficLightType&0x7F) == 1)
|
|
|
|
col += 0xFF000000;
|
|
|
|
if((m_carPathLinks[i].trafficLightType&0x7F) == 2)
|
|
|
|
col += 0x00FF0000;
|
|
|
|
if(m_carPathLinks[i].trafficLightType & 0x80)
|
|
|
|
col += 0x0000FF00;
|
|
|
|
CLines::RenderLineWithClipping(n1.x+0.2f, n1.y, n1.z,
|
|
|
|
n1.x+0.2f, n1.y, n1.z + 1.0f,
|
|
|
|
col, col);
|
|
|
|
|
|
|
|
for(j = 0; j < m_pathNodes[ni].numLinks; j++){
|
|
|
|
k = m_carPathConnections[m_pathNodes[ni].firstLink + j];
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector2D n2_2d = m_carPathLinks[k].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
int nk = m_carPathLinks[k].pathNodeIndex;
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector pn2 = m_pathNodes[nk].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
pn2.z += 0.3f;
|
|
|
|
CVector n2(n2_2d.x, n2_2d.y, pn2.z);
|
|
|
|
n2.z += 0.3f;
|
|
|
|
|
|
|
|
// Draw links to neighbours
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
n2.x, n2.y, n2.z,
|
|
|
|
0xFF00FFFF, 0xFF00FFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render ped path nodes
|
|
|
|
if(gbShowPedPaths)
|
|
|
|
for(i = m_numCarPathNodes; i < m_numPathNodes; i++){
|
2020-05-03 13:57:57 +00:00
|
|
|
if((m_pathNodes[i].GetPosition() - pos).MagnitudeSqr() > SQR(maxDist))
|
2020-04-10 16:36:39 +00:00
|
|
|
continue;
|
|
|
|
|
2020-05-03 13:57:57 +00:00
|
|
|
CVector n1 = m_pathNodes[i].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
n1.z += 0.3f;
|
|
|
|
|
|
|
|
// Draw node itself
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
n1.x, n1.y, n1.z + 1.0f,
|
|
|
|
0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
for(j = 0; j < m_pathNodes[i].numLinks; j++){
|
2020-05-03 13:57:57 +00:00
|
|
|
k = ConnectedNode(m_pathNodes[i].firstLink + j);
|
|
|
|
CVector n2 = m_pathNodes[k].GetPosition();
|
2020-04-10 16:36:39 +00:00
|
|
|
n2.z += 0.3f;
|
|
|
|
// Draw links to neighbours
|
|
|
|
CLines::RenderLineWithClipping(n1.x, n1.y, n1.z,
|
|
|
|
n2.x, n2.y, n2.z,
|
|
|
|
0xFFFFFFFF, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
// Draw connection flags
|
|
|
|
CVector mid = (n1+n2)/2.0f;
|
|
|
|
uint32 col = 0xFF;
|
2020-05-03 13:57:57 +00:00
|
|
|
if(ConnectionCrossesRoad(m_pathNodes[i].firstLink + j))
|
2020-04-10 16:36:39 +00:00
|
|
|
col += 0x00FF0000;
|
2020-05-03 13:57:57 +00:00
|
|
|
if(ConnectionHasTrafficLight(m_pathNodes[i].firstLink + j))
|
2020-04-10 16:36:39 +00:00
|
|
|
col += 0xFF000000;
|
|
|
|
CLines::RenderLineWithClipping(mid.x, mid.y, mid.z,
|
|
|
|
mid.x, mid.y, mid.z + 1.0f,
|
|
|
|
col, col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 13:57:57 +00:00
|
|
|
|
|
|
|
#ifdef MIAMI
|
|
|
|
CPathNode*
|
|
|
|
CPathFind::GetNode(int16 index)
|
|
|
|
{
|
|
|
|
if(index < 0)
|
|
|
|
return nil;
|
|
|
|
if(index < ARRAY_SIZE(ThePaths.m_searchNodes))
|
|
|
|
return &ThePaths.m_searchNodes[index];
|
|
|
|
return &ThePaths.m_pathNodes[index - ARRAY_SIZE(ThePaths.m_searchNodes)];
|
|
|
|
}
|
|
|
|
int16
|
|
|
|
CPathFind::GetIndex(CPathNode *node)
|
|
|
|
{
|
|
|
|
if(node == nil)
|
|
|
|
return -1;
|
|
|
|
if(node >= &ThePaths.m_searchNodes[0] && node < &ThePaths.m_searchNodes[ARRAY_SIZE(ThePaths.m_searchNodes)])
|
|
|
|
return node - ThePaths.m_searchNodes;
|
|
|
|
else
|
|
|
|
return (node - ThePaths.m_pathNodes) + ARRAY_SIZE(ThePaths.m_searchNodes);
|
|
|
|
}
|
|
|
|
#endif
|