Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/interfaces/StarEntity.cpp
blob: 150fcbddf54ee375ff18b7d8163e2a15b6d846d7 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "StarEntity.hpp"
#include "StarDamageManager.hpp"
#include "StarNetCompatibility.hpp"

namespace Star {

EnumMap<ClientEntityMode> const ClientEntityModeNames{
  {ClientEntityMode::ClientSlaveOnly, "ClientSlaveOnly"},
  {ClientEntityMode::ClientMasterAllowed, "ClientMasterAllowed"},
  {ClientEntityMode::ClientPresenceMaster, "ClientPresenceMaster"}
};

EnumMap<EntityType> const EntityTypeNames{
  {EntityType::Plant, "plant"},
  {EntityType::Object, "object"},
  {EntityType::Vehicle, "vehicle"},
  {EntityType::ItemDrop, "itemDrop"},
  {EntityType::PlantDrop, "plantDrop"},
  {EntityType::Projectile, "projectile"},
  {EntityType::Stagehand, "stagehand"},
  {EntityType::Monster, "monster"},
  {EntityType::Npc, "npc"},
  {EntityType::Player, "player"}
};

Entity::~Entity() {}

void Entity::init(World* world, EntityId entityId, EntityMode mode) {
  if (!world)
    throw EntityException("Entity::init called with null world pointer");
  if (entityId == NullEntityId)
    throw EntityException("Entity::init called with null entity id");
  if (m_world)
    throw EntityException("Entity::init called when already initialized");

  m_world = world;
  m_entityMode = mode;
  m_entityId = entityId;
}

void Entity::uninit() {
  m_world = nullptr;
  m_entityMode = {};
  m_entityId = NullEntityId;
}

pair<ByteArray, uint64_t> Entity::writeNetState(uint64_t fromVersion, NetCompatibilityRules rules) {
  return {ByteArray(), 0};
}

void Entity::readNetState(ByteArray data, float interpolationTime, NetCompatibilityRules rules) {}

void Entity::enableInterpolation(float) {}

void Entity::disableInterpolation() {}

RectF Entity::collisionArea() const {
  return RectF::null();
}

bool Entity::ephemeral() const {
  return false;
}

ClientEntityMode Entity::clientEntityMode() const {
  return ClientEntityMode::ClientSlaveOnly;
}

bool Entity::masterOnly() const {
  return false;
}

String Entity::description() const {
  return "";
}

List<LightSource> Entity::lightSources() const {
  return {};
}

List<DamageSource> Entity::damageSources() const {
  return {};
}

void Entity::hitOther(EntityId, DamageRequest const&) {}

void Entity::damagedOther(DamageNotification const&) {}

Maybe<HitType> Entity::queryHit(DamageSource const&) const {
  return {};
}

Maybe<PolyF> Entity::hitPoly() const {
  return {};
}

List<DamageNotification> Entity::applyDamage(DamageRequest const&) {
  return {};
}

List<DamageNotification> Entity::selfDamageNotifications() {
  return {};
}

bool Entity::shouldDestroy() const {
  return false;
}

void Entity::destroy(RenderCallback*) {}

Maybe<Json> Entity::receiveMessage(ConnectionId, String const&, JsonArray const&) {
  return {};
}

void Entity::update(float, uint64_t) {}

void Entity::render(RenderCallback*) {}

void Entity::renderLightSources(RenderCallback*) {}

EntityId Entity::entityId() const {
  return m_entityId;
}

EntityDamageTeam Entity::getTeam() const {
  return m_team;
}

bool Entity::inWorld() const {
  if (m_world) {
    starAssert(m_world && m_entityId != NullEntityId && m_entityMode);
    return true;
  } else {
    starAssert(!m_world && m_entityId == NullEntityId && !m_entityMode);
    return false;
  }
}

World* Entity::world() const {
  if (!m_world)
    throw EntityException("world() called while uninitialized");

  return m_world;
}

World* Entity::worldPtr() const {
  return m_world;
}

bool Entity::persistent() const {
  return m_persistent;
}

bool Entity::keepAlive() const {
  return m_keepAlive;
}

Maybe<String> Entity::uniqueId() const {
  return m_uniqueId;
}

Maybe<EntityMode> Entity::entityMode() const {
  return m_entityMode;
}

bool Entity::isMaster() const {
  return m_entityMode == EntityMode::Master;
}

bool Entity::isSlave() const {
  return m_entityMode == EntityMode::Slave;
}

Entity::Entity() {
  m_world = nullptr;
  m_entityId = NullEntityId;
  m_persistent = false;
  m_keepAlive = false;
}

void Entity::setPersistent(bool persistent) {
  m_persistent = persistent;
}

void Entity::setKeepAlive(bool keepAlive) {
  m_keepAlive = keepAlive;
}

void Entity::setUniqueId(Maybe<String> uniqueId) {
  m_uniqueId = uniqueId;
}

void Entity::setTeam(EntityDamageTeam newTeam) {
  m_team = newTeam;
}

}