Prevent frontend from starting game w/ >48 hogs
authorWuzzy <almikes@aol.com>
Mon, 10 Apr 2017 21:42:53 +0200
changeset 12222 a6cd48b8ef61
parent 12221 5b525d041fb4
child 12223 b532cc42ebd4
Prevent frontend from starting game w/ >48 hogs This is because the engine does not support >48 hogs (another bug), but at least this commit a common crash with useless/confusing error message.
ChangeLog.txt
QTfrontend/hwform.cpp
QTfrontend/ui/widget/teamselect.cpp
QTfrontend/ui/widget/teamselect.h
--- a/ChangeLog.txt	Mon Apr 10 20:56:01 2017 +0200
+++ b/ChangeLog.txt	Mon Apr 10 21:42:53 2017 +0200
@@ -188,6 +188,7 @@
  * Fixed mostly broken descriptions for multiplayer mission maps
  * Clicking on "New" in weapon scheme editor now creates empty weapon scheme instead of default
  * Fix language names in language list being always in English
+ * Prevent starting game with >48 hogs (because engine doesn't support it yet)
 
 Content Creation:
  + Theme objects can now have more than 1 in-land rect specified. You can specify the amount in theme.cfg by adding another number (and ,) before the first rect
--- a/QTfrontend/hwform.cpp	Mon Apr 10 20:56:01 2017 +0200
+++ b/QTfrontend/hwform.cpp	Mon Apr 10 21:42:53 2017 +0200
@@ -1594,6 +1594,14 @@
 
 void HWForm::StartMPGame()
 {
+    int numHogs = ui.pageMultiplayer->teamsSelect->getNumHedgehogs();
+    /* Don't allow to start game with >48 hogs.
+    TODO: Remove this as soon the engine supports more hogs. */
+    if(numHogs > 48)
+    {
+        MessageDialog::ShowErrorMessage(QMessageBox::tr("Sorry, Hedgewars can't be played with more than 48 hedgehogs. Please try again with fewer hedgehogs.\n\nCurrent number of hedgehogs: %1").arg(numHogs), this);
+        return;
+    }
     QString ammo;
     ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData(
                ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex()
--- a/QTfrontend/ui/widget/teamselect.cpp	Mon Apr 10 20:56:01 2017 +0200
+++ b/QTfrontend/ui/widget/teamselect.cpp	Mon Apr 10 21:42:53 2017 +0200
@@ -310,6 +310,17 @@
     return m_curNotPlayingTeams;
 }
 
+unsigned short TeamSelWidget::getNumHedgehogs() const
+{
+    unsigned short numHogs = 0;
+    QList<HWTeam>::const_iterator team;
+    for(team = curPlayingTeams.begin(); team != curPlayingTeams.end(); ++team)
+    {
+        numHogs += (*team).numHedgehogs();
+    }
+    return numHogs;
+}
+
 void TeamSelWidget::pre_changeTeamStatus(const HWTeam & team)
 {
     //team.setColor(framePlaying->getNextColor());
--- a/QTfrontend/ui/widget/teamselect.h	Mon Apr 10 20:56:01 2017 +0200
+++ b/QTfrontend/ui/widget/teamselect.h	Mon Apr 10 21:42:53 2017 +0200
@@ -47,6 +47,7 @@
         bool isPlaying(const HWTeam &team) const;
         QList<HWTeam> getPlayingTeams() const;
         QList<HWTeam> getNotPlayingTeams() const;
+	unsigned short getNumHedgehogs() const;
         void setInteractivity(bool interactive);
 
     public slots: