Small fixes

This commit is contained in:
Anton Vakhrushev 2019-10-13 17:13:04 +03:00
parent 8f1ac6c74f
commit d15aeaedc4
4 changed files with 15 additions and 3 deletions

View File

@ -24,5 +24,5 @@ run: format
.PHONY: spec .PHONY: spec
spec: format spec: format
./crystal spec --no-debug --warnings all --error-on-warnings --error-trace ./crystal spec --warnings all --error-on-warnings --error-trace

View File

@ -30,6 +30,9 @@ module Game
if @building.mining if @building.mining
world.push(MineCommand.new(@point)) world.push(MineCommand.new(@point))
end end
if @building.restoration
world.push(RestoreCommand.new(@point))
end
end end
end end
@ -51,10 +54,14 @@ module Game
tile = world.map.get(@point).as(BuildingTile) tile = world.map.get(@point).as(BuildingTile)
building = tile.building building = tile.building
mining = building.mining.as(Mining) mining = building.mining.as(Mining)
if !world.resources.has(mining.input)
return mining.ts
end
resource = mining.resource resource = mining.resource
deposit_tile = nearest_deposit(world, resource.type) deposit_tile = nearest_deposit(world, resource.type)
if deposit_tile 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 end
mining.ts mining.ts
end end

View File

@ -4,6 +4,10 @@ struct Game::Resource
enum Type enum Type
Crystals Crystals
Terraformation Terraformation
def to_res(amount : Capacity)
Resource.new self, amount
end
end end
def initialize(@type : Type, @amount : Capacity) def initialize(@type : Type, @amount : Capacity)

View File

@ -15,10 +15,11 @@ class Game::World
getter queue getter queue
getter score getter score
def push(command : Command) def push(command : Command) : TimePoint
dur = command.start(self) dur = command.start(self)
done_at = @ts + dur.to_i64 done_at = @ts + dur.to_i64
@queue.push(done_at, command) @queue.push(done_at, command)
done_at
end end
def run(ts : TimePoint) def run(ts : TimePoint)