UK_Eliter wrote:(1) Select randomly from the missiles and bombs the NPC has on-board.
(2) Fire/drop the weapon, unless it is a mine (or missile) with a large blast radius - in which latter case, do nothing (or fire one of the other weapons, if any).
Just firing a missile already randomly selects one of the available missiles. There is, however, a difference between missiles and mines, as they are used under different circumstances. An NPC will never drop a mine when it wants to fire a missile, and it will never fire a missile if it wants to drop a mine.
Firing missiles is not equivalent to dropping mines, neither strategically, nor tactically, nor in scripting terms. So I am not sure whether it would be a sensible thing to do in the first place.
UK_Eliter wrote:(1) Select randomly from the missiles and bombs the NPC has on-board, but exclude any with a a large blast radius.
(2) Fire/drop the selected weapon.
Randomly selecting one of the pylon-mounted weapons is easy enough.
Code: Select all
{
var missileSlot = Math.floor(Math.random() * this.ship.missiles.length);
var selectedMissile = this.ship.missiles[missileSlot];
}
You can even write that in one line
var selectedMissile = this.ship.missiles[Math.floor(Math.random() * this.ship.missiles.length)]
.
I am not sure what you mean by 'large blast radius'. I understand it to the effect of 'can/will kill the dropping ship as well'. This, however, depends on many factors, among them the strength and desired range of the dealing of damage, but also the current energy status of the dropping ship. The former are not known to scripts, I think. Therefore I'd say that you can't exclude a mine based on whether it can/will kill its dropping ship.
Also, as said above, missiles are completely different weapons from mines tactically and strategically. A missile is aimed at one single opponent and won't usually hurt anybody else. A mine is meant to work indiscriminately against more than one ship. If the dropping ship doesn't want to get hurt as well, there is one (and only one) simple solution: run away from it. However, running away doesn't make much sense after firing a missile. In situations where you can't run away fast enough, there is also one (and only one) simple solution: don't drop the mine in the first place, but use another weapon.
This is why I feel that a script which randomly selects either a missile or a mine, and fires/drops it regardless of the tactical situation, doesn't seem to make much sense.
UK_Eliter wrote:I'm got a script whereby a cloaked ship intercepts other ships, decloaks, fires, and optionally fires a projectile. But I don't want the ship blowing itself up.
The same as above: a mine is not a projectile. Therefore I don't see why it should be selectable at all in this situation.
UK_Eliter wrote:The simplest/good enough solution might simply be to put a timer (/delay/fuse) on NPC Q-bombs. After all, the PLAYER has a (non-neglibile) timer for theirs.
Mines
do have timers, for instance the Q-mine. The five-second-delay is defined in its own AI. It doesn't matter who drops it. There may be OXP mines which don't have delays defined (I don't know them all). But if the don't have a delay defined, they also have no delay if dropped by the player. In short: who drops a mine has nothing to do with the mine's delay. This depends purely on the type of mine.
Take the mines occasionally dropped by Renegade Pirates as an example. You kill the Renegade, and he leaves a Q-bomb among the debris. Only five seconds later, when you have come close in order to scoop the floating cargo, the whole thing explodes in your face. A classical 'Press Space' moment. That's why it's always a wise decision to run away from killed Renegade Pirates and wait a little. If nothing happens after five seconds, it's safe to return an get the loot.