author | nemo |
Mon, 05 Dec 2011 23:52:59 -0500 | |
changeset 6508 | bf5db4517148 |
parent 6060 | fdfc01419815 |
child 6616 | f77bb02b669f |
permissions | -rw-r--r-- |
172 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2006-2007 Ulyanov Igor <iulyanov@gmail.com> |
4 |
* Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
172 | 5 |
* |
184 | 6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
172 | 9 |
* |
184 | 10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
172 | 14 |
* |
184 | 15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
|
4976 | 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
18 |
*/ |
|
172 | 19 |
|
497 | 20 |
#include "hwconsts.h" |
164 | 21 |
#include "hwmap.h" |
1797 | 22 |
|
180
ea83b9e9057f
tcp sockets are incapsulated in TCPBase class now
displacer
parents:
177
diff
changeset
|
23 |
HWMap::HWMap() : |
ea83b9e9057f
tcp sockets are incapsulated in TCPBase class now
displacer
parents:
177
diff
changeset
|
24 |
TCPBase(false) |
164 | 25 |
{ |
26 |
} |
|
27 |
||
168 | 28 |
HWMap::~HWMap() |
29 |
{ |
|
30 |
} |
|
31 |
||
4534 | 32 |
void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData) |
164 | 33 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
34 |
m_seed = seed; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
35 |
templateFilter = filter; |
3133 | 36 |
m_mapgen = mapgen; |
37 |
m_maze_size = maze_size; |
|
4572 | 38 |
if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
39 |
Start(); |
164 | 40 |
} |
41 |
||
5213
a86768368309
make the associate button use the user's settings for loading demos/saves
nemo
parents:
4976
diff
changeset
|
42 |
QStringList HWMap::getArguments() |
177 | 43 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
44 |
QStringList arguments; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
45 |
arguments << cfgdir->absolutePath(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
46 |
arguments << QString("%1").arg(ipc_port); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
47 |
arguments << "landpreview"; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
48 |
return arguments; |
177 | 49 |
} |
50 |
||
51 |
void HWMap::onClientDisconnect() |
|
164 | 52 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
53 |
if (readbuffer.size() == 128 * 32 + 1) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
54 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
55 |
quint8 *buf = (quint8*) readbuffer.constData(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
56 |
QImage im(buf, 256, 128, QImage::Format_Mono); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
57 |
im.setNumColors(2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
58 |
emit HHLimitReceived(buf[128 * 32]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
59 |
emit ImageReceived(im); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
60 |
} |
164 | 61 |
} |
62 |
||
63 |
void HWMap::SendToClientFirst() |
|
64 |
{ |
|
4534 | 65 |
SendIPC(QString("eseed %1").arg(m_seed).toUtf8()); |
66 |
SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8()); |
|
67 |
SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8()); |
|
4489 | 68 |
|
69 |
switch (m_mapgen) |
|
70 |
{ |
|
71 |
case MAPGEN_MAZE: |
|
4534 | 72 |
SendIPC(QString("e$maze_size %1").arg(m_maze_size).toUtf8()); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
73 |
break; |
4489 | 74 |
|
75 |
case MAPGEN_DRAWN: |
|
76 |
{ |
|
77 |
QByteArray data = m_drawMapData; |
|
78 |
while(data.size() > 0) |
|
79 |
{ |
|
80 |
QByteArray tmp = data; |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
81 |
tmp.truncate(200); |
4489 | 82 |
SendIPC("edraw " + tmp); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
83 |
data.remove(0, 200); |
4489 | 84 |
} |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
85 |
break; |
4489 | 86 |
} |
87 |
default: ; |
|
88 |
} |
|
89 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
90 |
SendIPC("!"); |
164 | 91 |
} |