diff --git a/locale/en/pirates.cfg b/locale/en/pirates.cfg index e2ae9b3d..3bab1338 100644 --- a/locale/en/pirates.cfg +++ b/locale/en/pirates.cfg @@ -404,6 +404,7 @@ mode_tooltip=Mode. auto_undock_tooltip=The maximum time to stay at this location.\n\nOnce this time is reached, the boat undocks automatically. The captain can choose to leave earlier by pressing this button (or typing /undock). atsea_loading_tooltip=The next destination is loading. +defeat_krakens_tooltip=Defeat the krakens to proceed. leave_anytime_tooltip=The captain chooses when to undock the ship.\n\nThey can undock by pressing this button. atsea_waiting_tooltip=The ship pauses after each destination. When the captain is ready, they can click this button to proceed. @@ -548,6 +549,7 @@ gui_etaframe_board_warning=RETURN TO SHIP gui_etaframe_board_warning_tooltip=Probably time to board... gui_etaframe_autoundock=Auto-undock: gui_etaframe_arriving_in=Arriving in +gui_etaframe_defeat_krakens=Defeat the krakens! gui_etaframe_atsea_waiting=Captain — Click here to Sail gui_etaframe_undock=Undock: gui_etaframe_anytime=Anytime diff --git a/maps/pirates/api_events.lua b/maps/pirates/api_events.lua index e2d8c017..17f26cf2 100644 --- a/maps/pirates/api_events.lua +++ b/maps/pirates/api_events.lua @@ -60,7 +60,7 @@ function Public.silo_die() -- Crew.lose_life() Crew.try_lose({'pirates.loss_silo_destroyed'}) elseif (not destination.dynamic_data.rocketlaunched) then - if destination.static_params and destination.static_params.base_cost_to_undock and destination.static_params.base_cost_to_undock['launch_rocket'] == true and Boats.need_resources_to_undock() then + if destination.static_params and destination.static_params.base_cost_to_undock and destination.static_params.base_cost_to_undock['launch_rocket'] == true and Balance.need_resources_to_undock() then Crew.try_lose({'pirates.loss_silo_destroyed_before_necessary_launch'}) else Common.notify_force(force, {'pirates.silo_destroyed'}) diff --git a/maps/pirates/api_on_tick.lua b/maps/pirates/api_on_tick.lua index 17f3d6c6..b5b1f8be 100644 --- a/maps/pirates/api_on_tick.lua +++ b/maps/pirates/api_on_tick.lua @@ -1005,14 +1005,10 @@ function Public.loading_update(tickinterval) total = Common.map_loading_ticks_atsea_maze end - local eta_ticks = total - (memory.loadingticks - (memory.extra_time_at_sea or 0)) + -- local eta_ticks = total - (memory.loadingticks - (memory.extra_time_at_sea or 0)) - if eta_ticks < 60*20 and - memory.active_sea_enemies and - memory.active_sea_enemies.kraken_count and - memory.active_sea_enemies.kraken_count > 0 - then - memory.loadingticks = memory.loadingticks - tickinterval --reverse the change + if Kraken.get_active_kraken_count() > 0 then + memory.loadingticks = memory.loadingticks - tickinterval --reverse the change to avoid causing lag from map loading during fight else local fraction = memory.loadingticks / (total + (memory.extra_time_at_sea or 0)) @@ -1243,7 +1239,7 @@ function Public.Kraken_Destroyed_Backup_check(tickinterval) -- a server became s local boat = memory.boat if boat and boat.surface_name and boat.state and boat.state == Boats.enum_state.ATSEA_LOADING_MAP then - if (memory.active_sea_enemies and memory.active_sea_enemies.krakens and memory.active_sea_enemies.kraken_count and memory.active_sea_enemies.kraken_count > 0) then + if Kraken.get_active_kraken_count() > 0 then local surface = game.surfaces[boat.surface_name] diff --git a/maps/pirates/balance.lua b/maps/pirates/balance.lua index 624d87d1..9162da71 100644 --- a/maps/pirates/balance.lua +++ b/maps/pirates/balance.lua @@ -14,7 +14,7 @@ local CoreData = require 'maps.pirates.coredata' -- Kraken related parameters -Public.biter_swim_speed = 1 +Public.biter_swim_speed = 1.5 Public.kraken_biter_spawn_radius = 6 -- only used during non automatic forced spawning during kraken's "special ability" Public.kraken_spit_targeting_player_chance = 0 @@ -168,10 +168,19 @@ end Public.rockets_needed_x = 40*20 +-- Returns true if resources are mandatory to escape from island. Returns false, when resources are needed to just undock early. +function Public.need_resources_to_undock() + local x = Common.overworldx() + if x >= Public.rockets_needed_x and x ~= 40*21 then + return true + else + return false + end +end function Public.max_time_on_island() local x = Common.overworldx() - if x == 0 or (x >= Public.rockets_needed_x and x ~= 40*21) then + if x == 0 or Public.need_resources_to_undock() then -- if Common.overworldx() == 0 or ((Common.overworldx()/40) > 20 and (Common.overworldx()/40) < 25) then return -1 else diff --git a/maps/pirates/gui/gui.lua b/maps/pirates/gui/gui.lua index 56cc71ce..8500feb3 100644 --- a/maps/pirates/gui/gui.lua +++ b/maps/pirates/gui/gui.lua @@ -27,6 +27,7 @@ local Roles = require 'maps.pirates.roles.roles' local Event = require 'utils.event' local CustomEvents = require 'maps.pirates.custom_events' local IslandEnum = require 'maps.pirates.surfaces.islands.island_enum' +local Kraken = require 'maps.pirates.surfaces.sea.kraken' local ComfyGui = require 'utils.gui' ComfyGui.set_disabled_tab('Scoreboard', true) @@ -558,23 +559,32 @@ function Public.process_etaframe_update(player, flow1, bools) flow2.etaframe_label_2.caption = Utils.standard_string_form_of_time_in_seconds(passive_eta) elseif bools.atsea_loading_bool then - flow2.etaframe_label_1.visible = true - flow2.etaframe_label_2.visible = true + if Kraken.get_active_kraken_count() > 0 then + flow2.etaframe_label_1.visible = true + flow2.etaframe_label_2.visible = false - tooltip = {'pirates.atsea_loading_tooltip'} + tooltip = {'pirates.defeat_krakens_tooltip'} - local total = Common.map_loading_ticks_atsea - if destination.type == Surfaces.enum.DOCK then - total = Common.map_loading_ticks_atsea_dock - elseif destination.type == Surfaces.enum.ISLAND and destination.subtype == IslandEnum.enum.MAZE then - total = Common.map_loading_ticks_atsea_maze + flow2.etaframe_label_1.caption = {'pirates.gui_etaframe_defeat_krakens'} + else + flow2.etaframe_label_1.visible = true + flow2.etaframe_label_2.visible = true + + tooltip = {'pirates.atsea_loading_tooltip'} + + local total = Common.map_loading_ticks_atsea + if destination.type == Surfaces.enum.DOCK then + total = Common.map_loading_ticks_atsea_dock + elseif destination.type == Surfaces.enum.ISLAND and destination.subtype == IslandEnum.enum.MAZE then + total = Common.map_loading_ticks_atsea_maze + end + + local eta_ticks = total + (memory.extra_time_at_sea or 0) - memory.loadingticks + + flow2.etaframe_label_1.caption = {'pirates.gui_etaframe_arriving_in'} + flow2.etaframe_label_2.caption = Utils.standard_string_form_of_time_in_seconds(eta_ticks / 60) end - local eta_ticks = total + (memory.extra_time_at_sea or 0) - memory.loadingticks - - flow2.etaframe_label_1.caption = {'pirates.gui_etaframe_arriving_in'} - flow2.etaframe_label_2.caption = Utils.standard_string_form_of_time_in_seconds(eta_ticks / 60) - elseif bools.atsea_waiting_bool then flow2.etaframe_label_1.visible = true flow2.etaframe_label_2.visible = false @@ -593,7 +603,7 @@ function Public.process_etaframe_update(player, flow1, bools) flow2.etaframe_label_2.caption = {'pirates.gui_etaframe_anytime'} end - if bools.cost_bool then + if bools.cost_bool and Kraken.get_active_kraken_count() == 0 then local costs = destination.static_params.base_cost_to_undock local adjusted_costs = Common.time_adjusted_departure_cost(costs) @@ -608,8 +618,7 @@ function Public.process_etaframe_update(player, flow1, bools) -- local caption if bools.atsea_loading_bool then - -- @TODO: Fix magic numbers here - if Boats.need_resources_to_undock() then --bools.eta_bool is not helpful yet + if Balance.need_resources_to_undock() then flow2.etaframe_label_3.caption = {'pirates.gui_etaframe_next_escape_cost'} if bools.cost_includes_rocket_launch_bool then tooltip = {'pirates.resources_needed_tooltip_0_rocketvariant'} diff --git a/maps/pirates/structures/boats/boats.lua b/maps/pirates/structures/boats/boats.lua index 0b859aef..50b7887b 100644 --- a/maps/pirates/structures/boats/boats.lua +++ b/maps/pirates/structures/boats/boats.lua @@ -1473,13 +1473,4 @@ function Public.clear_fluid_from_ship_tanks(idx) end end -function Public.need_resources_to_undock() - local destination = Common.current_destination() - if destination and destination.dynamic_data and destination.dynamic_data.time_remaining == -1 then - return true - else - return false - end -end - return Public \ No newline at end of file diff --git a/maps/pirates/surfaces/sea/kraken.lua b/maps/pirates/surfaces/sea/kraken.lua index b7008566..ad8d5527 100644 --- a/maps/pirates/surfaces/sea/kraken.lua +++ b/maps/pirates/surfaces/sea/kraken.lua @@ -50,17 +50,29 @@ local swimming_biters_tick_token = end ) +function Public.get_active_kraken_count() + local memory = Memory.get_crew_memory() + if memory.active_sea_enemies and memory.active_sea_enemies.kraken_count then + return memory.active_sea_enemies.kraken_count + else + return 0 + end +end + -- should only be used during kraken encounter function Public.swimming_biters_tick(crew_id, kraken_id) Memory.set_working_id(crew_id) local memory = Memory.get_crew_memory() if not Common.is_id_valid(memory.id) then return end --check if crew disbanded if memory.game_lost then return end - local kraken_data = memory.active_sea_enemies.krakens[kraken_id] - if not kraken_data then return end --check if kraken died - local surface = game.surfaces[memory.sea_name] + if not Boats.is_boat_at_sea() then return end + + local surface = game.surfaces[memory.sea_name] local spawners_biters = surface.find_entities_filtered{force = memory.enemy_force_name} + + if Public.get_active_kraken_count() == 0 and #spawners_biters == 0 then return end + for _, biter in pairs(spawners_biters) do if biter and biter.valid then if biter.name ~= 'biter-spawner' then -- might need to be changed if kraken battle one day will involve worms too @@ -266,7 +278,7 @@ end function Public.overall_kraken_tick() local memory = Memory.get_crew_memory() - if memory.active_sea_enemies and memory.active_sea_enemies.kraken_count and memory.active_sea_enemies.kraken_count > 0 then + if Public.get_active_kraken_count() > 0 then local evo_increase = Balance.kraken_evo_increase_per_second() if evo_increase > 0 then if not memory.dynamic_kraken_evo then memory.dynamic_kraken_evo = 0 end @@ -306,7 +318,11 @@ function Public.try_spawn_kraken() memory.active_sea_enemies.kraken_count = memory.active_sea_enemies.kraken_count + 1 Task.set_timeout_in_ticks(10, kraken_tick_token, {crew_id = memory.id, kraken_id = kraken_id, step = 1, substep = 1}) - Task.set_timeout_in_ticks(10, swimming_biters_tick_token, {crew_id = memory.id, kraken_id = kraken_id}) + + -- creating multiple swim tick tokens, causes biters to swim faster + if Public.get_active_kraken_count() == 1 then + Task.set_timeout_in_ticks(10, swimming_biters_tick_token, {crew_id = memory.id, kraken_id = kraken_id}) + end end end