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