Scanner Alerting Enhancement

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

Moderators: winston, another_commander

Post Reply
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Scanner Alerting Enhancement

Post by jh145 »

Wanted: beta tester :mrgreen:

I've uploaded a simple expansion pack here: http://wiki.alioth.net/index.php/Scanne ... nhancement . Sorry, no corresponding wiki page yet as the missus is telling me to get off the computer! It needs Oolite version 1.81 or better.

When purchased (at, I think, TL12 and above), it makes new "yellow lollipops" on your scanner flash yellow/brown, and it console-logs the class of ship that's just appeared on the scanner. It's supposed to be mildly helpful in the event of a crowded playing field. It may just be irritating -- you tell me.

I'd be grateful for any comments you may have. One in particular from me: should this be primable?

Thanks.
Last edited by jh145 on Sat May 16, 2015 10:27 am, edited 1 time in total.
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scanner Alerting Enhancement

Post by Norby »

Nice work! Here are my usual tips to be the code even nicer. ;)

Code: Select all

  var pss = player.ship.script;
  pss.shipTargetAcquired = function(target) {
More simple if you define a this.shipTargetAcquired function in any worldScript which will be called for the player only. All ship script event handlers are usable for the player in worldScripts.

Code: Select all

var targets = system.filteredEntities(this,this._entityToWatch,player.ship,25600);
for (var i=0; i<targets.length; i++) this._updateScannerDisplayColour(targets[i],this._IN_RANGE);
A much faster way can prevent momentary stops in every seconds in slow machines:

Code: Select all

var targets = player.ship.checkScanner(true);
for (var i=0; i<targets.length; i++) 
    if(targets[i].scanClass == 'CLASS_NEUTRAL')
        this._updateScannerDisplayColour(targets[i],this._IN_RANGE);
I also suggest to change the timer delay to 1.37 or similar not round value to desync from other oxp's timers for smoother play.

TL5 is enough imho for a light software upgrade in your scanner.
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scanner Alerting Enhancement

Post by jh145 »

Thanks Norby, good advice. I'll get editing.

How do I define a worldScript which will be called for the player only? Or can I just define this.shipTargetAcquired in the single worldScript that I currently have?
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scanner Alerting Enhancement

Post by Norby »

jh145 wrote:
define this.shipTargetAcquired in the single worldScript that I currently have?
Yes. Even you can define the equipment activated and mode functions here also if you like to see your whole code in a single editor window.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scanner Alerting Enhancement

Post by cim »

jh145 wrote:
How do I define a worldScript which will be called for the player only?
Any ship script event handler can be used on a world script and applies to the player ship only in that case. This also keeps your player ship script events separated from everyone else's.

The only time I think you'd be better to define events on the player ship script were if they were specific to the ship hull type of the player, and in that case you'd be best predefining them by attaching the ship script in shipdata.plist
Norby wrote:
Even you can define the equipment activated and mode functions here also if you like to see your whole code in a single editor window.
You can do that, but I wouldn't recommend it, because the two functions will get called in different contexts to the rest of the script, so code like this will mysteriously fail

Code: Select all

this.$equipmentStatus = false;

this.shipWillEnterWitchspace = function() {
  this.$equipmentStatus = false;
}

this.$shipDockedWithStation = function() {
  if (this.$equipmentStatus) {
    // do something
  }
}

this.activated = function() {
  this.$equipmentStatus = true;
}
because this.$equipmentStatus in the equipment script and this.$equipmentStatus in the world script are separate variables existing in separate running copies of the script source.

Having the code in two windows is a good thing, as it reminds you that they're separate scripts.
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scanner Alerting Enhancement

Post by jh145 »

Norby wrote:
you can define the equipment activated and mode functions
Where's the equipment activation/mode-change API documented? (I'm sure it's somewhere in the javascript reference ...)
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scanner Alerting Enhancement

Post by Norby »

cim wrote:
the two functions will get called in different contexts to the rest of the script, so code like this will mysteriously fail
Failed at me first time also, then I learned to use worldScripts.myworldscriptname in eq scripts. ;)
jh145 wrote:
Where's the equipment activation/mode-change API documented?
I made this wiki page just now: Equipment scripts
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scanner Alerting Enhancement

Post by jh145 »

Thanks for the wiki page -- a big help!

Are those two functions called by the core game only when the keys are pressed? I mean, there's no "deactivate" function called when another piece of equipment gets primed, or anything like that, is there?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scanner Alerting Enhancement

Post by Wildeblood »

jh145 wrote:
Thanks for the wiki page -- a big help!

Are those two functions called by the core game only when the keys are pressed? I mean, there's no "deactivate" function called when another piece of equipment gets primed, or anything like that, is there?
No, there are just the two functions bound to key presses. That's all.
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scanner Alerting Enhancement

Post by jh145 »

cim wrote:
Any ship script event handler can be used on a world script and applies to the player ship only in that case. This also keeps your player ship script events separated from everyone else's.
Frustratingly, that's harder to get right than I expected.

Consider:

Code: Select all

this.shipTargetAcquired = this._SAE_rememberOne;   // doesn't work

this.shipTargetAcquired = function(target) { this._SAE_rememberOne(target); }   // works fine
What javascript context nonsense am I not understanding here?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scanner Alerting Enhancement

Post by cim »

jh145 wrote:

Code: Select all

this.shipTargetAcquired = this._SAE_rememberOne;   // doesn't work

this.shipTargetAcquired = function(target) { this._SAE_rememberOne(target); }   // works fine
The only reason I could think of that those would give different results is if this._SAE_rememberOne isn't defined until after this.shipTargetAcquired - in that situation, the first case would set it to undefined when the script was first loaded, and never touch its value again; the second wouldn't check the value of this._SAE_rememberOne until the handler was actually called, by which time it would have been defined.

If this._SAE_rememberOne is being defined above that line, then no idea - I'd need to look at the whole script.
User avatar
jh145
Dangerous
Dangerous
Posts: 94
Joined: Thu Dec 25, 2014 8:39 pm

Re: Scanner Alerting Enhancement

Post by jh145 »

That's it: the function is defined later in the script. Wow, javascript, what a pain.

Anywaaaayyyy... I've fixed the issue now and finally uploaded the OXZ to oolite.org. The scanner alerting enhancement is available to all :D
User avatar
Josef
Competent
Competent
Posts: 60
Joined: Sat May 29, 2021 6:20 pm
Location: Wien

Re: Scanner Alerting Enhancement

Post by Josef »

Hi everybody,
can anyone give me the information inwhat Techlevel it is possible to buy that equipment and how muchit will cost?
Thank you in advance!
Josef
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: Scanner Alerting Enhancement

Post by phkb »

Josef wrote: Sat Jun 05, 2021 5:26 am
can anyone give me the information inwhat Techlevel it is possible to buy that equipment and how muchit will cost?
750cr, TL8+ systems.
Post Reply