NPCs and Cloaking Devices

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

Moderators: winston, another_commander

Post Reply
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

NPCs and Cloaking Devices

Post by Smivs »

I have an NPC fitted with a cloaking device, and I was wondering how I can get it to switch on and off. At the moment it is 'automatically' activating when the ship is either attacked or attacking, which is a good thing, but never seems to switch off again, which isn't a good thing!.
How exactly does the game handle NPC cloaks?

EDIT:- I've now found a couple of threads regarding this here and here if anybody is interested.

I think Commander Mclane's suggestion
Commander McLane wrote:

More control would be achievable with new AI methods switchCloakOn and switchCloakOff...
is entirely sensible, and would be really useful. Is this likely to happen? Please :D
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: NPCs and Cloaking Devices

Post by Commander McLane »

Smivs wrote:
I think Commander Mclane's suggestion
Commander McLane wrote:

More control would be achievable with new AI methods switchCloakOn and switchCloakOff...
is entirely sensible, and would be really useful.
Thanks for the flowers! :D

It isn't implemented yet in this form, however, which makes NPC cloak control slightly more difficult, but not impossible.

The clue is in JS. You can't do it in the AI, but you can do it in an attached script. For examples have a look into personalities.oxp, which is the reason I requested the methods in the first place.

You can use the ship.isCloaked property to switch the cloak on or off. However, this brings only a certain degree of flexibility, because the use of the cloak is still mainly controlled by the engine itself through the attackShip-command. (The problem with this was that a NPC with a cloaking device would activate it as soon as it went into attack mode, but there is no command in the code to de-activate it again. So the NPC always stays cloaked from that point, until its energy has been drained.) Since Oolite 1.74 you can use a trick to allow you more control. Because all NPC equipment has become open for scripting, you can award or remove the cloaking device "on the fly", thereby exerting more control over cases in which you don't want the cloaking device to be used. Only this way it is possible to script a behaviour for NPCs that mimicks a typical player's use of the device, e.g. to cloak only for a second in order to get rid of incoming missiles.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The remove/re-award trick certainly works for the player (I use it in TCAT). I would wonder about it for NPCs though, as they would quite possibly immediately re-cloak when it was re-awarded?
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

Thargoid wrote:
The remove/re-award trick certainly works for the player (I use it in TCAT). I would wonder about it for NPCs though, as they would quite possibly immediately re-cloak when it was re-awarded?
I guess so, thus my approach in personalities is to only award it when I want them to cloak.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Post by Smivs »

Interesting stuff!
I posted this because I was in the process of getting my submission for Personalities together, which I have now done (PM on its way to Commander McLane as we speak!)
I would be interested to know more about the JS tricks you are using here, as I'm sure would others, so if you care to share it with us...
This is one reason I never gave my 'Contractor' a cloak, which I would very much like to do for the Bounty Hunter version at least. :)
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

It could be a good exercise in JS to analyze the personalities-ship-script. It's all there in the function this.startDecloakingTimer, which calls this.switchCloakOff.

Of course, doing it via JS means that you only can do it for ships with a ship-script, which limits the possibilities for generic ships. But you're always free to attach a ship script to your own OXP ship.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Post by Smivs »

Commander McLane wrote:
It could be a good exercise in JS to analyze the personalities-ship-script. It's all there in the function this.startDecloakingTimer, which calls this.switchCloakOff.

Of course, doing it via JS means that you only can do it for ships with a ship-script, which limits the possibilities for generic ships. But you're always free to attach a ship script to your own OXP ship.
Thanks, I'll certainly have a look. I know absolutely nothing about JS, but, well you've got to start somewhere. :)
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Cloaking is a bit of a mess when you want to influence it by script. The main reason is that it is largely a function with an autonomy of its own:

- When a ship has a cloak, it always will turn itself on when in attack mode and the ship has an energy level of more than 75%.
- Shut-off only happens after the energy drained beyond a certain level.

With script we now also can set it on/off, but the internal criteria for switching it on stay active. So when you try to switch it off in attack mode and the npc is still are full of energy, the autonomy will switch it on again. The only thing that reliable works is just add/remove the whole cloak itself as McLane wrote.

Maybe the code has to be changed slightly to make it more accessible for scripting. The easiest way would be to add a variable that detects if the mode once has been altered by script, and when yes, it stops any auto switching on with attack from than on and leaves all future changes to the script....
Post Reply