Okay, it's done. I think the smallest OXP I've ever done (and I've done quite some small OXPs).
Thanks, Eric, for the formula used by NPCs. I went for a more simple approach: It shall fire when your last energy bar is below one third, so:
Code: Select all
if(player.ship.energy < 22 && player.ship.hasEquipment("EQ_ESCAPE_POD") && player.ship.hasEquipment("EQ_AUTO_EJECT"))
As everybody can see here, the functionality indeed comes with an equipment upgrade, the Auto Eject Module. Costs 500 cr and is only available for purchase if you've got an escape pod in the first place. Also, as it is actually a modification of your escape pod, and has to connect to your ship's energy bars in order to measure the remaining energy, it is only available starting from TL 8 (instead of TL 6 like the escape pod itself). As it's a technical approach, it needs more sophistication in the equipment department.
And it is not 100% reliable, because several things can go wrong in a fight.
I did six consecutive tests by spawning a renegade pirate next to my ship and letting him blow me to pieces.
The first time the auto-eject worked (or rather it
would have worked if I was on trunk; the actual ejecting command doesn't exist yet in 1.73.4; but I got an error in my log that
player.ship.abandonShip(); is not a legal method, so I know that Oolite tried to execute it).
Two other times I was hit and destroyed by broadsides of plasma turrets, which vaporized the last one-and-a-half energy banks in an instant. So there was no moment when I was below one third of my last energy bank. It was: fine-with-one-and-a-half-banks -> Press Space, Commander. So, if your ship is swallowing broadsides of multiple plasma turrets, RUN! Don't rely on your auto eject!
The remaining three times either the escape pod itself (twice) or the auto eject module (once) got damaged during the fight
before I was on my last energy bank. So when it came to the final showdown -> Press Space, Commander.
Bottom line: even if it becomes available with Oolite 1.74, don't entrust your life to your Auto Eject Module. Sometimes it is a better idea to eject yourself early, because you never know what will happen once you're down to only two energy banks. And chances are that in the heat of the fight the small message on your screen,
Escape Pod damaged, escapes your attention.