From ffe54d30c162ae83d9a9136a2efc166383797bc1 Mon Sep 17 00:00:00 2001 From: David Gay Date: Mon, 16 Oct 2023 14:09:14 -0400 Subject: Use signed ints for ability scores --- src/rules/ability_scores.rs | 6 +++--- src/rules/npcs.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rules/ability_scores.rs b/src/rules/ability_scores.rs index 2b9acf0..05f996b 100644 --- a/src/rules/ability_scores.rs +++ b/src/rules/ability_scores.rs @@ -26,7 +26,7 @@ impl AbilityScore { #[derive(Debug)] pub struct AbilityScoreCollection { - scores: HashMap, + scores: HashMap, } impl AbilityScoreCollection { @@ -36,11 +36,11 @@ impl AbilityScoreCollection { } } - pub fn add_score(&mut self, ability_score: AbilityScore, value: u32) { + pub fn add_score(&mut self, ability_score: AbilityScore, value: i32) { self.scores.insert(ability_score, value); } - pub fn get_score(&self, ability_score: AbilityScore) -> Option<&u32> { + pub fn get_score(&self, ability_score: AbilityScore) -> Option<&i32> { self.scores.get(&ability_score) } } diff --git a/src/rules/npcs.rs b/src/rules/npcs.rs index d9fdc0f..dc65dbb 100644 --- a/src/rules/npcs.rs +++ b/src/rules/npcs.rs @@ -30,7 +30,7 @@ impl Npc { pub fn roll_henchman_ability_scores(&mut self) { rand::thread_rng(); - let mut ability_score_rolls: HashMap = HashMap::new(); + let mut ability_score_rolls: HashMap = HashMap::new(); for &ability in &[ AbilityScore::Strength, @@ -55,14 +55,14 @@ impl Npc { debug!("Bumped prime requisites, now at {}", roll_result.total()); // At this point we don't need the individual dice anymore. - let mut total = roll_result.total(); + let mut total = roll_result.total() as i32; // Add NPC-specific class ability score modifiers. total += class_ref .npc_ability_score_modifiers .get(&ability) .copied() - .unwrap_or(0) as u32; + .unwrap_or(0); debug!("After adding NPC class modifiers, now at {}", total); // Add racial ability score modifiers. @@ -70,14 +70,14 @@ impl Npc { .npc_ability_score_modifiers .get(&ability) .copied() - .unwrap_or(0) as u32; + .unwrap_or(0); debug!("After adding racial modifiers, now at {}", total); // Ensure racial ability score limits are imposed. // TODO: Use u8 for all of these, so no conversion from u32 will be needed. let [min_score, max_score] = race_ref.ability_score_ranges.get(&ability).unwrap().male; - total = total.max(min_score as u32); - total = total.min(max_score as u32); + total = total.max(min_score as i32); + total = total.min(max_score as i32); ability_score_rolls.insert(ability, total); } -- cgit v1.2.3