]> git.lizzy.rs Git - minetest.git/blob - src/scriptapi_env.h
Generalize hud_builtin_enable into hud_set_flags
[minetest.git] / src / scriptapi_env.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_ENVIRONMENT_H_
21 #define LUA_ENVIRONMENT_H_
22
23 extern "C" {
24 #include <lua.h>
25 #include <lauxlib.h>
26 }
27
28 #include "environment.h"
29
30 /*
31         EnvRef
32 */
33
34 class EnvRef
35 {
36 private:
37         ServerEnvironment *m_env;
38
39         static const char className[];
40         static const luaL_reg methods[];
41
42         static int gc_object(lua_State *L) ;
43
44         static EnvRef *checkobject(lua_State *L, int narg);
45
46         // Exported functions
47
48         // EnvRef:set_node(pos, node)
49         // pos = {x=num, y=num, z=num}
50         static int l_set_node(lua_State *L);
51
52         static int l_add_node(lua_State *L);
53
54         // EnvRef:remove_node(pos)
55         // pos = {x=num, y=num, z=num}
56         static int l_remove_node(lua_State *L);
57
58         // EnvRef:get_node(pos)
59         // pos = {x=num, y=num, z=num}
60         static int l_get_node(lua_State *L);
61
62         // EnvRef:get_node_or_nil(pos)
63         // pos = {x=num, y=num, z=num}
64         static int l_get_node_or_nil(lua_State *L);
65
66         // EnvRef:get_node_light(pos, timeofday)
67         // pos = {x=num, y=num, z=num}
68         // timeofday: nil = current time, 0 = night, 0.5 = day
69         static int l_get_node_light(lua_State *L);
70
71         // EnvRef:place_node(pos, node)
72         // pos = {x=num, y=num, z=num}
73         static int l_place_node(lua_State *L);
74
75         // EnvRef:dig_node(pos)
76         // pos = {x=num, y=num, z=num}
77         static int l_dig_node(lua_State *L);
78
79         // EnvRef:punch_node(pos)
80         // pos = {x=num, y=num, z=num}
81         static int l_punch_node(lua_State *L);
82
83         // EnvRef:get_meta(pos)
84         static int l_get_meta(lua_State *L);
85
86         // EnvRef:get_node_timer(pos)
87         static int l_get_node_timer(lua_State *L);
88
89         // EnvRef:add_entity(pos, entityname) -> ObjectRef or nil
90         // pos = {x=num, y=num, z=num}
91         static int l_add_entity(lua_State *L);
92
93         // EnvRef:add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
94         // pos = {x=num, y=num, z=num}
95         static int l_add_item(lua_State *L);
96
97         // EnvRef:add_rat(pos)
98         // pos = {x=num, y=num, z=num}
99         static int l_add_rat(lua_State *L);
100
101         // EnvRef:add_firefly(pos)
102         // pos = {x=num, y=num, z=num}
103         static int l_add_firefly(lua_State *L);
104
105         // EnvRef:get_player_by_name(name)
106         static int l_get_player_by_name(lua_State *L);
107
108         // EnvRef:get_objects_inside_radius(pos, radius)
109         static int l_get_objects_inside_radius(lua_State *L);
110
111         // EnvRef:set_timeofday(val)
112         // val = 0...1
113         static int l_set_timeofday(lua_State *L);
114
115         // EnvRef:get_timeofday() -> 0...1
116         static int l_get_timeofday(lua_State *L);
117
118         // EnvRef:find_node_near(pos, radius, nodenames) -> pos or nil
119         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
120         static int l_find_node_near(lua_State *L);
121
122         // EnvRef:find_nodes_in_area(minp, maxp, nodenames) -> list of positions
123         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
124         static int l_find_nodes_in_area(lua_State *L);
125
126         //      EnvRef:get_perlin(seeddiff, octaves, persistence, scale)
127         //  returns world-specific PerlinNoise
128         static int l_get_perlin(lua_State *L);
129
130         //  EnvRef:get_perlin_map(noiseparams, size)
131         //  returns world-specific PerlinNoiseMap
132         static int l_get_perlin_map(lua_State *L);
133
134         // EnvRef:clear_objects()
135         // clear all objects in the environment
136         static int l_clear_objects(lua_State *L);
137
138         static int l_spawn_tree(lua_State *L);
139
140
141         static int l_line_of_sight(lua_State *L);
142
143         //find a path between two positions
144         static int l_find_path(lua_State *L);
145
146 public:
147         EnvRef(ServerEnvironment *env);
148
149         ~EnvRef();
150
151         // Creates an EnvRef and leaves it on top of stack
152         // Not callable from Lua; all references are created on the C side.
153         static void create(lua_State *L, ServerEnvironment *env);
154
155         static void set_null(lua_State *L);
156
157         static void Register(lua_State *L);
158 };
159
160 /*****************************************************************************/
161 /* Minetest interface                                                        */
162 /*****************************************************************************/
163 // On environment step
164 void scriptapi_environment_step(lua_State *L, float dtime);
165 // After generating a piece of map
166 void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp,
167                 u32 blockseed);
168 void scriptapi_add_environment(lua_State *L, ServerEnvironment *env);
169
170 #endif /* LUA_ENVIRONMENT_H_ */