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