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