3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef CONTENT_SAO_HEADER
21 #define CONTENT_SAO_HEADER
23 #include "serverobject.h"
24 #include "content_object.h"
25 #include "itemgroup.h"
27 #include "object_properties.h"
29 ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
30 const std::string itemstring);
33 LuaEntitySAO needs some internals exposed.
36 class LuaEntitySAO : public ServerActiveObject
39 LuaEntitySAO(ServerEnvironment *env, v3f pos,
40 const std::string &name, const std::string &state);
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);
50 void step(float dtime, bool send_recommended);
51 std::string getClientInitializationData(u16 protocol_version);
52 std::string getStaticData();
54 const ToolCapabilities *toolcap=NULL,
55 ServerActiveObject *puncher=NULL,
56 float time_from_last_punch=1000000);
57 void rightClick(ServerActiveObject *clicker);
59 void moveTo(v3f pos, bool continuous);
60 float getMinimumSavedMovement();
61 std::string getDescription();
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);
73 void setAcceleration(v3f acceleration);
74 v3f getAcceleration();
75 void setYaw(float yaw);
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();
82 std::string getPropertyPacket();
83 void sendPosition(bool do_interpolate, bool is_movement_end);
85 std::string m_init_name;
86 std::string m_init_state;
88 struct ObjectProperties m_prop;
94 ItemGroupList m_armor_groups;
96 bool m_properties_sent;
97 float m_last_sent_yaw;
98 v3f m_last_sent_position;
99 v3f m_last_sent_velocity;
100 float m_last_sent_position_timer;
101 float m_last_sent_move_precision;
102 bool m_armor_groups_sent;
104 v2f m_animation_range;
105 float m_animation_speed;
106 float m_animation_blend;
107 bool m_animation_sent;
109 std::map<std::string, core::vector2d<v3f> > m_bone_position;
110 bool m_bone_position_sent;
112 int m_attachment_parent_id;
113 std::string m_attachment_bone;
114 v3f m_attachment_position;
115 v3f m_attachment_rotation;
116 bool m_attachment_sent;
120 PlayerSAO needs some internals exposed.
123 class PlayerSAO : public ServerActiveObject
126 PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
127 const std::set<std::string> &privs, bool is_singleplayer);
130 { return ACTIVEOBJECT_TYPE_PLAYER; }
131 u8 getSendType() const
132 { return ACTIVEOBJECT_TYPE_GENERIC; }
133 std::string getDescription();
136 Active object <-> environment interface
139 void addedToEnvironment(u32 dtime_s);
140 void removingFromEnvironment();
141 bool isStaticAllowed() const;
142 bool unlimitedTransferDistance() const;
143 std::string getClientInitializationData(u16 protocol_version);
144 std::string getStaticData();
146 void step(float dtime, bool send_recommended);
147 void setBasePosition(const v3f &position);
148 void setPos(v3f pos);
149 void moveTo(v3f pos, bool continuous);
152 Interaction interface
156 const ToolCapabilities *toolcap,
157 ServerActiveObject *puncher,
158 float time_from_last_punch);
159 void rightClick(ServerActiveObject *clicker);
163 void setArmorGroups(const ItemGroupList &armor_groups);
164 void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
165 void setBonePosition(std::string bone, v3f position, v3f rotation);
166 void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
167 ObjectProperties* accessObjectProperties();
168 void notifyObjectPropertiesModified();
174 Inventory* getInventory();
175 const Inventory* getInventory() const;
176 InventoryLocation getInventoryLocation() const;
177 void setInventoryModified();
178 std::string getWieldList() const;
179 int getWieldIndex() const;
180 void setWieldIndex(int i);
192 u16 getPeerID() const
199 v3f getLastGoodPosition() const
201 return m_last_good_position;
203 float resetTimeFromLastPunch()
205 float r = m_time_from_last_punch;
206 m_time_from_last_punch = 0.0;
209 void noCheatDigStart(v3s16 p)
211 m_nocheat_dig_pos = p;
212 m_nocheat_dig_time = 0;
214 v3s16 getNoCheatDigPos()
216 return m_nocheat_dig_pos;
218 float getNoCheatDigTime()
220 return m_nocheat_dig_time;
224 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
229 void updatePrivileges(const std::set<std::string> &privs,
230 bool is_singleplayer)
233 m_is_singleplayer = is_singleplayer;
237 std::string getPropertyPacket();
241 Inventory *m_inventory;
244 v3f m_last_good_position;
245 float m_last_good_position_age;
246 float m_time_from_last_punch;
247 v3s16 m_nocheat_dig_pos;
248 float m_nocheat_dig_time;
251 bool m_position_not_sent;
252 ItemGroupList m_armor_groups;
253 bool m_armor_groups_sent;
257 bool m_properties_sent;
258 struct ObjectProperties m_prop;
259 // Cached privileges for enforcement
260 std::set<std::string> m_privs;
261 bool m_is_singleplayer;
263 v2f m_animation_range;
264 float m_animation_speed;
265 float m_animation_blend;
266 bool m_animation_sent;
268 std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
269 bool m_bone_position_sent;
271 int m_attachment_parent_id;
272 std::string m_attachment_bone;
273 v3f m_attachment_position;
274 v3f m_attachment_rotation;
275 bool m_attachment_sent;
278 // Some flags used by Server
280 bool m_inventory_not_sent;
282 bool m_wielded_item_not_sent;