weapons #33

Merged
Dandaedre merged 2 commits from weapons into project_weaponry 2025-02-13 18:20:59 +01:00
9 changed files with 243 additions and 32 deletions

View File

@ -5,14 +5,39 @@
//! handling of the whole crafting process when the times comes
#![allow(dead_code)]
// use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::rc::Rc;
/// This element can be converted to tex
pub trait ToTex {}
/// Trait representing a view table
///
/// These table exist to allow to link several point of interest to a RecipeCollection
/// Please note that while FinalRepresentations and ViewTable are two separate traits,
/// they are always tied together as a view table will alway take specific assumptions
/// on the data present inside therefore not allowing many variations on the underlying
/// implementation of the representation
pub trait ViewTable {
/// The inner type of element that one would be peeking into
///
/// Usually the final representation of an Item
type InterestElement: RefinedList;
/// Specify this element can be made from parts (Unsure, maybe a way to ensure Add is presend ?)
pub trait FromParts {}
/// Give a list of interesting element indicises to further analyse
fn index_of_interest_points(&self) -> Vec<usize>;
/// Interrogate the FinalRepresentation to find interesting elements
fn find_points_of_interest(&self, representation: &Self::InterestElement);
// An alternative, non Self::Typed way of doing since there is only one usage for now
// fn find_points_of_interest(&self, representation: &impl FinalRepresentation);
}
/// Trait implemented by any struct holding the final representation of a RecipeCollection
///
/// This trait is rather placeholder, reminding the user to give only objects that are indeed
/// final representations and contains all important fields calculated
///
/// While it is possible to enforce from_recipe_collection, doing so would require the viewtable
/// lock itseld to a particular recipe.
/// While it is the case as of now, matters are not yet set in stone
pub trait RefinedList {}
/// Trait implemented for the final collection of a recipe, allowing it to be combined with parts
///
@ -105,11 +130,23 @@ pub(super) type FilterType<T> = Box<Rc<FilterFunctionType<T>>>;
/// A generic Filtering function
pub(crate) struct FilterFunction<T>(pub(super) FilterType<T>);
// impl<T> FilterFunction<T> {
// fn new_from_closure(m: &FilterFunctionType<T>) -> Self {
// FilterFunction(Box::new(Rc::new(m)))
// }
// }
/// This element can be converted to tex
pub trait ToTex {
/// Export the object to a Tex string
fn to_tex(&self) -> String;
}
/// This element can be converted to a csv for further analysis
pub trait ToAnalysis {
/// Convert this object into a csv
fn to_csv(&self) -> String;
}
/// Garanties that a struct can be generated from a database
pub trait DbSerializable {
/// Serialize the object from a database
fn from_database() -> Self;
}
// /// A blanket implementation giving all combinaisons of recipes with another RecipeCollection
// ///

View File

@ -0,0 +1,99 @@
// Workspace: weaponry
// File: weaponry/src/weaponry_structs/equipement_advanced_repr.rs
//! Give an advanced representation of the equipement, infering more fields (such a dpt, max_dps etc...)
//!
//! The generation of this fields is primordial to allow post filtering and visualisation
//!
//! Note that while ALL fields and representation will likely be backed into a megablob,
//! nothing prevents us to implement the trait for other objects and avoid massive computation
//! of all the fields even when the user will not be interested in them
#![allow(dead_code)]
use crate::interfaces::RefinedList;
use super::equipement_structs::InnerStats;
/// The final representation of the equipement inplementing all the fields needed for processing
pub struct RefinedEquipement {
/// The original inner stats
///
/// This structs takes ownership of the inner data
inner: InnerStats,
/// Advanced stats
advanced: AdvancedStats,
}
pub struct RefinedEquipementList(Vec<RefinedEquipement>);
// Just a checkmark
impl RefinedList for RefinedEquipementList {}
/// The list of advanced stats infered from an Equipement
#[allow(missing_docs, clippy::missing_docs_in_private_items)]
pub struct AdvancedStats {
damage_per_turn: f64,
damage_per_action: f64,
armor_break_per_turn: f64,
armor_break_per_action: f64,
damage_matrix: DamageMatrix,
/// Armor break factoring in the damage output: While a weapon might have high AB, not having any damage will seriously hinder that AB
expected_armor_break_per_turn: f64,
// All other criterias are already in the inner as raw criterias
}
/// A damage matrix, crossing damage conditions (high dice to low dice) with precision (high precision to low precision)
///
/// This simulation does only calculate a very limited preset of damage values
struct DamageMatrix {
/// The inner damage matrix
damage_matrix: Vec<f64>,
}
impl DamageMatrix {
/// Get the damage value from given condition
pub fn get_damage(&self, precision: Precision, dices: DiceNumber) -> f64 {
self.damage_matrix[precision.index() + 3 * dices.index()]
}
/// Calculate the damage simulation from a given InnerStats
pub fn calculate_damage(inner: &InnerStats) -> Self {
let _ = inner;
todo!()
}
}
/// The precision infered for a damage calculation event
pub enum Precision {
High = 9,
Medium = 6,
Low = 3,
}
/// The number of dices rolled for a damage simulation
pub enum DiceNumber {
High = 7,
Medium = 5,
Low = 3,
}
impl Precision {
#[inline]
/// Associate an index to the different values
fn index(&self) -> usize {
match self {
Precision::High => 0,
Precision::Medium => 1,
Precision::Low => 2,
}
}
}
impl DiceNumber {
#[inline]
/// Associate an index to the different values
fn index(&self) -> usize {
match self {
DiceNumber::High => 0,
DiceNumber::Medium => 1,
DiceNumber::Low => 2,
}
}
}

View File

@ -35,17 +35,13 @@ impl From<EqNature> for Equipement {
fn from(val: EqNature) -> Self {
Self {
stats: val.stats,
// filter_function: FilterFunction(default_filter_for_equipement()),
filter_function: FilterFunction::new(&|sel, lhs| {
match (&sel.target, &lhs.category) {
(Some(a), Some(b)) => a == b,
(None, None) => true,
_ => false,
}
// if let Some(targ) = &sel.target {
// &lhs.category
// }
// & default_filter()(sel, lhs)
// TODO : Checks that this is exactly desired behavious
// :Also check for Cross Weapon/Armor contamination
// Checks that the nature is compatible with the previous iteration
filter_function: FilterFunction::new(&|sel, lhs| match (&sel.target, &lhs.category) {
(Some(a), Some(b)) => a == b,
(None, None) => true,
_ => false,
}),
}
}

View File

@ -1,3 +1,30 @@
// Workspace: weaponry
// File: weaponry/src/weaponry_structs/equipement_impl_database.rs
//! All database specific implementations
use crate::interfaces::DbSerializable;
use super::equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape};
//TODO: Fred, make these and I'm happy
impl DbSerializable for EqShape {
fn from_database() -> Self {
todo!()
}
}
impl DbSerializable for EqMaterial {
fn from_database() -> Self {
todo!()
}
}
impl DbSerializable for EqNature {
fn from_database() -> Self {
todo!()
}
}
impl DbSerializable for EqFinishing {
fn from_database() -> Self {
todo!()
}
}

View File

@ -15,6 +15,21 @@ macro_rules! add_to_vec {
}};
}
/// Adds either of the vectors or merge them
macro_rules! add_two_options {
($self: expr, $rhs: expr) => {{
match ($self.clone(), $rhs.clone()) {
(None, None) => None,
(None, Some(a)) => Some(a),
(Some(a), None) => Some(a),
(Some(mut a), Some(mut b)) => {
a.0.append(&mut b.0);
Some(a)
}
}
}};
}
impl std::ops::Add for &InnerStats {
type Output = InnerStats;
@ -34,17 +49,7 @@ impl std::ops::Add for &InnerStats {
armor_break: self.armor_break + rhs.armor_break,
armor_pierce: self.armor_pierce + rhs.armor_pierce,
antimaterial: self.antimaterial + rhs.antimaterial,
damage_type: {
match (self.damage_type.clone(), rhs.damage_type.clone()) {
(None, None) => None,
(None, Some(a)) => Some(a),
(Some(a), None) => Some(a),
(Some(mut a), Some(mut b)) => {
a.0.append(&mut b.0);
Some(a)
}
}
},
damage_type: add_two_options!(self.damage_type, rhs.damage_type),
protection: self.protection + rhs.protection,
integrity: self.integrity + rhs.integrity,
torque_two_handed: self.torque_two_handed + rhs.torque_two_handed,

View File

@ -0,0 +1,16 @@
// Workspace: weaponry
// File: weaponry/src/weaponry_structs/equipement_tools.rs
//! Tools user facing, implement all that a end user would need
//!
//! This file implements all the functions the main runner will eventually launch
#![allow(dead_code)]
/// Tooling utility
fn load_database() {}
/// Export the data generated to tex
fn export_to_tex() {}
/// Export the data generated to csv
fn export_to_csv() {}

View File

@ -0,0 +1,28 @@
// Workspace: weaponry
// File: weaponry/src/weaponry_structs/equipement_views.rs
//! Implement the view trait to allow for a list of "Points of Interest" to be created
//! This list is imperative to allow several criterias to be looked up one after the other to gather as many points of data as possible
//!
//! It is mandatory that these points of interest link back to the original data by index and not by reference, to allow this operation to be thread safe
#![allow(dead_code)]
use crate::interfaces::ViewTable;
use super::equipement_advanced_repr::RefinedEquipementList;
/// A rather full view of an equipement, this multi field allow for a great amount of different operations but incurrs a rather hefty calculation price
struct EquipementFullView {}
impl ViewTable for EquipementFullView {
type InterestElement = RefinedEquipementList;
fn index_of_interest_points(&self) -> Vec<usize> {
todo!()
}
fn find_points_of_interest(&self, representation: &Self::InterestElement) {
let _ = representation;
todo!()
}
}

View File

@ -15,6 +15,7 @@
// #[global_allocator]
// static GLOBAL: Jemalloc = Jemalloc;
mod equipement_advanced_repr;
mod equipement_fields;
mod equipement_impl_advanced;
mod equipement_impl_basics;
@ -23,6 +24,8 @@ mod equipement_impl_io;
mod equipement_impl_logic;
mod equipement_impl_math;
pub mod equipement_structs;
pub mod equipement_tools;
mod equipement_views;
// Republishes the most used symbols
// All generic structs