Zappy Server
C++ game server: world, rules, scheduler, network
Loading...
Searching...
No Matches
Serializer.cpp
Go to the documentation of this file.
1#include "Serializer.hpp"
2
3static std::string id(int n) { return "#" + std::to_string(n); }
4static std::string n(int v) { return std::to_string(v); }
5static std::string res(const Resources& r)
6{
7 return n(r.food) + " " + n(r.linemate) + " " + n(r.deraumere) + " " + n(r.sibur) + " " +
8 n(r.mendiane) + " " + n(r.phiras) + " " + n(r.thystame);
9}
10
11std::string Serializer::msz(int x, int y) { return "msz " + n(x) + " " + n(y) + "\n"; }
12
13std::string Serializer::bct(int x, int y, const Resources& r)
14{
15 return "bct " + n(x) + " " + n(y) + " " + res(r) + "\n";
16}
17
18std::string Serializer::tna(const std::string& teamName) { return "tna " + teamName + "\n"; }
19
20std::string Serializer::pnw(int pid, int x, int y, Orientation o, int level,
21 const std::string& team)
22{
23 return "pnw " + id(pid) + " " + n(x) + " " + n(y) + " " + n(static_cast<int>(o)) + " " +
24 n(level) + " " + team + "\n";
25}
26
27std::string Serializer::ppo(int pid, int x, int y, Orientation o)
28{
29 return "ppo " + id(pid) + " " + n(x) + " " + n(y) + " " + n(static_cast<int>(o)) + "\n";
30}
31
32std::string Serializer::plv(int pid, int level) { return "plv " + id(pid) + " " + n(level) + "\n"; }
33
34std::string Serializer::pin(int pid, int x, int y, const Resources& r)
35{
36 return "pin " + id(pid) + " " + n(x) + " " + n(y) + " " + res(r) + "\n";
37}
38
39std::string Serializer::pex(int pid) { return "pex " + id(pid) + "\n"; }
40
41std::string Serializer::pbc(int pid, const std::string& msg)
42{
43 return "pbc " + id(pid) + " " + msg + "\n";
44}
45
46std::string Serializer::pic(int x, int y, int level, const std::vector<int>& ids)
47{
48 std::string s = "pic " + n(x) + " " + n(y) + " " + n(level);
49 for (int pid : ids) s += " " + id(pid);
50 return s + "\n";
51}
52
53std::string Serializer::pie(int x, int y, bool success)
54{
55 return "pie " + n(x) + " " + n(y) + " " + (success ? "1" : "0") + "\n";
56}
57
58std::string Serializer::pfk(int pid) { return "pfk " + id(pid) + "\n"; }
59
60std::string Serializer::pdr(int pid, int resourceIndex)
61{
62 return "pdr " + id(pid) + " " + n(resourceIndex) + "\n";
63}
64
65std::string Serializer::pgt(int pid, int resourceIndex)
66{
67 return "pgt " + id(pid) + " " + n(resourceIndex) + "\n";
68}
69
70std::string Serializer::pdi(int pid) { return "pdi " + id(pid) + "\n"; }
71
72std::string Serializer::enw(int eggId, int playerId, int x, int y)
73{
74 return "enw " + id(eggId) + " " + id(playerId) + " " + n(x) + " " + n(y) + "\n";
75}
76
77std::string Serializer::sse(int eggId, const std::string& teamName, int x, int y)
78{
79 return "sse " + id(eggId) + " " + teamName + " " + n(x) + " " + n(y) + "\n";
80}
81
82std::string Serializer::ebo(int eggId) { return "ebo " + id(eggId) + "\n"; }
83std::string Serializer::edi(int eggId) { return "edi " + id(eggId) + "\n"; }
84
85std::string Serializer::sgt(int freq) { return "sgt " + n(freq) + "\n"; }
86std::string Serializer::sst(int freq) { return "sst " + n(freq) + "\n"; }
87std::string Serializer::stu(int seconds, long long ticks)
88{
89 return "stu " + n(seconds) + " " + std::to_string(ticks) + "\n";
90}
91
92std::string Serializer::gwt(const std::string& team, int seconds, long long ticks)
93{
94 return "gwt " + team + " " + n(seconds) + " " + std::to_string(ticks) + "\n";
95}
96
97std::string Serializer::seg(const std::string& team) { return "seg " + team + "\n"; }
98std::string Serializer::smg(const std::string& msg) { return "smg " + msg + "\n"; }
99
100std::string Serializer::suc() { return "suc\n"; }
101std::string Serializer::sbp() { return "sbp\n"; }
Orientation
static std::string id(int n)
Definition Serializer.cpp:3
static std::string res(const Resources &r)
Definition Serializer.cpp:5
static std::string n(int v)
Definition Serializer.cpp:4
Represents the resources available in the game, including food and various minerals.
Definition Resources.hpp:17
int deraumere
Definition Resources.hpp:21
std::string sbp()
Bad command parameter from GUI. Wire: sbp\n
std::string pdr(int id, int resourceIndex)
Player drops resource resourceIndex (0..6). Wire: pdr #N i\n
std::string pin(int id, int x, int y, const Resources &r)
Player inventory. Wire: pin #N X Y q q q q q q q\n
std::string msz(int x, int y)
Map size. Wire: msz X Y\n
std::string sst(int freq)
Reply to "sst": frequency was changed to F. Wire: sst F\n
std::string seg(const std::string &team)
End of game, team won. Wire: seg NAME\n
std::string tna(const std::string &teamName)
Team name (one per team). Wire: tna NAME\n
std::string sgt(int freq)
Reply to "sgt": current time unit frequency. Wire: sgt F\n
std::string pex(int id)
Player expelled (got ejected). Wire: pex #N\n
std::string suc()
Unknown command from GUI (sent on unparseable line). Wire: suc\n
std::string edi(int eggId)
Egg died. Wire: edi #E\n
std::string ebo(int eggId)
Egg hatched, player connects from it. Wire: ebo #E\n
std::string gwt(const std::string &team, int seconds, long long ticks)
std::string bct(int x, int y, const Resources &r)
Tile content (resources on it). Wire: bct X Y q q q q q q q\n
std::string sse(int eggId, const std::string &teamName, int x, int y)
std::string stu(int seconds, long long ticks)
std::string pgt(int id, int resourceIndex)
Player takes resource resourceIndex (0..6). Wire: pgt #N i\n
std::string pfk(int id)
Player lays an egg (fork). Wire: pfk #N\n
std::string pie(int x, int y, bool success)
std::string pbc(int id, const std::string &msg)
Player broadcast. Wire: pbc #N MESSAGE\n
std::string ppo(int id, int x, int y, Orientation o)
Player position. Wire: ppo #N X Y O\n
std::string smg(const std::string &msg)
Server message to all GUIs. Wire: smg MESSAGE\n
std::string pnw(int id, int x, int y, Orientation o, int level, const std::string &team)
New player connected. Wire: pnw #N X Y O L NAME\n (L = level)
std::string pdi(int id)
Player death. Wire: pdi #N\n
std::string enw(int eggId, int playerId, int x, int y)
Egg laid by a player. Wire: enw #E #N X Y\n (E = egg, N = parent)
std::string plv(int id, int level)
Player level. Wire: plv #N L\n
std::string pic(int x, int y, int level, const std::vector< int > &ids)