author | koda |
Mon, 22 Jul 2013 21:32:08 +0200 | |
branch | 0.9.9 |
changeset 1739 | 76d47aa70290 |
parent 1683 | af34da5726aa |
child 1840 | 4747f0232b88 |
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 "predefteams.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"; |
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 |
1683 | 58 |
if(strLst.size() != 22) throw HWTeamConstructException(); |
1325 | 59 |
TeamName = strLst[0]; |
60 |
Grave = strLst[1]; |
|
61 |
Fort = strLst[2]; |
|
1662 | 62 |
Voicepack = strLst[3]; |
1683 | 63 |
Owner = strLst[4]; |
64 |
difficulty = strLst[5].toUInt(); |
|
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
65 |
for(int i = 0; i < 8; i++) |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
66 |
{ |
1683 | 67 |
HHName[i]=strLst[i * 2 + 6]; |
68 |
HHHat[i]=strLst[i * 2 + 7]; |
|
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
69 |
} |
314 | 70 |
} |
71 |
||
231 | 72 |
HWTeam::HWTeam(quint8 num) : |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
336
diff
changeset
|
73 |
difficulty(0), |
353 | 74 |
numHedgehogs(4), |
1325 | 75 |
m_isNetTeam(false) |
184 | 76 |
{ |
77 |
num %= PREDEFTEAMS_COUNT; |
|
78 |
TeamName = QApplication::translate("teams", pteams[num].TeamName); |
|
79 |
HHName[0] = QApplication::translate("teams", pteams[num].hh0name); |
|
80 |
HHName[1] = QApplication::translate("teams", pteams[num].hh1name); |
|
81 |
HHName[2] = QApplication::translate("teams", pteams[num].hh2name); |
|
82 |
HHName[3] = QApplication::translate("teams", pteams[num].hh3name); |
|
83 |
HHName[4] = QApplication::translate("teams", pteams[num].hh4name); |
|
84 |
HHName[5] = QApplication::translate("teams", pteams[num].hh5name); |
|
85 |
HHName[6] = QApplication::translate("teams", pteams[num].hh6name); |
|
86 |
HHName[7] = QApplication::translate("teams", pteams[num].hh7name); |
|
1293 | 87 |
HHHat[0] = pteams[num].hh0hat; |
88 |
HHHat[1] = pteams[num].hh1hat; |
|
89 |
HHHat[2] = pteams[num].hh2hat; |
|
90 |
HHHat[3] = pteams[num].hh3hat; |
|
91 |
HHHat[4] = pteams[num].hh4hat; |
|
92 |
HHHat[5] = pteams[num].hh5hat; |
|
93 |
HHHat[6] = pteams[num].hh6hat; |
|
94 |
HHHat[7] = pteams[num].hh7hat; |
|
95 |
||
184 | 96 |
Grave = pteams[num].Grave; |
97 |
Fort = pteams[num].Fort; |
|
98 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
99 |
{ |
|
100 |
binds[i].action = cbinds[i].action; |
|
101 |
binds[i].strbind = cbinds[i].strbind; |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
||
106 |
bool HWTeam::LoadFromFile() |
|
107 |
{ |
|
353 | 108 |
numHedgehogs=4; |
184 | 109 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
110 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
|
111 |
QTextStream stream(&cfgfile); |
|
112 |
stream.setCodec("UTF-8"); |
|
113 |
QString str; |
|
114 |
QString action; |
|
115 |
||
116 |
while (!stream.atEnd()) |
|
117 |
{ |
|
118 |
str = stream.readLine(); |
|
119 |
if (str.startsWith(";")) continue; |
|
245 | 120 |
/*if (str.startsWith("name team ")) |
184 | 121 |
{ |
122 |
str.remove(0, 10); |
|
123 |
TeamName = str; |
|
245 | 124 |
} else*/ |
184 | 125 |
if (str.startsWith("name hh")) |
126 |
{ |
|
127 |
str.remove(0, 7); |
|
128 |
long i = str.left(1).toLong(); |
|
129 |
if ((i < 0) || (i > 7)) continue; |
|
130 |
str.remove(0, 2); |
|
131 |
HHName[i] = str; |
|
132 |
} else |
|
1240 | 133 |
if (str.startsWith("hat")) |
134 |
{ |
|
135 |
str.remove(0, 3); |
|
136 |
long i = str.left(1).toLong(); |
|
137 |
if ((i < 0) || (i > 7)) continue; |
|
138 |
str.remove(0, 2); |
|
139 |
HHHat[i] = str; |
|
140 |
} else |
|
184 | 141 |
if (str.startsWith("grave ")) |
142 |
{ |
|
143 |
str.remove(0, 6); |
|
144 |
Grave = str; |
|
145 |
} else |
|
146 |
if (str.startsWith("fort ")) |
|
147 |
{ |
|
148 |
str.remove(0, 5); |
|
149 |
Fort = str; |
|
150 |
} else |
|
1659 | 151 |
if (str.startsWith("voicepack ")) |
152 |
{ |
|
153 |
str.remove(0, 10); |
|
154 |
Voicepack = str; |
|
155 |
} else |
|
184 | 156 |
if (str.startsWith("bind ")) |
157 |
{ |
|
158 |
str.remove(0, 5); |
|
159 |
action = str.section(' ', 1); |
|
160 |
str = str.section(' ', 0, 0); |
|
161 |
str.truncate(15); |
|
162 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
163 |
if (action == binds[i].action) |
|
164 |
{ |
|
165 |
binds[i].strbind = str; |
|
166 |
break; |
|
167 |
} |
|
239 | 168 |
} else |
231 | 169 |
if (str.startsWith("difficulty ")) |
170 |
{ |
|
171 |
str.remove(0, 11); |
|
172 |
difficulty=str.toUInt(); |
|
173 |
if (difficulty>5) difficulty=0; // this shouldn't normally happen |
|
184 | 174 |
} |
175 |
} |
|
176 |
cfgfile.close(); |
|
177 |
return true; |
|
178 |
} |
|
179 |
||
180 |
bool HWTeam::SaveToFile() |
|
181 |
{ |
|
245 | 182 |
if (OldTeamName != TeamName) |
183 |
{ |
|
184 |
QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg"); |
|
185 |
cfgfile.remove(); |
|
186 |
OldTeamName = TeamName; |
|
187 |
} |
|
184 | 188 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
189 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false; |
|
190 |
QTextStream stream(&cfgfile); |
|
191 |
stream.setCodec("UTF-8"); |
|
192 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
193 |
stream << "name team " << TeamName << endl; |
|
194 |
for (int i = 0; i < 8; i++) |
|
1240 | 195 |
{ |
184 | 196 |
stream << "name hh" << i << " " << HHName[i] << endl; |
1240 | 197 |
stream << "hat" << i << " " << HHHat[i] << endl; |
198 |
} |
|
184 | 199 |
stream << "grave " << Grave << endl; |
200 |
stream << "fort " << Fort << endl; |
|
1659 | 201 |
stream << "voicepack " << Voicepack << endl; |
184 | 202 |
for(int i = 0; i < BINDS_NUMBER; i++) |
203 |
{ |
|
204 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; |
|
205 |
} |
|
231 | 206 |
stream << "difficulty " << difficulty << endl; |
184 | 207 |
cfgfile.close(); |
208 |
return true; |
|
209 |
} |
|
210 |
||
211 |
void HWTeam::SetToPage(HWForm * hwform) |
|
212 |
{ |
|
213 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
|
336 | 214 |
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
184 | 215 |
for(int i = 0; i < 8; i++) |
216 |
{ |
|
217 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
|
1240 | 218 |
hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole)); |
184 | 219 |
} |
220 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
221 |
||
222 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
|
1659 | 223 |
hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(Voicepack)); |
1287 | 224 |
//hwform->ui.pageEditTeam->CBFort_activated(Fort); |
184 | 225 |
|
226 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
227 |
{ |
|
228 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
|
229 |
} |
|
230 |
} |
|
231 |
||
232 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
233 |
{ |
|
234 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
|
336 | 235 |
difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); |
184 | 236 |
for(int i = 0; i < 8; i++) |
237 |
{ |
|
238 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
|
1240 | 239 |
HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText(); |
184 | 240 |
} |
241 |
||
242 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
|
243 |
Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
1659 | 244 |
Voicepack = hwform->ui.pageEditTeam->CBVoicepack->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 |
{ |
247 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText(); |
|
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)); |
341 | 262 |
|
1325 | 263 |
if (!m_isNetTeam) |
341 | 264 |
for(int i = 0; i < BINDS_NUMBER; i++) |
265 |
sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
|
266 |
||
267 |
for (int t = 0; t < numHedgehogs; t++) |
|
1242 | 268 |
{ |
605 | 269 |
sl.push_back(QString("eaddhh %1 %2 %3") |
319 | 270 |
.arg(QString::number(difficulty), |
605 | 271 |
QString::number(InitHealth), |
272 |
HHName[t])); |
|
1242 | 273 |
sl.push_back(QString("ehat %1") |
274 |
.arg(HHHat[t])); |
|
275 |
} |
|
239 | 276 |
return sl; |
184 | 277 |
} |
278 |
||
352 | 279 |
bool HWTeam::isNetTeam() const |
280 |
{ |
|
1325 | 281 |
return m_isNetTeam; |
352 | 282 |
} |
283 |
||
284 |
||
184 | 285 |
bool HWTeam::operator==(const HWTeam& t1) const { |
1325 | 286 |
return TeamName==t1.TeamName; |
184 | 287 |
} |
288 |
||
289 |
bool HWTeam::operator<(const HWTeam& t1) const { |
|
1325 | 290 |
return TeamName<t1.TeamName; // if names are equal - test if it is net team |
184 | 291 |
} |