]> git.lizzy.rs Git - minetest.git/blob - src/content_sao.h
9ceb6ed6ae65879f523f4340ec07e677d7e3d2fe
[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 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.
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 General Public License for more details.
14
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.
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
28 ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
29                 const std::string itemstring);
30
31 /*
32         LuaEntitySAO needs some internals exposed.
33 */
34
35 struct LuaEntityProperties;
36
37 class LuaEntitySAO : public ServerActiveObject
38 {
39 public:
40         LuaEntitySAO(ServerEnvironment *env, v3f pos,
41                         const std::string &name, const std::string &state);
42         ~LuaEntitySAO();
43         u8 getType() const
44                 {return ACTIVEOBJECT_TYPE_LUAENTITY;}
45         virtual void addedToEnvironment();
46         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
47                         const std::string &data);
48         void step(float dtime, bool send_recommended);
49         std::string getClientInitializationData();
50         std::string getStaticData();
51         int punch(v3f dir,
52                         const ToolCapabilities *toolcap=NULL,
53                         ServerActiveObject *puncher=NULL,
54                         float time_from_last_punch=1000000);
55         void rightClick(ServerActiveObject *clicker);
56         void setPos(v3f pos);
57         void moveTo(v3f pos, bool continuous);
58         float getMinimumSavedMovement();
59         std::string getDescription();
60         void setHP(s16 hp);
61         s16 getHP() const;
62         /* LuaEntitySAO-specific */
63         void setVelocity(v3f velocity);
64         v3f getVelocity();
65         void setAcceleration(v3f acceleration);
66         v3f getAcceleration();
67         void setYaw(float yaw);
68         float getYaw();
69         void setTextureMod(const std::string &mod);
70         void setSprite(v2s16 p, int num_frames, float framelength,
71                         bool select_horiz_by_yawpitch);
72         std::string getName();
73         void setArmorGroups(const ItemGroupList &armor_groups);
74 private:
75         void sendPosition(bool do_interpolate, bool is_movement_end);
76
77         std::string m_init_name;
78         std::string m_init_state;
79         bool m_registered;
80         struct LuaEntityProperties *m_prop;
81         
82         s16 m_hp;
83         v3f m_velocity;
84         v3f m_acceleration;
85         float m_yaw;
86         ItemGroupList m_armor_groups;
87
88         float m_last_sent_yaw;
89         v3f m_last_sent_position;
90         v3f m_last_sent_velocity;
91         float m_last_sent_position_timer;
92         float m_last_sent_move_precision;
93         bool m_armor_groups_sent;
94 };
95
96 /*
97         PlayerSAO needs some internals exposed.
98 */
99
100 class PlayerSAO : public ServerActiveObject
101 {
102 public:
103         PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_);
104         ~PlayerSAO();
105         u8 getType() const
106                 {return ACTIVEOBJECT_TYPE_PLAYER;}
107         std::string getDescription();
108
109         /*
110                 Active object <-> environment interface
111         */
112
113         void addedToEnvironment();
114         void removingFromEnvironment();
115         bool isStaticAllowed() const;
116         bool unlimitedTransferDistance() const;
117         std::string getClientInitializationData();
118         std::string getStaticData();
119         void step(float dtime, bool send_recommended);
120         void setBasePosition(const v3f &position);
121         void setPos(v3f pos);
122         void moveTo(v3f pos, bool continuous);
123
124         /*
125                 Interaction interface
126         */
127
128         int punch(v3f dir,
129                 const ToolCapabilities *toolcap,
130                 ServerActiveObject *puncher,
131                 float time_from_last_punch);
132         void rightClick(ServerActiveObject *clicker);
133         s16 getHP() const;
134         void setHP(s16 hp);
135
136         /*
137                 Inventory interface
138         */
139
140         Inventory* getInventory();
141         const Inventory* getInventory() const;
142         InventoryLocation getInventoryLocation() const;
143         void setInventoryModified();
144         std::string getWieldList() const;
145         int getWieldIndex() const;
146         void setWieldIndex(int i);
147
148         /*
149                 PlayerSAO-specific
150         */
151
152         void disconnected();
153
154         void createCreativeInventory();
155
156         Player* getPlayer()
157         {
158                 return m_player;
159         }
160         u16 getPeerID() const
161         {
162                 return m_peer_id;
163         }
164         v3f getLastGoodPosition() const
165         {
166                 return m_last_good_position;
167         }
168         float resetTimeFromLastPunch()
169         {
170                 float r = m_time_from_last_punch;
171                 m_time_from_last_punch = 0.0;
172                 return r;
173         }
174
175 private:
176         Player *m_player;
177         u16 m_peer_id;
178         Inventory *m_inventory;
179         v3f m_last_good_position;
180         float m_last_good_position_age;
181         float m_time_from_last_punch;
182         int m_wield_index;
183         bool m_position_not_sent;
184
185 public:
186         // Some flags used by Server
187         bool m_teleported;
188         bool m_inventory_not_sent;
189         bool m_hp_not_sent;
190         bool m_wielded_item_not_sent;
191 };
192
193 #endif
194