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