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.
20 #ifndef CONTENT_CAO_HEADER
21 #define CONTENT_CAO_HEADER
24 #include "irrlichttypes_extrabloated.h"
25 #include "clientobject.h"
26 #include "object_properties.h"
27 #include "itemgroup.h"
28 #include "constants.h"
38 struct SmoothTranslator
45 f32 anim_time_counter = 0;
46 bool aim_is_end = true;
48 SmoothTranslator() {};
52 void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
54 void translate(f32 dtime);
57 class GenericCAO : public ClientActiveObject
60 // Only set at initialization
61 std::string m_name = "";
62 bool m_is_player = false;
63 bool m_is_local_player = false;
64 // Property-ish things
65 ObjectProperties m_prop;
67 scene::ISceneManager *m_smgr = nullptr;
68 IrrlichtDevice *m_irr = nullptr;
69 Client *m_client = nullptr;
70 aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
71 scene::IMeshSceneNode *m_meshnode = nullptr;
72 scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
73 WieldMeshSceneNode *m_wield_meshnode = nullptr;
74 scene::IBillboardSceneNode *m_spritenode = nullptr;
75 Nametag *m_nametag = nullptr;
76 v3f m_position = v3f(0.0f, 10.0f * BS, 0);
81 SmoothTranslator pos_translator;
82 // Spritesheet/animation stuff
83 v2f m_tx_size = v2f(1,1);
85 bool m_initial_tx_basepos_set = false;
86 bool m_tx_select_horiz_by_yawpitch = false;
87 v2s32 m_animation_range;
88 int m_animation_speed = 15;
89 int m_animation_blend = 0;
90 bool m_animation_loop = true;
91 // stores position and rotation for each bone name
92 std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
93 std::string m_attachment_bone = "";
94 v3f m_attachment_position;
95 v3f m_attachment_rotation;
96 bool m_attached_to_local = false;
98 int m_anim_num_frames = 1;
99 float m_anim_framelength = 0.2f;
100 float m_anim_timer = 0.0f;
101 ItemGroupList m_armor_groups;
102 float m_reset_textures_timer = -1.0f;
103 // stores texture modifier before punch update
104 std::string m_previous_texture_modifier = "";
105 // last applied texture modifier
106 std::string m_current_texture_modifier = "";
107 bool m_visuals_expired = false;
108 float m_step_distance_counter = 0.0f;
109 u8 m_last_light = 255;
110 bool m_is_visible = false;
112 std::vector<u16> m_children;
115 GenericCAO(Client *client, ClientEnvironment *env);
119 static ClientActiveObject* create(Client *client, ClientEnvironment *env)
121 return new GenericCAO(client, env);
124 inline ActiveObjectType getType() const
126 return ACTIVEOBJECT_TYPE_GENERIC;
129 void initialize(const std::string &data);
131 void processInitData(const std::string &data);
133 ClientActiveObject *getParent();
135 bool getCollisionBox(aabb3f *toset) const;
137 bool collideWithObjects() const;
139 aabb3f *getSelectionBox();
142 inline float getYaw() const
147 scene::ISceneNode *getSceneNode();
149 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
151 inline bool isLocalPlayer() const
153 return m_is_local_player;
156 inline bool isVisible() const
161 inline void setVisible(bool toset)
163 m_is_visible = toset;
166 void setChildrenVisible(bool toset);
168 void setAttachments();
170 void removeFromScene(bool permanent);
172 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
173 IrrlichtDevice *irr);
175 inline void expireVisuals()
177 m_visuals_expired = true;
180 void updateLight(u8 light_at_pos);
182 void updateLightNoCheck(u8 light_at_pos);
184 v3s16 getLightPosition();
186 void updateNodePos();
188 void step(float dtime, ClientEnvironment *env);
190 void updateTexturePos();
192 // std::string copy is mandatory as mod can be a class member and there is a swap
193 // on those class members
194 void updateTextures(std::string mod);
196 void updateAnimation();
198 void updateBonePosition();
200 void updateAttachments();
202 void processMessage(const std::string &data);
204 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
205 float time_from_last_punch=1000000);
207 std::string debugInfoText();
209 std::string infoText()
211 return m_prop.infotext;