@@ -106,302 +106,6 @@ class TestSAO : public ServerActiveObject
106
106
// Prototype (registers item for deserialization)
107
107
TestSAO proto_TestSAO (NULL , v3f(0 ,0 ,0 ));
108
108
109
- /*
110
- UnitSAO
111
- */
112
-
113
- UnitSAO::UnitSAO (ServerEnvironment *env, v3f pos):
114
- ServerActiveObject(env, pos)
115
- {
116
- // Initialize something to armor groups
117
- m_armor_groups[" fleshy" ] = 100 ;
118
- }
119
-
120
- ServerActiveObject *UnitSAO::getParent () const
121
- {
122
- if (!m_attachment_parent_id)
123
- return nullptr ;
124
- // Check if the parent still exists
125
- ServerActiveObject *obj = m_env->getActiveObject (m_attachment_parent_id);
126
-
127
- return obj;
128
- }
129
-
130
- void UnitSAO::setArmorGroups (const ItemGroupList &armor_groups)
131
- {
132
- m_armor_groups = armor_groups;
133
- m_armor_groups_sent = false ;
134
- }
135
-
136
- const ItemGroupList &UnitSAO::getArmorGroups () const
137
- {
138
- return m_armor_groups;
139
- }
140
-
141
- void UnitSAO::setAnimation (v2f frame_range, float frame_speed, float frame_blend, bool frame_loop)
142
- {
143
- // store these so they can be updated to clients
144
- m_animation_range = frame_range;
145
- m_animation_speed = frame_speed;
146
- m_animation_blend = frame_blend;
147
- m_animation_loop = frame_loop;
148
- m_animation_sent = false ;
149
- }
150
-
151
- void UnitSAO::getAnimation (v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop)
152
- {
153
- *frame_range = m_animation_range;
154
- *frame_speed = m_animation_speed;
155
- *frame_blend = m_animation_blend;
156
- *frame_loop = m_animation_loop;
157
- }
158
-
159
- void UnitSAO::setAnimationSpeed (float frame_speed)
160
- {
161
- m_animation_speed = frame_speed;
162
- m_animation_speed_sent = false ;
163
- }
164
-
165
- void UnitSAO::setBonePosition (const std::string &bone, v3f position, v3f rotation)
166
- {
167
- // store these so they can be updated to clients
168
- m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
169
- m_bone_position_sent = false ;
170
- }
171
-
172
- void UnitSAO::getBonePosition (const std::string &bone, v3f *position, v3f *rotation)
173
- {
174
- *position = m_bone_position[bone].X ;
175
- *rotation = m_bone_position[bone].Y ;
176
- }
177
-
178
- void UnitSAO::setAttachment (int parent_id, const std::string &bone, v3f position, v3f rotation)
179
- {
180
- // Attachments need to be handled on both the server and client.
181
- // If we just attach on the server, we can only copy the position of the parent. Attachments
182
- // are still sent to clients at an interval so players might see them lagging, plus we can't
183
- // read and attach to skeletal bones.
184
- // If we just attach on the client, the server still sees the child at its original location.
185
- // This breaks some things so we also give the server the most accurate representation
186
- // even if players only see the client changes.
187
-
188
- int old_parent = m_attachment_parent_id;
189
- m_attachment_parent_id = parent_id;
190
- m_attachment_bone = bone;
191
- m_attachment_position = position;
192
- m_attachment_rotation = rotation;
193
- m_attachment_sent = false ;
194
-
195
- if (parent_id != old_parent) {
196
- onDetach (old_parent);
197
- onAttach (parent_id);
198
- }
199
- }
200
-
201
- void UnitSAO::getAttachment (int *parent_id, std::string *bone, v3f *position,
202
- v3f *rotation) const
203
- {
204
- *parent_id = m_attachment_parent_id;
205
- *bone = m_attachment_bone;
206
- *position = m_attachment_position;
207
- *rotation = m_attachment_rotation;
208
- }
209
-
210
- void UnitSAO::clearChildAttachments ()
211
- {
212
- for (int child_id : m_attachment_child_ids) {
213
- // Child can be NULL if it was deleted earlier
214
- if (ServerActiveObject *child = m_env->getActiveObject (child_id))
215
- child->setAttachment (0 , " " , v3f (0 , 0 , 0 ), v3f (0 , 0 , 0 ));
216
- }
217
- m_attachment_child_ids.clear ();
218
- }
219
-
220
- void UnitSAO::clearParentAttachment ()
221
- {
222
- ServerActiveObject *parent = nullptr ;
223
- if (m_attachment_parent_id) {
224
- parent = m_env->getActiveObject (m_attachment_parent_id);
225
- setAttachment (0 , " " , m_attachment_position, m_attachment_rotation);
226
- } else {
227
- setAttachment (0 , " " , v3f (0 , 0 , 0 ), v3f (0 , 0 , 0 ));
228
- }
229
- // Do it
230
- if (parent)
231
- parent->removeAttachmentChild (m_id);
232
- }
233
-
234
- void UnitSAO::addAttachmentChild (int child_id)
235
- {
236
- m_attachment_child_ids.insert (child_id);
237
- }
238
-
239
- void UnitSAO::removeAttachmentChild (int child_id)
240
- {
241
- m_attachment_child_ids.erase (child_id);
242
- }
243
-
244
- const std::unordered_set<int > &UnitSAO::getAttachmentChildIds () const
245
- {
246
- return m_attachment_child_ids;
247
- }
248
-
249
- void UnitSAO::onAttach (int parent_id)
250
- {
251
- if (!parent_id)
252
- return ;
253
-
254
- ServerActiveObject *parent = m_env->getActiveObject (parent_id);
255
-
256
- if (!parent || parent->isGone ())
257
- return ; // Do not try to notify soon gone parent
258
-
259
- if (parent->getType () == ACTIVEOBJECT_TYPE_LUAENTITY) {
260
- // Call parent's on_attach field
261
- m_env->getScriptIface ()->luaentity_on_attach_child (parent_id, this );
262
- }
263
- }
264
-
265
- void UnitSAO::onDetach (int parent_id)
266
- {
267
- if (!parent_id)
268
- return ;
269
-
270
- ServerActiveObject *parent = m_env->getActiveObject (parent_id);
271
- if (getType () == ACTIVEOBJECT_TYPE_LUAENTITY)
272
- m_env->getScriptIface ()->luaentity_on_detach (m_id, parent);
273
-
274
- if (!parent || parent->isGone ())
275
- return ; // Do not try to notify soon gone parent
276
-
277
- if (parent->getType () == ACTIVEOBJECT_TYPE_LUAENTITY)
278
- m_env->getScriptIface ()->luaentity_on_detach_child (parent_id, this );
279
- }
280
-
281
- ObjectProperties* UnitSAO::accessObjectProperties ()
282
- {
283
- return &m_prop;
284
- }
285
-
286
- void UnitSAO::notifyObjectPropertiesModified ()
287
- {
288
- m_properties_sent = false ;
289
- }
290
-
291
- std::string UnitSAO::generateUpdateAttachmentCommand () const
292
- {
293
- std::ostringstream os (std::ios::binary);
294
- // command
295
- writeU8 (os, AO_CMD_ATTACH_TO);
296
- // parameters
297
- writeS16 (os, m_attachment_parent_id);
298
- os << serializeString (m_attachment_bone);
299
- writeV3F32 (os, m_attachment_position);
300
- writeV3F32 (os, m_attachment_rotation);
301
- return os.str ();
302
- }
303
-
304
- std::string UnitSAO::generateUpdateBonePositionCommand (const std::string &bone,
305
- const v3f &position, const v3f &rotation)
306
- {
307
- std::ostringstream os (std::ios::binary);
308
- // command
309
- writeU8 (os, AO_CMD_SET_BONE_POSITION);
310
- // parameters
311
- os << serializeString (bone);
312
- writeV3F32 (os, position);
313
- writeV3F32 (os, rotation);
314
- return os.str ();
315
- }
316
-
317
-
318
- std::string UnitSAO::generateUpdateAnimationSpeedCommand () const
319
- {
320
- std::ostringstream os (std::ios::binary);
321
- // command
322
- writeU8 (os, AO_CMD_SET_ANIMATION_SPEED);
323
- // parameters
324
- writeF32 (os, m_animation_speed);
325
- return os.str ();
326
- }
327
-
328
- std::string UnitSAO::generateUpdateAnimationCommand () const
329
- {
330
- std::ostringstream os (std::ios::binary);
331
- // command
332
- writeU8 (os, AO_CMD_SET_ANIMATION);
333
- // parameters
334
- writeV2F32 (os, m_animation_range);
335
- writeF32 (os, m_animation_speed);
336
- writeF32 (os, m_animation_blend);
337
- // these are sent inverted so we get true when the server sends nothing
338
- writeU8 (os, !m_animation_loop);
339
- return os.str ();
340
- }
341
-
342
-
343
- std::string UnitSAO::generateUpdateArmorGroupsCommand () const
344
- {
345
- std::ostringstream os (std::ios::binary);
346
- writeU8 (os, AO_CMD_UPDATE_ARMOR_GROUPS);
347
- writeU16 (os, m_armor_groups.size ());
348
- for (const auto &armor_group : m_armor_groups) {
349
- os<<serializeString (armor_group.first );
350
- writeS16 (os, armor_group.second );
351
- }
352
- return os.str ();
353
- }
354
-
355
-
356
- std::string UnitSAO::generateUpdatePositionCommand (const v3f &position, const v3f &velocity,
357
- const v3f &acceleration, const v3f &rotation, bool do_interpolate, bool is_movement_end,
358
- f32 update_interval)
359
- {
360
- std::ostringstream os (std::ios::binary);
361
- // command
362
- writeU8 (os, AO_CMD_UPDATE_POSITION);
363
- // pos
364
- writeV3F32 (os, position);
365
- // velocity
366
- writeV3F32 (os, velocity);
367
- // acceleration
368
- writeV3F32 (os, acceleration);
369
- // rotation
370
- writeV3F32 (os, rotation);
371
- // do_interpolate
372
- writeU8 (os, do_interpolate);
373
- // is_end_position (for interpolation)
374
- writeU8 (os, is_movement_end);
375
- // update_interval (for interpolation)
376
- writeF32 (os, update_interval);
377
- return os.str ();
378
- }
379
-
380
-
381
- std::string UnitSAO::generateSetPropertiesCommand (const ObjectProperties &prop) const
382
- {
383
- std::ostringstream os (std::ios::binary);
384
- writeU8 (os, AO_CMD_SET_PROPERTIES);
385
- prop.serialize (os);
386
- return os.str ();
387
- }
388
-
389
- std::string UnitSAO::generatePunchCommand (u16 result_hp) const
390
- {
391
- std::ostringstream os (std::ios::binary);
392
- // command
393
- writeU8 (os, AO_CMD_PUNCHED);
394
- // result_hp
395
- writeU16 (os, result_hp);
396
- return os.str ();
397
- }
398
-
399
- void UnitSAO::sendPunchCommand ()
400
- {
401
- m_messages_out.emplace (getId (), true , generatePunchCommand (getHP ()));
402
- }
403
-
404
-
405
109
/*
406
110
LuaEntitySAO
407
111
*/
0 commit comments