Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
kanthoney
Commodore
Commodore
Posts: 281
Joined: Thu Nov 07, 2013 10:21 pm

Re: Scripters cove

Post by kanthoney » Mon Feb 22, 2016 1:35 pm

Pick a random direction, using randomDirection(). Then work out the direction of the sun / planet by subtracting the position of the entity from the position of the planet, and normalise that using the direction() function. You've now got two vectors which should both have a length of one.

Now take the dot product of the two vectors (using the dot() function, obviously), which should be a number between -1 and 1. A value of 1 means the vectors are in the same direction and -1 means they're pointing in exactly in the opposite directions. So if the dot product is more than, say, 0.95 you're heading roughly towards the planet and need to try a different direction.

Ref: http://wiki.alioth.net/index.php/Oolite ... :_Vector3D

User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2543
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby » Mon Feb 22, 2016 1:50 pm

phkb wrote:I don't want the random direction to be into the sun or planet.
Here is my untested attempt to exclude the sun from a random direction.
The same should be checked for each items in system.planets array also.

Code: Select all

var pp = player.ship.position;
//heading from the player to the center of the sun
var h = sun.position.subtract(pp);
for(var i=0; i<100; i++) { //max. 100 retry
    var q = Quaternion.random();
    var qf = q.vectorForward();
    //angle from the center of the sun to the border of the disk
    if( Math.tan(qf.angleTo(h)) > sun.radius / pp.distanceTo(sun.position) ) {
        player.ship.orientation = q; //points out of the sun
        break;
    }
}

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Tue Feb 23, 2016 7:41 am

kanthoney wrote:using the dot() function, obviously
I love the clever use of "obviously"... :wink:

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Tue Mar 29, 2016 4:05 am

Is it possible to leverage the built-in assassin system? For instance, could accepting or completing a mission increase the chance of assassins at the witchpoint? Or does it need an entirely separate approach (eg Random Hits)?

User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4018
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim » Tue Mar 29, 2016 5:59 am

phkb wrote:Is it possible to leverage the built-in assassin system? For instance, could accepting or completing a mission increase the chance of assassins at the witchpoint? Or does it need an entirely separate approach (eg Random Hits)?
Give your mission script a custom populator, and have it add extra assassins sometimes. You can either add a separate myoxp-bonus-assassins entry, or override the existing "oolite-assassins" entry to one with a higher group count and/or a tougher callback function.

To get them to attack you have a few options:
- give the player a high-risk parcel or passenger for some parts of the mission
- add trader-courier+ to the player's role set a few times
- (probably better) add myoxp-mission-protagonist+ to the player's role set a few times, and use Role-categories.plist to add it to the oolite-courier role group.
(The plus on the end prevents distance-related decay of roles, which you probably want in this case)

You might also want to add an extra assassin personality to the comms array, conditional on the player having attracted these specific assassins, so that sometimes they can say "there's the pilot who offended the vice-Duke!" or whatever the mission is about.

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Tue Apr 05, 2016 3:17 am

Thanks for the previous response, cim.

Another question: Is it possible to remove a particular system ID as a witchspace destination for NPC's? The idea being to quarantine a system for whatever reason. I realise I can just add a timer or a frame callback and monitor all ships with hyperspace engines and check their destinationSystem property, but I was hoping for something a little more direct.

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Thu Aug 04, 2016 3:57 am

A question for any Vector experts out there...

How can you work out if a ship is on a particular lane? I can see that "entity" has a "position" vector, and a vector has a "toCoordinateSystem" method. So if I do something like this:

Code: Select all

var vect = myNPCShip.position.toCoordinateSystem("wpu");
log(this.name, "vect = " + vect.x + ", " + vect.y + ", " + vect.z);
and then running something like it over a few ships returns these results:
13:51:21.006 [myOXP]: ship = [Ship "Night Adder" position: (-16739.1, -33957.8, 309128) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:51:21.006 [myOXP]: vect = 0.05546399538012031, 0.07352871999922404, 0.7520263813183803
13:51:21.006 [myOXP]: ship = [Ship "Python" position: (5878.13, -45060.9, 34723.5) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:51:21.006 [myOXP]: vect = 0.006470267535101524, 0.11036057068886841, 0.08447313493024122
13:51:21.006 [myOXP]: ship = [Ship "Bug" position: (2346.88, -29148.4, -15840.6) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:51:21.006 [myOXP]: vect = 0.007663652896847149, 0.07072589638477839, -0.038536007153059604
13:51:21.006 [myOXP]: ship = [Ship "Cobra Mark III" position: (-371164, -98700.6, -106782) scanClass: CLASS_NEUTRAL status: STATUS_IN_FLIGHT]
13:51:21.006 [myOXP]: vect = 0.9319277605848015, 0.06686805118676767, -0.2597719691820526
Would any of these numbers indicate a ship on the witchpoint-planet lane?

User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2543
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby » Thu Aug 04, 2016 10:38 am

First you should define what you mean "on lane", for example within 2*scanner range (51200m) from the wp line.

Then use wpm where coords are in meters to be comparable with the selected width of lane. The 3. coordinate mean nothing for you (show the position along the lane) but the first two are two sides of a right triangle where the length of the third side (using Pythagorean theorem) is what you want to compare with the width of lane.

Another way: ............ Ship
PlanetImageWitchpoint

The "b" side is the wp lane (witchpoint is at origo so b is equal with system.mainPlanet.position), "a" is myNPCShip.position, gamma is a.angleTo(b) in radians what Math.sin() need. So you can do something like this (untested):

Code: Select all

var a = myNPCShip.position, p = system.mainPlanet;
if( a && p && a.magnitude() * Math.sin( a.angleTo(p.position) ) < 51200) {
    //myNPCShip is in wp lane
}
The check of "a" could prevent problems with destroyed NPCs, the check of planet is useful in interstellar space.

Usually worth count ships in Witchpoint-Main Station line also.

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Tue Aug 09, 2016 2:53 am

Thanks for the previous answer, Norby!

Another question: What would be the best way to reliably determine what alloys and wreckage were created with the destruction of a particular ship?

User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2543
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby » Tue Aug 09, 2016 1:39 pm

phkb wrote:what alloys and wreckage were created with the destruction of a particular ship?
Just an idea:
- in shipDied event save the time and position (could be tricky if ship is not valid anymore),
- in shipSpawned check if it is an alloy/wreckage, then compare the time and position with saved destructions and if it is "enough near" then assume it is crearted by that ship,
- remove old entries from the saved list after a sure timeout in a timer.

NEANDERTHAL
Above Average
Above Average
Posts: 20
Joined: Fri Jul 22, 2016 3:55 am

Re: Scripters cove

Post by NEANDERTHAL » Tue Aug 09, 2016 3:31 pm

How could one store a set amount of data for each system, and read/write as well as store that data for later use? For example, I want to save the amount of entities in each system for later reference. Would I have to store the data in the system description space? Could I keep this data in a script-generated file?

User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2543
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby » Tue Aug 09, 2016 4:03 pm

The script in SMax's MFDRestoreAfterLoad contain a nice example how to save an array of data into the savegame using JSON to convert it to string and load back in the startUp event.

Your array should be a property of your script so define it as this._YourArray = []; (like this.name at the top of the script) and use as this._YourArray[0] = 123; within your functions.

NEANDERTHAL
Above Average
Above Average
Posts: 20
Joined: Fri Jul 22, 2016 3:55 am

Re: Scripters cove

Post by NEANDERTHAL » Sat Aug 13, 2016 2:39 am

What does cargo_type = "CARGO_THARGOID" in shipdata.plist do exactly?

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Sat Aug 13, 2016 3:57 am

I'm not 100% sure, but I think that makes the item scoopable as Alien Items.

User avatar
phkb
Commodore
Commodore
Posts: 2353
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Fri Dec 02, 2016 2:16 am

Is it possible to check whether a particular ship can fit through the docking port of a station? Without, you know, actually trying.

Post Reply