Some PathFind fixes (not all)

This commit is contained in:
Sergeanur 2019-10-14 21:13:23 +03:00
parent 94b389ee16
commit 9d2b7a99b3
2 changed files with 23 additions and 15 deletions

View File

@ -795,9 +795,10 @@ CPathFind::SwitchRoadsOffInArea(float x1, float x2, float y1, float y2, float z1
int i; int i;
for(i = 0; i < m_numPathNodes; i++) for(i = 0; i < m_numPathNodes; i++)
if(x1 < m_pathNodes[i].pos.x && m_pathNodes[i].pos.x < x2 && if (x1 <= m_pathNodes[i].pos.x && m_pathNodes[i].pos.x <= x2 &&
y1 < m_pathNodes[i].pos.y && m_pathNodes[i].pos.y < y2 && y1 <= m_pathNodes[i].pos.y && m_pathNodes[i].pos.y <= y2 &&
z1 < m_pathNodes[i].pos.z && m_pathNodes[i].pos.z < z2) z1 <= m_pathNodes[i].pos.z && m_pathNodes[i].pos.z <= z2 &&
disable != m_pathNodes[i].bDisabled)
SwitchOffNodeAndNeighbours(i, disable); SwitchOffNodeAndNeighbours(i, disable);
} }
@ -807,14 +808,15 @@ CPathFind::SwitchPedRoadsOffInArea(float x1, float x2, float y1, float y2, float
int i; int i;
for(i = m_numCarPathNodes; i < m_numPathNodes; i++) for(i = m_numCarPathNodes; i < m_numPathNodes; i++)
if(x1 < m_pathNodes[i].pos.x && m_pathNodes[i].pos.x < x2 && if(x1 <= m_pathNodes[i].pos.x && m_pathNodes[i].pos.x <= x2 &&
y1 < m_pathNodes[i].pos.y && m_pathNodes[i].pos.y < y2 && y1 <= m_pathNodes[i].pos.y && m_pathNodes[i].pos.y <= y2 &&
z1 < m_pathNodes[i].pos.z && m_pathNodes[i].pos.z < z2) z1 <= m_pathNodes[i].pos.z && m_pathNodes[i].pos.z <= z2 &&
disable != m_pathNodes[i].bDisabled)
SwitchOffNodeAndNeighbours(i, disable); SwitchOffNodeAndNeighbours(i, disable);
} }
void void
CPathFind::SwitchRoadsInAngledArea(float x1, float y1, float z1, float x2, float y2, float z2, float length, uint8 type, uint8 enable) CPathFind::SwitchRoadsInAngledArea(float x1, float y1, float z1, float x2, float y2, float z2, float length, uint8 type, uint8 mode)
{ {
int i; int i;
int firstNode, lastNode; int firstNode, lastNode;
@ -835,18 +837,18 @@ CPathFind::SwitchRoadsInAngledArea(float x1, float y1, float z1, float x2, float
// angle of vector from p2 to p1 // angle of vector from p2 to p1
float angle = CGeneral::GetRadianAngleBetweenPoints(x1, y1, x2, y2) + HALFPI; float angle = CGeneral::GetRadianAngleBetweenPoints(x1, y1, x2, y2) + HALFPI;
while(angle < TWOPI) angle += TWOPI; while(angle < 0.0f) angle += TWOPI;
while(angle > TWOPI) angle -= TWOPI; while(angle > TWOPI) angle -= TWOPI;
// vector from p1 to p2 // vector from p1 to p2
CVector2D v12(x2 - x1, y2 - y1); CVector2D v12(x2 - x1, y2 - y1);
float len12 = v12.Magnitude(); float len12 = v12.Magnitude();
CVector2D vn12 = v12/len12; v12 /= len12;
// vector from p2 to new point p3
CVector2D v23(-Sin(angle)*length, Cos(angle)*length);
float len23 = v23.Magnitude(); // obivously just 'length' but whatever
CVector2D vn23 = v23/len23;
bool disable = !enable; // vector from p2 to new point p3
CVector2D v23(Sin(angle)*length, -(Cos(angle)*length));
v23 /= v23.Magnitude(); // obivously just 'length' but whatever
bool disable = mode == SWITCH_OFF;
for(i = firstNode; i < lastNode; i++){ for(i = firstNode; i < lastNode; i++){
if(m_pathNodes[i].pos.z < z1 || m_pathNodes[i].pos.z > z2) if(m_pathNodes[i].pos.z < z1 || m_pathNodes[i].pos.z > z2)
continue; continue;
@ -855,7 +857,7 @@ CPathFind::SwitchRoadsInAngledArea(float x1, float y1, float z1, float x2, float
if(dot < 0.0f || dot > len12) if(dot < 0.0f || dot > len12)
continue; continue;
dot = DotProduct2D(d, v23); dot = DotProduct2D(d, v23);
if(dot < 0.0f || dot > len23) if(dot < 0.0f || dot > length)
continue; continue;
if(m_pathNodes[i].bDisabled != disable) if(m_pathNodes[i].bDisabled != disable)
SwitchOffNodeAndNeighbours(i, disable); SwitchOffNodeAndNeighbours(i, disable);

View File

@ -15,6 +15,12 @@ enum
PATH_PED = 1, PATH_PED = 1,
}; };
enum
{
SWITCH_OFF = 0,
SWITCH_ON = 1,
};
struct CPathNode struct CPathNode
{ {
CVector pos; CVector pos;