Page 1 of 1
NPCs and Cloaking Devices
Posted: Wed Oct 06, 2010 9:15 pm
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
Re: NPCs and Cloaking Devices
Posted: Thu Oct 07, 2010 8:36 am
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!
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.
Posted: Thu Oct 07, 2010 8:41 am
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?
Posted: Thu Oct 07, 2010 8:47 am
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.
Posted: Thu Oct 07, 2010 9:56 am
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.
Posted: Thu Oct 07, 2010 8:27 pm
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.
Posted: Thu Oct 07, 2010 8:31 pm
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.
Posted: Thu Oct 07, 2010 9:00 pm
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....