Surely if(ship.AI==="timebombAI.plist") is all you need? If a replacement ship set uses a name other than "Quirium Cascade Mine", your test will fail and give a false negative. But any ship which has its active AI set to timebombAI.plist will be a Q-mine. Is there any possibility of that simple test giving a false positive?
The "why" is that that snippet of code was lifted from BGS. Svengali seemed to find it necessary, so I decided not to mess with something that somebody smarter than me had created. I should add that I actually had to remove the first part of the the check, which originally ran if(ship.isValid &&..., in order to get consistent detection. Until then, sometimes it worked, sometimes it didn't.
Comment by Svengali on this point would be appreciated.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
Comment by Svengali on this point would be appreciated.
BGS has the rule not to mess with other OXPs stuff if they don't call functionality in BGS explicitely. The checks are explicitely there to minimize possible clashes. BGS does (if the option is enabled) a monkeypatch to play a sound on explosion and I've decided to do it only for Q-Mines which are using the default setup (AI, name and script). And we have quite a few OXPs out there which are removing entities without checking anything, so testing .isValid is necessary.
Hmm.. so, would you recommend I leave the QBD code as-is, or implement Wildeblood's suggestion?
I never got to the bottom of why the .isValid test caused detection to fail sometimes.. from what you've said, I'm guessing if the Q-Bomb was launched by an OXP ship that perhaps in some situations the test may fail? My theorising at the time was that if the ship that spawned the Q-Bomb was destroyed before the test was performed, it may have been causing the test-failure.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
You can't make it failsafe - OXPs can do own cascading mines easily (with different AIs, names, scripts, roles, etc). So I'd suggest - use what feels right for your OXP.
Ok.. under the old "don't fix what ain't broke" principle, I'll leave it as is then. I gather that in 1.77, Q-Bomb detection is much simpler. I'll leave the fix for that version.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
/* Scan for cascade weapons. Won't be needed when v1.78 comes out.
* Reacts with a 'CASCADE_WEAPON_FOUND' AI message rather than 'CASCADE_WEAPON_DETECTED' used by Oolite v1.77+
*
* INPUT
* callerShip - caller ship.
*/
this.$scanForCascadeWeapon = function (callerShip) {
/* This is modified from some code in Random Hits spacebar ship script. */
var cascadeWeaponRoles = [
"EQ_QC_MINE",
"EQ_CASCADE_MISSILE",
"EQ_LAW_MISSILE",
"EQ_OVERRIDE_MISSILE",
"energy-bomb",
"RANDOM_HITS_MINE"
],
cascadeWeapons;
/* Search for any cascade weapons within maximum scanner range of the caller ship. */
cascadeWeapons = system.filteredEntities(this, function (entity) {
return (cascadeWeaponRoles.indexOf(entity.primaryRole) > -1);
}, callerShip, callerShip.scannerRange);
if (cascadeWeapons.length > 0) {
/* Found at least one. First one in the cascadeWeapons array is the closest.
* Set the target and send a CASCADE_WEAPON_FOUND message to the AI.
*/
callerShip.target = cascadeWeapons[0];
callerShip.reactToAIMessage("CASCADE_WEAPON_FOUND");
}
};
Thanks! That's one place I hadn't considered looking.. I'll check it out.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
Do NPC ships in normal play (ie not in OXP missions) actually use the Q-mine against the player?
Yes, they can, if they have the key has_energy_bomb (klick to see the other conditions) defined and set to something else than "no" or "0" in their shipdata.
None of the in-built ships have this key defined, though. Therefore you'll never see one of the standard ships use a Q-mine. Depending on their shipdata, this may be different for OXP ships.
And a new script event went into trunk today which will make things easier. 5476 (I think,maybe 5475) added cascadeWeaponDictated as a ship script event.
I was going to wait until the Q-Bomb detector reached the 100th download (currently on 97) but, being Christmas and all, I'm too excited to hold off.
The QBD is now able to function correctly both in 1.76.1 and 1.77+ (the old code did not work in trunk). I've simplified the pre-1.77 detection code as suggested by Wildeblood, and added code that will use the new this.cascadeWeaponDetected function instead, if the QBD detects that it is running in Oolite 1.77 or later.
Download link is in the first post of the thread.
Merry Christmas, all!
Last edited by Diziet Sma on Tue Dec 25, 2012 10:13 am, edited 1 time in total.
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied