Page 1 of 1

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

Posted: Wed Apr 02, 2025 3:25 am
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.

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

Posted: Wed Apr 02, 2025 11:35 am
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.

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

Posted: Wed Apr 02, 2025 5:47 pm
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.

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

Posted: Wed Apr 02, 2025 7:00 pm
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.

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

Posted: Wed Apr 02, 2025 7:36 pm
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.)

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

Posted: Wed Apr 02, 2025 10:47 pm
by Rseding91
There currently is not. But it could be added fairly easily - the same thing that the existing cargo pod dispatch logic uses.

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

Posted: Thu Apr 03, 2025 2:14 am
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.

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

Posted: Thu Apr 03, 2025 3:17 pm
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.

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

Posted: Thu Apr 03, 2025 3:24 pm
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