diff --git a/ROADMAP.md b/ROADMAP.md index 56e9541..5b7e853 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -20,7 +20,7 @@ - [x] Терраформация, 0 - 100% - [x] Кристаллы (базовый ресурс) -- [ ] Кислород +- [x] Кислород - [ ] Минералы - [ ] Металлы diff --git a/src/app.cr b/src/app.cr index 702691d..aed5bda 100644 --- a/src/app.cr +++ b/src/app.cr @@ -131,8 +131,9 @@ class App end def render_resources(world) - printf "Resources:\n Crystals: %5d\n Terraformation: %5d\n", + printf "Resources:\n Crystals: %5d\n Oxygen: %5d\n Terraformation: %5d\n", world.resources[Game::Resource::Type::Crystals], + world.resources[Game::Resource::Type::Oxygen], world.resources[Game::Resource::Type::Terraformation] end diff --git a/src/game/building.cr b/src/game/building.cr index 66f9902..ff5a371 100644 --- a/src/game/building.cr +++ b/src/game/building.cr @@ -9,12 +9,13 @@ module Game end class Mining - def initialize(@ts : TimeSpan, @resource : Resource, @input : ResourceBag) + def initialize(@ts : TimeSpan, @resource : Resource, @input : ResourceBag, @deposit : Bool = true) end getter ts getter resource getter input + getter deposit end class Construction @@ -47,6 +48,7 @@ module Game StartPoint CrystalMiner CrystalRestorer + OxygenCollector Terraformer end diff --git a/src/game/building_factory.cr b/src/game/building_factory.cr index 5eeed31..b4fc0a2 100644 --- a/src/game/building_factory.cr +++ b/src/game/building_factory.cr @@ -45,6 +45,23 @@ module Game } ) + add( + Building.new Building::Type::OxygenCollector, **{ + shortcut: "oxygen", + construction: Construction.new( + ts: 60, + cost: ResourceBag.new({Resource::Type::Crystals => 200}), + requirements: [] of Game::Building::Type + ), + mining: Mining.new( + ts: 30, + resource: Resource.new(Resource::Type::Oxygen, 10), + input: ResourceBag.new({Resource::Type::Crystals => 5}), + deposit: false + ), + } + ) + add( Building.new Building::Type::Terraformer, **{ shortcut: "terr", @@ -59,6 +76,7 @@ module Game ts: 60, input: ResourceBag.new({ Resource::Type::Crystals => 50, + Resource::Type::Oxygen => 20, }), output: ResourceBag.new({ Resource::Type::Terraformation => 5, diff --git a/src/game/command.cr b/src/game/command.cr index fef0ec0..5084561 100644 --- a/src/game/command.cr +++ b/src/game/command.cr @@ -74,6 +74,15 @@ module Game if !world.resources.has(mining.input) return mining.ts end + need_deposit = mining.deposit + if need_deposit + calc_for_deposit world, mining + else + calc_for_non_deposit world, mining + end + end + + private def calc_for_deposit(world : World, mining : Mining) : TimeSpan resource = mining.resource deposit_tile = nearest_deposit(world, resource.type) stock_tile = nearest_stock(world) @@ -81,8 +90,18 @@ module Game mined_amount = deposit_tile.dep.dec(resource.amount) @holded = resource.type.to_res mined_amount mining.ts + - 2 * tile.point.distance(stock_tile.point) + - 2 * tile.point.distance(deposit_tile.point) + 2 * @point.distance(stock_tile.point) + + 2 * @point.distance(deposit_tile.point) + else + mining.ts + end + end + + private def calc_for_non_deposit(world : World, mining : Mining) : TimeSpan + stock_tile = nearest_stock(world) + if stock_tile + @holded = mining.resource + mining.ts + 2 * @point.distance(stock_tile.point) else mining.ts end diff --git a/src/game/resources.cr b/src/game/resources.cr index 67c1db1..89e190d 100644 --- a/src/game/resources.cr +++ b/src/game/resources.cr @@ -3,6 +3,7 @@ require "./types" struct Game::Resource enum Type Crystals + Oxygen Terraformation def to_res(amount : Capacity)