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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
#pragma once
#include "StarPeriodic.hpp"
#include "StarPeriodicFunction.hpp"
#include "StarNetElementSystem.hpp"
#include "StarLuaComponents.hpp"
#include "StarLuaAnimationComponent.hpp"
#include "StarTileEntity.hpp"
#include "StarStatusEffectEntity.hpp"
#include "StarSet.hpp"
#include "StarColor.hpp"
#include "StarScriptedEntity.hpp"
#include "StarChattyEntity.hpp"
#include "StarWireEntity.hpp"
#include "StarInspectableEntity.hpp"
#include "StarNetworkedAnimator.hpp"
#include "StarDamageTypes.hpp"
#include "StarEntityRendering.hpp"
namespace Star {
STAR_CLASS(AudioInstance);
STAR_CLASS(ObjectDatabase);
STAR_STRUCT(ObjectConfig);
STAR_STRUCT(ObjectOrientation);
STAR_CLASS(Object);
class Object
: public virtual TileEntity,
public virtual StatusEffectEntity,
public virtual ScriptedEntity,
public virtual ChattyEntity,
public virtual InspectableEntity,
public virtual WireEntity {
public:
Object(ObjectConfigConstPtr config, Json const& parameters = JsonObject());
Json diskStore() const;
ByteArray netStore(NetCompatibilityRules rules = {});
virtual EntityType entityType() const override;
virtual ClientEntityMode clientEntityMode() const override;
virtual void init(World* world, EntityId entityId, EntityMode mode) override;
virtual void uninit() override;
virtual Vec2F position() const override;
virtual RectF metaBoundBox() const override;
virtual pair<ByteArray, uint64_t> writeNetState(uint64_t fromVersion = 0, NetCompatibilityRules rules = {}) override;
virtual void readNetState(ByteArray data, float interpolationTime = 0.0f, NetCompatibilityRules rules = {}) override;
virtual String description() const override;
virtual bool inspectable() const override;
virtual Maybe<String> inspectionLogName() const override;
virtual Maybe<String> inspectionDescription(String const& species) const override;
virtual List<LightSource> lightSources() const override;
virtual bool shouldDestroy() const override;
virtual void destroy(RenderCallback* renderCallback) override;
virtual void update(float dt, uint64_t currentStep) override;
virtual void render(RenderCallback* renderCallback) override;
virtual void renderLightSources(RenderCallback* renderCallback) override;
virtual bool checkBroken() override;
virtual Vec2I tilePosition() const override;
virtual List<Vec2I> spaces() const override;
virtual List<MaterialSpace> materialSpaces() const override;
virtual List<Vec2I> roots() const override;
Direction direction() const;
void setDirection(Direction direction);
// Updates tile position and calls updateOrientation
void setTilePosition(Vec2I const& pos) override;
// Find a new valid orientation for the object
void updateOrientation();
List<Vec2I> anchorPositions() const;
virtual List<Drawable> cursorHintDrawables() const;
String name() const;
String shortDescription() const;
String category() const;
virtual ObjectOrientationPtr currentOrientation() const;
virtual List<PersistentStatusEffect> statusEffects() const override;
virtual PolyF statusEffectArea() const override;
virtual List<DamageSource> damageSources() const override;
virtual Maybe<HitType> queryHit(DamageSource const& source) const override;
Maybe<PolyF> hitPoly() const override;
virtual List<DamageNotification> applyDamage(DamageRequest const& damage) override;
virtual bool damageTiles(List<Vec2I> const& position, Vec2F const& sourcePosition, TileDamage const& tileDamage) override;
RectF interactiveBoundBox() const override;
bool isInteractive() const override;
virtual InteractAction interact(InteractRequest const& request) override;
List<Vec2I> interactiveSpaces() const override;
Maybe<LuaValue> callScript(String const& func, LuaVariadic<LuaValue> const& args) override;
Maybe<LuaValue> evalScript(String const& code) override;
virtual Vec2F mouthPosition() const override;
virtual Vec2F mouthPosition(bool ignoreAdjustments) const override;
virtual List<ChatAction> pullPendingChatActions() override;
void breakObject(bool smash = true);
virtual size_t nodeCount(WireDirection direction) const override;
virtual Vec2I nodePosition(WireNode wireNode) const override;
virtual List<WireConnection> connectionsForNode(WireNode wireNode) const override;
virtual bool nodeState(WireNode wireNode) const override;
virtual void addNodeConnection(WireNode wireNode, WireConnection nodeConnection) override;
virtual void removeNodeConnection(WireNode wireNode, WireConnection nodeConnection) override;
virtual void evaluate(WireCoordinator* coordinator) override;
virtual List<QuestArcDescriptor> offeredQuests() const override;
virtual StringSet turnInQuests() const override;
virtual Vec2F questIndicatorPosition() const override;
Maybe<Json> receiveMessage(ConnectionId sendingConnection, String const& message, JsonArray const& args = {}) override;
// Check, in order, the passed in object parameters, the config parameters,
// and then the orientation parameters for the given key. Returns 'def' if
// no value is found.
Json configValue(String const& name, Json const& def = Json()) const;
ObjectConfigConstPtr config() const;
float liquidFillLevel() const;
bool biomePlaced() const;
using Entity::setUniqueId;
protected:
friend class ObjectDatabase;
// Will be automatically called at appropriate times. Derived classes must
// call base class versions.
virtual void getNetStates(bool initial);
virtual void setNetStates();
virtual void readStoredData(Json const& diskStore);
virtual Json writeStoredData() const;
void setImageKey(String const& name, String const& value);
size_t orientationIndex() const;
virtual void setOrientationIndex(size_t orientationIndex);
PolyF volume() const;
LuaMessageHandlingComponent<LuaStorableComponent<LuaUpdatableComponent<LuaWorldComponent<LuaBaseComponent>>>> m_scriptComponent;
mutable LuaAnimationComponent<LuaUpdatableComponent<LuaWorldComponent<LuaBaseComponent>>> m_scriptedAnimator;
NetElementTopGroup m_netGroup;
NetElementBool m_interactive;
NetElementData<List<MaterialSpace>> m_materialSpaces;
private:
struct InputNode {
Vec2I position;
NetElementData<List<WireConnection>> connections;
NetElementBool state;
};
struct OutputNode {
Vec2I position;
NetElementData<List<WireConnection>> connections;
NetElementBool state;
};
LuaCallbacks makeObjectCallbacks();
LuaCallbacks makeAnimatorObjectCallbacks();
void ensureNetSetup();
List<Drawable> orientationDrawables(size_t orientationIndex) const;
void addChatMessage(String const& message, Json const& config, String const& portrait = "");
void writeOutboundNode(Vec2I outboundNode, bool state);
EntityRenderLayer renderLayer() const;
// Base class render() simply calls all of these in turn.
void renderLights(RenderCallback* renderCallback) const;
void renderParticles(RenderCallback* renderCallback);
void renderSounds(RenderCallback* renderCallback);
Vec2F damageShake() const;
void checkLiquidBroken();
GameTimer m_liquidCheckTimer;
ObjectConfigConstPtr m_config;
NetElementHashMap<String, Json> m_parameters;
NetElementData<Maybe<String>> m_uniqueIdNetState;
NetElementInt m_xTilePosition;
NetElementInt m_yTilePosition;
NetElementEnum<Direction> m_direction;
float m_animationTimer;
int m_currentFrame;
Directives m_directives;
Directives m_colorDirectives;
String m_colorSuffix;
Maybe<PeriodicFunction<float>> m_lightFlickering;
EntityTileDamageStatusPtr m_tileDamageStatus;
bool m_broken;
bool m_unbreakable;
NetElementFloat m_health;
size_t m_orientationIndex;
NetElementSize m_orientationIndexNetState;
NetElementHashMap<String, String> m_netImageKeys;
mutable StringMap<String> m_imageKeys;
void resetEmissionTimers();
List<GameTimer> m_emissionTimers;
NetElementBool m_soundEffectEnabled;
AudioInstancePtr m_soundEffect;
NetElementData<Color> m_lightSourceColor;
Vec2F m_animationPosition;
float m_animationCenterLine;
NetworkedAnimatorPtr m_networkedAnimator;
NetworkedAnimator::DynamicTarget m_networkedAnimatorDynamicTarget;
List<ChatAction> m_pendingChatActions;
NetElementEvent m_newChatMessageEvent;
NetElementString m_chatMessage;
NetElementString m_chatPortrait;
NetElementData<Json> m_chatConfig;
mutable Maybe<pair<size_t, List<Drawable>>> m_orientationDrawablesCache;
List<InputNode> m_inputNodes;
List<OutputNode> m_outputNodes;
NetElementData<List<QuestArcDescriptor>> m_offeredQuests;
NetElementData<StringSet> m_turnInQuests;
NetElementHashMap<String, Json> m_scriptedAnimationParameters;
NetElementData<List<DamageSource>> m_damageSources;
ClientEntityMode m_clientEntityMode;
};
}
|