1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-28 23:06:38 +02:00

move wait to after destination load, halt loading for krakens

This commit is contained in:
danielmartin0 2024-09-11 15:24:41 +01:00
parent 552a6abc51
commit 64ff90782b
7 changed files with 105 additions and 110 deletions

View File

@ -101,7 +101,6 @@ ship_undocked_1=[font=heading-1]Ship undocked[/font] by captain.
ship_undocked_2=[font=heading-1]Ship auto-undocked[/font]. Return to ship.
ship_undocked_3=[font=heading-1]Ship auto-undocked[/font].
ship_set_off_to_next_island=[font=heading-1]Ship set sail[/font] for the next destination.
crew_continue_on_freeplay=The run now continues on 'Freeplay'.
victory_continue_reminder=If you wish to continue the game, click up top.
@ -145,7 +144,8 @@ granted_3=__1__ __2__, __3__, __4__.
approaching_destination=Approaching destination __1__, __2__.
loading_destination=Loading destination __1__, __2__.
wait_for_crew_to_finish_loading=Ship held at signal: Waiting for crew __1__ to finish loading.
wait_for_crew_to_finish_loading=Ship held at signal: Waiting for crew '__1__' to finish loading.
wait_for_crew_to_finish_fighting_kraken=Ship held at signal: Waiting for crew '__1__' to finish fighting kraken.
steer_left=Steering portside...
steer_right=Steering starboard...
@ -561,9 +561,9 @@ gui_minimap_main_tooltip=View the outside world.
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_loading_for=Loading for
gui_etaframe_defeat_krakens=Defeat the krakens!
gui_etaframe_atsea_waiting=Captain — Click here to Sail
gui_etaframe_atsea_waiting=Captain — Click here to Approach
gui_etaframe_undock=Undock:
gui_etaframe_anytime=Anytime
gui_etaframe_next_escape_cost=Next escape cost:

View File

@ -242,7 +242,7 @@ function Public.tell_biters_near_silo_to_attack_it()
local enemy_force_name = memory.enemy_force_name
-- don't do this too early
if destination.dynamic_data.timer < destination.dynamic_data.timeratlandingtime + Common.seconds_after_landing_to_enable_AI * 4 then return end
if destination.dynamic_data.timeratlandingtime and destination.dynamic_data.timer < destination.dynamic_data.timeratlandingtime + Common.seconds_after_landing_to_enable_AI * 4 then return end
if not (destination.dynamic_data.rocketsilos and destination.dynamic_data.rocketsilos[1] and destination.dynamic_data.rocketsilos[1].valid and destination.dynamic_data.rocketsilos[1].destructible) then return end
local attackcommand = Public.attack_target_entity(destination.dynamic_data.rocketsilos[1])

View File

@ -27,6 +27,7 @@ local Crew = require 'maps.pirates.crew'
local Math = require 'maps.pirates.math'
local _inspect = require 'utils.inspect'.inspect
local Kraken = require 'maps.pirates.surfaces.sea.kraken'
local CustomEvents = require 'maps.pirates.custom_events'
local Quest = require 'maps.pirates.quest'
-- local ShopDock = require 'maps.pirates.shop.dock'
@ -975,8 +976,6 @@ function Public.loading_update(tickinterval)
local destination_index = memory.mapbeingloadeddestination_index
if not destination_index then memory.loadingticks = nil return end
-- if (not memory.boat.state) or (not (memory.boat.state == Boats.enum_state.LANDED or memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP or memory.boat.state == Boats.enum_state.LEAVING_DOCK or (memory.boat.state == Boats.enum_state.APPROACHING and destination_index == 1))) then return end
if not memory.boat.state then return end
local map_loads = false
@ -987,36 +986,65 @@ function Public.loading_update(tickinterval)
if not map_loads then return end
local crew_to_wait_for = nil
if memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP then
for id, crew_memory in pairs(global_memory.crew_memories) do
if crew_memory.loadingticks and (crew_memory.loadingticks > memory.loadingticks or (crew_memory.loadingticks == memory.loadingticks and id < memory.id)) then
crew_to_wait_for = id
break
end
end
end
if crew_to_wait_for then
if not memory.waiting_for_other_crew or memory.waiting_for_other_crew ~= crew_to_wait_for then
memory.waiting_for_other_crew = crew_to_wait_for
local waiting_crew_name = global_memory.crew_memories[crew_to_wait_for].name or "Unknown crew"
Common.notify_force(memory.force, {'pirates.wait_for_crew_to_finish_loading', waiting_crew_name})
end
return
else
memory.waiting_for_other_crew = nil
end
memory.loadingticks = memory.loadingticks + tickinterval
-- if memory.loadingticks % 100 == 0 then game.print(memory.loadingticks) end
local destination_data = memory.destinations[destination_index]
if memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP or memory.boat.state == Boats.enum_state.LEAVING_DOCK then
local other_crew_loading = nil
local crew_fighting_kraken = nil
for id, crew_memory in pairs(global_memory.crew_memories) do
if crew_memory.loadingticks and (crew_memory.loadingticks > memory.loadingticks or (crew_memory.loadingticks == memory.loadingticks and id < memory.id)) then
other_crew_loading = id
end
if Kraken.get_active_kraken_count(crew_memory.id) > 0 then
crew_fighting_kraken = id
end
end
if crew_fighting_kraken and crew_fighting_kraken == memory.id then
memory.halted_due_to_crew_loading = nil
memory.halted_due_to_crew_fighting_kraken = memory.id
return
end
-- When other crews are loading, we halt loading if we're ATSEA_LOADING_MAP:
if other_crew_loading and memory.boat.state == Boats.enum_state.ATSEA_LOADING_MAP then
if (not memory.halted_due_to_crew_loading) or memory.halted_due_to_crew_loading ~= other_crew_loading then
memory.halted_due_to_crew_loading = other_crew_loading
memory.halted_due_to_crew_fighting_kraken = nil
local waiting_crew_name = global_memory.crew_memories[other_crew_loading].name or "Unknown crew"
Common.notify_force(memory.force, {'pirates.wait_for_crew_to_finish_loading', waiting_crew_name})
end
return
end
if crew_fighting_kraken then
if (not memory.halted_due_to_crew_fighting_kraken) or memory.halted_due_to_crew_fighting_kraken ~= crew_fighting_kraken then
memory.halted_due_to_crew_loading = nil
memory.halted_due_to_crew_fighting_kraken = crew_fighting_kraken
local fighting_crew_name = global_memory.crew_memories[crew_fighting_kraken].name or "Unknown crew"
Common.notify_force(memory.force, {'pirates.wait_for_crew_to_finish_fighting_kraken', fighting_crew_name})
end
if (memory.boat.state == Boats.enum_state.LEAVING_DOCK) then
memory.boat.speed = 0 -- This line depends on the fact it executes after the tick event that sets the boat speed to a positive value.
end
return
end
end
memory.halted_due_to_crew_loading = nil
memory.halted_due_to_crew_fighting_kraken = nil
memory.loadingticks = memory.loadingticks + tickinterval
if (not destination_data) then
if memory.boat and currentdestination.type == Surfaces.enum.LOBBY then
if memory.loadingticks >= 350 - Common.loading_interval then
@ -1106,19 +1134,22 @@ function Public.loading_update(tickinterval)
-- local eta_ticks = total - (memory.loadingticks - (memory.extra_time_at_sea or 0))
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))
local fraction = memory.loadingticks / (total + (memory.extra_time_at_sea or 0))
if fraction > Common.fraction_of_map_loaded_at_sea then
Progression.progress_to_destination(destination_index)
memory.loadingticks = 0
else
PiratesApiEvents.load_some_map_chunks_random_order(surface, currentdestination, fraction) --random order is good for maze world
if currentdestination.subtype == IslandEnum.enum.CAVE then
PiratesApiEvents.load_some_map_chunks_random_order(currentdestination.dynamic_data.cave_miner.cave_surface, currentdestination, fraction)
end
if fraction > Common.fraction_of_map_loaded_at_sea then
memory.boat.state = Boats.enum_state.ATSEA_WAITING_TO_SAIL
memory.force_toggle_machine_states = true
Boats.update_EEIs(memory.boat)
local force = memory.force
if not (force and force.valid) then return end
script.raise_event(CustomEvents.enum['update_crew_fuel_gui'], {})
else
PiratesApiEvents.load_some_map_chunks_random_order(surface, currentdestination, fraction) --random order is good for maze world
if currentdestination.subtype == IslandEnum.enum.CAVE then
PiratesApiEvents.load_some_map_chunks_random_order(currentdestination.dynamic_data.cave_miner.cave_surface, currentdestination, fraction)
end
end
@ -1338,7 +1369,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 Kraken.get_active_kraken_count() > 0 then
if Kraken.get_active_kraken_count(memory.id) > 0 then
local surface = game.surfaces[boat.surface_name]

View File

@ -148,25 +148,6 @@ function(cmd)
end
end)
commands.add_command(
'sail',
{'pirates.cmd_explain_sail'},
function(cmd)
cmd_set_memory(cmd)
local memory = Memory.get_crew_memory()
if not Common.is_id_valid(memory.id) then return end
--local param = tostring(cmd.parameter)
if check_admin(cmd) then
--local player = game.players[cmd.player_index]
Crew.summon_crew()
if memory.boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL then
Progression.at_sea_begin_to_set_sail()
end
end
end)
commands.add_command(
'setcaptain',
{'pirates.cmd_explain_setcaptain'},

View File

@ -562,7 +562,7 @@ 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
if Kraken.get_active_kraken_count() > 0 then
if Kraken.get_active_kraken_count(memory.id) > 0 then
flow2.etaframe_label_1.visible = true
flow2.etaframe_label_2.visible = false
@ -584,7 +584,7 @@ function Public.process_etaframe_update(player, flow1, bools)
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_1.caption = {'pirates.gui_etaframe_loading_for'}
flow2.etaframe_label_2.caption = Utils.standard_string_form_of_time_in_seconds(eta_ticks / 60)
end
@ -606,7 +606,7 @@ function Public.process_etaframe_update(player, flow1, bools)
flow2.etaframe_label_2.caption = {'pirates.gui_etaframe_anytime'}
end
if bools.cost_bool and Kraken.get_active_kraken_count() == 0 then
if bools.cost_bool and Kraken.get_active_kraken_count(memory.id) == 0 then
local costs = destination.static_params.base_cost_to_undock
local adjusted_costs = Common.time_adjusted_departure_cost(costs)
@ -1253,7 +1253,10 @@ local function on_gui_click(event)
elseif memory.boat.state == Boats.enum_state.ATSEA_WAITING_TO_SAIL then
if Roles.player_privilege_level(player) >= Roles.privilege_levels.CAPTAIN then
Progression.at_sea_begin_to_set_sail()
local destination_index = memory.mapbeingloadeddestination_index
Progression.progress_to_destination(destination_index)
memory.loadingticks = 0
end
end

View File

@ -537,29 +537,6 @@ function Public.undock_from_dock(manual)
end
function Public.at_sea_begin_to_set_sail()
local memory = Memory.get_crew_memory()
local boat = memory.boat
boat.state = Boats.enum_state.ATSEA_SAILING
memory.force_toggle_machine_states = true
Boats.update_EEIs(memory.boat)
script.raise_event(CustomEvents.enum['update_crew_fuel_gui'], {})
local force = memory.force
if not (force and force.valid) then return end
if memory.victory_continue_message then
memory.victory_continue_message = false
Common.notify_force(force, {'pirates.crew_continue_on_freeplay'}, CoreData.colors.notify_victory)
else
Common.notify_force(force, {'pirates.ship_set_off_to_next_island'})
end
end
local parrot_set_sail_advice =
@ -587,14 +564,11 @@ function Public.go_from_currentdestination_to_sea()
local destination = Common.current_destination()
if memory.game_lost then return end
local oldsurface = game.surfaces[destination.surface_name]
Sea.ensure_sea_surface()
local seaname = memory.sea_name
local boat = memory.boat
local old_boatposition = memory.boat.position
local new_boatposition = Utils.snap_coordinates_for_rails({x = Boats.get_scope(memory.boat).Data.width / 2, y = 0})
Boats.teleport_boat(boat, seaname, new_boatposition, CoreData.static_boat_floor, 'water')
@ -619,15 +593,19 @@ function Public.go_from_currentdestination_to_sea()
end
end
memory.boat.state = Boats.enum_state.ATSEA_WAITING_TO_SAIL
memory.force_toggle_machine_states = true
Boats.update_EEIs(memory.boat)
boat.state = Boats.enum_state.ATSEA_SAILING
memory.boat.speed = 0
memory.boat.position = new_boatposition
memory.boat.surface_name = seaname
memory.boat.fish_caught_while_at_sea = 0 -- how many times a fish was caught, rather than amount of fish caught in total
boat.speed = 0
boat.position = new_boatposition
boat.surface_name = seaname
boat.fish_caught_while_at_sea = 0 -- how many times a fish was caught, rather than amount of fish caught in total
local force = memory.force
if not (force and force.valid) then return end
if memory.victory_continue_message then
memory.victory_continue_message = false
Common.notify_force(force, {'pirates.crew_continue_on_freeplay'}, CoreData.colors.notify_victory)
end
memory.enemy_force.reset_evolution()

View File

@ -50,9 +50,11 @@ 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
function Public.get_active_kraken_count(crew_id)
local global_memory = Memory.get_global_memory()
local memory = global_memory.crew_memories[crew_id]
if memory and memory.active_sea_enemies and memory.active_sea_enemies.kraken_count then
return memory.active_sea_enemies.kraken_count
else
return 0
@ -71,7 +73,7 @@ function Public.swimming_biters_tick(crew_id, kraken_id)
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
if Public.get_active_kraken_count(memory.id) == 0 and #spawners_biters == 0 then return end
for _, biter in pairs(spawners_biters) do
if biter and biter.valid then
@ -280,7 +282,7 @@ end
function Public.overall_kraken_tick()
local memory = Memory.get_crew_memory()
if Public.get_active_kraken_count() > 0 then
if Public.get_active_kraken_count(memory.id) > 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
@ -322,7 +324,7 @@ function Public.try_spawn_kraken()
Task.set_timeout_in_ticks(10, kraken_tick_token, {crew_id = memory.id, kraken_id = kraken_id, step = 1, substep = 1})
-- creating multiple swim tick tokens, causes biters to swim faster
if Public.get_active_kraken_count() == 1 then
if Public.get_active_kraken_count(memory.id) == 1 then
Task.set_timeout_in_ticks(10, swimming_biters_tick_token, {crew_id = memory.id, kraken_id = kraken_id})
end
end