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