From 77349e9b8076a717fc9068c88318114a1333bd25 Mon Sep 17 00:00:00 2001 From: Antalia Date: Fri, 9 Mar 2012 20:13:07 +0000 Subject: [PATCH] Added age, currently enabled labors, and skill levels to dwarfexport XML --- plugins/dwarfexport/dwarfexport.cpp | 59 ++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/plugins/dwarfexport/dwarfexport.cpp b/plugins/dwarfexport/dwarfexport.cpp index 6c997ca27..5ac8fb24c 100644 --- a/plugins/dwarfexport/dwarfexport.cpp +++ b/plugins/dwarfexport/dwarfexport.cpp @@ -18,6 +18,8 @@ using namespace std; #include #include #include +#include +#include using namespace DFHack; using df::global::ui; @@ -124,6 +126,58 @@ static void printTraits(Core* c, df::unit* cre, ostream& out) out << " " << endl; } +static int32_t getCreatureAge(df::unit* cre) +{ + int32_t yearDifference = *df::global::cur_year - cre->relations.birth_year; + + // If the birthday this year has not yet passed, subtract one year. + // ASSUMPTION: birth_time is on the same scale as cur_year_tick + if (cre->relations.birth_time >= *df::global::cur_year_tick) { + yearDifference--; + } + + return yearDifference; +} + +static void printLabors(Core* c, df::unit* cre, ostream& out) +{ + // Using British spelling here, consistent with Runesmith + out << " " << endl; + for (int iCount = 0; iCount < sizeof(cre->status.labors); iCount++) + { + if (cre->status.labors[iCount]) { + // Get the caption for the labor index. + df::enums::unit_labor::unit_labor thisLabor = (df::enums::unit_labor::unit_labor)iCount; + element("Labour", get_caption(thisLabor), out); + } + } + out << " " << endl; +} + +static void printSkill(Core* c, df::unit_skill* skill, ostream& out) +{ + out << " " << endl; + + element("Name", get_caption(skill->id), out); + element("Level", skill->rating, out); + + out << " " << endl; +} + +static void printSkills(Core* c, df::unit* cre, ostream& out) +{ + + std::vector vSkills = cre->status.current_soul->skills; + + out << " " << endl; + for (int iCount = 0; iCount < vSkills.size(); iCount++) + { + printSkill(c, vSkills.at(iCount), out); + } + + out << " " << endl; +} + // GDC needs: // Name // Nickname @@ -136,13 +190,16 @@ static void export_dwarf(Core* c, df::unit* cre, ostream& out) { info += Translation::TranslateName(&cre->name, false); info[0] = toupper(info[0]); c->con.print("Exporting %s\n", info.c_str()); - + out << " " << endl; element("Name", info.c_str(), out); element("Nickname", cre->name.nickname.c_str(), out); element("Sex", cre->sex == 0 ? "Female" : "Male", out); + element("Age", getCreatureAge(cre), out); // Added age, active labors, and skills March 9, 2012 printAttributes(c, cre, out); printTraits(c, cre, out); + printLabors(c, cre, out); + printSkills(c, cre, out); out << " " << endl; }