Skip to content

Commit

Permalink
Fix ticket:2766 - failure to end game when victorious in teams. Also …
Browse files Browse the repository at this point in the history
…fix failure to end in loss.
  • Loading branch information
perim committed Jun 5, 2011
1 parent 3df67f1 commit 7842a7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
29 changes: 9 additions & 20 deletions data/base/multiplay/skirmish/rules.js
Expand Up @@ -129,19 +129,11 @@ function eventGameInit()
// END CONDITIONS
function checkEndConditions()
{
// Only read in data for players we check (speed optimization)
var factories = new Array(maxPlayers);
var droids = new Array(maxPlayers);
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
factories[playnum] = -1;
droids[playnum] = -1;
}
factories[me] = enumStruct(me, "A0LightFactory").length + enumStruct(me, "A0CyborgFactory").length;
droids[me] = enumDroid(me).length;
var factories = enumStruct(me, "A0LightFactory").length + enumStruct(me, "A0CyborgFactory").length;
var droids = enumDroid(me).length;

// Losing Conditions
if (droids[me] == 0 && factories[me] == 0)
if (droids == 0 && factories == 0)
{
var gameLost = true;

Expand All @@ -152,9 +144,9 @@ function checkEndConditions()
{
if (playnum != me && allianceExistsBetween(me, playnum))
{
factories[playnum] = enumStruct(playnum, factory).length + enumStruct(me, "A0CyborgFactory").length;
droids[playnum] = enumDroid("A0LightFactory").length;
if (droids[playnum] > 0 || factories[playnum] > 0)
factories = enumStruct(playnum, "A0LightFactory").length + enumStruct(playnum, "A0CyborgFactory").length;
droids = enumDroid(playnum).length;
if (droids > 0 || factories > 0)
{
gameLost = false; // someone from our team still alive
break;
Expand All @@ -179,12 +171,9 @@ function checkEndConditions()
{
if (playnum != me && !allianceExistsBetween(me, playnum)) // checking enemy player
{
if (factories[playnum] == -1) // cached count?
{
factories[playnum] = enumStruct(playnum, "A0LightFactory").length + enumStruct(me, "A0CyborgFactory").length; // nope
droids[playnum] = enumDroid(playnum).length;
}
if (droids[playnum] > 0 || factories[playnum] > 0)
factories = enumStruct(playnum, "A0LightFactory").length + enumStruct(playnum, "A0CyborgFactory").length; // nope
droids = enumDroid(playnum).length;
if (droids > 0 || factories > 0)
{
gamewon = false; //one of the enemies still alive
break;
Expand Down
3 changes: 3 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -715,6 +715,9 @@ bool registerFunctions(QScriptEngine *engine)
engine->globalObject().setProperty("CAMP_CLEAN", CAMP_CLEAN, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CAMP_BASE", CAMP_BASE, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CAMP_WALLS", CAMP_WALLS, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("NO_ALLIANCES", NO_ALLIANCES, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("ALLIANCES", ALLIANCES, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("ALLIANCES_TEAMS", ALLIANCES_TEAMS, QScriptValue::ReadOnly | QScriptValue::Undeletable);

return true;
}
3 changes: 3 additions & 0 deletions tests/lint.cpp
Expand Up @@ -606,6 +606,9 @@ bool testPlayerScript(QString path, int player, int difficulty)
engine->globalObject().setProperty("CAMP_CLEAN", CAMP_CLEAN, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CAMP_BASE", CAMP_BASE, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CAMP_WALLS", CAMP_WALLS, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("NO_ALLIANCES", NO_ALLIANCES, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("ALLIANCES", ALLIANCES, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("ALLIANCES_TEAMS", ALLIANCES_TEAMS, QScriptValue::ReadOnly | QScriptValue::Undeletable);

// Call init
callFunction(engine, "eventGameInit", QScriptValueList());
Expand Down

0 comments on commit 7842a7d

Please sign in to comment.