]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_sao.h
Scripting WIP
[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
26 class TestSAO : public ServerActiveObject
27 {
28 public:
29         TestSAO(ServerEnvironment *env, v3f pos);
30         u8 getType() const
31                 {return ACTIVEOBJECT_TYPE_TEST;}
32         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
33                         const std::string &data);
34         void step(float dtime, bool send_recommended);
35 private:
36         float m_timer1;
37         float m_age;
38 };
39
40 class ItemSAO : public ServerActiveObject
41 {
42 public:
43         ItemSAO(ServerEnvironment *env, v3f pos,
44                         const std::string inventorystring);
45         u8 getType() const
46                 {return ACTIVEOBJECT_TYPE_ITEM;}
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         InventoryItem* createInventoryItem();
53         InventoryItem* createPickedUpItem(){return createInventoryItem();}
54         void rightClick(Player *player);
55
56         float getMinimumSavedMovement(){ return 0.1*BS; }
57 private:
58         std::string m_inventorystring;
59         v3f m_speed_f;
60         v3f m_last_sent_position;
61         IntervalLimiter m_move_interval;
62 };
63
64 class RatSAO : public ServerActiveObject
65 {
66 public:
67         RatSAO(ServerEnvironment *env, v3f pos);
68         u8 getType() const
69                 {return ACTIVEOBJECT_TYPE_RAT;}
70         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
71                         const std::string &data);
72         void step(float dtime, bool send_recommended);
73         std::string getClientInitializationData();
74         std::string getStaticData();
75         InventoryItem* createPickedUpItem();
76 private:
77         bool m_is_active;
78         IntervalLimiter m_inactive_interval;
79         v3f m_speed_f;
80         v3f m_oldpos;
81         v3f m_last_sent_position;
82         float m_yaw;
83         float m_counter1;
84         float m_counter2;
85         float m_age;
86         bool m_touching_ground;
87 };
88
89 class Oerkki1SAO : public ServerActiveObject
90 {
91 public:
92         Oerkki1SAO(ServerEnvironment *env, v3f pos);
93         u8 getType() const
94                 {return ACTIVEOBJECT_TYPE_OERKKI1;}
95         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
96                         const std::string &data);
97         void step(float dtime, bool send_recommended);
98         std::string getClientInitializationData();
99         std::string getStaticData();
100         InventoryItem* createPickedUpItem(){return NULL;}
101         u16 punch(const std::string &toolname, v3f dir,
102                         const std::string &playername);
103         bool isPeaceful(){return false;}
104 private:
105         void doDamage(u16 d);
106
107         bool m_is_active;
108         IntervalLimiter m_inactive_interval;
109         v3f m_speed_f;
110         v3f m_oldpos;
111         v3f m_last_sent_position;
112         float m_yaw;
113         float m_counter1;
114         float m_counter2;
115         float m_age;
116         bool m_touching_ground;
117         u8 m_hp;
118         float m_after_jump_timer;
119 };
120
121 class FireflySAO : public ServerActiveObject
122 {
123 public:
124         FireflySAO(ServerEnvironment *env, v3f pos);
125         u8 getType() const
126                 {return ACTIVEOBJECT_TYPE_FIREFLY;}
127         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
128                         const std::string &data);
129         void step(float dtime, bool send_recommended);
130         std::string getClientInitializationData();
131         std::string getStaticData();
132         InventoryItem* createPickedUpItem();
133 private:
134         bool m_is_active;
135         IntervalLimiter m_inactive_interval;
136         v3f m_speed_f;
137         v3f m_oldpos;
138         v3f m_last_sent_position;
139         float m_yaw;
140         float m_counter1;
141         float m_counter2;
142         float m_age;
143         bool m_touching_ground;
144 };
145
146 class Settings;
147
148 class MobV2SAO : public ServerActiveObject
149 {
150 public:
151         MobV2SAO(ServerEnvironment *env, v3f pos,
152                         Settings *init_properties);
153         virtual ~MobV2SAO();
154         u8 getType() const
155                 {return ACTIVEOBJECT_TYPE_MOBV2;}
156         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
157                         const std::string &data);
158         std::string getStaticData();
159         std::string getClientInitializationData();
160         void step(float dtime, bool send_recommended);
161         InventoryItem* createPickedUpItem(){return NULL;}
162         u16 punch(const std::string &toolname, v3f dir,
163                         const std::string &playername);
164         bool isPeaceful();
165 private:
166         void sendPosition();
167         void setPropertyDefaults();
168         void readProperties();
169         void updateProperties();
170         void doDamage(u16 d);
171         
172         std::string m_move_type;
173         v3f m_speed;
174         v3f m_last_sent_position;
175         v3f m_oldpos;
176         float m_yaw;
177         float m_counter1;
178         float m_counter2;
179         float m_age;
180         bool m_touching_ground;
181         int m_hp;
182         bool m_walk_around;
183         float m_walk_around_timer;
184         bool m_next_pos_exists;
185         v3s16 m_next_pos_i;
186         float m_shoot_reload_timer;
187         bool m_shooting;
188         float m_shooting_timer;
189         float m_die_age;
190         v2f m_size;
191         bool m_falling;
192         float m_disturb_timer;
193         std::string m_disturbing_player;
194         float m_random_disturb_timer;
195         float m_shoot_y;
196         
197         Settings *m_properties;
198 };
199
200 struct LuaEntityProperties;
201
202 class LuaEntitySAO : public ServerActiveObject
203 {
204 public:
205         LuaEntitySAO(ServerEnvironment *env, v3f pos,
206                         const std::string &name, const std::string &state);
207         ~LuaEntitySAO();
208         u8 getType() const
209                 {return ACTIVEOBJECT_TYPE_LUAENTITY;}
210         virtual void addedToEnvironment(u16 id);
211         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
212                         const std::string &data);
213         void step(float dtime, bool send_recommended);
214         std::string getClientInitializationData();
215         std::string getStaticData();
216         InventoryItem* createPickedUpItem();
217         u16 punch(const std::string &toolname, v3f dir,
218                         const std::string &playername);
219         void rightClick(Player *player);
220
221         void setPos(v3f pos);
222         void moveTo(v3f pos, bool continuous);
223         float getMinimumSavedMovement();
224 private:
225         void sendPosition(bool do_interpolate, bool is_movement_end);
226
227         std::string m_init_name;
228         std::string m_init_state;
229         bool m_registered;
230         struct LuaEntityProperties *m_prop;
231         
232         float m_yaw;
233         float m_last_sent_yaw;
234         v3f m_last_sent_position;
235         float m_last_sent_position_timer;
236         float m_last_sent_move_precision;
237 };
238
239 #endif
240