Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion src/botlib/ai_move/bot_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ static void BotMove_RefreshAvoidReach(bot_movestate_t *ms)
}

float now = aasworld.time;
int latestIndex = -1;
float latestTime = 0.0f;
for (int i = 0; i < MAX_AVOIDREACH; ++i)
{
if (ms->avoidreach[i] <= 0)
Expand All @@ -673,8 +675,28 @@ static void BotMove_RefreshAvoidReach(bot_movestate_t *ms)
ms->avoidreach[i] = 0;
ms->avoidreachtimes[i] = 0.0f;
ms->avoidreachtries[i] = 0;
continue;
}
}

if (ms->avoidreachtimes[i] > latestTime)
{
latestTime = ms->avoidreachtimes[i];
latestIndex = i;
}
}

ms->lastavoidreachindex = latestIndex;
ms->lastavoidreachtime = latestTime;
if (latestIndex >= 0)
{
ms->lastavoidreach = ms->avoidreach[latestIndex];
ms->lastavoidreachtries = ms->avoidreachtries[latestIndex];
}
else
{
ms->lastavoidreach = 0;
ms->lastavoidreachtries = 0;
}
}

static bool BotMove_ShouldAvoidReach(const bot_movestate_t *ms, int reachnum)
Expand Down Expand Up @@ -1509,5 +1531,39 @@ void BotMove_ResetAvoidReach(int movestate)
memset(ms->avoidreach, 0, sizeof(ms->avoidreach));
memset(ms->avoidreachtimes, 0, sizeof(ms->avoidreachtimes));
memset(ms->avoidreachtries, 0, sizeof(ms->avoidreachtries));
ms->lastavoidreach = 0;
ms->lastavoidreachtime = 0.0f;
ms->lastavoidreachtries = 0;
ms->lastavoidreachindex = -1;
}

/*
=============
BotMove_ResetLastAvoidReach

Clears the most recently avoided reachability timer and decrements its tries.
=============
*/
void BotMove_ResetLastAvoidReach(int movestate)
{
bot_movestate_t *ms = BotMoveStateFromHandle(movestate);
if (ms == NULL)
{
return;
}

if (ms->lastavoidreachtime <= 0.0f ||
ms->lastavoidreachindex < 0 ||
ms->lastavoidreachindex >= MAX_AVOIDREACH)
{
return;
}

ms->avoidreachtimes[ms->lastavoidreachindex] = 0.0f;
if (ms->avoidreachtries[ms->lastavoidreachindex] > 0)
{
ms->avoidreachtries[ms->lastavoidreachindex]--;
}

BotMove_RefreshAvoidReach(ms);
}
18 changes: 11 additions & 7 deletions src/botlib/ai_move/bot_move.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ typedef struct bot_movestate_s
float lastgrappledist;
float reachability_time;

int avoidreach[MAX_AVOIDREACH];
float avoidreachtimes[MAX_AVOIDREACH];
int avoidreachtries[MAX_AVOIDREACH];

bot_avoidspot_t avoidspots[MAX_AVOIDSPOTS];
int numavoidspots;
int avoidreach[MAX_AVOIDREACH];
float avoidreachtimes[MAX_AVOIDREACH];
int avoidreachtries[MAX_AVOIDREACH];
int lastavoidreach;
float lastavoidreachtime;
int lastavoidreachtries;
int lastavoidreachindex;

bot_avoidspot_t avoidspots[MAX_AVOIDSPOTS];
int numavoidspots;
} bot_movestate_t;

int BotAllocMoveState(void);
Expand All @@ -165,6 +169,7 @@ void BotMoveToGoal(bot_moveresult_t *result,
int BotMoveInDirection(int movestate, const vec3_t dir, float speed, int type);

void BotMove_ResetAvoidReach(int movestate);
void BotMove_ResetLastAvoidReach(int movestate);

void AI_MoveFrame(bot_moveresult_t *result,
int movestate,
Expand All @@ -176,4 +181,3 @@ bot_moveresult_t BotTravel_Grapple(bot_movestate_t *ms, const struct aas_reachab
#ifdef __cplusplus
} /* extern "C" */
#endif

19 changes: 18 additions & 1 deletion src/botlib/interface/bot_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,23 @@ static void BotInterface_BotResetAvoidReach(int movestate)
BotMove_ResetAvoidReach(movestate);
}

/*
=============
BotInterface_BotResetLastAvoidReach

Resets the most recent avoid-reach entry in the movement state.
=============
*/
static void BotInterface_BotResetLastAvoidReach(int movestate)
{
if (!BotInterface_EnsureLibraryReady("BotResetLastAvoidReach"))
{
return;
}

BotMove_ResetLastAvoidReach(movestate);
}

static int BotInterface_BotAllocWeaponState(void)
{
if (!BotInterface_EnsureLibraryReady("BotAllocWeaponState"))
Expand Down Expand Up @@ -3454,6 +3471,7 @@ GLADIATOR_API bot_export_t *GetBotAPI(bot_import_t *import)
exportTable.BotMoveToGoal = BotInterface_BotMoveToGoal;
exportTable.BotMoveInDirection = BotInterface_BotMoveInDirection;
exportTable.BotResetAvoidReach = BotInterface_BotResetAvoidReach;
exportTable.BotResetLastAvoidReach = BotInterface_BotResetLastAvoidReach;
exportTable.BotLoadCharacter = BotLoadCharacter;
exportTable.BotFreeCharacter = BotFreeCharacter;
exportTable.BotLoadCharacterSkill = BotLoadCharacterSkill;
Expand Down Expand Up @@ -3485,4 +3503,3 @@ GLADIATOR_API bot_export_t *GetBotAPI(bot_import_t *import)

return &exportTable;
}

1 change: 1 addition & 0 deletions src/q2bridge/botlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ typedef struct bot_export_s {
void (*BotMoveToGoal)(bot_moveresult_t *result, int movestate, const bot_goal_t *goal, int travelflags);
int (*BotMoveInDirection)(int movestate, const vec3_t dir, float speed, int type);
void (*BotResetAvoidReach)(int movestate);
void (*BotResetLastAvoidReach)(int movestate);
int (*BotLoadCharacter)(const char *character_file, float skill);
void (*BotFreeCharacter)(int handle);
int (*BotLoadCharacterSkill)(const char *character_file, float skill);
Expand Down
Loading