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