author | unc0rr |
Wed, 03 Mar 2010 06:29:01 +0000 | |
changeset 2918 | 24d6dc579b47 |
parent 2879 | 935ead93893c |
child 2948 | 3f21a9dc93d0 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
1656
209cf0e2fc36
Finish voicepacks support in engine (not tested though)
unc0rr
parents:
1655
diff
changeset
|
3 |
* Copyright (c) 2005-2007, 2009 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> |
|
21 |
#include <QApplication> |
|
471 | 22 |
#include <QStringList> |
23 |
#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
|
24 |
#include <QCryptographicHash> |
184 | 25 |
#include "team.h" |
26 |
#include "hwform.h" |
|
27 |
#include "pages.h" |
|
28 |
#include "hwconsts.h" |
|
1240 | 29 |
#include "hats.h" |
314 | 30 |
|
1325 | 31 |
HWTeam::HWTeam(const QString & teamname) : |
32 |
difficulty(0), |
|
33 |
numHedgehogs(4), |
|
34 |
m_isNetTeam(false) |
|
184 | 35 |
{ |
36 |
TeamName = teamname; |
|
245 | 37 |
OldTeamName = TeamName; |
1240 | 38 |
for (int i = 0; i < 8; i++) |
39 |
{ |
|
40 |
HHName[i].sprintf("hedgehog %d", i); |
|
41 |
HHHat[i] = "NoHat"; |
|
42 |
} |
|
1538
8bc56dd2e997
Set default fort to 'Plane' and default grave to 'Statue'
unc0rr
parents:
1325
diff
changeset
|
43 |
Grave = "Statue"; |
8bc56dd2e997
Set default fort to 'Plane' and default grave to 'Statue'
unc0rr
parents:
1325
diff
changeset
|
44 |
Fort = "Plane"; |
1659 | 45 |
Voicepack = "Default"; |
2747 | 46 |
Flag = "hedgewars"; |
184 | 47 |
for(int i = 0; i < BINDS_NUMBER; i++) |
48 |
{ |
|
49 |
binds[i].action = cbinds[i].action; |
|
50 |
binds[i].strbind = cbinds[i].strbind; |
|
51 |
} |
|
52 |
} |
|
53 |
||
353 | 54 |
HWTeam::HWTeam(const QStringList& strLst) : |
1325 | 55 |
numHedgehogs(4), |
56 |
m_isNetTeam(true) |
|
314 | 57 |
{ |
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
58 |
// net teams are configured from QStringList |
2747 | 59 |
if(strLst.size() != 23) throw HWTeamConstructException(); |
1325 | 60 |
TeamName = strLst[0]; |
61 |
Grave = strLst[1]; |
|
62 |
Fort = strLst[2]; |
|
1662 | 63 |
Voicepack = strLst[3]; |
2747 | 64 |
Flag = strLst[4]; |
65 |
Owner = strLst[5]; |
|
66 |
difficulty = strLst[6].toUInt(); |
|
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
67 |
for(int i = 0; i < 8; i++) |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
68 |
{ |
2747 | 69 |
HHName[i]=strLst[i * 2 + 7]; |
70 |
HHHat[i]=strLst[i * 2 + 8]; |
|
2833
9c2accd92cc7
Check for empty hat, somehow claymore managed this, this should be a workaround pending figuring out how he did it.
nemo
parents:
2747
diff
changeset
|
71 |
// Somehow claymore managed an empty hat. Until we figure out how, this should avoid a repeat |
9c2accd92cc7
Check for empty hat, somehow claymore managed this, this should be a workaround pending figuring out how he did it.
nemo
parents:
2747
diff
changeset
|
72 |
// Checking net teams is probably pointless, but can't hurt. |
9c2accd92cc7
Check for empty hat, somehow claymore managed this, this should be a workaround pending figuring out how he did it.
nemo
parents:
2747
diff
changeset
|
73 |
if (HHHat[i].length() == 0) HHHat[i] = "NoHat"; |
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
74 |
} |
314 | 75 |
} |
76 |
||
1907 | 77 |
HWTeam::HWTeam() : |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
336
diff
changeset
|
78 |
difficulty(0), |
353 | 79 |
numHedgehogs(4), |
1325 | 80 |
m_isNetTeam(false) |
184 | 81 |
{ |
1840 | 82 |
TeamName = QString("Team"); |
83 |
for (int i = 0; i < 8; i++) |
|
84 |
{ |
|
85 |
HHName[i].sprintf("hedgehog %d", i); |
|
86 |
HHHat[i] = "NoHat"; |
|
87 |
} |
|
88 |
||
1907 | 89 |
Grave = QString("Simple"); // default |
90 |
Fort = QString("Island"); // default |
|
2192
4763a778c033
- Fix quickplay sound bug triggered by two faults: ttsmj's (passing voicepack with empty name in team config) and koda's (he changed fallback to default scheme condition)
unc0rr
parents:
1907
diff
changeset
|
91 |
Voicepack = "Default"; |
2747 | 92 |
Flag = "hedgewars"; |
1907 | 93 |
|
184 | 94 |
for(int i = 0; i < BINDS_NUMBER; i++) |
95 |
{ |
|
96 |
binds[i].action = cbinds[i].action; |
|
97 |
binds[i].strbind = cbinds[i].strbind; |
|
98 |
} |
|
99 |
} |
|
100 |
||
101 |
||
102 |
bool HWTeam::LoadFromFile() |
|
103 |
{ |
|
353 | 104 |
numHedgehogs=4; |
184 | 105 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
106 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
|
107 |
QTextStream stream(&cfgfile); |
|
108 |
stream.setCodec("UTF-8"); |
|
109 |
QString str; |
|
110 |
QString action; |
|
111 |
||
112 |
while (!stream.atEnd()) |
|
113 |
{ |
|
114 |
str = stream.readLine(); |
|
115 |
if (str.startsWith(";")) continue; |
|
245 | 116 |
/*if (str.startsWith("name team ")) |
184 | 117 |
{ |
118 |
str.remove(0, 10); |
|
119 |
TeamName = str; |
|
245 | 120 |
} else*/ |
184 | 121 |
if (str.startsWith("name hh")) |
122 |
{ |
|
123 |
str.remove(0, 7); |
|
124 |
long i = str.left(1).toLong(); |
|
125 |
if ((i < 0) || (i > 7)) continue; |
|
126 |
str.remove(0, 2); |
|
127 |
HHName[i] = str; |
|
128 |
} else |
|
1240 | 129 |
if (str.startsWith("hat")) |
130 |
{ |
|
131 |
str.remove(0, 3); |
|
132 |
long i = str.left(1).toLong(); |
|
133 |
if ((i < 0) || (i > 7)) continue; |
|
134 |
str.remove(0, 2); |
|
135 |
HHHat[i] = str; |
|
2833
9c2accd92cc7
Check for empty hat, somehow claymore managed this, this should be a workaround pending figuring out how he did it.
nemo
parents:
2747
diff
changeset
|
136 |
// Somehow claymore managed an empty hat. Until we figure out how, this should avoid a repeat |
9c2accd92cc7
Check for empty hat, somehow claymore managed this, this should be a workaround pending figuring out how he did it.
nemo
parents:
2747
diff
changeset
|
137 |
if (HHHat[i].length() == 0) HHHat[i] = "NoHat"; |
1240 | 138 |
} else |
184 | 139 |
if (str.startsWith("grave ")) |
140 |
{ |
|
141 |
str.remove(0, 6); |
|
142 |
Grave = str; |
|
143 |
} else |
|
144 |
if (str.startsWith("fort ")) |
|
145 |
{ |
|
146 |
str.remove(0, 5); |
|
147 |
Fort = str; |
|
148 |
} else |
|
2747 | 149 |
if (str.startsWith("flag ")) |
150 |
{ |
|
151 |
str.remove(0, 5); |
|
152 |
Flag = str; |
|
153 |
} else |
|
1659 | 154 |
if (str.startsWith("voicepack ")) |
155 |
{ |
|
156 |
str.remove(0, 10); |
|
157 |
Voicepack = str; |
|
158 |
} else |
|
184 | 159 |
if (str.startsWith("bind ")) |
160 |
{ |
|
161 |
str.remove(0, 5); |
|
162 |
action = str.section(' ', 1); |
|
163 |
str = str.section(' ', 0, 0); |
|
164 |
str.truncate(15); |
|
165 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
166 |
if (action == binds[i].action) |
|
167 |
{ |
|
168 |
binds[i].strbind = str; |
|
169 |
break; |
|
170 |
} |
|
239 | 171 |
} else |
231 | 172 |
if (str.startsWith("difficulty ")) |
173 |
{ |
|
174 |
str.remove(0, 11); |
|
175 |
difficulty=str.toUInt(); |
|
176 |
if (difficulty>5) difficulty=0; // this shouldn't normally happen |
|
184 | 177 |
} |
178 |
} |
|
179 |
cfgfile.close(); |
|
180 |
return true; |
|
181 |
} |
|
182 |
||
183 |
bool HWTeam::SaveToFile() |
|
184 |
{ |
|
245 | 185 |
if (OldTeamName != TeamName) |
186 |
{ |
|
187 |
QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg"); |
|
188 |
cfgfile.remove(); |
|
189 |
OldTeamName = TeamName; |
|
190 |
} |
|
184 | 191 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
192 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false; |
|
193 |
QTextStream stream(&cfgfile); |
|
194 |
stream.setCodec("UTF-8"); |
|
195 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
196 |
stream << "name team " << TeamName << endl; |
|
197 |
for (int i = 0; i < 8; i++) |
|
1240 | 198 |
{ |
184 | 199 |
stream << "name hh" << i << " " << HHName[i] << endl; |
1240 | 200 |
stream << "hat" << i << " " << HHHat[i] << endl; |
201 |
} |
|
184 | 202 |
stream << "grave " << Grave << endl; |
203 |
stream << "fort " << Fort << endl; |
|
1659 | 204 |
stream << "voicepack " << Voicepack << endl; |
2747 | 205 |
stream << "flag " << Flag << endl; |
184 | 206 |
for(int i = 0; i < BINDS_NUMBER; i++) |
207 |
{ |
|
208 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; |
|
209 |
} |
|
231 | 210 |
stream << "difficulty " << difficulty << endl; |
184 | 211 |
cfgfile.close(); |
212 |
return true; |
|
213 |
} |
|
214 |
||
215 |
void HWTeam::SetToPage(HWForm * hwform) |
|
216 |
{ |
|
217 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
|
336 | 218 |
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
184 | 219 |
for(int i = 0; i < 8; i++) |
220 |
{ |
|
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
|
221 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
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
|
222 |
if (HHHat[i].startsWith("Reserved")) |
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
|
223 |
hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+HHHat[i].remove(0,40), Qt::DisplayRole)); |
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
|
224 |
else |
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
|
225 |
hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole)); |
184 | 226 |
} |
227 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
2747 | 228 |
hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findText(Flag)); |
184 | 229 |
|
230 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
|
1659 | 231 |
hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(Voicepack)); |
1287 | 232 |
//hwform->ui.pageEditTeam->CBFort_activated(Fort); |
184 | 233 |
|
234 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
235 |
{ |
|
2428 | 236 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findData(binds[i].strbind)); |
184 | 237 |
} |
238 |
} |
|
239 |
||
240 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
241 |
{ |
|
242 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
|
336 | 243 |
difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); |
184 | 244 |
for(int i = 0; i < 8; i++) |
245 |
{ |
|
246 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
|
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
|
247 |
if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved")) |
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
|
248 |
HHHat[i] = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9); |
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
|
249 |
else |
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
|
250 |
HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText(); |
184 | 251 |
} |
252 |
||
253 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
|
254 |
Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
1659 | 255 |
Voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText(); |
2747 | 256 |
Flag = hwform->ui.pageEditTeam->CBFlag->currentText(); |
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
257 |
for(int i = 0; i < BINDS_NUMBER; i++) |
184 | 258 |
{ |
2428 | 259 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->itemData(hwform->ui.pageEditTeam->CBBind[i]->currentIndex()).toString(); |
184 | 260 |
} |
261 |
} |
|
262 |
||
341 | 263 |
QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const |
184 | 264 |
{ |
239 | 265 |
QStringList sl; |
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
|
266 |
if (m_isNetTeam) |
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
|
267 |
{ |
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
|
268 |
sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(QString(QCryptographicHash::hash(Owner.toLatin1(), QCryptographicHash::Md5).toHex()))); |
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
|
269 |
sl.push_back("erdriven"); |
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
|
270 |
} |
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
|
271 |
else sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(playerHash)); |
606
9d800fdfd3bd
Add ammostores in frontend, should help further ammostores implemetation
unc0rr
parents:
605
diff
changeset
|
272 |
|
341 | 273 |
sl.push_back(QString("egrave " + Grave)); |
274 |
sl.push_back(QString("efort " + Fort)); |
|
1659 | 275 |
sl.push_back(QString("evoicepack " + Voicepack)); |
2747 | 276 |
sl.push_back(QString("eflag " + Flag)); |
341 | 277 |
|
1325 | 278 |
if (!m_isNetTeam) |
341 | 279 |
for(int i = 0; i < BINDS_NUMBER; i++) |
2428 | 280 |
if(!binds[i].strbind.isEmpty()) |
281 |
sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
|
341 | 282 |
|
283 |
for (int t = 0; t < numHedgehogs; t++) |
|
1242 | 284 |
{ |
605 | 285 |
sl.push_back(QString("eaddhh %1 %2 %3") |
319 | 286 |
.arg(QString::number(difficulty), |
605 | 287 |
QString::number(InitHealth), |
288 |
HHName[t])); |
|
1242 | 289 |
sl.push_back(QString("ehat %1") |
290 |
.arg(HHHat[t])); |
|
291 |
} |
|
239 | 292 |
return sl; |
184 | 293 |
} |
294 |
||
352 | 295 |
bool HWTeam::isNetTeam() const |
296 |
{ |
|
1325 | 297 |
return m_isNetTeam; |
352 | 298 |
} |
299 |
||
300 |
||
184 | 301 |
bool HWTeam::operator==(const HWTeam& t1) const { |
1325 | 302 |
return TeamName==t1.TeamName; |
184 | 303 |
} |
304 |
||
305 |
bool HWTeam::operator<(const HWTeam& t1) const { |
|
1325 | 306 |
return TeamName<t1.TeamName; // if names are equal - test if it is net team |
184 | 307 |
} |
1840 | 308 |
|
309 |