sorry - swapping from rustfmt to prettier-rust

This commit is contained in:
Llywelwyn 2023-08-23 01:22:09 +01:00
parent 281396f9ce
commit c2c7e0bd52
93 changed files with 2797 additions and 2021 deletions

View file

@ -1,4 +1,4 @@
use crate::{raws::Reaction, Faction, HasAncestry, Map, Position, TakingTurn, WantsToMelee};
use crate::{ raws::Reaction, Faction, HasAncestry, Map, Position, TakingTurn, WantsToMelee };
use specs::prelude::*;
pub struct AdjacentAI {}
@ -34,22 +34,22 @@ impl<'a> System<'a> for AdjacentAI {
evaluate(entity, idx + 1, &ancestries, &factions, &mut reactions);
}
if pos.y > 0 {
evaluate(entity, idx - w as usize, &ancestries, &factions, &mut reactions);
evaluate(entity, idx - (w as usize), &ancestries, &factions, &mut reactions);
}
if pos.y < h - 1 {
evaluate(entity, idx + w as usize, &ancestries, &factions, &mut reactions);
evaluate(entity, idx + (w as usize), &ancestries, &factions, &mut reactions);
}
if pos.y > 0 && pos.x > 0 {
evaluate(entity, (idx - w as usize) - 1, &ancestries, &factions, &mut reactions);
evaluate(entity, idx - (w as usize) - 1, &ancestries, &factions, &mut reactions);
}
if pos.y > 0 && pos.x < w - 1 {
evaluate(entity, (idx - w as usize) + 1, &ancestries, &factions, &mut reactions);
evaluate(entity, idx - (w as usize) + 1, &ancestries, &factions, &mut reactions);
}
if pos.y < h - 1 && pos.x > 0 {
evaluate(entity, (idx + w as usize) - 1, &ancestries, &factions, &mut reactions);
evaluate(entity, idx + (w as usize) - 1, &ancestries, &factions, &mut reactions);
}
if pos.y < h - 1 && pos.x < w - 1 {
evaluate(entity, (idx + w as usize) + 1, &ancestries, &factions, &mut reactions);
evaluate(entity, idx + (w as usize) + 1, &ancestries, &factions, &mut reactions);
}
let mut done = false;
@ -79,7 +79,7 @@ fn evaluate(
idx: usize,
ancestries: &ReadStorage<HasAncestry>,
factions: &ReadStorage<Faction>,
reactions: &mut Vec<(Entity, Reaction)>,
reactions: &mut Vec<(Entity, Reaction)>
) {
crate::spatial::for_each_tile_content(idx, |other_entity| {
let result = crate::raws::get_reactions(
@ -87,7 +87,7 @@ fn evaluate(
other_entity,
&factions,
&ancestries,
&crate::raws::RAWS.lock().unwrap(),
&crate::raws::RAWS.lock().unwrap()
);
reactions.push((other_entity, result));
});

View file

@ -1,4 +1,4 @@
use crate::{EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToApproach};
use crate::{ EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToApproach };
use rltk::prelude::*;
use specs::prelude::*;
@ -29,19 +29,23 @@ impl<'a> System<'a> for ApproachAI {
entities,
) = data;
let mut turn_done: Vec<Entity> = Vec::new();
for (entity, mut pos, approach, mut viewshed, _turn) in
(&entities, &mut positions, &wants_to_approach, &mut viewsheds, &turns).join()
{
for (entity, mut pos, approach, mut viewshed, _turn) in (
&entities,
&mut positions,
&wants_to_approach,
&mut viewsheds,
&turns,
).join() {
turn_done.push(entity);
let path = a_star_search(
map.xy_idx(pos.x, pos.y) as i32,
map.xy_idx(approach.idx % map.width, approach.idx / map.width) as i32,
&mut *map,
&mut *map
);
if path.success && path.steps.len() > 1 {
let idx = map.xy_idx(pos.x, pos.y);
pos.x = path.steps[1] as i32 % map.width;
pos.y = path.steps[1] as i32 / map.width;
pos.x = (path.steps[1] as i32) % map.width;
pos.y = (path.steps[1] as i32) / map.width;
entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved");
let new_idx = map.xy_idx(pos.x, pos.y);
crate::spatial::move_entity(entity, idx, new_idx);

View file

@ -1,4 +1,4 @@
use crate::{Chasing, EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed};
use crate::{ Chasing, EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed };
use rltk::prelude::*;
use specs::prelude::*;
use std::collections::HashMap;
@ -48,20 +48,24 @@ impl<'a> System<'a> for ChaseAI {
// stored in the HashMap. If successful, follow the path. If not, remove
// the chasing component.
let mut turn_done: Vec<Entity> = Vec::new();
for (entity, _turn, mut pos, _chase, mut viewshed) in
(&entities, &turns, &mut positions, &chasing, &mut viewsheds).join()
{
for (entity, _turn, mut pos, _chase, mut viewshed) in (
&entities,
&turns,
&mut positions,
&chasing,
&mut viewsheds,
).join() {
turn_done.push(entity);
let target_pos = targets[&entity];
let path = a_star_search(
map.xy_idx(pos.x, pos.y) as i32,
map.xy_idx(target_pos.0, target_pos.1) as i32,
&mut *map,
&mut *map
);
if path.success && path.steps.len() > 1 && path.steps.len() < MAX_CHASE_DISTANCE {
let idx = map.xy_idx(pos.x, pos.y);
pos.x = path.steps[1] as i32 % map.width;
pos.y = path.steps[1] as i32 / map.width;
pos.x = (path.steps[1] as i32) % map.width;
pos.y = (path.steps[1] as i32) / map.width;
entity_moved.insert(entity, EntityMoved {}).expect("Failed to insert EntityMoved");
let new_idx = map.xy_idx(pos.x, pos.y);
crate::spatial::move_entity(entity, idx, new_idx);

View file

@ -1,4 +1,4 @@
use crate::{tile_walkable, EntityMoved, Map, MoveMode, Movement, Position, TakingTurn, Telepath, Viewshed};
use crate::{ tile_walkable, EntityMoved, Map, MoveMode, Movement, Position, TakingTurn, Telepath, Viewshed };
use specs::prelude::*;
// Rolling a 1d8+x to decide where to move, where x are the number
@ -33,9 +33,13 @@ impl<'a> System<'a> for DefaultAI {
entities,
) = data;
let mut turn_done: Vec<Entity> = Vec::new();
for (entity, _turn, mut pos, mut move_mode, mut viewshed) in
(&entities, &turns, &mut positions, &mut move_mode, &mut viewsheds).join()
{
for (entity, _turn, mut pos, mut move_mode, mut viewshed) in (
&entities,
&turns,
&mut positions,
&mut move_mode,
&mut viewsheds,
).join() {
turn_done.push(entity);
match &mut move_mode.mode {
Movement::Static => {}
@ -44,25 +48,33 @@ impl<'a> System<'a> for DefaultAI {
let mut y = pos.y;
let move_roll = rng.roll_dice(1, 8 + CHANCE_OF_REMAINING_STATIONARY);
match move_roll {
1 => x -= 1,
2 => x += 1,
3 => y -= 1,
4 => y += 1,
1 => {
x -= 1;
}
2 => {
x += 1;
}
3 => {
y -= 1;
}
4 => {
y += 1;
}
5 => {
x -= 1;
y -= 1
y -= 1;
}
6 => {
x += 1;
y -= 1
y -= 1;
}
7 => {
x -= 1;
y += 1
y += 1;
}
8 => {
x += 1;
y += 1
y += 1;
}
_ => {}
}
@ -88,8 +100,8 @@ impl<'a> System<'a> for DefaultAI {
let idx = map.xy_idx(pos.x, pos.y);
if path.len() > 1 {
if !crate::spatial::is_blocked(path[1] as usize) {
pos.x = path[1] as i32 % map.width;
pos.y = path[1] as i32 / map.width;
pos.x = (path[1] as i32) % map.width;
pos.y = (path[1] as i32) / map.width;
entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved");
let new_idx = map.xy_idx(pos.x, pos.y);
crate::spatial::move_entity(entity, idx, new_idx);
@ -110,10 +122,12 @@ impl<'a> System<'a> for DefaultAI {
let path = rltk::a_star_search(
map.xy_idx(pos.x, pos.y) as i32,
map.xy_idx(target_x, target_y) as i32,
&mut *map,
&mut *map
);
if path.success && path.steps.len() > 1 {
move_mode.mode = Movement::RandomWaypoint { path: Some(path.steps) };
move_mode.mode = Movement::RandomWaypoint {
path: Some(path.steps),
};
}
}
}

View file

@ -1,4 +1,4 @@
use crate::{gamelog, Attributes, Burden, EquipmentChanged, Equipped, InBackpack, Item, Pools};
use crate::{ gamelog, Attributes, Burden, EquipmentChanged, Equipped, InBackpack, Item, Pools };
use specs::prelude::*;
use std::collections::HashMap;
@ -52,7 +52,7 @@ impl<'a> System<'a> for EncumbranceSystem {
if let Some(attr) = attributes.get(*entity) {
let carry_capacity_lbs =
(attr.strength.base + attr.strength.modifiers) * CARRY_CAPACITY_PER_STRENGTH;
if pool.weight as i32 > 3 * carry_capacity_lbs {
if (pool.weight as i32) > 3 * carry_capacity_lbs {
// Overloaded
burdened
.insert(*entity, Burden { level: crate::BurdenLevel::Overloaded })
@ -60,7 +60,7 @@ impl<'a> System<'a> for EncumbranceSystem {
if *entity == *player {
gamelog::Logger::new().append("You're overloaded!").log();
}
} else if pool.weight as i32 > 2 * carry_capacity_lbs {
} else if (pool.weight as i32) > 2 * carry_capacity_lbs {
// Strained
burdened
.insert(*entity, Burden { level: crate::BurdenLevel::Strained })
@ -68,7 +68,7 @@ impl<'a> System<'a> for EncumbranceSystem {
if *entity == *player {
gamelog::Logger::new().append("You're strained.").log();
}
} else if pool.weight as i32 > carry_capacity_lbs {
} else if (pool.weight as i32) > carry_capacity_lbs {
// Burdened
burdened
.insert(*entity, Burden { level: crate::BurdenLevel::Burdened })

View file

@ -1,5 +1,5 @@
use crate::config::entity::*;
use crate::{Burden, BurdenLevel, Clock, Energy, Name, Position, RunState, TakingTurn, LOG_TICKS};
use crate::{ Burden, BurdenLevel, Clock, Energy, Name, Position, RunState, TakingTurn, LOG_TICKS };
use rltk::prelude::*;
use specs::prelude::*;
@ -68,7 +68,7 @@ impl<'a> System<'a> for EnergySystem {
1.0
};
// Every entity has a POTENTIAL equal to their speed.
let mut energy_potential: i32 = (energy.speed as f32 * burden_modifier) as i32;
let mut energy_potential: i32 = ((energy.speed as f32) * burden_modifier) as i32;
// Increment current energy by NORMAL_SPEED for every
// whole number of NORMAL_SPEEDS in their POTENTIAL.
while energy_potential >= NORMAL_SPEED {
@ -103,10 +103,9 @@ impl<'a> System<'a> for EnergySystem {
turns.insert(entity, TakingTurn {}).expect("Unable to insert turn.");
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
));
console::log(
format!("ENERGY SYSTEM: {} granted a turn. [leftover energy: {}].", name, energy.current)
);
}
}
}

View file

@ -1,4 +1,4 @@
use crate::{EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToFlee};
use crate::{ EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToFlee };
use rltk::prelude::*;
use specs::prelude::*;
@ -29,9 +29,13 @@ impl<'a> System<'a> for FleeAI {
entities,
) = data;
let mut turn_done: Vec<Entity> = Vec::new();
for (entity, _turn, mut pos, fleeing, mut viewshed) in
(&entities, &turns, &mut positions, &wants_to_flee, &mut viewsheds).join()
{
for (entity, _turn, mut pos, fleeing, mut viewshed) in (
&entities,
&turns,
&mut positions,
&wants_to_flee,
&mut viewsheds,
).join() {
turn_done.push(entity);
let my_idx = map.xy_idx(pos.x, pos.y);
map.populate_blocked();
@ -44,8 +48,8 @@ impl<'a> System<'a> for FleeAI {
if let Some(is_telepath) = telepaths.get_mut(entity) {
is_telepath.dirty = true;
}
pos.x = flee_target as i32 % map.width;
pos.y = flee_target as i32 / map.width;
pos.x = (flee_target as i32) % map.width;
pos.y = (flee_target as i32) / map.width;
entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved");
}
}

View file

@ -7,7 +7,7 @@ pub use quip_system::QuipSystem;
mod regen_system;
pub use regen_system::RegenSystem;
mod encumbrance_system;
pub use encumbrance_system::{EncumbranceSystem, CARRY_CAPACITY_PER_STRENGTH};
pub use encumbrance_system::{ EncumbranceSystem, CARRY_CAPACITY_PER_STRENGTH };
mod adjacent_ai_system;
pub use adjacent_ai_system::AdjacentAI;
mod visible_ai_system;

View file

@ -1,4 +1,4 @@
use crate::{gamelog, gui::renderable_colour, Name, Quips, Renderable, TakingTurn, Viewshed};
use crate::{ gamelog, gui::renderable_colour, Name, Quips, Renderable, TakingTurn, Viewshed };
use rltk::prelude::*;
use specs::prelude::*;
@ -26,7 +26,8 @@ impl<'a> System<'a> for QuipSystem {
} else {
(rng.roll_dice(1, quip.available.len() as i32) - 1) as usize
};
gamelog::Logger::new()
gamelog::Logger
::new()
.append("The")
.colour(renderable_colour(&renderables, entity))
.append(&name.name)

View file

@ -1,5 +1,14 @@
use crate::{
gamelog, gui::Class, Attributes, Clock, HasClass, Player, Pools, Position, RandomNumberGenerator, TakingTurn,
gamelog,
gui::Class,
Attributes,
Clock,
HasClass,
Player,
Pools,
Position,
RandomNumberGenerator,
TakingTurn,
};
use specs::prelude::*;
@ -55,8 +64,8 @@ impl<'a> System<'a> for RegenSystem {
for (e, _p, pool) in (&entities, &positions, &mut pools).join() {
let is_wizard = if let Some(class) = classes.get(e) { class.name == Class::Wizard } else { false };
let numerator = if is_wizard { WIZARD_MP_REGEN_MOD } else { NONWIZARD_MP_REGEN_MOD };
let multiplier: f32 = numerator as f32 / MP_REGEN_DIVISOR as f32;
let mp_regen_tick = ((MP_REGEN_BASE - pool.level) as f32 * multiplier) as i32;
let multiplier: f32 = (numerator as f32) / (MP_REGEN_DIVISOR as f32);
let mp_regen_tick = (((MP_REGEN_BASE - pool.level) as f32) * multiplier) as i32;
if current_turn % mp_regen_tick == 0 {
try_mana_regen_tick(pool, rng.roll_dice(1, get_mana_regen_per_tick(e, &attributes)));
}
@ -66,7 +75,7 @@ impl<'a> System<'a> for RegenSystem {
fn get_player_hp_regen_turn(level: i32) -> i32 {
if level < 10 {
return (42 / (level + 2)) + 1;
return 42 / (level + 2) + 1;
} else {
return 3;
}
@ -86,7 +95,7 @@ fn try_hp_regen_tick(pool: &mut Pools, amount: i32) {
fn get_mana_regen_per_tick(e: Entity, attributes: &ReadStorage<Attributes>) -> i32 {
let regen = if let Some(attributes) = attributes.get(e) {
((attributes.intelligence.bonus + attributes.wisdom.bonus) / 2) + MIN_MP_REGEN_PER_TURN
(attributes.intelligence.bonus + attributes.wisdom.bonus) / 2 + MIN_MP_REGEN_PER_TURN
} else {
MIN_MP_REGEN_PER_TURN
};

View file

@ -1,8 +1,12 @@
use crate::{
effects::{add_effect, EffectType, Targets},
effects::{ add_effect, EffectType, Targets },
gamelog,
gui::renderable_colour,
Clock, Confusion, Name, Renderable, TakingTurn,
Clock,
Confusion,
Name,
Renderable,
TakingTurn,
};
use rltk::prelude::*;
use specs::prelude::*;
@ -63,7 +67,7 @@ impl<'a> System<'a> for TurnStatusSystem {
lifespan: 200.0,
delay: 0.0,
},
Targets::Entity { target: entity },
Targets::Entity { target: entity }
);
} else {
not_my_turn.push(entity);
@ -93,7 +97,7 @@ impl<'a> System<'a> for TurnStatusSystem {
lifespan: 200.0,
delay: 0.0,
},
Targets::Entity { target: entity },
Targets::Entity { target: entity }
);
}
}

View file

@ -1,6 +1,16 @@
use crate::{
raws::Reaction, Chasing, Faction, HasAncestry, Map, Mind, Position, TakingTurn, Telepath, Viewshed,
WantsToApproach, WantsToFlee,
raws::Reaction,
Chasing,
Faction,
HasAncestry,
Map,
Mind,
Position,
TakingTurn,
Telepath,
Viewshed,
WantsToApproach,
WantsToFlee,
};
use rltk::prelude::*;
use specs::prelude::*;
@ -70,10 +80,10 @@ impl<'a> System<'a> for VisibleAI {
}
}
reactions.sort_by(|(a, _, _), (b, _, _)| {
let (a_x, a_y) = (a % map.width as usize, a / map.width as usize);
let (a_x, a_y) = (a % (map.width as usize), a / (map.width as usize));
let dist_a = DistanceAlg::PythagorasSquared.distance2d(Point::new(a_x, a_y), Point::new(pos.x, pos.y));
let dist_a_estimate = dist_a as i32;
let (b_x, b_y) = (b % map.width as usize, b / map.width as usize);
let (b_x, b_y) = (b % (map.width as usize), b / (map.width as usize));
let dist_b = DistanceAlg::PythagorasSquared.distance2d(Point::new(b_x, b_y), Point::new(pos.x, pos.y));
let dist_b_estimate = dist_b as i32;
return dist_b_estimate.cmp(&dist_a_estimate);
@ -110,7 +120,7 @@ fn evaluate(
ancestries: &ReadStorage<HasAncestry>,
factions: &ReadStorage<Faction>,
reactions: &mut Vec<(usize, Reaction, Entity)>,
minds: Option<&ReadStorage<Mind>>,
minds: Option<&ReadStorage<Mind>>
) {
crate::spatial::for_each_tile_content(idx, |other_entity| {
let mut check = true;
@ -129,7 +139,7 @@ fn evaluate(
other_entity,
&factions,
&ancestries,
&crate::raws::RAWS.lock().unwrap(),
&crate::raws::RAWS.lock().unwrap()
),
other_entity,
));