From 1a92f561fea9af31f171186439544671a43ec207 Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Wed, 28 Mar 2012 21:56:23 -0500 Subject: [PATCH 01/16] autolabor: set reequip flag when appropriate --- plugins/autolabor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index 733f08066..b453da0ca 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -683,7 +683,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (labor_infos[labor].is_exclusive && dwarf_info[dwarf].has_exclusive_labor) continue; - int value = dwarf_info[dwarf].mastery_penalty - dwarf_info[dwarf].assigned_jobs; + int value = dwarf_info[dwarf].mastery_penalty - dwarf_info[dwarf].assigned_jobs * 50; if (skill != df::enums::job_skill::NONE) { @@ -796,8 +796,12 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) dwarfs[dwarf]->status.labors[labor] = true; - if (labor_infos[labor].is_exclusive) + if (labor_infos[labor].is_exclusive) + { dwarf_info[dwarf].has_exclusive_labor = true; + // all the exclusive labors require equipment so this should force the dorf to reequip if needed + dwarfs[dwarf]->military.pickup_flags.bits.update = 1; + } } } From fea34bfdde2d5f5ab6e829e8f1706159fd9be02c Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Wed, 28 Mar 2012 21:57:08 -0500 Subject: [PATCH 02/16] autolabor: set reequip flag when appropriate. also tweaked scoring to reduce job clumping. --- plugins/autolabor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index 733f08066..b453da0ca 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -683,7 +683,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (labor_infos[labor].is_exclusive && dwarf_info[dwarf].has_exclusive_labor) continue; - int value = dwarf_info[dwarf].mastery_penalty - dwarf_info[dwarf].assigned_jobs; + int value = dwarf_info[dwarf].mastery_penalty - dwarf_info[dwarf].assigned_jobs * 50; if (skill != df::enums::job_skill::NONE) { @@ -796,8 +796,12 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) dwarfs[dwarf]->status.labors[labor] = true; - if (labor_infos[labor].is_exclusive) + if (labor_infos[labor].is_exclusive) + { dwarf_info[dwarf].has_exclusive_labor = true; + // all the exclusive labors require equipment so this should force the dorf to reequip if needed + dwarfs[dwarf]->military.pickup_flags.bits.update = 1; + } } } From d9d1d34d5a67b4b13a42d836a4a458493eed6113 Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Wed, 28 Mar 2012 23:24:05 -0500 Subject: [PATCH 03/16] track --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 6d11abbba..b41c666c6 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 6d11abbbae7e5408e739563266f3300261a5c726 +Subproject commit b41c666c6be6fe18906a98dababdc4ff681b8382 From 17ff235c817048797c9e8d14c7215a6ad67de29d Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 29 Mar 2012 10:59:54 +0400 Subject: [PATCH 04/16] Use codegen.out.xml instead of static.inc in cmake code generation rules. Now only that file is guaranteed to always be overwritten. --- library/CMakeLists.txt | 4 ++-- library/xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 4d6767b31..9de419b9f 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -189,14 +189,14 @@ FILE(GLOB GENERATE_INPUT_SCRIPTS ${dfapi_SOURCE_DIR}/xml/*.pm ${dfapi_SOURCE_DIR FILE(GLOB GENERATE_INPUT_XMLS ${dfapi_SOURCE_DIR}/xml/*.xml) ADD_CUSTOM_COMMAND( - OUTPUT ${dfapi_SOURCE_DIR}/include/df/static.inc + OUTPUT ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml COMMAND ${PERL_EXECUTABLE} xml/codegen.pl xml include/df WORKING_DIRECTORY ${dfapi_SOURCE_DIR} MAIN_DEPENDENCY ${dfapi_SOURCE_DIR}/xml/codegen.pl DEPENDS ${GENERATE_INPUT_XMLS} ${GENERATE_INPUT_SCRIPTS} ) -ADD_CUSTOM_TARGET(generate_headers DEPENDS ${dfapi_SOURCE_DIR}/include/df/static.inc) +ADD_CUSTOM_TARGET(generate_headers DEPENDS ${dfapi_SOURCE_DIR}/include/df/codegen.out.xml) IF(UNIX) # Don't produce debug info for generated stubs diff --git a/library/xml b/library/xml index 6d11abbba..3e1c72864 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 6d11abbbae7e5408e739563266f3300261a5c726 +Subproject commit 3e1c728640d8f5a9501908064a2d5385a156058c From f6c6218909fd196a5bd293b7f41ceaf9c7d4267c Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 29 Mar 2012 11:32:22 +0400 Subject: [PATCH 05/16] Temporary tweak: patch in __pairs and __ipairs from 5.2 into lua 5.1. --- depends/lua/src/lbaselib.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/depends/lua/src/lbaselib.c b/depends/lua/src/lbaselib.c index 2a4c079d3..f927e5632 100644 --- a/depends/lua/src/lbaselib.c +++ b/depends/lua/src/lbaselib.c @@ -236,10 +236,17 @@ static int luaB_next (lua_State *L) { static int luaB_pairs (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ - lua_pushvalue(L, 1); /* state, */ - lua_pushnil(L); /* and initial value */ + luaL_checkany(L, 1); + if (luaL_getmetafield(L, 1, "__pairs")) { + lua_pushvalue(L, 1); + lua_call(L, 1, 3); + } + else { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushnil(L); /* and initial value */ + } return 3; } @@ -255,10 +262,17 @@ static int ipairsaux (lua_State *L) { static int luaB_ipairs (lua_State *L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ - lua_pushvalue(L, 1); /* state, */ - lua_pushinteger(L, 0); /* and initial value */ + luaL_checkany(L, 1); + if (luaL_getmetafield(L, 1, "__ipairs")) { + lua_pushvalue(L, 1); + lua_call(L, 1, 3); + } + else { + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ + lua_pushvalue(L, 1); /* state, */ + lua_pushinteger(L, 0); /* and initial value */ + } return 3; } From 85c91c92d81b4ba226973aa9312c7b01e47554de Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 29 Mar 2012 14:39:13 +0400 Subject: [PATCH 06/16] Implement __pairs and __ipairs for DF objects. Structs enumerate fields in memory order in pairs(). Containers & biftields enumerate int indexes in ipairs, and string keys in pairs (i.e. using index-enum for arrays). --- library/LuaTypes.cpp | 238 ++++++++++++++++++++++++++++++----- library/LuaWrapper.cpp | 88 +++++++++++-- library/include/LuaWrapper.h | 20 ++- 3 files changed, 303 insertions(+), 43 deletions(-) diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index 76586bf71..089ead0dd 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -389,6 +389,43 @@ static void *find_field(lua_State *state, int index, const char *mode) return p; } +static int cur_iter_index(lua_State *state, int len, int fidx, int first_idx = -1) +{ + int rv; + + if (lua_isnil(state, fidx)) + rv = first_idx; + else + { + if (lua_isnumber(state, fidx)) + rv = lua_tointeger(state, fidx); + else + { + lua_pushvalue(state, fidx); + lua_rawget(state, UPVAL_FIELDTABLE); + if (!lua_isnumber(state, -1)) + field_error(state, fidx, "index not found", "iterate"); + rv = lua_tointeger(state, -1); + lua_pop(state, 1); + } + + if (rv < 0 || rv >= len) + field_error(state, fidx, "index out of bounds", "iterate"); + } + + return rv; +} + +static void iter_idx_to_name(lua_State *state, int idx) +{ + lua_pushvalue(state, idx); + lua_rawget(state, UPVAL_FIELDTABLE); + if (lua_isnil(state, -1)) + lua_pop(state, 1); + else + lua_replace(state, idx); +} + static uint8_t *check_method_call(lua_State *state, int min_args, int max_args) { int argc = lua_gettop(state)-1; @@ -592,6 +629,24 @@ static int meta_struct_newindex(lua_State *state) return 0; } +/** + * Metamethod: iterator for structures. + */ +static int meta_struct_next(lua_State *state) +{ + if (lua_gettop(state) < 2) lua_pushnil(state); + + int len = lua_objlen(state, UPVAL_FIELDTABLE); + int idx = cur_iter_index(state, len+1, 2, 0); + if (idx == len) + return 0; + + lua_rawgeti(state, UPVAL_FIELDTABLE, idx+1); + lua_dup(state); + lua_gettable(state, 1); + return 2; +} + /** * Metamethod: __index for primitives, i.e. simple object references. * Fields point to identity, or NULL for metafields. @@ -722,6 +777,39 @@ static int meta_container_newindex(lua_State *state) return 0; } +/** + * Metamethod: integer iterator for containers. + */ +static int meta_container_nexti(lua_State *state) +{ + if (lua_gettop(state) < 2) lua_pushnil(state); + + uint8_t *ptr = get_object_addr(state, 1, 2, "iterate"); + + auto id = (container_identity*)lua_touserdata(state, UPVAL_CONTAINER_ID); + int len = id->lua_item_count(state, ptr, container_identity::COUNT_LEN); + int idx = cur_iter_index(state, len, 2); + + if (++idx >= len) + return 0; + + lua_pushinteger(state, idx); + id->lua_item_read(state, 2, ptr, idx); + return 2; +} + +/** + * Metamethod: name iterator for containers. + */ +static int meta_container_next(lua_State *state) +{ + if (!meta_container_nexti(state)) + return 0; + + iter_idx_to_name(state, lua_gettop(state)-1); + return 2; +} + /** * Method: resize container */ @@ -781,6 +869,17 @@ static int meta_bitfield_len(lua_State *state) return 1; } +static void read_bitfield(lua_State *state, uint8_t *ptr, bitfield_identity *id, int idx) +{ + int size = id->getBits()[idx].size; + + int value = getBitfieldField(ptr, idx, size); + if (size <= 1) + lua_pushboolean(state, value != 0); + else + lua_pushinteger(state, value); +} + /** * Metamethod: __index for bitfields. */ @@ -803,13 +902,7 @@ static int meta_bitfield_index(lua_State *state) } int idx = check_container_index(state, id->getNumBits(), 2, iidx, "read"); - int size = id->getBits()[idx].size; - - int value = getBitfieldField(ptr, idx, size); - if (size <= 1) - lua_pushboolean(state, value != 0); - else - lua_pushinteger(state, value); + read_bitfield(state, ptr, id, idx); return 1; } @@ -846,6 +939,44 @@ static int meta_bitfield_newindex(lua_State *state) return 0; } +/** + * Metamethod: integer iterator for bitfields. + */ +static int meta_bitfield_nexti(lua_State *state) +{ + if (lua_gettop(state) < 2) lua_pushnil(state); + + uint8_t *ptr = get_object_addr(state, 1, 2, "iterate"); + + auto id = (bitfield_identity*)lua_touserdata(state, UPVAL_CONTAINER_ID); + int len = id->getNumBits(); + int idx = cur_iter_index(state, len, 2); + + if (idx < 0) + idx = 0; + else + idx += std::max(1, (int)id->getBits()[idx].size); + + if (idx >= len) + return 0; + + lua_pushinteger(state, idx); + read_bitfield(state, ptr, id, idx); + return 2; +} + +/** + * Metamethod: name iterator for bitfields. + */ +static int meta_bitfield_next(lua_State *state) +{ + if (!meta_bitfield_nexti(state)) + return 0; + + iter_idx_to_name(state, lua_gettop(state)-1); + return 2; +} + /** * Metamethod: __index for df.global */ @@ -906,36 +1037,43 @@ static void AddMethodWrapper(lua_State *state, int meta_idx, int field_idx, /** * Add fields in the array to the UPVAL_FIELDTABLE candidates on the stack. */ -static void IndexFields(lua_State *state, struct_identity *pstruct) +static void IndexFields(lua_State *state, int base, struct_identity *pstruct) { - // stack: metatable fieldtable + if (pstruct->getParent()) + IndexFields(state, base, pstruct->getParent()); - int base = lua_gettop(state) - 2; + auto fields = pstruct->getFields(); + if (!fields) + return; - for (struct_identity *p = pstruct; p; p = p->getParent()) + int cnt = lua_objlen(state, base+3); // field iter table + + for (int i = 0; fields[i].mode != struct_field_info::END; ++i) { - auto fields = p->getFields(); - if (!fields) - continue; + // Qualify conflicting field names with the type + std::string name = fields[i].name; - for (int i = 0; fields[i].mode != struct_field_info::END; ++i) + lua_getfield(state, base+2, name.c_str()); + if (!lua_isnil(state, -1)) + name = pstruct->getName() + ("." + name); + lua_pop(state, 1); + + // Handle the field + switch (fields[i].mode) { - switch (fields[i].mode) - { - case struct_field_info::OBJ_METHOD: - AddMethodWrapper(state, base+1, base+2, fields[i].name, - (function_identity_base*)fields[i].type); - break; + case struct_field_info::OBJ_METHOD: + AddMethodWrapper(state, base+1, base+2, name.c_str(), + (function_identity_base*)fields[i].type); + break; - case struct_field_info::CLASS_METHOD: - break; + case struct_field_info::CLASS_METHOD: + break; - default: - lua_pushstring(state,fields[i].name); - lua_pushlightuserdata(state,(void*)&fields[i]); - lua_rawset(state,base+2); - break; - } + default: + AssociateId(state, base+3, ++cnt, name.c_str()); + lua_pushlightuserdata(state, (void*)&fields[i]); + lua_setfield(state, base+2, name.c_str()); + break; } } } @@ -976,8 +1114,20 @@ static void MakeFieldMetatable(lua_State *state, struct_identity *pstruct, MakeMetatable(state, pstruct, "struct"); // meta, fields - IndexFields(state, pstruct); + // Index the fields + lua_newtable(state); + + IndexFields(state, base, pstruct); + + // Add the iteration metamethods + PushStructMethod(state, base+1, base+3, meta_struct_next); + SetPairsMethod(state, base+1, "__pairs"); + lua_pushnil(state); + SetPairsMethod(state, base+1, "__ipairs"); + + lua_setfield(state, base+1, "_index_table"); + // Add the indexing metamethods SetStructMethod(state, base+1, base+2, reader, "__index"); SetStructMethod(state, base+1, base+2, writer, "__newindex"); @@ -995,8 +1145,21 @@ static void MakePrimitiveMetatable(lua_State *state, type_identity *type) SetPtrMethods(state, base+1, base+2); + // Index the fields + lua_newtable(state); + EnableMetaField(state, base+2, "value", type); + AssociateId(state, base+3, 1, "value"); + + // Add the iteration metamethods + PushStructMethod(state, base+1, base+3, meta_struct_next); + SetPairsMethod(state, base+1, "__pairs"); + lua_pushnil(state); + SetPairsMethod(state, base+1, "__ipairs"); + lua_setfield(state, base+1, "_index_table"); + + // Add the indexing metamethods SetStructMethod(state, base+1, base+2, meta_primitive_index, "__index"); SetStructMethod(state, base+1, base+2, meta_primitive_newindex, "__newindex"); } @@ -1048,7 +1211,15 @@ static void MakeContainerMetatable(lua_State *state, container_identity *type, AddContainerMethodFun(state, base+1, base+2, method_container_erase, "erase", type, item, count); AddContainerMethodFun(state, base+1, base+2, method_container_insert, "insert", type, item, count); + // push the index table AttachEnumKeys(state, base+1, base+2, ienum); + + PushContainerMethod(state, base+1, base+3, meta_container_next, type, item, count); + SetPairsMethod(state, base+1, "__pairs"); + PushContainerMethod(state, base+1, base+3, meta_container_nexti, type, item, count); + SetPairsMethod(state, base+1, "__ipairs"); + + lua_pop(state, 1); } /* @@ -1078,6 +1249,13 @@ void bitfield_identity::build_metatable(lua_State *state) AttachEnumKeys(state, base+1, base+2, this); + PushContainerMethod(state, base+1, base+3, meta_bitfield_next, this, NULL, -1); + SetPairsMethod(state, base+1, "__pairs"); + PushContainerMethod(state, base+1, base+3, meta_bitfield_nexti, this, NULL, -1); + SetPairsMethod(state, base+1, "__ipairs"); + + lua_pop(state, 1); + EnableMetaField(state, base+2, "whole", this); } diff --git a/library/LuaWrapper.cpp b/library/LuaWrapper.cpp index 4436b828b..4e1c6205c 100644 --- a/library/LuaWrapper.cpp +++ b/library/LuaWrapper.cpp @@ -853,6 +853,23 @@ static int meta_enum_attr_index(lua_State *state) return 1; } +static int meta_nodata(lua_State *state) +{ + return 0; +} + +/** + * Metamethod: __pairs, returning 1st upvalue as iterator + */ +static int meta_pairs(lua_State *state) +{ + luaL_checkany(state, 1); + lua_pushvalue(state, lua_upvalueindex(1)); + lua_pushvalue(state, 1); + lua_pushnil(state); + return 3; +} + /** * Make a metatable with most common fields, and an empty table for UPVAL_FIELDTABLE. */ @@ -879,7 +896,8 @@ void LuaWrapper::MakeMetatable(lua_State *state, type_identity *type, const char lua_pushstring(state, kind); lua_setfield(state, base+1, "_kind"); - lua_newtable(state); // fieldtable + // Create the field table + lua_newtable(state); } /** @@ -930,25 +948,49 @@ void LuaWrapper::SetPtrMethods(lua_State *state, int meta_idx, int read_idx) EnableMetaField(state, read_idx, "_displace"); } +/** + * Add a __pairs/__ipairs metamethod using iterator on the top of stack. + */ +void LuaWrapper::SetPairsMethod(lua_State *state, int meta_idx, const char *name) +{ + if (lua_isnil(state, -1)) + { + lua_pop(state, 1); + lua_pushcfunction(state, meta_nodata); + } + + lua_pushcclosure(state, meta_pairs, 1); + lua_setfield(state, meta_idx, name); +} + /** * Add a struct-style (3 upvalues) metamethod to the metatable. */ -void LuaWrapper::SetStructMethod(lua_State *state, int meta_idx, int ftable_idx, - lua_CFunction function, const char *name) +void LuaWrapper::PushStructMethod(lua_State *state, int meta_idx, int ftable_idx, + lua_CFunction function) { lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_TYPETABLE_NAME); lua_pushvalue(state, meta_idx); lua_pushvalue(state, ftable_idx); lua_pushcclosure(state, function, 3); +} + +/** + * Add a struct-style (3 upvalues) metamethod to the metatable. + */ +void LuaWrapper::SetStructMethod(lua_State *state, int meta_idx, int ftable_idx, + lua_CFunction function, const char *name) +{ + PushStructMethod(state, meta_idx, ftable_idx, function); lua_setfield(state, meta_idx, name); } /** * Add a 6 upvalue metamethod to the metatable. */ -void LuaWrapper::SetContainerMethod(lua_State *state, int meta_idx, int ftable_idx, - lua_CFunction function, const char *name, - type_identity *container, type_identity *item, int count) +void LuaWrapper::PushContainerMethod(lua_State *state, int meta_idx, int ftable_idx, + lua_CFunction function, + type_identity *container, type_identity *item, int count) { lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_TYPETABLE_NAME); lua_pushvalue(state, meta_idx); @@ -962,31 +1004,48 @@ void LuaWrapper::SetContainerMethod(lua_State *state, int meta_idx, int ftable_i lua_pushinteger(state, count); lua_pushcclosure(state, function, 6); +} + +/** + * Add a 6 upvalue metamethod to the metatable. + */ +void LuaWrapper::SetContainerMethod(lua_State *state, int meta_idx, int ftable_idx, + lua_CFunction function, const char *name, + type_identity *container, type_identity *item, int count) +{ + PushContainerMethod(state, meta_idx, ftable_idx, function, container, item, count); lua_setfield(state, meta_idx, name); } /** * If ienum refers to a valid enum, attach its keys to UPVAL_FIELDTABLE, - * and the enum itself to the _enum metafield. + * and the enum itself to the _enum metafield. Pushes the key table on the stack */ void LuaWrapper::AttachEnumKeys(lua_State *state, int meta_idx, int ftable_idx, type_identity *ienum) { + EnableMetaField(state, ftable_idx, "_enum"); + + LookupInTable(state, ienum, DFHACK_TYPEID_TABLE_NAME); + lua_setfield(state, meta_idx, "_enum"); + LookupInTable(state, ienum, DFHACK_ENUM_TABLE_NAME); if (!lua_isnil(state, -1)) { + lua_dup(state); lua_newtable(state); lua_swap(state); lua_setfield(state, -2, "__index"); lua_setmetatable(state, ftable_idx); } else + { lua_pop(state, 1); + lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_EMPTY_TABLE_NAME); + } - LookupInTable(state, ienum, DFHACK_TYPEID_TABLE_NAME); - lua_setfield(state, meta_idx, "_enum"); - - EnableMetaField(state, ftable_idx, "_enum"); + lua_dup(state); + lua_setfield(state, meta_idx, "_index_table"); } static void BuildTypeMetatable(lua_State *state, type_identity *type) @@ -1004,7 +1063,7 @@ static void BuildTypeMetatable(lua_State *state, type_identity *type) static void RenderTypeChildren(lua_State *state, const std::vector &children); -static void AssociateId(lua_State *state, int table, int val, const char *name) +void LuaWrapper::AssociateId(lua_State *state, int table, int val, const char *name) { lua_pushinteger(state, val); lua_pushstring(state, name); @@ -1157,6 +1216,8 @@ static void RenderType(lua_State *state, compound_identity *node) lua_getfield(state, -1, "__newindex"); lua_setfield(state, base+2, "__newindex"); + lua_getfield(state, -1, "__pairs"); + lua_setfield(state, base+2, "__pairs"); lua_pop(state, 3); return; @@ -1201,6 +1262,9 @@ static void DoAttach(lua_State *state) lua_newtable(state); lua_setfield(state, LUA_REGISTRYINDEX, DFHACK_ENUM_TABLE_NAME); + lua_newtable(state); + lua_setfield(state, LUA_REGISTRYINDEX, DFHACK_EMPTY_TABLE_NAME); + lua_pushcfunction(state, change_error); lua_setfield(state, LUA_REGISTRYINDEX, DFHACK_CHANGEERROR_NAME); diff --git a/library/include/LuaWrapper.h b/library/include/LuaWrapper.h index 64ebf4de6..d3f1337e5 100644 --- a/library/include/LuaWrapper.h +++ b/library/include/LuaWrapper.h @@ -69,6 +69,7 @@ namespace DFHack { namespace LuaWrapper { #define DFHACK_NEW_NAME "DFHack::New" #define DFHACK_ASSIGN_NAME "DFHack::Assign" #define DFHACK_DELETE_NAME "DFHack::Delete" +#define DFHACK_EMPTY_TABLE_NAME "DFHack::EmptyTable" /* * Upvalue: contents of DFHACK_TYPETABLE_NAME @@ -160,6 +161,8 @@ namespace DFHack { namespace LuaWrapper { void SaveInTable(lua_State *state, void *node, const char *tname); void SaveTypeInfo(lua_State *state, void *node); + void AssociateId(lua_State *state, int table, int val, const char *name); + /** * Look up the key on the stack in DFHACK_TYPETABLE; * if found, put result on the stack and return true. @@ -178,11 +181,26 @@ namespace DFHack { namespace LuaWrapper { * Set metatable properties common to all actual DF object references. */ void SetPtrMethods(lua_State *state, int meta_idx, int read_idx); + /** + * Add a __pairs/__ipairs metamethod using iterator on the top of stack. + */ + void SetPairsMethod(lua_State *state, int meta_idx, const char *name); + /** + * Add a struct-style (3 upvalues) metamethod to the stack. + */ + void PushStructMethod(lua_State *state, int meta_idx, int ftable_idx, + lua_CFunction function); /** * Add a struct-style (3 upvalues) metamethod to the metatable. */ void SetStructMethod(lua_State *state, int meta_idx, int ftable_idx, lua_CFunction function, const char *name); + /** + * Add a 6 upvalue metamethod to the stack. + */ + void PushContainerMethod(lua_State *state, int meta_idx, int ftable_idx, + lua_CFunction function, + type_identity *container, type_identity *item, int count); /** * Add a 6 upvalue metamethod to the metatable. */ @@ -191,7 +209,7 @@ namespace DFHack { namespace LuaWrapper { type_identity *container, type_identity *item, int count); /** * If ienum refers to a valid enum, attach its keys to UPVAL_FIELDTABLE, - * and the enum itself to the _enum metafield. + * and the enum itself to the _enum metafield. Pushes the key table on the stack. */ void AttachEnumKeys(lua_State *state, int meta_idx, int ftable_idx, type_identity *ienum); From a9b7c74a232357ccaa2796aa6aba2c53218075c3 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 29 Mar 2012 14:47:33 +0400 Subject: [PATCH 07/16] Allow assigning NULL lightuserdata to pointers, and export a global. Otherwise there is no way to specify NULL via recursive lua table assign. --- library/LuaTypes.cpp | 9 ++++++++- library/LuaWrapper.cpp | 14 ++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index 089ead0dd..8b2974534 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -215,12 +215,19 @@ static void autovivify_ptr(lua_State *state, int fname_idx, void **pptr, lua_pop(state, 1); } +static bool is_null(lua_State *state, int val_index) +{ + return lua_isnil(state, val_index) || + (lua_islightuserdata(state, val_index) && + !lua_touserdata(state, val_index)); +} + void df::pointer_identity::lua_write(lua_State *state, int fname_idx, void *ptr, type_identity *target, int val_index) { auto pptr = (void**)ptr; - if (lua_isnil(state, val_index)) + if (is_null(state, val_index)) *pptr = NULL; else if (lua_istable(state, val_index)) { diff --git a/library/LuaWrapper.cpp b/library/LuaWrapper.cpp index 4e1c6205c..8e3bff7de 100644 --- a/library/LuaWrapper.cpp +++ b/library/LuaWrapper.cpp @@ -496,14 +496,7 @@ static int meta_sizeof(lua_State *state) luaL_error(state, "Usage: object:sizeof() or df.sizeof(object)"); // Two special cases: nil and lightuserdata for NULL and void* - if (lua_isnil(state, 1)) - { - lua_pushnil(state); - lua_pushinteger(state, 0); - return 2; - } - - if (lua_islightuserdata(state, 1)) + if (lua_isnil(state, 1) || lua_islightuserdata(state, 1)) { lua_pushnil(state); lua_pushnumber(state, (size_t)lua_touserdata(state, 1)); @@ -1314,6 +1307,11 @@ static void DoAttach(lua_State *state) lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_ASSIGN_NAME); lua_setfield(state, -2, "assign"); + lua_pushlightuserdata(state, NULL); + lua_setfield(state, -2, "NULL"); + lua_pushlightuserdata(state, NULL); + lua_setglobal(state, "NULL"); + freeze_table(state, true, "df"); lua_remove(state, -2); lua_setmetatable(state, -2); From 88c914142bcbd1a24bac09f5057b69472d7021d9 Mon Sep 17 00:00:00 2001 From: Robert Heinrich Date: Thu, 29 Mar 2012 15:33:54 +0200 Subject: [PATCH 08/16] added plugin changeitem (change material type and base quality) --- README.rst | 19 +++ library/xml | 2 +- plugins/CMakeLists.txt | 1 + plugins/changeitem.cpp | 322 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 plugins/changeitem.cpp diff --git a/README.rst b/README.rst index 1e5f84ca7..7f41f82f9 100644 --- a/README.rst +++ b/README.rst @@ -144,6 +144,25 @@ Example: ``changevein NATIVE_PLATINUM`` Convert vein at cursor position into platinum ore. +changeitem +========== +Allows changing item material and base quality. By default the item currently selected in the UI will be changed (you can select items in the 'k' list or inside containers/inventory). By default change is only allowed if materials is of the same subtype (for example wood<->wood, stone<->stone etc). But since some transformations work pretty well and may be desired you can override this with 'force'. Note that some attributes will not be touched, possibly resulting in weirdness. To get an idea how the RAW id should look like, check some items with 'info'. Using 'force' might create items which are not touched by crafters/haulers. + +Options +------- +:info: Don't change anything, print some info instead. +:here: Change all items at the cursor position. Requires in-game curser. +:material, m: Change material. Must be followed by valid material RAW id. +:quality, q: Change base quality. Must be followed by number (0-5). +:force: Ignore subtypes, force change to new material. + +Examples: +--------- +``changeitem m INORGANIC:GRANITE here`` + Change material of all items under the cursor to granite. +``changeitem q 5`` + Change currently selected item to masterpiece quality. + cursecheck ========== Checks a single map tile or the whole map/world for cursed creatures (ghosts, vampires, necromancers, werebeasts, zombies). diff --git a/library/xml b/library/xml index 1b1fe798e..8bb7f923b 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 1b1fe798e553cf0ed309606f32b8448bb96b30c8 +Subproject commit 8bb7f923b1d124610db7e30aeb3be8f4cb9bd021 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 84bdf8239..229c73e60 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -91,6 +91,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(follow follow.cpp) DFHACK_PLUGIN(changevein changevein.cpp) DFHACK_PLUGIN(changelayer changelayer.cpp) + DFHACK_PLUGIN(changeitem changeitem.cpp) DFHACK_PLUGIN(advtools advtools.cpp) DFHACK_PLUGIN(tweak tweak.cpp) DFHACK_PLUGIN(feature feature.cpp) diff --git a/plugins/changeitem.cpp b/plugins/changeitem.cpp new file mode 100644 index 000000000..b3fb2debc --- /dev/null +++ b/plugins/changeitem.cpp @@ -0,0 +1,322 @@ +// changeitem plugin +// allows to change the material type and quality of selected items +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include "Core.h" +#include "Console.h" +#include "Export.h" +#include "PluginManager.h" +#include "modules/Maps.h" +#include "modules/Gui.h" +#include "modules/Items.h" +#include "modules/Materials.h" +#include "modules/MapCache.h" + +#include "DataDefs.h" +#include "df/item.h" +#include "df/world.h" +#include "df/general_ref.h" + +using namespace DFHack; +using namespace df::enums; + +using MapExtras::Block; +using MapExtras::MapCache; +using df::global::world; + +DFHACK_PLUGIN("changeitem"); + +command_result df_changeitem(color_ostream &out, vector & parameters); + +const string changeitem_help = + "Changeitem allows to change some item attributes.\n" + "By default the item currently selected in the UI will be changed\n" + "(you can select items in the 'k' list or inside containers/inventory).\n" + "By default change is only allowed if materials is of the same subtype\n" + "(for example wood<->wood, stone<->stone etc). But since some transformations\n" + "work pretty well and may be desired you can override this with 'force'.\n" + "Note that some attributes will not be touched, possibly resulting in weirdness.\n" + "To get an idea how the RAW id should look like, check some items with 'info'.\n" + "Using 'force' might create items which are not touched by crafters/haulers.\n" + "Options:\n" + " info - don't change anything, print some item info instead\n" + " here - change all items at cursor position\n" + " material, m - change material. must be followed by material RAW id\n" + " quality, q - change base quality. must be followed by number (0-5)\n" + " force - ignore subtypes, force change to new material.\n" + "Example:\n" + " changeitem m INORGANIC:GRANITE here" + " change material of all items under the cursor to granite\n" + " changeitem q 5\n" + " change currently selected item to masterpiece quality\n"; + + +DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand( + "changeitem", "Change item attributes (material, quality).", + df_changeitem, false, + changeitem_help.c_str() + )); + + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + return CR_OK; +} + +// probably there is some method in the library which does the same +// todo: look for it :) +string describeQuality(int q) +{ + switch(q) + { + case 0: + return "Basic"; + case 1: + return "-Well-crafted-"; + case 2: + return "+Finely-crafted+"; + case 3: + return "*Superior quality*"; + case 4: + return "#Exceptional#"; + case 5: + return "$Masterful$"; + default: + return "!INVALID!"; + } +} + +command_result changeitem_execute( + color_ostream &out, df::item * item, + bool info, bool force, + bool change_material, string new_material, + bool change_quality, int new_quality); + +command_result df_changeitem(color_ostream &out, vector & parameters) +{ + CoreSuspender suspend; + + bool here = false; + bool info = false; + bool force = false; + + bool change_material = false; + string new_material = "none"; + + bool change_quality = false; + int new_quality = 0; + + for (size_t i = 0; i < parameters.size(); i++) + { + string & p = parameters[i]; + + if (p == "help" || p == "?") + { + out << changeitem_help << endl; + return CR_OK; + } + else if (p == "here") + { + here = true; + } + else if (p == "info") + { + info = true; + } + else if (p == "force") + { + force = true; + } + else if (p == "material" || p == "m" ) + { + // must be followed by material RAW id + // (string like 'INORGANIC:GRANITE', 'PLANT:MAPLE:WOOD', ...) + if(i == parameters.size()-1) + { + out.printerr("no material specified!\n"); + } + change_material = true; + new_material = parameters[i+1]; + i++; + } + else if (p == "quality" || p == "q") + { + // must be followed by numeric quality (allowed: 0-5) + if(i == parameters.size()-1) + { + out.printerr("no quality specified!\n"); + } + string & q = parameters[i+1]; + // meh. should use a stringstream instead. but it's only 6 numbers + if(q == "0") + new_quality = 0; + else if(q == "1") + new_quality = 1; + else if(q == "2") + new_quality = 2; + else if(q == "3") + new_quality = 3; + else if(q == "4") + new_quality = 4; + else if(q == "5") + new_quality = 5; + else + { + out << "Invalid quality specified!" << endl; + return CR_WRONG_USAGE; + } + out << "change to quality: " << describeQuality(new_quality) << endl; + change_quality = true; + i++; + } + else + { + out << p << ": Unknown command!" << endl; + return CR_WRONG_USAGE; + } + } + + if (!Maps::IsValid()) + { + out.printerr("Map is not available!\n"); + return CR_FAILURE; + } + + MaterialInfo mat_new; + if (change_material && !mat_new.find(new_material)) + { + out.printerr("No such material!\n"); + return CR_FAILURE; + } + + if (here) + { + int processed_total = 0; + int cx, cy, cz; + DFCoord pos_cursor; + + // needs a cursor + if (!Gui::getCursorCoords(cx,cy,cz)) + { + out.printerr("Cursor position not found. Please enable the cursor.\n"); + return CR_FAILURE; + } + pos_cursor = DFCoord(cx,cy,cz); + + // uh. is this check necessary? + // changeitem doesn't do stuff with map blocks... + { + MapCache MC; + Block * b = MC.BlockAt(pos_cursor / 16); + if(!b) + { + out.printerr("Cursor is in an invalid/uninitialized area. Place it over a floor.\n"); + return CR_FAILURE; + } + // when only changing material it doesn't matter if cursor is over a tile + //df::tiletype ttype = MC.tiletypeAt(pos_cursor); + //if(!DFHack::isFloorTerrain(ttype)) + //{ + // out.printerr("Cursor should be placed over a floor.\n"); + // return CR_FAILURE; + //} + } + + // iterate over all items, process those where pos = pos_cursor + size_t numItems = world->items.all.size(); + for(size_t i=0; i< numItems; i++) + { + df::item * item = world->items.all[i]; + DFCoord pos_item(item->pos.x, item->pos.y, item->pos.z); + + if (pos_item != pos_cursor) + continue; + + changeitem_execute(out, item, info, force, change_material, new_material, change_quality, new_quality); + processed_total++; + } + out.print("Done. %d items processed.\n", processed_total); + } + else + { + // needs a selected item + df::item *item = Gui::getSelectedItem(out); + if (!item) + { + out.printerr("No item selected.\n"); + return CR_FAILURE; + } + changeitem_execute(out, item, info, force, change_material, new_material, change_quality, new_quality); + } + return CR_OK; +} + +command_result changeitem_execute( + color_ostream &out, df::item * item, + bool info, bool force, + bool change_material, string new_material, + bool change_quality, int new_quality ) +{ + MaterialInfo mat_new; + MaterialInfo mat_old; + + if(change_material) + mat_new.find(new_material); + if(change_material || info) + mat_old.decode(item); + + // print some info, don't change stuff + if(info) + { + out << "Item info: " << endl; + out << " quality: " << describeQuality(item->getQuality()) << endl; + //if(item->isImproved()) + // out << " imp.quality: " << describeQuality(item->getImprovementQuality()) << endl; + out << " material: " << mat_old.getToken() << endl; + return CR_OK; + } + + if(change_quality) + { + item->setQuality(new_quality); + // it would be nice to be able to change the improved quality, too + // (only allowed if the item is already improved) + // but there is no method in item.h which supports that + // ok: hints from _Q/angavrilov: improvent is a vector, an item can have more than one improvement + // -> virtual_cast to item_constructedst + } + + if(change_material) + { + // subtype and mode should match to avoid doing dumb stuff like changing boulders into meat whatever + // changing a stone cabinet to wood is fine, though. as well as lots of other combinations. + // still, it's better to make the user activate 'force' if he really wants to. + + if(force||(mat_old.subtype == mat_new.subtype && mat_old.mode==mat_new.mode)) + { + item->setMaterial(mat_new.type); + item->setMaterialIndex(mat_new.index); + } + else + { + out.printerr("change denied: subtype doesn't match. use 'force' to override.\n"); + } + + item->flags.bits.unk8 = 0; // recalc temperatures next time touched + item->flags.bits.weight_computed = 0; // recalc weight next time touched + } + return CR_OK; +} From e249ef1377ba99388ac967a4f76dda4b863d50be Mon Sep 17 00:00:00 2001 From: Robert Heinrich Date: Thu, 29 Mar 2012 17:14:41 +0200 Subject: [PATCH 09/16] minor fix (forgot a line break in helpstring) --- plugins/changeitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/changeitem.cpp b/plugins/changeitem.cpp index b3fb2debc..dae0d4a6f 100644 --- a/plugins/changeitem.cpp +++ b/plugins/changeitem.cpp @@ -53,7 +53,7 @@ const string changeitem_help = " quality, q - change base quality. must be followed by number (0-5)\n" " force - ignore subtypes, force change to new material.\n" "Example:\n" - " changeitem m INORGANIC:GRANITE here" + " changeitem m INORGANIC:GRANITE here\n" " change material of all items under the cursor to granite\n" " changeitem q 5\n" " change currently selected item to masterpiece quality\n"; @@ -61,7 +61,7 @@ const string changeitem_help = DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) { - commands.clear(); + //commands.clear(); commands.push_back(PluginCommand( "changeitem", "Change item attributes (material, quality).", df_changeitem, false, From 836d8de73e84dc8cf69307218478d8639e26f469 Mon Sep 17 00:00:00 2001 From: Robert Heinrich Date: Thu, 29 Mar 2012 17:20:25 +0200 Subject: [PATCH 10/16] minor: commands.clear() is not needed in plugin_init() anymore. (done by pluginManager now) removed some useless comments --- plugins/changeitem.cpp | 1 - plugins/changelayer.cpp | 7 ------- plugins/cursecheck.cpp | 1 - plugins/liquids.cpp | 1 - 4 files changed, 10 deletions(-) diff --git a/plugins/changeitem.cpp b/plugins/changeitem.cpp index dae0d4a6f..b7dd17a06 100644 --- a/plugins/changeitem.cpp +++ b/plugins/changeitem.cpp @@ -61,7 +61,6 @@ const string changeitem_help = DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) { - //commands.clear(); commands.push_back(PluginCommand( "changeitem", "Change item attributes (material, quality).", df_changeitem, false, diff --git a/plugins/changelayer.cpp b/plugins/changelayer.cpp index 5f7d5cf0e..d56360d83 100644 --- a/plugins/changelayer.cpp +++ b/plugins/changelayer.cpp @@ -84,11 +84,8 @@ command_result changelayer (color_ostream &out, std::vector & para DFHACK_PLUGIN("changelayer"); -// Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - // Fill the command list with your commands. - commands.clear(); commands.push_back(PluginCommand( "changelayer", "Change a whole geology layer.", changelayer, false, /* true means that the command can't be used from non-interactive user interface */ @@ -98,12 +95,8 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("cursecheck", "Checks for cursed creatures (vampires, necromancers, zombies, ...).", cursecheck, false )); diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 5f4d5b4fe..a7483a886 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -57,7 +57,6 @@ DFHACK_PLUGIN("liquids"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { liquids_hist.load("liquids.history"); - commands.clear(); commands.push_back(PluginCommand( "liquids", "Place magma, water or obsidian.", df_liquids, true)); // interactive, needs console for prompt From 004acdad4ea71c8393decda998bad508b9a14a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Mar 2012 18:37:22 +0200 Subject: [PATCH 11/16] Tweaks! Strip commands.clear() from all plugins Fix changeitem - a variable name has changed in item flags --- library/xml | 2 +- plugins/advtools.cpp | 2 -- plugins/changeitem.cpp | 3 +-- plugins/changelayer.cpp | 1 - plugins/cursecheck.cpp | 1 - plugins/devel/regrass.cpp | 1 - plugins/feature.cpp | 1 - plugins/liquids.cpp | 1 - plugins/mapexport/mapexport.cpp | 1 - plugins/mode.cpp | 1 - plugins/plants.cpp | 1 - plugins/probe.cpp | 1 - plugins/prospector.cpp | 1 - plugins/rename.cpp | 1 - plugins/reveal.cpp | 1 - plugins/seedwatch.cpp | 1 - plugins/showmood.cpp | 1 - plugins/skeleton/skeleton.cpp | 1 - plugins/stockpiles.cpp | 1 - plugins/tiletypes.cpp | 1 - plugins/tubefill.cpp | 1 - plugins/tweak.cpp | 1 - plugins/vdig.cpp | 1 - plugins/versionosd.cpp | 1 - plugins/weather.cpp | 1 - plugins/workflow.cpp | 1 - 26 files changed, 2 insertions(+), 28 deletions(-) diff --git a/library/xml b/library/xml index 8bb7f923b..3e1c72864 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 8bb7f923b1d124610db7e30aeb3be8f4cb9bd021 +Subproject commit 3e1c728640d8f5a9501908064a2d5385a156058c diff --git a/plugins/advtools.cpp b/plugins/advtools.cpp index deaee4856..f88ba6f59 100644 --- a/plugins/advtools.cpp +++ b/plugins/advtools.cpp @@ -55,8 +55,6 @@ DFHACK_PLUGIN("advtools"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); - if (!ui_advmode) return CR_OK; diff --git a/plugins/changeitem.cpp b/plugins/changeitem.cpp index b3fb2debc..6a300f3b0 100644 --- a/plugins/changeitem.cpp +++ b/plugins/changeitem.cpp @@ -61,7 +61,6 @@ const string changeitem_help = DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "changeitem", "Change item attributes (material, quality).", df_changeitem, false, @@ -315,7 +314,7 @@ command_result changeitem_execute( out.printerr("change denied: subtype doesn't match. use 'force' to override.\n"); } - item->flags.bits.unk8 = 0; // recalc temperatures next time touched + item->flags.bits.temps_computed = 0; // recalc temperatures next time touched item->flags.bits.weight_computed = 0; // recalc weight next time touched } return CR_OK; diff --git a/plugins/changelayer.cpp b/plugins/changelayer.cpp index 5f7d5cf0e..77b084404 100644 --- a/plugins/changelayer.cpp +++ b/plugins/changelayer.cpp @@ -88,7 +88,6 @@ DFHACK_PLUGIN("changelayer"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { // Fill the command list with your commands. - commands.clear(); commands.push_back(PluginCommand( "changelayer", "Change a whole geology layer.", changelayer, false, /* true means that the command can't be used from non-interactive user interface */ diff --git a/plugins/cursecheck.cpp b/plugins/cursecheck.cpp index 7551fc689..d4005d3d0 100644 --- a/plugins/cursecheck.cpp +++ b/plugins/cursecheck.cpp @@ -57,7 +57,6 @@ DFHACK_PLUGIN("cursecheck"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("cursecheck", "Checks for cursed creatures (vampires, necromancers, zombies, ...).", cursecheck, false )); diff --git a/plugins/devel/regrass.cpp b/plugins/devel/regrass.cpp index d2d09a517..f4143f465 100644 --- a/plugins/devel/regrass.cpp +++ b/plugins/devel/regrass.cpp @@ -56,7 +56,6 @@ DFHACK_PLUGIN("regrass"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("regrass", "Regrows all surface grass, restoring outdoor plant growth for pre-0.31.19 worlds.", df_regrass)); return CR_OK; } diff --git a/plugins/feature.cpp b/plugins/feature.cpp index 834284e0f..e2ee9d4f1 100644 --- a/plugins/feature.cpp +++ b/plugins/feature.cpp @@ -96,7 +96,6 @@ DFHACK_PLUGIN("feature"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "feature", "List or manage map features.", feature, false, " feature list\n" diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 5f4d5b4fe..a7483a886 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -57,7 +57,6 @@ DFHACK_PLUGIN("liquids"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { liquids_hist.load("liquids.history"); - commands.clear(); commands.push_back(PluginCommand( "liquids", "Place magma, water or obsidian.", df_liquids, true)); // interactive, needs console for prompt diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp index c87613fa5..d7d9daea9 100644 --- a/plugins/mapexport/mapexport.cpp +++ b/plugins/mapexport/mapexport.cpp @@ -30,7 +30,6 @@ DFHACK_PLUGIN("mapexport"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { GOOGLE_PROTOBUF_VERIFY_VERSION; - commands.clear(); commands.push_back(PluginCommand("mapexport", "Exports the current map to a file.", mapexport, true)); return CR_OK; } diff --git a/plugins/mode.cpp b/plugins/mode.cpp index 4a4f9fb0a..d87fd5392 100644 --- a/plugins/mode.cpp +++ b/plugins/mode.cpp @@ -18,7 +18,6 @@ DFHACK_PLUGIN("mode"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "mode","View, change and track game mode.", mode, true, diff --git a/plugins/plants.cpp b/plugins/plants.cpp index eecbb17bd..09220c653 100644 --- a/plugins/plants.cpp +++ b/plugins/plants.cpp @@ -28,7 +28,6 @@ DFHACK_PLUGIN("plants"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("grow", "Grows saplings into trees (with active cursor, only the targetted one).", df_grow)); commands.push_back(PluginCommand("immolate", "Set plants on fire (under cursor, 'shrubs', 'trees' or 'all').", df_immolate)); commands.push_back(PluginCommand("extirpate", "Kill plants (same mechanics as immolate).", df_extirpate)); diff --git a/plugins/probe.cpp b/plugins/probe.cpp index aa207518d..c2a82840f 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -41,7 +41,6 @@ DFHACK_PLUGIN("probe"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("probe", "A tile probe", df_probe)); diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 179fe666f..5afbd2d0a 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -195,7 +195,6 @@ DFHACK_PLUGIN("prospector"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "prospect", "Show stats of available raw resources.", prospector, false, diff --git a/plugins/rename.cpp b/plugins/rename.cpp index 2384fbb3b..8dacf62a9 100644 --- a/plugins/rename.cpp +++ b/plugins/rename.cpp @@ -38,7 +38,6 @@ DFHACK_PLUGIN("rename"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); if (world && ui) { commands.push_back(PluginCommand( "rename", "Rename various things.", rename, false, diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp index 92ae89eb3..39a2ed9cd 100644 --- a/plugins/reveal.cpp +++ b/plugins/reveal.cpp @@ -76,7 +76,6 @@ DFHACK_PLUGIN("reveal"); DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) { - commands.clear(); commands.push_back(PluginCommand("reveal","Reveal the map. 'reveal hell' will also reveal hell. 'reveal demon' won't pause.",reveal)); commands.push_back(PluginCommand("unreveal","Revert the map to its previous state.",unreveal)); commands.push_back(PluginCommand("revtoggle","Reveal/unreveal depending on state.",revtoggle)); diff --git a/plugins/seedwatch.cpp b/plugins/seedwatch.cpp index f98f9213f..b50eb99d8 100755 --- a/plugins/seedwatch.cpp +++ b/plugins/seedwatch.cpp @@ -243,7 +243,6 @@ DFHACK_PLUGIN("seedwatch"); DFhackCExport command_result plugin_init(color_ostream &out, vector& commands) { - commands.clear(); commands.push_back(PluginCommand("seedwatch", "Switches cookery based on quantity of seeds, to keep reserves", df_seedwatch)); // fill in the abbreviations map, with abbreviations for the standard plants abbreviations["bs"] = "SLIVER_BARB"; diff --git a/plugins/showmood.cpp b/plugins/showmood.cpp index d49477b3f..7407e6af1 100644 --- a/plugins/showmood.cpp +++ b/plugins/showmood.cpp @@ -272,7 +272,6 @@ DFHACK_PLUGIN("showmood"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("showmood", "Shows items needed for current strange mood.", df_showmood)); return CR_OK; } diff --git a/plugins/skeleton/skeleton.cpp b/plugins/skeleton/skeleton.cpp index 3f5c6cd06..293e43c8d 100644 --- a/plugins/skeleton/skeleton.cpp +++ b/plugins/skeleton/skeleton.cpp @@ -29,7 +29,6 @@ DFHACK_PLUGIN("skeleton"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { // Fill the command list with your commands. - commands.clear(); commands.push_back(PluginCommand( "skeleton", "Do nothing, look pretty.", skeleton, false, /* true means that the command can't be used from non-interactive user interface */ diff --git a/plugins/stockpiles.cpp b/plugins/stockpiles.cpp index 4f3192f3e..0cd5d861d 100644 --- a/plugins/stockpiles.cpp +++ b/plugins/stockpiles.cpp @@ -29,7 +29,6 @@ DFHACK_PLUGIN("stockpiles"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); if (world && ui) { commands.push_back( PluginCommand( diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 32d0ba191..2b2bcf2e7 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -497,7 +497,6 @@ DFHACK_PLUGIN("tiletypes"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { tiletypes_hist.load("tiletypes.history"); - commands.clear(); commands.push_back(PluginCommand("tiletypes", "Paint map tiles freely, similar to liquids.", df_tiletypes, true)); return CR_OK; } diff --git a/plugins/tubefill.cpp b/plugins/tubefill.cpp index 93b7abff6..0dd045343 100644 --- a/plugins/tubefill.cpp +++ b/plugins/tubefill.cpp @@ -23,7 +23,6 @@ DFHACK_PLUGIN("tubefill"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("tubefill","Fill in all the adamantine tubes again.",tubefill)); return CR_OK; } diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index f3369c385..d2fef313b 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -41,7 +41,6 @@ DFHACK_PLUGIN("tweak"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "tweak", "Various tweaks for minor bugs.", tweak, false, " tweak clear-missing\n" diff --git a/plugins/vdig.cpp b/plugins/vdig.cpp index 9d96f2fef..607d49387 100644 --- a/plugins/vdig.cpp +++ b/plugins/vdig.cpp @@ -27,7 +27,6 @@ DFHACK_PLUGIN("vdig"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "vdig","Dig a whole vein.",vdig,Gui::cursor_hotkey, " Designates a whole vein under the cursor for digging.\n" diff --git a/plugins/versionosd.cpp b/plugins/versionosd.cpp index c7aa0da8b..714649228 100644 --- a/plugins/versionosd.cpp +++ b/plugins/versionosd.cpp @@ -46,7 +46,6 @@ DFTileSurface* createTile(int x, int y) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand("versionosd", "Toggles displaying version in DF window", df_versionosd)); diff --git a/plugins/weather.cpp b/plugins/weather.cpp index 8bf171748..68eb078ad 100644 --- a/plugins/weather.cpp +++ b/plugins/weather.cpp @@ -19,7 +19,6 @@ DFHACK_PLUGIN("weather"); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { - commands.clear(); commands.push_back(PluginCommand( "weather", "Print the weather map or change weather.", weather, false, diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index 237068b08..fa1d27952 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -59,7 +59,6 @@ DFHACK_PLUGIN("workflow"); DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { - commands.clear(); if (!world || !ui) return CR_FAILURE; From 5f53388890e10f7b1170c3550c45249fe53490e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Mar 2012 19:03:51 +0200 Subject: [PATCH 12/16] Track stonesense --- plugins/stonesense | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/stonesense b/plugins/stonesense index 07ddc8c13..906d6439d 160000 --- a/plugins/stonesense +++ b/plugins/stonesense @@ -1 +1 @@ -Subproject commit 07ddc8c13e0bb38cde77937803e9320e2b26f2d9 +Subproject commit 906d6439d4cb694cf287d63badabb675a8b89329 From adc0a6396def928029bcb3f026d5ea7a67931cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Mar 2012 19:17:04 +0200 Subject: [PATCH 13/16] DERP: missed the readme. --- README.rst | 2 +- Readme.html | 626 ++++++++++++++++++++++++++++++++-------------------- 2 files changed, 391 insertions(+), 237 deletions(-) diff --git a/README.rst b/README.rst index 7f41f82f9..09ac4bdcc 100644 --- a/README.rst +++ b/README.rst @@ -129,7 +129,7 @@ Examples: ``changelayer MARBLE all_biomes all_layers`` Convert all layers of all biomes which are not soil into marble. -.. Notes:: +.. note:: * If you use changelayer and nothing happens, try to pause/unpause the game for a while and try to move the cursor to another tile. Then try again. If that doesn't help try temporarily changing some other layer, undo your changes and try again for the layer you want to change. Saving and reloading your map might also help. * You should be fine if you only change single layers without the use of 'force'. Still it's advisable to save your game before messing with the map. diff --git a/Readme.html b/Readme.html index c8d5011d3..3a857670f 100644 --- a/Readme.html +++ b/Readme.html @@ -318,7 +318,7 @@ ul.auto-toc {
-

Introduction

+

Introduction

DFHack is a Dwarf Fortress memory access library and a set of basic tools that use it. Tools come in the form of plugins or (not yet) external tools. It is an attempt to unite the various ways tools @@ -326,169 +326,188 @@ access DF memory and allow for easier development of new tools.

Contents

-

Getting DFHack

+

Getting DFHack

The project is currently hosted on github, for both source and binaries at http://github.com/peterix/dfhack

Releases can be downloaded from here: https://github.com/peterix/dfhack/downloads

All new releases are announced in the bay12 thread: http://tinyurl.com/dfhack-ng

-

Compatibility

+

Compatibility

DFHack works on Windows XP, Vista, 7 or any modern Linux distribution. OSX is not supported due to lack of developers with a Mac.

Currently, only version 0.34.05 is supported. If you need DFHack @@ -497,7 +516,7 @@ for older versions, look for older releases.

It is possible to use the Windows DFHack under wine/OSX.

-

Installation/Removal

+

Installation/Removal

Installing DFhack involves copying files into your DF folder. Copy the files from a release archive so that:

@@ -517,7 +536,7 @@ Copy the files from a release archive so that:

If any of the plugins or dfhack itself refuses to load, check the stderr.log file created in your DF folder.

-

Using DFHack

+

Using DFHack

DFHack basically extends what DF can do with something similar to the drop-down console found in Quake engine games. On Windows, this is a separate command line window. On linux, the terminal used to launch the dfhack script is taken over (so, make sure you start from a terminal). Basic interaction with dfhack involves entering commands into the console. For some basic instroduction, use the 'help' command. To list all possible commands, use the 'ls' command. Many commands have their own help or detailed description. You can use 'command help' or 'command ?' to show that.

@@ -528,22 +547,22 @@ Many commands have their own help or detailed description. You can use 'command

Most of the commands come from plugins. Those reside in 'hack/plugins/'.

-

Something doesn't work, help!

+

Something doesn't work, help!

First, don't panic :) Second, dfhack keeps a few log files in DF's folder - stderr.log and stdout.log. You can look at those and possibly find out what's happening. If you found a bug, you can either report it in the bay12 DFHack thread, the issues tracker on github, contact me (peterix@gmail.com) or visit the #dfhack IRC channel on freenode.

-

The init file

+

The init file

If your DF folder contains a file named dfhack.init, its contents will be run every time you start DF. This allows setting up keybindings. An example file is provided as dfhack.init-example - you can tweak it and rename to dfhack.init if you want to use this functionality.

-

Commands

+

Commands

Almost all the commands support using the 'help <command-name>' built-in command to retrieve further help without having to look at this document. Alternatively, some accept a 'help'/'?' option on their command line.

-

adv-bodyswap

+

adv-bodyswap

This allows taking control over your followers and other creatures in adventure mode. For example, you can make them pick up new arms and armor and equip them properly.

-

Usage

+

Usage

  • When viewing unit details, body-swaps into that unit.
  • @@ -553,10 +572,10 @@ If you found a bug, you can either report it in the bay12 DFHack thread, the iss
-

advtools

+

advtools

A package of different adventure mode tools (currently just one)

-

Usage

+

Usage

@@ -568,16 +587,143 @@ If you found a bug, you can either report it in the bay12 DFHack thread, the iss
+
+

changelayer

+

Changes material of the geology layer under cursor to the specified inorganic RAW material. Can have impact on all surrounding regions, not only your embark! By default changing stone to soil and vice versa is not allowed. By default changes only the layer at the cursor position. Note that one layer can stretch across lots of z levels. By default changes only the geology which is linked to the biome under the cursor. That geology might be linked to other biomes as well, though. Mineral veins and gem clusters will stay on the map. Use 'changevein' for them. +tl;dr: You will end up with changing quite big areas in one go, especially if you use it in lower z levels. Use with care.

+
+

Options

+ +++ + + + + + + + + + + + +
all_biomes:Change selected layer for all biomes on your map. +Result may be undesirable since the same layer can AND WILL be on different z-levels for different biomes. Use the tool 'probe' to get an idea how layers and biomes are distributed on your map.
all_layers:Change all layers on your map (only for the selected biome unless 'all_biomes' is added). +Candy mountain, anyone? Will make your map quite boring, but tidy.
force:Allow changing stone to soil and vice versa. !!THIS CAN HAVE WEIRD EFFECTS, USE WITH CARE!! +Note that soil will not be magically replaced with stone. You will, however, get a stone floor after digging so it will allow the floor to be engraved. +Note that stone will not be magically replaced with soil. You will, however, get a soil floor after digging so it could be helpful for creating farm plots on maps with no soil.
verbose:Give some details about what is being changed.
trouble:Give some advice about known problems.
+
+
+

Examples:

+
+
changelayer GRANITE
+
Convert layer at cursor position into granite.
+
changelayer SILTY_CLAY force
+
Convert layer at cursor position into clay even if it's stone.
+
changelayer MARBLE all_biomes all_layers
+
Convert all layers of all biomes which are not soil into marble.
+
+
+

Note

+
    +
  • If you use changelayer and nothing happens, try to pause/unpause the game for a while and try to move the cursor to another tile. Then try again. If that doesn't help try temporarily changing some other layer, undo your changes and try again for the layer you want to change. Saving and reloading your map might also help.
  • +
  • You should be fine if you only change single layers without the use of 'force'. Still it's advisable to save your game before messing with the map.
  • +
  • When you force changelayer to convert soil to stone you might experience weird stuff (flashing tiles, tiles changed all over place etc). Try reverting the changes manually or even better use an older savegame. You did save your game, right?
  • +
+
+
+
-

changevein

+

changevein

Changes material of the vein under cursor to the specified inorganic RAW material.

+
+

Example:

+
+
changevein NATIVE_PLATINUM
+
Convert vein at cursor position into platinum ore.
+
+
+
+
+

changeitem

+

Allows changing item material and base quality. By default the item currently selected in the UI will be changed (you can select items in the 'k' list or inside containers/inventory). By default change is only allowed if materials is of the same subtype (for example wood<->wood, stone<->stone etc). But since some transformations work pretty well and may be desired you can override this with 'force'. Note that some attributes will not be touched, possibly resulting in weirdness. To get an idea how the RAW id should look like, check some items with 'info'. Using 'force' might create items which are not touched by crafters/haulers.

+
+

Options

+ +++ + + + + + + + + + + + +
info:Don't change anything, print some info instead.
here:Change all items at the cursor position. Requires in-game curser.
material, m:Change material. Must be followed by valid material RAW id.
quality, q:Change base quality. Must be followed by number (0-5).
force:Ignore subtypes, force change to new material.
+
+
+

Examples:

+
+
changeitem m INORGANIC:GRANITE here
+
Change material of all items under the cursor to granite.
+
changeitem q 5
+
Change currently selected item to masterpiece quality.
+
+
+
+
+

cursecheck

+

Checks a single map tile or the whole map/world for cursed creatures (ghosts, vampires, necromancers, werebeasts, zombies). +With an active in-game cursor only the selected tile will be observed. Without a cursor the whole map will be checked. +By default cursed creatures will be only counted in case you just want to find out if you have any of them running around in your fort. +By default dead and passive creatures (ghosts who were put to rest, killed vampires, ...) are ignored. +Undead skeletons, corpses, bodyparts and the like are all thrown into the curse category "zombie". +Anonymous zombies and resurrected body parts will show as "unnamed creature".

+
+

Options

+ +++ + + + + + + + + + +
detail:Print full name, date of birth, date of curse and some status info (some vampires might use fake identities in-game, though).
nick:Set the type of curse as nickname (does not always show up in-game, some vamps don't like nicknames).
all:Include dead and passive cursed creatures (can result in a quite long list after having FUN with necromancers).
verbose:Print all curse tags (if you really want to know it all).
+
+
+

Examples:

+
+
cursecheck detail all
+
Give detailed info about all cursed creatures including deceased ones (no in-game cursor).
+
cursecheck nick
+
Give a nickname all living/active cursed creatures on the map(no in-game cursor).
+
+
+

Note

+
    +
  • If you do a full search (with the option "all") former ghosts will show up with the cursetype "unknown" because their ghostly flag is not set anymore. But if you happen to find a living/active creature with cursetype "unknown" please report that in the dfhack thread on the modding forum or per irc. This is likely to happen with mods which introduce new types of curses, for example.
  • +
+
+
-

follow

+

follow

Makes the game view follow the currently highlighted unit after you exit from current menu/cursor mode. Handy for watching dwarves running around. Deactivated by moving the view manually.

-

forcepause

+

forcepause

Forces DF to pause. This is useful when your FPS drops below 1 and you lose control of the game.

    @@ -587,23 +733,23 @@ If you found a bug, you can either report it in the bay12 DFHack thread, the iss
-

nopause

+

nopause

Disables pausing (both manual and automatic) with the exception of pause forced by 'reveal hell'. This is nice for digging under rivers.

-

die

+

die

Instantly kills DF without saving.

-

autodump

+

autodump

This utility lets you quickly move all items designated to be dumped. Items are instantly moved to the cursor position, the dump flag is unset, and the forbid flag is set, as if it had been dumped normally. Be aware that any active dump item tasks still point at the item.

Cursor must be placed on a floor tile so the items can be dumped there.

-
-

Options

+
+

Options

@@ -623,20 +769,20 @@ Be aware that any active dump item tasks still point at the item.

-

autodump-destroy-here

+

autodump-destroy-here

Destroy items marked for dumping under cursor. Identical to autodump destroy-here, but intended for use as keybinding.

-

autodump-destroy-item

+

autodump-destroy-item

Destroy the selected item. The item may be selected in the 'k' list, or inside a container. If called again before the game is resumed, cancels destroy.

-

clean

+

clean

Cleans all the splatter that get scattered all over the map, items and creatures. In an old fortress, this can significantly reduce FPS lag. It can also spoil your !!FUN!!, so think before you use it.

-
@@ -651,7 +797,7 @@ In an old fortress, this can significantly reduce FPS lag. It can also spoil you
-

Extra options for 'map'

+

Extra options for 'map'

@@ -665,15 +811,15 @@ In an old fortress, this can significantly reduce FPS lag. It can also spoil you
-

spotclean

+

spotclean

Works like 'clean map snow mud', but only for the tile under the cursor. Ideal if you want to keep that bloody entrance 'clean map' would clean up.

-

cleanowned

+

cleanowned

Confiscates items owned by dwarfs. By default, owned food on the floor and rotten items are confistacted and dumped.

-
@@ -691,16 +837,16 @@ By default, owned food on the floor and rotten items are confistacted and dumped
-
-

Example:

+
+

Example:

cleanowned scattered X : This will confiscate rotten and dropped food, garbage on the floors and any worn items with 'X' damage and above.

-

colonies

+

colonies

Allows listing all the vermin colonies on the map and optionally turning them into honey bee colonies.

-
-

Options

+
+

Options

@@ -712,12 +858,12 @@ By default, owned food on the floor and rotten items are confistacted and dumped
-

deramp (by zilpin)

+

deramp (by zilpin)

Removes all ramps designated for removal from the map. This is useful for replicating the old channel digging designation. It also removes any and all 'down ramps' that can remain after a cave-in (you don't have to designate anything for that to happen).

-

df2minecraft

+

df2minecraft

This generates a minecraft world out of the currently loaded fortress. Generated worlds are placed into your DF folder, named "World #".

@@ -731,11 +877,11 @@ Generated worlds are placed into your DF folder, named "World #".

-

dfusion

+

dfusion

This is the DFusion lua plugin system by warmist/darius, running as a DFHack plugin.

See the bay12 thread for details: http://www.bay12forums.com/smf/index.php?topic=69682.15

@@ -755,11 +901,11 @@ Generated worlds are placed into your DF folder, named "World #".

-

drybuckets

+

drybuckets

This utility removes water from all buckets in your fortress, allowing them to be safely used for making lye.

-

fastdwarf

+

fastdwarf

Makes your minions move at ludicrous speeds.

    @@ -769,14 +915,14 @@ Generated worlds are placed into your DF folder, named "World #".

-

feature

+

feature

Enables management of map features.

  • Discovering a magma feature (magma pool, volcano, magma sea, or curious underground structure) permits magma workshops and furnaces to be built.
  • Discovering a cavern layer causes plants (trees, shrubs, and grass) from that cavern to grow within your fortress.
-
@@ -792,10 +938,10 @@ Generated worlds are placed into your DF folder, named "World #".

-

filltraffic

+

filltraffic

Set traffic designations using flood-fill starting at the cursor.

@@ -812,7 +958,7 @@ Generated worlds are placed into your DF folder, named "World #".

-

Other Options:

+

Other Options:

@@ -826,16 +972,16 @@ Generated worlds are placed into your DF folder, named "World #".

-
-

Example:

+
+

Example:

'filltraffic H' - When used in a room with doors, it will set traffic to HIGH in just that room.

-

alltraffic

+

alltraffic

Set traffic designations for every single tile of the map (useful for resetting traffic designations).

-
-

Traffic Type Codes:

+
+

Traffic Type Codes:

@@ -851,36 +997,36 @@ Generated worlds are placed into your DF folder, named "World #".

-
-

Example:

+
+

Example:

'alltraffic N' - Set traffic to 'normal' for all tiles.

-

fixdiplomats

+

fixdiplomats

Up to version 0.31.12, Elves only sent Diplomats to your fortress to propose tree cutting quotas due to a bug; once that bug was fixed, Elves stopped caring about excess tree cutting. This command adds a Diplomat position to all Elven civilizations, allowing them to negotiate tree cutting quotas (and allowing you to violate them and potentially start wars) in case you haven't already modified your raws accordingly.

-

fixmerchants

+

fixmerchants

This command adds the Guild Representative position to all Human civilizations, allowing them to make trade agreements (just as they did back in 0.28.181.40d and earlier) in case you haven't already modified your raws accordingly.

-

fixveins

+

fixveins

Removes invalid references to mineral inclusions and restores missing ones. Use this if you broke your embark with tools like tiletypes, or if you accidentally placed a construction on top of a valuable mineral floor.

-

fixwagons

+

fixwagons

Due to a bug in all releases of version 0.31, merchants no longer bring wagons with their caravans. This command re-enables them for all appropriate civilizations.

-

flows

+

flows

A tool for checking how many tiles contain flowing liquids. If you suspect that your magma sea leaks into HFS, you can use this tool to be sure without revealing the map.

-

getplants

+

getplants

This tool allows plant gathering and tree cutting by RAW ID. Specify the types of trees to cut down and/or shrubs to gather by their plant names, separated by spaces.

-
-

Options

+
+

Options

@@ -899,15 +1045,15 @@ Generated worlds are placed into your DF folder, named "World #".

-

tidlers

+

tidlers

Toggle between all possible positions where the idlers count can be placed.

-

twaterlvl

+

twaterlvl

Toggle between displaying/not displaying liquid depth as numbers.

-

job

+

job

Command for general job query and manipulation.

Options:
@@ -921,7 +1067,7 @@ Generated worlds are placed into your DF folder, named "World #".

-

job-material

+

job-material

Alter the material of the selected job. Invoked as: job-material <inorganic-token>

Intended to be used as a keybinding:
@@ -933,7 +1079,7 @@ Generated worlds are placed into your DF folder, named "World #".

-

job-duplicate

+

job-duplicate

Duplicate the selected job in a workshop:
    @@ -943,10 +1089,10 @@ Generated worlds are placed into your DF folder, named "World #".

-

keybinding

+

keybinding

Manages DFHack keybindings. Currently it supports any combination of Ctrl/Alt/Shift with F1-F9, or A-Z.

-
@@ -969,8 +1115,8 @@ Generated worlds are placed into your DF folder, named "World #".

-

liquids

-

Allows adding magma, water and obsidian to the game. It replaces the normal dfhack command line and can't be used from a hotkey. +

liquids

+

Allows adding magma, water and obsidian to the game. It replaces the normal dfhack command line and can't be used from a hotkey. Settings will be remembered as long as dfhack runs. Intended for use in combination with the command liquids-here (which can be bound to a hotkey). For more information, refer to the command's internal help.

Note

@@ -978,8 +1124,13 @@ For more information, refer to the command's internal help.

temperatures (creating heat traps). You've been warned.

+
+

liquids-here

+

Run the liquid spawner with the current/last settings made in liquids (if no settings in liquids were made it paints a point of 7/7 magma by default). +Intended to be used as keybinding. Requires an active in-game cursor.

+
-

mode

+

mode

This command lets you see and change the game mode directly. Not all combinations are good for every situation and most of them will produce undesirable results. There are a few good ones though.

@@ -991,11 +1142,11 @@ You just lost a fortress and gained an adventurer.

I take no responsibility of anything that happens as a result of using this tool :P

-

extirpate

+

extirpate

A tool for getting rid of trees and shrubs. By default, it only kills a tree/shrub under the cursor. The plants are turned into ashes instantly.

-
@@ -1011,22 +1162,22 @@ The plants are turned into ashes instantly.

-

grow

+

grow

Makes all saplings present on the map grow into trees (almost) instantly.

-

immolate

+

immolate

Very similar to extirpate, but additionally sets the plants on fire. The fires can and will spread ;)

-

probe

+

probe

Can be used to determine tile properties like temperature.

-

prospect

+

prospect

Prints a big list of all the present minerals and plants. By default, only the visible part of the map is scanned.

-
@@ -1041,13 +1192,13 @@ The plants are turned into ashes instantly.

-

Pre-embark estimate

+

Pre-embark estimate

If called during the embark selection screen, displays an estimate of layer stone availability. If the 'all' option is specified, also estimates veins. The estimate is computed either for 1 embark tile of the blinking biome, or for all tiles of the embark rectangle.

-
-

Options

+
+

Options

@@ -1059,14 +1210,14 @@ for 1 embark tile of the blinking biome, or for all tiles of the embark rectangl
-

regrass

+

regrass

Regrows all surface grass, restoring outdoor plant growth for pre-0.31.19 worlds.

-

rename

+

rename

Allows renaming various things.

-
@@ -1088,32 +1239,32 @@ for 1 embark tile of the blinking biome, or for all tiles of the embark rectangl
-

reveal

+

reveal

This reveals the map. By default, HFS will remain hidden so that the demons don't spawn. You can use 'reveal hell' to reveal everything. With hell revealed, you won't be able to unpause until you hide the map again. If you really want to unpause with hell revealed, use 'reveal demons'.

Reveal also works in adventure mode, but any of its effects are negated once you move. When you use it this way, you don't need to run 'unreveal'.

-

unreveal

+

unreveal

Reverts the effects of 'reveal'.

-

revtoggle

+

revtoggle

Switches between 'reveal' and 'unreveal'.

-

revflood

+

revflood

This command will hide the whole map and then reveal all the tiles that have a path to the in-game cursor.

-

revforget

+

revforget

When you use reveal, it saves information about what was/wasn't visible before revealing everything. Unreveal uses this information to hide things again. This command throws away the information. For example, use in cases where you abandoned with the fort revealed and no longer want the data.

-

lair

+

lair

This command allows you to mark the map as 'monster lair', preventing item scatter on abandon. When invoked as 'lair reset', it does the opposite.

Unlike reveal, this command doesn't save the information about tiles - you won't be able to restore state of real monster lairs using 'lair reset'.

-
@@ -1127,20 +1278,20 @@ for 1 embark tile of the blinking biome, or for all tiles of the embark rectangl
-

seedwatch

+

seedwatch

Tool for turning cooking of seeds and plants on/off depending on how much you have of them.

See 'seedwatch help' for detailed description.

-

showmood

+

showmood

Shows all items needed for the currently active strange mood.

-

copystock

+

copystock

Copies the parameters of the currently highlighted stockpile to the custom stockpile settings and switches to custom stockpile placement mode, effectively allowing you to copy/paste stockpiles easily.

-

ssense / stonesense

+

ssense / stonesense

An isometric visualizer that runs in a second window. This requires working graphics acceleration and at least a dual core CPU (otherwise it will slow down DF).

All the data resides in the 'stonesense' directory. For detailed instructions, see stonesense/README.txt

Compatible with Windows > XP SP3 and most modern Linux distributions.

@@ -1150,17 +1301,17 @@ for 1 embark tile of the blinking biome, or for all tiles of the embark rectangl http://df.magmawiki.com/index.php/Utility:Stonesense/Content_repository

-

tiletypes

+

tiletypes

Can be used for painting map tiles and is a interactive command, much like liquids. You can paint tiles by their properties - shape, general material and a few others (paint). You can also paint only over tiles that match a set of properties (filter)

For more details, see the 'help' command while using this.

-

tweak

+

tweak

Contains various tweaks for minor bugs (currently just one).

-
@@ -1168,29 +1319,32 @@ You can also paint only over tiles that match a set of properties (filter)

+ + +
tweak clear-missing:
 Remove the missing status from the selected unit. This allows engraving slabs for ghostly, but not yet found, creatures.
tweak clear-ghostly:
 Remove the ghostly status from the selected unit and mark it as dead. This allows getting rid of bugged ghosts which do not show up in the engraving slab menu at all, even after using clear-missing. It works, but is potentially very dangerous - so use with care. Probably (almost certainly) it does not have the same effects like a proper burial. You've been warned.
-

tubefill

+

tubefill

Fills all the adamantine veins again. Veins that were empty will be filled in too, but might still trigger a demon invasion (this is a known bug).

-

vdig

+

vdig

Designates a whole vein for digging. Requires an active in-game cursor placed over a vein tile. With the 'x' option, it will traverse z-levels (putting stairs between the same-material tiles).

-

vdigx

+

vdigx

A permanent alias for 'vdig x'.

-

expdig

+

expdig

This command can be used for exploratory mining.

See: http://df.magmawiki.com/index.php/DF2010:Exploratory_mining

There are two variables that can be set: pattern and filter.

-

Patterns:

+

Patterns:

@@ -1211,7 +1365,7 @@ You can also paint only over tiles that match a set of properties (filter)

-

Filters:

+

Filters:

@@ -1226,8 +1380,8 @@ You can also paint only over tiles that match a set of properties (filter)

After you have a pattern set, you can use 'expdig' to apply it again.

-
-

Examples:

+
+

Examples:

designate the diagonal 5 patter over all hidden tiles:
    @@ -1248,11 +1402,11 @@ You can also paint only over tiles that match a set of properties (filter)

-

digcircle

+

digcircle

A command for easy designation of filled and hollow circles. It has several types of options.

-

Shape:

+

Shape:

@@ -1267,7 +1421,7 @@ It has several types of options.

-

Action:

+

Action:

@@ -1282,7 +1436,7 @@ It has several types of options.

-

Designation types:

+

Designation types:

@@ -1304,8 +1458,8 @@ It has several types of options.

After you have set the options, the command called with no options repeats with the last selected parameters.

-
-

Examples:

+
+

Examples:

  • 'digcircle filled 3' = Dig a filled circle with radius = 3.
  • 'digcircle' = Do it again.
  • @@ -1313,11 +1467,11 @@ repeats with the last selected parameters.

-

weather

+

weather

Prints the current weather map by default.

Also lets you change the current weather to 'clear sky', 'rainy' or 'snowing'.

-
@@ -1333,10 +1487,10 @@ repeats with the last selected parameters.

-

workflow

+

workflow

Manage control of repeat jobs.

-
-

Usage

+
+

Usage

workflow enable [option...], workflow disable [option...]

If no options are specified, enables or disables the plugin. @@ -1357,7 +1511,7 @@ Otherwise, enables or disables any of the following options:

-

Function

+

Function

When the plugin is enabled, it protects all repeat jobs from removal. If they do disappear due to any cause, they are immediately re-added to their workshop and suspended.

@@ -1368,7 +1522,7 @@ the amount has to drop before jobs are resumed; this is intended to reduce the frequency of jobs being toggled.

-

Constraint examples

+

Constraint examples

Keep metal bolts within 900-1000, and wood/bone within 150-200.

 workflow amount AMMO:ITEM_AMMO_BOLTS/METAL 1000 100
@@ -1405,11 +1559,11 @@ the Mill Plants job to MUSHROOM_CUP_DIMPLE using the 'job item-material' command
 
-

mapexport

+

mapexport

Export the current loaded map as a file. This will be eventually usable with visualizers.

-

dwarfexport

+

dwarfexport

Export dwarves to RuneSmith-compatible XML.

From b847a026e3d3069e677872aa62bcd71ce0f6dd42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Mar 2012 19:17:48 +0200 Subject: [PATCH 14/16] Increment revision due to DERP. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5179c2b4..28b4d0645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ set(DF_VERSION_MINOR "34") set(DF_VERSION_PATCH "06") set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}") -set(DFHACK_RELEASE "1") +set(DFHACK_RELEASE "2") set(DFHACK_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}-r${DFHACK_RELEASE}") add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}") From 69b1bbe59ea1a3969a2623ba2d32b9455762307a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Mar 2012 20:00:26 +0200 Subject: [PATCH 15/16] Turn sorting lambdas into functors in autolabor. --- plugins/autolabor.cpp | 56 ++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index 26c4cb8b4..eee10e3eb 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -384,7 +384,7 @@ static const df::job_skill noble_skills[] = { df::enums::job_skill::RECORD_KEEPING, }; -struct dwarf_info +struct dwarf_info_t { int highest_skill; int total_skill; @@ -432,6 +432,38 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) return CR_OK; } +// sorting objects +struct dwarfinfo_sorter +{ + dwarfinfo_sorter(std::vector & info):dwarf_info(info){}; + bool operator() (int i,int j) + { + if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE) + return true; + if (dwarf_info[i].state != IDLE && dwarf_info[j].state == IDLE) + return false; + return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty; + }; + std::vector & dwarf_info; +}; +struct laborinfo_sorter +{ + bool operator() (int i,int j) + { + return labor_infos[i].mode < labor_infos[j].mode; + }; +}; + +struct values_sorter +{ + values_sorter(std::vector & values):values(values){}; + bool operator() (int i,int j) + { + return values[i] > values[j]; + }; + std::vector & values; +}; + DFhackCExport command_result plugin_onupdate ( color_ostream &out ) { static int step_count = 0; @@ -478,7 +510,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (n_dwarfs == 0) return CR_OK; - std::vector dwarf_info(n_dwarfs); + std::vector dwarf_info(n_dwarfs); std::vector best_noble(ARRAY_COUNT(noble_skills)); std::vector highest_noble_skill(ARRAY_COUNT(noble_skills)); @@ -643,8 +675,8 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) labors.push_back(labor); } - - std::sort(labors.begin(), labors.end(), [] (int i, int j) { return labor_infos[i].mode < labor_infos[j].mode; }); + laborinfo_sorter lasorter; + std::sort(labors.begin(), labors.end(), lasorter); // Handle all skills except those marked HAULERS @@ -734,7 +766,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) } if (labor_infos[labor].mode != EVERYONE) - std::sort(candidates.begin(), candidates.end(), [&values] (int i, int j) { return values[i] > values[j]; }); + { + values_sorter ivs(values); + std::sort(candidates.begin(), candidates.end(), ivs); + } for (int dwarf = 0; dwarf < n_dwarfs; dwarf++) { @@ -815,16 +850,9 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY) hauler_ids.push_back(dwarf); } - + dwarfinfo_sorter sorter(dwarf_info); // Idle dwarves come first, then we sort from least-skilled to most-skilled. - std::sort(hauler_ids.begin(), hauler_ids.end(), [&dwarf_info] (int i, int j) -> bool - { - if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE) - return true; - if (dwarf_info[i].state != IDLE && dwarf_info[j].state == IDLE) - return false; - return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty; - }); + std::sort(hauler_ids.begin(), hauler_ids.end(), sorter); // don't set any haulers if everyone is off drinking or something if (hauler_ids.size() == 0) { From 0c2c94fa92f27290fc499f4542179ed9a0f2a7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 29 Mar 2012 20:18:14 +0200 Subject: [PATCH 16/16] Remove random bad asserts --- plugins/autolabor.cpp | 12 ++++++++++++ plugins/mode.cpp | 3 ++- plugins/tiletypes.cpp | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index eee10e3eb..60a574ce2 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -590,8 +590,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (labor == df::enums::unit_labor::NONE) continue; + /* assert(labor >= 0); assert(labor < ARRAY_COUNT(labor_infos)); + */ if (labor_infos[labor].is_exclusive && dwarfs[dwarf]->status.labors[labor]) dwarf_info[dwarf].mastery_penalty -= 100; @@ -636,8 +638,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) { int job = dwarfs[dwarf]->job.current_job->job_type; + /* assert(job >= 0); assert(job < ARRAY_COUNT(dwarf_states)); + */ dwarf_info[dwarf].state = dwarf_states[job]; } @@ -656,8 +660,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) int labor = ENUM_ATTR(job_skill, labor, skill); if (labor != df::enums::unit_labor::NONE) { + /* assert(labor >= 0); assert(labor < ARRAY_COUNT(labor_to_skill)); + */ labor_to_skill[labor] = skill; } @@ -670,8 +676,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (labor == df::enums::unit_labor::NONE) continue; + /* assert(labor >= 0); assert(labor < ARRAY_COUNT(labor_infos)); + */ labors.push_back(labor); } @@ -684,8 +692,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) { auto labor = *lp; + /* assert(labor >= 0); assert(labor < ARRAY_COUNT(labor_infos)); + */ df::job_skill skill = labor_to_skill[labor]; @@ -864,8 +874,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if (labor == df::enums::unit_labor::NONE) continue; + /* assert(labor >= 0); assert(labor < ARRAY_COUNT(labor_infos)); + */ if (labor_infos[labor].mode != HAULERS) continue; diff --git a/plugins/mode.cpp b/plugins/mode.cpp index d87fd5392..33dd5875f 100644 --- a/plugins/mode.cpp +++ b/plugins/mode.cpp @@ -95,7 +95,8 @@ void printCurrentModes(t_gamemodes gm, Console & con) command_result mode (color_ostream &out_, vector & parameters) { - assert(out_.is_console()); + if(!out_.is_console()) + return CR_FAILURE; Console &out = static_cast(out_); string command = ""; diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 2b2bcf2e7..61b4ec8e7 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -524,7 +524,8 @@ command_result df_tiletypes (color_ostream &out, vector & parameters) } } - assert(out.is_console()); + if(!out.is_console()) + return CR_FAILURE; Console &con = static_cast(out); TileType filter, paint;