Ticket #3702: lockedTeams2.patch

File lockedTeams2.patch, 4.6 KB (added by Matthew Guttag, 8 years ago)

Corrected the patch to work with ceasefire

  • gui/session/menu.js

     
    295295        Engine.GetGUIObjectByName("diplomacyPlayerCiv["+(i-1)+"]").caption = g_CivData[g_Players[i].civ].Name;
    296296        Engine.GetGUIObjectByName("diplomacyPlayerTeam["+(i-1)+"]").caption = (g_Players[i].team < 0) ? translateWithContext("team", "None") : g_Players[i].team+1;
    297297        Engine.GetGUIObjectByName("diplomacyPlayerTheirs["+(i-1)+"]").caption = (i == g_ViewedPlayer) ? "" : (g_Players[i].isAlly[g_ViewedPlayer] ? translate("Ally") : (g_Players[i].isNeutral[g_ViewedPlayer] ? translate("Neutral") : translate("Enemy")));
    298 
    299         // Don't display the options for ourself, or if we or the other player aren't active anymore
    300         if (i == g_ViewedPlayer || g_Players[i].state != "active")
    301         {
    302             // Hide the unused/unselectable options
    303             for (let a of ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])
    304                 Engine.GetGUIObjectByName("diplomacyPlayer"+a+"["+(i-1)+"]").hidden = true;
    305             Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]").hidden = true;
     298       
     299        // Don't display the options for ourself
     300        if (i == g_ViewedPlayer || g_Players[g_ViewedPlayer].state != "active" || g_Players[i].state != "active")
     301        {
     302            // Hide the unused/unselectable options
     303            for (let action of ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])
     304                Engine.GetGUIObjectByName("diplomacyPlayer"+action+"["+(i-1)+"]").hidden = true;
     305            Engine.GetGUIObjectByName("diplomacyAttackRequest["+(i-1)+"]").hidden = true;
    306306            continue;
    307         }
    308 
     307        }
     308       
    309309        // Tribute
    310310        for (let resource of RESOURCES)
    311311        {
     
    353353        button.onpress = (function(i) { return function() {
    354354            Engine.PostNetworkCommand({ "type": "attack-request", "source": g_ViewedPlayer, "target": i });
    355355        }; })(i);
     356       
     357        //Don't display tribute options but do display attack options if teams locked and not on our team
     358        if (g_Players[g_ViewedPlayer].teamsLocked && (g_Players[g_ViewedPlayer].team != -1 && g_Players[i].team != -1 && g_Players[i].team != g_Players[g_ViewedPlayer].team))
     359        {
     360            // Hide the unused/unselectable options
     361            for (let action of ["TributeFood", "TributeWood", "TributeStone", "TributeMetal", "Ally", "Neutral", "Enemy"])
     362                Engine.GetGUIObjectByName("diplomacyPlayer"+action+"["+(i-1)+"]").hidden = true;
     363        }
    356364
    357         // Skip our own teams on teams locked
    358         if (g_Players[g_ViewedPlayer].teamsLocked && g_Players[g_ViewedPlayer].team != -1 && g_Players[g_ViewedPlayer].team == g_Players[i].team)
     365        // Skip our own teams and other teams on teams locked
     366        if (g_Players[g_ViewedPlayer].teamsLocked && g_Players[g_ViewedPlayer].team != -1 && g_Players[i].team != -1)
    359367            continue;
    360368
    361369        // Diplomacy settings
  • simulation/components/Player.js

     
    403403
    404404Player.prototype.SetDiplomacy = function(dipl)
    405405{
    406     // Should we check for teamsLocked here?
    407406    this.diplomacy = dipl;
    408407    Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
    409408};
     
    424423    // You can have alliances with other players,
    425424    if (this.teamsLocked)
    426425    {
    427         // but can't stab your team members in the back
    428         if (this.team == -1 || this.team != cmpPlayer.GetTeam())
     426        // Break alliance or declare war
     427        if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value)
    429428        {
    430             // Break alliance or declare war
    431             if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value)
     429            // Can't stab your team members in the back
     430            if (this.team == -1 || cmpPlayer.GetTeam() == -1 || this.team != cmpPlayer.GetTeam())
    432431            {
    433432                this.diplomacy[idx] = value;
    434433                cmpPlayer.SetDiplomacyIndex(this.playerID, value);
    435434            }
    436             else
    437             {
     435        }
     436        else
     437        {
     438            //Allow upgrading relations to neutral only
     439            if (this.team == -1 || cmpPlayer.GetTeam() == -1 || (this.team != cmpPlayer.GetTeam() && value == 0))
    438440                this.diplomacy[idx] = value;
    439             }
    440             Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
    441441        }
     442        Engine.BroadcastMessage(MT_DiplomacyChanged, {"player": this.playerID});
    442443    }
    443444    else
    444445    {
     
    714715
    715716    if (this.state != "active" || cmpPlayer.state != "active")
    716717        return;
    717 
     718   
     719    if (this.teamsLocked && this.team != -1 && cmpPlayer.team != -1 && this.team != cmpPlayer.team)
     720        return;
     721   
    718722    if (!this.SubtractResourcesOrNotify(amounts))
    719723        return;
    720724