1
0
forked from 0ad/0ad

Fix problems with EndGameManager in Atlas by waiting for the first turn

This was SVN commit r14118.
This commit is contained in:
sanderd17 2013-11-09 10:09:28 +00:00
parent 9cc172b164
commit 2d2853dd6f
2 changed files with 22 additions and 8 deletions

View File

@ -31,8 +31,25 @@ EndGameManager.prototype.SetAlliedVictory = function(flag)
this.alliedVictory = flag;
};
EndGameManager.prototype.PlayerLostAllConquestCriticalEntities = function(playerID)
/*
* Check players the next turn. Avoids problems in Atlas, with promoting entities etc
*/
EndGameManager.prototype.CheckPlayers = function()
{
if (this.timeout)
return;
// wait a turn for actually checking the players
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
this.timeout = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "CheckPlayersNow", 100, null);
};
/*
* Check players immediately. Might cause problems with converting/promoting entities.
*/
EndGameManager.prototype.CheckPlayersNow = function()
{
if (this.timeout)
this.timeout = null;
if (this.gameType == "endless")
return;
@ -56,7 +73,7 @@ EndGameManager.prototype.PlayerLostAllConquestCriticalEntities = function(player
cmpPlayers[i] = Engine.QueryInterface(playerEntityId, IID_Player);
if (cmpPlayers[i].GetState() != "active")
continue;
if (i == playerID)
if (cmpPlayers[i].GetConquestCriticalEntitiesCount() == 0)
Engine.PostMessage(playerEntityId, MT_PlayerDefeated, { "playerId": i } );
else
{

View File

@ -34,6 +34,7 @@ Player.prototype.Init = function()
this.cheatsEnabled = false;
this.cheatTimeMultiplier = 1;
this.heroes = [];
Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).CheckPlayers();
};
Player.prototype.SetPlayerID = function(id)
@ -482,12 +483,8 @@ Player.prototype.OnGlobalOwnershipChanged = function(msg)
if (cmpIdentity && cmpIdentity.HasClass("ConquestCritical"))
this.conquestCriticalEntitiesCount--;
if (this.conquestCriticalEntitiesCount == 0)
{
// end game when needed
var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
cmpEndGameManager.PlayerLostAllConquestCriticalEntities(this.playerID);
}
if (this.conquestCriticalEntitiesCount == 0) // end game when needed
Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).CheckPlayers();
if (cmpCost)
{