From 3b782829d364fa092927662aea9e1dc13d3ad2d7 Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Thu, 13 Oct 2022 21:39:42 +0300 Subject: [PATCH] Cliff explosives related tweaks Changes: - Chests with cliff-explosives in holds now explode after 5 second delay. - Changed the price of cliff explosives to cost 1000 coins for 5 (4x cheaper than before). Reasoning: This is an experiment to shift the coin spending meta. - Players now can find explosives and cliff-explosives in chests in the wild. --- maps/pirates/api_on_tick.lua | 73 +++++++++++++++++++++++++-------- maps/pirates/common.lua | 2 +- maps/pirates/crew.lua | 1 + maps/pirates/loot.lua | 2 + maps/pirates/surfaces/cabin.lua | 4 +- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/maps/pirates/api_on_tick.lua b/maps/pirates/api_on_tick.lua index 4dee1a4b..e34a79c0 100644 --- a/maps/pirates/api_on_tick.lua +++ b/maps/pirates/api_on_tick.lua @@ -1516,36 +1516,77 @@ function Public.update_alert_sound_frequency_tracker() end end +-- Check for cliff explosives in chest. function Public.check_for_cliff_explosives_in_hold_wooden_chests() local memory = Memory.get_crew_memory() local input_chests = memory.hold_surface_destroyable_wooden_chests + local queued_chests_timers = memory.hold_surface_timers_of_wooden_chests_queued_for_destruction + local tick_tack_timer = 5 -- how long it takes before chests detonate if not input_chests then return end - for i, chest in ipairs(input_chests) do + -- check which chests have cliff explosives in them + for i, chest in pairs(input_chests) do + -- @TODO: decide what to do when chest is invalid (perhaps it was destroyed by some future feature) if chest and chest.valid then local item_count = chest.get_item_count('cliff-explosives') if item_count and item_count > 0 then - local surface = chest.surface - local explosion = { - name = 'wooden-chest-explosion', - position = chest.position - } - local remnants = { - name = 'wooden-chest-remnants', - position = chest.position - } - - chest.destroy() - surface.create_entity(explosion) - surface.create_entity(remnants) - - table.fast_remove(memory.hold_surface_destroyable_wooden_chests, i) + if not queued_chests_timers[i] then + queued_chests_timers[i] = tick_tack_timer + end end end end + + -- update chest timers and when timer reaches 0 explode them + for i, _ in pairs(queued_chests_timers) do + local chest = input_chests[i] + if chest and chest.valid then + local surface = chest.surface + queued_chests_timers[i] = queued_chests_timers[i] - 1 + local timer = queued_chests_timers[i] + + if timer <= 0 then + -- check if sneaky players didn't decide to remove the explosives just before the explosion + local item_count = chest.get_item_count('cliff-explosives') + if item_count and item_count > 0 then + local explosion = { + name = 'wooden-chest-explosion', + position = chest.position + } + local remnants = { + name = 'wooden-chest-remnants', + position = chest.position + } + + chest.destroy() + surface.create_entity(explosion) + surface.create_entity(remnants) + + input_chests[i] = nil + end + + queued_chests_timers[i] = nil + else + local tick_tacks = {'*tick*', '*tick*', '*tack*', '*tak*', '*tik*', '*tok*'} + surface.create_entity( + { + name = 'flying-text', + position = chest.position, + text = tick_tacks[Math.random(#tick_tacks)], + color = {r = 0.75, g = 0.75, b = 0.75} + } + ) + end + else + -- we probably don't want to have it in the queue anymore if it's invalid now, do we? + queued_chests_timers[i] = nil + end + end end + + -- Code taken from Mountain fortress local function equalise_fluid_storage_pair(storage1, storage2) if not storage1.valid then diff --git a/maps/pirates/common.lua b/maps/pirates/common.lua index f33019b0..af8c1973 100644 --- a/maps/pirates/common.lua +++ b/maps/pirates/common.lua @@ -619,7 +619,7 @@ function Public.surface_place_random_obstacle_boxes(surface, center, width, heig for j = 1, size^2 do local p2 = surface.find_non_colliding_position('wooden-chest', p, 5, 0.1, true) or p local e = surface.create_entity{name = 'wooden-chest', position = p2, force = memory.force_name, create_build_effect_smoke = false} - memory.hold_surface_destroyable_wooden_chests[#memory.hold_surface_destroyable_wooden_chests + 1] = e + memory.hold_surface_destroyable_wooden_chests[e.unit_number] = e e.destructible = false e.minable = false e.rotatable = false diff --git a/maps/pirates/crew.lua b/maps/pirates/crew.lua index 914e9945..f348694a 100644 --- a/maps/pirates/crew.lua +++ b/maps/pirates/crew.lua @@ -757,6 +757,7 @@ function Public.initialise_crew(accepted_proposal) memory.overworldy = 0 memory.hold_surface_destroyable_wooden_chests = {} + memory.hold_surface_timers_of_wooden_chests_queued_for_destruction = {} memory.seaname = SurfacesCommon.encode_surface_name(memory.id, 0, SurfacesCommon.enum.SEA, enum.DEFAULT) diff --git a/maps/pirates/loot.lua b/maps/pirates/loot.lua index 2a257506..63d234bd 100644 --- a/maps/pirates/loot.lua +++ b/maps/pirates/loot.lua @@ -51,6 +51,8 @@ Public.chest_loot_data_raw = { {12, 0, 1, false, 'artillery-shell', 1, 1}, {4, 0, 0.8, false, 'pistol', 1, 3}, {3, 0, 0.2, false, 'storage-tank', 2, 4}, + {2, 0.1, 1, false, 'explosives', 5, 9}, + {2, 0.2, 1, false, 'cliff-explosives', 2, 4}, {0.25, 0, 0.5, false, 'uranium-238', 5, 8}, {8, 0, 1.2, true, 'steel-chest', 4, 12}, diff --git a/maps/pirates/surfaces/cabin.lua b/maps/pirates/surfaces/cabin.lua index 6e2131f1..77f6e052 100644 --- a/maps/pirates/surfaces/cabin.lua +++ b/maps/pirates/surfaces/cabin.lua @@ -111,8 +111,8 @@ Public.cabin_shop_data = { offer = {type='give-item', item = 'uranium-238', count = 10}, }, { - price = {{'coin', 800}, {'explosives', 4}}, - offer = {type='give-item', item = 'cliff-explosives', count = 1}, + price = {{'coin', 1000}, {'explosives', 5}}, + offer = {type='give-item', item = 'cliff-explosives', count = 5}, }, --disabled now that we can wait after any destination: -- {