iTrafficCreation and iScriptedOrders

More
19 years 2 weeks ago #12742 by Joco
Ok - update time re getting Pod Spewer to "eat" pods just like in the game per PS traffic.

I HAVE DONE IT! :D

Err now I just need to be able to repeat it. ROFL. Will post code as soon as I have things solid enough to be a usable example.

Cheers,
Joco.

--- 14-Apr ---
I'm getting some odd behaviour from the iDockport function that returns a set of handles to the dock ports. The count tells me 4 but the set returned is of varying size!!!

Looks like I need to build my own package to do this stuff specifically for Spewer dock ports. But I do know exactly how to identify them from the subsims attached to a station, so thats a plus. :)

Please Log in or Create an account to join the conversation.

More
19 years 2 weeks ago #12751 by Joco
Here it is. My package for spewing pods from a pod-spewer and docking them to a station that has a pod-spwer. Docking means they get properly docked/consumed by the spewer. :D
Code:
// // By Joco. 14-Apr-2005. // // package iSpewPods // // iSpewPods.pog // // Package name /////////////////////////////////////////////////////////////// package iSpewPods; // Imports //////////////////////////////////////////////////////////////////// // these are the packages were going to use uses Debug, Task, Sim, iCargo, iHabitat, iSim, iFaction, iInventory, iHabitat, iDockport, iPilotSetup, iAI; // Exports //////////////////////////////////////////////////////////////////// // these are the functions that are going to be called from other packages // n.b. these start with uppercase letters, no underscores provides SpewPod, DockPod; // Local functions //////////////////////////////////////////////////////////// prototype task detach_spewed_pod( hsim pod_sim ); prototype list get_subsims_like(hsim source, int type); /////////////////////////////////////////////////////////////////////////////// // Detach spewed pods and send them away from the station for pick up /////////////////////////////////////////////////////////////////////////////// list get_subsims_like(hsim source, int type) { // we need to find all the subsims in the source sim that have a type_flags // equal to 'type' hsubsim ssim; list results; int i; int subsim_count = Sim.SubsimCount( source ); for(i = 0; i < subsim_count; ++i) { ssim = Sim.NthSubsim( source, i ); if( Object.IntProperty( ssim, "type_flags" ) == type ) { List.AddTail( results, ssim ); } } return results; } task detach_spewed_pod( hsim pod_sim ) { hsim dock_parent; // as the pod spewer is animated we have to wait for the anim to finish before trying // to do anything more - like undocking it. Task.Sleep( Task.Current(), 15 ); // is there a better way? dock_parent = Sim.Parent( pod_sim ); debug { Debug.PrintString( "detach_spewed_pod: pod_sims dock parent: " ); Debug.PrintHandle( dock_parent ); Debug.PrintString( "\n" ); } // ensure the docking lock is off iSim.SetDockingLock( iSim.Cast(dock_parent), iSim.Cast(pod_sim), false ); // undock from station iSim.Undock( iSim.Cast(dock_parent), iSim.Cast(pod_sim) ); // Get the sim away from the station Sim.SetVelocityLocalToSim( pod_sim, 0, 0, -200 ); } hsim SpewPod(hhabitat station, int cargo_type, string owner_faction, string cargo_faction) { hsim pod_sim; hcargo cargo_defn; string sim_url = "ini:/sims/ships/utility/cargo_pod"; //sim_url = "ini:/sims/ships/utility/freightpod"; debug Debug.PrintString( "iSpewPods.SpewPod: Version 0.1\n" ); // make sure station has a spewer if( !iHabitat.HasSpewer( station ) ) { return none; } // is there a free spewer slot? if( !iHabitat.HasSpewerSlotFree( station ) ) { return none; } cargo_defn = iCargo.Find(cargo_type); pod_sim = Sim.Create(sim_url, iCargo.Name( cargo_defn )); if( pod_sim == none) { // if failed to create the sim don't go any further return none; } if (iSim.Type(iSim.Cast(pod_sim)) == T_CargoPod) { // we have a cargo pod, so set it up correctly //iSim.SetFaction(iSim.Cast(pod_sim), iFaction.Find(owner_faction)); Object.AddIntProperty(pod_sim,"cargo",cargo_type); //Object.AddIntProperty(pod,"cargo_faction",iFaction.Allegiance(iFaction.Find(cargo_faction))); } // try to spew from station if( iHabitat.Spew( station, pod_sim) ) { // install a basic AI in the pod so we can direct it to do things later, // like dock with things. iPilotSetup.GenericCargoPod( iShip.Cast(pod_sim) ); Task.Detach( start detach_spewed_pod( pod_sim ) ); return pod_sim; } return none; } bool DockPod(hsim pod_sim, hhabitat station) { int i; hsubsim spewer_port; hsubsim pod_sim_port; set station_modules; hobject hobj; list spewer_port_list; debug Debug.PrintString( "iSpewPods.DockPod: Version 0.1\n" ); // Some sanity checks first // make sure station has a spewer if( !iHabitat.HasSpewer( station ) ) { return false; } if( !iHabitat.HasSpewerSlotFree( station ) ) { return false; } // get handle to a spewer docking port spewer_port_list = get_subsims_like( Sim.Cast(station), 64); // find the first available port to use while( !List.IsEmpty( spewer_port_list ) ) { spewer_port = Subsim.Cast( List.Head( spewer_port_list ) ); List.RemoveHead( spewer_port_list ); // test if this port is available and enabled if( iDockport.Status( iDockport.Cast(spewer_port) ) == DS_Free) { if( !iDockport.IsDisabled( iDockport.Cast(spewer_port) ) ) break; } spewer_port = none; } debug { Debug.PrintString( "spewer_port = " ); Debug.PrintHandle( spewer_port ); Debug.PrintString( "\n" ); } // get the dockport on the cargo pod pod_sim_port = Sim.FindSubsimByName( pod_sim, "system_pod_port" ); // make sure we have both docking ports if((spewer_port == none) || (pod_sim_port == none)) { debug Debug.PrintString( "iSpewPods.DockPod: failed to find both spewer port and pod port\n"); return false; } // give the pods installed AI the docking order. iAI.GiveDockOrderWithDockport( iDockport.Cast(pod_sim_port), iDockport.Cast(spewer_port) ); return true; }

Please Log in or Create an account to join the conversation.

More
19 years 2 weeks ago #12754 by GrandpaTrout
Fantastic! Does the spewer consume the pods itself then? (I guess I don't see the Sim.Destroy anywhere in your code).

Please Log in or Create an account to join the conversation.

More
19 years 2 weeks ago #12756 by Joco
From what I can see the spewer does all the destroy stuff. The pods definately disappear without me doing anything. Try it out and see.

One of the few other remaining pieces is capsule jumping multiple ships. Perhaps that is handeled automatically by the traffic script. But testing AI capsule jumping would be let us know if there is still more work to be
done.

What else is left that needs research? Oh, yes. We can turn off the standard traffic by removing the system startup scripts. However, that removes all the special waypoints placed around each station. And perhaps the Lpoint handelers as well. (Look in scripts.ini in the EoC resource directory). So the question we need to answer is how to turn off the PS traffic scripts, without stopping our own traffic scripts from running correctly. How to turn off traffic, while keeping the station startup. And it could be as simple as using iRegion calls. But I have not researched it.


GrandpaTrout, any priority on these areas to be researched?
I was going to look at the capsule jumping stuff next. But re-reading this text I think I need a little more direction on what you mean. Are you refering to AI ships capsule jumping as a group to a destination or capsule jumping wingmen with the player?

Cheers,
Joco.

Please Log in or Create an account to join the conversation.

More
19 years 2 weeks ago #12763 by GrandpaTrout
Capsule jumping AI ships. What I am wondering is if the scripts are automatically handling the capsule jumping of formations of ships. I have every expectation that they do. However, it really needs to be tested. If it works, then it does not need research. Just making sure no stone is left unturned.

Please Log in or Create an account to join the conversation.

More
19 years 2 weeks ago #12765 by Joco
From the original checking I did on the scripted orders I think the AI capsule jumps are all handled. But will have a look to double check this. When I gave my ship group a system patrol order they definately went through an L-point together.

Please Log in or Create an account to join the conversation.