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