author | unc0rr |
Wed, 26 Jul 2006 12:25:48 +0000 | |
changeset 87 | ff213e443336 |
parent 86 | 664b536a1c27 |
child 88 | 6740a1c4edc9 |
permissions | -rw-r--r-- |
26 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*/ |
|
33 |
||
34 |
#include <QFile> |
|
35 |
#include <QTextStream> |
|
36 |
#include "team.h" |
|
37 |
#include "hwform.h" |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
38 |
#include "gameuiconfig.h" |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
39 |
#include "predefteams.h" |
87 | 40 |
#include "pages.h" |
26 | 41 |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
42 |
HWTeam::HWTeam(const QString & teamname, GameUIConfig * config) |
26 | 43 |
{ |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
44 |
this->config = config; |
26 | 45 |
TeamName = teamname; |
46 |
for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i); |
|
47 |
Grave = "Simple"; |
|
48 |
Fort = "Barrelhouse"; |
|
49 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
50 |
{ |
|
51 |
binds[i].action = cbinds[i].action; |
|
52 |
binds[i].strbind = cbinds[i].strbind; |
|
53 |
} |
|
54 |
} |
|
55 |
||
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
56 |
HWTeam::HWTeam(quint8 num, GameUIConfig * config) |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
57 |
{ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
58 |
this->config = config; |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
59 |
num %= PREDEFTEAMS_COUNT; |
87 | 60 |
TeamName = QObject::tr(pteams[num].TeamName); |
61 |
HHName[0] = QObject::tr(pteams[num].hh0name); |
|
62 |
HHName[1] = QObject::tr(pteams[num].hh1name); |
|
63 |
HHName[2] = QObject::tr(pteams[num].hh2name); |
|
64 |
HHName[3] = QObject::tr(pteams[num].hh3name); |
|
65 |
HHName[4] = QObject::tr(pteams[num].hh4name); |
|
66 |
HHName[5] = QObject::tr(pteams[num].hh5name); |
|
67 |
HHName[6] = QObject::tr(pteams[num].hh6name); |
|
68 |
HHName[7] = QObject::tr(pteams[num].hh7name); |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
69 |
Grave = pteams[num].Grave; |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
70 |
Fort = pteams[num].Fort; |
87 | 71 |
for(int i = 0; i < BINDS_NUMBER; i++) |
72 |
{ |
|
73 |
binds[i].action = cbinds[i].action; |
|
74 |
binds[i].strbind = cbinds[i].strbind; |
|
75 |
} |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
76 |
} |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
77 |
|
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
78 |
|
26 | 79 |
bool HWTeam::LoadFromFile() |
80 |
{ |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
81 |
QFile cfgfile(config->cfgdir.absolutePath() + "/" + TeamName + ".cfg"); |
26 | 82 |
if (!cfgfile.open(QIODevice::ReadOnly)) return false; |
83 |
QTextStream stream(&cfgfile); |
|
84 |
stream.setCodec("UTF-8"); |
|
85 |
QString str; |
|
86 |
QString action; |
|
87 |
||
88 |
while (!stream.atEnd()) |
|
89 |
{ |
|
90 |
str = stream.readLine(); |
|
91 |
if (str.startsWith(";")) continue; |
|
92 |
if (str.startsWith("name team ")) |
|
93 |
{ |
|
94 |
str.remove(0, 10); |
|
95 |
TeamName = str; |
|
96 |
} else |
|
97 |
if (str.startsWith("name hh")) |
|
98 |
{ |
|
99 |
str.remove(0, 7); |
|
100 |
long i = str.left(1).toLong(); |
|
101 |
if ((i < 0) || (i > 7)) continue; |
|
102 |
str.remove(0, 2); |
|
103 |
HHName[i] = str; |
|
104 |
} else |
|
105 |
if (str.startsWith("grave ")) |
|
106 |
{ |
|
107 |
str.remove(0, 6); |
|
108 |
Grave = str; |
|
109 |
} else |
|
110 |
if (str.startsWith("fort ")) |
|
111 |
{ |
|
112 |
str.remove(0, 5); |
|
113 |
Fort = str; |
|
114 |
} else |
|
115 |
if (str.startsWith("bind ")) |
|
116 |
{ |
|
117 |
str.remove(0, 5); |
|
118 |
action = str.section(' ', 1); |
|
119 |
str = str.section(' ', 0, 0); |
|
120 |
str.truncate(15); |
|
121 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
122 |
if (action == binds[i].action) |
|
123 |
{ |
|
124 |
binds[i].strbind = str; |
|
125 |
break; |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
cfgfile.close(); |
|
130 |
return true; |
|
131 |
} |
|
132 |
||
133 |
bool HWTeam::SaveToFile() |
|
134 |
{ |
|
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
135 |
QFile cfgfile(config->cfgdir.absolutePath() + "/" + TeamName + ".cfg"); |
26 | 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 |
} |
|
149 |
cfgfile.close(); |
|
150 |
return true; |
|
151 |
} |
|
152 |
||
153 |
void HWTeam::SetToPage(HWForm * hwform) |
|
154 |
{ |
|
87 | 155 |
hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); |
26 | 156 |
for(int i = 0; i < 8; i++) |
157 |
{ |
|
87 | 158 |
hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]); |
26 | 159 |
} |
87 | 160 |
hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); |
161 |
hwform->ui.pageEditTeam->CBGrave_activated(Grave); |
|
26 | 162 |
|
87 | 163 |
hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); |
164 |
hwform->ui.pageEditTeam->CBFort_activated(Fort); |
|
26 | 165 |
|
166 |
for(int i = 0; i < BINDS_NUMBER; i++) |
|
167 |
{ |
|
87 | 168 |
hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findText(binds[i].strbind)); |
26 | 169 |
} |
170 |
} |
|
171 |
||
172 |
void HWTeam::GetFromPage(HWForm * hwform) |
|
173 |
{ |
|
87 | 174 |
TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); |
26 | 175 |
for(int i = 0; i < 8; i++) |
176 |
{ |
|
87 | 177 |
HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); |
26 | 178 |
} |
179 |
||
87 | 180 |
Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); |
181 |
Fort = hwform->ui.pageEditTeam->CBFort->currentText(); |
|
26 | 182 |
for(int i = 0; i < 8; i++) |
183 |
{ |
|
87 | 184 |
binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->currentText(); |
26 | 185 |
} |
186 |
} |
|
187 |
||
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
188 |
QByteArray HWTeam::IPCTeamInfo() const |
26 | 189 |
{ |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
190 |
QByteArray buf; |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
191 |
#define ADD(a) { \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
192 |
QByteArray strmsg = a.toUtf8(); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
193 |
quint8 sz = strmsg.size(); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
194 |
buf.append(QByteArray((char *)&sz, 1)); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
195 |
buf.append(strmsg); \ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
196 |
} |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
197 |
|
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
198 |
ADD(QString("ename team " + TeamName)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
199 |
for (int i = 0; i < 8; i++) |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
200 |
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
|
201 |
ADD(QString("egrave " + Grave)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
202 |
ADD(QString("efort " + Fort)); |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
203 |
for(int i = 0; i < BINDS_NUMBER; i++) |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
204 |
{ |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
205 |
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
|
206 |
} |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
207 |
#undef ADD |
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
208 |
return buf; |
26 | 209 |
} |
86
664b536a1c27
Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents:
26
diff
changeset
|
210 |