Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 : the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 :
15 : You should have received a copy of the GNU Lesser 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 "content_mapnode.h"
21 :
22 : #include "irrlichttypes_bloated.h"
23 : #include "mapnode.h"
24 : #include "nodedef.h"
25 : #include "nameidmapping.h"
26 : #include "util/string.h"
27 :
28 : /*
29 : Legacy node content type IDs
30 : Ranges:
31 : 0x000...0x07f (0...127): param2 is fully usable
32 : 126 and 127 are reserved (CONTENT_AIR and CONTENT_IGNORE).
33 : 0x800...0xfff (2048...4095): higher 4 bits of param2 are not usable
34 : */
35 : #define CONTENT_STONE 0
36 : #define CONTENT_WATER 2
37 : #define CONTENT_TORCH 3
38 : #define CONTENT_WATERSOURCE 9
39 : #define CONTENT_SIGN_WALL 14
40 : #define CONTENT_CHEST 15
41 : #define CONTENT_FURNACE 16
42 : #define CONTENT_LOCKABLE_CHEST 17
43 : #define CONTENT_FENCE 21
44 : #define CONTENT_RAIL 30
45 : #define CONTENT_LADDER 31
46 : #define CONTENT_LAVA 32
47 : #define CONTENT_LAVASOURCE 33
48 : #define CONTENT_GRASS 0x800 //1
49 : #define CONTENT_TREE 0x801 //4
50 : #define CONTENT_LEAVES 0x802 //5
51 : #define CONTENT_GRASS_FOOTSTEPS 0x803 //6
52 : #define CONTENT_MESE 0x804 //7
53 : #define CONTENT_MUD 0x805 //8
54 : #define CONTENT_CLOUD 0x806 //10
55 : #define CONTENT_COALSTONE 0x807 //11
56 : #define CONTENT_WOOD 0x808 //12
57 : #define CONTENT_SAND 0x809 //13
58 : #define CONTENT_COBBLE 0x80a //18
59 : #define CONTENT_STEEL 0x80b //19
60 : #define CONTENT_GLASS 0x80c //20
61 : #define CONTENT_MOSSYCOBBLE 0x80d //22
62 : #define CONTENT_GRAVEL 0x80e //23
63 : #define CONTENT_SANDSTONE 0x80f //24
64 : #define CONTENT_CACTUS 0x810 //25
65 : #define CONTENT_BRICK 0x811 //26
66 : #define CONTENT_CLAY 0x812 //27
67 : #define CONTENT_PAPYRUS 0x813 //28
68 : #define CONTENT_BOOKSHELF 0x814 //29
69 : #define CONTENT_JUNGLETREE 0x815
70 : #define CONTENT_JUNGLEGRASS 0x816
71 : #define CONTENT_NC 0x817
72 : #define CONTENT_NC_RB 0x818
73 : #define CONTENT_APPLE 0x819
74 : #define CONTENT_SAPLING 0x820
75 :
76 : /*
77 : A conversion table for backwards compatibility.
78 : Maps <=v19 content types to current ones.
79 : Should never be touched.
80 : */
81 : content_t trans_table_19[21][2] = {
82 : {CONTENT_GRASS, 1},
83 : {CONTENT_TREE, 4},
84 : {CONTENT_LEAVES, 5},
85 : {CONTENT_GRASS_FOOTSTEPS, 6},
86 : {CONTENT_MESE, 7},
87 : {CONTENT_MUD, 8},
88 : {CONTENT_CLOUD, 10},
89 : {CONTENT_COALSTONE, 11},
90 : {CONTENT_WOOD, 12},
91 : {CONTENT_SAND, 13},
92 : {CONTENT_COBBLE, 18},
93 : {CONTENT_STEEL, 19},
94 : {CONTENT_GLASS, 20},
95 : {CONTENT_MOSSYCOBBLE, 22},
96 : {CONTENT_GRAVEL, 23},
97 : {CONTENT_SANDSTONE, 24},
98 : {CONTENT_CACTUS, 25},
99 : {CONTENT_BRICK, 26},
100 : {CONTENT_CLAY, 27},
101 : {CONTENT_PAPYRUS, 28},
102 : {CONTENT_BOOKSHELF, 29},
103 : };
104 :
105 0 : MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
106 : {
107 0 : MapNode result = n_from;
108 0 : if(version <= 19)
109 : {
110 0 : content_t c_from = n_from.getContent();
111 0 : for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
112 : {
113 0 : if(trans_table_19[i][1] == c_from)
114 : {
115 0 : result.setContent(trans_table_19[i][0]);
116 0 : break;
117 : }
118 : }
119 : }
120 0 : return result;
121 : }
122 :
123 0 : void content_mapnode_get_name_id_mapping(NameIdMapping *nimap)
124 : {
125 0 : nimap->set(0, "default:stone");
126 0 : nimap->set(2, "default:water_flowing");
127 0 : nimap->set(3, "default:torch");
128 0 : nimap->set(9, "default:water_source");
129 0 : nimap->set(14, "default:sign_wall");
130 0 : nimap->set(15, "default:chest");
131 0 : nimap->set(16, "default:furnace");
132 0 : nimap->set(17, "default:chest_locked");
133 0 : nimap->set(21, "default:fence_wood");
134 0 : nimap->set(30, "default:rail");
135 0 : nimap->set(31, "default:ladder");
136 0 : nimap->set(32, "default:lava_flowing");
137 0 : nimap->set(33, "default:lava_source");
138 0 : nimap->set(0x800, "default:dirt_with_grass");
139 0 : nimap->set(0x801, "default:tree");
140 0 : nimap->set(0x802, "default:leaves");
141 0 : nimap->set(0x803, "default:dirt_with_grass_footsteps");
142 0 : nimap->set(0x804, "default:mese");
143 0 : nimap->set(0x805, "default:dirt");
144 0 : nimap->set(0x806, "default:cloud");
145 0 : nimap->set(0x807, "default:coalstone");
146 0 : nimap->set(0x808, "default:wood");
147 0 : nimap->set(0x809, "default:sand");
148 0 : nimap->set(0x80a, "default:cobble");
149 0 : nimap->set(0x80b, "default:steelblock");
150 0 : nimap->set(0x80c, "default:glass");
151 0 : nimap->set(0x80d, "default:mossycobble");
152 0 : nimap->set(0x80e, "default:gravel");
153 0 : nimap->set(0x80f, "default:sandstone");
154 0 : nimap->set(0x810, "default:cactus");
155 0 : nimap->set(0x811, "default:brick");
156 0 : nimap->set(0x812, "default:clay");
157 0 : nimap->set(0x813, "default:papyrus");
158 0 : nimap->set(0x814, "default:bookshelf");
159 0 : nimap->set(0x815, "default:jungletree");
160 0 : nimap->set(0x816, "default:junglegrass");
161 0 : nimap->set(0x817, "default:nyancat");
162 0 : nimap->set(0x818, "default:nyancat_rainbow");
163 0 : nimap->set(0x819, "default:apple");
164 0 : nimap->set(0x820, "default:sapling");
165 : // Static types
166 0 : nimap->set(CONTENT_IGNORE, "ignore");
167 0 : nimap->set(CONTENT_AIR, "air");
168 0 : }
169 :
170 1 : class NewNameGetter
171 : {
172 : public:
173 1 : NewNameGetter()
174 1 : {
175 1 : old_to_new["CONTENT_STONE"] = "default:stone";
176 1 : old_to_new["CONTENT_WATER"] = "default:water_flowing";
177 1 : old_to_new["CONTENT_TORCH"] = "default:torch";
178 1 : old_to_new["CONTENT_WATERSOURCE"] = "default:water_source";
179 1 : old_to_new["CONTENT_SIGN_WALL"] = "default:sign_wall";
180 1 : old_to_new["CONTENT_CHEST"] = "default:chest";
181 1 : old_to_new["CONTENT_FURNACE"] = "default:furnace";
182 1 : old_to_new["CONTENT_LOCKABLE_CHEST"] = "default:locked_chest";
183 1 : old_to_new["CONTENT_FENCE"] = "default:wooden_fence";
184 1 : old_to_new["CONTENT_RAIL"] = "default:rail";
185 1 : old_to_new["CONTENT_LADDER"] = "default:ladder";
186 1 : old_to_new["CONTENT_LAVA"] = "default:lava_flowing";
187 1 : old_to_new["CONTENT_LAVASOURCE"] = "default:lava_source";
188 1 : old_to_new["CONTENT_GRASS"] = "default:dirt_with_grass";
189 1 : old_to_new["CONTENT_TREE"] = "default:tree";
190 1 : old_to_new["CONTENT_LEAVES"] = "default:leaves";
191 1 : old_to_new["CONTENT_GRASS_FOOTSTEPS"] = "default:dirt_with_grass_footsteps";
192 1 : old_to_new["CONTENT_MESE"] = "default:mese";
193 1 : old_to_new["CONTENT_MUD"] = "default:dirt";
194 1 : old_to_new["CONTENT_CLOUD"] = "default:cloud";
195 1 : old_to_new["CONTENT_COALSTONE"] = "default:coalstone";
196 1 : old_to_new["CONTENT_WOOD"] = "default:wood";
197 1 : old_to_new["CONTENT_SAND"] = "default:sand";
198 1 : old_to_new["CONTENT_COBBLE"] = "default:cobble";
199 1 : old_to_new["CONTENT_STEEL"] = "default:steel";
200 1 : old_to_new["CONTENT_GLASS"] = "default:glass";
201 1 : old_to_new["CONTENT_MOSSYCOBBLE"] = "default:mossycobble";
202 1 : old_to_new["CONTENT_GRAVEL"] = "default:gravel";
203 1 : old_to_new["CONTENT_SANDSTONE"] = "default:sandstone";
204 1 : old_to_new["CONTENT_CACTUS"] = "default:cactus";
205 1 : old_to_new["CONTENT_BRICK"] = "default:brick";
206 1 : old_to_new["CONTENT_CLAY"] = "default:clay";
207 1 : old_to_new["CONTENT_PAPYRUS"] = "default:papyrus";
208 1 : old_to_new["CONTENT_BOOKSHELF"] = "default:bookshelf";
209 1 : old_to_new["CONTENT_JUNGLETREE"] = "default:jungletree";
210 1 : old_to_new["CONTENT_JUNGLEGRASS"] = "default:junglegrass";
211 1 : old_to_new["CONTENT_NC"] = "default:nyancat";
212 1 : old_to_new["CONTENT_NC_RB"] = "default:nyancat_rainbow";
213 1 : old_to_new["CONTENT_APPLE"] = "default:apple";
214 1 : old_to_new["CONTENT_SAPLING"] = "default:sapling";
215 : // Just in case
216 1 : old_to_new["CONTENT_IGNORE"] = "ignore";
217 1 : old_to_new["CONTENT_AIR"] = "air";
218 1 : }
219 0 : std::string get(const std::string &old)
220 : {
221 0 : StringMap::const_iterator it = old_to_new.find(old);
222 0 : if (it == old_to_new.end())
223 0 : return "";
224 0 : return it->second;
225 : }
226 : private:
227 : StringMap old_to_new;
228 : };
229 :
230 1 : NewNameGetter newnamegetter;
231 :
232 0 : std::string content_mapnode_get_new_name(const std::string &oldname)
233 : {
234 0 : return newnamegetter.get(oldname);
235 : }
236 :
237 0 : content_t legacy_get_id(const std::string &oldname, INodeDefManager *ndef)
238 : {
239 0 : std::string newname = content_mapnode_get_new_name(oldname);
240 0 : if(newname == "")
241 0 : return CONTENT_IGNORE;
242 : content_t id;
243 0 : bool found = ndef->getId(newname, id);
244 0 : if(!found)
245 0 : return CONTENT_IGNORE;
246 0 : return id;
247 3 : }
248 :
|