From 22426597893f4818f2882e42de248c42a1f6152a Mon Sep 17 00:00:00 2001 From: themuffinator Date: Tue, 30 Dec 2025 22:01:23 +0000 Subject: [PATCH] Add BotResetLastAvoidReach export --- src/botlib/ai_move/bot_move.c | 41 ++++++++++++++++++++++++++++ src/botlib/ai_move/bot_move.h | 1 + src/botlib/interface/bot_interface.c | 18 ++++++++++++ src/q2bridge/botlib.h | 1 + 4 files changed, 61 insertions(+) diff --git a/src/botlib/ai_move/bot_move.c b/src/botlib/ai_move/bot_move.c index 1228f75..a55ea63 100644 --- a/src/botlib/ai_move/bot_move.c +++ b/src/botlib/ai_move/bot_move.c @@ -1696,6 +1696,47 @@ void BotMove_ResetAvoidReach(int movestate) memset(ms->avoidreachtries, 0, sizeof(ms->avoidreachtries)); } +/* +============= +BotResetLastAvoidReach + +Clear the most recent avoid reach entry. +============= +*/ +void BotResetLastAvoidReach(int movestate) +{ + int i; + int latest; + float latesttime; + bot_movestate_t *ms; + + ms = BotMoveStateFromHandle(movestate); + if (ms == NULL) + { + return; + } + + latesttime = 0.0f; + latest = 0; + for (i = 0; i < MAX_AVOIDREACH; i++) + { + if (ms->avoidreachtimes[i] > latesttime) + { + latesttime = ms->avoidreachtimes[i]; + latest = i; + } + } + + if (latesttime != 0.0f) + { + ms->avoidreachtimes[latest] = 0.0f; + if (ms->avoidreachtries[i] > 0) + { + ms->avoidreachtries[latest]--; + } + } +} + /* ============= BotReachabilityArea diff --git a/src/botlib/ai_move/bot_move.h b/src/botlib/ai_move/bot_move.h index 3fea103..fe9225b 100644 --- a/src/botlib/ai_move/bot_move.h +++ b/src/botlib/ai_move/bot_move.h @@ -165,6 +165,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 BotResetLastAvoidReach(int movestate); int BotReachabilityArea(const vec3_t origin, int client); int BotMovementViewTarget(int movestate, const bot_goal_t *goal, diff --git a/src/botlib/interface/bot_interface.c b/src/botlib/interface/bot_interface.c index 8df4dfd..59168f3 100644 --- a/src/botlib/interface/bot_interface.c +++ b/src/botlib/interface/bot_interface.c @@ -3358,6 +3358,23 @@ static void BotInterface_BotResetAvoidReach(int movestate) BotMove_ResetAvoidReach(movestate); } +/* +============= +BotInterface_BotResetLastAvoidReach + +Bridge reset helper for the most recent avoided reachability. +============= +*/ +static void BotInterface_BotResetLastAvoidReach(int movestate) +{ + if (!BotInterface_EnsureLibraryReady("BotResetLastAvoidReach")) + { + return; + } + + BotResetLastAvoidReach(movestate); +} + /* ============= BotInterface_BotReachabilityArea @@ -3715,6 +3732,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.BotReachabilityArea = BotInterface_BotReachabilityArea; exportTable.BotMovementViewTarget = BotInterface_BotMovementViewTarget; exportTable.BotPredictVisiblePosition = BotInterface_BotPredictVisiblePosition; diff --git a/src/q2bridge/botlib.h b/src/q2bridge/botlib.h index 0599454..898a238 100644 --- a/src/q2bridge/botlib.h +++ b/src/q2bridge/botlib.h @@ -264,6 +264,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 (*BotReachabilityArea)(vec3_t origin, int client); int (*BotMovementViewTarget)(int movestate, const bot_goal_t *goal, int travelflags, float lookahead, vec3_t target); int (*BotPredictVisiblePosition)(vec3_t origin, int areanum, const bot_goal_t *goal, int travelflags, vec3_t target);