author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 128 | 223522298250 |
child 184 | f97a7a3dc8f6 |
permissions | -rw-r--r-- |
26 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
128 | 3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
26 | 4 |
* |
183 | 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 |
|
26 | 8 |
* |
183 | 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. |
|
26 | 13 |
* |
183 | 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 |
|
26 | 17 |
*/ |
18 |
||
19 |
#include <QFile> |
|
20 |
#include <QTextStream> |
|
88 | 21 |
#include <QApplication> |
26 | 22 |
#include "team.h" |
23 |
#include "hwform.h" |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
24 |
#include "predefteams.h" |
87 | 25 |
#include "pages.h" |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
88
diff
changeset
|
26 |
#include "hwconsts.h" |
26 | 27 |
|
116 | 28 |
HWTeam::HWTeam(const QString & teamname) |
26 | 29 |
{ |
30 |
TeamName = teamname; |
|
31 |
for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i); |
|
32 |
Grave = "Simple"; |
|
33 |
Fort = "Barrelhouse"; |
|
34 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
35 |
{ |
|
36 |
binds[i].action = cbinds[i].action; |
|
37 |
binds[i].strbind = cbinds[i].strbind; |
|
38 |
} |
|
39 |
} |
|
40 |
||
116 | 41 |
HWTeam::HWTeam(quint8 num) |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
42 |
{ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
43 |
num %= PREDEFTEAMS_COUNT; |
88 | 44 |
TeamName = QApplication::translate("teams", pteams[num].TeamName); |
45 |
HHName[0] = QApplication::translate("teams", pteams[num].hh0name); |
|
46 |
HHName[1] = QApplication::translate("teams", pteams[num].hh1name); |
|
47 |
HHName[2] = QApplication::translate("teams", pteams[num].hh2name); |
|
48 |
HHName[3] = QApplication::translate("teams", pteams[num].hh3name); |
|
49 |
HHName[4] = QApplication::translate("teams", pteams[num].hh4name); |
|
50 |
HHName[5] = QApplication::translate("teams", pteams[num].hh5name); |
|
51 |
HHName[6] = QApplication::translate("teams", pteams[num].hh6name); |
|
52 |
HHName[7] = QApplication::translate("teams", pteams[num].hh7name); |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
53 |
Grave = pteams[num].Grave; |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
54 |
Fort = pteams[num].Fort; |
87 | 55 |
for(int i = 0; i < BINDS_NUMBER; i++) |
56 |
{ |
|
57 |
binds[i].action = cbinds[i].action; |
|
58 |
binds[i].strbind = cbinds[i].strbind; |
|
59 |
} |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
60 |
} |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
61 |
|
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
62 |
|
26 | 63 |
bool HWTeam::LoadFromFile() |
64 |
{ |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
88
diff
changeset
|
65 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
26 | 66 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
67 |
QTextStream stream(&cfgfile); |
|
68 |
stream.setCodec("UTF-8"); |
|
69 |
QString str; |
|
70 |
QString action; |
|
71 |
||
72 |
while (!stream.atEnd()) |
|
73 |
{ |
|
74 |
str = stream.readLine(); |
|
75 |
if (str.startsWith(";")) continue; |
|
76 |
if (str.startsWith("name team ")) |
|
77 |
{ |
|
78 |
str.remove(0, 10); |
|
79 |
TeamName = str; |
|
80 |
} else |
|
81 |
if (str.startsWith("name hh")) |
|
82 |
{ |
|
83 |
str.remove(0, 7); |
|
84 |
long i = str.left(1).toLong(); |
|
85 |
if ((i < 0) || (i > 7)) continue; |
|
86 |
str.remove(0, 2); |
|
87 |
HHName[i] = str; |
|
88 |
} else |
|
89 |
if (str.startsWith("grave ")) |
|
90 |
{ |
|
91 |
str.remove(0, 6); |
|
92 |
Grave = str; |
|
93 |
} else |
|
94 |
if (str.startsWith("fort ")) |
|
95 |
{ |
|
96 |
str.remove(0, 5); |
|
97 |
Fort = str; |
|
98 |
} else |
|
99 |
if (str.startsWith("bind ")) |
|
100 |
{ |
|
101 |
str.remove(0, 5); |
|
102 |
action = str.section(' ', 1); |
|
103 |
str = str.section(' ', 0, 0); |
|
104 |
str.truncate(15); |
|
105 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
106 |
if (action == binds[i].action) |
|
107 |
{ |
|
108 |
binds[i].strbind = str; |
|
109 |
break; |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
cfgfile.close(); |
|
114 |
return true; |
|
115 |
} |
|
116 |
||
117 |
bool HWTeam::SaveToFile() |
|
118 |
{ |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
88
diff
changeset
|
119 |
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg"); |
26 | 120 |
if (!cfgfile.open(QIODevice::WriteOnly)) return false; |
121 |
QTextStream stream(&cfgfile); |
|
122 |
stream.setCodec("UTF-8"); |
|
123 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
124 |
stream << "name team " << TeamName << endl; |
|
125 |
for (int i = 0; i < 8; i++) |
|
126 |
stream << "name hh" << i << " " << HHName[i] << endl; |
|
127 |
stream << "grave " << Grave << endl; |
|
128 |
stream << "fort " << Fort << endl; |
|
129 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
130 |
{ |
|
131 |
stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; |
|
132 |
} |
|
133 |
cfgfile.close(); |
|
134 |
return true; |
|
135 |
} |
|
136 |
||
137 |
void HWTeam::SetToPage(HWForm * hwform) |
|
138 |
{ |
|
87 | 139 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
26 | 140 |
for(int i = 0; i < 8; i++) |
141 |
{ |
|
87 | 142 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
26 | 143 |
} |
87 | 144 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
145 |
hwform->ui.pageEditTeam->CBGrave_activated(Grave); |
|
26 | 146 |
|
87 | 147 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
148 |
hwform->ui.pageEditTeam->CBFort_activated(Fort); |
|
26 | 149 |
|
150 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
151 |
{ |
|
87 | 152 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
26 | 153 |
} |
154 |
} |
|
155 |
||
156 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
157 |
{ |
|
87 | 158 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
26 | 159 |
for(int i = 0; i < 8; i++) |
160 |
{ |
|
87 | 161 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
26 | 162 |
} |
163 |
||
87 | 164 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
165 |
Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
26 | 166 |
for(int i = 0; i < 8; i++) |
167 |
{ |
|
87 | 168 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText(); |
26 | 169 |
} |
170 |
} |
|
171 |
||
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
172 |
QByteArray HWTeam::IPCTeamInfo() const |
26 | 173 |
{ |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
174 |
QByteArray buf; |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
175 |
#define ADD(a) { \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
176 |
QByteArray strmsg = a.toUtf8(); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
177 |
quint8 sz = strmsg.size(); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
178 |
buf.append(QByteArray((char *)&sz, 1)); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
179 |
buf.append(strmsg); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
180 |
} |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
181 |
|
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
182 |
ADD(QString("ename team " + TeamName)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
183 |
for (int i = 0; i < 8; i++) |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
184 |
ADD(QString("ename hh%1 ").arg(i).append(HHName[i])); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
185 |
ADD(QString("egrave " + Grave)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
186 |
ADD(QString("efort " + Fort)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
187 |
for(int i = 0; i < BINDS_NUMBER; i++) |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
188 |
{ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
189 |
ADD(QString("ebind " + binds[i].strbind + " " + binds[i].action)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
190 |
} |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
191 |
#undef ADD |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
192 |
return buf; |
26 | 193 |
} |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
194 |
|
117 | 195 |
bool HWTeam::operator==(const HWTeam& t1) const { |
196 |
return TeamName==t1.TeamName; |
|
197 |
} |
|
198 |
||
199 |
bool HWTeam::operator<(const HWTeam& t1) const { |
|
200 |
return TeamName<t1.TeamName; |
|
201 |
} |