1 /*
2 script/common/c_content.h
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 */
5 
6 /*
7 This file is part of Freeminer.
8 
9 Freeminer is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Freeminer  is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Freeminer.  If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 /******************************************************************************/
25 /******************************************************************************/
26 /* WARNING!!!! do NOT add this header in any include file or any code file    */
27 /*             not being a script/modapi file!!!!!!!!                         */
28 /******************************************************************************/
29 /******************************************************************************/
30 
31 #ifndef C_CONTENT_H_
32 #define C_CONTENT_H_
33 
34 extern "C" {
35 #include <lua.h>
36 }
37 
38 #include <iostream>
39 #include <map>
40 #include <vector>
41 
42 #include "irrlichttypes_bloated.h"
43 #include "util/string.h"
44 
45 namespace Json { class Value; }
46 
47 struct MapNode;
48 class INodeDefManager;
49 struct PointedThing;
50 struct ItemStack;
51 struct ItemDefinition;
52 struct ToolCapabilities;
53 struct ObjectProperties;
54 struct SimpleSoundSpec;
55 struct ServerSoundParams;
56 class Inventory;
57 struct NodeBox;
58 struct ContentFeatures;
59 struct TileDef;
60 class Server;
61 struct DigParams;
62 struct HitParams;
63 struct EnumString;
64 struct NoiseParams;
65 class Schematic;
66 
67 
68 ContentFeatures    read_content_features         (lua_State *L, int index);
69 TileDef            read_tiledef                  (lua_State *L, int index);
70 void               read_soundspec                (lua_State *L, int index,
71                                                   SimpleSoundSpec &spec);
72 NodeBox            read_nodebox                  (lua_State *L, int index);
73 
74 void               read_server_sound_params      (lua_State *L, int index,
75                                                   ServerSoundParams &params);
76 
77 void          push_dig_params           (lua_State *L,const DigParams &params);
78 void          push_hit_params           (lua_State *L,const HitParams &params);
79 
80 ItemStack     read_item                 (lua_State *L, int index, Server* srv);
81 
82 
83 ToolCapabilities   read_tool_capabilities    (lua_State *L,
84                                               int table);
85 void               push_tool_capabilities    (lua_State *L,
86                                               const ToolCapabilities &prop);
87 
88 ItemDefinition     read_item_definition      (lua_State *L,
89                                               int index,
90                                               ItemDefinition default_def);
91 void               read_object_properties    (lua_State *L,
92                                               int index,
93                                               ObjectProperties *prop);
94 
95 void               push_inventory_list       (lua_State *L,
96                                               Inventory *inv,
97                                               const char *name);
98 void               read_inventory_list       (lua_State *L,
99                                               int tableindex,
100                                               Inventory *inv,
101                                               const char *name,
102                                               Server* srv,
103                                               int forcesize=-1);
104 
105 MapNode            readnode                  (lua_State *L,
106                                               int index,
107                                               INodeDefManager *ndef);
108 void               pushnode                  (lua_State *L,
109                                               const MapNode &n,
110                                               INodeDefManager *ndef);
111 
112 NodeBox            read_nodebox              (lua_State *L, int index);
113 
114 void               read_groups               (lua_State *L,
115                                               int index,
116                                               std::map<std::string, int> &result);
117 
118 //TODO rename to "read_enum_field"
119 int                getenumfield              (lua_State *L,
120                                               int table,
121                                               const char *fieldname,
122                                               const EnumString *spec,
123                                               int default_);
124 
125 bool               getflagsfield             (lua_State *L, int table,
126                                               const char *fieldname,
127                                               FlagDesc *flagdesc,
128                                               u32 *flags, u32 *flagmask);
129 
130 bool               read_flags                (lua_State *L, int index,
131                                               FlagDesc *flagdesc,
132                                               u32 *flags, u32 *flagmask);
133 
134 u32                read_flags_table          (lua_State *L, int table,
135                                               FlagDesc *flagdesc, u32 *flagmask);
136 
137 void               push_items                (lua_State *L,
138                                               const std::vector<ItemStack> &items);
139 
140 std::vector<ItemStack> read_items            (lua_State *L,
141                                               int index,
142                                               Server* srv);
143 
144 void               read_soundspec            (lua_State *L,
145                                               int index,
146                                               SimpleSoundSpec &spec);
147 
148 
149 bool               string_to_enum            (const EnumString *spec,
150                                               int &result,
151                                               const std::string &str);
152 
153 NoiseParams*       read_noiseparams          (lua_State *L, int index);
154 
155 bool               read_noiseparams_nc       (lua_State *L, int index,
156                                               NoiseParams *np);
157 bool               get_schematic             (lua_State *L, int index,
158                                               Schematic *schem,
159                                               INodeDefManager *ndef,
160                              std::map<std::string, std::string> &replace_names);
161 bool               read_schematic            (lua_State *L, int index,
162                                               Schematic *dschem,
163                                               INodeDefManager *ndef,
164                              std::map<std::string, std::string> &replace_names);
165 
166 void               luaentity_get             (lua_State *L,u16 id);
167 
168 bool               push_json_value           (lua_State *L,
169                                               const Json::Value &value,
170                                               int nullindex);
171 void               read_json_value           (lua_State *L,
172                                               Json::Value &root,
173                                               int index,
174                                               u8 recursion = 0);
175 
176 extern struct EnumString es_TileAnimationType[];
177 
178 #endif /* C_CONTENT_H_ */
179