mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Rename body place to controller location
Review asked for location and controller over place and body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
babc210a38
commit
2fcf3f10c7
2 files changed
+28
-28
No files matched your search
@@ -77,8 +77,8 @@ The greatly simplified data flow is as follows:
|
|||||||
7. Scenario displays and updates a progress bar as each chunk is received.
|
7. Scenario displays and updates a progress bar as each chunk is received.
|
||||||
8. Once all chunks have loaded the player's synced inventory is recreated from the data and the player can start playing.
|
8. Once all chunks have loaded the player's synced inventory is recreated from the data and the player can start playing.
|
||||||
|
|
||||||
While the player is a spectator waiting for the data they can't walk away, and their character comes back where it stood.
|
While the player is a spectator waiting for the data they can't walk away, and their controller comes back where it was.
|
||||||
A mod that teleports the spectator more than 4 tiles, or to another surface, moves where the character comes back to.
|
A mod that teleports the spectator more than 4 tiles, or to another surface, moves where the controller comes back to.
|
||||||
|
|
||||||
When the player leaves the inventory is uploaded if it's a synced inventory and the exclusive access the scenario script holds is released.
|
When the player leaves the inventory is uploaded if it's a synced inventory and the exclusive access the scenario script holds is released.
|
||||||
Should an error occur during this process the player is given the option to use a temporary inventory instead, which will be merged back into the synced inventory the next time the sync succeeds on that instance.
|
Should an error occur during this process the player is given the option to use a temporary inventory instead, which will be merged back into the synced inventory the next time the sync succeeds on that instance.
|
||||||
|
|||||||
@@ -73,17 +73,17 @@ local function remove_inventory_bonus_raise(script_data, player_name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Where the player's body stands, in the shape restore_position takes
|
-- Where the player's controller is, in the shape restore_position takes
|
||||||
local function body_place(player)
|
local function controller_location(player)
|
||||||
local place = { vehicle = player.driving and player.vehicle or nil }
|
local location = { vehicle = player.driving and player.vehicle or nil }
|
||||||
if v2_remote_controller then
|
if v2_remote_controller then
|
||||||
place.surface = player.physical_surface
|
location.surface = player.physical_surface
|
||||||
place.position = player.physical_position
|
location.position = player.physical_position
|
||||||
else
|
else
|
||||||
place.surface = player.surface
|
location.surface = player.surface
|
||||||
place.position = player.position
|
location.position = player.position
|
||||||
end
|
end
|
||||||
return place
|
return location
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Turn a synced player into a spectator while their player data is downloaded or applied, if this instance syncs
|
-- Turn a synced player into a spectator while their player data is downloaded or applied, if this instance syncs
|
||||||
@@ -106,10 +106,10 @@ local function spectate(player, player_record, record)
|
|||||||
-- Store original position to teleport back to. Only once per record: a rejoin while a prefetched copy is held
|
-- Store original position to teleport back to. Only once per record: a rejoin while a prefetched copy is held
|
||||||
-- spectates again, and the spectator's position then isn't where the body stood
|
-- spectates again, and the spectator's position then isn't where the body stood
|
||||||
if record.position == nil then
|
if record.position == nil then
|
||||||
local here = body_place(player)
|
local location = controller_location(player)
|
||||||
record.surface = here.surface
|
record.surface = location.surface
|
||||||
record.position = here.position
|
record.position = location.position
|
||||||
record.vehicle = here.vehicle
|
record.vehicle = location.vehicle
|
||||||
end
|
end
|
||||||
|
|
||||||
save_local_controller(player, player_record, record.components)
|
save_local_controller(player, player_record, record.components)
|
||||||
@@ -132,8 +132,8 @@ local function keep_body_place(player_record, record)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Where the body goes back when sync code gives it back, if it took it
|
-- Where the controller goes back when sync code gives it back, if it took it
|
||||||
local function body_place_of(script_data, player_name)
|
local function restore_location(script_data, player_name)
|
||||||
for _, downloads in ipairs({ script_data.active_downloads, script_data.finished_downloads }) do
|
for _, downloads in ipairs({ script_data.active_downloads, script_data.finished_downloads }) do
|
||||||
local record = downloads[player_name]
|
local record = downloads[player_name]
|
||||||
if record and record.position ~= nil then
|
if record and record.position ~= nil then
|
||||||
@@ -506,7 +506,7 @@ function player_sync.sync_player(acquire_response)
|
|||||||
and player.controller_type == defines.controllers.character
|
and player.controller_type == defines.controllers.character
|
||||||
then
|
then
|
||||||
save_local_controller(player, player_record, player_record.components)
|
save_local_controller(player, player_record, player_record.components)
|
||||||
player_record.body_place = body_place(player)
|
player_record.body_place = controller_location(player)
|
||||||
local character = player.character
|
local character = player.character
|
||||||
player.set_controller({ type = defines.controllers.spectator })
|
player.set_controller({ type = defines.controllers.spectator })
|
||||||
if character then character.destroy() end
|
if character then character.destroy() end
|
||||||
@@ -587,27 +587,27 @@ player_sync.events[defines.events.on_player_joined_game] = function(event)
|
|||||||
script_data.active_uploads[player.name] = nil
|
script_data.active_uploads[player.name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- A spectator whose body sync code took stays where the body stood. A jump of more than 4 tiles, or to another surface,
|
-- A spectator whose controller sync code took stays at its restore location. A jump of more than 4 tiles, or to another
|
||||||
-- is another mod's teleport and moves where the body goes back instead.
|
-- surface, is another mod's teleport and moves the restore location instead.
|
||||||
player_sync.events[defines.events.on_player_changed_position] = function(event)
|
player_sync.events[defines.events.on_player_changed_position] = function(event)
|
||||||
local player = assert(game.get_player(event.player_index))
|
local player = assert(game.get_player(event.player_index))
|
||||||
if player.controller_type ~= defines.controllers.spectator then
|
if player.controller_type ~= defines.controllers.spectator then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local place = body_place_of(get_script_data(), player.name)
|
local location = restore_location(get_script_data(), player.name)
|
||||||
if not place then
|
if not location then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local position = player.position --[[@as MapPosition.struct]]
|
local position = player.position --[[@as MapPosition.struct]]
|
||||||
local dx = position.x - place.position.x
|
local dx = position.x - location.position.x
|
||||||
local dy = position.y - place.position.y
|
local dy = position.y - location.position.y
|
||||||
if player.surface == place.surface and dx * dx + dy * dy <= 16 then
|
if player.surface == location.surface and dx * dx + dy * dy <= 16 then
|
||||||
player.teleport(place.position, place.surface)
|
player.teleport(location.position, location.surface)
|
||||||
else
|
else
|
||||||
place.surface = player.surface
|
location.surface = player.surface
|
||||||
place.position = position
|
location.position = position
|
||||||
place.vehicle = nil
|
location.vehicle = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user