Equipment incompatibility handling

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Equipment incompatibility handling

Post by dybal »

If EQ_A lists EQ_B as incompatible, but not vice-versa:

-if the player installs EQ_A and then EQ_B he will have both, until the next save/load
-if the player installs EQ_B, he won't be offered EQ_A

If the savefile has both EQ_A and EQ_B in extra equipment dictionary, the player will lose EQ_A when he loads the savefile.

If a script awards EQ_A and then EQ_B, the ships has both.

if a script awards EQ_B and then EQ_A, the second award fails.

Right now it's possible to have both EQ_A and EQ_B for a game session if acquired in the right order... but the clean-up at game load time tells me that's not how it should be... if that's so, then equipmentAdded event handler in oolite-equipment-control.js needs some work!
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Equipment incompatibility handling

Post by dybal »

Code: Select all

/* Add equipment effects */
this.equipmentAdded = function(equip)
{
    if (!this.$started)
    {
        return;
    }
    if (!this.$equipmentEnabled[equip])
    {
        if (this.$equipmentEnable[equip])
        {
            var info = EquipmentInfo.infoForKey(equip);
//          log(this.name,"Enabling "+info.equipmentKey); //tmp - remove later
            var result = this.$equipmentEnable[equip].bind(this,info)();
            if (result == -1)
            {
            |   return;
            }
        }
    }
    var eq_dict = this.$equipmentEnabled;
    var eqIncompatible;
    for (eqKey in eq_dict) {
        eqIncompatible = EquipmentInfo.infoForKey(eqKey).incompatibleEquipment;
        if (eqIncompatible && eqIncompatible.indexOf(equip) >= 0) {
            player.ship.removeEquipment(eqKey);
        }
    }
    this.$equipmentEnabled[equip] = 1;
};
Already debugged...

EDIT: I posted this in the wrong topic... now moved to the correct one :oops: :wink:
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Equipment incompatibility handling

Post by dybal »

I would like to create a branch in the github repo and then a PR... whom should I contact to get permission to create a branch/PR?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Equipment incompatibility handling

Post by phkb »

I've added the branch and PR for the time being.
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Equipment incompatibility handling

Post by dybal »

Thanks!
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Equipment incompatibility handling

Post by dybal »

Found a problem with my code, EquipmentInfo.inforForKey doesn't return an object for those EQ_NUMERIC* from the HUD...

Code: Select all

23:22:54.175 [LogEvents]: ship lost EQ_NUMERIC3_ALERTCONDITIONGREEN
23:22:54.175 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (Oolite Equipment Control 1.89): TypeError: EquipmentInfo.infoForKey(eqKey) is null
23:22:54.175 [script.javaScript.exception.unexpectedType]:       /home/dybal/GNUstep/Applications/Oolite-trunk/oolite.app/Resources/Scripts/oolite-equipment-control.js, line 162.
Revised code:

Code: Select all

   var eq_dict = this.$equipmentEnabled;
    var eqInfo;
    for (eqKey in eq_dict) {
        eqInfo = EquipmentInfo.infoForKey(eqKey);
        if (eqInfo && eqInfo.incompatibleEquipment && eqInfo.incompatibleEquipment.indexOf(equip) >= 0) {
            player.ship.removeEquipment(eqKey);
        }
    }
    this.$equipmentEnabled[equip] = 1;
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Equipment incompatibility handling

Post by phkb »

Was also missing a declaration for eqKey. New PR added.
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Equipment incompatibility handling

Post by dybal »

phkb wrote: Thu Aug 13, 2020 5:00 am
Was also missing a declaration for eqKey. New PR added.
So it does... :oops:

The interpreter didn't take objection to the lack: there were no errors in Latest.log when I run it (and I had a trace inside the loop to check things since I wasn't seeing the behaviour I expected when loading a savefile with a pair of incompatible equipments - the problem wasn't here but at the equipments' declaration in equipment.plist though - so I'm sure that code was executed)

Anyway, thanks for applying and correcting it!
Post Reply