Falling sand and gravel
[oweals/minetest.git] / src / content_inventory.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_inventory.h"
21 #include "inventory.h"
22 #include "content_mapnode.h"
23 //#include "serverobject.h"
24 #include "content_sao.h"
25 //#include "gamedef.h"
26 //#include "nodedef.h"
27
28 std::string item_craft_get_image_name(const std::string &subname,
29                 IGameDef *gamedef)
30 {
31         if(subname == "Stick")
32                 return "stick.png";
33         else if(subname == "paper")
34                 return "paper.png";
35         else if(subname == "book")
36                 return "book.png";
37         else if(subname == "lump_of_coal")
38                 return "lump_of_coal.png";
39         else if(subname == "lump_of_iron")
40                 return "lump_of_iron.png";
41         else if(subname == "lump_of_clay")
42                 return "lump_of_clay.png";
43         else if(subname == "steel_ingot")
44                 return "steel_ingot.png";
45         else if(subname == "clay_brick")
46                 return "clay_brick.png";
47         else if(subname == "rat")
48                 return "rat.png";
49         else if(subname == "cooked_rat")
50                 return "cooked_rat.png";
51         else if(subname == "scorched_stuff")
52                 return "scorched_stuff.png";
53         else if(subname == "firefly")
54                 return "firefly.png";
55         else if(subname == "apple")
56                 return "apple.png^[forcesingle";
57         else if(subname == "apple_iron")
58                 return "apple_iron.png";
59         else if(subname == "testobject1") // test object
60                 return "unknown_block.png^[forcesingle";
61         else
62                 return "cloud.png"; // just something
63 }
64
65 ServerActiveObject* item_craft_create_object(const std::string &subname,
66                 ServerEnvironment *env, v3f pos)
67 {
68         if(subname == "rat")
69         {
70                 ServerActiveObject *obj = new RatSAO(env, pos);
71                 return obj;
72         }
73         else if(subname == "firefly")
74         {
75                 ServerActiveObject *obj = new FireflySAO(env, pos);
76                 return obj;
77         }
78         else if(subname == "testobject1")
79         {
80                 ServerActiveObject *obj = new LuaEntitySAO(env, pos, "TNT", "");
81                 return obj;
82         }
83
84         return NULL;
85 }
86
87 s16 item_craft_get_drop_count(const std::string &subname, IGameDef *gamedef)
88 {
89         if(subname == "rat" || subname == "firefly" || subname == "testobject1")
90                 return 1;
91
92         return -1;
93 }
94
95 bool item_craft_is_cookable(const std::string &subname, IGameDef *gamedef)
96 {
97         if(subname == "lump_of_iron" || subname == "lump_of_clay" || subname == "rat" || subname == "cooked_rat")
98                 return true;
99                 
100         return false;
101 }
102
103 InventoryItem* item_craft_create_cook_result(const std::string &subname,
104                 IGameDef *gamedef)
105 {
106         if(subname == "lump_of_iron")
107                 return new CraftItem(gamedef, "steel_ingot", 1);
108         else if(subname == "lump_of_clay")
109                 return new CraftItem(gamedef, "clay_brick", 1);
110         else if(subname == "rat")
111                 return new CraftItem(gamedef, "cooked_rat", 1);
112         else if(subname == "cooked_rat")
113                 return new CraftItem(gamedef, "scorched_stuff", 1);
114
115         return NULL;
116 }
117
118 bool item_craft_is_eatable(const std::string &subname, IGameDef *gamedef)
119 {
120         if(subname == "cooked_rat")
121                 return true;
122         else if(subname == "apple")
123                 return true;
124         else if(subname == "apple_iron")
125                 return true;
126         return false;
127 }
128
129 s16 item_craft_eat_hp_change(const std::string &subname, IGameDef *gamedef)
130 {
131         if(subname == "cooked_rat")
132                 return 6; // 3 hearts
133         else if(subname == "apple")
134                 return 4; // 2 hearts
135         else if(subname == "apple_iron")
136                 return 8; // 4 hearts
137         return 0;
138 }
139
140