3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #include "content_craft.h"
21 #include "inventory.h"
22 #include "content_mapnode.h"
26 items: actually *items[9]
27 return value: allocates a new item, or returns NULL.
29 InventoryItem *craft_get_result(InventoryItem **items)
34 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
35 if(checkItemCombination(items, specs))
37 return new MaterialItem(CONTENT_WOOD, 4);
44 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
45 if(checkItemCombination(items, specs))
47 return new CraftItem("Stick", 4);
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))
62 return new MaterialItem(CONTENT_FENCE, 2);
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))
78 //return new MapBlockObjectItem("Sign");
79 return new MaterialItem(CONTENT_SIGN_WALL, 1);
86 specs[0] = ItemSpec(ITEM_CRAFT, "lump_of_coal");
87 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
88 if(checkItemCombination(items, specs))
90 return new MaterialItem(CONTENT_TORCH, 4);
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))
104 return new ToolItem("WPick", 0);
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))
118 return new ToolItem("STPick", 0);
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))
132 return new ToolItem("SteelPick", 0);
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))
146 return new ToolItem("MesePick", 0);
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))
158 return new ToolItem("WShovel", 0);
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))
170 return new ToolItem("STShovel", 0);
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))
182 return new ToolItem("SteelShovel", 0);
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))
196 return new ToolItem("WAxe", 0);
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))
210 return new ToolItem("STAxe", 0);
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))
224 return new ToolItem("SteelAxe", 0);
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))
236 return new ToolItem("WSword", 0);
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))
248 return new ToolItem("STSword", 0);
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))
260 return new ToolItem("SteelSword", 0);
267 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
268 specs[1] = ItemSpec(ITEM_CRAFT, "Stick");
269 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
270 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
271 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
272 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
273 specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
274 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
275 specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
276 if(checkItemCombination(items, specs))
278 return new MaterialItem(CONTENT_RAIL, 15);
285 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
286 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
287 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
288 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
289 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
290 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
291 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
292 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
293 if(checkItemCombination(items, specs))
295 return new MaterialItem(CONTENT_CHEST, 1);
302 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
303 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
304 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
305 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
306 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
307 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
308 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
309 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
310 if(checkItemCombination(items, specs))
312 return new MaterialItem(CONTENT_FURNACE, 1);
319 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
320 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
321 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
322 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
323 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
324 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
325 specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
326 specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
327 specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
328 if(checkItemCombination(items, specs))
330 return new MaterialItem(CONTENT_STEEL, 1);
337 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
338 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
339 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
340 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
341 if(checkItemCombination(items, specs))
343 return new MaterialItem(CONTENT_SANDSTONE, 1);
350 specs[3] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
351 specs[4] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
352 specs[6] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
353 specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
354 if(checkItemCombination(items, specs))
356 return new MaterialItem(CONTENT_CLAY, 1);
363 specs[3] = ItemSpec(ITEM_CRAFT, "clay_brick");
364 specs[4] = ItemSpec(ITEM_CRAFT, "clay_brick");
365 specs[6] = ItemSpec(ITEM_CRAFT, "clay_brick");
366 specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
367 if(checkItemCombination(items, specs))
369 return new MaterialItem(CONTENT_BRICK, 1);
376 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
377 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
378 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
379 if(checkItemCombination(items, specs))
381 return new CraftItem("paper", 1);
388 specs[1] = ItemSpec(ITEM_CRAFT, "paper");
389 specs[4] = ItemSpec(ITEM_CRAFT, "paper");
390 specs[7] = ItemSpec(ITEM_CRAFT, "paper");
391 if(checkItemCombination(items, specs))
393 return new CraftItem("book", 1);
400 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
401 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
402 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
403 specs[3] = ItemSpec(ITEM_CRAFT, "book");
404 specs[4] = ItemSpec(ITEM_CRAFT, "book");
405 specs[5] = ItemSpec(ITEM_CRAFT, "book");
406 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
407 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
408 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
409 if(checkItemCombination(items, specs))
411 return new MaterialItem(CONTENT_BOOKSHELF, 1);
418 void craft_set_creative_inventory(Player *player)
420 player->resetInventory();
422 // Give some good tools
424 InventoryItem *item = new ToolItem("MesePick", 0);
425 void* r = player->inventory.addItem("main", item);
429 InventoryItem *item = new ToolItem("SteelPick", 0);
430 void* r = player->inventory.addItem("main", item);
434 InventoryItem *item = new ToolItem("SteelAxe", 0);
435 void* r = player->inventory.addItem("main", item);
439 InventoryItem *item = new ToolItem("SteelShovel", 0);
440 void* r = player->inventory.addItem("main", item);
448 // CONTENT_IGNORE-terminated list
449 u8 material_items[] = {
475 u8 *mip = material_items;
476 for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
478 if(*mip == CONTENT_IGNORE)
481 InventoryItem *item = new MaterialItem(*mip, 1);
482 player->inventory.addItem("main", item);
488 assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
491 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
492 player->inventory.addItem("main", item);
495 for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
497 // Skip some materials
498 if(i == CONTENT_WATER || i == CONTENT_TORCH
499 || i == CONTENT_COALSTONE)
502 InventoryItem *item = new MaterialItem(i, 1);
503 player->inventory.addItem("main", item);
509 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
510 void* r = player->inventory.addItem("main", item);
515 void craft_give_initial_stuff(Player *player)
518 InventoryItem *item = new ToolItem("SteelPick", 0);
519 void* r = player->inventory.addItem("main", item);
523 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
524 void* r = player->inventory.addItem("main", item);
528 InventoryItem *item = new ToolItem("SteelAxe", 0);
529 void* r = player->inventory.addItem("main", item);
533 InventoryItem *item = new ToolItem("SteelShovel", 0);
534 void* r = player->inventory.addItem("main", item);
538 InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
539 void* r = player->inventory.addItem("main", item);
543 InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
544 void* r = player->inventory.addItem("main", item);
548 InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
549 void* r = player->inventory.addItem("main", item);
553 InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
554 void* r = player->inventory.addItem("main", item);
558 InventoryItem *item = new CraftItem("Stick", 4);
559 void* r = player->inventory.addItem("main", item);
563 InventoryItem *item = new ToolItem("WPick", 32000);
564 void* r = player->inventory.addItem("main", item);
568 InventoryItem *item = new ToolItem("STPick", 32000);
569 void* r = player->inventory.addItem("main", item);
573 for(u16 i=0; i<4; i++)
575 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
576 bool r = player->inventory.addItem("main", item);
579 /*// Give some other stuff
581 InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
582 bool r = player->inventory.addItem("main", item);