Oolite Bulletins

For information and discussion about Oolite.
It is currently Sat Nov 18, 2017 11:15 pm

All times are UTC




Post new topic  Reply to topic  [ 1403 posts ]  Go to page Previous 190 91 92 93 94 Next
Author Message
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 9:15 am 
Offline
Commodore
Commodore
User avatar

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

_________________
My OXP's


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 9:47 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

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

Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 9:49 am 
Offline
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
User avatar

Joined: Sat Jul 04, 2009 9:31 pm
Posts: 12915
Location: Corke's Drift
Just maths then? <chortles>

_________________
The only good fnord is a dead fnord!


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 10:52 am 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Wed Aug 15, 2012 4:19 am
Posts: 2469
Location: Finland
Something like this might work. Or not. Totally untested and possibly over complicated, but hopefully understandable.
Code:
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.

Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 11:43 am 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1801
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Thanks spara! That's a great help! I'll let you know how it goes.

_________________
My OXP's


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 12:07 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Wed Aug 15, 2012 4:19 am
Posts: 2469
Location: Finland
Not atan, but asin of course. I'm getting sloppy. Fixed now.


Top
   
 Post subject: Re: Scripters cove
PostPosted: Fri Sep 15, 2017 12:44 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

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


Top
   
 Post subject: Re: Scripters cove
PostPosted: Thu Sep 28, 2017 4:34 am 
Offline
Commodore
Commodore
User avatar

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

_________________
My OXP's


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Oct 29, 2017 5:22 pm 
Offline
---- E L I T E ----
---- E L I T E ----

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


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Nov 05, 2017 7:11 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Thu Jun 20, 2013 10:22 pm
Posts: 1105
This doesn't appear to work and I don't know why...

Code:
	//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" :-)


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Nov 05, 2017 7:17 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Thu Jun 20, 2013 10:22 pm
Posts: 1105
Quote:
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" :-)


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Nov 05, 2017 9:19 pm 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1801
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Can you change the code to this and report the log file results?
Code:
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);
}

_________________
My OXP's


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Nov 05, 2017 9:21 pm 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jul 21, 2013 12:26 pm
Posts: 545
Traces. Make sure the function is actually called. Print out the value of the variables you are testing.


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Nov 05, 2017 10:23 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Thu Jun 20, 2013 10:22 pm
Posts: 1105
Quote:
Can you change the code to this and report the log file results?
Relevant section of log:
Code:
[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...

Quote:
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" :-)


Top
   
 Post subject: Re: Scripters cove
PostPosted: Sun Nov 05, 2017 10:34 pm 
Offline
---- E L I T E ----
---- E L I T E ----
User avatar

Joined: Thu Jun 20, 2013 10:22 pm
Posts: 1105
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:
[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:
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" :-)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1403 posts ]  Go to page Previous 190 91 92 93 94 Next

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited