author | unc0rr |
Tue, 13 Jan 2009 20:21:40 +0000 | |
changeset 1662 | cefb9d0f816f |
parent 1659 | fd593a5e71fb |
child 1683 | af34da5726aa |
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 |
1662 | 58 |
if(strLst.size() < 21) throw HWTeamConstructException(); |
1325 | 59 |
TeamName = strLst[0]; |
60 |
Grave = strLst[1]; |
|
61 |
Fort = strLst[2]; |
|
1662 | 62 |
Voicepack = strLst[3]; |
63 |
difficulty = strLst[4].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 |
{ |
1662 | 66 |
HHName[i]=strLst[i * 2 + 5]; |
67 |
HHHat[i]=strLst[i * 2 + 6]; |
|
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
68 |
} |
314 | 69 |
} |
70 |
||
231 | 71 |
HWTeam::HWTeam(quint8 num) : |
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 |
{ |
76 |
num %= PREDEFTEAMS_COUNT; |
|
77 |
TeamName = QApplication::translate("teams", pteams[num].TeamName); |
|
78 |
HHName[0] = QApplication::translate("teams", pteams[num].hh0name); |
|
79 |
HHName[1] = QApplication::translate("teams", pteams[num].hh1name); |
|
80 |
HHName[2] = QApplication::translate("teams", pteams[num].hh2name); |
|
81 |
HHName[3] = QApplication::translate("teams", pteams[num].hh3name); |
|
82 |
HHName[4] = QApplication::translate("teams", pteams[num].hh4name); |
|
83 |
HHName[5] = QApplication::translate("teams", pteams[num].hh5name); |
|
84 |
HHName[6] = QApplication::translate("teams", pteams[num].hh6name); |
|
85 |
HHName[7] = QApplication::translate("teams", pteams[num].hh7name); |
|
1293 | 86 |
HHHat[0] = pteams[num].hh0hat; |
87 |
HHHat[1] = pteams[num].hh1hat; |
|
88 |
HHHat[2] = pteams[num].hh2hat; |
|
89 |
HHHat[3] = pteams[num].hh3hat; |
|
90 |
HHHat[4] = pteams[num].hh4hat; |
|
91 |
HHHat[5] = pteams[num].hh5hat; |
|
92 |
HHHat[6] = pteams[num].hh6hat; |
|
93 |
HHHat[7] = pteams[num].hh7hat; |
|
94 |
||
184 | 95 |
Grave = pteams[num].Grave; |
96 |
Fort = pteams[num].Fort; |
|
97 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
98 |
{ |
|
99 |
binds[i].action = cbinds[i].action; |
|
100 |
binds[i].strbind = cbinds[i].strbind; |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
||
105 |
bool HWTeam::LoadFromFile() |
|
106 |
{ |
|
353 | 107 |
numHedgehogs=4; |
184 | 108 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
109 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
|
110 |
QTextStream stream(&cfgfile); |
|
111 |
stream.setCodec("UTF-8"); |
|
112 |
QString str; |
|
113 |
QString action; |
|
114 |
||
115 |
while (!stream.atEnd()) |
|
116 |
{ |
|
117 |
str = stream.readLine(); |
|
118 |
if (str.startsWith(";")) continue; |
|
245 | 119 |
/*if (str.startsWith("name team ")) |
184 | 120 |
{ |
121 |
str.remove(0, 10); |
|
122 |
TeamName = str; |
|
245 | 123 |
} else*/ |
184 | 124 |
if (str.startsWith("name hh")) |
125 |
{ |
|
126 |
str.remove(0, 7); |
|
127 |
long i = str.left(1).toLong(); |
|
128 |
if ((i < 0) || (i > 7)) continue; |
|
129 |
str.remove(0, 2); |
|
130 |
HHName[i] = str; |
|
131 |
} else |
|
1240 | 132 |
if (str.startsWith("hat")) |
133 |
{ |
|
134 |
str.remove(0, 3); |
|
135 |
long i = str.left(1).toLong(); |
|
136 |
if ((i < 0) || (i > 7)) continue; |
|
137 |
str.remove(0, 2); |
|
138 |
HHHat[i] = str; |
|
139 |
} else |
|
184 | 140 |
if (str.startsWith("grave ")) |
141 |
{ |
|
142 |
str.remove(0, 6); |
|
143 |
Grave = str; |
|
144 |
} else |
|
145 |
if (str.startsWith("fort ")) |
|
146 |
{ |
|
147 |
str.remove(0, 5); |
|
148 |
Fort = str; |
|
149 |
} else |
|
1659 | 150 |
if (str.startsWith("voicepack ")) |
151 |
{ |
|
152 |
str.remove(0, 10); |
|
153 |
Voicepack = str; |
|
154 |
} else |
|
184 | 155 |
if (str.startsWith("bind ")) |
156 |
{ |
|
157 |
str.remove(0, 5); |
|
158 |
action = str.section(' ', 1); |
|
159 |
str = str.section(' ', 0, 0); |
|
160 |
str.truncate(15); |
|
161 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
162 |
if (action == binds[i].action) |
|
163 |
{ |
|
164 |
binds[i].strbind = str; |
|
165 |
break; |
|
166 |
} |
|
239 | 167 |
} else |
231 | 168 |
if (str.startsWith("difficulty ")) |
169 |
{ |
|
170 |
str.remove(0, 11); |
|
171 |
difficulty=str.toUInt(); |
|
172 |
if (difficulty>5) difficulty=0; // this shouldn't normally happen |
|
184 | 173 |
} |
174 |
} |
|
175 |
cfgfile.close(); |
|
176 |
return true; |
|
177 |
} |
|
178 |
||
179 |
bool HWTeam::SaveToFile() |
|
180 |
{ |
|
245 | 181 |
if (OldTeamName != TeamName) |
182 |
{ |
|
183 |
QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg"); |
|
184 |
cfgfile.remove(); |
|
185 |
OldTeamName = TeamName; |
|
186 |
} |
|
184 | 187 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
188 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false; |
|
189 |
QTextStream stream(&cfgfile); |
|
190 |
stream.setCodec("UTF-8"); |
|
191 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
192 |
stream << "name team " << TeamName << endl; |
|
193 |
for (int i = 0; i < 8; i++) |
|
1240 | 194 |
{ |
184 | 195 |
stream << "name hh" << i << " " << HHName[i] << endl; |
1240 | 196 |
stream << "hat" << i << " " << HHHat[i] << endl; |
197 |
} |
|
184 | 198 |
stream << "grave " << Grave << endl; |
199 |
stream << "fort " << Fort << endl; |
|
1659 | 200 |
stream << "voicepack " << Voicepack << endl; |
184 | 201 |
for(int i = 0; i < BINDS_NUMBER; i++) |
202 |
{ |
|
203 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; |
|
204 |
} |
|
231 | 205 |
stream << "difficulty " << difficulty << endl; |
184 | 206 |
cfgfile.close(); |
207 |
return true; |
|
208 |
} |
|
209 |
||
210 |
void HWTeam::SetToPage(HWForm * hwform) |
|
211 |
{ |
|
212 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
|
336 | 213 |
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
184 | 214 |
for(int i = 0; i < 8; i++) |
215 |
{ |
|
216 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
|
1240 | 217 |
hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole)); |
184 | 218 |
} |
219 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
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 |
{ |
|
227 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
|
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(); |
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
244 |
for(int i = 0; i < BINDS_NUMBER; i++) |
184 | 245 |
{ |
246 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText(); |
|
247 |
} |
|
248 |
} |
|
249 |
||
341 | 250 |
QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const |
184 | 251 |
{ |
239 | 252 |
QStringList sl; |
605 | 253 |
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
|
254 |
|
1325 | 255 |
if (m_isNetTeam) |
341 | 256 |
sl.push_back("erdriven"); |
257 |
||
258 |
sl.push_back(QString("egrave " + Grave)); |
|
259 |
sl.push_back(QString("efort " + Fort)); |
|
1659 | 260 |
sl.push_back(QString("evoicepack " + Voicepack)); |
341 | 261 |
|
1325 | 262 |
if (!m_isNetTeam) |
341 | 263 |
for(int i = 0; i < BINDS_NUMBER; i++) |
264 |
sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
|
265 |
||
266 |
for (int t = 0; t < numHedgehogs; t++) |
|
1242 | 267 |
{ |
605 | 268 |
sl.push_back(QString("eaddhh %1 %2 %3") |
319 | 269 |
.arg(QString::number(difficulty), |
605 | 270 |
QString::number(InitHealth), |
271 |
HHName[t])); |
|
1242 | 272 |
sl.push_back(QString("ehat %1") |
273 |
.arg(HHHat[t])); |
|
274 |
} |
|
239 | 275 |
return sl; |
184 | 276 |
} |
277 |
||
352 | 278 |
bool HWTeam::isNetTeam() const |
279 |
{ |
|
1325 | 280 |
return m_isNetTeam; |
352 | 281 |
} |
282 |
||
283 |
||
184 | 284 |
bool HWTeam::operator==(const HWTeam& t1) const { |
1325 | 285 |
return TeamName==t1.TeamName; |
184 | 286 |
} |
287 |
||
288 |
bool HWTeam::operator<(const HWTeam& t1) const { |
|
1325 | 289 |
return TeamName<t1.TeamName; // if names are equal - test if it is net team |
184 | 290 |
} |