Code: Select all
if (system.mainStation && system.mainStation.position.distanceTo(this.ship) < 25000 && Math.random() < 0.5)
There are a few more instances of this error if you search the full repository: https://github.com/OoliteProject/oolite ... distanceTo
1. All (7) of the distanceTo checks in oolite-tutorial.js. Here's a link to a fixed copy of the script: https://pastebin.com/3NUKx5wi
2. One check in oolite-constrictor.js (but it seems that nothing ever calls the _checkDistance function in there?)
3. Many in oolite-priorityai.js. Also take note of this.distance() calls which wrap distanceTo. Here's a link to a copy of oolite-priorityai.js (taken from the 1.89.0.200612 nightly, which is one behind but it hasn't changed) where I went through all 105 matches for "distance" and made corrections where needed (almost all of them): https://pastebin.com/QzPMdMRL
Since there were so many errors in the AI script, I will be very interested to see the "intended" behavior of the AI now...
The implementation of distanceTo is:
Code: Select all
// distanceTo(v : vectorExpression) : Number
static JSBool VectorDistanceTo(JSContext *context, uintN argc, jsval *vp)
{
OOJS_PROFILE_ENTER
HPVector thisv, thatv;
double result;
if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"distanceTo"))) return NO;
if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"distanceTo", argc, OOJS_ARGV, &thatv, NULL))) return NO;
result = HPdistance(thisv, thatv);
OOJS_RETURN_DOUBLE(result);
OOJS_PROFILE_EXIT
}
I've also updated the wiki page with a caution.