author | unc0rr |
Sun, 16 Dec 2012 12:05:32 +0400 | |
branch | flibqtfrontend |
changeset 8282 | 1f81bcce3ee6 |
parent 8133 | 2d0f56423eb3 |
child 8363 | 0b4ac686fc44 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6952 | 3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QFile> |
|
20 |
#include <QTextStream> |
|
471 | 21 |
#include <QStringList> |
22 |
#include <QLineEdit> |
|
2874
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2833
diff
changeset
|
23 |
#include <QCryptographicHash> |
3333 | 24 |
#include <QSettings> |
7130 | 25 |
#include <QStandardItemModel> |
8100 | 26 |
#include <QDebug> |
5252 | 27 |
|
184 | 28 |
#include "team.h" |
29 |
#include "hwform.h" |
|
7258 | 30 |
#include "DataManager.h" |
314 | 31 |
|
8103 | 32 |
HWTeam::HWTeam(const QString & teamname, QObject *parent) : |
33 |
QObject(parent) |
|
184 | 34 |
{ |
8106 | 35 |
QList<QByteArray> baList; |
36 |
||
8103 | 37 |
flib_team team; |
8133 | 38 |
memset(&team, 0, sizeof(team)); |
8106 | 39 |
baList << teamname.toUtf8(); |
40 |
team.name = baList.last().data(); |
|
8133 | 41 |
team.grave = const_cast<char *>("Statue"); |
42 |
team.fort = const_cast<char *>("Plane"); |
|
43 |
team.voicepack = const_cast<char *>("Default"); |
|
44 |
team.flag = const_cast<char *>("hedgewars"); |
|
8103 | 45 |
|
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:
5907
diff
changeset
|
46 |
for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
47 |
{ |
8106 | 48 |
baList << QLineEdit::tr("hedgehog %1").arg(i+1).toUtf8(); |
49 |
team.hogs[i].name = baList.last().data(); |
|
8133 | 50 |
team.hogs[i].hat = const_cast<char *>("NoHat"); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
51 |
} |
8103 | 52 |
|
53 |
m_oldTeamName = teamname; |
|
54 |
||
55 |
QVector<flib_binding> binds(BINDS_NUMBER); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
56 |
for(int i = 0; i < BINDS_NUMBER; i++) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
57 |
{ |
8106 | 58 |
baList << cbinds[i].action.toUtf8(); |
59 |
binds[i].action = baList.last().data(); |
|
60 |
baList << cbinds[i].strbind.toUtf8(); |
|
61 |
binds[i].binding = baList.last().data(); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
62 |
} |
8103 | 63 |
team.bindings = binds.data(); |
64 |
team.bindingCount = binds.size(); |
|
65 |
||
8106 | 66 |
m_team = flib_team_copy(&team); |
184 | 67 |
} |
68 |
||
8103 | 69 |
HWTeam::HWTeam(const QStringList& strLst, QObject *parent) : |
70 |
QObject(parent) |
|
314 | 71 |
{ |
8106 | 72 |
QList<QByteArray> baList; |
73 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
74 |
// net teams are configured from QStringList |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
75 |
if(strLst.size() != 23) throw HWTeamConstructException(); |
8103 | 76 |
flib_team team; |
8133 | 77 |
memset(&team, 0, sizeof(team)); |
314 | 78 |
|
8106 | 79 |
for(int i = 0; i < 6; ++i) |
80 |
baList << strLst[i].toUtf8(); |
|
81 |
team.name = baList[0].data(); |
|
8103 | 82 |
m_oldTeamName = strLst[0]; |
8106 | 83 |
team.grave = baList[1].data(); |
84 |
team.fort = baList[2].data(); |
|
85 |
team.voicepack = baList[3].data(); |
|
86 |
team.flag = baList[4].data(); |
|
87 |
team.ownerName = baList[5].data(); |
|
8103 | 88 |
int difficulty = strLst[6].toUInt(); |
314 | 89 |
|
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:
5907
diff
changeset
|
90 |
for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
91 |
{ |
8106 | 92 |
baList << strLst[i * 2 + 7].toUtf8(); |
93 |
team.hogs[i].name = baList.last().data(); |
|
8103 | 94 |
|
95 |
QString hat = strLst[i * 2 + 8]; |
|
96 |
if (hat.isEmpty()) |
|
8133 | 97 |
team.hogs[i].hat = const_cast<char *>("NoHat"); |
8103 | 98 |
else |
8106 | 99 |
{ |
100 |
baList << hat.toUtf8(); |
|
101 |
team.hogs[i].hat = baList.last().data(); |
|
102 |
} |
|
8103 | 103 |
|
104 |
team.hogs[i].difficulty = difficulty; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
105 |
} |
1840 | 106 |
|
8103 | 107 |
m_oldTeamName = strLst[0]; |
1907 | 108 |
|
8103 | 109 |
QVector<flib_binding> binds(BINDS_NUMBER); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
110 |
for(int i = 0; i < BINDS_NUMBER; i++) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
111 |
{ |
8106 | 112 |
baList << cbinds[i].action.toUtf8(); |
113 |
binds[i].action = baList.last().data(); |
|
114 |
baList << cbinds[i].strbind.toUtf8(); |
|
115 |
binds[i].binding = baList.last().data(); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
116 |
} |
8103 | 117 |
team.bindings = binds.data(); |
118 |
team.bindingCount = binds.size(); |
|
119 |
||
120 |
m_team = flib_team_copy(&team); |
|
184 | 121 |
} |
122 |
||
8103 | 123 |
|
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:
6060
diff
changeset
|
124 |
HWTeam::HWTeam(const HWTeam & other) : |
8103 | 125 |
QObject(other.parent()) |
126 |
, m_oldTeamName(other.m_oldTeamName) |
|
8100 | 127 |
, m_team(flib_team_copy(other.m_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:
6060
diff
changeset
|
128 |
{ |
8106 | 129 |
m_team->hogsInGame = other.m_team->hogsInGame; |
130 |
m_team->remoteDriven = other.m_team->remoteDriven; |
|
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:
6060
diff
changeset
|
131 |
} |
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:
6060
diff
changeset
|
132 |
|
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:
6060
diff
changeset
|
133 |
HWTeam & HWTeam::operator = (const HWTeam & other) |
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:
6060
diff
changeset
|
134 |
{ |
6225
505643d4c23d
disconnect when going back from lobby page (regression fix)
sheepluva
parents:
6223
diff
changeset
|
135 |
if(this != &other) |
505643d4c23d
disconnect when going back from lobby page (regression fix)
sheepluva
parents:
6223
diff
changeset
|
136 |
{ |
8103 | 137 |
m_oldTeamName = other.m_oldTeamName; |
138 |
m_team = flib_team_copy(other.m_team); |
|
8106 | 139 |
|
140 |
m_team->hogsInGame = other.m_team->hogsInGame; |
|
141 |
m_team->remoteDriven = other.m_team->remoteDriven; |
|
6225
505643d4c23d
disconnect when going back from lobby page (regression fix)
sheepluva
parents:
6223
diff
changeset
|
142 |
} |
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:
6060
diff
changeset
|
143 |
|
6225
505643d4c23d
disconnect when going back from lobby page (regression fix)
sheepluva
parents:
6223
diff
changeset
|
144 |
return *this; |
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:
6060
diff
changeset
|
145 |
} |
184 | 146 |
|
8100 | 147 |
HWTeam::~HWTeam() |
148 |
{ |
|
149 |
if(m_team) |
|
150 |
flib_team_destroy(m_team); |
|
151 |
} |
|
152 |
||
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:
5907
diff
changeset
|
153 |
bool HWTeam::loadFromFile() |
184 | 154 |
{ |
8103 | 155 |
QString name = QString::fromUtf8(m_team->name); |
156 |
||
8100 | 157 |
if(m_team) |
158 |
flib_team_destroy(m_team); |
|
159 |
||
8126 | 160 |
m_team = flib_team_from_ini(QString("/Teams/%1.hwt").arg(name).toUtf8().data()); |
8100 | 161 |
|
162 |
return m_team != NULL; |
|
184 | 163 |
} |
164 |
||
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:
5907
diff
changeset
|
165 |
bool HWTeam::fileExists() |
3381 | 166 |
{ |
8126 | 167 |
QFile f(QString("physfs://Teams/%1.hwt").arg(name())); |
3381 | 168 |
return f.exists(); |
169 |
} |
|
170 |
||
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:
5907
diff
changeset
|
171 |
bool HWTeam::deleteFile() |
3159 | 172 |
{ |
8103 | 173 |
if(m_team->remoteDriven) |
3159 | 174 |
return false; |
8103 | 175 |
|
8126 | 176 |
QFile cfgfile(QString("physfs://Teams/%1.hwt").arg(name())); |
3159 | 177 |
cfgfile.remove(); |
178 |
return true; |
|
179 |
} |
|
180 |
||
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:
5907
diff
changeset
|
181 |
bool HWTeam::saveToFile() |
184 | 182 |
{ |
8103 | 183 |
if (m_oldTeamName != name()) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
184 |
{ |
8126 | 185 |
QFile cfgfile(QString("physfs://Teams/%1.hwt").arg(m_oldTeamName)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
186 |
cfgfile.remove(); |
8103 | 187 |
m_oldTeamName = name(); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2879
diff
changeset
|
188 |
} |
8098 | 189 |
|
8126 | 190 |
return flib_team_to_ini(QString("physfs://Teams/%1.hwt").arg(name()).toUtf8(), m_team) == 0; |
184 | 191 |
} |
192 |
||
193 |
||
352 | 194 |
bool HWTeam::isNetTeam() const |
195 |
{ |
|
8103 | 196 |
return m_team->remoteDriven; |
352 | 197 |
} |
198 |
||
199 |
||
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
200 |
bool HWTeam::operator==(const HWTeam& t1) const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
201 |
{ |
8103 | 202 |
return qstrcmp(m_team->name, t1.m_team->name) == 0; |
184 | 203 |
} |
204 |
||
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
205 |
bool HWTeam::operator<(const HWTeam& t1) const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
206 |
{ |
8103 | 207 |
return qstrcmp(m_team->name, t1.m_team->name) < 0; // if names are equal - test if it is net team |
184 | 208 |
} |
1840 | 209 |
|
210 |
||
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:
5907
diff
changeset
|
211 |
//// Methods for member inspection+modification //// |
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
212 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
213 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
214 |
// name |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
215 |
QString HWTeam::name() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
216 |
{ |
8103 | 217 |
return QString::fromUtf8(m_team->name); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
218 |
} |
8103 | 219 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
220 |
void HWTeam::setName(const QString & name) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
221 |
{ |
8103 | 222 |
free(m_team->name); |
223 |
||
8130 | 224 |
m_team->name = strdup(name.toUtf8().constData()); |
8103 | 225 |
} |
226 |
||
227 |
QString HWTeam::hedgehogName(int index) const |
|
228 |
{ |
|
229 |
return QString::fromUtf8(m_team->hogs[index].name); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
230 |
} |
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:
5907
diff
changeset
|
231 |
|
8103 | 232 |
QString HWTeam::hedgehogHat(int index) const |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
233 |
{ |
8103 | 234 |
return QString::fromUtf8(m_team->hogs[index].hat); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
235 |
} |
8103 | 236 |
|
237 |
void HWTeam::setHedgehogName(int index, const QString & name) |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
238 |
{ |
8103 | 239 |
free(m_team->hogs[index].name); |
240 |
||
8130 | 241 |
m_team->hogs[index].name = strdup(name.toUtf8().constData()); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
242 |
} |
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:
5907
diff
changeset
|
243 |
|
8103 | 244 |
void HWTeam::setHedgehogHat(int index, const QString & hat) |
245 |
{ |
|
246 |
free(m_team->hogs[index].hat); |
|
247 |
||
8130 | 248 |
m_team->hogs[index].hat = strdup(hat.toUtf8().constData()); |
8103 | 249 |
} |
250 |
||
251 |
||
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:
5907
diff
changeset
|
252 |
// owner |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
253 |
QString HWTeam::owner() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
254 |
{ |
8103 | 255 |
return QString::fromUtf8(m_team->ownerName); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
256 |
} |
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:
5907
diff
changeset
|
257 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
258 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
259 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
260 |
// difficulty |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
261 |
unsigned int HWTeam::difficulty() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
262 |
{ |
8103 | 263 |
return m_team->hogs[0].difficulty; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
264 |
} |
8103 | 265 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
266 |
void HWTeam::setDifficulty(unsigned int level) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
267 |
{ |
8103 | 268 |
for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i) |
269 |
m_team->hogs[i].difficulty = level; |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
270 |
} |
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:
5907
diff
changeset
|
271 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
272 |
// color |
7130 | 273 |
int HWTeam::color() const |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
274 |
{ |
8103 | 275 |
return m_team->colorIndex; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
276 |
} |
7130 | 277 |
|
278 |
QColor HWTeam::qcolor() const |
|
279 |
{ |
|
8103 | 280 |
return DataManager::instance().colorsModel()->item(m_team->colorIndex)->data().value<QColor>(); |
7130 | 281 |
} |
282 |
||
283 |
void HWTeam::setColor(int color) |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
284 |
{ |
8103 | 285 |
m_team->colorIndex = color % DataManager::instance().colorsModel()->rowCount(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
286 |
} |
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:
5907
diff
changeset
|
287 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
288 |
|
6024 | 289 |
// binds |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
290 |
QString HWTeam::keyBind(unsigned int idx) const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
291 |
{ |
8103 | 292 |
return QString::fromUtf8(m_team->bindings[idx].binding); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
293 |
} |
8103 | 294 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
295 |
void HWTeam::bindKey(unsigned int idx, const QString & key) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
296 |
{ |
8103 | 297 |
free(m_team->bindings[idx].binding); |
298 |
||
8130 | 299 |
m_team->bindings[idx].binding = strdup(key.toUtf8().constData()); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
300 |
} |
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:
5907
diff
changeset
|
301 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
302 |
// flag |
8103 | 303 |
void HWTeam::setFlag(const QString & flag) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
304 |
{ |
8103 | 305 |
free(m_team->flag); |
306 |
||
307 |
m_team->flag = strdup(flag.toUtf8().constData()); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
308 |
} |
8103 | 309 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
310 |
QString HWTeam::flag() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
311 |
{ |
8103 | 312 |
return QString::fromUtf8(m_team->flag); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
313 |
} |
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:
5907
diff
changeset
|
314 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
315 |
// fort |
8103 | 316 |
void HWTeam::setFort(const QString & fort) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
317 |
{ |
8103 | 318 |
free(m_team->fort); |
319 |
||
320 |
m_team->fort = strdup(fort.toUtf8().constData()); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
321 |
} |
8103 | 322 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
323 |
QString HWTeam::fort() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
324 |
{ |
8103 | 325 |
return QString::fromUtf8(m_team->fort); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
326 |
} |
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:
5907
diff
changeset
|
327 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
328 |
// grave |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
329 |
void HWTeam::setGrave(const QString & grave) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
330 |
{ |
8103 | 331 |
free(m_team->grave); |
332 |
||
333 |
m_team->grave = strdup(grave.toUtf8().constData()); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
334 |
} |
8103 | 335 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
336 |
QString HWTeam::grave() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
337 |
{ |
8103 | 338 |
return QString::fromUtf8(m_team->grave); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
339 |
} |
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:
5907
diff
changeset
|
340 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
341 |
// voicepack - getter/setter |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
342 |
void HWTeam::setVoicepack(const QString & voicepack) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
343 |
{ |
8103 | 344 |
free(m_team->voicepack); |
345 |
||
346 |
m_team->voicepack = strdup(voicepack.toUtf8().constData()); |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
347 |
} |
8103 | 348 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
349 |
QString HWTeam::voicepack() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
350 |
{ |
8103 | 351 |
return QString::fromUtf8(m_team->voicepack); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
352 |
} |
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:
5907
diff
changeset
|
353 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
354 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
355 |
// campaignProgress - getter |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
356 |
unsigned int HWTeam::campaignProgress() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
357 |
{ |
8103 | 358 |
return m_team->campaignProgress; |
359 |
} |
|
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:
5907
diff
changeset
|
360 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
361 |
// amount of hedgehogs |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
362 |
unsigned char HWTeam::numHedgehogs() const |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
363 |
{ |
8103 | 364 |
return m_team->hogsInGame; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
365 |
} |
8103 | 366 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
367 |
void HWTeam::setNumHedgehogs(unsigned char num) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
368 |
{ |
8103 | 369 |
m_team->hogsInGame = num; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
370 |
} |
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:
5907
diff
changeset
|
371 |
|
daffc14a518a
cleaning up a little bit more, especially team class. we were leaking teams into heap memory on quick game starts btw
sheepluva
parents:
5907
diff
changeset
|
372 |
// rounds+wins - incrementors |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
373 |
void HWTeam::incRounds() |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
374 |
{ |
8103 | 375 |
m_team->rounds++; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
376 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
377 |
void HWTeam::incWins() |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
378 |
{ |
8103 | 379 |
m_team->wins++; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6225
diff
changeset
|
380 |
} |
8106 | 381 |
|
382 |
flib_team * HWTeam::toFlibTeam() |
|
383 |
{ |
|
8130 | 384 |
return flib_team_copy(m_team); |
8106 | 385 |
} |