ravenous-tools/weaponry/src/weaponry_structs/equipement_impl_math.rs

93 lines
3.6 KiB
Rust

// Workspace: weaponry
// File: weaponry/src/weaponry_structs/equipement_math.rs
//! Implements base math for each field
//!
use super::equipement_structs::InnerEquipementStats;
use crate::weaponry_structs::SpecialField;
/// Add a new vector to a clone of a inner field
macro_rules! add_to_vec {
($self: expr, $rhs: expr) => {{
let mut new = $self.clone();
new.append(&mut $rhs.clone());
new
}};
}
/// Adds either of the vectors or merge them
macro_rules! add_two_options {
($self: expr, $rhs: expr) => {{
match ($self.as_ref(), $rhs.as_ref()) {
(None, None) => None,
(None, Some(a)) => Some(a.clone()),
(Some(a), None) => Some(a.clone()),
(Some(a), Some(b)) => Some(a.clone() + b.clone()),
}
}};
}
/// Clones the first option that has some data
macro_rules! first_correct_option {
($self:expr, $rhs:expr) => {
match ($self.as_ref(), $rhs.as_ref()) {
(Some(a), _) => Some(a.clone()),
(_, Some(b)) => Some(b.clone()),
_ => None,
}
};
}
impl std::ops::Add for &InnerEquipementStats {
type Output = InnerEquipementStats;
fn add(self, rhs: Self) -> Self::Output {
InnerEquipementStats {
// TODO: Decide the behaviour of ids, as uuid are useless but this is even more useless
id: add_to_vec!(self.id, rhs.id),
name: add_to_vec!(self.name, rhs.name),
rarity: self.rarity + rhs.rarity,
cost: self.cost + rhs.cost,
difficulty: self.difficulty + rhs.difficulty,
tier: self.tier + rhs.tier,
damage: self.damage + rhs.damage,
p_damage: self.p_damage + rhs.p_damage,
precision: self.precision + rhs.precision,
rmax: self.rmax + rhs.rmax,
armor_break: self.armor_break + rhs.armor_break,
armor_pierce: self.armor_pierce + rhs.armor_pierce,
antimaterial: self.antimaterial + rhs.antimaterial,
damage_type: add_two_options!(self.damage_type, rhs.damage_type),
protection: self.protection + rhs.protection,
integrity: self.integrity + rhs.integrity,
torque_two_handed: add_two_options!(self.torque_two_handed, rhs.torque_two_handed),
torque_one_handed: add_two_options!(self.torque_one_handed, rhs.torque_one_handed),
dodge: self.dodge + rhs.dodge,
parry: self.parry + rhs.parry,
speed: self.speed + rhs.speed,
stealth: self.stealth + rhs.stealth,
// macro_category: self.macro_category.clone().or(rhs.macro_category.clone()), // Can be further optimized
// target: self.target.clone().or(rhs.target.clone()), // Can be further optimized
special: self.special.clone() + rhs.special.clone(), // Can be further optimized
action_cost: self.action_cost + rhs.action_cost,
reload_cost: self.reload_cost.or(rhs.reload_cost),
range: self.range + rhs.range,
agility_bonus: self.agility_bonus + rhs.agility_bonus,
category_base: first_correct_option!(self.category_base, rhs.category_base),
category_size: first_correct_option!(self.category_size, rhs.category_size),
target_category: first_correct_option!(self.target_category, rhs.target_category),
}
}
}
impl std::ops::Add for SpecialField {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
let mut c = self.clone();
// TODO: Overcopy, kinda meaningless optimisation tho
c.0.append(&mut rhs.clone().0);
c
}
}