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"
24 #include "mapnode.h" // For content_t
27 items: actually *items[9]
28 return value: allocates a new item, or returns NULL.
30 InventoryItem *craft_get_result(InventoryItem **items)
35 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE);
36 if(checkItemCombination(items, specs))
38 return new MaterialItem(CONTENT_WOOD, 4);
45 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
46 if(checkItemCombination(items, specs))
48 return new CraftItem("Stick", 4);
55 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
56 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
57 specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
58 specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
59 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
60 specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
61 if(checkItemCombination(items, specs))
63 return new MaterialItem(CONTENT_FENCE, 2);
70 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
71 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
72 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
73 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
74 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
75 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
76 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
77 if(checkItemCombination(items, specs))
79 //return new MapBlockObjectItem("Sign");
80 return new MaterialItem(CONTENT_SIGN_WALL, 1);
87 specs[0] = ItemSpec(ITEM_CRAFT, "lump_of_coal");
88 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
89 if(checkItemCombination(items, specs))
91 return new MaterialItem(CONTENT_TORCH, 4);
98 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
99 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
100 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
101 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
102 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
103 if(checkItemCombination(items, specs))
105 return new ToolItem("WPick", 0);
112 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
113 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
114 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
115 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
116 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
117 if(checkItemCombination(items, specs))
119 return new ToolItem("STPick", 0);
126 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
127 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
128 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
129 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
130 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
131 if(checkItemCombination(items, specs))
133 return new ToolItem("SteelPick", 0);
140 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
141 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
142 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE);
143 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
144 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
145 if(checkItemCombination(items, specs))
147 return new ToolItem("MesePick", 0);
154 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
155 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
156 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
157 if(checkItemCombination(items, specs))
159 return new ToolItem("WShovel", 0);
166 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
167 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
168 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
169 if(checkItemCombination(items, specs))
171 return new ToolItem("STShovel", 0);
178 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
179 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
180 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
181 if(checkItemCombination(items, specs))
183 return new ToolItem("SteelShovel", 0);
190 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
191 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
192 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
193 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
194 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
195 if(checkItemCombination(items, specs))
197 return new ToolItem("WAxe", 0);
204 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
205 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
206 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
207 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
208 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
209 if(checkItemCombination(items, specs))
211 return new ToolItem("STAxe", 0);
218 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
219 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
220 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
221 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
222 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
223 if(checkItemCombination(items, specs))
225 return new ToolItem("SteelAxe", 0);
232 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
233 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
234 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
235 if(checkItemCombination(items, specs))
237 return new ToolItem("WSword", 0);
244 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
245 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
246 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
247 if(checkItemCombination(items, specs))
249 return new ToolItem("STSword", 0);
256 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
257 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
258 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
259 if(checkItemCombination(items, specs))
261 return new ToolItem("SteelSword", 0);
268 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
269 specs[1] = ItemSpec(ITEM_CRAFT, "Stick");
270 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
271 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
272 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
273 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
274 specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
275 specs[7] = ItemSpec(ITEM_CRAFT, "Stick");
276 specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
277 if(checkItemCombination(items, specs))
279 return new MaterialItem(CONTENT_RAIL, 15);
286 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
287 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
288 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
289 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
290 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
291 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
292 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
293 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
294 if(checkItemCombination(items, specs))
296 return new MaterialItem(CONTENT_CHEST, 1);
303 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
304 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
305 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
306 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
307 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
308 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
309 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
310 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
311 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
312 if(checkItemCombination(items, specs))
314 return new MaterialItem(CONTENT_LOCKABLE_CHEST, 1);
321 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
322 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
323 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
324 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
325 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
326 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
327 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
328 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
329 if(checkItemCombination(items, specs))
331 return new MaterialItem(CONTENT_FURNACE, 1);
338 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
339 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
340 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
341 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
342 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
343 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
344 specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
345 specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
346 specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
347 if(checkItemCombination(items, specs))
349 return new MaterialItem(CONTENT_STEEL, 1);
356 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
357 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
358 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
359 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
360 if(checkItemCombination(items, specs))
362 return new MaterialItem(CONTENT_SANDSTONE, 1);
369 specs[3] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
370 specs[4] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
371 specs[6] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
372 specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
373 if(checkItemCombination(items, specs))
375 return new MaterialItem(CONTENT_CLAY, 1);
382 specs[3] = ItemSpec(ITEM_CRAFT, "clay_brick");
383 specs[4] = ItemSpec(ITEM_CRAFT, "clay_brick");
384 specs[6] = ItemSpec(ITEM_CRAFT, "clay_brick");
385 specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
386 if(checkItemCombination(items, specs))
388 return new MaterialItem(CONTENT_BRICK, 1);
395 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
396 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
397 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
398 if(checkItemCombination(items, specs))
400 return new CraftItem("paper", 1);
407 specs[1] = ItemSpec(ITEM_CRAFT, "paper");
408 specs[4] = ItemSpec(ITEM_CRAFT, "paper");
409 specs[7] = ItemSpec(ITEM_CRAFT, "paper");
410 if(checkItemCombination(items, specs))
412 return new CraftItem("book", 1);
419 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
420 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
421 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
422 specs[3] = ItemSpec(ITEM_CRAFT, "book");
423 specs[4] = ItemSpec(ITEM_CRAFT, "book");
424 specs[5] = ItemSpec(ITEM_CRAFT, "book");
425 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
426 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
427 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
428 if(checkItemCombination(items, specs))
430 return new MaterialItem(CONTENT_BOOKSHELF, 1);
437 specs[0] = ItemSpec(ITEM_CRAFT, "Stick");
438 specs[2] = ItemSpec(ITEM_CRAFT, "Stick");
439 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
440 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
441 specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
442 specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
443 specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
444 if(checkItemCombination(items, specs))
446 return new MaterialItem(CONTENT_LADDER, 1);
453 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
454 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
455 specs[4] = ItemSpec(ITEM_CRAFT, "apple");
456 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
457 specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
458 if(checkItemCombination(items, specs))
460 return new CraftItem("apple_iron", 1);
467 void craft_set_creative_inventory(Player *player)
469 player->resetInventory();
471 // Give some good tools
473 InventoryItem *item = new ToolItem("MesePick", 0);
474 void* r = player->inventory.addItem("main", item);
478 InventoryItem *item = new ToolItem("SteelPick", 0);
479 void* r = player->inventory.addItem("main", item);
483 InventoryItem *item = new ToolItem("SteelAxe", 0);
484 void* r = player->inventory.addItem("main", item);
488 InventoryItem *item = new ToolItem("SteelShovel", 0);
489 void* r = player->inventory.addItem("main", item);
497 // CONTENT_IGNORE-terminated list
498 content_t material_items[] = {
525 content_t *mip = material_items;
526 for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
528 if(*mip == CONTENT_IGNORE)
531 InventoryItem *item = new MaterialItem(*mip, 1);
532 player->inventory.addItem("main", item);
538 assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
541 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
542 player->inventory.addItem("main", item);
545 for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
547 // Skip some materials
548 if(i == CONTENT_WATER || i == CONTENT_TORCH
549 || i == CONTENT_COALSTONE)
552 InventoryItem *item = new MaterialItem(i, 1);
553 player->inventory.addItem("main", item);
559 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
560 void* r = player->inventory.addItem("main", item);
565 void craft_give_initial_stuff(Player *player)
568 InventoryItem *item = new ToolItem("SteelPick", 0);
569 void* r = player->inventory.addItem("main", item);
573 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
574 void* r = player->inventory.addItem("main", item);
578 InventoryItem *item = new ToolItem("SteelAxe", 0);
579 void* r = player->inventory.addItem("main", item);
583 InventoryItem *item = new ToolItem("SteelShovel", 0);
584 void* r = player->inventory.addItem("main", item);
588 InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
589 void* r = player->inventory.addItem("main", item);
593 InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
594 void* r = player->inventory.addItem("main", item);
598 InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
599 void* r = player->inventory.addItem("main", item);
603 InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
604 void* r = player->inventory.addItem("main", item);
608 InventoryItem *item = new CraftItem("Stick", 4);
609 void* r = player->inventory.addItem("main", item);
613 InventoryItem *item = new ToolItem("WPick", 32000);
614 void* r = player->inventory.addItem("main", item);
618 InventoryItem *item = new ToolItem("STPick", 32000);
619 void* r = player->inventory.addItem("main", item);
623 for(u16 i=0; i<4; i++)
625 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
626 bool r = player->inventory.addItem("main", item);
629 /*// Give some other stuff
631 InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
632 bool r = player->inventory.addItem("main", item);