aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/fparkan-game/src/main.rs17
-rw-r--r--crates/fparkan-runtime/src/lib.rs5
-rw-r--r--crates/fparkan-runtime/src/projectile.rs50
-rw-r--r--crates/fparkan-runtime/src/projectile_shield.rs11
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs14
-rw-r--r--docs/tomes/06-behavior.md3
6 files changed, 80 insertions, 20 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 7389e101..a8f3f431 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -107,7 +107,7 @@ use fparkan_render_vulkan::{
VulkanStaticTexture, VulkanStaticTextureMip, VulkanStaticVertex,
};
use fparkan_runtime::{
- apply_projectile_contact, autodemo_camera, board_friendly_warbot, capture_building_with_notice,
+ apply_projectile_impact, autodemo_camera, board_friendly_warbot, capture_building_with_notice,
capture_neutral_warbot, create, deploy_mine, disembark_warbot, frame as step_mission_frame,
frame_with_player_motion, load_gameplay_mission_with_build_parts, load_mission_static_preview,
load_mission_static_preview_roots, loaded_mission_assets, loaded_mission_object_drafts,
@@ -117,7 +117,7 @@ use fparkan_runtime::{
starting_player_weapons, AutoDemoCamera, AutoDemoView, BuildingMeshNode, Engine, EngineError,
EngineServices, FrameResult, LoadedMission, MissionAssets, MissionEventStop, MissionMode,
MissionObjectDraft, MissionRequest, MissionStartupInput, PlayerMotion, PlayerProjectile,
- PlayerWeapons, StartingCockpit, SIMULATION_COVERAGE,
+ PlayerWeapons, ProjectileImpact, StartingCockpit, SIMULATION_COVERAGE,
};
#[cfg(test)]
use fparkan_runtime::{load_mission_with_init_stubs, plan_player_motion};
@@ -10533,15 +10533,22 @@ impl StaticVulkanApp {
}) {
"communicator-field"
} else if let Some(hit) = unit_contact {
- match draw.volume.map(|volume| apply_projectile_contact(engine, hit, volume)).transpose() {
- Ok(Some(Some((remaining, removed)))) => eprintln!(
+ let outcome = draw
+ .volume
+ .map(|volume| apply_projectile_impact(engine, hit, volume))
+ .transpose();
+ match &outcome {
+ Ok(Some(ProjectileImpact::ShieldAbsorbed)) => {},
+ Ok(Some(ProjectileImpact::Damage { remaining, removed })) => eprintln!(
"player_projectile_hit shooter={} pool={pool} target={} remaining={remaining} removed={removed} queue_time_ms={clock_ms}", shooter.slot, hit.handle.slot,
),
outcome => eprintln!(
"sim_coverage player_projectile_target_stub=1 target={} result={outcome:?}", hit.handle.slot,
),
}
- if hit.building_node().is_some() {
+ if matches!(outcome, Ok(Some(ProjectileImpact::ShieldAbsorbed))) {
+ "shield"
+ } else if hit.building_node().is_some() {
"building"
} else {
"unit"
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 3a5609db..33f27dac 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -175,8 +175,9 @@ pub use production::{
order_factory_scheme,
};
pub use projectile::{
- apply_projectile_contact, apply_projectile_hit, load_player_projectile, projectile_terrain_hit,
- projectile_unit_hit, PlayerProjectile, ProjectileAssets, ProjectileContact, ProjectileNode,
+ apply_projectile_contact, apply_projectile_hit, apply_projectile_impact,
+ load_player_projectile, projectile_terrain_hit, projectile_unit_hit, PlayerProjectile,
+ ProjectileAssets, ProjectileContact, ProjectileImpact, ProjectileNode,
};
pub use projectile_parts::depleted_chassis_nodes;
pub use research::order_lab_research;
diff --git a/crates/fparkan-runtime/src/projectile.rs b/crates/fparkan-runtime/src/projectile.rs
index fc9f6965..ff745655 100644
--- a/crates/fparkan-runtime/src/projectile.rs
+++ b/crates/fparkan-runtime/src/projectile.rs
@@ -276,18 +276,64 @@ pub(super) fn unit_sphere(
Some((center, radius))
}
+/// Result of applying a projectile to a building or unit.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum ProjectileImpact {
+ /// The shield took the entire hit and the hull was untouched.
+ ShieldAbsorbed,
+ /// The contacted part lost health, or the unit was destroyed.
+ Damage {
+ /// Health left on the contacted part.
+ remaining: f32,
+ /// Whether the impact removed the whole unit.
+ removed: bool,
+ },
+ /// No damage result was available for the contacted target or part.
+ Unresolved,
+}
+
/// Applies projectile damage to the contacted part of a building or unit.
+/// Returns the hull damage result when the hit reached the hull.
pub fn apply_projectile_contact(
engine: &mut Engine,
contact: ProjectileContact,
volume: f32,
) -> Result<Option<(f32, bool)>, ControlResourceAccessError> {
+ Ok(match apply_projectile_impact(engine, contact, volume)? {
+ ProjectileImpact::Damage { remaining, removed } => Some((remaining, removed)),
+ ProjectileImpact::ShieldAbsorbed | ProjectileImpact::Unresolved => None,
+ })
+}
+
+/// Applies a projectile and distinguishes shield absorption from unresolved damage.
+pub fn apply_projectile_impact(
+ engine: &mut Engine,
+ contact: ProjectileContact,
+ volume: f32,
+) -> Result<ProjectileImpact, ControlResourceAccessError> {
let key = match contact.node {
- Some(ProjectileNode::CaptureBarrier) => return Ok(None),
+ Some(ProjectileNode::CaptureBarrier) => return Ok(ProjectileImpact::Unresolved),
None | Some(ProjectileNode::Chassis(0)) => None,
Some(ProjectileNode::Chassis(key) | ProjectileNode::Building(key)) => Some(key),
};
- let volume = super::projectile_shield::absorb(engine, contact, volume);
+ let unabsorbed = super::projectile_shield::absorb(engine, contact, volume);
+ if volume > 0.0 && unabsorbed == 0.0 {
+ return Ok(ProjectileImpact::ShieldAbsorbed);
+ }
+ Ok(
+ match apply_contact_damage(engine, contact, key, unabsorbed)? {
+ Some((remaining, removed)) => ProjectileImpact::Damage { remaining, removed },
+ None => ProjectileImpact::Unresolved,
+ },
+ )
+}
+
+fn apply_contact_damage(
+ engine: &mut Engine,
+ contact: ProjectileContact,
+ key: Option<u32>,
+ volume: f32,
+) -> Result<Option<(f32, bool)>, ControlResourceAccessError> {
let table = engine.loaded.as_ref().and_then(|mission| {
mission
.control_device_tables
diff --git a/crates/fparkan-runtime/src/projectile_shield.rs b/crates/fparkan-runtime/src/projectile_shield.rs
index d41ea0bd..a0875278 100644
--- a/crates/fparkan-runtime/src/projectile_shield.rs
+++ b/crates/fparkan-runtime/src/projectile_shield.rs
@@ -279,8 +279,8 @@ mod tests {
#[ignore = "requires licensed corpus"]
fn licensed_autodemo_shield_blocks_and_then_exposes_one_sector() {
use crate::{
- apply_projectile_contact, create, load_gameplay_mission, EngineServices, MissionMode,
- MissionRequest, MissionStartupInput,
+ apply_projectile_impact, create, load_gameplay_mission, EngineServices, MissionMode,
+ MissionRequest, MissionStartupInput, ProjectileImpact,
};
use fparkan_vfs::DirectoryVfs;
use std::sync::Arc;
@@ -337,10 +337,9 @@ mod tests {
let (center, radius) = engine.shield_impacts.as_ref().unwrap().local_spheres[0]
.expect("stock AutoDemo warbot enclosure");
assert!(center[2] > 0.0 && radius > 6.0);
- assert!(
- apply_projectile_contact(&mut engine, contact, capacity * 0.5)
- .unwrap()
- .is_none()
+ assert_eq!(
+ apply_projectile_impact(&mut engine, contact, capacity * 0.5).unwrap(),
+ ProjectileImpact::ShieldAbsorbed
);
let impacts = take_shield_impacts(&mut engine);
let [impact] = impacts.as_slice() else {
diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs
index 03bf5c8d..224213bb 100644
--- a/crates/fparkan-runtime/src/unit_combat.rs
+++ b/crates/fparkan-runtime/src/unit_combat.rs
@@ -1,5 +1,5 @@
use super::{
- apply_projectile_contact,
+ apply_projectile_impact,
autodemo::MOBILE_UNIT,
combat_report::{CombatObject, CombatReport},
player_weapon::prepare_unit_weapons,
@@ -9,7 +9,7 @@ use super::{
unit_patrol::UnitPatrol,
weapon_pose::WeaponPoses,
Engine, MissionAssets, MissionDocument, MissionObjectDraft, ObjectHandle, PlayerProjectile,
- PlayerWeapons,
+ PlayerWeapons, ProjectileImpact,
};
use fparkan_vfs::Vfs;
use fparkan_world::{identity_metadata, transform_state};
@@ -468,16 +468,20 @@ impl AutoDemoCombat {
let target = CombatObject::read(&engine.world, hit.handle);
match data
.volume
- .map(|volume| apply_projectile_contact(engine, hit, volume))
+ .map(|volume| apply_projectile_impact(engine, hit, volume))
{
- Some(Ok(Some((_, true)))) => {
+ Some(Ok(ProjectileImpact::ShieldAbsorbed)) => {}
+ Some(Ok(ProjectileImpact::Damage { removed: true, .. })) => {
self.report.destroyed(flight.shooter_identity, target, now);
events.push(AutoDemoCombatEvent::Destroyed {
shooter: flight.shooter,
target: hit.handle,
});
}
- Some(Ok(Some((remaining, false)))) => {
+ Some(Ok(ProjectileImpact::Damage {
+ remaining,
+ removed: false,
+ })) => {
if let Some(node) = hit.building_node() {
events.push(AutoDemoCombatEvent::BuildingHit {
shooter: flight.shooter,
diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md
index 56f207b6..3f4cad1a 100644
--- a/docs/tomes/06-behavior.md
+++ b/docs/tomes/06-behavior.md
@@ -2798,6 +2798,9 @@ GOG `Control.dll` выбор выполняется по RVA `0x2c590`, а сиÐ
силу сектора с 3040 до 2141. При пробое сектор опустошается, а к корпусу
проходит разность. FParkan выполняет эту проверку в найденной точке
контакта. Отдельная поверхность поля ещё открыта.
+Полное поглощение завершает полёт снаряда и учитывается как отработавшее
+попадание в щит. Отчёт о неподдержанных контактах учитывает случаи, в
+которых движок не смог обработать цель.
Попадание в заряженный сектор запускает эффект из устройства 9,
например `r_shield_g` у одного из варботов AutoDemo. Оригинал по RVA