Skip to content

Commit

Permalink
WIP apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
micutio committed Sep 19, 2022
1 parent 8f46050 commit efe2b7f
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 295 deletions.
18 changes: 9 additions & 9 deletions src/entity/act/hereditary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 241,7 @@ impl Action for Attack {
"{} attacked {} for {} damage",
&owner.visual.name, &t.visual.name, self.lvl
),
game::msg::MsgClass::Info,
game::msg::Class::Info,
);
// show particle effect
ui::register_particle(
Expand All @@ -263,7 263,7 @@ impl Action for Attack {
if owner.is_player() {
state
.log
.add("Nothing to attack here", game::msg::MsgClass::Info);
.add("Nothing to attack here", game::msg::Class::Info);
}
ActionResult::Failure
}
Expand Down Expand Up @@ -355,13 355,13 @@ impl Action for InjectRnaVirus {
"{0} {1} infected {2} with virus RNA",
owner.visual.name, verb, target.visual.name
),
game::msg::MsgClass::Alert,
game::msg::Class::Alert,
);
}
let original_ai = target.control.take();
// TODO: Determine the duration of "infection" dynamically.
let overriding_ai =
control::Controller::Npc(Box::new(ai::AiForceVirusProduction::new_duration(
control::Controller::Npc(Box::new(ai::ForcedVirusProduction::new_duration(
original_ai,
4,
Some(owner.dna.raw.clone()),
Expand Down Expand Up @@ -464,7 464,7 @@ impl Action for InjectRetrovirus {
"{0} {1} infected {2} with virus RNA",
owner.visual.name, verb, target.visual.name
),
game::msg::MsgClass::Alert,
game::msg::Class::Alert,
);
}
// insert virus dna into target dna
Expand All @@ -480,7 480,7 @@ impl Action for InjectRetrovirus {
let original_ai = target.control.take();
// TODO: Determine the duration of "infection" dynamically.
let overriding_ai =
control::Controller::Npc(Box::new(ai::AiForceVirusProduction::new_duration(
control::Controller::Npc(Box::new(ai::ForcedVirusProduction::new_duration(
original_ai,
4,
Some(owner.dna.raw.clone()),
Expand Down Expand Up @@ -584,7 584,7 @@ impl Action for ProduceVirion {
};
state.log.add(
format!("{0} {1} forced to produce virions", owner.visual.name, verb),
game::msg::MsgClass::Alert,
game::msg::Class::Alert,
);
}
owner.inventory.items.push(
Expand All @@ -599,7 599,7 @@ impl Action for ProduceVirion {
.gene_library
.dna_to_traits(genetics::DnaType::Rna, dna),
)
.control(control::Controller::Npc(Box::new(ai::AiVirus {}))),
.control(control::Controller::Npc(Box::new(ai::Virus {}))),
);
}
None => {
Expand Down Expand Up @@ -630,7 630,7 @@ impl Action for ProduceVirion {
.gene_library
.dna_to_traits(genetics::DnaType::Rna, &dna_from_seq),
)
.control(control::Controller::Npc(Box::new(ai::AiVirus {}))),
.control(control::Controller::Npc(Box::new(ai::Virus {}))),
// TODO: Separate Ai for retroviruses?
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/entity/act/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 25,15 @@ impl Action for PickUpItem {
if owner.inventory.items.len() > owner.actuators.volume as usize {
state
.log
.add("Your inventory is full!", game::msg::MsgClass::Info);
.add("Your inventory is full!", game::msg::Class::Info);
}
// only add object if it has in item tag
state.log.add(
format!(
"{} picked up a {}",
owner.visual.name, &target_obj.visual.name
),
game::msg::MsgClass::Info,
game::msg::Class::Info,
);
owner.add_to_inventory(target_obj);

Expand Down Expand Up @@ -102,7 102,7 @@ impl Action for DropItem {
let mut item: Object = owner.remove_from_inventory(self.lvl as usize);
state.log.add(
format!("{} dropped a {}", owner.visual.name, &item.visual.name),
game::msg::MsgClass::Info,
game::msg::Class::Info,
);
// set the item to be dropped at the same position as the player
item.pos.move_to(&owner.pos);
Expand Down
66 changes: 32 additions & 34 deletions src/entity/ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,7 @@ use crate::entity::act::{self, Action};
use crate::entity::control::{self, Ai};
use crate::entity::{genetics, Object};
use crate::game::{self, ObjectStore, State};
use crate::util::rng::RngExtended;
use crate::util::random::RngExtended;

use rand::seq::{IteratorRandom, SliceRandom};
use serde::{Deserialize, Serialize};
Expand All @@ -19,10 19,10 @@ use std::fmt::Debug;
/// which saves some more CPU cycles.
#[cfg_attr(not(target_arch = "wasm32"), derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct AiPassive;
pub struct Passive;

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiPassive {
impl Ai for Passive {
fn act(
&mut self,
_state: &mut State,
Expand All @@ -36,16 36,16 @@ impl Ai for AiPassive {
/// Each turn chooses a random valid action with a random valid target
#[cfg_attr(not(target_arch = "wasm32"), derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct AiRandom;
pub struct RandomAction;

impl AiRandom {
pub fn new() -> Self {
AiRandom {}
impl RandomAction {
pub const fn new() -> Self {
Self {}
}
}

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiRandom {
impl Ai for RandomAction {
fn act(
&mut self,
state: &mut State,
Expand Down Expand Up @@ -88,7 88,7 @@ impl Ai for AiRandom {

// b) no empty targets available
if !adjacent_targets.iter().any(|t| !t.physics.is_blocking) {
valid_targets.retain(|t| *t != act::TargetCategory::EmptyObject)
valid_targets.retain(|t| *t != act::TargetCategory::EmptyObject);
}

// d) no blocking targets available => remove blocking from selection
Expand Down Expand Up @@ -118,7 118,7 @@ impl Ai for AiRandom {
.filter(|at| at.physics.is_blocking)
.choose(&mut state.rng)
{
boxed_action.set_target(act::Target::from_pos(&owner.pos, &target_obj.pos))
boxed_action.set_target(act::Target::from_pos(&owner.pos, &target_obj.pos));
}
}
act::TargetCategory::EmptyObject => {
Expand All @@ -127,12 127,12 @@ impl Ai for AiRandom {
.filter(|at| !at.physics.is_blocking)
.choose(&mut state.rng)
{
boxed_action.set_target(act::Target::from_pos(&owner.pos, &target_obj.pos))
boxed_action.set_target(act::Target::from_pos(&owner.pos, &target_obj.pos));
}
}
act::TargetCategory::Any => {
if let Some(target_obj) = adjacent_targets.choose(&mut state.rng) {
boxed_action.set_target(act::Target::from_pos(&owner.pos, &target_obj.pos))
boxed_action.set_target(act::Target::from_pos(&owner.pos, &target_obj.pos));
}
}
}
Expand All @@ -144,10 144,10 @@ impl Ai for AiRandom {
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AiRandomWalk;
pub struct RandomWalk;

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiRandomWalk {
impl Ai for RandomWalk {
fn act(
&mut self,
state: &mut State,
Expand Down Expand Up @@ -177,16 177,16 @@ impl Ai for AiRandomWalk {
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AiVirus;
pub struct Virus;

impl AiVirus {
pub fn new() -> Self {
AiVirus {}
impl Virus {
pub const fn new() -> Self {
Self {}
}
}

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiVirus {
impl Ai for Virus {
fn act(
&mut self,
state: &mut State,
Expand Down Expand Up @@ -272,29 272,29 @@ impl Ai for AiVirus {

#[cfg_attr(not(target_arch = "wasm32"), derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct AiForceVirusProduction {
pub struct ForcedVirusProduction {
original_ai: Option<control::Controller>,
turns_active: Option<i32>,
current_turn: i32,
rna: Option<Vec<u8>>,
}

impl AiForceVirusProduction {
pub fn new_duration(
impl ForcedVirusProduction {
pub const fn new_duration(
original_ai: Option<control::Controller>,
duration_turns: i32,
rna: Option<Vec<u8>>,
) -> Self {
AiForceVirusProduction {
Self {
original_ai,
turns_active: Some(duration_turns),
current_turn: 0,
rna,
}
}

fn _new_forever(original_ai: Option<control::Controller>, rna: Option<Vec<u8>>) -> Self {
AiForceVirusProduction {
const fn _new_forever(original_ai: Option<control::Controller>, rna: Option<Vec<u8>>) -> Self {
Self {
original_ai,
turns_active: None,
current_turn: 0,
Expand All @@ -304,7 304,7 @@ impl AiForceVirusProduction {
}

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiForceVirusProduction {
impl Ai for ForcedVirusProduction {
fn act(
&mut self,
_state: &mut State,
Expand All @@ -326,10 326,10 @@ impl Ai for AiForceVirusProduction {
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AiWallTile;
pub struct WallTile;

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiWallTile {
impl Ai for WallTile {
fn act(
&mut self,
state: &mut State,
Expand Down Expand Up @@ -369,11 369,9 @@ impl Ai for AiWallTile {
.into_iter()
.flatten()
.filter(|obj| {
if let Some(_tile) = &obj.tile {
obj.tile.as_ref().map_or(false, |_tile| {
!obj.physics.is_blocking || !objects.is_pos_occupied(&obj.pos)
} else {
false
}
})
})
.choose(&mut state.rng);
if let Some(target) = target_cell {
Expand All @@ -391,10 389,10 @@ impl Ai for AiWallTile {
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AiFloorTile;
pub struct FloorTile;

#[cfg_attr(not(target_arch = "wasm32"), typetag::serde)]
impl Ai for AiFloorTile {
impl Ai for FloorTile {
fn act(
&mut self,
_state: &mut State,
Expand Down
32 changes: 15 additions & 17 deletions src/entity/complement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 13,14 @@
//! pathogens or host cells that have been damaged physically or by infection.
//!
//! ## General idea of interactions
//! - CauseInflammation up if pathogen present
//! - CauseInflammation up if CauseInflammation adjacent
//! - CauseInflammation up if unprocessed cell waste present
//! - web protein up if pathogen present AND CauseInflammation present
//! - stinging protein up if pathogen present AND CauseInflammation up
//! - `CauseInflammation` up if pathogen present
//! - `CauseInflammation` up if `CauseInflammation` adjacent
//! - `CauseInflammation` up if unprocessed cell waste present
//! - web protein up if pathogen present AND `CauseInflammation` present
//! - stinging protein up if pathogen present AND `CauseInflammation` up
//! - inhibitor protein up if triggered? AND no pathogen present
//! - inhibitor protein up if processed cell waste present
//! - CauseInflammation down if inhibitor protein up
//! - `CauseInflammation` down if inhibitor protein up
use crate::game;
use crate::world_gen::TileType;
Expand All @@ -38,17 38,17 @@ const MIN_CONCENTRATION: f32 = 0.0;
const MAX_CONCENTRATION: f32 = 0.99;

#[derive(Debug, Serialize, Deserialize)]
pub struct ComplementProteins {
pub struct Proteins {
pub current_proteins: [f32; 4], // 4 <- number of complement system proteins
next_proteins: [f32; 4], // 4 <- number of complement system proteins
}

impl ComplementProteins {
pub fn new() -> Self {
impl Proteins {
pub const fn new() -> Self {
let current_proteins = [0.0, 0.0, 0.0, 0.0];
let next_proteins = [0.0, 0.0, 0.0, 0.0];

ComplementProteins {
Self {
current_proteins,
next_proteins,
}
Expand All @@ -64,11 64,9 @@ impl ComplementProteins {
neighbor_tiles
.flatten()
.filter(|obj| {
if let Some(t) = &obj.tile {
matches!(t.typ, TileType::Floor)
} else {
false
}
obj.tile
.as_ref()
.map_or(false, |t| matches!(t.typ, TileType::Floor))
})
.for_each(|obj| {
if let Some(t) = &obj.tile {
Expand All @@ -89,7 87,7 @@ impl ComplementProteins {

(0..accumulated_proteins.len()).for_each(|i| {
let delta = accumulated_proteins[i] - self.current_proteins[i];
let new_value = self.current_proteins[i] (delta * 0.5);
let new_value = delta.mul_add(0.5, self.current_proteins[i]);
self.next_proteins[i] =
f32::max(f32::min(new_value, MAX_CONCENTRATION), MIN_CONCENTRATION);
});
Expand Down Expand Up @@ -121,7 119,7 @@ impl ComplementProteins {
}
}

impl Default for ComplementProteins {
impl Default for Proteins {
fn default() -> Self {
Self::new()
}
Expand Down
2 changes: 1 addition & 1 deletion src/entity/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 54,7 @@ pub struct Player {

impl Player {
pub fn new() -> Self {
Player {
Self {
primary_action: Box::new(act::Pass),
secondary_action: Box::new(act::Pass),
quick1_action: Box::new(act::Pass),
Expand Down
Loading

0 comments on commit efe2b7f

Please sign in to comment.