1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/pirates/main.lua

396 lines
11 KiB
Lua
Raw Normal View History

2021-10-13 10:21:53 +02:00
2022-02-26 20:25:48 +02:00
--[[
2022-03-29 01:36:38 +02:00
Pirate Ship is maintained by thesixthroc and hosted by Comfy.
2022-02-26 20:25:48 +02:00
Want to host it? Ask us at getcomfy.eu/discord!
]]
2022-03-11 12:40:55 +02:00
--[[
2022-03-29 01:36:38 +02:00
2022-03-11 12:40:55 +02:00
== Tips for Developers! ==
2022-03-29 01:36:38 +02:00
The scenario is quite complex, but there are ways to get started, even if you don't know much Lua. Some ideas (incomplete):
Go to pirates/surfaces/islands/first and edit stuff there to see the effect it has on the first island
Ask thesixthroc for access to the ToDo list on Github Projects, to see what needs doing
2022-03-11 12:40:55 +02:00
]]
2022-04-08 15:49:53 +02:00
--[[personal note for thesixthroc in XX years: my design notes are all in Obsidian (edit: mostly moved to Github Projects)]]
2022-04-08 16:13:28 +02:00
2021-10-13 10:21:53 +02:00
-- require 'modules.biters_yield_coins'
require 'modules.biter_noms_you'
require 'modules.no_deconstruction_of_neutral_entities'
2022-03-29 01:36:38 +02:00
require 'maps.pirates.custom_events' --probably do this before anything else
2022-03-13 03:44:32 +02:00
2022-03-19 23:20:55 +02:00
require 'utils.server'
local _inspect = require 'utils.inspect'.inspect
2021-10-13 10:21:53 +02:00
-- local Modifers = require 'player_modifiers'
2022-04-08 15:49:53 +02:00
local BottomFrame = require 'utils.gui.bottom_frame'
2022-02-25 02:01:28 +02:00
local Autostash = require 'modules.autostash'
2022-03-19 23:20:55 +02:00
require 'modules.inserter_drops_pickup'
2021-10-13 10:21:53 +02:00
2022-02-26 20:25:48 +02:00
2021-10-13 10:21:53 +02:00
local TickFunctions = require 'maps.pirates.tick_functions'
local ClassTickFunctions = require 'maps.pirates.tick_functions_classes'
2022-03-19 23:20:55 +02:00
require 'maps.pirates.commands'
require 'maps.pirates.math'
2021-10-13 10:21:53 +02:00
local Memory = require 'maps.pirates.memory'
2022-03-19 23:20:55 +02:00
require 'maps.pirates.gui.gui'
2021-10-13 10:21:53 +02:00
local Common = require 'maps.pirates.common'
local CoreData = require 'maps.pirates.coredata'
2022-03-19 23:20:55 +02:00
require 'maps.pirates.utils_local'
2021-10-13 10:21:53 +02:00
local Balance = require 'maps.pirates.balance'
local Crew = require 'maps.pirates.crew'
local Roles = require 'maps.pirates.roles.roles'
local Structures = require 'maps.pirates.structures.structures'
local Surfaces = require 'maps.pirates.surfaces.surfaces'
local Interface = require 'maps.pirates.interface'
2022-03-19 23:20:55 +02:00
require 'maps.pirates.structures.boats.boats'
2021-10-13 10:21:53 +02:00
local Progression = require 'maps.pirates.progression'
local Ai = require 'maps.pirates.ai'
2022-03-19 23:20:55 +02:00
require 'maps.pirates.ores'
require 'maps.pirates.quest'
require 'maps.pirates.parrot'
require 'maps.pirates.shop.shop'
require 'maps.pirates.boat_upgrades'
2021-10-13 10:21:53 +02:00
local Token = require 'utils.token'
local Task = require 'utils.task'
2022-03-13 12:55:04 +02:00
require 'utils.profiler'
2021-10-13 10:21:53 +02:00
local Public = {}
2022-02-26 20:25:48 +02:00
-- parrot sprites from https://elthen.itch.io/2d-pixel-art-parrot-sprites, licensed appropriately
2021-10-13 10:21:53 +02:00
local jetty_delayed = Token.register(
2022-03-19 23:20:55 +02:00
-- function(data)
function()
2021-10-13 10:21:53 +02:00
Surfaces.Lobby.place_lobby_jetty_and_boats()
end
)
local function on_init()
Memory.global_reset_memory()
local global_memory = Memory.get_global_memory()
game.reset_time_played()
-- local spectator = game.create_force('spectator')
-- local spectator_permissions = game.permissions.create_group('spectator')
-- spectator_permissions.set_allows_action(defines.input_action.start_walking,false)
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
Autostash.insert_into_furnace(true)
-- Autostash.insert_into_wagon(true)
Autostash.bottom_button(true)
BottomFrame.reset()
BottomFrame.activate_custom_buttons(true)
2021-10-13 15:56:49 +02:00
-- BottomFrame.bottom_right(true)
2021-10-13 10:21:53 +02:00
local mgs = game.surfaces['nauvis'].map_gen_settings
mgs.width = 16
mgs.height = 16
game.surfaces['nauvis'].map_gen_settings = mgs
game.surfaces['nauvis'].clear()
game.create_surface('piratedev1', Common.default_map_gen_settings(100, 100))
2022-03-16 17:01:50 +02:00
game.surfaces['piratedev1'].clear()
2021-10-13 10:21:53 +02:00
Common.init_game_settings(Balance.technology_price_multiplier)
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
global_memory.active_crews_cap = Common.active_crews_cap
global_memory.minimum_capacity_slider_value = Common.minimum_capacity_slider_value
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
Surfaces.Lobby.create_starting_dock_surface()
local lobby = game.surfaces[CoreData.lobby_surface_name]
game.forces.player.set_spawn_position(Common.lobby_spawnpoint, lobby)
game.forces.player.character_running_speed_modifier = Balance.base_extra_character_speed
2022-03-19 23:20:55 +02:00
game.create_force('environment')
2021-10-13 10:21:53 +02:00
for id = 1, 3, 1 do
2022-03-19 23:20:55 +02:00
game.create_force(string.format('enemy-%03d', id))
game.create_force(string.format('ancient-friendly-%03d', id))
game.create_force(string.format('ancient-hostile-%03d', id))
2021-10-13 10:21:53 +02:00
local crew_force = game.create_force(string.format('crew-%03d', id))
Crew.reset_crew_and_enemy_force(id)
crew_force.research_queue_enabled = true
end
-- Delay.global_add(Delay.global_enum.PLACE_LOBBY_JETTY_AND_BOATS)
Task.set_timeout_in_ticks(2, jetty_delayed, {})
2022-02-26 20:25:48 +02:00
if _DEBUG then
game.print('Debug mode on. Use /go to get started (sometimes crashes)')
end
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
end
local event = require 'utils.event'
event.on_init(on_init)
local function crew_tick()
local memory = Memory.get_crew_memory()
local destination = Common.current_destination()
local tick = game.tick
TickFunctions.boat_movement_tick(5) --arguments are tick intervals
-- TickFunctions.parrot_tick(5)
if tick % 10 == 0 then
TickFunctions.prevent_disembark(10)
TickFunctions.prevent_unbarreling_off_ship(10)
end
if memory.age and memory.overworldx and memory.overworldx > 0 then
memory.age = memory.age + 5
end
if memory.real_age then
memory.real_age = memory.real_age + 5
end
if tick % 60 == 0 then
TickFunctions.captain_warn_afk(60)
end
if tick % Common.loading_interval == 0 then
TickFunctions.loading_update(Common.loading_interval)
end
if tick % 5 == 0 then
TickFunctions.quest_progress_tick(5)
end
2022-02-27 18:42:25 +02:00
if tick % 5 == 0 then
TickFunctions.strobe_player_colors(5)
2022-02-26 20:25:48 +02:00
end
2021-10-13 10:21:53 +02:00
if tick % 10 == 0 then
TickFunctions.shop_ratelimit_tick(10)
end
if tick % 30 == 0 then
TickFunctions.silo_update(30)
end
2022-02-24 21:39:03 +02:00
if tick % 60 == 0 then
TickFunctions.ship_deplete_fuel(60)
end
2021-10-13 10:21:53 +02:00
if tick % 10 == 0 then
TickFunctions.pick_up_tick(10)
end
if tick % 60 == 0 then
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING then
TickFunctions.crowsnest_natural_move(120)
end
end
if tick % 60 == 15 or tick % 60 == 45 then
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING then
TickFunctions.overworld_check_collisions(120)
end
end
if tick % 60 == 30 then
if memory.boat and memory.boat.state == Structures.Boats.enum_state.ATSEA_SAILING then
TickFunctions.crowsnest_steer(120)
end
end
if tick % 60 == 0 then
TickFunctions.slower_boat_tick(60)
end
if tick % 10 == 0 then
TickFunctions.update_boat_stored_resources(10)
end
2022-03-13 03:44:32 +02:00
if tick % 10 == 0 then
TickFunctions.covered_requirement_check(10)
2021-10-13 10:21:53 +02:00
end
if tick % 30 == 0 then
TickFunctions.buried_treasure_check(30)
end
if tick % 60 == 0 then
TickFunctions.raft_raids(60)
end
2022-03-04 19:57:58 +02:00
if tick % 60 == 0 then
TickFunctions.place_cached_structures(60)
2021-10-13 10:21:53 +02:00
end
if tick % 240 == 0 then
TickFunctions.check_all_spawners_dead(240)
end
if tick % 60 == 0 then
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
if destination.dynamic_data.timer then
destination.dynamic_data.timer = destination.dynamic_data.timer + 1
end
if memory.captain_acceptance_timer then
memory.captain_acceptance_timer = memory.captain_acceptance_timer - 1
if memory.captain_acceptance_timer == 0 then
Roles.assign_captain_based_on_priorities()
end
end
2022-03-09 01:36:03 +02:00
if memory.captain_accrued_time_data and memory.playerindex_captain and memory.overworldx and memory.overworldx > 0 and memory.overworldx < CoreData.victory_x then --only count time in the 'main game'
2021-10-13 15:56:49 +02:00
local player = game.players[memory.playerindex_captain]
if player and player.name then
if (not memory.captain_accrued_time_data[player.name]) then memory.captain_accrued_time_data[player.name] = 0 end
memory.captain_accrued_time_data[player.name] = memory.captain_accrued_time_data[player.name] + 1
end
2021-10-13 10:21:53 +02:00
end
if destination.dynamic_data.time_remaining and destination.dynamic_data.time_remaining > 0 then
destination.dynamic_data.time_remaining = destination.dynamic_data.time_remaining - 1
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
if destination.dynamic_data.time_remaining == 0 then
if memory.boat and memory.boat.surface_name then
local surface_name_decoded = Surfaces.SurfacesCommon.decode_surface_name(memory.boat.surface_name)
local type = surface_name_decoded.type
if type == Surfaces.enum.ISLAND then
2022-03-12 13:51:11 +02:00
Progression.retreat_from_island(false)
2021-10-13 10:21:53 +02:00
elseif type == Surfaces.enum.DOCK then
2022-03-12 13:51:11 +02:00
Progression.undock_from_dock(false)
2021-10-13 10:21:53 +02:00
end
end
end
end
end
2022-02-28 18:36:46 +02:00
if tick % 240 == 0 then
if memory.max_players_recorded then
local count_now = #Common.crew_get_crew_members()
if count_now and count_now > memory.max_players_recorded then
memory.max_players_recorded = count_now
end
end
end
2022-03-04 19:57:58 +02:00
2022-03-07 11:50:25 +02:00
if tick % 240 == 0 then
TickFunctions.Kraken_Destroyed_Backup_check(240)
end
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
if tick % 300 == 0 then
TickFunctions.periodic_free_resources(300)
end
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
if tick % 30 == 0 then
ClassTickFunctions.update_character_properties(30)
end
2022-03-19 23:20:55 +02:00
2022-03-08 00:00:14 +02:00
if tick % 30 == 0 then
ClassTickFunctions.class_renderings(30)
2021-10-13 10:21:53 +02:00
end
if tick % 120 == 0 then
Ai.Tick_actions(120)
end
if tick % 240 == 0 then
TickFunctions.LOS_tick(240)
end
2022-03-19 23:20:55 +02:00
2022-03-11 18:46:02 +02:00
if tick % 420 == 0 then
ClassTickFunctions.class_rewards_tick(420)
2022-03-07 11:50:25 +02:00
end
2021-10-13 10:21:53 +02:00
if tick % 300 == 0 then
TickFunctions.update_recentcrewmember_list(300)
end
if tick % 1800 == 0 then
TickFunctions.transfer_pollution(1800)
end
2022-03-09 23:39:47 +02:00
if tick % 3600 == 0 then
TickFunctions.prune_offline_characters_list(3600)
2022-03-09 01:36:03 +02:00
end
2021-10-13 10:21:53 +02:00
-- if tick % (60*60*60) == 0 then
-- Parrot.parrot_say_tip()
-- end
if memory.crew_disband_tick then
if memory.crew_disband_tick < tick then
memory.crew_disband_tick = nil
Crew.disband_crew()
end
return
end
end
local function global_tick()
local global_memory = Memory.get_global_memory()
local tick = game.tick
if tick % 60 == 0 then
TickFunctions.update_players_second()
end
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
if tick % 30 == 0 then
for _, player in pairs(game.connected_players) do
-- figure out which crew this is about:
local crew_id = tonumber(string.sub(player.force.name, -3, -1)) or 0
Memory.set_working_id(crew_id)
Roles.update_tags(player)
end
end
for _, id in pairs(global_memory.crew_active_ids) do
Memory.set_working_id(id)
crew_tick()
end
TickFunctions.update_player_guis(5)
end
event.on_nth_tick(5, global_tick)
local function instatick()
local global_memory = Memory.get_global_memory()
for _, id in pairs(global_memory.crew_active_ids) do
Memory.set_working_id(id)
2022-03-29 01:36:38 +02:00
TickFunctions.minimap_jam(1)
2021-10-13 10:21:53 +02:00
TickFunctions.silo_insta_update()
end
end
event.on_nth_tick(1, instatick)
----- FOR BUGFIXING HARD CRASHES (segfaults) ------
2022-03-09 01:36:03 +02:00
-- often, segfaults are due to an error during chunk generation (as of 1.1.0 or so, anyway.)
2021-10-13 10:21:53 +02:00
-- to help debug, comment this out, and instead use the command /chnk to generate some chunks manually
event.add(defines.events.on_chunk_generated, Interface.event_on_chunk_generated)
2022-02-27 01:33:19 +02:00
----- FOR DESYNC BUGFIXING -----
2022-03-09 01:36:03 +02:00
local gMeta = getmetatable(_ENV)
if not gMeta then
gMeta = {}
setmetatable(_ENV, gMeta)
end
gMeta.__newindex = function(_, n, v)
log('Desync warning: attempt to write to undeclared var ' .. n)
global[n] = v
end
gMeta.__index = function(_, n)
return global[n]
end
2021-10-13 10:21:53 +02:00
return Public