1 #include "gameconfig.h" |
|
2 |
|
3 GameConfig::GameConfig() : m_isPreview(true) { setPreview(m_isPreview); } |
|
4 |
|
5 const char** GameConfig::argv() const { |
|
6 m_argv.resize(m_arguments.size()); |
|
7 |
|
8 for (int i = 0; i < m_arguments.size(); ++i) |
|
9 m_argv[i] = m_arguments[i].data(); |
|
10 |
|
11 return m_argv.data(); |
|
12 } |
|
13 |
|
14 int GameConfig::argc() const { return m_arguments.size(); } |
|
15 |
|
16 const QList<QByteArray> GameConfig::config() const { |
|
17 QList<QByteArray> cfg = m_cfg; |
|
18 cfg.append("\x01!"); |
|
19 return cfg; |
|
20 } |
|
21 |
|
22 void GameConfig::clear() { |
|
23 m_arguments.clear(); |
|
24 m_cfg.clear(); |
|
25 } |
|
26 |
|
27 void GameConfig::cmdSeed(const QByteArray& seed) { cfgAppend("eseed " + seed); } |
|
28 |
|
29 void GameConfig::cmdTheme(const QByteArray& theme) { |
|
30 cfgAppend("e$theme " + theme); |
|
31 } |
|
32 |
|
33 void GameConfig::cmdMapgen(int mapgen) { |
|
34 cfgAppend("e$mapgen " + QByteArray::number(mapgen)); |
|
35 } |
|
36 |
|
37 void GameConfig::cmdTeam(const Team& team) { |
|
38 cfgAppend("eaddteam <hash> " + team.color + " " + team.name); |
|
39 |
|
40 for (const Hedgehog& h : team.hedgehogs()) { |
|
41 cfgAppend("eaddhh " + QByteArray::number(h.level) + " " + |
|
42 QByteArray::number(h.hp) + " " + h.name); |
|
43 cfgAppend("ehat " + h.hat); |
|
44 } |
|
45 cfgAppend( |
|
46 "eammloadt 9391929422199121032235111001200000000211100101011111000102"); |
|
47 cfgAppend( |
|
48 "eammprob 0405040541600655546554464776576666666155510101115411111114"); |
|
49 cfgAppend( |
|
50 "eammdelay 0000000000000205500000040007004000000000220000000600020000"); |
|
51 cfgAppend( |
|
52 "eammreinf 1311110312111111123114111111111111111211111111111111111111"); |
|
53 cfgAppend("eammstore"); |
|
54 } |
|
55 |
|
56 bool GameConfig::isPreview() const { return m_isPreview; } |
|
57 |
|
58 void GameConfig::setPreview(bool isPreview) { |
|
59 m_isPreview = isPreview; |
|
60 |
|
61 m_arguments.clear(); |
|
62 |
|
63 if (m_isPreview) { |
|
64 m_arguments << "" |
|
65 << "--internal" |
|
66 << "--landpreview"; |
|
67 |
|
68 } else { |
|
69 m_arguments << "" |
|
70 << "--internal" |
|
71 << "--nomusic"; |
|
72 } |
|
73 } |
|
74 |
|
75 void GameConfig::cfgAppend(const QByteArray& cmd) { |
|
76 Q_ASSERT(cmd.size() < 256); |
|
77 |
|
78 quint8 len = cmd.size(); |
|
79 m_cfg.append(QByteArray::fromRawData(reinterpret_cast<const char*>(&len), 1) + |
|
80 cmd); |
|
81 } |
|