ToolDefManager serialization
[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
26 bool item_material_is_cookable(content_t content, IGameDef *gamedef)
27 {
28         if(content == CONTENT_TREE)
29                 return true;
30         else if(content == CONTENT_COBBLE)
31                 return true;
32         else if(content == CONTENT_SAND)
33                 return true;
34         return false;
35 }
36
37 InventoryItem* item_material_create_cook_result(content_t content,
38                 IGameDef *gamedef)
39 {
40         if(content == CONTENT_TREE)
41                 return new CraftItem(gamedef, "lump_of_coal", 1);
42         else if(content == CONTENT_COBBLE)
43                 return new MaterialItem(gamedef, CONTENT_STONE, 1);
44         else if(content == CONTENT_SAND)
45                 return new MaterialItem(gamedef, CONTENT_GLASS, 1);
46         return NULL;
47 }
48
49 std::string item_craft_get_image_name(const std::string &subname,
50                 IGameDef *gamedef)
51 {
52         if(subname == "Stick")
53                 return "stick.png";
54         else if(subname == "paper")
55                 return "paper.png";
56         else if(subname == "book")
57                 return "book.png";
58         else if(subname == "lump_of_coal")
59                 return "lump_of_coal.png";
60         else if(subname == "lump_of_iron")
61                 return "lump_of_iron.png";
62         else if(subname == "lump_of_clay")
63                 return "lump_of_clay.png";
64         else if(subname == "steel_ingot")
65                 return "steel_ingot.png";
66         else if(subname == "clay_brick")
67                 return "clay_brick.png";
68         else if(subname == "rat")
69                 return "rat.png";
70         else if(subname == "cooked_rat")
71                 return "cooked_rat.png";
72         else if(subname == "scorched_stuff")
73                 return "scorched_stuff.png";
74         else if(subname == "firefly")
75                 return "firefly.png";
76         else if(subname == "apple")
77                 return "apple.png^[forcesingle";
78         else if(subname == "apple_iron")
79                 return "apple_iron.png";
80         else if(subname == "testobject1") // test object
81                 return "unknown_block.png^[forcesingle";
82         else
83                 return "cloud.png"; // just something
84 }
85
86 ServerActiveObject* item_craft_create_object(const std::string &subname,
87                 ServerEnvironment *env, v3f pos)
88 {
89         if(subname == "rat")
90         {
91                 ServerActiveObject *obj = new RatSAO(env, pos);
92                 return obj;
93         }
94         else if(subname == "firefly")
95         {
96                 ServerActiveObject *obj = new FireflySAO(env, pos);
97                 return obj;
98         }
99         else if(subname == "testobject1")
100         {
101                 ServerActiveObject *obj = new LuaEntitySAO(env, pos, "TNT", "");
102                 return obj;
103         }
104
105         return NULL;
106 }
107
108 s16 item_craft_get_drop_count(const std::string &subname, IGameDef *gamedef)
109 {
110         if(subname == "rat" || subname == "firefly" || subname == "testobject1")
111                 return 1;
112
113         return -1;
114 }
115
116 bool item_craft_is_cookable(const std::string &subname, IGameDef *gamedef)
117 {
118         if(subname == "lump_of_iron" || subname == "lump_of_clay" || subname == "rat" || subname == "cooked_rat")
119                 return true;
120                 
121         return false;
122 }
123
124 InventoryItem* item_craft_create_cook_result(const std::string &subname,
125                 IGameDef *gamedef)
126 {
127         if(subname == "lump_of_iron")
128                 return new CraftItem(gamedef, "steel_ingot", 1);
129         else if(subname == "lump_of_clay")
130                 return new CraftItem(gamedef, "clay_brick", 1);
131         else if(subname == "rat")
132                 return new CraftItem(gamedef, "cooked_rat", 1);
133         else if(subname == "cooked_rat")
134                 return new CraftItem(gamedef, "scorched_stuff", 1);
135
136         return NULL;
137 }
138
139 bool item_craft_is_eatable(const std::string &subname, IGameDef *gamedef)
140 {
141         if(subname == "cooked_rat")
142                 return true;
143         else if(subname == "apple")
144                 return true;
145         else if(subname == "apple_iron")
146                 return true;
147         return false;
148 }
149
150 s16 item_craft_eat_hp_change(const std::string &subname, IGameDef *gamedef)
151 {
152         if(subname == "cooked_rat")
153                 return 6; // 3 hearts
154         else if(subname == "apple")
155                 return 4; // 2 hearts
156         else if(subname == "apple_iron")
157                 return 8; // 4 hearts
158         return 0;
159 }
160
161