]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_sao.h
Scripting WIP: dynamic object stuff
[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);
54         void rightClick(ServerActiveObject *clicker);
55         float getMinimumSavedMovement(){ return 0.1*BS; }
56 private:
57         std::string m_inventorystring;
58         v3f m_speed_f;
59         v3f m_last_sent_position;
60         IntervalLimiter m_move_interval;
61 };
62
63 class RatSAO : public ServerActiveObject
64 {
65 public:
66         RatSAO(ServerEnvironment *env, v3f pos);
67         u8 getType() const
68                 {return ACTIVEOBJECT_TYPE_RAT;}
69         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
70                         const std::string &data);
71         void step(float dtime, bool send_recommended);
72         std::string getClientInitializationData();
73         std::string getStaticData();
74         void punch(ServerActiveObject *puncher);
75 private:
76         bool m_is_active;
77         IntervalLimiter m_inactive_interval;
78         v3f m_speed_f;
79         v3f m_oldpos;
80         v3f m_last_sent_position;
81         float m_yaw;
82         float m_counter1;
83         float m_counter2;
84         float m_age;
85         bool m_touching_ground;
86 };
87
88 class Oerkki1SAO : public ServerActiveObject
89 {
90 public:
91         Oerkki1SAO(ServerEnvironment *env, v3f pos);
92         u8 getType() const
93                 {return ACTIVEOBJECT_TYPE_OERKKI1;}
94         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
95                         const std::string &data);
96         void step(float dtime, bool send_recommended);
97         std::string getClientInitializationData();
98         std::string getStaticData();
99         InventoryItem* createPickedUpItem(){return NULL;}
100         void punch(ServerActiveObject *puncher);
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         void punch(ServerActiveObject *puncher);
161         bool isPeaceful();
162 private:
163         void sendPosition();
164         void setPropertyDefaults();
165         void readProperties();
166         void updateProperties();
167         void doDamage(u16 d);
168         
169         std::string m_move_type;
170         v3f m_speed;
171         v3f m_last_sent_position;
172         v3f m_oldpos;
173         float m_yaw;
174         float m_counter1;
175         float m_counter2;
176         float m_age;
177         bool m_touching_ground;
178         int m_hp;
179         bool m_walk_around;
180         float m_walk_around_timer;
181         bool m_next_pos_exists;
182         v3s16 m_next_pos_i;
183         float m_shoot_reload_timer;
184         bool m_shooting;
185         float m_shooting_timer;
186         float m_die_age;
187         v2f m_size;
188         bool m_falling;
189         float m_disturb_timer;
190         std::string m_disturbing_player;
191         float m_random_disturb_timer;
192         float m_shoot_y;
193         
194         Settings *m_properties;
195 };
196
197 struct LuaEntityProperties;
198
199 class LuaEntitySAO : public ServerActiveObject
200 {
201 public:
202         LuaEntitySAO(ServerEnvironment *env, v3f pos,
203                         const std::string &name, const std::string &state);
204         ~LuaEntitySAO();
205         u8 getType() const
206                 {return ACTIVEOBJECT_TYPE_LUAENTITY;}
207         virtual void addedToEnvironment(u16 id);
208         static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
209                         const std::string &data);
210         void step(float dtime, bool send_recommended);
211         std::string getClientInitializationData();
212         std::string getStaticData();
213         InventoryItem* createPickedUpItem();
214         void punch(ServerActiveObject *puncher);
215         void rightClick(ServerActiveObject *clicker);
216         void setPos(v3f pos);
217         void moveTo(v3f pos, bool continuous);
218         float getMinimumSavedMovement();
219 private:
220         void sendPosition(bool do_interpolate, bool is_movement_end);
221
222         std::string m_init_name;
223         std::string m_init_state;
224         bool m_registered;
225         struct LuaEntityProperties *m_prop;
226         
227         float m_yaw;
228         float m_last_sent_yaw;
229         v3f m_last_sent_position;
230         float m_last_sent_position_timer;
231         float m_last_sent_move_precision;
232 };
233
234 #endif
235