From 859eb950334719ad15f96a022f5caf8c276a35ab Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sun, 9 Apr 2023 19:06:22 +0100 Subject: [PATCH] Log error instead of panicking --- rtsim/src/data/sentiment.rs | 9 +++++---- rtsim/src/rule/simulate_npcs.rs | 4 ++-- server/src/rtsim/tick.rs | 9 ++++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/rtsim/src/data/sentiment.rs b/rtsim/src/data/sentiment.rs index 080a6b5e4d..30ed3be98a 100644 --- a/rtsim/src/data/sentiment.rs +++ b/rtsim/src/data/sentiment.rs @@ -13,7 +13,7 @@ pub const NPC_MAX_SENTIMENTS: usize = 128; /// Magic factor used to control sentiment decay speed (note: higher = slower /// decay, for implementation reasons). -const DECAY_FACTOR: f32 = 1.0; //6.0; TODO: Use this value when we're happy that everything is working as intended +const DECAY_TIME_FACTOR: f32 = 1.0; //6.0; TODO: Use this value when we're happy that everything is working as intended /// The target that a sentiment is felt toward. // NOTE: More could be added to this! For example: @@ -73,14 +73,14 @@ impl Sentiments { /// sentiment to neutral decay with the following formula: /// /// ```ignore - /// seconds_until_neutrality = ((sentiment_value * 127 * DECAY_FACTOR) ^ 2) / 2 + /// seconds_until_neutrality = ((sentiment_value * 127 * DECAY_TIME_FACTOR) ^ 2) / 2 /// ``` /// /// For example, a positive (see [`Sentiment::POSITIVE`]) sentiment has a /// value of `0.2`, so we get /// /// ```ignore - /// seconds_until_neutrality = ((0.1 * 127 * DECAY_FACTOR) ^ 2) / 2 = ~2,903 seconds, or 48 minutes + /// seconds_until_neutrality = ((0.1 * 127 * DECAY_TIME_FACTOR) ^ 2) / 2 = ~2,903 seconds, or 48 minutes /// ``` /// /// Some 'common' sentiment decay times are as follows: @@ -178,7 +178,8 @@ impl Sentiment { // TODO: Make dt-independent so we can slow tick rates // 36 = 6 * 6 if rng.gen_bool( - (1.0 / (self.positivity.unsigned_abs() as f32 * DECAY_FACTOR.powi(2) * dt)) as f64, + (1.0 / (self.positivity.unsigned_abs() as f32 * DECAY_TIME_FACTOR.powi(2) * dt)) + as f64, ) { self.positivity -= self.positivity.signum(); } diff --git a/rtsim/src/rule/simulate_npcs.rs b/rtsim/src/rule/simulate_npcs.rs index 3b5a4f7740..f35dc3a215 100644 --- a/rtsim/src/rule/simulate_npcs.rs +++ b/rtsim/src/rule/simulate_npcs.rs @@ -11,7 +11,7 @@ use common::{ }; use rand::prelude::*; use rand_chacha::ChaChaRng; -use tracing::warn; +use tracing::{error, warn}; use world::site::SiteKind; pub struct SimulateNpcs; @@ -36,7 +36,7 @@ fn on_setup(ctx: EventCtx) { let actor = Actor::Npc(npc_id); vehicle.riders.push(actor); if ride.steering && vehicle.driver.replace(actor).is_some() { - panic!("Replaced driver"); + error!("Replaced driver"); } } } diff --git a/server/src/rtsim/tick.rs b/server/src/rtsim/tick.rs index 2706c7cdb2..0bf9d55da6 100644 --- a/server/src/rtsim/tick.rs +++ b/server/src/rtsim/tick.rs @@ -21,6 +21,7 @@ use rtsim::data::{ }; use specs::{Join, Read, ReadExpect, ReadStorage, WriteExpect, WriteStorage}; use std::{sync::Arc, time::Duration}; +use tracing::error; use world::site::settlement::trader_loadout; fn humanoid_config(profession: &Profession) -> &'static str { @@ -36,7 +37,13 @@ fn humanoid_config(profession: &Profession) -> &'static str { 1 => "common.entity.world.traveler1", 2 => "common.entity.world.traveler2", 3 => "common.entity.world.traveler3", - _ => panic!("Not a valid adventurer rank"), + _ => { + error!( + "Tried to get configuration for invalid adventurer rank {}", + rank + ); + "common.entity.world.traveler3" + }, }, Profession::Blacksmith => "common.entity.village.blacksmith", Profession::Chef => "common.entity.village.chef",