Frontend:
authorsmxx
Fri, 16 Apr 2010 12:38:31 +0000
changeset 3344 b18a166e6ca4
parent 3343 6289df7747c0
child 3345 25ad24233e77
Frontend: * Added missing default binds for alternative camera movement (Numpad 2, 4, 6 and 8) * Added new hedgehog structure to teams and added loading/saving of basic stats * Added loading/saving of local achievements to teams (wip; might change/get dropped)
QTfrontend/CMakeLists.txt
QTfrontend/achievements.cpp
QTfrontend/achievements.h
QTfrontend/binds.cpp
QTfrontend/game.cpp
QTfrontend/namegen.cpp
QTfrontend/newnetclient.cpp
QTfrontend/team.cpp
QTfrontend/team.h
project_files/hedgewars.pro
--- a/QTfrontend/CMakeLists.txt	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/CMakeLists.txt	Fri Apr 16 12:38:31 2010 +0000
@@ -87,6 +87,7 @@
 	ammoSchemeModel.cpp
 	togglebutton.cpp
 	bgwidget.cpp
+	achievements.cpp
 	)
 
 #xfire integration
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/achievements.cpp	Fri Apr 16 12:38:31 2010 +0000
@@ -0,0 +1,30 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2005-2010 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <QObject>
+
+#include "achievements.h"
+
+const char achievements[][5][256] = {
+    // 5 array members each: id, caption, description, image, required number
+    //{"rounds1", QT_TRANSLATE_NOOP("achievements", "No complete Newbie!"),  QT_TRANSLATE_NOOP("achievements", "Manage to survive %1 games playing on the official server, no matter if it's a draw or win."), "nonewb",     1},
+    //{"rounds2", QT_TRANSLATE_NOOP("achievements", "Getting used to it!"),  QT_TRANSLATE_NOOP("achievements", "Manage to survive %1 games playing on the official server, no matter if it's a draw or win."), "getused",   25},
+    //{"rounds3", QT_TRANSLATE_NOOP("achievements", "Backyard Veteran"),     QT_TRANSLATE_NOOP("achievements", "Manage to survive %1 games playing on the official server, no matter if it's a draw or win."), "veteran",  100},
+    //{"rounds4", QT_TRANSLATE_NOOP("achievements", "1001 Stories to tell"), QT_TRANSLATE_NOOP("achievements", "Manage to survive %1 games playing on the official server, no matter if it's a draw or win."), "stories", 1001},
+    {0, 0, 0, 0, 0} // "terminator" line
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/achievements.h	Fri Apr 16 12:38:31 2010 +0000
@@ -0,0 +1,25 @@
+/*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2005-2010 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef ACHIEVEMENTS_H
+#define ACHIEVEMENTS_H
+
+#define MAX_ACHIEVEMENTS 128
+extern const char achievements[][5][256];
+
+#endif // ACHIEVEMENTS_H
--- a/QTfrontend/binds.cpp	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/binds.cpp	Fri Apr 16 12:38:31 2010 +0000
@@ -46,10 +46,10 @@
     {"timer 4", "4",    QT_TRANSLATE_NOOP("binds", "timer 4 sec"),  NULL, NULL},
     {"timer 5", "5",    QT_TRANSLATE_NOOP("binds", "timer 5 sec"),  NULL, NULL},
     {"findhh",  "h",    QT_TRANSLATE_NOOP("binds", "find hedgehog"),    QT_TRANSLATE_NOOP("binds (categories)", "Camera and cursor controls"), QT_TRANSLATE_NOOP("binds (descriptions)", "Move the camera to the active hog:")},
-    {"+cur_u",  "", QT_TRANSLATE_NOOP("binds", "up"),   NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Move the cursor or camera without using the mouse:")},
-    {"+cur_l",  "", QT_TRANSLATE_NOOP("binds", "left"), NULL, NULL},
-    {"+cur_r",  "", QT_TRANSLATE_NOOP("binds", "right"),    NULL, NULL},
-    {"+cur_d",  "", QT_TRANSLATE_NOOP("binds", "down"), NULL, NULL},
+    {"+cur_u",  "[8]", QT_TRANSLATE_NOOP("binds", "up"),   NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Move the cursor or camera without using the mouse:")},
+    {"+cur_l",  "[4]", QT_TRANSLATE_NOOP("binds", "left"), NULL, NULL},
+    {"+cur_r",  "[6]", QT_TRANSLATE_NOOP("binds", "right"),    NULL, NULL},
+    {"+cur_d",  "[2]", QT_TRANSLATE_NOOP("binds", "down"), NULL, NULL},
 //  {"+cur_m",  "", QT_TRANSLATE_NOOP("binds", "movement key modifier"),    NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Specify a modifier key to move camera and cursor using your default hog movement keys:")},
     {"zoomin",  "wheeldown",    QT_TRANSLATE_NOOP("binds", "zoom in"),  NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Modify the camera's zoom level:")},
     {"zoomout", "wheelup",  QT_TRANSLATE_NOOP("binds", "zoom out"), NULL, NULL},
--- a/QTfrontend/game.cpp	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/game.cpp	Fri Apr 16 12:38:31 2010 +0000
@@ -124,7 +124,7 @@
     team2->numHedgehogs = 4;
 	do
         namegen.TeamRandomNames(team2,TRUE);
-	while(!team2->TeamName.compare(team1->TeamName) || !team2->HHHat[0].compare(team1->HHHat[0]));
+	while(!team2->TeamName.compare(team1->TeamName) || !team2->Hedgehogs[0].Hat.compare(team1->Hedgehogs[0].Hat));
     HWProto::addStringListToBuffer(teamscfg,
             team2->TeamGameConfig(100));
 
--- a/QTfrontend/namegen.cpp	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/namegen.cpp	Fri Apr 16 12:38:31 2010 +0000
@@ -62,7 +62,7 @@
         for(int i = 0; i < 8; i++)
         {
             if ((TypesHatnames[kind].size()) > 0){
-                team->HHHat[i] = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
+                team->Hedgehogs[i].Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())];
             }
             RandomNameByHat(team,i);
         }
@@ -75,12 +75,12 @@
 void HWNamegen::RandomNameByHat(HWTeam*& team, const int &i)
 {
     QStringList Dictionaries;
-    HatCfgLoad(team->HHHat[i],Dictionaries);
+    HatCfgLoad(team->Hedgehogs[i].Hat,Dictionaries);
 
     QStringList Dictionary;
     DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary);
 
-    team->HHName[i] = Dictionary[rand()%(Dictionary.size())];
+    team->Hedgehogs[i].Name = Dictionary[rand()%(Dictionary.size())];
 }
 
 void HWNamegen::DictLoad(const QString filename, QStringList &list)
--- a/QTfrontend/newnetclient.cpp	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/newnetclient.cpp	Fri Apr 16 12:38:31 2010 +0000
@@ -122,9 +122,9 @@
     for(int i = 0; i < 8; ++i)
     {
         cmd.append(delimeter);
-        cmd.append(team.HHName[i]);
+        cmd.append(team.Hedgehogs[i].Name);
         cmd.append(delimeter);
-        cmd.append(team.HHHat[i]);
+        cmd.append(team.Hedgehogs[i].Hat);
     }
     RawSendNet(cmd);
 }
--- a/QTfrontend/team.cpp	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/team.cpp	Fri Apr 16 12:38:31 2010 +0000
@@ -38,8 +38,8 @@
     OldTeamName = TeamName;
     for (int i = 0; i < 8; i++)
     {
-        HHName[i].sprintf("hedgehog %d", i);
-        HHHat[i] = "NoHat";
+        Hedgehogs[i].Name.sprintf("hedgehog %d", i);
+        Hedgehogs[i].Hat = "NoHat";
     }
     Grave = "Statue";
     Fort = "Plane";
@@ -67,11 +67,11 @@
     difficulty = strLst[6].toUInt();
     for(int i = 0; i < 8; i++)
     {
-        HHName[i]=strLst[i * 2 + 7];
-        HHHat[i]=strLst[i * 2 + 8];
+        Hedgehogs[i].Name=strLst[i * 2 + 7];
+        Hedgehogs[i].Hat=strLst[i * 2 + 8];
 // Somehow claymore managed an empty hat.  Until we figure out how, this should avoid a repeat
 // Checking net teams is probably pointless, but can't hurt.
-        if (HHHat[i].length() == 0) HHHat[i] = "NoHat"; 
+        if (Hedgehogs[i].Hat.length() == 0) Hedgehogs[i].Hat = "NoHat"; 
     }
 }
 
@@ -83,8 +83,8 @@
     TeamName = QString("Team");
     for (int i = 0; i < 8; i++)
     {
-        HHName[i].sprintf("hedgehog %d", i);
-        HHHat[i] = "NoHat";
+        Hedgehogs[i].Name.sprintf("hedgehog %d", i);
+        Hedgehogs[i].Hat = "NoHat";
     }
 
     Grave = QString("Simple"); // default
@@ -113,15 +113,20 @@
     for(int i = 0; i < 8; i++)
     {
         QString hh = QString("Hedgehog%1/").arg(i);
-        HHName[i] = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i)).toString();
-        HHHat[i] = teamfile.value(hh + "Hat", "NoHat").toString();
-        //teamfile.setValue(hh + "Kills", 0);
-        //teamfile.setValue(hh + "Deaths", 0);
-        //teamfile.setValue(hh + "Rounds", 0);
-        //teamfile.setValue(hh + "Suicides", 0);
+        Hedgehogs[i].Name = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i)).toString();
+        Hedgehogs[i].Hat = teamfile.value(hh + "Hat", "NoHat").toString();
+        Hedgehogs[i].Rounds = teamfile.value(hh + "Rounds", 0).toInt();
+        Hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt();
+        Hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt();
+        Hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt();
     }
     for(int i = 0; i < BINDS_NUMBER; i++)
         binds[i].action = teamfile.value(QString("Binds/%1").arg(binds[i].strbind), cbinds[i].action).toString();
+    for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
+        if(achievements[i][0][0])
+            AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
+        else
+            break;
     return true;
 }
 
@@ -153,15 +158,20 @@
     for(int i = 0; i < 8; i++)
     {
         QString hh = QString("Hedgehog%1/").arg(i);
-        teamfile.setValue(hh + "Name", HHName[i]);
-        teamfile.setValue(hh + "Hat", HHHat[i]);
-        teamfile.setValue(hh + "Kills", 0);
-        teamfile.setValue(hh + "Deaths", 0);
-        teamfile.setValue(hh + "Rounds", 0);
-        teamfile.setValue(hh + "Suicides", 0);
+        teamfile.setValue(hh + "Name", Hedgehogs[i].Name);
+        teamfile.setValue(hh + "Hat", Hedgehogs[i].Hat);
+        teamfile.setValue(hh + "Rounds", Hedgehogs[i].Rounds);
+        teamfile.setValue(hh + "Kills", Hedgehogs[i].Kills);
+        teamfile.setValue(hh + "Deaths", Hedgehogs[i].Deaths);
+        teamfile.setValue(hh + "Suicides", Hedgehogs[i].Suicides);
     }
     for(int i = 0; i < BINDS_NUMBER; i++)
         teamfile.setValue(QString("Binds/%1").arg(binds[i].strbind), binds[i].action);
+    for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
+        if(achievements[i][0][0])
+            teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]);
+        else
+            break;
     return true;
 }
 
@@ -171,11 +181,11 @@
     hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty);
     for(int i = 0; i < 8; i++)
     {
-         hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]);
-         if (HHHat[i].startsWith("Reserved"))
-            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+HHHat[i].remove(0,40), Qt::DisplayRole));
+         hwform->ui.pageEditTeam->HHNameEdit[i]->setText(Hedgehogs[i].Name);
+         if (Hedgehogs[i].Hat.startsWith("Reserved"))
+            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+Hedgehogs[i].Hat.remove(0,40), Qt::DisplayRole));
          else
-            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole));
+            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(Hedgehogs[i].Hat, Qt::DisplayRole));
     }
     hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave));
     hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findText(Flag));
@@ -196,11 +206,11 @@
     difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex();
     for(int i = 0; i < 8; i++)
     {
-        HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
+        Hedgehogs[i].Name = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
         if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved"))
-            HHHat[i] = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9);
+            Hedgehogs[i].Hat = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9);
         else
-            HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText();
+            Hedgehogs[i].Hat = hwform->ui.pageEditTeam->HHHats[i]->currentText();
     }
 
     Grave = hwform->ui.pageEditTeam->CBGrave->currentText();
@@ -238,9 +248,9 @@
       sl.push_back(QString("eaddhh %1 %2 %3")
                .arg(QString::number(difficulty),
                 QString::number(InitHealth),
-                HHName[t]));
+                Hedgehogs[t].Name));
       sl.push_back(QString("ehat %1")
-               .arg(HHHat[t]));
+               .arg(Hedgehogs[t].Hat));
     }
     return sl;
 }
--- a/QTfrontend/team.h	Fri Apr 16 00:02:30 2010 +0000
+++ b/QTfrontend/team.h	Fri Apr 16 12:38:31 2010 +0000
@@ -23,6 +23,7 @@
 #include <QColor>
 #include <QString>
 #include "binds.h"
+#include "achievements.h"
 
 class HWForm;
 class GameUIConfig;
@@ -31,6 +32,13 @@
 {
 };
 
+struct HWHog
+{
+    QString Name;
+    QString Hat;
+    int Rounds, Kills, Deaths, Suicides;
+};
+
 class HWTeam
 {
     public:
@@ -41,13 +49,13 @@
         bool isNetTeam() const;
 
         QString TeamName;
-        QString HHName[8];
-        QString HHHat[8];
         QString Grave;
         QString Fort;
         QString Flag;
         QString Voicepack;
         QString Owner;
+        HWHog Hedgehogs[8];
+        unsigned int AchievementProgress[MAX_ACHIEVEMENTS];
         unsigned int difficulty;
         BindAction binds[BINDS_NUMBER];
 
--- a/project_files/hedgewars.pro	Fri Apr 16 00:02:30 2010 +0000
+++ b/project_files/hedgewars.pro	Fri Apr 16 12:38:31 2010 +0000
@@ -32,7 +32,8 @@
 	../QTfrontend/team.h ../QTfrontend/teamselect.h \
 	../QTfrontend/teamselhelper.h ../QTfrontend/togglebutton.h \
 	../QTfrontend/ui_hwform.h ../QTfrontend/vertScrollArea.h \
-	../QTfrontend/weaponItem.h ../QTfrontend/xfire.h
+	../QTfrontend/weaponItem.h ../QTfrontend/xfire.h \
+	../QTfrontend/achievements.h
 
 SOURCES += ../QTfrontend/SDLs.cpp ../QTfrontend/SquareLabel.cpp \
 	../QTfrontend/about.cpp ../QTfrontend/ammoSchemeModel.cpp \
@@ -55,6 +56,7 @@
 	../QTfrontend/teamselect.cpp ../QTfrontend/teamselhelper.cpp \
 	../QTfrontend/togglebutton.cpp ../QTfrontend/ui_hwform.cpp \
 	../QTfrontend/vertScrollArea.cpp ../QTfrontend/weaponItem.cpp \
+	../QTfrontend/achievements.cpp
 
 win32 {
 SOURCES += ../QTfrontend/xfire.cpp