2012-03-22 09:30:15 -06:00
|
|
|
// cursecheck plugin
|
|
|
|
//
|
|
|
|
// check single tile or whole map/world for cursed creatures by checking if a valid curse date (!=-1) is set
|
|
|
|
// if a cursor is active only the selected tile will be observed
|
|
|
|
// without cursor the whole map will be checked
|
|
|
|
// by default cursed creatures will be only counted
|
|
|
|
//
|
|
|
|
// the tool was intended to help finding vampires but it will also list necromancers, werebeasts and zombies
|
|
|
|
//
|
|
|
|
// Options:
|
|
|
|
// detail - print full name, date of birth, date of curse (vamp might use fake identity, though)
|
|
|
|
// show if the creature is active or dead, missing, ghostly (ghost vampires should not exist in 34.05)
|
|
|
|
// identify type of curse (works fine for vanilla ghosts, vamps, werebeasts, zombies and necromancers)
|
2012-03-24 05:02:41 -06:00
|
|
|
// nick - set nickname to type of curse(does not always show up ingame, some vamps don't like nicknames)
|
2012-03-22 09:30:15 -06:00
|
|
|
// all - don't ignore dead and inactive creatures (former ghosts, dead necromancers, ...)
|
|
|
|
// verbose - acts like detail but also lists all curse tags (if you want to know it all).
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "modules/Units.h"
|
|
|
|
#include <modules/Translation.h>
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
|
|
|
#include "df/unit.h"
|
|
|
|
#include "df/unit_soul.h"
|
|
|
|
#include "df/historical_entity.h"
|
|
|
|
#include "df/historical_figure.h"
|
|
|
|
#include "df/historical_figure_info.h"
|
2014-07-29 15:30:22 -06:00
|
|
|
#include "df/identity.h"
|
2012-03-22 09:30:15 -06:00
|
|
|
#include "df/language_name.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/world_raws.h"
|
2014-07-29 15:26:14 -06:00
|
|
|
#include "df/incident.h"
|
2012-03-22 09:30:15 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("cursecheck");
|
2014-12-02 19:44:20 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
REQUIRE_GLOBAL(cursor);
|
|
|
|
|
|
|
|
command_result cursecheck (color_ostream &out, vector <string> & parameters);
|
2012-03-22 09:30:15 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand("cursecheck",
|
2015-11-09 20:37:45 -07:00
|
|
|
"Check for cursed creatures (undead, necromancers...)",
|
2012-03-22 09:30:15 -06:00
|
|
|
cursecheck, false ));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string determineCurse(df::unit * unit)
|
|
|
|
{
|
|
|
|
string cursetype = "unknown";
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2012-03-22 09:30:15 -06:00
|
|
|
// ghosts: ghostly, duh
|
2012-03-25 04:11:00 -06:00
|
|
|
// as of DF 34.05 and higher vampire ghosts and the like should not be possible
|
|
|
|
// if they get reintroduced later it will become necessary to watch 'ghostly' seperately
|
2012-03-22 09:30:15 -06:00
|
|
|
if(unit->flags3.bits.ghostly)
|
|
|
|
cursetype = "ghost";
|
|
|
|
|
|
|
|
// zombies: undead or hate life (according to ag), not bloodsuckers
|
|
|
|
if( (unit->curse.add_tags1.bits.OPPOSED_TO_LIFE || unit->curse.add_tags1.bits.NOT_LIVING)
|
|
|
|
&& !unit->curse.add_tags1.bits.BLOODSUCKER )
|
|
|
|
cursetype = "zombie";
|
|
|
|
|
|
|
|
// necromancers: alive, don't eat, don't drink, don't age
|
2015-02-14 20:53:06 -07:00
|
|
|
if(!unit->curse.add_tags1.bits.NOT_LIVING
|
|
|
|
&& unit->curse.add_tags1.bits.NO_EAT
|
|
|
|
&& unit->curse.add_tags1.bits.NO_DRINK
|
2012-03-22 09:30:15 -06:00
|
|
|
&& unit->curse.add_tags2.bits.NO_AGING
|
|
|
|
)
|
|
|
|
cursetype = "necromancer";
|
|
|
|
|
|
|
|
// werecreatures: alive, DO eat, DO drink, don't age
|
2015-02-14 20:53:06 -07:00
|
|
|
if(!unit->curse.add_tags1.bits.NOT_LIVING
|
|
|
|
&& !unit->curse.add_tags1.bits.NO_EAT
|
|
|
|
&& !unit->curse.add_tags1.bits.NO_DRINK
|
2012-03-22 09:30:15 -06:00
|
|
|
&& unit->curse.add_tags2.bits.NO_AGING )
|
|
|
|
cursetype = "werebeast";
|
|
|
|
|
|
|
|
// vampires: bloodsucker (obvious enough)
|
|
|
|
if(unit->curse.add_tags1.bits.BLOODSUCKER)
|
|
|
|
cursetype = "vampire";
|
|
|
|
|
|
|
|
return cursetype;
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result cursecheck (color_ostream &out, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
CoreSuspender suspend;
|
|
|
|
int32_t cursorX, cursorY, cursorZ;
|
|
|
|
Gui::getCursorCoords(cursorX,cursorY,cursorZ);
|
|
|
|
|
|
|
|
bool giveDetails = false;
|
|
|
|
bool giveNick = false;
|
|
|
|
bool ignoreDead = true;
|
|
|
|
bool verbose = false;
|
|
|
|
size_t cursecount = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < parameters.size();i++)
|
|
|
|
{
|
|
|
|
if(parameters[i] == "help" || parameters[i] == "?")
|
|
|
|
{
|
|
|
|
out.print( " Search for cursed creatures (ghosts, vampires, necromancers, zombies, werebeasts).\n"
|
|
|
|
" With map cursor active only the current tile will be checked.\n"
|
|
|
|
" Without an in-game cursor the whole map/world will be scanned.\n"
|
|
|
|
" By default cursed creatures are only counted to make it more interesting.\n"
|
|
|
|
" By default dead and passive creatures (aka really dead) are ignored.\n"
|
|
|
|
"Options:\n"
|
|
|
|
" detail - show details (name and age shown ingame might differ)\n"
|
|
|
|
" nick - try to set cursetype as nickname (does not always work)\n"
|
|
|
|
" all - include dead and passive creatures\n"
|
|
|
|
" verbose - show all curse tags (if you really want to know it all)\n"
|
|
|
|
);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
if(parameters[i] == "detail")
|
|
|
|
giveDetails = true;
|
|
|
|
if(parameters[i] == "nick")
|
|
|
|
giveNick = true;
|
|
|
|
if(parameters[i] == "all")
|
|
|
|
ignoreDead = false;
|
|
|
|
if(parameters[i] == "verbose")
|
|
|
|
{
|
|
|
|
// verbose makes no sense without enabling details
|
2015-02-14 20:53:06 -07:00
|
|
|
giveDetails = true;
|
2012-03-22 09:30:15 -06:00
|
|
|
verbose = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whole map if no cursor is active
|
|
|
|
bool checkWholeMap = false;
|
|
|
|
if(cursorX == -30000)
|
|
|
|
{
|
|
|
|
out.print("No cursor; will check all units on the map.\n");
|
|
|
|
checkWholeMap = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < world->units.all.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit * unit = world->units.all[i];
|
|
|
|
|
2018-06-08 03:09:11 -06:00
|
|
|
// filter out all "living" units that are currently removed from play
|
2012-03-22 09:30:15 -06:00
|
|
|
// don't spam all completely dead creatures if not explicitly wanted
|
2018-06-14 01:42:45 -06:00
|
|
|
if((!Units::isActive(unit) && !Units::isKilled(unit)) || (Units::isKilled(unit) && ignoreDead))
|
2012-03-22 09:30:15 -06:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bail out if we have a map cursor and creature is not at that specific position
|
|
|
|
if ( !checkWholeMap && (unit->pos.x != cursorX || unit->pos.y != cursorY || unit->pos.z != cursorZ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// non-cursed creatures have curse_year == -1
|
2016-08-10 21:50:00 -06:00
|
|
|
if(unit->curse_year != -1)
|
2012-03-22 09:30:15 -06:00
|
|
|
{
|
|
|
|
cursecount++;
|
|
|
|
|
|
|
|
string cursetype = determineCurse(unit);
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2012-03-22 09:30:15 -06:00
|
|
|
if(giveNick)
|
|
|
|
{
|
2018-05-12 12:59:04 -06:00
|
|
|
Units::setNickname(unit, cursetype); //"CURSED");
|
2012-03-22 09:30:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if(giveDetails)
|
|
|
|
{
|
|
|
|
if(unit->name.has_name)
|
|
|
|
{
|
|
|
|
string firstname = unit->name.first_name;
|
|
|
|
string restofname = Translation::TranslateName(&unit->name, false);
|
|
|
|
firstname[0] = toupper(firstname[0]);
|
|
|
|
|
|
|
|
// if creature has no nickname, restofname will already contain firstname
|
|
|
|
// no need for double output
|
|
|
|
if(restofname.compare(0, firstname.length(),firstname) != 0)
|
|
|
|
out.print("%s ", firstname.c_str());
|
|
|
|
out.print("%s ", restofname.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// happens with unnamed zombies and resurrected body parts
|
|
|
|
out.print("Unnamed creature ");
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:26:14 -06:00
|
|
|
auto death = df::incident::find(unit->counters.death_id);
|
2012-03-22 09:30:15 -06:00
|
|
|
bool missing = false;
|
|
|
|
if (death && !death->flags.bits.discovered)
|
|
|
|
{
|
|
|
|
missing = true;
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2012-03-22 09:30:15 -06:00
|
|
|
out.print("born in %d, cursed in %d to be a %s. (%s%s%s)\n",
|
2016-08-10 21:50:00 -06:00
|
|
|
unit->birth_year,
|
|
|
|
unit->curse_year,
|
2012-03-22 09:30:15 -06:00
|
|
|
cursetype.c_str(),
|
2015-02-14 20:53:06 -07:00
|
|
|
// technically most cursed creatures are undead,
|
2012-03-22 09:30:15 -06:00
|
|
|
// therefore output 'active' if they are not completely dead
|
2018-06-08 03:09:11 -06:00
|
|
|
unit->flags2.bits.killed ? "deceased" : "active",
|
2012-03-22 09:30:15 -06:00
|
|
|
unit->flags3.bits.ghostly ? "-ghostly" : "",
|
|
|
|
missing ? "-missing" : ""
|
|
|
|
);
|
|
|
|
|
|
|
|
if (missing)
|
|
|
|
{
|
|
|
|
out.print("- You can use 'tweak clear-missing' to allow engraving a memorial easier.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// dump all curse flags on demand
|
|
|
|
if (verbose)
|
|
|
|
{
|
2012-03-25 04:11:00 -06:00
|
|
|
out << "Curse flags: "
|
|
|
|
<< bitfield_to_string(unit->curse.add_tags1) << endl
|
|
|
|
<< bitfield_to_string(unit->curse.add_tags2) << endl;
|
2012-03-22 09:30:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkWholeMap)
|
|
|
|
out.print("Number of cursed creatures on map: %d \n", cursecount);
|
|
|
|
else
|
|
|
|
out.print("Number of cursed creatures on tile: %d \n", cursecount);
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2012-03-22 09:30:15 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|