improved logging (debug stuff)
This commit is contained in:
parent
aac6e0ad02
commit
c00418f7c8
4 changed files with 24 additions and 38 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Clock, Energy, Position, RunState, TakingTurn};
|
||||
use crate::{Clock, Energy, Name, Position, RunState, TakingTurn, LOG_TICKS};
|
||||
use rltk::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
|
|
@ -18,10 +18,11 @@ impl<'a> System<'a> for EnergySystem {
|
|||
WriteExpect<'a, RandomNumberGenerator>,
|
||||
WriteExpect<'a, RunState>,
|
||||
ReadExpect<'a, Entity>,
|
||||
ReadStorage<'a, Name>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (clock, mut energies, positions, mut turns, entities, mut rng, mut runstate, player) = data;
|
||||
let (clock, mut energies, positions, mut turns, entities, mut rng, mut runstate, player, names) = data;
|
||||
// If not ticking, do nothing.
|
||||
if *runstate != RunState::Ticking {
|
||||
return;
|
||||
|
|
@ -31,6 +32,9 @@ impl<'a> System<'a> for EnergySystem {
|
|||
if energy.current >= TURN_COST {
|
||||
energy.current -= TURN_COST;
|
||||
crate::gamelog::record_event("turns", 1);
|
||||
if LOG_TICKS {
|
||||
console::log(format!("===== TURN {} =====", crate::gamelog::get_event_count("turns")));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Clear TakingTurn{} from every entity.
|
||||
|
|
@ -38,23 +42,11 @@ impl<'a> System<'a> for EnergySystem {
|
|||
for (entity, energy, _pos) in (&entities, &mut energies, &positions).join() {
|
||||
// Every entity has a POTENTIAL equal to their speed.
|
||||
let mut energy_potential: i32 = energy.speed;
|
||||
if entity == *player {
|
||||
console::log(format!(
|
||||
"TICK for Player with speed {}: [current energy: {}]",
|
||||
energy.speed, energy.current
|
||||
));
|
||||
}
|
||||
// Increment current energy by NORMAL_SPEED for every
|
||||
// whole number of NORMAL_SPEEDS in their POTENTIAL.
|
||||
while energy_potential >= NORMAL_SPEED {
|
||||
energy_potential -= NORMAL_SPEED;
|
||||
energy.current += NORMAL_SPEED;
|
||||
if entity == *player {
|
||||
console::log(format!(
|
||||
"Gained 12 energy. [current: {}, potential: {}]",
|
||||
energy.current, energy_potential
|
||||
));
|
||||
}
|
||||
}
|
||||
// Roll a NORMAL_SPEED-sided die. If less than their
|
||||
// remaining POTENTIAL, increment current energy by
|
||||
|
|
@ -64,12 +56,6 @@ impl<'a> System<'a> for EnergySystem {
|
|||
if energy_potential > 0 {
|
||||
if rng.roll_dice(1, NORMAL_SPEED) <= energy_potential {
|
||||
energy.current += NORMAL_SPEED;
|
||||
if entity == *player {
|
||||
console::log(format!(
|
||||
"Rolled for remainder! Gained 12 energy. [current energy: {}]",
|
||||
energy.current
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
// TURN_COST is equal to 4 * NORMAL_SPEED. If the current entity
|
||||
|
|
@ -78,13 +64,14 @@ impl<'a> System<'a> for EnergySystem {
|
|||
if energy.current >= TURN_COST {
|
||||
turns.insert(entity, TakingTurn {}).expect("Unable to insert turn.");
|
||||
energy.current -= TURN_COST;
|
||||
if LOG_TICKS {
|
||||
let name = if let Some(name) = names.get(entity) { &name.name } else { "Unknown entity" };
|
||||
console::log(format!(
|
||||
"ENERGY SYSTEM: {} granted a turn. [leftover energy: {}].",
|
||||
name, energy.current
|
||||
));
|
||||
}
|
||||
if entity == *player {
|
||||
if entity == *player {
|
||||
console::log(format!(
|
||||
"Player has >=TURN_COST energy, granting a turn. [remaining energy: {}]",
|
||||
energy.current
|
||||
));
|
||||
}
|
||||
*runstate = RunState::AwaitingInput;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use super::{gamelog, HungerClock, HungerState, SufferDamage};
|
||||
use super::{gamelog, HungerClock, HungerState, SufferDamage, LOG_TICKS};
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct HungerSystem {}
|
||||
|
|
@ -12,8 +12,8 @@ impl<'a> System<'a> for HungerSystem {
|
|||
let (entities, mut hunger_clock, player_entity, mut inflict_damage) = data;
|
||||
|
||||
for (entity, mut clock) in (&entities, &mut hunger_clock).join() {
|
||||
if entity == *player_entity {
|
||||
rltk::console::log(format!("HUNGER TICK for Player [current clock: {}]", clock.duration));
|
||||
if LOG_TICKS && entity == *player_entity {
|
||||
rltk::console::log(format!("HUNGER SYSTEM: Ticked for player entity. [clock: {}]", clock.duration));
|
||||
}
|
||||
clock.duration -= 1;
|
||||
if clock.duration > 0 {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ extern crate lazy_static;
|
|||
|
||||
//Consts
|
||||
pub const SHOW_MAPGEN: bool = false;
|
||||
pub const LOG_SPAWNING: bool = true;
|
||||
pub const LOG_TICKS: bool = true;
|
||||
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
pub enum RunState {
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@ use super::Raws;
|
|||
use crate::components::*;
|
||||
use crate::gamesystem::*;
|
||||
use crate::random_table::RandomTable;
|
||||
use crate::LOG_SPAWNING;
|
||||
use regex::Regex;
|
||||
use rltk::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use specs::saveload::{MarkedBuilder, SimpleMarker};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
const SPAWN_LOGGING: bool = true;
|
||||
|
||||
pub enum SpawnType {
|
||||
AtPosition { x: i32, y: i32 },
|
||||
Equipped { by: Entity },
|
||||
|
|
@ -376,7 +375,7 @@ pub fn spawn_named_mob(
|
|||
eb = eb.with(LootTable { table: loot.table.clone(), chance: loot.chance });
|
||||
}
|
||||
|
||||
if SPAWN_LOGGING {
|
||||
if LOG_SPAWNING {
|
||||
rltk::console::log(format!(
|
||||
"SPAWNLOG: {} ({}HP, {}MANA, {}BAC) spawned at level {} ({}[base], {}[map difficulty], {}[player level]), worth {} XP",
|
||||
&mob_template.name, mob_hp, mob_mana, mob_bac, mob_level, base_mob_level, map_difficulty, player_level, xp_value
|
||||
|
|
@ -487,12 +486,10 @@ pub fn table_by_name(raws: &RawMaster, key: &str, difficulty: i32) -> RandomTabl
|
|||
return rt;
|
||||
}
|
||||
}
|
||||
if SPAWN_LOGGING {
|
||||
rltk::console::log(format!(
|
||||
"SPAWNLOG: Something went wrong when trying to spawn {} @ map difficulty {}. Returned debug entry.",
|
||||
key, difficulty
|
||||
));
|
||||
}
|
||||
rltk::console::log(format!(
|
||||
"DEBUGINFO: Something went wrong when trying to spawn {} @ map difficulty {}. Returned debug entry.",
|
||||
key, difficulty
|
||||
));
|
||||
return RandomTable::new().add("debug", 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue