diff --git a/.luacheckrc b/.luacheckrc index b8242326..4c964557 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -960,6 +960,13 @@ stds.factorio_defines = { 'waiting_for_space_in_destination', } }, + render_mode = { + fields = { + 'game', + 'chart', + 'chart_zoomed_in' + } + }, events = { fields = { 'on_ai_command_completed', diff --git a/features/retailer.lua b/features/retailer.lua index 7287ef3b..2f0214b9 100644 --- a/features/retailer.lua +++ b/features/retailer.lua @@ -586,6 +586,12 @@ function Retailer.add_market(group_name, market_entity) set_market_group_name(market_entity.position, group_name) end +---Returns the group name of the market, nil if not registered. +---@param market_entity LuaEntity +function Retailer.get_market_group_name(market_entity) + return get_market_group_name(market_entity.position) +end + ---Sets an item for all the group_name markets. ---@param group_name string ---@param prototype table with item name and price diff --git a/map_gen/maps/crash_site.lua b/map_gen/maps/crash_site.lua index 25bb985e..8c37caae 100644 --- a/map_gen/maps/crash_site.lua +++ b/map_gen/maps/crash_site.lua @@ -556,7 +556,8 @@ local function init() local worms = { 'small-worm-turret', 'medium-worm-turret', - 'big-worm-turret' + 'big-worm-turret', + 'behemoth-worm-turret' } local max_spawner_chance = 1 / 256 @@ -599,14 +600,17 @@ local function init() if d < 512 then max_lvl = 2 min_lvl = 1 - else + elseif d < 768 then max_lvl = 3 min_lvl = 2 + else + max_lvl = 4 + min_lvl = 2 end local lvl = math.random() ^ (384 / d) * max_lvl lvl = math.ceil(lvl) --local lvl = math.floor(d / 256) + 1 - lvl = math.clamp(lvl, min_lvl, 3) + lvl = math.clamp(lvl, min_lvl, 4) return {name = worms[lvl]} end end diff --git a/map_gen/maps/crash_site/crash_site_toast.lua b/map_gen/maps/crash_site/crash_site_toast.lua index 746ee09f..2ee7319b 100644 --- a/map_gen/maps/crash_site/crash_site_toast.lua +++ b/map_gen/maps/crash_site/crash_site_toast.lua @@ -4,12 +4,9 @@ local Color = require 'resources.color_presets' local Public = {} -local market_signal = {type = 'virtual', name = 'signal-O'} - local find_outpost_name = Gui.uid_name() -function Public.do_outpost_toast(market, outpost_name, message) - local data = {market = market, outpost_name = outpost_name} +function Public.do_outpost_toast(market, message) Toast.toast_all_players_template( 15, function(container) @@ -21,7 +18,7 @@ function Public.do_outpost_toast(market, outpost_name, message) style = 'slot_button' } - Gui.set_data(sprite, data) + Gui.set_data(sprite, market.position) local label = container.add { @@ -41,11 +38,9 @@ Gui.on_click( function(event) local player = event.player local element = event.element - local data = Gui.get_data(element) - local market = data.market - local outpost_name = data.outpost_name + local position = Gui.get_data(element) - player.add_custom_alert(market, market_signal, outpost_name, true) + player.zoom_to_world(position, 0.5) end ) diff --git a/map_gen/maps/crash_site/entity_died_events.lua b/map_gen/maps/crash_site/entity_died_events.lua index 027b2695..61844434 100644 --- a/map_gen/maps/crash_site/entity_died_events.lua +++ b/map_gen/maps/crash_site/entity_died_events.lua @@ -31,7 +31,8 @@ local entity_drop_amount = { ['spitter-spawner'] = {low = 8, high = 24}, ['small-worm-turret'] = {low = 3, high = 10}, ['medium-worm-turret'] = {low = 8, high = 24}, - ['big-worm-turret'] = {low = 15, high = 30} + ['big-worm-turret'] = {low = 15, high = 30}, + ['behemoth-worm-turret'] = {low = 25, high = 45} } local spill_items = @@ -51,6 +52,7 @@ local entity_spawn_map = { ['behemoth-spitter'] = {name = 'big-worm-turret', count = 1, chance = 0.2}, ['biter-spawner'] = {type = 'biter', count = 5, chance = 1}, ['spitter-spawner'] = {type = 'spitter', count = 5, chance = 1}, + ['behemoth-worm-turret'] = {name = 'behemoth-spitter', count = 2, chance = 1}, ['stone-furnace'] = {type = 'cause', count = 2, chance = 1}, ['steel-furnace'] = {type = 'cause', count = 2, chance = 1}, ['electric-furnace'] = {type = 'cause', count = 4, chance = 1}, @@ -97,7 +99,8 @@ local unit_levels = { local worms = { ['small-worm-turret'] = true, ['medium-worm-turret'] = true, - ['big-worm-turret'] = true + ['big-worm-turret'] = true, + ['behemoth-worm-turret'] = true } local allowed_cause_source = { diff --git a/map_gen/maps/crash_site/outpost_builder.lua b/map_gen/maps/crash_site/outpost_builder.lua index 2b58c06b..eb013452 100644 --- a/map_gen/maps/crash_site/outpost_builder.lua +++ b/map_gen/maps/crash_site/outpost_builder.lua @@ -17,6 +17,8 @@ local concat = table.concat local floor = math.floor local format = string.format local tostring = tostring +local draw_text = rendering.draw_text +local render_mode_game = defines.render_mode.game local b = require 'map_gen.shared.builders' @@ -55,6 +57,7 @@ local turret_to_outpost = {} local magic_crafters = {index = 1} local magic_fluid_crafters = {index = 1} local outposts = {} +local artillery_outposts = {index = 1} local outpost_count = 0 Global.register( @@ -64,7 +67,8 @@ Global.register( turret_to_outpost = turret_to_outpost, magic_crafters = magic_crafters, magic_fluid_crafters = magic_fluid_crafters, - outposts = outposts + outposts = outposts, + artillery_outposts = artillery_outposts }, function(tbl) refill_turrets = tbl.refil_turrets @@ -73,6 +77,7 @@ Global.register( magic_crafters = tbl.magic_crafters magic_fluid_crafters = tbl.magic_fluid_crafters outposts = tbl.outposts + artillery_outposts = tbl.artillery_outposts end ) @@ -675,7 +680,10 @@ local function to_shape(blocks, part_size, on_init) level = 1, upgrade_rate = nil, upgrade_base_cost = nil, - upgrade_cost_base = nil + upgrade_cost_base = nil, + artillery_area = nil, + artillery_turrets = nil, + last_fire_tick = nil } end @@ -928,7 +936,9 @@ local function update_market_upgrade_description(outpost_data) prototype.price = upgrade_base_cost * #outpost_magic_crafters * upgrade_cost_base ^ (level - 1) prototype.name_label = 'Upgrade Outpost to level ' .. tostring(level + 1) - local str = {''} + local tooltip_str = {''} + local mapview_str = {''} + local count = 2 for k, v in pairs(base_outputs) do local base_rate = v * 60 local upgrade_per_level = base_rate * upgrade_rate @@ -937,24 +947,38 @@ local function update_market_upgrade_description(outpost_data) local name = game.item_prototypes[k] if name then - str[#str + 1] = name.localised_name + tooltip_str[count] = concat {'[item=', k, ']'} + mapview_str[count] = name.localised_name else name = game.fluid_prototypes[k] if name then - str[#str + 1] = name.localised_name + tooltip_str[count] = concat {'[fluid=', k, ']'} + mapview_str[count] = name.localised_name else - str[#str + 1] = k + tooltip_str[count] = k + mapview_str[count] = k end end + count = count + 1 - str[#str + 1] = concat {': ', format('%.2f', current_rate), ' -> ', format('%.2f / sec', next_rate)} - str[#str + 1] = '\n' + local str = concat {': ', format('%.2f', current_rate), ' -> ', format('%.2f / sec', next_rate)} + + tooltip_str[count] = str + tooltip_str[count + 1] = '\n' + + mapview_str[count] = str + mapview_str[count + 1] = ', ' + + count = count + 2 end - str[#str] = nil + tooltip_str[count - 1] = nil + mapview_str[count - 1] = nil - prototype.description = str + prototype.description = tooltip_str prototype.disabled = false + prototype.mapview_description = mapview_str + Retailer.set_item(outpost_id, prototype) end @@ -975,7 +999,7 @@ local function do_outpost_upgrade(event) local outpost_name = Retailer.get_market_group_label(outpost_id) local message = concat {outpost_name, ' has been upgraded to level ', level} - CrashSiteToast.do_outpost_toast(outpost_data.market, outpost_name, message) + CrashSiteToast.do_outpost_toast(outpost_data.market, message) Server.to_discord_bold(concat {'*** ', message, ' ***'}) for i = 1, #outpost_magic_crafters do @@ -1051,7 +1075,7 @@ local function do_capture_outpost(outpost_data) end local message = 'Outpost captured: ' .. name - CrashSiteToast.do_outpost_toast(outpost_data.market, name, message) + CrashSiteToast.do_outpost_toast(outpost_data.market, message) Server.to_discord_bold(concat {'*** ', message, ' ***'}) activate_market_upgrade(outpost_data) @@ -1083,6 +1107,80 @@ local function do_refill_turrets() end end +local artillery_target_entities = { + 'player', + 'tank', + 'car', + 'locomotive', + 'cargo-wagon', + 'fluid-wagon', + 'artillery-wagon' +} +local function do_artillery_turrets_targets() + local index = artillery_outposts.index + + if index > #artillery_outposts then + artillery_outposts.index = 1 + return + end + + artillery_outposts.index = index + 1 + + local outpost = artillery_outposts[index] + + local now = game.tick + if now - outpost.last_fire_tick < 300 then + return + end + + local turrets = outpost.artillery_turrets + for i = #turrets, 1, -1 do + local turret = turrets[i] + if not turret.valid then + fast_remove(turrets, i) + end + end + + local count = #turrets + if count == 0 then + fast_remove(artillery_outposts, index) + return + end + + outpost.last_fire_tick = now + + local turret = turrets[1] + local area = outpost.artillery_area + local surface = turret.surface + + local entities = surface.find_entities_filtered {area = area, name = artillery_target_entities} + + if #entities == 0 then + return + end + + local postion = turret.position + local tx, ty = postion.x, postion.y + + for i = 1, count do + local entity = entities[math.random(#entities)] + if entity and entity.valid then + local pos = entity.position + local x, y = pos.x, pos.y + local dx, dy = tx - x, ty - y + local d = dx * dx + dy * dy + if d >= 1024 then -- 32 ^ 2 + surface.create_entity { + name = 'artillery-projectile', + position = postion, + target = entity, + speed = 1.5 + } + end + end + end +end + local function do_magic_crafters() local limit = #magic_crafters if limit == 0 then @@ -1170,6 +1268,7 @@ end local function tick() do_refill_turrets() + do_artillery_turrets_targets() do_magic_crafters() do_magic_fluid_crafters() end @@ -1203,6 +1302,34 @@ Public.refill_liquid_turret_callback = end ) +Public.refill_artillery_turret_callback = + Token.register( + function(turret, data) + local outpost_id = data.outpost_id + + refill_turrets[#refill_turrets + 1] = {turret = turret, data = data.callback_data} + turret_to_outpost[turret.unit_number] = outpost_id + + local outpost_data = outposts[outpost_id] + outpost_data.turret_count = outpost_data.turret_count + 1 + + local artillery_turrets = outpost_data.artillery_turrets + if not artillery_turrets then + artillery_turrets = {} + outpost_data.artillery_turrets = artillery_turrets + + local pos = turret.position + local x, y = pos.x, pos.y + outpost_data.artillery_area = {{x - 128, y - 128}, {x + 128, y + 128}} + outpost_data.last_fire_tick = 0 + + artillery_outposts[#artillery_outposts + 1] = outpost_data + end + + artillery_turrets[#artillery_turrets + 1] = turret + end +) + Public.power_source_callback = Token.register( function(turret, data) @@ -1641,6 +1768,55 @@ local function coin_mined(event) end end +local function market_selected(event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + + if player.render_mode == render_mode_game then + return + end + + local selected = player.selected + + if not selected or not selected.valid or selected.name ~= 'market' then + return + end + + local group = Retailer.get_market_group_name(selected) + local prototype = Retailer.get_items(group)['upgrade'] + + if prototype.disabled then + return + end + + local args = { + text = nil, + target = selected, + target_offset = nil, + alignment = 'center', + surface = selected.surface, + color = {1, 1, 1}, + players = {player}, + scale = 1.5, + scale_with_zoom = true, + time_to_live = 180 + } + + args.text = prototype.name_label + args.target_offset = {0, -6.5} + draw_text(args) + + args.text = 'Price: ' .. prototype.price + args.target_offset = {0, -5} + draw_text(args) + + args.text = prototype.mapview_description + args.target_offset = {0, -3.5} + draw_text(args) +end + Event.add(defines.events.on_tick, tick) Event.add(defines.events.on_entity_died, turret_died) @@ -1654,4 +1830,6 @@ Event.add(defines.events.on_player_mined_item, coin_mined) Event.add(Retailer.events.on_market_purchase, do_outpost_upgrade) +Event.add(defines.events.on_selected_entity_changed, market_selected) + return Public diff --git a/map_gen/maps/crash_site/outpost_data/artillery_block.lua b/map_gen/maps/crash_site/outpost_data/artillery_block.lua index 5441f3c2..84a63ed7 100644 --- a/map_gen/maps/crash_site/outpost_data/artillery_block.lua +++ b/map_gen/maps/crash_site/outpost_data/artillery_block.lua @@ -1,7 +1,7 @@ local ob = require 'map_gen.maps.crash_site.outpost_builder' return ob.make_1_way { - turret = {callback = ob.refill_turret_callback, data = ob.artillery_shell_ammo}, + turret = {callback = ob.refill_artillery_turret_callback, data = ob.artillery_shell_ammo}, [1] = {tile = 'refined-concrete'}, [2] = {tile = 'refined-concrete'}, [3] = {tile = 'refined-concrete'},