Skip to content

Commit

Permalink
compat: The factorissimo buildings now count as maraxsis surfaces by …
Browse files Browse the repository at this point in the history
…the mod.
  • Loading branch information
notnotmelon committed Dec 13, 2024
1 parent 2e17707 commit d421da9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 34 deletions.
7 changes: 2 additions & 5 deletions control.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
_G.maraxsis = require "scripts.constants"
require "lib.lib"

maraxsis.prototypes = {
[maraxsis.MARAXSIS_SURFACE_NAME] = require "scripts.map-gen.surfaces.maraxsis",
[maraxsis.TRENCH_SURFACE_NAME] = require "scripts.map-gen.surfaces.maraxsis-trench",
}

require "scripts.map-gen.surfaces.maraxsis"
require "scripts.map-gen.surfaces.maraxsis-trench"
require "scripts.submarine"
require "scripts.drowning"
require "scripts.nightvision"
Expand Down
8 changes: 2 additions & 6 deletions scripts/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ local MARAXSIS_SURFACE_NAME = "maraxsis"
local MARAXSIS_SURFACES = { -- all surfaces with water mechanics
[TRENCH_SURFACE_NAME] = true,
[MARAXSIS_SURFACE_NAME] = true,
}

local MARAXSIS_GET_OPPOSITE_SURFACE = {
[TRENCH_SURFACE_NAME] = MARAXSIS_SURFACE_NAME,
[MARAXSIS_SURFACE_NAME] = TRENCH_SURFACE_NAME,
["maraxsis-factory-floor"] = true,
["maraxsis-trench-factory-floor"] = true,
}

local MARAXSIS_SAND_EXTRACTORS = {
Expand Down Expand Up @@ -63,7 +60,6 @@ return {
TRENCH_SURFACE_NAME = TRENCH_SURFACE_NAME,
MARAXSIS_SURFACE_NAME = MARAXSIS_SURFACE_NAME,
MARAXSIS_SURFACES = MARAXSIS_SURFACES,
MARAXSIS_GET_OPPOSITE_SURFACE = MARAXSIS_GET_OPPOSITE_SURFACE,
MARAXSIS_SAND_EXTRACTORS = MARAXSIS_SAND_EXTRACTORS,
SUBMARINE_FUEL_SOURCES = SUBMARINE_FUEL_SOURCES,
DOME_DISABLEABLE_TYPES = DOME_DISABLEABLE_TYPES,
Expand Down
9 changes: 0 additions & 9 deletions scripts/map-gen/surfaces/maraxsis-trench.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ maraxsis.on_event(defines.events.on_surface_created, function(event)
surface.map_gen_settings = mgs
end)

local function get_surface()
return game.planets[maraxsis.TRENCH_SURFACE_NAME].create_surface()
end

maraxsis.on_event(defines.events.on_script_trigger_effect, function(event)
if event.effect_id ~= "maraxsis-trench-wall-created" then return end

Expand All @@ -44,8 +40,3 @@ maraxsis.on_event(defines.events.on_space_platform_changed_state, function(event
game.print {"maraxsis.invalid-space-platform", platform.name}
platform.destroy(0)
end)

return {
get_surface = get_surface,
type = "maraxsis-trench",
}
11 changes: 1 addition & 10 deletions scripts/map-gen/surfaces/maraxsis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end)
maraxsis.on_event(defines.events.on_chunk_generated, function(event)
local surface = event.surface
local surface_name = surface.name
if surface_name ~= maraxsis.MARAXSIS_SURFACE_NAME and surface_name ~= maraxsis.TRENCH_SURFACE_NAME then return end
if not maraxsis.MARAXSIS_SURFACES[surface_name] then return end

local chunkpos = event.position
local x = chunkpos.x * 32 + 16
Expand All @@ -21,10 +21,6 @@ maraxsis.on_event(defines.events.on_chunk_generated, function(event)
fancy_water.minable = false
end)

local function get_surface()
return game.planets[maraxsis.MARAXSIS_SURFACE_NAME].create_surface()
end

local function cliff_created(event)
local old_cliff = event.target_entity
local surface = old_cliff.surface
Expand Down Expand Up @@ -99,8 +95,3 @@ maraxsis.on_event(defines.events.on_script_trigger_effect, function(event)
coral_created(event)
end
end)

return {
type = "maraxsis",
get_surface = get_surface,
}
12 changes: 8 additions & 4 deletions scripts/submarine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,22 @@ local function enter_submarine(player, submarine)
end
maraxsis.register_delayed_function("enter_submarine", enter_submarine)

local OPPOSITE_SURFACE = {
[maraxsis.TRENCH_SURFACE_NAME] = maraxsis.MARAXSIS_SURFACE_NAME,
[maraxsis.MARAXSIS_SURFACE_NAME] = maraxsis.TRENCH_SURFACE_NAME,
}

---determines if the submarine should rise to the surface or sink to the bottom. returns nil if surface transfer is impossible
---@param submarine LuaEntity
---@return LuaSurface?, MapPosition?
local function determine_submerge_direction(submarine)
local position = submarine.position
local surface = submarine.surface
local surface_name = surface.name
local prototype = maraxsis.prototypes[surface_name]
if not prototype then error("no prototype for surface " .. surface_name) end

local opposite_surface_name = maraxsis.MARAXSIS_GET_OPPOSITE_SURFACE[surface_name]
local target_surface = maraxsis.prototypes[opposite_surface_name].get_surface()
local opposite_surface_name = OPPOSITE_SURFACE[surface_name]
if not opposite_surface_name then return end
local target_surface = game.planets[opposite_surface_name].create_surface()

if surface_name == maraxsis.MARAXSIS_SURFACE_NAME then
local tile_at_surface = surface.get_tile(position)
Expand Down

0 comments on commit d421da9

Please sign in to comment.