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"
37 struct SmoothTranslator
44 f32 anim_time_counter;
53 void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
55 void translate(f32 dtime);
60 class GenericCAO : public ClientActiveObject
63 // Only set at initialization
66 bool m_is_local_player;
67 // Property-ish things
68 ObjectProperties m_prop;
70 scene::ISceneManager *m_smgr;
71 IrrlichtDevice *m_irr;
73 aabb3f m_selection_box;
74 scene::IMeshSceneNode *m_meshnode;
75 scene::IAnimatedMeshSceneNode *m_animated_meshnode;
76 WieldMeshSceneNode *m_wield_meshnode;
77 scene::IBillboardSceneNode *m_spritenode;
84 SmoothTranslator pos_translator;
85 // Spritesheet/animation stuff
88 bool m_initial_tx_basepos_set;
89 bool m_tx_select_horiz_by_yawpitch;
90 v2s32 m_animation_range;
91 int m_animation_speed;
92 int m_animation_blend;
93 bool m_animation_loop;
94 UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
95 std::string m_attachment_bone;
96 v3f m_attachment_position;
97 v3f m_attachment_rotation;
98 bool m_attached_to_local;
100 int m_anim_num_frames;
101 float m_anim_framelength;
103 ItemGroupList m_armor_groups;
104 float m_reset_textures_timer;
105 bool m_visuals_expired;
106 float m_step_distance_counter;
110 std::vector<u16> m_children;
113 GenericCAO(Client *client, ClientEnvironment *env);
117 static ClientActiveObject* create(Client *client, ClientEnvironment *env)
119 return new GenericCAO(client, env);
122 inline ActiveObjectType getType() const
124 return ACTIVEOBJECT_TYPE_GENERIC;
127 void initialize(const std::string &data);
129 void processInitData(const std::string &data);
131 ClientActiveObject *getParent();
133 bool getCollisionBox(aabb3f *toset) const;
135 bool collideWithObjects();
137 aabb3f *getSelectionBox();
140 inline float getYaw() const
145 scene::ISceneNode *getSceneNode();
147 scene::IMeshSceneNode *getMeshSceneNode();
149 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
151 WieldMeshSceneNode *getWieldMeshSceneNode();
153 scene::IBillboardSceneNode *getSpriteSceneNode();
155 inline bool isPlayer() const
160 inline bool isLocalPlayer() const
162 return m_is_local_player;
165 inline bool isVisible() const
170 inline void setVisible(bool toset)
172 m_is_visible = toset;
175 void setChildrenVisible(bool toset);
177 void setAttachments();
179 void removeFromScene(bool permanent);
181 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
182 IrrlichtDevice *irr);
184 inline void expireVisuals()
186 m_visuals_expired = true;
189 void updateLight(u8 light_at_pos);
191 void updateLightNoCheck(u8 light_at_pos);
193 v3s16 getLightPosition();
195 void updateNodePos();
197 void step(float dtime, ClientEnvironment *env);
199 void updateTexturePos();
201 void updateTextures(const std::string &mod);
203 void updateAnimation();
205 void updateBonePosition();
207 void updateAttachments();
209 void processMessage(const std::string &data);
211 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
212 float time_from_last_punch=1000000);
214 std::string debugInfoText();
216 std::string infoText()
218 return m_prop.infotext;