move (prematurely) finishing game by removing all teams into engine since that's where it should happen
authorsheepluva
Wed, 26 Oct 2011 01:50:08 +0200
changeset 6211 ee9465c0ea82
parent 6210 923c8414e3af
child 6212 a5d95f32e17f
move (prematurely) finishing game by removing all teams into engine since that's where it should happen
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
hedgewars/uTeams.pas
--- a/QTfrontend/game.cpp	Wed Oct 26 01:17:44 2011 +0200
+++ b/QTfrontend/game.cpp	Wed Oct 26 01:50:08 2011 +0200
@@ -390,13 +390,9 @@
     emit GameStateChanged(state);
 }
 
-void HWGame::KillAllTeams()
+void HWGame::abort()
 {
-    if (m_pTeamSelWidget)
-    {
-        QByteArray buf;
-        foreach(HWTeam team, m_pTeamSelWidget->getPlayingTeams())
-            HWProto::addStringToBuffer(buf, QString("eteamgone %1").arg(team.name()));
-        RawSendIPC(buf);
-    }
+    QByteArray buf;
+    HWProto::addStringToBuffer(buf, QString("efinish"));
+    RawSendIPC(buf);
 }
--- a/QTfrontend/game.h	Wed Oct 26 01:17:44 2011 +0200
+++ b/QTfrontend/game.h	Wed Oct 26 01:50:08 2011 +0200
@@ -54,7 +54,7 @@
     void StartNet();
     void StartTraining(const QString & file);
     void StartCampaign(const QString & file);
-    void KillAllTeams();
+    void abort();
     GameState gameState;
     bool netSuspend;
 
--- a/QTfrontend/hwform.cpp	Wed Oct 26 01:17:44 2011 +0200
+++ b/QTfrontend/hwform.cpp	Wed Oct 26 01:50:08 2011 +0200
@@ -482,7 +482,8 @@
     if (id == ID_PAGE_ROOMSLIST) {
         if (hwnet && game && game->gameState == gsStarted) { // abnormal exit - kick or room destruction - send kills.
             game->netSuspend = true;
-            game->KillAllTeams();
+            ui.pageRoomsList->displayWarning(tr("Game aborted"));
+            game->abort();
         }
     }
 
--- a/hedgewars/uTeams.pas	Wed Oct 26 01:17:44 2011 +0200
+++ b/hedgewars/uTeams.pas	Wed Oct 26 01:50:08 2011 +0200
@@ -542,6 +542,23 @@
 end;
 
 
+procedure chFinish(var s:shortstring);
+var t: LongInt;
+begin
+// avoid compiler hint
+s:= s;
+
+t:= 0;
+while (t < cMaxTeams) and (TeamsArray[t] <> nil) do
+    begin
+    TeamsArray[t]^.hasGone:= true;
+    inc(t);
+    end;
+
+AddChatString('** Good-bye!');
+RecountAllTeamsHealth();
+end;
+
 procedure initModule;
 begin
     RegisterVariable('addhh', vtCommand, @chAddHH, false);
@@ -549,6 +566,7 @@
     RegisterVariable('hhcoords', vtCommand, @chSetHHCoords, false);
     RegisterVariable('bind', vtCommand, @chBind, true );
     RegisterVariable('teamgone', vtCommand, @chTeamGone, true );
+    RegisterVariable('finish', vtCommand, @chFinish, true ); // all teams gone
 
     CurrentTeam:= nil;
     PreviousTeam:= nil;