Stop cargo pods landing without a cargo pad

Place to get help with not working mods / modding interface.
reaperrar
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Mar 14, 2016 5:47 am
Contact:

Stop cargo pods landing without a cargo pad

Post by reaperrar »

I have this mod - https://mods.factorio.com/mod/fragile-cargo-pods
Cargo pods break when hitting the surface of planets. You need landing pads! Ensures a fresh start on each planet.

For now, you'll have to disable the mod if landing fresh on Aquilo.

Todo: Disable once Aquilo is unlocked, or only destroy pods landing on some planet surfaces. If anyone knows how to achieve this please let me know.
I'm trying to work out the todo part above & hoping someone might have some insight.

Getting technical - the "cargo-pod" entity spawns a "cargo-pod-container" which is a "temporary-container" prototype. To achieve what I have so far I set the "cargo-pod-container"'s TTL to 1 tick, basically causing instant death.

My first attempt at this involved searching for all cargo-pod-container's every 1 second and destroy()ing them. However, This seemed to introduce some stutter each time the search occurred so I'm presuming it was too intensive an operation. Plus, the cargo-pod-container would be on the surface for up to 1 second before I could destroy it.

The second attempt involved modifying the prototype at runtime so the TTL is set based on if Aquilo research has been unlocked. However, as most probably know but I just found out, you can't modify the prototype at runtime.

The third attempt involved setting the surface properties (inherited field of "temporary-container" prototypes) to match that of Aquilo but it didn't seem to have any effect.

I've also tried to find an event the script can listen to that triggers when the "cargo-pod-container" spawns, but found nothing.

Does anyone know how I might achieve what I'm after?
s6x
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Nov 15, 2024 8:22 pm
Contact:

Re: Stop cargo pods landing without a cargo pad

Post by s6x »

I was able to make this work by listening to on_entity_died.

data.lua

Code: Select all

local durable_container = util.table.deepcopy(data.raw["temporary-container"]["cargo-pod-container"])
durable_container.name = "fcp-durable-cargo-pod-container"
durable_container.localised_name = { "entity-name.cargo-pod-container" }

local breaking_container = util.table.deepcopy(data.raw["temporary-container"]["cargo-pod-container"])
breaking_container.name = "fcp-breaking-cargo-pod-container"
breaking_container.localised_name = { "entity-name.cargo-pod-container" }
breaking_container.time_to_live = 1

data:extend({durable_container, breaking_container})

data.raw["temporary-container"]["cargo-pod-container"].time_to_live = 1
data.raw["temporary-container"]["cargo-pod-container"].dying_explosion = nil
data.raw["temporary-container"]["cargo-pod-container"].remains_when_mined = nil
control.lua

Code: Select all

function cargo_pod_died(event)
	local pod = event.entity
	local replacement_name
	
	if (pod.surface.name == "aquilo") then
		replacement_name = "fcp-durable-cargo-pod-container"
	else
		replacement_name = "fcp-breaking-cargo-pod-container"
	end
	
	local newpod = pod.surface.create_entity({
		name = replacement_name,
		position = pod.position,
		force = pod.force,
		fast_replace = true,
		create_build_effect_smoke = false
	})
end
script.on_event(defines.events.on_entity_died, cargo_pod_died, {{filter = "name", name = "cargo-pod-container"}})
reaperrar
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Mar 14, 2016 5:47 am
Contact:

Re: Stop cargo pods landing without a cargo pad

Post by reaperrar »

Thanks s6x, that seems to work perfectly!

There's just one thing I can't wrap my head around, when calling create_entity how does the replacement entity have the same inventory as the destroyed one? I'm guessing it's something to do with the "fast_replace = true" but I can't see any noticeable reference to the event.entity to indicate what is supposed to be replaced.
s6x
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Nov 15, 2024 8:22 pm
Contact:

Re: Stop cargo pods landing without a cargo pad

Post by s6x »

I think it's because you're fast replacing a container and the new entity's position is exactly the same as the old entity's position, so it transfers the contents.
Post Reply

Return to “Modding help”