Ticket #3891: territoryBlinking.diff

File territoryBlinking.diff, 5.3 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/simulation/components/TerritoryDecay.js

     
    4848
    4949    for (var i = 1; i < numPlayers; ++i)
    5050        if (this.connectedNeighbours[i] > 0 && cmpPlayer.IsMutualAlly(i))
    51             return true; // don't decay if connected to a connected ally
     51        {
     52            // don't decay if connected to a connected ally; disable blinking
     53            cmpTerritoryManager.SetTerritoryBlinking(pos.x, pos.y, false);
     54            return true;
     55        }
    5256
    53     cmpTerritoryManager.SetTerritoryBlinking(pos.x, pos.y);
     57    cmpTerritoryManager.SetTerritoryBlinking(pos.x, pos.y, true);
    5458    return false;
    5559};
    5660
     
    114118        this.UpdateDecayState();
    115119};
    116120
     121TerritoryDecay.prototype.OnDiplomacyChanged = function(msg)
     122{
     123    // changes the connectedness of certain areas
     124    if (!this.territoryOwnership)
     125        this.UpdateDecayState();
     126};
     127
    117128TerritoryDecay.prototype.OnOwnershipChanged = function(msg)
    118129{
    119130    // if it influences the territory, wait until we get a TerritoriesChanged message
  • source/simulation2/components/CCmpTerritoryManager.cpp

     
    237237    virtual std::vector<u32> GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected);
    238238    virtual bool IsConnected(entity_pos_t x, entity_pos_t z);
    239239
    240     virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z);
     240    virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable);
     241    virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z);
    241242
    242243    // To support lazy updates of territory render data,
    243244    // we maintain a DirtyID here and increment it whenever territories change;
     
    731732    return (m_Territories->get(i, j) & TERRITORY_CONNECTED_MASK) != 0;
    732733}
    733734
    734 void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z)
     735void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable)
    735736{
    736737    CalculateTerritories();
    737738    if (!m_Territories)
     
    747748
    748749    FLOODFILL(i, j,
    749750        u8 bitmask = m_Territories->get(nx, nz);
    750         if ((bitmask & TERRITORY_PLAYER_MASK) != thisOwner || (bitmask & TERRITORY_BLINKING_MASK))
     751        if ((bitmask & TERRITORY_PLAYER_MASK) != thisOwner)
    751752            continue;
    752         m_Territories->set(nx, nz, bitmask | TERRITORY_BLINKING_MASK);
     753        u8 blinking = bitmask & TERRITORY_BLINKING_MASK;
     754        if (enable && !blinking)
     755            m_Territories->set(nx, nz, bitmask | TERRITORY_BLINKING_MASK);
     756        else if (!enable && blinking)
     757            m_Territories->set(nx, nz, bitmask & (0xFF - TERRITORY_BLINKING_MASK));
     758        else
     759            continue;
    753760    );
    754761    m_BoundaryLinesDirty = true;
    755762}
    756763
     764bool CCmpTerritoryManager::IsTerritoryBlinking(entity_pos_t x, entity_pos_t z)
     765{
     766    u16 i, j;
     767    NearestTerritoryTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H);
     768    return (bool) m_Territories->get(i, j) & TERRITORY_BLINKING_MASK;
     769}
     770
    757771TerritoryOverlay::TerritoryOverlay(CCmpTerritoryManager& manager) :
    758772    TerrainTextureOverlay((float)Pathfinding::NAVCELLS_PER_TILE / ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE),
    759773    m_TerritoryManager(manager)
  • source/simulation2/components/ICmpTerritoryManager.cpp

     
    2525DEFINE_INTERFACE_METHOD_2("GetOwner", player_id_t, ICmpTerritoryManager, GetOwner, entity_pos_t, entity_pos_t)
    2626DEFINE_INTERFACE_METHOD_3("GetNeighbours", std::vector<u32>, ICmpTerritoryManager, GetNeighbours, entity_pos_t, entity_pos_t, bool)
    2727DEFINE_INTERFACE_METHOD_2("IsConnected", bool, ICmpTerritoryManager, IsConnected, entity_pos_t, entity_pos_t)
    28 DEFINE_INTERFACE_METHOD_2("SetTerritoryBlinking", void, ICmpTerritoryManager, SetTerritoryBlinking, entity_pos_t, entity_pos_t)
     28DEFINE_INTERFACE_METHOD_3("SetTerritoryBlinking", void, ICmpTerritoryManager, SetTerritoryBlinking, entity_pos_t, entity_pos_t, bool)
     29DEFINE_INTERFACE_METHOD_2("IsTerritoryBlinking", bool, ICmpTerritoryManager, IsTerritoryBlinking, entity_pos_t, entity_pos_t)
    2930DEFINE_INTERFACE_METHOD_1("GetTerritoryPercentage", u8, ICmpTerritoryManager, GetTerritoryPercentage, player_id_t)
    3031END_INTERFACE_WRAPPER(TerritoryManager)
  • source/simulation2/components/ICmpTerritoryManager.h

     
    7070    /**
    7171     * Set a piece of territory to blinking. Must be updated on every territory calculation
    7272     */
    73     virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0;
     73    virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable) = 0;
    7474
    7575    /**
     76     * Check if a piece of territory is blinking.
     77     */
     78    virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0;
     79
     80    /**
    7681     * Returns the percentage of the world controlled by a given player as defined by
    7782     * the number of territory cells the given player owns
    7883     */