From ee7bb120928b8e49eec23f3481930b599e56eeb4 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Sun, 6 Dec 2026 01:51:00 +0800 Subject: [PATCH] fix(ground-ai): finish single-vehicle combat decisions Check the live barrel trajectory against the exposed target and shorten fire delays. Resolve automatic and secondary guns using stock weapon data. Keep short halts and withdrawals coherent, follow the order while engaged, and reverse on the route with direction-aware obstacle recovery. Verified daScript loading and native AI script readiness in the guarded 2.61.0.64 lab client. Battle behavior requires manual acceptance. --- .../src/renderer/src/i18n/locales/en.json | 24 ++- .../src/renderer/src/i18n/locales/zh-CN.json | 22 +- .../src/pages/tuning/bot-tuning-fields.ts | 22 +- apps/launcher/src/shared/schemas/tuning.ts | 22 +- apps/server/src/tuning/ground-ai-tuning.ts | 22 +- apps/server/tuning/ground-ai.jsonc | 69 ++++--- game-ai/ground/wto_ai_ammo_common.das | 52 +++++ game-ai/ground/wto_ai_behavior_common.das | 73 +++++-- game-ai/ground/wto_ai_combat_types_common.das | 40 ++-- game-ai/ground/wto_ai_drive_common.das | 9 +- game-ai/ground/wto_ai_estimate_common.das | 58 ++++-- game-ai/ground/wto_ai_facing_common.das | 75 ++++--- game-ai/ground/wto_ai_fire_aux_common.das | 192 +++++++++++------- game-ai/ground/wto_ai_fire_checks_common.das | 110 ++++++++++ game-ai/ground/wto_ai_fire_common.das | 101 +++++---- game-ai/ground/wto_ai_fire_gate_common.das | 166 ++++----------- game-ai/ground/wto_ai_follow_common.das | 16 ++ game-ai/ground/wto_ai_nav_common.das | 49 +---- game-ai/ground/wto_ai_nav_types_common.das | 1 + game-ai/ground/wto_ai_perceive_common.das | 15 +- game-ai/ground/wto_ai_route_common.das | 2 +- game-ai/ground/wto_ai_runtime.das | 15 ++ game-ai/ground/wto_ai_sight_common.das | 14 +- game-ai/ground/wto_ai_slots_common.das | 10 +- game-ai/ground/wto_ai_specs_common.das | 42 ++-- game-ai/ground/wto_ai_stats_common.das | 12 +- .../ground/wto_ai_tactics_actions_common.das | 34 ++-- game-ai/ground/wto_ai_tactics_common.das | 43 ++-- game-ai/ground/wto_ai_traverse_common.das | 36 +++- game-ai/ground/wto_ai_trigger_common.das | 76 +++++-- game-ai/ground/wto_ai_types_common.das | 12 +- game-ai/ground/wto_ai_unstick_common.das | 25 ++- .../ground/wto_ai_weapon_profile_common.das | 76 +++++++ .../patcher/src/ground-ai/ground-ai-config.ts | 44 +++- 34 files changed, 1030 insertions(+), 549 deletions(-) create mode 100644 game-ai/ground/wto_ai_ammo_common.das create mode 100644 game-ai/ground/wto_ai_fire_checks_common.das create mode 100644 game-ai/ground/wto_ai_weapon_profile_common.das diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index d7ec166..a763e0a 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -686,7 +686,15 @@ }, "behavior": { "scoreIntervalSec": "Behavior scoring interval", - "minHoldSec": "Minimum time a behavior is kept", + "advanceHoldSec": "Advance commitment", + "engageHoldSec": "Engage while moving commitment", + "haltHoldSec": "Short halt commitment", + "coverHoldSec": "Take cover commitment", + "repositionHoldSec": "Reposition commitment", + "postHoldSec": "Hold position commitment", + "disperseHoldSec": "Disperse commitment", + "targetValueWeight": "Weight of a viable shot while moving", + "nearThreatHaltBonus": "Short-halt bonus under a close threat", "switchMargin": "Extra score needed to switch behavior", "advanceScore": "Score: advance along the order route", "engageScore": "Score: engage on the move", @@ -704,9 +712,8 @@ "hullAngleDeg": "Hull angle to the main threat", "faceToleranceDeg": "Facing tolerance while standing", "faceMinDanger": "Threat danger needed to face it", - "faceHaltLimitDeg": "Facing error that turns the hull during a short halt", "reverseTravelAngleDeg": "Threat angle off the travel direction for driving backwards", - "reverseMaxGoalDistM": "Drive backwards only toward a goal within", + "reverseMaxTurnDistM": "Max distance to the next turn or route end when reversing", "reverseMinSpeedMps": "Lowest top reverse speed for driving backwards", "reverseHoldSec": "Minimum time between switching forwards and backwards" }, @@ -734,17 +741,22 @@ "enemyReloadSec": "How long a target counts as reloading after it fired", "fleetingThresholdBonus": "Threshold drop for a target about to slip away", "fleetingLateralMps": "Crossing speed of a slipping-away target", - "bigGunThresholdPenalty": "Threshold rise for big slow-loading guns", + "fleetingLookAheadSec": "Look-ahead for losing line of sight", + "reloadThresholdPenalty": "Fire-threshold increase for long reloads", + "longReloadSec": "Reload time for the full threshold penalty", + "lowAmmoRounds": "Ammunition count below which shots are conserved", + "lowAmmoThresholdPenalty": "Fire-threshold increase with little ammunition", + "aimSkill": "Crew skill for aiming spread", + "autocannonMinShotsPerSec": "Minimum firing rate for automatic cannons (rounds/s)", "retreatThresholdPenalty": "Threshold rise while pulling back to cover", "minShotIntervalSec": "Minimum main-gun shot interval", "autocannonAimSlack": "Autocannon aim slack (times target size)", "burstSec": "Burst length", "burstPauseSec": "Pause between bursts", - "burstRecheckSec": "Safety re-check interval within a burst", "autocannonReloadDetectSec": "Autocannon not-ready time that counts as a reload", "auxWeapons": "Fire secondary and coaxial weapons", "auxMaxRangeM": "Secondary and coaxial weapon range", - "auxFireAtArmor": "Secondary and coaxial weapons also fire at armored targets", + "auxFireAtArmor": "Coaxial weapons also fire at non-light vehicles", "friendlyCorridorM": "Friendly fire corridor width", "ballisticStepMaxM": "Ballistic occlusion step length", "ballisticSweepRadiusM": "Ballistic sphere sweep radius", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index cf6d61b..77958af 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -686,7 +686,15 @@ }, "behavior": { "scoreIntervalSec": "行为打分间隔", - "minHoldSec": "行为最短保持时间", + "advanceHoldSec": "??????", + "engageHoldSec": "????????", + "haltHoldSec": "????????", + "coverHoldSec": "????????", + "repositionHoldSec": "??????", + "postHoldSec": "??????", + "disperseHoldSec": "??????", + "targetValueWeight": "???????????", + "nearThreatHaltBonus": "??????????", "switchMargin": "切换行为所需高出的分数", "advanceScore": "得分:沿任务路线推进", "engageScore": "得分:交战推进", @@ -704,9 +712,8 @@ "hullAngleDeg": "车头对主威胁的倾角", "faceToleranceDeg": "停车时朝向容差", "faceMinDanger": "需要车头对准的威胁危险度下限", - "faceHaltLimitDeg": "短停时朝向偏差超过多少才转车体", "reverseTravelAngleDeg": "威胁偏离行进方向多少度时倒车跟路", - "reverseMaxGoalDistM": "仅在离目的地这么近时倒车跟路", + "reverseMaxTurnDistM": "????????????????????", "reverseMinSpeedMps": "倒车跟路所需的最低倒车极速", "reverseHoldSec": "前进与倒车切换的最短间隔" }, @@ -734,13 +741,18 @@ "enemyReloadSec": "目标开火后视为装填中的时长", "fleetingThresholdBonus": "目标即将离开视线时门槛降低", "fleetingLateralMps": "视为即将离开视线的横穿速度", - "bigGunThresholdPenalty": "大口径慢装填火炮的门槛升高", + "fleetingLookAheadSec": "?????????", + "reloadThresholdPenalty": "????????????", + "longReloadSec": "????????????", + "lowAmmoRounds": "???????????", + "lowAmmoThresholdPenalty": "????????????", + "aimSkill": "???????????", + "autocannonMinShotsPerSec": "???????????/??", "retreatThresholdPenalty": "退入掩体途中的门槛升高", "minShotIntervalSec": "主炮最短开火间隔", "autocannonAimSlack": "机炮放宽倍数(目标尺寸的倍数)", "burstSec": "点射时长", "burstPauseSec": "点射间隔", - "burstRecheckSec": "点射中复查弹道和友军的间隔", "autocannonReloadDetectSec": "机炮持续未就绪多久算换弹", "auxWeapons": "使用副炮和并列武器", "auxMaxRangeM": "副炮和并列武器的射击距离", diff --git a/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts b/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts index 56428c6..a2a531a 100644 --- a/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts +++ b/apps/launcher/src/renderer/src/pages/tuning/bot-tuning-fields.ts @@ -255,7 +255,15 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [ customOnly: true, fields: [ num('behavior', 'scoreIntervalSec', 0.1, 3, 's'), - num('behavior', 'minHoldSec', 0, 10, 's'), + num('behavior', 'advanceHoldSec', 0, 10, 's'), + num('behavior', 'engageHoldSec', 0, 10, 's'), + num('behavior', 'haltHoldSec', 0, 10, 's'), + num('behavior', 'coverHoldSec', 0, 10, 's'), + num('behavior', 'repositionHoldSec', 0, 10, 's'), + num('behavior', 'postHoldSec', 0, 10, 's'), + num('behavior', 'disperseHoldSec', 0, 10, 's'), + num('behavior', 'targetValueWeight', 0, 1), + num('behavior', 'nearThreatHaltBonus', 0, 1), num('behavior', 'switchMargin', 0, 1), num('behavior', 'advanceScore', 0, 1), num('behavior', 'engageScore', 0, 1), @@ -273,9 +281,8 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [ num('behavior', 'hullAngleDeg', 0, 45, '°'), num('behavior', 'faceToleranceDeg', 3, 60, '°'), num('behavior', 'faceMinDanger', 0, 2), - num('behavior', 'faceHaltLimitDeg', 10, 180, '°'), num('behavior', 'reverseTravelAngleDeg', 60, 180, '°'), - num('behavior', 'reverseMaxGoalDistM', 0, 2000, 'm'), + num('behavior', 'reverseMaxTurnDistM', 0, 200, 'm'), num('behavior', 'reverseMinSpeedMps', 0.5, 10, 'm/s'), num('behavior', 'reverseHoldSec', 0, 20, 's'), ], @@ -308,13 +315,18 @@ export const BOT_TUNING_GROUPS: readonly BotTuningGroup[] = [ num('fireControl', 'enemyReloadSec', 0, 15, 's'), num('fireControl', 'fleetingThresholdBonus', 0, 0.5), num('fireControl', 'fleetingLateralMps', 0.5, 15, 'm/s'), - num('fireControl', 'bigGunThresholdPenalty', 0, 0.5), + num('fireControl', 'fleetingLookAheadSec', 0.1, 2, 's'), + num('fireControl', 'reloadThresholdPenalty', 0, 0.5), + num('fireControl', 'longReloadSec', 1, 60, 's'), + int('fireControl', 'lowAmmoRounds', 1, 60), + num('fireControl', 'lowAmmoThresholdPenalty', 0, 0.5), + num('fireControl', 'aimSkill', 0, 1), + num('fireControl', 'autocannonMinShotsPerSec', 0.5, 30), num('fireControl', 'retreatThresholdPenalty', 0, 0.6), num('fireControl', 'minShotIntervalSec', 0.1, 5, 's'), num('fireControl', 'autocannonAimSlack', 1, 10), num('fireControl', 'burstSec', 0.2, 6, 's'), num('fireControl', 'burstPauseSec', 0, 5, 's'), - num('fireControl', 'burstRecheckSec', 0.05, 2, 's'), num('fireControl', 'autocannonReloadDetectSec', 0.1, 3, 's'), { id: 'groundAi.fireControl.auxWeapons', section: 'fireControl', field: 'auxWeapons', kind: 'bool' }, num('fireControl', 'auxMaxRangeM', 30, 1500, 'm'), diff --git a/apps/launcher/src/shared/schemas/tuning.ts b/apps/launcher/src/shared/schemas/tuning.ts index d1caa79..1076abc 100644 --- a/apps/launcher/src/shared/schemas/tuning.ts +++ b/apps/launcher/src/shared/schemas/tuning.ts @@ -231,7 +231,15 @@ const GroundAiTurretSchema = z.object({ const GroundAiBehaviorSchema = z.object({ scoreIntervalSec: z.number().min(0.1).max(3), - minHoldSec: z.number().min(0).max(10), + advanceHoldSec: z.number().min(0).max(10), + engageHoldSec: z.number().min(0).max(10), + haltHoldSec: z.number().min(0).max(10), + coverHoldSec: z.number().min(0).max(10), + repositionHoldSec: z.number().min(0).max(10), + postHoldSec: z.number().min(0).max(10), + disperseHoldSec: z.number().min(0).max(10), + targetValueWeight: z.number().min(0).max(1), + nearThreatHaltBonus: z.number().min(0).max(1), switchMargin: z.number().min(0).max(1), advanceScore: z.number().min(0).max(1), engageScore: z.number().min(0).max(1), @@ -249,9 +257,8 @@ const GroundAiBehaviorSchema = z.object({ hullAngleDeg: z.number().min(0).max(45), faceToleranceDeg: z.number().min(3).max(60), faceMinDanger: z.number().min(0).max(2), - faceHaltLimitDeg: z.number().min(10).max(180), reverseTravelAngleDeg: z.number().min(60).max(180), - reverseMaxGoalDistM: z.number().min(0).max(2000), + reverseMaxTurnDistM: z.number().min(0).max(200), reverseMinSpeedMps: z.number().min(0.5).max(10), reverseHoldSec: z.number().min(0).max(20), }); @@ -291,13 +298,18 @@ const GroundAiFireControlSchema = z.object({ enemyReloadSec: z.number().min(0).max(15), fleetingThresholdBonus: z.number().min(0).max(0.5), fleetingLateralMps: z.number().min(0.5).max(15), - bigGunThresholdPenalty: z.number().min(0).max(0.5), + fleetingLookAheadSec: z.number().min(0.1).max(2), + reloadThresholdPenalty: z.number().min(0).max(0.5), + longReloadSec: z.number().min(1).max(60), + lowAmmoRounds: z.number().int().min(1).max(60), + lowAmmoThresholdPenalty: z.number().min(0).max(0.5), + aimSkill: z.number().min(0).max(1), + autocannonMinShotsPerSec: z.number().min(0.5).max(30), retreatThresholdPenalty: z.number().min(0).max(0.6), minShotIntervalSec: z.number().min(0.1).max(5), autocannonAimSlack: z.number().min(1).max(10), burstSec: z.number().min(0.2).max(6), burstPauseSec: z.number().min(0).max(5), - burstRecheckSec: z.number().min(0.05).max(2), autocannonReloadDetectSec: z.number().min(0.1).max(3), auxWeapons: z.boolean(), auxMaxRangeM: z.number().min(30).max(1500), diff --git a/apps/server/src/tuning/ground-ai-tuning.ts b/apps/server/src/tuning/ground-ai-tuning.ts index 411391b..399ab50 100644 --- a/apps/server/src/tuning/ground-ai-tuning.ts +++ b/apps/server/src/tuning/ground-ai-tuning.ts @@ -377,7 +377,15 @@ function readTurretSection(turret: TuningReader): GroundAiTuning['turret'] { function readBehaviorSection(bhv: TuningReader): GroundAiTuning['behavior'] { return { scoreIntervalSec: bhv.number('scoreIntervalSec', { min: 0.1, max: 3 }), - minHoldSec: bhv.number('minHoldSec', { min: 0, max: 10 }), + advanceHoldSec: bhv.number('advanceHoldSec', { min: 0, max: 10 }), + engageHoldSec: bhv.number('engageHoldSec', { min: 0, max: 10 }), + haltHoldSec: bhv.number('haltHoldSec', { min: 0, max: 10 }), + coverHoldSec: bhv.number('coverHoldSec', { min: 0, max: 10 }), + repositionHoldSec: bhv.number('repositionHoldSec', { min: 0, max: 10 }), + postHoldSec: bhv.number('postHoldSec', { min: 0, max: 10 }), + disperseHoldSec: bhv.number('disperseHoldSec', { min: 0, max: 10 }), + targetValueWeight: bhv.number('targetValueWeight', { min: 0, max: 1 }), + nearThreatHaltBonus: bhv.number('nearThreatHaltBonus', { min: 0, max: 1 }), switchMargin: bhv.number('switchMargin', { min: 0, max: 1 }), advanceScore: bhv.number('advanceScore', { min: 0, max: 1 }), engageScore: bhv.number('engageScore', { min: 0, max: 1 }), @@ -395,9 +403,8 @@ function readBehaviorSection(bhv: TuningReader): GroundAiTuning['behavior'] { hullAngleDeg: bhv.number('hullAngleDeg', { min: 0, max: 45 }), faceToleranceDeg: bhv.number('faceToleranceDeg', { min: 3, max: 60 }), faceMinDanger: bhv.number('faceMinDanger', { min: 0, max: 2 }), - faceHaltLimitDeg: bhv.number('faceHaltLimitDeg', { min: 10, max: 180 }), reverseTravelAngleDeg: bhv.number('reverseTravelAngleDeg', { min: 60, max: 180 }), - reverseMaxGoalDistM: bhv.number('reverseMaxGoalDistM', { min: 0, max: 2000 }), + reverseMaxTurnDistM: bhv.number('reverseMaxTurnDistM', { min: 0, max: 200 }), reverseMinSpeedMps: bhv.number('reverseMinSpeedMps', { min: 0.5, max: 10 }), reverseHoldSec: bhv.number('reverseHoldSec', { min: 0, max: 20 }), }; @@ -462,13 +469,18 @@ function readFireControlSection(fc: TuningReader): GroundAiTuning['fireControl'] enemyReloadSec: fc.number('enemyReloadSec', { min: 0, max: 15 }), fleetingThresholdBonus: fc.number('fleetingThresholdBonus', { min: 0, max: 0.5 }), fleetingLateralMps: fc.number('fleetingLateralMps', { min: 0.5, max: 15 }), - bigGunThresholdPenalty: fc.number('bigGunThresholdPenalty', { min: 0, max: 0.5 }), + fleetingLookAheadSec: fc.number('fleetingLookAheadSec', { min: 0.1, max: 2 }), + reloadThresholdPenalty: fc.number('reloadThresholdPenalty', { min: 0, max: 0.5 }), + longReloadSec: fc.number('longReloadSec', { min: 1, max: 60 }), + lowAmmoRounds: fc.int('lowAmmoRounds', { min: 1, max: 60 }), + lowAmmoThresholdPenalty: fc.number('lowAmmoThresholdPenalty', { min: 0, max: 0.5 }), + aimSkill: fc.number('aimSkill', { min: 0, max: 1 }), + autocannonMinShotsPerSec: fc.number('autocannonMinShotsPerSec', { min: 0.5, max: 30 }), retreatThresholdPenalty: fc.number('retreatThresholdPenalty', { min: 0, max: 0.6 }), minShotIntervalSec: fc.number('minShotIntervalSec', { min: 0.1, max: 5 }), autocannonAimSlack: fc.number('autocannonAimSlack', { min: 1, max: 10 }), burstSec: fc.number('burstSec', { min: 0.2, max: 6 }), burstPauseSec: fc.number('burstPauseSec', { min: 0, max: 5 }), - burstRecheckSec: fc.number('burstRecheckSec', { min: 0.05, max: 2 }), autocannonReloadDetectSec: fc.number('autocannonReloadDetectSec', { min: 0.1, max: 3 }), auxWeapons: fc.bool('auxWeapons'), auxMaxRangeM: fc.number('auxMaxRangeM', { min: 30, max: 1500 }), diff --git a/apps/server/tuning/ground-ai.jsonc b/apps/server/tuning/ground-ai.jsonc index 7e498e9..1e8f6b4 100644 --- a/apps/server/tuning/ground-ai.jsonc +++ b/apps/server/tuning/ground-ai.jsonc @@ -346,24 +346,22 @@ "scanPeriodSec": 6.0 }, - // Hull channel (decision layer design, section 7). Every scoreIntervalSec (at once when a target - // appears or is lost, a reload starts or ends, or the bot is hit) each behavior gets a score and - // the best runs; a running one is kept for minHoldSec, then until another scores switchMargin - // more. Scores: advance (no target in sight), engage (target in sight; +urgencyWeight when the - // order is urgent), halt (the trigger asks to stand for its shot; +urgencyWeight when not urgent, - // -crossfirePenalty per extra enemy aiming at the bot), cover (reloading with a known threat; - // +coverDangerWeight x danger, -coverOffensivePenalty on an urgent attack, not again for - // coverRetrySec after no cover was found), reposition (engagement stuck), hold (at the post, - // watching the last exit, waiting at the rally point) and disperse (crowded). Engaging on the - // move slows to the speed the trigger asks for; an urgent order keeps urgentSpeedKeep of the - // march speed. Medium and heavy tanks and tank destroyers face the most dangerous threat (danger - // at least faceMinDanger) angled by hullAngleDeg: holding within faceToleranceDeg, on a short halt - // only when more than faceHaltLimitDeg off. With that threat more than reverseTravelAngleDeg off - // the direction of travel and the goal within reverseMaxGoalDistM, a vehicle reversing at least - // reverseMinSpeedMps drives its route backwards; it switches at most every reverseHoldSec. + // Hull channel: choose a behavior by score, holding each for its configured commitment time + // unless an emergency or a large score difference interrupts it. A cover withdrawal runs + // through its arrival or timeout. A short halt lasts through the weapon's shooting window. + // Tracked tanks and tank destroyers face the main threat at the post or during a halt. + // They can reverse along a short route segment to keep their front toward that threat. "behavior": { "scoreIntervalSec": 0.5, - "minHoldSec": 1.5, + "advanceHoldSec": 1.5, + "engageHoldSec": 1.5, + "haltHoldSec": 3.0, + "coverHoldSec": 2.0, + "repositionHoldSec": 2.0, + "postHoldSec": 1.5, + "disperseHoldSec": 1.5, + "targetValueWeight": 0.1, + "nearThreatHaltBonus": 0.28, "switchMargin": 0.15, "advanceScore": 0.5, "engageScore": 0.55, @@ -381,9 +379,8 @@ "hullAngleDeg": 20.0, "faceToleranceDeg": 15.0, "faceMinDanger": 0.15, - "faceHaltLimitDeg": 60.0, "reverseTravelAngleDeg": 110.0, - "reverseMaxGoalDistM": 200.0, + "reverseMaxTurnDistM": 45.0, "reverseMinSpeedMps": 2.5, "reverseHoldSec": 3.0 }, @@ -396,10 +393,9 @@ // lead uncertainty on a crossing target, with the barrel's current offset as the mean error. // The threshold starts at fireThreshold and drops by aimingThresholdBonus when the target aims // at the bot, by up to closeThresholdBonus inside closeRangeM, by enemyReloadThresholdBonus for - // enemyReloadSec after the target fired, and by fleetingThresholdBonus when it crosses faster - // than fleetingLateralMps partly hidden; it rises by up to bigGunThresholdPenalty for guns above - // 75 mm and by retreatThresholdPenalty while pulling back to cover, and never goes below - // minFireThreshold. Main-gun shots are at least minShotIntervalSec apart. + // enemyReloadSec after the target fired, and by fleetingThresholdBonus if its estimated motion + // will take it out of sight. Longer reloads, scarce ammunition and falling back raise the threshold. + // The pre-fire budget limits ballistic checks per frame. Every firing request gets fresh checks. "fireControl": { "maxEngageRangeM": 1250.0, "closeRangeM": 100.0, @@ -407,19 +403,19 @@ "longRangeM": 800.0, // At or below this speed the bot counts as standing (also the answer "stop" to a speed request). "stopSpeedMaxMps": 0.45, - "longRangeWindowSec": 4.0, + "longRangeWindowSec": 1.0, // Fixed (casemate) guns: how far off the gun may be before the hull is asked to turn. "baseAlignDeg": 0.42, // Outside close range, the rate at which barrel alignment drifts relative to the aim direction. "barrelSettleDegSec": 1.8, - "closeSettleHoldSec": 0.08, - "settleHoldSec": 0.20, - "aimErrorDeg": 0.12, + "closeSettleHoldSec": 0.06, + "settleHoldSec": 0.12, + "aimErrorDeg": 0.07, "moveErrDegPerMps": 0.35, "turnErrDegPerDegSec": 0.03, "stabErrFactor": 0.2, "targetHalfHeightM": 1.0, - "fireThreshold": 0.35, + "fireThreshold": 0.45, "minFireThreshold": 0.1, "aimingThresholdBonus": 0.1, "closeThresholdBonus": 0.15, @@ -427,20 +423,23 @@ "enemyReloadSec": 3.0, "fleetingThresholdBonus": 0.1, "fleetingLateralMps": 3.0, - "bigGunThresholdPenalty": 0.08, + "fleetingLookAheadSec": 0.65, + "reloadThresholdPenalty": 0.08, + "longReloadSec": 15.0, + "lowAmmoRounds": 5, + "lowAmmoThresholdPenalty": 0.08, + "aimSkill": 0.5, + "autocannonMinShotsPerSec": 1.5, "retreatThresholdPenalty": 0.2, "minShotIntervalSec": 0.65, - // Belt-fed autocannons (6.3): fire while within autocannonAimSlack times the target's angular - // half size, in bursts of burstSec with burstPauseSec between, checking barrel, trajectory and - // friendlies again every burstRecheckSec. Not ready for longer than autocannonReloadDetectSec - // counts as a reload. + // Automatic cannons are identified from stock belt and firing-rate data. They fire in bursts + // while within the aim slack. A longer wait between rounds counts as a reload. "autocannonAimSlack": 3.0, "burstSec": 1.2, "burstPauseSec": 0.6, - "burstRecheckSec": 0.3, "autocannonReloadDetectSec": 0.6, - // Secondary cannon and coaxial weapons (6.4) fire bursts alongside the main gun at light - // vehicles within auxMaxRangeM (at any vehicle with auxFireAtArmor). + // Secondary and coaxial guns have their own aim and ballistic checks. The armor toggle allows + // coaxial fire at vehicles outside the light-vehicle filter. "auxWeapons": true, "auxMaxRangeM": 300.0, "auxFireAtArmor": false, diff --git a/game-ai/ground/wto_ai_ammo_common.das b/game-ai/ground/wto_ai_ammo_common.das new file mode 100644 index 0000000..b678370 --- /dev/null +++ b/game-ai/ground/wto_ai_ammo_common.das @@ -0,0 +1,52 @@ +// Ammunition assigned to the selected primary gun by the stock ammunition stowage. +options indenting = 2 +options no_global_heap = true +module wto_ai_ammo_common shared + +require ecs +require math +require DagorMath +require AmmoStowage +require Unit +require Weapon +require %appGame.wtoai.wto_ai_combat_types_common + +[never_inline] +def public wto_main_gun_ammo(gun : WTGun const?; fc : WtoFireState const&) : int + var stored = 0 + for set in gun.properties.bulletSets + stored += max(0, set.bulletsCount) + let stockCount = fc.rackTurret == fc.turretNo ? fc.rackRounds : -1 + if stockCount < 0 && stored == 0 + return -1 + return max(max(stockCount, stored), int(gun.currentLoadedAmmoCount)) + +def private wto_ammo_type_for_mount(unit : Unit const?; turret : int; first, end : int; weapons : IntList const&) : bool + for i in range(max(0, first), min(length(weapons), end)) + let weapon = get_weapon(unit.weap.Weapons, weapons[i]) + if weapon != null && int(weapon.turretNo) == turret + return true + return false + +[never_inline] +def public wto_ammo_sample(unit : Unit const?; ammoState : uint; types : IPoint4List const&; + weapons : IntList const&; slots : UInt32List const&; counts : IPoint2List const&; + var fc : WtoFireState&) + if fc.turretNo < 0 + return + fc.rackTurret = fc.turretNo + fc.rackRounds = -1 + for i in range(WTO_MAX_SHELL_PROFILES) + fc.rackBySet[i] = 0 + let distinctTypes = (ammoState & uint(AmmoState.ENABLE_PER_AMMO_TYPES)) != 0u + for ammoType in range(length(types)) + let remap = types[ammoType] + if !wto_ammo_type_for_mount(unit, fc.turretNo, remap.y, remap.z, weapons) + continue + var rounds = 0 + for i in range(min(length(slots), length(counts))) + if int(slots[i] & 0xffu) == ammoType + rounds += max(0, counts[i].x) + fc.rackRounds = max(0, fc.rackRounds) + rounds + if distinctTypes && remap.w >= 0 && remap.w < WTO_MAX_SHELL_PROFILES + fc.rackBySet[remap.w] += rounds diff --git a/game-ai/ground/wto_ai_behavior_common.das b/game-ai/ground/wto_ai_behavior_common.das index a145a57..86bd3e2 100644 --- a/game-ai/ground/wto_ai_behavior_common.das +++ b/game-ai/ground/wto_ai_behavior_common.das @@ -1,9 +1,5 @@ -// Hull channel behavior choice (decision layer design, 7.2): every behavior gets a 0-1 score from -// the order, the threat table, the bot's own state and the other channels' requests; the best one -// runs. A chosen behavior is kept for at least behavior.minHoldSec and afterwards until another -// scores behavior.switchMargin higher, unless it ends by itself or can no longer run. Scoring -// happens every behavior.scoreIntervalSec and at once when a target comes into sight or is lost, -// a reload starts or ends, or the bot is hit (a hit also lifts the minimum hold). +// Hull channel behavior choice from the order, threats, vehicle state and weapon requests. +// Actions own their completion conditions. Critical threats and hits can interrupt a commitment. options indenting = 2 options no_global_heap = true module wto_ai_behavior_common shared @@ -15,6 +11,8 @@ require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_order_common require %appGame.wtoai.wto_ai_combat_types_common require %appGame.wtoai.wto_ai_types_common +require %appGame.wtoai.wto_ai_threat_common +require %appGame.wtoai.wto_ai_facing_common // What one tactics tick knows, built once (wto_ai_tactics_common.das) and read by the scores and // the behaviors. threatPos: the most dangerous known threat, else the remembered target, else the @@ -28,12 +26,15 @@ struct public WtoBhvCtx threatDir : float3 = float3(1.0, 0.0, 0.0) topDanger : float = 0.0 aimingCount : int = 0 + nearThreat : bool = false + targetValue : float = 0.0 baseGoal : float3 = float3(0.0, 0.0, 0.0) distGoal : float = 0.0 atGoal : bool = false urgent : bool = false offensive : bool = false haltWanted : bool = false + turnWanted : bool = false stopRangeOk : bool = false stale : bool = false crowded : bool = false @@ -86,12 +87,17 @@ def public wto_bhv_context(world : WtoWorldSnap const&; now : float; myPos, hull c.topDanger = slot.threat.entries[top].danger c.threatDir = wto_xz_normalize(c.threatPos - myPos, hullFwd) for i in range(slot.threat.count) - if slot.threat.entries[i].aiming && slot.threat.entries[i].seesMe + assume entry = slot.threat.entries[i] + if entry.aiming && entry.seesMe c.aimingCount++ - c.urgent = slot.order.urgency == WTO_URGENCY_HIGH || c.distGoal > 130.0 + c.nearThreat = c.nearThreat || entry.dist <= WTO_AI_FC_CLOSE_RANGE_M + c.urgent = slot.order.valid && slot.order.urgency == WTO_URGENCY_HIGH c.offensive = wto_order_is_offensive(slot.order.role) + c.targetValue = min(1.0, wto_threat_danger_of(slot, p.targetEid)) * slot.trigger.hitProbAligned assume tr = slot.trigger - c.haltWanted = (now - tr.wantSpeedAt) <= WTO_AI_TACTICS_TICK_SEC * 3.0 && tr.wantSpeedMps <= WTO_AI_FC_STOP_SPEED_MAX_MPS + let requestFresh = (now - tr.wantSpeedAt) <= WTO_AI_TACTICS_TICK_SEC * 3.0 + c.haltWanted = requestFresh && tr.targetEid == p.targetEid && slot.fire.gunReady && !slot.spec.isAutocannon && tr.wantSpeedMps <= WTO_AI_FC_STOP_SPEED_MAX_MPS + c.turnWanted = !slot.fire.reloading && wto_face_has_request(slot) c.stopRangeOk = c.hasTarget && wto_bhv_stop_range_ok(c.distTarget, slot) c.stale = stale c.crowded = slot.crowd.isCrowded @@ -121,14 +127,18 @@ def private wto_bhv_scores(now : float; c : WtoBhvCtx const&; slot : WtoBotSlot for i in range(WTO_BHV_COUNT) s[i] = 0.0 let urgentF = c.urgent ? 1.0 : 0.0 - if !c.atGoal + if !c.atGoal && c.holdReason != WTO_HOLD_RALLY s[WTO_BHV_ADVANCE] = c.hasTarget ? 0.0 : WTO_AI_BHV_ADVANCE - s[WTO_BHV_ENGAGE] = c.hasTarget ? (WTO_AI_BHV_ENGAGE + WTO_AI_BHV_URGENCY_W * urgentF) : 0.0 - if c.hasTarget && c.haltWanted && c.stopRangeOk && !c.atGoal && now >= slot.tactics.shortHaltCooldownUntil + if c.hasTarget + s[WTO_BHV_ENGAGE] = WTO_AI_BHV_ENGAGE + WTO_AI_BHV_URGENCY_W * urgentF + WTO_AI_BHV_TARGET_VALUE_W * c.targetValue + let halting = slot.tactics.behavior == WTO_BHV_HALT && slot.tactics.state == WTO_STATE_SHORT_HALT + let haltRequest = c.haltWanted || c.turnWanted || halting + if haltRequest && c.stopRangeOk && !c.atGoal && now >= slot.tactics.shortHaltCooldownUntil let crossfire = float(max(0, c.aimingCount - 1)) - s[WTO_BHV_HALT] = WTO_AI_BHV_HALT + WTO_AI_BHV_URGENCY_W * (1.0 - urgentF) - WTO_AI_BHV_CROSSFIRE * crossfire + let nearBonus = c.nearThreat ? WTO_AI_BHV_NEAR_HALT_BONUS : 0.0 + s[WTO_BHV_HALT] = WTO_AI_BHV_HALT + WTO_AI_BHV_URGENCY_W * (1.0 - urgentF) + nearBonus - WTO_AI_BHV_CROSSFIRE * crossfire let coverRetry = now - slot.tactics.coverFailedAt >= WTO_AI_BHV_COVER_RETRY_SEC - if slot.fire.reloading && (c.hasTarget || c.remembered) && !slot.spec.isAutocannonBelt && coverRetry + if slot.fire.reloading && (c.hasTarget || c.remembered) && !slot.spec.isAutocannon && coverRetry let pushing = c.offensive && c.urgent ? 1.0 : 0.0 s[WTO_BHV_COVER] = WTO_AI_BHV_COVER + WTO_AI_BHV_COVER_DANGER_W * min(1.0, c.topDanger) - WTO_AI_BHV_COVER_OFFENSIVE * pushing if c.stale || slot.tactics.repositionActive @@ -137,6 +147,8 @@ def private wto_bhv_scores(now : float; c : WtoBhvCtx const&; slot : WtoBotSlot s[WTO_BHV_HOLD] = WTO_AI_BHV_HOLD if (c.crowded || now < slot.tactics.disperseUntil) && c.distTarget > WTO_AI_FC_CLOSE_RANGE_M s[WTO_BHV_DISPERSE] = WTO_AI_BHV_DISPERSE + for i in range(WTO_BHV_COUNT) + s[i] = clamp(s[i], 0.0, 1.0) def private wto_bhv_best(s : float[9] const&; skip : int; var bestScore, secondScore : float&; var second : int&) : int var best = WTO_BHV_ADVANCE @@ -156,19 +168,38 @@ def private wto_bhv_best(s : float[9] const&; skip : int; var bestScore, secondS second = i return best -// Scores now if due (or `force`, after the running behavior ended itself: it is then left out), -// and switches when the commitment allows it. +def private wto_bhv_hold_sec(bhv : int) : float + if bhv == WTO_BHV_ADVANCE + return WTO_AI_BHV_ADVANCE_HOLD_SEC + if bhv == WTO_BHV_ENGAGE + return WTO_AI_BHV_ENGAGE_HOLD_SEC + if bhv == WTO_BHV_HALT + return WTO_AI_BHV_HALT_HOLD_SEC + if bhv == WTO_BHV_COVER + return WTO_AI_BHV_COVER_HOLD_SEC + if bhv == WTO_BHV_REPOSITION + return WTO_AI_BHV_REPOSITION_HOLD_SEC + if bhv == WTO_BHV_HOLD + return WTO_AI_BHV_POST_HOLD_SEC + if bhv == WTO_BHV_DISPERSE + return WTO_AI_BHV_DISPERSE_HOLD_SEC + return 0.0 + +// The retreat action owns movement until arrival or timeout. Damage handling runs before this. [never_inline] def public wto_bhv_choose(now : float; c : WtoBhvCtx const&; force : bool; var slot : WtoBotSlot&) assume tac = slot.tactics - let hit = slot.perceive.lastDamagedAt > tac.scoredDamageAt - let due = (force || hit || now >= tac.nextScoreAt || c.hasTarget != tac.scoredHasTarget || + if !force && tac.behavior == WTO_BHV_COVER && tac.state == WTO_STATE_RETREAT_COVER + return + let emergency = slot.perceive.lastDamagedAt > tac.scoredDamageAt || (c.nearThreat && !tac.scoredNearThreat) + let due = (force || emergency || now >= tac.nextScoreAt || c.hasTarget != tac.scoredHasTarget || slot.fire.reloading != tac.scoredReloading) if !due return tac.nextScoreAt = now + WTO_AI_BHV_SCORE_SEC tac.scoredHasTarget = c.hasTarget tac.scoredReloading = slot.fire.reloading + tac.scoredNearThreat = c.nearThreat tac.scoredDamageAt = slot.perceive.lastDamagedAt var s : float[9] wto_bhv_scores(now, c, slot, s) @@ -177,12 +208,12 @@ def public wto_bhv_choose(now : float; c : WtoBhvCtx const&; force : bool; var s var second = -1 let best = wto_bhv_best(s, force ? tac.behavior : -1, bestScore, secondScore, second) let cur = tac.behavior - let curScore = (cur >= 0 && cur < WTO_BHV_COUNT) ? s[cur] : 0.0 + let curScore = s[cur] tac.behaviorScore = curScore if best == cur || bestScore <= 0.0 return - let held = (now - tac.behaviorSince) < WTO_AI_BHV_MIN_HOLD_SEC && !hit - if !force && curScore > 0.0 && (held || bestScore < curScore + WTO_AI_BHV_SWITCH_MARGIN) + let held = (now - tac.behaviorSince) < wto_bhv_hold_sec(cur) + if !force && curScore > 0.0 && held && !emergency && bestScore < curScore + WTO_AI_BHV_SWITCH_MARGIN return if WTO_AI_DIAG_TELEMETRY let secondName = second >= 0 ? wto_bhv_name(second) : "-" diff --git a/game-ai/ground/wto_ai_combat_types_common.das b/game-ai/ground/wto_ai_combat_types_common.das index 89a9ad0..d173e47 100644 --- a/game-ai/ground/wto_ai_combat_types_common.das +++ b/game-ai/ground/wto_ai_combat_types_common.das @@ -88,6 +88,7 @@ struct public WtoPerceiveState lookAroundUntil : float = -100.0 // When the engaged target was last seen firing (it is likely reloading for a while after). targetShotAt : float = -100.0 + targetFleeting : bool = false // One discovered enemy in the bot's threat table (decision layer design, section 4). `seen`: seen // clearly (fireable); `seesMe`: in line of sight this tick; `aiming`: its hull points at the bot or @@ -118,13 +119,13 @@ struct public WtoTurretState lookEid : EntityId = INVALID_ENTITY_ID holdUntil : float = -100.0 -// Trigger channel (decision layer design, section 6). hitProb / threshold: the last estimate for -// the main weapon (hitProbAligned: the same with the barrel on target); aimSlackDeg: how far off -// an autocannon may be and still fire; wantSpeedMps: the highest own speed at which the shot -// would reach the threshold (99 = no limit, 0 = only standing), a request the hull channel -// weighs. biasEpoch changes the aiming bias once per shooting opportunity (per shot, or per -// autocannon burst). burst*: the autocannon's current burst and pause; coax*: the same for the -// secondary and coaxial weapons, coaxBlocked a bit per weapon group failing its last check. +[safe_when_uninitialized] +struct public WtoWeaponBurst + untilAt : float = -100.0 + pauseUntil : float = -100.0 + lastShotAt : float = -100.0 + +// The main gun's hit estimate and speed request, plus independent burst timers. [safe_when_uninitialized] struct public WtoTriggerState hitProb : float = 0.0 @@ -133,16 +134,13 @@ struct public WtoTriggerState aimSlackDeg : float = 1.0 wantSpeedMps : float = 99.0 wantSpeedAt : float = -100.0 + targetEid : EntityId = INVALID_ENTITY_ID biasEpoch : int = 0 burstUntil : float = -100.0 burstPauseUntil : float = -100.0 - burstCheckedUntil : float = -100.0 - coaxBurstUntil : float = -100.0 - coaxPauseUntil : float = -100.0 - coaxCheckedUntil : float = -100.0 - coaxBlocked : int = 0 - coaxShots : int = 0 - lastLogAt : float = -100.0 + secondary : WtoWeaponBurst = WtoWeaponBurst() + coaxial : WtoWeaponBurst = WtoWeaponBurst() + auxShots : int = 0 [safe_when_uninitialized] struct public WtoGunTraverse @@ -152,6 +150,15 @@ struct public WtoGunTraverse hasPitchTable : bool = false pitchSector : float4 = float4(1.0, 0.0, 1.0, 0.0) +[safe_when_uninitialized] +struct public WtoMountFire + shellHash : uint = 0u + shellValid : bool = false + automatic : bool = false + shell : WtoShellProfile = WtoShellProfile() + traverseReady : bool = false + traverse : WtoGunTraverse = WtoGunTraverse() + [safe_when_uninitialized] struct public WtoFireState turretNo : int = -1 @@ -164,6 +171,11 @@ struct public WtoFireState gunDamaged : bool = false notReadySince : float = -100.0 loadedBulletIdx : int = -1 + ammoRemaining : int = -1 + rackTurret : int = -1 + rackRounds : int = -1 + rackBySet : int[12] + mounts : WtoMountFire[16] activeSpeedMps : float = 880.0 activeDragCx : float = 0.35 activeMassKg : float = 10.0 diff --git a/game-ai/ground/wto_ai_drive_common.das b/game-ai/ground/wto_ai_drive_common.das index a9fa33d..d3b7864 100644 --- a/game-ai/ground/wto_ai_drive_common.das +++ b/game-ai/ground/wto_ai_drive_common.das @@ -127,10 +127,11 @@ def private wto_compute_reverse_axes(cmd : WtoDriveCmd const&; spec : WtoVehicle // Coordinate-free signed rear angle: >0 means desired rear travel lies toward hull LEFT (+Z). let rearErr = atan2(dot(wishRear, left), dot(wishRear, rear)) outStr = clamp(rearErr * 1.45 + omega * 0.28, -1.0, 1.0) * WTO_AI_NAV_STEER_SIGN - let maxSafeRev = min(spec.vMaxRev, sqrt(max(1.0, (cmd.rearClearM - 1.8) * 2.2))) - let vTarget = -clamp(cmd.speedMps, 1.2, max(1.4, maxSafeRev)) - let vErr = vTarget - vFwd - outThr = vErr < -0.15 ? clamp(-0.52 + vErr * 0.32, -1.0, -0.35) : -0.28 + let clearanceCap = sqrt(max(0.0, (cmd.rearClearM - 1.8) * 2.2)) + let vTarget = min(cmd.speedMps, min(spec.vMaxRev, clearanceCap)) + let response = (vTarget + vFwd) / WTO_AI_NAV_MOVING_FIRE_SPEED_RAMP_MPS + outThr = -clamp(response, 0.0, 1.0) + outBrk = clamp(-response, 0.0, 1.0) [never_inline] def private wto_compute_cruise_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleSpec const&; diff --git a/game-ai/ground/wto_ai_estimate_common.das b/game-ai/ground/wto_ai_estimate_common.das index cc94929..b496246 100644 --- a/game-ai/ground/wto_ai_estimate_common.das +++ b/game-ai/ground/wto_ai_estimate_common.das @@ -6,6 +6,7 @@ module wto_ai_estimate_common shared require ecs require math +require Ballistics require %appGame.wtoai.wto_ai_config_common require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_combat_types_common @@ -91,30 +92,37 @@ def public wto_est_on_los_lost(now : float; selfEid : EntityId; var p : WtoPerce if WTO_AI_DIAG_TELEMETRY print("WTO_AI|WATCH|eid={uint(selfEid)}|tgt={uint(p.targetEid)}|dur={dur}\n") +// The same estimated target motion is used to lead and to validate the real barrel shot. +def public wto_est_target_vel(p : WtoPerceiveState const&) : float3 + let scale = p.sampleCount >= 2 ? clamp(0.35 + 0.65 * p.velQuality, 0.0, 1.0) : 0.0 + return p.estVel * scale + +def public wto_shot_drag(dragCx, massKg, caliberM : float) : float + let area = 0.25 * WTO_PI * caliberM * caliberM + return 0.5 * 1.225 * dragCx * area / max(0.1, massKg) + +def private wto_est_avg_speed(speedMps, drag, dist : float) : float + let dragDist = min(drag * dist, 60.0) + if dragDist <= 1.0e-4 + return max(120.0, speedMps) + return max(120.0, speedMps * (dragDist / (exp(dragDist) - 1.0))) + [never_inline] -def public wto_est_compute_biased_lead(muzzlePos, myVel, aimBase : float3; - var slot : WtoBotSlot&; - var outLeadPt : float3&) : float +def private wto_est_compute_biased_lead(muzzlePos, myVel, aimBase : float3; speedMps, drag : float; + var slot : WtoBotSlot&; var outLeadPt : float3&) : float assume p = slot.perceive let rawDelta = aimBase - muzzlePos let rawDist = length(rawDelta) - let dragLoss = clamp(slot.fire.activeDragCx * 0.00011 * rawDist, 0.0, 0.28) - let vEff = max(120.0, slot.fire.activeSpeedMps * (1.0 - dragLoss)) - - // Lead uses ONLY our own visual velocity estimate, scaled by observation quality. - let leadScale = p.sampleCount >= 2 ? clamp(0.35 + 0.65 * p.velQuality, 0.0, 1.0) : 0.0 - let usedVel = p.estVel * leadScale + let vEff = wto_est_avg_speed(speedMps, drag, rawDist) + let usedVel = wto_est_target_vel(p) var leadPt = aimBase var tof = 0.0 for _iter in range(2) tof = clamp(length(leadPt - muzzlePos) / vEff, 0.0, 3.5) - leadPt = aimBase + usedVel * tof - myVel * (tof * 0.85) + leadPt = aimBase + (usedVel - myVel) * tof - // Sample bounded natural bias ONCE per shooting opportunity (target + shot + state + 12m grid). - let gx = uint(int(muzzlePos.x / 12.0) + 4096) - let gz = uint(int(muzzlePos.z / 12.0) + 4096) - let key = (uint(p.targetEid) ^ (uint(slot.trigger.biasEpoch) * 2654435761u) ^ - (uint(slot.tactics.state) * 40503u) ^ (gx * 73856093u) ^ (gz * 19349663u)) + // Keep the same bias until the target, shot opportunity or velocity estimate changes. + let key = uint(p.targetEid) ^ (uint(slot.trigger.biasEpoch) * 2654435761u) if !p.oppSeeded || p.oppKey != key p.oppKey = key p.oppSeeded = true @@ -125,10 +133,28 @@ def public wto_est_compute_biased_lead(muzzlePos, myVel, aimBase : float3; // Error envelope shrinks naturally as observation quality converges. let tgtSpd = length(p.estVel) let leadSpread = tgtSpd * tof * WTO_AI_EST_LEAD_ERR_FRAC * (1.0 - 0.72 * p.velQuality) - let distSpread = WTO_AI_EST_BASE_SIGMA_M * clamp(rawDist / 350.0, 0.25, 2.6) * (1.2 - 0.55 * p.velQuality) + let distSpread = (1.0 - WTO_AI_FC_AIM_SKILL) * WTO_AI_EST_BASE_SIGMA_M * clamp(rawDist / 350.0, 0.25, 2.6) * (1.2 - 0.55 * p.velQuality) let latOff = clamp((leadSpread + distSpread) * p.oppBiasU, -WTO_AI_EST_MAX_BIAS_M, WTO_AI_EST_MAX_BIAS_M) let vertOff = clamp(distSpread * 0.65 * p.oppBiasV, -WTO_AI_EST_MAX_BIAS_M * 0.5, WTO_AI_EST_MAX_BIAS_M * 0.5) let toAimXZ = wto_xz_normalize(rawDelta, float3(1.0, 0.0, 0.0)) let latAxis = float3(-toAimXZ.z, 0.0, toAimXZ.x) outLeadPt = leadPt + latAxis * latOff + float3(0.0, vertOff, 0.0) return rawDist + +[never_inline] +def public wto_solve_ballistic_aim(muzzlePos, myVel, aimBase : float3; speedMps, dragCx, massKg, caliberM : float; + var slot : WtoBotSlot&; var outAimPt, outWishDir : float3&) : float + var leadPt = aimBase + let drag = wto_shot_drag(dragCx, massKg, caliberM) + let rawDist = wto_est_compute_biased_lead(muzzlePos, myVel, aimBase, speedMps, drag, slot, leadPt) + let vEff = wto_est_avg_speed(speedMps, drag, rawDist) + outAimPt = leadPt + var arcDir = float3(0.0, 0.0, 0.0) + if calculate_arc_low_start_dir(muzzlePos, leadPt, vEff, arcDir) && length_sq(arcDir) > 0.25 + outWishDir = normalize(arcDir) + else + let d = max(1.0, length(leadPt - muzzlePos)) + let tof = d / vEff + let dropComp = float3(0.0, 0.5 * 9.81 * tof * tof, 0.0) + outWishDir = normalize(leadPt + dropComp - muzzlePos) + return rawDist diff --git a/game-ai/ground/wto_ai_facing_common.das b/game-ai/ground/wto_ai_facing_common.das index 95f34ab..73c5c25 100644 --- a/game-ai/ground/wto_ai_facing_common.das +++ b/game-ai/ground/wto_ai_facing_common.das @@ -1,9 +1,4 @@ -// Facing constraint of the hull channel (decision layer design, 7.3). Until penetration can be -// estimated, medium tanks, heavy tanks and tank destroyers turn the front toward the most dangerous -// known threat, angled by behavior.hullAngleDeg to the side nearer the current heading; light -// vehicles and SPAA are not bound. A target outside the gun's traverse overrides this for every -// vehicle (the hull turns the gun onto it). While advancing toward a nearby goal with the threat -// behind the direction of travel, the bot drives the route backwards instead of showing its rear. +// Hull facing and the direction of travel along a navigation corridor. options indenting = 2 options no_global_heap = true module wto_ai_facing_common shared @@ -15,9 +10,11 @@ require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_combat_types_common require %appGame.wtoai.wto_ai_types_common require %appGame.wtoai.wto_ai_nav_types_common +require %appGame.wtoai.wto_ai_follow_common +require %appGame.wtoai.wto_ai_drive_common -def private wto_face_bound_role(role : int) : bool - return role == WTO_ROLE_MEDIUM || role == WTO_ROLE_HEAVY || role == WTO_ROLE_TD +def private wto_face_bound(spec : WtoVehicleSpec const&) : bool + return spec.isTracked && (spec.role == WTO_ROLE_MEDIUM || spec.role == WTO_ROLE_HEAVY || spec.role == WTO_ROLE_TD) def private wto_face_rotate(dir : float3; rad : float) : float3 return float3(dir.x * cos(rad) - dir.z * sin(rad), 0.0, dir.x * sin(rad) + dir.z * cos(rad)) @@ -42,42 +39,70 @@ def private wto_face_threat_pos(now : float; slot : WtoBotSlot const&; var outPo return true return false -// Per tactics tick, before the behaviors run. +// The turret can request a turn for a visible target that is outside the mount traverse. +def public wto_face_has_request(slot : WtoBotSlot const&) : bool + let target = slot.fire.hullAimTarget + if !target || !slot.perceive.hasClearLos || target != slot.perceive.targetEid || slot.tactics.immobilized + return false + return wto_pivot_drive_mode(slot.spec, slot.nav.frontClearM, slot.nav.rearClearM, true) != WTO_DRIVE_HALT + [never_inline] def public wto_face_update(now : float; myPos, hullFwd : float3; var slot : WtoBotSlot&) assume tac = slot.tactics tac.faceActive = false tac.faceFromThreat = false - if !!slot.fire.hullAimTarget && slot.fire.hullAimTarget == slot.perceive.targetEid - tac.faceDir = wto_xz_normalize(slot.fire.hullAimDir, hullFwd) - tac.faceActive = true - return + tac.faceForGun = false + if !slot.perceive.hasClearLos || tac.gunFacingTarget != slot.perceive.targetEid + tac.gunFacingTarget = INVALID_ENTITY_ID var threatPos = myPos - if !wto_face_bound_role(slot.spec.role) || !wto_face_threat_pos(now, slot, threatPos) + if !wto_face_bound(slot.spec) || !wto_face_threat_pos(now, slot, threatPos) return tac.faceThreatDir = wto_xz_normalize(threatPos - myPos, hullFwd) tac.faceDir = wto_face_angled(tac.faceThreatDir, hullFwd) tac.faceActive = true tac.faceFromThreat = true -// Whether to drive the route backwards this tick (advancing or engaging toward a goal within -// behavior.reverseMaxGoalDistM with the faced threat more than reverseTravelAngleDeg off the -// direction of travel). A decision is kept for at least behavior.reverseHoldSec. +// A standing action can keep the hull facing its gun's target if the strongest threat remains in front. [never_inline] -def public wto_face_reverse_update(now, distGoal : float; var slot : WtoBotSlot&) +def public wto_face_accept_gun(hullFwd : float3; var slot : WtoBotSlot&) assume tac = slot.tactics + if !wto_face_has_request(slot) && !tac.gunFacingTarget + return + let wanted = wto_xz_normalize(slot.fire.hullAimDir, hullFwd) + let allowedAngle = min(90.0, WTO_AI_BHV_HULL_ANGLE_DEG + WTO_AI_BHV_FACE_TOL_DEG) + if tac.faceFromThreat && dot(wanted, tac.faceThreatDir) < cos(allowedAngle * WTO_DEG_TO_RAD) + tac.gunFacingTarget = INVALID_ENTITY_ID + return + tac.gunFacingTarget = slot.perceive.targetEid + tac.faceDir = wanted + tac.faceActive = true + tac.faceForGun = true + +def public wto_face_side_exposed(slot : WtoBotSlot const&) : bool + assume tac = slot.tactics + if !tac.faceFromThreat + return false + let travel = wto_xz_normalize(slot.nav.steerDir, tac.faceThreatDir) + return abs(dot(travel, tac.faceThreatDir)) < sin(WTO_AI_BHV_FACE_TOL_DEG * WTO_DEG_TO_RAD) + +// Choose steering direction after tracking the active corridor and before updating traffic. +[never_inline] +def public wto_face_reverse_update(now : float; myPos, hullFwd : float3; var slot : WtoBotSlot&) + assume tac = slot.tactics + assume rt = slot.route let moving = tac.behavior == WTO_BHV_ADVANCE || tac.behavior == WTO_BHV_ENGAGE - let able = slot.spec.vMaxRev >= WTO_AI_BHV_REVERSE_MIN_MPS && !slot.tactics.immobilized - var want = moving && able && tac.faceFromThreat && distGoal <= WTO_AI_BHV_REVERSE_MAX_GOAL_M + let able = slot.spec.vMaxRev >= WTO_AI_BHV_REVERSE_MIN_MPS && !tac.immobilized + var want = moving && able && tac.faceFromThreat && rt.corridorLen >= 2 if want - let travel = wto_xz_normalize(slot.nav.steerDir, tac.faceThreatDir) - let offDeg = acos(clamp(dot(travel, tac.faceThreatDir), -1.0, 1.0)) * WTO_RAD_TO_DEG - want = offDeg >= WTO_AI_BHV_REVERSE_ANGLE_DEG + let seg = clamp(rt.segIdx, 0, rt.corridorLen - 2) + let travel = wto_xz_normalize(rt.corridor[seg + 1] - rt.corridor[seg], hullFwd) + let opposite = dot(travel, tac.faceThreatDir) <= cos(WTO_AI_BHV_REVERSE_ANGLE_DEG * WTO_DEG_TO_RAD) + want = opposite && wto_follow_near_turn(rt, myPos, WTO_AI_BHV_REVERSE_MAX_TURN_M) if want == tac.reverseTravel return - if (now - tac.reverseSince) < WTO_AI_BHV_REVERSE_HOLD_SEC && moving + if want && (now - tac.reverseSince) < WTO_AI_BHV_REVERSE_HOLD_SEC return tac.reverseTravel = want tac.reverseSince = now if WTO_AI_DIAG_TELEMETRY - print("WTO_AI|REVERSE_TRAVEL|t={now}|eid={uint(slot.eid)}|on={want}|goal={distGoal}\n") + print("WTO_AI|REVERSE_TRAVEL|t={now}|eid={uint(slot.eid)}|on={want}\n") diff --git a/game-ai/ground/wto_ai_fire_aux_common.das b/game-ai/ground/wto_ai_fire_aux_common.das index 56b48c4..af55b90 100644 --- a/game-ai/ground/wto_ai_fire_aux_common.das +++ b/game-ai/ground/wto_ai_fire_aux_common.das @@ -1,9 +1,4 @@ -// Secondary cannon and coaxial weapons (decision layer design, 6.4): each weapon group decides for -// itself, alongside the main gun, so they can fire in the same moment. They fire bursts at the -// engaged target while their own barrel is within the aim slack of it, at light vehicles (any -// vehicle with fireControl.auxFireAtArmor) within fireControl.auxMaxRangeM. Before a burst and -// every burstRecheckSec, each group's straight line from its own muzzle is checked for hard cover -// and friendlies; a group that fails is held until the next check. +// Secondary and coaxial guns have their own aim solution, readiness, burst timer and safety checks. options indenting = 2 options no_global_heap = true module wto_ai_fire_aux_common shared @@ -16,99 +11,138 @@ require Unit require Weapon require %game.utils.utils_common require %appGame.wtoai.wto_ai_config_common -require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_combat_types_common require %appGame.wtoai.wto_ai_types_common require %appGame.wtoai.wto_ai_world_common -require %appGame.wtoai.wto_ai_sight_common +require %appGame.wtoai.wto_ai_estimate_common require %appGame.wtoai.wto_ai_trigger_common -require %appGame.wtoai.wto_ai_fire_gate_common +require %appGame.wtoai.wto_ai_traverse_common +require %appGame.wtoai.wto_ai_weapon_profile_common +require %appGame.wtoai.wto_ai_fire_checks_common -let private AUX_SECONDARY_BIT = 1 -let private AUX_COAXIAL_BIT = 2 +def private wto_aux_in_range(dist : float) : bool + return WTO_AI_FC_AUX_ENABLED && dist <= min(WTO_AI_FC_AUX_MAX_RANGE_M, WTO_AI_FC_MAX_RANGE_M) + +def private wto_aux_group(groupNo : int) : bool + return groupNo == int(WeaponTriggerGroups.TRIGGER_GROUP_SECONDARY) || groupNo == int(WeaponTriggerGroups.TRIGGER_GROUP_COAXIAL_GUN) -// The group's first working weapon that is ready to fire: its muzzle and barrel direction. [never_inline] -def private wto_aux_ready_barrel(unit : Unit const?; group : WeaponTriggerGroups; var outPos, outDir : float3&) : bool - var found = false +def public wto_fire_aux_aim(var unit : Unit?; className : string; dt, dist : float; var slot : WtoBotSlot&) : bool + if !wto_aux_in_range(dist) + return false + var changed = false + for tIdx, turret in iter_range(unit.weap.turret), unit.weap.turret + if !wto_aux_group(int(turret.triggerGroupNo)) || tIdx >= length(slot.fire.mounts) + continue + let weapon = get_weapon(unit.weap.Weapons, int(turret.triggerNo), int(turret.weaponIndex)) + if weapon == null || weapon.isDummyGun || weapon.prop.launcher + continue + let gun = as_gun(weapon) + assume mount = slot.fire.mounts[tIdx] + if gun == null || gun.isInoperable || !wto_mount_load_shell(unit, className, tIdx, gun, mount) + continue + var gunTm : float3x4 + weapon_calcShootTm(weapon, unit.unitTm, gunTm) + if length_sq(gunTm[0]) <= 0.25 + continue + let base = slot.perceive.visibleAimPt + var aimPt = base + var direction = gunTm[0] + let _range = wto_solve_ballistic_aim(gunTm[3], unit.vel, base, mount.shell.speedMps, mount.shell.dragCx, mount.shell.massKg, mount.shell.caliberM, slot, aimPt, direction) + if wto_aim_aux_mount(unit, className, dt, tIdx, direction, mount) + changed = true + return changed + +[never_inline] +def private wto_aux_check_barrel(world : WtoWorldSnap const&; unit : Unit const?; weapon : Weapon const?; + now, dist : float; target : WtoUnitSnap const&; mount : WtoMountFire const&; + var slot : WtoBotSlot&) : bool + var gunTm : float3x4 + weapon_calcShootTm(weapon, unit.unitTm, gunTm) + if length_sq(gunTm[0]) <= 0.25 + return false + let actual = normalize(gunTm[0]) + let base = slot.perceive.visibleAimPt + var aimPt = base + var direction = actual + let _range = wto_solve_ballistic_aim(gunTm[3], unit.vel, base, mount.shell.speedMps, mount.shell.dragCx, mount.shell.massKg, mount.shell.caliberM, slot, aimPt, direction) + let error = wto_trig_aim_error(actual, direction) + if !wto_trig_aux_aim_ok(now, dist, length(unit.vel), error, unit.pos, target, mount, slot) + return false + var blockCode = WTO_BLOCK_NONE + return wto_fire_check_barrel(world, unit, slot, gunTm[3], actual, aimPt, mount.shell, !mount.automatic, blockCode) == WTO_DENY_OK + +// Count all guns the native trigger would fire, including barrels without a usable turret entry. +def private wto_aux_ready_count(unit : Unit const?; group : WeaponTriggerGroups) : int + var ready = 0 + var supported = true get_weapons_by_trigger_group(unit.weap.Weapons, group) <| $(weapons : array const#) for i in range(length(weapons)) - if found - break assume weapon = weapons[i] if weapon == null || weapon.isDummyGun continue let gun = as_gun(weapon) - if gun == null || gun.isInoperable || !gun.isReadyToShoot - continue - var tm : float3x4 - weapon_calcShootTm(weapon, unit.unitTm, tm) - if length_sq(tm[0]) > 0.25 - outPos = tm[3] - outDir = normalize(tm[0]) - found = true - return found + if weapon.prop.launcher || gun == null + supported = false + elif !gun.isInoperable && gun.isReadyToShoot + ready++ + return supported ? ready : 0 -// Hard cover or a friendly on the straight line from the group's muzzle (or no ready weapon). [never_inline] -def private wto_aux_blocked(world : WtoWorldSnap const&; unit : Unit const?; group : WeaponTriggerGroups; - aimPt : float3; slot : WtoBotSlot const&) : bool - var muzzle = unit.pos - var dir = unit.unitTm[0] - if !wto_aux_ready_barrel(unit, group, muzzle, dir) - return true - if wto_sight_hard_segment_blocked(world, slot.eid, slot.perceive.targetEid, muzzle, aimPt, 0.05, 0.35, 0.65) != WTO_BLOCK_NONE - return true - let flightSec = length(aimPt - muzzle) / 900.0 - return !wto_gate_friendly_segment_clear(world, slot.eid, slot.army, muzzle, aimPt, flightSec * 0.5) - -// Fires the group once when its ready barrel is within the aim slack and it passed the last check. -[never_inline] -def private wto_aux_fire_group(var unit : Unit?; group : WeaponTriggerGroups; bit : int; aimPt : float3; - var slot : WtoBotSlot&) - assume tr = slot.trigger - if (tr.coaxBlocked & bit) != 0 +def private wto_aux_fire_group(world : WtoWorldSnap const&; var unit : Unit?; className : string; + group : WeaponTriggerGroups; now, dist : float; target : WtoUnitSnap const&; + var slot : WtoBotSlot&; var burst : WtoWeaponBurst&; var fireBudget : int&) + if fireBudget <= 0 || (now >= burst.untilAt && now < burst.pauseUntil) return - var muzzle = unit.pos - var dir = unit.unitTm[0] - if !wto_aux_ready_barrel(unit, group, muzzle, dir) + let needed = wto_aux_ready_count(unit, group) + if needed <= 0 return - let toAim = aimPt - muzzle - let dist = length(toAim) - if dist < 1.0 || dot(dir, toAim / dist) < cos(tr.aimSlackDeg * WTO_DEG_TO_RAD) + var checked = 0 + var rapid = true + for tIdx, turret in iter_range(unit.weap.turret), unit.weap.turret + if int(turret.triggerGroupNo) != int(group) || tIdx >= length(slot.fire.mounts) + continue + let weapon = get_weapon(unit.weap.Weapons, int(turret.triggerNo), int(turret.weaponIndex)) + if weapon == null || weapon.isDummyGun + continue + let gun = as_gun(weapon) + if gun == null || gun.isInoperable || !gun.isReadyToShoot + continue + assume mount = slot.fire.mounts[tIdx] + if checked == 0 + fireBudget-- + if (!wto_mount_load_shell(unit, className, tIdx, gun, mount) || + !wto_aux_check_barrel(world, unit, weapon, now, dist, target, mount, slot)) + return + checked++ + rapid = rapid && mount.automatic + if checked != needed + return + if rapid + var opening = false + if wto_trig_burst_gate(now, true, burst.untilAt, burst.pauseUntil, opening) != WTO_DENY_OK + return + elif now - burst.lastShotAt < WTO_AI_FC_MIN_SHOT_INTERVAL_SEC return unit_single_shot(unit, int(group)) - tr.coaxShots++ + burst.lastShotAt = now + slot.trigger.auxShots++ -def private wto_aux_target_allowed(world : WtoWorldSnap const&; slot : WtoBotSlot const&) : bool +[never_inline] +def public wto_fire_aux_update(world : WtoWorldSnap const&; var unit : Unit?; className : string; + now, dist : float; var slot : WtoBotSlot&; var fireBudget : int&) + if !wto_aux_in_range(dist) + return let idx = wto_world_find_unit(world, slot.perceive.targetEid) if idx < 0 - return false - assume tgt = world.units[idx] - return WTO_AI_FC_AUX_FIRE_AT_ARMOR || tgt.isLightTag || tgt.halfWid < 1.35 - -// Per frame while the main weapon is engaging a target in sight. -[never_inline] -def public wto_fire_aux_update(world : WtoWorldSnap const&; var unit : Unit?; now, distXZ : float; aimPt : float3; - var slot : WtoBotSlot&; var fireBudget : int&) - assume tr = slot.trigger - if !WTO_AI_FC_AUX_ENABLED || unit == null || unit.weap == null || distXZ > WTO_AI_FC_AUX_MAX_RANGE_M return - if !wto_aux_target_allowed(world, slot) - return - var started = false - let onTarget = slot.fire.lastAimErrDeg <= tr.aimSlackDeg - if wto_trig_burst_gate(now, onTarget, tr.coaxBurstUntil, tr.coaxPauseUntil, started) != WTO_DENY_OK - return - if started || now >= tr.coaxCheckedUntil - if fireBudget <= 0 - return - fireBudget-- - tr.coaxBlocked = 0 - if wto_aux_blocked(world, unit, WeaponTriggerGroups.TRIGGER_GROUP_SECONDARY, aimPt, slot) - tr.coaxBlocked |= AUX_SECONDARY_BIT - if wto_aux_blocked(world, unit, WeaponTriggerGroups.TRIGGER_GROUP_COAXIAL_GUN, aimPt, slot) - tr.coaxBlocked |= AUX_COAXIAL_BIT - tr.coaxCheckedUntil = now + WTO_AI_FC_BURST_RECHECK_SEC - wto_aux_fire_group(unit, WeaponTriggerGroups.TRIGGER_GROUP_SECONDARY, AUX_SECONDARY_BIT, aimPt, slot) - wto_aux_fire_group(unit, WeaponTriggerGroups.TRIGGER_GROUP_COAXIAL_GUN, AUX_COAXIAL_BIT, aimPt, slot) + assume target = world.units[idx] + var secondary = slot.trigger.secondary + wto_aux_fire_group(world, unit, className, WeaponTriggerGroups.TRIGGER_GROUP_SECONDARY, now, dist, target, + slot, secondary, fireBudget) + slot.trigger.secondary = secondary + if WTO_AI_FC_AUX_FIRE_AT_ARMOR || target.isLightTag || target.halfWid < 1.35 + var coaxial = slot.trigger.coaxial + wto_aux_fire_group(world, unit, className, WeaponTriggerGroups.TRIGGER_GROUP_COAXIAL_GUN, now, dist, target, + slot, coaxial, fireBudget) + slot.trigger.coaxial = coaxial diff --git a/game-ai/ground/wto_ai_fire_checks_common.das b/game-ai/ground/wto_ai_fire_checks_common.das new file mode 100644 index 0000000..d9de437 --- /dev/null +++ b/game-ai/ground/wto_ai_fire_checks_common.das @@ -0,0 +1,110 @@ +// Per-barrel pre-fire checks: muzzle clearance, the drag-integrated trajectory and friendlies. +options indenting = 2 +options no_global_heap = true +module wto_ai_fire_checks_common shared + +require ecs +require math +require DagorMath +require Unit +require %appGame.wtoai.wto_ai_config_common +require %appGame.wtoai.wto_ai_math_common +require %appGame.wtoai.wto_ai_combat_types_common +require %appGame.wtoai.wto_ai_types_common +require %appGame.wtoai.wto_ai_sight_common +require %appGame.wtoai.wto_ai_estimate_common +require %appGame.wtoai.wto_ai_trigger_common +require %appGame.wtoai.wto_ai_world_common + +[safe_when_uninitialized] +struct private WtoShotWindow + center : float3 = float3(0.0, 0.0, 0.0) + velocity : float3 = float3(0.0, 0.0, 0.0) + along : float3 = float3(1.0, 0.0, 0.0) + halfWidth : float = 0.0 + halfHeight : float = 0.0 + +def private wto_shot_hits_window(window : WtoShotWindow const&; at : float3; time : float) : bool + let miss = at - (window.center + window.velocity * time) + let across = float3(-window.along.z, 0.0, window.along.x) + return abs(dot(miss, across)) <= window.halfWidth && abs(miss.y) <= window.halfHeight + +[never_inline] +def public wto_gate_friendly_segment_clear(world : WtoWorldSnap const&; selfEid : EntityId; + army : int; p0, p1 : float3; tMid : float) : bool + let delta = p1 - p0 + let segLen = length(delta) + if segLen < 0.2 + return true + let dir = delta / segLen + for i in range(world.unitCount) + assume u = world.units[i] + if !u.isAlive || !u.isGround || u.army != army || u.eid == selfEid + continue + let predPos = u.pos + u.vel * tMid + float3(0.0, 1.3, 0.0) + let along = clamp(dot(predPos - p0, dir), 0.0, segLen) + let clearR = WTO_AI_FC_FRIENDLY_CORRIDOR_M + u.halfWid + if length_sq(predPos - (p0 + dir * along)) < clearR * clearR + return false + return true + +[never_inline] +def private wto_gate_check_ballistic_arc(world : WtoWorldSnap const&; selfEid, targetEid : EntityId; army : int; + muzzlePos, liveDir, carrierVel : float3; shell : WtoShellProfile const&; + window : WtoShotWindow const&; checkMiss : bool; var outBlock : int&) : int + let dragK = wto_shot_drag(shell.dragCx, shell.massKg, shell.caliberM) + var cur = muzzlePos + var vel = liveDir * shell.speedMps + carrierVel + var t = 0.0 + for step in range(64) + let spd = length(vel) + let remaining = dot(window.center + window.velocity * t - cur, window.along) + if spd < 20.0 || remaining <= 0.0 + return WTO_DENY_AIM_ERR + let segWant = min(WTO_AI_FC_BALLISTIC_STEP_M, remaining) + let dt = clamp(segWant / spd, 0.004, 0.14) + let accel = float3(0.0, -9.81, 0.0) - vel * (dragK * spd) + var next = cur + vel * dt + accel * (0.5 * dt * dt) + let nextRemaining = dot(window.center + window.velocity * (t + dt) - next, window.along) + let ends = nextRemaining <= 0.0 + var segmentTime = dt + if ends + let fraction = clamp(remaining / max(1.0e-5, remaining - nextRemaining), 0.0, 1.0) + next = lerp(cur, next, fraction) + segmentTime *= fraction + let trimS = step == 0 ? 0.35 : 0.0 + let trimE = ends ? 0.65 : 0.0 + let blk = wto_sight_hard_segment_blocked(world, selfEid, targetEid, cur, next, WTO_AI_FC_BALLISTIC_SWEEP_R_M, trimS, trimE) + if blk != WTO_BLOCK_NONE + outBlock = blk + return WTO_DENY_ARC_HARD + if !wto_gate_friendly_segment_clear(world, selfEid, army, cur, next, t + segmentTime * 0.5) + return WTO_DENY_FRIENDLY + t += segmentTime + if ends + return (!checkMiss || wto_shot_hits_window(window, next, t)) ? WTO_DENY_OK : WTO_DENY_AIM_ERR + cur = next + vel = vel + accel * dt + return WTO_DENY_AIM_ERR + +[never_inline] +def public wto_fire_check_barrel(world : WtoWorldSnap const&; unit : Unit const?; + slot : WtoBotSlot const&; muzzlePos, liveDir, aimPt : float3; + shell : WtoShellProfile const&; checkMiss : bool; + var outBlock : int&) : int + let straightBlk = wto_sight_hard_segment_blocked(world, slot.eid, slot.perceive.targetEid, muzzlePos, aimPt, 0.05, 0.35, 0.65) + if straightBlk != WTO_BLOCK_NONE + outBlock = straightBlk + return WTO_DENY_MUZZLE_HARD + let idx = wto_world_find_unit(world, slot.perceive.targetEid) + if idx < 0 + return WTO_DENY_NO_TARGET + assume target = world.units[idx] + var window = WtoShotWindow() + window.center = slot.perceive.visibleAimPt + window.velocity = wto_est_target_vel(slot.perceive) + window.along = wto_xz_normalize(window.center - muzzlePos, liveDir) + let dist = sqrt(wto_xz_dist_sq(unit.pos, target.pos)) + wto_trig_target_half(unit.pos, target, dist, slot.perceive.visiblePointCount, window.halfWidth, window.halfHeight) + return wto_gate_check_ballistic_arc(world, slot.eid, slot.perceive.targetEid, slot.army, + muzzlePos, liveDir, unit.vel, shell, window, checkMiss, outBlock) diff --git a/game-ai/ground/wto_ai_fire_common.das b/game-ai/ground/wto_ai_fire_common.das index 2958eba..97dd288 100644 --- a/game-ai/ground/wto_ai_fire_common.das +++ b/game-ai/ground/wto_ai_fire_common.das @@ -14,7 +14,6 @@ require Mission require Unit require IGroundModel require Weapon -require Ballistics require %game.utils.utils_common require %appGame.wtoai.wto_ai_config_common require %appGame.wtoai.wto_ai_math_common @@ -27,6 +26,7 @@ require %appGame.wtoai.wto_ai_traverse_common require %appGame.wtoai.wto_ai_turret_common require %appGame.wtoai.wto_ai_trigger_common require %appGame.wtoai.wto_ai_fire_aux_common +require %appGame.wtoai.wto_ai_ammo_common [never_inline] def private wto_sync_active_shell(gun : WTGun const?; spec : WtoVehicleSpec const&; var fc : WtoFireState&) @@ -55,8 +55,8 @@ def private wto_sync_active_shell(gun : WTGun const?; spec : WtoVehicleSpec cons return [never_inline] -def private wto_select_next_shell(var gun : WTGun?; spec : WtoVehicleSpec const&; wantSoft : bool) - if gun == null || spec.isAutocannonBelt +def private wto_select_next_shell(var gun : WTGun?; spec : WtoVehicleSpec const&; wantSoft : bool; fc : WtoFireState const&) + if gun == null || spec.isAutocannon return let setCount = length(gun.properties.bulletSets) if setCount < 2 @@ -67,7 +67,9 @@ def private wto_select_next_shell(var gun : WTGun?; spec : WtoVehicleSpec const& var firstAvail = -1 for bsIdx in range(setCount) assume bs = gun.properties.bulletSets[bsIdx] - if bs.bulletsCount <= 0 || length(bs.bullet) <= 0 || bs.bullet[0] == null + let loaded = bsIdx == int(gun.chosenBulletType) && gun.currentLoadedAmmoCount > 0 + let stocked = fc.rackTurret == fc.turretNo && bsIdx < length(fc.rackBySet) && fc.rackBySet[bsIdx] > 0 + if !(loaded || stocked || bs.bulletsCount > 0) || length(bs.bullet) <= 0 || bs.bullet[0] == null continue if firstAvail < 0 firstAvail = bsIdx @@ -80,7 +82,7 @@ def private wto_select_next_shell(var gun : WTGun?; spec : WtoVehicleSpec const& continue if spec.shells[si].isSoftShell && bestSoft < 0 bestSoft = bsIdx - elif spec.shells[si].isAntiArmor && spec.shells[si].penMm > bestArmorPen + if spec.shells[si].isAntiArmor && spec.shells[si].penMm > bestArmorPen bestArmor = bsIdx bestArmorPen = spec.shells[si].penMm break @@ -97,7 +99,7 @@ def private wto_take_primary_gun(var gun : WTGun?; turretNo, previousTurret : in fc.turretNo = turretNo if fc.turretNo != previousTurret fc.loadedBulletIdx = -1 - wto_select_next_shell(gun, spec, wantSoftShell) + wto_select_next_shell(gun, spec, wantSoftShell, fc) wto_sync_active_shell(gun, spec, fc) [never_inline] @@ -109,6 +111,7 @@ def private wto_inspect_primary_weapon(var unit : Unit?; now : float; fc.gunReady = false fc.reloading = false fc.gunDamaged = false + fc.ammoRemaining = -1 if unit == null || unit.weap == null return -1 var selected = -1 @@ -141,8 +144,9 @@ def private wto_inspect_primary_weapon(var unit : Unit?; now : float; if selected < 0 selected = index wto_take_primary_gun(gun, int(weapon.turretNo), previousTurret, spec, wantSoftShell, fc) - if gun.isReadyToShoot - fc.gunReady = true + fc.ammoRemaining = wto_main_gun_ammo(gun, fc) + anyReserve = anyReserve || fc.ammoRemaining > 0 + fc.gunReady = fc.gunReady || gun.isReadyToShoot totalLoaded += max(0, gun.currentLoadedAmmoCount) if gun.currentLoadedAmmoCount > 0 || gun.currentBulletSet.bulletsCount > 0 || weapon.countBullets > 0 anyReserve = true @@ -154,11 +158,11 @@ def private wto_inspect_primary_weapon(var unit : Unit?; now : float; def private wto_finish_weapon_state(now : float; spec : WtoVehicleSpec const&; anyGun, anyAlive, anyReserve : bool; totalLoaded : int; var fc : WtoFireState&) fc.gunDamaged = anyGun && !anyAlive - // A belt-fed autocannon is not ready between two rounds; only a longer wait is a reload. + // An autocannon is not ready between two rounds; only a longer wait is a reload. if fc.gunReady || !anyAlive fc.notReadySince = now let acReload = (now - fc.notReadySince) > WTO_AI_FC_AC_RELOAD_DETECT_SEC - fc.reloading = anyAlive && !fc.gunReady && anyReserve && (!spec.isAutocannonBelt || acReload) + fc.reloading = anyAlive && !fc.gunReady && anyReserve && (!spec.isAutocannon || acReload) if fc.pendingShotConfirm if (fc.prevLoadedAmmo >= 0 && totalLoaded < fc.prevLoadedAmmo) || !fc.gunReady fc.shotCount++ @@ -167,24 +171,6 @@ def private wto_finish_weapon_state(now : float; spec : WtoVehicleSpec const&; a fc.pendingShotConfirm = false fc.prevLoadedAmmo = totalLoaded -[never_inline] -def private wto_solve_ballistic_aim(muzzlePos, myVel : float3; var slot : WtoBotSlot&; - aimBase : float3; var outAimPt, outWishDir : float3&) : float - var leadPt = aimBase - let rawDist = wto_est_compute_biased_lead(muzzlePos, myVel, aimBase, slot, leadPt) - let dragLoss = clamp(slot.fire.activeDragCx * 0.00011 * rawDist, 0.0, 0.28) - let vEff = max(120.0, slot.fire.activeSpeedMps * (1.0 - dragLoss)) - outAimPt = leadPt - var arcDir = float3(0.0, 0.0, 0.0) - if calculate_arc_low_start_dir(muzzlePos, leadPt, vEff, arcDir) && length_sq(arcDir) > 0.25 - outWishDir = normalize(arcDir) - else - let d = max(1.0, length(leadPt - muzzlePos)) - let tof = d / vEff - let dropComp = float3(0.0, 0.5 * 9.81 * tof * tof, 0.0) - outWishDir = normalize(leadPt + dropComp - muzzlePos) - return rawDist - [never_inline] def private wto_sample_muzzle(unit : Unit const?; primaryIndex : int; var outPos, outDir : float3&) : bool @@ -217,13 +203,25 @@ def private wto_clear_aim_tracking(var fc : WtoFireState&) def private wto_yield_air_fire(var unit : Unit?; var slot : WtoBotSlot&) wto_set_hull_aim(unit, false, 0.0, unit.unitTm[0], slot) wto_clear_aim_tracking(slot.fire) - wto_trig_clear(slot.trigger) + wto_trig_set_target(INVALID_ENTITY_ID, slot.trigger) var gm = as_gm(unit) if gm != null *gm |> set_check_visibility_target(true) *gm |> set_ignore_stop_for_fire(true) set_unit_attack_type(unit, "attack_target") +[never_inline] +def private wto_fire_has_engagement(slot : WtoBotSlot const&) : bool + assume p = slot.perceive + let yielding = slot.spec.role == WTO_ROLE_SPAA && slot.tactics.state == WTO_STATE_DISABLED + return p.hasClearLos && !!p.targetEid && !p.targetIsAir && !yielding && !wto_turret_prefers_threat(slot) + +def private wto_fire_wants_soft(world : WtoWorldSnap const&; slot : WtoBotSlot const&) : bool + if !slot.perceive.hasClearLos || slot.perceive.targetIsAir + return false + let idx = wto_world_find_unit(world, slot.perceive.targetEid) + return idx >= 0 && (world.units[idx].isLightTag || world.units[idx].halfWid < 1.35) + [never_inline] def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?; className : string; now, dt : float; var slot : WtoBotSlot&; var fireBudget : int&) @@ -233,40 +231,39 @@ def public wto_fire_update(world : WtoWorldSnap const&; var unit : Unit?; classN wto_yield_air_fire(unit, slot) return set_unit_attack_type(unit, "dont_aim") - var wantSoftShell = false - if slot.perceive.hasClearLos && !!slot.perceive.targetEid && !slot.perceive.targetIsAir - let tgtIdx = wto_world_find_unit(world, slot.perceive.targetEid) - if tgtIdx >= 0 - wantSoftShell = world.units[tgtIdx].isLightTag || world.units[tgtIdx].halfWid < 1.35 - let primaryIndex = wto_inspect_primary_weapon(unit, now, slot.spec, wantSoftShell, slot.fire) + let wantSoft = wto_fire_wants_soft(world, slot) + let primaryIndex = wto_inspect_primary_weapon(unit, now, slot.spec, wantSoft, slot.fire) var muzzlePos = unit.pos + float3(0.0, 1.95, 0.0) var liveBarrelDir = unit.unitTm[0] let _preSample = wto_sample_muzzle(unit, primaryIndex, muzzlePos, liveBarrelDir) - let hFwd = unit.unitTm[0] var wishWorldDir = hFwd - var aimPt = muzzlePos + hFwd * 50.0 + var aimPt = muzzlePos var distToTgt = 9999.0 - // A clearly seen target is aimed at unless a more dangerous threat calls the turret away; - // otherwise the turret channel picks where to look (wto_ai_turret_common.das). - let engageValid = (slot.perceive.hasClearLos && !!slot.perceive.targetEid && !slot.perceive.targetIsAir && - !(slot.spec.role == WTO_ROLE_SPAA && slot.tactics.state == WTO_STATE_DISABLED) && !wto_turret_prefers_threat(slot)) - if engageValid - let baseAim = slot.perceive.visibleAimPt - distToTgt = wto_solve_ballistic_aim(muzzlePos, unit.vel, slot, baseAim, aimPt, wishWorldDir) + let engage = wto_fire_has_engagement(slot) + let distXZ = sqrt(wto_xz_dist_sq(unit.pos, slot.perceive.knownPos)) + let target = engage ? slot.perceive.targetEid : INVALID_ENTITY_ID + wto_trig_set_target(target, slot.trigger) + var auxAimed = false + if engage + let aimBase = slot.perceive.visibleAimPt + distToTgt = wto_solve_ballistic_aim(muzzlePos, unit.vel, aimBase, slot.fire.activeSpeedMps, slot.fire.activeDragCx, slot.fire.activeMassKg, slot.fire.activeCaliberM, slot, aimPt, wishWorldDir) + auxAimed = wto_fire_aux_aim(unit, className, dt, distXZ, slot) else wishWorldDir = wto_turret_look_dir(now, muzzlePos, unit.pos, hFwd, slot) - var wishYaw = 0.0 var wishPitch = 0.0 wto_world_to_hull_deg(wishWorldDir, hFwd, unit.unitTm[1], unit.unitTm[2], wishYaw, wishPitch) wto_drive_mounted_gun(unit, className, dt, wishYaw, wishPitch, slot) - let canEngage = engageValid && distToTgt <= WTO_AI_FC_MAX_RANGE_M && wto_sample_muzzle(unit, primaryIndex, muzzlePos, liveBarrelDir) + if slot.fire.traverse.known || auxAimed + wto_apply_weapon_aim(unit, dt) + let canEngage = engage && distToTgt <= WTO_AI_FC_MAX_RANGE_M && wto_sample_muzzle(unit, primaryIndex, muzzlePos, liveBarrelDir) wto_set_hull_aim(unit, canEngage, wishYaw, liveBarrelDir, slot) - if !canEngage + if canEngage + wto_fire_gate_try_shoot(world, unit, className, now, distXZ, muzzlePos, aimPt, liveBarrelDir, wishWorldDir, slot, fireBudget) + else wto_clear_aim_tracking(slot.fire) - wto_trig_clear(slot.trigger) - return - let distXZ = sqrt(wto_xz_dist_sq(unit.pos, slot.perceive.knownPos)) - wto_fire_gate_try_shoot(world, unit, now, distXZ, muzzlePos, aimPt, liveBarrelDir, wishWorldDir, slot, fireBudget) - wto_fire_aux_update(world, unit, now, distXZ, aimPt, slot, fireBudget) + slot.trigger.wantSpeedMps = 99.0 + slot.trigger.wantSpeedAt = -100.0 + if engage + wto_fire_aux_update(world, unit, className, now, distXZ, slot, fireBudget) diff --git a/game-ai/ground/wto_ai_fire_gate_common.das b/game-ai/ground/wto_ai_fire_gate_common.das index 6a14df3..01370be 100644 --- a/game-ai/ground/wto_ai_fire_gate_common.das +++ b/game-ai/ground/wto_ai_fire_gate_common.das @@ -1,10 +1,4 @@ -// Single fire-permission gate for the main weapon (cannon, launcher, SPAA self-defense). -// Every shot must pass visual confirmation, weapon readiness, the 800 m continuous LOS window, the -// trigger channel's hit probability against its fire threshold (wto_ai_trigger_common.das), aim -// settle, frame pre-fire budget, muzzle hard-ray, drag-integrated ballistic trajectory sweep, -// predicted friendly corridor, and multi-barrel group validation. A belt-fed autocannon fires in -// bursts whenever it is roughly on target and repeats the expensive checks only every -// fireControl.burstRecheckSec within a burst. +// Main weapon fire permission and burst control. All fired barrels pass a fresh safety check. options indenting = 2 options no_global_heap = true module wto_ai_fire_gate_common shared @@ -20,113 +14,45 @@ require %appGame.wtoai.wto_ai_config_common require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_combat_types_common require %appGame.wtoai.wto_ai_types_common -require %appGame.wtoai.wto_ai_sight_common +require %appGame.wtoai.wto_ai_fire_checks_common +require %appGame.wtoai.wto_ai_weapon_profile_common require %appGame.wtoai.wto_ai_trigger_common [never_inline] -def public wto_gate_friendly_segment_clear(world : WtoWorldSnap const&; selfEid : EntityId; - army : int; p0, p1 : float3; tMid : float) : bool - let delta = p1 - p0 - let segLen = length(delta) - if segLen < 0.2 - return true - let dir = delta / segLen - for i in range(world.unitCount) - assume u = world.units[i] - if !u.isAlive || !u.isGround || u.army != army || u.eid == selfEid - continue - let predPos = u.pos + u.vel * tMid + float3(0.0, 1.3, 0.0) - let along = clamp(dot(predPos - p0, dir), 0.0, segLen) - let clearR = WTO_AI_FC_FRIENDLY_CORRIDOR_M + u.halfWid - if length_sq(predPos - (p0 + dir * along)) < clearR * clearR - return false - return true - -[never_inline] -def private wto_gate_check_ballistic_arc(world : WtoWorldSnap const&; - selfEid, targetEid : EntityId; army : int; - muzzlePos, liveDir, carrierVel, aimPt : float3; - speedMps, dragCx, massKg, caliberM : float; checkMiss : bool; - var outBlock : int&) : int - let toAim = aimPt - muzzlePos - let targetDist = length(toAim) - if targetDist < 1.5 - return WTO_DENY_OK - let toAimDir = toAim / targetDist - let area = 0.25 * WTO_PI * caliberM * caliberM - let dragK = 0.5 * 1.225 * dragCx * area / max(0.1, massKg) - var cur = muzzlePos - var vel = liveDir * max(80.0, speedMps) + carrierVel - var t = 0.0 - var traveled = 0.0 - for step in range(64) - let spd = length(vel) - if spd < 20.0 - return WTO_DENY_AIM_ERR - let remain = max(0.5, targetDist - traveled) - let segWant = min(WTO_AI_FC_BALLISTIC_STEP_M, remain) - let dt = clamp(segWant / spd, 0.004, 0.14) - let accel = float3(0.0, -9.81, 0.0) - vel * (dragK * spd) - var next = cur + vel * dt + accel * (0.5 * dt * dt) - let nextProj = dot(next - muzzlePos, toAimDir) - let isLast = nextProj >= targetDist - 0.5 - if isLast && nextProj > targetDist && length_sq(next - cur) > 0.01 - let curProj = dot(cur - muzzlePos, toAimDir) - let frac = clamp((targetDist - curProj) / max(0.01, nextProj - curProj), 0.0, 1.0) - next = lerp(cur, next, frac) - let trimS = step == 0 ? 0.35 : 0.0 - let trimE = isLast ? 0.65 : 0.0 - let blk = wto_sight_hard_segment_blocked(world, selfEid, targetEid, cur, next, WTO_AI_FC_BALLISTIC_SWEEP_R_M, trimS, trimE) - if blk != WTO_BLOCK_NONE - outBlock = blk - return WTO_DENY_ARC_HARD - if !wto_gate_friendly_segment_clear(world, selfEid, army, cur, next, t + dt * 0.5) - return WTO_DENY_FRIENDLY - traveled += length(next - cur) - cur = next - vel = vel + accel * dt - t += dt - if isLast - let missTol = max(3.2, targetDist * 0.012) - if checkMiss && length_sq(cur - aimPt) > missTol * missTol - return WTO_DENY_AIM_ERR - return WTO_DENY_OK - return WTO_DENY_AIM_ERR - -[never_inline] -def private wto_gate_check_barrel(world : WtoWorldSnap const&; unit : Unit const?; - slot : WtoBotSlot const&; muzzlePos, liveDir, aimPt : float3; checkMiss : bool; - var outBlock : int&) : int - let straightBlk = wto_sight_hard_segment_blocked(world, slot.eid, slot.perceive.targetEid, muzzlePos, aimPt, 0.05, 0.35, 0.65) - if straightBlk != WTO_BLOCK_NONE - outBlock = straightBlk - return WTO_DENY_MUZZLE_HARD - return wto_gate_check_ballistic_arc(world, slot.eid, slot.perceive.targetEid, slot.army, - muzzlePos, liveDir, unit.vel, aimPt, - slot.fire.activeSpeedMps, slot.fire.activeDragCx, slot.fire.activeMassKg, slot.fire.activeCaliberM, checkMiss, outBlock) - -[never_inline] -def private wto_gate_check_all_primary_guns(world : WtoWorldSnap const&; unit : Unit const?; - slot : WtoBotSlot const&; primaryMuzzle, primaryDir, aimPt : float3; - checkMiss : bool; var outBlock : int&) : int - let primaryRes = wto_gate_check_barrel(world, unit, slot, primaryMuzzle, primaryDir, aimPt, checkMiss, outBlock) - if primaryRes != WTO_DENY_OK - return primaryRes - if unit == null || unit.weap == null - return WTO_DENY_OK +def private wto_gate_check_all_primary_guns(world : WtoWorldSnap const&; unit : Unit const?; className : string; + primaryMuzzle, primaryDir, aimPt : float3; checkMiss : bool; + var slot : WtoBotSlot&; var outBlock : int&) : int + var shell = WtoShellProfile() + shell.speedMps = slot.fire.activeSpeedMps + shell.dragCx = slot.fire.activeDragCx + shell.massKg = slot.fire.activeMassKg + shell.caliberM = slot.fire.activeCaliberM + let result = wto_fire_check_barrel(world, unit, slot, primaryMuzzle, primaryDir, aimPt, shell, checkMiss, outBlock) + if result != WTO_DENY_OK + return result for tIdx, turret in iter_range(unit.weap.turret), unit.weap.turret if tIdx == slot.fire.turretNo || int(turret.triggerGroupNo) != int(WeaponTriggerGroups.TRIGGER_GROUP_PRIMARY) continue let weapon = get_weapon(unit.weap.Weapons, int(turret.triggerNo), int(turret.weaponIndex)) if weapon == null || weapon.isDummyGun continue + let gun = as_gun(weapon) + if gun == null + return WTO_DENY_MULTI_GUN + if gun.isInoperable || !gun.isReadyToShoot + continue + if tIdx >= length(slot.fire.mounts) + return WTO_DENY_MULTI_GUN + assume cached = slot.fire.mounts[tIdx] + if !wto_mount_load_shell(unit, className, tIdx, gun, cached) + return WTO_DENY_MULTI_GUN var gunTm : float3x4 weapon_calcShootTm(weapon, unit.unitTm, gunTm) if length_sq(gunTm[0]) <= 0.25 - continue - let secRes = wto_gate_check_barrel(world, unit, slot, gunTm[3], normalize(gunTm[0]), aimPt, checkMiss, outBlock) - if secRes != WTO_DENY_OK - return secRes == WTO_DENY_FRIENDLY ? WTO_DENY_FRIENDLY : WTO_DENY_MULTI_GUN + return WTO_DENY_MULTI_GUN + let next = wto_fire_check_barrel(world, unit, slot, gunTm[3], normalize(gunTm[0]), aimPt, cached.shell, checkMiss, outBlock) + if next != WTO_DENY_OK + return next == WTO_DENY_FRIENDLY ? WTO_DENY_FRIENDLY : WTO_DENY_MULTI_GUN return WTO_DENY_OK [never_inline] @@ -165,7 +91,7 @@ def private wto_gate_log_deny(now, distXZ : float; reason, blk : int; var slot : def private wto_gate_request_primary_shot(var unit : Unit?; now, distXZ : float; var slot : WtoBotSlot&) assume fc = slot.fire unit_single_shot(unit, int(WeaponTriggerGroups.TRIGGER_GROUP_PRIMARY)) - let firstOfBurst = !slot.spec.isAutocannonBelt || (now - fc.lastShotAt) > 0.5 + let firstOfBurst = !slot.spec.isAutocannon || (now - fc.lastShotAt) > 0.5 fc.lastShotAt = now fc.pendingShotConfirm = true fc.pendingShotAt = now @@ -173,7 +99,7 @@ def private wto_gate_request_primary_shot(var unit : Unit?; now, distXZ : float; fc.lastDenyBlock = WTO_BLOCK_NONE fc.shotErrSumDeg += fc.lastAimErrDeg fc.maxShotErrDeg = max(fc.maxShotErrDeg, fc.lastAimErrDeg) - if !slot.spec.isAutocannonBelt + if !slot.spec.isAutocannon fc.settleHoldSec = 0.0 slot.trigger.biasEpoch++ if WTO_AI_DIAG_TELEMETRY && firstOfBurst @@ -182,7 +108,7 @@ def private wto_gate_request_primary_shot(var unit : Unit?; now, distXZ : float; // Main gun: one shot per permission, once the hit probability reaches the threshold and the // barrel has settled on the target. [never_inline] -def private wto_gate_try_single(world : WtoWorldSnap const&; var unit : Unit?; now, distXZ : float; +def private wto_gate_try_single(world : WtoWorldSnap const&; var unit : Unit?; className : string; now, distXZ : float; muzzlePos, aimPt, liveDir, wishDir : float3; probOk, withinTraverse : bool; var slot : WtoBotSlot&; var fireBudget : int&) assume fc = slot.fire @@ -208,17 +134,15 @@ def private wto_gate_try_single(world : WtoWorldSnap const&; var unit : Unit?; n return fireBudget-- var blk = WTO_BLOCK_NONE - let gateRes = wto_gate_check_all_primary_guns(world, unit, slot, muzzlePos, liveDir, aimPt, true, blk) + let gateRes = wto_gate_check_all_primary_guns(world, unit, className, muzzlePos, liveDir, aimPt, true, slot, blk) if gateRes != WTO_DENY_OK wto_gate_log_deny(now, distXZ, gateRes, blk, slot) return wto_gate_request_primary_shot(unit, now, distXZ, slot) -// Belt-fed autocannon (decision layer design, 6.3): bursts while within the aim slack, without -// waiting for the barrel to settle; the barrel, trajectory and friendly checks run at the start -// of a burst and every burstRecheckSec, not for every round. +// An automatic gun uses burst timing and the looser aim window, with a fresh safety check per shot. [never_inline] -def private wto_gate_try_burst(world : WtoWorldSnap const&; var unit : Unit?; now, distXZ : float; +def private wto_gate_try_burst(world : WtoWorldSnap const&; var unit : Unit?; className : string; now, distXZ : float; muzzlePos, aimPt, liveDir : float3; aimErrDeg : float; withinTraverse : bool; var slot : WtoBotSlot&; var fireBudget : int&) assume fc = slot.fire @@ -233,34 +157,32 @@ def private wto_gate_try_burst(world : WtoWorldSnap const&; var unit : Unit?; no deny = WTO_DENY_LONG_WINDOW else deny = wto_trig_burst_gate(now, aimErrDeg <= tr.aimSlackDeg, tr.burstUntil, tr.burstPauseUntil, started) - if started - tr.biasEpoch++ - tr.burstCheckedUntil = -100.0 var blk = WTO_BLOCK_NONE - if deny == WTO_DENY_OK && now >= tr.burstCheckedUntil + if deny == WTO_DENY_OK if fireBudget <= 0 deny = WTO_DENY_BUDGET else fireBudget-- - deny = wto_gate_check_all_primary_guns(world, unit, slot, muzzlePos, liveDir, aimPt, false, blk) - if deny == WTO_DENY_OK - tr.burstCheckedUntil = now + WTO_AI_FC_BURST_RECHECK_SEC + deny = wto_gate_check_all_primary_guns(world, unit, className, muzzlePos, liveDir, aimPt, false, slot, blk) if deny != WTO_DENY_OK wto_gate_log_deny(now, distXZ, deny, blk, slot) return + if started + tr.biasEpoch++ wto_gate_request_primary_shot(unit, now, distXZ, slot) [never_inline] -def public wto_fire_gate_try_shoot(world : WtoWorldSnap const&; var unit : Unit?; +def public wto_fire_gate_try_shoot(world : WtoWorldSnap const&; var unit : Unit?; className : string; now, distXZ : float; muzzlePos, aimPt, liveDir, wishDir : float3; var slot : WtoBotSlot&; var fireBudget : int&) assume fc = slot.fire let aimErrDeg = acos(clamp(dot(liveDir, wishDir), -1.0, 1.0)) * WTO_RAD_TO_DEG fc.lastAimErrDeg = aimErrDeg let turnDegSec = abs(slot.drive.omegaYawRad) * WTO_RAD_TO_DEG - let probOk = wto_trig_evaluate(world, now, unit.pos, length(unit.vel), turnDegSec, distXZ, aimErrDeg, slot) + let offset = wto_trig_aim_error(liveDir, wishDir) + let probOk = wto_trig_evaluate(world, now, unit.pos, length(unit.vel), turnDegSec, distXZ, offset, slot) let withinTraverse = fc.hullAimTarget == INVALID_ENTITY_ID - if slot.spec.isAutocannonBelt - wto_gate_try_burst(world, unit, now, distXZ, muzzlePos, aimPt, liveDir, aimErrDeg, withinTraverse, slot, fireBudget) + if slot.spec.isAutocannon + wto_gate_try_burst(world, unit, className, now, distXZ, muzzlePos, aimPt, liveDir, aimErrDeg, withinTraverse, slot, fireBudget) else - wto_gate_try_single(world, unit, now, distXZ, muzzlePos, aimPt, liveDir, wishDir, probOk, withinTraverse, slot, fireBudget) + wto_gate_try_single(world, unit, className, now, distXZ, muzzlePos, aimPt, liveDir, wishDir, probOk, withinTraverse, slot, fireBudget) diff --git a/game-ai/ground/wto_ai_follow_common.das b/game-ai/ground/wto_ai_follow_common.das index 7d8dacc..3d75722 100644 --- a/game-ai/ground/wto_ai_follow_common.das +++ b/game-ai/ground/wto_ai_follow_common.das @@ -56,6 +56,22 @@ def public wto_follow_lookahead(spec : WtoVehicleSpec const&; speedMps : float) def public wto_follow_target(rt : WtoRouteState const&; lookM : float) : float3 return wto_poly_walk(rt.corridor, rt.corridorLen, rt.segIdx, rt.segT, lookM) +// A bend, or the end of the route, is within the distance the hull is willing to reverse. +[never_inline] +def public wto_follow_near_turn(rt : WtoRouteState const&; myPos : float3; limitM : float) : bool + let corner = clamp(rt.segIdx + 1, 1, rt.corridorLen - 1) + var dist = sqrt(wto_xz_dist_sq(myPos, rt.corridor[corner])) + let bendDot = cos(WTO_AI_PF_CORNER_ANGLE_DEG * WTO_DEG_TO_RAD) + for i in range(corner, rt.corridorLen - 1) + if dist > limitM + return false + let into = wto_xz_normalize(rt.corridor[i] - rt.corridor[i - 1], float3(1.0, 0.0, 0.0)) + let out = wto_xz_normalize(rt.corridor[i + 1] - rt.corridor[i], into) + if dot(into, out) <= bendDot + return true + dist += sqrt(wto_xz_dist_sq(rt.corridor[i], rt.corridor[i + 1])) + return !rt.truncated && dist <= limitM + // Highest speed at `distToB` metres before corner b (a -> b -> c) that still allows turning it. [never_inline] def private wto_follow_corner_cap(a, b, c : float3; distToB, lookM, halfLen : float) : float diff --git a/game-ai/ground/wto_ai_nav_common.das b/game-ai/ground/wto_ai_nav_common.das index 6a71a29..9e66e84 100644 --- a/game-ai/ground/wto_ai_nav_common.das +++ b/game-ai/ground/wto_ai_nav_common.das @@ -21,6 +21,7 @@ require %appGame.wtoai.wto_ai_navquery_common require %appGame.wtoai.wto_ai_navmesh_common require %appGame.wtoai.wto_ai_route_common require %appGame.wtoai.wto_ai_follow_common +require %appGame.wtoai.wto_ai_facing_common require %appGame.wtoai.wto_ai_avoid_common require %appGame.wtoai.wto_ai_traffic_common require %appGame.wtoai.wto_ai_unstick_common @@ -32,42 +33,16 @@ def private wto_nav_halt(myPos, hullFwd : float3; var slot : WtoBotSlot&) wto_drive_cmd_set(slot.driveCmd, WTO_DRIVE_HALT, myPos, hullFwd, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) slot.nav.bumperBlockedSince = -100.0 -// A target outside the gun's traverse: the fire layer asks for the hull to turn to it, and the -// chassis pivots in place where it has room (wto_ai_traverse_common.das). -[never_inline] -def private wto_try_hull_aim(myPos, hullFwd : float3; var slot : WtoBotSlot&) : bool - let state = slot.tactics.state - let allowed = (state == WTO_STATE_MARCH || state == WTO_STATE_RUN_AND_GUN || state == WTO_STATE_PREAIM || - state == WTO_STATE_SHORT_HALT || state == WTO_STATE_HULL_ANGLE) - if !allowed - return false - if !slot.fire.hullAimTarget || slot.fire.hullAimTarget != slot.perceive.targetEid || slot.tactics.immobilized - return false - if wto_pivot_drive_mode(slot.spec, slot.nav.frontClearM, slot.nav.rearClearM, true) == WTO_DRIVE_HALT - return false - slot.nav.stuckCheckAt = -100.0 - let direction = wto_xz_normalize(slot.fire.hullAimDir, hullFwd) - wto_drive_cmd_set(slot.driveCmd, WTO_DRIVE_PIVOT, myPos, direction, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) - return true - -[never_inline] -def private wto_nav_hull_angle(myPos, hullFwd : float3; var slot : WtoBotSlot&) - let wishAngle = wto_xz_normalize(slot.tactics.hullAngleDir, hullFwd) - let angErr = acos(clamp(dot(wishAngle, hullFwd), -1.0, 1.0)) * WTO_RAD_TO_DEG - if angErr > WTO_AI_BHV_FACE_TOL_DEG - slot.nav.stuckCheckAt = -100.0 - wto_drive_cmd_set(slot.driveCmd, WTO_DRIVE_PIVOT, myPos + wishAngle * 14.0, wishAngle, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) - else - wto_nav_halt(myPos, hullFwd, slot) - // Standing for a shot or in cover: turn toward the facing direction (decision layer design, 7.3) // only when the hull is more than limitDeg off it, else hold still. [never_inline] -def private wto_nav_stand(myPos, hullFwd : float3; limitDeg : float; var slot : WtoBotSlot&) +def private wto_nav_stand(myPos, hullFwd : float3; var slot : WtoBotSlot&) assume tac = slot.tactics - if tac.faceActive && acos(clamp(dot(tac.faceDir, hullFwd), -1.0, 1.0)) * WTO_RAD_TO_DEG > limitDeg + let limit = tac.faceForGun ? WTO_AI_FC_BASE_ALIGN_DEG : WTO_AI_BHV_FACE_TOL_DEG + let errorDeg = acos(clamp(dot(tac.faceDir, hullFwd), -1.0, 1.0)) * WTO_RAD_TO_DEG + if tac.faceActive && errorDeg > limit && wto_pivot_drive_mode(slot.spec, slot.nav.frontClearM, slot.nav.rearClearM, true) != WTO_DRIVE_HALT slot.nav.stuckCheckAt = -100.0 - wto_drive_cmd_set(slot.driveCmd, WTO_DRIVE_PIVOT, myPos + tac.faceDir * 14.0, tac.faceDir, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) + wto_drive_cmd_set(slot.driveCmd, WTO_DRIVE_PIVOT, myPos, tac.faceDir, 0.0, slot.nav.frontClearM, slot.nav.rearClearM) return wto_nav_halt(myPos, hullFwd, slot) @@ -168,6 +143,7 @@ def private wto_nav_follow(var world : WtoWorldSnap&; navState : int; now : floa wto_nav_halt(myPos, hullFwd, slot) return wto_follow_track(myPos, rt) + wto_face_reverse_update(now, myPos, hullFwd, slot) let reverse = slot.tactics.reverseTravel let lead = reverse ? -hullFwd : hullFwd let speedNow = abs(slot.drive.lastVFwd) @@ -204,13 +180,10 @@ def public wto_nav_update(var world : WtoWorldSnap&; navState, slotIdx : int; no slot.nav.frontClearM = wto_terrain_hard_ray(probeBase, hullFwd, 24.0) slot.nav.rearClearM = wto_terrain_hard_ray(probeBase, -hullFwd, 18.0) let st = slot.tactics.state - if wto_try_hull_aim(myPos, hullFwd, slot) - return - if st == WTO_STATE_HULL_ANGLE - wto_nav_hull_angle(myPos, hullFwd, slot) - return - if st == WTO_STATE_SHORT_HALT || st == WTO_STATE_COVER_RELOAD - wto_nav_stand(myPos, hullFwd, st == WTO_STATE_SHORT_HALT ? WTO_AI_BHV_FACE_HALT_LIMIT_DEG : WTO_AI_BHV_FACE_TOL_DEG, slot) + if st != WTO_STATE_MARCH && st != WTO_STATE_RUN_AND_GUN + slot.tactics.reverseTravel = false + if st == WTO_STATE_HULL_ANGLE || st == WTO_STATE_SHORT_HALT || st == WTO_STATE_COVER_RELOAD + wto_nav_stand(myPos, hullFwd, slot) return if slot.tactics.desiredSpeedMps <= 0.05 wto_nav_halt(myPos, hullFwd, slot) diff --git a/game-ai/ground/wto_ai_nav_types_common.das b/game-ai/ground/wto_ai_nav_types_common.das index 4791783..3e92006 100644 --- a/game-ai/ground/wto_ai_nav_types_common.das +++ b/game-ai/ground/wto_ai_nav_types_common.das @@ -69,6 +69,7 @@ struct public WtoNavState lastUnstickAt : float = -100.0 reverseTarget : float3 = float3(0.0, 0.0, 0.0) reverseUntil : float = -100.0 + unstickForward : bool = false reverseCount : int = 0 unstickEvents : int = 0 contactEvents : int = 0 diff --git a/game-ai/ground/wto_ai_perceive_common.das b/game-ai/ground/wto_ai_perceive_common.das index e2bdb17..cf814fc 100644 --- a/game-ai/ground/wto_ai_perceive_common.das +++ b/game-ai/ground/wto_ai_perceive_common.das @@ -113,7 +113,7 @@ def private wto_perc_layer_mul(dist, cosGun, cosHull : float; lookAround : bool) return 0.0 // Integrates one enemy's exposure this tick; its track index, or -1 when no perception layer -// covers it or it is hidden. `vis` gets the visible sample count, `aimPt` the first visible one. +// covers it or it is hidden. The output is the visible sample count and its center. [never_inline] def private wto_exp_observe(world : WtoWorldSnap const&; now, dt : float; myEye, lookDir, hullDir : float3; lookAround : bool; u : WtoUnitSnap const&; var slot : WtoBotSlot&; @@ -200,6 +200,17 @@ def private wto_perc_look(now : float; hullDir : float3; var slot : WtoBotSlot&; p.nextLookAroundAt = now + WTO_AI_PERC_LOOK_AROUND_SEC return now < p.lookAroundUntil +// A quick prediction from the bot's own motion estimate, using the existing visual occluders. +[never_inline] +def private wto_perc_fleeting(world : WtoWorldSnap const&; myEye : float3; slot : WtoBotSlot const&) : bool + assume p = slot.perceive + let los = wto_xz_normalize(p.knownPos - myEye, float3(1.0, 0.0, 0.0)) + let laterally = abs(dot(p.estVel, float3(-los.z, 0.0, los.x))) + if laterally < WTO_AI_FC_FLEETING_LAT_MPS + return false + let future = p.visibleAimPt + p.estVel * WTO_AI_FC_FLEETING_LOOKAHEAD_SEC + return wto_sight_visual_clear(world, slot.eid, p.targetEid, myEye, future) != WTO_BLOCK_NONE + [never_inline] def public wto_perceive_update(var world : WtoWorldSnap&; now, dt : float; myPos, hullFwd : float3; var slot : WtoBotSlot&) @@ -229,6 +240,7 @@ def public wto_perceive_update(var world : WtoWorldSnap&; now, dt : float; p.wasEngaging = !tgt.isAir p.watchUntil = -100.0 wto_est_push_visual_sample(now, tgt.eid, tgt.pos, p) + p.targetFleeting = !tgt.isAir && wto_perc_fleeting(world, myEye, slot) if p.lockedEid != tgt.eid || now >= p.lockedUntil - 0.5 p.lockedEid = tgt.eid p.lockedUntil = now + WTO_AI_TACTICS_STICKY_SEC @@ -239,6 +251,7 @@ def public wto_perceive_update(var world : WtoWorldSnap&; now, dt : float; // Lost visual confirmation: immediately revoke LOS, freeze exit point for 2-5 s watch, zero velocity. p.hasClearLos = false + p.targetFleeting = false p.visiblePointCount = 0 p.goodLosSec = 0.0 wto_est_on_los_lost(now, slot.eid, p) diff --git a/game-ai/ground/wto_ai_route_common.das b/game-ai/ground/wto_ai_route_common.das index a249f93..14758b6 100644 --- a/game-ai/ground/wto_ai_route_common.das +++ b/game-ai/ground/wto_ai_route_common.das @@ -35,7 +35,7 @@ def public wto_route_filter(spec : WtoVehicleSpec const&) : int [never_inline] def public wto_route_active_goal(myPos, finalGoal : float3; slot : WtoBotSlot const&) : float3 let st = slot.tactics.state - let marching = st == WTO_STATE_MARCH || st == WTO_STATE_PREAIM || st == WTO_STATE_RELOAD_ADVANCE + let marching = st == WTO_STATE_MARCH || st == WTO_STATE_RUN_AND_GUN if !marching || !slot.order.routeRelayValid return finalGoal let relay = slot.order.routeRelayPos diff --git a/game-ai/ground/wto_ai_runtime.das b/game-ai/ground/wto_ai_runtime.das index 10ac9f8..657e555 100644 --- a/game-ai/ground/wto_ai_runtime.das +++ b/game-ai/ground/wto_ai_runtime.das @@ -38,6 +38,7 @@ require %appGame.wtoai.wto_ai_nav_common require %appGame.wtoai.wto_ai_navmesh_common require %appGame.wtoai.wto_ai_drive_common require %appGame.wtoai.wto_ai_fire_common +require %appGame.wtoai.wto_ai_ammo_common require %appGame.wtoai.wto_ai_diag_common require %appGame.wtoai.wto_ai_stats_common require %appGame.wtoai.wto_ai_slots_common @@ -167,6 +168,20 @@ def wto_ai_world_tick_es(act : UpdateStageInfoAct) wto_navmesh_log_stats(g_navmesh) wto_stats_tick(now, g_stats) +[es(tag=server, before=wto_ai_pipeline_es)] +def wto_ai_ammo_sample_es(act : UpdateStageInfoAct; eid : EntityId; unit__ref : UnitRef; + ammo_stowage__ammoState : uint; ammo_stowage__ammoTypeRemap : IPoint4List; + ammo_stowage__weaponsIds : IntList; ammo_slots__ammoMaskAndType : UInt32List; + ammo_slots__numAmmo : IPoint2List) + if act.dt <= 0.0 || !g_world.valid || !WTO_AI_LAYER_FIRE_CONTROL + return + let index = wto_slots_find(g_bots, eid) + let u = unit__ref.unit + if index < 0 || u == null || u.weap == null || g_world.time < g_bots[index].nextTacticsAt + return + wto_ammo_sample(u, ammo_stowage__ammoState, ammo_stowage__ammoTypeRemap, ammo_stowage__weaponsIds, + ammo_slots__ammoMaskAndType, ammo_slots__numAmmo, g_bots[index].fire) + [es(tag=server, no_order)] def wto_ai_pipeline_es(act : UpdateStageInfoAct; eid : EntityId; var unit__ref : UnitRef&; unit__className : string = ""; diff --git a/game-ai/ground/wto_ai_sight_common.das b/game-ai/ground/wto_ai_sight_common.das index 0d4374a..c816c98 100644 --- a/game-ai/ground/wto_ai_sight_common.das +++ b/game-ai/ground/wto_ai_sight_common.das @@ -117,12 +117,24 @@ def public wto_sight_check_target_samples(world : WtoWorldSnap const&; let count = clamp(maxSamples, 1, 4) var vis = 0 var sum = float3(0.0, 0.0, 0.0) + var visible : bool[4] for s in range(count) - if wto_sight_visual_clear(world, selfEid, tgt.eid, eyePos, pts[s]) == WTO_BLOCK_NONE + visible[s] = wto_sight_visual_clear(world, selfEid, tgt.eid, eyePos, pts[s]) == WTO_BLOCK_NONE + if visible[s] sum += pts[s] vis++ // Aim at the middle of what is visible (decision layer design, 6.2), not at the first visible // point, which with the hull hidden is the gun mantlet every time. if vis > 0 outBestPt = sum / float(vis) + if vis > 1 && wto_sight_visual_clear(world, selfEid, tgt.eid, eyePos, outBestPt) != WTO_BLOCK_NONE + let center = outBestPt + var bestDist = 1.0e9 + for s in range(count) + if !visible[s] + continue + let d = length_sq(pts[s] - center) + if d < bestDist + bestDist = d + outBestPt = pts[s] return vis diff --git a/game-ai/ground/wto_ai_slots_common.das b/game-ai/ground/wto_ai_slots_common.das index fd19219..fe81acc 100644 --- a/game-ai/ground/wto_ai_slots_common.das +++ b/game-ai/ground/wto_ai_slots_common.das @@ -23,7 +23,7 @@ def public wto_slots_find(bots : WtoBotSlot[64]; eid : EntityId) : int // Frees the unit's slot and clears engagement counters aimed at it; true when a slot was freed. [never_inline] -def public wto_slots_forget(var bots : WtoBotSlot[64]; eid : EntityId) : bool +def public wto_slots_forget(var bots : WtoBotSlot[64]&; eid : EntityId) : bool let idx = wto_slots_find(bots, eid) if idx >= 0 if bots[idx].drive.routeBOwned @@ -38,7 +38,7 @@ def public wto_slots_forget(var bots : WtoBotSlot[64]; eid : EntityId) : bool // The unit's slot, taking a free one for a new unit (then `created` is set); -1 when full. [never_inline] -def public wto_slots_acquire(var bots : WtoBotSlot[64]; eid : EntityId; army : int; now : float; +def public wto_slots_acquire(var bots : WtoBotSlot[64]&; eid : EntityId; army : int; now : float; var created : bool&) : int let cap = min(WTO_MAX_BOTS, WTO_AI_MAX_TRACKED_BOTS) var freeIdx = -1 @@ -63,7 +63,7 @@ def public wto_slots_acquire(var bots : WtoBotSlot[64]; eid : EntityId; army : i // Releases vehicle control of every bot and clears all slots. [never_inline] -def public wto_slots_reset_all(var bots : WtoBotSlot[64]) +def public wto_slots_reset_all(var bots : WtoBotSlot[64]&) for i in range(WTO_MAX_BOTS) if bots[i].drive.routeBOwned wto_drive_request_control(bots[i].eid, 0) @@ -72,7 +72,7 @@ def public wto_slots_reset_all(var bots : WtoBotSlot[64]) // Slots not refreshed by the pipeline for a while belong to units that are gone. [never_inline] -def public wto_slots_drop_stale(var bots : WtoBotSlot[64]; now : float) +def public wto_slots_drop_stale(var bots : WtoBotSlot[64]&; now : float) for i in range(WTO_MAX_BOTS) if bots[i].used && (now - bots[i].lastSeenAt) > 3.5 bots[i] = WtoBotSlot() @@ -92,7 +92,7 @@ def public wto_slots_phys_available(bots : WtoBotSlot[64]) : bool // A hit on `eid` by `offEid`: confirms an effective shot of our firing bot (resetting its stalemate // counters) and gives our damaged bot the direction it was hit from (never the offender's position). [never_inline] -def public wto_slots_on_damage(world : WtoWorldSnap const&; var bots : WtoBotSlot[64]; eid, offEid : EntityId; +def public wto_slots_on_damage(world : WtoWorldSnap const&; var bots : WtoBotSlot[64]&; eid, offEid : EntityId; u : Unit const?; hitPos : float3; hpDropped : bool; now : float) let offBotIdx = wto_slots_find(bots, offEid) if offBotIdx >= 0 && bots[offBotIdx].army != int(u.army) && hpDropped diff --git a/game-ai/ground/wto_ai_specs_common.das b/game-ai/ground/wto_ai_specs_common.das index 60ebdfb..51e6c12 100644 --- a/game-ai/ground/wto_ai_specs_common.das +++ b/game-ai/ground/wto_ai_specs_common.das @@ -16,6 +16,8 @@ require IGroundModel require HeavyVehicleModel require Weapon require WTBallistics +require %appGame.wtoai.wto_ai_config_common +require %appGame.wtoai.wto_ai_weapon_profile_common require %game.utils.utils_common require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_combat_types_common @@ -36,18 +38,14 @@ def private wto_parse_role_strings(unitType : string; expClass : string; isLight [never_inline] def private wto_record_shell_block(bBlk : DataBlock const&; var spec : WtoVehicleSpec&; isDefault : bool) - let spd = bBlk |> datablock_getReal("speed", 0.0) - if spd <= 80.0 || spd >= 2600.0 + var shell = WtoShellProfile() + if !wto_profile_read(bBlk, shell) return - let cx = clamp(bBlk |> datablock_getReal("Cx", 0.35), 0.05, 1.5) - let mass = clamp(bBlk |> datablock_getReal("mass", 10.0), 0.05, 250.0) - let rawCal = bBlk |> datablock_getReal("ballisticCaliber", 0.0) - let cal = clamp(rawCal > 0.002 ? rawCal : bBlk |> datablock_getReal("caliber", 0.09), 0.005, 0.4) if isDefault && spec.shellCount == 0 - spec.muzzleSpeedMps = spd - spec.shellDragCx = cx - spec.shellMassKg = mass - spec.shellCaliberM = cal + spec.muzzleSpeedMps = shell.speedMps + spec.shellDragCx = shell.dragCx + spec.shellMassKg = shell.massKg + spec.shellCaliberM = shell.caliberM let bName = bBlk |> datablock_getStr("bulletName", "") if empty(bName) || spec.shellCount >= WTO_MAX_SHELL_PROFILES return @@ -57,29 +55,26 @@ def private wto_record_shell_block(bBlk : DataBlock const&; var spec : WtoVehicl return let idx = spec.shellCount let bt = bBlk |> datablock_getStr("bulletType", "") - let isSoft = find(bt, "he_frag") >= 0 || find(bt, "hesh") >= 0 + let isSoft = find(bt, "he_frag") >= 0 || find(bt, "hesh") >= 0 || find(bt, "he_part") >= 0 || find(bt, "heat") >= 0 let isNonCombat = find(bt, "smoke") >= 0 || find(bt, "practice") >= 0 || find(bt, "shrapnel") >= 0 - spec.shells[idx].nameHash = h - spec.shells[idx].speedMps = spd - spec.shells[idx].dragCx = cx - spec.shells[idx].massKg = mass - spec.shells[idx].caliberM = cal - spec.shells[idx].isSoftShell = isSoft - spec.shells[idx].isAntiArmor = !isSoft && !isNonCombat - spec.shells[idx].penMm = float(calc_max_penetration(bBlk)) + shell.nameHash = h + shell.isSoftShell = isSoft + shell.isAntiArmor = !isSoft && !isNonCombat || find(bt, "heat") >= 0 + shell.penMm = float(calc_max_penetration(bBlk)) + spec.shells[idx] = shell spec.shellCount = idx + 1 [never_inline] -def private wto_parse_weapon_blk(weapBlkPath : string; var spec : WtoVehicleSpec&) +def private wto_parse_weapon_blk(weapBlkPath : string; beltMount : bool; var spec : WtoVehicleSpec&) if empty(weapBlkPath) || find(weapBlkPath, "dummy_weapon") >= 0 return datablock_load_cached(weapBlkPath, DataBlockReadFlag.ROBUST) <| $(wBlk) let isRocket = wBlk |> datablock_getBool("rocketGun", false) let isCannon = wBlk |> datablock_getBool("cannon", false) - let isBelt = wBlk |> datablock_getBool("isBulletBelt", false) if isRocket && !isCannon return - spec.isAutocannonBelt = isBelt + spec.isAutocannon = beltMount || wto_profile_is_automatic(wBlk) + spec.reloadSec = wBlk |> datablock_getReal("reloadTime", 0.0) spec.shellCount = 0 datablock_for_each_block(wBlk, "bullet") <| $(bBlk) wto_record_shell_block(bBlk, spec, true) @@ -130,7 +125,8 @@ def private wto_parse_unit_blk(className : string; isLightTag : bool; var spec : let stabBlk = weapBlk |> datablock_get_block_by_name("gunStabilizer") if stabBlk != null spec.hasVertStab = *stabBlk |> datablock_getBool("hasVertical", false) - wto_parse_weapon_blk(wPath, spec) + let beltMount = weapBlk |> datablock_getBool("isBulletBelt", false) + wto_parse_weapon_blk(wPath, beltMount, spec) return loaded [never_inline] diff --git a/game-ai/ground/wto_ai_stats_common.das b/game-ai/ground/wto_ai_stats_common.das index ed37fc1..b1283c0 100644 --- a/game-ai/ground/wto_ai_stats_common.das +++ b/game-ai/ground/wto_ai_stats_common.das @@ -91,8 +91,8 @@ def private wto_stats_spot(now : float; groundTgt : bool; var slot : WtoBotSlot& [never_inline] def private wto_stats_shots(myPos : float3; var slot : WtoBotSlot&; var bs : WtoBattleStats&) assume st = slot.stats - bs.auxShots += slot.trigger.coaxShots - st.lastAuxShots - st.lastAuxShots = slot.trigger.coaxShots + bs.auxShots += slot.trigger.auxShots - st.lastAuxShots + st.lastAuxShots = slot.trigger.auxShots let fired = slot.fire.shotCount - st.lastShots st.lastShots = slot.fire.shotCount if fired <= 0 @@ -104,22 +104,22 @@ def private wto_stats_shots(myPos : float3; var slot : WtoBotSlot&; var bs : Wto if abs(slot.drive.lastVFwd) >= WTO_AI_PF_STATIONARY_MPS bs.movingShots[role] += fired bs.bandMoving[band] += fired - if slot.spec.isAutocannonBelt + if slot.spec.isAutocannon bs.acShots += fired // A shooting window: a ground target seen clearly within engagement range and the gun ready. [never_inline] def private wto_stats_window(dt : float; myPos : float3; groundTgt : bool; slot : WtoBotSlot const&; var bs : WtoBattleStats&) - // A belt-fed autocannon is briefly not ready between rounds; that still counts as a window. - let ready = slot.fire.gunReady || slot.spec.isAutocannonBelt + // An autocannon is briefly not ready between rounds; that still counts as a window. + let ready = slot.fire.gunReady || slot.spec.isAutocannon if !groundTgt || !ready || slot.fire.reloading return if wto_xz_dist_sq(myPos, slot.perceive.knownPos) > WTO_AI_FC_MAX_RANGE_M * WTO_AI_FC_MAX_RANGE_M return bs.windowSec[wto_stats_role(slot)] += dt bs.denySec[clamp(slot.fire.lastDenyReason, 0, WTO_DENY_COUNT - 1)] += dt - if slot.spec.isAutocannonBelt + if slot.spec.isAutocannon bs.acWindowSec += dt // The nearest enemy ground vehicle within statsSampleRangeM if it is in line of sight, else -1. diff --git a/game-ai/ground/wto_ai_tactics_actions_common.das b/game-ai/ground/wto_ai_tactics_actions_common.das index 46b16cd..45bb656 100644 --- a/game-ai/ground/wto_ai_tactics_actions_common.das +++ b/game-ai/ground/wto_ai_tactics_actions_common.das @@ -42,24 +42,30 @@ def public wto_friendly_retreat_dir(world : WtoWorldSnap const&; army : int; return wto_xz_normalize(blended, toSpawn) return wto_xz_normalize(-threatDir, float3(1.0, 0.0, 0.0)) +[never_inline] +def public wto_sm_handle_spaa(world : WtoWorldSnap const&; now : float; + myPos, threatDir : float3; distXZ : float; var slot : WtoBotSlot&) : bool + assume p = slot.perceive + if slot.spec.role != WTO_ROLE_SPAA || !p.hasClearLos || !p.targetEid + return false + if p.targetIsAir + slot.tactics.spaaYieldAir = true + wto_sm_set_state(now, WTO_STATE_MARCH, myPos, 0.0, "spaa_air_engage", distXZ, slot) + return true + if distXZ >= 220.0 + return false + let backDir = wto_friendly_retreat_dir(world, slot.army, myPos, threatDir) + let goal = wto_clamp_battle_xz(myPos + backDir * 70.0, world.battleCenter, world.battleRadius, 40.0) + wto_sm_set_state(now, WTO_STATE_DISABLED, goal, slot.spec.vMaxFwd, "spaa_evade_tank", distXZ, slot) + return true + [never_inline] def public wto_sm_handle_disabled_and_repair(world : WtoWorldSnap const&; now : float; - myPos, threatPos, threatDir : float3; - isBurn : bool; repairRemainingSec, distXZ : float; - var slot : WtoBotSlot&) : bool + myPos, threatPos, threatDir : float3; + isBurn : bool; repairRemainingSec, distXZ : float; + var slot : WtoBotSlot&) : bool assume tac = slot.tactics assume p = slot.perceive - tac.spaaYieldAir = false - if slot.spec.role == WTO_ROLE_SPAA - if p.hasClearLos && p.targetIsAir && !!p.targetEid - tac.spaaYieldAir = true - wto_sm_set_state(now, WTO_STATE_MARCH, myPos, 0.0, "spaa_air_engage", distXZ, slot) - return true - if p.hasClearLos && !p.targetIsAir && !!p.targetEid && distXZ < 220.0 - let backDir = wto_friendly_retreat_dir(world, slot.army, myPos, threatDir) - let goal = wto_clamp_battle_xz(myPos + backDir * 70.0, world.battleCenter, world.battleRadius, 40.0) - wto_sm_set_state(now, WTO_STATE_DISABLED, goal, slot.spec.vMaxFwd, "spaa_evade_tank", distXZ, slot) - return true // Engine/tracks broken (cannot move): halt in place and request native repair; gun keeps self-defending. if tac.immobilized diff --git a/game-ai/ground/wto_ai_tactics_common.das b/game-ai/ground/wto_ai_tactics_common.das index 5b51546..4d0b2cc 100644 --- a/game-ai/ground/wto_ai_tactics_common.das +++ b/game-ai/ground/wto_ai_tactics_common.das @@ -1,7 +1,7 @@ // Hull channel (decision layer design, section 7), once per tactics tick: damage/repair and ridge // withdrawal take over at once; otherwise the behavior chosen by score (wto_ai_behavior_common.das) // runs as a small action that sets the goal, speed and WTO_STATE_* for navigation. The facing -// constraint and the reverse-travel decision (wto_ai_facing_common.das) are updated every tick. +// constraint is updated here, while navigation decides the direction to follow its corridor. // A behavior that ends by itself (shot taken, cover reached and reloaded, no cover found) is // replaced in the same tick. options indenting = 2 @@ -27,11 +27,16 @@ require %appGame.wtoai.wto_ai_facing_common def private wto_sm_sync_engagement_counters(dt : float; var slot : WtoBotSlot&) assume tac = slot.tactics assume p = slot.perceive - if p.hasClearLos && !!p.targetEid && !p.targetIsAir && tac.engageTargetEid != p.targetEid - tac.engageTargetEid = p.targetEid - tac.engageShotsNoEffect = 0 - tac.engageNoShotHalts = 0 - tac.engageTotalHaltSec = 0.0 + let shots = slot.fire.shotCount - tac.engageObservedShots + tac.engageObservedShots = slot.fire.shotCount + if p.hasClearLos && !!p.targetEid && !p.targetIsAir + if tac.engageTargetEid != p.targetEid + tac.engageTargetEid = p.targetEid + tac.engageShotsNoEffect = 0 + tac.engageNoShotHalts = 0 + tac.engageTotalHaltSec = 0.0 + elif shots > 0 && slot.fire.lastShotAt > tac.lastEffectAt + tac.engageShotsNoEffect += shots if tac.state == WTO_STATE_SHORT_HALT tac.engageTotalHaltSec += dt @@ -91,21 +96,20 @@ def private wto_sm_march_speed(slot : WtoBotSlot const&; distGoal : float) : flo // Short halt (7.1): stand until the shot leaves, the reload starts, the target is gone or // stateMachine.shortHaltMaxSec runs out; then a cooldown of shortHaltCooldownSec. [never_inline] -def private wto_tac_halt(now : float; myPos : float3; c : WtoBhvCtx const&; var slot : WtoBotSlot&) : bool +def private wto_tac_halt(now : float; myPos, hullFwd : float3; c : WtoBhvCtx const&; var slot : WtoBotSlot&) : bool assume tac = slot.tactics if tac.state != WTO_STATE_SHORT_HALT + wto_face_accept_gun(hullFwd, slot) wto_sm_set_state(now, WTO_STATE_SHORT_HALT, myPos, 0.0, "halt_for_shot", c.distTarget, slot) return true let shots = slot.fire.shotCount - tac.haltStartShots - if shots > 0 - tac.engageShotsNoEffect += shots - tac.haltStartShots = slot.fire.shotCount let timeout = (now - tac.haltEnterAt) >= WTO_AI_SM_SHORT_HALT_MAX_SEC if timeout && shots <= 0 tac.engageNoShotHalts++ if shots > 0 || timeout || slot.fire.reloading || !c.hasTarget || !c.stopRangeOk tac.shortHaltCooldownUntil = now + WTO_AI_SM_SHORT_HALT_COOLDOWN_SEC return false + wto_face_accept_gun(hullFwd, slot) wto_sm_set_state(now, WTO_STATE_SHORT_HALT, myPos, 0.0, "halt_hold", c.distTarget, slot) return true @@ -117,15 +121,15 @@ def private wto_tac_engage(now : float; c : WtoBhvCtx const&; var slot : WtoBotS var speed = march assume tr = slot.trigger let fresh = (now - tr.wantSpeedAt) <= WTO_AI_TACTICS_TICK_SEC * 3.0 - if fresh && tr.wantSpeedMps > WTO_AI_FC_STOP_SPEED_MAX_MPS && tr.wantSpeedMps < march + let crossExposed = c.urgent && wto_face_side_exposed(slot) + if fresh && tr.targetEid == slot.perceive.targetEid && !crossExposed && tr.wantSpeedMps > WTO_AI_FC_STOP_SPEED_MAX_MPS && tr.wantSpeedMps < march speed = lerp(tr.wantSpeedMps, march, c.urgent ? WTO_AI_BHV_URGENT_SPEED_KEEP : 0.0) wto_sm_set_state(now, WTO_STATE_RUN_AND_GUN, c.baseGoal, speed, "engage", c.distTarget, slot) return true [never_inline] def private wto_tac_hold(now : float; myPos, hullFwd : float3; c : WtoBhvCtx const&; var slot : WtoBotSlot&) : bool - assume tac = slot.tactics - tac.hullAngleDir = tac.faceActive ? tac.faceDir : hullFwd + wto_face_accept_gun(hullFwd, slot) let why = c.holdReason == WTO_HOLD_WATCH ? "watch_last_exit" : (c.holdReason == WTO_HOLD_RALLY ? "rally_wait" : "hold_post") wto_sm_set_state(now, WTO_STATE_HULL_ANGLE, myPos, 0.0, why, c.distTarget, slot) return c.holdReason != WTO_HOLD_NONE @@ -155,7 +159,7 @@ def private wto_tac_run(world : WtoWorldSnap const&; now : float; myPos, hullFwd if bhv == WTO_BHV_ENGAGE return c.hasTarget && wto_tac_engage(now, c, slot) if bhv == WTO_BHV_HALT - return wto_tac_halt(now, myPos, c, slot) + return wto_tac_halt(now, myPos, hullFwd, c, slot) if bhv == WTO_BHV_COVER return wto_tac_cover(world, now, myPos, hullFwd, c, slot) if bhv == WTO_BHV_REPOSITION @@ -177,13 +181,16 @@ def public wto_tactics_update(world : WtoWorldSnap const&; now, dt : float; if !WTO_AI_LAYER_TACTICS wto_sm_set_state(now, WTO_STATE_MARCH, slot.order.valid ? slot.order.goalPos : myPos, slot.spec.vMaxFwd * 0.9, "layer_off", 9999.0, slot) return + wto_sm_sync_engagement_counters(dt, slot) + wto_face_update(now, myPos, hullFwd, slot) var c = WtoBhvCtx() wto_bhv_context(world, now, myPos, hullFwd, wto_sm_reposition_stale(now, slot), slot, c) - wto_sm_sync_engagement_counters(dt, slot) wto_cover_update_memory(world, now, myPos, slot) - wto_face_update(now, myPos, hullFwd, slot) + slot.tactics.spaaYieldAir = false if wto_sm_handle_disabled_and_repair(world, now, myPos, c.threatPos, c.threatDir, isBurn, repairRemainingSec, c.distTarget, slot) wto_bhv_take_over(now, WTO_BHV_REPAIR, slot) + elif wto_sm_handle_spaa(world, now, myPos, c.threatDir, c.distTarget, slot) + wto_bhv_take_over(now, slot.tactics.spaaYieldAir ? WTO_BHV_HOLD : WTO_BHV_WITHDRAW, slot) elif wto_sm_handle_ridge(world, now, myPos, c.threatDir, c.distTarget, slot) wto_bhv_take_over(now, WTO_BHV_WITHDRAW, slot) else @@ -191,5 +198,7 @@ def public wto_tactics_update(world : WtoWorldSnap const&; now, dt : float; if !wto_tac_run(world, now, myPos, hullFwd, c, slot, crowdSummary) wto_bhv_choose(now, c, true, slot) if !wto_tac_run(world, now, myPos, hullFwd, c, slot, crowdSummary) + wto_bhv_take_over(now, WTO_BHV_ADVANCE, slot) wto_tac_advance(now, myPos, c, slot) - wto_face_reverse_update(now, c.distGoal, slot) + if !slot.tactics.faceForGun + slot.tactics.gunFacingTarget = INVALID_ENTITY_ID diff --git a/game-ai/ground/wto_ai_traverse_common.das b/game-ai/ground/wto_ai_traverse_common.das index e24d3a6..e9fe26b 100644 --- a/game-ai/ground/wto_ai_traverse_common.das +++ b/game-ai/ground/wto_ai_traverse_common.das @@ -27,7 +27,7 @@ def private wto_valid_angle_range(angles : float2) : bool return wto_is_finite(angles.x) && wto_is_finite(angles.y) && angles.x <= angles.y [never_inline] -def private wto_read_gunner_mount(className : string; triggerNo, weaponIndex : int; +def public wto_read_gunner_mount(className : string; triggerNo, weaponIndex : int; readMount : block<(mount : DataBlock) : void>) if empty(className) || triggerNo < WTO_FIRST_GUNNER_TRIGGER || weaponIndex < 0 return @@ -40,7 +40,7 @@ def private wto_read_gunner_mount(className : string; triggerNo, weaponIndex : i datablock_for_each_block(*common, "Weapon") <| $(mount) if (mount |> datablock_getStr("trigger", "")) != trigger return - if index == weaponIndex && (mount |> datablock_getStr("triggerGroup", "primary")) == "primary" + if index == weaponIndex invoke(readMount, mount) index++ @@ -177,9 +177,35 @@ def public wto_drive_mounted_gun(var unit : Unit?; className : string; dt : floa let pitchDelta = clamp(wishPitchDeg - fc.curPitchDeg, -maxPitchStep, maxPitchStep) turret.pitchLim = clamp(fc.curPitchDeg + pitchDelta, pitch.x, pitch.y) break - if fc.traverse.known - var uPos = unit.pos - updateWeaponAnims(*unit.weap, dtStep, 1.0, uPos) + +// Secondary mounts with their own limits can track independently. Coaxial mounts with no +// limits follow the main turret through the stock weapon animation. +[never_inline] +def public wto_aim_aux_mount(var unit : Unit?; className : string; dt : float; turretNo : int; + wishDir : float3; var cached : WtoMountFire&) : bool + assume turret = unit.weap.turret[turretNo] + let triggerNo = int(turret.triggerNo) + let weaponIndex = int(turret.weaponIndex) + if !cached.traverseReady + wto_load_gun_traverse(className, triggerNo, weaponIndex, cached.traverse) + cached.traverseReady = true + if !cached.traverse.known + return false + var wishYaw = 0.0 + var wishPitch = 0.0 + wto_world_to_hull_deg(wishDir, unit.unitTm[0], unit.unitTm[1], unit.unitTm[2], wishYaw, wishPitch) + let step = clamp(dt, 0.005, 0.12) + let cmdYaw = wto_step_mounted_yaw(turret.currentState.yaw, wishYaw, step * 24.0, cached.traverse.yaw) + let pitch = wto_gun_pitch_at_yaw(className, triggerNo, weaponIndex, cmdYaw, cached.traverse) + turret.yawLim = cmdYaw + if pitch.x <= pitch.y + let pitchChange = clamp(wishPitch - turret.currentState.pitch, -step * 10.0, step * 10.0) + turret.pitchLim = clamp(turret.currentState.pitch + pitchChange, pitch.x, pitch.y) + return true + +def public wto_apply_weapon_aim(var unit : Unit?; dt : float) + var pos = unit.pos + updateWeaponAnims(*unit.weap, clamp(dt, 0.005, 0.12), 1.0, pos) def public wto_set_hull_aim(unit : Unit const?; active : bool; wishYaw : float; liveBarrelDir : float3; var slot : WtoBotSlot&) diff --git a/game-ai/ground/wto_ai_trigger_common.das b/game-ai/ground/wto_ai_trigger_common.das index f63b4c6..5705072 100644 --- a/game-ai/ground/wto_ai_trigger_common.das +++ b/game-ai/ground/wto_ai_trigger_common.das @@ -31,10 +31,15 @@ def private wto_trig_window(half, offset, sigma : float) : float return clamp(0.5 * (wto_trig_erf((half - offset) / s) + wto_trig_erf((half + offset) / s)), 0.0, 1.0) // Hit probability against a target `halfW` x `halfH` metres at `dist` (angles in radians). -def private wto_trig_prob(halfW, halfH, dist, offsetRad, sigmaRad : float) : float - let o = offsetRad * 0.7071 +def private wto_trig_prob(halfW, halfH, dist : float; offset : float2; sigmaRad : float) : float let d = max(dist, 5.0) - return wto_trig_window(atan2(halfW, d), o, sigmaRad) * wto_trig_window(atan2(halfH, d), o, sigmaRad) + return wto_trig_window(atan2(halfW, d), offset.x, sigmaRad) * wto_trig_window(atan2(halfH, d), offset.y, sigmaRad) + +def public wto_trig_aim_error(actual, wanted : float3) : float2 + let across = wto_xz_normalize(float3(-wanted.z, 0.0, wanted.x), float3(0.0, 0.0, 1.0)) + let up = cross(across, wanted) + let ahead = dot(actual, wanted) + return float2(atan2(dot(actual, across), ahead), atan2(dot(actual, up), ahead)) // Expected angular spread of a shot (radians) at own speed and hull turn rate. def private wto_trig_sigma(spec : WtoVehicleSpec const&; speedMps, turnDegSec, leadErrM, dist : float) : float @@ -46,7 +51,7 @@ def private wto_trig_sigma(spec : WtoVehicleSpec const&; speedMps, turnDegSec, l return sqrt(base * base + move * move + lead * lead) // Half width and half height (m) of the visible part of the target as seen from `myPos`. -def private wto_trig_target_half(myPos : float3; tgt : WtoUnitSnap const&; dist : float; visCount : int; +def public wto_trig_target_half(myPos : float3; tgt : WtoUnitSnap const&; dist : float; visCount : int; var halfW, halfH : float&) let los = wto_xz_normalize(tgt.pos - myPos, float3(1.0, 0.0, 0.0)) let perp = float3(-los.z, 0.0, los.x) @@ -61,7 +66,7 @@ def private wto_trig_target_half(myPos : float3; tgt : WtoUnitSnap const&; dist // has just fired (reloading) or is about to slip out of sight; higher for big slow-loading guns // and while pulling back to cover. [never_inline] -def private wto_trig_threshold(now, dist : float; fleeting : bool; slot : WtoBotSlot const&) : float +def private wto_trig_threshold(now, dist, reloadSec : float; ammo : int; slot : WtoBotSlot const&) : float assume p = slot.perceive var thr = WTO_AI_FC_FIRE_THRESHOLD for i in range(slot.threat.count) @@ -71,9 +76,11 @@ def private wto_trig_threshold(now, dist : float; fleeting : bool; slot : WtoBot thr -= WTO_AI_FC_CLOSE_BONUS * (1.0 - dist / WTO_AI_FC_CLOSE_RANGE_M) if now - p.targetShotAt <= WTO_AI_FC_ENEMY_RELOAD_SEC thr -= WTO_AI_FC_ENEMY_RELOAD_BONUS - if fleeting + if p.targetFleeting thr -= WTO_AI_FC_FLEETING_BONUS - thr += WTO_AI_FC_BIG_GUN_PENALTY * clamp((slot.fire.activeCaliberM - 0.075) / 0.05, 0.0, 1.0) + thr += WTO_AI_FC_RELOAD_PENALTY * clamp(reloadSec / WTO_AI_FC_LONG_RELOAD_SEC, 0.0, 1.0) + if ammo >= 0 && ammo < WTO_AI_FC_LOW_AMMO_ROUNDS + thr += WTO_AI_FC_LOW_AMMO_PENALTY * (1.0 - float(ammo) / float(WTO_AI_FC_LOW_AMMO_ROUNDS)) if slot.tactics.state == WTO_STATE_RETREAT_COVER thr += WTO_AI_FC_RETREAT_PENALTY return clamp(thr, WTO_AI_FC_MIN_THRESHOLD, 0.95) @@ -82,15 +89,15 @@ def private wto_trig_threshold(now, dist : float; fleeting : bool; slot : WtoBot // threshold: 99 when the current speed is fine or when even standing would not help. [never_inline] def private wto_trig_speed_request(spec : WtoVehicleSpec const&; halfW, halfH, dist, leadErrM, speedNow, thr : float) : float - if wto_trig_prob(halfW, halfH, dist, 0.0, wto_trig_sigma(spec, speedNow, 0.0, leadErrM, dist)) >= thr + if wto_trig_prob(halfW, halfH, dist, float2(0.0, 0.0), wto_trig_sigma(spec, speedNow, 0.0, leadErrM, dist)) >= thr return 99.0 - if wto_trig_prob(halfW, halfH, dist, 0.0, wto_trig_sigma(spec, 0.0, 0.0, leadErrM, dist)) < thr + if wto_trig_prob(halfW, halfH, dist, float2(0.0, 0.0), wto_trig_sigma(spec, 0.0, 0.0, leadErrM, dist)) < thr return 99.0 var lo = 0.0 var hi = speedNow for _i in range(6) let mid = 0.5 * (lo + hi) - if wto_trig_prob(halfW, halfH, dist, 0.0, wto_trig_sigma(spec, mid, 0.0, leadErrM, dist)) >= thr + if wto_trig_prob(halfW, halfH, dist, float2(0.0, 0.0), wto_trig_sigma(spec, mid, 0.0, leadErrM, dist)) >= thr lo = mid else hi = mid @@ -101,7 +108,7 @@ def private wto_trig_speed_request(spec : WtoVehicleSpec const&; halfW, halfH, d // the autocannon aim slack and the speed request. True when the shot is good enough. [never_inline] def public wto_trig_evaluate(world : WtoWorldSnap const&; now : float; myPos : float3; speedNow, turnDegSec, - dist, aimErrDeg : float; var slot : WtoBotSlot&) : bool + dist : float; offset : float2; var slot : WtoBotSlot&) : bool assume tr = slot.trigger assume p = slot.perceive let tgtIdx = wto_world_find_unit(world, p.targetEid) @@ -119,13 +126,16 @@ def public wto_trig_evaluate(world : WtoWorldSnap const&; now : float; myPos : f let tof = dist / max(120.0, slot.fire.activeSpeedMps) let leadErrM = latSpeed * tof * WTO_AI_EST_LEAD_ERR_FRAC * (1.0 - 0.72 * p.velQuality) let sigma = wto_trig_sigma(slot.spec, speedNow, turnDegSec, leadErrM, dist) - let fleeting = latSpeed >= WTO_AI_FC_FLEETING_LAT_MPS && p.visiblePointCount < 3 - tr.threshold = wto_trig_threshold(now, dist, fleeting, slot) - tr.hitProb = wto_trig_prob(halfW, halfH, dist, aimErrDeg * WTO_DEG_TO_RAD, sigma) - tr.hitProbAligned = wto_trig_prob(halfW, halfH, dist, 0.0, sigma) + tr.threshold = wto_trig_threshold(now, dist, slot.spec.reloadSec, slot.fire.ammoRemaining, slot) + tr.hitProb = wto_trig_prob(halfW, halfH, dist, offset, sigma) + tr.hitProbAligned = wto_trig_prob(halfW, halfH, dist, float2(0.0, 0.0), sigma) tr.aimSlackDeg = max(WTO_AI_FC_BASE_ALIGN_DEG, WTO_AI_FC_AC_AIM_SLACK * atan2(0.5 * (halfW + halfH), max(dist, 5.0)) * WTO_RAD_TO_DEG) - tr.wantSpeedMps = wto_trig_speed_request(slot.spec, halfW, halfH, dist, leadErrM, speedNow, tr.threshold) - tr.wantSpeedAt = now + if slot.fire.gunReady && !slot.fire.reloading && !slot.spec.isAutocannon + tr.wantSpeedMps = wto_trig_speed_request(slot.spec, halfW, halfH, dist, leadErrM, speedNow, tr.threshold) + tr.wantSpeedAt = now + else + tr.wantSpeedMps = 99.0 + tr.wantSpeedAt = -100.0 return tr.hitProb >= tr.threshold // Autocannon and coaxial bursts (decision layer design, 6.3): fire for burstSec, pause for @@ -144,8 +154,34 @@ def public wto_trig_burst_gate(now : float; aimOk : bool; var burstUntil, pauseU started = true return WTO_DENY_OK -// No engaged target: nothing is requested from the hull. -def public wto_trig_clear(var tr : WtoTriggerState&) +// Track burst schedules and speed requests by target. Leaving it starts a fresh opportunity. +def public wto_trig_set_target(eid : EntityId; var tr : WtoTriggerState&) + if eid == tr.targetEid + return + tr.targetEid = eid + tr.biasEpoch++ + tr.wantSpeedMps = 99.0 + tr.wantSpeedAt = -100.0 tr.hitProb = 0.0 tr.hitProbAligned = 0.0 - tr.wantSpeedMps = 99.0 + tr.burstUntil = -100.0 + tr.burstPauseUntil = -100.0 + tr.secondary = WtoWeaponBurst() + tr.coaxial = WtoWeaponBurst() + +[never_inline] +def public wto_trig_aux_aim_ok(now, dist, ownSpeed : float; aimErr : float2; myPos : float3; + target : WtoUnitSnap const&; mount : WtoMountFire const&; + slot : WtoBotSlot const&) : bool + var halfW = 0.0 + var halfH = 0.0 + wto_trig_target_half(myPos, target, dist, slot.perceive.visiblePointCount, halfW, halfH) + if mount.automatic + let slack = atan2(0.5 * (halfW + halfH), max(dist, 5.0)) * WTO_AI_FC_AC_AIM_SLACK + return length(aimErr) <= max(WTO_AI_FC_BASE_ALIGN_DEG * WTO_DEG_TO_RAD, slack) + let los = wto_xz_normalize(target.pos - myPos, float3(1.0, 0.0, 0.0)) + let lateral = abs(dot(slot.perceive.estVel, float3(-los.z, 0.0, los.x))) + let leadErr = lateral * (dist / mount.shell.speedMps) * WTO_AI_EST_LEAD_ERR_FRAC * (1.0 - 0.72 * slot.perceive.velQuality) + let turn = abs(slot.drive.omegaYawRad) * WTO_RAD_TO_DEG + let sigma = wto_trig_sigma(slot.spec, ownSpeed, turn, leadErr, dist) + return wto_trig_prob(halfW, halfH, dist, aimErr, sigma) >= wto_trig_threshold(now, dist, 0.0, -1, slot) diff --git a/game-ai/ground/wto_ai_types_common.das b/game-ai/ground/wto_ai_types_common.das index 79877f8..9373fb4 100644 --- a/game-ai/ground/wto_ai_types_common.das +++ b/game-ai/ground/wto_ai_types_common.das @@ -24,18 +24,16 @@ let public WTO_ROLE_SPAA = 4 let public WTO_STATE_MARCH = 0 let public WTO_STATE_RUN_AND_GUN = 1 -let public WTO_STATE_PREAIM = 2 let public WTO_STATE_SHORT_HALT = 3 let public WTO_STATE_RETREAT_COVER = 4 let public WTO_STATE_COVER_RELOAD = 5 -let public WTO_STATE_RELOAD_ADVANCE = 6 let public WTO_STATE_HULL_ANGLE = 7 let public WTO_STATE_REPOSITION = 8 let public WTO_STATE_DISABLED = 9 let public WTO_STATE_DISPERSE = 10 let public WTO_STATE_RIDGE_WITHDRAW = 11 -// Hull channel behaviors (decision layer design, 7.1), chosen by score in +// Hull channel behaviors, chosen by score in // wto_ai_behavior_common.das; each runs as one or more WTO_STATE_* actions. REPAIR and WITHDRAW // are not scored: they take over at once. let public WTO_BHV_ADVANCE = 0 @@ -67,7 +65,8 @@ struct public WtoVehicleSpec shellCaliberM : float = 0.09 shellCount : int = 0 shells : WtoShellProfile[12] - isAutocannonBelt : bool = false + isAutocannon : bool = false + reloadSec : float = 0.0 isPureLauncher : bool = false halfLen : float = 3.4 halfWid : float = 1.75 @@ -190,12 +189,12 @@ struct public WtoTacticsState retreatTarget : float3 = float3(0.0, 0.0, 0.0) retreatUntil : float = -100.0 retreatReverse : bool = false - hullAngleDir : float3 = float3(1.0, 0.0, 0.0) repositionGoal : float3 = float3(0.0, 0.0, 0.0) repositionOrigin : float3 = float3(0.0, 0.0, 0.0) repositionActive : bool = false engageTargetEid : EntityId = INVALID_ENTITY_ID engageShotsNoEffect : int = 0 + engageObservedShots : int = 0 engageNoShotHalts : int = 0 engageTotalHaltSec : float = 0.0 lastEffectAt : float = -100.0 @@ -217,6 +216,7 @@ struct public WtoTacticsState nextScoreAt : float = 0.0 scoredHasTarget : bool = false scoredReloading : bool = false + scoredNearThreat : bool = false scoredDamageAt : float = -100.0 coverFailedAt : float = -100.0 // Facing constraint (7.3): the hull should point along faceDir (within the facing tolerance) @@ -226,6 +226,8 @@ struct public WtoTacticsState faceDir : float3 = float3(1.0, 0.0, 0.0) faceThreatDir : float3 = float3(1.0, 0.0, 0.0) faceFromThreat : bool = false + faceForGun : bool = false + gunFacingTarget : EntityId = INVALID_ENTITY_ID reverseTravel : bool = false reverseSince : float = -100.0 diff --git a/game-ai/ground/wto_ai_unstick_common.das b/game-ai/ground/wto_ai_unstick_common.das index 4e349ff..99f87d1 100644 --- a/game-ai/ground/wto_ai_unstick_common.das +++ b/game-ai/ground/wto_ai_unstick_common.das @@ -19,17 +19,19 @@ require %appGame.wtoai.wto_ai_navquery_common require %appGame.wtoai.wto_ai_navmesh_common require %appGame.wtoai.wto_ai_follow_common -// Where to back up to: unstickReverseM back along the corridor (or straight back), cut short +// Move against the previous direction of travel along the corridor, cut short // where the mesh ends; false when there is no room behind. [never_inline] -def private wto_unstick_reverse_target(navState : int; myPos, hullFwd : float3; slot : WtoBotSlot const&; +def private wto_unstick_reverse_target(navState : int; myPos, hullFwd : float3; forward : bool; slot : WtoBotSlot const&; var target : float3&) : bool - if slot.nav.rearClearM < 2.5 + let clear = forward ? slot.nav.frontClearM : slot.nav.rearClearM + if clear < 2.5 return false assume rt = slot.route - let straightBack = myPos - hullFwd * WTO_AI_PF_UNSTICK_REV_M + let leaveDir = forward ? hullFwd : -hullFwd + let straightBack = myPos + leaveDir * WTO_AI_PF_UNSTICK_REV_M target = rt.corridorLen >= 2 ? wto_poly_walk_back(rt.corridor, rt.corridorLen, rt.segIdx, rt.segT, WTO_AI_PF_UNSTICK_REV_M) : straightBack - if wto_xz_dist_sq(myPos, target) < 4.0 + if wto_xz_dist_sq(myPos, target) < 4.0 || dot(target - myPos, leaveDir) <= 0.0 target = straightBack if navState != WTO_NAVMESH_LOADED || rt.tier < 0 return true @@ -44,9 +46,11 @@ def private wto_unstick_reverse_target(navState : int; myPos, hullFwd : float3; [never_inline] def private wto_unstick_start_reverse(navState : int; now : float; myPos, hullFwd : float3; var slot : WtoBotSlot&) var target = myPos - if !wto_unstick_reverse_target(navState, myPos, hullFwd, slot, target) + let forward = slot.tactics.reverseTravel + if !wto_unstick_reverse_target(navState, myPos, hullFwd, forward, slot, target) return slot.nav.reverseTarget = target + slot.nav.unstickForward = forward slot.nav.reverseUntil = now + WTO_AI_PF_UNSTICK_REV_SEC slot.nav.reverseCount++ @@ -105,19 +109,22 @@ def public wto_unstick_contact(var world : WtoWorldSnap&; navState : int; now : print("WTO_AI|NAV_CONTACT|eid={uint(slot.eid)}|repeat={nav.contactRepeats}|pos={myPos}|body={nav.contactBodyPos}\n") wto_unstick_start_reverse(navState, now, myPos, hullFwd, slot) -// Backing up after being stuck; true while the manoeuvre runs (the drive command is set). +// True while moving away from a blockage, with the drive command set. [never_inline] def public wto_unstick_reversing(now : float; myPos : float3; var slot : WtoBotSlot&) : bool assume nav = slot.nav if now >= nav.reverseUntil return false - if wto_xz_dist_sq(myPos, nav.reverseTarget) < 1.0 || nav.rearClearM < 2.1 + let clear = nav.unstickForward ? nav.frontClearM : nav.rearClearM + if wto_xz_dist_sq(myPos, nav.reverseTarget) < 1.0 || clear < 2.1 nav.reverseUntil = -100.0 nav.stuckCheckAt = -100.0 return false let dir = wto_xz_normalize(nav.reverseTarget - myPos, -nav.steerDir) nav.steerDir = dir - wto_drive_cmd_set(slot.driveCmd, WTO_DRIVE_REVERSE, nav.reverseTarget, dir, max(2.0, slot.spec.vMaxRev), nav.frontClearM, nav.rearClearM) + let mode = nav.unstickForward ? WTO_DRIVE_CRUISE : WTO_DRIVE_REVERSE + let speed = nav.unstickForward ? min(slot.spec.vMaxFwd, slot.spec.vMaxRev) : max(2.0, slot.spec.vMaxRev) + wto_drive_cmd_set(slot.driveCmd, mode, nav.reverseTarget, dir, speed, nav.frontClearM, nav.rearClearM) return true // Per nav tick while following: detects no progress and escalates through the three levels. diff --git a/game-ai/ground/wto_ai_weapon_profile_common.das b/game-ai/ground/wto_ai_weapon_profile_common.das new file mode 100644 index 0000000..23d429b --- /dev/null +++ b/game-ai/ground/wto_ai_weapon_profile_common.das @@ -0,0 +1,76 @@ +// Stock shell data for a gun mount's active ammunition. Modules sharing a trigger still check +// each available barrel and its ammunition before firing. +options indenting = 2 +options no_global_heap = true +module wto_ai_weapon_profile_common shared + +require ecs +require app +require math +require strings +require DagorDataBlock +require Unit +require Weapon +require %appGame.wtoai.wto_ai_config_common +require %appGame.wtoai.wto_ai_combat_types_common +require %appGame.wtoai.wto_ai_traverse_common + +def public wto_profile_read(bullet : DataBlock const&; var shell : WtoShellProfile&) : bool + let speed = bullet |> datablock_getReal("speed", 0.0) + if speed <= 80.0 || speed >= 2600.0 + return false + let cal = bullet |> datablock_getReal("ballisticCaliber", 0.0) + shell.speedMps = speed + shell.dragCx = clamp(bullet |> datablock_getReal("Cx", 0.35), 0.05, 1.5) + shell.massKg = clamp(bullet |> datablock_getReal("mass", 10.0), 0.05, 250.0) + shell.caliberM = clamp(cal > 0.002 ? cal : bullet |> datablock_getReal("caliber", 0.09), 0.005, 0.4) + return true + +def public wto_profile_is_automatic(weapon : DataBlock const&) : bool + let cannon = weapon |> datablock_getBool("cannon", false) + let belt = weapon |> datablock_getBool("isBulletBelt", false) + let rate = weapon |> datablock_getReal("shotFreq", 0.0) + return belt || (cannon && rate >= WTO_AI_FC_AC_MIN_RATE_HZ) + +def private wto_profile_match(bullet : DataBlock const&; var cached : WtoMountFire&) + let name = bullet |> datablock_getStr("bulletName", "") + if !cached.shellValid && !empty(name) && ecs_hash(name) == cached.shellHash + cached.shellValid = wto_profile_read(bullet, cached.shell) + +[never_inline] +def private wto_profile_read_weapon(mount : DataBlock const&; var cached : WtoMountFire&) + let path = mount |> datablock_getStr("blk", "") + if empty(path) + return + let belt = mount |> datablock_getBool("isBulletBelt", false) + datablock_load_cached(path, DataBlockReadFlag.ROBUST) <| $(weapon) + cached.automatic = belt || wto_profile_is_automatic(weapon) + datablock_for_each_block(weapon, "bullet") <| $(bullet) + wto_profile_match(bullet, cached) + if !cached.shellValid + datablock_for_each_block(weapon) <| $(set) + datablock_for_each_block(set, "bullet") <| $(bullet) + wto_profile_match(bullet, cached) + +// Cache per turret and loaded projectile. Every ballistic check uses that weapon's profile. +[never_inline] +def public wto_mount_load_shell(unit : Unit const?; className : string; turretNo : int; + gun : WTGun const?; var cached : WtoMountFire&) : bool + let idx = int(gun.chosenBulletType) + if idx < 0 || idx >= length(gun.properties.bulletSets) + return false + assume bulletSet = gun.properties.bulletSets[idx] + if length(bulletSet.bullet) == 0 || bulletSet.bullet[0] == null + return false + let name = bulletSet.bullet[0].getName + if empty(name) + return false + let hash = ecs_hash(name) + if cached.shellHash == hash + return cached.shellValid + cached.shellHash = hash + cached.shellValid = false + assume turret = unit.weap.turret[turretNo] + wto_read_gunner_mount(className, int(turret.triggerNo), int(turret.weaponIndex)) <| $(mount) + wto_profile_read_weapon(mount, cached) + return cached.shellValid diff --git a/packages/patcher/src/ground-ai/ground-ai-config.ts b/packages/patcher/src/ground-ai/ground-ai-config.ts index 6f88c9b..60ff06d 100644 --- a/packages/patcher/src/ground-ai/ground-ai-config.ts +++ b/packages/patcher/src/ground-ai/ground-ai-config.ts @@ -254,7 +254,15 @@ export interface GroundAiConfig { }; readonly behavior: { readonly scoreIntervalSec: number; - readonly minHoldSec: number; + readonly advanceHoldSec: number; + readonly engageHoldSec: number; + readonly haltHoldSec: number; + readonly coverHoldSec: number; + readonly repositionHoldSec: number; + readonly postHoldSec: number; + readonly disperseHoldSec: number; + readonly targetValueWeight: number; + readonly nearThreatHaltBonus: number; readonly switchMargin: number; readonly advanceScore: number; readonly engageScore: number; @@ -272,9 +280,8 @@ export interface GroundAiConfig { readonly hullAngleDeg: number; readonly faceToleranceDeg: number; readonly faceMinDanger: number; - readonly faceHaltLimitDeg: number; readonly reverseTravelAngleDeg: number; - readonly reverseMaxGoalDistM: number; + readonly reverseMaxTurnDistM: number; readonly reverseMinSpeedMps: number; readonly reverseHoldSec: number; }; @@ -302,13 +309,18 @@ export interface GroundAiConfig { readonly enemyReloadSec: number; readonly fleetingThresholdBonus: number; readonly fleetingLateralMps: number; - readonly bigGunThresholdPenalty: number; + readonly fleetingLookAheadSec: number; + readonly reloadThresholdPenalty: number; + readonly longReloadSec: number; + readonly lowAmmoRounds: number; + readonly lowAmmoThresholdPenalty: number; + readonly aimSkill: number; + readonly autocannonMinShotsPerSec: number; readonly retreatThresholdPenalty: number; readonly minShotIntervalSec: number; readonly autocannonAimSlack: number; readonly burstSec: number; readonly burstPauseSec: number; - readonly burstRecheckSec: number; readonly autocannonReloadDetectSec: number; readonly auxWeapons: boolean; readonly auxMaxRangeM: number; @@ -496,7 +508,15 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] { ['WTO_AI_TURRET_SCAN_ARC_DEG', 'float', c.turret.scanArcDeg], ['WTO_AI_TURRET_SCAN_PERIOD_SEC', 'float', c.turret.scanPeriodSec], ['WTO_AI_BHV_SCORE_SEC', 'float', c.behavior.scoreIntervalSec], - ['WTO_AI_BHV_MIN_HOLD_SEC', 'float', c.behavior.minHoldSec], + ['WTO_AI_BHV_ADVANCE_HOLD_SEC', 'float', c.behavior.advanceHoldSec], + ['WTO_AI_BHV_ENGAGE_HOLD_SEC', 'float', c.behavior.engageHoldSec], + ['WTO_AI_BHV_HALT_HOLD_SEC', 'float', c.behavior.haltHoldSec], + ['WTO_AI_BHV_COVER_HOLD_SEC', 'float', c.behavior.coverHoldSec], + ['WTO_AI_BHV_REPOSITION_HOLD_SEC', 'float', c.behavior.repositionHoldSec], + ['WTO_AI_BHV_POST_HOLD_SEC', 'float', c.behavior.postHoldSec], + ['WTO_AI_BHV_DISPERSE_HOLD_SEC', 'float', c.behavior.disperseHoldSec], + ['WTO_AI_BHV_TARGET_VALUE_W', 'float', c.behavior.targetValueWeight], + ['WTO_AI_BHV_NEAR_HALT_BONUS', 'float', c.behavior.nearThreatHaltBonus], ['WTO_AI_BHV_SWITCH_MARGIN', 'float', c.behavior.switchMargin], ['WTO_AI_BHV_ADVANCE', 'float', c.behavior.advanceScore], ['WTO_AI_BHV_ENGAGE', 'float', c.behavior.engageScore], @@ -514,9 +534,8 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] { ['WTO_AI_BHV_HULL_ANGLE_DEG', 'float', c.behavior.hullAngleDeg], ['WTO_AI_BHV_FACE_TOL_DEG', 'float', c.behavior.faceToleranceDeg], ['WTO_AI_BHV_FACE_MIN_DANGER', 'float', c.behavior.faceMinDanger], - ['WTO_AI_BHV_FACE_HALT_LIMIT_DEG', 'float', c.behavior.faceHaltLimitDeg], ['WTO_AI_BHV_REVERSE_ANGLE_DEG', 'float', c.behavior.reverseTravelAngleDeg], - ['WTO_AI_BHV_REVERSE_MAX_GOAL_M', 'float', c.behavior.reverseMaxGoalDistM], + ['WTO_AI_BHV_REVERSE_MAX_TURN_M', 'float', c.behavior.reverseMaxTurnDistM], ['WTO_AI_BHV_REVERSE_MIN_MPS', 'float', c.behavior.reverseMinSpeedMps], ['WTO_AI_BHV_REVERSE_HOLD_SEC', 'float', c.behavior.reverseHoldSec], ['WTO_AI_FC_MAX_RANGE_M', 'float', c.fireControl.maxEngageRangeM], @@ -542,13 +561,18 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] { ['WTO_AI_FC_ENEMY_RELOAD_SEC', 'float', c.fireControl.enemyReloadSec], ['WTO_AI_FC_FLEETING_BONUS', 'float', c.fireControl.fleetingThresholdBonus], ['WTO_AI_FC_FLEETING_LAT_MPS', 'float', c.fireControl.fleetingLateralMps], - ['WTO_AI_FC_BIG_GUN_PENALTY', 'float', c.fireControl.bigGunThresholdPenalty], + ['WTO_AI_FC_FLEETING_LOOKAHEAD_SEC', 'float', c.fireControl.fleetingLookAheadSec], + ['WTO_AI_FC_RELOAD_PENALTY', 'float', c.fireControl.reloadThresholdPenalty], + ['WTO_AI_FC_LONG_RELOAD_SEC', 'float', c.fireControl.longReloadSec], + ['WTO_AI_FC_LOW_AMMO_ROUNDS', 'int', c.fireControl.lowAmmoRounds], + ['WTO_AI_FC_LOW_AMMO_PENALTY', 'float', c.fireControl.lowAmmoThresholdPenalty], + ['WTO_AI_FC_AIM_SKILL', 'float', c.fireControl.aimSkill], + ['WTO_AI_FC_AC_MIN_RATE_HZ', 'float', c.fireControl.autocannonMinShotsPerSec], ['WTO_AI_FC_RETREAT_PENALTY', 'float', c.fireControl.retreatThresholdPenalty], ['WTO_AI_FC_MIN_SHOT_INTERVAL_SEC', 'float', c.fireControl.minShotIntervalSec], ['WTO_AI_FC_AC_AIM_SLACK', 'float', c.fireControl.autocannonAimSlack], ['WTO_AI_FC_BURST_SEC', 'float', c.fireControl.burstSec], ['WTO_AI_FC_BURST_PAUSE_SEC', 'float', c.fireControl.burstPauseSec], - ['WTO_AI_FC_BURST_RECHECK_SEC', 'float', c.fireControl.burstRecheckSec], ['WTO_AI_FC_AC_RELOAD_DETECT_SEC', 'float', c.fireControl.autocannonReloadDetectSec], ['WTO_AI_FC_AUX_ENABLED', 'bool', c.fireControl.auxWeapons], ['WTO_AI_FC_AUX_MAX_RANGE_M', 'float', c.fireControl.auxMaxRangeM],