]> git.lizzy.rs Git - dragonfireclient.git/blob - src/content_mapnode.cpp
extended content-type range
[dragonfireclient.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 "content_nodemeta.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 content_t trans_table_19[][2] = {
35         {CONTENT_GRASS, 1},
36         {CONTENT_TREE, 4},
37         {CONTENT_LEAVES, 5},
38         {CONTENT_GRASS_FOOTSTEPS, 6},
39         {CONTENT_MESE, 7},
40         {CONTENT_MUD, 8},
41         {CONTENT_CLOUD, 10},
42         {CONTENT_COALSTONE, 11},
43         {CONTENT_WOOD, 12},
44         {CONTENT_SAND, 13},
45         {CONTENT_COBBLE, 18},
46         {CONTENT_STEEL, 19},
47         {CONTENT_GLASS, 20},
48         {CONTENT_MOSSYCOBBLE, 22},
49         {CONTENT_GRAVEL, 23},
50 };
51
52 MapNode mapnode_translate_from_internal(MapNode n_from, u8 version)
53 {
54         MapNode result = n_from;
55         if(version <= 19)
56         {
57                 content_t c_from = n_from.getContent();
58                 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
59                 {
60                         if(trans_table_19[i][0] == c_from)
61                         {
62                                 result.setContent(trans_table_19[i][1]);
63                                 break;
64                         }
65                 }
66         }
67         return result;
68 }
69 MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
70 {
71         MapNode result = n_from;
72         if(version <= 19)
73         {
74                 content_t c_from = n_from.getContent();
75                 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
76                 {
77                         if(trans_table_19[i][1] == c_from)
78                         {
79                                 result.setContent(trans_table_19[i][0]);
80                                 break;
81                         }
82                 }
83         }
84         return result;
85 }
86
87 void content_mapnode_init()
88 {
89         // Read some settings
90         bool new_style_water = g_settings.getBool("new_style_water");
91         bool new_style_leaves = g_settings.getBool("new_style_leaves");
92         bool invisible_stone = g_settings.getBool("invisible_stone");
93
94         content_t i;
95         ContentFeatures *f = NULL;
96
97         i = CONTENT_STONE;
98         f = &content_features(i);
99         f->setAllTextures("stone.png");
100         f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
101         f->param_type = CPT_MINERAL;
102         f->is_ground_content = true;
103         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 1";
104         setStoneLikeDiggingProperties(f->digging_properties, 1.0);
105         if(invisible_stone)
106                 f->solidness = 0; // For debugging, hides regular stone
107         
108         i = CONTENT_GRASS;
109         f = &content_features(i);
110         f->setAllTextures("mud.png^grass_side.png");
111         f->setTexture(0, "grass.png");
112         f->setTexture(1, "mud.png");
113         f->param_type = CPT_MINERAL;
114         f->is_ground_content = true;
115         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
116         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
117         
118         i = CONTENT_GRASS_FOOTSTEPS;
119         f = &content_features(i);
120         f->setAllTextures("mud.png^grass_side.png");
121         f->setTexture(0, "grass_footsteps.png");
122         f->setTexture(1, "mud.png");
123         f->param_type = CPT_MINERAL;
124         f->is_ground_content = true;
125         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
126         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
127         
128         i = CONTENT_MUD;
129         f = &content_features(i);
130         f->setAllTextures("mud.png");
131         f->setInventoryTextureCube("mud.png", "mud.png", "mud.png");
132         f->param_type = CPT_MINERAL;
133         f->is_ground_content = true;
134         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
135         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
136         
137         i = CONTENT_SAND;
138         f = &content_features(i);
139         f->setAllTextures("sand.png");
140         f->setInventoryTextureCube("sand.png", "sand.png", "sand.png");
141         f->param_type = CPT_MINERAL;
142         f->is_ground_content = true;
143         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
144         setDirtLikeDiggingProperties(f->digging_properties, 1.0);
145         
146         i = CONTENT_GRAVEL;
147         f = &content_features(i);
148         f->setAllTextures("gravel.png");
149         f->setInventoryTextureCube("gravel.png", "gravel.png", "gravel.png");
150         f->param_type = CPT_MINERAL;
151         f->is_ground_content = true;
152         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
153         setDirtLikeDiggingProperties(f->digging_properties, 1.75);
154         
155         i = CONTENT_TREE;
156         f = &content_features(i);
157         f->setAllTextures("tree.png");
158         f->setTexture(0, "tree_top.png");
159         f->setTexture(1, "tree_top.png");
160         f->param_type = CPT_MINERAL;
161         f->is_ground_content = true;
162         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
163         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
164         
165         i = CONTENT_LEAVES;
166         f = &content_features(i);
167         f->light_propagates = true;
168         //f->param_type = CPT_MINERAL;
169         f->param_type = CPT_LIGHT;
170         f->is_ground_content = true;
171         if(new_style_leaves)
172         {
173                 f->solidness = 0; // drawn separately, makes no faces
174                 f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
175         }
176         else
177         {
178                 f->setAllTextures("[noalpha:leaves.png");
179         }
180         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
181         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
182
183         i = CONTENT_GLASS;
184         f = &content_features(i);
185         f->light_propagates = true;
186         f->param_type = CPT_LIGHT;
187         f->is_ground_content = true;
188         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
189         f->solidness = 0; // drawn separately, makes no faces
190         f->setInventoryTextureCube("glass.png", "glass.png", "glass.png");
191         setWoodLikeDiggingProperties(f->digging_properties, 0.15);
192
193         i = CONTENT_FENCE;
194         f = &content_features(i);
195         f->light_propagates = true;
196         f->param_type = CPT_LIGHT;
197         f->is_ground_content = true;
198         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
199         f->solidness = 0; // drawn separately, makes no faces
200         f->air_equivalent = true; // grass grows underneath
201         f->setInventoryTexture("item_fence.png");
202         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
203
204         // Deprecated
205         i = CONTENT_COALSTONE;
206         f = &content_features(i);
207         f->setAllTextures("stone.png^mineral_coal.png");
208         f->is_ground_content = true;
209         setStoneLikeDiggingProperties(f->digging_properties, 1.5);
210         
211         i = CONTENT_WOOD;
212         f = &content_features(i);
213         f->setAllTextures("wood.png");
214         f->setInventoryTextureCube("wood.png", "wood.png", "wood.png");
215         f->is_ground_content = true;
216         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
217         setWoodLikeDiggingProperties(f->digging_properties, 0.75);
218         
219         i = CONTENT_MESE;
220         f = &content_features(i);
221         f->setAllTextures("mese.png");
222         f->setInventoryTextureCube("mese.png", "mese.png", "mese.png");
223         f->is_ground_content = true;
224         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
225         setStoneLikeDiggingProperties(f->digging_properties, 0.5);
226         
227         i = CONTENT_CLOUD;
228         f = &content_features(i);
229         f->setAllTextures("cloud.png");
230         f->setInventoryTextureCube("cloud.png", "cloud.png", "cloud.png");
231         f->is_ground_content = true;
232         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
233         
234         i = CONTENT_AIR;
235         f = &content_features(i);
236         f->param_type = CPT_LIGHT;
237         f->light_propagates = true;
238         f->sunlight_propagates = true;
239         f->solidness = 0;
240         f->walkable = false;
241         f->pointable = false;
242         f->diggable = false;
243         f->buildable_to = true;
244         f->air_equivalent = true;
245         
246         i = CONTENT_WATER;
247         f = &content_features(i);
248         f->setInventoryTextureCube("water.png", "water.png", "water.png");
249         f->param_type = CPT_LIGHT;
250         f->light_propagates = true;
251         f->solidness = 0; // Drawn separately, makes no faces
252         f->walkable = false;
253         f->pointable = false;
254         f->diggable = false;
255         f->buildable_to = true;
256         f->liquid_type = LIQUID_FLOWING;
257         f->liquid_alternative_flowing = CONTENT_WATER;
258         
259         i = CONTENT_WATERSOURCE;
260         f = &content_features(i);
261         //f->setInventoryTexture("water.png");
262         f->setInventoryTextureCube("water.png", "water.png", "water.png");
263         if(new_style_water)
264         {
265                 f->solidness = 0; // drawn separately, makes no faces
266         }
267         else // old style
268         {
269                 f->solidness = 1;
270
271                 TileSpec t;
272                 if(g_texturesource)
273                         t.texture = g_texturesource->getTexture("water.png");
274                 
275                 t.alpha = WATER_ALPHA;
276                 t.material_type = MATERIAL_ALPHA_VERTEX;
277                 t.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
278                 f->setAllTiles(t);
279         }
280         f->param_type = CPT_LIGHT;
281         f->light_propagates = true;
282         f->walkable = false;
283         f->pointable = false;
284         f->diggable = false;
285         f->buildable_to = true;
286         f->liquid_type = LIQUID_SOURCE;
287         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
288         f->liquid_alternative_flowing = CONTENT_WATER;
289         
290         i = CONTENT_TORCH;
291         f = &content_features(i);
292         f->setInventoryTexture("torch_on_floor.png");
293         f->param_type = CPT_LIGHT;
294         f->light_propagates = true;
295         f->sunlight_propagates = true;
296         f->solidness = 0; // drawn separately, makes no faces
297         f->walkable = false;
298         f->wall_mounted = true;
299         f->air_equivalent = true;
300         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
301         f->light_source = LIGHT_MAX-1;
302         f->digging_properties.set("", DiggingProperties(true, 0.0, 0));
303         
304         i = CONTENT_SIGN_WALL;
305         f = &content_features(i);
306         f->setInventoryTexture("sign_wall.png");
307         f->param_type = CPT_LIGHT;
308         f->light_propagates = true;
309         f->sunlight_propagates = true;
310         f->solidness = 0; // drawn separately, makes no faces
311         f->walkable = false;
312         f->wall_mounted = true;
313         f->air_equivalent = true;
314         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
315         if(f->initial_metadata == NULL)
316                 f->initial_metadata = new SignNodeMetadata("Some sign");
317         f->digging_properties.set("", DiggingProperties(true, 0.5, 0));
318         
319         i = CONTENT_CHEST;
320         f = &content_features(i);
321         f->param_type = CPT_FACEDIR_SIMPLE;
322         f->setAllTextures("chest_side.png");
323         f->setTexture(0, "chest_top.png");
324         f->setTexture(1, "chest_top.png");
325         f->setTexture(5, "chest_front.png"); // Z-
326         f->setInventoryTexture("chest_top.png");
327         //f->setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
328         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
329         if(f->initial_metadata == NULL)
330                 f->initial_metadata = new ChestNodeMetadata();
331         setWoodLikeDiggingProperties(f->digging_properties, 1.0);
332         
333         i = CONTENT_FURNACE;
334         f = &content_features(i);
335         f->param_type = CPT_FACEDIR_SIMPLE;
336         f->setAllTextures("furnace_side.png");
337         f->setTexture(5, "furnace_front.png"); // Z-
338         f->setInventoryTexture("furnace_front.png");
339         //f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
340         f->dug_item = std::string("MaterialItem ")+itos(CONTENT_COBBLE)+" 6";
341         if(f->initial_metadata == NULL)
342                 f->initial_metadata = new FurnaceNodeMetadata();
343         setStoneLikeDiggingProperties(f->digging_properties, 3.0);
344         
345         i = CONTENT_COBBLE;
346         f = &content_features(i);
347         f->setAllTextures("cobble.png");
348         f->setInventoryTextureCube("cobble.png", "cobble.png", "cobble.png");
349         f->param_type = CPT_NONE;
350         f->is_ground_content = true;
351         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
352         setStoneLikeDiggingProperties(f->digging_properties, 0.9);
353
354         i = CONTENT_MOSSYCOBBLE;
355         f = &content_features(i);
356         f->setAllTextures("mossycobble.png");
357         f->setInventoryTextureCube("mossycobble.png", "mossycobble.png", "mossycobble.png");
358         f->param_type = CPT_NONE;
359         f->is_ground_content = true;
360         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
361         setStoneLikeDiggingProperties(f->digging_properties, 0.8);
362         
363         i = CONTENT_STEEL;
364         f = &content_features(i);
365         f->setAllTextures("steel_block.png");
366         f->setInventoryTextureCube("steel_block.png", "steel_block.png",
367                         "steel_block.png");
368         f->param_type = CPT_NONE;
369         f->is_ground_content = true;
370         f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
371         setStoneLikeDiggingProperties(f->digging_properties, 5.0);
372         
373         // NOTE: Remember to add frequently used stuff to the texture atlas in tile.cpp
374         
375
376         /*
377                 Add MesePick to everything
378         */
379         for(u16 i=0; i<256; i++)
380         {
381                 content_features(i).digging_properties.set("MesePick",
382                                 DiggingProperties(true, 0.0, 65535./1337));
383         }
384
385 }
386
387 void setStoneLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
388 {
389         list.set("",
390                         DiggingProperties(true, 15.0*toughness, 0));
391         
392         list.set("WPick",
393                         DiggingProperties(true, 1.3*toughness, 65535./30.*toughness));
394         list.set("STPick",
395                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
396         list.set("SteelPick",
397                         DiggingProperties(true, 0.50*toughness, 65535./333.*toughness));
398
399         /*list.set("MesePick",
400                         DiggingProperties(true, 0.0*toughness, 65535./20.*toughness));*/
401 }
402
403 void setDirtLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
404 {
405         list.set("",
406                         DiggingProperties(true, 0.75*toughness, 0));
407         
408         list.set("WShovel",
409                         DiggingProperties(true, 0.4*toughness, 65535./50.*toughness));
410         list.set("STShovel",
411                         DiggingProperties(true, 0.2*toughness, 65535./150.*toughness));
412         list.set("SteelShovel",
413                         DiggingProperties(true, 0.15*toughness, 65535./400.*toughness));
414 }
415
416 void setWoodLikeDiggingProperties(DiggingPropertiesList &list, float toughness)
417 {
418         list.set("",
419                         DiggingProperties(true, 3.0*toughness, 0));
420         
421         list.set("WAxe",
422                         DiggingProperties(true, 1.5*toughness, 65535./30.*toughness));
423         list.set("STAxe",
424                         DiggingProperties(true, 0.75*toughness, 65535./100.*toughness));
425         list.set("SteelAxe",
426                         DiggingProperties(true, 0.5*toughness, 65535./333.*toughness));
427 }
428
429