Add oxygen collector
This commit is contained in:
parent
9b057bdc9f
commit
7802836fe7
@ -20,7 +20,7 @@
|
||||
|
||||
- [x] Терраформация, 0 - 100%
|
||||
- [x] Кристаллы (базовый ресурс)
|
||||
- [ ] Кислород
|
||||
- [x] Кислород
|
||||
- [ ] Минералы
|
||||
- [ ] Металлы
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -3,6 +3,7 @@ require "./types"
|
||||
struct Game::Resource
|
||||
enum Type
|
||||
Crystals
|
||||
Oxygen
|
||||
Terraformation
|
||||
|
||||
def to_res(amount : Capacity)
|
||||
|
Loading…
Reference in New Issue
Block a user