diff --git a/Makefile b/Makefile index 36c7a4e..798f1a3 100644 --- a/Makefile +++ b/Makefile @@ -24,5 +24,5 @@ run: format .PHONY: spec spec: format - ./crystal spec --no-debug --warnings all --error-on-warnings --error-trace + ./crystal spec --warnings all --error-on-warnings --error-trace diff --git a/src/game/command.cr b/src/game/command.cr index f8e9cf8..f8dbfc6 100644 --- a/src/game/command.cr +++ b/src/game/command.cr @@ -30,6 +30,9 @@ module Game if @building.mining world.push(MineCommand.new(@point)) end + if @building.restoration + world.push(RestoreCommand.new(@point)) + end end end @@ -51,10 +54,14 @@ module Game tile = world.map.get(@point).as(BuildingTile) building = tile.building mining = building.mining.as(Mining) + if !world.resources.has(mining.input) + return mining.ts + end resource = mining.resource deposit_tile = nearest_deposit(world, resource.type) if deposit_tile - @holded = Resource.new resource.type, deposit_tile.dep.dec(resource.amount) + mined_amount = deposit_tile.dep.dec(resource.amount) + @holded = resource.type.to_res mined_amount end mining.ts end diff --git a/src/game/resources.cr b/src/game/resources.cr index a2163e7..3b5cfac 100644 --- a/src/game/resources.cr +++ b/src/game/resources.cr @@ -4,6 +4,10 @@ struct Game::Resource enum Type Crystals Terraformation + + def to_res(amount : Capacity) + Resource.new self, amount + end end def initialize(@type : Type, @amount : Capacity) diff --git a/src/game/world.cr b/src/game/world.cr index e441b9d..f4e43a7 100644 --- a/src/game/world.cr +++ b/src/game/world.cr @@ -15,10 +15,11 @@ class Game::World getter queue getter score - def push(command : Command) + def push(command : Command) : TimePoint dur = command.start(self) done_at = @ts + dur.to_i64 @queue.push(done_at, command) + done_at end def run(ts : TimePoint)