Update all code styles

This commit is contained in:
Cooldude2606
2024-09-28 01:56:54 +01:00
parent 5e2a62ab27
commit 292c1a1b68
194 changed files with 9817 additions and 9703 deletions

View File

@@ -33,13 +33,13 @@ local Jail = {
-- @tparam number player_index the index of the player who was jailed
-- @tparam string by_player_name the name of the player who jailed the other player
-- @tparam string reason the reason that the player was jailed
on_player_jailed=script.generate_event_name(),
on_player_jailed = script.generate_event_name(),
--- When a player is unassigned from jail
-- @event on_player_unjailed
-- @tparam number player_index the index of the player who was unjailed
-- @tparam string by_player_name the name of the player who unjailed the other player
on_player_unjailed=script.generate_event_name(),
}
on_player_unjailed = script.generate_event_name(),
},
}
--- Used to emit the jail related events
@@ -49,11 +49,11 @@ local Jail = {
-- @tparam string reason the reason for the action (jail)
local function event_emit(event, player, by_player_name, reason)
script.raise_event(event, {
name=event,
tick=game.tick,
player_index=player.index,
by_player_name=by_player_name,
reason=reason
name = event,
tick = game.tick,
player_index = player.index,
by_player_name = by_player_name,
reason = reason,
})
end
@@ -65,7 +65,7 @@ end
-- @tparam LuaPlayer player the player to check if they are in jail
-- @treturn boolean whether the player is currently in jail
function Jail.is_jailed(player)
return has_role(player, 'Jail')
return has_role(player, "Jail")
end
--- Moves a player to jail and removes all other roles
@@ -78,9 +78,9 @@ function Jail.jail_player(player, by_player_name, reason)
if not player then return end
if not by_player_name then return end
reason = reason or 'Non given.'
reason = reason or "Non given."
if has_role(player, 'Jail') then return end
if has_role(player, "Jail") then return end
local roles = get_roles(player)
player.walking_state = { walking = false, direction = player.walking_state.direction }
@@ -91,7 +91,7 @@ function Jail.jail_player(player, by_player_name, reason)
player.repair_state = { repairing = false, position = player.repair_state.position }
unassign_roles(player, roles, by_player_name, nil, true)
assign_roles(player, 'Jail', by_player_name, nil, true)
assign_roles(player, "Jail", by_player_name, nil, true)
assign_roles(player, roles, by_player_name, nil, true)
event_emit(Jail.events.on_player_jailed, player, by_player_name, reason)
@@ -108,9 +108,9 @@ function Jail.unjail_player(player, by_player_name)
if not player then return end
if not by_player_name then return end
if not has_role(player, 'Jail') then return end
if not has_role(player, "Jail") then return end
unassign_roles(player, 'Jail', by_player_name, nil, true)
unassign_roles(player, "Jail", by_player_name, nil, true)
event_emit(Jail.events.on_player_unjailed, player, by_player_name)

View File

@@ -47,13 +47,20 @@ local Production = {}
-- @treturn[1] defines.flow_precision_index the next precision value
-- @treturn[1] number the multiplicive difference between the values
function Production.precision_up(precision)
if precision == precision_index.five_seconds then return precision_index.one_minute, 60
elseif precision == precision_index.one_minute then return precision_index.ten_minutes, 10
elseif precision == precision_index.ten_minutes then return precision_index.one_hour, 6
elseif precision == precision_index.one_hour then return precision_index.ten_hours, 10
elseif precision == precision_index.ten_hours then return precision_index.fifty_hours, 5
elseif precision == precision_index.fifty_hours then return precision_index.two_hundred_fifty_hours, 5
elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.one_thousand_hours, 4
if precision == precision_index.five_seconds then
return precision_index.one_minute, 60
elseif precision == precision_index.one_minute then
return precision_index.ten_minutes, 10
elseif precision == precision_index.ten_minutes then
return precision_index.one_hour, 6
elseif precision == precision_index.one_hour then
return precision_index.ten_hours, 10
elseif precision == precision_index.ten_hours then
return precision_index.fifty_hours, 5
elseif precision == precision_index.fifty_hours then
return precision_index.two_hundred_fifty_hours, 5
elseif precision == precision_index.two_hundred_fifty_hours then
return precision_index.one_thousand_hours, 4
end
end
@@ -62,13 +69,20 @@ end
-- @treturn[1] defines.flow_precision_index the next precision value
-- @treturn[1] number the multiplicive difference between the values
function Production.precision_down(precision)
if precision == precision_index.one_minute then return precision_index.five_seconds, 60
elseif precision == precision_index.ten_minutes then return precision_index.one_minute, 10
elseif precision == precision_index.one_hour then return precision_index.ten_minutes, 6
elseif precision == precision_index.ten_hours then return precision_index.one_hour, 10
elseif precision == precision_index.fifty_hours then return precision_index.ten_hours, 5
elseif precision == precision_index.two_hundred_fifty_hours then return precision_index.fifty_hours, 5
elseif precision == precision_index.one_thousand_hours then return precision_index.two_hundred_fifty_hours, 4
if precision == precision_index.one_minute then
return precision_index.five_seconds, 60
elseif precision == precision_index.ten_minutes then
return precision_index.one_minute, 10
elseif precision == precision_index.one_hour then
return precision_index.ten_minutes, 6
elseif precision == precision_index.ten_hours then
return precision_index.one_hour, 10
elseif precision == precision_index.fifty_hours then
return precision_index.ten_hours, 5
elseif precision == precision_index.two_hundred_fifty_hours then
return precision_index.fifty_hours, 5
elseif precision == precision_index.one_thousand_hours then
return precision_index.two_hundred_fifty_hours, 4
end
end
@@ -76,14 +90,22 @@ end
-- @tparam defines.flow_precision_index precision
-- @treturn number the number of ticks in this time
function Production.precision_ticks(precision)
if precision == precision_index.five_seconds then return 300
elseif precision == precision_index.one_minute then return 3600
elseif precision == precision_index.ten_minutes then return 36000
elseif precision == precision_index.one_hour then return 216000
elseif precision == precision_index.ten_hours then return 2160000
elseif precision == precision_index.fifty_hours then return 10800000
elseif precision == precision_index.two_hundred_fifty_hours then return 54000000
elseif precision == precision_index.one_thousand_hours then return 216000000
if precision == precision_index.five_seconds then
return 300
elseif precision == precision_index.one_minute then
return 3600
elseif precision == precision_index.ten_minutes then
return 36000
elseif precision == precision_index.one_hour then
return 216000
elseif precision == precision_index.ten_hours then
return 2160000
elseif precision == precision_index.fifty_hours then
return 10800000
elseif precision == precision_index.two_hundred_fifty_hours then
return 54000000
elseif precision == precision_index.one_thousand_hours then
return 216000000
end
end
@@ -104,11 +126,10 @@ function Production.get_production_total(force, item_name)
end
return {
made=made,
used=used,
net=made-used
made = made,
used = used,
net = made - used,
}
end
--- Returns the production data for the given precision game time
@@ -120,16 +141,15 @@ function Production.get_production(force, item_name, precision)
local made, used = 0, 0
for _, surface in pairs(game.surfaces) do
local stats = force.get_item_production_statistics(surface).get_flow_count
made = made + stats{name=item_name, category="input", precision_index=precision}
used = used + stats{name=item_name, category="output", precision_index=precision}
made = made + stats{ name = item_name, category = "input", precision_index = precision }
used = used + stats{ name = item_name, category = "output", precision_index = precision }
end
return {
made=made,
used=used,
net=made-used
made = made,
used = used,
net = made - used,
}
end
--- Returns the current fluctuation from the average
@@ -143,11 +163,10 @@ function Production.get_fluctuations(force, item_name, precision)
local previous = Production.get_production(force, item_name, precision_up)
return {
made=(current.made/previous.made)-1,
used=(current.used/previous.used)-1,
net=(current.net/previous.net)-1,
made = (current.made / previous.made) - 1,
used = (current.used / previous.used) - 1,
net = (current.net / previous.net) - 1,
}
end
--- Returns the amount of ticks required to produce a certain amount
@@ -160,7 +179,7 @@ function Production.get_production_eta(force, item_name, precision, required)
required = required or 1000
local ticks = Production.precision_ticks(precision)
local production = Production.get_production(force, item_name, precision)
return production.made == 0 and -1 or ticks*required/production.made
return production.made == 0 and -1 or ticks * required / production.made
end
--- Returns the amount of ticks required to consume a certain amount
@@ -173,7 +192,7 @@ function Production.get_consumsion_eta(force, item_name, precision, required)
required = required or 1000
local ticks = Production.precision_ticks(precision)
local production = Production.get_production(force, item_name, precision)
return production.used == 0 and -1 or ticks*required/production.used
return production.used == 0 and -1 or ticks * required / production.used
end
--- Returns the amount of ticks required to produce but not consume a certain amount
@@ -186,7 +205,7 @@ function Production.get_net_eta(force, item_name, precision, required)
required = required or 1000
local ticks = Production.precision_ticks(precision)
local production = Production.get_production(force, item_name, precision)
return production.net == 0 and -1 or ticks*required/production.net
return production.net == 0 and -1 or ticks * required / production.net
end
--- Formating.
@@ -223,17 +242,16 @@ function Production.format_number(value)
local surfix = rtn:sub(-1)
if value > 0 then
rtn = '+'..rtn
elseif value == 0 and rtn:sub(1, 1) == '-' then
rtn = "+" .. rtn
elseif value == 0 and rtn:sub(1, 1) == "-" then
rtn = rtn:sub(2)
end
if not tonumber(surfix) then
return surfix, rtn:sub(1, -2)
else
return '', rtn
return "", rtn
end
end
return Production
return Production

View File

@@ -21,11 +21,11 @@ local EntityProtection = {
-- @tparam number player_index the player index of the player who got mined the entities
-- @tparam LuaEntity entity the last entity which was mined
on_repeat_violation = script.generate_event_name(),
}
},
}
-- Convert config tables into lookup tables
for _, config_key in ipairs{'always_protected_names', 'always_protected_types', 'always_trigger_repeat_names', 'always_trigger_repeat_types'} do
for _, config_key in ipairs{ "always_protected_names", "always_protected_types", "always_trigger_repeat_names", "always_trigger_repeat_types" } do
local tbl = config[config_key]
for key, value in ipairs(tbl) do
tbl[key] = nil
@@ -49,7 +49,7 @@ local repeats = {} -- Stores repeat removals by players
Storage.register({
protected_entities = protected_entities,
protected_areas = protected_areas,
repeats = repeats
repeats = repeats,
}, function(tbl)
protected_entities = tbl.protected_entities
protected_areas = tbl.protected_areas
@@ -61,12 +61,12 @@ end)
--- Get the key used in protected_entities
local function get_entity_key(entity)
return string.format('%i,%i', math.floor(entity.position.x), math.floor(entity.position.y))
return string.format("%i,%i", math.floor(entity.position.x), math.floor(entity.position.y))
end
--- Get the key used in protected_areas
local function get_area_key(area)
return string.format('%i,%i', math.floor(area.left_top.x), math.floor(area.left_top.y))
return string.format("%i,%i", math.floor(area.left_top.x), math.floor(area.left_top.y))
end
--- Check if an entity is always protected
@@ -145,6 +145,7 @@ function EntityProtection.is_position_protected(surface, position)
return true
end
end
return false
end
@@ -203,4 +204,4 @@ Event.add(defines.events.on_robot_pre_mined, event_remove_entity)
Event.add(defines.events.on_entity_died, event_remove_entity)
Event.add(defines.events.script_raised_destroy, event_remove_entity)
return EntityProtection
return EntityProtection

View File

@@ -30,7 +30,7 @@ local Storage = require("modules/exp_util/storage")
local valid_player = Game.get_player_from_any
local Reports = {
user_reports={}, -- stores all user reports, global table
user_reports = {}, -- stores all user reports, global table
events = {
--- When a player is reported
-- @event on_player_reported
@@ -45,8 +45,8 @@ local Reports = {
-- @tparam string removed_by_name the name of the player who removed the report
-- @tparam number batch_count the number of reports removed in this batch, always one when not a batch
-- @tparam number batch the index of this event in a batch, always one when not a batch
on_report_removed = script.generate_event_name()
}
on_report_removed = script.generate_event_name(),
},
}
local user_reports = Reports.user_reports
@@ -112,6 +112,7 @@ function Reports.count_reports(player, custom_count)
for by_player_name, reason in pairs(reports) do
ctn = ctn + custom_count(player, by_player_name, reason)
end
return ctn
else
return table_size(reports)
@@ -132,7 +133,7 @@ function Reports.report_player(player, by_player_name, reason)
if not player then return end
local player_name = player.name
if reason == nil or not reason:find("%S") then reason = 'No reason given' end
if reason == nil or not reason:find("%S") then reason = "No reason given" end
local reports = user_reports[player_name]
if not reports then
@@ -151,7 +152,7 @@ function Reports.report_player(player, by_player_name, reason)
tick = game.tick,
player_index = player.index,
by_player_name = by_player_name,
reason = reason
reason = reason,
})
return true
@@ -171,7 +172,7 @@ local function report_removed_event(player, reported_by_name, removed_by_name, b
reported_by_name = reported_by_name,
removed_by_name = removed_by_name,
batch_count = batch_count or 1,
batch = batch or 1
batch = batch or 1,
})
end

View File

@@ -39,7 +39,7 @@ end
local Rockets = {
times = {},
stats = {},
silos = {}
silos = {},
}
local rocket_times = Rockets.times
@@ -48,7 +48,7 @@ local rocket_silos = Rockets.silos
Storage.register({
rocket_times = rocket_times,
rocket_stats = rocket_stats,
rocket_silos = rocket_silos
rocket_silos = rocket_silos,
}, function(tbl)
Rockets.times = tbl.rocket_times
Rockets.stats = tbl.rocket_stats
@@ -63,7 +63,7 @@ end)
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
function Rockets.get_silo_data(silo)
local position = silo.position
local silo_name = math.floor(position.x)..':'..math.floor(position.y)
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
return rocket_silos[silo_name]
end
@@ -99,6 +99,7 @@ function Rockets.get_silos(force_name)
table.insert(rtn, silo_data)
end
end
return rtn
end
@@ -125,6 +126,7 @@ function Rockets.get_game_rocket_count()
for _, force in pairs(game.forces) do
rtn = rtn + force.rockets_launched
end
return rtn
end
@@ -139,10 +141,10 @@ function Rockets.get_rolling_average(force_name, count)
local last_launch_time = rocket_times[force_name][rocket_count]
local start_rocket_time = 0
if count < rocket_count then
start_rocket_time = rocket_times[force_name][rocket_count-count+1]
start_rocket_time = rocket_times[force_name][rocket_count - count + 1]
rocket_count = count
end
return math.floor((last_launch_time-start_rocket_time)/rocket_count)
return math.floor((last_launch_time - start_rocket_time) / rocket_count)
end
--- Event used to update the stats and the hui when a rocket is launched
@@ -163,8 +165,8 @@ Event.add(defines.events.on_rocket_launched, function(event)
if rockets_launched == 1 then
stats.first_launch = event.tick
stats.fastest_launch = event.tick
elseif event.tick-stats.last_launch < stats.fastest_launch then
stats.fastest_launch = event.tick-stats.last_launch
elseif event.tick - stats.last_launch < stats.fastest_launch then
stats.fastest_launch = event.tick - stats.last_launch
end
stats.last_launch = event.tick
@@ -176,13 +178,13 @@ Event.add(defines.events.on_rocket_launched, function(event)
rocket_times[force_name][rockets_launched] = event.tick
local remove_rocket = rockets_launched-largest_rolling_avg
local remove_rocket = rockets_launched - largest_rolling_avg
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
rocket_times[force_name][remove_rocket] = nil
end
--- Adds this 1 to the launch count for this silo
silo_data.launched = silo_data.launched+1
silo_data.launched = silo_data.launched + 1
end)
--- When a launch is reiggered it will await reset
@@ -195,19 +197,19 @@ end)
--- Adds a silo to the list when it is built
local function on_built(event)
local entity = event.created_entity
if entity.valid and entity.name == 'rocket-silo' then
if entity.valid and entity.name == "rocket-silo" then
local force = entity.force
local force_name = force.name
local position = entity.position
local silo_name = math.floor(position.x)..':'..math.floor(position.y)
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
rocket_silos[silo_name] = {
name=silo_name,
force=force_name,
entity=entity,
launched=0,
awaiting_reset=false,
built=game.tick
name = silo_name,
force = force_name,
entity = entity,
launched = 0,
awaiting_reset = false,
built = game.tick,
}
end
end
@@ -215,4 +217,4 @@ end
Event.add(defines.events.on_built_entity, on_built)
Event.add(defines.events.on_robot_built_entity, on_built)
return Rockets
return Rockets

View File

@@ -18,14 +18,14 @@ local Selection = {
-- @tparam number player_index the player index of the player who left selection mode
-- @tparam string selection the name of the selection which ended
on_player_selection_end = script.generate_event_name(),
}
},
}
local selection_tool = { name='selection-tool' }
local selection_tool = { name = "selection-tool" }
local selections = {}
Storage.register({
selections = selections
selections = selections,
}, function(tbl)
selections = tbl.selections
end)
@@ -42,7 +42,7 @@ function Selection.start(player, selection_name, single_use, ...)
name = Selection.events.on_player_selection_end,
tick = game.tick,
player_index = player.index,
selection = selections[player.index].name
selection = selections[player.index].name,
})
end
@@ -51,7 +51,7 @@ function Selection.start(player, selection_name, single_use, ...)
name = selection_name,
arguments = { ... },
single_use = single_use == true,
character = player.character
character = player.character,
}
-- Raise the event
@@ -59,7 +59,7 @@ function Selection.start(player, selection_name, single_use, ...)
name = Selection.events.on_player_selection_start,
tick = game.tick,
player_index = player.index,
selection = selection_name
selection = selection_name,
})
-- Give a selection tool if one is not in use
@@ -86,7 +86,7 @@ function Selection.stop(player)
name = Selection.events.on_player_selection_end,
tick = game.tick,
player_index = player.index,
selection = selection
selection = selection,
})
-- Remove the selection tool
@@ -146,7 +146,7 @@ end
--- Stop selection if the selection tool is removed from the cursor
Event.add(defines.events.on_player_cursor_stack_changed, function(event)
local player = game.get_player(event.player_index) ---@cast player -nil
local player = game.get_player(event.player_index) --- @cast player -nil
if player.cursor_stack.is_selection_tool then return end
Selection.stop(player)
end)
@@ -169,4 +169,4 @@ end
Event.add(defines.events.on_player_selected_area, stop_after_use)
Event.add(defines.events.on_player_alt_selected_area, stop_after_use)
return Selection
return Selection

View File

@@ -1,4 +1,3 @@
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Storage = require("modules/exp_util/storage")
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
@@ -12,7 +11,7 @@ local Public = {}
----- Storage data -----
Storage.register({
following = following,
spectating = spectating
spectating = spectating,
}, function(tbl)
following = tbl.following
spectating = tbl.spectating
@@ -24,7 +23,7 @@ end)
-- @tparam LuaPlayer player The player to test the controller type of
-- @treturn boolean Returns true if the player is in spectator mode
function Public.is_spectating(player)
assert(player and player.valid, 'Invalid player given to follower')
assert(player and player.valid, "Invalid player given to follower")
return player.controller_type == defines.controllers.spectator
end
@@ -32,7 +31,7 @@ end
-- @tparam LuaPlayer player The player that will be placed into spectator mode
-- @treturn boolean Returns false if the player was already in spectator mode
function Public.start_spectate(player)
assert(player and player.valid, 'Invalid player given to follower')
assert(player and player.valid, "Invalid player given to follower")
if spectating[player.index] or not player.character then return false end
local character = player.character
local opened = player.opened
@@ -46,7 +45,7 @@ end
--- Return a player from spectator mode back to their character, if their character was killed then respawn them
-- @tparam LuaPlayer player The player that will leave spectator mode
function Public.stop_spectate(player)
assert(player and player.valid, 'Invalid player given to follower')
assert(player and player.valid, "Invalid player given to follower")
local character = spectating[player.index]
spectating[player.index] = nil
if character and character.valid then
@@ -63,7 +62,7 @@ end
-- @tparam LuaPlayer player The player to test the follow mode of
-- @treturn boolean Returns true if the player is in follow mode
function Public.is_following(player)
assert(player and player.valid, 'Invalid player given to follower')
assert(player and player.valid, "Invalid player given to follower")
return following[player.index] ~= nil
end
@@ -71,8 +70,8 @@ end
-- @tparam LuaPlayer player The player that will follow the entity
-- @tparam ?LuaPlayer|LuaEntity entity The player or entity that will be followed
function Public.start_follow(player, entity)
assert(player and player.valid, 'Invalid player given to follower')
assert(entity and entity.valid, 'Invalid entity given to follower')
assert(player and player.valid, "Invalid player given to follower")
assert(entity and entity.valid, "Invalid entity given to follower")
local spectate = Public.start_spectate(player)
player.close_map()
@@ -84,7 +83,7 @@ end
--- Returns camera control to the player, will return a player to their character if start_follow placed them into spectator mode
-- @tparam LuaPlayer player The player that will regain control of their camera
function Public.stop_follow(player)
assert(player and player.valid, 'Invalid player given to follower')
assert(player and player.valid, "Invalid player given to follower")
if following[player.index] and following[player.index][4] and Public.is_spectating(player) then
Public.stop_spectate(player)
end
@@ -105,32 +104,32 @@ end
--- Label used to show that the player is following, also used to allow esc to stop following
-- @element follow_label
follow_label =
Gui.element(function(definition, parent, target)
Gui.destroy_if_valid(parent[definition.name])
Gui.element(function(definition, parent, target)
Gui.destroy_if_valid(parent[definition.name])
local label = parent.add{
type = 'label',
style = 'frame_title',
caption = 'Following '..target.name..'.\nClick here or press esc to stop following.',
name = definition.name
}
local label = parent.add{
type = "label",
style = "frame_title",
caption = "Following " .. target.name .. ".\nClick here or press esc to stop following.",
name = definition.name,
}
local player = Gui.get_player_from_element(parent)
local res = player.display_resolution
label.location = {0, res.height-150}
label.style.width = res.width
label.style.horizontal_align = 'center'
player.opened = label
local player = Gui.get_player_from_element(parent)
local res = player.display_resolution
label.location = { 0, res.height - 150 }
label.style.width = res.width
label.style.horizontal_align = "center"
player.opened = label
return label
end)
:static_name(Gui.unique_static_name)
:on_click(Public.stop_follow)
:on_close(function(player)
-- Don't call set_controller during on_close as it invalidates the controller
-- Setting an invalid position (as to not equal their current) will call stop_follow on the next tick
following[player.index][3] = {}
end)
return label
end)
:static_name(Gui.unique_static_name)
:on_click(Public.stop_follow)
:on_close(function(player)
-- Don't call set_controller during on_close as it invalidates the controller
-- Setting an invalid position (as to not equal their current) will call stop_follow on the next tick
following[player.index][3] = {}
end)
----- Events -----
@@ -170,4 +169,4 @@ Event.add(defines.events.on_pre_player_left_game, function(event)
end)
----- Module Return -----
return Public
return Public

View File

@@ -14,13 +14,13 @@ local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expco
local Storage = require("modules/exp_util/storage")
--- Stores all data for the warp gui
local TaskData = Datastore.connect('TaskData')
local TaskData = Datastore.connect("TaskData")
TaskData:set_serializer(function(raw_key) return raw_key.task_id end)
local Tasks = {}
-- Storage lookup table for force name to task ids
local force_tasks = {_uid=1}
local force_tasks = { _uid = 1 }
Storage.register(force_tasks, function(tbl)
force_tasks = tbl
end)
@@ -59,11 +59,11 @@ function Tasks.add_task(force_name, player_name, task_title, task_body)
TaskData:set(task_id, {
task_id = task_id,
force_name = force_name,
title = task_title or '',
body = task_body or '',
last_edit_name = player_name or '<server>',
title = task_title or "",
body = task_body or "",
last_edit_name = player_name or "<server>",
last_edit_time = game.tick,
currently_editing = {}
currently_editing = {},
})
return task_id

View File

@@ -17,22 +17,22 @@ local vlayer_data = {
energy = {},
circuit = {},
storage_input = {},
storage_output = {}
storage_output = {},
},
properties = {
total_surface_area = 0,
used_surface_area = 0,
production = 0,
discharge = 0,
capacity = 0
capacity = 0,
},
storage = {
items = {},
power_items = {},
energy = 0,
unallocated = {}
unallocated = {},
},
surface = table.deep_copy(config.surface)
surface = table.deep_copy(config.surface),
}
Storage.register(vlayer_data, function(tbl)
@@ -45,7 +45,7 @@ for name, properties in pairs(config.allowed_items) do
if properties.power then
vlayer_data.storage.power_items[name] = {
value = properties.fuel_value * 1000000,
count = 0
count = 0,
}
end
end
@@ -61,7 +61,7 @@ for item_name, properties in pairs(config.modded_items) do
surface_area = (base_properties.surface_area or 0) * m,
production = (base_properties.production or 0) * m,
capacity = (base_properties.capacity or 0) * m,
modded = true
modded = true,
}
end
@@ -133,7 +133,7 @@ end
--[[
25,000 / 416 s
昼 208秒 ソーラー効率100%
夕方 83秒 1秒ごとにソーラー発電量が約1.2%ずつ下がり、やがて0%になる
夕方 83秒 1秒ごとにソーラー発電量が約1.2%ずつ下がり、やがて0%になる
夜 41秒 ソーラー発電量が0%になる
朝方 83秒 1秒ごとにソーラー発電量が約1.2%ずつ上がり、やがて100%になる
@@ -160,7 +160,6 @@ local function get_production_multiplier()
if brightness >= surface.min_brightness then
return mul * (brightness - surface.min_brightness) / (1 - surface.min_brightness)
else
return 0
end
@@ -173,16 +172,12 @@ local function get_production_multiplier()
if daytime <= surface.dusk then -- Noon to Sunset
return mul
elseif daytime <= surface.evening then -- Sunset to Night
return mul * (1 - ((daytime - surface.dusk) / (surface.evening - surface.dusk)))
elseif daytime <= surface.morning then -- Night to Sunrise
return 0
elseif daytime <= surface.dawn then -- Sunrise to Morning
return mul * ((surface.daytime - surface.morning) / (surface.dawn - surface.morning))
else -- Morning to Noon
return mul
end
@@ -214,7 +209,7 @@ end
-- @tparam number count The count of the item to allocate
function vlayer.allocate_item(item_name, count)
local item_properties = config.allowed_items[item_name]
assert(item_properties, 'Item not allowed in vlayer: ' .. tostring(item_name))
assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name))
if item_properties.production then
vlayer_data.properties.production = vlayer_data.properties.production + item_properties.production * count
@@ -253,7 +248,7 @@ end
-- @tparam number count The count of the item to insert
function vlayer.insert_item(item_name, count)
local item_properties = config.allowed_items[item_name]
assert(item_properties, 'Item not allowed in vlayer: ' .. tostring(item_name))
assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name))
vlayer_data.storage.items[item_name] = vlayer_data.storage.items[item_name] + count
if not config.unlimited_surface_area and item_properties.required_area and item_properties.required_area > 0 then
@@ -266,7 +261,6 @@ function vlayer.insert_item(item_name, count)
end
vlayer_data.storage.unallocated[item_name] = vlayer_data.storage.unallocated[item_name] + count - allocate_count
else
vlayer.allocate_item(item_name, count)
end
@@ -279,7 +273,7 @@ end
-- @treturn number The count of the item actually removed
function vlayer.remove_item(item_name, count)
local item_properties = config.allowed_items[item_name]
assert(item_properties, 'Item not allowed in vlayer: ' .. tostring(item_name))
assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name))
local remove_unallocated = 0
if not config.unlimited_surface_area and item_properties.required_area and item_properties.required_area > 0 then
@@ -325,7 +319,7 @@ end
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface
function vlayer.create_input_interface(surface, position, circuit, last_user)
local interface = surface.create_entity{name='logistic-chest-storage', position=position, force='neutral'}
local interface = surface.create_entity{ name = "logistic-chest-storage", position = position, force = "neutral" }
table.insert(vlayer_data.entity_interfaces.storage_input, interface)
if last_user then
@@ -335,7 +329,7 @@ function vlayer.create_input_interface(surface, position, circuit, last_user)
if circuit then
for k, _ in pairs(circuit) do
for _, v in pairs(circuit[k]) do
interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v})
interface.connect_neighbour{ wire = defines.wire_type[k], target_entity = v }
end
end
end
@@ -352,7 +346,6 @@ local function handle_input_interfaces()
for index, interface in pairs(vlayer_data.entity_interfaces.storage_input) do
if not interface.valid then
vlayer_data.entity_interfaces.storage_input[index] = nil
else
local inventory = interface.get_inventory(defines.inventory.chest)
@@ -361,21 +354,18 @@ local function handle_input_interfaces()
if config.allowed_items[name].modded then
if config.modded_auto_downgrade then
vlayer.insert_item(config.modded_items[name].base_game_equivalent, count * config.modded_items[name].multiplier)
else
vlayer.insert_item(name, count)
end
else
if vlayer_data.storage.power_items[name] then
vlayer_data.storage.power_items[name].count = vlayer_data.storage.power_items[name].count + count
else
vlayer.insert_item(name, count)
end
end
inventory.remove({name=name, count=count})
inventory.remove{ name = name, count = count }
end
end
end
@@ -388,7 +378,7 @@ end
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface
function vlayer.create_output_interface(surface, position, circuit, last_user)
local interface = surface.create_entity{name='logistic-chest-requester', position=position, force='neutral'}
local interface = surface.create_entity{ name = "logistic-chest-requester", position = position, force = "neutral" }
table.insert(vlayer_data.entity_interfaces.storage_output, interface)
if last_user then
@@ -398,7 +388,7 @@ function vlayer.create_output_interface(surface, position, circuit, last_user)
if circuit then
for k, _ in pairs(circuit) do
for _, v in pairs(circuit[k]) do
interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v})
interface.connect_neighbour{ wire = defines.wire_type[k], target_entity = v }
end
end
end
@@ -415,7 +405,6 @@ local function handle_output_interfaces()
for index, interface in pairs(vlayer_data.entity_interfaces.storage_output) do
if not interface.valid then
vlayer_data.entity_interfaces.storage_output[index] = nil
else
local inventory = interface.get_inventory(defines.inventory.chest)
@@ -426,11 +415,11 @@ local function handle_output_interfaces()
local current_amount = inventory.get_item_count(request.name)
local request_amount = math.min(request.count - current_amount, vlayer_data.storage.items[request.name])
if request_amount > 0 and inventory.can_insert({name=request.name, count=request_amount}) then
if request_amount > 0 and inventory.can_insert{ name = request.name, count = request_amount } then
local removed_item_count = vlayer.remove_item(request.name, request_amount)
if removed_item_count > 0 then
inventory.insert({name=request.name, count=removed_item_count})
inventory.insert{ name = request.name, count = removed_item_count }
end
end
end
@@ -488,7 +477,7 @@ function vlayer.get_statistics()
energy_storage = vlayer_data.storage.energy,
day_time = math.floor(vlayer_data.surface.daytime * vlayer_data.surface.ticks_per_day),
day_length = vlayer_data.surface.ticks_per_day,
tick = game.tick
tick = game.tick,
}
end
@@ -500,17 +489,17 @@ end
--- Circuit signals used for the statistics
function vlayer.get_circuits()
return {
total_surface_area = 'signal-A',
used_surface_area = 'signal-U',
remaining_surface_area = 'signal-R',
production_multiplier = 'signal-M',
energy_production = 'signal-P',
energy_sustained = 'signal-S',
energy_capacity = 'signal-C',
energy_storage = 'signal-E',
day_time = 'signal-D',
day_length = 'signal-L',
tick = 'signal-T',
total_surface_area = "signal-A",
used_surface_area = "signal-U",
remaining_surface_area = "signal-R",
production_multiplier = "signal-M",
energy_production = "signal-P",
energy_sustained = "signal-S",
energy_capacity = "signal-C",
energy_storage = "signal-E",
day_time = "signal-D",
day_length = "signal-L",
tick = "signal-T",
}
end
@@ -520,7 +509,7 @@ end
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface
function vlayer.create_circuit_interface(surface, position, circuit, last_user)
local interface = surface.create_entity{name='constant-combinator', position=position, force='neutral'}
local interface = surface.create_entity{ name = "constant-combinator", position = position, force = "neutral" }
table.insert(vlayer_data.entity_interfaces.circuit, interface)
if last_user then
@@ -530,7 +519,7 @@ function vlayer.create_circuit_interface(surface, position, circuit, last_user)
if circuit then
for k, _ in pairs(circuit) do
for _, v in pairs(circuit[k]) do
interface.connect_neighbour({wire=defines.wire_type[k], target_entity=v})
interface.connect_neighbour{ wire = defines.wire_type[k], target_entity = v }
end
end
end
@@ -549,7 +538,6 @@ local function handle_circuit_interfaces()
for index, interface in pairs(vlayer_data.entity_interfaces.circuit) do
if not interface.valid then
vlayer_data.entity_interfaces.circuit[index] = nil
else
local circuit_oc = interface.get_or_create_control_behavior()
local max_signals = circuit_oc.signals_count
@@ -558,14 +546,12 @@ local function handle_circuit_interfaces()
-- Set the virtual signals based on the vlayer stats
for stat_name, signal_name in pairs(circuit) do
if stat_name:find('energy') then
circuit_oc.set_signal(signal_index, {signal={type='virtual', name=signal_name}, count=math.floor(stats[stat_name] / mega)})
elseif stat_name == 'production_multiplier' then
circuit_oc.set_signal(signal_index, {signal={type='virtual', name=signal_name}, count=math.floor(stats[stat_name] * 10000)})
if stat_name:find("energy") then
circuit_oc.set_signal(signal_index, { signal = { type = "virtual", name = signal_name }, count = math.floor(stats[stat_name] / mega) })
elseif stat_name == "production_multiplier" then
circuit_oc.set_signal(signal_index, { signal = { type = "virtual", name = signal_name }, count = math.floor(stats[stat_name] * 10000) })
else
circuit_oc.set_signal(signal_index, {signal={type='virtual', name=signal_name}, count=math.floor(stats[stat_name])})
circuit_oc.set_signal(signal_index, { signal = { type = "virtual", name = signal_name }, count = math.floor(stats[stat_name]) })
end
signal_index = signal_index + 1
@@ -574,7 +560,7 @@ local function handle_circuit_interfaces()
-- Set the item signals based on stored items
for item_name, count in pairs(vlayer_data.storage.items) do
if prototypes.item[item_name] and count > 0 then
circuit_oc.set_signal(signal_index, {signal={type='item', name=item_name}, count=count})
circuit_oc.set_signal(signal_index, { signal = { type = "item", name = item_name }, count = count })
signal_index = signal_index + 1
if signal_index > max_signals then
return -- No more signals can be added
@@ -600,11 +586,11 @@ end
-- @tparam[opt] LuaPlayer player The player to show as the last user of the interface
-- @treturn LuaEntity The entity that was created for the interface, or nil if it could not be created
function vlayer.create_energy_interface(surface, position, last_user)
if not surface.can_place_entity{name='electric-energy-interface', position=position} then
if not surface.can_place_entity{ name = "electric-energy-interface", position = position } then
return nil
end
local interface = surface.create_entity{name='electric-energy-interface', position=position, force='neutral'}
local interface = surface.create_entity{ name = "electric-energy-interface", position = position, force = "neutral" }
table.insert(vlayer_data.entity_interfaces.energy, interface)
if last_user then
@@ -635,7 +621,6 @@ local function handle_energy_interfaces()
for index, interface in pairs(vlayer_data.entity_interfaces.energy) do
if not interface.valid then
vlayer_data.entity_interfaces.energy[index] = nil
else
available_energy = available_energy + interface.energy
end
@@ -657,7 +642,7 @@ local function handle_energy_interfaces()
if not config.unlimited_capacity and vlayer_data.storage.energy > vlayer_data.properties.capacity * mega then
vlayer_data.storage.energy = vlayer_data.properties.capacity * mega
-- burn the trash to produce power
-- burn the trash to produce power
elseif vlayer_data.storage.power_items then
for k, v in pairs(vlayer_data.storage.power_items) do
local max_burning = (vlayer_data.properties.capacity * mega / 2) - vlayer_data.storage.energy
@@ -679,11 +664,11 @@ end
-- @treturn MapPosition The position the interface was at, or nil if no interface was found
function vlayer.remove_interface(surface, position)
local entities = surface.find_entities_filtered{
name = {'logistic-chest-storage', 'logistic-chest-requester', 'constant-combinator', 'electric-energy-interface'},
force = 'neutral',
name = { "logistic-chest-storage", "logistic-chest-requester", "constant-combinator", "electric-energy-interface" },
force = "neutral",
position = position,
radius = 2,
limit = 1
limit = 1,
}
-- Get the details which will be returned
@@ -696,32 +681,29 @@ function vlayer.remove_interface(surface, position)
local pos = interface.position
-- Return the type of interface removed and do some clean up
if name == 'logistic-chest-storage' then
if name == "logistic-chest-storage" then
move_items_stack(interface.get_inventory(defines.inventory.chest).get_contents())
table.remove_element(vlayer_data.entity_interfaces.storage_input, interface)
interface.destroy()
return 'storage-input', pos
elseif name == 'logistic-chest-requester' then
return "storage-input", pos
elseif name == "logistic-chest-requester" then
move_items_stack(interface.get_inventory(defines.inventory.chest).get_contents())
table.remove_element(vlayer_data.entity_interfaces.storage_output, interface)
interface.destroy()
return 'storage-output', pos
elseif name == 'constant-combinator' then
return "storage-output", pos
elseif name == "constant-combinator" then
table.remove_element(vlayer_data.entity_interfaces.circuit, interface)
interface.destroy()
return 'circuit', pos
elseif name == 'electric-energy-interface' then
return "circuit", pos
elseif name == "electric-energy-interface" then
vlayer_data.storage.energy = vlayer_data.storage.energy + interface.energy
table.remove_element(vlayer_data.entity_interfaces.energy, interface)
interface.destroy()
return 'energy', pos
return "energy", pos
end
end

View File

@@ -30,19 +30,20 @@ local valid_player = Game.get_player_from_any
--- Stores the quickbar filters for a player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
local PlayerWarnings = PlayerData.Required:combine('Warnings')
local PlayerWarnings = PlayerData.Required:combine("Warnings")
PlayerWarnings:set_metadata{
stringify = function(value)
if not value then return 'You have no warnings' end
if not value then return "You have no warnings" end
local count = 0
for _ in pairs(value) do count = count + 1 end
return 'You have '..count..' warnings'
end
return "You have " .. count .. " warnings"
end,
}
local Warnings = {
user_warnings=PlayerWarnings,
user_script_warnings={},
user_warnings = PlayerWarnings,
user_script_warnings = {},
events = {
--- When a warning is added to a player
-- @event on_warning_added
@@ -71,7 +72,7 @@ local Warnings = {
-- @tparam number player_index the index of the player who is having the warning removed
-- @tparam number warning_count the new number of warnings that the player has
on_script_warning_removed = script.generate_event_name(),
}
},
}
local user_script_warnings = Warnings.user_script_warnings
@@ -105,18 +106,18 @@ function Warnings.add_warning(player, by_player_name, reason)
if not player then return end
if not by_player_name then return end
reason = reason or 'None given.'
reason = reason or "None given."
local warning_count
PlayerWarnings:update(player.name, function(_, warnings)
local warning = {
by_player_name = by_player_name,
reason = reason
reason = reason,
}
if not warnings then
warning_count = 1
return {warning}
return { warning }
else
table.insert(warnings, warning)
warning_count = #warnings
@@ -129,20 +130,20 @@ function Warnings.add_warning(player, by_player_name, reason)
player_index = player.index,
warning_count = warning_count,
by_player_name = by_player_name,
reason = reason
reason = reason,
})
local action = config.actions[warning_count]
if action then
local _type = type(action)
if _type == 'function' then
if _type == "function" then
action(player, by_player_name, warning_count)
elseif _type == 'table' then
elseif _type == "table" then
local current = table.deepcopy(action)
table.insert(current, 2,by_player_name)
table.insert(current, 3,warning_count)
table.insert(current, 2, by_player_name)
table.insert(current, 3, warning_count)
player.print(current)
elseif type(action) == 'string' then
elseif type(action) == "string" then
player.print(action)
end
end
@@ -166,7 +167,7 @@ local function warning_removed_event(player, warning_by_name, removed_by_name, w
warning_by_name = warning_by_name,
removed_by_name = removed_by_name,
batch_count = batch_count or 1,
batch = batch or 1
batch = batch or 1,
})
end
@@ -206,7 +207,7 @@ function Warnings.clear_warnings(player, by_player_name)
local warning_count = #warnings
for n, warning in pairs(warnings) do
warning_removed_event(player, warning.by_player_name, by_player_name, warning_count-n, n, warning_count)
warning_removed_event(player, warning.by_player_name, by_player_name, warning_count - n, n, warning_count)
end
PlayerWarnings:remove(player)
@@ -236,7 +237,7 @@ function Warnings.add_script_warning(player, reason)
player = valid_player(player)
if not player then return end
reason = reason or 'Non given.'
reason = reason or "Non given."
local warnings = user_script_warnings[player.name]
if not warnings then
@@ -246,7 +247,7 @@ function Warnings.add_script_warning(player, reason)
table.insert(warnings, {
tick = game.tick,
reason = reason
reason = reason,
})
local warning_count = #warnings
@@ -256,11 +257,11 @@ function Warnings.add_script_warning(player, reason)
tick = game.tick,
player_index = player.index,
warning_count = warning_count,
reason = reason
reason = reason,
})
if warning_count > config.script_warning_limit then
Warnings.add_warning(player, '<server>', reason)
Warnings.add_warning(player, "<server>", reason)
end
return warning_count
@@ -274,7 +275,7 @@ local function script_warning_removed_event(player, warning_count)
name = Warnings.events.on_script_warning_removed,
tick = game.tick,
player_index = player.index,
warning_count = warning_count
warning_count = warning_count,
})
end
@@ -306,7 +307,7 @@ function Warnings.clear_script_warnings(player)
local warning_count = #warnings
for n, _ in pairs(warnings) do
script_warning_removed_event(player, warning_count-n)
script_warning_removed_event(player, warning_count - n)
end
user_script_warnings[player.name] = nil
@@ -314,8 +315,8 @@ function Warnings.clear_script_warnings(player)
end
-- script warnings are removed after a certain amount of time to make them even more lienient
local script_warning_cool_down = config.script_warning_cool_down*3600
Event.on_nth_tick(script_warning_cool_down/4, function()
local script_warning_cool_down = config.script_warning_cool_down * 3600
Event.on_nth_tick(script_warning_cool_down / 4, function()
local cutoff = game.tick - script_warning_cool_down
for player_name, script_warnings in pairs(user_script_warnings) do
if #script_warnings > 0 then
@@ -328,4 +329,4 @@ Event.on_nth_tick(script_warning_cool_down/4, function()
end
end)
return Warnings
return Warnings

View File

@@ -26,14 +26,14 @@ local Storage = require("modules/exp_util/storage")
local config = require("modules.exp_legacy.config.gui.warps") --- @dep config.warps
--- Stores all data for the warp system
local WrapData = Datastore.connect('WrapData')
local WrapData = Datastore.connect("WrapData")
WrapData:set_serializer(function(raw_key) return raw_key.warp_id end)
local Warps = {}
-- Storage lookup table for force name to task ids
local force_warps = {_uid=1}
---@cast force_warps table<string, { spawn: string, [number]: string }>
local force_warps = { _uid = 1 }
--- @cast force_warps table<string, { spawn: string, [number]: string }>
Storage.register(force_warps, function(tbl)
force_warps = tbl
end)
@@ -65,13 +65,13 @@ WrapData:on_update(function(warp_id, warp, old_warp)
for _, next_warp_id in pairs(warp_ids) do
local next_warp = WrapData:get(next_warp_id)
if next_warp_id ~= spawn_id then
warp_names[next_warp.name..next_warp_id] = next_warp_id
warp_names[next_warp.name .. next_warp_id] = next_warp_id
end
end
-- Sort the warp names in alphabetical order
local new_warp_ids = table.get_values(table.keysort(warp_names))
table.insert(new_warp_ids, 1,spawn_id)
table.insert(new_warp_ids, 1, spawn_id)
new_warp_ids.spawn = spawn_id
force_warps[force_name] = new_warp_ids
end
@@ -98,7 +98,7 @@ function Warps.make_warp_tag(warp_id)
local tag = warp.tag
if tag and tag.valid then
tag.text = 'Warp: ' .. name
tag.text = "Warp: " .. name
tag.icon = icon
return false
end
@@ -109,9 +109,9 @@ function Warps.make_warp_tag(warp_id)
local position = warp.position
tag = force.add_chart_tag(surface, {
position = {position.x+0.5, position.y+0.5},
text = 'Warp: ' .. name,
icon = icon
position = { position.x + 0.5, position.y + 0.5 },
text = "Warp: " .. name,
icon = icon,
})
-- Add the tag to this warp, store.update not needed as we dont want it to trigger
@@ -165,16 +165,17 @@ function Warps.make_warp_area(warp_id)
-- Add a tile pattern on top of the base
local tiles = {}
for _, tile in pairs(config.tiles) do
table.insert(tiles, {name=tile[1], position={tile[2]+posx, tile[3]+posy}})
table.insert(tiles, { name = tile[1], position = { tile[2] + posx, tile[3] + posy } })
end
surface.set_tiles(tiles)
-- Add entities to the warp structure
for _, entity in pairs(config.entities) do
entity = surface.create_entity{
name=entity[1],
position={entity[2]+posx, entity[3]+posy},
force='neutral'
name = entity[1],
position = { entity[2] + posx, entity[3] + posy },
force = "neutral",
}
entity.destructible = false
entity.health = 0
@@ -182,7 +183,7 @@ function Warps.make_warp_area(warp_id)
entity.rotatable = false
-- Save reference of the last power pole
if entity.type == 'electric-pole' then
if entity.type == "electric-pole" then
warp.electric_pole = entity
end
end
@@ -209,18 +210,18 @@ function Warps.remove_warp_area(warp_id)
local tiles = {}
for _, tile in pairs(config.tiles) do
table.insert(tiles, {name=old_tile, position={tile[2]+position.x, tile[3]+position.y}})
table.insert(tiles, { name = old_tile, position = { tile[2] + position.x, tile[3] + position.y } })
end
surface.set_tiles(tiles)
local area = {
{position.x-radius, position.y-radius},
{position.x+radius, position.y+radius}
{ position.x - radius, position.y - radius },
{ position.x + radius, position.y + radius },
}
-- Remove warp structure entities
local entities = surface.find_entities_filtered{ force='neutral', area=area, name = remove_warp_area_entity_names }
local entities = surface.find_entities_filtered{ force = "neutral", area = area, name = remove_warp_area_entity_names }
for _, entity in pairs(entities) do
-- Destroy them, this will leave corpses of the entities that it destroyed.
if entity and entity.valid and entity.destructible == false then
@@ -228,6 +229,7 @@ function Warps.remove_warp_area(warp_id)
entity.die(entity.force)
end
end
-- Rechart map area, useful if warp is not covered by a radar
game.forces[warp.force_name].chart(surface, area)
end
@@ -269,8 +271,8 @@ function Warps.teleport_player(warp_id, player)
local warp = WrapData:get(warp_id)
local surface = warp.surface
local position = {
x=warp.position.x+0.5,
y=warp.position.y+0.5
x = warp.position.x + 0.5,
y = warp.position.y + 0.5,
}
if player.vehicle then
@@ -285,13 +287,13 @@ function Warps.teleport_player(warp_id, player)
if not entity.teleport(goto_position) then
player.driving = false
-- Need to calculate new goto_position because entities have different collision boxes
goto_position = surface.find_non_colliding_position('character', position, 32, 1)
goto_position = surface.find_non_colliding_position("character", position, 32, 1)
player.teleport(goto_position, surface)
end
end
else
-- Teleport the player
local goto_position = surface.find_non_colliding_position('character', position, 32, 1)
local goto_position = surface.find_non_colliding_position("character", position, 32, 1)
if player.driving then player.driving = false end
player.teleport(goto_position, surface)
end
@@ -318,7 +320,7 @@ function Warps.add_warp(force_name, surface, position, player_name, warp_name)
-- Get new warp id
local warp_id = tostring(force_warps._uid)
force_warps._uid = force_warps._uid + 1
warp_name = warp_name or 'New warp'
warp_name = warp_name or "New warp"
-- Get the existing warps for this force
local warp_ids = force_warps[force_name]
@@ -345,9 +347,9 @@ function Warps.add_warp(force_name, surface, position, player_name, warp_name)
surface = surface,
position = {
x = math.floor(position.x),
y = math.floor(position.y)
y = math.floor(position.y),
},
last_edit_name = player_name or '<server>',
last_edit_name = player_name or "<server>",
last_edit_time = game.tick,
currently_editing = editing,
updates = 0,
@@ -389,7 +391,7 @@ function Warps.update_warp(warp_id, new_name, new_icon, player_name)
new_icon = warp.icon
end
warp.last_edit_name = player_name or '<server>'
warp.last_edit_name = player_name or "<server>"
warp.last_edit_time = game.tick
warp.name = new_name or warp.name
warp.icon = new_icon or warp.icon