From cc02ced0ac854ce60d3320b426af4fa9b97d5629 Mon Sep 17 00:00:00 2001 From: Quietust Date: Sat, 21 Jan 2017 15:16:06 -0600 Subject: [PATCH 01/43] Fix RTTI in Win64 - offsets are relative to the current module (e.g. the DLL), so it needs to be looked up explicitly --- library/Process-windows.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp index cb2e16bd2..3a1da0ac4 100644 --- a/library/Process-windows.cpp +++ b/library/Process-windows.cpp @@ -342,12 +342,14 @@ int Process::adjustOffset(int offset, bool to_file) return -1; } - string Process::doReadClassName (void * vptr) { char * rtti = readPtr((char *)vptr - sizeof(void*)); #ifdef DFHACK64 - char * typeinfo = d->base + readDWord(rtti + 0xC); + void *base; + if (!RtlPcToFileHeader(rtti, &base)) + return "dummy"; + char * typeinfo = (char *)base + readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0x10+4); // skips the .?AV #else char * typeinfo = readPtr(rtti + 0xC); From c659b885b6ab5d6e71a0e5650b7882f99066445e Mon Sep 17 00:00:00 2001 From: Japa Date: Wed, 25 Jan 2017 23:06:03 +0530 Subject: [PATCH 02/43] Start a plugin to rename generated creatures to have sensible IDs --- plugins/CMakeLists.txt | 1 + plugins/generated-creature-renamer.cpp | 79 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 plugins/generated-creature-renamer.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4611009c3..6b1f80634 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -122,6 +122,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(follow follow.cpp) DFHACK_PLUGIN(forceequip forceequip.cpp) DFHACK_PLUGIN(fortplan fortplan.cpp LINK_LIBRARIES buildingplan-lib) + DFHACK_PLUGIN(generated-creature-renamer generated-creature-renamer.cpp) DFHACK_PLUGIN(getplants getplants.cpp) DFHACK_PLUGIN(hotkeys hotkeys.cpp) DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp new file mode 100644 index 000000000..8c2fe20ef --- /dev/null +++ b/plugins/generated-creature-renamer.cpp @@ -0,0 +1,79 @@ +#include "Console.h" +#include "Core.h" +#include "DataDefs.h" +#include "Export.h" +#include "PluginManager.h" +#include "df/world.h" +#include "df/world_raws.h" +#include "df/creature_raw.h" +#include "df/caste_raw.h" + +//#include "df/world.h" + +using namespace DFHack; + +DFHACK_PLUGIN("rename_creatures"); +REQUIRE_GLOBAL(world); + +command_result rename_creatures (color_ostream &out, std::vector & parameters); + +DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) +{ + commands.push_back(PluginCommand( + "rename_creatures", + "Renames generated creature tags to something friendlier to modders", + rename_creatures, + false, //allow non-interactive use + "longHelpString" + )); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown (color_ostream &out) +{ + return CR_OK; +} + +std::string descriptors[] = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", +"damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", +"mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", +"ladybug", "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", +"dung beetle", "rhinoceros beetle", "rove beetle", "snakefly", "lacewing", "antlion larva", +"mosquito", "flea", "scorpionfly", "caddisfly", "butterfly", "moth", "caterpillar", "maggot", +"spider", "tarantula", "scorpion", "tick", "mite", "shrimp", "lobster", "crab", "nematode", +"snail", "slug", "earthworm", "leech", "bristleworm", "ribbon worm", "flat worm", "toad", "frog", +"salamander", "newt", "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", +"gila monster", "monitor", "serpent", "viper", "rattlesnake", "cobra", "python", "anaconda", "turtle", +"tortoise", "pterosaur", "dimetrodon", "sauropod", "theropod", "iguanodont", "hadrosaurid", "stegosaurid", +"ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", "quail", "pheasant", +"gull", "loon", "grebe", "albatross", "petrel", "penguin", "pelican", "stork", "vulture", "flamingo", +"falcon", "kestrel", "condor", "osprey", "buzzard", "eagle", "harrier", "kite", "crane", "dove", +"pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", +"hornbill", "quetzal", "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", +"fantail", "shrike", "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", +"warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", "tanager", +"cardinal", "bunting", "finch", "titmouse", "chickadee", "waxwing", "flycatcher", "opossum", "koala", +"wombat", "kangaroo", "sloth", "anteater", "armadillo", "squirrel", "marmot", "beaver", "gopher", +"mouse", "porcupine", "chinchilla", "cavy", "capybara", "rabbit", "hare", "lemur", "loris", "monkey", +"hedgehog", "shrew", "mole", "fruit bat", "wolf", "coyote", "jackal", "raccoon", "coati", +"weasel", "otter", "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", +"walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", "warthog", +"hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", +"bison", "buffalo", "bull" }; + +command_result rename_creatures (color_ostream &out, std::vector & parameters) +{ + if (!parameters.empty()) + return CR_WRONG_USAGE; + CoreSuspender suspend; + for (int i = 0; i < world->raws.creatures.all.size(); i++) + { + auto creatureRaw = world->raws.creatures.all[i]; + if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) + continue; + out.print(creatureRaw->creature_id.c_str()); + out.print(creatureRaw->caste[0]->description.c_str()); + } + return CR_OK; +} + From 934d5b32bce6f880d9e3ff4b2f1bbc134421c5bb Mon Sep 17 00:00:00 2001 From: Japa Date: Thu, 26 Jan 2017 10:00:38 +0530 Subject: [PATCH 03/43] Fix creature listing and plugin name --- plugins/generated-creature-renamer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 8c2fe20ef..81816d061 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -12,7 +12,7 @@ using namespace DFHack; -DFHACK_PLUGIN("rename_creatures"); +DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); command_result rename_creatures (color_ostream &out, std::vector & parameters); @@ -72,7 +72,9 @@ command_result rename_creatures (color_ostream &out, std::vector & if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) continue; out.print(creatureRaw->creature_id.c_str()); + out.print("\n"); out.print(creatureRaw->caste[0]->description.c_str()); + out.print("\n"); } return CR_OK; } From 365624453e3ee0f6b9e953ff15a523fe902a900f Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Thu, 26 Jan 2017 12:45:40 +0530 Subject: [PATCH 04/43] Finish up the generated-creature-renamer plugin. --- plugins/generated-creature-renamer.cpp | 93 +++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 11 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 81816d061..c6c7cdfec 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -7,6 +7,7 @@ #include "df/world_raws.h" #include "df/creature_raw.h" #include "df/caste_raw.h" +#include "modules/World.h" //#include "df/world.h" @@ -15,26 +16,34 @@ using namespace DFHack; DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); -command_result rename_creatures (color_ostream &out, std::vector & parameters); +command_result rename_creatures(color_ostream &out, std::vector & parameters); +command_result list_creatures(color_ostream &out, std::vector & parameters); -DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) +DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( - "rename_creatures", + "rename-generated", "Renames generated creature tags to something friendlier to modders", rename_creatures, false, //allow non-interactive use - "longHelpString" + "Renames generated creature tags to something friendlier to modders" + )); + commands.push_back(PluginCommand( + "list-generated", + "Prints a list of generated creature tokens. Use \"list-generated detailed\" to show descriptions.", + list_creatures, + false, //allow non-interactive use + "Prints a list of generated creature tokens. Use \"list-generated detailed\" to show descriptions." )); return CR_OK; } -DFhackCExport command_result plugin_shutdown (color_ostream &out) +DFhackCExport command_result plugin_shutdown(color_ostream &out) { return CR_OK; } -std::string descriptors[] = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", +std::string descriptors[221] = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", "damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", "mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", "ladybug", "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", @@ -48,7 +57,7 @@ std::string descriptors[] = { "blob", "quadruped", "humanoid", "silverfish", "ma "ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", "quail", "pheasant", "gull", "loon", "grebe", "albatross", "petrel", "penguin", "pelican", "stork", "vulture", "flamingo", "falcon", "kestrel", "condor", "osprey", "buzzard", "eagle", "harrier", "kite", "crane", "dove", -"pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", +"pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", "hornbill", "quetzal", "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", "fantail", "shrike", "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", "warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", "tanager", @@ -61,21 +70,83 @@ std::string descriptors[] = { "blob", "quadruped", "humanoid", "silverfish", "ma "hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", "bison", "buffalo", "bull" }; -command_result rename_creatures (color_ostream &out, std::vector & parameters) +command_result rename_creatures(color_ostream &out, std::vector & parameters) { if (!parameters.empty()) return CR_WRONG_USAGE; CoreSuspender suspend; + + int descriptorCount[221] = { 0 }; + + if (World::GetPersistentData("AlreadyRenamedCreatures").isValid()) + { + return CR_OK; + } + + for (int i = 0; i < world->raws.creatures.all.size(); i++) + { + auto creatureRaw = world->raws.creatures.all[i]; + if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) + continue; + size_t minPos = std::string::npos; + size_t foundIndex = std::string::npos; + + for (size_t j = 0; j < 221; j++) + { + size_t pos = creatureRaw->caste[0]->description.find(descriptors[j]); + if (pos < minPos) + { + minPos = pos; + foundIndex = j; + } + } + + if (foundIndex < std::string::npos) + { + size_t digitPos = creatureRaw->creature_id.find_first_of("0123456789"); + if (digitPos > creatureRaw->creature_id.length()) + digitPos = creatureRaw->creature_id.length(); + + creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex]); + + if (descriptorCount[foundIndex] > 0) + { + creatureRaw->creature_id.append(std::to_string(descriptorCount[foundIndex])); + } + + descriptorCount[foundIndex]++; + } + } + World::AddPersistentData("AlreadyRenamedCreatures"); + + return CR_OK; +} + +command_result list_creatures(color_ostream &out, std::vector & parameters) +{ + bool detailed = false; + if (!parameters.empty()) + { + if (parameters.size() > 1) + return CR_WRONG_USAGE; + if(parameters[0].compare("detailed") != 0) + return CR_WRONG_USAGE; + detailed = true; + } + + CoreSuspender suspend; for (int i = 0; i < world->raws.creatures.all.size(); i++) { auto creatureRaw = world->raws.creatures.all[i]; if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) continue; out.print(creatureRaw->creature_id.c_str()); - out.print("\n"); - out.print(creatureRaw->caste[0]->description.c_str()); + if (detailed) + { + out.print("\t"); + out.print(creatureRaw->caste[0]->description.c_str()); + } out.print("\n"); } - return CR_OK; } From 24a653f77be87aa83a8efece28245e282c7b73a8 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Thu, 26 Jan 2017 12:50:37 +0530 Subject: [PATCH 05/43] added ants and apes to the list. --- plugins/generated-creature-renamer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index c6c7cdfec..20e861c83 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -43,7 +43,8 @@ DFhackCExport command_result plugin_shutdown(color_ostream &out) return CR_OK; } -std::string descriptors[221] = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", +#define NUM_DESC 223 +std::string descriptors[NUM_DESC] = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", "damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", "mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", "ladybug", "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", @@ -68,7 +69,7 @@ std::string descriptors[221] = { "blob", "quadruped", "humanoid", "silverfish", "weasel", "otter", "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", "walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", "warthog", "hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", -"bison", "buffalo", "bull" }; +"bison", "buffalo", "bull", "ape", "ant" }; command_result rename_creatures(color_ostream &out, std::vector & parameters) { @@ -76,7 +77,7 @@ command_result rename_creatures(color_ostream &out, std::vector & return CR_WRONG_USAGE; CoreSuspender suspend; - int descriptorCount[221] = { 0 }; + int descriptorCount[NUM_DESC] = { 0 }; if (World::GetPersistentData("AlreadyRenamedCreatures").isValid()) { @@ -91,7 +92,7 @@ command_result rename_creatures(color_ostream &out, std::vector & size_t minPos = std::string::npos; size_t foundIndex = std::string::npos; - for (size_t j = 0; j < 221; j++) + for (size_t j = 0; j < NUM_DESC; j++) { size_t pos = creatureRaw->caste[0]->description.find(descriptors[j]); if (pos < minPos) From c3c3f37b0660d301a6008d85ef3a6db9247b2030 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Thu, 26 Jan 2017 15:58:43 +0530 Subject: [PATCH 06/43] Added more descriptor types, and made it run on world load. --- dfhack.init-example | 3 + plugins/generated-creature-renamer.cpp | 144 +++++++++++++------------ 2 files changed, 78 insertions(+), 69 deletions(-) diff --git a/dfhack.init-example b/dfhack.init-example index 169d40046..a0dd220e1 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -233,6 +233,9 @@ enable \ # enable mouse controls and sand indicator in embark screen embark-tools enable sticky sand mouse +# Renames generated creatures to reflect the template used to generate them. +enable generated-creature-renamer + ########### # Scripts # ########### diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 20e861c83..1a738cce4 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -16,18 +16,10 @@ using namespace DFHack; DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); -command_result rename_creatures(color_ostream &out, std::vector & parameters); command_result list_creatures(color_ostream &out, std::vector & parameters); DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { - commands.push_back(PluginCommand( - "rename-generated", - "Renames generated creature tags to something friendlier to modders", - rename_creatures, - false, //allow non-interactive use - "Renames generated creature tags to something friendlier to modders" - )); commands.push_back(PluginCommand( "list-generated", "Prints a list of generated creature tokens. Use \"list-generated detailed\" to show descriptions.", @@ -43,82 +35,96 @@ DFhackCExport command_result plugin_shutdown(color_ostream &out) return CR_OK; } -#define NUM_DESC 223 -std::string descriptors[NUM_DESC] = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", -"damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", -"mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", -"ladybug", "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", -"dung beetle", "rhinoceros beetle", "rove beetle", "snakefly", "lacewing", "antlion larva", -"mosquito", "flea", "scorpionfly", "caddisfly", "butterfly", "moth", "caterpillar", "maggot", -"spider", "tarantula", "scorpion", "tick", "mite", "shrimp", "lobster", "crab", "nematode", -"snail", "slug", "earthworm", "leech", "bristleworm", "ribbon worm", "flat worm", "toad", "frog", -"salamander", "newt", "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", -"gila monster", "monitor", "serpent", "viper", "rattlesnake", "cobra", "python", "anaconda", "turtle", -"tortoise", "pterosaur", "dimetrodon", "sauropod", "theropod", "iguanodont", "hadrosaurid", "stegosaurid", -"ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", "quail", "pheasant", -"gull", "loon", "grebe", "albatross", "petrel", "penguin", "pelican", "stork", "vulture", "flamingo", -"falcon", "kestrel", "condor", "osprey", "buzzard", "eagle", "harrier", "kite", "crane", "dove", -"pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", -"hornbill", "quetzal", "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", -"fantail", "shrike", "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", -"warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", "tanager", -"cardinal", "bunting", "finch", "titmouse", "chickadee", "waxwing", "flycatcher", "opossum", "koala", -"wombat", "kangaroo", "sloth", "anteater", "armadillo", "squirrel", "marmot", "beaver", "gopher", -"mouse", "porcupine", "chinchilla", "cavy", "capybara", "rabbit", "hare", "lemur", "loris", "monkey", -"hedgehog", "shrew", "mole", "fruit bat", "wolf", "coyote", "jackal", "raccoon", "coati", -"weasel", "otter", "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", -"walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", "warthog", -"hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", -"bison", "buffalo", "bull", "ape", "ant" }; - -command_result rename_creatures(color_ostream &out, std::vector & parameters) -{ - if (!parameters.empty()) - return CR_WRONG_USAGE; - CoreSuspender suspend; +DFHACK_PLUGIN_IS_ENABLED(is_enabled); - int descriptorCount[NUM_DESC] = { 0 }; +DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) +{ + is_enabled = enable; + return CR_OK; +} - if (World::GetPersistentData("AlreadyRenamedCreatures").isValid()) - { +#define NUM_DESC 227 +std::string descriptors[NUM_DESC] = { " blob", " quadruped", " humanoid", " silverfish", " mayfly", " dragonfly", +" damselfly", " stonefly", " earwig", " grasshopper", " cricket", " stick insect", " cockroach", " termite", +" mantis", " louse", " thrips", " aphid", " cicada", " assassin bug", " wasp", " hornet", " tiger beetle", +" ladybug", " weevil", " darkling beetle", " click beetle", " firefly", " scarab beetle", " stag beetle", +" dung beetle", " rhinoceros beetle", " rove beetle", " snakefly", " lacewing", " antlion larva", +" mosquito", " flea", " scorpionfly", " caddisfly", " butterfly", " moth", " caterpillar", " maggot", +" spider", " tarantula", " scorpion", " tick", " mite", " shrimp", " lobster", " crab", " nematode", +" snail", " slug", " earthworm", " leech", " bristleworm", " ribbon worm", " flat worm", " toad", " frog", +" salamander", " newt", " alligator", " crocodile", " lizard", " chameleon", " iguana", " gecko", " skink", +" gila monster", " monitor", " serpent", " viper", " rattlesnake", " cobra", " python", " anaconda", " turtle", +" tortoise", " pterosaur", " dimetrodon", " sauropod", " theropod", " iguanodont", " hadrosaurid", " stegosaurid", +" ceratopsid", " ankylosaurid", " duck", " goose", " swan", " turkey", " grouse", " chicken", " quail", " pheasant", +" gull", " loon", " grebe", " albatross", " petrel", " penguin", " pelican", " stork", " vulture", " flamingo", +" falcon", " kestrel", " condor", " osprey", " buzzard", " eagle", " harrier", " kite", " crane", " dove", +" pigeon", " parrot", " cockatoo", " cuckoo", " nightjar", " swift", " hummingbird", " kingfisher", +" hornbill", " quetzal", " toucan", " woodpecker", " lyrebird", " thornbill", " honeyeater", " oriole", +" fantail", " shrike", " crow", " raven", " magpie", " kinglet", " lark", " swallow", " martin", " bushtit", +" warbler", " thrush", " oxpecker", " starling", " mockingbird", " wren", " nuthatch", " sparrow", " tanager", +" cardinal", " bunting", " finch", " titmouse", " chickadee", " waxwing", " flycatcher", " opossum", " koala", +" wombat", " kangaroo", " sloth", " anteater", " armadillo", " squirrel", " marmot", " beaver", " gopher", +" mouse", " porcupine", " chinchilla", " cavy", " capybara", " rabbit", " hare", " lemur", " loris", " monkey", +" hedgehog", " shrew", " mole", " fruit bat", " wolf", " coyote", " jackal", " raccoon", " coati", +" weasel", " otter", " badger", " skunk", " bear", " panda", " panther", " mongoose", " hyena", " civet", +" walrus", " pangolin", " elephant", " mammoth", " horse", " zebra", " tapir", " rhinoceros", " warthog", +" hippopotamus", " camel", " llama", " giraffe", " deer", " moose", " antelope", " sheep", " goat", +" bison", " buffalo", " bull", " ape", " ant", " bat", " owl", " pig", " bee" }; + + +DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) +{ + if (!is_enabled) return CR_OK; - } - - for (int i = 0; i < world->raws.creatures.all.size(); i++) + switch (event) { - auto creatureRaw = world->raws.creatures.all[i]; - if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) - continue; - size_t minPos = std::string::npos; - size_t foundIndex = std::string::npos; + case DFHack::SC_WORLD_LOADED: + CoreSuspender suspend; - for (size_t j = 0; j < NUM_DESC; j++) + int descriptorCount[NUM_DESC] = { 0 }; + + if (World::GetPersistentData("AlreadyRenamedCreatures").isValid()) { - size_t pos = creatureRaw->caste[0]->description.find(descriptors[j]); - if (pos < minPos) - { - minPos = pos; - foundIndex = j; - } + return CR_OK; } - if (foundIndex < std::string::npos) + for (int i = 0; i < world->raws.creatures.all.size(); i++) { - size_t digitPos = creatureRaw->creature_id.find_first_of("0123456789"); - if (digitPos > creatureRaw->creature_id.length()) - digitPos = creatureRaw->creature_id.length(); + auto creatureRaw = world->raws.creatures.all[i]; + if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) + continue; + size_t minPos = std::string::npos; + size_t foundIndex = std::string::npos; - creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex]); - - if (descriptorCount[foundIndex] > 0) + for (size_t j = 0; j < NUM_DESC; j++) { - creatureRaw->creature_id.append(std::to_string(descriptorCount[foundIndex])); + size_t pos = creatureRaw->caste[0]->description.find(descriptors[j]); + if (pos < minPos) + { + minPos = pos; + foundIndex = j; + } } - descriptorCount[foundIndex]++; + if (foundIndex < std::string::npos) + { + size_t digitPos = creatureRaw->creature_id.find_first_of("0123456789"); + if (digitPos > creatureRaw->creature_id.length()) + digitPos = creatureRaw->creature_id.length(); + + creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex], 1, std::string::npos); + + if (descriptorCount[foundIndex] > 0) + { + creatureRaw->creature_id.append(std::to_string(descriptorCount[foundIndex])); + } + + descriptorCount[foundIndex]++; + } } + World::AddPersistentData("AlreadyRenamedCreatures"); + break; } - World::AddPersistentData("AlreadyRenamedCreatures"); return CR_OK; } From f65a9810996d9d20d2423ab534cb04c495c905d5 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 4 Feb 2017 14:46:38 -0500 Subject: [PATCH 07/43] Fix indentation --- plugins/proto/RemoteFortressReader.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/proto/RemoteFortressReader.proto index fdfc25d99..af25c9a4b 100644 --- a/plugins/proto/RemoteFortressReader.proto +++ b/plugins/proto/RemoteFortressReader.proto @@ -322,8 +322,8 @@ message UnitDefinition optional int32 blood_max = 14; optional int32 blood_count = 15; optional UnitAppearance appearance = 16; - optional int32 profession_id = 17; - repeated string noble_positions = 18; + optional int32 profession_id = 17; + repeated string noble_positions = 18; } message UnitList @@ -756,4 +756,4 @@ message DigCommand message SingleBool { optional bool Value = 1; -} \ No newline at end of file +} From a8f48331886d2f2327fddb1c88a8e04ef54d2979 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 4 Feb 2017 14:49:09 -0500 Subject: [PATCH 08/43] internal_memscan: add extra check --- library/LuaApi.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index b8a6fe53d..39404e9be 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -2557,6 +2557,9 @@ static int internal_memscan(lua_State *L) for (int i = 0; i <= hcount; i++) { uint8_t *p = haystack + i*hstep; + if (p + nsize > haystack + (hcount * hstep)) { + break; + } if (memcmp(p, needle, nsize) == 0) { lua_pushinteger(L, i); lua_pushinteger(L, (lua_Integer)p); From 7823d78cd91210ae1e648be038b6a92a6f658391 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 4 Feb 2017 14:49:21 -0500 Subject: [PATCH 09/43] Update xml and embark-tools field name --- library/xml | 2 +- plugins/embark-tools.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/xml b/library/xml index 34331ef67..fc2570c6c 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 34331ef67f3d163f4ab66121449a8217eb1cfb47 +Subproject commit fc2570c6c0179fcdf48610f0e3eaef7f84908da7 diff --git a/plugins/embark-tools.cpp b/plugins/embark-tools.cpp index d2bdf4909..274f8cad7 100644 --- a/plugins/embark-tools.cpp +++ b/plugins/embark-tools.cpp @@ -128,7 +128,7 @@ public: if (input->count(df::interface_key::SETUP_EMBARK)) { cancel = true; - screen->in_embark_normal = 1; + screen->in_embark_only_warning = 1; } }; }; From 34988e53b9022e27c1f4412f403b57b987561270 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Feb 2017 22:03:06 -0500 Subject: [PATCH 10/43] Update supported keys in keybinding help text --- library/Core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Core.cpp b/library/Core.cpp index 6afe907aa..b1bf67973 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1043,7 +1043,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v << " keybinding set [@context] \"cmdline\" \"cmdline\"..." << endl << " keybinding add [@context] \"cmdline\" \"cmdline\"..." << endl << "Later adds, and earlier items within one command have priority." << endl - << "Supported keys: [Ctrl-][Alt-][Shift-](A-Z, or F1-F9, or Enter)." << endl + << "Supported keys: [Ctrl-][Alt-][Shift-](A-Z, 0-9, F1-F12, or Enter)." << endl << "Context may be used to limit the scope of the binding, by" << endl << "requiring the current context to have a certain prefix." << endl << "Current UI context is: " From f2164d27c9d939407a4f814c1da2d5e39aceb72b Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Feb 2017 22:11:35 -0500 Subject: [PATCH 11/43] ls: List scripts outside of hack/scripts Closes #412 --- library/Core.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index b1bf67973..642da61ea 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -279,19 +279,24 @@ static void listScripts(PluginManager *plug_mgr, std::map &pset, std::vector files; Filesystem::listdir(path, files); + path += '/'; for (size_t i = 0; i < files.size(); i++) { if (hasEnding(files[i], ".lua")) { - std::string help = getScriptHelp(path + files[i], "--"); - - pset[prefix + files[i].substr(0, files[i].size()-4)] = help; + string help = getScriptHelp(path + files[i], "--"); + string key = prefix + files[i].substr(0, files[i].size()-4); + if (pset.find(key) == pset.end()) { + pset[key] = help; + } } else if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && hasEnding(files[i], ".rb")) { - std::string help = getScriptHelp(path + files[i], "#"); - - pset[prefix + files[i].substr(0, files[i].size()-3)] = help; + string help = getScriptHelp(path + files[i], "#"); + string key = prefix + files[i].substr(0, files[i].size()-3); + if (pset.find(key) == pset.end()) { + pset[key] = help; + } } else if (all && !files[i].empty() && files[i][0] != '.') { @@ -300,6 +305,14 @@ static void listScripts(PluginManager *plug_mgr, std::map &pset, } } +static void listAllScripts(map &pset, bool all) +{ + vector paths; + Core::getInstance().getScriptPaths(&paths); + for (string path : paths) + listScripts(Core::getInstance().getPluginManager(), pset, path, all); +} + namespace { struct ScriptArgs { const string *pcmd; @@ -418,7 +431,7 @@ static bool try_autocomplete(color_ostream &con, const std::string &first, std:: bool all = (first.find('/') != std::string::npos); std::map scripts; - listScripts(plug_mgr, scripts, Core::getInstance().getHackPath() + "scripts/", all); + listAllScripts(scripts, all); for (auto iter = scripts.begin(); iter != scripts.end(); ++iter) if (iter->first.substr(0, first.size()) == first) possible.push_back(iter->first); @@ -907,7 +920,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v con.reset_color(); } std::map scripts; - listScripts(plug_mgr, scripts, getHackPath() + "scripts/", all); + listAllScripts(scripts, all); if (!scripts.empty()) { con.print("\nscripts:\n"); From f94cc47be0ec9257ac9bd245590e9a7f6dc21b3f Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 5 Feb 2017 22:12:10 -0500 Subject: [PATCH 12/43] Update scripts (devel/find-offsets, season-palette) --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index 20eb2146f..76ee1ec38 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 20eb2146fb93912b07034f3192dde1cf95a9ec7f +Subproject commit 76ee1ec38bf56fce0e48404520ce5e0ebe22702b From b18bd72c05db76d3a33742fec10488986a246cd2 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 6 Feb 2017 10:12:20 +0530 Subject: [PATCH 13/43] Replace tab with spaces. --- plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 6b1f80634..f7586f03d 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -122,7 +122,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(follow follow.cpp) DFHACK_PLUGIN(forceequip forceequip.cpp) DFHACK_PLUGIN(fortplan fortplan.cpp LINK_LIBRARIES buildingplan-lib) - DFHACK_PLUGIN(generated-creature-renamer generated-creature-renamer.cpp) + DFHACK_PLUGIN(generated-creature-renamer generated-creature-renamer.cpp) DFHACK_PLUGIN(getplants getplants.cpp) DFHACK_PLUGIN(hotkeys hotkeys.cpp) DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) From 6e75840d911f2f481ad498d13730deffa6a56418 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 6 Feb 2017 10:18:14 +0530 Subject: [PATCH 14/43] Don't start creature-renamer automatically. --- dfhack.init-example | 3 --- 1 file changed, 3 deletions(-) diff --git a/dfhack.init-example b/dfhack.init-example index a0dd220e1..169d40046 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -233,9 +233,6 @@ enable \ # enable mouse controls and sand indicator in embark screen embark-tools enable sticky sand mouse -# Renames generated creatures to reflect the template used to generate them. -enable generated-creature-renamer - ########### # Scripts # ########### From 1aef1d1b98f0b2e78a1bc519d0f952ea7472c51b Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 6 Feb 2017 10:42:10 +0530 Subject: [PATCH 15/43] use STD::Vector instead of a C array, and set version properly. --- plugins/generated-creature-renamer.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 1a738cce4..8f82f0e63 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -16,6 +16,8 @@ using namespace DFHack; DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); +#define RENAMER_VERSION 1 + command_result list_creatures(color_ostream &out, std::vector & parameters); DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) @@ -43,8 +45,7 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) return CR_OK; } -#define NUM_DESC 227 -std::string descriptors[NUM_DESC] = { " blob", " quadruped", " humanoid", " silverfish", " mayfly", " dragonfly", +std::vector descriptors = { " blob", " quadruped", " humanoid", " silverfish", " mayfly", " dragonfly", " damselfly", " stonefly", " earwig", " grasshopper", " cricket", " stick insect", " cockroach", " termite", " mantis", " louse", " thrips", " aphid", " cicada", " assassin bug", " wasp", " hornet", " tiger beetle", " ladybug", " weevil", " darkling beetle", " click beetle", " firefly", " scarab beetle", " stag beetle", @@ -81,9 +82,10 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan case DFHack::SC_WORLD_LOADED: CoreSuspender suspend; - int descriptorCount[NUM_DESC] = { 0 }; + std::vector descriptorCount = std::vector(descriptors.size()); - if (World::GetPersistentData("AlreadyRenamedCreatures").isValid()) + auto version = World::GetPersistentData("AlreadyRenamedCreatures"); + if (version.isValid() && version.ival(1) >= RENAMER_VERSION) { return CR_OK; } @@ -96,7 +98,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan size_t minPos = std::string::npos; size_t foundIndex = std::string::npos; - for (size_t j = 0; j < NUM_DESC; j++) + for (size_t j = 0; j < descriptors.size(); j++) { size_t pos = creatureRaw->caste[0]->description.find(descriptors[j]); if (pos < minPos) @@ -122,7 +124,8 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan descriptorCount[foundIndex]++; } } - World::AddPersistentData("AlreadyRenamedCreatures"); + version = World::AddPersistentData("AlreadyRenamedCreatures"); + version.ival(1) = RENAMER_VERSION; break; } From 5b83c6fe685dc82dc35c228fea9014942949ff5d Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 6 Feb 2017 10:49:22 +0530 Subject: [PATCH 16/43] Add spaces to search string programmatically. --- plugins/generated-creature-renamer.cpp | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 8f82f0e63..caace087a 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -45,32 +45,32 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) return CR_OK; } -std::vector descriptors = { " blob", " quadruped", " humanoid", " silverfish", " mayfly", " dragonfly", -" damselfly", " stonefly", " earwig", " grasshopper", " cricket", " stick insect", " cockroach", " termite", -" mantis", " louse", " thrips", " aphid", " cicada", " assassin bug", " wasp", " hornet", " tiger beetle", -" ladybug", " weevil", " darkling beetle", " click beetle", " firefly", " scarab beetle", " stag beetle", -" dung beetle", " rhinoceros beetle", " rove beetle", " snakefly", " lacewing", " antlion larva", -" mosquito", " flea", " scorpionfly", " caddisfly", " butterfly", " moth", " caterpillar", " maggot", -" spider", " tarantula", " scorpion", " tick", " mite", " shrimp", " lobster", " crab", " nematode", -" snail", " slug", " earthworm", " leech", " bristleworm", " ribbon worm", " flat worm", " toad", " frog", -" salamander", " newt", " alligator", " crocodile", " lizard", " chameleon", " iguana", " gecko", " skink", -" gila monster", " monitor", " serpent", " viper", " rattlesnake", " cobra", " python", " anaconda", " turtle", -" tortoise", " pterosaur", " dimetrodon", " sauropod", " theropod", " iguanodont", " hadrosaurid", " stegosaurid", -" ceratopsid", " ankylosaurid", " duck", " goose", " swan", " turkey", " grouse", " chicken", " quail", " pheasant", -" gull", " loon", " grebe", " albatross", " petrel", " penguin", " pelican", " stork", " vulture", " flamingo", -" falcon", " kestrel", " condor", " osprey", " buzzard", " eagle", " harrier", " kite", " crane", " dove", -" pigeon", " parrot", " cockatoo", " cuckoo", " nightjar", " swift", " hummingbird", " kingfisher", -" hornbill", " quetzal", " toucan", " woodpecker", " lyrebird", " thornbill", " honeyeater", " oriole", -" fantail", " shrike", " crow", " raven", " magpie", " kinglet", " lark", " swallow", " martin", " bushtit", -" warbler", " thrush", " oxpecker", " starling", " mockingbird", " wren", " nuthatch", " sparrow", " tanager", -" cardinal", " bunting", " finch", " titmouse", " chickadee", " waxwing", " flycatcher", " opossum", " koala", -" wombat", " kangaroo", " sloth", " anteater", " armadillo", " squirrel", " marmot", " beaver", " gopher", -" mouse", " porcupine", " chinchilla", " cavy", " capybara", " rabbit", " hare", " lemur", " loris", " monkey", -" hedgehog", " shrew", " mole", " fruit bat", " wolf", " coyote", " jackal", " raccoon", " coati", -" weasel", " otter", " badger", " skunk", " bear", " panda", " panther", " mongoose", " hyena", " civet", -" walrus", " pangolin", " elephant", " mammoth", " horse", " zebra", " tapir", " rhinoceros", " warthog", -" hippopotamus", " camel", " llama", " giraffe", " deer", " moose", " antelope", " sheep", " goat", -" bison", " buffalo", " bull", " ape", " ant", " bat", " owl", " pig", " bee" }; +std::vector descriptors = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", +"damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", +"mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", +"ladybug", "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", +"dung beetle", "rhinoceros beetle", "rove beetle", "snakefly", "lacewing", "antlion larva", +"mosquito", "flea", "scorpionfly", "caddisfly", "butterfly", "moth", "caterpillar", "maggot", +"spider", "tarantula", "scorpion", "tick", "mite", "shrimp", "lobster", "crab", "nematode", +"snail", "slug", "earthworm", "leech", "bristleworm", "ribbon worm", "flat worm", "toad", "frog", +"salamander", "newt", "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", +"gila monster", "monitor", "serpent", "viper", "rattlesnake", "cobra", "python", "anaconda", "turtle", +"tortoise", "pterosaur", "dimetrodon", "sauropod", "theropod", "iguanodont", "hadrosaurid", "stegosaurid", +"ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", "quail", "pheasant", +"gull", "loon", "grebe", "albatross", "petrel", "penguin", "pelican", "stork", "vulture", "flamingo", +"falcon", "kestrel", "condor", "osprey", "buzzard", "eagle", "harrier", "kite", "crane", "dove", +"pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", +"hornbill", "quetzal", "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", +"fantail", "shrike", "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", +"warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", "tanager", +"cardinal", "bunting", "finch", "titmouse", "chickadee", "waxwing", "flycatcher", "opossum", "koala", +"wombat", "kangaroo", "sloth", "anteater", "armadillo", "squirrel", "marmot", "beaver", "gopher", +"mouse", "porcupine", "chinchilla", "cavy", "capybara", "rabbit", "hare", "lemur", "loris", "monkey", +"hedgehog", "shrew", "mole", "fruit bat", "wolf", "coyote", "jackal", "raccoon", "coati", +"weasel", "otter", "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", +"walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", "warthog", +"hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", +"bison", "buffalo", "bull", "ape", "ant", "bat", "owl", "pig", "bee"}; DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) @@ -100,7 +100,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan for (size_t j = 0; j < descriptors.size(); j++) { - size_t pos = creatureRaw->caste[0]->description.find(descriptors[j]); + size_t pos = creatureRaw->caste[0]->description.find(" " + descriptors[j]); if (pos < minPos) { minPos = pos; From 64e217132e41957c51347280bece3697e02a81d9 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 6 Feb 2017 10:50:18 +0530 Subject: [PATCH 17/43] Don't offset the raplacement by 1 since there's no space now. --- plugins/generated-creature-renamer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index caace087a..7e0f2c309 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -114,7 +114,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan if (digitPos > creatureRaw->creature_id.length()) digitPos = creatureRaw->creature_id.length(); - creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex], 1, std::string::npos); + creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex]); if (descriptorCount[foundIndex] > 0) { From 68faca09ee03726e8408253dcc08a02d6a9a3baf Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Tue, 7 Feb 2017 10:27:57 +0530 Subject: [PATCH 18/43] Added missing base types given by toady, and reorganized the list to look better. --- plugins/generated-creature-renamer.cpp | 58 ++++++++++++++------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 7e0f2c309..1d0b98f58 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -45,32 +45,38 @@ DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) return CR_OK; } -std::vector descriptors = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", -"damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", -"mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", -"ladybug", "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", -"dung beetle", "rhinoceros beetle", "rove beetle", "snakefly", "lacewing", "antlion larva", -"mosquito", "flea", "scorpionfly", "caddisfly", "butterfly", "moth", "caterpillar", "maggot", -"spider", "tarantula", "scorpion", "tick", "mite", "shrimp", "lobster", "crab", "nematode", -"snail", "slug", "earthworm", "leech", "bristleworm", "ribbon worm", "flat worm", "toad", "frog", -"salamander", "newt", "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", -"gila monster", "monitor", "serpent", "viper", "rattlesnake", "cobra", "python", "anaconda", "turtle", -"tortoise", "pterosaur", "dimetrodon", "sauropod", "theropod", "iguanodont", "hadrosaurid", "stegosaurid", -"ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", "quail", "pheasant", -"gull", "loon", "grebe", "albatross", "petrel", "penguin", "pelican", "stork", "vulture", "flamingo", -"falcon", "kestrel", "condor", "osprey", "buzzard", "eagle", "harrier", "kite", "crane", "dove", -"pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", -"hornbill", "quetzal", "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", -"fantail", "shrike", "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", -"warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", "tanager", -"cardinal", "bunting", "finch", "titmouse", "chickadee", "waxwing", "flycatcher", "opossum", "koala", -"wombat", "kangaroo", "sloth", "anteater", "armadillo", "squirrel", "marmot", "beaver", "gopher", -"mouse", "porcupine", "chinchilla", "cavy", "capybara", "rabbit", "hare", "lemur", "loris", "monkey", -"hedgehog", "shrew", "mole", "fruit bat", "wolf", "coyote", "jackal", "raccoon", "coati", -"weasel", "otter", "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", -"walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", "warthog", -"hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", -"bison", "buffalo", "bull", "ape", "ant", "bat", "owl", "pig", "bee"}; +std::vector descriptors = { + "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", "damselfly", "stonefly", + "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", "mantis", "louse", + "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", "ladybug", + "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", "dung beetle", "rhinoceros beetle", + "rove beetle", "snakefly", "lacewing", "antlion larva", "mosquito", "flea", "scorpionfly", "caddisfly", + "butterfly", "moth", "caterpillar", "maggot", "spider", "tarantula", "scorpion", "tick", + "mite", "shrimp", "lobster", "crab", "nematode", "snail", "slug", "earthworm", + "leech", "bristleworm", "ribbon worm", "flat worm", "toad", "frog", "salamander", "newt", + "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", "gila monster", + "monitor", "serpent", "viper", "rattlesnake", "cobra", "python", "anaconda", "turtle", + "tortoise", "pterosaur", "dimetrodon", "sauropod", "theropod", "iguanodont", "hadrosaurid", "stegosaurid", + "ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", + "quail", "pheasant", "gull", "loon", "grebe", "albatross", "petrel", "penguin", + "pelican", "stork", "vulture", "flamingo", "falcon", "kestrel", "condor", "osprey", + "buzzard", "eagle", "harrier", "kite", "crane", "dove", "pigeon", "parrot", + "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", "hornbill", "quetzal", + "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", "fantail", "shrike", + "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", + "warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", + "tanager", "cardinal", "bunting", "finch", "titmouse", "chickadee", "waxwing", "flycatcher", + "opossum", "koala", "wombat", "kangaroo", "sloth", "anteater", "armadillo", "squirrel", + "marmot", "beaver", "gopher", "mouse", "porcupine", "chinchilla", "cavy", "capybara", + "rabbit", "hare", "lemur", "loris", "monkey", "hedgehog", "shrew", "mole", + "fruit bat", "wolf", "coyote", "jackal", "raccoon", "coati", "weasel", "otter", + "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", + "walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", + "warthog", "hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", + "sheep", "goat", "bison", "buffalo", "bull", "ape", "ant", "bat", + "owl", "pig", "bee", "fly", "hawk", "jay", "rat", "fox", + "cat", "ass", "elk" +}; DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) From f9b296884c728ea416a799505e4d30d1e7ee2ce1 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Tue, 7 Feb 2017 11:01:42 +0530 Subject: [PATCH 19/43] Made the creature renamer work more than once on the same save, and changed the format of the resulting names. --- plugins/generated-creature-renamer.cpp | 51 +++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 1d0b98f58..9463773b2 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -16,7 +16,7 @@ using namespace DFHack; DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); -#define RENAMER_VERSION 1 +#define RENAMER_VERSION 2 command_result list_creatures(color_ostream &out, std::vector & parameters); @@ -78,6 +78,14 @@ std::vector descriptors = { "cat", "ass", "elk" }; +std::vector prefixes = { + "FORGOTTEN_BEAST_", + "TITAN_", + "DEMON_", + "NIGHT_CREATURE_", + "HF" +}; + DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) { @@ -102,7 +110,19 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) continue; size_t minPos = std::string::npos; - size_t foundIndex = std::string::npos; + size_t foundIndex = -1; + size_t prefixIndex = -1; + + for (rsize_t j = 0; j < prefixes.size(); j++) + { + if (creatureRaw->creature_id.compare(0, prefixes[j].length(), prefixes[j]) == 0) + { + prefixIndex = j; + } + } + + if (prefixIndex < 0) + continue; //unrecognized generaed type. for (size_t j = 0; j < descriptors.size(); j++) { @@ -114,21 +134,26 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan } } - if (foundIndex < std::string::npos) - { - size_t digitPos = creatureRaw->creature_id.find_first_of("0123456789"); - if (digitPos > creatureRaw->creature_id.length()) - digitPos = creatureRaw->creature_id.length(); + if (foundIndex < 0) + continue; //can't find a match. - creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex]); + auto descriptor = descriptors[foundIndex]; - if (descriptorCount[foundIndex] > 0) - { - creatureRaw->creature_id.append(std::to_string(descriptorCount[foundIndex])); - } + for (int j = 0; j < descriptor.size(); j++) + { + if (descriptor[j] == ' ') + descriptor[j] = '_'; + else + descriptor[j] = toupper(descriptor[j]); + } + + creatureRaw->creature_id = prefixes[prefixIndex] + descriptor; - descriptorCount[foundIndex]++; + if (descriptorCount[foundIndex] > 0) + { + creatureRaw->creature_id.append("_" + std::to_string(descriptorCount[foundIndex])); } + descriptorCount[foundIndex]++; } version = World::AddPersistentData("AlreadyRenamedCreatures"); version.ival(1) = RENAMER_VERSION; From b151ad7c750f4bdc4e0b69240a98d854843615c6 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Tue, 7 Feb 2017 11:09:39 +0530 Subject: [PATCH 20/43] always make sure the name prefix has an underscore at the end of it. --- plugins/generated-creature-renamer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 9463773b2..df7b5c0d3 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -16,7 +16,7 @@ using namespace DFHack; DFHACK_PLUGIN("generated-creature-renamer"); REQUIRE_GLOBAL(world); -#define RENAMER_VERSION 2 +#define RENAMER_VERSION 3 command_result list_creatures(color_ostream &out, std::vector & parameters); @@ -147,6 +147,10 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan descriptor[j] = toupper(descriptor[j]); } + auto prefix = prefixes[prefixIndex]; + if (prefix[prefix.length() - 1] != '_') + prefix.append("_"); + creatureRaw->creature_id = prefixes[prefixIndex] + descriptor; if (descriptorCount[foundIndex] > 0) From 10bbd3cb39ff1cf97f14329f60de9bed0a735ff7 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Tue, 7 Feb 2017 11:19:45 +0530 Subject: [PATCH 21/43] Added a function to spit out a generated graphics pack file. Not done yet. --- plugins/generated-creature-renamer.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index df7b5c0d3..e6cf8723f 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -19,6 +19,7 @@ REQUIRE_GLOBAL(world); #define RENAMER_VERSION 3 command_result list_creatures(color_ostream &out, std::vector & parameters); +command_result save_generated_raw(color_ostream &out, std::vector & parameters); DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { @@ -29,7 +30,13 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector & pa } } +command_result save_generated_raw(color_ostream &out, std::vector & parameters) +{ + + return CR_OK; +} From 873feaee2b04e1d27a48253b5ee616ced0521a82 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Tue, 7 Feb 2017 15:57:35 +0530 Subject: [PATCH 22/43] Added a function to the creature renamer to save a graphics pack file to set graphics for all the generated creatures. --- plugins/generated-creature-renamer.cpp | 177 +++++++++++++++++-------- 1 file changed, 121 insertions(+), 56 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index e6cf8723f..5eb030d44 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -8,6 +8,7 @@ #include "df/creature_raw.h" #include "df/caste_raw.h" #include "modules/World.h" +#include "MemAccess.h" //#include "df/world.h" @@ -25,17 +26,17 @@ DFhackCExport command_result plugin_init(color_ostream &out, std::vector descriptorCount = std::vector(descriptors.size()); + + auto version = World::GetPersistentData("AlreadyRenamedCreatures"); + if (version.isValid() && version.ival(1) >= RENAMER_VERSION) { - case DFHack::SC_WORLD_LOADED: - CoreSuspender suspend; + return CR_OK; + } - std::vector descriptorCount = std::vector(descriptors.size()); + int creatureCount = 0; - auto version = World::GetPersistentData("AlreadyRenamedCreatures"); - if (version.isValid() && version.ival(1) >= RENAMER_VERSION) - { - return CR_OK; - } + for (int i = 0; i < world->raws.creatures.all.size(); i++) + { + auto creatureRaw = world->raws.creatures.all[i]; + if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) + continue; + size_t minPos = std::string::npos; + size_t foundIndex = -1; + size_t prefixIndex = -1; - for (int i = 0; i < world->raws.creatures.all.size(); i++) + for (rsize_t j = 0; j < prefixes.size(); j++) { - auto creatureRaw = world->raws.creatures.all[i]; - if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) - continue; - size_t minPos = std::string::npos; - size_t foundIndex = -1; - size_t prefixIndex = -1; - - for (rsize_t j = 0; j < prefixes.size(); j++) + if (creatureRaw->creature_id.compare(0, prefixes[j].length(), prefixes[j]) == 0) { - if (creatureRaw->creature_id.compare(0, prefixes[j].length(), prefixes[j]) == 0) - { - prefixIndex = j; - } + prefixIndex = j; } + } - if (prefixIndex < 0) - continue; //unrecognized generaed type. + if (prefixIndex < 0) + continue; //unrecognized generaed type. - for (size_t j = 0; j < descriptors.size(); j++) + for (size_t j = 0; j < descriptors.size(); j++) + { + size_t pos = creatureRaw->caste[0]->description.find(" " + descriptors[j]); + if (pos < minPos) { - size_t pos = creatureRaw->caste[0]->description.find(" " + descriptors[j]); - if (pos < minPos) - { - minPos = pos; - foundIndex = j; - } + minPos = pos; + foundIndex = j; } + } - if (foundIndex < 0) - continue; //can't find a match. + if (foundIndex < 0) + continue; //can't find a match. - auto descriptor = descriptors[foundIndex]; + auto descriptor = descriptors[foundIndex]; - for (int j = 0; j < descriptor.size(); j++) - { - if (descriptor[j] == ' ') - descriptor[j] = '_'; - else - descriptor[j] = toupper(descriptor[j]); - } + for (int j = 0; j < descriptor.size(); j++) + { + if (descriptor[j] == ' ') + descriptor[j] = '_'; + else + descriptor[j] = toupper(descriptor[j]); + } - auto prefix = prefixes[prefixIndex]; - if (prefix[prefix.length() - 1] != '_') - prefix.append("_"); + auto prefix = prefixes[prefixIndex]; + if (prefix[prefix.length() - 1] != '_') + prefix.append("_"); - creatureRaw->creature_id = prefixes[prefixIndex] + descriptor; + creatureRaw->creature_id = prefixes[prefixIndex] + descriptor; - if (descriptorCount[foundIndex] > 0) - { - creatureRaw->creature_id.append("_" + std::to_string(descriptorCount[foundIndex])); - } - descriptorCount[foundIndex]++; + if (descriptorCount[foundIndex] > 0) + { + creatureRaw->creature_id.append("_" + std::to_string(descriptorCount[foundIndex])); } - version = World::AddPersistentData("AlreadyRenamedCreatures"); - version.ival(1) = RENAMER_VERSION; - break; + descriptorCount[foundIndex]++; + creatureCount++; } + version = World::AddPersistentData("AlreadyRenamedCreatures"); + version.ival(1) = RENAMER_VERSION; + + out << "Renamed " << creatureCount << " generated creatures to have sensible names." << endl; + + return CR_OK; } @@ -200,10 +207,68 @@ command_result list_creatures(color_ostream &out, std::vector & pa } out.print("\n"); } + return CR_OK; } command_result save_generated_raw(color_ostream &out, std::vector & parameters) { +#ifdef LINUX_BUILD + std::string pathSep = "/"; +#else + std::string pathSep = "\\"; +#endif + int pageWidth = 16; + int pageHeight = (descriptors.size() / pageWidth) + ((descriptors.size() % pageWidth > 0) ? 1 : 0); + int tileWidth = 24; + int tileHeight = 24; + std::string fileName = "graphics_procedural_creatures"; + std::string pageName = "PROCEDURAL_FRIENDLY"; + int repeats = 128; + + std::ofstream outputFile(fileName + ".txt", std::ios::out | std::ios::trunc); + + outputFile << fileName << endl << endl; + + outputFile << "[OBJECT:GRAPHICS]" << endl << endl; + + outputFile << "[TILE_PAGE:" << pageName << "]" << endl; + outputFile << " [FILE:procedural_friendly.png]" << endl; + outputFile << " [TILE_DIM:" << tileWidth << ":" << tileHeight << "]" << endl; + outputFile << " [PAGE_DIM:" << pageWidth << ":" << pageHeight << "]" << endl << endl; + + for (size_t descIndex = 0; descIndex < descriptors.size(); descIndex++) + { + for (size_t prefIndex = 0; prefIndex < prefixes.size(); prefIndex++) + { + for (size_t rep = 0; rep < repeats; rep++) + { + auto descriptor = descriptors[descIndex]; + + for (int j = 0; j < descriptor.size(); j++) + { + if (descriptor[j] == ' ') + descriptor[j] = '_'; + else + descriptor[j] = toupper(descriptor[j]); + } + + auto prefix = prefixes[prefIndex]; + if (prefix[prefix.length() - 1] != '_') + prefix.append("_"); + + std::string token = prefix + descriptor; + if (rep > 0) + token.append("_" + std::to_string(rep)); + + outputFile << "[CREATURE_GRAPHICS:" << token << "]" << endl; + outputFile << " [DEFAULT:" << pageName << ":" << descIndex % pageWidth << ":" << descIndex / pageWidth << ":ADD_COLOR]" << endl; + } + outputFile << endl; + } + outputFile << endl; + } + + outputFile.close(); return CR_OK; } From 2c19f6b237f555aaf5de0abf6a08043aa8bf1024 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Wed, 8 Feb 2017 10:34:11 +0530 Subject: [PATCH 23/43] remove rsize_t --- plugins/generated-creature-renamer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 5eb030d44..13f0f9a6f 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -124,7 +124,7 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan size_t foundIndex = -1; size_t prefixIndex = -1; - for (rsize_t j = 0; j < prefixes.size(); j++) + for (size_t j = 0; j < prefixes.size(); j++) { if (creatureRaw->creature_id.compare(0, prefixes[j].length(), prefixes[j]) == 0) { From 0d8decd7eccbab575334646bcd9f67a2e795b0f4 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Wed, 8 Feb 2017 10:54:42 +0530 Subject: [PATCH 24/43] Remove trailing whitespaces. --- plugins/generated-creature-renamer.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/generated-creature-renamer.cpp b/plugins/generated-creature-renamer.cpp index 13f0f9a6f..49444eaf4 100644 --- a/plugins/generated-creature-renamer.cpp +++ b/plugins/generated-creature-renamer.cpp @@ -57,32 +57,32 @@ std::vector descriptors = { "blob", "quadruped", "humanoid", "silverfish", "mayfly", "dragonfly", "damselfly", "stonefly", "earwig", "grasshopper", "cricket", "stick insect", "cockroach", "termite", "mantis", "louse", "thrips", "aphid", "cicada", "assassin bug", "wasp", "hornet", "tiger beetle", "ladybug", - "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", "dung beetle", "rhinoceros beetle", - "rove beetle", "snakefly", "lacewing", "antlion larva", "mosquito", "flea", "scorpionfly", "caddisfly", + "weevil", "darkling beetle", "click beetle", "firefly", "scarab beetle", "stag beetle", "dung beetle", "rhinoceros beetle", + "rove beetle", "snakefly", "lacewing", "antlion larva", "mosquito", "flea", "scorpionfly", "caddisfly", "butterfly", "moth", "caterpillar", "maggot", "spider", "tarantula", "scorpion", "tick", "mite", "shrimp", "lobster", "crab", "nematode", "snail", "slug", "earthworm", "leech", "bristleworm", "ribbon worm", "flat worm", "toad", "frog", "salamander", "newt", - "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", "gila monster", + "alligator", "crocodile", "lizard", "chameleon", "iguana", "gecko", "skink", "gila monster", "monitor", "serpent", "viper", "rattlesnake", "cobra", "python", "anaconda", "turtle", "tortoise", "pterosaur", "dimetrodon", "sauropod", "theropod", "iguanodont", "hadrosaurid", "stegosaurid", - "ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", + "ceratopsid", "ankylosaurid", "duck", "goose", "swan", "turkey", "grouse", "chicken", "quail", "pheasant", "gull", "loon", "grebe", "albatross", "petrel", "penguin", "pelican", "stork", "vulture", "flamingo", "falcon", "kestrel", "condor", "osprey", "buzzard", "eagle", "harrier", "kite", "crane", "dove", "pigeon", "parrot", "cockatoo", "cuckoo", "nightjar", "swift", "hummingbird", "kingfisher", "hornbill", "quetzal", - "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", "fantail", "shrike", + "toucan", "woodpecker", "lyrebird", "thornbill", "honeyeater", "oriole", "fantail", "shrike", "crow", "raven", "magpie", "kinglet", "lark", "swallow", "martin", "bushtit", "warbler", "thrush", "oxpecker", "starling", "mockingbird", "wren", "nuthatch", "sparrow", "tanager", "cardinal", "bunting", "finch", "titmouse", "chickadee", "waxwing", "flycatcher", "opossum", "koala", "wombat", "kangaroo", "sloth", "anteater", "armadillo", "squirrel", - "marmot", "beaver", "gopher", "mouse", "porcupine", "chinchilla", "cavy", "capybara", - "rabbit", "hare", "lemur", "loris", "monkey", "hedgehog", "shrew", "mole", + "marmot", "beaver", "gopher", "mouse", "porcupine", "chinchilla", "cavy", "capybara", + "rabbit", "hare", "lemur", "loris", "monkey", "hedgehog", "shrew", "mole", "fruit bat", "wolf", "coyote", "jackal", "raccoon", "coati", "weasel", "otter", "badger", "skunk", "bear", "panda", "panther", "mongoose", "hyena", "civet", "walrus", "pangolin", "elephant", "mammoth", "horse", "zebra", "tapir", "rhinoceros", - "warthog", "hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", + "warthog", "hippopotamus", "camel", "llama", "giraffe", "deer", "moose", "antelope", "sheep", "goat", "bison", "buffalo", "bull", "ape", "ant", "bat", - "owl", "pig", "bee", "fly", "hawk", "jay", "rat", "fox", + "owl", "pig", "bee", "fly", "hawk", "jay", "rat", "fox", "cat", "ass", "elk" }; From c68faaae378ba5fec6dbe7127b1ec79a38584536 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Fri, 10 Feb 2017 15:30:48 +0530 Subject: [PATCH 25/43] Add basic documentation for the generated-creature-renamer plugin. --- docs/Plugins.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/Plugins.rst b/docs/Plugins.rst index b3e68459d..b34b41da9 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -2453,6 +2453,24 @@ armor onto a war animal or to add unusual items (such as crowns) to any unit. For more information run ``forceequip help``. See also `modtools/equip-item`. +.. _generated-creature-renamer: + +generated-creature-renamer +========================== +Automatically renames generated creatures, such as forgotten beasts, titans, +etc, to have raw token names that match the description given in-game. + +The `list-generated` command can be used to list the token names of all +generated creatures in a given save, with an optional `detailed` argument +to show the accompanying description. + +The `save-generated-raws` command will save a sample creature graphics file in +the Dwarf Fortress root directory, to use as a start for making a graphics set +for generated creatures using the new names that they get with this plugin. + +The new names are saved with the save, and the plugin, when enabled, only runs once +per save, unless there's an update. + .. _lair: lair From f89678c47259ac3b06c15af8f5165f7d86f12816 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 11 Feb 2017 15:07:48 -0500 Subject: [PATCH 26/43] Fix backticks --- docs/Plugins.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Plugins.rst b/docs/Plugins.rst index b34b41da9..9e7498cee 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -2460,11 +2460,11 @@ generated-creature-renamer Automatically renames generated creatures, such as forgotten beasts, titans, etc, to have raw token names that match the description given in-game. -The `list-generated` command can be used to list the token names of all -generated creatures in a given save, with an optional `detailed` argument +The ``list-generated`` command can be used to list the token names of all +generated creatures in a given save, with an optional ``detailed`` argument to show the accompanying description. -The `save-generated-raws` command will save a sample creature graphics file in +The ``save-generated-raws`` command will save a sample creature graphics file in the Dwarf Fortress root directory, to use as a start for making a graphics set for generated creatures using the new names that they get with this plugin. From b110355b53778d2ffa5a509bcb84ab433ea40502 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 11 Feb 2017 15:09:46 -0500 Subject: [PATCH 27/43] Add missing space --- docs/Plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Plugins.rst b/docs/Plugins.rst index 9e7498cee..e2b829020 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -2540,7 +2540,7 @@ Options: :-unit: Make the strange mood strike the selected unit instead of picking one randomly. Unit eligibility is still enforced. :-type : Force the mood to be of a particular type instead of choosing randomly based on happiness. - Valid values for Tare "fey", "secretive", "possessed", "fell", and "macabre". + Valid values for T are "fey", "secretive", "possessed", "fell", and "macabre". :-skill S: Force the mood to use a specific skill instead of choosing the highest moodable skill. Valid values are "miner", "carpenter", "engraver", "mason", "tanner", "weaver", "clothier", "weaponsmith", "armorsmith", "metalsmith", "gemcutter", "gemsetter", From a10d4ae226db6f1f7c562f06b2cfd1804db03b81 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 11 Feb 2017 16:53:50 -0500 Subject: [PATCH 28/43] Add viewscreen::feed_key method --- library/include/df/custom/viewscreen.methods.inc | 5 +++++ library/xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library/include/df/custom/viewscreen.methods.inc b/library/include/df/custom/viewscreen.methods.inc index c5d277716..b1f07242e 100644 --- a/library/include/df/custom/viewscreen.methods.inc +++ b/library/include/df/custom/viewscreen.methods.inc @@ -1 +1,6 @@ friend struct df::interfacest; +void feed_key(df::interface_key key) { + std::set input; + input.insert(key); + feed(&input); +} diff --git a/library/xml b/library/xml index fc2570c6c..e60c4259a 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit fc2570c6c0179fcdf48610f0e3eaef7f84908da7 +Subproject commit e60c4259ab9ea9326af42173024a3b3e40fe6688 From 8b27ed5f1c5ae0b6f991621caaa69545d1f134eb Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 11 Feb 2017 17:07:49 -0500 Subject: [PATCH 29/43] Update changelog --- NEWS.rst | 8 ++++++++ docs/NEWS-dev.rst | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 2fdbfc561..4229da17f 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -64,6 +64,7 @@ Ruby New Plugins ----------- - `dwarfvet` enables animal caretaking +- `generated-creature-renamer`: Renames generated creature IDs for use with graphics packs - `labormanager` (formerly autolabor2): a more advanced alternative to `autolabor` - `misery`: re-added and updated for the 0.4x series - `title-folder`: shows DF folder name in window title bar when enabled @@ -80,6 +81,7 @@ Fixes ----- - The DF path on OS X can now contain spaces and ``:`` characters - Buildings::setOwner() changes now persist properly when saved +- ``ls`` now lists scripts in folders other than ``hack/scripts``, when applicable - `add-thought`: fixed support for emotion names - `autofarm`: Made surface farms detect local biome - `devel/find-offsets`: fixed a crash when vtables used by globals aren't available @@ -88,6 +90,10 @@ Fixes - Fixed crash when selecting a profession from an empty list - Custom professions are now sorted alphabetically more reliably +- `modtools/create-unit`: stopped permanently overwriting the creature creation + menu in arena mode +- `title-version`: now hidden when loading an arena + Misc Improvements ----------------- - Documented all default keybindings (from :file:`dfhack.init-example`) in the @@ -101,6 +107,8 @@ Misc Improvements - site towers, world buildings - surface material +- `title-version`: Added a prerelease indicator + DFHack 0.43.03-r1 ================= diff --git a/docs/NEWS-dev.rst b/docs/NEWS-dev.rst index 9920e3433..2efc9bf2a 100644 --- a/docs/NEWS-dev.rst +++ b/docs/NEWS-dev.rst @@ -37,6 +37,35 @@ Development Changelog .. contents:: :depth: 2 +DFHack 0.43.05-beta1 +==================== + +Fixes +----- +- Fixed various crashes on 64-bit Windows related to DFHack screens, notably `manipulator` +- ``ls`` now lists scripts in folders other than ``hack/scripts``, when applicable +- `modtools/create-unit`: stopped permanently overwriting the creature creation + menu in arena mode +- `season-palette`: fixed an issue where only part of the screen was redrawn + after changing the color scheme +- `title-version`: now hidden when loading an arena + +Structures +---------- +- ``file_compressorst``: fixed field sizes on x64 +- ``ui_sidebar_menus.command_line``: fixed field sizes on x64 +- ``viewscreen_layer_arena_creaturest``: identified more fields +- ``world.math``: identified +- ``world.murky_pools``: identified + +Additions/Removals +------------------ +- `generated-creature-renamer`: Renames generated creature IDs for use with graphics packs + +Other Changes +------------- +- `title-version`: Added a prerelease indicator + DFHack 0.43.05-alpha4 ===================== From 2fdd4d96b623611c92a66cb2fe9b8b28e8ab8309 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 11 Feb 2017 20:24:51 -0500 Subject: [PATCH 30/43] Add more XML changes to NEWS-dev --- docs/NEWS-dev.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/NEWS-dev.rst b/docs/NEWS-dev.rst index 2efc9bf2a..df74735c0 100644 --- a/docs/NEWS-dev.rst +++ b/docs/NEWS-dev.rst @@ -43,6 +43,7 @@ DFHack 0.43.05-beta1 Fixes ----- - Fixed various crashes on 64-bit Windows related to DFHack screens, notably `manipulator` +- Fixed addresses of next_id globals on 64-bit Linux (fixes an `automaterial`/box-select crash) - ``ls`` now lists scripts in folders other than ``hack/scripts``, when applicable - `modtools/create-unit`: stopped permanently overwriting the creature creation menu in arena mode @@ -53,7 +54,9 @@ Fixes Structures ---------- - ``file_compressorst``: fixed field sizes on x64 +- ``historical_entity``: fixed alignment on x64 - ``ui_sidebar_menus.command_line``: fixed field sizes on x64 +- ``viewscreen_choose_start_sitest``: added 3 missing fields, renamed ``in_embark_only_warning`` - ``viewscreen_layer_arena_creaturest``: identified more fields - ``world.math``: identified - ``world.murky_pools``: identified From 33060c7d0e2432fe31c62f35234bd96250055388 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 11 Feb 2017 20:48:37 -0500 Subject: [PATCH 31/43] Bump to beta1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3602655b4..c7c0835a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,7 +137,7 @@ endif() # set up versioning. set(DF_VERSION "0.43.05") -SET(DFHACK_RELEASE "alpha4") +SET(DFHACK_RELEASE "beta1") SET(DFHACK_PRERELEASE TRUE) set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}") From 19695b4ee7e8b370c8ce53aa2dcd399e1e9ca94d Mon Sep 17 00:00:00 2001 From: lethosor Date: Fri, 17 Feb 2017 22:53:48 -0500 Subject: [PATCH 32/43] EventManager/eventful: Pass building ID pointers to event handlers Previously, there was some disagreement over whether event handlers such as Buildings::updateBuildings() took building pointers or building IDs shoved into pointers. It turned out to be the latter, which, unfortunately, did not compile on x64. Passing building IDs isn't possible in all cases, because building event handlers can be called for recently-deleted buildings too. Pointers to building IDs do work reliably, though. Fixes #1003 --- library/modules/Buildings.cpp | 92 ++++++++++++++++---------------- library/modules/EventManager.cpp | 6 +-- plugins/eventful.cpp | 6 +-- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 9d672cd58..55f0869a4 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -1182,52 +1182,52 @@ void Buildings::clearBuildings(color_ostream& out) { void Buildings::updateBuildings(color_ostream& out, void* ptr) { - // int32_t id = (int32_t)ptr; - // auto building = df::building::find(id); - - // if (building) - // { - // // Already cached -> weird, so bail out - // if (corner1.count(id)) - // return; - // // Civzones cannot be cached because they can - // // overlap each other and normal buildings. - // if (!building->isSettingOccupancy()) - // return; - - // df::coord p1(min(building->x1, building->x2), min(building->y1,building->y2), building->z); - // df::coord p2(max(building->x1, building->x2), max(building->y1,building->y2), building->z); - - // corner1[id] = p1; - // corner2[id] = p2; - - // for ( int32_t x = p1.x; x <= p2.x; x++ ) { - // for ( int32_t y = p1.y; y <= p2.y; y++ ) { - // df::coord pt(x,y,building->z); - // if (containsTile(building, pt, false)) - // locationToBuilding[pt] = id; - // } - // } - // } - // else if (corner1.count(id)) - // { - // //existing building: destroy it - // df::coord p1 = corner1[id]; - // df::coord p2 = corner2[id]; - - // for ( int32_t x = p1.x; x <= p2.x; x++ ) { - // for ( int32_t y = p1.y; y <= p2.y; y++ ) { - // df::coord pt(x,y,p1.z); - - // auto cur = locationToBuilding.find(pt); - // if (cur != locationToBuilding.end() && cur->second == id) - // locationToBuilding.erase(cur); - // } - // } - - // corner1.erase(id); - // corner2.erase(id); - // } + int32_t id = *((int32_t*)ptr); + auto building = df::building::find(id); + + if (building) + { + // Already cached -> weird, so bail out + if (corner1.count(id)) + return; + // Civzones cannot be cached because they can + // overlap each other and normal buildings. + if (!building->isSettingOccupancy()) + return; + + df::coord p1(min(building->x1, building->x2), min(building->y1,building->y2), building->z); + df::coord p2(max(building->x1, building->x2), max(building->y1,building->y2), building->z); + + corner1[id] = p1; + corner2[id] = p2; + + for ( int32_t x = p1.x; x <= p2.x; x++ ) { + for ( int32_t y = p1.y; y <= p2.y; y++ ) { + df::coord pt(x,y,building->z); + if (containsTile(building, pt, false)) + locationToBuilding[pt] = id; + } + } + } + else if (corner1.count(id)) + { + //existing building: destroy it + df::coord p1 = corner1[id]; + df::coord p2 = corner2[id]; + + for ( int32_t x = p1.x; x <= p2.x; x++ ) { + for ( int32_t y = p1.y; y <= p2.y; y++ ) { + df::coord pt(x,y,p1.z); + + auto cur = locationToBuilding.find(pt); + if (cur != locationToBuilding.end() && cur->second == id) + locationToBuilding.erase(cur); + } + } + + corner1.erase(id); + corner2.erase(id); + } } void Buildings::getStockpileContents(df::building_stockpilest *stockpile, std::vector *items) diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index dfb978022..e2baf9bfb 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -273,7 +273,7 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event } for ( size_t a = 0; a < df::global::world->buildings.all.size(); a++ ) { df::building* b = df::global::world->buildings.all[a]; - Buildings::updateBuildings(out, (void*)b); + Buildings::updateBuildings(out, (void*)&(b->id)); buildings.insert(b->id); } lastSyndromeTime = -1; @@ -609,7 +609,7 @@ static void manageBuildingEvent(color_ostream& out) { buildings.insert(a); for ( auto b = copy.begin(); b != copy.end(); b++ ) { EventHandler bob = (*b).second; - bob.eventHandler(out, (void*)intptr_t(a)); + bob.eventHandler(out, (void*)&a); } } nextBuilding = *df::global::building_next_id; @@ -625,7 +625,7 @@ static void manageBuildingEvent(color_ostream& out) { for ( auto b = copy.begin(); b != copy.end(); b++ ) { EventHandler bob = (*b).second; - bob.eventHandler(out, (void*)intptr_t(id)); + bob.eventHandler(out, (void*)&id); } a = buildings.erase(a); } diff --git a/plugins/eventful.cpp b/plugins/eventful.cpp index 14f1ec26e..365542314 100644 --- a/plugins/eventful.cpp +++ b/plugins/eventful.cpp @@ -183,8 +183,8 @@ void ev_mng_invasion(color_ostream& out, void* ptr) } static void ev_mng_building(color_ostream& out, void* ptr) { - int32_t myId=*(int32_t*)&ptr; - onBuildingCreatedDestroyed(out,myId); + int32_t id = *((int32_t*)ptr); + onBuildingCreatedDestroyed(out, id); } static void ev_mng_inventory(color_ostream& out, void* ptr) { @@ -289,7 +289,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(furnace_hook, fillSidebarMenu); struct product_hook : item_product { typedef item_product interpose_base; - + DEFINE_VMETHOD_INTERPOSE( void, produce, (df::unit *unit, From c21b7bf9419d98b7adcbf156fe226dd16eec01de Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Mar 2017 15:56:50 -0500 Subject: [PATCH 33/43] Add a Painter:key_string() method --- library/lua/gui.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 603c7ab44..b83691acf 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -354,6 +354,10 @@ function Painter:key(code,pen,...) ) end +function Painter:key_string(code, text, ...) + return self:key(code):string(': '):string(text, ...) +end + -------------------------- -- Abstract view object -- -------------------------- From 13cdc38b2f462efadee204b51fe541ca8683fd68 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Mar 2017 15:57:09 -0500 Subject: [PATCH 34/43] Update scripts/gui/extended-status (new bed queueing feature) --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index 76ee1ec38..a05e51095 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 76ee1ec38bf56fce0e48404520ce5e0ebe22702b +Subproject commit a05e51095d9d571213aa33caffb5912468a3e6dc From 43a58f8d85aa61d4994f0bc7352d7bf6e3356de0 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Mar 2017 20:29:46 -0500 Subject: [PATCH 35/43] Remove obsolete settings from Windows build scripts, plus misc. updates - Added BUILD_DOCS=1 to release scripts - Removed "breakfast" scripts, which used the same settings as "all", plus a release version override, which is rarely used (if at all) and can be done separately. --- build/win32/generate-MSVC-all-breakfast.bat | 9 --------- build/win32/generate-MSVC-all.bat | 2 +- build/win32/generate-MSVC-minimal.bat | 2 +- build/win32/generate-MSVC-release.bat | 2 +- build/win64/generate-MSVC-all-breakfast.bat | 9 --------- build/win64/generate-MSVC-all.bat | 2 +- build/win64/generate-MSVC-minimal.bat | 2 +- build/win64/generate-MSVC-release.bat | 2 +- 8 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 build/win32/generate-MSVC-all-breakfast.bat delete mode 100644 build/win64/generate-MSVC-all-breakfast.bat diff --git a/build/win32/generate-MSVC-all-breakfast.bat b/build/win32/generate-MSVC-all-breakfast.bat deleted file mode 100644 index ac26c4f75..000000000 --- a/build/win32/generate-MSVC-all-breakfast.bat +++ /dev/null @@ -1,9 +0,0 @@ -@echo off -IF EXIST DF_PATH.txt SET /P _DF_PATH= Date: Wed, 1 Mar 2017 20:35:27 -0500 Subject: [PATCH 36/43] Update Windows build instructions for 0.43.05 --- docs/Compile.rst | 60 ++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/docs/Compile.rst b/docs/Compile.rst index ac324a9f7..ebf6936c5 100644 --- a/docs/Compile.rst +++ b/docs/Compile.rst @@ -100,6 +100,9 @@ change, so specifying it explicitly is a good idea. cmake .. -DDFHACK_BUILD_ARCH=64 +Note that the scripts in the "build" folder on Windows will set the architecture +automatically. + Other settings -------------- There are a variety of other settings which you can find in CMakeCache.txt in @@ -355,47 +358,34 @@ Dependencies ------------ You will need the following: -* Microsoft Visual Studio 2010 SP1, with the C++ language +* Microsoft Visual Studio 2015, with the C++ language * Git * CMake * Perl with XML::LibXML and XML::LibXSLT * It is recommended to install StrawberryPerl, which includes both. -Microsoft Visual Studio 2010 SP1 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -DFHack has to be compiled with the Microsoft Visual C++ 2010 SP1 toolchain; later -versions won't work against Dwarf Fortress due to ABI and STL incompatibilities. - -At present, the only way to obtain the MSVC C++ 2010 toolchain is to install a -full copy of Microsoft Visual Studio 2010 SP1. The free Express version is sufficient. - -You can grab it from `Microsoft's site `_. - -You should also install the Visual Studio 2010 SP1 update. +* Python (for documentation; optional, except for release builds) -You can confirm whether you have SP1 by opening the Visual Studio 2010 IDE -and selecting About from the Help menu. If you have SP1 it will have *SP1Rel* -at the end of the version number, for example: *Version 10.0.40219.1 SP1Rel* - -Use of pre-SP1 releases has been reported to cause issues and is therefore not -supported by DFHack. Please ensure you are using SP1 before raising any Issues. - -If your Windows Update is configured to receive updates for all Microsoft -Products, not just Windows, you will receive the SP1 update automatically -through Windows Update (you will probably need to trigger a manual check.) +Microsoft Visual Studio 2015 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +DFHack has to be compiled with the Microsoft Visual C++ 2015 toolchain; other +versions won't work against Dwarf Fortress due to ABI and STL incompatibilities. -If not, you can download it directly `from this Microsoft Download link `_. +At present, the only way to obtain the MSVC C++ 2015 toolchain is to install a +full copy of Microsoft Visual Studio 2015. The free Community version is +sufficient. Additional dependencies: installing with the Chocolatey Package Manager ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The remainder of dependencies - Git, CMake and StrawberryPerl - can be most -easily installed using the Chocolatey Package Manger. Chocolatey is a + +The remainder of dependencies - Git, CMake, StrawberryPerl, and Python - can be +most easily installed using the Chocolatey Package Manger. Chocolatey is a \*nix-style package manager for Windows. It's fast, small (8-20MB on disk) and very capable. Think "``apt-get`` for Windows." -Chocolatey is a preferred way of installing the required dependencies -as it's quicker, less effort and will install known-good utilities +Chocolatey is a recommended way of installing the required dependencies +as it's quicker, requires less effort, and will install known-good utilities guaranteed to have the correct setup (especially PATH). To install Chocolatey and the required dependencies: @@ -482,8 +472,10 @@ install XML::LibXML and XML::LibXSLT for it using CPAN. Build ----- -There are several different batch files in the ``build`` folder along -with a script that's used for picking the DF path. +There are several different batch files in the ``win32`` and ``win64`` +subfolders in the ``build`` folder, along with a script that's used for picking +the DF path. Use the subfolder corresponding to the architecture that you want +to build for. First, run ``set_df_path.vbs`` and point the dialog that pops up at a suitable DF installation which is of the appropriate version for the DFHack @@ -501,6 +493,9 @@ solution file(s): in, then hit configure, then generate. More options can appear after the configure step. * ``minimal`` will create a minimal solution with just the bare necessities - the main library and standard plugins. +* ``release`` will create a solution with everything that should be included in + release builds of DFHack. Note that this includes documentation, which requires + Python. Then you can either open the solution with MSVC or use one of the msbuild scripts: @@ -548,9 +543,10 @@ files as detailed above. Building/installing from the Visual Studio IDE: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -After running the CMake generate script you will have a new folder called VC2010. -Open the file ``dfhack.sln`` inside that folder. If you have multiple versions of -Visual Studio installed, make sure you open with Visual Studio 2010. +After running the CMake generate script you will have a new folder called VC2015 +or VC2015_32, depending on the architecture you specified. Open the file +``dfhack.sln`` inside that folder. If you have multiple versions of Visual +Studio installed, make sure you open with Visual Studio 2015. The first thing you must then do is change the build type. It defaults to Debug, but this cannot be used on Windows. Debug is not binary-compatible with DF. From b675f0fd3c62e26b90a44619da696001f2c1ad52 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Mar 2017 20:44:47 -0500 Subject: [PATCH 37/43] Move old git note to bottom of compilation docs --- docs/Compile.rst | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/Compile.rst b/docs/Compile.rst index ebf6936c5..647dbb30b 100644 --- a/docs/Compile.rst +++ b/docs/Compile.rst @@ -31,6 +31,8 @@ To get the latest development code (develop branch), clone as above and then:: git checkout develop git submodule update +Generally, you should only need to clone DFHack once. + **Important note regarding submodule update and changing branches**: You must run ``git submodule update`` every time you change branches, @@ -39,17 +41,9 @@ If a submodule only exists on the newer branch, you also need to run ``git submodule update --init``. Failure to do this may result in strange build errors or "not a known DF version" errors. -**Important note regarding very old git versions** +**More notes**: -If you are using git 1.8.0 or older, and cloned DFHack before commit 85a920d -(around DFHack v0.43.03-alpha1), you may run into fatal git errors when updating -submodules after switching branches. This is due to those versions of git being -unable to handle our change from "scripts/3rdparty/name" submodules to a single -"scripts" submodule. This may be fixable by renaming .git/modules/scripts to -something else and re-running ``git submodule update --init`` on the branch with -the single scripts submodule (and running it again when switching back to the -one with multiple submodules, if necessary), but it is usually much simpler to -upgrade your git version. +* `note-old-git-and-dfhack` Contributing to DFHack ====================== @@ -670,3 +664,21 @@ Chocolatey as outlined in the `Windows section `:: Then close that Admin ``cmd.exe``, re-open another Admin ``cmd.exe``, and run:: pip install sphinx + +Misc. Notes +=========== + +.. _note-old-git-and-dfhack: + +Note on using very old git versions with pre-0.43.03 DFHack versions +-------------------------------------------------------------------- + +If you are using git 1.8.0 or older, and cloned DFHack before commit 85a920d +(around DFHack v0.43.03-alpha1), you may run into fatal git errors when updating +submodules after switching branches. This is due to those versions of git being +unable to handle our change from "scripts/3rdparty/name" submodules to a single +"scripts" submodule. This may be fixable by renaming .git/modules/scripts to +something else and re-running ``git submodule update --init`` on the branch with +the single scripts submodule (and running it again when switching back to the +one with multiple submodules, if necessary), but it is usually much simpler to +upgrade your git version. From 0cc51f8d69f299a2170eb2385ceb18d4df4afb6a Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Mar 2017 21:29:17 -0500 Subject: [PATCH 38/43] Add support for downloading files in advance, useful for offline builds Also document this in Compile.rst - there have been complaints about the fact that DFHack downloads files at build time not being documented at all. --- CMake/DownloadFile.cmake | 21 +++++++++++++++++++++ CMake/downloads/.gitignore | 3 +++ CMake/downloads/README.txt | 3 +++ docs/Compile.rst | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 CMake/downloads/.gitignore create mode 100644 CMake/downloads/README.txt diff --git a/CMake/DownloadFile.cmake b/CMake/DownloadFile.cmake index 8f9938f90..fe9e4e05e 100644 --- a/CMake/DownloadFile.cmake +++ b/CMake/DownloadFile.cmake @@ -9,10 +9,31 @@ function(file_md5_if_exists FILE VAR) endif() endfunction() +function(search_downloads FILE_MD5 VAR) + set(${VAR} "" PARENT_SCOPE) + file(GLOB FILES ${CMAKE_SOURCE_DIR}/CMake/downloads/*) + foreach(FILE ${FILES}) + file(MD5 "${FILE}" CUR_MD5) + if("${CUR_MD5}" STREQUAL "${FILE_MD5}") + set(${VAR} ${FILE} PARENT_SCOPE) + return() + endif() + endforeach() +endfunction() + function(download_file URL DEST EXPECTED_MD5) get_filename_component(FILENAME "${URL}" NAME) file_md5_if_exists("${DEST}" CUR_MD5) + search_downloads(${EXPECTED_MD5} DLPATH) + if(NOT("${DLPATH}" STREQUAL "")) + message("* Copying ${FILENAME} from ${DLPATH}") + execute_process(COMMAND "${CMAKE_COMMAND}" -E copy + "${DLPATH}" + "${DEST}") + return() + endif() + if(NOT "${EXPECTED_MD5}" STREQUAL "${CUR_MD5}") message("* Downloading ${FILENAME}") file(DOWNLOAD "${URL}" "${DEST}" EXPECTED_MD5 "${EXPECTED_MD5}" SHOW_PROGRESS) diff --git a/CMake/downloads/.gitignore b/CMake/downloads/.gitignore new file mode 100644 index 000000000..ff7b252fe --- /dev/null +++ b/CMake/downloads/.gitignore @@ -0,0 +1,3 @@ +* +!README.txt +!.gitignore diff --git a/CMake/downloads/README.txt b/CMake/downloads/README.txt new file mode 100644 index 000000000..40b504725 --- /dev/null +++ b/CMake/downloads/README.txt @@ -0,0 +1,3 @@ +This folder exists as an alternate location for downloaded files. Files will +ordinarily not be downloaded here, but CMake will look for them here anyway to +facilitate offline builds. diff --git a/docs/Compile.rst b/docs/Compile.rst index 647dbb30b..c69d1de29 100644 --- a/docs/Compile.rst +++ b/docs/Compile.rst @@ -43,6 +43,7 @@ build errors or "not a known DF version" errors. **More notes**: +* `note-offline-builds` - read this if your build machine may not have an internet connection! * `note-old-git-and-dfhack` Contributing to DFHack @@ -668,6 +669,37 @@ Then close that Admin ``cmd.exe``, re-open another Admin ``cmd.exe``, and run:: Misc. Notes =========== +.. _note-offline-builds: + +Note on building DFHack offline +------------------------------- + +As of 0.43.05, DFHack downloads several files during the build process, depending +on your target OS and architecture. If your build machine's internet connection +is unreliable, or nonexistent, you can download these files in advance. + +First, you must locate the files you will need. These can be found in the +`dfhack-bin repo `_. Look for the +most recent version number *before or equal to* the DF version which you are +building for. For example, suppose "0.43.05" and "0.43.07" are listed. You should +choose "0.43.05" if you are building for 0.43.05 or 0.43.06, and "0.43.07" if +you are building for 0.43.07 or 0.43.08. + +Then, download all of the files you need, and save them to ``/CMake/downloads/``. The destination filename you choose +does not matter, as long as the files end up in the ``CMake/downloads`` folder. +You need to download all of the files for the architecture(s) you are building +for. For example, if you are building for 32-bit Linux and 64-bit Windows, +download all files starting with ``linux32`` and ``win64``. GitHub should sort +files alphabetically, so all the files you need should be next to each other. + +It is recommended that you create a build folder and run CMake to verify that +you have downloaded everything at this point, assuming your download machine has +CMake installed. This involves running a "generate" batch script on Windows, or +a command starting with ``cmake ..`` on Linux and OS X. CMake should +automatically locate files that you placed in ``CMake/downloads``, and use them +instead of attempting to download them. + .. _note-old-git-and-dfhack: Note on using very old git versions with pre-0.43.03 DFHack versions From 15759808e5a33da4fff2521a51039f2e4abf8da7 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 2 Mar 2017 14:04:14 -0500 Subject: [PATCH 39/43] Fix "plug" output width for generated-creature-renamer --- library/Core.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 642da61ea..198e49df4 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -931,8 +931,8 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v } else if (builtin == "plug") { - const char *header_format = "%25s %10s %4s %8s\n"; - const char *row_format = "%25s %10s %4i %8s\n"; + const char *header_format = "%30s %10s %4s %8s\n"; + const char *row_format = "%30s %10s %4i %8s\n"; con.print(header_format, "Name", "State", "Cmds", "Enabled"); plug_mgr->refresh(); From 334817fa1be79a9f529433ade677a39e08b34c30 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 2 Mar 2017 14:04:34 -0500 Subject: [PATCH 40/43] Add Lua API functions to determine architecture --- library/LuaApi.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 39404e9be..a2446c78a 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1386,6 +1386,16 @@ static std::string getOSType() } } +static int getArchitecture() +{ + return sizeof(void*) * 8; +} + +static std::string getArchitectureName() +{ + return getArchitecture() == 64 ? "x86_64" : "x86"; +} + static std::string getDFVersion() { return Core::getInstance().vinfo->getVersion(); } static uint32_t getTickCount() { return Core::getInstance().p->getTickCount(); } @@ -1403,6 +1413,8 @@ static std::string df2console(std::string s) { return DF2CONSOLE(s); } static const LuaWrapper::FunctionReg dfhack_module[] = { WRAP(getOSType), + WRAP(getArchitecture), + WRAP(getArchitectureName), WRAP(getDFVersion), WRAP(getDFPath), WRAP(getTickCount), From d53c00d726811ed2649d754f42be679a52b09162 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 2 Mar 2017 14:05:08 -0500 Subject: [PATCH 41/43] Update scripts (add install-info) --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index a05e51095..7e8daa168 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit a05e51095d9d571213aa33caffb5912468a3e6dc +Subproject commit 7e8daa16822cc67f8e84adab7607694b622fe434 From 67f39316ce6e105fc99efd957693782b02ed199c Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 2 Mar 2017 14:05:34 -0500 Subject: [PATCH 42/43] Update xml (assorted viewscreen changes) --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index e60c4259a..a292304c6 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit e60c4259ab9ea9326af42173024a3b3e40fe6688 +Subproject commit a292304c6097a499dfa749d5cc8ab24e69e004f5 From 38702febf7077842158c376a4b088288c616f3c4 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 14 Mar 2017 00:24:05 -0400 Subject: [PATCH 43/43] Use LUA_(C)PATH_VAR instead of LUA_(C)PATH in luaconf.h This was apparently changed at some point around Lua 5.3, so a custom LUA_PATH environment variable could prevent DFHack from initializing. --- depends/lua/include/luaconf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/depends/lua/include/luaconf.h b/depends/lua/include/luaconf.h index ce96b4747..051d2a944 100644 --- a/depends/lua/include/luaconf.h +++ b/depends/lua/include/luaconf.h @@ -200,8 +200,8 @@ LUA_CDIR"?.so;" "./?.so" #endif /* } */ -#define LUA_PATH "DFHACK_LUA_PATH" -#define LUA_CPATH "DFHACK_LUA_CPATH" +#define LUA_PATH_VAR "DFHACK_LUA_PATH" +#define LUA_CPATH_VAR "DFHACK_LUA_CPATH" /* @@ LUA_DIRSEP is the directory separator (for submodules).