]> git.lizzy.rs Git - minetest.git/blob - src/content_sao.h
Add an option to disable object <-> object collision for Lua entities
[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         bool collideWithObjects();
83 private:
84         std::string getPropertyPacket();
85         void sendPosition(bool do_interpolate, bool is_movement_end);
86
87         std::string m_init_name;
88         std::string m_init_state;
89         bool m_registered;
90         struct ObjectProperties m_prop;
91         
92         s16 m_hp;
93         v3f m_velocity;
94         v3f m_acceleration;
95         float m_yaw;
96         ItemGroupList m_armor_groups;
97         
98         bool m_properties_sent;
99         float m_last_sent_yaw;
100         v3f m_last_sent_position;
101         v3f m_last_sent_velocity;
102         float m_last_sent_position_timer;
103         float m_last_sent_move_precision;
104         bool m_armor_groups_sent;
105
106         v2f m_animation_range;
107         float m_animation_speed;
108         float m_animation_blend;
109         bool m_animation_sent;
110
111         std::map<std::string, core::vector2d<v3f> > m_bone_position;
112         bool m_bone_position_sent;
113
114         int m_attachment_parent_id;
115         std::string m_attachment_bone;
116         v3f m_attachment_position;
117         v3f m_attachment_rotation;
118         bool m_attachment_sent;
119 };
120
121 /*
122         PlayerSAO needs some internals exposed.
123 */
124
125 class PlayerSAO : public ServerActiveObject
126 {
127 public:
128         PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
129                         const std::set<std::string> &privs, bool is_singleplayer);
130         ~PlayerSAO();
131         u8 getType() const
132         { return ACTIVEOBJECT_TYPE_PLAYER; }
133         u8 getSendType() const
134         { return ACTIVEOBJECT_TYPE_GENERIC; }
135         std::string getDescription();
136
137         /*
138                 Active object <-> environment interface
139         */
140
141         void addedToEnvironment(u32 dtime_s);
142         void removingFromEnvironment();
143         bool isStaticAllowed() const;
144         bool unlimitedTransferDistance() const;
145         std::string getClientInitializationData(u16 protocol_version);
146         std::string getStaticData();
147         bool isAttached();
148         void step(float dtime, bool send_recommended);
149         void setBasePosition(const v3f &position);
150         void setPos(v3f pos);
151         void moveTo(v3f pos, bool continuous);
152         void setYaw(float);
153         void setPitch(float);
154
155         /*
156                 Interaction interface
157         */
158
159         int punch(v3f dir,
160                 const ToolCapabilities *toolcap,
161                 ServerActiveObject *puncher,
162                 float time_from_last_punch);
163         void rightClick(ServerActiveObject *clicker);
164         s16 getHP() const;
165         void setHP(s16 hp);
166         u16 getBreath() const;
167         void setBreath(u16 breath);
168         void setArmorGroups(const ItemGroupList &armor_groups);
169         void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
170         void setBonePosition(std::string bone, v3f position, v3f rotation);
171         void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
172         ObjectProperties* accessObjectProperties();
173         void notifyObjectPropertiesModified();
174
175         /*
176                 Inventory interface
177         */
178
179         Inventory* getInventory();
180         const Inventory* getInventory() const;
181         InventoryLocation getInventoryLocation() const;
182         void setInventoryModified();
183         std::string getWieldList() const;
184         int getWieldIndex() const;
185         void setWieldIndex(int i);
186
187         /*
188                 PlayerSAO-specific
189         */
190
191         void disconnected();
192
193         Player* getPlayer()
194         {
195                 return m_player;
196         }
197         u16 getPeerID() const
198         {
199                 return m_peer_id;
200         }
201
202         // Cheat prevention
203
204         v3f getLastGoodPosition() const
205         {
206                 return m_last_good_position;
207         }
208         float resetTimeFromLastPunch()
209         {
210                 float r = m_time_from_last_punch;
211                 m_time_from_last_punch = 0.0;
212                 return r;
213         }
214         void noCheatDigStart(v3s16 p)
215         {
216                 m_nocheat_dig_pos = p;
217                 m_nocheat_dig_time = 0;
218         }
219         v3s16 getNoCheatDigPos()
220         {
221                 return m_nocheat_dig_pos;
222         }
223         float getNoCheatDigTime()
224         {
225                 return m_nocheat_dig_time;
226         }
227         void noCheatDigEnd()
228         {
229                 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
230         }
231
232         // Other
233
234         void updatePrivileges(const std::set<std::string> &privs,
235                         bool is_singleplayer)
236         {
237                 m_privs = privs;
238                 m_is_singleplayer = is_singleplayer;
239         }
240
241         bool getCollisionBox(aabb3f *toset);
242         bool collideWithObjects();
243
244 private:
245         std::string getPropertyPacket();
246         
247         Player *m_player;
248         u16 m_peer_id;
249         Inventory *m_inventory;
250
251         // Cheat prevention
252         v3f m_last_good_position;
253         float m_last_good_position_age;
254         float m_time_from_last_punch;
255         v3s16 m_nocheat_dig_pos;
256         float m_nocheat_dig_time;
257
258         int m_wield_index;
259         bool m_position_not_sent;
260         ItemGroupList m_armor_groups;
261         bool m_armor_groups_sent;
262
263         bool m_properties_sent;
264         struct ObjectProperties m_prop;
265         // Cached privileges for enforcement
266         std::set<std::string> m_privs;
267         bool m_is_singleplayer;
268
269         v2f m_animation_range;
270         float m_animation_speed;
271         float m_animation_blend;
272         bool m_animation_sent;
273
274         std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
275         bool m_bone_position_sent;
276
277         int m_attachment_parent_id;
278         std::string m_attachment_bone;
279         v3f m_attachment_position;
280         v3f m_attachment_rotation;
281         bool m_attachment_sent;
282
283 public:
284         // Some flags used by Server
285         bool m_moved;
286         bool m_inventory_not_sent;
287         bool m_hp_not_sent;
288         bool m_breath_not_sent;
289         bool m_wielded_item_not_sent;
290
291         float m_physics_override_speed;
292         float m_physics_override_jump;
293         float m_physics_override_gravity;
294         bool m_physics_override_sent;
295 };
296
297 #endif
298