starting on config files

This commit is contained in:
Llywelwyn 2023-08-23 00:58:01 +01:00
parent 98a4422b15
commit 281396f9ce
11 changed files with 23 additions and 22 deletions

View file

@ -1,11 +1,11 @@
use crate::config::entity::*;
use crate::{Burden, BurdenLevel, Clock, Energy, Name, Position, RunState, TakingTurn, LOG_TICKS};
use rltk::prelude::*;
use specs::prelude::*;
pub struct EnergySystem {}
pub const NORMAL_SPEED: i32 = 12;
const TURN_COST: i32 = NORMAL_SPEED * 4;
const TURN_COST: i32 = NORMAL_SPEED * TURN_COST_MULTIPLIER;
impl<'a> System<'a> for EnergySystem {
#[allow(clippy::type_complexity)]

View file

@ -1,5 +1,5 @@
mod energy_system;
pub use energy_system::{EnergySystem, NORMAL_SPEED};
pub use energy_system::EnergySystem;
mod turn_status_system;
pub use turn_status_system::TurnStatusSystem;
mod quip_system;

4
src/config/entity.rs Normal file
View file

@ -0,0 +1,4 @@
pub const DEFAULT_VIEWSHED_STANDARD: i32 = 16; // Standard viewshed radius for almost all entities.
pub const NORMAL_SPEED: i32 = 12; // Normal speed for almost all entities.
pub const TURN_COST_MULTIPLIER: i32 = 4; // How many ticks per turn for an entity with NORMAL_SPEED.

1
src/config/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod entity;

View file

@ -1,7 +1,7 @@
use super::{gamesystem::attr_bonus, gamesystem::get_attribute_rolls, Attributes, Pools, Renderable, RunState, State};
use crate::config::entity::NORMAL_SPEED;
use crate::{
ai::NORMAL_SPEED, raws, Attribute, Energy, HasAncestry, HasClass, KnownSpell, KnownSpells, Pool, Skill, Skills,
Telepath, BUC,
raws, Attribute, Energy, HasAncestry, HasClass, KnownSpell, KnownSpells, Pool, Skill, Skills, Telepath, BUC,
};
use rltk::prelude::*;
use serde::{Deserialize, Serialize};

View file

@ -29,6 +29,7 @@ mod inventory;
mod particle_system;
use particle_system::{ParticleBuilder, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME};
mod ai;
mod config;
mod effects;
mod gamesystem;
mod random_table;

View file

@ -252,7 +252,7 @@ pub fn multiply_by_float(rgb: rltk::RGB, offsets: (f32, f32, f32)) -> RGB {
fn darken_by_distance(pos: Point, other_pos: Point) -> f32 {
let distance = DistanceAlg::Pythagoras.distance2d(pos, other_pos) as f32; // Get distance in tiles.
let interp_factor = (distance - START_DARKEN_AT_N_TILES)
/ (MAX_DARKEN_AT_N_TILES * crate::spawner::VIEWSHED_MOD - START_DARKEN_AT_N_TILES);
/ (MAX_DARKEN_AT_N_TILES * crate::config::entity::DEFAULT_VIEWSHED_STANDARD as f32 - START_DARKEN_AT_N_TILES);
let interp_factor = interp_factor.max(0.0).min(1.0); // Clamp [0-1]
return 1.0 - interp_factor * (1.0 - MAX_DARKENING);
}

View file

@ -1,9 +1,9 @@
use super::{Raws, Reaction};
use crate::components::*;
use crate::config::entity;
use crate::gamesystem::*;
use crate::gui::Ancestry;
use crate::random_table::RandomTable;
use crate::spawner;
use crate::LOG_SPAWNING;
use regex::Regex;
use rltk::prelude::*;
@ -381,11 +381,7 @@ pub fn spawn_named_mob(
eb = ecs.create_entity().marked::<SimpleMarker<SerializeMe>>();
eb = spawn_position(pos, eb, key, raws);
eb = eb.with(Name { name: mob_template.name.clone(), plural: mob_template.name.clone() });
eb = eb.with(Viewshed {
visible_tiles: Vec::new(),
range: (mob_template.vision_range as f32 * spawner::VIEWSHED_MOD) as i32,
dirty: true,
});
eb = eb.with(Viewshed { visible_tiles: Vec::new(), range: mob_template.vision_range as i32, dirty: true });
if let Some(telepath) = &mob_template.telepathy_range {
eb = eb.with(Telepath { telepath_tiles: Vec::new(), range: *telepath, dirty: true });
}

View file

@ -1,16 +1,15 @@
use super::{
ai::NORMAL_SPEED, random_table::RandomTable, raws, Attribute, Attributes, Clock, Energy, EquipmentChanged, Faction,
HungerClock, HungerState, Map, Mind, Name, Player, Pool, Pools, Position, Rect, Renderable, SerializeMe, Skill,
Skills, TileType, Viewshed,
random_table::RandomTable, raws, Attribute, Attributes, Clock, Energy, EquipmentChanged, Faction, HungerClock,
HungerState, Map, Mind, Name, Player, Pool, Pools, Position, Rect, Renderable, SerializeMe, Skill, Skills,
TileType, Viewshed,
};
use crate::config::entity;
use crate::gamesystem::*;
use rltk::{RandomNumberGenerator, RGB};
use specs::prelude::*;
use specs::saveload::{MarkedBuilder, SimpleMarker};
use std::collections::HashMap;
pub const VIEWSHED_MOD: f32 = 1.25;
/// Spawns the player and returns his/her entity object.
pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
let mut skills = Skills { skills: HashMap::new() };
@ -19,7 +18,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
skills.skills.insert(Skill::Magic, 0);
let (int, con) = (10, 10);
// We only create the player once, so create the Clock here for counting turns too.
ecs.create_entity().with(Clock {}).with(Energy { current: 0, speed: NORMAL_SPEED }).build();
ecs.create_entity().with(Clock {}).with(Energy { current: 0, speed: entity::NORMAL_SPEED }).build();
let player = ecs
.create_entity()
.with(Position { x: player_x, y: player_y })
@ -32,7 +31,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
.with(Player {})
.with(Mind {})
.with(Faction { name: "player".to_string() })
.with(Viewshed { visible_tiles: Vec::new(), range: (12 as f32 * VIEWSHED_MOD) as i32, dirty: true })
.with(Viewshed { visible_tiles: Vec::new(), range: entity::DEFAULT_VIEWSHED_STANDARD, dirty: true })
.with(Name { name: "you".to_string(), plural: "you".to_string() })
.with(HungerClock { state: HungerState::Satiated, duration: 1200 })
.with(Attributes {
@ -56,7 +55,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
})
.with(EquipmentChanged {})
.with(skills)
.with(Energy { current: 0, speed: NORMAL_SPEED })
.with(Energy { current: 0, speed: entity::NORMAL_SPEED })
.marked::<SimpleMarker<SerializeMe>>()
.build();

View file

@ -805,11 +805,11 @@ function __wbg_get_imports() {
const ret = makeMutClosure(arg0, arg1, 124, __wbg_adapter_20);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper2705 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper2716 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 518, __wbg_adapter_23);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_closure_wrapper2707 = function(arg0, arg1, arg2) {
imports.wbg.__wbindgen_closure_wrapper2718 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 518, __wbg_adapter_23);
return addHeapObject(ret);
};

Binary file not shown.