removed bad code bits from pathfinding
fixed too long duck pressing in combat restore bits of player avoidance code
This commit is contained in:
parent
fa3efb431f
commit
1b1ae9ea91
7 changed files with 196 additions and 207 deletions
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
# This software is licensed under the BSD-style license.
|
||||
# Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
# http:#yapb.jeefo.net/license
|
||||
# http://yapb.jeefo.net/license
|
||||
#
|
||||
|
||||
MODNAME = yapb
|
||||
|
|
|
|||
|
|
@ -54,12 +54,12 @@
|
|||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v120_xp</PlatformToolset>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v120_xp</PlatformToolset>
|
||||
<PlatformToolset>v140_xp</PlatformToolset>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
|
|
@ -181,14 +181,14 @@
|
|||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<OmitFramePointers>false</OmitFramePointers>
|
||||
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
|
||||
<AdditionalIncludeDirectories>..\mmgr;..\include\engine;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<ExceptionHandling>Async</ExceptionHandling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<StructMemberAlignment>8Bytes</StructMemberAlignment>
|
||||
<StructMemberAlignment>Default</StructMemberAlignment>
|
||||
<BufferSecurityCheck>true</BufferSecurityCheck>
|
||||
<FunctionLevelLinking>false</FunctionLevelLinking>
|
||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||
|
|
@ -209,6 +209,7 @@
|
|||
<FlushDenormalResultsToZero>true</FlushDenormalResultsToZero>
|
||||
<Parallelization>false</Parallelization>
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
<Optimization>Full</Optimization>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
|
|
@ -225,7 +226,7 @@
|
|||
<OutputFile>.\release\yapb.dll</OutputFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DelayLoadDLLs>user32.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<GenerateDebugInformation>Debug</GenerateDebugInformation>
|
||||
<GenerateMapFile>false</GenerateMapFile>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<OptimizeReferences>false</OptimizeReferences>
|
||||
|
|
|
|||
|
|
@ -1080,7 +1080,7 @@ void Bot::CombatFight (void)
|
|||
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))
|
||||
m_duckTime = GetWorldTime () + 1.0f;
|
||||
m_duckTime = GetWorldTime () + 0.5f;
|
||||
|
||||
m_moveSpeed = 0.0;
|
||||
m_strafeSpeed = 0.0;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
else if (stricmp (arg0, "botmenu") == 0 || stricmp (arg0, "menu") == 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 ()))))
|
||||
{
|
||||
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 ()))
|
||||
|
|
@ -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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
extern ConVar yb_danger_factor;
|
||||
|
||||
if (yb_danger_factor.GetFloat () >= 4096)
|
||||
yb_danger_factor.SetFloat (4096.0);
|
||||
|
||||
if (g_bombPlanted)
|
||||
g_waypoint->SetBombPosition ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#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_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
|
||||
{
|
||||
// forcee bomber to select closest goal, if round-start goal was reset by something
|
||||
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
|
||||
{
|
||||
|
|
@ -314,8 +344,6 @@ void Bot::CheckTerrain (float movedDistance)
|
|||
|
||||
TraceResult tr;
|
||||
|
||||
// very cpu intensive
|
||||
#if 0
|
||||
ent = NULL;
|
||||
edict_t *pentNearest = NULL;
|
||||
|
||||
|
|
@ -348,7 +376,6 @@ void Bot::CheckTerrain (float movedDistance)
|
|||
m_moveSpeed = -pev->maxspeed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Standing still, no need to check?
|
||||
// FIXME: doesn't care for ladder movement (handled separately) should be included in some way
|
||||
|
|
@ -1235,94 +1262,93 @@ void Bot::FindShortestPath (int srcIndex, int destIndex)
|
|||
}
|
||||
}
|
||||
|
||||
// Priority queue class (smallest item out first)
|
||||
// priority queue class (smallest item out first, hlsdk)
|
||||
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:
|
||||
struct HeapNode_t
|
||||
struct Node
|
||||
{
|
||||
int id;
|
||||
float priority;
|
||||
} *m_heap;
|
||||
float pri;
|
||||
};
|
||||
|
||||
int m_size;
|
||||
int m_heapSize;
|
||||
Node *m_heap;
|
||||
|
||||
void HeapSiftDown (int);
|
||||
void HeapSiftUp (void);
|
||||
};
|
||||
public:
|
||||
|
||||
PriorityQueue::PriorityQueue (void)
|
||||
inline bool IsEmpty (void)
|
||||
{
|
||||
m_size = 0;
|
||||
m_heapSize = MAX_WAYPOINTS * 4;
|
||||
m_heap = (HeapNode_t *) malloc (sizeof (HeapNode_t) * m_heapSize);
|
||||
return m_size == 0;
|
||||
}
|
||||
|
||||
PriorityQueue::~PriorityQueue (void)
|
||||
inline PriorityQueue (int initialSize)
|
||||
{
|
||||
free (m_heap);
|
||||
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
|
||||
void PriorityQueue::Insert (int value, float priority)
|
||||
inline void Push (int value, float pri)
|
||||
{
|
||||
if (m_size >= m_heapSize)
|
||||
{
|
||||
m_heapSize += 100;
|
||||
m_heap = (HeapNode_t *)realloc (m_heap, sizeof (HeapNode_t) * m_heapSize);
|
||||
m_heap = (Node *) realloc (m_heap, sizeof (Node) * m_heapSize);
|
||||
|
||||
if (m_heap == NULL)
|
||||
TerminateOnMalloc ();
|
||||
ServerPrint ("REALLOCATING");
|
||||
}
|
||||
|
||||
m_heap[m_size].priority = priority;
|
||||
m_heap[m_size].pri = pri;
|
||||
m_heap[m_size].id = value;
|
||||
|
||||
m_size++;
|
||||
HeapSiftUp ();
|
||||
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
|
||||
int PriorityQueue::Remove (void)
|
||||
inline int Pop (void)
|
||||
{
|
||||
int retID = m_heap[0].id;
|
||||
int result = 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 parent = 0;
|
||||
int child = (2 * parent) + 1;
|
||||
|
||||
HeapNode_t ref = m_heap[parent];
|
||||
Node ref = m_heap[parent];
|
||||
|
||||
while (child < m_size)
|
||||
{
|
||||
int rightChild = (2 * parent) + 2;
|
||||
int right = (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)
|
||||
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];
|
||||
|
|
@ -1331,84 +1357,63 @@ void PriorityQueue::HeapSiftDown (int subRoot)
|
|||
child = (2 * parent) + 1;
|
||||
}
|
||||
m_heap[parent] = ref;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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)
|
||||
float gfunctionKillsDistT (int currentIndex, int parentIndex)
|
||||
{
|
||||
// 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 *parent = g_waypoint->GetPath (parentIndex);
|
||||
|
||||
for (int i = 0; i < MAX_PATH_INDEX; i++)
|
||||
{
|
||||
int neighbour = current->index[i];
|
||||
|
||||
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)
|
||||
cost *= 2;
|
||||
cost *= 1.5;
|
||||
|
||||
if (parentIndex < 0 || parentIndex > g_numWaypoints || parentIndex == currentIndex)
|
||||
return cost * (yb_danger_factor.GetInt () * 20 / (2 * g_highestDamageT));
|
||||
|
||||
return g_waypoint->GetPathDistance (parentIndex, currentIndex) + (cost * 10 * yb_danger_factor.GetInt ());
|
||||
return g_waypoint->GetPathDistance (parentIndex, currentIndex) + cost;
|
||||
}
|
||||
|
||||
|
||||
int gfunctionKillsDistCT (int currentIndex, int parentIndex)
|
||||
float gfunctionKillsDistCT (int currentIndex, int parentIndex)
|
||||
{
|
||||
// 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 *parent = g_waypoint->GetPath (parentIndex);
|
||||
|
||||
for (int i = 0; i < MAX_PATH_INDEX; i++)
|
||||
{
|
||||
int neighbour = current->index[i];
|
||||
|
||||
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)
|
||||
cost *= 2;
|
||||
cost *= 1.5;
|
||||
|
||||
if (parentIndex < 0 || parentIndex > g_numWaypoints || parentIndex == currentIndex)
|
||||
return cost * (yb_danger_factor.GetInt () * 20 / (2 * g_highestDamageCT));
|
||||
|
||||
return g_waypoint->GetPathDistance (parentIndex, currentIndex) + (cost * 10 * yb_danger_factor.GetInt ());
|
||||
return g_waypoint->GetPathDistance (parentIndex, currentIndex) + cost;
|
||||
}
|
||||
|
||||
int gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex)
|
||||
float gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex)
|
||||
{
|
||||
// least kills and number of nodes to goal for a team
|
||||
|
||||
|
|
@ -1418,16 +1423,16 @@ int gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex)
|
|||
return 65355;
|
||||
|
||||
else if (current->flags & (FLAG_CROUCH | FLAG_LADDER))
|
||||
return gfunctionKillsDistCT (currentIndex, parentIndex) * 5000;
|
||||
return gfunctionKillsDistCT (currentIndex, parentIndex) * 500;
|
||||
|
||||
return gfunctionKillsDistCT (currentIndex, parentIndex);
|
||||
}
|
||||
|
||||
int gfunctionKillsT (int currentIndex, int parentIndex)
|
||||
float gfunctionKillsT (int currentIndex, int parentIndex)
|
||||
{
|
||||
// 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);
|
||||
|
||||
|
|
@ -1436,20 +1441,23 @@ int gfunctionKillsT (int currentIndex, int parentIndex)
|
|||
int neighbour = current->index[i];
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -1458,31 +1466,34 @@ int gfunctionKillsCT (int currentIndex, int parentIndex)
|
|||
int neighbour = current->index[i];
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
if (parentIndex == -1)
|
||||
return 0;
|
||||
|
||||
Path *current = g_waypoint->GetPath (currentIndex);
|
||||
|
||||
if (current->flags & FLAG_NOHOSTAGE)
|
||||
return 65355;
|
||||
|
||||
else if (current->flags & (FLAG_CROUCH | FLAG_LADDER))
|
||||
return gfunctionKillsDistCT (currentIndex, parentIndex) * 5000;
|
||||
return gfunctionKillsDistCT (currentIndex, parentIndex) * 500;
|
||||
|
||||
return gfunctionKillsCT (currentIndex, parentIndex);
|
||||
}
|
||||
|
||||
int gfunctionPathDist (int currentIndex, int parentIndex)
|
||||
float gfunctionPathDist (int currentIndex, int parentIndex)
|
||||
{
|
||||
if (parentIndex == -1)
|
||||
return 0;
|
||||
|
|
@ -1504,19 +1515,20 @@ int gfunctionPathDist (int currentIndex, int parentIndex)
|
|||
return 65355;
|
||||
}
|
||||
|
||||
int gfunctionPathDistWithHostage (int currentIndex, int parentIndex)
|
||||
float gfunctionPathDistWithHostage (int currentIndex, int parentIndex)
|
||||
{
|
||||
Path *current = g_waypoint->GetPath (currentIndex);
|
||||
|
||||
if (current->flags & FLAG_NOHOSTAGE)
|
||||
return 65355;
|
||||
|
||||
else if (current->flags & (FLAG_CROUCH | FLAG_LADDER))
|
||||
return gfunctionPathDist (currentIndex, parentIndex) * 5000;
|
||||
return gfunctionPathDist (currentIndex, parentIndex) * 500;
|
||||
|
||||
return gfunctionPathDist (currentIndex, parentIndex);
|
||||
}
|
||||
|
||||
int hfunctionSquareDist (int index, int, int goalIndex)
|
||||
float hfunctionSquareDist (int index, int, int goalIndex)
|
||||
{
|
||||
// square distance heuristic
|
||||
|
||||
|
|
@ -1527,30 +1539,29 @@ int hfunctionSquareDist (int index, int, int goalIndex)
|
|||
float deltaY = fabsf (start->origin.y - goal->origin.y);
|
||||
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
|
||||
|
||||
if (g_waypoint->GetPath (startIndex)->flags & FLAG_NOHOSTAGE)
|
||||
return 65536;
|
||||
return 65355;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int hfunctionNumberNodes (int index, int startIndex, int goalIndex)
|
||||
float hfunctionNumberNodes (int index, int startIndex, int goalIndex)
|
||||
{
|
||||
return hfunctionSquareDist (index, startIndex, goalIndex) / 128 * g_highestKills;
|
||||
}
|
||||
|
||||
|
||||
void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
|
||||
{
|
||||
// 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;
|
||||
|
||||
// A* Stuff
|
||||
enum AStarState_t {OPEN, CLOSED, NEW};
|
||||
enum AStarState {OPEN, CLOSED, NEW};
|
||||
|
||||
struct AStar_t
|
||||
struct AStar
|
||||
{
|
||||
int g;
|
||||
int f;
|
||||
float g;
|
||||
float f;
|
||||
short parentIndex;
|
||||
AStarState_t state;
|
||||
AStarState state;
|
||||
} astar[MAX_WAYPOINTS];
|
||||
|
||||
PriorityQueue openList;
|
||||
PriorityQueue openList (MAX_WAYPOINTS * 0.5);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int (*gcalc) (int, int) = NULL;
|
||||
int (*hcalc) (int, int, int) = NULL;
|
||||
float (*gcalc) (int, int) = NULL;
|
||||
float (*hcalc) (int, int, int) = NULL;
|
||||
|
||||
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].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
|
||||
int currentIndex = openList.Remove ();
|
||||
int currentIndex = openList.Pop ();
|
||||
|
||||
// is the current node the goal node?
|
||||
if (currentIndex == destIndex)
|
||||
|
|
@ -1697,9 +1708,9 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType)
|
|||
continue;
|
||||
|
||||
// calculate the F value as F = G + H
|
||||
int g = astar[currentIndex].g + gcalc (currentChild, currentIndex);
|
||||
int h = hcalc (currentChild, srcIndex, destIndex);
|
||||
int f = g + h;
|
||||
float g = astar[currentIndex].g + gcalc (currentChild, currentIndex);
|
||||
float h = hcalc (currentChild, srcIndex, destIndex);
|
||||
float f = g + h;
|
||||
|
||||
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].f = f;
|
||||
|
||||
openList.Insert (currentChild, g);
|
||||
openList.Push (currentChild, g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,11 +110,11 @@ int Waypoint::FindNearest (Vector origin, float minDistance, int flags)
|
|||
|
||||
for (int i = 0; i < g_numWaypoints; i++)
|
||||
{
|
||||
float distance = (m_paths[i]->origin - origin).GetLength ();
|
||||
|
||||
if (flags != -1 && !(m_paths[i]->flags & flags))
|
||||
continue; // if flag not -1 and waypoint has no this flag, skip waypoint
|
||||
|
||||
float distance = (m_paths[i]->origin - origin).GetLength ();
|
||||
|
||||
if (distance < minDistance)
|
||||
{
|
||||
index = i;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue