diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 7e71feb7..79da9bcf 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -109,14 +109,12 @@ local function do_turret_energy() for index = 1, #power_sources do local ps_data = power_sources[index] - if not (ps_data or ps_data.valid) then + if not (ps_data and ps_data.valid) then fast_remove(power_sources, index) return end - if ps_data and ps_data.valid then - ps_data.energy = 0xfffff - end + ps_data.energy = 0xfffff end end diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index 7fddc058..4e7dfcac 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -315,10 +315,7 @@ local function kick_players_from_surface(ic, car) if validate_entity(main_surface) then for _, e in pairs(car.surface.find_entities_filtered({area = car.area})) do if validate_entity(e) and e.name == 'character' and e.player then - e.player.teleport( - main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), - main_surface - ) + e.player.teleport(main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), main_surface) end end end @@ -360,10 +357,7 @@ local function kick_player_from_surface(ic, player, target) if p then target.teleport(p, car.entity.surface) else - target.teleport( - main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), - main_surface - ) + target.teleport(main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), main_surface) end target.print('You were kicked out of ' .. player.name .. ' vehicle.', Color.warning) end @@ -590,10 +584,7 @@ function Public.save_car(ic, event) } Task.set_timeout_in_ticks(10, remove_car, params) if ic.restore_on_theft then - local e = - player.surface.create_entity( - {name = car.name, position = position, force = player.force, create_build_effect_smoke = false} - ) + local e = player.surface.create_entity({name = car.name, position = position, force = player.force, create_build_effect_smoke = false}) e.health = health restore_surface(ic, p, e) else @@ -932,13 +923,16 @@ function Public.use_door_with_entity(ic, player, door) end function Public.item_transfer(ic) - for _, car in pairs(ic.cars) do - if validate_entity(car.entity) then - if car.transfer_entities then - for k, e in pairs(car.transfer_entities) do - if validate_entity(e) then - transfer_functions[e.name](car, e) - end + local car + ic.current_car_index, car = next(ic.cars, ic.current_car_index) + if not car then + return + end + if validate_entity(car.entity) then + if car.transfer_entities then + for k, e in pairs(car.transfer_entities) do + if validate_entity(e) then + transfer_functions[e.name](car, e) end end end diff --git a/maps/mountain_fortress_v3/ic/main.lua b/maps/mountain_fortress_v3/ic/main.lua index 5654ffaa..ca43de61 100644 --- a/maps/mountain_fortress_v3/ic/main.lua +++ b/maps/mountain_fortress_v3/ic/main.lua @@ -81,7 +81,7 @@ local function on_tick() local ic = IC.get() local tick = game.tick - if tick % 60 == 0 then + if tick % 10 == 1 then Functions.item_transfer(ic) end diff --git a/maps/mountain_fortress_v3/ic/table.lua b/maps/mountain_fortress_v3/ic/table.lua index c47d2ded..bd0168a4 100644 --- a/maps/mountain_fortress_v3/ic/table.lua +++ b/maps/mountain_fortress_v3/ic/table.lua @@ -30,6 +30,7 @@ function Public.reset() this.restore_on_theft = false this.doors = {} this.cars = {} + this.current_car_index = nil this.renders = {} this.saved_surfaces = {} this.allowed_surface = 'nauvis' diff --git a/maps/mountain_fortress_v3/icw/functions.lua b/maps/mountain_fortress_v3/icw/functions.lua index fad05db2..c0a3e58f 100644 --- a/maps/mountain_fortress_v3/icw/functions.lua +++ b/maps/mountain_fortress_v3/icw/functions.lua @@ -36,10 +36,7 @@ local function kick_players_from_surface(wagon) if validate_entity(main_surface) then for _, e in pairs(wagon.surface.find_entities_filtered({area = wagon.area})) do if validate_entity(e) and e.name == 'character' and e.player then - e.player.teleport( - main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), - main_surface - ) + e.player.teleport(main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), main_surface) end end end @@ -734,10 +731,7 @@ local function move_room_to_train(icw, train, wagon) train.top_y = destination_area.right_bottom.y - if - destination_area.left_top.x == wagon.area.left_top.x and destination_area.left_top.y == wagon.area.left_top.y and - wagon.surface.name == train.surface.name - then + if destination_area.left_top.x == wagon.area.left_top.x and destination_area.left_top.y == wagon.area.left_top.y and wagon.surface.name == train.surface.name then return end kick_players_from_surface(wagon) @@ -842,15 +836,15 @@ function Public.reconstruct_all_trains(icw) end function Public.item_transfer(icw) - for _, wagon in pairs(icw.wagons) do - if not validate_entity(wagon.entity) then - return - end - if wagon.transfer_entities then - for k, e in pairs(wagon.transfer_entities) do - if validate_entity(e) then - transfer_functions[e.name](wagon, e) - end + local wagon + icw.current_wagon_index, wagon = next(icw.wagons, icw.current_wagon_index) + if not wagon then + return + end + if validate_entity(wagon.entity) and wagon.transfer_entities then + for k, e in pairs(wagon.transfer_entities) do + if validate_entity(e) then + transfer_functions[e.name](wagon, e) end end end diff --git a/maps/mountain_fortress_v3/icw/main.lua b/maps/mountain_fortress_v3/icw/main.lua index 784dcf91..2c33c891 100644 --- a/maps/mountain_fortress_v3/icw/main.lua +++ b/maps/mountain_fortress_v3/icw/main.lua @@ -95,7 +95,7 @@ local function on_tick() local icw = ICW.get() local tick = game.tick - if tick % 60 == 0 then + if tick % 10 == 1 then Functions.item_transfer(icw) end if tick % 240 == 0 then diff --git a/maps/mountain_fortress_v3/icw/table.lua b/maps/mountain_fortress_v3/icw/table.lua index 045fb6de..743edd33 100644 --- a/maps/mountain_fortress_v3/icw/table.lua +++ b/maps/mountain_fortress_v3/icw/table.lua @@ -23,6 +23,7 @@ function Public.reset() end this.doors = {} this.wagons = {} + this.current_wagon_index = nil this.trains = {} this.players = {} this.surfaces = {}