removed bad code bits from pathfinding

fixed too long duck pressing in combat
restore bits of player avoidance code
This commit is contained in:
Dmitry 2015-06-06 14:19:19 +03:00
commit 1b1ae9ea91
7 changed files with 196 additions and 207 deletions

View file

@ -4,7 +4,7 @@
# #
# This software is licensed under the BSD-style license. # This software is licensed under the BSD-style license.
# Additional exceptions apply. For full license details, see LICENSE.txt or visit: # Additional exceptions apply. For full license details, see LICENSE.txt or visit:
# http:#yapb.jeefo.net/license # http://yapb.jeefo.net/license
# #
MODNAME = yapb MODNAME = yapb

View file

@ -54,12 +54,12 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v140_xp</PlatformToolset>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v140_xp</PlatformToolset>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@ -181,14 +181,14 @@
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers> <OmitFramePointers>false</OmitFramePointers>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations> <EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>..\mmgr;..\include\engine;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\mmgr;..\include\engine;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
<ExceptionHandling>Async</ExceptionHandling> <ExceptionHandling>Async</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<StructMemberAlignment>8Bytes</StructMemberAlignment> <StructMemberAlignment>Default</StructMemberAlignment>
<BufferSecurityCheck>true</BufferSecurityCheck> <BufferSecurityCheck>true</BufferSecurityCheck>
<FunctionLevelLinking>false</FunctionLevelLinking> <FunctionLevelLinking>false</FunctionLevelLinking>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
@ -209,6 +209,7 @@
<FlushDenormalResultsToZero>true</FlushDenormalResultsToZero> <FlushDenormalResultsToZero>true</FlushDenormalResultsToZero>
<Parallelization>false</Parallelization> <Parallelization>false</Parallelization>
<FloatingPointModel>Fast</FloatingPointModel> <FloatingPointModel>Fast</FloatingPointModel>
<Optimization>Full</Optimization>
</ClCompile> </ClCompile>
<ResourceCompile> <ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -225,7 +226,7 @@
<OutputFile>.\release\yapb.dll</OutputFile> <OutputFile>.\release\yapb.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner> <SuppressStartupBanner>true</SuppressStartupBanner>
<DelayLoadDLLs>user32.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs> <DelayLoadDLLs>user32.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>Debug</GenerateDebugInformation>
<GenerateMapFile>false</GenerateMapFile> <GenerateMapFile>false</GenerateMapFile>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<OptimizeReferences>false</OptimizeReferences> <OptimizeReferences>false</OptimizeReferences>

View file

@ -3390,7 +3390,7 @@ void Bot::RunTask (void)
destIndex = FindGoal (); destIndex = FindGoal ();
m_prevGoalIndex = destIndex; m_prevGoalIndex = destIndex;
m_chosenGoalIndex = destIndex; m_chosenGoalIndex = destIndex;
// remember index // remember index
GetTask ()->data = destIndex; GetTask ()->data = destIndex;

View file

@ -1080,7 +1080,7 @@ void Bot::CombatFight (void)
int nearestToEnemyPoint = g_waypoint->FindNearest (m_enemy->v.origin); int nearestToEnemyPoint = g_waypoint->FindNearest (m_enemy->v.origin);
if (shouldDuck && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && g_waypoint->IsDuckVisible (m_currentWaypointIndex, nearestToEnemyPoint)) if (shouldDuck && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && g_waypoint->IsDuckVisible (m_currentWaypointIndex, nearestToEnemyPoint))
m_duckTime = GetWorldTime () + 1.0f; m_duckTime = GetWorldTime () + 0.5f;
m_moveSpeed = 0.0; m_moveSpeed = 0.0;
m_strafeSpeed = 0.0; m_strafeSpeed = 0.0;

View file

@ -228,23 +228,6 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c
} }
} }
// sets health for all available bots
else if (stricmp (arg0, "sethealth") == 0 || stricmp (arg0, "health") == 0)
{
if (IsNullString (arg1))
ClientPrint (ent, print_withtag, "Please specify health");
else
{
ClientPrint (ent, print_withtag, "Bot health is set to %d%%", atoi (arg1));
for (int i = 0; i < GetMaxClients (); i++)
{
if (g_botManager->GetBot (i) != NULL)
g_botManager->GetBot (i)->pev->health = fabsf (atof (arg1));
}
}
}
// displays main bot menu // displays main bot menu
else if (stricmp (arg0, "botmenu") == 0 || stricmp (arg0, "menu") == 0) else if (stricmp (arg0, "botmenu") == 0 || stricmp (arg0, "menu") == 0)
DisplayMenuToClient (ent, &g_menus[0]); DisplayMenuToClient (ent, &g_menus[0]);
@ -2227,7 +2210,7 @@ void StartFrame (void)
else if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ())))) else if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ()))))
{ {
g_clients[i].flags &= ~CF_ADMIN; g_clients[i].flags &= ~CF_ADMIN;
ServerPrint ("Player %s had lost remote access to YaPB.", STRING (player->v.netname)); ServerPrint ("Player %s had lost remote access to yapb.", STRING (player->v.netname));
} }
} }
else if (IsNullString (yb_password_key.GetString ()) && IsNullString (yb_password.GetString ())) else if (IsNullString (yb_password_key.GetString ()) && IsNullString (yb_password.GetString ()))
@ -2235,7 +2218,7 @@ void StartFrame (void)
if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ()))) == 0) if (strcmp (yb_password.GetString (), INFOKEY_VALUE (GET_INFOKEYBUFFER (g_clients[i].ent), const_cast <char *> (yb_password_key.GetString ()))) == 0)
{ {
g_clients[i].flags |= CF_ADMIN; g_clients[i].flags |= CF_ADMIN;
ServerPrint ("Player %s had gained full remote access to YaPB.", STRING (player->v.netname)); ServerPrint ("Player %s had gained full remote access to yapb.", STRING (player->v.netname));
} }
} }
} }
@ -2250,12 +2233,6 @@ void StartFrame (void)
} }
g_timePerSecondUpdate = GetWorldTime () + 1.0f; g_timePerSecondUpdate = GetWorldTime () + 1.0f;
} }
extern ConVar yb_danger_factor;
if (yb_danger_factor.GetFloat () >= 4096)
yb_danger_factor.SetFloat (4096.0);
if (g_bombPlanted) if (g_bombPlanted)
g_waypoint->SetBombPosition (); g_waypoint->SetBombPosition ();
} }

View file

@ -9,8 +9,6 @@
#include <core.h> #include <core.h>
ConVar yb_danger_factor ("yb_danger_factor", "900", VT_NOSERVER);
ConVar yb_aim_method ("yb_aim_method", "3", VT_NOSERVER); ConVar yb_aim_method ("yb_aim_method", "3", VT_NOSERVER);
ConVar yb_aim_damper_coefficient_x ("yb_aim_damper_coefficient_x", "0.22", VT_NOSERVER); ConVar yb_aim_damper_coefficient_x ("yb_aim_damper_coefficient_x", "0.22", VT_NOSERVER);
@ -197,8 +195,40 @@ TacticChoosen:
} }
else if (tactic == 3 && !g_waypoint->m_goalPoints.IsEmpty ()) // map goal waypoint else if (tactic == 3 && !g_waypoint->m_goalPoints.IsEmpty ()) // map goal waypoint
{ {
// forcee bomber to select closest goal, if round-start goal was reset by something
if (m_hasC4 && g_timeRoundStart + 20.0f < GetWorldTime ()) if (m_hasC4 && g_timeRoundStart + 20.0f < GetWorldTime ())
{ {
float minDist = 1024.0f;
int count = 0;
for (int i = 0; i < g_numWaypoints; i++)
{
Path *path = g_waypoint->GetPath (i);
if (!(path->flags & FLAG_GOAL))
continue;
float distance = (path->origin - pev->origin).GetLength ();
if (distance < minDist)
{
if (count < 4)
{
goalChoices[count] = i;
count++;
}
minDist = distance;
}
}
for (int i = 0; i < 4; i++)
{
if (goalChoices[i] == -1)
{
goalChoices[i] = g_waypoint->m_goalPoints.GetRandomElement ();
InternalAssert (goalChoices[i] >= 0 && goalChoices[i] < g_numWaypoints);
}
}
} }
else else
{ {
@ -314,8 +344,6 @@ void Bot::CheckTerrain (float movedDistance)
TraceResult tr; TraceResult tr;
// very cpu intensive
#if 0
ent = NULL; ent = NULL;
edict_t *pentNearest = NULL; edict_t *pentNearest = NULL;
@ -348,7 +376,6 @@ void Bot::CheckTerrain (float movedDistance)
m_moveSpeed = -pev->maxspeed; m_moveSpeed = -pev->maxspeed;
} }
} }
#endif
// Standing still, no need to check? // Standing still, no need to check?
// FIXME: doesn't care for ladder movement (handled separately) should be included in some way // FIXME: doesn't care for ladder movement (handled separately) should be included in some way
@ -1235,180 +1262,158 @@ void Bot::FindShortestPath (int srcIndex, int destIndex)
} }
} }
// Priority queue class (smallest item out first) // priority queue class (smallest item out first, hlsdk)
class PriorityQueue class PriorityQueue
{ {
public:
PriorityQueue (void);
~PriorityQueue (void);
inline int Empty (void) { return m_size == 0; }
inline int Size (void) { return m_size; }
void Insert (int, float);
int Remove (void);
private: private:
struct HeapNode_t struct Node
{ {
int id; int id;
float priority; float pri;
} *m_heap; };
int m_size; int m_size;
int m_heapSize; int m_heapSize;
Node *m_heap;
void HeapSiftDown (int); public:
void HeapSiftUp (void);
inline bool IsEmpty (void)
{
return m_size == 0;
}
inline PriorityQueue (int initialSize)
{
m_size = 0;
m_heapSize = initialSize;
m_heap = new Node[m_heapSize];
}
inline ~PriorityQueue (void)
{
delete[] m_heap;
m_heap = NULL;
}
// inserts a value into the priority queue
inline void Push (int value, float pri)
{
if (m_size >= m_heapSize)
{
m_heapSize += 100;
m_heap = (Node *) realloc (m_heap, sizeof (Node) * m_heapSize);
ServerPrint ("REALLOCATING");
}
m_heap[m_size].pri = pri;
m_heap[m_size].id = value;
int child = ++m_size - 1;
while (child)
{
int parent = (child - 1) / 2;
if (m_heap[parent].pri <= m_heap[child].pri)
break;
Node ref = m_heap[child];
m_heap[child] = m_heap[parent];
m_heap[parent] = ref;
child = parent;
}
}
// removes the smallest item from the priority queue
inline int Pop (void)
{
int result = m_heap[0].id;
m_size--;
m_heap[0] = m_heap[m_size];
int parent = 0;
int child = (2 * parent) + 1;
Node ref = m_heap[parent];
while (child < m_size)
{
int right = (2 * parent) + 2;
if (right < m_size && m_heap[right].pri < m_heap[child].pri)
child = right;
if (ref.pri <= m_heap[child].pri)
break;
m_heap[parent] = m_heap[child];
parent = child;
child = (2 * parent) + 1;
}
m_heap[parent] = ref;
return result;
}
}; };
PriorityQueue::PriorityQueue (void)
{
m_size = 0;
m_heapSize = MAX_WAYPOINTS * 4;
m_heap = (HeapNode_t *) malloc (sizeof (HeapNode_t) * m_heapSize);
}
PriorityQueue::~PriorityQueue (void) float gfunctionKillsDistT (int currentIndex, int parentIndex)
{
free (m_heap);
m_heap = NULL;
}
// inserts a value into the priority queue
void PriorityQueue::Insert (int value, float priority)
{
if (m_size >= m_heapSize)
{
m_heapSize += 100;
m_heap = (HeapNode_t *)realloc (m_heap, sizeof (HeapNode_t) * m_heapSize);
if (m_heap == NULL)
TerminateOnMalloc ();
}
m_heap[m_size].priority = priority;
m_heap[m_size].id = value;
m_size++;
HeapSiftUp ();
}
// removes the smallest item from the priority queue
int PriorityQueue::Remove (void)
{
int retID = m_heap[0].id;
m_size--;
m_heap[0] = m_heap[m_size];
HeapSiftDown (0);
return retID;
}
void PriorityQueue::HeapSiftDown (int subRoot)
{
int parent = subRoot;
int child = (2 * parent) + 1;
HeapNode_t ref = m_heap[parent];
while (child < m_size)
{
int rightChild = (2 * parent) + 2;
if (rightChild < m_size)
{
if (m_heap[rightChild].priority < m_heap[child].priority)
child = rightChild;
}
if (ref.priority <= m_heap[child].priority)
break;
m_heap[parent] = m_heap[child];
parent = child;
child = (2 * parent) + 1;
}
m_heap[parent] = ref;
}
void PriorityQueue::HeapSiftUp (void)
{
int child = m_size - 1;
while (child)
{
int parent = (child - 1) / 2;
if (m_heap[parent].priority <= m_heap[child].priority)
break;
HeapNode_t temp = m_heap[child];
m_heap[child] = m_heap[parent];
m_heap[parent] = temp;
child = parent;
}
}
int gfunctionKillsDistT (int currentIndex, int parentIndex)
{ {
// least kills and number of nodes to goal for a team // least kills and number of nodes to goal for a team
int cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage + g_highestDamageT; if (parentIndex == -1)
return 0;
float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage + g_highestDamageT;
Path *current = g_waypoint->GetPath (currentIndex); Path *current = g_waypoint->GetPath (currentIndex);
Path *parent = g_waypoint->GetPath (parentIndex);
for (int i = 0; i < MAX_PATH_INDEX; i++) for (int i = 0; i < MAX_PATH_INDEX; i++)
{ {
int neighbour = current->index[i]; int neighbour = current->index[i];
if (neighbour != -1) if (neighbour != -1)
cost += (g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team0Damage * 0.3; cost += (g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team0Damage;
} }
if (current->flags & FLAG_CROUCH) if (current->flags & FLAG_CROUCH)
cost *= 2; cost *= 1.5;
if (parentIndex < 0 || parentIndex > g_numWaypoints || parentIndex == currentIndex) return g_waypoint->GetPathDistance (parentIndex, currentIndex) + cost;
return cost * (yb_danger_factor.GetInt () * 20 / (2 * g_highestDamageT));
return g_waypoint->GetPathDistance (parentIndex, currentIndex) + (cost * 10 * yb_danger_factor.GetInt ());
} }
int gfunctionKillsDistCT (int currentIndex, int parentIndex) float gfunctionKillsDistCT (int currentIndex, int parentIndex)
{ {
// least kills and number of nodes to goal for a team // least kills and number of nodes to goal for a team
int cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage + g_highestDamageCT; if (parentIndex == -1)
return 0;
float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage + g_highestDamageCT;
Path *current = g_waypoint->GetPath (currentIndex); Path *current = g_waypoint->GetPath (currentIndex);
Path *parent = g_waypoint->GetPath (parentIndex);
for (int i = 0; i < MAX_PATH_INDEX; i++) for (int i = 0; i < MAX_PATH_INDEX; i++)
{ {
int neighbour = current->index[i]; int neighbour = current->index[i];
if (neighbour != -1) if (neighbour != -1)
cost += static_cast <int> ((g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team1Damage * 0.3); cost += static_cast <int> ((g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team1Damage);
} }
if (current->flags & FLAG_CROUCH) if (current->flags & FLAG_CROUCH)
cost *= 2; cost *= 1.5;
if (parentIndex < 0 || parentIndex > g_numWaypoints || parentIndex == currentIndex) return g_waypoint->GetPathDistance (parentIndex, currentIndex) + cost;
return cost * (yb_danger_factor.GetInt () * 20 / (2 * g_highestDamageCT));
return g_waypoint->GetPathDistance (parentIndex, currentIndex) + (cost * 10 * yb_danger_factor.GetInt ());
} }
int gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex) float gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex)
{ {
// least kills and number of nodes to goal for a team // least kills and number of nodes to goal for a team
@ -1418,16 +1423,16 @@ int gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex)
return 65355; return 65355;
else if (current->flags & (FLAG_CROUCH | FLAG_LADDER)) else if (current->flags & (FLAG_CROUCH | FLAG_LADDER))
return gfunctionKillsDistCT (currentIndex, parentIndex) * 5000; return gfunctionKillsDistCT (currentIndex, parentIndex) * 500;
return gfunctionKillsDistCT (currentIndex, parentIndex); return gfunctionKillsDistCT (currentIndex, parentIndex);
} }
int gfunctionKillsT (int currentIndex, int parentIndex) float gfunctionKillsT (int currentIndex, int parentIndex)
{ {
// least kills to goal for a team // least kills to goal for a team
int cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage; float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage;
Path *current = g_waypoint->GetPath (currentIndex); Path *current = g_waypoint->GetPath (currentIndex);
@ -1436,20 +1441,23 @@ int gfunctionKillsT (int currentIndex, int parentIndex)
int neighbour = current->index[i]; int neighbour = current->index[i];
if (neighbour != -1) if (neighbour != -1)
cost += (g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team0Damage * 0.3; cost += (g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team0Damage;
} }
if (current->flags & FLAG_CROUCH) if (current->flags & FLAG_CROUCH)
cost *= 2; cost *= 1.5;
return cost * 10 * yb_danger_factor.GetInt (); return cost;
} }
int gfunctionKillsCT (int currentIndex, int parentIndex) float gfunctionKillsCT (int currentIndex, int parentIndex)
{ {
// least kills to goal for a team // least kills to goal for a team
int cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage; if (parentIndex == -1)
return 0;
float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage;
Path *current = g_waypoint->GetPath (currentIndex); Path *current = g_waypoint->GetPath (currentIndex);
@ -1458,31 +1466,34 @@ int gfunctionKillsCT (int currentIndex, int parentIndex)
int neighbour = current->index[i]; int neighbour = current->index[i];
if (neighbour != -1) if (neighbour != -1)
cost += (g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team1Damage * 0.3; cost += (g_experienceData + (neighbour * g_numWaypoints) + neighbour)->team1Damage;
} }
if (current->flags & FLAG_CROUCH) if (current->flags & FLAG_CROUCH)
cost *= 2; cost *= 1.5;
return cost * 10 * yb_danger_factor.GetInt (); return cost + 0.5f;
} }
int gfunctionKillsCTWithHostage (int currentIndex, int parentIndex) float gfunctionKillsCTWithHostage (int currentIndex, int parentIndex)
{ {
// least kills to goal for a team // least kills to goal for a team
if (parentIndex == -1)
return 0;
Path *current = g_waypoint->GetPath (currentIndex); Path *current = g_waypoint->GetPath (currentIndex);
if (current->flags & FLAG_NOHOSTAGE) if (current->flags & FLAG_NOHOSTAGE)
return 65355; return 65355;
else if (current->flags & (FLAG_CROUCH | FLAG_LADDER)) else if (current->flags & (FLAG_CROUCH | FLAG_LADDER))
return gfunctionKillsDistCT (currentIndex, parentIndex) * 5000; return gfunctionKillsDistCT (currentIndex, parentIndex) * 500;
return gfunctionKillsCT (currentIndex, parentIndex); return gfunctionKillsCT (currentIndex, parentIndex);
} }
int gfunctionPathDist (int currentIndex, int parentIndex) float gfunctionPathDist (int currentIndex, int parentIndex)
{ {
if (parentIndex == -1) if (parentIndex == -1)
return 0; return 0;
@ -1504,19 +1515,20 @@ int gfunctionPathDist (int currentIndex, int parentIndex)
return 65355; return 65355;
} }
int gfunctionPathDistWithHostage (int currentIndex, int parentIndex) float gfunctionPathDistWithHostage (int currentIndex, int parentIndex)
{ {
Path *current = g_waypoint->GetPath (currentIndex); Path *current = g_waypoint->GetPath (currentIndex);
if (current->flags & FLAG_NOHOSTAGE) if (current->flags & FLAG_NOHOSTAGE)
return 65355; return 65355;
else if (current->flags & (FLAG_CROUCH | FLAG_LADDER)) else if (current->flags & (FLAG_CROUCH | FLAG_LADDER))
return gfunctionPathDist (currentIndex, parentIndex) * 5000; return gfunctionPathDist (currentIndex, parentIndex) * 500;
return gfunctionPathDist (currentIndex, parentIndex); return gfunctionPathDist (currentIndex, parentIndex);
} }
int hfunctionSquareDist (int index, int, int goalIndex) float hfunctionSquareDist (int index, int, int goalIndex)
{ {
// square distance heuristic // square distance heuristic
@ -1527,30 +1539,29 @@ int hfunctionSquareDist (int index, int, int goalIndex)
float deltaY = fabsf (start->origin.y - goal->origin.y); float deltaY = fabsf (start->origin.y - goal->origin.y);
float deltaZ = fabsf (start->origin.z - goal->origin.z); float deltaZ = fabsf (start->origin.z - goal->origin.z);
return static_cast <int> (deltaX + deltaY + deltaZ); return static_cast <unsigned int> (deltaX + deltaY + deltaZ);
} }
int hfunctionSquareDistWithHostage (int index, int startIndex, int goalIndex) float hfunctionSquareDistWithHostage (int index, int startIndex, int goalIndex)
{ {
// square distance heuristic with hostages // square distance heuristic with hostages
if (g_waypoint->GetPath (startIndex)->flags & FLAG_NOHOSTAGE) if (g_waypoint->GetPath (startIndex)->flags & FLAG_NOHOSTAGE)
return 65536; return 65355;
return hfunctionSquareDist (index, startIndex, goalIndex); return hfunctionSquareDist (index, startIndex, goalIndex);
} }
int hfunctionNone (int index, int startIndex, int goalIndex) float hfunctionNone (int index, int startIndex, int goalIndex)
{ {
return hfunctionSquareDist (index, startIndex, goalIndex) / (128 * 10); return hfunctionSquareDist (index, startIndex, goalIndex) / (128 * 10);
} }
int hfunctionNumberNodes (int index, int startIndex, int goalIndex) float hfunctionNumberNodes (int index, int startIndex, int goalIndex)
{ {
return hfunctionSquareDist (index, startIndex, goalIndex) / 128 * g_highestKills; return hfunctionSquareDist (index, startIndex, goalIndex) / 128 * g_highestKills;
} }
void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType) void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
{ {
// this function finds a path from srcIndex to destIndex // this function finds a path from srcIndex to destIndex
@ -1573,17 +1584,17 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
m_goalValue = 0.0; m_goalValue = 0.0;
// A* Stuff // A* Stuff
enum AStarState_t {OPEN, CLOSED, NEW}; enum AStarState {OPEN, CLOSED, NEW};
struct AStar_t struct AStar
{ {
int g; float g;
int f; float f;
short parentIndex; short parentIndex;
AStarState_t state; AStarState state;
} astar[MAX_WAYPOINTS]; } astar[MAX_WAYPOINTS];
PriorityQueue openList; PriorityQueue openList (MAX_WAYPOINTS * 0.5);
for (int i = 0; i < MAX_WAYPOINTS; i++) for (int i = 0; i < MAX_WAYPOINTS; i++)
{ {
@ -1593,8 +1604,8 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
astar[i].state = NEW; astar[i].state = NEW;
} }
int (*gcalc) (int, int) = NULL; float (*gcalc) (int, int) = NULL;
int (*hcalc) (int, int, int) = NULL; float (*hcalc) (int, int, int) = NULL;
switch (pathType) switch (pathType)
{ {
@ -1653,12 +1664,12 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
astar[srcIndex].f = astar[srcIndex].g + hcalc (srcIndex, srcIndex, destIndex); astar[srcIndex].f = astar[srcIndex].g + hcalc (srcIndex, srcIndex, destIndex);
astar[srcIndex].state = OPEN; astar[srcIndex].state = OPEN;
openList.Insert (srcIndex, astar[srcIndex].g); openList.Push (srcIndex, astar[srcIndex].g);
while (!openList.Empty ()) while (!openList.IsEmpty ())
{ {
// remove the first node from the open list // remove the first node from the open list
int currentIndex = openList.Remove (); int currentIndex = openList.Pop ();
// is the current node the goal node? // is the current node the goal node?
if (currentIndex == destIndex) if (currentIndex == destIndex)
@ -1697,9 +1708,9 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
continue; continue;
// calculate the F value as F = G + H // calculate the F value as F = G + H
int g = astar[currentIndex].g + gcalc (currentChild, currentIndex); float g = astar[currentIndex].g + gcalc (currentChild, currentIndex);
int h = hcalc (currentChild, srcIndex, destIndex); float h = hcalc (currentChild, srcIndex, destIndex);
int f = g + h; float f = g + h;
if (astar[currentChild].state == NEW || astar[currentChild].f > f) if (astar[currentChild].state == NEW || astar[currentChild].f > f)
{ {
@ -1710,7 +1721,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
astar[currentChild].g = g; astar[currentChild].g = g;
astar[currentChild].f = f; astar[currentChild].f = f;
openList.Insert (currentChild, g); openList.Push (currentChild, g);
} }
} }
} }

View file

@ -110,11 +110,11 @@ int Waypoint::FindNearest (Vector origin, float minDistance, int flags)
for (int i = 0; i < g_numWaypoints; i++) for (int i = 0; i < g_numWaypoints; i++)
{ {
float distance = (m_paths[i]->origin - origin).GetLength ();
if (flags != -1 && !(m_paths[i]->flags & flags)) if (flags != -1 && !(m_paths[i]->flags & flags))
continue; // if flag not -1 and waypoint has no this flag, skip waypoint continue; // if flag not -1 and waypoint has no this flag, skip waypoint
float distance = (m_paths[i]->origin - origin).GetLength ();
if (distance < minDistance) if (distance < minDistance)
{ {
index = i; index = i;