forked from 0ad/0ad
fix tests + code style cleanup
This was SVN commit r14426.
This commit is contained in:
parent
433293c7b2
commit
cd125a94e2
@ -2192,22 +2192,22 @@ function removeGuard()
|
||||
|
||||
function increaseAlertLevel()
|
||||
{
|
||||
var raisers = g_Selection.toList().filter(function(e) {
|
||||
var entities = g_Selection.toList().filter(function(e) {
|
||||
var state = GetEntityState(e);
|
||||
return (state && state.alertRaiser && state.alertRaiser.canIncreaseLevel);
|
||||
});
|
||||
|
||||
Engine.PostNetworkCommand({"type": "increase-alert-level", "entities": raisers});
|
||||
Engine.PostNetworkCommand({"type": "increase-alert-level", "entities": entities});
|
||||
}
|
||||
|
||||
function endOfAlert()
|
||||
{
|
||||
var raisers = g_Selection.toList().filter(function(e) {
|
||||
var entities = g_Selection.toList().filter(function(e) {
|
||||
var state = GetEntityState(e);
|
||||
return (state && state.alertRaiser && state.alertRaiser.hasRaisedAlert);
|
||||
});
|
||||
|
||||
Engine.PostNetworkCommand({"type": "alert-end", "entities": raisers});
|
||||
Engine.PostNetworkCommand({"type": "alert-end", "entities": entities});
|
||||
}
|
||||
|
||||
function clearSelection()
|
||||
|
@ -24,6 +24,7 @@ EndGameManager.prototype.Init = function()
|
||||
EndGameManager.prototype.SetGameType = function(newGameType)
|
||||
{
|
||||
this.gameType = newGameType;
|
||||
warn(this.gameType);
|
||||
Engine.BroadcastMessage(MT_GameTypeChanged, {});
|
||||
};
|
||||
|
||||
@ -32,14 +33,8 @@ EndGameManager.prototype.CheckGameType = function(type)
|
||||
return this.gameType == type;
|
||||
};
|
||||
|
||||
EndGameManager.prototype.RegisterWonder = function(entity)
|
||||
EndGameManager.prototype.MarkPlayerAsWon = function(playerID)
|
||||
{
|
||||
if (!this.CheckGameType("wonder"))
|
||||
return;
|
||||
|
||||
var cmpWon = QueryOwnerInterface(entity, IID_Player);
|
||||
cmpWon.SetState("won");
|
||||
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
var numPlayers = cmpPlayerManager.GetNumPlayers();
|
||||
for (var i = 1; i < numPlayers; i++)
|
||||
@ -48,7 +43,7 @@ EndGameManager.prototype.RegisterWonder = function(entity)
|
||||
var cmpPlayer = Engine.QueryInterface(playerEntityId, IID_Player);
|
||||
if (cmpPlayer.GetState() != "active")
|
||||
continue;
|
||||
if (this.alliedVictory && cmpPlayer.IsMutualAlly(cmpWon.GetPlayerID()))
|
||||
if (playerID == cmpPlayer.GetPlayerID() || this.alliedVictory && cmpPlayer.IsMutualAlly(playerID))
|
||||
cmpPlayer.SetState("won")
|
||||
else
|
||||
Engine.PostMessage(playerEntityId, MT_PlayerDefeated, { "playerId": i } );
|
||||
@ -67,19 +62,19 @@ EndGameManager.prototype.SetAlliedVictory = function(flag)
|
||||
/*
|
||||
* Check players the next turn. Avoids problems in Atlas, with promoting entities etc
|
||||
*/
|
||||
EndGameManager.prototype.CheckPlayers = function()
|
||||
EndGameManager.prototype.CheckConquestCriticalEntities = 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);
|
||||
this.timeout = cmpTimer.SetTimeout(this.entity, IID_EndGameManager, "CheckConquestCriticalEntitiesNow", 100, null);
|
||||
};
|
||||
|
||||
/*
|
||||
* Check players immediately. Might cause problems with converting/promoting entities.
|
||||
*/
|
||||
EndGameManager.prototype.CheckPlayersNow = function()
|
||||
EndGameManager.prototype.CheckConquestCriticalEntitiesNow = function()
|
||||
{
|
||||
if (this.timeout)
|
||||
this.timeout = null;
|
||||
|
@ -289,7 +289,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
|
||||
}
|
||||
|
||||
var cmpAlertRaiser = Engine.QueryInterface(ent, IID_AlertRaiser);
|
||||
if(cmpAlertRaiser)
|
||||
if (cmpAlertRaiser)
|
||||
{
|
||||
ret.alertRaiser = {
|
||||
"level": cmpAlertRaiser.GetLevel(),
|
||||
|
@ -37,7 +37,7 @@ Player.prototype.Init = function()
|
||||
this.cheatsEnabled = false;
|
||||
this.cheatTimeMultiplier = 1;
|
||||
this.heroes = [];
|
||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).CheckPlayers();
|
||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).CheckConquestCriticalEntities();
|
||||
};
|
||||
|
||||
Player.prototype.SetPlayerID = function(id)
|
||||
|
@ -49,19 +49,17 @@ Wonder.prototype.ResetTimer = function(ownerID)
|
||||
if (i != ownerID)
|
||||
players.push(i);
|
||||
|
||||
this.otherMessage = cmpGuiInterface.AddTimeNotification(
|
||||
{
|
||||
"message": cmpPlayer.GetName() + " will have won in %T",
|
||||
"players": players,
|
||||
"time": +this.template.TimeTillVictory*1000
|
||||
});
|
||||
this.ownMessage = cmpGuiInterface.AddTimeNotification(
|
||||
{
|
||||
"message": "You will have won in %T",
|
||||
"players": [ownerID],
|
||||
"time": +this.template.TimeTillVictory*1000
|
||||
});
|
||||
this.timer = cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_EndGameManager, "RegisterWonder", +this.template.TimeTillVictory*1000, this.entity);
|
||||
this.otherMessage = cmpGuiInterface.AddTimeNotification({
|
||||
"message": cmpPlayer.GetName() + " will have won in %T",
|
||||
"players": players,
|
||||
"time": +this.template.TimeTillVictory*1000
|
||||
});
|
||||
this.ownMessage = cmpGuiInterface.AddTimeNotification({
|
||||
"message": "You will have won in %T",
|
||||
"players": [ownerID],
|
||||
"time": +this.template.TimeTillVictory*1000
|
||||
});
|
||||
this.timer = cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_EndGameManager, "MarkPlayerAsWon", +this.template.TimeTillVictory*1000, ownerID);
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_Wonder, "Wonder", Wonder);
|
||||
|
@ -79,10 +79,16 @@ AddMock(100, IID_Player, {
|
||||
AddMock(100, IID_EntityLimits, {
|
||||
GetLimits: function() { return {"Foo": 10}; },
|
||||
GetCounts: function() { return {"Foo": 5}; },
|
||||
GetLimitChangers: function() {return {"Foo": {}}; }
|
||||
});
|
||||
|
||||
AddMock(100, IID_TechnologyManager, {
|
||||
IsTechnologyResearched: function(tech) { return false; },
|
||||
IsTechnologyResearched: function(tech) { if (tech == "phase_village") return true; else return false; },
|
||||
GetQueuedResearch: function() { return {}; },
|
||||
GetStartedResearch: function() { return {}; },
|
||||
GetResearchedTechs: function() { return {}; },
|
||||
GetClassCounts: function() { return {}; },
|
||||
GetTypeCountsByClass: function() { return {}; },
|
||||
GetTechModifications: function() { return {}; },
|
||||
});
|
||||
|
||||
@ -135,41 +141,9 @@ AddMock(101, IID_Player, {
|
||||
AddMock(101, IID_EntityLimits, {
|
||||
GetLimits: function() { return {"Bar": 20}; },
|
||||
GetCounts: function() { return {"Bar": 0}; },
|
||||
GetLimitChangers: function() {return {"Bar": {}}; }
|
||||
});
|
||||
|
||||
AddMock(100, IID_TechnologyManager, {
|
||||
IsTechnologyResearched: function(tech) { if (tech == "phase_village") return true; else return false; },
|
||||
GetQueuedResearch: function() { return {}; },
|
||||
GetStartedResearch: function() { return {}; },
|
||||
GetResearchedTechs: function() { return {}; },
|
||||
GetClassCounts: function() { return {}; },
|
||||
GetTypeCountsByClass: function() { return {}; },
|
||||
GetTechModifications: function() { return {}; },
|
||||
});
|
||||
AddMock(100, IID_StatisticsTracker, {
|
||||
GetStatistics: function() {
|
||||
return {
|
||||
"unitsTrained": 10,
|
||||
"unitsLost": 9,
|
||||
"buildingsConstructed": 5,
|
||||
"buildingsLost": 4,
|
||||
"civCentresBuilt": 1,
|
||||
"resourcesGathered": {
|
||||
"food": 100,
|
||||
"wood": 0,
|
||||
"metal": 0,
|
||||
"stone": 0,
|
||||
"vegetarianFood": 0,
|
||||
},
|
||||
"treasuresCollected": 0,
|
||||
"percentMapExplored": 10,
|
||||
};
|
||||
},
|
||||
IncreaseTrainedUnitsCounter: function() { return 1; },
|
||||
IncreaseConstructedBuildingsCounter: function() { return 1; },
|
||||
IncreaseBuiltCivCentresCounter: function() { return 1; },
|
||||
});
|
||||
|
||||
AddMock(101, IID_TechnologyManager, {
|
||||
IsTechnologyResearched: function(tech) { if (tech == "phase_village") return true; else return false; },
|
||||
GetQueuedResearch: function() { return {}; },
|
||||
@ -230,6 +204,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
||||
isEnemy: [true, true],
|
||||
entityLimits: {"Foo": 10},
|
||||
entityCounts: {"Foo": 5},
|
||||
entityLimitChangers: {"Foo": {}},
|
||||
techModifications: {},
|
||||
researchQueued: {},
|
||||
researchStarted: {},
|
||||
@ -258,6 +233,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
||||
isEnemy: [false, false],
|
||||
entityLimits: {"Bar": 20},
|
||||
entityCounts: {"Bar": 0},
|
||||
entityLimitChangers: {"Bar": {}},
|
||||
techModifications: {},
|
||||
researchQueued: {},
|
||||
researchStarted: {},
|
||||
@ -293,6 +269,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
||||
isEnemy: [true, true],
|
||||
entityLimits: {"Foo": 10},
|
||||
entityCounts: {"Foo": 5},
|
||||
entityLimitChangers: {"Foo": {}},
|
||||
techModifications: {},
|
||||
researchQueued: {},
|
||||
researchStarted: {},
|
||||
@ -337,6 +314,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
||||
isEnemy: [false, false],
|
||||
entityLimits: {"Bar": 20},
|
||||
entityCounts: {"Bar": 0},
|
||||
entityLimitChangers: {"Bar": {}},
|
||||
techModifications: {},
|
||||
researchQueued: {},
|
||||
researchStarted: {},
|
||||
|
Loading…
Reference in New Issue
Block a user