From 385f1ba20fb2f39f808e61caa64ca26b65aee40e Mon Sep 17 00:00:00 2001 From: Rendo Date: Sat, 15 Nov 2025 17:12:42 +0500 Subject: [PATCH] Small faction check improvement --- src/projectile.rs | 2 +- src/ships/mod.rs | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/projectile.rs b/src/projectile.rs index 4f51816..295895f 100644 --- a/src/projectile.rs +++ b/src/projectile.rs @@ -45,7 +45,7 @@ pub fn observe_collision( let Ok((mut collided, faction)) = collision_query.get_mut(collision.with) else { return; }; - if faction == &projectile.faction { + if projectile.faction.can_damage(faction) { return; } diff --git a/src/ships/mod.rs b/src/ships/mod.rs index 3d4b5cb..d54bfd7 100644 --- a/src/ships/mod.rs +++ b/src/ships/mod.rs @@ -5,10 +5,33 @@ use crate::projectile::spawn_projectile; pub mod enemy; pub mod player; -#[derive(Component, PartialEq)] +#[derive(Component)] pub enum Factions { PlayerFaction, EnemyFaction, + NeutralFaction, +} + +impl Factions { + pub fn can_damage(&self, other: &Factions) -> bool { + match self { + Factions::PlayerFaction => match other { + Factions::PlayerFaction => false, + Factions::EnemyFaction => true, + Factions::NeutralFaction => false, + }, + Factions::EnemyFaction => match other { + Factions::PlayerFaction => true, + Factions::EnemyFaction => false, + Factions::NeutralFaction => false, + }, + Factions::NeutralFaction => match other { + Factions::EnemyFaction => false, + Factions::NeutralFaction => false, + Factions::PlayerFaction => false, + }, + } + } } pub struct ShipsPlugin;