diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index 2396e03fd..30a4da271 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -164,57 +164,92 @@ void virtual_identity::Init(Core *core) */ } -std::string DFHack::bitfieldToString(const void *p, int size, const bitfield_item_info *items) +bool DFHack::findBitfieldField(unsigned *idx, const std::string &name, + unsigned size, const bitfield_item_info *items) { - std::string res; - const char *data = (const char*)p; + for (unsigned i = 0; i < size; i++) { + if (items[i].name && items[i].name == name) + { + *idx = i; + return true; + } + } - for (int i = 0; i < size; i++) { - unsigned v; + return false; +} - if (items[i].size > 1) { - unsigned pdv = *(unsigned*)&data[i/8]; - v = (pdv >> (i%8)) & ((1 << items[i].size)-1); - } else { - v = (data[i/8]>>(i%8)) & 1; - } +void DFHack::setBitfieldField(void *p, unsigned idx, unsigned size, int value) +{ + uint8_t *data = ((uint8_t*)p) + (idx/8); + unsigned shift = idx%8; + uint32_t mask = ((1<> shift) + + if (!(mask & ~0xFFU)) ACCESS(uint8_t); + else if (!(mask & ~0xFFFFU)) ACCESS(uint16_t); + else ACCESS(uint32_t); + +#undef ACCESS +} + +void DFHack::bitfieldToString(std::vector *pvec, const void *p, + unsigned size, const bitfield_item_info *items) +{ + for (unsigned i = 0; i < size; i++) { + int value = getBitfieldField(p, i, std::min(1,items[i].size)); + + if (value) { + std::string name = format_key(items[i].name, i); if (items[i].size > 1) - res += stl_sprintf("=%u", v); + name += stl_sprintf("=%u", value); + + pvec->push_back(name); } if (items[i].size > 1) i += items[i].size-1; } - - return res; } -int DFHack::findBitfieldField_(const std::string &name, int size, const bitfield_item_info *items) +int DFHack::findEnumItem(const std::string &name, int size, const char *const *items) { for (int i = 0; i < size; i++) { - if (items[i].name && items[i].name == name) + if (items[i] && items[i] == name) return i; } return -1; } -int DFHack::findEnumItem_(const std::string &name, int size, const char *const *items) +void DFHack::flagarrayToString(std::vector *pvec, const void *p, + int bytes, int base, int size, const char *const *items) { - for (int i = 0; i < size; i++) { - if (items[i] && items[i] == name) - return i; + for (unsigned i = 0; i < bytes*8; i++) { + int value = getBitfieldField(p, i, 1); + + if (value) + { + int ridx = int(i) - base; + const char *name = (ridx >= 0 && ridx < size) ? items[ridx] : NULL; + pvec->push_back(format_key(name, i)); + } } - - return -1; } diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp index dff8af0a0..8247cd002 100644 --- a/library/MiscUtils.cpp +++ b/library/MiscUtils.cpp @@ -36,6 +36,8 @@ distribution. #include #include +#include + std::string stl_sprintf(const char *fmt, ...) { va_list lst; va_start(lst, fmt); @@ -82,6 +84,20 @@ bool split_string(std::vector *out, return out->size() > 1; } +std::string join_strings(const std::string &separator, const std::vector &items) +{ + std::stringstream ss; + + for (size_t i = 0; i < items.size(); i++) + { + if (i) + ss << separator; + ss << items[i]; + } + + return ss.str(); +} + std::string toUpper(const std::string &str) { std::string rv(str.size(),' '); diff --git a/library/RemoteTools.cpp b/library/RemoteTools.cpp index a3e3c9e4d..aa6324356 100644 --- a/library/RemoteTools.cpp +++ b/library/RemoteTools.cpp @@ -61,6 +61,13 @@ using dfproto::CoreTextNotification; using dfproto::CoreTextFragment; using google::protobuf::MessageLite; +void DFHack::strVectorToRepeatedField(RepeatedPtrField *pf, + const std::vector &vec) +{ + for (size_t i = 0; i < vec.size(); ++i) + *pf->Add() = vec[i]; +} + CoreService::CoreService() { suspend_depth = 0; diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h index b4623f791..46662efca 100644 --- a/library/include/DataDefs.h +++ b/library/include/DataDefs.h @@ -25,6 +25,7 @@ distribution. #pragma once #include +#include #include #include @@ -36,6 +37,10 @@ distribution. #undef interface #endif +/* + * Definitions of DFHack namespace structs used by generated headers. + */ + namespace DFHack { class virtual_class {}; @@ -153,6 +158,10 @@ inline int linear_index(const DFHack::enum_list_attr &lst, const st return -1; } +/* + * Definitions of df namespace structs used by generated headers. + */ + namespace df { using DFHack::virtual_ptr; @@ -213,8 +222,20 @@ namespace df namespace enums {} } +/* + * Templates for access to enum and bitfield traits. + */ + +DFHACK_EXPORT std::string join_strings(const std::string &separator, const std::vector &items); + namespace DFHack { - // Enums + /* + * Enum trait tools. + */ + + /** + * Return the next item in the enum, wrapping to the first one at the end. + */ template inline typename df::enum_traits::enum_type next_enum_item(T v) { typedef df::enum_traits traits; @@ -223,55 +244,185 @@ namespace DFHack { return (iv < traits::last_item_value) ? T(iv+1) : traits::first_item; } + /** + * Check if the value is valid for its enum type. + */ template inline bool is_valid_enum_item(T v) { return df::enum_traits::is_valid(v); } + /** + * Return the enum item key string pointer, or NULL if none. + */ template inline const char *enum_item_raw_key(T val) { typedef df::enum_traits traits; return traits::is_valid(val) ? traits::key_table[val - traits::first_item_value] : NULL; } + /** + * Return the enum item key string pointer, or "?" if none. + */ template inline const char *enum_item_key_str(T val) { return ifnull(enum_item_raw_key(val), "?"); } - DFHACK_EXPORT int findEnumItem_(const std::string &name, int size, const char *const *items); + template + std::string format_key(const char *keyname, BaseType val) { + if (keyname) return std::string(keyname); + std::stringstream ss; ss << "?" << val << "?"; return ss.str(); + } + /** + * Return the enum item key string, or ?123? (using the numeric value) if unknown. + */ + template + inline std::string enum_item_key(T val) { + typedef typename df::enum_traits::base_type base_type; + return format_key(enum_item_raw_key(val), base_type(val)); + } + + DFHACK_EXPORT int findEnumItem(const std::string &name, int size, const char *const *items); + + /** + * Find an enum item by key string. Returns success code. + */ template inline bool find_enum_item(T *var, const std::string &name) { typedef df::enum_traits traits; int size = traits::last_item_value-traits::first_item_value+1; - int idx = findEnumItem_(name, size, traits::key_table); + int idx = findEnumItem(name, size, traits::key_table); if (idx < 0) return false; *var = T(traits::first_item_value+idx); return true; } - DFHACK_EXPORT int findBitfieldField_(const std::string &name, int size, const bitfield_item_info *items); + /* + * Bitfield tools. + */ + + DFHACK_EXPORT bool findBitfieldField(unsigned *idx, const std::string &name, + unsigned size, const bitfield_item_info *items); + DFHACK_EXPORT void setBitfieldField(void *p, unsigned idx, unsigned size, int value); + DFHACK_EXPORT int getBitfieldField(const void *p, unsigned idx, unsigned size); + /** + * Find a bitfield item by key string. Returns success code. + */ template - inline int findBitfieldField(const std::string &name) { + inline bool find_bitfield_field(unsigned *idx, const std::string &name, const T* = NULL) { typedef df::bitfield_traits traits; - return findBitfieldField_(name, traits::bit_count, traits::bits); + return findBitfieldField(&idx, name, traits::bit_count, traits::bits); } - DFHACK_EXPORT std::string bitfieldToString(const void *p, int size, const bitfield_item_info *items); + /** + * Find a bitfield item by key and set its value. Returns success code. + */ + template + inline bool set_bitfield_field(T *bitfield, const std::string &name, int value) + { + typedef df::bitfield_traits traits; + unsigned idx; + if (!findBitfieldField(&idx, name, traits::bit_count, traits::bits)) return false; + setBitfieldField(&bitfield->whole, idx, traits::bits[idx].size, value); + return true; + } + /** + * Find a bitfield item by key and retrieve its value. Returns success code. + */ template - inline std::string bitfieldToString(const T &val) { + inline bool get_bitfield_field(int *value, const T &bitfield, const std::string &name) + { typedef df::bitfield_traits traits; - return bitfieldToString(&val.whole, traits::bit_count, traits::bits); + unsigned idx; + if (!findBitfieldField(&idx, name, traits::bit_count, traits::bits)) return false; + *value = getBitfieldField(&bitfield.whole, idx, traits::bits[idx].size); + return true; + } + + DFHACK_EXPORT void bitfieldToString(std::vector *pvec, const void *p, + unsigned size, const bitfield_item_info *items); + + /** + * Represent bitfield bits as strings in a vector. + */ + template + inline void bitfield_to_string(std::vector *pvec, const T &val) { + typedef df::bitfield_traits traits; + bitfieldToString(pvec, &val.whole, traits::bit_count, traits::bits); } -} + /** + * Represent bitfield bits as a string, using sep as join separator. + */ + template + inline std::string bitfield_to_string(const T &val, const std::string &sep = " ") { + std::vector tmp; + bitfield_to_string(&tmp, val); + return join_strings(sep, tmp); + } + + /* + * BitArray tools + */ + + /** + * Find a flag array item by key string. Returns success code. + */ + template + inline bool find_bitfield_field(unsigned *idx, const std::string &name, const BitArray*) { + T tmp; + if (!find_enum_item(&tmp, name) || tmp < 0) return false; + *idx = unsigned(tmp); + return true; + } + + /** + * Find a flag array item by key and set its value. Returns success code. + */ + template + inline bool set_bitfield_field(BitArray *bitfield, const std::string &name, int value) + { + T tmp; + if (!find_enum_item(&tmp, name) || tmp < 0) return false; + bitfield->set(tmp, value!=0); + return true; + } + + /** + * Find a flag array item by key and retrieve its value. Returns success code. + */ + template + inline bool get_bitfield_field(int *value, const BitArray &bitfield, const std::string &name) + { + T tmp; + if (!find_enum_item(&tmp, name) || tmp < 0) return false; + *value = (bitfield->is_set(tmp) ? 1 : 0); + return true; + } + + DFHACK_EXPORT void flagarrayToString(std::vector *pvec, const void *p, + int bytes, int base, int size, const char *const *items); + + /** + * Represent flag array bits as strings in a vector. + */ + template + inline void bitfield_to_string(std::vector *pvec, const BitArray &val) { + typedef df::enum_traits traits; + int size = traits::last_item_value-traits::first_item_value+1; + flagarrayToString(pvec, val.bits, val.size, + (int)traits::first_item_value, size, traits::key_table); + } + +} #define ENUM_ATTR(enum,attr,val) (df::enum_traits::attrs(val).attr) #define ENUM_ATTR_STR(enum,attr,val) DFHack::ifnull(ENUM_ATTR(enum,attr,val),"?") -#define ENUM_KEY_STR(enum,val) (DFHack::enum_item_key_str(val)) +#define ENUM_KEY_STR(enum,val) (DFHack::enum_item_key(val)) #define ENUM_FIRST_ITEM(enum) (df::enum_traits::first_item) #define ENUM_LAST_ITEM(enum) (df::enum_traits::last_item) @@ -280,6 +431,10 @@ namespace DFHack { #define FOR_ENUM_ITEMS(enum,iter) \ for(df::enum iter = ENUM_FIRST_ITEM(enum); iter <= ENUM_LAST_ITEM(enum); iter = df::enum(1+int(iter))) +/* + * Include mandatory generated headers. + */ + // Global object pointers #include "df/global_objects.h" diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h index 039b75b20..e5ecb25f4 100644 --- a/library/include/MiscUtils.h +++ b/library/include/MiscUtils.h @@ -253,6 +253,7 @@ Link *linked_list_insert_after(Link *pos, Link *link) DFHACK_EXPORT bool split_string(std::vector *out, const std::string &str, const std::string &separator, bool squash_empty = false); +DFHACK_EXPORT std::string join_strings(const std::string &separator, const std::vector &items); DFHACK_EXPORT std::string toUpper(const std::string &str); DFHACK_EXPORT std::string toLower(const std::string &str); diff --git a/library/include/RemoteTools.h b/library/include/RemoteTools.h index 9c5a9b069..00d5e5281 100644 --- a/library/include/RemoteTools.h +++ b/library/include/RemoteTools.h @@ -27,8 +27,26 @@ distribution. #include "Export.h" #include "RemoteServer.h" -namespace DFHack +#include "DataDefs.h" + +namespace DFHack { + using google::protobuf::RepeatedPtrField; + + DFHACK_EXPORT void strVectorToRepeatedField(RepeatedPtrField *pf, + const std::vector &vec); + + /** + * Represent bitfield bits as a repeated string field. + */ + template + inline void bitfield_to_string(RepeatedPtrField *pf, const T &val) { + std::vector tmp; + bitfield_to_string(&tmp, val); + strVectorToRepeatedField(pf, tmp); + } + + class CoreService : public RPCService { int suspend_depth; public: diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index d1ca7923c..2c9a5d1d0 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -159,11 +159,11 @@ static void print_job_item_details(color_ostream &out, df::job *job, unsigned id } if (item->flags1.whole) - out << " flags1: " << bitfieldToString(item->flags1) << endl; + out << " flags1: " << bitfield_to_string(item->flags1) << endl; if (item->flags2.whole) - out << " flags2: " << bitfieldToString(item->flags2) << endl; + out << " flags2: " << bitfield_to_string(item->flags2) << endl; if (item->flags3.whole) - out << " flags3: " << bitfieldToString(item->flags3) << endl; + out << " flags3: " << bitfield_to_string(item->flags3) << endl; if (!item->reaction_class.empty()) out << " reaction class: " << item->reaction_class << endl; @@ -178,7 +178,7 @@ void DFHack::printJobDetails(color_ostream &out, df::job *job) out.color(job->flags.bits.suspend ? Console::COLOR_DARKGREY : Console::COLOR_GREY); out << "Job " << job->id << ": " << ENUM_KEY_STR(job_type,job->job_type); if (job->flags.whole) - out << " (" << bitfieldToString(job->flags) << ")"; + out << " (" << bitfield_to_string(job->flags) << ")"; out << endl; out.reset_color(); @@ -192,7 +192,7 @@ void DFHack::printJobDetails(color_ostream &out, df::job *job) { out << " material: " << mat.toString(); if (job->material_category.whole) - out << " (" << bitfieldToString(job->material_category) << ")"; + out << " (" << bitfield_to_string(job->material_category) << ")"; out << endl; } @@ -201,7 +201,7 @@ void DFHack::printJobDetails(color_ostream &out, df::job *job) ItemTypeInfo iinfo(itype, job->item_subtype); out << " item: " << iinfo.toString() - << " (" << bitfieldToString(job->item_category) << ")" << endl; + << " (" << bitfield_to_string(job->item_category) << ")" << endl; } if (job->hist_figure_id >= 0) diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 68aadc3d6..8f5739c7e 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -505,11 +505,8 @@ bool DFHack::parseJobMaterialCategory(df::job_material_category *cat, const std: for (size_t i = 0; i < items.size(); i++) { - int id = findBitfieldField(items[i]); - if (id < 0) + if (!set_bitfield_field(cat, items[i], 1)) return false; - - cat->whole |= (1 << id); } return true; @@ -524,11 +521,8 @@ bool DFHack::parseJobMaterialCategory(df::dfhack_material_category *cat, const s for (size_t i = 0; i < items.size(); i++) { - int id = findBitfieldField(items[i]); - if (id < 0) + if (!set_bitfield_field(cat, items[i], 1)) return false; - - cat->whole |= (1 << id); } return true; diff --git a/plugins/devel/dumpmats.cpp b/plugins/devel/dumpmats.cpp index 6ee3d693f..ba888e7cf 100644 --- a/plugins/devel/dumpmats.cpp +++ b/plugins/devel/dumpmats.cpp @@ -245,13 +245,13 @@ command_result df_dumpmats (color_ostream &out, vector ¶meters) FOR_ENUM_ITEMS(material_flags, i) { if (mat->flags.is_set(i)) - out.print("\t[%s]\n", ENUM_KEY_STR(material_flags, i)); + out.print("\t[%s]\n", ENUM_KEY_STR(material_flags, i).c_str()); } if (mat->extract_storage != item_type::BARREL) - out.print("\t[EXTRACT_STORAGE:%s]\n", ENUM_KEY_STR(item_type, mat->extract_storage)); + out.print("\t[EXTRACT_STORAGE:%s]\n", ENUM_KEY_STR(item_type, mat->extract_storage).c_str()); if (mat->butcher_special_type != item_type::NONE || mat->butcher_special_subtype != -1) - out.print("\t[BUTCHER_SPECIAL:%s:%s]\n", ENUM_KEY_STR(item_type, mat->butcher_special_type), (mat->butcher_special_subtype == -1) ? "NONE" : "?"); + out.print("\t[BUTCHER_SPECIAL:%s:%s]\n", ENUM_KEY_STR(item_type, mat->butcher_special_type).c_str(), (mat->butcher_special_subtype == -1) ? "NONE" : "?"); if (mat->meat_name[0].size() || mat->meat_name[1].size() || mat->meat_name[2].size()) out.print("\t[MEAT_NAME:%s:%s:%s]\n", mat->meat_name[0].c_str(), mat->meat_name[1].c_str(), mat->meat_name[2].c_str()); if (mat->block_name[0].size() || mat->block_name[1].size()) diff --git a/plugins/feature.cpp b/plugins/feature.cpp index cadd91b69..834284e0f 100644 --- a/plugins/feature.cpp +++ b/plugins/feature.cpp @@ -38,7 +38,9 @@ static command_result feature(color_ostream &out, vector ¶meters) df::feature_init *feature_init = world->cur_savegame.map_features[i]; string name; feature_init->getName(&name); - out.print("Feature #%i (\"%s\", type %s) is %s\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()), feature_init->flags.is_set(feature_init_flags::Discovered) ? "discovered" : "hidden"); + out.print("Feature #%i (\"%s\", type %s) is %s\n", + i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()).c_str(), + feature_init->flags.is_set(feature_init_flags::Discovered) ? "discovered" : "hidden"); } } else if(cmd == "show") @@ -60,7 +62,8 @@ static command_result feature(color_ostream &out, vector ¶meters) feature_init->flags.set(feature_init_flags::Discovered); string name; feature_init->getName(&name); - out.print("Feature #%i (\"%s\", type %s) is now discovered\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType())); + out.print("Feature #%i (\"%s\", type %s) is now discovered\n", + i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()).c_str()); } else if(cmd == "hide") { @@ -81,7 +84,8 @@ static command_result feature(color_ostream &out, vector ¶meters) feature_init->flags.clear(feature_init_flags::Discovered); string name; feature_init->getName(&name); - out.print("Feature #%i (\"%s\", type %s) is now hidden\n", i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType())); + out.print("Feature #%i (\"%s\", type %s) is now hidden\n", + i, name.c_str(), ENUM_KEY_STR(feature_type, feature_init->getType()).c_str()); } else return CR_WRONG_USAGE; diff --git a/plugins/jobutils.cpp b/plugins/jobutils.cpp index ca234423a..603346c33 100644 --- a/plugins/jobutils.cpp +++ b/plugins/jobutils.cpp @@ -146,7 +146,7 @@ static command_result job_material_in_job(color_ostream &out, MaterialInfo &new_ if (new_mat.getCraftClass() != old_class) { out.printerr("New material %s does not satisfy requirement: %s\n", - new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class)); + new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class).c_str()); return CR_FAILURE; } @@ -277,7 +277,7 @@ static command_result job_duplicate(color_ostream &out, vector & parame job->job_type != job_type::CollectSand && job->job_type != job_type::CollectClay)) { - out.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type)); + out.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type).c_str()); return CR_FAILURE; } diff --git a/plugins/probe.cpp b/plugins/probe.cpp index bff612680..cc3cbb0f6 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -175,15 +175,15 @@ command_result df_probe (color_ostream &out, vector & parameters) df::tiletype_special special = tileSpecial(tiletype); df::tiletype_variant variant = tileVariant(tiletype); out.print("%-10s: %4d %s\n","Class" ,shape, - ENUM_KEY_STR(tiletype_shape, shape)); + ENUM_KEY_STR(tiletype_shape, shape).c_str()); out.print("%-10s: %4d %s\n","Material" , - material, ENUM_KEY_STR(tiletype_material, material)); + material, ENUM_KEY_STR(tiletype_material, material).c_str()); out.print("%-10s: %4d %s\n","Special" , - special, ENUM_KEY_STR(tiletype_special, special)); + special, ENUM_KEY_STR(tiletype_special, special).c_str()); out.print("%-10s: %4d %s\n" ,"Variant" , - variant, ENUM_KEY_STR(tiletype_variant, variant)); + variant, ENUM_KEY_STR(tiletype_variant, variant).c_str()); out.print("%-10s: %s\n" ,"Direction", - tileDirection(tiletype).getStr()); + tileDirection(tiletype).getStr()); out.print("\n"); out.print("temperature1: %d U\n",mc.temperature1At(cursor)); @@ -300,34 +300,38 @@ command_result df_bprobe (color_ostream &out, vector & parameters) continue; string name; building.origin->getName(&name); - out.print("Building %i - \"%s\" - type %s", building.origin->id, name.c_str(), ENUM_KEY_STR(building_type, building.type)); + out.print("Building %i - \"%s\" - type %s", + building.origin->id, name.c_str(), + ENUM_KEY_STR(building_type, building.type).c_str()); switch (building.type) { case building_type::Civzone: - out.print(", subtype %s", ENUM_KEY_STR(civzone_type, building.civzone_type)); + out.print(", subtype %s", ENUM_KEY_STR(civzone_type, building.civzone_type).c_str()); break; case building_type::Furnace: - out.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type)); + out.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type).c_str()); if (building.furnace_type == furnace_type::Custom) - out.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str()); + out.print(", custom type %i (%s)", building.custom_type, + world->raws.buildings.all[building.custom_type]->code.c_str()); break; case building_type::Workshop: - out.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type)); + out.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type).c_str()); if (building.workshop_type == workshop_type::Custom) - out.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str()); + out.print(", custom type %i (%s)", building.custom_type, + world->raws.buildings.all[building.custom_type]->code.c_str()); break; case building_type::Construction: - out.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type)); + out.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type).c_str()); break; case building_type::Shop: - out.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type)); + out.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type).c_str()); break; case building_type::SiegeEngine: - out.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type)); + out.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type).c_str()); break; case building_type::Trap: - out.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type)); + out.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type).c_str()); break; default: if (building.subtype != -1) diff --git a/plugins/showmood.cpp b/plugins/showmood.cpp index d47bd8a80..d49477b3f 100644 --- a/plugins/showmood.cpp +++ b/plugins/showmood.cpp @@ -235,16 +235,16 @@ command_result df_showmood (color_ostream &out, vector & parameters) else out.print("%s unknown body parts (%s:%s:%s)", mat_name.c_str(), - bitfieldToString(item->flags1).c_str(), - bitfieldToString(item->flags2).c_str(), - bitfieldToString(item->flags3).c_str()); + bitfield_to_string(item->flags1).c_str(), + bitfield_to_string(item->flags2).c_str(), + bitfield_to_string(item->flags3).c_str()); } else out.print("indeterminate %s item (%s:%s:%s)", mat_name.c_str(), - bitfieldToString(item->flags1).c_str(), - bitfieldToString(item->flags2).c_str(), - bitfieldToString(item->flags3).c_str()); + bitfield_to_string(item->flags1).c_str(), + bitfield_to_string(item->flags2).c_str(), + bitfield_to_string(item->flags3).c_str()); break; default: { @@ -252,9 +252,9 @@ command_result df_showmood (color_ostream &out, vector & parameters) out.print("item %s material %s flags (%s:%s:%s)", itinfo.toString().c_str(), mat_name.c_str(), - bitfieldToString(item->flags1).c_str(), - bitfieldToString(item->flags2).c_str(), - bitfieldToString(item->flags3).c_str()); + bitfield_to_string(item->flags1).c_str(), + bitfield_to_string(item->flags2).c_str(), + bitfield_to_string(item->flags3).c_str()); break; } } diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index b48ce85db..237068b08 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -502,7 +502,7 @@ static bool recover_job(color_ostream &out, ProtectedJob *pj) if (!pj->holder) { out.printerr("Forgetting job %d (%s): holder building lost.", - pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type)); + pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type).c_str()); forget_job(out, pj); return true; } @@ -511,7 +511,7 @@ static bool recover_job(color_ostream &out, ProtectedJob *pj) if (pj->holder->jobs.size() >= 10) { out.printerr("Forgetting job %d (%s): holder building has too many jobs.", - pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type)); + pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type).c_str()); forget_job(out, pj); return true; } @@ -534,7 +534,7 @@ static bool recover_job(color_ostream &out, ProtectedJob *pj) deleteJobStruct(recovered); out.printerr("Inconsistency: job %d (%s) already in list.", - pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type)); + pj->id, ENUM_KEY_STR(job_type, pj->job_copy->job_type).c_str()); return true; } @@ -1283,7 +1283,7 @@ static void update_jobs_by_constraints(color_ostream &out) if (ct->material.isValid()) info = ct->material.toString() + " " + info; else if (ct->mat_mask.whole) - info = bitfieldToString(ct->mat_mask) + " " + info; + info = bitfield_to_string(ct->mat_mask) + " " + info; if (is_running != ct->is_active) { @@ -1337,7 +1337,7 @@ static std::string shortJobDescription(df::job *job) if (mat.isValid()) rv += " [" + mat.toString() + "]"; else if (mat_mask.whole) - rv += " [" + bitfieldToString(mat_mask) + "]"; + rv += " [" + bitfield_to_string(mat_mask) + "]"; return rv; }