Scripters cove

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

Moderators: winston, another_commander

User avatar
phkb
Commodore
Commodore
Posts: 2403
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » 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?

User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2552
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara » Fri Sep 15, 2017 9:47 am

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: 13637
Joined: Sat Jul 04, 2009 9:31 pm
Location: Corke's Drift
Contact:

Re: Scripters cove

Post by Cody » Fri Sep 15, 2017 9:49 am

Just maths then? <chortles>

User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2552
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara » Fri Sep 15, 2017 10:52 am

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
Commodore
Commodore
Posts: 2403
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Fri Sep 15, 2017 11:43 am

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: 2552
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara » Fri Sep 15, 2017 12:07 pm

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: 2552
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara » Fri Sep 15, 2017 12:44 pm

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
Commodore
Commodore
Posts: 2403
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Thu Sep 28, 2017 4:34 am

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: 596
Joined: Sun Jul 21, 2013 12:26 pm

Re: Scripters cove

Post by Astrobe » Sun Oct 29, 2017 5:22 pm

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: 1341
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear » Sun Nov 05, 2017 7:11 pm

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? :?
"With our thoughts, we make the world" :-) - - - Game too slow for you? Masslock Compensators - - - Trouble getting out of trouble? Indestructible Injectors

User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 1341
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear » Sun Nov 05, 2017 7:17 pm

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?
"With our thoughts, we make the world" :-) - - - Game too slow for you? Masslock Compensators - - - Trouble getting out of trouble? Indestructible Injectors

User avatar
phkb
Commodore
Commodore
Posts: 2403
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Sun Nov 05, 2017 9:19 pm

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: 596
Joined: Sun Jul 21, 2013 12:26 pm

Re: Scripters cove

Post by Astrobe » Sun Nov 05, 2017 9:21 pm

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: 1341
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear » Sun Nov 05, 2017 10:23 pm

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
"With our thoughts, we make the world" :-) - - - Game too slow for you? Masslock Compensators - - - Trouble getting out of trouble? Indestructible Injectors

User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 1341
Joined: Thu Jun 20, 2013 10:22 pm

Re: Scripters cove

Post by Redspear » Sun Nov 05, 2017 10:34 pm

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...
"With our thoughts, we make the world" :-) - - - Game too slow for you? Masslock Compensators - - - Trouble getting out of trouble? Indestructible Injectors

Post Reply