iTrafficCreation and iScriptedOrders

More
19 years 3 weeks ago #12854 by Joco
Updated code post:
* new ldsi ini file to support pirate ldsi trap explosion (thanks MajorTom)
* code tweaked for this new sim
* tested need for delay between lds disrupt and sfx placement. Doesn't seem to be a need.

Cheers,
Joco.

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

More
19 years 3 weeks ago #12855 by Joco
Update: Remote pilot of Pods to dock with own freighter

I have this working. :D
Very simple process. I have a master monitor task that you can start and stop, and can set the delay between checks. When it is running it looks to see if the player is in remote pilot mode. If you are AND the ship you are in has docked it kicks you out of remote pilot mode. I tested it by piloting/docking a cargo pod to my own ship. Worked like a charm.

Will just clean the code a little then will post.

Cheers,
Joco.
Code:
// // By Joco. // // package iCargoPilot // // iCargoPilot.pog // // Package name /////////////////////////////////////////////////////////////// package iCargoPilot; // Imports //////////////////////////////////////////////////////////////////// // these are the packages were going to use uses Debug, Task, Global, Sim, iSim, iShip, iRemotePilot; // Exports //////////////////////////////////////////////////////////////////// // these are the functions that are going to be called from other packages // n.b. these start with uppercase letters, no underscores provides StartCargoPilot, StopCargoPilot; // Local functions //////////////////////////////////////////////////////////// prototype task cargopilot_scanner( float frequency ); /////////////////////////////////////////////////////////////////////////////// // Remote Piloting Cargo Code /////////////////////////////////////////////////////////////////////////////// task cargopilot_scanner( float frequency ) { hship remote; while( true ) { debug Debug.PrintString( "iCargoPilot: Monitor task v0.1\n" ); remote = none; // Look to see if player is in remote control if( iRemotePilot.RemoteActive() ) { remote = iRemotePilot.ReturnCurrentRemoteVessel(); // if the remote is docked kick player back to the mothership if( iSim.IsDocked( iSim.Cast(remote) ) ) { iRemotePilot.DeactivateConnection (); } } Task.Sleep( Task.Current(), frequency ); } } StartCargoPilot( float frequency ) { htask hmonitor; if( Global.Exists( "cargopilot_task_handle" ) ) { // already have a handle so should already have monitor task, 1 is enough debug Debug.PrintString( "StartLDSPirates: tried to start more than one monitor task.\n" ); return; } hmonitor = start cargopilot_scanner( frequency ); Task.Detach( hmonitor ); // store handle in a global Global.CreateHandle( "cargopilot_task_handle", GA_Read|GA_NoSave, hmonitor ); } StopCargoPilot() { htask hmonitor; if( Global.Exists( "cargopilot_task_handle" ) ) { hmonitor = Task.Cast( Global.Handle( "cargopilot_task_handle" ) ); Task.Halt( hmonitor ); Global.Destroy( "cargopilot_task_handle" ); } }

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

More
19 years 3 weeks ago #12856 by MajorTom
You might want to check to see if the pod is actually docked to the mothership:

Theoretically a player could dock the pod to something else besides
the mothership (if he accidently targeted another pod instead of the
mothership and pressed F8). Your code would deactivate the remote
connection, but the player would never be able to re-connect to one
of the pods and re-route it because the task would deactivate the
connection momentarily. (he would lose two pods because they would
both be blocked).
You could use iSim.IsDockedTo( hsim sim1, hsim sim2 ); and either
call iShip.UndockSelf if you wanted (so the player could reconnect)
or simply not deactivate the connection until the player finally
figures out whats going on.

In your StopCargoPilot function: I think I read somewheres you are
supposed to destroy globals to prevent memory leaks. More important
in this case, if you don't destroy the global, the next time you run
the StartCargoPilot function, pog will silently fail to create a
global (because the global already exists) and you could end up with
a whole bunch of tasks running that are never stopped (because each
task you start still has it's own handle even though you can't "see" it).

Iwar2 Multiplayer Fan Site

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

More
19 years 3 weeks ago #12857 by Joco

Originally posted by MajorTom

You might want to check to see if the pod is actually docked to the mothership:

I believe it is. At least when I get back into the normal player ship the cargo pod is docked and pressing undock detaches it.

Theoretically a player could dock the pod to something else besides
the mothership (if he accidently targeted another pod instead of the
mothership and pressed F8). Your code would deactivate the remote
connection, but the player would never be able to re-connect to one
of the pods and re-route it because the task would deactivate the
connection momentarily. (he would lose two pods because they would
both be blocked).

You could use iSim.IsDockedTo( hsim sim1, hsim sim2 ); and either
call iShip.UndockSelf if you wanted (so the player could reconnect)
or simply not deactivate the connection until the player finally
figures out whats going on.

True. I had not written this code as a complete system. Just as a method to check if a player has docked then to kick them back to the original craft. Now if the auto kicking was not something desired then doing a key binding approach might work. Would that be preferable to auto returning? Mind you I am not saying that I can get that approach to work. Also the current code allows you to set the pause between tests. So with a 10-15 sec pause you could reconnect and hit undock before getting kicked back again.

In your StopCargoPilot function: I think I read somewheres you are
supposed to destroy globals to prevent memory leaks. More important
in this case, if you don't destroy the global, the next time you run
the StartCargoPilot function, pog will silently fail to create a
global (because the global already exists) and you could end up with
a whole bunch of tasks running that are never stopped (because each
task you start still has it's own handle even though you can't "see" it).

I've just assumed you are on the money and have cleaned things in both the caropilot and pirate code to test/clean the globals I am setting. At this point this code is written for single player in mind. It probably wont work for multiplay.

Thanks for the feedback.

Cheers,
Joco.

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

More
19 years 3 weeks ago #12858 by MajorTom
Lol, I hadn't doubted that it docked :D
I meant the first sentence about checking if it is docked to the
mothership in combination with the next paragraph because the player
may have docked to another pod (or a station or whatever)

Originally posted by Joco

Now if the auto kicking was not something desired then doing a
key binding approach might work. Would that be preferable to auto
returning? Mind you I am not saying that I can get that approach to work.

I personally think auto kicking on the dock event would be
preferable immediatly after hearing that satisfying "clunk" when it
docks. (but not 10-15 secs later [xx(]

You could do a keybind to deactivate the remote connection easily
enough. Just call iRemotePilot.DeactivateConnection (); in the
function that the key activates.

Also the current code allows you to set the pause between tests. So with a 10-15 sec pause you could reconnect and hit undock before getting kicked back again.

I dunno, if you can target a pod if it is docked to another pod,
so you may not be able to re-connect? (Subtargeting does not work
on pods in MP, I've never tried it in SP)

The downside of the pause means you are possibly sitting there from
10 - 14.9 secs looking at the dockport of your freighter before your
remote connection to the pod is released? If thats the case you
could try something like this:

while( ! iSim.IsDocked( iSim.Cast(remote) ) )
{
Task.Sleep( Task.Current(), 0.5 );
}
iRemotePilot.DeactivateConnection ();

To make it even more explicit you could use:
while (!iSim.IsDockedTo (iSim.Cast(remote),iSim.Cast(iShipfindPlayerShip()) )


At this point this code is written for single player in mind. It probably wont work for multiplay.

As far as destroying globals goes it's the same in MP or SP.
Actually, your code wouldn't work in MP for several reasons(*),
but thats not a problem since we have all the code for rem
connecting and docking pods already working in the Epic Online
multiplay mod. Thats why I can offer advice on this subject here.

* In A MP game there would be be several players simultanously Rem
connecting and docking. So you have to be careful not to deactivate
the connection for all the players whenever just one of them has
docked his pod. (or rem connect everyone to the same pod ;) )
Also in MP you should be able to dock a pod to another players ship
if you want to do teamwork. But, you can't allow people to dock pods
malicously to stations where they would be unretrievable for others.

Iwar2 Multiplayer Fan Site

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

More
19 years 3 weeks ago #12859 by Joco
Yeah - many ways to skin the cat. I think the simple approach is ok. It at least shows the basics so if anyone wants to do something more exotic than can extend on things.

Right - off to the next puzzle. :)

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