mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-17 20:58:13 +02:00
remove laggy function
This commit is contained in:
parent
36f080a33b
commit
ac6a0b2171
@ -532,18 +532,22 @@ local function construct_doors(ic, car)
|
||||
|
||||
local main_tile_name = 'black-refined-concrete'
|
||||
|
||||
for _, x in pairs({area.left_top.x - 1, area.right_bottom.x + 0.5}) do
|
||||
for _, x in pairs({area.left_top.x - 1.5, area.right_bottom.x + 1.5}) do
|
||||
local p
|
||||
if car.name == 'car' then
|
||||
p = {x, area.left_top.y + 10}
|
||||
p = {x = x, y = area.left_top.y + 10}
|
||||
else
|
||||
p = {x, area.left_top.y + 20}
|
||||
p = {x = x, y = area.left_top.y + 20}
|
||||
end
|
||||
if p.x < 0 then
|
||||
surface.set_tiles({{name = main_tile_name, position = {x = p.x + 0.5, y = p.y}}}, true)
|
||||
else
|
||||
surface.set_tiles({{name = main_tile_name, position = {x = p.x - 1, y = p.y}}}, true)
|
||||
end
|
||||
surface.set_tiles({{name = main_tile_name, position = p}}, true)
|
||||
local e =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'player-port',
|
||||
name = 'car',
|
||||
position = {x, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)},
|
||||
force = 'neutral',
|
||||
create_build_effect_smoke = false
|
||||
@ -552,6 +556,7 @@ local function construct_doors(ic, car)
|
||||
e.destructible = false
|
||||
e.minable = false
|
||||
e.operable = false
|
||||
e.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 1})
|
||||
ic.doors[e.unit_number] = car.entity.unit_number
|
||||
car.doors[#car.doors + 1] = e
|
||||
end
|
||||
@ -815,9 +820,11 @@ function Public.create_car(ic, event)
|
||||
local name, mined = get_player_entity(ic, player, ce)
|
||||
|
||||
if
|
||||
name == 'tank' and ce.name == 'car' and not mined or name == 'car' and ce.name == 'car' and not mined or
|
||||
name == 'car' and ce.name == 'tank' and not mined or
|
||||
name == 'car' and ce.name == 'car' and not mined or name == 'car' and ce.name == 'tank' and not mined or
|
||||
name == 'tank' and ce.name == 'car' and not mined or
|
||||
name == 'tank' and ce.name == 'tank' and not mined or
|
||||
name == 'spidertron' and ce.name == 'car' and not mined or
|
||||
name == 'spidertron' and ce.name == 'tank' and not mined or
|
||||
name == 'spidertron' and ce.name == 'spidertron' and not mined
|
||||
then
|
||||
return player.print('Multiple vehicles are not supported at the moment.', Color.warning)
|
||||
@ -989,63 +996,6 @@ function Public.infinity_scrap(ic, event, recreate)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.teleport_players_around(ic)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if validate_player(player) then
|
||||
if player.surface.find_entity('player-port', player.position) then
|
||||
local door = player.surface.find_entity('player-port', player.position)
|
||||
if validate_entity(door) then
|
||||
local doors = ic.doors
|
||||
local cars = ic.cars
|
||||
|
||||
local car = false
|
||||
if doors[door.unit_number] then
|
||||
car = cars[doors[door.unit_number]]
|
||||
end
|
||||
if cars[door.unit_number] then
|
||||
car = cars[door.unit_number]
|
||||
end
|
||||
if not car then
|
||||
return
|
||||
end
|
||||
|
||||
local player_data = get_player_data(ic, player)
|
||||
if player_data.state then
|
||||
player_data.state = player_data.state - 1
|
||||
if player_data.state == 0 then
|
||||
player_data.state = nil
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if not validate_entity(car.entity) then
|
||||
return
|
||||
end
|
||||
|
||||
if car.entity.surface.name ~= player.surface.name then
|
||||
if validate_entity(car.entity) and car.owner == player.index then
|
||||
IC_Gui.remove_toolbar(player)
|
||||
car.entity.minable = true
|
||||
end
|
||||
local surface = car.entity.surface
|
||||
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
|
||||
local position = {car.entity.position.x + x_vector, car.entity.position.y}
|
||||
local surface_position = surface.find_non_colliding_position('character', position, 128, 0.5)
|
||||
if car.entity.type == 'car' or car.entity.name == 'spidertron' then
|
||||
player.teleport(surface_position, surface)
|
||||
player_data.state = 2
|
||||
player.driving = true
|
||||
else
|
||||
player.teleport(surface_position, surface)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Public.use_door_with_entity(ic, player, door)
|
||||
local player_data = get_player_data(ic, player)
|
||||
if player_data.state then
|
||||
@ -1088,31 +1038,50 @@ function Public.use_door_with_entity(ic, player, door)
|
||||
player_data.fallback_surface = car.entity.surface.index
|
||||
player_data.fallback_position = {car.entity.position.x, car.entity.position.y}
|
||||
|
||||
local surface = car.surface
|
||||
if validate_entity(car.entity) and car.owner == player.index then
|
||||
IC_Gui.add_toolbar(player)
|
||||
car.entity.minable = false
|
||||
end
|
||||
if car.entity.surface.name == player.surface.name then
|
||||
local surface = car.surface
|
||||
if validate_entity(car.entity) and car.owner == player.index then
|
||||
IC_Gui.add_toolbar(player)
|
||||
car.entity.minable = false
|
||||
end
|
||||
|
||||
if not validate_entity(surface) then
|
||||
return
|
||||
end
|
||||
if not validate_entity(surface) then
|
||||
return
|
||||
end
|
||||
|
||||
local area = car.area
|
||||
local x_vector = door.position.x - player.position.x
|
||||
local position
|
||||
if x_vector > 0 then
|
||||
position = {area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
|
||||
local area = car.area
|
||||
local x_vector = door.position.x - player.position.x
|
||||
local position
|
||||
if x_vector > 0 then
|
||||
position = {area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
|
||||
else
|
||||
position = {area.right_bottom.x - 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
|
||||
end
|
||||
local p = surface.find_non_colliding_position('character', position, 128, 0.5)
|
||||
if p then
|
||||
player.teleport(p, surface)
|
||||
else
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
else
|
||||
position = {area.right_bottom.x - 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
|
||||
if validate_entity(car.entity) and car.owner == player.index then
|
||||
IC_Gui.remove_toolbar(player)
|
||||
car.entity.minable = true
|
||||
end
|
||||
local surface = car.entity.surface
|
||||
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
|
||||
local position = {car.entity.position.x + x_vector, car.entity.position.y}
|
||||
local surface_position = surface.find_non_colliding_position('character', position, 128, 0.5)
|
||||
if car.entity.type == 'car' or car.entity.name == 'spidertron' then
|
||||
player.teleport(surface_position, surface)
|
||||
player_data.state = 2
|
||||
player.driving = true
|
||||
else
|
||||
player.teleport(surface_position, surface)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
end
|
||||
local p = surface.find_non_colliding_position('character', position, 128, 0.5)
|
||||
if p then
|
||||
player.teleport(p, surface)
|
||||
else
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
end
|
||||
|
||||
function Public.item_transfer(ic)
|
||||
|
@ -94,7 +94,6 @@ local function on_tick()
|
||||
local tick = game.tick
|
||||
|
||||
if tick % 60 == 0 then
|
||||
Functions.teleport_players_around(ic)
|
||||
Functions.item_transfer(ic)
|
||||
end
|
||||
|
||||
|
@ -320,13 +320,17 @@ local function construct_wagon_doors(icw, wagon)
|
||||
|
||||
local main_tile_name = 'black-refined-concrete'
|
||||
|
||||
for _, x in pairs({area.left_top.x - 1, area.right_bottom.x + 0.5}) do
|
||||
local p = {x, area.left_top.y + 30}
|
||||
surface.set_tiles({{name = main_tile_name, position = p}}, true)
|
||||
for _, x in pairs({area.left_top.x - 1.5, area.right_bottom.x + 1.5}) do
|
||||
local p = {x = x, y = area.left_top.y + 30}
|
||||
if p.x < 0 then
|
||||
surface.set_tiles({{name = main_tile_name, position = {x = p.x + 0.5, y = p.y}}}, true)
|
||||
else
|
||||
surface.set_tiles({{name = main_tile_name, position = {x = p.x - 1, y = p.y}}}, true)
|
||||
end
|
||||
local e =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'player-port',
|
||||
name = 'car',
|
||||
position = {x, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)},
|
||||
force = 'neutral',
|
||||
create_build_effect_smoke = false
|
||||
@ -335,6 +339,7 @@ local function construct_wagon_doors(icw, wagon)
|
||||
e.destructible = false
|
||||
e.minable = false
|
||||
e.operable = false
|
||||
e.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 1})
|
||||
icw.doors[e.unit_number] = wagon.entity.unit_number
|
||||
wagon.doors[#wagon.doors + 1] = e
|
||||
end
|
||||
@ -761,91 +766,6 @@ function Public.subtract_wagon_entity_count(icw, removed_entity)
|
||||
wagon.entity.minable = true
|
||||
end
|
||||
|
||||
function Public.teleport_players_around(icw)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if validate_player(player) then
|
||||
local trusted = Session.get_trusted_table()
|
||||
|
||||
if player.surface.find_entity('player-port', player.position) then
|
||||
local door = player.surface.find_entity('player-port', player.position)
|
||||
if door and door.valid then
|
||||
local doors = icw.doors
|
||||
local wagons = icw.wagons
|
||||
|
||||
local wagon = false
|
||||
if doors[door.unit_number] then
|
||||
wagon = wagons[doors[door.unit_number]]
|
||||
end
|
||||
if wagons[door.unit_number] then
|
||||
wagon = wagons[door.unit_number]
|
||||
end
|
||||
if not wagon then
|
||||
return
|
||||
end
|
||||
|
||||
local player_data = get_player_data(icw, player)
|
||||
if player_data.state then
|
||||
player_data.state = player_data.state - 1
|
||||
if player_data.state == 0 then
|
||||
player_data.state = nil
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
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
|
||||
local position = {wagon.entity.position.x + x_vector, wagon.entity.position.y}
|
||||
local surface_position = surface.find_non_colliding_position('character', position, 128, 0.5)
|
||||
if wagon.entity.type == 'locomotive' then
|
||||
if not trusted[player.name] and not player.admin then
|
||||
player.teleport(surface_position, surface)
|
||||
player.driving = false
|
||||
Public.kill_minimap(player)
|
||||
player.print('Wooops - you slipped out of the driver seat!', Color.warning)
|
||||
else
|
||||
player.teleport(surface_position, surface)
|
||||
player_data.state = 2
|
||||
player.driving = true
|
||||
Public.kill_minimap(player)
|
||||
end
|
||||
else
|
||||
player.teleport(surface_position, surface)
|
||||
Public.kill_minimap(player)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
elseif wagon.entity.type == 'locomotive' and player.driving then
|
||||
player.driving = false
|
||||
else
|
||||
local surface = wagon.surface
|
||||
local area = wagon.area
|
||||
local x_vector = door.position.x - player.position.x
|
||||
local position
|
||||
if x_vector > 0 then
|
||||
position = {
|
||||
area.left_top.x + 0.5,
|
||||
area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)
|
||||
}
|
||||
else
|
||||
position = {
|
||||
area.right_bottom.x - 0.5,
|
||||
area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)
|
||||
}
|
||||
end
|
||||
local p = surface.find_non_colliding_position('character', position, 128, 0.5)
|
||||
if p then
|
||||
player.teleport(p, surface)
|
||||
else
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
player_data.surface = surface.index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Public.use_cargo_wagon_door_with_entity(icw, player, door)
|
||||
local player_data = get_player_data(icw, player)
|
||||
if player_data.state then
|
||||
|
@ -155,7 +155,6 @@ local function on_tick()
|
||||
local tick = game.tick
|
||||
|
||||
if tick % 60 == 0 then
|
||||
Functions.teleport_players_around(icw)
|
||||
Functions.item_transfer(icw)
|
||||
end
|
||||
if tick % 240 == 0 then
|
||||
|
@ -1532,38 +1532,6 @@ local function on_console_chat(event)
|
||||
shoo(event)
|
||||
end
|
||||
|
||||
-- local function tp_player()
|
||||
-- for _, player in pairs(game.connected_players) do
|
||||
-- if not validate_player(player) then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- local active_surface_index = WPT.get('active_surface_index')
|
||||
-- if not active_surface_index then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- local surface = game.surfaces[active_surface_index]
|
||||
|
||||
-- local nauvis = 'nauvis'
|
||||
|
||||
-- if string.sub(player.surface.name, 0, #nauvis) == nauvis then
|
||||
-- if player.surface.find_entity('player-port', player.position) then
|
||||
-- player.teleport(
|
||||
-- surface.find_non_colliding_position(
|
||||
-- 'character',
|
||||
-- game.forces.player.get_spawn_position(surface),
|
||||
-- 3,
|
||||
-- 0,
|
||||
-- 5
|
||||
-- ),
|
||||
-- surface
|
||||
-- )
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
local function on_player_changed_surface(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not validate_player(player) then
|
||||
|
@ -81,50 +81,4 @@ function Public.get(key)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
|
||||
|
||||
local function clear_nauvis()
|
||||
local surface = game.surfaces['nauvis']
|
||||
local mgs = surface.map_gen_settings
|
||||
mgs.width = 16
|
||||
mgs.height = 16
|
||||
surface.map_gen_settings = mgs
|
||||
surface.clear()
|
||||
surface.request_to_generate_chunks({0, 0}, 0.5)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
game.forces.player.chart(surface, {{-16, -16}, {16, 16}})
|
||||
end
|
||||
|
||||
local function place_grid()
|
||||
local surface = game.surfaces['nauvis']
|
||||
rendering.draw_text {
|
||||
text = 'How did you end up here? O_o',
|
||||
surface = surface,
|
||||
target = {0, -12},
|
||||
color = {r = 0.98, g = 0.66, b = 0.22},
|
||||
scale = 3,
|
||||
font = 'heading-1',
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
local e =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'player-port',
|
||||
position = {0, 5},
|
||||
force = 'neutral',
|
||||
create_build_effect_smoke = false
|
||||
}
|
||||
)
|
||||
e.destructible = false
|
||||
e.minable = false
|
||||
e.operable = false
|
||||
end
|
||||
|
||||
local clear_nauvis_token = Token.register(clear_nauvis)
|
||||
local place_grid_token = Token.register(place_grid)
|
||||
|
||||
]]
|
||||
return Public
|
||||
|
Loading…
x
Reference in New Issue
Block a user