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