2022-06-01 20:50:36 +02:00
-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates.
2021-10-13 10:21:53 +02:00
local Global = require ' utils.global '
2022-03-19 23:20:55 +02:00
-- local CoreData = require 'maps.pirates.coredata'
2021-10-13 10:21:53 +02:00
local pirates_global_memory = { }
local Public = { }
-- register only this
Global.register (
pirates_global_memory ,
function ( tbl )
pirates_global_memory = tbl
end
)
function Public . global_reset_memory ( )
for k , _ in pairs ( pirates_global_memory ) do
pirates_global_memory [ k ] = nil
end
pirates_global_memory.config = { }
pirates_global_memory.afk_player_indices = { }
pirates_global_memory.playerindex_to_time_played_continuously = { }
2022-03-01 17:57:23 +02:00
pirates_global_memory.playerindex_to_captainhood_priority = { }
2021-10-13 10:21:53 +02:00
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 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
pirates_global_memory.lobby_boats = { }
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
pirates_global_memory.active_crews_cap = nil
pirates_global_memory.crew_capacity_min = nil
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
pirates_global_memory.crewproposals = { }
pirates_global_memory.global_delayed_tasks = { }
pirates_global_memory.global_buffered_tasks = { }
2022-06-02 15:07:17 +02:00
pirates_global_memory.last_players_health = { } --used to make damage reduction work somewhat properly
2021-10-13 10:21:53 +02:00
end
2022-05-09 01:36:48 +02:00
function Public . initialise_crew_memory ( id ) --mostly serves as a dev reference of memory entries
2022-03-13 03:44:32 +02:00
-- but not _everything_ is stored here, it's just a guide to the most important things
2021-10-13 10:21:53 +02:00
pirates_global_memory.crew_memories [ id ] = { }
local memory = pirates_global_memory.crew_memories [ id ]
memory.secs_id = nil
memory.id = nil
memory.age = nil
memory.real_age = nil
memory.completion_time = nil
memory.force_name = nil
memory.enemy_force_name = nil
memory.original_proposal = nil
memory.name = nil
memory.difficulty_option = nil
memory.capacity_option = nil
-- memory.mode_option = nil
memory.difficulty = nil
memory.capacity = nil
-- memory.mode = nil
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
memory.destinations = nil
memory.currentdestination_index = nil
memory.hold_surface_count = nil
memory.merchant_ships_unlocked = nil
memory.boat = nil
2022-03-04 19:57:58 +02:00
memory.available_classes_pool = nil
2022-07-07 22:01:45 +02:00
-- Duplicating unlocked classes data for consistency reasons (this way, entries will remain in the same order when unlocked class data changes)
2022-07-28 19:15:31 +02:00
-- @TODO Might have to consider sacrificing consistency(or find a way to retain consistency) to reduce the chance of contradicting data which results in weird bugs (this happened once already)
2022-07-07 22:01:45 +02:00
memory.unlocked_classes = nil
2022-03-19 23:20:55 +02:00
2022-06-08 15:26:49 +02:00
memory.seconds_until_alert_sound_can_be_played_again = 0
2021-10-13 10:21:53 +02:00
memory.crewplayerindices = nil
memory.spectatorplayerindices = nil
memory.tempbanned_from_joining_data = nil
memory.playerindex_captain = nil
memory.captain_accrued_time_data = nil
2022-02-28 18:36:46 +02:00
memory.max_players_recorded = nil
2022-03-09 01:36:03 +02:00
memory.temporarily_logged_off_characters = nil
2021-10-13 10:21:53 +02:00
memory.speed_boost_characters = nil
memory.enemyboats = nil
memory.overworld_krakens = nil
memory.active_sea_enemies = nil
memory.kraken_stream_registrations = nil
memory.mainshop_availability_bools = nil
memory.delayed_tasks = nil
memory.buffered_tasks = nil
memory.game_lost = false
memory.game_won = false
memory.crew_disband_tick = nil
memory.destinationsvisited_indices = nil
memory.overworldx = nil
memory.overworldy = nil
memory.mapbeingloadeddestination_index = nil
memory.loadingticks = nil
2022-02-24 21:39:03 +02:00
memory.stored_fuel = nil
2021-10-13 10:21:53 +02:00
memory.spawnpoint = nil
2022-03-01 23:59:48 +02:00
memory.evolution_factor = nil
2021-10-13 10:21:53 +02:00
memory.scripted_biters = nil
memory.scripted_unit_groups = nil
memory.floating_pollution = nil
2022-05-06 14:00:57 +02:00
memory.playtesting_stats = nil
2022-06-15 23:00:18 +02:00
memory.cliff_explosives_acquired_once = false -- used to give tip by parrot what to do with them(only triggers from buying it in captain's cabin)
memory.hold_surface_destroyable_wooden_chests = nil
2021-10-13 10:21:53 +02:00
end
2022-03-13 03:44:32 +02:00
function Public . fallthrough_crew_memory ( ) --could make this a metatable, but metatables and factorio global seem not to play nicely
2021-10-13 10:21:53 +02:00
return {
id = 0 ,
difficulty = 1 ,
force_name = ' player ' ,
boat = { } ,
destinations = { } ,
spectatorplayerindices = { } ,
crewplayerindices = { } ,
--[[boat = {
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 ,
} ] ]
}
end
function Public . get_crew_memory ( )
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
end
function Public . get_global_memory ( )
return pirates_global_memory
end
function Public . set_working_id ( id )
pirates_global_memory.working_id = id
end
return Public