Move cook result properly to ContentFeatures

This commit is contained in:
Perttu Ahola 2011-11-16 01:34:09 +02:00
parent f107967fdc
commit 37a5f8a30b
6 changed files with 19 additions and 29 deletions

@ -22,29 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_mapnode.h" #include "content_mapnode.h"
//#include "serverobject.h" //#include "serverobject.h"
#include "content_sao.h" #include "content_sao.h"
//#include "gamedef.h"
bool item_material_is_cookable(content_t content, IGameDef *gamedef) //#include "nodedef.h"
{
if(content == CONTENT_TREE)
return true;
else if(content == CONTENT_COBBLE)
return true;
else if(content == CONTENT_SAND)
return true;
return false;
}
InventoryItem* item_material_create_cook_result(content_t content,
IGameDef *gamedef)
{
if(content == CONTENT_TREE)
return new CraftItem(gamedef, "lump_of_coal", 1);
else if(content == CONTENT_COBBLE)
return new MaterialItem(gamedef, CONTENT_STONE, 1);
else if(content == CONTENT_SAND)
return new MaterialItem(gamedef, CONTENT_GLASS, 1);
return NULL;
}
std::string item_craft_get_image_name(const std::string &subname, std::string item_craft_get_image_name(const std::string &subname,
IGameDef *gamedef) IGameDef *gamedef)

@ -29,10 +29,6 @@ class ServerActiveObject;
class ServerEnvironment; class ServerEnvironment;
class IGameDef; class IGameDef;
bool item_material_is_cookable(content_t content, IGameDef *gamedef);
InventoryItem* item_material_create_cook_result(content_t content,
IGameDef *gamedef);
std::string item_craft_get_image_name(const std::string &subname, std::string item_craft_get_image_name(const std::string &subname,
IGameDef *gamedef); IGameDef *gamedef);
ServerActiveObject* item_craft_create_object(const std::string &subname, ServerActiveObject* item_craft_create_object(const std::string &subname,

@ -206,6 +206,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->cookresult_item = std::string("MaterialItem2 ")+itos(CONTENT_GLASS)+" 1";
setDirtLikeMaterialProperties(f->material, 1.0); setDirtLikeMaterialProperties(f->material, 1.0);
i = CONTENT_GRAVEL; i = CONTENT_GRAVEL;
@ -252,6 +253,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
f->param_type = CPT_MINERAL; f->param_type = CPT_MINERAL;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->cookresult_item = "CraftItem lump_of_coal 1";
setWoodLikeMaterialProperties(f->material, 1.0); setWoodLikeMaterialProperties(f->material, 1.0);
i = CONTENT_JUNGLETREE; i = CONTENT_JUNGLETREE;
@ -596,6 +598,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
f->param_type = CPT_NONE; f->param_type = CPT_NONE;
f->is_ground_content = true; f->is_ground_content = true;
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->cookresult_item = std::string("MaterialItem2 ")+itos(CONTENT_STONE)+" 1";
setStoneLikeMaterialProperties(f->material, 0.9); setStoneLikeMaterialProperties(f->material, 0.9);
i = CONTENT_MOSSYCOBBLE; i = CONTENT_MOSSYCOBBLE;

@ -158,12 +158,17 @@ video::ITexture * MaterialItem::getImage(ITextureSource *tsrc) const
bool MaterialItem::isCookable() const bool MaterialItem::isCookable() const
{ {
return item_material_is_cookable(m_content, m_gamedef); INodeDefManager *ndef = m_gamedef->ndef();
const ContentFeatures &f = ndef->get(m_content);
return (f.cookresult_item != "");
} }
InventoryItem *MaterialItem::createCookResult() const InventoryItem *MaterialItem::createCookResult() const
{ {
return item_material_create_cook_result(m_content, m_gamedef); INodeDefManager *ndef = m_gamedef->ndef();
const ContentFeatures &f = ndef->get(m_content);
std::istringstream is(f.cookresult_item, std::ios::binary);
return InventoryItem::deSerialize(is, m_gamedef);
} }
/* /*

@ -140,6 +140,8 @@ void ContentFeatures::reset()
air_equivalent = false; air_equivalent = false;
often_contains_mineral = false; often_contains_mineral = false;
dug_item = ""; dug_item = "";
extra_dug_item = "";
extra_dug_item_rarity = 2;
initial_metadata = NULL; initial_metadata = NULL;
liquid_type = LIQUID_NONE; liquid_type = LIQUID_NONE;
liquid_alternative_flowing = CONTENT_IGNORE; liquid_alternative_flowing = CONTENT_IGNORE;
@ -149,6 +151,7 @@ void ContentFeatures::reset()
damage_per_second = 0; damage_per_second = 0;
selection_box = NodeBox(); selection_box = NodeBox();
material = MaterialProperties(); material = MaterialProperties();
cookresult_item = "";
} }
void ContentFeatures::serialize(std::ostream &os) void ContentFeatures::serialize(std::ostream &os)
@ -198,6 +201,7 @@ void ContentFeatures::serialize(std::ostream &os)
writeU32(os, damage_per_second); writeU32(os, damage_per_second);
selection_box.serialize(os); selection_box.serialize(os);
material.serialize(os); material.serialize(os);
os<<serializeString(cookresult_item);
} }
void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef) void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef)
@ -250,6 +254,7 @@ void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef)
damage_per_second = readU32(is); damage_per_second = readU32(is);
selection_box.deSerialize(is); selection_box.deSerialize(is);
material.deSerialize(is); material.deSerialize(is);
cookresult_item = deSerializeString(is);
} }
void ContentFeatures::setTexture(u16 i, std::string name) void ContentFeatures::setTexture(u16 i, std::string name)

@ -209,6 +209,7 @@ struct ContentFeatures
std::string dug_item; std::string dug_item;
// Extra dug item and its rarity // Extra dug item and its rarity
std::string extra_dug_item; std::string extra_dug_item;
// Usual get interval for extra dug item
s32 extra_dug_item_rarity; s32 extra_dug_item_rarity;
// Initial metadata is cloned from this // Initial metadata is cloned from this
NodeMetadata *initial_metadata; NodeMetadata *initial_metadata;
@ -227,6 +228,7 @@ struct ContentFeatures
u32 damage_per_second; u32 damage_per_second;
NodeBox selection_box; NodeBox selection_box;
MaterialProperties material; MaterialProperties material;
std::string cookresult_item;
/* /*
Methods Methods