Fix wood growing
This commit is contained in:
parent
533f05c88f
commit
bd1e38e4c2
@ -11,7 +11,7 @@ class BuildWoodMillCommand < Command
|
||||
|
||||
def start(world : World) : Int32
|
||||
printf " << start build mill at [%d:%d]\n", @point.x, @point.y
|
||||
return BASE_TIME
|
||||
BASE_TIME
|
||||
end
|
||||
|
||||
def finish(world : World)
|
||||
@ -37,7 +37,7 @@ class GetWoodCommand < Command
|
||||
else
|
||||
printf " << no wood tile\n"
|
||||
@wood = 0
|
||||
return BASE_TIME
|
||||
BASE_TIME
|
||||
end
|
||||
end
|
||||
|
||||
@ -49,7 +49,7 @@ class GetWoodCommand < Command
|
||||
@point.x, @point.y,
|
||||
dist, @wood,
|
||||
wood_point.x, wood_point.y
|
||||
return BASE_TIME + 2 * dist
|
||||
BASE_TIME + 2 * dist
|
||||
end
|
||||
|
||||
def finish(world : World)
|
||||
@ -73,7 +73,7 @@ class BuildForesterHouseCommand < Command
|
||||
|
||||
def start(world : World) : Int32
|
||||
printf " >> start build forester house at [%d:%d]\n", @point.x, @point.y
|
||||
return BASE_TIME
|
||||
BASE_TIME
|
||||
end
|
||||
|
||||
def finish(world : World)
|
||||
@ -99,9 +99,9 @@ class GrowWoodCommand < Command
|
||||
if !@wood_tile.nil?
|
||||
calc_time(@wood_tile.as(Tile))
|
||||
else
|
||||
printf "no wood tile\n"
|
||||
printf " >> no wood tile\n"
|
||||
@wood = 0
|
||||
return BASE_TIME
|
||||
BASE_TIME
|
||||
end
|
||||
end
|
||||
|
||||
@ -112,12 +112,13 @@ class GrowWoodCommand < Command
|
||||
@point.x, @point.y,
|
||||
dist,
|
||||
wood_point.x, wood_point.y
|
||||
return BASE_TIME + 2 * dist
|
||||
BASE_TIME + 2 * dist
|
||||
end
|
||||
|
||||
def finish(world : World)
|
||||
printf " >> finish grow wood at [%d,%d]\n", @point.x, @point.y
|
||||
if !@wood_tile.nil?
|
||||
printf " >> finish grow wood for %d\n", BASE_WOOD
|
||||
@wood_tile.as(Tile).charge(BASE_WOOD)
|
||||
end
|
||||
world.push(GrowWoodCommand.new(@point))
|
||||
@ -125,7 +126,7 @@ class GrowWoodCommand < Command
|
||||
|
||||
private def nearest_wood(world : World)
|
||||
world.map.nearest_tile @point do |tile|
|
||||
tile.letter == 'f' && tile.cur < tile.cur
|
||||
tile.letter == 'f' && tile.cur < tile.cap
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -37,15 +37,15 @@ abstract class Tile
|
||||
if value >= @cur
|
||||
wd = @cur
|
||||
@cur = 0
|
||||
return wd
|
||||
wd
|
||||
else
|
||||
@cur -= value
|
||||
return value
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def charge(value)
|
||||
if value + @cur > @cap
|
||||
if (value + @cur) > @cap
|
||||
@cur = @cap
|
||||
else
|
||||
@cur += value
|
||||
|
@ -60,7 +60,11 @@ end
|
||||
|
||||
w = World.new
|
||||
w.map.print
|
||||
w.push(BuildWoodMillCommand.new(Point.new(0, 0)))
|
||||
w.push(BuildForesterHouseCommand.new(Point.new(0, 0)))
|
||||
w.run(60)
|
||||
w.push(BuildWoodMillCommand.new(Point.new(2, 1)))
|
||||
w.push(BuildWoodMillCommand.new(Point.new(2, 3)))
|
||||
w.push(BuildForesterHouseCommand.new(Point.new(2, 0)))
|
||||
w.push(BuildForesterHouseCommand.new(Point.new(1, 2)))
|
||||
w.push(BuildForesterHouseCommand.new(Point.new(3, 2)))
|
||||
w.run(120)
|
||||
w.map.print
|
||||
printf "Wood: %d\n", w.resources.wood
|
||||
|
Loading…
Reference in New Issue
Block a user