nlist: make selected list accessible globally
[waspsaliva.git] / src / server / unit_sao.h
bloba21e055c567607bd13124b57a1e58666a857f050
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013-2020 Minetest core developers & community
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #pragma once
23 #include "object_properties.h"
24 #include "serveractiveobject.h"
26 class UnitSAO : public ServerActiveObject
28 public:
29 UnitSAO(ServerEnvironment *env, v3f pos);
30 virtual ~UnitSAO() = default;
32 u16 getHP() const { return m_hp; }
33 // Use a function, if isDead can be defined by other conditions
34 bool isDead() const { return m_hp == 0; }
36 // Rotation
37 void setRotation(v3f rotation) { m_rotation = rotation; }
38 const v3f &getRotation() const { return m_rotation; }
39 v3f getRadRotation() { return m_rotation * core::DEGTORAD; }
41 // Deprecated
42 f32 getRadYawDep() const { return (m_rotation.Y + 90.) * core::DEGTORAD; }
44 // Armor groups
45 inline bool isImmortal() const
47 return itemgroup_get(getArmorGroups(), "immortal");
49 void setArmorGroups(const ItemGroupList &armor_groups);
50 const ItemGroupList &getArmorGroups() const;
52 // Animation
53 void setAnimation(v2f frame_range, float frame_speed, float frame_blend,
54 bool frame_loop);
55 void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend,
56 bool *frame_loop);
57 void setAnimationSpeed(float frame_speed);
59 // Bone position
60 void setBonePosition(const std::string &bone, v3f position, v3f rotation);
61 void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
63 // Attachments
64 ServerActiveObject *getParent() const;
65 inline bool isAttached() const { return getParent(); }
66 void setAttachment(int parent_id, const std::string &bone, v3f position,
67 v3f rotation, bool force_visible);
68 void getAttachment(int *parent_id, std::string *bone, v3f *position,
69 v3f *rotation, bool *force_visible) const;
70 void clearChildAttachments();
71 void clearParentAttachment();
72 void addAttachmentChild(int child_id);
73 void removeAttachmentChild(int child_id);
74 const std::unordered_set<int> &getAttachmentChildIds() const;
76 // Object properties
77 ObjectProperties *accessObjectProperties();
78 void notifyObjectPropertiesModified();
79 void sendOutdatedData();
81 // Update packets
82 std::string generateUpdateAttachmentCommand() const;
83 std::string generateUpdateAnimationSpeedCommand() const;
84 std::string generateUpdateAnimationCommand() const;
85 std::string generateUpdateArmorGroupsCommand() const;
86 static std::string generateUpdatePositionCommand(const v3f &position,
87 const v3f &velocity, const v3f &acceleration, const v3f &rotation,
88 bool do_interpolate, bool is_movement_end, f32 update_interval);
89 std::string generateSetPropertiesCommand(const ObjectProperties &prop) const;
90 static std::string generateUpdateBonePositionCommand(const std::string &bone,
91 const v3f &position, const v3f &rotation);
92 void sendPunchCommand();
94 protected:
95 u16 m_hp = 1;
97 v3f m_rotation;
99 ItemGroupList m_armor_groups;
101 // Object properties
102 bool m_properties_sent = true;
103 ObjectProperties m_prop;
105 // Stores position and rotation for each bone name
106 std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
108 int m_attachment_parent_id = 0;
110 private:
111 void onAttach(int parent_id);
112 void onDetach(int parent_id);
114 std::string generatePunchCommand(u16 result_hp) const;
116 // Armor groups
117 bool m_armor_groups_sent = false;
119 // Animation
120 v2f m_animation_range;
121 float m_animation_speed = 0.0f;
122 float m_animation_blend = 0.0f;
123 bool m_animation_loop = true;
124 bool m_animation_sent = false;
125 bool m_animation_speed_sent = false;
127 // Bone positions
128 bool m_bone_position_sent = false;
130 // Attachments
131 std::unordered_set<int> m_attachment_child_ids;
132 std::string m_attachment_bone = "";
133 v3f m_attachment_position;
134 v3f m_attachment_rotation;
135 bool m_attachment_sent = false;
136 bool m_force_visible = false;