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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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"
28 ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
29 const std::string itemstring);
32 LuaEntitySAO needs some internals exposed.
35 struct LuaEntityProperties;
37 class LuaEntitySAO : public ServerActiveObject
40 LuaEntitySAO(ServerEnvironment *env, v3f pos,
41 const std::string &name, const std::string &state);
44 { return ACTIVEOBJECT_TYPE_LUAENTITY; }
45 u8 getSendType() const
46 { return ACTIVEOBJECT_TYPE_GENERIC; }
47 virtual void addedToEnvironment();
48 static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
49 const std::string &data);
50 void step(float dtime, bool send_recommended);
51 std::string getClientInitializationData();
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 /* LuaEntitySAO-specific */
66 void setVelocity(v3f velocity);
68 void setAcceleration(v3f acceleration);
69 v3f getAcceleration();
70 void setYaw(float yaw);
72 void setTextureMod(const std::string &mod);
73 void setSprite(v2s16 p, int num_frames, float framelength,
74 bool select_horiz_by_yawpitch);
75 std::string getName();
77 std::string getPropertyPacket();
78 void sendPosition(bool do_interpolate, bool is_movement_end);
80 std::string m_init_name;
81 std::string m_init_state;
83 struct LuaEntityProperties *m_prop;
89 ItemGroupList m_armor_groups;
91 bool m_properties_sent;
92 float m_last_sent_yaw;
93 v3f m_last_sent_position;
94 v3f m_last_sent_velocity;
95 float m_last_sent_position_timer;
96 float m_last_sent_move_precision;
97 bool m_armor_groups_sent;
101 PlayerSAO needs some internals exposed.
104 class PlayerSAO : public ServerActiveObject
107 PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_);
110 { return ACTIVEOBJECT_TYPE_PLAYER; }
111 u8 getSendType() const
112 { return ACTIVEOBJECT_TYPE_GENERIC; }
113 std::string getDescription();
116 Active object <-> environment interface
119 void addedToEnvironment();
120 void removingFromEnvironment();
121 bool isStaticAllowed() const;
122 bool unlimitedTransferDistance() const;
123 std::string getClientInitializationData();
124 std::string getStaticData();
125 void step(float dtime, bool send_recommended);
126 void setBasePosition(const v3f &position);
127 void setPos(v3f pos);
128 void moveTo(v3f pos, bool continuous);
131 Interaction interface
135 const ToolCapabilities *toolcap,
136 ServerActiveObject *puncher,
137 float time_from_last_punch);
138 void rightClick(ServerActiveObject *clicker);
141 void setArmorGroups(const ItemGroupList &armor_groups);
147 Inventory* getInventory();
148 const Inventory* getInventory() const;
149 InventoryLocation getInventoryLocation() const;
150 void setInventoryModified();
151 std::string getWieldList() const;
152 int getWieldIndex() const;
153 void setWieldIndex(int i);
161 void createCreativeInventory();
167 u16 getPeerID() const
171 v3f getLastGoodPosition() const
173 return m_last_good_position;
175 float resetTimeFromLastPunch()
177 float r = m_time_from_last_punch;
178 m_time_from_last_punch = 0.0;
183 std::string getPropertyPacket();
187 Inventory *m_inventory;
188 v3f m_last_good_position;
189 float m_last_good_position_age;
190 float m_time_from_last_punch;
192 bool m_position_not_sent;
193 ItemGroupList m_armor_groups;
194 bool m_armor_groups_sent;
195 bool m_properties_sent;
198 // Some flags used by Server
200 bool m_inventory_not_sent;
202 bool m_wielded_item_not_sent;