Page 3 of 5

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Fri Nov 02, 2012 10:21 am
by Diziet Sma
Wildeblood wrote:
Why the obsessive checking to determine if a spawned ship is a Q-mine?

Code: Select all

if(ship.isMine && ship.AI==="timebombAI.plist" && ship.name==="Quirium Cascade Mine" && ship.script.name==="oolite-default-ship-script")
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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Fri Nov 02, 2012 3:27 pm
by Svengali
Diziet Sma wrote:
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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Fri Nov 02, 2012 4:09 pm
by Diziet Sma
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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Fri Nov 02, 2012 7:00 pm
by Svengali
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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Sat Nov 03, 2012 3:22 am
by Diziet Sma
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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Sun Nov 04, 2012 11:55 pm
by Tricky
Or you could modify this bit of code that is modified from [EliteWiki] Random Hits OXP...

Code: Select all

    /* 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");
        }
    };

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Mon Nov 05, 2012 12:42 am
by Diziet Sma
Thanks! That's one place I hadn't considered looking.. I'll check it out. 8)

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Mon Nov 05, 2012 1:40 am
by Wildeblood
I added this into my HUD script yesterday, among other things:

Code: Select all

this.shipSpawned = function(ship)
	{
	if (ship.isMine && ship.AI === "timebombAI.plist" && ship.position.distanceTo(player.ship.position) < 25600) this.$panicAlert();
	}
- where panicAlert() is the function that turns the scanner bright red when it's time to panic. That seems to be a sufficient number of checks to me.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Wed Nov 07, 2012 1:37 pm
by JazHaz
Do NPC ships in normal play (ie not in OXP missions) actually use the Q-mine against the player?

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Wed Nov 07, 2012 1:55 pm
by Commander McLane
JazHaz wrote:
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 Image 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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Wed Nov 07, 2012 10:42 pm
by UK_Eliter
Ah yes, q-mines. I think I'll increase the chance of these being carried by the NPC versions of some the ships I've created . .

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Wed Nov 07, 2012 10:50 pm
by Thargoid
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.

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Wed Nov 07, 2012 11:42 pm
by Commander McLane
Thargoid wrote:
I wonder what a psychiatrist would analyze about you from that Freudian error... :wink:

Re: [RELEASE] Quirium Cascade Mine Detector (V1.1)

Posted: Thu Nov 08, 2012 7:43 am
by Thargoid
Dictated, detected, let's call the whole thing off... :oops:

Yak herring poet.

Re: [UPDATED RELEASE] Quirium Cascade Mine Detector (V1.2)

Posted: Tue Dec 25, 2012 8:52 am
by Diziet Sma
Now updated to version 1.2. :D

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. :lol:

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!