OXP idea: Escape capsule locator

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: OXP idea: Escape capsule locator

Post by Capt. Murphy »

There quite a few things to think of - another issue is making sure the replaced escape pods have the same pilot type as the original so you still get your rewards and bounties - not trivial as again the pilot type is invisible to JS so I have to script to find the role of the newly derelict ship that spawned the pod, then use that to set a particular custom escape pod role which in turn spawns a replacement beacon escape pod with the appropriate pilot type.......

Then reversing that if the equipment is damaged..... :roll:

I think it can be done the way CSOTB has suggested and I'm trying that route first, if it fails or I get into a blind corner I'll go back to the tiny dummy beacon idea.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: OXP idea: Escape capsule locator

Post by Capt. Murphy »

OK -

can any scripters tell me what's wrong with this?

Code: Select all

function ecl_findescapecapsules(entity)
	{
		return (entity.roles[0] == "ecl_escape_capsule");
	}
	var targets = system.filteredEntities(this, ecl_findescapecapsules);
it's telling me that entity.roles is undefined.

The alternative

Code: Select all

function ecl_findescapecapsules(entity)
	{
		return (entity.hasRole("ecl_escape_capsule"));
	}
	var targets = system.filteredEntities(this, ecl_findescapecapsules);
is telling me that entity.hasRole is not a function.

I've successfully used the same basic code with entity.primaryRole == "whatever" in other scripts and can't work out why this is different?
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: OXP idea: Escape capsule locator

Post by Eric Walch »

Capt. Murphy wrote:
OK -

can any scripters tell me what's wrong with this?
Probably not all found entities are ships. I think planets are also on the entity list. It should be:

Code: Select all

return (entity.isShip && entity.roles[0] == "ecl_escape_capsule");
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: OXP idea: Escape capsule locator

Post by Kaks »

Apart from Eric's perfectly valid solution, you might want to consider testing for specific properties immediately before trying to use them (a technique widely used by js programmers to detect & use specific browser features):

Code: Select all

      return ( entity.hasRole && entity.hasRole("ecl_escape_capsule") );
if the entity being filtered hasn't got the hasRole property, the function should simply return false, without throwing an error...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: OXP idea: Escape capsule locator

Post by Capt. Murphy »

Gotcha - thank-you gents.

Edit to add - it seems odd that entity.primaryRole == "whatever" doesn't throw an error in the same construction. (I've just tested it).

I've also just reminded myself of the system.shipsWithPrimaryRole and system.shipsWithRole methods which are probably more suited to my purposes.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: OXP idea: Escape capsule locator

Post by Kaks »

if .primaryRole doesn't exist (i.e. the entity is not a ship), then your comparison is understood as:

undefined == "whatever"

which is also a valid js comparison! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: OXP idea: Escape capsule locator

Post by Capt. Murphy »

Mmm - I still don't get why that is different from the entity.roles[0] which does throw an error if entity.roles[0] is undefined. Unless the JS engine is more likely to throw an error for arrays.

Anyway the equipment script seems to be working well now. All "escape-capsule" role pods are replaced with a pod with a custom-role including an appropriate pilot type (from core game characters.plist) for the derelict's role and bounty that spawned them, a beacon and custom scanner colours. On equipment damaged they are all swapped for a no_beacon, standard scanner colour version of the custom role. A timer checks for on the fly repair of the equipment and if repaired converts the no-beacon pods back to the with beacon version as-well as checking for any new "escape-capsule" original role pods and swapping them out. If griffs is installed the griff escape pod model is used, if not what-ever is currently named "escape-capsule" (I think all the other ship-sets use the same names as the core set??)

There will need to be little handwavium about some NPC pilots disabling/removing their pod's distress beacon to account for other OXP pods with a custom role not being detected by this equipment but overall that is a good thing.

I want to do some more testing before release and also think I'll add in some code to introduce occasional Moray Medical Rescue Ships which inject around the system chasing the custom pods. Don't want to make pod hunting too easy and lucrative for the player.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: OXP idea: Escape capsule locator

Post by Eric Walch »

Capt. Murphy wrote:
Mmm - I still don't get why that is different from the entity.roles[0] which does throw an error if entity.roles[0] is undefined. Unless the JS engine is more likely to throw an error for arrays.
With entity.primaryRole you only test for a null property. The same would be so when testing for entity.roles. The problem arrises when testing for entity.roles[0] because you than request a test for the first member inside a null property.
Makara
Dangerous
Dangerous
Posts: 122
Joined: Sat Oct 17, 2009 6:34 pm

Re: OXP idea: Escape capsule locator

Post by Makara »

Capt. Murphy wrote:
There will need to be little handwavium about some NPC pilots disabling/removing their pod's distress beacon to account for other OXP pods with a custom role not being detected by this equipment but overall that is a good thing.
One thought is that the Escape pod locator ought to be restricted to clean pilots only - possibly to the extent of breaking/disappearing should a commander lose their clean legal status. This isn't something you'd want in the hands of pirates or slavers. Not much handwavium needed for pilots disabling the beacons - any high ransom/bounty types could easily prefer to take their chances in a pod than in the hands of pirates or the authorities, and concern about the locator being possessed by such unsavoury types covers other cases :D
Capt. Murphy wrote:
I want to do some more testing before release and also think I'll add in some code to introduce occasional Moray Medical Rescue Ships which inject around the system chasing the custom pods. Don't want to make pod hunting too easy and lucrative for the player.
Bit of a shame to miss out on the chance to breathe new life into the Cobra Clipper SAR (one of Murgh's ships I believe), although I suppose going for Moray Medical Boats makes it easier for those trying to keep a consistent Griffyverse.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: OXP idea: Escape capsule locator

Post by Eric Walch »

Makara wrote:
Bit of a shame to miss out on the chance to breathe new life into the Cobra Clipper SAR (one of Murgh's ships I believe), although I suppose going for Moray Medical Boats makes it easier for those trying to keep a consistent Griffyverse.
That ship is by Murgh but could never have worked for Murgh. Murgh used the AI command to search ships by role 'escape-capsule'. But that role search command ignored all 'ships' of type "CARGO' and type 'ROCK'. Effectively it never found a pod :evil: Murgh must have noticed this but still released it.
Its only in the current release were a JS search command is used, that this oxp started to scoop the ejected pilots.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: OXP idea: Escape capsule locator

Post by Smivs »

Makara wrote:
Bit of a shame to miss out on the chance to breathe new life into the Cobra Clipper SAR (one of Murgh's ships I believe), although I suppose going for Moray Medical Boats makes it easier for those trying to keep a consistent Griffyverse.
Not my project but I do know one Commander is working on a SAR version of the Chopped Cobra/Cobra S9 :D
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: OXP idea: Escape capsule locator

Post by Kaks »

Capt. Murphy wrote:
Mmm - I still don't get why that is different from the entity.roles[0] which does throw an error if entity.roles[0] is undefined.
Ok, maybe you'll see what I mean if we go through it step by step:

If you check simply for entity.roles and entity roles is undefined, no problem!
If you check for entity.roles[0] you're already looking for a property of an undefined object. Trying to access properties of an undefined (or null) object is an error, trying to access the undefined (or null) object itself isn't an error, since any object can be either undefined or null.

In other words, trying to access properties of something that can't have properties is an error.


do try

Code: Select all

(entity.roles && entity.roles[0] ==  "ecl_escape_capsule" )
and you'll see you won't get any js errors either... I didn't think it was worth mentioning it, since

Code: Select all

( entity.hasRole && entity.hasRole("ecl_escape_capsule") )
does look through all roles rather than just the first one...


BTW, if you replace the .roles object with a non-array object on purpose, then js will complain again.

Trying to access a non-array as if it was an array is also an error. Go figure.

Hope this helps,

Kaks.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: OXP idea: Escape capsule locator

Post by Capt. Murphy »

Thanks again Eric and Kaks - it has sunk in now. I did kind of know the array was the problem without quite understanding the reason. :wink:

I'll certainly take a look at Murgh's ship - but I think I'll stick to making the Moray Medical the rescue ship within the OXP, a because it's a core ship and it's name fits the role, given that pilots in a pod might need some immediate patching up themselves.
However I will include what is needed in turns of roles and/or scripts to make Murgh's ship (or any other) compatible with this OXP's rescue role, as my changing escape-pod roles is likely to break what functionality it has if both are installed.

Actually I will include a like_ship to the clipper SAR in my shipdata - so if you've got the OXP installed some of the rescue ships spawned by this OXP will be the clipper, but with an AI and shipscript that will work with the custom role pods. Same goes for the SAR Chopped Cobra when it's released.

The restricting the equipment to clean players makes sense and had crossed my mind. I should be able to script disabling it on the fly for players that do get themselves a record.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
Makara
Dangerous
Dangerous
Posts: 122
Joined: Sat Oct 17, 2009 6:34 pm

Re: OXP idea: Escape capsule locator

Post by Makara »

Capt. Murphy wrote:
The restricting the equipment to clean players makes sense and had crossed my mind. I should be able to script disabling it on the fly for players that do get themselves a record.
A think about this makes me wonder if full-on removal rather than disabling may be the way to go for someone gaining offender status. The in-game justification is simply that a license to use one must be re-applied for after criminality has caused it to be withdrawn (a straight equipment malfunction/damage can be handled as normal) - if they had got a criminal record for slave trading the authorities may think twice (yep, I know that level of detail is not possible, but you get the idea). The pragmatic reason is that it avoids getting it stuck in a loop with the various autorepair stuff around now :wink: Maybe have a "cracked" version that can only be obtained/repaired at a Hacker Outpost (Anarchies.oxp) for a massively inflated price but doesn't care about legal status.

Interestingly this gizmo would tie in with the Cobra Clipper SAR backstory, "as Obnoxicorp sought more profit by franchising the EscapePod retrieval industry". Nice that it avoids a conflict of narrative there :D
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: OXP idea: Escape capsule locator

Post by Thargoid »

One small question - how does the equipment know your legal status?

And in an even more odd one - how would it manage to uninstall itself if by mistake you launch from the main station with a barrel of slaves in your hold?
Post Reply