summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Gay <eapoems@riseup.net>2023-10-16 14:09:14 -0400
committerDavid Gay <eapoems@riseup.net>2023-10-16 14:09:14 -0400
commitffe54d30c162ae83d9a9136a2efc166383797bc1 (patch)
tree81e786db68356f0945f00df88dc9fe3ef9e92771 /src
parent686726b414dcb9d0fe66ec0d64436f51919a0fd1 (diff)
Use signed ints for ability scores
Diffstat (limited to 'src')
-rw-r--r--src/rules/ability_scores.rs6
-rw-r--r--src/rules/npcs.rs12
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<AbilityScore, u32>,
+ scores: HashMap<AbilityScore, i32>,
}
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<AbilityScore, u32> = HashMap::new();
+ let mut ability_score_rolls: HashMap<AbilityScore, i32> = 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);
}