author | unc0rr |
Tue, 23 Dec 2008 20:44:32 +0000 | |
changeset 1548 | 682c0c968997 |
parent 1538 | 8bc56dd2e997 |
child 1655 | 16f687fc18e3 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2005-2007 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"; |
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 |
1325 | 57 |
if(strLst.size() < 20) throw HWTeamConstructException(); |
58 |
TeamName = strLst[0]; |
|
59 |
Grave = strLst[1]; |
|
60 |
Fort = strLst[2]; |
|
61 |
difficulty = strLst[3].toUInt(); |
|
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
62 |
for(int i = 0; i < 8; i++) |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
63 |
{ |
1325 | 64 |
HHName[i]=strLst[i * 2 + 4]; |
65 |
HHHat[i]=strLst[i * 2 + 5]; |
|
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1244
diff
changeset
|
66 |
} |
314 | 67 |
} |
68 |
||
231 | 69 |
HWTeam::HWTeam(quint8 num) : |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
336
diff
changeset
|
70 |
difficulty(0), |
353 | 71 |
numHedgehogs(4), |
1325 | 72 |
m_isNetTeam(false) |
184 | 73 |
{ |
74 |
num %= PREDEFTEAMS_COUNT; |
|
75 |
TeamName = QApplication::translate("teams", pteams[num].TeamName); |
|
76 |
HHName[0] = QApplication::translate("teams", pteams[num].hh0name); |
|
77 |
HHName[1] = QApplication::translate("teams", pteams[num].hh1name); |
|
78 |
HHName[2] = QApplication::translate("teams", pteams[num].hh2name); |
|
79 |
HHName[3] = QApplication::translate("teams", pteams[num].hh3name); |
|
80 |
HHName[4] = QApplication::translate("teams", pteams[num].hh4name); |
|
81 |
HHName[5] = QApplication::translate("teams", pteams[num].hh5name); |
|
82 |
HHName[6] = QApplication::translate("teams", pteams[num].hh6name); |
|
83 |
HHName[7] = QApplication::translate("teams", pteams[num].hh7name); |
|
1293 | 84 |
HHHat[0] = pteams[num].hh0hat; |
85 |
HHHat[1] = pteams[num].hh1hat; |
|
86 |
HHHat[2] = pteams[num].hh2hat; |
|
87 |
HHHat[3] = pteams[num].hh3hat; |
|
88 |
HHHat[4] = pteams[num].hh4hat; |
|
89 |
HHHat[5] = pteams[num].hh5hat; |
|
90 |
HHHat[6] = pteams[num].hh6hat; |
|
91 |
HHHat[7] = pteams[num].hh7hat; |
|
92 |
||
184 | 93 |
Grave = pteams[num].Grave; |
94 |
Fort = pteams[num].Fort; |
|
95 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
96 |
{ |
|
97 |
binds[i].action = cbinds[i].action; |
|
98 |
binds[i].strbind = cbinds[i].strbind; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
||
103 |
bool HWTeam::LoadFromFile() |
|
104 |
{ |
|
353 | 105 |
numHedgehogs=4; |
184 | 106 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
107 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
|
108 |
QTextStream stream(&cfgfile); |
|
109 |
stream.setCodec("UTF-8"); |
|
110 |
QString str; |
|
111 |
QString action; |
|
112 |
||
113 |
while (!stream.atEnd()) |
|
114 |
{ |
|
115 |
str = stream.readLine(); |
|
116 |
if (str.startsWith(";")) continue; |
|
245 | 117 |
/*if (str.startsWith("name team ")) |
184 | 118 |
{ |
119 |
str.remove(0, 10); |
|
120 |
TeamName = str; |
|
245 | 121 |
} else*/ |
184 | 122 |
if (str.startsWith("name hh")) |
123 |
{ |
|
124 |
str.remove(0, 7); |
|
125 |
long i = str.left(1).toLong(); |
|
126 |
if ((i < 0) || (i > 7)) continue; |
|
127 |
str.remove(0, 2); |
|
128 |
HHName[i] = str; |
|
129 |
} else |
|
1240 | 130 |
if (str.startsWith("hat")) |
131 |
{ |
|
132 |
str.remove(0, 3); |
|
133 |
long i = str.left(1).toLong(); |
|
134 |
if ((i < 0) || (i > 7)) continue; |
|
135 |
str.remove(0, 2); |
|
136 |
HHHat[i] = str; |
|
137 |
} else |
|
184 | 138 |
if (str.startsWith("grave ")) |
139 |
{ |
|
140 |
str.remove(0, 6); |
|
141 |
Grave = str; |
|
142 |
} else |
|
143 |
if (str.startsWith("fort ")) |
|
144 |
{ |
|
145 |
str.remove(0, 5); |
|
146 |
Fort = str; |
|
147 |
} else |
|
148 |
if (str.startsWith("bind ")) |
|
149 |
{ |
|
150 |
str.remove(0, 5); |
|
151 |
action = str.section(' ', 1); |
|
152 |
str = str.section(' ', 0, 0); |
|
153 |
str.truncate(15); |
|
154 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
155 |
if (action == binds[i].action) |
|
156 |
{ |
|
157 |
binds[i].strbind = str; |
|
158 |
break; |
|
159 |
} |
|
239 | 160 |
} else |
231 | 161 |
if (str.startsWith("difficulty ")) |
162 |
{ |
|
163 |
str.remove(0, 11); |
|
164 |
difficulty=str.toUInt(); |
|
165 |
if (difficulty>5) difficulty=0; // this shouldn't normally happen |
|
184 | 166 |
} |
167 |
} |
|
168 |
cfgfile.close(); |
|
169 |
return true; |
|
170 |
} |
|
171 |
||
172 |
bool HWTeam::SaveToFile() |
|
173 |
{ |
|
245 | 174 |
if (OldTeamName != TeamName) |
175 |
{ |
|
176 |
QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg"); |
|
177 |
cfgfile.remove(); |
|
178 |
OldTeamName = TeamName; |
|
179 |
} |
|
184 | 180 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
181 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false; |
|
182 |
QTextStream stream(&cfgfile); |
|
183 |
stream.setCodec("UTF-8"); |
|
184 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
185 |
stream << "name team " << TeamName << endl; |
|
186 |
for (int i = 0; i < 8; i++) |
|
1240 | 187 |
{ |
184 | 188 |
stream << "name hh" << i << " " << HHName[i] << endl; |
1240 | 189 |
stream << "hat" << i << " " << HHHat[i] << endl; |
190 |
} |
|
184 | 191 |
stream << "grave " << Grave << endl; |
192 |
stream << "fort " << Fort << endl; |
|
193 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
194 |
{ |
|
195 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; |
|
196 |
} |
|
231 | 197 |
stream << "difficulty " << difficulty << endl; |
184 | 198 |
cfgfile.close(); |
199 |
return true; |
|
200 |
} |
|
201 |
||
202 |
void HWTeam::SetToPage(HWForm * hwform) |
|
203 |
{ |
|
204 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
|
336 | 205 |
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
184 | 206 |
for(int i = 0; i < 8; i++) |
207 |
{ |
|
208 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
|
1240 | 209 |
hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole)); |
184 | 210 |
} |
211 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
212 |
||
213 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
|
1287 | 214 |
//hwform->ui.pageEditTeam->CBFort_activated(Fort); |
184 | 215 |
|
216 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
217 |
{ |
|
218 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
223 |
{ |
|
224 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
|
336 | 225 |
difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); |
184 | 226 |
for(int i = 0; i < 8; i++) |
227 |
{ |
|
228 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
|
1240 | 229 |
HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText(); |
184 | 230 |
} |
231 |
||
232 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
|
233 |
Fort = hwform->ui.pageEditTeam->CBFort->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)); |
|
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 |
} |