mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Fix use of created_entity
This commit is contained in:
@@ -15,6 +15,8 @@ local directions = {
|
|||||||
["SW"] = 0.875,
|
["SW"] = 0.875,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- @param entity LuaEntity
|
||||||
|
--- @return string
|
||||||
local function get_direction(entity)
|
local function get_direction(entity)
|
||||||
local angle = math.atan2(entity.position.y, entity.position.x) / math.pi
|
local angle = math.atan2(entity.position.y, entity.position.x) / math.pi
|
||||||
for direction, required_angle in pairs(directions) do
|
for direction, required_angle in pairs(directions) do
|
||||||
@@ -29,19 +31,20 @@ end
|
|||||||
local custom_string = " *"
|
local custom_string = " *"
|
||||||
local custom_string_len = #custom_string
|
local custom_string_len = #custom_string
|
||||||
|
|
||||||
|
--- @param event EventData.on_built_entity | EventData.on_robot_built_entity
|
||||||
local function station_name_changer(event)
|
local function station_name_changer(event)
|
||||||
local entity = event.created_entity
|
local entity = event.entity
|
||||||
local name = entity.name
|
local name = entity.name
|
||||||
if name == "entity-ghost" then
|
if name == "entity-ghost" then
|
||||||
if entity.ghost_name ~= "train-stop" then return end
|
if entity.ghost_name ~= "train-stop" then return end
|
||||||
local backername = entity.backer_name
|
local backer_name = entity.backer_name
|
||||||
if backername ~= "" then
|
if backer_name ~= "" then
|
||||||
entity.backer_name = backername .. custom_string
|
entity.backer_name = backer_name .. custom_string
|
||||||
end
|
end
|
||||||
elseif name == "train-stop" then -- only do the event if its a train stop
|
elseif name == "train-stop" then -- only do the event if its a train stop
|
||||||
local backername = entity.backer_name
|
local backer_name = entity.backer_name or ""
|
||||||
if backername:sub(-custom_string_len) == custom_string then
|
if backer_name:sub(-custom_string_len) == custom_string then
|
||||||
entity.backer_name = backername:sub(1, -custom_string_len - 1)
|
entity.backer_name = backer_name:sub(1, -custom_string_len - 1)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -49,14 +52,14 @@ local function station_name_changer(event)
|
|||||||
-- expanded box for recourse search:
|
-- expanded box for recourse search:
|
||||||
local bounding2 = { { bounding_box.left_top.x - 100, bounding_box.left_top.y - 100 }, { bounding_box.right_bottom.x + 100, bounding_box.right_bottom.y + 100 } }
|
local bounding2 = { { bounding_box.left_top.x - 100, bounding_box.left_top.y - 100 }, { bounding_box.right_bottom.x + 100, bounding_box.right_bottom.y + 100 } }
|
||||||
-- gets all resources in bounding_box2:
|
-- gets all resources in bounding_box2:
|
||||||
local recourses = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" }
|
local resources = game.surfaces[1].find_entities_filtered{ area = bounding2, type = "resource" }
|
||||||
if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2
|
if #resources > 0 then -- save cpu time if their are no resources in bounding_box2
|
||||||
local closest_distance
|
local closest_distance
|
||||||
local px, py = bounding_box.left_top.x, bounding_box.left_top.y
|
local px, py = bounding_box.left_top.x, bounding_box.left_top.y
|
||||||
local recourse_closed
|
local recourse_closed
|
||||||
|
|
||||||
-- Check which recourse is closest
|
-- Check which recourse is closest
|
||||||
for i, item in ipairs(recourses) do
|
for i, item in ipairs(resources) do
|
||||||
local dx, dy = px - item.bounding_box.left_top.x, py - item.bounding_box.left_top.y
|
local dx, dy = px - item.bounding_box.left_top.x, py - item.bounding_box.left_top.y
|
||||||
local distance = (dx * dx) + (dy * dy)
|
local distance = (dx * dx) + (dy * dy)
|
||||||
if not closest_distance or distance < closest_distance then
|
if not closest_distance or distance < closest_distance then
|
||||||
|
|||||||
@@ -195,8 +195,9 @@ Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- Adds a silo to the list when it is built
|
--- Adds a silo to the list when it is built
|
||||||
|
--- @param event EventData.on_built_entity | EventData.on_robot_built_entity
|
||||||
local function on_built(event)
|
local function on_built(event)
|
||||||
local entity = event.created_entity
|
local entity = event.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 = entity.force
|
||||||
local force_name = force.name
|
local force_name = force.name
|
||||||
|
|||||||
@@ -574,8 +574,9 @@ Event.on_nth_tick(150, function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- Adds a silo to the list when it is built
|
--- Adds a silo to the list when it is built
|
||||||
|
--- @param event EventData.on_built_entity | EventData.on_robot_built_entity
|
||||||
local function on_built(event)
|
local function on_built(event)
|
||||||
local entity = event.created_entity
|
local entity = event.entity
|
||||||
if entity.valid and entity.name == "rocket-silo" then
|
if entity.valid and entity.name == "rocket-silo" then
|
||||||
update_rocket_gui_progress(entity.force.name)
|
update_rocket_gui_progress(entity.force.name)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user