]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_cao.h
Various grammar improvements (#7769)
[dragonfireclient.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 template<typename T>
38 struct SmoothTranslator
39 {
40         T val_old;
41         T val_current;
42         T val_target;
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(T current);
50
51         void update(T new_target, bool is_end_position = false,
52                 float update_interval = -1);
53
54         void translate(f32 dtime);
55 };
56
57 struct SmoothTranslatorWrapped : SmoothTranslator<f32>
58 {
59         void translate(f32 dtime);
60 };
61
62 class GenericCAO : public ClientActiveObject
63 {
64 private:
65         // Only set at initialization
66         std::string m_name = "";
67         bool m_is_player = false;
68         bool m_is_local_player = false;
69         // Property-ish things
70         ObjectProperties m_prop;
71         //
72         scene::ISceneManager *m_smgr = nullptr;
73         Client *m_client = nullptr;
74         aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
75         scene::IMeshSceneNode *m_meshnode = nullptr;
76         scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
77         WieldMeshSceneNode *m_wield_meshnode = nullptr;
78         scene::IBillboardSceneNode *m_spritenode = nullptr;
79         Nametag *m_nametag = nullptr;
80         v3f m_position = v3f(0.0f, 10.0f * BS, 0);
81         v3f m_velocity;
82         v3f m_acceleration;
83         float m_yaw = 0.0f;
84         s16 m_hp = 1;
85         SmoothTranslator<v3f> pos_translator;
86         SmoothTranslatorWrapped yaw_translator;
87         // Spritesheet/animation stuff
88         v2f m_tx_size = v2f(1,1);
89         v2s16 m_tx_basepos;
90         bool m_initial_tx_basepos_set = false;
91         bool m_tx_select_horiz_by_yawpitch = false;
92         v2s32 m_animation_range;
93         float m_animation_speed = 15.0f;
94         float m_animation_blend = 0.0f;
95         bool m_animation_loop = true;
96         // stores position and rotation for each bone name
97         std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
98         std::string m_attachment_bone = "";
99         v3f m_attachment_position;
100         v3f m_attachment_rotation;
101         bool m_attached_to_local = false;
102         int m_anim_frame = 0;
103         int m_anim_num_frames = 1;
104         float m_anim_framelength = 0.2f;
105         float m_anim_timer = 0.0f;
106         ItemGroupList m_armor_groups;
107         float m_reset_textures_timer = -1.0f;
108         // stores texture modifier before punch update
109         std::string m_previous_texture_modifier = "";
110         // last applied texture modifier
111         std::string m_current_texture_modifier = "";
112         bool m_visuals_expired = false;
113         float m_step_distance_counter = 0.0f;
114         u8 m_last_light = 255;
115         bool m_is_visible = false;
116         s8 m_glow = 0;
117
118         std::vector<u16> m_children;
119
120 public:
121         GenericCAO(Client *client, ClientEnvironment *env);
122
123         ~GenericCAO();
124
125         static ClientActiveObject* create(Client *client, ClientEnvironment *env)
126         {
127                 return new GenericCAO(client, env);
128         }
129
130         inline ActiveObjectType getType() const
131         {
132                 return ACTIVEOBJECT_TYPE_GENERIC;
133         }
134         inline const ItemGroupList &getGroups() const
135         {
136                 return m_armor_groups;
137         }
138         void initialize(const std::string &data);
139
140         void processInitData(const std::string &data);
141
142         bool getCollisionBox(aabb3f *toset) const;
143
144         bool collideWithObjects() const;
145
146         virtual bool getSelectionBox(aabb3f *toset) const;
147
148         v3f getPosition();
149         inline float getYaw() const
150         {
151                 return m_yaw;
152         }
153
154         const bool isImmortal();
155
156         scene::ISceneNode *getSceneNode();
157
158         scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
159
160         inline f32 getStepHeight() const
161         {
162                 return m_prop.stepheight;
163         }
164
165         inline bool isLocalPlayer() const
166         {
167                 return m_is_local_player;
168         }
169
170         inline bool isVisible() const
171         {
172                 return m_is_visible;
173         }
174
175         inline void setVisible(bool toset)
176         {
177                 m_is_visible = toset;
178         }
179
180         void setChildrenVisible(bool toset);
181
182         ClientActiveObject *getParent() const;
183
184         void setAttachments();
185
186         void removeFromScene(bool permanent);
187
188         void addToScene(ITextureSource *tsrc);
189
190         inline void expireVisuals()
191         {
192                 m_visuals_expired = true;
193         }
194
195         void updateLight(u8 light_at_pos);
196
197         void updateLightNoCheck(u8 light_at_pos);
198
199         v3s16 getLightPosition();
200
201         void updateNodePos();
202
203         void step(float dtime, ClientEnvironment *env);
204
205         void updateTexturePos();
206
207         // std::string copy is mandatory as mod can be a class member and there is a swap
208         // on those class members... do NOT pass by reference
209         void updateTextures(std::string mod);
210
211         void updateAnimation();
212
213         void updateAnimationSpeed();
214
215         void updateBonePosition();
216
217         void updateAttachments();
218
219         void processMessage(const std::string &data);
220
221         bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
222                         float time_from_last_punch=1000000);
223
224         std::string debugInfoText();
225
226         std::string infoText()
227         {
228                 return m_prop.infotext;
229         }
230 };