-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProtocol_4.hpp
80 lines (69 loc) · 2.92 KB
/
Protocol_4.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include "Protocol.hpp"
#include "../Entities/Ejected.hpp"
class Protocol_4 : public Protocol {
public:
Protocol_4(Player *owner):
Protocol(owner) {
}
virtual Buffer &clearAll() {
return Protocol::updateNodes({}, {}, {}, {});
}
virtual Buffer &updateNodes(const std::vector<e_ptr> &eatNodes, const std::vector<e_ptr> &updNodes,
const std::vector<e_ptr> &delNodes, const std::vector<e_ptr> &addNodes) {
buffer.writeUInt8(0x10);
// Eat record
buffer.writeUInt16_LE((unsigned short)eatNodes.size());
for (e_ptr entity : eatNodes) {
buffer.writeUInt32_LE(entity->killerId());
buffer.writeUInt32_LE((unsigned)entity->nodeId());
}
// Add record
for (e_ptr entity : addNodes) {
buffer.writeUInt32_LE((unsigned)entity->nodeId());
buffer.writeInt16_LE((short)entity->position().x);
buffer.writeInt16_LE((short)entity->position().y);
buffer.writeUInt16_LE((unsigned short)entity->radius());
buffer.writeUInt8(entity->color().r); // red
buffer.writeUInt8(entity->color().g); // green
buffer.writeUInt8(entity->color().b); // blue
unsigned char flags = 0; // extendedFlag
if (entity->state & isSpiked)
flags |= 0x01; // has spikes on outline
if (entity->state & isAgitated)
flags |= 0x10;
if (entity->type == Ejected::TYPE)
flags |= 0x20;
buffer.writeUInt8(flags); // flag
if (entity->type == PlayerCell::TYPE)
buffer.writeStrNull_UCS2(entity->owner()->cellNameUCS2());
else
buffer.writeUInt16_LE(0);
}
// Update record
for (e_ptr entity : updNodes) {
buffer.writeUInt32_LE((unsigned)entity->nodeId());
buffer.writeInt16_LE((short)entity->position().x);
buffer.writeInt16_LE((short)entity->position().y);
buffer.writeUInt16_LE((unsigned short)entity->radius());
buffer.writeUInt8(entity->color().r); // red
buffer.writeUInt8(entity->color().g); // green
buffer.writeUInt8(entity->color().b); // blue
unsigned char flags = 0; // extendedFlag
if (entity->state & isSpiked)
flags |= 0x01; // has spikes on outline
if (entity->state & isAgitated)
flags |= 0x10;
if (entity->type == Ejected::TYPE)
flags |= 0x20;
buffer.writeUInt8(flags); // flag
buffer.writeUInt16_LE(0); // name
}
buffer.writeUInt32_LE(0); // stop update record
// Remove record
buffer.writeUInt32_LE((unsigned)delNodes.size());
for (e_ptr entity : delNodes)
buffer.writeUInt32_LE((unsigned)entity->nodeId());
return buffer;
}
};