4122fd037ebc5da868222fcdbe6ec93232312f0b
[oweals/minetest.git] / src / script / lua_api / l_env.h
1 /*
2 Minetest
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 L_ENV_H_
21 #define L_ENV_H_
22
23 extern "C" {
24 #include <lua.h>
25 #include <lauxlib.h>
26 }
27
28 #include "environment.h"
29 #include "lua_api/l_base.h"
30
31 class ModApiEnvMod
32         :public ModApiBase
33 {
34 private:
35         // minetest.set_node(pos, node)
36         // pos = {x=num, y=num, z=num}
37         static int l_set_node(lua_State *L);
38
39         static int l_add_node(lua_State *L);
40
41         // minetest.remove_node(pos)
42         // pos = {x=num, y=num, z=num}
43         static int l_remove_node(lua_State *L);
44
45         // minetest.get_node(pos)
46         // pos = {x=num, y=num, z=num}
47         static int l_get_node(lua_State *L);
48
49         // minetest.get_node_or_nil(pos)
50         // pos = {x=num, y=num, z=num}
51         static int l_get_node_or_nil(lua_State *L);
52
53         // minetest.get_node_light(pos, timeofday)
54         // pos = {x=num, y=num, z=num}
55         // timeofday: nil = current time, 0 = night, 0.5 = day
56         static int l_get_node_light(lua_State *L);
57
58         // minetest.place_node(pos, node)
59         // pos = {x=num, y=num, z=num}
60         static int l_place_node(lua_State *L);
61
62         // minetest.dig_node(pos)
63         // pos = {x=num, y=num, z=num}
64         static int l_dig_node(lua_State *L);
65
66         // minetest.punch_node(pos)
67         // pos = {x=num, y=num, z=num}
68         static int l_punch_node(lua_State *L);
69
70
71         // minetest.get_node_max_level(pos)
72         // pos = {x=num, y=num, z=num}
73         static int l_get_node_max_level(lua_State *L);
74
75         // minetest.get_node_level(pos)
76         // pos = {x=num, y=num, z=num}
77         static int l_get_node_level(lua_State *L);
78
79         // minetest.set_node_level(pos)
80         // pos = {x=num, y=num, z=num}
81         static int l_set_node_level(lua_State *L);
82
83         // minetest.add_node_level(pos)
84         // pos = {x=num, y=num, z=num}
85         static int l_add_node_level(lua_State *L);
86
87         // minetest.get_meta(pos)
88         static int l_get_meta(lua_State *L);
89
90         // minetest.get_node_timer(pos)
91         static int l_get_node_timer(lua_State *L);
92
93         // minetest.add_entity(pos, entityname) -> ObjectRef or nil
94         // pos = {x=num, y=num, z=num}
95         static int l_add_entity(lua_State *L);
96
97         // minetest.add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
98         // pos = {x=num, y=num, z=num}
99         static int l_add_item(lua_State *L);
100
101         // minetest.get_player_by_name(name)
102         static int l_get_player_by_name(lua_State *L);
103
104         // minetest.get_objects_inside_radius(pos, radius)
105         static int l_get_objects_inside_radius(lua_State *L);
106
107         // minetest.set_timeofday(val)
108         // val = 0...1
109         static int l_set_timeofday(lua_State *L);
110
111         // minetest.get_timeofday() -> 0...1
112         static int l_get_timeofday(lua_State *L);
113
114         // minetest.find_node_near(pos, radius, nodenames) -> pos or nil
115         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
116         static int l_find_node_near(lua_State *L);
117
118         // minetest.find_nodes_in_area(minp, maxp, nodenames) -> list of positions
119         // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
120         static int l_find_nodes_in_area(lua_State *L);
121
122         // minetest.get_perlin(seeddiff, octaves, persistence, scale)
123         // returns world-specific PerlinNoise
124         static int l_get_perlin(lua_State *L);
125
126         // minetest.get_perlin_map(noiseparams, size)
127         // returns world-specific PerlinNoiseMap
128         static int l_get_perlin_map(lua_State *L);
129         
130         // minetest.get_voxel_manip()
131         // returns world-specific voxel manipulator
132         static int l_get_voxel_manip(lua_State *L);
133         
134         // minetest.get_mapgen_object(objectname)
135         // returns the requested object used during map generation
136         static int l_get_mapgen_object(lua_State *L);
137         
138         // minetest.set_mapgen_params(params)
139         // set mapgen parameters
140         static int l_set_mapgen_params(lua_State *L);
141
142         // minetest.clear_objects()
143         // clear all objects in the environment
144         static int l_clear_objects(lua_State *L);
145
146         // minetest.spawn_tree(pos, treedef)
147         static int l_spawn_tree(lua_State *L);
148
149         // minetest.line_of_sight(pos1, pos2, stepsize) -> true/false
150         static int l_line_of_sight(lua_State *L);
151
152         // minetest.find_path(pos1, pos2, searchdistance,
153         //     max_jump, max_drop, algorithm) -> table containing path
154         static int l_find_path(lua_State *L);
155
156         // minetest.transforming_liquid_add(pos)
157         static int l_transforming_liquid_add(lua_State *L);
158
159         static int l_get_heat(lua_State *L);
160         static int l_get_humidity(lua_State *L);
161         
162         static struct EnumString es_MapgenObject[];
163         
164 public:
165         bool Initialize(lua_State *L, int top);
166 };
167
168 class LuaABM : public ActiveBlockModifier
169 {
170 private:
171         int m_id;
172
173         std::set<std::string> m_trigger_contents;
174         std::set<std::string> m_required_neighbors;
175         float m_trigger_interval;
176         u32 m_trigger_chance;
177 public:
178         LuaABM(lua_State *L, int id,
179                         const std::set<std::string> &trigger_contents,
180                         const std::set<std::string> &required_neighbors,
181                         float trigger_interval, u32 trigger_chance):
182                 m_id(id),
183                 m_trigger_contents(trigger_contents),
184                 m_required_neighbors(required_neighbors),
185                 m_trigger_interval(trigger_interval),
186                 m_trigger_chance(trigger_chance)
187         {
188         }
189         virtual std::set<std::string> getTriggerContents()
190         {
191                 return m_trigger_contents;
192         }
193         virtual std::set<std::string> getRequiredNeighbors()
194         {
195                 return m_required_neighbors;
196         }
197         virtual float getTriggerInterval()
198         {
199                 return m_trigger_interval;
200         }
201         virtual u32 getTriggerChance()
202         {
203                 return m_trigger_chance;
204         }
205         virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
206                         u32 active_object_count, u32 active_object_count_wider);
207 };
208
209 #endif /* L_ENV_H_ */