Ticket #4092: 4092_ai_compatibility.patch

File 4092_ai_compatibility.patch, 2.3 KB (added by elexis, 8 years ago)

Added AI compatibility, as noticed by fatherbushido. Those are all the occurances of RestrictedClasses. Couldn't find any template besides the fishing ship which has an Attack component but no attacking abilities (besides killing whale).

  • binaries/data/mods/public/simulation/ai/common-api/entity.js

    m.Template = m.Class({  
    322322    canAttackClass: function(saidClass) {
    323323        if (!this.get("Attack"))
    324324            return false;
    325325
    326326        for (let type in this.get("Attack"))
    327         {
    328             let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string");
    329             if (!restrictedClasses)
    330                 continue;
    331             if (restrictedClasses.split(" ").indexOf(saidClass) !== -1)
     327            if (restrictedClasses && !MatchesClassList([saidClass], restrictedClasses)))
    332328                return false;
    333         }
     329
    334330        return true;
    335331    },
    336332
    337333    "buildableEntities": function() {
    338334        let templates = this.get("Builder/Entities/_string");
  • binaries/data/mods/public/simulation/components/Attack.js

    Attack.prototype.CanAttack = function(ta  
    240240
    241241        let restrictedClasses = this.GetRestrictedClasses(type);
    242242        if (!restrictedClasses.length)
    243243            return true;
    244244
    245         if (targetClasses.every(c => restrictedClasses.indexOf(c) == -1))
     245        if (!MatchesClassList(targetClasses, restrictedClasses))
    246246            return true;
    247247    }
    248248
    249249    return false;
    250250};
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fishing.xml

     
    1010      <Hack>10.0</Hack>
    1111      <Pierce>0.0</Pierce>
    1212      <Crush>0.0</Crush>
    1313      <MaxRange>5.0</MaxRange>
    1414      <RepeatTime>1000</RepeatTime>
    15       <RestrictedClasses datatype="tokens">Ship Structure Human Elephant Domestic</RestrictedClasses>
     15      <RestrictedClasses datatype="tokens">!SeaCreature </RestrictedClasses>
    1616    </Melee>
    1717  </Attack>
    1818  <Footprint>
    1919    <Square width="4.0" depth="10.0"/>
    2020    <Height>6.0</Height>