From 6a417c538f0af9e611d6f94cfb12d36f51982db8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 16 Nov 2011 02:22:41 +0200 Subject: [PATCH] Remove burn time definitions from FurnaceNodeMetadata --- src/content_mapnode.cpp | 21 +++++++++++ src/content_nodemeta.cpp | 81 ++-------------------------------------- src/inventory.cpp | 26 +++++++++++++ src/inventory.h | 10 ++++- src/materials.cpp | 2 + src/materials.h | 11 +++--- src/nodedef.cpp | 8 +++- src/nodedef.h | 2 + src/scriptapi.cpp | 5 ++- 9 files changed, 79 insertions(+), 87 deletions(-) diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 30a70679a..c3e507e21 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -254,6 +254,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->cookresult_item = "CraftItem lump_of_coal 1"; + f->furnace_burntime = 30; setWoodLikeMaterialProperties(f->material, 1.0); i = CONTENT_JUNGLETREE; @@ -263,6 +264,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->setTexture(1, "jungletree_top.png"); f->param_type = CPT_MINERAL; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->furnace_burntime = 30; setWoodLikeMaterialProperties(f->material, 1.0); i = CONTENT_JUNGLEGRASS; @@ -277,6 +279,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->walkable = false; setLeavesLikeMaterialProperties(f->material, 1.0); + f->furnace_burntime = 2; i = CONTENT_LEAVES; f = nodemgr->getModifiable(i); @@ -289,6 +292,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->extra_dug_item_rarity = 20; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; setLeavesLikeMaterialProperties(f->material, 1.0); + f->furnace_burntime = 1.0; i = CONTENT_CACTUS; f = nodemgr->getModifiable(i); @@ -300,6 +304,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; setWoodLikeMaterialProperties(f->material, 0.75); + f->furnace_burntime = 15; i = CONTENT_PAPYRUS; f = nodemgr->getModifiable(i); @@ -312,6 +317,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->walkable = false; setLeavesLikeMaterialProperties(f->material, 0.5); + f->furnace_burntime = 1; i = CONTENT_BOOKSHELF; f = nodemgr->getModifiable(i); @@ -324,6 +330,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->param_type = CPT_MINERAL; f->is_ground_content = true; setWoodLikeMaterialProperties(f->material, 0.75); + f->furnace_burntime = 30; i = CONTENT_GLASS; f = nodemgr->getModifiable(i); @@ -350,6 +357,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->selection_box.type = NODEBOX_FIXED; f->selection_box.fixed = core::aabbox3d( -BS/7, -BS/2, -BS/7, BS/7, BS/2, BS/7); + f->furnace_burntime = 30/2; setWoodLikeMaterialProperties(f->material, 0.75); i = CONTENT_RAIL; @@ -367,6 +375,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->air_equivalent = true; // grass grows underneath f->walkable = false; f->selection_box.type = NODEBOX_FIXED; + f->furnace_burntime = 5; setDirtLikeMaterialProperties(f->material, 0.75); i = CONTENT_LADDER; @@ -383,6 +392,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->walkable = false; f->climbable = true; f->selection_box.type = NODEBOX_WALLMOUNTED; + f->furnace_burntime = 5; setWoodLikeMaterialProperties(f->material, 0.5); // Deprecated @@ -398,6 +408,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->setInventoryTextureCube("wood.png", "wood.png", "wood.png"); f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->furnace_burntime = 30/4; setWoodLikeMaterialProperties(f->material, 0.75); i = CONTENT_MESE; @@ -406,6 +417,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->setInventoryTextureCube("mese.png", "mese.png", "mese.png"); f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; + f->furnace_burntime = 30; setStoneLikeMaterialProperties(f->material, 0.5); i = CONTENT_CLOUD; @@ -509,6 +521,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->post_effect_color = video::SColor(192, 255, 64, 0); // New-style lava source material (mostly unused) f->setSpecialMaterial(0, MaterialSpec("lava.png", false)); + f->furnace_burntime = 60; i = CONTENT_TORCH; f = nodemgr->getModifiable(i); @@ -533,6 +546,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->selection_box.wall_side = core::aabbox3d( -BS/2, -BS/3.333, -BS/10, -BS/2+BS/3.333, BS/3.333, BS/10); setConstantMaterialProperties(f->material, 0.0); + f->furnace_burntime = 4; i = CONTENT_SIGN_WALL; f = nodemgr->getModifiable(i); @@ -550,6 +564,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->initial_metadata = new SignNodeMetadata(NULL, "Some sign"); setConstantMaterialProperties(f->material, 0.5); f->selection_box.type = NODEBOX_WALLMOUNTED; + f->furnace_burntime = 10; i = CONTENT_CHEST; f = nodemgr->getModifiable(i); @@ -564,6 +579,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) if(f->initial_metadata == NULL) f->initial_metadata = new ChestNodeMetadata(NULL); setWoodLikeMaterialProperties(f->material, 1.0); + f->furnace_burntime = 30; i = CONTENT_LOCKABLE_CHEST; f = nodemgr->getModifiable(i); @@ -578,6 +594,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) if(f->initial_metadata == NULL) f->initial_metadata = new LockingChestNodeMetadata(NULL); setWoodLikeMaterialProperties(f->material, 1.0); + f->furnace_burntime = 30; i = CONTENT_FURNACE; f = nodemgr->getModifiable(i); @@ -629,6 +646,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->setInventoryTexture("nc_front.png"); f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; setStoneLikeMaterialProperties(f->material, 3.0); + f->furnace_burntime = 1; i = CONTENT_NC_RB; f = nodemgr->getModifiable(i); @@ -636,6 +654,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->setInventoryTexture("nc_rb.png"); f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; setStoneLikeMaterialProperties(f->material, 3.0); + f->furnace_burntime = 1; i = CONTENT_SAPLING; f = nodemgr->getModifiable(i); @@ -649,6 +668,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->air_equivalent = false; f->walkable = false; setConstantMaterialProperties(f->material, 0.0); + f->furnace_burntime = 10; i = CONTENT_APPLE; f = nodemgr->getModifiable(i); @@ -663,6 +683,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr) f->air_equivalent = true; f->dug_item = std::string("CraftItem apple 1"); setConstantMaterialProperties(f->material, 0.0); + f->furnace_burntime = 3; } diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 50dcbd080..17b4a3da4 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -326,7 +326,7 @@ bool FurnaceNodeMetadata::step(float dtime) // accomodate any result item if(room_available) { - m_src_totaltime = 3; + m_src_totaltime = src_item->getCookTime(); } else { @@ -381,85 +381,12 @@ bool FurnaceNodeMetadata::step(float dtime) assert(fuel_list); const InventoryItem *fuel_item = fuel_list->getItem(0); - if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(fuel_item)) - { - m_fuel_totaltime = 30; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_JUNGLETREE).checkItem(fuel_item)) - { - m_fuel_totaltime = 30; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_FENCE).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/2; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_WOOD).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/4; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_BOOKSHELF).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/4; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_LEAVES).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/16; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/32; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_JUNGLEGRASS).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/32; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_MATERIAL, CONTENT_CACTUS).checkItem(fuel_item)) - { - m_fuel_totaltime = 30/4; + if(fuel_item && fuel_item->getBurnTime() >= 0){ + m_fuel_totaltime = fuel_item->getBurnTime(); m_fuel_time = 0; fuel_list->decrementMaterials(1); changed = true; - } - else if(ItemSpec(ITEM_CRAFT, "Stick").checkItem(fuel_item)) - { - m_fuel_totaltime = 30/4/4; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else if(ItemSpec(ITEM_CRAFT, "lump_of_coal").checkItem(fuel_item)) - { - m_fuel_totaltime = 40; - m_fuel_time = 0; - fuel_list->decrementMaterials(1); - changed = true; - } - else - { + } else { //infostream<<"No fuel found"<ndef(); + const ContentFeatures &f = ndef->get(m_content); + return f.furnace_cooktime; +} + +float MaterialItem::getBurnTime() const +{ + INodeDefManager *ndef = m_gamedef->ndef(); + const ContentFeatures &f = ndef->get(m_content); + return f.furnace_burntime; +} + /* ToolItem */ @@ -258,6 +272,18 @@ InventoryItem *CraftItem::createCookResult() const return item_craft_create_cook_result(m_subname, m_gamedef); } +float CraftItem::getCookTime() const +{ + return 3.0; +} + +float CraftItem::getBurnTime() const +{ + if(m_subname == "lump_of_coal") + return 40; + return -1; +} + bool CraftItem::use(ServerEnvironment *env, ServerActiveObject *user) { if(!item_craft_is_eatable(m_subname, m_gamedef)) diff --git a/src/inventory.h b/src/inventory.h index 5401ff1b9..b9de48f9a 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -106,10 +106,12 @@ public: // Whether it can be cooked virtual bool isCookable() const {return false;} - // Time of cooking - virtual float getCookTime(){return 3.0;} // Result of cooking (can randomize) virtual InventoryItem *createCookResult() const {return NULL;} + // Time of cooking + virtual float getCookTime() const {return 3.0;} + // Whether it can be burned (<0 = cannot be burned) + virtual float getBurnTime() const {return -1;} // Eat, press, activate, whatever. // Called when item is right-clicked when lying on ground. @@ -180,6 +182,8 @@ public: */ bool isCookable() const; InventoryItem *createCookResult() const; + float getCookTime() const; + float getBurnTime() const; /* Special methods */ @@ -258,6 +262,8 @@ public: bool isCookable() const; InventoryItem *createCookResult() const; + float getCookTime() const; + float getBurnTime() const; bool use(ServerEnvironment *env, ServerActiveObject *user); diff --git a/src/materials.cpp b/src/materials.cpp index ab2e2d273..5c89eafd8 100644 --- a/src/materials.cpp +++ b/src/materials.cpp @@ -32,6 +32,7 @@ void MaterialProperties::serialize(std::ostream &os) writeF1000(os, crackiness); writeF1000(os, crumbliness); writeF1000(os, cuttability); + writeF1000(os, flammability); } void MaterialProperties::deSerialize(std::istream &is) @@ -45,6 +46,7 @@ void MaterialProperties::deSerialize(std::istream &is) crackiness = readF1000(is); crumbliness = readF1000(is); cuttability = readF1000(is); + flammability = readF1000(is); } DiggingProperties getDiggingProperties(u16 content, ToolDiggingProperties *tp, diff --git a/src/materials.h b/src/materials.h index 4e067fd66..9db33fc63 100644 --- a/src/materials.h +++ b/src/materials.h @@ -56,15 +56,16 @@ struct MaterialProperties // Sword is best for cuttable light stuff. float cuttability; // If high, ignites easily - //float flammability; + float flammability; MaterialProperties(): diggability(DIGGABLE_NOT), constant_time(0.5), - weight(1), - crackiness(1), - crumbliness(1), - cuttability(1) + weight(0), + crackiness(0), + crumbliness(0), + cuttability(0), + flammability(0) {} void serialize(std::ostream &os); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2e0c6fad6..210e466d2 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -151,7 +151,9 @@ void ContentFeatures::reset() damage_per_second = 0; selection_box = NodeBox(); material = MaterialProperties(); - cookresult_item = ""; + cookresult_item = ""; // Cannot be cooked + furnace_cooktime = 3.0; + furnace_burntime = -1.0; // Cannot be burned } void ContentFeatures::serialize(std::ostream &os) @@ -202,6 +204,8 @@ void ContentFeatures::serialize(std::ostream &os) selection_box.serialize(os); material.serialize(os); os<