Re: Scripters cove
Posted: Fri Sep 15, 2017 9:15 am
I'm sorry if this has been posted elsewhere, but I couldn't find it. How can I determine if a point in space is currently behind a planet/moon/sun from where the player currently is?
For information and discussion about Oolite.
https://bb.oolite.space/
Code: Select all
var vStellarBody = bodyEntity.position;
var rStellarBody = bodyEntity.radius;
var vTarget = targetEntity.position;
var vPlayerShip = player.ship.position;
var vPlayerToStellar = vStellarBody.subtract(vPlayerShip);
var vPlayerToTarget = vTarget.subtract(vPlayerShip);
var dPlayerToStellar = vPlayerToStellar.magnitude();
var dPlayerToTarget = vPlayerToTarget.magnitude();
if (dPlayerToStellar < dPlayerToTarget) {
var aStellar = Math.asin(rStellarBody / dPlayerToStellar);
var aTarget = vPlayerToStellar.angleTo(vPlayerToTarget);
if (aStellar > aTarget)
\\ hidden
else
\\ visible
}
Code: Select all
var vStellarBody = bodyEntity.position;
var rStellarBody = bodyEntity.radius;
var vTarget = targetEntity.position;
var vPlayerShip = player.ship.position;
var vPlayerToTarget = vTarget.subtract(vPlayerShip);
var dPlayerToStellar = vPlayerShip.distanceTo(vStellarBody);
var dPlayerToTarget = vPlayerToTarget.magnitude();
if (dPlayerToStellar < dPlayerToTarget) {
var vTest = vPlayerShip.add(vPlayerToTarget.direction().multiply(dPlayerToStellar));
var dTest = vTest.distanceTo(vStellarBody);
if (rStellarBody > dTest)
\\ hidden
else
\\ visible
}
Math.sqrt(dPlayerToStellar^2 - rStellarBody^2)
instead of dPlayerToStellar
. Then it works. I think. Code: Select all
//speed adjustments
this.startUpComplete = this.equipmentAdded = this.playerBoughtNewShip = function()
{ if(player.ship.equipmentStatus("EQ_TRANSIT_GRADE") == "EQUIPMENT_OK" && player.ship.equipmentStatus("EQ_TRANSIT_DEFAULT") != "EQUIPMENT_OK" && player.ship.equipmentStatus("EQ_PERFORMANCE_DEFAULT") != "EQUIPMENT_OK")
{player.ship.maxSpeed -= 50;}
if(player.ship.equipmentStatus("EQ_PERFORMANCE_GRADE") == "EQUIPMENT_OK" && player.ship.equipmentStatus("EQ_PERFORMANCE_DEFAULT") != "EQUIPMENT_OK" && player.ship.equipmentStatus("EQ_TRANSIT_DEFAULT") != "EQUIPMENT_OK")
{player.ship.maxSpeed += 50;}
if(player.ship.equipmentStatus("EQ_TRANSIT_GRADE") == "EQUIPMENT_OK" && player.ship.equipmentStatus("EQ_PERFORMANCE_DEFAULT") == "EQUIPMENT_OK")
{player.ship.maxSpeed -= 100;}
if(player.ship.equipmentStatus("EQ_PERFORMANCE_GRADE") == "EQUIPMENT_OK" && player.ship.equipmentStatus("EQ_TRANSIT_DEFAULT") == "EQUIPMENT_OK")
{player.ship.maxSpeed += 100;}
}
Nope, still not working.Hmm... I'll try it as an 'else' argument and report back but I don't think that should be necessary, should it?
Code: Select all
this.startUpComplete = this.equipmentAdded = this.playerBoughtNewShip = function()
{
var p = player.ship;
var td = p.equipmentStatus("EQ_TRANSIT_DEFAULT");
var tg = p.equipmentStatus("EQ_TRANSIT_GRADE");
var pd = p.equipmentStatus("EQ_PERFORMANCE_DEFAULT");
var pg = p.equipmentStatus("EQ_PERFORMANCE_GRADE");
log(this.name, "transit def " + td + ", gde " + tg);
log(this.name, "perform def " + pd + ", gde " + pg);
log(this.name, "maxspeed pre = " + p.maxSpeed);
if(tg == "EQUIPMENT_OK" && td != "EQUIPMENT_OK" && pd != "EQUIPMENT_OK") {p.maxSpeed -= 50;}
if(pg == "EQUIPMENT_OK" && pd != "EQUIPMENT_OK" && td != "EQUIPMENT_OK") {p.maxSpeed += 50;}
if(tg == "EQUIPMENT_OK" && pd == "EQUIPMENT_OK") {p.maxSpeed -= 100;}
if(pg == "EQUIPMENT_OK" && td == "EQUIPMENT_OK") {p.maxSpeed += 100;}
log(this.name, "maxspeed post = " + p.maxSpeed);
}
Relevant section of log:phkb wrote:Can you change the code to this and report the log file results?
Code: Select all
[shipclassequip-grade]: transit def EQUIPMENT_UNAVAILABLE, gde EQUIPMENT_UNAVAILABLE
[shipclassequip-grade]: perform def EQUIPMENT_UNAVAILABLE, gde EQUIPMENT_UNAVAILABLE
[shipclassequip-grade]: maxspeed pre = 350
[shipclassequip-grade]: maxspeed post = 350
Yeah, that's good advice... there's so much basic scripting I have to learn. I'm just a beginner fumbling with bits and pieces from the wiki...Astrobe wrote:Traces. Make sure the function is actually called. Print out the value of the variables you are testing.
Code: Select all
[shipclassequip-grade]: transit def EQUIPMENT_UNAVAILABLE, gde EQUIPMENT_OK
[shipclassequip-grade]: perform def EQUIPMENT_UNAVAILABLE, gde EQUIPMENT_UNAVAILABLE
[shipclassequip-grade]: maxspeed pre = 350
[shipclassequip-grade]: maxspeed post = 300
Code: Select all
this.equipmentAdded =