Skip to content

Commit

Permalink
Add flashing logistics icon and lookup the logistic network through t…
Browse files Browse the repository at this point in the history
…here
  • Loading branch information
Quezler committed Dec 11, 2023
1 parent 893ee5e commit 4672f59
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
11 changes: 10 additions & 1 deletion mods/se-interstellar-construction-requests-fulfillment/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ local technology = {
}
}

local uplink = table.deepcopy(data.raw['logistic-container']['logistic-chest-buffer'])
uplink.name = 'se-interstellar-construction-requests-fulfillment--buffer-chest'
uplink.flags = {'not-on-map', 'no-automated-item-removal', 'no-automated-item-insertion'}
uplink.selectable_in_game = false
uplink.animation = util.empty_sprite()
uplink.collision_mask = {}
uplink.selection_box = {{-1.5, -1.5}, {1.5, 1.5}}
-- log(serpent.block(uplink))

technology.icons = table.deepcopy(data.raw['technology']['se-meteor-point-defence']).icons
technology.icons[2].tint = tint

data:extend({turret, item, recipe, technology})
data:extend({turret, item, recipe, technology, uplink})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "se-interstellar-construction-requests-fulfillment",
"title": "Space Exploration - interstellar construction requests fulfillment",
"description": "Keeping building equipment stocked at every planet is tedious, just shoot it there from nauvis.",
"version": "1.0.7",
"version": "1.0.8",
"author": "Quezler",
"factorio_version": "1.1",
"dependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function Handler.on_init(event)
global.alert_targets = {}
global.alert_targets_per_tick = 1

global.children_to_kill = {}

-- log('items_to_place_this')
-- for _, entity_prototype in pairs(game.entity_prototypes) do
-- for _, item_to_place_this in pairs(entity_prototype.items_to_place_this or {}) do
Expand All @@ -32,24 +34,47 @@ end
function Handler.on_configuration_changed(event)
global.alert_targets = global.alert_targets or {}
global.alert_targets_per_tick = global.alert_targets_per_tick or 1

global.children_to_kill = global.children_to_kill or {}

for unit_number, struct in pairs(global.structs) do
if struct.entity.valid and not struct.buffer_chest then
Handler.create_buffer_chest_for(struct)
end
end
end

function Handler.on_created_entity(event)
local entity = event.created_entity or event.entity or event.destination

entity.active = false

global.structs[entity.unit_number] = {
local struct = {
unit_number = entity.unit_number,
entity = entity,
barrel = 0,
proxy = nil, -- entity occupied if present and valid
updated_at = game.tick,
}

Handler.create_buffer_chest_for(struct)
global.structs[entity.unit_number] = struct
table.insert(global.pile, entity.unit_number)
end

function Handler.create_buffer_chest_for(struct)
local chest = struct.entity.surface.create_entity{
name = 'se-interstellar-construction-requests-fulfillment--buffer-chest',
force = struct.entity.force,
position = struct.entity.position,
}

chest.destructible = false
struct.buffer_chest = chest

global.children_to_kill[script.register_on_entity_destroyed(struct.entity)] = chest
end

function Handler.shuffle_array_in_place(t)
for i = #t, 2, -1 do
local j = math.random(i)
Expand Down Expand Up @@ -80,7 +105,9 @@ function Handler.draw_random_card()

if struct.entity.energy >= Handler.get_energy_per_shot() then
if not struct.proxy or not struct.proxy.valid then
return struct
if struct.buffer_chest.logistic_network then
return struct
end
end
end

Expand Down Expand Up @@ -124,9 +151,7 @@ function Handler.handle_construction_alert(alert_target)
if not struct then break end

if alert_target.force == struct.entity.force then
-- we're gonna check for orange coverage for now, instead of green venn diagrams and filtering out personal roboports
local network = struct.entity.surface.find_logistic_network_by_position(struct.entity.position, struct.entity.force)
if network and network.can_satisfy_request(item_to_place_this.name, item_to_place_this.count, true) then
if struct.buffer_chest.logistic_network.can_satisfy_request(item_to_place_this.name, item_to_place_this.count, true) then
local proxy = struct.entity.surface.create_entity{
name = 'item-request-proxy',
force = struct.entity.force,
Expand Down Expand Up @@ -208,6 +233,13 @@ function Handler.on_entity_destroyed(event)

end
end

local child = global.children_to_kill[event.registration_number]
if child then global.children_to_kill[event.registration_number] = nil
if child.valid then
child.destroy()
end
end
end

function Handler.on_tick(event)
Expand Down

0 comments on commit 4672f59

Please sign in to comment.