Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ local ensure_storages = function()
end
-- non surface specific settings
storage.job_start_delay = storage.job_start_delay or 300 -- five seconds
storage.entities_per_second = storage.entities_per_second or 1000
if storage.debug_toggle == nil then
storage.debug_toggle = false
end
Expand Down Expand Up @@ -384,6 +383,7 @@ script.on_event(ev.on_lua_shortcut, function (event)
end
end)

---@param event EventData.on_custom_input
script.on_event("ctron-get-selection-tool", function (event)
local name = event.input_name
if name ~= "ctron-get-selection-tool" then return end
Expand Down
2 changes: 1 addition & 1 deletion data/selection_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data:extend(
select = {
border_color = { r = 0, g = 0, b = 0.5 }, -- blue
cursor_box_type = "entity",
mode = { "entity-ghost", "tile-ghost" }
mode = { "any-entity", "tile-ghost", "same-force" }
},

-- shift left click
Expand Down
7 changes: 3 additions & 4 deletions script/entity_processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,11 @@ script.on_event(ev.on_player_selected_area, function(event)
if entity and entity.valid then
if entity.type == 'entity-ghost' or entity.type == 'tile-ghost' or entity.type == 'item-request-proxy' then
entity_proc.create_chunk(entity, storage.construction_queue[surface_index], surface_index, true)
elseif entity.to_be_upgraded() then
entity_proc.create_chunk(entity, storage.upgrade_queue[surface_index], surface_index, true)
end
end
end
for _, entity in pairs(event.surface.find_entities_filtered{area=event.area, type='item-request-proxy'}) do
entity_proc.create_chunk(entity, storage.construction_queue[surface_index], surface_index, true)
end
end)

-- right click
Expand Down Expand Up @@ -452,7 +451,7 @@ entity_proc.deconstruction = function(entity)
storage.entity_inventory_cache[entity_name] = {}
local max_index = entity.get_max_inventory_index()
for i = 1, max_index do
local inventory = entity.get_inventory(i)
local inventory = entity.get_inventory(i --[[@as defines.inventory]])
if (inventory ~= nil) then
table.insert(storage.entity_inventory_cache[entity_name], i) -- add inventory defines index to cache against the entity
end
Expand Down
19 changes: 11 additions & 8 deletions script/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ end
function job:request_items(item_list)
self.job_status = {"ctron_status.requesting_items"}
local slot = 1
local logistic_point = self.worker.get_logistic_point(0) ---@cast logistic_point -nil
local logistic_point = self.worker.get_logistic_point(defines.logistic_member_index.spidertron_requester) ---@cast logistic_point -nil
local section = logistic_point.get_section(1)
-- disable trash unrequested
if logistic_point.trash_not_requested then
Expand All @@ -443,6 +443,8 @@ function job:request_items(item_list)
end
end

---@param construction_robots table<LuaEntity>
---@return boolean
function job:check_robot_activity(construction_robots)
self.last_robot_orientations = self.last_robot_orientations or {}
local moved_robot_count = 0
Expand Down Expand Up @@ -471,6 +473,7 @@ function job:check_robot_activity(construction_robots)
return true
end

---@return boolean
function job:validate_worker()
if self.worker and self.worker.valid then
return true
Expand All @@ -489,10 +492,9 @@ function job:validate_worker()
self.worker_inventory = self.worker.get_inventory(defines.inventory.spider_trunk)
self.worker_ammo_slots = self.worker.get_inventory(defines.inventory.spider_ammo)
self.worker_trash_inventory = self.worker.get_inventory(defines.inventory.spider_trash)
else
return false
end
end
return false
end

function job:validate_station()
Expand Down Expand Up @@ -608,7 +610,7 @@ function job:validate_logisitics()
self.worker_logistic_network = self.worker_logistic_cell.logistic_network
end
-- validate that there is a logisitic section available, if not create one
local logistic_point = worker.get_logistic_point(0) ---@cast logistic_point -nil
local logistic_point = worker.get_logistic_point(defines.logistic_member_index.spidertron_requester) ---@cast logistic_point -nil
local section = logistic_point.get_section(1)
if not section then
logistic_point.add_section()
Expand Down Expand Up @@ -672,7 +674,7 @@ end
-- this function lists the current item requests of the worker
function job:list_item_requests()
local worker = self.worker ---@cast worker -nil
local logistic_point = worker.get_logistic_point(0) ---@cast logistic_point -nil
local logistic_point = worker.get_logistic_point(defines.logistic_member_index.spidertron_requester) ---@cast logistic_point -nil
local section = logistic_point.get_section(1)
return section.filters or {}
end
Expand All @@ -681,7 +683,7 @@ end
---@return boolean
function job:check_item_request_fulfillment()
local worker = self.worker ---@cast worker -nil
local logistic_point = worker.get_logistic_point(0) ---@cast logistic_point -nil
local logistic_point = worker.get_logistic_point(defines.logistic_member_index.spidertron_requester) ---@cast logistic_point -nil
local section = logistic_point.get_section(1)
local is_fulfilled = true
local inventory_items = util_func.convert_to_item_list(self.worker_inventory.get_contents()) -- spider inventory contents
Expand Down Expand Up @@ -1081,7 +1083,7 @@ function job:starting()
return
else
-- check if there are any items being delivered
local requester_point = worker.get_logistic_point(0) ---@cast requester_point -nil
local requester_point = worker.get_logistic_point(defines.logistic_member_index.spidertron_requester) ---@cast requester_point -nil
if next(requester_point.targeted_items_deliver) then return end
-- check if requested items have been delivered
if not self:check_item_request_fulfillment() then
Expand Down Expand Up @@ -1136,6 +1138,7 @@ function job:in_progress()

-- Am I in the correct position?
local _, task_position = next(self.task_positions)
---@cast task_position MapPosition
if not self:position_check(task_position, 3) then return end

--===========================================================================--
Expand Down Expand Up @@ -1172,7 +1175,7 @@ function job:finishing()
-- clear items
if not self:clear_items() then return end
-- clear logistic requests
local logistic_point = self.worker.get_logistic_point(0) ---@cast logistic_point -nil
local logistic_point = self.worker.get_logistic_point(defines.logistic_member_index.spidertron_requester) ---@cast logistic_point -nil
local section = logistic_point.get_section(1)
section.filters = {}
-- randomize idle position around station
Expand Down
8 changes: 6 additions & 2 deletions script/job/destroy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ function destroy_job:in_progress()
local bomb = storage.atomic_ammo_name[self.surface_index]
self.worker_inventory.remove({name = bomb.name, quality = bomb.quality, count = 1})
self:launch_nuke(entity, surounding_entities)
if distance_from_pos < 36 then
-- move to safe position to avoid entering the explosion radius
worker.autopilot_destination = self.safe_positions[#self.safe_positions]
end
return
end
else
Expand Down Expand Up @@ -394,8 +398,8 @@ function destroy_job:launch_nuke(target, surounding_entities)
speed = 0.4,
force = worker.force
}
-- move to safe position to avoid entering the explosion radius
worker.autopilot_destination = self.safe_positions[#self.safe_positions]
-- stop moving
worker.autopilot_destination = nil
-- mark surounding_entities as considered targets to avoid double ups
self.considered_spawners[target.unit_number] = true
for _, neighbour_entity in pairs(surounding_entities) do
Expand Down
8 changes: 8 additions & 0 deletions script/job_processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ local job_types = {
["destroy"] = destroy_job
}

---@param surface_index uint
job_proc.process_queues = function(surface_index)
if not (storage.available_ctron_count[surface_index] > 0) then return end
for job_type, job_class in pairs(job_types) do
job_proc.process_queue(surface_index, job_type, job_class)
end
end

--- Process a single job queue
---@param surface_index uint
---@param job_type string
---@param job_class job
job_proc.process_queue = function(surface_index, job_type, job_class)
local job_start_delay = storage.job_start_delay
for _, chunk in pairs(storage[job_type .. '_queue'][surface_index]) do
Expand All @@ -73,6 +78,9 @@ job_proc.process_queue = function(surface_index, job_type, job_class)
if not storage.horde_mode[surface_index] then
storage.jobs[storage.job_index]:claim_chunks_in_proximity()
end
if job_type == "destroy" then
break -- to allow minion assignment
end
else
-- clear the chunk from the queue
storage[job_type .. "_queue"][surface_index][chunk.key] = nil
Expand Down
12 changes: 5 additions & 7 deletions script/type_annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

-- [ALIASES]

---@alias Area BoundingBox

---@alias ItemCounts table<string, integer>
---@alias ItemCounts table<string, table<string, integer>>

---@alias EntityQueue table<uint, table<string, Chunk>>

Expand All @@ -32,7 +30,6 @@
---@field initial_target MapPosition?

---@class Chunk
---@field area Area
---@field key string
---@field surface uint
---@field last_update_tick uint
Expand All @@ -42,6 +39,7 @@
---@field merged boolean?
---@field required_items ItemCounts
---@field trash_items ItemCounts
---@field skip_chunk_checks boolean?

---@class job
---@field job_index uint
Expand All @@ -63,6 +61,7 @@
---@field considered_spawners table
---@field minion_jobs table
---@field safe_positions table
---@field vassal_jobs job

---@class RegisteredEntity
---@field name string
Expand Down Expand Up @@ -141,7 +140,6 @@
---@field desired_robot_name string
---@field repair_tool_name string
---@field construction_mat_alert uint
---@field entities_per_second uint
---@field spider_remote_toggle boolean
---@field ammo_name string
---@field ammo_count uint
Expand All @@ -150,5 +148,5 @@
--- @field user_interface table<uint, any?>

-- set type of global (this will never get executed, only intellisense will see this)
---@type Global
__Constructron_Continued__global = {}
-- ---@type Global
-- __Constructron_Continued__global = {}
8 changes: 4 additions & 4 deletions script/utility_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ local color_table = {
}

---@param constructron LuaEntity
---@param job_type "idle" | "construction" | "deconstruction" | "destroy" | "upgrade" | "repair" | "utility" | "cargo" | "minion"
---@param job_type JobTypes | "idle"
me.paint_constructron = function(constructron, job_type)
if not (constructron and constructron.valid) then return end
local color = color_table[job_type]
Expand Down Expand Up @@ -143,7 +143,7 @@ me.position_from_chunk = function(chunk_index)
end

---@param chunk_index ChunkPosition
---@return Area
---@return BoundingBox
me.get_area_from_chunk = function(chunk_index)
local area = {{
y = chunk_index.y * 80,
Expand All @@ -157,7 +157,7 @@ end

---@param position MapPosition
---@param range number
---@return Area
---@return BoundingBox
me.get_area_from_position = function(position, range)
local area = {{
y = (position.y) - range,
Expand All @@ -169,7 +169,7 @@ me.get_area_from_position = function(position, range)
return area
end

---@param area Area
---@param area BoundingBox
---@param radius float
---@return MapPosition[]
me.calculate_construct_positions = function(area, radius)
Expand Down