3 Copyright (C) 2010-2011 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);
49 void step(float dtime, bool send_recommended);
50 std::string getClientInitializationData();
51 std::string getStaticData();
53 const ToolCapabilities *toolcap=NULL,
54 ServerActiveObject *puncher=NULL,
55 float time_from_last_punch=1000000);
56 void rightClick(ServerActiveObject *clicker);
58 void moveTo(v3f pos, bool continuous);
59 float getMinimumSavedMovement();
60 std::string getDescription();
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 void setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation);
67 ObjectProperties* accessObjectProperties();
68 void notifyObjectPropertiesModified();
69 /* LuaEntitySAO-specific */
70 void setVelocity(v3f velocity);
72 void setAcceleration(v3f acceleration);
73 v3f getAcceleration();
74 void setYaw(float yaw);
76 void setTextureMod(const std::string &mod);
77 void setSprite(v2s16 p, int num_frames, float framelength,
78 bool select_horiz_by_yawpitch);
79 std::string getName();
81 std::string getPropertyPacket();
82 void sendPosition(bool do_interpolate, bool is_movement_end);
84 std::string m_init_name;
85 std::string m_init_state;
87 struct ObjectProperties m_prop;
93 ItemGroupList m_armor_groups;
95 bool m_properties_sent;
96 float m_last_sent_yaw;
97 v3f m_last_sent_position;
98 v3f m_last_sent_velocity;
99 float m_last_sent_position_timer;
100 float m_last_sent_move_precision;
101 bool m_armor_groups_sent;
105 PlayerSAO needs some internals exposed.
108 class PlayerSAO : public ServerActiveObject
111 PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
112 const std::set<std::string> &privs, bool is_singleplayer);
115 { return ACTIVEOBJECT_TYPE_PLAYER; }
116 u8 getSendType() const
117 { return ACTIVEOBJECT_TYPE_GENERIC; }
118 std::string getDescription();
121 Active object <-> environment interface
124 void addedToEnvironment(u32 dtime_s);
125 void removingFromEnvironment();
126 bool isStaticAllowed() const;
127 bool unlimitedTransferDistance() const;
128 std::string getClientInitializationData();
129 std::string getStaticData();
130 void step(float dtime, bool send_recommended);
131 void setBasePosition(const v3f &position);
132 void setPos(v3f pos);
133 void moveTo(v3f pos, bool continuous);
136 Interaction interface
140 const ToolCapabilities *toolcap,
141 ServerActiveObject *puncher,
142 float time_from_last_punch);
143 void rightClick(ServerActiveObject *clicker);
147 void setArmorGroups(const ItemGroupList &armor_groups);
148 void setAnimations(v2f frames, float frame_speed, float frame_blend);
149 void setBonePosRot(std::string bone, v3f position, v3f rotation);
150 void setAttachment(ServerActiveObject *parent, std::string bone, v3f position, v3f rotation);
151 ObjectProperties* accessObjectProperties();
152 void notifyObjectPropertiesModified();
158 Inventory* getInventory();
159 const Inventory* getInventory() const;
160 InventoryLocation getInventoryLocation() const;
161 void setInventoryModified();
162 std::string getWieldList() const;
163 int getWieldIndex() const;
164 void setWieldIndex(int i);
176 u16 getPeerID() const
183 v3f getLastGoodPosition() const
185 return m_last_good_position;
187 float resetTimeFromLastPunch()
189 float r = m_time_from_last_punch;
190 m_time_from_last_punch = 0.0;
193 void noCheatDigStart(v3s16 p)
195 m_nocheat_dig_pos = p;
196 m_nocheat_dig_time = 0;
198 v3s16 getNoCheatDigPos()
200 return m_nocheat_dig_pos;
202 float getNoCheatDigTime()
204 return m_nocheat_dig_time;
208 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
213 void updatePrivileges(const std::set<std::string> &privs,
214 bool is_singleplayer)
217 m_is_singleplayer = is_singleplayer;
221 std::string getPropertyPacket();
225 Inventory *m_inventory;
228 v3f m_last_good_position;
229 float m_last_good_position_age;
230 float m_time_from_last_punch;
231 v3s16 m_nocheat_dig_pos;
232 float m_nocheat_dig_time;
235 bool m_position_not_sent;
236 ItemGroupList m_armor_groups;
237 bool m_armor_groups_sent;
238 bool m_properties_sent;
239 struct ObjectProperties m_prop;
240 // Cached privileges for enforcement
241 std::set<std::string> m_privs;
242 bool m_is_singleplayer;
245 // Some flags used by Server
247 bool m_inventory_not_sent;
249 bool m_wielded_item_not_sent;