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