Scripters cove

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

Moderators: another_commander, winston

User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scripters cove

Post by jh145 »

As far as I can tell, there's no very efficient method to check the scanner for escape pods, as they are not "powered" in the sense of having such a large power unit that they mass-lock the player. Correct?

I was planning on updating the Scanner Alerting Enhancement to check for escape pods, but I am reluctant to call system.filteredEntities() or similar. Is there a good workaround? I'd like to run the scan every second or so.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

jh145 wrote:
I was planning on updating the Scanner Alerting Enhancement to check for escape pods, but I am reluctant to call system.filteredEntities() or similar. Is there a good workaround? I'd like to run the scan every second or so.
player.ship.checkScanner() will return up to 32 nearby objects within scanner range (not necessarily the nearest 32 objects, if the scanner is particularly busy). It's often quicker to call that, and then filter the result yourself, than to use system.filteredEntities in this sort of situation.
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scripters cove

Post by jh145 »

D'oh, thanks. I was using checkScanner(true) but didn't bother to ask myself what that "true" parameter was all about.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted »

I just don't understand vectors... :?

I want to write a function that will return the bearing (in degrees) to System B from System A.

My clumsy attempt...

Code: Select all


function checkForBottleneck(sys)
{
  var bearing, from = Vector3D([t.coordinates.x, t.coordinates.y, 0]);  //  start system coordinates
  var to = Vector3D([sys.coordinates.x, sys.coordinates.y, 0]);         //  target system coordinates
  var north = from.add(Vector3D([t.coordinates.x, t.coordinates.y - 1, 0]));
  //  Maybe I misunderstand: 
  //  The idea is to create a vector -- which I understand to be a line segment with a direction
  //  component -- pointing 0 degrees due north from the start system... but it doesn't seem
  //  to work...
      
  var angle = radiansToDegrees(north.angleTo(to)), cluster = sys.systemsInRange(7);
  function findBearing() {if(t.coordinates.x > sys.coordinates.x) {bearing = 360 - angle;}}
  function radiansToDegrees(rad) {return rad * (180 / Math.PI);}
  if(cluster.length < 5) {log(ns.RLE_IM.name, sys.name + " might be a bottleneck system...");}
  log(ns.RLE_IM.name, "Angle from " + t.name + " to " + sys.name + ":  " + bearing + " degrees.");
}
It all works fine except that bearing comes back undefined and I just can't figure out why...

What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Scripters cove

Post by Day »

You should define radiansToDegree() before calling it.

EDIT: findBearing() is defined, but not called. So as bearing is assigned only in findBearing(), bearing is always undefined.

EDIT2:
What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).

EDIT3:
A vector is not really an arrow, this is just an easy geometrical representation. Mathematically, a vector in a n-dimensional system is a group of n values relative to these n dimensions.
For example:
- in 2D, a coordinate can be represented by a vector (x, y) which is a couple of values.
- in 3D, a coordinate can be represented by a vector (x, y, z) which is a triplet of values.
- in 26D, a coordinate can be represented by a vector (a, b, c, ..., z) which is a 26-group of values.

Now, it's really easy too use vectors to represent things in 2D or 3D, so we use them. The math domain is called Vectorial spaces (well, at least in France).
But we use them for things with a lot more dimensions, like the preferences of a user:
- user intensity of preference of character 1 in a game,
- user intensity of preference of character 2 in a game,
- user intensity of preference of character 3 in a game,
- user intensity of preference of character 4 in a game,
- user intensity of preference of character 5 in a game,
- user intensity of preference of character 6 in a game.
Now we represent the intensity of preference for a user as a vector (0, 4, 6, 2, 5, 10).
And do this for all users.
And notice that the users are in groups, visible when representing geometrically all these vectors simultaneously (those liking character 1 not liking the character 3).

And do that for marketing or spam, to identify which people are likely to succumb to product X based on what we already know of them, and what already known similar people (those with near vectors) have succumbed to...
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted »

Day wrote:
EDIT2:
What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).
From the origin... I had that 100% all wrong!

So clearly, my idea is all wet...

Which leaves me with the problem: How do I determine the compass bearing/azimuth (in degrees) to B from A?
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Scripters cove

Post by Day »

Phasted wrote:
Day wrote:
EDIT2:
What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).
From the origin... I had that 100% all wrong!

So clearly, my idea is all wet...
Maybe not. I mean, a vector (1, 2) is a move of 1 along x, and 2 along y. It can be represented as an arrow from (0, 0) to (1, 2)
Which leaves me with the problem: How do I determine the compass bearing/azimuth (in degrees) to B from A?
Your formula was sound, I think. Just the order of your commands.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2286
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Vectors

Post by Wildeblood »

Day wrote:
A vector is not really an arrow, this is just an easy geometrical representation. Mathematically, a vector in a n-dimensional system is a group of n values relative to these n dimensions.
For example:
- in 2D, a coordinate can be represented by a vector (x, y) which is a couple of values.
- in 3D, a coordinate can be represented by a vector (x, y, z) which is a triplet of values.
- in 26D, a coordinate can be represented by a vector (a, b, c, ..., z) which is a 26-group of values.

Now, it's really easy too use vectors to represent things in 2D or 3D, so we use them. The math domain is called Vectorial spaces (well, at least in France).
But we use them for things with a lot more dimensions, like the preferences of a user:
- user intensity of preference of character 1 in a game,
- user intensity of preference of character 2 in a game,
- user intensity of preference of character 3 in a game,
- user intensity of preference of character 4 in a game,
- user intensity of preference of character 5 in a game,
- user intensity of preference of character 6 in a game.
Now we represent the intensity of preference for a user as a vector (0, 4, 6, 2, 5, 10).
And do this for all users.
And notice that the users are in groups, visible when representing geometrically all these vectors simultaneously (those liking character 1 not liking the character 3).

And do that for marketing or spam, to identify which people are likely to succumb to product X based on what we already know of them, and what already known similar people (those with near vectors) have succumbed to...
Tell more, please.
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Scripters cove

Post by Day »

Something like this could work (not tested):

function checkForBottleneck(sys)
{
function radiansToDegrees(rad) {return rad * 180 / Math.PI;}

var fromTo = Vector3D([sys.coordinates.x - t.coordinates.x, sys.coordinates.y - t.coordinates.y, 0]);
var north = Vector3D([0, -1, 0]));
var angle = radiansToDegrees(north.angleTo(fromTo));
log(ns.RLE_IM.name, "Angle from " + t.name + " to " + sys.name + ": " + angle + " degrees.");
}
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Vectors

Post by Day »

Wildeblood wrote:
Tell more, please.
Really? I would have thought to be rather boring.

On which part? The math part, or the usage part?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2286
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Vectors

Post by Wildeblood »

Day wrote:
Wildeblood wrote:
Tell more, please.
Really? I would have thought to be rather boring.

On which part? The math part, or the usage part?
Ether or both. It seems like an interesting subject.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Vectors

Post by Phasted »

Day wrote:
Wildeblood wrote:
Tell more, please.
Really? I would have thought to be rather boring.
Far from boring... in fact, quite useful. Thanks to your very helpful insight on visualizing vectors and your suggestion about converting the coordinates, I was able to solve my problem... or the first part of it anyway...

Code: Select all

this._prepareForNextSystem = function(type)
{
  if(type === "galactic") {return;}
  var d, t = System.infoForSystem(galaxyNumber, player.ship.targetSystem);
  function findEconBalance() {}
  function findDistance(sys)
  {
    function findBearing()
    {
      var c = "coordinates", V3D = Vector3D;
      var from = V3D([t[c].x, t[c].y, 0]), North = V3D([0, -1, 0]), to = V3D([sys[c].x, sys[c].y, 0]);
      var adj_c = convertCoordinates(), angle = radToDeg(North.angleTo(adj_c)), bearing = angleToBearing();
      function angleToBearing() {if(from.x > to.x) {return 360 - angle;} else {return angle;}}
      function convertCoordinates() {return V3D([(to.x - from.x), (to.y - from.y), 0]);}
      function radToDeg(rad) {return rad * (180 / Math.PI);}
      log(ns.RLE_IM.name, "Bearing from " + t.name + " to " + sys.name + ":  " + bearing + " degrees.");
    }
    d = t.distanceToSystem(sys);
    findBearing();
  }
  this._cluster = t.systemsInRange(7);
  //this._group = t.systemsInRange(14);
  //this._sector = t.systemsInRange(21);
  //this._quadrant = t.systemsInRange(28);
  this._cluster.forEach(findDistance);

Tested and bug-free. Thanks.
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Vectors

Post by Day »

Phasted wrote:
Day wrote:
Wildeblood wrote:
Tell more, please.
Really? I would have thought to be rather boring.
Far from boring... in fact, quite useful. Thanks to your very helpful insight on visualizing vectors and your suggestion about converting the coordinates, I was able to solve my problem... or the first part of it anyway...
:oops:
Phasted wrote:

Code: Select all

    function findBearing()
    {
      var c = "coordinates", V3D = Vector3D;
      var from = V3D([t[c].x, t[c].y, 0]), North = V3D([0, -1, 0]), to = V3D([sys[c].x, sys[c].y, 0]);
      var adj_c = convertCoordinates(), angle = radToDeg(North.angleTo(adj_c)), bearing = angleToBearing();
      function angleToBearing() {if(from.x > to.x) {return 360 - angle;} else {return angle;}}
      function convertCoordinates() {return V3D([(to.x - from.x), (to.y - from.y), 0]);}
      function radToDeg(rad) {return rad * (180 / Math.PI);}
      log(ns.RLE_IM.name, "Bearing from " + t.name + " to " + sys.name + ":  " + bearing + " degrees.");
    }
Tested and bug-free. Thanks.
You're welcome.
Is this working, even the exact first time it is called? I'm puzzled at the fact you use functions before declaring them (convertToCoordinates, radToDeg, angleToBearing).

Another thing. You might like to use the ternary operator ?: in angleToBearing().
It would be rewritten like this:

Code: Select all

function angleToBearing() { return from.x > to.x ? 360 - angle : angle;}
It's an easy way to do if then else.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Vectors

Post by Phasted »

Day wrote:
Is this working, even the exact first time it is called? I'm puzzled at the fact you use functions before declaring them (convertToCoordinates, radToDeg, angleToBearing).

In JavaScript, function definitions are "hoisted" to the top of the enclosing function or code. So, as long as all of the variables are declared and defined BEFORE the function is called, you can put the function definition just about anywhere,,,

This one is tricky. The variables have to be defined in a certain order (c before from and to; from and to before adj_c, etc.) But it works...
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Vectors

Post by Day »

Phasted wrote:
Day wrote:
Is this working, even the exact first time it is called? I'm puzzled at the fact you use functions before declaring them (convertToCoordinates, radToDeg, angleToBearing).
In JavaScript, function definitions are "hoisted" to the top of the enclosing function or code. So, as long as all of the variables are declared and defined BEFORE the function is called, you can put the function definition just about anywhere,,,

This one is tricky. The variables have to be defined in a certain order (c before from and to; from and to before adj_c, etc.) But it works...
Ah... But maybe it doesn't work when functions are declared this way?:

Code: Select all

var thingie = function() {alert("Hello World!";)}
Post Reply