diff --git a/maps/mountain_fortress_v2/locomotive.lua b/maps/mountain_fortress_v2/locomotive.lua index 8171d253..2a926b9e 100644 --- a/maps/mountain_fortress_v2/locomotive.lua +++ b/maps/mountain_fortress_v2/locomotive.lua @@ -35,7 +35,6 @@ function Public.locomotive_spawn(surface, position) }) global.locomotive.color = {0, 255, 0} - global.locomotive.minable = false global.locomotive_cargo.minable = false for y = -1, 0, 0.05 do @@ -45,6 +44,7 @@ function Public.locomotive_spawn(surface, position) Immersive_cargo_wagons.register_wagon(global.locomotive) local wagon = Immersive_cargo_wagons.register_wagon(global.locomotive_cargo) + wagon.entity_count = 999 local surface = wagon.surface local center_position = {x = wagon.area.left_top.x + (wagon.area.right_bottom.x - wagon.area.left_top.x) * 0.5, y = wagon.area.left_top.y + (wagon.area.right_bottom.y - wagon.area.left_top.y) * 0.5} diff --git a/modules/immersive_cargo_wagons/functions.lua b/modules/immersive_cargo_wagons/functions.lua index 4478d82d..17d6ddf7 100644 --- a/modules/immersive_cargo_wagons/functions.lua +++ b/modules/immersive_cargo_wagons/functions.lua @@ -7,7 +7,7 @@ local table_remove = table.remove local math_round = math.round local math_random = math.random -local function request_reconstruction(icw) +function Public.request_reconstruction(icw) icw.rebuild_tick = game.tick + 30 end @@ -162,7 +162,7 @@ function Public.kill_wagon(icw, entity) surface.set_tiles({{name = "out-of-map", position = tile.position}}, true) end icw.wagons[entity.unit_number] = nil - request_reconstruction(icw) + Public.request_reconstruction(icw) end function Public.create_room_surface(icw, unit_number) @@ -304,7 +304,7 @@ function Public.create_wagon(icw, created_entity) entity_count = 0, } Public.create_wagon_room(icw, icw.wagons[created_entity.unit_number]) - request_reconstruction(icw) + Public.request_reconstruction(icw) return icw.wagons[created_entity.unit_number] end diff --git a/modules/immersive_cargo_wagons/main.lua b/modules/immersive_cargo_wagons/main.lua index 4d9bcfdd..5e5372dd 100644 --- a/modules/immersive_cargo_wagons/main.lua +++ b/modules/immersive_cargo_wagons/main.lua @@ -80,6 +80,8 @@ local function on_gui_closed(event) local entity = event.entity if not entity then return end if not entity.valid then return end + if not entity.unit_number then return end + if not icw.wagons[entity.unit_number] then return end Functions.kill_minimap(game.players[event.player_index]) end @@ -97,6 +99,10 @@ local function on_player_died(event) Functions.kill_minimap(game.players[event.player_index]) end +local function on_train_created(event) + Functions.request_reconstruction(icw) +end + local function on_tick() local tick = game.tick if tick % 60 == 0 then Functions.item_transfer(icw) end @@ -125,6 +131,7 @@ 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_created, on_player_created)