From 76c92c5555e7ee4b9654958b02d1b262a37e765d Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 21 Jul 2018 13:34:23 +0200 Subject: Removed need to load settings for the bitwise game engine It's all constants now. --- src/engine/bitwise_engine.rs | 30 +++++++++++++++++++++--------- src/engine/constants.rs | 8 ++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src/engine') diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs index add7d31..c7cadf1 100644 --- a/src/engine/bitwise_engine.rs +++ b/src/engine/bitwise_engine.rs @@ -48,9 +48,9 @@ pub struct TeslaCooldown { impl GameState for BitwiseGameState { - fn simulate(&mut self, settings: &GameSettings, player_command: Command, opponent_command: Command) -> GameStatus { - BitwiseGameState::perform_command(settings, &mut self.player, &mut self.player_buildings, player_command); - BitwiseGameState::perform_command(settings, &mut self.opponent, &mut self.opponent_buildings, opponent_command); + fn simulate(&mut self, _settings: &GameSettings, player_command: Command, opponent_command: Command) -> GameStatus { + BitwiseGameState::perform_command(&mut self.player, &mut self.player_buildings, player_command); + BitwiseGameState::perform_command(&mut self.opponent, &mut self.opponent_buildings, opponent_command); BitwiseGameState::update_construction(&mut self.player_buildings); BitwiseGameState::update_construction(&mut self.opponent_buildings); @@ -209,25 +209,37 @@ impl BitwiseGameState { res } - fn perform_command(settings: &GameSettings, player: &mut Player, player_buildings: &mut PlayerBuildings, command: Command) { + fn perform_command(player: &mut Player, player_buildings: &mut PlayerBuildings, command: Command) { match command { Command::Nothing => {}, Command::Build(p, b) => { - let blueprint = settings.building_settings(b); let bitfield = p.to_either_bitfield(); + let price = match b { + BuildingType::Attack => MISSILE_PRICE, + BuildingType::Defence => DEFENCE_PRICE, + BuildingType::Energy => ENERGY_PRICE, + BuildingType::Tesla => TESLA_PRICE, + }; + let construction_time = match b { + BuildingType::Attack => MISSILE_CONSTRUCTION_TIME, + BuildingType::Defence => DEFENCE_CONSTRUCTION_TIME, + BuildingType::Energy => ENERGY_CONSTRUCTION_TIME, + BuildingType::Tesla => TESLA_CONSTRUCTION_TIME, + }; + // This is used internally. I should not be making // invalid moves! debug_assert!(player_buildings.buildings[0] & bitfield == 0); - debug_assert!(p.x < settings.size.x && p.y < settings.size.y); - debug_assert!(player.energy >= blueprint.price); + debug_assert!(p.x < FULL_MAP_WIDTH && p.y < MAP_HEIGHT); + debug_assert!(player.energy >= price); debug_assert!(b != BuildingType::Tesla || player_buildings.count_teslas() < TESLA_MAX); - player.energy -= blueprint.price; + player.energy -= price; player_buildings.unconstructed.push(UnconstructedBuilding { pos: p, - construction_time_left: blueprint.construction_time, + construction_time_left: construction_time, building_type: b }); player_buildings.occupied |= bitfield; diff --git a/src/engine/constants.rs b/src/engine/constants.rs index e321a81..9805f72 100644 --- a/src/engine/constants.rs +++ b/src/engine/constants.rs @@ -7,15 +7,23 @@ pub const MISSILE_COOLDOWN_STATES: usize = MISSILE_COOLDOWN+1; pub const MISSILE_SPEED: usize = 2; pub const MISSILE_MAX_SINGLE_CELL: usize = SINGLE_MAP_WIDTH as usize / MISSILE_SPEED; pub const MISSILE_DAMAGE: u8 = 5; +pub const MISSILE_PRICE: u16 = 30; +pub const MISSILE_CONSTRUCTION_TIME: u8 = 1; pub const DEFENCE_HEALTH: usize = 4; // '20' health is 4 hits +pub const DEFENCE_PRICE: u16 = 30; +pub const DEFENCE_CONSTRUCTION_TIME: u8 = 3; pub const TESLA_MAX: usize = 2; pub const TESLA_COOLDOWN: u8 = 10; pub const TESLA_FIRING_ENERGY: u16 = 100; pub const TESLA_DAMAGE: u8 = 20; +pub const TESLA_PRICE: u16 = 300; +pub const TESLA_CONSTRUCTION_TIME: u8 = 10; pub const ENERGY_GENERATED_BASE: u16 = 5; pub const ENERGY_GENERATED_TOWER: u16 = 3; +pub const ENERGY_PRICE: u16 = 20; +pub const ENERGY_CONSTRUCTION_TIME: u8 = 1; pub const DECONSTRUCT_ENERGY: u16 = 5; -- cgit v1.2.3