3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef CONTENT_SAO_HEADER
21 #define CONTENT_SAO_HEADER
23 #include "serverobject.h"
24 #include "content_object.h"
26 class TestSAO : public ServerActiveObject
29 TestSAO(ServerEnvironment *env, v3f pos);
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);
40 class ItemSAO : public ServerActiveObject
43 ItemSAO(ServerEnvironment *env, v3f pos, const std::string itemstring);
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; }
55 std::string m_itemstring;
56 bool m_itemstring_changed;
58 v3f m_last_sent_position;
59 IntervalLimiter m_move_interval;
62 class RatSAO : public ServerActiveObject
65 RatSAO(ServerEnvironment *env, v3f pos);
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);
76 IntervalLimiter m_inactive_interval;
79 v3f m_last_sent_position;
84 bool m_touching_ground;
87 class Oerkki1SAO : public ServerActiveObject
90 Oerkki1SAO(ServerEnvironment *env, v3f pos);
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;}
101 void doDamage(u16 d);
104 IntervalLimiter m_inactive_interval;
107 v3f m_last_sent_position;
112 bool m_touching_ground;
114 float m_after_jump_timer;
117 class FireflySAO : public ServerActiveObject
120 FireflySAO(ServerEnvironment *env, v3f pos);
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();
130 IntervalLimiter m_inactive_interval;
133 v3f m_last_sent_position;
138 bool m_touching_ground;
143 class MobV2SAO : public ServerActiveObject
146 MobV2SAO(ServerEnvironment *env, v3f pos,
147 Settings *init_properties);
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);
160 void setPropertyDefaults();
161 void readProperties();
162 void updateProperties();
163 void doDamage(u16 d);
165 std::string m_move_type;
167 v3f m_last_sent_position;
173 bool m_touching_ground;
176 float m_walk_around_timer;
177 bool m_next_pos_exists;
179 float m_shoot_reload_timer;
181 float m_shooting_timer;
185 float m_disturb_timer;
186 std::string m_disturbing_player;
187 float m_random_disturb_timer;
190 Settings *m_properties;
193 struct LuaEntityProperties;
195 class LuaEntitySAO : public ServerActiveObject
198 LuaEntitySAO(ServerEnvironment *env, v3f pos,
199 const std::string &name, const std::string &state);
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);
217 void setAcceleration(v3f acceleration);
218 v3f getAcceleration();
219 void setYaw(float yaw);
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();
226 void sendPosition(bool do_interpolate, bool is_movement_end);
228 std::string m_init_name;
229 std::string m_init_state;
231 struct LuaEntityProperties *m_prop;
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;