Log error instead of panicking

This commit is contained in:
Joshua Barretto 2023-04-09 19:06:22 +01:00
parent 308ee2f674
commit 859eb95033
3 changed files with 15 additions and 7 deletions

View File

@ -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();
}

View File

@ -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<SimulateNpcs, OnSetup>) {
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");
}
}
}

View File

@ -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",