3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "irrlichttypes_extrabloated.h"
24 #include "clientobject.h"
25 #include "object_properties.h"
26 #include "itemgroup.h"
27 #include "constants.h"
38 struct SmoothTranslator
44 f32 anim_time_counter = 0;
45 bool aim_is_end = true;
47 SmoothTranslator() = default;
51 void update(T new_target, bool is_end_position = false,
52 float update_interval = -1);
54 void translate(f32 dtime);
57 struct SmoothTranslatorWrapped : SmoothTranslator<f32>
59 void translate(f32 dtime);
62 class GenericCAO : public ClientActiveObject
65 // Only set at initialization
66 std::string m_name = "";
67 bool m_is_player = false;
68 bool m_is_local_player = false;
69 // Property-ish things
70 ObjectProperties m_prop;
72 scene::ISceneManager *m_smgr = nullptr;
73 Client *m_client = nullptr;
74 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
75 scene::IMeshSceneNode *m_meshnode = nullptr;
76 scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
77 WieldMeshSceneNode *m_wield_meshnode = nullptr;
78 scene::IBillboardSceneNode *m_spritenode = nullptr;
79 Nametag *m_nametag = nullptr;
80 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
85 SmoothTranslator<v3f> pos_translator;
86 SmoothTranslatorWrapped yaw_translator;
87 // Spritesheet/animation stuff
88 v2f m_tx_size = v2f(1,1);
90 bool m_initial_tx_basepos_set = false;
91 bool m_tx_select_horiz_by_yawpitch = false;
92 v2s32 m_animation_range;
93 float m_animation_speed = 15.0f;
94 float m_animation_blend = 0.0f;
95 bool m_animation_loop = true;
96 // stores position and rotation for each bone name
97 std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
98 std::string m_attachment_bone = "";
99 v3f m_attachment_position;
100 v3f m_attachment_rotation;
101 bool m_attached_to_local = false;
102 int m_anim_frame = 0;
103 int m_anim_num_frames = 1;
104 float m_anim_framelength = 0.2f;
105 float m_anim_timer = 0.0f;
106 ItemGroupList m_armor_groups;
107 float m_reset_textures_timer = -1.0f;
108 // stores texture modifier before punch update
109 std::string m_previous_texture_modifier = "";
110 // last applied texture modifier
111 std::string m_current_texture_modifier = "";
112 bool m_visuals_expired = false;
113 float m_step_distance_counter = 0.0f;
114 u8 m_last_light = 255;
115 bool m_is_visible = false;
118 std::vector<u16> m_children;
121 GenericCAO(Client *client, ClientEnvironment *env);
125 static ClientActiveObject* create(Client *client, ClientEnvironment *env)
127 return new GenericCAO(client, env);
130 inline ActiveObjectType getType() const
132 return ACTIVEOBJECT_TYPE_GENERIC;
134 inline const ItemGroupList &getGroups() const
136 return m_armor_groups;
138 void initialize(const std::string &data);
140 void processInitData(const std::string &data);
142 bool getCollisionBox(aabb3f *toset) const;
144 bool collideWithObjects() const;
146 virtual bool getSelectionBox(aabb3f *toset) const;
149 inline float getYaw() const
154 const bool isImmortal();
156 scene::ISceneNode *getSceneNode();
158 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
160 inline f32 getStepHeight() const
162 return m_prop.stepheight;
165 inline bool isLocalPlayer() const
167 return m_is_local_player;
170 inline bool isVisible() const
175 inline void setVisible(bool toset)
177 m_is_visible = toset;
180 void setChildrenVisible(bool toset);
182 ClientActiveObject *getParent() const;
184 void setAttachments();
186 void removeFromScene(bool permanent);
188 void addToScene(ITextureSource *tsrc);
190 inline void expireVisuals()
192 m_visuals_expired = true;
195 void updateLight(u8 light_at_pos);
197 void updateLightNoCheck(u8 light_at_pos);
199 v3s16 getLightPosition();
201 void updateNodePos();
203 void step(float dtime, ClientEnvironment *env);
205 void updateTexturePos();
207 // std::string copy is mandatory as mod can be a class member and there is a swap
208 // on those class members... do NOT pass by reference
209 void updateTextures(std::string mod);
211 void updateAnimation();
213 void updateAnimationSpeed();
215 void updateBonePosition();
217 void updateAttachments();
219 void processMessage(const std::string &data);
221 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
222 float time_from_last_punch=1000000);
224 std::string debugInfoText();
226 std::string infoText()
228 return m_prop.infotext;