Ticket #2749: t2749_prevent_neutral_players_from_attacking_each_other.patch

File t2749_prevent_neutral_players_from_attacking_each_other.patch, 2.3 KB (added by elexis, 9 years ago)

Implemented that neutral players can't attack each other with the code changes suggested by sanderd17 above. Tested and boats, CCs and units won't attack and can't start capture attacks. As soon as one sets the neutral player to enemy, both diplomacy states will be reset to enemy and attacks start immediately. Not sure about the distribution of capture points though.

  • binaries/data/mods/public/simulation/components/Capturable.js

     
    6767    // Before changing the value, activate Fogging if necessary to hide changes
    6868    var cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging);
    6969    if (cmpFogging)
    7070        cmpFogging.Activate();
    7171
    72     var enemiesFilter = function(v, i) { return v > 0 && !cmpPlayerSource.IsAlly(i); };
     72    var enemiesFilter = function(v, i) { return v > 0 && cmpPlayerSource.IsEnemy(i); };
    7373    var numberOfEnemies = this.cp.filter(enemiesFilter).length;
    7474
    7575    if (numberOfEnemies == 0)
    7676        return 0;
    7777
    7878    // distribute the capture points over all enemies
    7979    var distributedAmount = amount / numberOfEnemies;
    8080    for (let i in this.cp)
    8181    {
    82         if (cmpPlayerSource.IsAlly(i))
     82        if (!cmpPlayerSource.IsEnemy(i))
    8383            continue;
    8484        if (this.cp[i] > distributedAmount)
    8585            this.cp[i] -= distributedAmount;
    8686        else
    8787            this.cp[i] = 0;
     
    119119    if (!cmpPlayerSource)
    120120        warn(playerID + " has no player component defined on its id");
    121121    var cp = this.GetCapturePoints()
    122122    var sourceEnemyCp = 0;
    123123    for (let i in this.GetCapturePoints())
    124         if (!cmpPlayerSource.IsAlly(i))
     124        if (cmpPlayerSource.IsEnemy(i))
    125125            sourceEnemyCp += cp[i];
    126126    return sourceEnemyCp > 0;
    127127};
    128128
    129129//// Private functions ////
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    17371737    var cmpTargetPlayer = QueryOwnerInterface(data.target, IID_Player);
    17381738    if (!cmpEntityPlayer || !cmpTargetPlayer)
    17391739        return false;
    17401740
    17411741    // if the owner is an enemy, it's up to the attack component to decide
    1742     if (!cmpEntityPlayer.IsAlly(cmpTargetPlayer.GetPlayerID()))
     1742    if (cmpEntityPlayer.IsEnemy(cmpTargetPlayer.GetPlayerID()))
    17431743        return cmpAttack.CanAttack(data.target);
    17441744    return false;
    17451745};
    17461746
    17471747/*