X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fcontent_nodemeta.cpp;h=e79ff6d54c14762772542612f403f8588cdea34b;hb=3f58028d3198e77ce26d09680f0a637188610871;hp=433e6d04b23e372138eaee5f33d945fd295d00b9;hpb=467b3cf4c10b5078371af0a3b5ae951017f35020;p=dragonfireclient.git diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 433e6d04b..e79ff6d54 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -117,6 +117,70 @@ std::string ChestNodeMetadata::getInventoryDrawSpecString() "list[current_player;main;0,5;8,4;]"; } +/* + LockingChestNodeMetadata +*/ + +// Prototype +LockingChestNodeMetadata proto_LockingChestNodeMetadata; + +LockingChestNodeMetadata::LockingChestNodeMetadata() +{ + NodeMetadata::registerType(typeId(), create); + + m_inventory = new Inventory(); + m_inventory->addList("0", 8*4); +} +LockingChestNodeMetadata::~LockingChestNodeMetadata() +{ + delete m_inventory; +} +u16 LockingChestNodeMetadata::typeId() const +{ + return CONTENT_LOCKABLE_CHEST; +} +NodeMetadata* LockingChestNodeMetadata::create(std::istream &is) +{ + LockingChestNodeMetadata *d = new LockingChestNodeMetadata(); + d->setOwner(deSerializeString(is)); + d->m_inventory->deSerialize(is); + return d; +} +NodeMetadata* LockingChestNodeMetadata::clone() +{ + LockingChestNodeMetadata *d = new LockingChestNodeMetadata(); + *d->m_inventory = *m_inventory; + return d; +} +void LockingChestNodeMetadata::serializeBody(std::ostream &os) +{ + os<serialize(os); +} +std::string LockingChestNodeMetadata::infoText() +{ + return "Locking Chest"; +} +bool LockingChestNodeMetadata::nodeRemovalDisabled() +{ + /* + Disable removal if chest contains something + */ + InventoryList *list = m_inventory->getList("0"); + if(list == NULL) + return false; + if(list->getUsedSlots() == 0) + return false; + return true; +} +std::string LockingChestNodeMetadata::getInventoryDrawSpecString() +{ + return + "invsize[8,9;]" + "list[current_name;0;0,0;8,4;]" + "list[current_player;main;0,5;8,4;]"; +} + /* FurnaceNodeMetadata */ @@ -182,19 +246,45 @@ std::string FurnaceNodeMetadata::infoText() assert(src_list); const InventoryItem *src_item = src_list->getItem(0); - if(src_item) + if(src_item && src_item->isCookable()) { + InventoryList *dst_list = m_inventory->getList("dst"); + if(!dst_list->roomForCookedItem(src_item)) + return "Furnace is overloaded"; return "Furnace is out of fuel"; + } else return "Furnace is inactive"; } else { - std::string s = "Furnace is active ("; - s += itos(m_fuel_time/m_fuel_totaltime*100); - s += "%)"; + std::string s = "Furnace is active"; + // Do this so it doesn't always show (0%) for weak fuel + if(m_fuel_totaltime > 3) { + s += " ("; + s += itos(m_fuel_time/m_fuel_totaltime*100); + s += "%)"; + } return s; } } +bool FurnaceNodeMetadata::nodeRemovalDisabled() +{ + /* + Disable removal if furnace is not empty + */ + InventoryList *list[3] = {m_inventory->getList("src"), + m_inventory->getList("dst"), m_inventory->getList("fuel")}; + + for(int i = 0; i < 3; i++) { + if(list[i] == NULL) + continue; + if(list[i]->getUsedSlots() == 0) + continue; + return true; + } + return false; + +} void FurnaceNodeMetadata::inventoryModified() { dstream<<"Furnace inventory modification callback"<getList("src"); assert(src_list); - const InventoryItem *src_item = src_list->getItem(0); + InventoryItem *src_item = src_list->getItem(0); + + bool room_available = false; + + if(src_item && src_item->isCookable()) + room_available = dst_list->roomForCookedItem(src_item); // Start only if there are free slots in dst, so that it can // accomodate any result item - if(dst_list->getFreeSlots() > 0 && src_item && src_item->isCookable()) + if(room_available) { m_src_totaltime = 3; } @@ -252,13 +347,23 @@ bool FurnaceNodeMetadata::step(float dtime) m_src_totaltime = 0; } changed = true; - continue; + + // If the fuel was not used up this step, just keep burning it + if(m_fuel_time < m_fuel_totaltime) + continue; } /* - If there is no source item or source item is not cookable, stop loop. + Get the source again in case it has all burned + */ + src_item = src_list->getItem(0); + + /* + If there is no source item, or the source item is not cookable, + or the furnace is still cooking, or the furnace became overloaded, stop loop. */ - if(src_item == NULL || m_src_totaltime < 0.001) + if(src_item == NULL || !room_available || m_fuel_time < m_fuel_totaltime || + dst_list->roomForCookedItem(src_item) == false) { m_step_accumulator = 0; break;