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