]> git.lizzy.rs Git - minetest-m13.git/blob - src/content_sao.h
cead54d2f76ee992b8d4427d445b42ee08e6cf7c
[minetest-m13.git] / src / content_sao.h
1 /*
2 Minetest-m13
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, const std::string itemstring);
44         u8 getType() const
45                 {return ACTIVEOBJECT_TYPE_ITEM;}
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         ItemStack createItemStack();
52         void punch(ServerActiveObject *puncher, float time_from_last_punch);
53         float getMinimumSavedMovement(){ return 0.1*BS; }
54 private:
55         std::string m_itemstring;
56         bool m_itemstring_changed;
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         void punch(ServerActiveObject *puncher, float time_from_last_punch);
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         void punch(ServerActiveObject *puncher, float time_from_last_punch);
99         bool isPeaceful(){return false;}
100 private:
101         void doDamage(u16 d);
102
103         bool m_is_active;
104         IntervalLimiter m_inactive_interval;
105         v3f m_speed_f;
106         v3f m_oldpos;
107         v3f m_last_sent_position;
108         float m_yaw;
109         float m_counter1;
110         float m_counter2;
111         float m_age;
112         bool m_touching_ground;
113         u8 m_hp;
114         float m_after_jump_timer;
115 };
116
117 class FireflySAO : public ServerActiveObject
118 {
119 public:
120         FireflySAO(ServerEnvironment *env, v3f pos);
121         u8 getType() const
122                 {return ACTIVEOBJECT_TYPE_FIREFLY;}
123         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
124                         const std::string &data);
125         void step(float dtime, bool send_recommended);
126         std::string getClientInitializationData();
127         std::string getStaticData();
128 private:
129         bool m_is_active;
130         IntervalLimiter m_inactive_interval;
131         v3f m_speed_f;
132         v3f m_oldpos;
133         v3f m_last_sent_position;
134         float m_yaw;
135         float m_counter1;
136         float m_counter2;
137         float m_age;
138         bool m_touching_ground;
139 };
140
141 class Settings;
142
143 class MobV2SAO : public ServerActiveObject
144 {
145 public:
146         MobV2SAO(ServerEnvironment *env, v3f pos,
147                         Settings *init_properties);
148         virtual ~MobV2SAO();
149         u8 getType() const
150                 {return ACTIVEOBJECT_TYPE_MOBV2;}
151         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
152                         const std::string &data);
153         std::string getStaticData();
154         std::string getClientInitializationData();
155         void step(float dtime, bool send_recommended);
156         void punch(ServerActiveObject *puncher, float time_from_last_punch);
157         bool isPeaceful();
158 private:
159         void sendPosition();
160         void setPropertyDefaults();
161         void readProperties();
162         void updateProperties();
163         void doDamage(u16 d);
164         
165         std::string m_move_type;
166         v3f m_speed;
167         v3f m_last_sent_position;
168         v3f m_oldpos;
169         float m_yaw;
170         float m_counter1;
171         float m_counter2;
172         float m_age;
173         bool m_touching_ground;
174         int m_hp;
175         bool m_walk_around;
176         float m_walk_around_timer;
177         bool m_next_pos_exists;
178         v3s16 m_next_pos_i;
179         float m_shoot_reload_timer;
180         bool m_shooting;
181         float m_shooting_timer;
182         float m_die_age;
183         v2f m_size;
184         bool m_falling;
185         float m_disturb_timer;
186         std::string m_disturbing_player;
187         float m_random_disturb_timer;
188         float m_shoot_y;
189         
190         Settings *m_properties;
191 };
192
193 struct LuaEntityProperties;
194
195 class LuaEntitySAO : public ServerActiveObject
196 {
197 public:
198         LuaEntitySAO(ServerEnvironment *env, v3f pos,
199                         const std::string &name, const std::string &state);
200         ~LuaEntitySAO();
201         u8 getType() const
202                 {return ACTIVEOBJECT_TYPE_LUAENTITY;}
203         virtual void addedToEnvironment();
204         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
205                         const std::string &data);
206         void step(float dtime, bool send_recommended);
207         std::string getClientInitializationData();
208         std::string getStaticData();
209         void punch(ServerActiveObject *puncher, float time_from_last_punch);
210         void rightClick(ServerActiveObject *clicker);
211         void setPos(v3f pos);
212         void moveTo(v3f pos, bool continuous);
213         float getMinimumSavedMovement();
214         /* LuaEntitySAO-specific */
215         void setVelocity(v3f velocity);
216         v3f getVelocity();
217         void setAcceleration(v3f acceleration);
218         v3f getAcceleration();
219         void setYaw(float yaw);
220         float getYaw();
221         void setTextureMod(const std::string &mod);
222         void setSprite(v2s16 p, int num_frames, float framelength,
223                         bool select_horiz_by_yawpitch);
224         std::string getName();
225 private:
226         void sendPosition(bool do_interpolate, bool is_movement_end);
227
228         std::string m_init_name;
229         std::string m_init_state;
230         bool m_registered;
231         struct LuaEntityProperties *m_prop;
232         
233         v3f m_velocity;
234         v3f m_acceleration;
235         float m_yaw;
236         float m_last_sent_yaw;
237         v3f m_last_sent_position;
238         v3f m_last_sent_velocity;
239         float m_last_sent_position_timer;
240         float m_last_sent_move_precision;
241 };
242
243 #endif
244