3 Copyright (C) 2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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.
23 #include "lua_api/l_base.h"
24 #include "irrlichttypes.h"
26 class ServerActiveObject;
35 class ObjectRef : public ModApiBase {
37 ServerActiveObject *m_object;
39 static const char className[];
40 static const luaL_reg methods[];
42 static ObjectRef *checkobject(lua_State *L, int narg);
44 static ServerActiveObject* getobject(ObjectRef *ref);
46 static LuaEntitySAO* getluaobject(ObjectRef *ref);
48 static PlayerSAO* getplayersao(ObjectRef *ref);
50 static Player* getplayer(ObjectRef *ref);
55 static int gc_object(lua_State *L);
58 static int l_remove(lua_State *L);
61 // returns: {x=num, y=num, z=num}
62 static int l_getpos(lua_State *L);
65 static int l_setpos(lua_State *L);
67 // moveto(self, pos, continuous=false)
68 static int l_moveto(lua_State *L);
70 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
71 static int l_punch(lua_State *L);
73 // right_click(self, clicker); clicker = an another ObjectRef
74 static int l_right_click(lua_State *L);
77 // hp = number of hitpoints (2 * number of hearts)
79 static int l_set_hp(lua_State *L);
82 // returns: number of hitpoints (2 * number of hearts)
83 // 0 if not applicable to this type of object
84 static int l_get_hp(lua_State *L);
86 // get_inventory(self)
87 static int l_get_inventory(lua_State *L);
89 // get_wield_list(self)
90 static int l_get_wield_list(lua_State *L);
92 // get_wield_index(self)
93 static int l_get_wield_index(lua_State *L);
95 // get_wielded_item(self)
96 static int l_get_wielded_item(lua_State *L);
98 // set_wielded_item(self, itemstack or itemstring or table or nil)
99 static int l_set_wielded_item(lua_State *L);
101 // set_armor_groups(self, groups)
102 static int l_set_armor_groups(lua_State *L);
104 // get_armor_groups(self)
105 static int l_get_armor_groups(lua_State *L);
107 // set_physics_override(self, physics_override_speed, physics_override_jump,
108 // physics_override_gravity, sneak, sneak_glitch)
109 static int l_set_physics_override(lua_State *L);
111 // get_physics_override(self)
112 static int l_get_physics_override(lua_State *L);
114 // set_animation(self, frame_range, frame_speed, frame_blend, frame_loop)
115 static int l_set_animation(lua_State *L);
117 // get_animation(self)
118 static int l_get_animation(lua_State *L);
120 // set_bone_position(self, std::string bone, v3f position, v3f rotation)
121 static int l_set_bone_position(lua_State *L);
123 // get_bone_position(self, bone)
124 static int l_get_bone_position(lua_State *L);
126 // set_attach(self, parent, bone, position, rotation)
127 static int l_set_attach(lua_State *L);
130 static int l_get_attach(lua_State *L);
133 static int l_set_detach(lua_State *L);
135 // set_properties(self, properties)
136 static int l_set_properties(lua_State *L);
138 // get_properties(self)
139 static int l_get_properties(lua_State *L);
142 static int l_is_player(lua_State *L);
144 /* LuaEntitySAO-only */
146 // setvelocity(self, {x=num, y=num, z=num})
147 static int l_setvelocity(lua_State *L);
150 static int l_getvelocity(lua_State *L);
152 // setacceleration(self, {x=num, y=num, z=num})
153 static int l_setacceleration(lua_State *L);
155 // getacceleration(self)
156 static int l_getacceleration(lua_State *L);
158 // setyaw(self, radians)
159 static int l_setyaw(lua_State *L);
162 static int l_getyaw(lua_State *L);
164 // settexturemod(self, mod)
165 static int l_settexturemod(lua_State *L);
167 // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
168 // select_horiz_by_yawpitch=false)
169 static int l_setsprite(lua_State *L);
172 // get_entity_name(self)
173 static int l_get_entity_name(lua_State *L);
175 // get_luaentity(self)
176 static int l_get_luaentity(lua_State *L);
180 // is_player_connected(self)
181 static int l_is_player_connected(lua_State *L);
183 // get_player_name(self)
184 static int l_get_player_name(lua_State *L);
186 // get_player_velocity(self)
187 static int l_get_player_velocity(lua_State *L);
189 // get_look_dir(self)
190 static int l_get_look_dir(lua_State *L);
192 // get_look_pitch(self)
193 static int l_get_look_pitch(lua_State *L);
195 // get_look_yaw(self)
196 static int l_get_look_yaw(lua_State *L);
198 // set_look_pitch(self, radians)
199 static int l_set_look_pitch(lua_State *L);
201 // set_look_yaw(self, radians)
202 static int l_set_look_yaw(lua_State *L);
204 // set_breath(self, breath)
205 static int l_set_breath(lua_State *L);
207 // get_breath(self, breath)
208 static int l_get_breath(lua_State *L);
210 // set_inventory_formspec(self, formspec)
211 static int l_set_inventory_formspec(lua_State *L);
213 // get_inventory_formspec(self) -> formspec
214 static int l_get_inventory_formspec(lua_State *L);
216 // get_player_control(self)
217 static int l_get_player_control(lua_State *L);
219 // get_player_control_bits(self)
220 static int l_get_player_control_bits(lua_State *L);
222 // hud_add(self, id, form)
223 static int l_hud_add(lua_State *L);
226 static int l_hud_remove(lua_State *L);
228 // hud_change(self, id, stat, data)
229 static int l_hud_change(lua_State *L);
231 // hud_get_next_id(self)
232 static u32 hud_get_next_id(lua_State *L);
235 static int l_hud_get(lua_State *L);
237 // hud_set_flags(self, flags)
238 static int l_hud_set_flags(lua_State *L);
241 static int l_hud_get_flags(lua_State *L);
243 // hud_set_hotbar_itemcount(self, hotbar_itemcount)
244 static int l_hud_set_hotbar_itemcount(lua_State *L);
246 // hud_get_hotbar_itemcount(self)
247 static int l_hud_get_hotbar_itemcount(lua_State *L);
249 // hud_set_hotbar_image(self, name)
250 static int l_hud_set_hotbar_image(lua_State *L);
252 // hud_get_hotbar_image(self)
253 static int l_hud_get_hotbar_image(lua_State *L);
255 // hud_set_hotbar_selected_image(self, name)
256 static int l_hud_set_hotbar_selected_image(lua_State *L);
258 // hud_get_hotbar_selected_image(self)
259 static int l_hud_get_hotbar_selected_image(lua_State *L);
261 // set_sky(self, type, list)
262 static int l_set_sky(lua_State *L);
264 // get_sky(self, type, list)
265 static int l_get_sky(lua_State *L);
267 // override_day_night_ratio(self, type)
268 static int l_override_day_night_ratio(lua_State *L);
270 // get_day_night_ratio(self)
271 static int l_get_day_night_ratio(lua_State *L);
273 // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
274 static int l_set_local_animation(lua_State *L);
276 // get_local_animation(self)
277 static int l_get_local_animation(lua_State *L);
279 // set_eye_offset(self, v3f first pv, v3f third pv)
280 static int l_set_eye_offset(lua_State *L);
282 // get_eye_offset(self)
283 static int l_get_eye_offset(lua_State *L);
285 // set_nametag_attributes(self, attributes)
286 static int l_set_nametag_attributes(lua_State *L);
288 // get_nametag_attributes(self)
289 static int l_get_nametag_attributes(lua_State *L);
292 ObjectRef(ServerActiveObject *object);
296 // Creates an ObjectRef and leaves it on top of stack
297 // Not callable from Lua; all references are created on the C side.
298 static void create(lua_State *L, ServerActiveObject *object);
300 static void set_null(lua_State *L);
302 static void Register(lua_State *L);
305 #endif /* L_OBJECT_H_ */