|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2007 Ulyanov Igor <iulyanov@gmail.com> |
|
4 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
5 * |
|
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 |
|
9 * |
|
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. |
|
14 * |
|
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 |
|
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 */ |
|
19 |
|
20 #include "hwconsts.h" |
|
21 #include "hwmap.h" |
|
22 |
|
23 HWMap::HWMap() : |
|
24 TCPBase(false) |
|
25 { |
|
26 } |
|
27 |
|
28 HWMap::~HWMap() |
|
29 { |
|
30 } |
|
31 |
|
32 void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData) |
|
33 { |
|
34 m_seed = seed; |
|
35 templateFilter = filter; |
|
36 m_mapgen = mapgen; |
|
37 m_maze_size = maze_size; |
|
38 if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; |
|
39 Start(); |
|
40 } |
|
41 |
|
42 QStringList HWMap::getArguments() |
|
43 { |
|
44 QStringList arguments; |
|
45 arguments << cfgdir->absolutePath(); |
|
46 arguments << QString("%1").arg(ipc_port); |
|
47 arguments << "landpreview"; |
|
48 return arguments; |
|
49 } |
|
50 |
|
51 void HWMap::onClientDisconnect() |
|
52 { |
|
53 if (readbuffer.size() == 128 * 32 + 1) |
|
54 { |
|
55 quint8 *buf = (quint8*) readbuffer.constData(); |
|
56 QImage im(buf, 256, 128, QImage::Format_Mono); |
|
57 im.setNumColors(2); |
|
58 emit HHLimitReceived(buf[128 * 32]); |
|
59 emit ImageReceived(im); |
|
60 } |
|
61 } |
|
62 |
|
63 void HWMap::SendToClientFirst() |
|
64 { |
|
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()); |
|
68 |
|
69 switch (m_mapgen) |
|
70 { |
|
71 case MAPGEN_MAZE: |
|
72 SendIPC(QString("e$maze_size %1").arg(m_maze_size).toUtf8()); |
|
73 break; |
|
74 |
|
75 case MAPGEN_DRAWN: |
|
76 { |
|
77 QByteArray data = m_drawMapData; |
|
78 while(data.size() > 0) |
|
79 { |
|
80 QByteArray tmp = data; |
|
81 tmp.truncate(200); |
|
82 SendIPC("edraw " + tmp); |
|
83 data.remove(0, 200); |
|
84 } |
|
85 break; |
|
86 } |
|
87 default: ; |
|
88 } |
|
89 |
|
90 SendIPC("!"); |
|
91 } |