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