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"
33 struct SmoothTranslator
40 f32 anim_time_counter;
49 void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
51 void translate(f32 dtime);
56 class GenericCAO : public ClientActiveObject
59 // Only set at initialization
62 bool m_is_local_player;
64 // Property-ish things
65 ObjectProperties m_prop;
67 scene::ISceneManager *m_smgr;
68 IrrlichtDevice *m_irr;
69 core::aabbox3d<f32> m_selection_box;
70 scene::IMeshSceneNode *m_meshnode;
71 scene::IAnimatedMeshSceneNode *m_animated_meshnode;
72 WieldMeshSceneNode *m_wield_meshnode;
73 scene::IBillboardSceneNode *m_spritenode;
74 scene::ITextSceneNode* m_textnode;
80 SmoothTranslator pos_translator;
81 // Spritesheet/animation stuff
84 bool m_initial_tx_basepos_set;
85 bool m_tx_select_horiz_by_yawpitch;
86 v2s32 m_animation_range;
87 int m_animation_speed;
88 int m_animation_blend;
89 std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
90 std::string m_attachment_bone;
91 v3f m_attachment_position;
92 v3f m_attachment_rotation;
93 bool m_attached_to_local;
95 int m_anim_num_frames;
96 float m_anim_framelength;
98 ItemGroupList m_armor_groups;
99 float m_reset_textures_timer;
100 bool m_visuals_expired;
101 float m_step_distance_counter;
105 std::vector<u16> m_children;
108 GenericCAO(IGameDef *gamedef, ClientEnvironment *env);
112 static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
114 return new GenericCAO(gamedef, env);
117 inline ActiveObjectType getType() const
119 return ACTIVEOBJECT_TYPE_GENERIC;
122 void initialize(const std::string &data);
124 ClientActiveObject *getParent();
126 bool getCollisionBox(aabb3f *toset);
128 bool collideWithObjects();
130 core::aabbox3d<f32>* getSelectionBox();
134 scene::ISceneNode *getSceneNode();
136 scene::IMeshSceneNode *getMeshSceneNode();
138 scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
140 WieldMeshSceneNode *getWieldMeshSceneNode();
142 scene::IBillboardSceneNode *getSpriteSceneNode();
144 inline bool isPlayer() const
149 inline bool isLocalPlayer() const
151 return m_is_local_player;
154 inline bool isVisible() const
159 inline void setVisible(bool toset)
161 m_is_visible = toset;
164 void setAttachments();
166 void removeFromScene(bool permanent);
168 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
169 IrrlichtDevice *irr);
171 inline void expireVisuals()
173 m_visuals_expired = true;
176 void updateLight(u8 light_at_pos);
178 v3s16 getLightPosition();
180 void updateNodePos();
182 void step(float dtime, ClientEnvironment *env);
184 void updateTexturePos();
186 void updateTextures(const std::string &mod);
188 void updateAnimation();
190 void updateBonePosition();
192 void updateAttachments();
194 void processMessage(const std::string &data);
196 bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
197 float time_from_last_punch=1000000);
199 std::string debugInfoText();