Skip to content

Commit 9f0bba6

Browse files
authored
Update CrashSite outposts (#1552)
* Add outposts max level * Fix rendering targets * Cleanup style comments * Make outpost data clear
1 parent 672e0e3 commit 9f0bba6

File tree

3 files changed

+113
-34
lines changed

3 files changed

+113
-34
lines changed

features/retailer.lua

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ local function redraw_market_items(data)
331331
number = stack_count,
332332
tooltip = tooltip,
333333
})
334-
button.style = 'slot_button'
334+
button.style = 'slot_button_in_shallow_frame'
335335

336336
Gui.set_data(button, {index = i, data = data, stack_count = stack_count})
337337

@@ -353,21 +353,40 @@ local function redraw_market_items(data)
353353
end
354354

355355
local function do_coin_label(coin_count, label)
356-
label.caption = {'', coin_count, ' ', currency_item_name, ' ', {'common.available'}}
357-
label.style.font = 'default-bold'
356+
label.caption = { '', coin_count, ' ', currency_item_name, ' ', { 'common.available' } }
358357
end
359358

360359
local function draw_market_frame(player, group_name)
361360
local frame = player.gui.center.add({
362361
type = 'frame',
363362
name = market_frame_name,
364-
caption = Retailer.get_market_group_label(group_name),
365363
direction = 'vertical',
364+
style = 'non_draggable_frame'
366365
})
367366

368-
local scroll_pane = frame.add({type = 'scroll-pane'})
369-
local scroll_style = scroll_pane.style
370-
scroll_style.maximal_height = 600
367+
do -- Header
368+
local header = frame.add { type = 'flow', direction = 'horizontal' }
369+
Gui.set_style(header, { horizontal_spacing = 8, vertical_align = 'center', bottom_padding = 4 })
370+
371+
header.add { type = 'label', caption = Retailer.get_market_group_label(group_name), style = 'frame_title' }
372+
Gui.add_pusher(header)
373+
374+
local button = header.add {
375+
type = 'sprite-button',
376+
name = market_frame_close_button_name,
377+
sprite = 'utility/close',
378+
clicked_sprite = 'utility/close_black',
379+
style = 'close_button',
380+
tooltip = {'gui.close-instruction'}
381+
}
382+
Gui.set_data(button, frame)
383+
end
384+
385+
local inner = frame.add { type = 'frame', style = 'entity_frame', direction = 'vertical' }
386+
Gui.set_style(inner, { padding = 0 })
387+
388+
local scroll_pane = inner.add{ type = 'scroll-pane' }
389+
Gui.set_style(scroll_pane, { maximal_height = 600, padding = 8, top_padding = 12 })
371390

372391
local grid = scroll_pane.add({type = 'table', column_count = 10})
373392

@@ -381,34 +400,41 @@ local function draw_market_frame(player, group_name)
381400
player_index = player.index,
382401
}
383402

384-
local coin_label = frame.add({type = 'label'})
403+
local footer = inner.add { type = 'frame', style = 'subheader_frame' }.add { type = 'flow', direction = 'horizontal' }
404+
Gui.set_style(footer, { vertical_align = 'center', padding = 4, horizontal_spacing = 8 })
405+
406+
local coin_label = footer.add { type = 'label', style = 'bold_label' }
385407
do_coin_label(player_coins, coin_label)
386408
data.coin_label = coin_label
409+
Gui.add_pusher(footer)
387410

388411
redraw_market_items(data)
389412

390-
local bottom_grid = frame.add({type = 'table', column_count = 2})
413+
footer.add{ type = 'label', caption = { '', {'common.quantity'}, ': ' }, style = 'caption_label' }
391414

392-
bottom_grid.add({type = 'label', caption = {'', {'common.quantity'}, ': '}}).style.font = 'default-bold'
393-
394-
local count_text = bottom_grid.add({
395-
type = 'text-box',
415+
local count_text = footer.add {
416+
type = 'textfield',
396417
name = count_text_name,
397418
text = '1',
398-
})
419+
numeric = true,
420+
allow_decimal = false,
421+
allow_negative = false,
422+
}
423+
Gui.set_style(count_text, { width = 45 })
399424

400-
local count_slider = frame.add({
425+
local count_slider = footer.add {
401426
type = 'slider',
402427
name = count_slider_name,
403428
minimum_value = 1,
404429
maximum_value = 7,
405430
value = 1,
406-
})
407-
408-
frame.add({name = market_frame_close_button_name, type = 'button', caption = 'Close'})
431+
style = 'notched_slider',
432+
}
433+
Gui.set_style(count_slider, { width = 115 })
409434

410-
count_slider.style.width = 115
411-
count_text.style.width = 45
435+
Gui.add_pusher(footer)
436+
local padding = footer.add { type = 'empty-widget' }
437+
Gui.set_style(padding, { width = 100 })
412438

413439
data.slider = count_slider
414440
data.text = count_text

map_gen/maps/crash_site/outpost_builder.lua

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,38 @@ Global.register(
8989
end
9090
)
9191

92+
---@class MagicCrafter
93+
---@field base_rate number
94+
---@field entity LuaEntity
95+
---@field item string
96+
---@field last_tick number
97+
---@field rate number
98+
99+
---@class MagicFluidCrafter
100+
---@field base_rate number
101+
---@field entity LuaEntity
102+
---@field item string
103+
---@field last_tick number
104+
---@field rate number
105+
---@field fluidbox_index
106+
107+
---@class OutpostData
108+
---@field outpost_id number, unique identifier for the outpost
109+
---@field area BoundingBox, area covered by the outpost
110+
---@field artillery_area? BoundingBox, area covered by artillery
111+
---@field artillery_turrets? LuaEntity[], table of artillery turrets
112+
---@field base_outputs table<string, number>, outputs produced by the outpost for upgrades
113+
---@field last_fire_tick? number, last tick when artillery fired
114+
---@field level number, current level of the outpost
115+
---@field magic_crafters MagicCrafter[], table of magic crafters
116+
---@field magic_fluid_crafters? MagicFluidCrafter[], table of magic fluid crafters
117+
---@field market LuaEntity, reference to the market entity
118+
---@field maximum_level? number, maximum level
119+
---@field turret_count number, number of turrets attached to the outpost
120+
---@field upgrade_base_cost number, base cost for upgrading
121+
---@field upgrade_cost_base number, cost multiplier for upgrades
122+
---@field upgrade_rate number, rate at which the outpost upgrades
123+
92124
--[[ local function get_direction(part)
93125
local dir = bit32.band(part, direction_bit_mask)
94126
return bit32.rshift(dir, direction_bit_shift - 1)
@@ -683,15 +715,15 @@ local function to_shape(blocks, part_size, on_init)
683715
--magic_fluid_crafters = {},
684716
market = nil,
685717
turret_count = 0,
686-
top_left = {nil, nil},
687-
bottom_right = {nil, nil},
718+
area = nil,
688719
level = 1,
720+
maximum_level = nil,
689721
upgrade_rate = nil,
690722
upgrade_base_cost = nil,
691723
upgrade_cost_base = nil,
692724
artillery_area = nil,
693725
artillery_turrets = nil,
694-
last_fire_tick = nil
726+
last_fire_tick = nil,
695727
}
696728
end
697729

@@ -988,9 +1020,13 @@ local function update_market_upgrade_description(outpost_data)
9881020

9891021
prototype.description = tooltip_str
9901022
prototype.disabled = false
991-
9921023
prototype.mapview_description = mapview_str
9931024

1025+
if outpost_data.maximum_level and (outpost_data.level >= outpost_data.maximum_level) then
1026+
prototype.disabled = true
1027+
prototype.disabled_reason = 'Max level reached.'
1028+
end
1029+
9941030
Retailer.set_item(outpost_id, prototype)
9951031
end
9961032

@@ -1008,7 +1044,6 @@ local function do_outpost_upgrade(event)
10081044
local level = outpost_data.level + 1
10091045
outpost_data.level = level
10101046

1011-
10121047
local player_name = event.player.name
10131048
local outpost_name = Retailer.get_market_group_label(outpost_id)
10141049
local message = concat {player_name, ' has upgraded ', outpost_name, ' to level ', level}
@@ -1080,7 +1115,7 @@ local function find_nearest_player(position)
10801115
end
10811116

10821117
local function do_capture_outpost(outpost_data)
1083-
local area = {top_left = outpost_data.top_left, bottom_right = outpost_data.bottom_right}
1118+
local area = outpost_data.area
10841119
local walls = RS.get_surface().find_entities_filtered {area = area, force = 'enemy', name = 'stone-wall'}
10851120

10861121
for i = 1, #walls do
@@ -1643,8 +1678,13 @@ Public.wall_callback =
16431678

16441679
local outpost_id = data.outpost_id
16451680
local outpost_data = outposts[outpost_id]
1646-
local top_left = outpost_data.top_left
1647-
local bottom_right = outpost_data.bottom_right
1681+
local area = outpost_data.area
1682+
if not area then
1683+
area = { top_left = {}, bottom_right = {} }
1684+
outpost_data.area = area
1685+
end
1686+
local top_left = area.top_left
1687+
local bottom_right = area.bottom_right
16481688
local tx, ty = top_left.x, top_left.y
16491689
local bx, by = bottom_right.x, bottom_right.y
16501690

@@ -1736,6 +1776,12 @@ Public.market_set_items_callback =
17361776
outpost_data.upgrade_rate = callback_data.upgrade_rate
17371777
outpost_data.upgrade_base_cost = upgrade_base_cost
17381778
outpost_data.upgrade_cost_base = callback_data.upgrade_cost_base
1779+
outpost_data.maximum_level = callback_data.maximum_level_count
1780+
if callback_data.maximum_level_formula then
1781+
assert((outpost_data.maximum_level == nil), 'maximum_level has already been defined')
1782+
local formula = Token.get(callback_data.maximum_level_formula)
1783+
outpost_data.maximum_level = formula(callback_data)
1784+
end
17391785

17401786
Retailer.add_market(market_id, entity)
17411787
Retailer.set_market_group_label(market_id, callback_data.market_name)
@@ -1946,8 +1992,10 @@ local function market_selected(event)
19461992

19471993
local args = {
19481994
text = nil,
1949-
target = selected,
1950-
target_offset = nil,
1995+
target = {
1996+
entity = selected,
1997+
offset = nil,
1998+
},
19511999
alignment = 'center',
19522000
surface = selected.surface,
19532001
color = {1, 1, 1},
@@ -1958,15 +2006,15 @@ local function market_selected(event)
19582006
}
19592007

19602008
args.text = prototype.name_label
1961-
args.target_offset = {0, -6.5}
2009+
args.target.offset = {0, -6.5}
19622010
draw_text(args)
19632011

19642012
args.text = 'Price: ' .. prototype.price
1965-
args.target_offset = {0, -5}
2013+
args.target.offset = {0, -5}
19662014
draw_text(args)
19672015

19682016
args.text = prototype.mapview_description
1969-
args.target_offset = {0, -3.5}
2017+
args.target.offset = {0, -3.5}
19702018
draw_text(args)
19712019
end
19722020

map_gen/maps/crash_site/scenario.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,19 @@ local function init(config)
802802

803803
map = b.apply_entity(map, ore_grid)
804804

805+
local spawn_maximum_level_formula = Token.register(function()
806+
return game.is_multiplayer() and 6 or nil
807+
end)
808+
805809
local market = {
806810
callback = spawn_callback,
807811
data = {
808812
market_name = 'Spawn',
809813
upgrade_rate = 0.5,
810814
upgrade_base_cost = 500,
811815
upgrade_cost_base = 2,
816+
maximum_level_count = nil,
817+
maximum_level_formula = spawn_maximum_level_formula,
812818
{
813819
price = 0,
814820
stack_limit = 1,
@@ -862,7 +868,6 @@ local function init(config)
862868
name_label = {'command_description.crash_site_barrage_radius_name_label', 1},
863869
sprite = 'virtual-signal/signal-B',
864870
description = {'command_description.crash_site_barrage_radius', 1, 0, 25}
865-
866871
},
867872
{
868873
price = 1000,

0 commit comments

Comments
 (0)