Scripters cove
Moderators: winston, another_commander
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Scripters cove
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?
Re: Scripters cove
You could calculate the viewing angle of the planet, moon or sun. You could also calculate the angle between the vectors from the player to the stellar object and from the player to the point in space. Then you could do some comparison between the angles.
Last edited by spara on Fri Sep 15, 2017 11:25 am, edited 1 time in total.
- Cody
- Sharp Shooter Spam Assassin
- Posts: 16081
- Joined: Sat Jul 04, 2009 9:31 pm
- Location: The Lizard's Claw
- Contact:
Re: Scripters cove
Just maths then? <chortles>
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
And any survivors, their debts I will certainly pay. There's always a way!
Re: Scripters cove
Something like this might work. Or not. Totally untested and possibly over complicated, but hopefully understandable.
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
}
Last edited by spara on Fri Sep 15, 2017 12:04 pm, edited 1 time in total.
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Scripters cove
Thanks spara! That's a great help! I'll let you know how it goes.
Re: Scripters cove
Not atan, but asin of course. I'm getting sloppy. Fixed now.
Re: Scripters cove
Here's a bit more elegant (?) solution . The idea with this one is to move towards the target for the same amount as is the distance from the center of the planetary body and then test if we're inside the body or not.
Edit: The problem with this one, is that it's not very exact. It's simpler and it roughly works, but if you want to be sure, you'll use the first method .
Edit2: The correct amount of movement would be
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
}
Edit2: The correct amount of movement would be
Math.sqrt(dPlayerToStellar^2 - rStellarBody^2)
instead of dPlayerToStellar
. Then it works. I think. - phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Scripters cove
Thanks for these snippets, spara. Very helpful! Both versions work well with planetary bodies.
A further complication: is it possible to do the same thing with stations? I attempted a very rough hack, by just finding the largest side of the station's bounding box, halving that and using it as a radius value. I couldn't get consistent results though, particularly with very non-round stations (eg Torus stations).
A further complication: is it possible to do the same thing with stations? I attempted a very rough hack, by just finding the largest side of the station's bounding box, halving that and using it as a radius value. I couldn't get consistent results though, particularly with very non-round stations (eg Torus stations).
Re: Scripters cove
I'm using Fuel Tanks OXP, which implements the fuel tank as a mine. I noticed some time ago that enemies seem to adopt an "avoid it" behavior (despite fact that the "mine" is destroyed right after launch), but today a bunch of hostiles stopped attacking me a few seconds after I used a fuel tank.
Is it because the fuel level is part of the "threat assessment" by NPCs, or is it because the value of my ship decreased (I raised the price of a fuel tank to 400Cr) or is it because they detected the launch of a mine?
Is it because the fuel level is part of the "threat assessment" by NPCs, or is it because the value of my ship decreased (I raised the price of a fuel tank to 400Cr) or is it because they detected the launch of a mine?
- Redspear
- ---- E L I T E ----
- Posts: 2687
- Joined: Thu Jun 20, 2013 10:22 pm
- Location: On the moon Thought, orbiting the planet Ignorance.
Re: Scripters cove
This doesn't appear to work and I don't know why...
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
//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;}
}
- Redspear
- ---- E L I T E ----
- Posts: 2687
- Joined: Thu Jun 20, 2013 10:22 pm
- Location: On the moon Thought, orbiting the planet Ignorance.
Re: Scripters cove
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?
Any ideas?
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Scripters cove
Can you change the code to this and report the log file results?
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);
}
Re: Scripters cove
Traces. Make sure the function is actually called. Print out the value of the variables you are testing.
- Redspear
- ---- E L I T E ----
- Posts: 2687
- Joined: Thu Jun 20, 2013 10:22 pm
- Location: On the moon Thought, orbiting the planet Ignorance.
Re: Scripters cove
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.
Thanks guys
- Redspear
- ---- E L I T E ----
- Posts: 2687
- Joined: Thu Jun 20, 2013 10:22 pm
- Location: On the moon Thought, orbiting the planet Ignorance.
Re: Scripters cove
OK, so switching to transit grade in game didn't register.
So I tried the same switch, saved and then restarted with the save game...
Well the numbers appear to be correct...
I'll give it another try with numeric HUD.
(edit:)
And... it works from a save game but not without a save...
Should recognise a change in grade but it's only happening on start up at present.
I'll have a rethink...
So I tried the same switch, saved and then restarted with the save game...
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
I'll give it another try with numeric HUD.
(edit:)
And... it works from a save game but not without a save...
Code: Select all
this.equipmentAdded =
I'll have a rethink...