From c659b885b6ab5d6e71a0e5650b7882f99066445e Mon Sep 17 00:00:00 2001 From: Japa Date: Wed, 25 Jan 2017 23:06:03 +0530 Subject: [PATCH 01/17] 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 02/17] 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 03/17] 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 04/17] 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 05/17] 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 b18bd72c05db76d3a33742fec10488986a246cd2 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 6 Feb 2017 10:12:20 +0530 Subject: [PATCH 06/17] 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 07/17] 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 08/17] 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 09/17] 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 10/17] 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 11/17] 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 12/17] 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 13/17] 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 14/17] 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 15/17] 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 16/17] 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 17/17] 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" };