]> git.lizzy.rs Git - minetest.git/blob - src/content_craft.cpp
removed furnace menu because it is not needed anymore
[minetest.git] / src / content_craft.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 #include "content_craft.h"
21 #include "inventory.h"
22 #include "content_mapnode.h"
23 #include "player.h"
24
25 /*
26         items: actually *items[9]
27         return value: allocates a new item, or returns NULL.
28 */
29 InventoryItem *craft_get_result(InventoryItem **items)
30 {
31         // Wood
32         {
33                 ItemSpec specs[9];
34                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
35                 if(checkItemCombination(items, specs))
36                 {
37                         return new MaterialItem(CONTENT_WOOD, 4);
38                 }
39         }
40
41         // Stick
42         {
43                 ItemSpec specs[9];
44                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
45                 if(checkItemCombination(items, specs))
46                 {
47                         return new CraftItem("Stick", 4);
48                 }
49         }
50
51         // Fence
52         {
53                 ItemSpec specs[9];
54                 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
55                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
56                 specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
57                 specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
58                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
59                 specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
60                 if(checkItemCombination(items, specs))
61                 {
62                         return new MaterialItem(CONTENT_FENCE, 2);
63                 }
64         }
65
66         // Sign
67         {
68                 ItemSpec specs[9];
69                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
70                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
71                 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
72                 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
73                 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
74                 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
75                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
76                 if(checkItemCombination(items, specs))
77                 {
78                         //return new MapBlockObjectItem("Sign");
79                         return new MaterialItem(CONTENT_SIGN_WALL, 1);
80                 }
81         }
82
83         // Torch
84         {
85                 ItemSpec specs[9];
86                 specs[0] = ItemSpec(ITEM_CRAFT, "lump_of_coal");
87                 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
88                 if(checkItemCombination(items, specs))
89                 {
90                         return new MaterialItem(CONTENT_TORCH, 4);
91                 }
92         }
93
94         // Wooden pick
95         {
96                 ItemSpec specs[9];
97                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
98                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
99                 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
100                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
101                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
102                 if(checkItemCombination(items, specs))
103                 {
104                         return new ToolItem("WPick", 0);
105                 }
106         }
107
108         // Stone pick
109         {
110                 ItemSpec specs[9];
111                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
112                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
113                 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
114                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
115                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
116                 if(checkItemCombination(items, specs))
117                 {
118                         return new ToolItem("STPick", 0);
119                 }
120         }
121
122         // Steel pick
123         {
124                 ItemSpec specs[9];
125                 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
126                 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
127                 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
128                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
129                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
130                 if(checkItemCombination(items, specs))
131                 {
132                         return new ToolItem("SteelPick", 0);
133                 }
134         }
135
136         // Mese pick
137         {
138                 ItemSpec specs[9];
139                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
140                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
141                 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
142                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
143                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
144                 if(checkItemCombination(items, specs))
145                 {
146                         return new ToolItem("MesePick", 0);
147                 }
148         }
149
150         // Wooden shovel
151         {
152                 ItemSpec specs[9];
153                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
154                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
155                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
156                 if(checkItemCombination(items, specs))
157                 {
158                         return new ToolItem("WShovel", 0);
159                 }
160         }
161
162         // Stone shovel
163         {
164                 ItemSpec specs[9];
165                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
166                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
167                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
168                 if(checkItemCombination(items, specs))
169                 {
170                         return new ToolItem("STShovel", 0);
171                 }
172         }
173
174         // Steel shovel
175         {
176                 ItemSpec specs[9];
177                 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
178                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
179                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
180                 if(checkItemCombination(items, specs))
181                 {
182                         return new ToolItem("SteelShovel", 0);
183                 }
184         }
185
186         // Wooden axe
187         {
188                 ItemSpec specs[9];
189                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
190                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
191                 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
192                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
193                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
194                 if(checkItemCombination(items, specs))
195                 {
196                         return new ToolItem("WAxe", 0);
197                 }
198         }
199
200         // Stone axe
201         {
202                 ItemSpec specs[9];
203                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
204                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
205                 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
206                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
207                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
208                 if(checkItemCombination(items, specs))
209                 {
210                         return new ToolItem("STAxe", 0);
211                 }
212         }
213
214         // Steel axe
215         {
216                 ItemSpec specs[9];
217                 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
218                 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
219                 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
220                 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
221                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
222                 if(checkItemCombination(items, specs))
223                 {
224                         return new ToolItem("SteelAxe", 0);
225                 }
226         }
227
228         // Wooden sword
229         {
230                 ItemSpec specs[9];
231                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
232                 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
233                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
234                 if(checkItemCombination(items, specs))
235                 {
236                         return new ToolItem("WSword", 0);
237                 }
238         }
239
240         // Stone sword
241         {
242                 ItemSpec specs[9];
243                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
244                 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
245                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
246                 if(checkItemCombination(items, specs))
247                 {
248                         return new ToolItem("STSword", 0);
249                 }
250         }
251
252         // Steel sword
253         {
254                 ItemSpec specs[9];
255                 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
256                 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
257                 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
258                 if(checkItemCombination(items, specs))
259                 {
260                         return new ToolItem("SteelSword", 0);
261                 }
262         }
263
264         // Chest
265         {
266                 ItemSpec specs[9];
267                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
268                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
269                 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
270                 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
271                 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
272                 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
273                 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
274                 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
275                 if(checkItemCombination(items, specs))
276                 {
277                         return new MaterialItem(CONTENT_CHEST, 1);
278                 }
279         }
280
281         // Furnace
282         {
283                 ItemSpec specs[9];
284                 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
285                 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
286                 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
287                 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
288                 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
289                 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
290                 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
291                 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
292                 if(checkItemCombination(items, specs))
293                 {
294                         return new MaterialItem(CONTENT_FURNACE, 1);
295                 }
296         }
297
298         // Steel block
299         {
300                 ItemSpec specs[9];
301                 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
302                 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
303                 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
304                 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
305                 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
306                 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
307                 specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
308                 specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
309                 specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
310                 if(checkItemCombination(items, specs))
311                 {
312                         return new MaterialItem(CONTENT_STEEL, 1);
313                 }
314         }
315
316         return NULL;
317 }
318
319 void craft_set_creative_inventory(Player *player)
320 {
321         player->resetInventory();
322         
323         // Give some good tools
324         {
325                 InventoryItem *item = new ToolItem("MesePick", 0);
326                 void* r = player->inventory.addItem("main", item);
327                 assert(r == NULL);
328         }
329         {
330                 InventoryItem *item = new ToolItem("SteelPick", 0);
331                 void* r = player->inventory.addItem("main", item);
332                 assert(r == NULL);
333         }
334         {
335                 InventoryItem *item = new ToolItem("SteelAxe", 0);
336                 void* r = player->inventory.addItem("main", item);
337                 assert(r == NULL);
338         }
339         {
340                 InventoryItem *item = new ToolItem("SteelShovel", 0);
341                 void* r = player->inventory.addItem("main", item);
342                 assert(r == NULL);
343         }
344
345         /*
346                 Give materials
347         */
348         
349         // CONTENT_IGNORE-terminated list
350         u8 material_items[] = {
351                 CONTENT_TORCH,
352                 CONTENT_COBBLE,
353                 CONTENT_MUD,
354                 CONTENT_STONE,
355                 CONTENT_SAND,
356                 CONTENT_TREE,
357                 CONTENT_LEAVES,
358                 CONTENT_GLASS,
359                 CONTENT_FENCE,
360                 CONTENT_MESE,
361                 CONTENT_WATERSOURCE,
362                 CONTENT_CLOUD,
363                 CONTENT_CHEST,
364                 CONTENT_FURNACE,
365                 CONTENT_SIGN_WALL,
366                 CONTENT_IGNORE
367         };
368         
369         u8 *mip = material_items;
370         for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
371         {
372                 if(*mip == CONTENT_IGNORE)
373                         break;
374
375                 InventoryItem *item = new MaterialItem(*mip, 1);
376                 player->inventory.addItem("main", item);
377
378                 mip++;
379         }
380
381 #if 0
382         assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
383         
384         // add torch first
385         InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
386         player->inventory.addItem("main", item);
387         
388         // Then others
389         for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
390         {
391                 // Skip some materials
392                 if(i == CONTENT_WATER || i == CONTENT_TORCH
393                         || i == CONTENT_COALSTONE)
394                         continue;
395
396                 InventoryItem *item = new MaterialItem(i, 1);
397                 player->inventory.addItem("main", item);
398         }
399 #endif
400
401         /*// Sign
402         {
403                 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
404                 void* r = player->inventory.addItem("main", item);
405                 assert(r == NULL);
406         }*/
407 }
408
409 void craft_give_initial_stuff(Player *player)
410 {
411         {
412                 InventoryItem *item = new ToolItem("SteelPick", 0);
413                 void* r = player->inventory.addItem("main", item);
414                 assert(r == NULL);
415         }
416         {
417                 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
418                 void* r = player->inventory.addItem("main", item);
419                 assert(r == NULL);
420         }
421         {
422                 InventoryItem *item = new ToolItem("SteelAxe", 0);
423                 void* r = player->inventory.addItem("main", item);
424                 assert(r == NULL);
425         }
426         {
427                 InventoryItem *item = new ToolItem("SteelShovel", 0);
428                 void* r = player->inventory.addItem("main", item);
429                 assert(r == NULL);
430         }
431         {
432                 InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
433                 void* r = player->inventory.addItem("main", item);
434                 assert(r == NULL);
435         }
436         /*{
437                 InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
438                 void* r = player->inventory.addItem("main", item);
439                 assert(r == NULL);
440         }
441         {
442                 InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
443                 void* r = player->inventory.addItem("main", item);
444                 assert(r == NULL);
445         }
446         {
447                 InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
448                 void* r = player->inventory.addItem("main", item);
449                 assert(r == NULL);
450         }
451         {
452                 InventoryItem *item = new CraftItem("Stick", 4);
453                 void* r = player->inventory.addItem("main", item);
454                 assert(r == NULL);
455         }
456         {
457                 InventoryItem *item = new ToolItem("WPick", 32000);
458                 void* r = player->inventory.addItem("main", item);
459                 assert(r == NULL);
460         }
461         {
462                 InventoryItem *item = new ToolItem("STPick", 32000);
463                 void* r = player->inventory.addItem("main", item);
464                 assert(r == NULL);
465         }*/
466         /*// and some signs
467         for(u16 i=0; i<4; i++)
468         {
469                 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
470                 bool r = player->inventory.addItem("main", item);
471                 assert(r == true);
472         }*/
473         /*// Give some other stuff
474         {
475                 InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
476                 bool r = player->inventory.addItem("main", item);
477                 assert(r == true);
478         }*/
479 }
480