]> git.lizzy.rs Git - dragonfireclient.git/blob - src/scriptapi_object.h
build with ogles2 driver
[dragonfireclient.git] / src / scriptapi_object.h
1 /*
2 Minetest-c55
3 Copyright (C) 2013 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 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.
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 Lesser General Public License for more details.
14
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.
18 */
19
20 #ifndef LUA_OBJECT_H_
21 #define LUA_OBJECT_H_
22
23 extern "C" {
24 #include <lua.h>
25 #include <lauxlib.h>
26 }
27
28 #include "serverobject.h"
29 #include "content_sao.h"
30 #include "player.h"
31
32 /*
33         ObjectRef
34 */
35
36 class ObjectRef
37 {
38 private:
39         ServerActiveObject *m_object;
40
41         static const char className[];
42         static const luaL_reg methods[];
43 public:
44         static ObjectRef *checkobject(lua_State *L, int narg);
45
46         static ServerActiveObject* getobject(ObjectRef *ref);
47 private:
48         static LuaEntitySAO* getluaobject(ObjectRef *ref);
49
50         static PlayerSAO* getplayersao(ObjectRef *ref);
51
52         static Player* getplayer(ObjectRef *ref);
53
54         // Exported functions
55
56         // garbage collector
57         static int gc_object(lua_State *L);
58
59         // remove(self)
60         static int l_remove(lua_State *L);
61
62         // getpos(self)
63         // returns: {x=num, y=num, z=num}
64         static int l_getpos(lua_State *L);
65
66         // setpos(self, pos)
67         static int l_setpos(lua_State *L);
68
69         // moveto(self, pos, continuous=false)
70         static int l_moveto(lua_State *L);
71
72         // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
73         static int l_punch(lua_State *L);
74
75         // right_click(self, clicker); clicker = an another ObjectRef
76         static int l_right_click(lua_State *L);
77
78         // set_hp(self, hp)
79         // hp = number of hitpoints (2 * number of hearts)
80         // returns: nil
81         static int l_set_hp(lua_State *L);
82
83         // get_hp(self)
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);
87
88         // get_inventory(self)
89         static int l_get_inventory(lua_State *L);
90
91         // get_wield_list(self)
92         static int l_get_wield_list(lua_State *L);
93
94         // get_wield_index(self)
95         static int l_get_wield_index(lua_State *L);
96
97         // get_wielded_item(self)
98         static int l_get_wielded_item(lua_State *L);
99
100         // set_wielded_item(self, itemstack or itemstring or table or nil)
101         static int l_set_wielded_item(lua_State *L);
102
103         // set_armor_groups(self, groups)
104         static int l_set_armor_groups(lua_State *L);
105
106         // set_animation(self, frame_range, frame_speed, frame_blend)
107         static int l_set_animation(lua_State *L);
108
109         // set_bone_position(self, std::string bone, v3f position, v3f rotation)
110         static int l_set_bone_position(lua_State *L);
111
112         // set_attach(self, parent, bone, position, rotation)
113         static int l_set_attach(lua_State *L);
114
115         // set_detach(self)
116         static int l_set_detach(lua_State *L);
117
118         // set_properties(self, properties)
119         static int l_set_properties(lua_State *L);
120
121         /* LuaEntitySAO-only */
122
123         // setvelocity(self, {x=num, y=num, z=num})
124         static int l_setvelocity(lua_State *L);
125
126         // getvelocity(self)
127         static int l_getvelocity(lua_State *L);
128
129         // setacceleration(self, {x=num, y=num, z=num})
130         static int l_setacceleration(lua_State *L);
131
132         // getacceleration(self)
133         static int l_getacceleration(lua_State *L);
134
135         // setyaw(self, radians)
136         static int l_setyaw(lua_State *L);
137
138         // getyaw(self)
139         static int l_getyaw(lua_State *L);
140
141         // settexturemod(self, mod)
142         static int l_settexturemod(lua_State *L);
143
144         // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
145         //           select_horiz_by_yawpitch=false)
146         static int l_setsprite(lua_State *L);
147
148         // DEPRECATED
149         // get_entity_name(self)
150         static int l_get_entity_name(lua_State *L);
151
152         // get_luaentity(self)
153         static int l_get_luaentity(lua_State *L);
154
155         /* Player-only */
156
157         // is_player(self)
158         static int l_is_player(lua_State *L);
159
160         // get_player_name(self)
161         static int l_get_player_name(lua_State *L);
162
163         // get_look_dir(self)
164         static int l_get_look_dir(lua_State *L);
165
166         // get_look_pitch(self)
167         static int l_get_look_pitch(lua_State *L);
168
169         // get_look_yaw(self)
170         static int l_get_look_yaw(lua_State *L);
171
172         // set_inventory_formspec(self, formspec)
173         static int l_set_inventory_formspec(lua_State *L);
174
175         // get_inventory_formspec(self) -> formspec
176         static int l_get_inventory_formspec(lua_State *L);
177
178         // get_player_control(self)
179         static int l_get_player_control(lua_State *L);
180
181         // get_player_control_bits(self)
182         static int l_get_player_control_bits(lua_State *L);
183
184 public:
185         ObjectRef(ServerActiveObject *object);
186
187         ~ObjectRef();
188
189         // Creates an ObjectRef and leaves it on top of stack
190         // Not callable from Lua; all references are created on the C side.
191         static void create(lua_State *L, ServerActiveObject *object);
192
193         static void set_null(lua_State *L);
194
195         static void Register(lua_State *L);
196 };
197
198 /*****************************************************************************/
199 /* scriptapi internal                                                        */
200 /*****************************************************************************/
201 // Creates a new anonymous reference if cobj=NULL or id=0
202 void objectref_get_or_create(lua_State *L,
203                 ServerActiveObject *cobj);
204 void objectref_get(lua_State *L, u16 id);
205 void read_object_properties(lua_State *L, int index,
206                 ObjectProperties *prop);
207
208 /*****************************************************************************/
209 /* Minetest interface                                                        */
210 /*****************************************************************************/
211 void scriptapi_add_object_reference(lua_State *L, ServerActiveObject *cobj);
212 void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj);
213
214 #endif /* LUA_OBJECT_H_ */