Handle ActiveBlockModifier intervals properly, down to 1s
[oweals/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 #include "mapnode.h" // For content_t
25 #include "gamedef.h"
26
27 void craft_set_creative_inventory(Player *player, IGameDef *gamedef)
28 {
29         INodeDefManager *ndef = gamedef->ndef();
30
31         player->resetInventory();
32         
33         // Give some good tools
34         {
35                 InventoryItem *item = new ToolItem(gamedef, "MesePick", 0);
36                 void* r = player->inventory.addItem("main", item);
37                 assert(r == NULL);
38         }
39         {
40                 InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0);
41                 void* r = player->inventory.addItem("main", item);
42                 assert(r == NULL);
43         }
44         {
45                 InventoryItem *item = new ToolItem(gamedef, "SteelAxe", 0);
46                 void* r = player->inventory.addItem("main", item);
47                 assert(r == NULL);
48         }
49         {
50                 InventoryItem *item = new ToolItem(gamedef, "SteelShovel", 0);
51                 void* r = player->inventory.addItem("main", item);
52                 assert(r == NULL);
53         }
54
55         /*
56                 Give materials
57         */
58         
59         // CONTENT_IGNORE-terminated list
60         content_t material_items[] = {
61                 LEGN(ndef, "CONTENT_TORCH"),
62                 LEGN(ndef, "CONTENT_COBBLE"),
63                 LEGN(ndef, "CONTENT_MUD"),
64                 LEGN(ndef, "CONTENT_STONE"),
65                 LEGN(ndef, "CONTENT_SAND"),
66                 LEGN(ndef, "CONTENT_SANDSTONE"),
67                 LEGN(ndef, "CONTENT_CLAY"),
68                 LEGN(ndef, "CONTENT_BRICK"),
69                 LEGN(ndef, "CONTENT_TREE"),
70                 LEGN(ndef, "CONTENT_LEAVES"),
71                 LEGN(ndef, "CONTENT_CACTUS"),
72                 LEGN(ndef, "CONTENT_PAPYRUS"),
73                 LEGN(ndef, "CONTENT_BOOKSHELF"),
74                 LEGN(ndef, "CONTENT_GLASS"),
75                 LEGN(ndef, "CONTENT_FENCE"),
76                 LEGN(ndef, "CONTENT_RAIL"),
77                 LEGN(ndef, "CONTENT_MESE"),
78                 LEGN(ndef, "CONTENT_WATERSOURCE"),
79                 LEGN(ndef, "CONTENT_CLOUD"),
80                 LEGN(ndef, "CONTENT_CHEST"),
81                 LEGN(ndef, "CONTENT_FURNACE"),
82                 LEGN(ndef, "CONTENT_SIGN_WALL"),
83                 LEGN(ndef, "CONTENT_LAVASOURCE"),
84                 CONTENT_IGNORE
85         };
86         
87         content_t *mip = material_items;
88         for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
89         {
90                 if(*mip == CONTENT_IGNORE)
91                         break;
92
93                 InventoryItem *item = new MaterialItem(gamedef, *mip, 1);
94                 player->inventory.addItem("main", item);
95
96                 mip++;
97         }
98
99 #if 0
100         assert(USEFUL_LEGN(ndef, "CONTENT_COUNT") <= PLAYER_INVENTORY_SIZE);
101         
102         // add torch first
103         InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_TORCH"), 1);
104         player->inventory.addItem("main", item);
105         
106         // Then others
107         for(u16 i=0; i<USEFUL_LEGN(ndef, "CONTENT_COUNT"); i++)
108         {
109                 // Skip some materials
110                 if(i == LEGN(ndef, "CONTENT_WATER") || i == LEGN(ndef, "CONTENT_TORCH")
111                         || i == LEGN(ndef, "CONTENT_COALSTONE"))
112                         continue;
113
114                 InventoryItem *item = new MaterialItem(gamedef, i, 1);
115                 player->inventory.addItem("main", item);
116         }
117 #endif
118
119         /*// Sign
120         {
121                 InventoryItem *item = new MapBlockObjectItem(gamedef, "Sign Example text");
122                 void* r = player->inventory.addItem("main", item);
123                 assert(r == NULL);
124         }*/
125 }
126
127