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