some generation-time mud flow tweaking
[oweals/minetest.git] / src / mapnode.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010 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 #include "mapnode.h"
21 #include "tile.h"
22 #include "porting.h"
23 #include <string>
24 #include "mineral.h"
25
26 ContentFeatures::~ContentFeatures()
27 {
28         if(translate_to)
29                 delete translate_to;
30 }
31
32 struct ContentFeatures g_content_features[256];
33
34 ContentFeatures & content_features(u8 i)
35 {
36         return g_content_features[i];
37 }
38
39 void init_mapnode(IIrrlichtWrapper *irrlicht)
40 {
41         u8 i;
42         ContentFeatures *f = NULL;
43
44         i = CONTENT_STONE;
45         f = &g_content_features[i];
46         f->setAllTextures(irrlicht->getTextureId("stone.png"));
47         f->param_type = CPT_MINERAL;
48         f->is_ground_content = true;
49         
50         i = CONTENT_GRASS;
51         f = &g_content_features[i];
52         f->setAllTextures(TextureSpec(irrlicht->getTextureId("mud.png"),
53                         irrlicht->getTextureId("grass_side.png")));
54         f->setTexture(0, irrlicht->getTextureId("grass.png"));
55         f->setTexture(1, irrlicht->getTextureId("mud.png"));
56         f->setInventoryTexture(irrlicht->getTextureId("grass.png"));
57         f->param_type = CPT_MINERAL;
58         f->is_ground_content = true;
59         
60         i = CONTENT_GRASS_FOOTSTEPS;
61         f = &g_content_features[i];
62         f->setAllTextures(TextureSpec(irrlicht->getTextureId("mud.png"),
63                         irrlicht->getTextureId("grass_side.png")));
64         f->setTexture(0, irrlicht->getTextureId("grass_footsteps.png"));
65         f->setTexture(1, irrlicht->getTextureId("mud.png"));
66         f->setInventoryTexture(irrlicht->getTextureId("grass_footsteps.png"));
67         f->param_type = CPT_MINERAL;
68         f->is_ground_content = true;
69         
70         i = CONTENT_MUD;
71         f = &g_content_features[i];
72         f->setAllTextures(irrlicht->getTextureId("mud.png"));
73         f->param_type = CPT_MINERAL;
74         f->is_ground_content = true;
75         
76         i = CONTENT_SAND;
77         f = &g_content_features[i];
78         f->setAllTextures(irrlicht->getTextureId("mud.png"));
79         f->param_type = CPT_MINERAL;
80         f->is_ground_content = true;
81         
82         i = CONTENT_TREE;
83         f = &g_content_features[i];
84         f->setAllTextures(irrlicht->getTextureId("tree.png"));
85         f->setTexture(0, irrlicht->getTextureId("tree_top.png"));
86         f->setTexture(1, irrlicht->getTextureId("tree_top.png"));
87         f->setInventoryTexture(irrlicht->getTextureId("tree_top.png"));
88         f->param_type = CPT_MINERAL;
89         f->is_ground_content = true;
90         
91         i = CONTENT_LEAVES;
92         f = &g_content_features[i];
93         f->setAllTextures(irrlicht->getTextureId("leaves.png"));
94         f->param_type = CPT_MINERAL;
95         f->is_ground_content = true;
96         
97         i = CONTENT_COALSTONE;
98         f = &g_content_features[i];
99         f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
100         /*f->setAllTextures(irrlicht->getTextureId("coalstone.png"));
101         f->is_ground_content = true;*/
102         
103         i = CONTENT_WOOD;
104         f = &g_content_features[i];
105         f->setAllTextures(irrlicht->getTextureId("wood.png"));
106         f->is_ground_content = true;
107         
108         i = CONTENT_MESE;
109         f = &g_content_features[i];
110         f->setAllTextures(irrlicht->getTextureId("mese.png"));
111         f->is_ground_content = true;
112         
113         i = CONTENT_CLOUD;
114         f = &g_content_features[i];
115         f->setAllTextures(irrlicht->getTextureId("cloud.png"));
116         f->is_ground_content = true;
117         
118         i = CONTENT_AIR;
119         f = &g_content_features[i];
120         f->param_type = CPT_LIGHT;
121         f->light_propagates = true;
122         f->sunlight_propagates = true;
123         f->solidness = 0;
124         f->walkable = false;
125         f->pointable = false;
126         f->diggable = false;
127         f->buildable_to = true;
128         
129         i = CONTENT_WATER;
130         f = &g_content_features[i];
131         f->setInventoryTexture(irrlicht->getTextureId("water.png"));
132         f->param_type = CPT_LIGHT;
133         f->light_propagates = true;
134         f->solidness = 0; // Drawn separately, makes no faces
135         f->walkable = false;
136         f->pointable = false;
137         f->diggable = false;
138         f->buildable_to = true;
139         f->liquid_type = LIQUID_FLOWING;
140         
141         i = CONTENT_WATERSOURCE;
142         f = &g_content_features[i];
143         //f->setTexture(0, irrlicht->getTextureId("water.png"), WATER_ALPHA);
144         f->setAllTextures(irrlicht->getTextureId("water.png"), WATER_ALPHA);
145         f->setInventoryTexture(irrlicht->getTextureId("water.png"));
146         f->param_type = CPT_LIGHT;
147         f->light_propagates = true;
148         f->solidness = 1;
149         f->walkable = false;
150         f->pointable = false;
151         f->diggable = false;
152         f->buildable_to = true;
153         f->liquid_type = LIQUID_SOURCE;
154         
155         i = CONTENT_TORCH;
156         f = &g_content_features[i];
157         f->setInventoryTexture(irrlicht->getTextureId("torch_on_floor.png"));
158         f->param_type = CPT_LIGHT;
159         f->light_propagates = true;
160         f->solidness = 0; // drawn separately, makes no faces
161         f->walkable = false;
162         f->wall_mounted = true;
163         
164 }
165
166 TileSpec MapNode::getTile(v3s16 dir)
167 {
168         TileSpec spec;
169         
170         s32 dir_i = -1;
171         
172         if(dir == v3s16(0,0,0))
173                 dir_i = -1;
174         else if(dir == v3s16(0,1,0))
175                 dir_i = 0;
176         else if(dir == v3s16(0,-1,0))
177                 dir_i = 1;
178         else if(dir == v3s16(1,0,0))
179                 dir_i = 2;
180         else if(dir == v3s16(-1,0,0))
181                 dir_i = 3;
182         else if(dir == v3s16(0,0,1))
183                 dir_i = 4;
184         else if(dir == v3s16(0,0,-1))
185                 dir_i = 5;
186         
187         if(dir_i == -1)
188                 // Non-directional
189                 spec = content_features(d).tiles[0];
190         else 
191                 spec = content_features(d).tiles[dir_i];
192         
193         if(content_features(d).param_type == CPT_MINERAL)
194         {
195                 u8 mineral = param & 0x1f;
196                 // Add mineral block texture
197                 textureid_t tid = mineral_block_texture(mineral);
198                 if(tid != 0)
199                         spec.spec.addTid(tid);
200         }
201
202         return spec;
203 }
204
205 u8 MapNode::getMineral()
206 {
207         if(content_features(d).param_type == CPT_MINERAL)
208         {
209                 return param & 0x1f;
210         }
211
212         return MINERAL_NONE;
213 }
214
215 // Pointers to c_str()s g_content_features[i].inventory_image_path
216 //const char * g_content_inventory_texture_paths[USEFUL_CONTENT_COUNT] = {0};
217
218 void init_content_inventory_texture_paths()
219 {
220         dstream<<"DEPRECATED "<<__FUNCTION_NAME<<std::endl;
221         /*for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
222         {
223                 g_content_inventory_texture_paths[i] =
224                                 g_content_features[i].inventory_image_path.c_str();
225         }*/
226 }
227