#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MatCatId {
pub category: u8, pub variant: u16, pub grade: u16, }
impl MatCatId {
pub fn new(category: u8, variant: u16, grade: u16) -> Self {
Self { category, variant, grade }
}
}
#[derive(Debug, Clone, Copy)]
pub struct MatProps {
pub density: f32, pub conductivity: f32, pub hardness: f32, pub flammability: f32, pub corrosion: f32, pub tensile: f32, }
fn default_props_for_category(cat: u8) -> MatProps {
match cat {
1 => MatProps { density: 7.5,
conductivity: 0.7,
hardness: 5.0,
flammability: 0.0,
corrosion: 0.5,
tensile: 200.0,
},
2 => MatProps { density: 1.2,
conductivity: 0.0,
hardness: 2.0,
flammability: 0.8,
corrosion: 0.0,
tensile: 50.0,
},
3 => MatProps { density: 0.7,
conductivity: 0.0,
hardness: 3.0,
flammability: 0.9,
corrosion: 0.1,
tensile: 40.0,
},
_ => MatProps { density: 1.0,
conductivity: 0.0,
hardness: 1.0,
flammability: 0.5,
corrosion: 0.5,
tensile: 10.0,
},
}
}
fn override_variant_props(cat: u8, var: u16, mut props: MatProps) -> MatProps {
match (cat, var) {
(1, 42) => { props.density = 8.9;
props.conductivity = 1.0;
props.hardness = 3.0;
props.corrosion = 0.6;
props.tensile = 210.0;
}
(1, 43) => { props.density = 7.9;
props.conductivity = 0.2;
props.hardness = 4.0;
props.corrosion = 0.8;
props.tensile = 250.0;
}
(2, 10) => { props.density = 1.4;
props.hardness = 2.5;
props.flammability = 0.4;
props.tensile = 55.0;
}
_ => {}
}
props
}
pub fn props_for(id: &MatCatId) -> MatProps {
let defaults = default_props_for_category(id.category);
override_variant_props(id.category, id.variant, defaults)
}