The Quest To Spew
19 years 1 month ago #18568
by mdvalley
The Quest To Spew was created by mdvalley
I am working on a simple mod to Epic that will allow the player to use the pod spewer instead of the magical pod appear/disappear. As of now, I have basic spewer functionality in the Epic buying system. iHabitat.Spew is a nice function. Here’s what happens when you call it, in order:
1) A pod appears and starts sliding out.
2) The pod becomes visible on the contact list.
3) The pod reaches the end of the conveyor belt and vanishes from the list for a few seconds.
4) The game crashes.
I figured that it needed an undock command to let go, so I whipped up a nice while loop to keep the pod trying to undock. But in my noobishness I didn’t realize it would be run atomically. *ctrl-alt-del* So I made a task. All it does it start the spew function and use that while loop to make it sleep for 0.1 seconds between attempts.
task spew_it(hship pod, hhabitat station)
{
iHabitat.Spew(station,pod);
while(!iShip.UndockSelf(pod))
{Task.Sleep(Task.Current(), 0.1);}
}
Works like a charm.
Limitations so far:
If you spew more than 4 at a time, only 4 come out. Will fix this next.
When the pod undocks, it just sits there and the next pod to come out that spot runs into it. More of an annoyance than anything else.
1) A pod appears and starts sliding out.
2) The pod becomes visible on the contact list.
3) The pod reaches the end of the conveyor belt and vanishes from the list for a few seconds.
4) The game crashes.
I figured that it needed an undock command to let go, so I whipped up a nice while loop to keep the pod trying to undock. But in my noobishness I didn’t realize it would be run atomically. *ctrl-alt-del* So I made a task. All it does it start the spew function and use that while loop to make it sleep for 0.1 seconds between attempts.
task spew_it(hship pod, hhabitat station)
{
iHabitat.Spew(station,pod);
while(!iShip.UndockSelf(pod))
{Task.Sleep(Task.Current(), 0.1);}
}
Works like a charm.
Limitations so far:
If you spew more than 4 at a time, only 4 come out. Will fix this next.
When the pod undocks, it just sits there and the next pod to come out that spot runs into it. More of an annoyance than anything else.
Please Log in or Create an account to join the conversation.
19 years 1 month ago #13773
by mdvalley
Just call (and detach!) this to spew a pod. Why the atomic bit? Simple. When buy is pressed, one of these tasks is started for every pod that is bought. That can be a lot of pods, all vying for a spewer slot. It might be possible for a task to see the open slot, but not call the Spew function before another task sees the open slot. Both would try to spew, and a pod would be lost. With the atomic, the slot is guaranteed reserved before any other task has a chance to check.
As a test, I went to a common mine and bought seventy pods at once! They came rolling out, 4 at a time. Halfway through, a poor ai freighter tried to use the spewer. It just sat there, docked, as the blue pods spewed. Finally, at the end, two yellow pods came out alongside my blue ones. Glad to see it got its ore. Eighty pods (the 10 I bought as a test before the 70), all in four bunches around the spewer.
Next step: selling.
Replied by mdvalley on topic The Quest To Spew
Code:
task spew_it(hship pod, hhabitat station)
{
bool goodtospew = false;
while(!goodtospew)
{
atomic
{
goodtospew = iHabitat.HasSpewerSlotFree(station);
if(goodtospew) {
iHabitat.Spew(station,pod);
}
}
Task.Sleep(Task.Current(), 0.1);
}
while(!iShip.UndockSelf(pod)) {
Task.Sleep(Task.Current(), 0.1);
}
}
Just call (and detach!) this to spew a pod. Why the atomic bit? Simple. When buy is pressed, one of these tasks is started for every pod that is bought. That can be a lot of pods, all vying for a spewer slot. It might be possible for a task to see the open slot, but not call the Spew function before another task sees the open slot. Both would try to spew, and a pod would be lost. With the atomic, the slot is guaranteed reserved before any other task has a chance to check.
As a test, I went to a common mine and bought seventy pods at once! They came rolling out, 4 at a time. Halfway through, a poor ai freighter tried to use the spewer. It just sat there, docked, as the blue pods spewed. Finally, at the end, two yellow pods came out alongside my blue ones. Glad to see it got its ore. Eighty pods (the 10 I bought as a test before the 70), all in four bunches around the spewer.
Next step: selling.
Please Log in or Create an account to join the conversation.
19 years 1 month ago #13775
by mdvalley
Replied by mdvalley on topic The Quest To Spew
Small bug. It seems that the pods get stuck on undock mode, making them a mite hard to carry. Whether the task is repeating itself, or the while loop doesn’t end when iShip.UndockSelf supposedly returns true when the pods detach from the spewer, I can’t tell yet. Must... write... fix...
Please Log in or Create an account to join the conversation.
- GrandpaTrout
- Offline
- King of Space
19 years 1 month ago #13776
by GrandpaTrout
Replied by GrandpaTrout on topic The Quest To Spew
These ideas sound good. I can provide some pointers into the code that will help you out.
tPodUtil.pog has many useful functions including tPodUtil.DockPorts which will return a set of empty ports. Also tPodUtil.AutodockPod will fly a pod over to dock to a specific dockport.
tEPlayerOrders has all the code for commanding wingmen to load and unload pods. Those functions should make good examples for the player ship. They could be used directly if the player ship were assigned to a group.
The second while loop could just test if the pod is still docked to anything and exit if it is not.
tPodUtil.pog has many useful functions including tPodUtil.DockPorts which will return a set of empty ports. Also tPodUtil.AutodockPod will fly a pod over to dock to a specific dockport.
tEPlayerOrders has all the code for commanding wingmen to load and unload pods. Those functions should make good examples for the player ship. They could be used directly if the player ship were assigned to a group.
The second while loop could just test if the pod is still docked to anything and exit if it is not.
Please Log in or Create an account to join the conversation.
19 years 1 month ago #13777
by mdvalley
Replied by mdvalley on topic The Quest To Spew
It seems that iShip.UndockSelf, contrary to the documentation, does not return true if docking was successful. Replace
iShip.UndockSelf(pod)
with
iShip.Undock(pod,station)
and it works. THAT function returns true upon successful undocking, letting the task terminate.
The pod-to-spewer code is becoming a real headache. According to iDockport.DockportsofType(station,DT_All,DS_Any), the stations have only the two universal ports. The spewer does not register.
Here’s the dock-the-pod code so far:
When I sell, my sell code undocks all sold pods, sets them to the station’s faction, and starts this task on every pod. I did this with 6 pods. Four went to the spewer and two went to the universal ports. On top of that, once a pod uses a spewer hole, the AI traffic can’t use it. If all four holes are filled this way, then the AI pods just sit there when the freighters drop them off.
I’m wondering what I should do to get the spewer I hijacked working again. Should I destroy the pod sim? Should I give the undock command, despite the pod no longer existing in the game world? Doesn’t help that I can’t query the spewer.
iShip.UndockSelf(pod)
with
iShip.Undock(pod,station)
and it works. THAT function returns true upon successful undocking, letting the task terminate.
The pod-to-spewer code is becoming a real headache. According to iDockport.DockportsofType(station,DT_All,DS_Any), the stations have only the two universal ports. The spewer does not register.
Here’s the dock-the-pod code so far:
Code:
task send_pod_home(hisim pod, hhabitat station)
{
bool goodtodock = false;
iSim.SetFaction(pod,iSim.Faction(station));
iShip.InstallAIPilot( iShip.Cast(pod), 0.25, 4.0, 0.1,"","","","");
iAI.GiveApproachOrderNoDropOff(pod, station);
while(!goodtodock)
{
atomic
{
goodtodock = iHabitat.HasSpewerSlotFree(station);
if(goodtodock) {
iAI.GiveReservedDockOrder(pod, station);
}
}
Task.Sleep(Task.Current(),1);
}
Task.Detach(start autodock_task(iShip.Cast(pod), station));
return;
}
When I sell, my sell code undocks all sold pods, sets them to the station’s faction, and starts this task on every pod. I did this with 6 pods. Four went to the spewer and two went to the universal ports. On top of that, once a pod uses a spewer hole, the AI traffic can’t use it. If all four holes are filled this way, then the AI pods just sit there when the freighters drop them off.
I’m wondering what I should do to get the spewer I hijacked working again. Should I destroy the pod sim? Should I give the undock command, despite the pod no longer existing in the game world? Doesn’t help that I can’t query the spewer.
Please Log in or Create an account to join the conversation.
- GrandpaTrout
- Offline
- King of Space
19 years 1 month ago #13778
by GrandpaTrout
Replied by GrandpaTrout on topic The Quest To Spew
Joco did some work with the pod spewer. Search for posts by him and see if he put posted the solution.
Please Log in or Create an account to join the conversation.