# HG changeset patch
# User unc0rr
# Date 1319815235 -14400
# Node ID cc3eb9b7230fdb041597bd16ee40a0d47d8556a9
# Parent  96d10dcd6d84c531342e5b5f142018f99a2a5fc3
It doesn't make much sense to make checks like 'if(game)' if you never set game to 0. Using smart pointers instead. Does it fix segfaults? Probably.

diff -r 96d10dcd6d84 -r cc3eb9b7230f QTfrontend/CMakeLists.txt
--- a/QTfrontend/CMakeLists.txt	Fri Oct 28 13:10:46 2011 +0200
+++ b/QTfrontend/CMakeLists.txt	Fri Oct 28 19:20:35 2011 +0400
@@ -118,6 +118,7 @@
     gameuiconfig.h
     HWApplication.h
     hwform.h
+    team.h
     )
 
 set(hwfr_hdrs
diff -r 96d10dcd6d84 -r cc3eb9b7230f QTfrontend/hwform.cpp
--- a/QTfrontend/hwform.cpp	Fri Oct 28 13:10:46 2011 +0200
+++ b/QTfrontend/hwform.cpp	Fri Oct 28 19:20:35 2011 +0400
@@ -96,7 +96,12 @@
 QString playerHash;
 
 HWForm::HWForm(QWidget *parent, QString styleSheet)
-  : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
+  : QMainWindow(parent)
+  , game(0)
+  , pnetserver(0)
+  , pRegisterServer(0)
+  , editedTeam(0)
+  , hwnet(0)
 {
     // set music track
     SDLInteraction::instance().setMusicTrack(
@@ -106,7 +111,6 @@
 #ifdef USE_XFIRE
     xfire_init();
 #endif
-    game = NULL;
     gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex());
@@ -1162,7 +1166,7 @@
             ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
             ).toString();
 
-    CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
+	CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
 
     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
diff -r 96d10dcd6d84 -r cc3eb9b7230f QTfrontend/hwform.h
--- a/QTfrontend/hwform.h	Fri Oct 28 13:10:46 2011 +0200
+++ b/QTfrontend/hwform.h	Fri Oct 28 19:20:35 2011 +0400
@@ -22,6 +22,7 @@
 #include <QMainWindow>
 #include <QStack>
 #include <QTime>
+#include <QPointer>
 
 #include "netserver.h"
 #include "game.h"
@@ -156,11 +157,11 @@
         ID_PAGE_DRAWMAP         = 20,
         ID_PAGE_DATADOWNLOAD    = 21
         };
-    HWGame * game;
-    HWNetServer* pnetserver;
-    HWNetRegisterServer* pRegisterServer;
-    HWTeam * editedTeam;
-    HWNewNet * hwnet;
+	QPointer<HWGame> game;
+	QPointer<HWNetServer> pnetserver;
+	QPointer<HWNetRegisterServer> pRegisterServer;
+	QPointer<HWTeam> editedTeam;
+	QPointer<HWNewNet> hwnet;
     HWNamegen * namegen;
     AmmoSchemeModel * ammoSchemeModel;
     QStack<int> PagesStack;
diff -r 96d10dcd6d84 -r cc3eb9b7230f QTfrontend/team.cpp
--- a/QTfrontend/team.cpp	Fri Oct 28 13:10:46 2011 +0200
+++ b/QTfrontend/team.cpp	Fri Oct 28 19:20:35 2011 +0400
@@ -28,9 +28,10 @@
 #include "hats.h"
 
 HWTeam::HWTeam(const QString & teamname) :
-    m_difficulty(0),
-    m_numHedgehogs(4),
-    m_isNetTeam(false)
+	QObject(0)
+	, m_difficulty(0)
+	, m_numHedgehogs(4)
+	, m_isNetTeam(false)
 {
     m_name = teamname;
     OldTeamName = m_name;
@@ -54,8 +55,9 @@
 }
 
 HWTeam::HWTeam(const QStringList& strLst) :
-  m_numHedgehogs(4),
-  m_isNetTeam(true)
+	QObject(0)
+	, m_numHedgehogs(4)
+	, m_isNetTeam(true)
 {
     // net teams are configured from QStringList
     if(strLst.size() != 23) throw HWTeamConstructException();
@@ -80,9 +82,10 @@
 }
 
 HWTeam::HWTeam() :
-  m_difficulty(0),
-  m_numHedgehogs(4),
-  m_isNetTeam(false)
+	QObject(0)
+  , m_difficulty(0)
+  , m_numHedgehogs(4)
+  , m_isNetTeam(false)
 {
     m_name = QString("Team");
     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
@@ -106,6 +109,53 @@
     m_campaignProgress = 0;
 }
 
+HWTeam::HWTeam(const HWTeam & other) :
+		QObject(0)
+		, OldTeamName(other.OldTeamName)
+		, m_name(other.m_name)
+		, m_grave(other.m_grave)
+		, m_fort(other.m_fort)
+		, m_flag(other.m_flag)
+		, m_voicepack(other.m_voicepack)
+		, m_hedgehogs(other.m_hedgehogs)
+		, m_difficulty(other.m_difficulty)
+		, m_binds(other.m_binds)
+		, m_numHedgehogs(other.m_numHedgehogs)
+		, m_color(other.m_color)
+		, m_isNetTeam(other.m_isNetTeam)
+		, m_owner(other.m_owner)
+		, m_campaignProgress(other.m_campaignProgress)
+		, m_rounds(other.m_rounds)
+		, m_wins(other.m_wins)
+//	  , AchievementProgress(other.AchievementProgress)
+{
+
+}
+
+HWTeam & HWTeam::operator = (const HWTeam & other)
+{
+	if(this != &other)
+	{
+		OldTeamName = other.OldTeamName;
+		m_name = other.m_name;
+		m_grave = other.m_grave;
+		m_fort = other.m_fort;
+		m_flag = other.m_flag;
+		m_voicepack = other.m_voicepack;
+//		m_hedgehogs = other.m_hedgehogs;
+		m_difficulty = other.m_difficulty;
+//		m_binds = other.m_binds;
+		m_numHedgehogs = other.m_numHedgehogs;
+		m_color = other.m_color;
+		m_isNetTeam = other.m_isNetTeam;
+		m_owner = other.m_owner;
+		m_campaignProgress = other.m_campaignProgress;
+		m_rounds = other.m_rounds;
+		m_wins = other.m_wins;
+	}
+
+	return *this;
+}
 
 bool HWTeam::loadFromFile()
 {
diff -r 96d10dcd6d84 -r cc3eb9b7230f QTfrontend/team.h
--- a/QTfrontend/team.h	Fri Oct 28 13:10:46 2011 +0200
+++ b/QTfrontend/team.h	Fri Oct 28 19:20:35 2011 +0400
@@ -42,14 +42,17 @@
 };
 
 // class representing a team
-class HWTeam
+class HWTeam : public QObject
 {
+	Q_OBJECT
+
     public:
 
         // constructors
         HWTeam(const QString & teamname);
         HWTeam(const QStringList& strLst);
         HWTeam();
+		HWTeam(const HWTeam & other);
 
         // file operations
         static HWTeam loadFromFile(const QString & teamName);
@@ -93,9 +96,9 @@
         QStringList teamGameConfig(quint32 InitHealth) const;
 
         // comparison operators
-        bool operator==(const HWTeam& t1) const;
-        bool operator<(const HWTeam& t1) const;
-
+		bool operator == (const HWTeam& t1) const;
+		bool operator < (const HWTeam& t1) const;
+		HWTeam & operator = (const HWTeam & other);
 
 
     private:
@@ -109,11 +112,11 @@
         QString m_flag;
         QString m_voicepack;
         HWHog m_hedgehogs[HEDGEHOGS_PER_TEAM];
-        unsigned int m_difficulty;
+		quint8 m_difficulty;
         BindAction m_binds[BINDS_NUMBER];
 
         // class members that contain info for the current game setup
-        unsigned char m_numHedgehogs;
+		quint8 m_numHedgehogs;
         QColor m_color;
         bool m_isNetTeam;
         QString m_owner;
@@ -123,8 +126,6 @@
         unsigned int m_rounds;
         unsigned int m_wins;
         unsigned int AchievementProgress[MAX_ACHIEVEMENTS];
-
-
 };
 
 #endif
diff -r 96d10dcd6d84 -r cc3eb9b7230f project_files/hedgewars.pro
--- a/project_files/hedgewars.pro	Fri Oct 28 13:10:46 2011 +0200
+++ b/project_files/hedgewars.pro	Fri Oct 28 19:20:35 2011 +0400
@@ -93,7 +93,7 @@
     ../QTfrontend/achievements.h \
     ../QTfrontend/binds.h \
     ../QTfrontend/ui_hwform.h \
-    ../QTfrontend/KB.h \
+	../QTfrontend/KB.h \
     ../QTfrontend/hwconsts.h \
     ../QTfrontend/sdlkeys.h