From 2f2c4dfb00db8e7e3792e1e7ce9917f76be228b0 Mon Sep 17 00:00:00 2001 From: themuffinator Date: Tue, 30 Dec 2025 22:01:55 +0000 Subject: [PATCH] Add BotResetLastAvoidReach export --- src/botlib/ai_move/bot_move.c | 36 ++++++++++++++++++++++++++++ src/botlib/ai_move/bot_move.h | 1 + src/botlib/interface/bot_interface.c | 20 +++++++++++++++- src/q2bridge/botlib.h | 1 + 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/botlib/ai_move/bot_move.c b/src/botlib/ai_move/bot_move.c index 1228f75..4d6be06 100644 --- a/src/botlib/ai_move/bot_move.c +++ b/src/botlib/ai_move/bot_move.c @@ -1696,6 +1696,42 @@ void BotMove_ResetAvoidReach(int movestate) memset(ms->avoidreachtries, 0, sizeof(ms->avoidreachtries)); } +/* +============= +BotResetLastAvoidReach + +Clear the most recently avoided reachability timer without resetting the full list. +============= +*/ +void BotResetLastAvoidReach(int movestate) +{ + bot_movestate_t *ms = BotMoveStateFromHandle(movestate); + if (ms == NULL) + { + return; + } + + int latest = -1; + float latesttime = 0.0f; + for (int i = 0; i < MAX_AVOIDREACH; ++i) + { + if (ms->avoidreachtimes[i] > latesttime) + { + latesttime = ms->avoidreachtimes[i]; + latest = i; + } + } + + if (latest >= 0 && latesttime > 0.0f) + { + ms->avoidreachtimes[latest] = 0.0f; + if (ms->avoidreachtries[latest] > 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..a433ee8 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 + +Expose last-avoid reachability resets through the botlib API. +============= +*/ +static void BotInterface_BotResetLastAvoidReach(int movestate) +{ + if (!BotInterface_EnsureLibraryReady("BotResetLastAvoidReach")) + { + return; + } + + BotResetLastAvoidReach(movestate); +} + /* ============= BotInterface_BotReachabilityArea @@ -3712,9 +3729,10 @@ GLADIATOR_API bot_export_t *GetBotAPI(bot_import_t *import) exportTable.BotFreeMoveState = BotInterface_BotFreeMoveState; exportTable.BotResetMoveState = BotInterface_BotResetMoveState; exportTable.BotInitMoveState = BotInterface_BotInitMoveState; - exportTable.BotMoveToGoal = BotInterface_BotMoveToGoal; + 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..c1f5969 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);