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