Ticket #3526: connectedTerritory.diff

File connectedTerritory.diff, 4.5 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/simulation/components/BuildRestrictions.js

     
    171171
    172172    var pos = cmpPosition.GetPosition2D();
    173173    var tileOwner = cmpTerritoryManager.GetOwner(pos.x, pos.y);
    174     var isOwn = (tileOwner == cmpPlayer.GetPlayerID());
    175     var isNeutral = (tileOwner == 0);
    176     var isAlly = !isOwn && cmpPlayer.IsAlly(tileOwner);
    177     // We count neutral players as enemies, so you can't build in their territory.
    178     var isEnemy = !isNeutral && (cmpPlayer.IsEnemy(tileOwner) || cmpPlayer.IsNeutral(tileOwner));
     174    var isConnected = cmpTerritoryManager.IsConnected(pos.x, pos.y);
     175    if (!isConnected)
     176    {
     177        // if the area itself isn't connected, check if it's connected to an ally
     178        var neighbours = cmpTerritoryManager.GetNeighbours(pos.x, pos.y, true);
     179        isConnected = neighbours.some((v, i) => v > 0 && cmpPlayer.IsMutualAlly(i));
     180    }
    179181
    180     var territoryFail = true;
     182    var isOwn = tileOwner == cmpPlayer.GetPlayerID();
     183    var isMutualAlly = cmpPlayer.IsExclusiveMutualAlly(tileOwner);
     184    var isNeutral = tileOwner == 0;
     185
     186    var territoryValid = true;
    181187    var territoryType = "";
    182     if (isAlly && !this.HasTerritory("ally"))
    183         // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
    184         territoryType = markForTranslationWithContext("Territory type", "ally");
    185     else if (isOwn && !this.HasTerritory("own"))
    186         // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
    187         territoryType = markForTranslationWithContext("Territory type", "own");
    188     else if (isNeutral && !this.HasTerritory("neutral"))
    189         // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
    190         territoryType = markForTranslationWithContext("Territory type", "neutral");
    191     else if (isEnemy && !this.HasTerritory("enemy"))
    192         // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
    193         territoryType = markForTranslationWithContext("Territory type", "enemy");
     188    if (isOwn)
     189    {
     190        if (!this.HasTerritory("own"))
     191        {
     192            territoryValid = false;
     193            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     194            territoryType = markForTranslationWithContext("Territory type", "own");
     195        }
     196        else if (!isConnected)
     197        {
     198            territoryValid = false;
     199            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     200            territoryType = markForTranslationWithContext("Territory type", "unconnected");
     201        }
     202    }
     203    else if (isMutualAlly)
     204    {
     205        if (!this.HasTerritory("ally"))
     206        {
     207            territoryValid = false;
     208            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     209            territoryType = markForTranslationWithContext("Territory type", "allied");
     210        }
     211        else if (!isConnected)
     212        {
     213            territoryValid = false;
     214            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     215            territoryType = markForTranslationWithContext("Territory type", "unconnected");
     216        }
     217    }
     218    else if (isNeutral)
     219    {
     220        if (!this.HasTerritory("neutral"))
     221        {
     222            territoryValid = false;
     223            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     224            territoryType = markForTranslationWithContext("Territory type", "neutral");
     225        }
     226    }
    194227    else
    195         territoryFail = false;
     228    {
     229        // consider everything else enemy territory
     230        if (!this.HasTerritory("enemy"))
     231        {
     232            territoryValid = false;
     233            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     234            territoryType = markForTranslationWithContext("Territory type", "enemy");
     235        }
     236    }
    196237
    197     if (territoryFail)
     238    if (!territoryValid)
    198239    {
    199240        result.message = markForTranslation("%(name)s cannot be built in %(territoryType)s territory. Valid territories: %(validTerritories)s");
    200241        result.translateParameters.push("territoryType");