diff --git a/src/expansion.cr b/src/expansion.cr index 11a997a..7874078 100644 --- a/src/expansion.cr +++ b/src/expansion.cr @@ -7,7 +7,7 @@ world = Game::World.new(ts) router = CLI::CommandRouter.new -router.add "harv {x} {y}", "Build harvester at x,y" do |p| +router.add "harv {x} {y}", "Build harvester at x,y (+80cr/10s)" do |p| x = p["x"].to_i32 y = p["y"].to_i32 point = Game::Point.new(x, y) @@ -15,14 +15,14 @@ router.add "harv {x} {y}", "Build harvester at x,y" do |p| printf "Build harvester at %d %d\n", x, y end -router.add "rest {x} {y}", "Build restorer at x,y (100 cr)" do |p| +router.add "rest {x} {y}", "Build restorer at x,y (100 cr, +30cr/15s)" do |p| x = p["x"].to_i32 y = p["y"].to_i32 point = Game::Point.new(x, y) world.push(Game::BuildCrystalRestorerCommand.new(point)) end -router.add "terr {x} {y}", "Build terraformator at x,y (300 cr)" do |p| +router.add "terr {x} {y}", "Build terraformator at x,y (300 cr, +5terr/-50cr/60s)" do |p| x = p["x"].to_i32 y = p["y"].to_i32 point = Game::Point.new(x, y) diff --git a/src/game/command.cr b/src/game/command.cr index e72631b..2ed6327 100644 --- a/src/game/command.cr +++ b/src/game/command.cr @@ -170,13 +170,22 @@ module Game class TerraformCommand < Command PRODUCTION_TIME = 60 + REST_TIME = 20 PRODUCTION_VALUE = 5 + CRYSTAL_REQUIRED = 50 def initialize(@point : Point) + @can_terr = false end def start(world : World) : Int32 - PRODUCTION_TIME + if world.resources.has(ResourceType::Crystal, CRYSTAL_REQUIRED) + world.resources.dec(ResourceType::Crystal, CRYSTAL_REQUIRED) + @can_terr = true + PRODUCTION_TIME + else + REST_TIME + end end def desc : String @@ -184,7 +193,9 @@ module Game end def finish(world : World) - world.resources.inc(ResourceType::Terraformation, PRODUCTION_VALUE) + if @can_terr + world.resources.inc(ResourceType::Terraformation, PRODUCTION_VALUE) + end world.push(TerraformCommand.new(@point)) end end diff --git a/src/game/resources.cr b/src/game/resources.cr index e1bcd08..1e1bcc5 100644 --- a/src/game/resources.cr +++ b/src/game/resources.cr @@ -17,6 +17,10 @@ class Game::Resources @values[t] end + def has(t : ResourceType, value : Int32) : Bool + @values[t] >= value + end + def inc(t : ResourceType, value : Int32) new_value = @values[t] + value if new_value < 0