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.
28 #include "serverobject.h"
29 #include "content_sao.h"
39 ServerActiveObject *m_object;
41 static const char className[];
42 static const luaL_reg methods[];
44 static ObjectRef *checkobject(lua_State *L, int narg);
46 static ServerActiveObject* getobject(ObjectRef *ref);
48 static LuaEntitySAO* getluaobject(ObjectRef *ref);
50 static PlayerSAO* getplayersao(ObjectRef *ref);
52 static Player* getplayer(ObjectRef *ref);
57 static int gc_object(lua_State *L);
60 static int l_remove(lua_State *L);
63 // returns: {x=num, y=num, z=num}
64 static int l_getpos(lua_State *L);
67 static int l_setpos(lua_State *L);
69 // moveto(self, pos, continuous=false)
70 static int l_moveto(lua_State *L);
72 // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
73 static int l_punch(lua_State *L);
75 // right_click(self, clicker); clicker = an another ObjectRef
76 static int l_right_click(lua_State *L);
79 // hp = number of hitpoints (2 * number of hearts)
81 static int l_set_hp(lua_State *L);
84 // returns: number of hitpoints (2 * number of hearts)
85 // 0 if not applicable to this type of object
86 static int l_get_hp(lua_State *L);
88 // get_inventory(self)
89 static int l_get_inventory(lua_State *L);
91 // get_wield_list(self)
92 static int l_get_wield_list(lua_State *L);
94 // get_wield_index(self)
95 static int l_get_wield_index(lua_State *L);
97 // get_wielded_item(self)
98 static int l_get_wielded_item(lua_State *L);
100 // set_wielded_item(self, itemstack or itemstring or table or nil)
101 static int l_set_wielded_item(lua_State *L);
103 // set_armor_groups(self, groups)
104 static int l_set_armor_groups(lua_State *L);
106 // set_physics_override(self, physics_override_speed, physics_override_jump, physics_override_gravity)
107 static int l_set_physics_override(lua_State *L);
109 // set_animation(self, frame_range, frame_speed, frame_blend)
110 static int l_set_animation(lua_State *L);
112 // set_bone_position(self, std::string bone, v3f position, v3f rotation)
113 static int l_set_bone_position(lua_State *L);
115 // set_attach(self, parent, bone, position, rotation)
116 static int l_set_attach(lua_State *L);
119 static int l_set_detach(lua_State *L);
121 // set_properties(self, properties)
122 static int l_set_properties(lua_State *L);
124 /* LuaEntitySAO-only */
126 // setvelocity(self, {x=num, y=num, z=num})
127 static int l_setvelocity(lua_State *L);
130 static int l_getvelocity(lua_State *L);
132 // setacceleration(self, {x=num, y=num, z=num})
133 static int l_setacceleration(lua_State *L);
135 // getacceleration(self)
136 static int l_getacceleration(lua_State *L);
138 // setyaw(self, radians)
139 static int l_setyaw(lua_State *L);
142 static int l_getyaw(lua_State *L);
144 // settexturemod(self, mod)
145 static int l_settexturemod(lua_State *L);
147 // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
148 // select_horiz_by_yawpitch=false)
149 static int l_setsprite(lua_State *L);
152 // get_entity_name(self)
153 static int l_get_entity_name(lua_State *L);
155 // get_luaentity(self)
156 static int l_get_luaentity(lua_State *L);
161 static int l_is_player(lua_State *L);
163 // get_player_name(self)
164 static int l_get_player_name(lua_State *L);
166 // get_look_dir(self)
167 static int l_get_look_dir(lua_State *L);
169 // get_look_pitch(self)
170 static int l_get_look_pitch(lua_State *L);
172 // get_look_yaw(self)
173 static int l_get_look_yaw(lua_State *L);
175 // set_look_pitch(self, radians)
176 static int l_set_look_pitch(lua_State *L);
178 // set_look_yaw(self, radians)
179 static int l_set_look_yaw(lua_State *L);
181 // set_inventory_formspec(self, formspec)
182 static int l_set_inventory_formspec(lua_State *L);
184 // get_inventory_formspec(self) -> formspec
185 static int l_get_inventory_formspec(lua_State *L);
187 // get_player_control(self)
188 static int l_get_player_control(lua_State *L);
190 // get_player_control_bits(self)
191 static int l_get_player_control_bits(lua_State *L);
193 // hud_add(self, id, form)
194 static int l_hud_add(lua_State *L);
197 static int l_hud_remove(lua_State *L);
199 // hud_change(self, id, stat, data)
200 static int l_hud_change(lua_State *L);
203 static int l_hud_get(lua_State *L);
206 ObjectRef(ServerActiveObject *object);
210 // Creates an ObjectRef and leaves it on top of stack
211 // Not callable from Lua; all references are created on the C side.
212 static void create(lua_State *L, ServerActiveObject *object);
214 static void set_null(lua_State *L);
216 static void Register(lua_State *L);
219 /*****************************************************************************/
220 /* scriptapi internal */
221 /*****************************************************************************/
222 // Creates a new anonymous reference if cobj=NULL or id=0
223 void objectref_get_or_create(lua_State *L,
224 ServerActiveObject *cobj);
225 void objectref_get(lua_State *L, u16 id);
226 void read_object_properties(lua_State *L, int index,
227 ObjectProperties *prop);
229 /*****************************************************************************/
230 /* Minetest interface */
231 /*****************************************************************************/
232 void scriptapi_add_object_reference(lua_State *L, ServerActiveObject *cobj);
233 void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj);
235 #endif /* LUA_OBJECT_H_ */