]> git.lizzy.rs Git - minetest.git/blob - src/content_sao.h
Merge pull request #243 from xyzz/liquid_renewable
[minetest.git] / src / content_sao.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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         void step(float dtime, bool send_recommended);
50         std::string getClientInitializationData();
51         std::string getStaticData();
52         int punch(v3f dir,
53                         const ToolCapabilities *toolcap=NULL,
54                         ServerActiveObject *puncher=NULL,
55                         float time_from_last_punch=1000000);
56         void rightClick(ServerActiveObject *clicker);
57         void setPos(v3f pos);
58         void moveTo(v3f pos, bool continuous);
59         float getMinimumSavedMovement();
60         std::string getDescription();
61         void setHP(s16 hp);
62         s16 getHP() const;
63         void setArmorGroups(const ItemGroupList &armor_groups);
64         ObjectProperties* accessObjectProperties();
65         void notifyObjectPropertiesModified();
66         /* LuaEntitySAO-specific */
67         void setVelocity(v3f velocity);
68         v3f getVelocity();
69         void setAcceleration(v3f acceleration);
70         v3f getAcceleration();
71         void setYaw(float yaw);
72         float getYaw();
73         void setTextureMod(const std::string &mod);
74         void setSprite(v2s16 p, int num_frames, float framelength,
75                         bool select_horiz_by_yawpitch);
76         std::string getName();
77 private:
78         std::string getPropertyPacket();
79         void sendPosition(bool do_interpolate, bool is_movement_end);
80
81         std::string m_init_name;
82         std::string m_init_state;
83         bool m_registered;
84         struct ObjectProperties m_prop;
85         
86         s16 m_hp;
87         v3f m_velocity;
88         v3f m_acceleration;
89         float m_yaw;
90         ItemGroupList m_armor_groups;
91         
92         bool m_properties_sent;
93         float m_last_sent_yaw;
94         v3f m_last_sent_position;
95         v3f m_last_sent_velocity;
96         float m_last_sent_position_timer;
97         float m_last_sent_move_precision;
98         bool m_armor_groups_sent;
99 };
100
101 /*
102         PlayerSAO needs some internals exposed.
103 */
104
105 class PlayerSAO : public ServerActiveObject
106 {
107 public:
108         PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
109                         const std::set<std::string> &privs, bool is_singleplayer);
110         ~PlayerSAO();
111         u8 getType() const
112         { return ACTIVEOBJECT_TYPE_PLAYER; }
113         u8 getSendType() const
114         { return ACTIVEOBJECT_TYPE_GENERIC; }
115         std::string getDescription();
116
117         /*
118                 Active object <-> environment interface
119         */
120
121         void addedToEnvironment(u32 dtime_s);
122         void removingFromEnvironment();
123         bool isStaticAllowed() const;
124         bool unlimitedTransferDistance() const;
125         std::string getClientInitializationData();
126         std::string getStaticData();
127         void step(float dtime, bool send_recommended);
128         void setBasePosition(const v3f &position);
129         void setPos(v3f pos);
130         void moveTo(v3f pos, bool continuous);
131
132         /*
133                 Interaction interface
134         */
135
136         int punch(v3f dir,
137                 const ToolCapabilities *toolcap,
138                 ServerActiveObject *puncher,
139                 float time_from_last_punch);
140         void rightClick(ServerActiveObject *clicker);
141         s16 getHP() const;
142         void setHP(s16 hp);
143         
144         void setArmorGroups(const ItemGroupList &armor_groups);
145         ObjectProperties* accessObjectProperties();
146         void notifyObjectPropertiesModified();
147
148         /*
149                 Inventory interface
150         */
151
152         Inventory* getInventory();
153         const Inventory* getInventory() const;
154         InventoryLocation getInventoryLocation() const;
155         void setInventoryModified();
156         std::string getWieldList() const;
157         int getWieldIndex() const;
158         void setWieldIndex(int i);
159
160         /*
161                 PlayerSAO-specific
162         */
163
164         void disconnected();
165
166         Player* getPlayer()
167         {
168                 return m_player;
169         }
170         u16 getPeerID() const
171         {
172                 return m_peer_id;
173         }
174
175         // Cheat prevention
176
177         v3f getLastGoodPosition() const
178         {
179                 return m_last_good_position;
180         }
181         float resetTimeFromLastPunch()
182         {
183                 float r = m_time_from_last_punch;
184                 m_time_from_last_punch = 0.0;
185                 return r;
186         }
187         void noCheatDigStart(v3s16 p)
188         {
189                 m_nocheat_dig_pos = p;
190                 m_nocheat_dig_time = 0;
191         }
192         v3s16 getNoCheatDigPos()
193         {
194                 return m_nocheat_dig_pos;
195         }
196         float getNoCheatDigTime()
197         {
198                 return m_nocheat_dig_time;
199         }
200         void noCheatDigEnd()
201         {
202                 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
203         }
204
205         // Other
206
207         void updatePrivileges(const std::set<std::string> &privs,
208                         bool is_singleplayer)
209         {
210                 m_privs = privs;
211                 m_is_singleplayer = is_singleplayer;
212         }
213
214 private:
215         std::string getPropertyPacket();
216         
217         Player *m_player;
218         u16 m_peer_id;
219         Inventory *m_inventory;
220
221         // Cheat prevention
222         v3f m_last_good_position;
223         float m_last_good_position_age;
224         float m_time_from_last_punch;
225         v3s16 m_nocheat_dig_pos;
226         float m_nocheat_dig_time;
227
228         int m_wield_index;
229         bool m_position_not_sent;
230         ItemGroupList m_armor_groups;
231         bool m_armor_groups_sent;
232         bool m_properties_sent;
233         struct ObjectProperties m_prop;
234         // Cached privileges for enforcement
235         std::set<std::string> m_privs;
236         bool m_is_singleplayer;
237
238 public:
239         // Some flags used by Server
240         bool m_teleported;
241         bool m_inventory_not_sent;
242         bool m_hp_not_sent;
243         bool m_wielded_item_not_sent;
244 };
245
246 #endif
247