Fix an alone if to be with a missing else
[oweals/minetest.git] / src / content_cao.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #pragma once
21
22 #include <map>
23 #include "irrlichttypes_extrabloated.h"
24 #include "clientobject.h"
25 #include "object_properties.h"
26 #include "itemgroup.h"
27 #include "constants.h"
28
29 class Camera;
30 class Client;
31 struct Nametag;
32
33 /*
34         SmoothTranslator
35 */
36
37 struct SmoothTranslator
38 {
39         v3f vect_old;
40         v3f vect_show;
41         v3f vect_aim;
42         f32 anim_counter = 0;
43         f32 anim_time = 0;
44         f32 anim_time_counter = 0;
45         bool aim_is_end = true;
46
47         SmoothTranslator() = default;
48
49         void init(v3f vect);
50
51         void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
52
53         void translate(f32 dtime);
54 };
55
56 class GenericCAO : public ClientActiveObject
57 {
58 private:
59         // Only set at initialization
60         std::string m_name = "";
61         bool m_is_player = false;
62         bool m_is_local_player = false;
63         // Property-ish things
64         ObjectProperties m_prop;
65         //
66         scene::ISceneManager *m_smgr = nullptr;
67         Client *m_client = nullptr;
68         aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
69         scene::IMeshSceneNode *m_meshnode = nullptr;
70         scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
71         WieldMeshSceneNode *m_wield_meshnode = nullptr;
72         scene::IBillboardSceneNode *m_spritenode = nullptr;
73         Nametag *m_nametag = nullptr;
74         v3f m_position = v3f(0.0f, 10.0f * BS, 0);
75         v3f m_velocity;
76         v3f m_acceleration;
77         float m_yaw = 0.0f;
78         s16 m_hp = 1;
79         SmoothTranslator pos_translator;
80         // Spritesheet/animation stuff
81         v2f m_tx_size = v2f(1,1);
82         v2s16 m_tx_basepos;
83         bool m_initial_tx_basepos_set = false;
84         bool m_tx_select_horiz_by_yawpitch = false;
85         v2s32 m_animation_range;
86         float m_animation_speed = 15.0f;
87         float m_animation_blend = 0.0f;
88         bool m_animation_loop = true;
89         // stores position and rotation for each bone name
90         std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
91         std::string m_attachment_bone = "";
92         v3f m_attachment_position;
93         v3f m_attachment_rotation;
94         bool m_attached_to_local = false;
95         int m_anim_frame = 0;
96         int m_anim_num_frames = 1;
97         float m_anim_framelength = 0.2f;
98         float m_anim_timer = 0.0f;
99         ItemGroupList m_armor_groups;
100         float m_reset_textures_timer = -1.0f;
101         // stores texture modifier before punch update
102         std::string m_previous_texture_modifier = "";
103         // last applied texture modifier
104         std::string m_current_texture_modifier = "";
105         bool m_visuals_expired = false;
106         float m_step_distance_counter = 0.0f;
107         u8 m_last_light = 255;
108         bool m_is_visible = false;
109         s8 m_glow = 0;
110
111         std::vector<u16> m_children;
112
113 public:
114         GenericCAO(Client *client, ClientEnvironment *env);
115
116         ~GenericCAO();
117
118         static ClientActiveObject* create(Client *client, ClientEnvironment *env)
119         {
120                 return new GenericCAO(client, env);
121         }
122
123         inline ActiveObjectType getType() const
124         {
125                 return ACTIVEOBJECT_TYPE_GENERIC;
126         }
127         inline const ItemGroupList &getGroups() const
128         {
129                 return m_armor_groups;
130         }
131         void initialize(const std::string &data);
132
133         void processInitData(const std::string &data);
134
135         ClientActiveObject *getParent() const;
136
137         bool getCollisionBox(aabb3f *toset) const;
138
139         bool collideWithObjects() const;
140
141         virtual bool getSelectionBox(aabb3f *toset) const;
142
143         v3f getPosition();
144         inline float getYaw() const
145         {
146                 return m_yaw;
147         }
148
149         const bool isImmortal();
150
151         scene::ISceneNode *getSceneNode();
152
153         scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
154
155         inline f32 getStepHeight() const
156         {
157                 return m_prop.stepheight;
158         }
159
160         inline bool isLocalPlayer() const
161         {
162                 return m_is_local_player;
163         }
164
165         inline bool isVisible() const
166         {
167                 return m_is_visible;
168         }
169
170         inline void setVisible(bool toset)
171         {
172                 m_is_visible = toset;
173         }
174
175         void setChildrenVisible(bool toset);
176
177         void setAttachments();
178
179         void removeFromScene(bool permanent);
180
181         void addToScene(ITextureSource *tsrc);
182
183         inline void expireVisuals()
184         {
185                 m_visuals_expired = true;
186         }
187
188         void updateLight(u8 light_at_pos);
189
190         void updateLightNoCheck(u8 light_at_pos);
191
192         v3s16 getLightPosition();
193
194         void updateNodePos();
195
196         void step(float dtime, ClientEnvironment *env);
197
198         void updateTexturePos();
199
200         // std::string copy is mandatory as mod can be a class member and there is a swap
201         // on those class members
202         void updateTextures(std::string mod);
203
204         void updateAnimation();
205
206         void updateAnimationSpeed();
207
208         void updateBonePosition();
209
210         void updateAttachments();
211
212         void processMessage(const std::string &data);
213
214         bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
215                         float time_from_last_punch=1000000);
216
217         std::string debugInfoText();
218
219         std::string infoText()
220         {
221                 return m_prop.infotext;
222         }
223 };