feat(ground-ai): add ready-rack dual-ammo bot spawn loadouts and shell switching
Select realistic ready-rack dual-shell loadouts for AI tanks on the local server, inject them natively on bot spawn, and switch between anti-armor and soft-target shells in battle: - Add the loadout section to tuning/ground-ai.jsonc (lowReadyRackThreshold, topUpAmmoCount, primaryAmmoPct, secondaryMinRounds, penetrationCompareDistM), validated in ground-ai-tuning.ts. - Add the tank-bot-ammo v2 dataset (apps/server/src/game-data/datasets/ tank-bot-ammo.ts) reading primary cannon weapon name, capacity, firstStage/autoLoad shell ready-rack counts (excluding separate charges), and selectable shell modifications (using Lanz-Odermatt kinetic fields, cumulativeDamage, armorpower, and transitive reqModification chains). - Add selectBotTankLoadouts (apps/server/src/battle/bot-tank-loadouts.ts): carry ready-rack count when >= 15 (top up to 22 when smaller or absent, clamped to gun capacity), skip SPAA/belt autocannons, pick highest-tier APFSDS/anti-armor primary (~80%) plus HE/HESH/HEAT secondary (~20%, min 3 rounds) when available, and attach required addModification entries and per-tank wtoAmmo_<unit> strings to customBots when mode != stock. - Hook Unit::changeAircraft (already located dynamically on .37 and .58) in native/wto-net/src/local_mp_loadout.c to assign the 24-byte ChangeUnitReflection.bullets entries via bullet_vec_assign for LocalMP bot spawns (async == 0, non-local bot MPlayer), leaving player spawns untouched. - Track soft-target vs anti-armor shell classes in wto_ai_specs_common.das and write gun.nextBulletType in wto_ai_fire_common.das to queue HE/HESH against light/narrow targets and APFSDS/AP against MBTs/heavy armor. 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, 12/12 LocalMP module installation, clean daScript load (wto_ai_runtime.das loaded in 211 ms, 0 compile errors), and real 2.61.0.58 loadout selection on cn_ztz_96a (18 APFSDS + 4 HE), germ_leopard_2a4 (12 DM23 + 3 HEATFS), ussr_t_80bvm (22 3BM60 + 6 HE), us_m1a2_abrams (14 M829A2 + 4 HEAT-MP), ussr_t_34_1941 (18 APHEBC + 4 HE), and ussr_zsu_23_4 (stock belt kept). Live battle acceptance begins in Step 9.
This commit is contained in:
1 parent
d5008baeff
commit
ac35c25851
14 files changed
+601
-10
No files matched your search
@@ -13,8 +13,19 @@
|
||||
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct ReflBulletEntry {
|
||||
const char *weapon_name;
|
||||
const char *bullet_mod;
|
||||
uint16_t count;
|
||||
uint8_t trigger_group;
|
||||
uint8_t pad[5];
|
||||
} ReflBulletEntry;
|
||||
|
||||
C_ASSERT(sizeof(ReflBulletEntry) == 24);
|
||||
|
||||
typedef void (__fastcall *SemChangeAircraftSendFn)(
|
||||
void *self, const char *unit_name, const char *weapon_name, const void *modifications_blk,
|
||||
const char *skin_name, const void *custom_preset_blk, uint8_t flags_byte,
|
||||
@@ -39,9 +50,9 @@ typedef uint64_t (__fastcall *StrHashFnv1Fn)(const char *str, size_t len);
|
||||
typedef int32_t (__fastcall *NameMapAddNameIdFn)(void *map, const char *str, size_t len, uint64_t hash);
|
||||
|
||||
static SemChangeAircraftSendFn orig_sem_send;
|
||||
static UnitChangeAircraftFn orig_unit_change_aircraft;
|
||||
static ReflCtorFn fn_refl_ctor;
|
||||
static ReflDtorFn fn_refl_dtor;
|
||||
static UnitChangeAircraftFn fn_unit_change_aircraft;
|
||||
static DataBlockSetFromFn fn_datablock_set_from;
|
||||
static DataBlockDtorFn fn_datablock_dtor;
|
||||
static BulletSetVecAssignFn fn_bullet_vec_assign;
|
||||
@@ -120,6 +131,93 @@ static void apply_mplayer_spawn_base(uint8_t *mplayer, int32_t req_base_id)
|
||||
*(float *)(mplayer + LMP_MP_OFF_SPAWN_POS_Z) = 0.0f;
|
||||
}
|
||||
|
||||
static int is_bot_unit(const uint8_t *unit)
|
||||
{
|
||||
const uint8_t *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 int parse_bullet_pair(const char *token, char *mod_buf, size_t mod_size, uint16_t *out_count)
|
||||
{
|
||||
const char *colon = strchr(token, ':');
|
||||
size_t mod_len;
|
||||
unsigned long parsed;
|
||||
char *end;
|
||||
|
||||
if (colon == NULL)
|
||||
return 0;
|
||||
mod_len = (size_t)(colon - token);
|
||||
if (mod_len >= mod_size)
|
||||
return 0;
|
||||
memcpy(mod_buf, token, mod_len);
|
||||
mod_buf[mod_len] = '\0';
|
||||
parsed = strtoul(colon + 1, &end, 10);
|
||||
if (end == colon + 1 || (*end != '\0' && *end != '|') || parsed == 0 || parsed > 0xfffeu)
|
||||
return 0;
|
||||
*out_count = (uint16_t)parsed;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void apply_bot_tank_ammo(const uint8_t *unit, uint8_t *refl)
|
||||
{
|
||||
const char *raw_name, *unit_name, *spec, *p1, *p2;
|
||||
char key[128], weapon[96], b0[96], b1[96];
|
||||
uint16_t c0 = 0, c1 = 0;
|
||||
size_t wlen;
|
||||
ReflBulletEntry slots[2];
|
||||
size_t count = 0;
|
||||
|
||||
if (g_local_mp_mission_settings == NULL || g_lmp_datablock_get_str == NULL || !is_bot_unit(unit))
|
||||
return;
|
||||
raw_name = *(const char *const *)(refl + LMP_REFL_OFF_UNIT_NAME);
|
||||
if (raw_name == NULL || *raw_name == '\0')
|
||||
return;
|
||||
unit_name = strncmp(raw_name, "tankModels/", 11) == 0 ? raw_name + 11 : raw_name;
|
||||
if (strlen(unit_name) + 9 >= sizeof(key))
|
||||
return;
|
||||
memcpy(key, "wtoAmmo_", 8);
|
||||
strcpy_s(key + 8, sizeof(key) - 8, unit_name);
|
||||
spec = g_lmp_datablock_get_str(g_local_mp_mission_settings + LMP_MIS_OFF_CUSTOM_BOTS, key, "");
|
||||
if (spec == NULL || *spec == '\0')
|
||||
return;
|
||||
p1 = strchr(spec, '|');
|
||||
if (p1 == NULL)
|
||||
return;
|
||||
wlen = (size_t)(p1 - spec);
|
||||
if (wlen == 0 || wlen >= sizeof(weapon))
|
||||
return;
|
||||
memcpy(weapon, spec, wlen);
|
||||
weapon[wlen] = '\0';
|
||||
if (!parse_bullet_pair(p1 + 1, b0, sizeof(b0), &c0))
|
||||
return;
|
||||
|
||||
memset(slots, 0, sizeof(slots));
|
||||
slots[0].weapon_name = weapon;
|
||||
slots[0].bullet_mod = b0;
|
||||
slots[0].count = c0;
|
||||
slots[0].trigger_group = 0xffu;
|
||||
count = 1;
|
||||
p2 = strchr(p1 + 1, '|');
|
||||
if (p2 != NULL && parse_bullet_pair(p2 + 1, b1, sizeof(b1), &c1)) {
|
||||
slots[1].weapon_name = weapon;
|
||||
slots[1].bullet_mod = b1;
|
||||
slots[1].count = c1;
|
||||
slots[1].trigger_group = 0xffu;
|
||||
count = 2;
|
||||
}
|
||||
fn_bullet_vec_assign(refl + LMP_REFL_OFF_BULLETS_VEC, &slots[0], &slots[count]);
|
||||
log_line("local_mp: bot tank ammo unit='%s' weapon='%s' b0='%s':%u b1='%s':%u",
|
||||
unit_name, weapon, b0, (unsigned)c0, count > 1 ? b1 : "", (unsigned)c1);
|
||||
}
|
||||
|
||||
static uint8_t __fastcall hook_unit_change_aircraft(void *unit, void *refl, uint8_t async)
|
||||
{
|
||||
if (local_mp_is_host() && unit != NULL && refl != NULL && async == 0)
|
||||
apply_bot_tank_ammo((const uint8_t *)unit, (uint8_t *)refl);
|
||||
return orig_unit_change_aircraft(unit, refl, async);
|
||||
}
|
||||
|
||||
static void __fastcall hook_sem_change_aircraft_send(
|
||||
void *self, const char *unit_name, const char *weapon_name, const void *modifications_blk,
|
||||
const char *skin_name, const void *custom_preset_blk, uint8_t flags_byte,
|
||||
@@ -182,7 +280,7 @@ static void __fastcall hook_sem_change_aircraft_send(
|
||||
refl[LMP_REFL_OFF_VERT_TARGETING] = vertical_targeting ? 1u : 0u;
|
||||
*(float *)(refl + LMP_REFL_OFF_BOMB_FUSE) = bomb_activation_time;
|
||||
|
||||
fn_unit_change_aircraft(hero, refl, 1);
|
||||
orig_unit_change_aircraft(hero, refl, 1);
|
||||
fn_refl_dtor(refl);
|
||||
|
||||
if (mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_PILOT_CONTROL &&
|
||||
@@ -198,6 +296,7 @@ int install_local_mp_loadout_hooks(void)
|
||||
{
|
||||
const LocalMpHookSpec hooks[] = {
|
||||
{ "sem_change_aircraft_send", g_lmp.sem_change_aircraft_send, (void *)&hook_sem_change_aircraft_send, (void **)&orig_sem_send },
|
||||
{ "unit_change_aircraft", g_lmp.unit_change_aircraft, (void *)&hook_unit_change_aircraft, (void **)&orig_unit_change_aircraft },
|
||||
};
|
||||
|
||||
/* The reflection is built in a fixed stack buffer; its bullet sets vector is its last member. */
|
||||
@@ -208,7 +307,6 @@ int install_local_mp_loadout_hooks(void)
|
||||
}
|
||||
fn_refl_ctor = (ReflCtorFn)g_lmp.refl_ctor;
|
||||
fn_refl_dtor = (ReflDtorFn)g_lmp.refl_dtor;
|
||||
fn_unit_change_aircraft = (UnitChangeAircraftFn)g_lmp.unit_change_aircraft;
|
||||
fn_datablock_set_from = (DataBlockSetFromFn)g_lmp.datablock_set_from;
|
||||
fn_datablock_dtor = (DataBlockDtorFn)g_lmp.datablock_dtor;
|
||||
fn_bullet_vec_assign = (BulletSetVecAssignFn)g_lmp.bullet_vec_assign;
|
||||
|
||||
Reference in new issue
Block a user