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_COBBLE);
304 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
305 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
306 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
307 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
308 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
309 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
310 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE);
311 if(checkItemCombination(items, specs))
313 return new MaterialItem(CONTENT_FURNACE, 1);
320 specs[0] = ItemSpec(ITEM_CRAFT, "steel_ingot");
321 specs[1] = ItemSpec(ITEM_CRAFT, "steel_ingot");
322 specs[2] = ItemSpec(ITEM_CRAFT, "steel_ingot");
323 specs[3] = ItemSpec(ITEM_CRAFT, "steel_ingot");
324 specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot");
325 specs[5] = ItemSpec(ITEM_CRAFT, "steel_ingot");
326 specs[6] = ItemSpec(ITEM_CRAFT, "steel_ingot");
327 specs[7] = ItemSpec(ITEM_CRAFT, "steel_ingot");
328 specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot");
329 if(checkItemCombination(items, specs))
331 return new MaterialItem(CONTENT_STEEL, 1);
338 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
339 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
340 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
341 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND);
342 if(checkItemCombination(items, specs))
344 return new MaterialItem(CONTENT_SANDSTONE, 1);
351 specs[3] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
352 specs[4] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
353 specs[6] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
354 specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay");
355 if(checkItemCombination(items, specs))
357 return new MaterialItem(CONTENT_CLAY, 1);
364 specs[3] = ItemSpec(ITEM_CRAFT, "clay_brick");
365 specs[4] = ItemSpec(ITEM_CRAFT, "clay_brick");
366 specs[6] = ItemSpec(ITEM_CRAFT, "clay_brick");
367 specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick");
368 if(checkItemCombination(items, specs))
370 return new MaterialItem(CONTENT_BRICK, 1);
377 specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
378 specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
379 specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS);
380 if(checkItemCombination(items, specs))
382 return new CraftItem("paper", 1);
389 specs[1] = ItemSpec(ITEM_CRAFT, "paper");
390 specs[4] = ItemSpec(ITEM_CRAFT, "paper");
391 specs[7] = ItemSpec(ITEM_CRAFT, "paper");
392 if(checkItemCombination(items, specs))
394 return new CraftItem("book", 1);
401 specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
402 specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
403 specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
404 specs[3] = ItemSpec(ITEM_CRAFT, "book");
405 specs[4] = ItemSpec(ITEM_CRAFT, "book");
406 specs[5] = ItemSpec(ITEM_CRAFT, "book");
407 specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
408 specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
409 specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD);
410 if(checkItemCombination(items, specs))
412 return new MaterialItem(CONTENT_BOOKSHELF, 1);
419 specs[0] = ItemSpec(ITEM_CRAFT, "Stick");
420 specs[2] = ItemSpec(ITEM_CRAFT, "Stick");
421 specs[3] = ItemSpec(ITEM_CRAFT, "Stick");
422 specs[4] = ItemSpec(ITEM_CRAFT, "Stick");
423 specs[5] = ItemSpec(ITEM_CRAFT, "Stick");
424 specs[6] = ItemSpec(ITEM_CRAFT, "Stick");
425 specs[8] = ItemSpec(ITEM_CRAFT, "Stick");
426 if(checkItemCombination(items, specs))
428 return new MaterialItem(CONTENT_LADDER, 1);
435 void craft_set_creative_inventory(Player *player)
437 player->resetInventory();
439 // Give some good tools
441 InventoryItem *item = new ToolItem("MesePick", 0);
442 void* r = player->inventory.addItem("main", item);
446 InventoryItem *item = new ToolItem("SteelPick", 0);
447 void* r = player->inventory.addItem("main", item);
451 InventoryItem *item = new ToolItem("SteelAxe", 0);
452 void* r = player->inventory.addItem("main", item);
456 InventoryItem *item = new ToolItem("SteelShovel", 0);
457 void* r = player->inventory.addItem("main", item);
465 // CONTENT_IGNORE-terminated list
466 content_t material_items[] = {
493 content_t *mip = material_items;
494 for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
496 if(*mip == CONTENT_IGNORE)
499 InventoryItem *item = new MaterialItem(*mip, 1);
500 player->inventory.addItem("main", item);
506 assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
509 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
510 player->inventory.addItem("main", item);
513 for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
515 // Skip some materials
516 if(i == CONTENT_WATER || i == CONTENT_TORCH
517 || i == CONTENT_COALSTONE)
520 InventoryItem *item = new MaterialItem(i, 1);
521 player->inventory.addItem("main", item);
527 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
528 void* r = player->inventory.addItem("main", item);
533 void craft_give_initial_stuff(Player *player)
536 InventoryItem *item = new ToolItem("SteelPick", 0);
537 void* r = player->inventory.addItem("main", item);
541 InventoryItem *item = new MaterialItem(CONTENT_TORCH, 99);
542 void* r = player->inventory.addItem("main", item);
546 InventoryItem *item = new ToolItem("SteelAxe", 0);
547 void* r = player->inventory.addItem("main", item);
551 InventoryItem *item = new ToolItem("SteelShovel", 0);
552 void* r = player->inventory.addItem("main", item);
556 InventoryItem *item = new MaterialItem(CONTENT_COBBLE, 99);
557 void* r = player->inventory.addItem("main", item);
561 InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
562 void* r = player->inventory.addItem("main", item);
566 InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
567 void* r = player->inventory.addItem("main", item);
571 InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
572 void* r = player->inventory.addItem("main", item);
576 InventoryItem *item = new CraftItem("Stick", 4);
577 void* r = player->inventory.addItem("main", item);
581 InventoryItem *item = new ToolItem("WPick", 32000);
582 void* r = player->inventory.addItem("main", item);
586 InventoryItem *item = new ToolItem("STPick", 32000);
587 void* r = player->inventory.addItem("main", item);
591 for(u16 i=0; i<4; i++)
593 InventoryItem *item = new MapBlockObjectItem("Sign Example text");
594 bool r = player->inventory.addItem("main", item);
597 /*// Give some other stuff
599 InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
600 bool r = player->inventory.addItem("main", item);