80a96e3275ec2e16f4531aaac37c41a1d0a328ed
[oweals/minetest.git] / src / script / common / c_content.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
21 /******************************************************************************/
22 /******************************************************************************/
23 /* WARNING!!!! do NOT add this header in any include file or any code file    */
24 /*             not being a script/modapi file!!!!!!!!                         */
25 /******************************************************************************/
26 /******************************************************************************/
27
28 #pragma once
29
30 extern "C" {
31 #include <lua.h>
32 }
33
34 #include <iostream>
35 #include <vector>
36
37 #include "irrlichttypes_bloated.h"
38 #include "util/string.h"
39 #include "itemgroup.h"
40 #include "itemdef.h"
41 #include "c_types.h"
42
43 namespace Json { class Value; }
44
45 struct MapNode;
46 class INodeDefManager;
47 struct PointedThing;
48 struct ItemStack;
49 struct ItemDefinition;
50 struct ToolCapabilities;
51 struct ObjectProperties;
52 struct SimpleSoundSpec;
53 struct ServerSoundParams;
54 class Inventory;
55 struct NodeBox;
56 struct ContentFeatures;
57 struct TileDef;
58 class Server;
59 struct DigParams;
60 struct HitParams;
61 struct EnumString;
62 struct NoiseParams;
63 class Schematic;
64
65
66 ContentFeatures    read_content_features     (lua_State *L, int index);
67 void               push_content_features     (lua_State *L,
68                                               const ContentFeatures &c);
69
70 void               push_nodebox              (lua_State *L,
71                                               const NodeBox &box);
72 void               push_box                  (lua_State *L,
73                                               const std::vector<aabb3f> &box);
74
75 void               push_palette              (lua_State *L,
76                                               const std::vector<video::SColor> *palette);
77
78 TileDef            read_tiledef              (lua_State *L, int index,
79                                               u8 drawtype);
80
81 void               read_soundspec            (lua_State *L, int index,
82                                               SimpleSoundSpec &spec);
83 NodeBox            read_nodebox              (lua_State *L, int index);
84
85 void               read_server_sound_params  (lua_State *L, int index,
86                                               ServerSoundParams &params);
87
88 void               push_dig_params           (lua_State *L,
89                                               const DigParams &params);
90 void               push_hit_params           (lua_State *L,
91                                               const HitParams &params);
92
93 ItemStack          read_item                 (lua_State *L, int index, IItemDefManager *idef);
94
95 struct TileAnimationParams read_animation_definition(lua_State *L, int index);
96
97 ToolCapabilities   read_tool_capabilities    (lua_State *L, int table);
98 void               push_tool_capabilities    (lua_State *L,
99                                               const ToolCapabilities &prop);
100
101 void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def,
102                 ItemDefinition &def);
103 void               push_item_definition      (lua_State *L,
104                                               const ItemDefinition &i);
105 void               push_item_definition_full (lua_State *L,
106                                               const ItemDefinition &i);
107
108 void               read_object_properties    (lua_State *L, int index,
109                                               ObjectProperties *prop,
110                                               IItemDefManager *idef);
111 void               push_object_properties    (lua_State *L,
112                                               ObjectProperties *prop);
113
114 void               push_inventory_list       (lua_State *L,
115                                               Inventory *inv,
116                                               const char *name);
117 void               read_inventory_list       (lua_State *L, int tableindex,
118                                               Inventory *inv, const char *name,
119                                               Server *srv, int forcesize=-1);
120
121 MapNode            readnode                  (lua_State *L, int index,
122                                               INodeDefManager *ndef);
123 void               pushnode                  (lua_State *L, const MapNode &n,
124                                               INodeDefManager *ndef);
125
126
127 void               read_groups               (lua_State *L, int index,
128                                               ItemGroupList &result);
129
130 void               push_groups               (lua_State *L,
131                                               const ItemGroupList &groups);
132
133 //TODO rename to "read_enum_field"
134 int                getenumfield              (lua_State *L, int table,
135                                               const char *fieldname,
136                                               const EnumString *spec,
137                                               int default_);
138
139 bool               getflagsfield             (lua_State *L, int table,
140                                               const char *fieldname,
141                                               FlagDesc *flagdesc,
142                                               u32 *flags, u32 *flagmask);
143
144 bool               read_flags                (lua_State *L, int index,
145                                               FlagDesc *flagdesc,
146                                               u32 *flags, u32 *flagmask);
147
148 void               push_flags_string         (lua_State *L, FlagDesc *flagdesc,
149                                               u32 flags, u32 flagmask);
150
151 u32                read_flags_table          (lua_State *L, int table,
152                                               FlagDesc *flagdesc, u32 *flagmask);
153
154 void               push_items                (lua_State *L,
155                                               const std::vector<ItemStack> &items);
156
157 std::vector<ItemStack> read_items            (lua_State *L,
158                                               int index,
159                                               Server* srv);
160
161 void               push_soundspec            (lua_State *L,
162                                               const SimpleSoundSpec &spec);
163
164 bool               string_to_enum            (const EnumString *spec,
165                                               int &result,
166                                               const std::string &str);
167
168 bool               read_noiseparams          (lua_State *L, int index,
169                                               NoiseParams *np);
170 void               push_noiseparams          (lua_State *L, NoiseParams *np);
171
172 void               luaentity_get             (lua_State *L,u16 id);
173
174 bool               push_json_value           (lua_State *L,
175                                               const Json::Value &value,
176                                               int nullindex);
177 void               read_json_value           (lua_State *L, Json::Value &root,
178                                               int index, u8 recursion = 0);
179
180 void               push_pointed_thing        (lua_State *L, const PointedThing &pointed, bool csm = false);
181
182 void               push_objectRef            (lua_State *L, const u16 id);
183
184 extern struct EnumString es_TileAnimationType[];