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"
36 struct SmoothTranslator
43 f32 anim_time_counter;
52 void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
54 void translate(f32 dtime);
59 class GenericCAO : public ClientActiveObject
62 // Only set at initialization
65 bool m_is_local_player;
66 // Property-ish things
67 ObjectProperties m_prop;
69 scene::ISceneManager *m_smgr;
70 IrrlichtDevice *m_irr;
72 aabb3f m_selection_box;
73 scene::IMeshSceneNode *m_meshnode;
74 scene::IAnimatedMeshSceneNode *m_animated_meshnode;
75 WieldMeshSceneNode *m_wield_meshnode;
76 scene::IBillboardSceneNode *m_spritenode;
83 SmoothTranslator pos_translator;
84 // Spritesheet/animation stuff
87 bool m_initial_tx_basepos_set;
88 bool m_tx_select_horiz_by_yawpitch;
89 v2s32 m_animation_range;
90 int m_animation_speed;
91 int m_animation_blend;
92 bool m_animation_loop;
93 UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
94 std::string m_attachment_bone;
95 v3f m_attachment_position;
96 v3f m_attachment_rotation;
97 bool m_attached_to_local;
99 int m_anim_num_frames;
100 float m_anim_framelength;
102 ItemGroupList m_armor_groups;
103 float m_reset_textures_timer;
104 bool m_visuals_expired;
105 float m_step_distance_counter;
109 std::vector<u16> m_children;
112 GenericCAO(IGameDef *gamedef, ClientEnvironment *env);
116 static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
118 return new GenericCAO(gamedef, env);
121 inline ActiveObjectType getType() const
123 return ACTIVEOBJECT_TYPE_GENERIC;
126 void initialize(const std::string &data);
128 void processInitData(const std::string &data);
130 ClientActiveObject *getParent();
132 bool getCollisionBox(aabb3f *toset);
134 bool collideWithObjects();
136 aabb3f *getSelectionBox();
140 scene::ISceneNode *getSceneNode();
142 scene::IMeshSceneNode *getMeshSceneNode();
144 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
146 WieldMeshSceneNode *getWieldMeshSceneNode();
148 scene::IBillboardSceneNode *getSpriteSceneNode();
150 inline bool isPlayer() const
155 inline bool isLocalPlayer() const
157 return m_is_local_player;
160 inline bool isVisible() const
165 inline void setVisible(bool toset)
167 m_is_visible = toset;
170 void setChildrenVisible(bool toset);
172 void setAttachments();
174 void removeFromScene(bool permanent);
176 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
177 IrrlichtDevice *irr);
179 inline void expireVisuals()
181 m_visuals_expired = true;
184 void updateLight(u8 light_at_pos);
186 void updateLightNoCheck(u8 light_at_pos);
188 v3s16 getLightPosition();
190 void updateNodePos();
192 void step(float dtime, ClientEnvironment *env);
194 void updateTexturePos();
196 void updateTextures(const std::string &mod);
198 void updateAnimation();
200 void updateBonePosition();
202 void updateAttachments();
204 void processMessage(const std::string &data);
206 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
207 float time_from_last_punch=1000000);
209 std::string debugInfoText();
211 std::string infoText()
213 return m_prop.infotext;