summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-07-21 13:34:23 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-07-21 13:34:23 +0200
commit76c92c5555e7ee4b9654958b02d1b262a37e765d (patch)
tree610a6905c61bf1aae6198b4c3869f62cdbbe1d73 /src/engine
parenta1f2934e82312761b6eb2cc2cb427895868f5f19 (diff)
Removed need to load settings for the bitwise game engine
It's all constants now.
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bitwise_engine.rs30
-rw-r--r--src/engine/constants.rs8
2 files changed, 29 insertions, 9 deletions
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;