Ticket #3526: connectedTerritory.2.diff

File connectedTerritory.2.diff, 6.0 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/simulation/ai/petra/mapModule.js

     
    33
    44// other map functions
    55m.TERRITORY_PLAYER_MASK = 0x1F;
     6m.TERRITORY_BLINKING_MASK = 0x40;
    67
    78m.createObstructionMap = function(gameState, accessIndex, template)
    89{
     
    4344    for (let k = 0; k < territoryMap.data.length; ++k)
    4445    {
    4546        let tilePlayer = (territoryMap.data[k] & m.TERRITORY_PLAYER_MASK);
    46         if ((!buildNeutral && tilePlayer == 0) ||
    47             (!buildOwn && tilePlayer == PlayerID) ||
    48             (!buildAlly && tilePlayer != PlayerID && gameState.isPlayerAlly(tilePlayer)) ||
    49             (!buildEnemy && tilePlayer != 0 && gameState.isPlayerEnemy(tilePlayer)))
    50             continue;
     47        let isConnected = (territoryMap.data[k] & m.TERRITORY_BLINKING_MASK) == 0;
     48        if (tilePlayer == PlayerID)
     49        {
     50            if (!buildOwn || !buildNeutral && !isConnected)
     51                continue;
     52        }
     53        else if (tilePlayer != PlayerID && gameState.isPlayerAlly(tilePlayer))
     54        {
     55            if (!buildAlly || !buildNeutral && !isConnected)
     56                continue;
     57        }
     58        else if (tilePlayer == 0)
     59        {
     60            if (!buildNeutral)
     61                continue;
     62        }
     63        else
     64        {
     65            if (!buildEnemy)
     66                continue;
     67        }
     68
    5169        let x = ratio * (k % territoryMap.width);
    5270        let y = ratio * (Math.floor(k / territoryMap.width));
    5371        for (let ix = 0; ix < ratio; ++ix)
  • 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.IsTerritoryBlinking(pos.x, pos.y);
     175    var isOwn = tileOwner == cmpPlayer.GetPlayerID();
     176    var isMutualAlly = cmpPlayer.IsExclusiveMutualAlly(tileOwner);
     177    var isNeutral = tileOwner == 0;
    179178
    180     var territoryFail = true;
    181     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");
     179    var invalidTerritory = "";
     180    if (isOwn)
     181    {
     182        if (!this.HasTerritory("own"))
     183            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     184            invalidTerritory = markForTranslationWithContext("Territory type", "own");
     185        else if (!isConnected && !this.HasTerritory("neutral"))
     186            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     187            invalidTerritory = markForTranslationWithContext("Territory type", "unconnected own");
     188    }
     189    else if (isMutualAlly)
     190    {
     191        if (!this.HasTerritory("ally"))
     192            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     193            invalidTerritory = markForTranslationWithContext("Territory type", "allied");
     194        else if (!isConnected && !this.HasTerritory("neutral"))
     195            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     196            invalidTerritory = markForTranslationWithContext("Territory type", "unconnected allied");
     197    }
     198    else if (isNeutral)
     199    {
     200        if (!this.HasTerritory("neutral"))
     201            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     202            invalidTerritory = markForTranslationWithContext("Territory type", "neutral");
     203    }
    194204    else
    195         territoryFail = false;
     205    {
     206        // consider everything else enemy territory
     207        if (!this.HasTerritory("enemy"))
     208            // Translation: territoryType being displayed in a translated sentence in the form: "House cannot be built in %(territoryType)s territory.".
     209            invalidTerritory = markForTranslationWithContext("Territory type", "enemy");
     210    }
    196211
    197     if (territoryFail)
     212    if (invalidTerritory)
    198213    {
    199214        result.message = markForTranslation("%(name)s cannot be built in %(territoryType)s territory. Valid territories: %(validTerritories)s");
    200215        result.translateParameters.push("territoryType");
    201216        result.translateParameters.push("validTerritories");
    202         result.parameters.territoryType = {"context": "Territory type", "message": territoryType};
     217        result.parameters.territoryType = {"context": "Territory type", "message": invalidTerritory};
    203218        // gui code will join this array to a string
    204219        result.parameters.validTerritories = {"context": "Territory type list", "list": this.GetTerritories()};
    205220        return result;  // Fail