]> git.lizzy.rs Git - minetest.git/blob - src/content_sao.h
bfce83d02fd1d9a3c8c9da8e2af79aecf23bbc46
[minetest.git] / src / content_sao.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 #ifndef CONTENT_SAO_HEADER
21 #define CONTENT_SAO_HEADER
22
23 #include "serverobject.h"
24 #include "content_object.h"
25 #include "itemgroup.h"
26 #include "player.h"
27 #include "object_properties.h"
28
29 ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
30                 const std::string itemstring);
31
32 /*
33         LuaEntitySAO needs some internals exposed.
34 */
35
36 class LuaEntitySAO : public ServerActiveObject
37 {
38 public:
39         LuaEntitySAO(ServerEnvironment *env, v3f pos,
40                         const std::string &name, const std::string &state);
41         ~LuaEntitySAO();
42         u8 getType() const
43         { return ACTIVEOBJECT_TYPE_LUAENTITY; }
44         u8 getSendType() const
45         { return ACTIVEOBJECT_TYPE_GENERIC; }
46         virtual void addedToEnvironment(u32 dtime_s);
47         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
48                         const std::string &data);
49         bool isAttached();
50         void step(float dtime, bool send_recommended);
51         std::string getClientInitializationData(u16 protocol_version);
52         std::string getStaticData();
53         int punch(v3f dir,
54                         const ToolCapabilities *toolcap=NULL,
55                         ServerActiveObject *puncher=NULL,
56                         float time_from_last_punch=1000000);
57         void rightClick(ServerActiveObject *clicker);
58         void setPos(v3f pos);
59         void moveTo(v3f pos, bool continuous);
60         float getMinimumSavedMovement();
61         std::string getDescription();
62         void setHP(s16 hp);
63         s16 getHP() const;
64         void setArmorGroups(const ItemGroupList &armor_groups);
65         void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
66         void setBonePosition(std::string bone, v3f position, v3f rotation);
67         void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
68         ObjectProperties* accessObjectProperties();
69         void notifyObjectPropertiesModified();
70         /* LuaEntitySAO-specific */
71         void setVelocity(v3f velocity);
72         v3f getVelocity();
73         void setAcceleration(v3f acceleration);
74         v3f getAcceleration();
75         void setYaw(float yaw);
76         float getYaw();
77         void setTextureMod(const std::string &mod);
78         void setSprite(v2s16 p, int num_frames, float framelength,
79                         bool select_horiz_by_yawpitch);
80         std::string getName();
81         bool getCollisionBox(aabb3f *toset);
82 private:
83         std::string getPropertyPacket();
84         void sendPosition(bool do_interpolate, bool is_movement_end);
85
86         std::string m_init_name;
87         std::string m_init_state;
88         bool m_registered;
89         struct ObjectProperties m_prop;
90         
91         s16 m_hp;
92         v3f m_velocity;
93         v3f m_acceleration;
94         float m_yaw;
95         ItemGroupList m_armor_groups;
96         
97         bool m_properties_sent;
98         float m_last_sent_yaw;
99         v3f m_last_sent_position;
100         v3f m_last_sent_velocity;
101         float m_last_sent_position_timer;
102         float m_last_sent_move_precision;
103         bool m_armor_groups_sent;
104
105         v2f m_animation_range;
106         float m_animation_speed;
107         float m_animation_blend;
108         bool m_animation_sent;
109
110         std::map<std::string, core::vector2d<v3f> > m_bone_position;
111         bool m_bone_position_sent;
112
113         int m_attachment_parent_id;
114         std::string m_attachment_bone;
115         v3f m_attachment_position;
116         v3f m_attachment_rotation;
117         bool m_attachment_sent;
118 };
119
120 /*
121         PlayerSAO needs some internals exposed.
122 */
123
124 class PlayerSAO : public ServerActiveObject
125 {
126 public:
127         PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
128                         const std::set<std::string> &privs, bool is_singleplayer);
129         ~PlayerSAO();
130         u8 getType() const
131         { return ACTIVEOBJECT_TYPE_PLAYER; }
132         u8 getSendType() const
133         { return ACTIVEOBJECT_TYPE_GENERIC; }
134         std::string getDescription();
135
136         /*
137                 Active object <-> environment interface
138         */
139
140         void addedToEnvironment(u32 dtime_s);
141         void removingFromEnvironment();
142         bool isStaticAllowed() const;
143         bool unlimitedTransferDistance() const;
144         std::string getClientInitializationData(u16 protocol_version);
145         std::string getStaticData();
146         bool isAttached();
147         void step(float dtime, bool send_recommended);
148         void setBasePosition(const v3f &position);
149         void setPos(v3f pos);
150         void moveTo(v3f pos, bool continuous);
151         void setYaw(float);
152         void setPitch(float);
153
154         /*
155                 Interaction interface
156         */
157
158         int punch(v3f dir,
159                 const ToolCapabilities *toolcap,
160                 ServerActiveObject *puncher,
161                 float time_from_last_punch);
162         void rightClick(ServerActiveObject *clicker);
163         s16 getHP() const;
164         void setHP(s16 hp);
165         u16 getBreath() const;
166         void setBreath(u16 breath);
167         void setArmorGroups(const ItemGroupList &armor_groups);
168         void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
169         void setBonePosition(std::string bone, v3f position, v3f rotation);
170         void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
171         ObjectProperties* accessObjectProperties();
172         void notifyObjectPropertiesModified();
173
174         /*
175                 Inventory interface
176         */
177
178         Inventory* getInventory();
179         const Inventory* getInventory() const;
180         InventoryLocation getInventoryLocation() const;
181         void setInventoryModified();
182         std::string getWieldList() const;
183         int getWieldIndex() const;
184         void setWieldIndex(int i);
185
186         /*
187                 PlayerSAO-specific
188         */
189
190         void disconnected();
191
192         Player* getPlayer()
193         {
194                 return m_player;
195         }
196         u16 getPeerID() const
197         {
198                 return m_peer_id;
199         }
200
201         // Cheat prevention
202
203         v3f getLastGoodPosition() const
204         {
205                 return m_last_good_position;
206         }
207         float resetTimeFromLastPunch()
208         {
209                 float r = m_time_from_last_punch;
210                 m_time_from_last_punch = 0.0;
211                 return r;
212         }
213         void noCheatDigStart(v3s16 p)
214         {
215                 m_nocheat_dig_pos = p;
216                 m_nocheat_dig_time = 0;
217         }
218         v3s16 getNoCheatDigPos()
219         {
220                 return m_nocheat_dig_pos;
221         }
222         float getNoCheatDigTime()
223         {
224                 return m_nocheat_dig_time;
225         }
226         void noCheatDigEnd()
227         {
228                 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
229         }
230
231         // Other
232
233         void updatePrivileges(const std::set<std::string> &privs,
234                         bool is_singleplayer)
235         {
236                 m_privs = privs;
237                 m_is_singleplayer = is_singleplayer;
238         }
239
240         bool getCollisionBox(aabb3f *toset);
241
242 private:
243         std::string getPropertyPacket();
244         
245         Player *m_player;
246         u16 m_peer_id;
247         Inventory *m_inventory;
248
249         // Cheat prevention
250         v3f m_last_good_position;
251         float m_last_good_position_age;
252         float m_time_from_last_punch;
253         v3s16 m_nocheat_dig_pos;
254         float m_nocheat_dig_time;
255
256         int m_wield_index;
257         bool m_position_not_sent;
258         ItemGroupList m_armor_groups;
259         bool m_armor_groups_sent;
260
261         bool m_properties_sent;
262         struct ObjectProperties m_prop;
263         // Cached privileges for enforcement
264         std::set<std::string> m_privs;
265         bool m_is_singleplayer;
266
267         v2f m_animation_range;
268         float m_animation_speed;
269         float m_animation_blend;
270         bool m_animation_sent;
271
272         std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
273         bool m_bone_position_sent;
274
275         int m_attachment_parent_id;
276         std::string m_attachment_bone;
277         v3f m_attachment_position;
278         v3f m_attachment_rotation;
279         bool m_attachment_sent;
280
281 public:
282         // Some flags used by Server
283         bool m_moved;
284         bool m_inventory_not_sent;
285         bool m_hp_not_sent;
286         bool m_breath_not_sent;
287         bool m_wielded_item_not_sent;
288
289         float m_physics_override_speed;
290         float m_physics_override_jump;
291         float m_physics_override_gravity;
292         bool m_physics_override_sent;
293 };
294
295 #endif
296