2024-09-10 11:29:44 +01:00
-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/ComfyFactory/ComfyFactorio and https://github.com/danielmartin0/ComfyFactorio-Pirates.
2022-06-01 19:50:36 +01:00
2021-10-13 09:21:53 +01:00
local Global = require ' utils.global '
2022-03-19 21:20:55 +00:00
-- local CoreData = require 'maps.pirates.coredata'
2021-10-13 09:21:53 +01:00
local pirates_global_memory = { }
local Public = { }
-- register only this
Global.register (
2022-11-08 21:55:40 +01:00
pirates_global_memory ,
function ( tbl )
pirates_global_memory = tbl
end
2021-10-13 09:21:53 +01:00
)
function Public . global_reset_memory ( )
for k , _ in pairs ( pirates_global_memory ) do
pirates_global_memory [ k ] = nil
end
2022-11-08 21:55:40 +01:00
pirates_global_memory.config = { }
2022-11-18 22:18:16 +02:00
pirates_global_memory.disband_crews = false -- false = disband crew button hidden by default
2022-11-08 21:55:40 +01:00
pirates_global_memory.afk_player_indices = { }
pirates_global_memory.playerindex_to_time_played_continuously = { }
pirates_global_memory.playerindex_to_captainhood_priority = { }
pirates_global_memory.player_gui_memories = { }
pirates_global_memory.crew_memories = { }
pirates_global_memory.crew_active_ids = { }
pirates_global_memory.working_id = nil --should only ever be nil, 1, 2 or 3
2022-03-19 21:20:55 +00:00
2022-11-08 21:55:40 +01:00
pirates_global_memory.lobby_boats = { }
2022-03-19 21:20:55 +00:00
2024-09-10 16:27:47 +01:00
pirates_global_memory.active_crews_cap_in_memory = nil
2022-11-08 21:55:40 +01:00
pirates_global_memory.crew_capacity_min = nil
2022-03-19 21:20:55 +00:00
2022-11-08 21:55:40 +01:00
pirates_global_memory.crewproposals = { }
2021-10-13 09:21:53 +01:00
2022-11-08 21:55:40 +01:00
pirates_global_memory.global_delayed_tasks = { }
pirates_global_memory.global_buffered_tasks = { }
2022-06-02 16:07:17 +03:00
2022-11-08 21:55:40 +01:00
pirates_global_memory.last_players_health = { } --used to make damage reduction work somewhat properly
2021-10-13 09:21:53 +01:00
end
2024-09-10 13:57:00 +01:00
function Public . initialise_crew_memory ( id )
2022-11-08 21:55:40 +01:00
pirates_global_memory.crew_memories [ id ] = { }
2024-09-09 16:07:47 +01:00
local memory = pirates_global_memory.crew_memories [ id ]
memory.game_lost = false
memory.game_won = false
2021-10-13 09:21:53 +01:00
end
2022-03-13 01:44:32 +00:00
function Public . fallthrough_crew_memory ( ) --could make this a metatable, but metatables and factorio global seem not to play nicely
2022-11-08 21:55:40 +01:00
return {
id = 0 ,
difficulty = 1 ,
2023-06-26 21:51:55 +03:00
force_name = ' player ' , -- should match Common.lobby_force_name
2022-11-08 21:55:40 +01:00
boat = { } ,
destinations = { } ,
spectatorplayerindices = { } ,
crewplayerindices = { }
--[[boat = {
2021-10-13 09:21:53 +01:00
type = nil ,
state = nil ,
speed = nil ,
speedticker1 = nil ,
speedticker2 = nil ,
speedticker3 = nil ,
stored_resources = { } ,
position = nil , --the far right edge of the boat
decksteeringchests = nil ,
crowsneststeeringchests = nil ,
cannons = nil ,
EEI = nil ,
EEIpower_production = nil ,
EEIelectric_buffer_size = nil ,
dockedposition = nil ,
surface_name = nil ,
} ] ]
2022-11-08 21:55:40 +01:00
}
2021-10-13 09:21:53 +01:00
end
function Public . get_crew_memory ( )
2022-11-08 21:55:40 +01:00
if pirates_global_memory.working_id and pirates_global_memory.working_id > 0 then
return pirates_global_memory.crew_memories [ pirates_global_memory.working_id ] or Public.fallthrough_crew_memory ( )
else
return Public.fallthrough_crew_memory ( )
end
2021-10-13 09:21:53 +01:00
end
function Public . get_global_memory ( )
2022-11-08 21:55:40 +01:00
return pirates_global_memory
2021-10-13 09:21:53 +01:00
end
function Public . set_working_id ( id )
2022-11-08 21:55:40 +01:00
pirates_global_memory.working_id = id
2021-10-13 09:21:53 +01:00
end
return Public