Change mine command with storehouse calc
This commit is contained in:
parent
d15aeaedc4
commit
e8f7453a8f
@ -13,7 +13,7 @@ module Game::TestCommand
|
|||||||
Point.new(0, 0),
|
Point.new(0, 0),
|
||||||
Building.new(
|
Building.new(
|
||||||
Building::Type::StartPoint,
|
Building::Type::StartPoint,
|
||||||
storage: 200
|
storage: 200, roles: [Building::Role::Storehouse]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
map.set DepositTile.new(
|
map.set DepositTile.new(
|
||||||
@ -79,8 +79,10 @@ module Game::TestCommand
|
|||||||
it "should complete mining command" do
|
it "should complete mining command" do
|
||||||
world = World.new create_map_with_resource
|
world = World.new create_map_with_resource
|
||||||
command = MineCommand.new Point.new(0, 1), once: true
|
command = MineCommand.new Point.new(0, 1), once: true
|
||||||
world.push command
|
time_point = (20 + 1 * 2 + 1 * 2).to_i64
|
||||||
world.run 20
|
done_at = world.push command
|
||||||
|
done_at.should eq time_point
|
||||||
|
world.run time_point
|
||||||
# Check world resources
|
# Check world resources
|
||||||
world.resources[Resource::Type::Crystals].should eq 40
|
world.resources[Resource::Type::Crystals].should eq 40
|
||||||
# Check tile deposit
|
# Check tile deposit
|
||||||
|
@ -63,7 +63,7 @@ module Game
|
|||||||
storage : Capacity | Nil = nil
|
storage : Capacity | Nil = nil
|
||||||
)
|
)
|
||||||
@name = name != "" ? name : @type.to_s
|
@name = name != "" ? name : @type.to_s
|
||||||
@roles = roles.nil? ? Array(Role).new : roles
|
@roles = roles.nil? ? Array(Role).new : roles.as(Array(Role))
|
||||||
@construction = construction.nil? ? Construction.immediatly : construction.as(Construction)
|
@construction = construction.nil? ? Construction.immediatly : construction.as(Construction)
|
||||||
@production = production
|
@production = production
|
||||||
@mining = mining
|
@mining = mining
|
||||||
@ -79,5 +79,9 @@ module Game
|
|||||||
getter mining
|
getter mining
|
||||||
getter restoration
|
getter restoration
|
||||||
getter storage
|
getter storage
|
||||||
|
|
||||||
|
def has_role(role : Role) : Bool
|
||||||
|
@roles.includes? role
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,12 +59,15 @@ module Game
|
|||||||
end
|
end
|
||||||
resource = mining.resource
|
resource = mining.resource
|
||||||
deposit_tile = nearest_deposit(world, resource.type)
|
deposit_tile = nearest_deposit(world, resource.type)
|
||||||
if deposit_tile
|
stock_tile = nearest_stock(world)
|
||||||
|
if deposit_tile && stock_tile
|
||||||
mined_amount = deposit_tile.dep.dec(resource.amount)
|
mined_amount = deposit_tile.dep.dec(resource.amount)
|
||||||
@holded = resource.type.to_res mined_amount
|
@holded = resource.type.to_res mined_amount
|
||||||
end
|
mining.ts + 2 * tile.point.distance(stock_tile.point) + 2 * tile.point.distance(deposit_tile.point)
|
||||||
|
else
|
||||||
mining.ts
|
mining.ts
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def finish(world : World)
|
def finish(world : World)
|
||||||
if @holded
|
if @holded
|
||||||
@ -82,6 +85,13 @@ module Game
|
|||||||
end
|
end
|
||||||
tile.as?(DepositTile)
|
tile.as?(DepositTile)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private def nearest_stock(world : World) : BuildingTile?
|
||||||
|
tile = world.map.nearest_tile @point do |tile|
|
||||||
|
tile.is_a?(BuildingTile) && tile.building.has_role Building::Role::Storehouse
|
||||||
|
end
|
||||||
|
tile.as?(BuildingTile)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RestoreCommand < Command
|
class RestoreCommand < Command
|
||||||
|
Loading…
Reference in New Issue
Block a user