[2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
petrathekat
Burner Inserter
Burner Inserter
Posts: 15
Joined: Fri Apr 19, 2024 7:12 pm
Contact:

[2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by petrathekat »

According to the documentation, setting a cargo-pod's destination to defines.cargo_destination.surface should redirect the pod to a landing pad if available.
Cargo pods will switch destination type from surface to station before starting descent if there is a station available and CargoDestination::position has not been specified.
However, this does not appear to be the case. It instead will always send the pod to near 0,0 of that surface, even if there is a landing pad on the surface.

Specifically, I am making a rocket silo that launches rockets from Nauvis to the moon, or from the moon to Nauvis.
  • I have a custom rocket-silo prototype with launch_to_space_platforms = false.
  • It launches a custom rocket-silo-rocket with a custom cargo-pod.
  • In defines.events.on_cargo_pod_finished_ascending, I check if the cargo pod is of my custom type and that it's getting launched from Nauvis or its moon. If it is I set the whole cargo_pod_destination field to point to the other body.

Code: Select all

event.cargo_pod.cargo_pod_destination = { 
	type = defines.cargo_destination.surface, 
	surface = nauvis_if_moon_otherwise_moon_pseudocode(),
}
The cargo pod ends up on the right surface, just not the right place.

See the attached screenshot; that cargo pod was originally launched from the moon.
Attachments
Screenshot_20250401_221918.png
Screenshot_20250401_221918.png (1.93 MiB) Viewed 439 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 15268
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by Rseding91 »

Once the finished ascent event is running the descent logic has already started and the comment no longer applies.

The comment only applies if the target has been set before it finished ascending and switched to descending.
If you want to get ahold of me I'm almost always on Discord.
petrathekat
Burner Inserter
Burner Inserter
Posts: 15
Joined: Fri Apr 19, 2024 7:12 pm
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by petrathekat »

Okay. What event handler should I run that in? on_rocket_launched? event.rocket.cargo_pod.foobar() ?

Edit: I can't seem to find the cargo pod anywhere in on_rocket_launched. It does exist in on_rocket_launch_ordered (via event.rocket.attached_cargo_pod). However setting that pod's cargo_pod_destination in the way described above still sends it around 0,0 and not to the landing pad.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15268
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by Rseding91 »

Actually, I looked into this wrong to begin with. It appears that comment is simply wrong and there is no special logic anymore. It's from long go and simply was never removed.
If you want to get ahold of me I'm almost always on Discord.
petrathekat
Burner Inserter
Burner Inserter
Posts: 15
Joined: Fri Apr 19, 2024 7:12 pm
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by petrathekat »

Darn. Is there a script API way to hook into the game's cargo pad finding logic at all? (I suppose you could just search the surface for the cargo-landing-pad but this feels unperformant, so you'd have to cache it ... and presumably the Factorio engine already knows where it is.)
Rseding91
Factorio Staff
Factorio Staff
Posts: 15268
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by Rseding91 »

There currently is not. But it could be added fairly easily - the same thing that the existing cargo pod dispatch logic uses.
If you want to get ahold of me I'm almost always on Discord.
petrathekat
Burner Inserter
Burner Inserter
Posts: 15
Joined: Fri Apr 19, 2024 7:12 pm
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by petrathekat »

Would you please add it? :)

I can open a new thread if this thread has diverged too far from the original post topic.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15268
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by Rseding91 »

So, more developments. The original comment *is true* except in the case of setting the destination to "surface" while that surface is the same surface the pod is on. In that case, the act of setting it to "surface" causes it to find a landing spot on that surface at that very moment and it will never land in a station.
If you want to get ahold of me I'm almost always on Discord.
Xorimuth
Filter Inserter
Filter Inserter
Posts: 727
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [2.0.43] Setting a cargo pod's destination to `defines.cargo_pod.surface` will not redirect it to a cargo bay

Post by Xorimuth »

petrathekat wrote: Wed Apr 02, 2025 5:47 pm Okay. What event handler should I run that in? on_rocket_launched? event.rocket.cargo_pod.foobar() ?

Edit: I can't seem to find the cargo pod anywhere in on_rocket_launched. It does exist in on_rocket_launch_ordered (via event.rocket.attached_cargo_pod). However setting that pod's cargo_pod_destination in the way described above still sends it around 0,0 and not to the landing pad.
Personally I'd use on_rocket_launch_ordered yes, but it should work fine in on_cargo_pod_finished_ascending too because the event is raised just before it switches the cargo pod's surface and does the processing around that.

I suspect your problem is that the cargo landing pad hasn't been set to accept your custom cargo-pod. You might need to add your cargo-pods to this list https://lua-api.factorio.com/latest/typ ... argo_units.

E.g.

Code: Select all

for _, hatch in pairs(data.raw["cargo-landing-pad"]["cargo-landing-pad"].cargo_station_parameters.hatch_definitions) do
  table.insert(hatch.receiving_cargo_units, "your-custom-cargo-pod")
end
I use this exact functionality in my mod Lunar Landings, to deliver cargo to the landing pad on Nauvis if there is one, and they drop around {0, 0} if there isn't: https://github.com/tburrows13/LunarLand ... #L401-L411
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Post Reply

Return to “Modding interface requests”