author | alfadur |
Wed, 07 Aug 2019 17:28:54 +0300 | |
changeset 15310 | 0076bf602969 |
parent 14280 | 61bc44de2b4c |
permissions | -rw-r--r-- |
14159
8354b390f1a2
Some refactoring of qmlfrontend. It now shows land preview generated by hedgewars-engine
unC0Rr
parents:
14148
diff
changeset
|
1 |
#include "game_config.h" |
14148 | 2 |
|
14279 | 3 |
#include <QtEndian> |
4 |
||
14278
645e4591361f
Send seed to engine to receive random map previews
unC0Rr
parents:
14159
diff
changeset
|
5 |
GameConfig::GameConfig() {} |
14148 | 6 |
|
7 |
const char** GameConfig::argv() const { |
|
8 |
m_argv.resize(m_arguments.size()); |
|
9 |
||
10 |
for (int i = 0; i < m_arguments.size(); ++i) |
|
11 |
m_argv[i] = m_arguments[i].data(); |
|
12 |
||
13 |
return m_argv.data(); |
|
14 |
} |
|
15 |
||
16 |
int GameConfig::argc() const { return m_arguments.size(); } |
|
17 |
||
18 |
const QList<QByteArray> GameConfig::config() const { |
|
19 |
QList<QByteArray> cfg = m_cfg; |
|
20 |
cfg.append("\x01!"); |
|
21 |
return cfg; |
|
22 |
} |
|
23 |
||
24 |
void GameConfig::clear() { |
|
25 |
m_arguments.clear(); |
|
26 |
m_cfg.clear(); |
|
27 |
} |
|
28 |
||
29 |
void GameConfig::cmdSeed(const QByteArray& seed) { cfgAppend("eseed " + seed); } |
|
30 |
||
31 |
void GameConfig::cmdTheme(const QByteArray& theme) { |
|
32 |
cfgAppend("e$theme " + theme); |
|
33 |
} |
|
34 |
||
35 |
void GameConfig::cmdMapgen(int mapgen) { |
|
36 |
cfgAppend("e$mapgen " + QByteArray::number(mapgen)); |
|
37 |
} |
|
38 |
||
39 |
void GameConfig::cmdTeam(const Team& team) { |
|
40 |
cfgAppend("eaddteam <hash> " + team.color + " " + team.name); |
|
41 |
||
42 |
for (const Hedgehog& h : team.hedgehogs()) { |
|
43 |
cfgAppend("eaddhh " + QByteArray::number(h.level) + " " + |
|
44 |
QByteArray::number(h.hp) + " " + h.name); |
|
45 |
cfgAppend("ehat " + h.hat); |
|
46 |
} |
|
47 |
cfgAppend( |
|
48 |
"eammloadt 9391929422199121032235111001200000000211100101011111000102"); |
|
49 |
cfgAppend( |
|
50 |
"eammprob 0405040541600655546554464776576666666155510101115411111114"); |
|
51 |
cfgAppend( |
|
52 |
"eammdelay 0000000000000205500000040007004000000000220000000600020000"); |
|
53 |
cfgAppend( |
|
54 |
"eammreinf 1311110312111111123114111111111111111211111111111111111111"); |
|
55 |
cfgAppend("eammstore"); |
|
56 |
} |
|
57 |
||
58 |
void GameConfig::cfgAppend(const QByteArray& cmd) { |
|
14279 | 59 |
Q_ASSERT(cmd.size() <= 49215); |
14148 | 60 |
|
14280
61bc44de2b4c
It was bad idea to store QByteArray referencing memory on stack
unC0Rr
parents:
14279
diff
changeset
|
61 |
QByteArray sizeBytes; |
14279 | 62 |
if (cmd.size() < 64) { |
63 |
quint8 len = static_cast<quint8>(cmd.size()); |
|
14280
61bc44de2b4c
It was bad idea to store QByteArray referencing memory on stack
unC0Rr
parents:
14279
diff
changeset
|
64 |
sizeBytes = QByteArray::fromRawData(reinterpret_cast<const char*>(&len), 1); |
14279 | 65 |
} else { |
66 |
quint16 size = static_cast<quint16>(cmd.size()) - 64; |
|
67 |
size = (size / 256 + 64) * 256 + size & 0xff; |
|
68 |
quint16 size_be = qToBigEndian(size); |
|
69 |
||
14280
61bc44de2b4c
It was bad idea to store QByteArray referencing memory on stack
unC0Rr
parents:
14279
diff
changeset
|
70 |
sizeBytes = |
61bc44de2b4c
It was bad idea to store QByteArray referencing memory on stack
unC0Rr
parents:
14279
diff
changeset
|
71 |
QByteArray::fromRawData(reinterpret_cast<const char*>(&size_be), 2); |
14279 | 72 |
} |
73 |
||
14280
61bc44de2b4c
It was bad idea to store QByteArray referencing memory on stack
unC0Rr
parents:
14279
diff
changeset
|
74 |
m_cfg.append(sizeBytes + cmd); |
14148 | 75 |
} |