@@ -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 )
9951031end
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)
10801115end
10811116
10821117local 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 )
19712019end
19722020
0 commit comments