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 "environment.h"
26 class ModApiEnvMod : public ModApiBase {
28 // set_node(pos, node)
29 // pos = {x=num, y=num, z=num}
30 static int l_set_node(lua_State *L);
32 static int l_add_node(lua_State *L);
35 // pos = {x=num, y=num, z=num}
36 static int l_remove_node(lua_State *L);
38 // swap_node(pos, node)
39 // pos = {x=num, y=num, z=num}
40 static int l_swap_node(lua_State *L);
43 // pos = {x=num, y=num, z=num}
44 static int l_get_node(lua_State *L);
46 // get_node_or_nil(pos)
47 // pos = {x=num, y=num, z=num}
48 static int l_get_node_or_nil(lua_State *L);
50 // get_node_light(pos, timeofday)
51 // pos = {x=num, y=num, z=num}
52 // timeofday: nil = current time, 0 = night, 0.5 = day
53 static int l_get_node_light(lua_State *L);
55 // place_node(pos, node)
56 // pos = {x=num, y=num, z=num}
57 static int l_place_node(lua_State *L);
60 // pos = {x=num, y=num, z=num}
61 static int l_dig_node(lua_State *L);
64 // pos = {x=num, y=num, z=num}
65 static int l_punch_node(lua_State *L);
67 // get_node_max_level(pos)
68 // pos = {x=num, y=num, z=num}
69 static int l_get_node_max_level(lua_State *L);
71 // get_node_level(pos)
72 // pos = {x=num, y=num, z=num}
73 static int l_get_node_level(lua_State *L);
75 // set_node_level(pos)
76 // pos = {x=num, y=num, z=num}
77 static int l_set_node_level(lua_State *L);
79 // add_node_level(pos)
80 // pos = {x=num, y=num, z=num}
81 static int l_add_node_level(lua_State *L);
83 // find_nodes_with_meta(pos1, pos2)
84 static int l_find_nodes_with_meta(lua_State *L);
87 static int l_get_meta(lua_State *L);
89 // get_node_timer(pos)
90 static int l_get_node_timer(lua_State *L);
92 // add_entity(pos, entityname) -> ObjectRef or nil
93 // pos = {x=num, y=num, z=num}
94 static int l_add_entity(lua_State *L);
96 // add_item(pos, itemstack or itemstring or table) -> ObjectRef or nil
97 // pos = {x=num, y=num, z=num}
98 static int l_add_item(lua_State *L);
100 // get_player_by_name(name)
101 static int l_get_player_by_name(lua_State *L);
103 // get_objects_inside_radius(pos, radius)
104 static int l_get_objects_inside_radius(lua_State *L);
106 // set_timeofday(val)
108 static int l_set_timeofday(lua_State *L);
110 // get_timeofday() -> 0...1
111 static int l_get_timeofday(lua_State *L);
114 static int l_get_gametime(lua_State *L);
116 // get_day_count() -> int
117 static int l_get_day_count(lua_State *L);
119 // find_node_near(pos, radius, nodenames) -> pos or nil
120 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
121 static int l_find_node_near(lua_State *L);
123 // find_nodes_in_area(minp, maxp, nodenames) -> list of positions
124 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
125 static int l_find_nodes_in_area(lua_State *L);
127 // find_surface_nodes_in_area(minp, maxp, nodenames) -> list of positions
128 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
129 static int l_find_nodes_in_area_under_air(lua_State *L);
131 // emerge_area(p1, p2)
132 static int l_emerge_area(lua_State *L);
134 // delete_area(p1, p2) -> true/false
135 static int l_delete_area(lua_State *L);
137 // get_perlin(seeddiff, octaves, persistence, scale)
138 // returns world-specific PerlinNoise
139 static int l_get_perlin(lua_State *L);
141 // get_perlin_map(noiseparams, size)
142 // returns world-specific PerlinNoiseMap
143 static int l_get_perlin_map(lua_State *L);
146 // returns world-specific voxel manipulator
147 static int l_get_voxel_manip(lua_State *L);
150 // clear all objects in the environment
151 static int l_clear_objects(lua_State *L);
153 // spawn_tree(pos, treedef)
154 static int l_spawn_tree(lua_State *L);
156 // line_of_sight(pos1, pos2, stepsize) -> true/false
157 static int l_line_of_sight(lua_State *L);
159 // find_path(pos1, pos2, searchdistance,
160 // max_jump, max_drop, algorithm) -> table containing path
161 static int l_find_path(lua_State *L);
163 // transforming_liquid_add(pos)
164 static int l_transforming_liquid_add(lua_State *L);
166 // forceload_block(blockpos)
167 // forceloads a block
168 static int l_forceload_block(lua_State *L);
170 // forceload_free_block(blockpos)
171 // stops forceloading a position
172 static int l_forceload_free_block(lua_State *L);
175 static void Initialize(lua_State *L, int top);
177 static struct EnumString es_ClearObjectsMode[];
180 class LuaABM : public ActiveBlockModifier {
184 std::set<std::string> m_trigger_contents;
185 std::set<std::string> m_required_neighbors;
186 float m_trigger_interval;
187 u32 m_trigger_chance;
188 bool m_simple_catch_up;
190 LuaABM(lua_State *L, int id,
191 const std::set<std::string> &trigger_contents,
192 const std::set<std::string> &required_neighbors,
193 float trigger_interval, u32 trigger_chance, bool simple_catch_up):
195 m_trigger_contents(trigger_contents),
196 m_required_neighbors(required_neighbors),
197 m_trigger_interval(trigger_interval),
198 m_trigger_chance(trigger_chance),
199 m_simple_catch_up(simple_catch_up)
202 virtual std::set<std::string> getTriggerContents()
204 return m_trigger_contents;
206 virtual std::set<std::string> getRequiredNeighbors()
208 return m_required_neighbors;
210 virtual float getTriggerInterval()
212 return m_trigger_interval;
214 virtual u32 getTriggerChance()
216 return m_trigger_chance;
218 virtual bool getSimpleCatchUp()
220 return m_simple_catch_up;
222 virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
223 u32 active_object_count, u32 active_object_count_wider);
226 class LuaLBM : public LoadingBlockModifierDef
231 LuaLBM(lua_State *L, int id,
232 const std::set<std::string> &trigger_contents,
233 const std::string &name,
234 bool run_at_every_load):
237 this->run_at_every_load = run_at_every_load;
238 this->trigger_contents = trigger_contents;
241 virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n);
244 struct ScriptCallbackState {
245 GameScripting *script;
248 unsigned int refcount;
252 #endif /* L_ENV_H_ */