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