QTfrontend/team.h
author unc0rr
Mon, 26 Nov 2012 00:06:42 +0400
branchflibqtfrontend
changeset 8106 861d145b270e
parent 8103 c247346d296f
child 8363 0b4ac686fc44
permissions -rw-r--r--
Oops, temporary objects involved
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 486
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6952
7f70f37bbf08 license header year range adjustments
sheepluva
parents: 6700
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 352
diff changeset
     4
 * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    19
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    20
#ifndef TEAM_H
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    21
#define TEAM_H
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    22
207
287077789132 coosing colors added
displacer
parents: 184
diff changeset
    23
#include <QColor>
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    24
#include <QString>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    25
#include "binds.h"
3344
b18a166e6ca4 Frontend:
smxx
parents: 3236
diff changeset
    26
#include "achievements.h"
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    27
#include "hwconsts.h"
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7131
diff changeset
    28
#include "frontlib.h"
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    29
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    30
class HWForm;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    31
class GameUIConfig;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    32
314
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    33
class HWTeamConstructException
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    34
{
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    35
};
83773ccf4f09 client/server net pre-alpha
displacer
parents: 312
diff changeset
    36
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    37
// class representing a team
6223
cc3eb9b7230f 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.
unc0rr
parents: 6024
diff changeset
    38
class HWTeam : public QObject
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    39
{
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    40
        Q_OBJECT
6223
cc3eb9b7230f 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.
unc0rr
parents: 6024
diff changeset
    41
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2747
diff changeset
    42
    public:
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    43
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    44
        // constructors
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    45
        HWTeam(const QString & teamname = QString("Team"), QObject * parent = 0);
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    46
        HWTeam(const QStringList& strLst, QObject * parent = 0);
6225
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
    47
        HWTeam(const HWTeam & other);
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7131
diff changeset
    48
        ~HWTeam();
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    49
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    50
        // file operations
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    51
        static HWTeam loadFromFile(const QString & teamName);
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    52
        bool loadFromFile();
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    53
        bool deleteFile();
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    54
        bool saveToFile();
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    55
        bool fileExists();
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    56
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    57
        // attribute getters
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    58
        unsigned int campaignProgress() const;
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6952
diff changeset
    59
        int color() const;
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6952
diff changeset
    60
        QColor qcolor() const;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    61
        unsigned int difficulty() const;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    62
        QString flag() const;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    63
        QString fort() const;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    64
        QString grave() const;
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    65
        //const HWHog & hedgehog(unsigned int idx) const;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    66
        bool isNetTeam() const;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    67
        QString keyBind(unsigned int idx) const;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    68
        QString name() const;
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    69
        unsigned char numHedgehogs() const;
6616
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    70
        QString owner() const;
f77bb02b669f astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents: 6225
diff changeset
    71
        QString voicepack() const;
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 348
diff changeset
    72
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    73
        // attribute setters
6024
d38da7c19e43 some more cleanups and refactoring.
sheepluva
parents: 6015
diff changeset
    74
        void bindKey(unsigned int idx, const QString & key);
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    75
        void setDifficulty(unsigned int level);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    76
        void setFlag(const QString & flag);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    77
        void setFort(const QString & fort);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    78
        void setGrave(const QString & grave);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    79
        void setName(const QString & name);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    80
        void setNumHedgehogs(unsigned char num);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    81
        void setVoicepack(const QString & voicepack);
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    82
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    83
        QString hedgehogName(int index) const;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    84
        QString hedgehogHat(int index) const;
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    85
        void setHedgehogName(int index, const QString & name);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    86
        void setHedgehogHat(int index, const QString & hat);
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
    87
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    88
        // increments for statistical info
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    89
        void incRounds();
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    90
        void incWins();
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    91
8106
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    92
        flib_team * toFlibTeam();
861d145b270e Oops, temporary objects involved
unc0rr
parents: 8103
diff changeset
    93
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    94
        // comparison operators
6225
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
    95
        bool operator == (const HWTeam& t1) const;
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
    96
        bool operator < (const HWTeam& t1) const;
505643d4c23d disconnect when going back from lobby page (regression fix)
sheepluva
parents: 6223
diff changeset
    97
        HWTeam & operator = (const HWTeam & other);
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
    98
7130
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6952
diff changeset
    99
public slots:
fcab1fd02bc6 - Allow switching colors with mouse wheel
unc0rr
parents: 6952
diff changeset
   100
        void setColor(int color);
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
   101
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
   102
    private:
8103
c247346d296f Convert HWTeam to be a wrapper to flib_team
unc0rr
parents: 8100
diff changeset
   103
        QString m_oldTeamName;
6015
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
   104
daffc14a518a cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents: 4976
diff changeset
   105
        // class members that contain the general team info and settings
8100
0e6fadf81a2c - frontlib loads team config via physfs
unc0rr
parents: 7131
diff changeset
   106
        flib_team * m_team;
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   107
};
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   108
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   109
#endif