feat(ground-ai): scope custom ground AI to slot bots and PvE defenders
- Capture unit_mgr, agent_unit_idx, unit_count, and unit_array inside driveToPos::update (patches/native/local_mp_ground_ai.jsonc) so local_mp_ground_ai.c short-circuits stock movement only for MPlayer slot bots (userId < -1) and leaves non-MPlayer mission wave AI (such as Ground Assault enemy tanks) on stock mission control. - Return customBots/wtoPveMode from wtoGroundAiScriptReady so ground AI scripts in Assault PvE take over only Team A friendly defenders (army 1) and synthesize a friendly defense anchor from the mission safe_zone area. Verified: MSVC wto_ws.dll build (0 project warnings), .37 check-patches (14/14), .37/.64 native module resolution (18/18), and temporary game-copy build packing 55 ground AI modules; in-game acceptance pending.
This commit is contained in:
1 parent
aaae2e4187
commit
9ba92f289d
8 files changed
+108
-10
No files matched your search
@@ -22,11 +22,14 @@ require %appGame.wtoai.wto_ai_nav_types_common
|
||||
require %appGame.wtoai.wto_ai_follow_common
|
||||
|
||||
[never_inline]
|
||||
def public wto_drive_announce_script_ready()
|
||||
def public wto_drive_announce_script_ready() : bool
|
||||
let own = (WTO_AI_ENABLED && WTO_AI_LAYER_NAVIGATION && WTO_AI_NAV_DRIVE_MODE == "vehicle_phys") ? "1" : "0"
|
||||
var pve = false
|
||||
using() <| $(var blk : DataBlock)
|
||||
add(blk, "ownMovement", own)
|
||||
call_mission_action("wtoGroundAiScriptReady", blk)
|
||||
pve = datablock_getInt(blk, "pveMode", 0) != 0
|
||||
return pve
|
||||
|
||||
[never_inline]
|
||||
def public wto_drive_request_control(eid : EntityId; holdMs : int)
|
||||
|
||||
@@ -61,6 +61,7 @@ var private @safe_when_uninitialized g_navmesh : WtoNavmeshBattle
|
||||
var private @safe_when_uninitialized g_stats : WtoBattleStats
|
||||
var private g_next_trace_at : float = 0.0
|
||||
var private g_trace_due : bool = false
|
||||
var private g_pve_mode : bool = false
|
||||
|
||||
// Custom ground AI must only run inside a real multiplayer battle. Single-player test
|
||||
// drives also dispatch tag=server ECS, but their target vehicles must never be taken over.
|
||||
@@ -71,7 +72,7 @@ def private wto_any_layer_active() : bool
|
||||
|
||||
[init]
|
||||
def wto_ai_script_init()
|
||||
wto_drive_announce_script_ready()
|
||||
g_pve_mode = wto_drive_announce_script_ready()
|
||||
|
||||
[never_inline]
|
||||
def private wto_reset_runtime()
|
||||
@@ -87,13 +88,14 @@ def private wto_reset_runtime()
|
||||
g_next_diag_at = 0.0
|
||||
g_next_trace_at = 0.0
|
||||
g_trace_due = false
|
||||
g_pve_mode = false
|
||||
wto_navmesh_battle_reset(g_navmesh)
|
||||
wto_slots_reset_all(g_bots)
|
||||
|
||||
[es(tag=server, on_event=(EventMissionUnload, EventEntityManagerBeforeClear, EventEcsMissionLoaded))]
|
||||
def wto_ai_mission_reset_es(evt : Event)
|
||||
wto_reset_runtime()
|
||||
wto_drive_announce_script_ready()
|
||||
g_pve_mode = wto_drive_announce_script_ready()
|
||||
|
||||
// Battle loading: read the navigation pack in the background before the first world tick.
|
||||
[es(tag=server, on_event=EventEcsMissionLoaded)]
|
||||
@@ -150,8 +152,9 @@ def wto_ai_world_tick_es(act : UpdateStageInfoAct)
|
||||
wto_reset_runtime()
|
||||
wto_slots_drop_stale(g_bots, now)
|
||||
if !g_world.valid
|
||||
wto_drive_announce_script_ready()
|
||||
print("WTO_AI|RUNTIME_READY\n")
|
||||
g_pve_mode = wto_drive_announce_script_ready()
|
||||
g_world.pveMode = g_pve_mode
|
||||
print("WTO_AI|RUNTIME_READY|pve={g_pve_mode ? 1 : 0}\n")
|
||||
wto_world_refresh(now, wto_trace_is_due(now, g_next_trace_at), g_world)
|
||||
if WTO_AI_LAYER_NAVIGATION
|
||||
wto_navmesh_battle_tick(g_world, now, g_navmesh)
|
||||
@@ -202,7 +205,8 @@ def wto_ai_pipeline_es(act : UpdateStageInfoAct; eid : EntityId; var unit__ref :
|
||||
return
|
||||
let army = int(unit.army)
|
||||
let gm = as_gm(unit)
|
||||
if (army != 1 && army != 2) || gm == null || gm.moveSys == null || as_hv(unit) == null
|
||||
// In Ground Assault PvE, only friendly defenders (army 1) use custom AI; enemy waves keep stock AI.
|
||||
if (army != 1 && army != 2) || (g_pve_mode && army != 1) || gm == null || gm.moveSys == null || as_hv(unit) == null
|
||||
return
|
||||
let now = float(get_app().usefulTotalTime)
|
||||
var created = false
|
||||
|
||||
@@ -145,6 +145,7 @@ struct public WtoWorldSnap
|
||||
deadIdCursor : int = 0
|
||||
recordedDeadEids : EntityId[64]
|
||||
battleMode : int = 0
|
||||
pveMode : bool = false
|
||||
zoneVersion : int = 0
|
||||
capCount : int = 0
|
||||
caps : WtoCapSnap[8]
|
||||
|
||||
@@ -83,6 +83,34 @@ def private wto_collect_zone_entities(var pIds : int[8]&; var pPos : float3[8]&;
|
||||
pCount++
|
||||
return pCount
|
||||
|
||||
[never_inline]
|
||||
def private wto_append_pve_defense_zone(var snap : WtoWorldSnap&)
|
||||
var cx = 0.0
|
||||
var cz = 0.0
|
||||
var rad = 60.0
|
||||
var found = false
|
||||
let areaId = get_area_id("safe_zone")
|
||||
if areaId >= 0
|
||||
let lim = get_area_limits_xz(areaId)
|
||||
cx = 0.5 * (lim.x + lim.z)
|
||||
cz = 0.5 * (lim.y + lim.w)
|
||||
rad = clamp(0.25 * (abs(lim.z - lim.x) + abs(lim.w - lim.y)), 25.0, 180.0)
|
||||
found = true
|
||||
elif snap.teamSpawnValid[1]
|
||||
cx = snap.teamSpawnCenter[1].x
|
||||
cz = snap.teamSpawnCenter[1].z
|
||||
found = true
|
||||
if !found
|
||||
return
|
||||
let refY = snap.teamSpawnValid[1] ? snap.teamSpawnCenter[1].y : 120.0
|
||||
snap.caps[0].zoneId = 0
|
||||
snap.caps[0].center = float3(cx, wto_snap_cap_y(cx, refY, cz), cz)
|
||||
snap.caps[0].radius = rad
|
||||
snap.caps[0].ownerArmy = 1
|
||||
snap.caps[0].progress = -100.0
|
||||
snap.caps[0].contested = true
|
||||
snap.capCount = 1
|
||||
|
||||
[never_inline]
|
||||
def public wto_world_refresh_caps(var snap : WtoWorldSnap&)
|
||||
let prevCount = snap.capCount
|
||||
@@ -117,6 +145,8 @@ def public wto_world_refresh_caps(var snap : WtoWorldSnap&)
|
||||
snap.caps[cIdx].progress = prog
|
||||
snap.caps[cIdx].contested = (own == 1 && prog > -99.0) || (own == 2 && prog < 99.0) || (own == 0 && abs(prog) > 1.0)
|
||||
snap.capCount = cIdx + 1
|
||||
if snap.pveMode && snap.capCount == 0
|
||||
wto_append_pve_defense_zone(snap)
|
||||
wto_detect_battle_mode(snap, nameHint)
|
||||
var changed = snap.capCount != prevCount
|
||||
for i in range(snap.capCount)
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
typedef void (__fastcall *MissionActionFn)(const char *name, const void *blk);
|
||||
typedef uint8_t *(__fastcall *AsGroundModelFn)(uint8_t *unit);
|
||||
typedef uint8_t (__fastcall *DriveToPosUpdateFn)(void *node, void *agent, float dt);
|
||||
typedef void (__fastcall *GroundAiBlkSetIntFn)(void *blk, const char *name, const int32_t *value);
|
||||
typedef void (__fastcall *GroundAiBlkToOwnedFn)(void *blk);
|
||||
|
||||
typedef struct GroundAiDriveControl {
|
||||
uint8_t *unit;
|
||||
@@ -117,11 +119,54 @@ static int read_uint(const void *blk, const char *key, uint32_t *out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int is_slot_bot_agent(const void *agent)
|
||||
{
|
||||
const uint8_t *mgr;
|
||||
uint32_t idx, count;
|
||||
uint8_t *const *units;
|
||||
const uint8_t *unit, *owner;
|
||||
|
||||
if (agent == NULL || g_lmp.ground_ai_unit_mgr == NULL)
|
||||
return 0;
|
||||
mgr = *(const uint8_t *const *)g_lmp.ground_ai_unit_mgr;
|
||||
if (mgr == NULL)
|
||||
return 0;
|
||||
idx = *(const uint32_t *)((const uint8_t *)agent + g_lmp.ground_ai_agent_unit_idx);
|
||||
count = *(const uint32_t *)(mgr + g_lmp.ground_ai_unit_count);
|
||||
units = *(uint8_t *const *const *)(mgr + g_lmp.ground_ai_unit_array);
|
||||
if (units == NULL || idx >= count)
|
||||
return 0;
|
||||
unit = units[idx];
|
||||
if (unit == NULL)
|
||||
return 0;
|
||||
owner = *(const uint8_t *const *)(unit + LMP_UNIT_OFF_MPLAYER);
|
||||
return owner != NULL && !local_mp_is_local_mplayer(owner) &&
|
||||
*(const int64_t *)(owner + LMP_MP_OFF_USER_ID) < -1;
|
||||
}
|
||||
|
||||
static void write_pve_mode_flag(void *blk)
|
||||
{
|
||||
int32_t pve = 0;
|
||||
|
||||
if (blk == NULL || g_lmp.blk_set_int == NULL || g_lmp.blk_to_owned == NULL)
|
||||
return;
|
||||
if (g_local_mp_mission_settings != NULL && g_lmp_datablock_get_str != NULL) {
|
||||
const char *flag = g_lmp_datablock_get_str(
|
||||
g_local_mp_mission_settings + LMP_MIS_OFF_CUSTOM_BOTS, "wtoPveMode", "0");
|
||||
pve = (flag != NULL && strcmp(flag, "1") == 0) ? 1 : 0;
|
||||
}
|
||||
if (*(int32_t *)((uint8_t *)blk + LMP_BLK_OFF_OWNED_STATE) != -1)
|
||||
((GroundAiBlkToOwnedFn)g_lmp.blk_to_owned)(blk);
|
||||
((GroundAiBlkSetIntFn)g_lmp.blk_set_int)(blk, "pveMode", &pve);
|
||||
}
|
||||
|
||||
static uint8_t __fastcall hook_drive_to_pos_update(void *node, void *agent, float dt)
|
||||
{
|
||||
/* Keep the BehTree object initialized on the unit so vehicle physics steps normally,
|
||||
* but short-circuit stock driveToPos to ER_SUCCESS (1) whenever our AI script is active. */
|
||||
if (local_mp_is_host() && InterlockedCompareExchange(&g_script_owns_movement, 0, 0))
|
||||
* short-circuiting stock driveToPos only for MPlayer slot bots. Non-MPlayer mission AI
|
||||
* units (such as Ground Assault enemy tank waves) keep running stock mission movement. */
|
||||
if (local_mp_is_host() && InterlockedCompareExchange(&g_script_owns_movement, 0, 0) &&
|
||||
is_slot_bot_agent(agent))
|
||||
return 1;
|
||||
return orig_drive_to_pos_update(node, agent, dt);
|
||||
}
|
||||
@@ -138,6 +183,7 @@ static void __fastcall hook_mission_action(const char *name, const void *blk)
|
||||
(unsigned)(own ? 1 : 0), own ? "disabled" : "kept");
|
||||
}
|
||||
}
|
||||
write_pve_mode_flag((void *)blk);
|
||||
return;
|
||||
}
|
||||
if (name != NULL && strcmp(name, NAV_ACTION) == 0) {
|
||||
|
||||
@@ -217,6 +217,10 @@ static const LmpValueSpec SPECS[] = {
|
||||
A(GROUND_AI, "ground_ai_mission_binding.action", ground_ai_mission_action),
|
||||
A(GROUND_AI, "ground_ai_as_ground_model", ground_ai_as_ground_model),
|
||||
A(GROUND_AI, "ground_ai_drive_to_pos_update", ground_ai_drive_to_pos_update),
|
||||
A(GROUND_AI, "ground_ai_drive_to_pos_update.unit_mgr", ground_ai_unit_mgr),
|
||||
O(GROUND_AI, "ground_ai_drive_to_pos_update.agent_unit_idx", ground_ai_agent_unit_idx),
|
||||
O(GROUND_AI, "ground_ai_drive_to_pos_update.unit_count", ground_ai_unit_count),
|
||||
O(GROUND_AI, "ground_ai_drive_to_pos_update.unit_array", ground_ai_unit_array),
|
||||
O(GROUND_AI, "ground_ai_move_properties.move_system", ground_ai_move_system),
|
||||
O(GROUND_AI, "ground_ai_move_annotation.inactive", ground_ai_move_inactive),
|
||||
|
||||
|
||||
@@ -106,7 +106,9 @@ typedef struct LmpValues {
|
||||
size_t ks_rule_spawn_pos, ks_rule_spawn_pos_count, ks_spawn_pos_stride, mp_ks_progress, app_terrain;
|
||||
/* local_mp_ground_ai */
|
||||
uint8_t *ground_ai_mission_action, *ground_ai_as_ground_model, *ground_ai_drive_to_pos_update;
|
||||
uint8_t *ground_ai_unit_mgr;
|
||||
size_t ground_ai_move_system, ground_ai_move_inactive;
|
||||
size_t ground_ai_agent_unit_idx, ground_ai_unit_count, ground_ai_unit_array;
|
||||
/* local_mp_air_ai_sync */
|
||||
uint8_t *air_ai_add_unsorted_plane;
|
||||
} LmpValues;
|
||||
|
||||
@@ -66,13 +66,21 @@
|
||||
}]
|
||||
},
|
||||
// driveToPos::update (vtable[1] of the tankBot driveToPos behavior node).
|
||||
// 2.61.0.37: 0x861370. 2.61.0.58: 0x863a90.
|
||||
// Captures the unit manager global, agent unit-index offset, and unit table fields so the
|
||||
// hook short-circuits stock driving only for MPlayer slot bots (leaving mission wave AI alone).
|
||||
// 2.61.0.37: 0x861370. 2.61.0.58: 0x863a90. 2.61.0.64: 0x863af0.
|
||||
"ground_ai_drive_to_pos_update": {
|
||||
"variants": [{
|
||||
"written_for": "2.61.0.37",
|
||||
"locate": {
|
||||
"method": "signature",
|
||||
"pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 02 00 00 44 0f 29 bc 24 80 02 00 00 44 0f 29 b4 24 70 02 00 00 44 0f 29 ac 24 60 02 00 00 44 0f 29 a4 24 50 02 00 00 44 0f 29 9c 24 40 02 00 00 44 0f 29 94 24 30 02 00 00 44 0f 29 8c 24 20 02 00 00 44 0f 29 84 24 10 02 00 00 0f 29 bc 24 00 02 00 00 0f 29 b4 24 f0 01 00 00 44 0f 28 da 49 89 cf 48 8b 3d ?? ?? ?? ?? 44 8b 72 08 0f b6 87 f3 00 00 00 48 8b 9f 60 06 00 00 48 85 db 40 0f 94 c5 40 08 c5 40 f6 c5 01 75 09 48 89 d9 ff 15 ?? ?? ?? ?? 44"
|
||||
"pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 02 00 00 44 0f 29 bc 24 80 02 00 00 44 0f 29 b4 24 70 02 00 00 44 0f 29 ac 24 60 02 00 00 44 0f 29 a4 24 50 02 00 00 44 0f 29 9c 24 40 02 00 00 44 0f 29 94 24 30 02 00 00 44 0f 29 8c 24 20 02 00 00 44 0f 29 84 24 10 02 00 00 0f 29 bc 24 00 02 00 00 0f 29 b4 24 f0 01 00 00 44 0f 28 da 49 89 cf 48 8b 3d ?? ?? ?? ?? 44 8b 72 08 0f b6 87 f3 00 00 00 48 8b 9f 60 06 00 00 48 85 db 40 0f 94 c5 40 08 c5 40 f6 c5 01 75 09 48 89 d9 ff 15 ?? ?? ?? ?? 44 3b b7 ?? ?? ?? ?? 73 13 48 8b 87 ?? ?? ?? ?? 4a 8b 3c f0",
|
||||
"captures": {
|
||||
"unit_mgr": { "offset": 117, "type": "rel32" },
|
||||
"agent_unit_idx": { "offset": 124, "type": "u8" },
|
||||
"unit_count": { "offset": 167, "type": "u32" },
|
||||
"unit_array": { "offset": 176, "type": "u32" }
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user