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