fix(ground-ai): harden drive ownership, teardown and failure switch
Address two issues found in the first isolated 2.61.0.58 live runs and add a test switch to disable silent fallback to stock movement: - Add navigation.returnToStockOnFailure in tuning/ground-ai.jsonc (default true), compiled into WTO_AI_NAV_RETURN_TO_STOCK and written to wto_ws.cfg as ground_ai_return_to_stock=0 when disabled. When false, failed or timed-out bots keep stock movement paused, brake in place and log the failure once instead of silently handing control back to stock tankBot. - Allow holdMs=0 release actions even after local_mp_is_host() flips false during mission unload, add eid=0 bulk release on wto_reset_runtime(), and match slots by eid rather than live owner lookup so match exit cleans up the native control table immediately. - Stop releasing drive ownership when a vehicle is immobilized by damage or repair; brake in place and pause the echo watchdog instead, avoiding the 1-second release/re-acquire flapping observed during combat. Log exact release reasons and back off for 1 second if MoveSystem.inactive is cleared externally. Verified MSVC build of wto_ws.dll (0 warnings in project C sources), root and launcher type checks, 14/14 check-patches on 2.61.0.58, and a temporary 2.61.0.58 game copy build confirming ground_ai_return_to_stock=0 in wto_ws.cfg and 15 packed daScript modules. Live battle re-check pending.
This commit is contained in:
1 parent
89242e91f0
commit
73bae4785f
11 files changed
+116
-27
No files matched your search
@@ -5,6 +5,8 @@
|
||||
* port=<local server port> without a valid port the hooks still answer every host name
|
||||
* locally but refuse every connection that would leave the machine
|
||||
* log=0|1 optional, defaults to 1; when 0, wto_ws.log is not opened
|
||||
* ground_ai_return_to_stock=0|1 optional, defaults to 1; when 0, timed-out ground AI control
|
||||
* stays paused instead of returning to stock tankBot (testing)
|
||||
* exe.time_date_stamp=0x... the executable the native values were resolved for
|
||||
* exe.size_of_image=0x...
|
||||
* native.<name>=<value> what the LocalMP modules need from the executable: RVAs of
|
||||
@@ -35,6 +37,7 @@ static wchar_t g_folder[MAX_PATH];
|
||||
static CRITICAL_SECTION g_log_lock;
|
||||
static FILE *g_log;
|
||||
static int g_log_enabled = 1;
|
||||
static int g_ground_ai_return_to_stock = 1;
|
||||
static NativeValue g_native[NATIVE_VALUES_MAX];
|
||||
static size_t g_native_count;
|
||||
static int64_t g_exe_time_date_stamp = -1;
|
||||
@@ -102,6 +105,8 @@ static void read_settings(void)
|
||||
read_port(line + 5);
|
||||
else if (strncmp(line, "log=", 4) == 0)
|
||||
g_log_enabled = atoi(line + 4) != 0;
|
||||
else if (strncmp(line, "ground_ai_return_to_stock=", 26) == 0)
|
||||
g_ground_ai_return_to_stock = atoi(line + 26) != 0;
|
||||
else if (strncmp(line, "exe.time_date_stamp=", 20) == 0)
|
||||
parse_value(line + 20, &g_exe_time_date_stamp);
|
||||
else if (strncmp(line, "exe.size_of_image=", 18) == 0)
|
||||
@@ -138,6 +143,11 @@ int config_native_matches_executable(void)
|
||||
(int64_t)nt->OptionalHeader.SizeOfImage == g_exe_size_of_image;
|
||||
}
|
||||
|
||||
int config_ground_ai_return_to_stock(void)
|
||||
{
|
||||
return g_ground_ai_return_to_stock;
|
||||
}
|
||||
|
||||
void config_load(HMODULE self)
|
||||
{
|
||||
wchar_t path[MAX_PATH];
|
||||
|
||||
@@ -13,3 +13,5 @@ void describe_address(const struct sockaddr *name, int length, char *text, size_
|
||||
int config_native_value(const char *name, int64_t *value);
|
||||
/* Whether the settings were resolved for the executable this process runs (PE time stamp and size). */
|
||||
int config_native_matches_executable(void);
|
||||
/* Whether timed-out ground AI control returns to stock tankBot (wto_ws.cfg "ground_ai_return_to_stock="); 1 by default. */
|
||||
int config_ground_ai_return_to_stock(void);
|
||||
@@ -21,6 +21,7 @@ typedef struct GroundAiDriveControl {
|
||||
uint8_t *move_system;
|
||||
uint32_t eid;
|
||||
float remaining_seconds;
|
||||
int stalled_logged;
|
||||
} GroundAiDriveControl;
|
||||
|
||||
static MissionActionFn orig_mission_action;
|
||||
@@ -58,25 +59,40 @@ static void give_back_drive(GroundAiDriveControl *control, const char *reason)
|
||||
memset(control, 0, sizeof(*control));
|
||||
}
|
||||
|
||||
static void release_by_eid(uint32_t eid, const char *reason)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(controls) / sizeof(controls[0]); i++) {
|
||||
if (controls[i].unit == NULL)
|
||||
continue;
|
||||
if (eid == 0 || controls[i].eid == eid)
|
||||
give_back_drive(&controls[i], reason);
|
||||
}
|
||||
}
|
||||
|
||||
static void update_drive_control(uint32_t eid, uint32_t hold_ms)
|
||||
{
|
||||
uint8_t *unit = (uint8_t *)g_lmp_get_unit_by_eid(eid);
|
||||
uint8_t *move_system = get_move_system(unit);
|
||||
uint8_t *owner = move_system ? get_bot_owner(unit, eid) : NULL;
|
||||
uint8_t *unit;
|
||||
uint8_t *move_system;
|
||||
uint8_t *owner;
|
||||
GroundAiDriveControl *control;
|
||||
uint8_t *inactive;
|
||||
|
||||
if (hold_ms == 0) {
|
||||
release_by_eid(eid, eid == 0 ? "mission reset" : "script released");
|
||||
return;
|
||||
}
|
||||
if (eid == 0 || !local_mp_is_host())
|
||||
return;
|
||||
unit = (uint8_t *)g_lmp_get_unit_by_eid(eid);
|
||||
move_system = get_move_system(unit);
|
||||
owner = move_system ? get_bot_owner(unit, eid) : NULL;
|
||||
if (owner == NULL)
|
||||
return;
|
||||
control = &controls[owner[LMP_MP_OFF_PID]];
|
||||
if (control->unit != NULL &&
|
||||
(control->eid != eid || control->unit != unit || control->move_system != move_system))
|
||||
give_back_drive(control, "vehicle changed");
|
||||
if (hold_ms == 0) {
|
||||
if (control->unit != NULL)
|
||||
give_back_drive(control, "script released");
|
||||
return;
|
||||
}
|
||||
|
||||
inactive = move_system + g_lmp.ground_ai_move_inactive;
|
||||
if (control->unit == NULL) {
|
||||
@@ -89,6 +105,7 @@ static void update_drive_control(uint32_t eid, uint32_t hold_ms)
|
||||
log_line("local_mp: ground AI acquired drive eid=%#lx", (unsigned long)eid);
|
||||
}
|
||||
control->remaining_seconds = (float)hold_ms / 1000.0f;
|
||||
control->stalled_logged = 0;
|
||||
}
|
||||
|
||||
static int read_uint(const void *blk, const char *key, uint32_t *out)
|
||||
@@ -115,8 +132,9 @@ static void __fastcall hook_mission_action(const char *name, const void *blk)
|
||||
orig_mission_action(name, blk);
|
||||
return;
|
||||
}
|
||||
if (blk == NULL || !local_mp_is_host() ||
|
||||
!read_uint(blk, "eid", &eid) || eid == 0 || !read_uint(blk, "holdMs", &hold_ms))
|
||||
if (blk == NULL || !read_uint(blk, "eid", &eid) || !read_uint(blk, "holdMs", &hold_ms))
|
||||
return;
|
||||
if (hold_ms > 0 && (eid == 0 || !local_mp_is_host()))
|
||||
return;
|
||||
AcquireSRWLockExclusive(&control_lock);
|
||||
update_drive_control(eid, hold_ms);
|
||||
@@ -149,8 +167,15 @@ void local_mp_ground_ai_update(float dt)
|
||||
}
|
||||
if (dt > 0.0f)
|
||||
control->remaining_seconds -= dt;
|
||||
if (control->remaining_seconds <= 0.0f)
|
||||
give_back_drive(control, "script stopped renewing control");
|
||||
if (control->remaining_seconds <= 0.0f) {
|
||||
if (config_ground_ai_return_to_stock()) {
|
||||
give_back_drive(control, "script stopped renewing control");
|
||||
} else if (!control->stalled_logged) {
|
||||
control->stalled_logged = 1;
|
||||
log_line("local_mp: ground AI control stalled eid=%#lx (auto-return disabled; stock movement kept paused)",
|
||||
(unsigned long)control->eid);
|
||||
}
|
||||
}
|
||||
}
|
||||
ReleaseSRWLockExclusive(&control_lock);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user