Moved some mapnode content stuff from mapnode.{h,cpp} and digging property stuff...
[oweals/minetest.git] / src / content_mapnode.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 // For g_settings
21 #include "main.h"
22
23 #include "content_mapnode.h"
24 #include "mapnode.h"
25 #include "nodemetadata.h"
26
27 // TODO: Get rid of these and set up some attributes like toughness,
28 //       fluffyness, and a funciton to calculate time and durability loss
29 //       (and sound? and whatever else) from them
30 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
31 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
32 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness);
33
34 void content_mapnode_init()
35 {
36         // Read some settings
37         bool new_style_water = g_settings.getBool("new_style_water");
38         bool new_style_leaves = g_settings.getBool("new_style_leaves");
39
40         u8 i;
41         ContentFeatures *f = NULL;
42
43         i = CONTENT_STONE;
44         f = &content_features(i);
45         f->setAllTextures("stone.png");
46         f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
47         f->param_type = CPT_MINERAL;
48         f->is_ground_content = true;
49         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1";
50         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
51         
52         i = CONTENT_GRASS;
53         f = &content_features(i);
54         f->setAllTextures("mud.png^grass_side.png");
55         f->setTexture(0, "grass.png");
56         f->setTexture(1, "mud.png");
57         f->param_type = CPT_MINERAL;
58         f->is_ground_content = true;
59         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
60         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
61         
62         i = CONTENT_GRASS_FOOTSTEPS;
63         f = &content_features(i);
64         f->setAllTextures("mud.png^grass_side.png");
65         f->setTexture(0, "grass_footsteps.png");
66         f->setTexture(1, "mud.png");
67         f->param_type = CPT_MINERAL;
68         f->is_ground_content = true;
69         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
70         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
71         
72         i = CONTENT_MUD;
73         f = &content_features(i);
74         f->setAllTextures("mud.png");
75         f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
76         f->param_type = CPT_MINERAL;
77         f->is_ground_content = true;
78         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
79         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
80         
81         i = CONTENT_SAND;
82         f = &content_features(i);
83         f->setAllTextures("sand.png");
84         f->param_type = CPT_MINERAL;
85         f->is_ground_content = true;
86         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
87         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
88         
89         i = CONTENT_TREE;
90         f = &content_features(i);
91         f->setAllTextures("tree.png");
92         f->setTexture(0, "tree_top.png");
93         f->setTexture(1, "tree_top.png");
94         f->param_type = CPT_MINERAL;
95         f->is_ground_content = true;
96         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
97         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
98         
99         i = CONTENT_LEAVES;
100         f = &content_features(i);
101         f->light_propagates = true;
102         //f->param_type = CPT_MINERAL;
103         f->param_type = CPT_LIGHT;
104         f->is_ground_content = true;
105         if(new_style_leaves)
106         {
107                 f->solidness = 0; // drawn separately, makes no faces
108                 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
109         }
110         else
111         {
112                 f->setAllTextures("[noalpha:leaves.png");
113         }
114         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
115         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
116
117         i = CONTENT_GLASS;
118         f = &content_features(i);
119         f->light_propagates = true;
120         f->param_type = CPT_LIGHT;
121         f->is_ground_content = true;
122         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
123         f->solidness = 0; // drawn separately, makes no faces
124         f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
125         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
126
127         i = CONTENT_FENCE;
128         f = &content_features(i);
129         f->light_propagates = true;
130         f->param_type = CPT_LIGHT;
131         f->is_ground_content = true;
132         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
133         f->solidness = 0; // drawn separately, makes no faces
134         f->air_equivalent = true; // grass grows underneath
135         f->setInventoryTexture("item_fence.png");
136         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
137
138         // Deprecated
139         i = CONTENT_COALSTONE;
140         f = &content_features(i);
141         //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
142         f->setAllTextures("stone.png^mineral_coal.png");
143         f->is_ground_content = true;
144         setStoneLikeDiggingProperties(f->digging_properties, 1.5);
145         
146         i = CONTENT_WOOD;
147         f = &content_features(i);
148         f->setAllTextures("wood.png");
149         f->is_ground_content = true;
150         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
151         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
152         
153         i = CONTENT_MESE;
154         f = &content_features(i);
155         f->setAllTextures("mese.png");
156         f->is_ground_content = true;
157         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
158         setStoneLikeDiggingProperties(f->digging_properties, 0.5);
159         
160         i = CONTENT_CLOUD;
161         f = &content_features(i);
162         f->setAllTextures("cloud.png");
163         f->is_ground_content = true;
164         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
165         
166         i = CONTENT_AIR;
167         f = &content_features(i);
168         f->param_type = CPT_LIGHT;
169         f->light_propagates = true;
170         f->sunlight_propagates = true;
171         f->solidness = 0;
172         f->walkable = false;
173         f->pointable = false;
174         f->diggable = false;
175         f->buildable_to = true;
176         f->air_equivalent = true;
177         
178         i = CONTENT_WATER;
179         f = &content_features(i);
180         f->setInventoryTextureCube("water.png", "water.png", "water.png");
181         f->param_type = CPT_LIGHT;
182         f->light_propagates = true;
183         f->solidness = 0; // Drawn separately, makes no faces
184         f->walkable = false;
185         f->pointable = false;
186         f->diggable = false;
187         f->buildable_to = true;
188         f->liquid_type = LIQUID_FLOWING;
189         f->liquid_alternative_flowing = CONTENT_WATER;
190         
191         i = CONTENT_WATERSOURCE;
192         f = &content_features(i);
193         f->setInventoryTexture("water.png");
194         if(new_style_water)
195         {
196                 f->solidness = 0; // drawn separately, makes no faces
197         }
198         else // old style
199         {
200                 f->solidness = 1;
201
202                 TileSpec t;
203                 if(g_texturesource)
204                         t.texture = g_texturesource->getTexture("water.png");
205                 
206                 t.alpha = WATER_ALPHA;
207                 t.material_type = MATERIAL_ALPHA_VERTEX;
208                 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
209                 f->setAllTiles(t);
210         }
211         f->param_type = CPT_LIGHT;
212         f->light_propagates = true;
213         f->walkable = false;
214         f->pointable = false;
215         f->diggable = false;
216         f->buildable_to = true;
217         f->liquid_type = LIQUID_SOURCE;
218         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
219         f->liquid_alternative_flowing = CONTENT_WATER;
220         
221         i = CONTENT_TORCH;
222         f = &content_features(i);
223         f->setInventoryTexture("torch_on_floor.png");
224         f->param_type = CPT_LIGHT;
225         f->light_propagates = true;
226         f->sunlight_propagates = true;
227         f->solidness = 0; // drawn separately, makes no faces
228         f->walkable = false;
229         f->wall_mounted = true;
230         f->air_equivalent = true;
231         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
232         f->light_source = LIGHT_MAX;
233         f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
234         
235         i = CONTENT_SIGN_WALL;
236         f = &content_features(i);
237         f->setInventoryTexture("sign_wall.png");
238         f->param_type = CPT_LIGHT;
239         f->light_propagates = true;
240         f->sunlight_propagates = true;
241         f->solidness = 0; // drawn separately, makes no faces
242         f->walkable = false;
243         f->wall_mounted = true;
244         f->air_equivalent = true;
245         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
246         if(f->initial_metadata == NULL)
247                 f->initial_metadata = new SignNodeMetadata("Some sign");
248         f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
249         
250         i = CONTENT_CHEST;
251         f = &content_features(i);
252         f->param_type = CPT_FACEDIR_SIMPLE;
253         f->setAllTextures("chest_side.png");
254         f->setTexture(0, "chest_top.png");
255         f->setTexture(1, "chest_top.png");
256         f->setTexture(5, "chest_front.png"); // Z-
257         f->setInventoryTexture("chest_top.png");
258         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
259         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
260         if(f->initial_metadata == NULL)
261                 f->initial_metadata = new ChestNodeMetadata();
262         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
263         
264         i = CONTENT_FURNACE;
265         f = &content_features(i);
266         f->param_type = CPT_FACEDIR_SIMPLE;
267         f->setAllTextures("furnace_side.png");
268         f->setTexture(5, "furnace_front.png"); // Z-
269         f->setInventoryTexture("furnace_front.png");
270         //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
271         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
272         if(f->initial_metadata == NULL)
273                 f->initial_metadata = new FurnaceNodeMetadata();
274         setStoneLikeDiggingProperties(f->digging_properties, 3.0);
275         
276         i = CONTENT_COBBLE;
277         f = &content_features(i);
278         f->setAllTextures("cobble.png");
279         f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
280         f->param_type = CPT_NONE;
281         f->is_ground_content = true;
282         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
283         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
284         
285         i = CONTENT_STEEL;
286         f = &content_features(i);
287         f->setAllTextures("steel_block.png");
288         f->setInventoryTextureCube("steel_block.png", "steel_block.png",
289                         "steel_block.png");
290         f->param_type = CPT_NONE;
291         f->is_ground_content = true;
292         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
293         setStoneLikeDiggingProperties(f->digging_properties, 5.0);
294         
295         // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
296         
297
298         /*
299                 Add MesePick to everything
300         */
301         for(u16 i=0; i<256; i++)
302         {
303                 content_features(i).digging_properties.set("MesePick",
304                                 DiggingProperties(true, 0.0, 65535./1337));
305         }
306
307 }
308
309 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
310 {
311         list.set("",
312                         DiggingProperties(true, 15.0*toughness, 0));
313         
314         list.set("WPick",
315                         DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
316         list.set("STPick",
317                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
318         list.set("SteelPick",
319                         DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
320
321         /*list.set("MesePick",
322                         DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
323 }
324
325 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
326 {
327         list.set("",
328                         DiggingProperties(true, 0.75*toughness, 0));
329         
330         list.set("WShovel",
331                         DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
332         list.set("STShovel",
333                         DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
334         list.set("SteelShovel",
335                         DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
336 }
337
338 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
339 {
340         list.set("",
341                         DiggingProperties(true, 3.0*toughness, 0));
342         
343         list.set("WAxe",
344                         DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
345         list.set("STAxe",
346                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
347         list.set("SteelAxe",
348                         DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));
349 }
350
351