author | koda |
Sat, 22 Jan 2011 01:38:01 +0100 | |
branch | 0.9.15 |
changeset 4765 | adef9ec50d63 |
parent 4572 | 087fdb85e2ef |
child 4976 | 088d40d8aba2 |
permissions | -rw-r--r-- |
172 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2006, 2007 Igor Ulyanov <iulyanov@gmail.com> |
172 | 4 |
* |
184 | 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 |
|
172 | 8 |
* |
184 | 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. |
|
172 | 13 |
* |
184 | 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 */ |
|
172 | 17 |
|
497 | 18 |
#include "hwconsts.h" |
164 | 19 |
#include "hwmap.h" |
1797 | 20 |
|
180
ea83b9e9057f
tcp sockets are incapsulated in TCPBase class now
displacer
parents:
177
diff
changeset
|
21 |
HWMap::HWMap() : |
ea83b9e9057f
tcp sockets are incapsulated in TCPBase class now
displacer
parents:
177
diff
changeset
|
22 |
TCPBase(false) |
164 | 23 |
{ |
24 |
} |
|
25 |
||
168 | 26 |
HWMap::~HWMap() |
27 |
{ |
|
28 |
} |
|
29 |
||
4534 | 30 |
void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData) |
164 | 31 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
32 |
m_seed = seed; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
33 |
templateFilter = filter; |
3133 | 34 |
m_mapgen = mapgen; |
35 |
m_maze_size = maze_size; |
|
4572 | 36 |
if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
37 |
Start(); |
164 | 38 |
} |
39 |
||
177 | 40 |
QStringList HWMap::setArguments() |
41 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
42 |
QStringList arguments; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
43 |
arguments << cfgdir->absolutePath(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
44 |
arguments << QString("%1").arg(ipc_port); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
45 |
arguments << "landpreview"; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
46 |
return arguments; |
177 | 47 |
} |
48 |
||
49 |
void HWMap::onClientDisconnect() |
|
164 | 50 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
51 |
if (readbuffer.size() == 128 * 32 + 1) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
52 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
53 |
quint8 *buf = (quint8*) readbuffer.constData(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
54 |
QImage im(buf, 256, 128, QImage::Format_Mono); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
55 |
im.setNumColors(2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
56 |
emit HHLimitReceived(buf[128 * 32]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
57 |
emit ImageReceived(im); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
58 |
} |
164 | 59 |
} |
60 |
||
61 |
void HWMap::SendToClientFirst() |
|
62 |
{ |
|
4534 | 63 |
SendIPC(QString("eseed %1").arg(m_seed).toUtf8()); |
64 |
SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8()); |
|
65 |
SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8()); |
|
4489 | 66 |
|
67 |
switch (m_mapgen) |
|
68 |
{ |
|
69 |
case MAPGEN_MAZE: |
|
4534 | 70 |
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
|
71 |
break; |
4489 | 72 |
|
73 |
case MAPGEN_DRAWN: |
|
74 |
{ |
|
75 |
QByteArray data = m_drawMapData; |
|
76 |
while(data.size() > 0) |
|
77 |
{ |
|
78 |
QByteArray tmp = data; |
|
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
79 |
tmp.truncate(200); |
4489 | 80 |
SendIPC("edraw " + tmp); |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
81 |
data.remove(0, 200); |
4489 | 82 |
} |
4494
9585435e20f7
Pass hardcoded drawn map from frontend into engine \o/
unc0rr
parents:
4489
diff
changeset
|
83 |
break; |
4489 | 84 |
} |
85 |
default: ; |
|
86 |
} |
|
87 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1797
diff
changeset
|
88 |
SendIPC("!"); |
164 | 89 |
} |