]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_sao.h
Use GenericCAO in place of LuaEntityCAO and PlayerCAO
[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 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         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();
53         int punch(v3f dir,
54                         const ToolCapabilities *toolcap=NULL,
55                         ServerActiveObject *puncher=NULL,
56                         float time_from_last_punch=1000000);
57         void rightClick(ServerActiveObject *clicker);
58         void setPos(v3f pos);
59         void moveTo(v3f pos, bool continuous);
60         float getMinimumSavedMovement();
61         std::string getDescription();
62         void setHP(s16 hp);
63         s16 getHP() const;
64         void setArmorGroups(const ItemGroupList &armor_groups);
65         /* LuaEntitySAO-specific */
66         void setVelocity(v3f velocity);
67         v3f getVelocity();
68         void setAcceleration(v3f acceleration);
69         v3f getAcceleration();
70         void setYaw(float yaw);
71         float getYaw();
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();
76 private:
77         std::string getPropertyPacket();
78         void sendPosition(bool do_interpolate, bool is_movement_end);
79
80         std::string m_init_name;
81         std::string m_init_state;
82         bool m_registered;
83         struct LuaEntityProperties *m_prop;
84         
85         s16 m_hp;
86         v3f m_velocity;
87         v3f m_acceleration;
88         float m_yaw;
89         ItemGroupList m_armor_groups;
90         
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;
98 };
99
100 /*
101         PlayerSAO needs some internals exposed.
102 */
103
104 class PlayerSAO : public ServerActiveObject
105 {
106 public:
107         PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_);
108         ~PlayerSAO();
109         u8 getType() const
110         { return ACTIVEOBJECT_TYPE_PLAYER; }
111         u8 getSendType() const
112         { return ACTIVEOBJECT_TYPE_GENERIC; }
113         std::string getDescription();
114
115         /*
116                 Active object <-> environment interface
117         */
118
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);
129
130         /*
131                 Interaction interface
132         */
133
134         int punch(v3f dir,
135                 const ToolCapabilities *toolcap,
136                 ServerActiveObject *puncher,
137                 float time_from_last_punch);
138         void rightClick(ServerActiveObject *clicker);
139         s16 getHP() const;
140         void setHP(s16 hp);
141         void setArmorGroups(const ItemGroupList &armor_groups);
142
143         /*
144                 Inventory interface
145         */
146
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);
154
155         /*
156                 PlayerSAO-specific
157         */
158
159         void disconnected();
160
161         void createCreativeInventory();
162
163         Player* getPlayer()
164         {
165                 return m_player;
166         }
167         u16 getPeerID() const
168         {
169                 return m_peer_id;
170         }
171         v3f getLastGoodPosition() const
172         {
173                 return m_last_good_position;
174         }
175         float resetTimeFromLastPunch()
176         {
177                 float r = m_time_from_last_punch;
178                 m_time_from_last_punch = 0.0;
179                 return r;
180         }
181
182 private:
183         std::string getPropertyPacket();
184         
185         Player *m_player;
186         u16 m_peer_id;
187         Inventory *m_inventory;
188         v3f m_last_good_position;
189         float m_last_good_position_age;
190         float m_time_from_last_punch;
191         int m_wield_index;
192         bool m_position_not_sent;
193         ItemGroupList m_armor_groups;
194         bool m_armor_groups_sent;
195         bool m_properties_sent;
196
197 public:
198         // Some flags used by Server
199         bool m_teleported;
200         bool m_inventory_not_sent;
201         bool m_hp_not_sent;
202         bool m_wielded_item_not_sent;
203 };
204
205 #endif
206