mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-06 00:23:49 +02:00
fix for rejoining players with missing surface
This commit is contained in:
parent
faa3fd9317
commit
fe1601bc57
@ -47,6 +47,9 @@ local function connect_power_pole(entity, wagon_area_left_top_y)
|
||||
end
|
||||
|
||||
local function equal_fluid(source_tank, target_tank)
|
||||
if not source_tank.valid then return end
|
||||
if not target_tank.valid then return end
|
||||
|
||||
local source_fluid = source_tank.fluidbox[1]
|
||||
if not source_fluid then return end
|
||||
|
||||
@ -199,6 +202,8 @@ local function get_player_data(icw, player)
|
||||
if icw.players[player.index] then return player_data end
|
||||
|
||||
icw.players[player.index] = {
|
||||
surface = 1,
|
||||
fallback_surface = 1,
|
||||
zoom = 0.30,
|
||||
map_size = 360,
|
||||
}
|
||||
@ -419,6 +424,9 @@ function Public.use_cargo_wagon_door(icw, player, door)
|
||||
if wagons[door.unit_number] then wagon = wagons[door.unit_number] end
|
||||
if not wagon then return end
|
||||
|
||||
player_data.fallback_surface = wagon.entity.surface.index
|
||||
player_data.fallback_position = {wagon.entity.position.x, wagon.entity.position.y}
|
||||
|
||||
if wagon.entity.surface.name ~= player.surface.name then
|
||||
local surface = wagon.entity.surface
|
||||
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
|
||||
@ -429,6 +437,7 @@ function Public.use_cargo_wagon_door(icw, player, door)
|
||||
player_data.state = 2
|
||||
player.driving = true
|
||||
Public.kill_minimap(player)
|
||||
player_data.surface = surface.index
|
||||
else
|
||||
local surface = wagon.surface
|
||||
local area = wagon.area
|
||||
@ -445,6 +454,7 @@ function Public.use_cargo_wagon_door(icw, player, door)
|
||||
else
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,6 +67,25 @@ local function on_player_driving_changed_state(event)
|
||||
Functions.use_cargo_wagon_door(icw, player, event.entity)
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player_data = icw.players[event.player_index]
|
||||
if not player_data then return end
|
||||
|
||||
local surface = game.surfaces[player_data.surface]
|
||||
if surface and surface.valid then return end
|
||||
|
||||
local fallback_surface = game.surfaces[player_data.fallback_surface]
|
||||
if not fallback_surface or not fallback_surface.valid then return end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local p = fallback_surface.find_non_colliding_position("character", player_data.fallback_position, 32, 0.5)
|
||||
if p then
|
||||
player.teleport(p, fallback_surface)
|
||||
else
|
||||
player.teleport(player.force.get_spawn_position(fallback_surface), fallback_surface)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_left_game(event)
|
||||
Functions.kill_minimap(game.players[event.player_index])
|
||||
end
|
||||
@ -127,18 +146,19 @@ function Public.register_wagon(wagon_entity, delay_surface)
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
Event.add(defines.events.on_train_created, on_train_created)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
Event.add(defines.events.on_player_died, on_player_died)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(defines.events.on_gui_closed, on_gui_closed)
|
||||
Event.add(defines.events.on_gui_opened, on_gui_opened)
|
||||
Event.add(defines.events.on_player_died, on_player_died)
|
||||
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
Event.add(defines.events.on_train_created, on_train_created)
|
||||
|
||||
return Public
|
Loading…
Reference in New Issue
Block a user