1
0
forked from 0ad/0ad

Improve ownership changes by only giving the cp of the old owner to the new owner.

This was SVN commit r16755.
This commit is contained in:
sanderd17 2015-06-13 09:53:15 +00:00
parent 30efa73a38
commit 204dcf201c
2 changed files with 22 additions and 16 deletions

View File

@ -25,7 +25,7 @@ function init(initData, hotloadData)
// Pick a random background and initialise it
g_BackgroundCode = Math.floor(Math.random() * g_BackgroundLayerData.length);
var layerset = g_BackgroundLayerData[g_BackgroundCode];
for (var i = 0; i < layerset.length; i++)
for (var i = 0; i < layerset.length; ++i)
{
var layer = layerset[i];
var guiObj = Engine.GetGUIObjectByName("background["+i+"]");

View File

@ -253,22 +253,28 @@ Capturable.prototype.OnTerritoryDecayChanged = function(msg)
Capturable.prototype.OnOwnershipChanged = function(msg)
{
if (this.cp.length)
{
if (!this.cp[msg.from])
return; // nothing to change
// Was already initialised, this happens on defeat or wololo
// transfer the points of the old owner to the new one
this.cp[msg.to] += this.cp[msg.from];
this.cp[msg.from] = 0;
this.RegisterCapturePointsChanged();
}
else
{
// initialise the capture points when created
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
for (let i = 0; i < cmpPlayerManager.GetNumPlayers(); ++i)
if (i == msg.to)
this.cp[i] = this.maxCp;
else
this.cp[i] = 0;
}
this.CheckTimer();
// if the new owner has no capture points, it means that either
// * it's being initialised now, or
// * it changed ownership for a different reason (defeat, atlas, ...)
if (this.cp[msg.to])
return;
// initialise the capture points when created
this.cp = [];
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
for (let i = 0; i < cmpPlayerManager.GetNumPlayers(); ++i)
if (i == msg.to)
this.cp[i] = this.maxCp;
else
this.cp[i] = 0;
};
Engine.RegisterComponentType(IID_Capturable, "Capturable", Capturable);