Skip to content

Commit

Permalink
Mtn: fix locomotive issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkiz committed Nov 11, 2024
1 parent 81a167f commit fa4db38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion maps/mountain_fortress_v3/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,7 @@ function Public.on_player_changed_position(event)
if not loco_surface or not loco_surface.valid then
return
end
if player.surface.index == loco_surface.index then
if player.character ~= nil and player.character.surface.index == loco_surface.index then
local map_gen = loco_surface.map_gen_settings
if player.position.y > map_gen.height then player.set_controller { type = 1, character = player.character } end
if player.position.y < (-map_gen.height / 2) then player.set_controller { type = 1, character = player.character } end
Expand Down
16 changes: 13 additions & 3 deletions maps/mountain_fortress_v3/icw/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,12 @@ function Public.reconstruct_all_trains(icw)
if not validate_entity(wagon.entity) then
icw.wagons[unit_number] = nil
Public.request_reconstruction(icw)
goto cont
return
end

local locomotive = WPT.get('locomotive')
if not (locomotive and locomotive.valid) then
return
end

if not wagon.surface then
Expand All @@ -981,8 +986,13 @@ function Public.reconstruct_all_trains(icw)
end
local carriages = wagon.entity.train.carriages

Public.construct_train(icw, wagon.entity, carriages)
::cont::
for _, carriage in pairs(carriages) do
if not icw.wagons[carriage.unit_number] then
Public.create_wagon(icw, carriage)
end
end

Public.construct_train(icw, locomotive, carriages)
end
delete_empty_surfaces(icw)
return true
Expand Down

0 comments on commit fa4db38

Please sign in to comment.