author | unc0rr |
Sun, 14 Jan 2007 21:51:17 +0000 | |
changeset 337 | a46abb65eb0c |
parent 336 | 82d654db133d |
child 339 | 7535ab6c3820 |
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); |
|
336 | 167 |
hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); |
168 |
hwform->ui.pageEditTeam->CBTeamLvl_activated(difficulty); |
|
184 | 169 |
for(int i = 0; i < 8; i++) |
170 |
{ |
|
171 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
|
172 |
} |
|
173 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
|
174 |
hwform->ui.pageEditTeam->CBGrave_activated(Grave); |
|
175 |
||
176 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
|
177 |
hwform->ui.pageEditTeam->CBFort_activated(Fort); |
|
178 |
||
179 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
180 |
{ |
|
181 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
186 |
{ |
|
187 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
|
336 | 188 |
difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); |
184 | 189 |
for(int i = 0; i < 8; i++) |
190 |
{ |
|
191 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
|
192 |
} |
|
193 |
||
194 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
|
195 |
Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
196 |
for(int i = 0; i < BINDS_NUMBER; i++) |
184 | 197 |
{ |
198 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText(); |
|
199 |
} |
|
200 |
} |
|
201 |
||
319 | 202 |
QStringList HWTeam::TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth, bool netTeam) const |
184 | 203 |
{ |
239 | 204 |
QStringList sl; |
205 |
sl.push_back("eaddteam"); |
|
206 |
sl.push_back(QString("ecolor %1").arg(color)); |
|
207 |
sl.push_back("ename team " + TeamName); |
|
247
07605d2a2024
- Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents:
245
diff
changeset
|
208 |
for (int i = 0; i < hedgehogs; i++) |
239 | 209 |
sl.push_back(QString("ename hh%1 ").arg(i).append(HHName[i])); |
319 | 210 |
if(!netTeam) { |
211 |
sl.push_back(QString("egrave " + Grave)); |
|
212 |
sl.push_back(QString("efort " + Fort)); |
|
213 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
214 |
{ |
|
215 |
sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
|
216 |
} |
|
184 | 217 |
} |
239 | 218 |
for (int t = 0; t < hedgehogs; t++) |
319 | 219 |
sl.push_back(QString("eaddhh %1 %2") |
220 |
.arg(QString::number(difficulty), |
|
221 |
QString::number(InitHealth))); |
|
239 | 222 |
return sl; |
184 | 223 |
} |
224 |
||
225 |
bool HWTeam::operator==(const HWTeam& t1) const { |
|
226 |
return TeamName==t1.TeamName; |
|
227 |
} |
|
228 |
||
229 |
bool HWTeam::operator<(const HWTeam& t1) const { |
|
230 |
return TeamName<t1.TeamName; |
|
231 |
} |