From 36e44c682cc2cecb552eca8dfc75ad1a436086cc Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 17 Sep 2012 21:15:51 +0400 Subject: Add a plugin implementing 'add spatter to item' reactions. --- library/include/modules/Materials.h | 5 +++++ library/modules/Materials.cpp | 13 +++++++++++++ library/xml | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'library') diff --git a/library/include/modules/Materials.h b/library/include/modules/Materials.h index 76c89de3..fb5a6353 100644 --- a/library/include/modules/Materials.h +++ b/library/include/modules/Materials.h @@ -131,6 +131,11 @@ namespace DFHack bool findPlant(const std::string &token, const std::string &subtoken); bool findCreature(const std::string &token, const std::string &subtoken); + bool findProduct(df::material *material, const std::string &name); + bool findProduct(const MaterialInfo &info, const std::string &name) { + return findProduct(info.material, name); + } + std::string getToken(); std::string toString(uint16_t temp = 10015, bool named = true); diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 50cf21a9..db9c9c7d 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -283,6 +283,19 @@ bool MaterialInfo::findCreature(const std::string &token, const std::string &sub return decode(-1); } +bool MaterialInfo::findProduct(df::material *material, const std::string &name) +{ + if (!material || name.empty()) + return decode(-1); + + auto &pids = material->reaction_product.id; + for (size_t i = 0; i < pids.size(); i++) + if ((*pids[i]) == name) + return decode(material->reaction_product.material, i); + + return decode(-1); +} + std::string MaterialInfo::getToken() { if (isNone()) diff --git a/library/xml b/library/xml index a6b95f1c..260ff4a1 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit a6b95f1c42991e485f7e0bb5d029a5eca14ce9ae +Subproject commit 260ff4a1ddcfd54d0143aa6d908a93c4ff709c87 -- cgit v1.2.1