Skip to content

Commit

Permalink
Merge pull request #299 from ComfyFactory/expanse_update
Browse files Browse the repository at this point in the history
Expanse update - locale, early uranium access, fixes
  • Loading branch information
hanakocz authored Aug 18, 2022
2 parents 1aa4329 + 412fb76 commit 18c0ce7
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 68 deletions.
11 changes: 10 additions & 1 deletion locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ map_info_text=This is a harsh world, the heat is unbearable and the sand is shar
[expanse]
map_info_main_caption=-- E x p a n s e --
map_info_sub_caption=
map_info_text=The blue chests are hungry.\nFeed them and they will reward you with more land.\n\nThe friendly infini tree will provide you with all the wood you ever wanted.\nThe everlasting rock with be happy to provide resources for you.\n\nIf you find yourself stuck, put a reroll token, the COIN, in the chest to get a new offer.\nUnlocking chests may drop additional tokens.\nBiters might invade your lands, we managed to mark the danger sites, but biters might choose some of them randomly.\nMining research now increases inventory size.
map_info_text=The blue chests are hungry.\nFeed them and they will reward you with more land.\n\nThe friendly infini tree will provide you with all the wood you ever wanted.\nThe everlasting rock with be happy to provide resources for you.\n\nIf you find yourself stuck, put a reroll token, the COIN, in the chest to get a new offer.\nUnlocking chests may drop additional tokens.\nBiters might invade your lands, we managed to mark the danger sites, but biters might choose some of them randomly.\nMining research now increases inventory size.\nTank with acid allows some uranium from the rock, if you have uranium research.
biters_invasion_warning=Warning! Biters are aproaching your positions and will attack in about __1__ seconds! We detected __2__ groups aproaching some of the marked positions!
tokens_dropped=__1__ has dropped their tokens! __2__
chest_reset=The hungry chest has renewed its offers! __1__
colored_text=[color=__1__,__2__,__3__]__4__[/color]
gps=[gps=__1__,__2__,__3__]
tile_unlock=__1__ has unlocked new grounds! __2__
stats_gui=Expanse hungry chest stats
stats_size=Total size unlocked: __1__
stats_attack=Next biter invasion: __1__ / __2__ possible positions, __3__ groups
stats_item_tooltip=__1__, value: __2__

[fish_defender]
map_info_main_caption=--Fish Defender--
Expand Down
85 changes: 54 additions & 31 deletions maps/expanse/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ local function remove_old_renders(container)
end
end

function Public.spawn_units(spawner)
local evolution = game.forces.enemy.evolution_factor
local position = spawner.position
for i = 1, 4 + math.floor(8 * evolution), 1 do
local biter_roll = BiterRaffle.roll('mixed', evolution)
local free_pos = spawner.surface.find_non_colliding_position(biter_roll, {x = position.x + math.random(-8,8), y = position.y + math.random(-8,8)}, 12, 0.05)
spawner.surface.create_entity({name = biter_roll, position = free_pos or position, force = 'enemy'})
end
end

function Public.get_item_tooltip(name)
return {'expanse.stats_item_tooltip', game.item_prototypes[name].localised_name, Price_raffle.get_item_worth(name)}
end

function Public.invasion_numbers()
local evo = game.forces.enemy.evolution_factor
return {candidates = 3 + math.floor(evo * 10), groups = 1 + math.floor(evo * 4)}
end

function Public.invasion_warn(event)
local seconds = (120 * 60 - event.delay) / 60
game.print({'expanse.biters_invasion_warning', seconds, event.size}, {r = 0.88, g = 0.22, b = 0.22})
Expand Down Expand Up @@ -211,7 +230,7 @@ function Public.invasion_trigger(event)
local biters = {}
for i = 1, 5 + math.floor(30 * evolution) + round * 5, 1 do
local biter_roll = BiterRaffle.roll('mixed', evolution)
local free_pos = surface.find_non_colliding_position(biter_roll, position, 12, 0.05)
local free_pos = surface.find_non_colliding_position(biter_roll, {x = position.x + math.random(-8,8), y = position.y + math.random(-8,8)}, 12, 0.05)
biters[#biters + 1] = surface.create_entity({name = biter_roll, position = free_pos or position, force = 'enemy'})
end
local group = surface.create_unit_group{position = position, force = 'enemy'}
Expand All @@ -222,7 +241,7 @@ function Public.invasion_trigger(event)
group.start_moving()
local worm_roll = BiterRaffle.roll('worm', evolution)
for i = 1, 3 + math.floor(7 * evolution), 1 do
local worm_pos = surface.find_non_colliding_position(worm_roll, {x = position.x + math.random(-6,6), y = position.y + math.random(-6,6)}, 12, 0.1)
local worm_pos = surface.find_non_colliding_position(worm_roll, {x = position.x + math.random(-12,12), y = position.y + math.random(-12,12)}, 12, 0.1)
if worm_pos then
surface.create_entity({name = worm_roll, position = worm_pos, force = 'enemy'})
end
Expand All @@ -247,15 +266,14 @@ local function schedule_biters(expanse, surface, position, delay, round)
table.insert(expanse.schedule, {tick = game.tick + delay + 120 * 60, event = 'invasion_trigger', parameters = {surface = surface, position = position, round = round}})
end

local function plan_invasion(expanse, evolution)
local function plan_invasion(expanse, invasion_numbers)
local candidates = expanse.invasion_candidates
table.shuffle_table(candidates)
local size = 1 + math.floor(evolution * 4)
schedule_warning(expanse, size, 0)
schedule_warning(expanse, size, 60 * 60)
schedule_warning(expanse, size, 90 * 60)
local rounds = 4 + math.random(1, 4)
for i = 1, size, 1 do
schedule_warning(expanse, invasion_numbers.groups, 0)
schedule_warning(expanse, invasion_numbers.groups, 60 * 60)
schedule_warning(expanse, invasion_numbers.groups, 90 * 60)
local rounds = 4 + math.random(1, 8)
for i = 1, invasion_numbers.groups, 1 do
local surface = candidates[i].surface
local position = candidates[i].position
schedule_detonation(expanse, surface, position)
Expand All @@ -264,16 +282,16 @@ local function plan_invasion(expanse, evolution)
end
rendering.set_time_to_live(candidates[i].render, 122 * 60 + rounds * 300)
end
for j = size + 1, #candidates, 1 do
for j = invasion_numbers.groups + 1, #candidates, 1 do
rendering.set_time_to_live(candidates[j].render, 122 * 60)
end
expanse.invasion_candidates = {}
end

function Public.check_invasion(expanse)
local evolution = game.forces.enemy.evolution_factor
if #expanse.invasion_candidates >= 3 + math.floor(evolution * 10) then
plan_invasion(expanse, evolution)
local invasion_numbers = Public.invasion_numbers()
if #expanse.invasion_candidates >= invasion_numbers.candidates then
plan_invasion(expanse, invasion_numbers)
end
end

Expand Down Expand Up @@ -305,10 +323,6 @@ function Public.expand(expanse, left_top)
}
)

for _, e in pairs(source_surface.find_entities(area)) do
e.destroy()
end

local positions = {
{x = left_top.x + math.random(1, square_size - 2), y = left_top.y},
{x = left_top.x, y = left_top.y + math.random(1, square_size - 2)},
Expand All @@ -328,13 +342,12 @@ function Public.expand(expanse, left_top)
local a = math.floor(expanse.square_size * 0.5)
for x = 1, 3, 1 do
for y = 1, 3, 1 do
surface.set_tiles({{name = 'water', position = {a + x + 2, a + y - 2}}}, true)
surface.set_tiles({{name = 'water', position = {a + x + 2, a + y + 2}}}, true)
end
end
surface.create_entity({name = 'crude-oil', position = {a - 5, a}, amount = 1500000})

Task.set_timeout_in_ticks(30, delay_infini_tree_token, {surface = surface, position = {a, a - 3}})
surface.create_entity({name = 'rock-big', position = {a, a}})
surface.create_entity({name = 'crude-oil', position = {a - 4, a - 4}, amount = 1500000})
Task.set_timeout_in_ticks(30, delay_infini_tree_token, {surface = surface, position = {a - 4, a + 4}})
surface.create_entity({name = 'rock-big', position = {a + 4, a - 4}})
surface.spill_item_stack({a, a + 2}, {name = 'coin', count = 1}, false, nil, false)
surface.spill_item_stack({a + 0.5, a + 2.5}, {name = 'coin', count = 1}, false, nil, false)
surface.spill_item_stack({a - 0.5, a + 2.5}, {name = 'coin', count = 1}, false, nil, false)
Expand All @@ -349,18 +362,16 @@ function Public.expand(expanse, left_top)
end
end

local function init_container(expanse, entity)
local function init_container(expanse, entity, budget)
local left_top = get_left_top(expanse, entity.position)
if not left_top then
return
end

local cell_value = get_cell_value(expanse, left_top)

local cell_value = budget or get_cell_value(expanse, left_top)
local item_stacks = {}
local roll_count = 2
local roll_count = 3
for _ = 1, roll_count, 1 do
for _, stack in pairs(Price_raffle.roll(math.floor(cell_value / roll_count), 2)) do
for _, stack in pairs(Price_raffle.roll(math.floor(cell_value / roll_count), 3, nil, cell_value / (roll_count * 6))) do
if not item_stacks[stack.name] then
item_stacks[stack.name] = stack.count
else
Expand All @@ -370,7 +381,7 @@ local function init_container(expanse, entity)
end

local price = {}
local offset = -2
local offset = -3
for k, v in pairs(item_stacks) do
table.insert(price, {name = k, count = v, render = create_costs_render(entity, k, offset)})
offset = offset + 1
Expand All @@ -380,6 +391,14 @@ local function init_container(expanse, entity)
containers[entity.unit_number] = {entity = entity, left_top = left_top, price = price}
end

local function get_remaining_budget(container)
local budget = 0
for _, item_stack in pairs(container.price) do
budget = budget + (item_stack.count * Price_raffle.get_item_worth(item_stack.name))
end
return budget
end

function Public.set_container(expanse, entity)
if entity.name ~= 'logistic-chest-requester' then
return
Expand All @@ -404,11 +423,15 @@ function Public.set_container(expanse, entity)
expanse.cost_stats['coin'] = (expanse.cost_stats['coin'] or 0) + count_removed
script.raise_event(expanse.events.gui_update, {item = 'coin'})
remove_old_renders(container)
init_container(expanse, entity)
init_container(expanse, entity, get_remaining_budget(container))
container = expanse.containers[entity.unit_number]
game.print("The hungry chest has renewed it's offer! [gps=" .. math.floor(entity.position.x) .. ',' .. math.floor(entity.position.y) .. ',expanse]')
game.print({'expanse.chest_reset', {'expanse.gps', math.floor(entity.position.x), math.floor(entity.position.y), 'expanse'}})
end
end
if contents['infinity-chest'] then
remove_old_renders(container)
container.price = {}
end
end

for key, item_stack in pairs(container.price) do
Expand Down
Loading

0 comments on commit 18c0ce7

Please sign in to comment.