forked from mirrors/0ad
Fix territory not being updated when diplomacy changes. Fixes #3891
This was SVN commit r18012.
This commit is contained in:
@@ -48,9 +48,13 @@ TerritoryDecay.prototype.IsConnected = function()
|
||||
|
||||
for (var i = 1; i < numPlayers; ++i)
|
||||
if (this.connectedNeighbours[i] > 0 && cmpPlayer.IsMutualAlly(i))
|
||||
return true; // don't decay if connected to a connected ally
|
||||
{
|
||||
// don't decay if connected to a connected ally; disable blinking
|
||||
cmpTerritoryManager.SetTerritoryBlinking(pos.x, pos.y, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
cmpTerritoryManager.SetTerritoryBlinking(pos.x, pos.y);
|
||||
cmpTerritoryManager.SetTerritoryBlinking(pos.x, pos.y, true);
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -114,6 +118,13 @@ TerritoryDecay.prototype.OnTerritoryPositionChanged = function(msg)
|
||||
this.UpdateDecayState();
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.OnDiplomacyChanged = function(msg)
|
||||
{
|
||||
// Can change the connectedness of certain areas
|
||||
if (!this.territoryOwnership)
|
||||
this.UpdateDecayState();
|
||||
};
|
||||
|
||||
TerritoryDecay.prototype.OnOwnershipChanged = function(msg)
|
||||
{
|
||||
// if it influences the territory, wait until we get a TerritoriesChanged message
|
||||
|
||||
@@ -237,7 +237,8 @@ public:
|
||||
virtual std::vector<u32> GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected);
|
||||
virtual bool IsConnected(entity_pos_t x, entity_pos_t z);
|
||||
|
||||
virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z);
|
||||
virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable);
|
||||
virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z);
|
||||
|
||||
// To support lazy updates of territory render data,
|
||||
// we maintain a DirtyID here and increment it whenever territories change;
|
||||
@@ -731,7 +732,7 @@ bool CCmpTerritoryManager::IsConnected(entity_pos_t x, entity_pos_t z)
|
||||
return (m_Territories->get(i, j) & TERRITORY_CONNECTED_MASK) != 0;
|
||||
}
|
||||
|
||||
void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z)
|
||||
void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable)
|
||||
{
|
||||
CalculateTerritories();
|
||||
if (!m_Territories)
|
||||
@@ -747,13 +748,26 @@ void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z)
|
||||
|
||||
FLOODFILL(i, j,
|
||||
u8 bitmask = m_Territories->get(nx, nz);
|
||||
if ((bitmask & TERRITORY_PLAYER_MASK) != thisOwner || (bitmask & TERRITORY_BLINKING_MASK))
|
||||
if ((bitmask & TERRITORY_PLAYER_MASK) != thisOwner)
|
||||
continue;
|
||||
u8 blinking = bitmask & TERRITORY_BLINKING_MASK;
|
||||
if (enable && !blinking)
|
||||
m_Territories->set(nx, nz, bitmask | TERRITORY_BLINKING_MASK);
|
||||
else if (!enable && blinking)
|
||||
m_Territories->set(nx, nz, bitmask & ~TERRITORY_BLINKING_MASK);
|
||||
else
|
||||
continue;
|
||||
m_Territories->set(nx, nz, bitmask | TERRITORY_BLINKING_MASK);
|
||||
);
|
||||
m_BoundaryLinesDirty = true;
|
||||
}
|
||||
|
||||
bool CCmpTerritoryManager::IsTerritoryBlinking(entity_pos_t x, entity_pos_t z)
|
||||
{
|
||||
u16 i, j;
|
||||
NearestTerritoryTile(x, z, i, j, m_Territories->m_W, m_Territories->m_H);
|
||||
return (m_Territories->get(i, j) & TERRITORY_BLINKING_MASK) != 0;
|
||||
}
|
||||
|
||||
TerritoryOverlay::TerritoryOverlay(CCmpTerritoryManager& manager) :
|
||||
TerrainTextureOverlay((float)Pathfinding::NAVCELLS_PER_TILE / ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE),
|
||||
m_TerritoryManager(manager)
|
||||
|
||||
@@ -25,6 +25,7 @@ BEGIN_INTERFACE_WRAPPER(TerritoryManager)
|
||||
DEFINE_INTERFACE_METHOD_2("GetOwner", player_id_t, ICmpTerritoryManager, GetOwner, entity_pos_t, entity_pos_t)
|
||||
DEFINE_INTERFACE_METHOD_3("GetNeighbours", std::vector<u32>, ICmpTerritoryManager, GetNeighbours, entity_pos_t, entity_pos_t, bool)
|
||||
DEFINE_INTERFACE_METHOD_2("IsConnected", bool, ICmpTerritoryManager, IsConnected, entity_pos_t, entity_pos_t)
|
||||
DEFINE_INTERFACE_METHOD_2("SetTerritoryBlinking", void, ICmpTerritoryManager, SetTerritoryBlinking, entity_pos_t, entity_pos_t)
|
||||
DEFINE_INTERFACE_METHOD_3("SetTerritoryBlinking", void, ICmpTerritoryManager, SetTerritoryBlinking, entity_pos_t, entity_pos_t, bool)
|
||||
DEFINE_INTERFACE_METHOD_2("IsTerritoryBlinking", bool, ICmpTerritoryManager, IsTerritoryBlinking, entity_pos_t, entity_pos_t)
|
||||
DEFINE_INTERFACE_METHOD_1("GetTerritoryPercentage", u8, ICmpTerritoryManager, GetTerritoryPercentage, player_id_t)
|
||||
END_INTERFACE_WRAPPER(TerritoryManager)
|
||||
|
||||
@@ -70,7 +70,12 @@ public:
|
||||
/**
|
||||
* Set a piece of territory to blinking. Must be updated on every territory calculation
|
||||
*/
|
||||
virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0;
|
||||
virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable) = 0;
|
||||
|
||||
/**
|
||||
* Check if a piece of territory is blinking.
|
||||
*/
|
||||
virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0;
|
||||
|
||||
/**
|
||||
* Returns the percentage of the world controlled by a given player as defined by
|
||||
|
||||
Reference in New Issue
Block a user