Skip to content

Commit

Permalink
Reworked the mod to be faster & simpeler (pickup pre-existing cannons…
Browse files Browse the repository at this point in the history
… before updating or you'll lose them)
  • Loading branch information
Quezler committed Dec 21, 2023
1 parent abf9073 commit 3dcc894
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 350 deletions.
21 changes: 18 additions & 3 deletions mods/se-interstellar-construction-requests-fulfillment/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
If you cannot be bothered so send construction materials to planets via rockets or ships, this might be the mod for you.

This mod was developed/tested in a controlled environment on a pre-multi-planet SE save, performance issues and bugs can be expected.

1.0 info:

The balance, if any, is that it takes a large amount of power for every single item you send,
so stuff you use en-masse like conveyors and inserters might still be worth sending via rocket.

This mod was developed/tested in a controlled environment on a pre-multi-planet SE save, performance issues and bugs can be expected.

(currently) not supported:
- curved rails
- deliveries other than modules
- no players online
- a "travel delay"

1.1 info:

You now only need one turret per logistic network, at the moment there are no power costs.

Adding a capsule is not feasible since the point ammo texture has no mask, and copying & recolloring it would break the space exploration licence.

Basically this mod is currently unbalanced as fuck, you just need a cannon at your mall and construction bots at the destination surface to place stuff.

todo:
- handle shooting to networks with no storage space available
- figuring out a nice cost that isn't a burden to distribute
- possibly looking into a shooting delay, but then again several turrets in the same network impacts performance and requests aren't split across them
- since you currently only need one i could have used the weapon delivery cannon texture as a base so its a large building, but i like the 4 barrels
44 changes: 27 additions & 17 deletions mods/se-interstellar-construction-requests-fulfillment/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,49 @@ for _, event in ipairs({
defines.events.on_entity_cloned,
}) do
script.on_event(event, Handler.on_created_entity, {
{filter = 'name', name = 'se-interstellar-construction-requests-fulfillment--turret'},
{filter = 'name', name = 'interstellar-construction-turret--buffer-chest'},
})
end

script.on_event(defines.events.on_entity_destroyed, Handler.on_entity_destroyed)

script.on_nth_tick(600, function(event) -- no_material_for_construction expires after 10 seconds
local forces_checked = {}

for _, player in ipairs(game.connected_players) do
if not forces_checked[player.force.index] then
forces_checked[player.force.index] = true
local alerts = player.get_alerts{
type = defines.alert_type.no_material_for_construction,
}

for surface_index, surface_alerts in pairs(alerts) do
for _, surface_alert in ipairs(surface_alerts[defines.alert_type.no_material_for_construction]) do
if surface_alert.target and surface_alert.target.valid and surface_alert.target.unit_number then
global.alert_targets[surface_alert.target.unit_number] = surface_alert.target
if not forces_checked[player.force.index] then

if player.is_alert_enabled(defines.alert_type.no_material_for_construction) then
forces_checked[player.force.index] = true
local alerts = player.get_alerts{
type = defines.alert_type.no_material_for_construction,
}

for surface_index, surface_alerts in pairs(alerts) do
for _, surface_alert in ipairs(surface_alerts[defines.alert_type.no_material_for_construction]) do
if surface_alert.target and surface_alert.target.valid and surface_alert.target.unit_number then
global.alert_targets[surface_alert.target.unit_number] = surface_alert.target
end
end
end
else
player.enable_alert(defines.alert_type.no_material_for_construction)
-- command response for `/alerts enable no_material_for_construction`
player.print('Alert type no_material_for_construction has been enabled.')
end
end
end

end -- if
end -- for

global.missing_items = {}
global.alert_targets_emptied = false
global.alert_targets_per_tick = math.ceil(table_size(global.alert_targets) / 600)
-- log('global.alert_targets_per_tick = ' .. global.alert_targets_per_tick)

-- todo: sort struct keys in order from networks with the most diverse amount of items to the lowest
end)

script.on_event(defines.events.on_tick, Handler.on_tick)
script.on_nth_tick(60 * 60 * 10, Handler.gc) -- every 10 minutes

commands.add_command('se-interstellar-construction-requests-fulfillment', nil, function(command)
local item_request_proxy_whitelist = {}
Expand All @@ -51,9 +63,7 @@ commands.add_command('se-interstellar-construction-requests-fulfillment', nil, f

local player = game.get_player(command.player_index)
player.print(serpent.block({
table_size(global.structs),
#global.deck,
#global.pile,
table_size(global.v1_structs),
'global.alert_targets = ' .. table_size(global.alert_targets),
'global.alert_targets_per_tick = ' .. global.alert_targets_per_tick,
'global.item_request_proxy_whitelist = ' .. table.concat(item_request_proxy_whitelist, ', '),
Expand Down
78 changes: 38 additions & 40 deletions mods/se-interstellar-construction-requests-fulfillment/data.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
local turret = table.deepcopy(data.raw['ammo-turret']['se-meteor-point-defence-container'])
turret.type = 'electric-turret'
turret.name = 'se-interstellar-construction-requests-fulfillment--turret'

local tint = {r=244, g=209, b=6}
turret.base_picture.layers[2].tint = tint
turret.base_picture.layers[2].hr_version.tint = tint

turret.icon = nil
turret.icons = table.deepcopy(data.raw['item']['se-meteor-point-defence'].icons)
turret.icons[2].tint = tint

turret.energy_source = {
buffer_capacity = "4GJ",
input_flow_limit = "0.1GW",
type = "electric",
usage_priority = "secondary-input"
}

turret.attack_parameters = {
ammo_type = {
category = "se-meteor-defence",
energy_consumption = "1GJ",
},
range = 1,
cooldown = 1,
type = "beam",
local buffer_chest = table.deepcopy(data.raw['logistic-container']['logistic-chest-buffer'])
buffer_chest.name = 'interstellar-construction-turret--buffer-chest'

buffer_chest.selection_box = {{-1.50, -1.50}, { 1.50, 1.50}}
buffer_chest.collision_box = {{-1.35, -1.35}, { 1.35, 1.35}}
buffer_chest.drawing_box = {{-1.35, -4.35}, { 1.35, 1.35}}

buffer_chest.icon = nil
buffer_chest.icons = table.deepcopy(data.raw['item']['se-meteor-point-defence'].icons)
buffer_chest.icons[2].tint = tint

buffer_chest.animation = table.deepcopy(data.raw['ammo-turret']['se-meteor-point-defence-container'].base_picture)
buffer_chest.animation.layers[2].tint = tint
buffer_chest.animation.layers[2].hr_version.tint = tint

buffer_chest.inventory_size = 30
buffer_chest.enable_inventory_bar = false

buffer_chest.circuit_wire_connection_point = nil
buffer_chest.circuit_wire_max_distance = nil
buffer_chest.corpse = "medium-remnants"
buffer_chest.dying_explosion = "medium-explosion"
buffer_chest.fast_replaceable_group = nil
buffer_chest.max_health = 2000
buffer_chest.resistances = {
{ type = "impact", percent = 100 },
{ type = "fire" , percent = 100 },
}

turret.localised_name = nil
turret.localised_description = nil
table.insert(buffer_chest.flags, "hide-alt-info")
table.insert(buffer_chest.flags, "no-automated-item-removal")
table.insert(buffer_chest.flags, "no-automated-item-insertion")

-- log(serpent.block(buffer_chest))

--

Expand All @@ -44,15 +49,15 @@ local item = {
item.icons = table.deepcopy(data.raw['item']['se-meteor-point-defence']).icons
item.icons[2].tint = tint

item.place_result = turret.name
turret.minable.result = item.name
item.place_result = buffer_chest.name
buffer_chest.minable.result = item.name

--

local recipe = {
type = 'recipe',
name = 'se-interstellar-construction-requests-fulfillment--recipe',
result = 'se-interstellar-construction-requests-fulfillment--item',
result = item.name,
enabled = false,
energy_required = 5,
ingredients = {
Expand Down Expand Up @@ -90,16 +95,9 @@ 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, uplink})
--

data:extend({buffer_chest, item, recipe, technology})
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.22",
"version": "1.1.0",
"author": "Quezler",
"factorio_version": "1.1",
"dependencies": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[entity-name]
se-interstellar-construction-requests-fulfillment--turret=Interstellar construction turret
interstellar-construction-turret--buffer-chest=Interstellar construction turret

[technology-name]
se-interstellar-construction-requests-fulfillment--technology=Interstellar construction turrets
Expand Down
Loading

0 comments on commit 3dcc894

Please sign in to comment.