Added more descriptor types, and made it run on world load.

develop
Japa Illo 2017-01-26 15:58:43 +05:30
parent 24a653f77b
commit c3c3f37b06
2 changed files with 78 additions and 69 deletions

@ -233,6 +233,9 @@ enable \
# enable mouse controls and sand indicator in embark screen # enable mouse controls and sand indicator in embark screen
embark-tools enable sticky sand mouse embark-tools enable sticky sand mouse
# Renames generated creatures to reflect the template used to generate them.
enable generated-creature-renamer
########### ###########
# Scripts # # Scripts #
########### ###########

@ -16,18 +16,10 @@ using namespace DFHack;
DFHACK_PLUGIN("generated-creature-renamer"); DFHACK_PLUGIN("generated-creature-renamer");
REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(world);
command_result rename_creatures(color_ostream &out, std::vector <std::string> & parameters);
command_result list_creatures(color_ostream &out, std::vector <std::string> & parameters); command_result list_creatures(color_ostream &out, std::vector <std::string> & parameters);
DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &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( commands.push_back(PluginCommand(
"list-generated", "list-generated",
"Prints a list of generated creature tokens. Use \"list-generated detailed\" to show descriptions.", "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; return CR_OK;
} }
#define NUM_DESC 223 DFHACK_PLUGIN_IS_ENABLED(is_enabled);
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 <std::string> & parameters)
{
if (!parameters.empty())
return CR_WRONG_USAGE;
CoreSuspender suspend;
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; return CR_OK;
} switch (event)
for (int i = 0; i < world->raws.creatures.all.size(); i++)
{ {
auto creatureRaw = world->raws.creatures.all[i]; case DFHack::SC_WORLD_LOADED:
if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED)) CoreSuspender suspend;
continue;
size_t minPos = std::string::npos;
size_t foundIndex = std::string::npos;
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]); return CR_OK;
if (pos < minPos)
{
minPos = pos;
foundIndex = j;
}
} }
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"); auto creatureRaw = world->raws.creatures.all[i];
if (digitPos > creatureRaw->creature_id.length()) if (!creatureRaw->flags.is_set(df::enums::creature_raw_flags::GENERATED))
digitPos = creatureRaw->creature_id.length(); continue;
size_t minPos = std::string::npos;
size_t foundIndex = std::string::npos;
creatureRaw->creature_id.replace(digitPos, std::string::npos, descriptors[foundIndex]); for (size_t j = 0; j < NUM_DESC; j++)
if (descriptorCount[foundIndex] > 0)
{ {
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; return CR_OK;
} }