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