From 899ce22ed30b2a0372e394dc2c6a0259b054708a Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Fri, 8 Jul 2022 23:06:35 +0300 Subject: [PATCH] Parrot tip for burried treasure Changes: - When players find treasure map, but are unable to dig it, parrots will give them tip, when they will leave the island. --- locale/en/pirates.cfg | 1 + maps/pirates/api_events.lua | 2 - maps/pirates/api_on_tick.lua | 49 +++++++++++++++-------- maps/pirates/main.lua | 1 + maps/pirates/progression.lua | 12 ++++++ maps/pirates/surfaces/islands/islands.lua | 2 + maps/pirates/surfaces/surfaces.lua | 7 +--- 7 files changed, 51 insertions(+), 23 deletions(-) diff --git a/locale/en/pirates.cfg b/locale/en/pirates.cfg index 2ba498a1..20fb9f5d 100644 --- a/locale/en/pirates.cfg +++ b/locale/en/pirates.cfg @@ -72,6 +72,7 @@ parrot_radioactive_tip_2=The biters don't care if we pollute here, but they evol parrot_maze_tip_1=Something seems wrong with our minimap. parrot_captain_first_time_in_cabin_hint=The captain can buy items in the cabin, such as rail signals to steer the ship. parrot_cliff_explosive_tip=Cliff explosives? I remember they're powerful enough to blow those annoying chests in our hold. +parrot_burried_treasure_tip=If X marks the spot - use inserters to dig! diff --git a/maps/pirates/api_events.lua b/maps/pirates/api_events.lua index 6f14960b..177cd6de 100644 --- a/maps/pirates/api_events.lua +++ b/maps/pirates/api_events.lua @@ -1681,8 +1681,6 @@ function Public.event_on_chunk_generated(event) if special.name and special.name == 'buried-treasure' then if destination.dynamic_data.buried_treasure and crewid ~= 0 then - - destination.dynamic_data.buried_treasure[#destination.dynamic_data.buried_treasure + 1] = {treasure = Loot.buried_treasure_loot(), position = special.position} end elseif special.name and special.name == 'chest' then diff --git a/maps/pirates/api_on_tick.lua b/maps/pirates/api_on_tick.lua index afed2e4d..6bbf0a36 100644 --- a/maps/pirates/api_on_tick.lua +++ b/maps/pirates/api_on_tick.lua @@ -674,21 +674,26 @@ end function Public.buried_treasure_check(tickinterval) - local memory = Memory.get_crew_memory() + -- local memory = Memory.get_crew_memory() local destination = Common.current_destination() local remaining = destination.dynamic_data.treasure_remaining - if remaining and remaining > 0 and destination.surface_name and destination.dynamic_data.buried_treasure and #destination.dynamic_data.buried_treasure > 0 then - local surface = game.surfaces[destination.surface_name] - local treasure_table = destination.dynamic_data.buried_treasure + if not (remaining and remaining > 0 and destination.surface_name and destination.dynamic_data.buried_treasure and #destination.dynamic_data.buried_treasure > 0) then + return + end - for i = 1, #treasure_table do - local treasure = treasure_table[i] - if not treasure then break end + local surface = game.surfaces[destination.surface_name] + local treasure_table = destination.dynamic_data.buried_treasure + + for i = 1, #treasure_table do + local treasure = treasure_table[i] + if not treasure then break end + + local t = treasure.treasure + + if t then local p = treasure.position - - local free = surface.can_place_entity{name = 'wooden-chest', position = p} if free then @@ -724,13 +729,6 @@ function Public.buried_treasure_check(tickinterval) if inserters[j] and inserters[j][1] then local ins = inserters[j][1] - local t = treasure.treasure - -- if #treasure.treasure > 0 then - -- t = treasure.treasure - -- -- t = treasure.treasure[1] - -- end - if not t then break end - if destination.dynamic_data.treasure_remaining > 0 and ins.held_stack.count == 0 and ins.status == defines.entity_status.waiting_for_source_items then surface.create_entity{name = 'item-on-ground', position = p, stack = {name = t.name, count = 1}} t.count = t.count - 1 @@ -1537,4 +1535,23 @@ function Public.equalise_fluid_storages() end end +function Public.revealed_buried_treasure_distance_check() + local destination = Common.current_destination() + + if destination.dynamic_data.some_player_was_close_to_buried_treasure then return end + + local maps = destination.dynamic_data.treasure_maps or {} + for _, map in pairs(maps) do + if map.state == 'picked_up' then + for _, player in pairs(Common.crew_get_crew_members()) do + if player.character and player.character.valid then + if Math.distance(player.character.position, map.buried_treasure_position) <= 20 then + destination.dynamic_data.some_player_was_close_to_buried_treasure = true + end + end + end + end + end +end + return Public \ No newline at end of file diff --git a/maps/pirates/main.lua b/maps/pirates/main.lua index 0df097e3..c7c57583 100644 --- a/maps/pirates/main.lua +++ b/maps/pirates/main.lua @@ -184,6 +184,7 @@ local function crew_tick() PiratesApiOnTick.update_alert_sound_frequency_tracker() PiratesApiOnTick.check_for_cliff_explosives_in_hold_wooden_chests() PiratesApiOnTick.equalise_fluid_storages() -- Made the update less often for small performance gain, but frequency can be increased if players complain + PiratesApiOnTick.revealed_buried_treasure_distance_check() if destination.dynamic_data.timer then destination.dynamic_data.timer = destination.dynamic_data.timer + 1 diff --git a/maps/pirates/progression.lua b/maps/pirates/progression.lua index acf0ca9c..a306d2b3 100644 --- a/maps/pirates/progression.lua +++ b/maps/pirates/progression.lua @@ -617,6 +617,18 @@ function Public.go_from_currentdestination_to_sea() Overworld.try_overworld_move_v2{x = d, y = 0} + -- If crew revealed treasure, but couldn't figure out how to dig it, give them tip + if destination.dynamic_data.some_player_was_close_to_buried_treasure then + local maps = destination.dynamic_data.treasure_maps or {} + for _, map in pairs(maps) do + if map.state == 'picked_up' then + Common.parrot_speak(memory.force, {'pirates.parrot_burried_treasure_tip'}) + break + end + end + end + + local players_marooned_count = 0 for _, player in pairs(game.connected_players) do if (player.surface == oldsurface and player.character and player.character.valid) then diff --git a/maps/pirates/surfaces/islands/islands.lua b/maps/pirates/surfaces/islands/islands.lua index 6353957c..600f3fb7 100644 --- a/maps/pirates/surfaces/islands/islands.lua +++ b/maps/pirates/surfaces/islands/islands.lua @@ -73,6 +73,8 @@ function Public.spawn_treasure_maps(destination, points_to_avoid) local p = Hunt.mid_farness_position_1(args, points_to_avoid) + -- game.print(p) + map.position = p map.mapobject_rendering = rendering.draw_sprite{ surface = surface, diff --git a/maps/pirates/surfaces/surfaces.lua b/maps/pirates/surfaces/surfaces.lua index 525d5df0..1f5a7437 100644 --- a/maps/pirates/surfaces/surfaces.lua +++ b/maps/pirates/surfaces/surfaces.lua @@ -691,6 +691,8 @@ end function Public.clean_up(destination) + -- game.print('clean_up') + local memory = Memory.get_crew_memory() local oldsurface = game.surfaces[destination.surface_name] @@ -701,11 +703,6 @@ function Public.clean_up(destination) local seasurface = game.surfaces[memory.sea_name] Quest.try_resolve_quest() - destination.dynamic_data.quest_type = nil - destination.dynamic_data.quest_reward = nil - destination.dynamic_data.quest_progress = nil - destination.dynamic_data.quest_progressneeded = nil - destination.dynamic_data.quest_complete = nil -- handle players that were left on the island -- if there is more than one crew on a surface, this will need to be generalised