Fix some of the undefined warnings reported by the new SpiderMonkey. Initialize the player diplomacy arrays earlier in PlayerManager.

This was SVN commit r14882.
This commit is contained in:
sanderd17 2014-03-29 11:03:00 +00:00
parent 120f71d944
commit 132020f88e
6 changed files with 21 additions and 6 deletions

View file

@ -24,6 +24,7 @@ GuiInterface.prototype.Init = function()
this.renamedEntities = [];
this.timeNotificationID = 1;
this.timeNotifications = [];
this.entsRallyPointsDisplayed = [];
};
/*
@ -664,7 +665,10 @@ GuiInterface.prototype.GetTechnologyData = function(player, name)
"specific": specific,
"generic": template.genericName,
};
ret.icon = "technologies/" + template.icon;
if (template.icon)
ret.icon = "technologies/" + template.icon;
else
ret.icon = null;
ret.cost = {
"food": template.cost ? (+template.cost.food) : 0,
"wood": template.cost ? (+template.cost.wood) : 0,

View file

@ -364,7 +364,7 @@ Player.prototype.SetDiplomacyIndex = function(idx, value)
if (this.teamsLocked)
{
// but can't stab your team members in the back
if (this.team == -1 || cmpPlayer && this.team != cmpPlayer.GetTeam())
if (this.team == -1 || this.team != cmpPlayer.GetTeam())
{
// Break alliance or declare war
if (Math.min(this.diplomacy[idx],cmpPlayer.diplomacy[this.playerID]) > value)

View file

@ -11,8 +11,20 @@ PlayerManager.prototype.Init = function()
PlayerManager.prototype.AddPlayer = function(ent)
{
var id = this.playerEntities.length;
Engine.QueryInterface(ent, IID_Player).SetPlayerID(id);
var cmpPlayer = Engine.QueryInterface(ent, IID_Player)
cmpPlayer.SetPlayerID(id);
this.playerEntities.push(ent);
// initialize / update the diplomacy arrays
var newDiplo = [];
for (var i = 0; i < id; i++)
{
var cmpOtherPlayer = Engine.QueryInterface(this.GetPlayerByID(i), IID_Player);
cmpOtherPlayer.diplomacy[id] = -1;
newDiplo[i] = -1;
}
newDiplo[id] = 1;
cmpPlayer.SetDiplomacy(newDiplo);
return id;
};

View file

@ -108,7 +108,7 @@ ProductionQueue.prototype.CalculateEntitiesList = function()
var upgradeTemplate = function(templateName)
{
var template = cmpTemplateManager.GetTemplate(templateName);
while (template.Promotion)
while (template.Promotion !== undefined)
{
var requiredXp = ApplyValueModificationsToTemplate("Promotion/RequiredXp", +template.Promotion.RequiredXp, playerID, template);
if (requiredXp > 0)

View file

@ -121,7 +121,7 @@ TechnologyManager.prototype.CanResearch = function (tech)
if (this.IsInProgress(tech))
return false;
return this.CheckTechnologyRequirements(template.requirements);
return this.CheckTechnologyRequirements(template.requirements || null);
};
// Private function for checking a set of requirements is met

View file

@ -97,7 +97,6 @@ function LoadPlayerSettings(settings, newPlayers)
else
{
// Init diplomacy
cmpPlayer.SetDiplomacy(new Array(numPlayers));
var myTeam = getSetting(pData, pDefs, "Team");
// Set all but self as enemies as SetTeam takes care of allies