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