author | unc0rr |
Sun, 31 Aug 2008 16:00:31 +0000 | |
changeset 1240 | 16b85f292030 |
parent 1066 | 1f1b3686a2b0 |
child 1242 | 4aca5f7b2504 |
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 |
|
352 | 31 |
HWTeam::HWTeam(const QString & teamname, unsigned int netID) : |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
336
diff
changeset
|
32 |
difficulty(0), |
353 | 33 |
numHedgehogs(4), |
352 | 34 |
m_netID(netID) |
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 |
} |
|
184 | 43 |
Grave = "Simple"; |
44 |
Fort = "Barrelhouse"; |
|
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) : |
53 |
numHedgehogs(4) |
|
314 | 54 |
{ |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
336
diff
changeset
|
55 |
// net teams are configured from QStringList |
443
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
353
diff
changeset
|
56 |
if(strLst.size()<13) throw HWTeamConstructException(); |
314 | 57 |
TeamName=strLst[0]; |
352 | 58 |
m_netID=strLst[1].toUInt(); |
443
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
353
diff
changeset
|
59 |
Grave=strLst[2]; |
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
353
diff
changeset
|
60 |
Fort=strLst[3]; |
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
353
diff
changeset
|
61 |
difficulty=strLst[4].toUInt(); |
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
353
diff
changeset
|
62 |
for(int i = 0; i < 8; i++) HHName[i]=strLst[i+5]; |
314 | 63 |
} |
64 |
||
231 | 65 |
HWTeam::HWTeam(quint8 num) : |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
336
diff
changeset
|
66 |
difficulty(0), |
353 | 67 |
numHedgehogs(4), |
352 | 68 |
m_netID(0) |
184 | 69 |
{ |
70 |
num %= PREDEFTEAMS_COUNT; |
|
71 |
TeamName = QApplication::translate("teams", pteams[num].TeamName); |
|
72 |
HHName[0] = QApplication::translate("teams", pteams[num].hh0name); |
|
73 |
HHName[1] = QApplication::translate("teams", pteams[num].hh1name); |
|
74 |
HHName[2] = QApplication::translate("teams", pteams[num].hh2name); |
|
75 |
HHName[3] = QApplication::translate("teams", pteams[num].hh3name); |
|
76 |
HHName[4] = QApplication::translate("teams", pteams[num].hh4name); |
|
77 |
HHName[5] = QApplication::translate("teams", pteams[num].hh5name); |
|
78 |
HHName[6] = QApplication::translate("teams", pteams[num].hh6name); |
|
79 |
HHName[7] = QApplication::translate("teams", pteams[num].hh7name); |
|
80 |
Grave = pteams[num].Grave; |
|
81 |
Fort = pteams[num].Fort; |
|
82 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
83 |
{ |
|
84 |
binds[i].action = cbinds[i].action; |
|
85 |
binds[i].strbind = cbinds[i].strbind; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
||
90 |
bool HWTeam::LoadFromFile() |
|
91 |
{ |
|
353 | 92 |
numHedgehogs=4; |
184 | 93 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
94 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
|
95 |
QTextStream stream(&cfgfile); |
|
96 |
stream.setCodec("UTF-8"); |
|
97 |
QString str; |
|
98 |
QString action; |
|
99 |
||
100 |
while (!stream.atEnd()) |
|
101 |
{ |
|
102 |
str = stream.readLine(); |
|
103 |
if (str.startsWith(";")) continue; |
|
245 | 104 |
/*if (str.startsWith("name team ")) |
184 | 105 |
{ |
106 |
str.remove(0, 10); |
|
107 |
TeamName = str; |
|
245 | 108 |
} else*/ |
184 | 109 |
if (str.startsWith("name hh")) |
110 |
{ |
|
111 |
str.remove(0, 7); |
|
112 |
long i = str.left(1).toLong(); |
|
113 |
if ((i < 0) || (i > 7)) continue; |
|
114 |
str.remove(0, 2); |
|
115 |
HHName[i] = str; |
|
116 |
} else |
|
1240 | 117 |
if (str.startsWith("hat")) |
118 |
{ |
|
119 |
str.remove(0, 3); |
|
120 |
long i = str.left(1).toLong(); |
|
121 |
if ((i < 0) || (i > 7)) continue; |
|
122 |
str.remove(0, 2); |
|
123 |
HHHat[i] = str; |
|
124 |
} else |
|
184 | 125 |
if (str.startsWith("grave ")) |
126 |
{ |
|
127 |
str.remove(0, 6); |
|
128 |
Grave = str; |
|
129 |
} else |
|
130 |
if (str.startsWith("fort ")) |
|
131 |
{ |
|
132 |
str.remove(0, 5); |
|
133 |
Fort = str; |
|
134 |
} else |
|
135 |
if (str.startsWith("bind ")) |
|
136 |
{ |
|
137 |
str.remove(0, 5); |
|
138 |
action = str.section(' ', 1); |
|
139 |
str = str.section(' ', 0, 0); |
|
140 |
str.truncate(15); |
|
141 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
142 |
if (action == binds[i].action) |
|
143 |
{ |
|
144 |
binds[i].strbind = str; |
|
145 |
break; |
|
146 |
} |
|
239 | 147 |
} else |
231 | 148 |
if (str.startsWith("difficulty ")) |
149 |
{ |
|
150 |
str.remove(0, 11); |
|
151 |
difficulty=str.toUInt(); |
|
152 |
if (difficulty>5) difficulty=0; // this shouldn't normally happen |
|
184 | 153 |
} |
154 |
} |
|
155 |
cfgfile.close(); |
|
156 |
return true; |
|
157 |
} |
|
158 |
||
159 |
bool HWTeam::SaveToFile() |
|
160 |
{ |
|
245 | 161 |
if (OldTeamName != TeamName) |
162 |
{ |
|
163 |
QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg"); |
|
164 |
cfgfile.remove(); |
|
165 |
OldTeamName = TeamName; |
|
166 |
} |
|
184 | 167 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
168 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false; |
|
169 |
QTextStream stream(&cfgfile); |
|
170 |
stream.setCodec("UTF-8"); |
|
171 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
172 |
stream << "name team " << TeamName << endl; |
|
173 |
for (int i = 0; i < 8; i++) |
|
1240 | 174 |
{ |
184 | 175 |
stream << "name hh" << i << " " << HHName[i] << endl; |
1240 | 176 |
stream << "hat" << i << " " << HHHat[i] << endl; |
177 |
} |
|
184 | 178 |
stream << "grave " << Grave << endl; |
179 |
stream << "fort " << Fort << endl; |
|
180 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
181 |
{ |
|
182 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; |
|
183 |
} |
|
231 | 184 |
stream << "difficulty " << difficulty << endl; |
184 | 185 |
cfgfile.close(); |
186 |
return true; |
|
187 |
} |
|
188 |
||
189 |
void HWTeam::SetToPage(HWForm * hwform) |
|
190 |
{ |
|
191 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
|
336 | 192 |
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
193 |
hwform->ui.pageEditTeam->CBTeamLvl_activated(difficulty); |
|
184 | 194 |
for(int i = 0; i < 8; i++) |
195 |
{ |
|
196 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
|
1240 | 197 |
hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(HHHat[i], Qt::DisplayRole)); |
184 | 198 |
} |
199 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
200 |
hwform->ui.pageEditTeam->CBGrave_activated(Grave); |
|
201 |
||
202 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
|
203 |
hwform->ui.pageEditTeam->CBFort_activated(Fort); |
|
204 |
||
205 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
206 |
{ |
|
207 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
|
208 |
} |
|
209 |
} |
|
210 |
||
211 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
212 |
{ |
|
213 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
|
336 | 214 |
difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); |
184 | 215 |
for(int i = 0; i < 8; i++) |
216 |
{ |
|
217 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
|
1240 | 218 |
HHHat[i] = hwform->ui.pageEditTeam->HHHats[i]->currentText(); |
184 | 219 |
} |
220 |
||
221 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
|
222 |
Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
223 |
for(int i = 0; i < BINDS_NUMBER; i++) |
184 | 224 |
{ |
225 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText(); |
|
226 |
} |
|
227 |
} |
|
228 |
||
341 | 229 |
QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const |
184 | 230 |
{ |
239 | 231 |
QStringList sl; |
605 | 232 |
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
|
233 |
|
352 | 234 |
if (m_netID) |
341 | 235 |
sl.push_back("erdriven"); |
236 |
||
237 |
sl.push_back(QString("egrave " + Grave)); |
|
238 |
sl.push_back(QString("efort " + Fort)); |
|
239 |
||
352 | 240 |
if (!m_netID) |
341 | 241 |
for(int i = 0; i < BINDS_NUMBER; i++) |
242 |
sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
|
243 |
||
244 |
for (int t = 0; t < numHedgehogs; t++) |
|
605 | 245 |
sl.push_back(QString("eaddhh %1 %2 %3") |
319 | 246 |
.arg(QString::number(difficulty), |
605 | 247 |
QString::number(InitHealth), |
248 |
HHName[t])); |
|
239 | 249 |
return sl; |
184 | 250 |
} |
251 |
||
352 | 252 |
bool HWTeam::isNetTeam() const |
253 |
{ |
|
254 |
return m_netID!=0; |
|
255 |
} |
|
256 |
||
257 |
unsigned int HWTeam::getNetID() const |
|
258 |
{ |
|
259 |
return m_netID; |
|
260 |
} |
|
261 |
||
184 | 262 |
bool HWTeam::operator==(const HWTeam& t1) const { |
352 | 263 |
return TeamName==t1.TeamName && m_netID==t1.m_netID; |
184 | 264 |
} |
265 |
||
266 |
bool HWTeam::operator<(const HWTeam& t1) const { |
|
352 | 267 |
return m_netID<t1.m_netID || TeamName<t1.TeamName; // if names are equal - test if it is net team |
184 | 268 |
} |