Page 34 of 118

Re: Scripters cove

Posted: Fri Dec 02, 2011 2:54 am
by RyanHoots
Thanks. :)

I've modified it a little, and it doesn't work (nothing in the latest.log):

borg.js

Code: Select all

this.name			= "borg"
this.author			= "Ryan Hoots";
this.copyright		= "This script is in the public domain.";
this.version		= "1.0";


this.shipTargetAcquired = this.shipBeingAttacked = function ()
{
this.ship.commsMessage(expandDescription("We are Borg. [RH-borg-banter]"));
};
descriptions.plist

Code: Select all

{

RH-borg-banter = (

"You will be assimilated. Resistance is futile.",
"Your tehcnological and biological distinctiveness will be added to our own.",
"You will be assimilated. Resistance is useless."

);

}

Re: Scripters cove

Posted: Fri Dec 02, 2011 10:07 am
by Kaks
Everything seems to work ok here.

All I can think of is that old chestnut: did you press shift while starting up Oolite?
When making changes inside an OXP you need to press shift at startup to force Oolite to refresh its internal cache with the new data...

Re: Scripters cove

Posted: Fri Dec 02, 2011 3:44 pm
by RyanHoots
I did... even though I've set my GNUstep defaults to always flush the cache. I may need to check my shipdata.plist. But if that file didn't work, how would the Borg appear in the first place? :?

Re: Scripters cove

Posted: Fri Dec 02, 2011 4:58 pm
by RyanHoots
:oops:
It was the shipdata.plist... take a look at this line:

Code: Select all

//		script = "borg.js";
Yep, I added // so I could test the shipdata without worrying about the script (which, at the time, I had not yet started to write). I forgot to remove it. :roll:

Edit: One more problem. Whenever I shoot the cube, it responds with the same set of remarks. I may have to tweak the script, it's annoying with a Mil laser... :wink:

Re: Scripters cove

Posted: Fri Dec 02, 2011 8:12 pm
by cim
I've got a fairly simple mission put together. Follow a rescue ship (plus two escorts) to another system, protect them from pirate attacks as they repair a freighter, then follow the rescue ship (Moray), the freighter (any large trader), and other surviving escorts (standard 'escort') back to the original system.

All working fairly well.

The only problem is that I'm losing *far* more ships to witchspace accidents than to hostile fire. Quite often the mission will go perfectly smoothly - all four ships will jump back to the home system (using the same wormhole), I follow them - and at that point I lose at least one ship about half the time. Since two of the four ships (rescue and freighter) are mission critical, that usually fails the mission too and there's nothing you can do to stop it. (happens occasionally on the jump in, too - one of the escorts goes missing with a shipDied() event...)

Any ideas on what's going wrong and how to fix it?

Re: Scripters cove

Posted: Fri Dec 02, 2011 8:50 pm
by Kaks
No idea so far, but a PM with the WIP would be appreciated. It might be a bug in Oolite, and if that's the case your oxp should help fix it.

Re: Scripters cove

Posted: Fri Dec 02, 2011 11:15 pm
by cim
Kaks wrote:
No idea so far, but a PM with the WIP would be appreciated. It might be a bug in Oolite, and if that's the case your oxp should help fix it.
Ah - tracked it down, I think. Setting the ships to print their cause of death found it: scrape damage from the witchspace beacon. (Entering the wormhole between the leader and its escorts seems to trigger this fairly reliably on one of the escorts)

Re: Scripters cove

Posted: Sat Dec 03, 2011 6:16 pm
by Kaks
Confirmed! It's an Oolite bug, and a fix is on its way, after some proper testing! :)

Re: Scripters cove

Posted: Sat Dec 03, 2011 10:01 pm
by Gimi
Could anyone give me an example of an info.plist script written in openstep, or do they have to be in XML?

Re: Scripters cove

Posted: Sat Dec 03, 2011 10:04 pm
by Eric Walch
Gimi wrote:
Could anyone give me an example of an info.plist script written in openstep, or do they have to be in XML?
The one inside Oolite itself should be openstep.

Re: Scripters cove

Posted: Sun Dec 04, 2011 1:37 pm
by cim
Kaks wrote:
Confirmed! It's an Oolite bug, and a fix is on its way, after some proper testing! :)
And the fix in r4675 deals with it. Thank you.

Re: Scripters cove

Posted: Sun Dec 04, 2011 6:52 pm
by Kaks
Sometimes an oxp would like to make an NPC jump to another system. However, the NPC might well be blocked by a nearby mass, since it's not always obvious how far away from the station you can safely jump, here's a way to find the minimum distance from any station in order to hopefully jump successfully at the first attempt. It's a combination of AI.plist and ship script, I'm afraid...

NB: I'm using squared distance because it's faster to calculate than distance.

Code: Select all

this.minimumJumpSquaredDistance = function(other) {
   // internal Oolite constants used: K = 0.1, SCANNER_MAX_RANGE = 25600
   let dist=other.mass * 0.1;
   return (dist > 655360000 ? 655360000 : dist); // 25600 * 25600
}
We can now select the nearest safe jump coordinates:

Code: Select all

this.selectNearestJumpPoint = function() {
   let other = system.filteredEntities(this,function(e){return e.isStation;}, this.ship)[0]; // select closest station!
   let A = this.ship.position.subtract(other.position);
   let min2 = this.minimumJumpSquaredDistance(other));

   if (min2 > A.squaredDistanceTo(other.position)){
      let dir = A.magnitude() > 0 ? A.direction() : Vector3D(1,0,0);
      this.ship.savedCoordinates=other.position.add(dir.multiply(Math.sqrt(min2)));
   } else
      reactToAIMessage("DESIRED_RANGE_ACHIEVED");
}
On the AI side you'll have to have something like this:

Code: Select all

	"JUMP_AWAY" =
	{
		ENTER = ("sendScriptMessage: selectNearestJumpPoint",setDestinationFromCoordinates, "setDesiredRangeTo:0.5");
		"COURSE_OK" = ("setSpeedFactorTo: 1.0", performFlyToRangeFromDestination);
		"DESIRED_RANGE_ACHIEVED" = (performHyperSpaceExit);
		UPDATE = ("sendScriptMessage: selectNearestJumpPoint",checkCourseToDestination, "pauseAI: 10.0");
	};
	"NEW_WAYPOINT" =
	{
		ENTER = ("setSpeedFactorTo: 1.0", setDesiredRangeForWaypoint, checkCourseToDestination, "pauseAI: 2.0");
		"WAYPOINT_SET" = ("setStateTo: NEW_WAYPOINT");
		"COURSE_OK" = ("setStateTo: JUMP_AWAY");
		"DESIRED_RANGE_ACHIEVED" = ("setStateTo:JUMP_AWAY");
	};
That should get your ship to go to the nearest available jump spot, then jump. If your ship is already in the clear, it should jump away immediately...

Of course, assuming that the nearest station is the mass of a coriolis station, all you have to do is set coordinates to a random spot about 5-6 km from the station, and your ship should be good to go!

Still, these chunks of code might give an idea or two to some enterprising OXP makers, so I thought I'd share! :D

PS & NB: I haven't tested the code above too rigorously, so there might well be a couple of bugs lurking in there... :P

Re: Scripters cove

Posted: Sun Dec 04, 2011 8:01 pm
by Capt. Murphy
It'll be incorprated to escort contracts for sure. Thanks Kaks.

Re: Scripters cove

Posted: Tue Dec 06, 2011 7:38 am
by Fatleaf
Can a ship be armed with multiple railguns?

EDIT: I have my answer. NPC's can't have them :( RUBBISH!

Re: Scripters cove

Posted: Thu Dec 08, 2011 10:30 pm
by Cmdr. Maegil
Feasibility study:

a) can a NPC be formed of several spatially fixed, but otherwise independent entities?
I'm thinking of large sized ships composed by different (possibly frangible) main entities, each a section of the hull, capable of independently and automatically ordering its turrets to target enemies inside their field of fire.
If the target is lost, out of their field of fire or destroyed, it'd automatically look for new targets.

b) can a PC be likewise composed, with NPC "parasites" embedded?