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