Scripters cove

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

Moderators: winston, another_commander

User avatar
phkb
Impressively Grand Sub-Admiral
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

Post by phkb »

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?
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

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.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Scripters cove

Post by Cody »

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!
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

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.
User avatar
phkb
Impressively Grand Sub-Admiral
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

Post by phkb »

Thanks spara! That's a great help! I'll let you know how it goes.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

Not atan, but asin of course. I'm getting sloppy. Fixed now.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

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.

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
}
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 Math.sqrt(dPlayerToStellar^2 - rStellarBody^2) instead of dPlayerToStellar. Then it works. I think. :lol:
User avatar
phkb
Impressively Grand Sub-Admiral
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

Post by phkb »

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).
Astrobe
---- E L I T E ----
---- E L I T E ----
Posts: 609
Joined: Sun Jul 21, 2013 12:26 pm

Re: Scripters cove

Post by Astrobe »

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?
User avatar
Redspear
---- E L I T E ----
---- 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

Post by Redspear »

This doesn't appear to work and I don't know why...

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;}
}
Hmm... I'll try it as an 'else' argument and report back but I don't think that should be necessary, should it? :?
User avatar
Redspear
---- E L I T E ----
---- 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

Post by Redspear »

Hmm... I'll try it as an 'else' argument and report back but I don't think that should be necessary, should it? :?
Nope, still not working.

Any ideas?
User avatar
phkb
Impressively Grand Sub-Admiral
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

Post by phkb »

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);
}
Astrobe
---- E L I T E ----
---- E L I T E ----
Posts: 609
Joined: Sun Jul 21, 2013 12:26 pm

Re: Scripters cove

Post by Astrobe »

Traces. Make sure the function is actually called. Print out the value of the variables you are testing.
User avatar
Redspear
---- E L I T E ----
---- 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

Post by Redspear »

phkb wrote:
Can you change the code to this and report the log file results?
Relevant section of log:

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
Hmm... I'm guessing that's not good...

Astrobe wrote:
Traces. Make sure the function is actually called. Print out the value of the variables you are testing.
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...

Thanks guys :D
User avatar
Redspear
---- E L I T E ----
---- 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

Post by Redspear »

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...

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
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...

Code: Select all

this.equipmentAdded =
Should recognise a change in grade but it's only happening on start up at present.

I'll have a rethink...
Post Reply