From 19c43715818af5cdea6ed8f9f6b193d2f1901e9e Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 01:47:15 +0200 Subject: [PATCH 01/13] Add switch -1 to skillmodify.cpp --- tools/playground/skillmodify.cpp | 76 +++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/tools/playground/skillmodify.cpp b/tools/playground/skillmodify.cpp index c53ead8c8..db5eada94 100644 --- a/tools/playground/skillmodify.cpp +++ b/tools/playground/skillmodify.cpp @@ -20,9 +20,10 @@ * - Kill/revive creature(s) with --kill/--revive * - Show skills/labors only when -ss/-sl/-v is given or a skill/labor is changed * - Allow multiple -i switches - * - Display current job * Done: + * - Add switch -1 to only display one line for every creature. Good for an overview. + * - Display current job (has been there all the time, but not shown in Windows due to missing memory offsets) * - Remove magic numbers * - Show social skills only when -ss is given * - Hide hauler labors when +sh is given @@ -82,10 +83,12 @@ using namespace std; #define MAX_MOOD 4 #define NO_MOOD -1 -bool quiet; +bool quiet=true; bool verbose = false; bool showhauler = true; bool showsocial = false; +bool showfirstlineonly = false; + int hauler_labors[] = { LABOR_STONE_HAULING ,LABOR_WOOD_HAULING @@ -120,6 +123,7 @@ void usage(int argc, const char * argv[]) << "-q : Suppress \"Press any key to continue\" at program termination" << endl << "-v : Increase verbosity" << endl << "-c creature : Only show/modify this creature type instead of dwarfes" << endl + << "-1 : Only display one line per creature" << endl << "-i id : Only show/modify creature with this id" << endl << "-nn : Only show/modify creatures with no custom nickname (migrants)" << endl << "--nicks : Only show/modify creatures with custom nickname" << endl @@ -130,7 +134,7 @@ void usage(int argc, const char * argv[]) << "-ral : Remove all labors from creature" << endl << "-ah : Add hauler labors (stone hauling, etc.) to creature" << endl << "-rh : Remove hauler labors (stone hauling, etc.) from creature" << endl - << "--setmood : Set mood to n (-1 = no mood, max=4)" << endl + << "--setmood : Set mood to n (-1 = no mood, max=4, buggy!)" << endl // Doesn't work, because hapiness is recalculated //<< "--sethappiness : Set happiness to n" << endl << "-f : Force an action" << endl @@ -203,51 +207,69 @@ bool is_in(int m, int set[], int set_size) void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, int index) { - cout << "Creature[" << index << "]: " << toCaps(Materials->raceEx[creature.race].rawname); + DFHack::Translation *Tran = DF->getTranslation(); DFHack::VersionInfo *mem = DF->getMemoryInfo(); + string name="(no name)"; if(creature.name.nickname[0]) { - cout << ", " << creature.name.nickname; + name = creature.name.nickname; } else { if(creature.name.first_name[0]) - { - cout << ", " << toCaps(creature.name.first_name); - } - - string transName = Tran->TranslateName(creature.name,false); - if(!transName.empty()) - { - cout << " " << toCaps(transName); - } + { + name = toCaps(creature.name.first_name); + + string transName = Tran->TranslateName(creature.name,false); + if(!transName.empty()) + { + name += " " + toCaps(transName); + } + } } - string prof_string=""; + string profession=""; try { - prof_string = mem->getProfession(creature.profession); + profession = mem->getProfession(creature.profession); } catch (exception& e) { cout << "Error retrieving creature profession: " << e.what() << endl; } - cout << ", " << toCaps(prof_string) << "(" << int(creature.profession) << ")"; - if(creature.custom_profession[0]) { - cout << "/" << creature.custom_profession; + profession = creature.custom_profession; } + + string job="No Job"; if(creature.current_job.active) { - cout << ", current job: " << mem->getJob(creature.current_job.jobId); + job=mem->getJob(creature.current_job.jobId); } - cout << ", Happy = " << creature.happiness; - cout << endl; + if (showfirstlineonly) + { + printf("%3d", index); + printf(" %-32s", name.c_str()); + printf(" %-15s", toCaps(profession).c_str()); + printf(" %-30s", job.c_str()); + printf(" %d", creature.happiness); + + return; + } + else + { + printf("ID: %d", index); + printf(", %s", name.c_str()); + printf(", %s", toCaps(profession).c_str()); + printf(", Job: %s", job.c_str()); + printf(", Happiness: %d", creature.happiness); + printf("\n"); + } if((creature.mood != NO_MOOD) && (creature.mood<=MAX_MOOD)) { @@ -392,6 +414,10 @@ int main (int argc, const char* argv[]) { verbose = true; } + else if(arg_cur == "-1") + { + showfirstlineonly = true; + } else if(arg_cur == "-ss" || arg_cur == "--showsocial") { showsocial = true; @@ -572,6 +598,12 @@ int main (int argc, const char* argv[]) } else { + if (showfirstlineonly) + { + printf("ID Name/nickname Job title Current job Happiness\n"); + printf("--- -------------------------------- --------------- ------------------------------ ---------\n"); + } + vector addrs; for(uint32_t creature_idx = 0; creature_idx < numCreatures; creature_idx++) { From ad93afc1eeb3451fb75e64b2210daf871bf0ee3a Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 06:30:37 +0200 Subject: [PATCH 02/13] Hide skills with level 0 and 0 experience points - Hide skills with level 0 and 0 experience points - Tabs to spaces --- tools/playground/skillmodify.cpp | 86 +++++++++++++++++--------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/tools/playground/skillmodify.cpp b/tools/playground/skillmodify.cpp index db5eada94..1596d1b11 100644 --- a/tools/playground/skillmodify.cpp +++ b/tools/playground/skillmodify.cpp @@ -20,6 +20,7 @@ * - Kill/revive creature(s) with --kill/--revive * - Show skills/labors only when -ss/-sl/-v is given or a skill/labor is changed * - Allow multiple -i switches + * - Hide skills with level 0 and 0 experience points * Done: * - Add switch -1 to only display one line for every creature. Good for an overview. @@ -68,17 +69,17 @@ using namespace std; #define SKILL_FLATTERY 82 #define SKILL_CONSOLING 83 #define SKILL_PACIFICATION 84 -#define LABOR_STONE_HAULING 1 -#define LABOR_WOOD_HAULING 2 -#define LABOR_BURIAL 3 -#define LABOR_FOOD_HAULING 4 -#define LABOR_REFUSE_HAULING 5 -#define LABOR_ITEM_HAULING 6 -#define LABOR_FURNITURE_HAULING 7 -#define LABOR_ANIMAL_HAULING 8 -#define LABOR_CLEANING 9 +#define LABOR_STONE_HAULING 1 +#define LABOR_WOOD_HAULING 2 +#define LABOR_BURIAL 3 +#define LABOR_FOOD_HAULING 4 +#define LABOR_REFUSE_HAULING 5 +#define LABOR_ITEM_HAULING 6 +#define LABOR_FURNITURE_HAULING 7 +#define LABOR_ANIMAL_HAULING 8 +#define LABOR_CLEANING 9 #define LABOR_FEED_PATIENTS_PRISONERS 22 -#define LABOR_RECOVERING_WOUNDED 23 +#define LABOR_RECOVERING_WOUNDED 23 #define NOT_SET INT_MIN #define MAX_MOOD 4 #define NO_MOOD -1 @@ -123,7 +124,7 @@ void usage(int argc, const char * argv[]) << "-q : Suppress \"Press any key to continue\" at program termination" << endl << "-v : Increase verbosity" << endl << "-c creature : Only show/modify this creature type instead of dwarfes" << endl - << "-1 : Only display one line per creature" << endl + << "-1 : Only display one line per creature" << endl << "-i id : Only show/modify creature with this id" << endl << "-nn : Only show/modify creatures with no custom nickname (migrants)" << endl << "--nicks : Only show/modify creatures with custom nickname" << endl @@ -220,15 +221,15 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in else { if(creature.name.first_name[0]) - { - name = toCaps(creature.name.first_name); - - string transName = Tran->TranslateName(creature.name,false); - if(!transName.empty()) - { - name += " " + toCaps(transName); - } - } + { + name = toCaps(creature.name.first_name); + + string transName = Tran->TranslateName(creature.name,false); + if(!transName.empty()) + { + name += " " + toCaps(transName); + } + } } string profession=""; @@ -241,34 +242,34 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in } if(creature.custom_profession[0]) { - profession = creature.custom_profession; + profession = creature.custom_profession; } string job="No Job"; if(creature.current_job.active) { - job=mem->getJob(creature.current_job.jobId); + job=mem->getJob(creature.current_job.jobId); } if (showfirstlineonly) { - printf("%3d", index); - printf(" %-32s", name.c_str()); - printf(" %-15s", toCaps(profession).c_str()); - printf(" %-30s", job.c_str()); - printf(" %d", creature.happiness); + printf("%3d", index); + printf(" %-32s", name.c_str()); + printf(" %-15s", toCaps(profession).c_str()); + printf(" %-30s", job.c_str()); + printf(" %d", creature.happiness); - return; + return; } else { - printf("ID: %d", index); - printf(", %s", name.c_str()); - printf(", %s", toCaps(profession).c_str()); - printf(", Job: %s", job.c_str()); - printf(", Happiness: %d", creature.happiness); - printf("\n"); + printf("ID: %d", index); + printf(", %s", name.c_str()); + printf(", %s", toCaps(profession).c_str()); + printf(", Job: %s", job.c_str()); + printf(", Happiness: %d", creature.happiness); + printf("\n"); } if((creature.mood != NO_MOOD) && (creature.mood<=MAX_MOOD)) @@ -311,8 +312,11 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in skillname = "Unknown skill"; cout << e.what() << endl; } - cout << "(Skill " << int(skillid) << ") " << setw(16) << skillname << ": " - << skillrating << "/" << skillexperience << endl; + if (skillrating > 0 || skillexperience > 0) + { + cout << "(Skill " << int(skillid) << ") " << setw(16) << skillname << ": " + << skillrating << "/" << skillexperience << endl; + } } } @@ -598,11 +602,11 @@ int main (int argc, const char* argv[]) } else { - if (showfirstlineonly) - { - printf("ID Name/nickname Job title Current job Happiness\n"); - printf("--- -------------------------------- --------------- ------------------------------ ---------\n"); - } + if (showfirstlineonly) + { + printf("ID Name/nickname Job title Current job Happiness\n"); + printf("--- -------------------------------- --------------- ------------------------------ ---------\n"); + } vector addrs; for(uint32_t creature_idx = 0; creature_idx < numCreatures; creature_idx++) From 30d5bfbf4702d88c0325beb93db4c9681b2aa549 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 11:55:18 +0200 Subject: [PATCH 03/13] Show creature type (again) --- tools/playground/skillmodify.cpp | 38 +++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tools/playground/skillmodify.cpp b/tools/playground/skillmodify.cpp index 1596d1b11..21ded8a57 100644 --- a/tools/playground/skillmodify.cpp +++ b/tools/playground/skillmodify.cpp @@ -23,6 +23,7 @@ * - Hide skills with level 0 and 0 experience points * Done: + * - Show creature type (again) * - Add switch -1 to only display one line for every creature. Good for an overview. * - Display current job (has been there all the time, but not shown in Windows due to missing memory offsets) * - Remove magic numbers @@ -176,13 +177,26 @@ DFHack::Creatures * Creatures = NULL; std::string toCaps(std::string s) { const int length = s.length(); + bool caps=true; if (length == 0) { return s; } - s[0] = std::toupper(s[0]); - for(int i=1; i!=length ; ++i) + for(int i=0; i!=length ; ++i) { - s[i] = std::tolower(s[i]); + if (caps) + { + s[i] = std::toupper(s[i]); + caps = false; + } + else if (s[i] == '_' || s[i] == ' ') + { + s[i] = ' '; + caps = true; + } + else + { + s[i] = std::tolower(s[i]); + } } return s; } @@ -213,6 +227,12 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in DFHack::Translation *Tran = DF->getTranslation(); DFHack::VersionInfo *mem = DF->getMemoryInfo(); + string type="(no type)"; + if (Materials->raceEx[creature.race].rawname[0]) + { + type = toCaps(Materials->raceEx[creature.race].rawname); + } + string name="(no name)"; if(creature.name.nickname[0]) { @@ -255,8 +275,9 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in if (showfirstlineonly) { printf("%3d", index); + printf(" %-17s", type.c_str()); printf(" %-32s", name.c_str()); - printf(" %-15s", toCaps(profession).c_str()); + printf(" %-16s", toCaps(profession).c_str()); printf(" %-30s", job.c_str()); printf(" %d", creature.happiness); @@ -265,6 +286,7 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in else { printf("ID: %d", index); + printf(", %s", type.c_str()); printf(", %s", name.c_str()); printf(", %s", toCaps(profession).c_str()); printf(", Job: %s", job.c_str()); @@ -344,8 +366,8 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in if(creature.flags1.bits.skeleton) { cout << "Flag: Skeletal" << endl; } if(creature.flags1.bits.zombie) { cout << "Flag: Zombie" << endl; } if(creature.flags1.bits.tame) { cout << "Flag: Tame" << endl; } - if(creature.flags1.bits.royal_guard){ cout << "Flag: Royal_guard" << endl; } - if(creature.flags1.bits.fortress_guard){cout<<"Flag: Fortress_guard" << endl; } + if(creature.flags1.bits.royal_guard){ cout << "Flag: Royal guard" << endl; } + if(creature.flags1.bits.fortress_guard){cout<<"Flag: Fortress guard" << endl; } /* FLAGS 2 */ if(creature.flags2.bits.killed) { cout << "Flag: Killed by kill function" << endl; } if(creature.flags2.bits.resident) { cout << "Flag: Resident" << endl; } @@ -604,8 +626,8 @@ int main (int argc, const char* argv[]) { if (showfirstlineonly) { - printf("ID Name/nickname Job title Current job Happiness\n"); - printf("--- -------------------------------- --------------- ------------------------------ ---------\n"); + printf("ID Type Name/nickname Job title Current job Happiness\n"); + printf("--- ----------------- -------------------------------- ---------------- ------------------------------ ---------\n"); } vector addrs; From 1d1c10601d7cb9fc8455799e13e8b9011feee1e9 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 12:47:50 +0200 Subject: [PATCH 04/13] Add --showdead flag to also display dead creatures - Add --showdead flag to also display dead creatures - Display more creature flags - Updated usage() --- tools/playground/skillmodify.cpp | 58 ++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/tools/playground/skillmodify.cpp b/tools/playground/skillmodify.cpp index 21ded8a57..4e00ffa71 100644 --- a/tools/playground/skillmodify.cpp +++ b/tools/playground/skillmodify.cpp @@ -23,8 +23,10 @@ * - Hide skills with level 0 and 0 experience points * Done: + * - Add --showdead flag to also display dead creatures + * - Display more creature flags * - Show creature type (again) - * - Add switch -1 to only display one line for every creature. Good for an overview. + * - Add switch -1/--summary to only display one line for every creature. Good for an overview. * - Display current job (has been there all the time, but not shown in Windows due to missing memory offsets) * - Remove magic numbers * - Show social skills only when -ss is given @@ -90,6 +92,7 @@ bool verbose = false; bool showhauler = true; bool showsocial = false; bool showfirstlineonly = false; +bool showdead = false; int hauler_labors[] = { LABOR_STONE_HAULING @@ -122,14 +125,19 @@ void usage(int argc, const char * argv[]) cout << "Usage:" << endl << argv[0] << " [option 1] [option 2] [...]" << endl + << endl + << "Display options:" << endl << "-q : Suppress \"Press any key to continue\" at program termination" << endl << "-v : Increase verbosity" << endl << "-c creature : Only show/modify this creature type instead of dwarfes" << endl - << "-1 : Only display one line per creature" << endl + << "-1/--summary : Only display one line per creature" << endl << "-i id : Only show/modify creature with this id" << endl - << "-nn : Only show/modify creatures with no custom nickname (migrants)" << endl + << "-nn/--nonicks : Only show/modify creatures with no custom nickname (migrants)" << endl << "--nicks : Only show/modify creatures with custom nickname" << endl << "-ll : List available labors" << endl + << "--showdead : Also show/modify dead creatures" << endl + << endl + << "Modifying options:" << endl << "-al : Add labor to creature" << endl << "-rl : Remove labor from creature" << endl << "-ras : Remove all skills from creature" << endl @@ -279,7 +287,11 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in printf(" %-32s", name.c_str()); printf(" %-16s", toCaps(profession).c_str()); printf(" %-30s", job.c_str()); - printf(" %d", creature.happiness); + printf(" %5d", creature.happiness); + if (showdead) + { + printf(" %-5s", creature.flags1.bits.dead ? "Dead" : "Alive"); + } return; } @@ -361,13 +373,21 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in } } /* FLAGS 1 */ - if(creature.flags1.bits.dead) { cout << "Flag: Dead" << endl; } - if(creature.flags1.bits.on_ground) { cout << "Flag: On the ground" << endl; } - if(creature.flags1.bits.skeleton) { cout << "Flag: Skeletal" << endl; } - if(creature.flags1.bits.zombie) { cout << "Flag: Zombie" << endl; } - if(creature.flags1.bits.tame) { cout << "Flag: Tame" << endl; } - if(creature.flags1.bits.royal_guard){ cout << "Flag: Royal guard" << endl; } - if(creature.flags1.bits.fortress_guard){cout<<"Flag: Fortress guard" << endl; } + if(creature.flags1.bits.dead) { cout << "Flag: Dead" << endl; } + if(creature.flags1.bits.on_ground) { cout << "Flag: On the ground" << endl; } + if(creature.flags1.bits.skeleton) { cout << "Flag: Skeletal" << endl; } + if(creature.flags1.bits.zombie) { cout << "Flag: Zombie" << endl; } + if(creature.flags1.bits.tame) { cout << "Flag: Tame" << endl; } + if(creature.flags1.bits.active_invader) { cout << toCaps("Flag: active_invader") << endl; } + if(creature.flags1.bits.hidden_in_ambush) { cout << toCaps("Flag: hidden_in_ambush") << endl; } + if(creature.flags1.bits.invader_origin) { cout << toCaps("Flag: invader_origin") << endl; } + if(creature.flags1.bits.coward) { cout << toCaps("Flag: coward") << endl; } + if(creature.flags1.bits.hidden_ambusher) { cout << toCaps("Flag: hidden_ambusher") << endl; } + if(creature.flags1.bits.caged) { cout << toCaps("Flag: caged") << endl; } + if(creature.flags1.bits.chained) { cout << toCaps("Flag: chained") << endl; } + if(creature.flags1.bits.royal_guard) { cout << "Flag: Royal guard" << endl; } + if(creature.flags1.bits.fortress_guard) { cout << "Flag: Fortress guard" << endl; } + /* FLAGS 2 */ if(creature.flags2.bits.killed) { cout << "Flag: Killed by kill function" << endl; } if(creature.flags2.bits.resident) { cout << "Flag: Resident" << endl; } @@ -440,7 +460,7 @@ int main (int argc, const char* argv[]) { verbose = true; } - else if(arg_cur == "-1") + else if(arg_cur == "-1" || arg_cur == "--summary") { showfirstlineonly = true; } @@ -452,6 +472,10 @@ int main (int argc, const char* argv[]) { showhauler = false; } + else if(arg_cur == "--showdead") + { + showdead = true; + } else if(arg_cur == "-ras") { remove_skills = true; @@ -519,7 +543,7 @@ int main (int argc, const char* argv[]) { remove_hauler = true; } - else if(arg_cur == "-nn") + else if(arg_cur == "-nn" || arg_cur == "--nonicks") { find_nonicks = true; } @@ -626,8 +650,8 @@ int main (int argc, const char* argv[]) { if (showfirstlineonly) { - printf("ID Type Name/nickname Job title Current job Happiness\n"); - printf("--- ----------------- -------------------------------- ---------------- ------------------------------ ---------\n"); + printf("ID Type Name/nickname Job title Current job Happy%s\n", showdead?" Dead ":""); + printf("--- ----------------- -------------------------------- ---------------- ------------------------------ -----%s\n", showdead?" -----":""); } vector addrs; @@ -648,7 +672,7 @@ int main (int argc, const char* argv[]) || (find_nicks == true && hasnick == true) || (find_nicks == false && find_nonicks == false)) && (find_nonicks == false || creature.name.nickname[0] == '\0') - && (!creature.flags1.bits.dead) + && (showdead == true || !creature.flags1.bits.dead) ) { printCreature(DF,creature,creature_idx); @@ -674,7 +698,7 @@ int main (int argc, const char* argv[]) { cout << "Not changing creature because none of -c (other than dwarf), -i or -nn was" << endl - << "selected. Add -f to still do mass designation." << endl; + << "selected. Add -f (force) to override this safety measure." << endl; dochange = false; } From 547dbe05faa3bf02f9ca5254fd5d3ea5b72f6421 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 13:22:14 +0200 Subject: [PATCH 05/13] Add --showallflags flag to display all flags Add --showallflags flag to display all flags of a creature. (Default: Display a few important ones.) --- tools/playground/skillmodify.cpp | 121 ++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 26 deletions(-) diff --git a/tools/playground/skillmodify.cpp b/tools/playground/skillmodify.cpp index 4e00ffa71..0f6a04a9f 100644 --- a/tools/playground/skillmodify.cpp +++ b/tools/playground/skillmodify.cpp @@ -23,6 +23,7 @@ * - Hide skills with level 0 and 0 experience points * Done: + * - Add --showallflags flag to display all flags (default: display a few important ones) * - Add --showdead flag to also display dead creatures * - Display more creature flags * - Show creature type (again) @@ -93,6 +94,7 @@ bool showhauler = true; bool showsocial = false; bool showfirstlineonly = false; bool showdead = false; +bool showallflags = false; int hauler_labors[] = { LABOR_STONE_HAULING @@ -136,6 +138,7 @@ void usage(int argc, const char * argv[]) << "--nicks : Only show/modify creatures with custom nickname" << endl << "-ll : List available labors" << endl << "--showdead : Also show/modify dead creatures" << endl + << "--showallflags: Show all flags of a creature" << endl << endl << "Modifying options:" << endl << "-al : Add labor to creature" << endl @@ -372,33 +375,95 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in cout << "(Labor " << i << ") " << setw(16) << laborname << endl; } } - /* FLAGS 1 */ - if(creature.flags1.bits.dead) { cout << "Flag: Dead" << endl; } - if(creature.flags1.bits.on_ground) { cout << "Flag: On the ground" << endl; } - if(creature.flags1.bits.skeleton) { cout << "Flag: Skeletal" << endl; } - if(creature.flags1.bits.zombie) { cout << "Flag: Zombie" << endl; } - if(creature.flags1.bits.tame) { cout << "Flag: Tame" << endl; } - if(creature.flags1.bits.active_invader) { cout << toCaps("Flag: active_invader") << endl; } - if(creature.flags1.bits.hidden_in_ambush) { cout << toCaps("Flag: hidden_in_ambush") << endl; } - if(creature.flags1.bits.invader_origin) { cout << toCaps("Flag: invader_origin") << endl; } - if(creature.flags1.bits.coward) { cout << toCaps("Flag: coward") << endl; } - if(creature.flags1.bits.hidden_ambusher) { cout << toCaps("Flag: hidden_ambusher") << endl; } - if(creature.flags1.bits.caged) { cout << toCaps("Flag: caged") << endl; } - if(creature.flags1.bits.chained) { cout << toCaps("Flag: chained") << endl; } - if(creature.flags1.bits.royal_guard) { cout << "Flag: Royal guard" << endl; } - if(creature.flags1.bits.fortress_guard) { cout << "Flag: Fortress guard" << endl; } - - /* FLAGS 2 */ - if(creature.flags2.bits.killed) { cout << "Flag: Killed by kill function" << endl; } - if(creature.flags2.bits.resident) { cout << "Flag: Resident" << endl; } - if(creature.flags2.bits.gutted) { cout << "Flag: Gutted" << endl; } - if(creature.flags2.bits.slaughter) { cout << "Flag: Marked for slaughter" << endl; } - if(creature.flags2.bits.underworld) { cout << "Flag: From the underworld" << endl; } - - if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) ) + if (showallflags) { - string artifact_name = Tran->TranslateName(creature.artifact_name,false); - cout << "Artifact: " << artifact_name << endl; + DFHack::t_creaturflags1 f1 = creature.flags1; + DFHack::t_creaturflags2 f2 = creature.flags2; + + if(f1.bits.had_mood){cout<TranslateName(creature.artifact_name,false); + cout << "Artifact: " << artifact_name << endl; + } } } @@ -476,6 +541,10 @@ int main (int argc, const char* argv[]) { showdead = true; } + else if(arg_cur == "--showallflags") + { + showallflags = true; + } else if(arg_cur == "-ras") { remove_skills = true; From 841c4b042cc1c06a14e8e58c69508ad9295a4f08 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 14:42:53 +0200 Subject: [PATCH 06/13] Kill creature(s) with --kill --- tools/playground/skillmodify.cpp | 73 ++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/tools/playground/skillmodify.cpp b/tools/playground/skillmodify.cpp index 0f6a04a9f..552f59964 100644 --- a/tools/playground/skillmodify.cpp +++ b/tools/playground/skillmodify.cpp @@ -1,13 +1,14 @@ /********************************************* - * skillmodify.cpp - * * Purpose: * * - Display creatures * - Modify skills and labors of creatures + * - Kill creatures + * - Etc. * * Version: 0.1.1 * Date: 2011-04-07 + * Author: raoulxq (based on creaturedump.cpp from peterix) * Todo: * - Option to add/remove single skills @@ -17,12 +18,13 @@ * - Filter by last name with -ln * - Add pattern matching (or at least matching) to -n/-fn/-ln * - Set nickname with --setnick (only if -i is given) - * - Kill/revive creature(s) with --kill/--revive + * - Revive creature(s) with --revive * - Show skills/labors only when -ss/-sl/-v is given or a skill/labor is changed * - Allow multiple -i switches - * - Hide skills with level 0 and 0 experience points * Done: + * - Kill creature(s) with --kill + * - Hide skills with level 0 and 0 experience points * - Add --showallflags flag to display all flags (default: display a few important ones) * - Add --showdead flag to also display dead creatures * - Display more creature flags @@ -148,6 +150,7 @@ void usage(int argc, const char * argv[]) << "-ah : Add hauler labors (stone hauling, etc.) to creature" << endl << "-rh : Remove hauler labors (stone hauling, etc.) from creature" << endl << "--setmood : Set mood to n (-1 = no mood, max=4, buggy!)" << endl + << "--kill : Kill creature(s) (may need to be called multiple times)" << endl // Doesn't work, because hapiness is recalculated //<< "--sethappiness : Set happiness to n" << endl << "-f : Force an action" << endl @@ -481,6 +484,7 @@ int main (int argc, const char* argv[]) bool find_nicks = false; bool remove_skills = false; bool remove_labors = false; + bool kill_creature = false; bool make_hauler = false; bool remove_hauler = false; bool add_labor = false; @@ -600,6 +604,12 @@ int main (int argc, const char* argv[]) set_happiness_n = arg_next_int; i++; } + else if(arg_cur == "--kill") + { + kill_creature = true; + showallflags = true; + showdead = true; + } else if(arg_cur == "-ral") { remove_labors = true; @@ -751,6 +761,7 @@ int main (int argc, const char* argv[]) remove_skills || remove_labors || add_labor || remove_labor || make_hauler || remove_hauler + || kill_creature || set_happiness || set_mood ); @@ -775,6 +786,60 @@ int main (int argc, const char* argv[]) { if(creature.has_default_soul) { + if (kill_creature) + { + /* + [quote author=Eldrick Tobin link=topic=58809.msg2178545#msg2178545 date=1302638055] + + After extensive testing that just ate itself -.-; + + Runesmith does not unset the following: + - Active Invader (sets if they are just about the invade, as Currently + Invading removes this one) + - Hidden Ambusher (Just in Case, however it is still set when an Active Invader) + - Hidden in Ambush (Just in Case, however it is still set when an Active Invader, + until discovery) + - Incoming (Sets if something is here yet... wave X of a siege here) + - Invader -Fleeing/Leaving + - Currently Invading + + When it nukes something it basically just sets them to 'dead'. It does not also + set them to 'killed'. Show dead will show everything (short of 'vanished'/'deleted' + I'd suspect) so one CAN go through the intensive process to revive a broken siege. These + particular flags are not visible at the same exact time so multiple passes -even through + a narrow segment- are advised. + + Problem I ran into (last thing before I mention something more DFHack related): + I set the Killed Flag (but not dead), and I got mortally wounded siegers that refused to + just pift in Magma. [color=purple]Likely missing upper torsoes on examination[/color]. + + */ + DFHack::t_creaturflags1 f1 = creature.flags1; + DFHack::t_creaturflags2 f2 = creature.flags2; + + f1.bits.dead = 1; + f2.bits.killed = 1; + f1.bits.active_invader = 0; /*!< 17: Active invader (for organized ones) */ + f1.bits.hidden_ambusher = 0; /*!< 21: Active marauder/invader moving inward? */ + f1.bits.hidden_in_ambush = 0; + f1.bits.invades = 0; /*!< 22: Marauder resident/invader moving in all the way */ + + cout << "Setting f1.bits.dead = 1" << endl; + cout << "Setting f2.bits.killed = 1" << endl; + cout << "Setting f1.bits.active_invader = 0" << endl; + cout << "Setting f1.bits.hidden_ambusher = 0" << endl; + cout << "Setting f1.bits.hidden_in_ambush = 0" << endl; + cout << "Setting f1.bits.invades = 0" << endl; + cout << "Writing flags..." << endl; + if (!Creatures->WriteFlags(creature_idx, f1.whole, f2.whole)) + { + cout << "Error writing creature flags!" << endl; + } + // We want the flags to be shown after our modification, but they are not read back + creature.flags1 = f1; + creature.flags2 = f2; + } + if (set_mood) { cout << "Setting mood to " << set_mood_n << "..." << endl; From 2d1f1b45af265a0adfeee73cd588e8a58a01ffe1 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 14:47:53 +0200 Subject: [PATCH 07/13] Renamed dfskillmodify to dfcreature. --- tools/playground/CMakeLists.txt | 10 ++++++---- tools/playground/{skillmodify.cpp => creature.cpp} | 0 2 files changed, 6 insertions(+), 4 deletions(-) rename tools/playground/{skillmodify.cpp => creature.cpp} (100%) diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index 21dbbe6c7..14db195b8 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -80,11 +80,13 @@ DFHACK_TOOL(dfprinttiletypes printtiletypes.cpp) # Will have many options in the future. DFHACK_TOOL(dfhellhole hellhole.cpp) -# skillmodify +# dfcreature # Author: raoulxq -# Lets modify skills and labors of dwarfs and other creatures -# Allows mass-modify, esp. for all immigrants -DFHACK_TOOL(dfskillmodify skillmodify.cpp) +# - Display creatures +# - Modify skills and labors of creatures +# - Kill creatures +# - Etc. +DFHACK_TOOL(dfcreature creature.cpp) # digpattern # Author: raoulxq diff --git a/tools/playground/skillmodify.cpp b/tools/playground/creature.cpp similarity index 100% rename from tools/playground/skillmodify.cpp rename to tools/playground/creature.cpp From 21e499f69d481372559e7235374c36ee74c1ffab Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Wed, 13 Apr 2011 15:42:52 +0200 Subject: [PATCH 08/13] Fix for display issues - Switch -i didn't work without -c for non-dwarfs - Enable killing of non-dwarf children --- tools/playground/creature.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/playground/creature.cpp b/tools/playground/creature.cpp index 552f59964..66e6351a0 100644 --- a/tools/playground/creature.cpp +++ b/tools/playground/creature.cpp @@ -23,6 +23,7 @@ * - Allow multiple -i switches * Done: + * - Rename from skillmodify.cpp to creature.cpp * - Kill creature(s) with --kill * - Hide skills with level 0 and 0 experience points * - Add --showallflags flag to display all flags (default: display a few important ones) @@ -75,6 +76,7 @@ using namespace std; #define SKILL_FLATTERY 82 #define SKILL_CONSOLING 83 #define SKILL_PACIFICATION 84 + #define LABOR_STONE_HAULING 1 #define LABOR_WOOD_HAULING 2 #define LABOR_BURIAL 3 @@ -90,6 +92,9 @@ using namespace std; #define MAX_MOOD 4 #define NO_MOOD -1 +#define PROFESSION_CHILD 96 +#define PROFESSION_BABY 97 + bool quiet=true; bool verbose = false; bool showhauler = true; @@ -299,6 +304,8 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in printf(" %-5s", creature.flags1.bits.dead ? "Dead" : "Alive"); } + printf("\n"); + return; } else @@ -468,6 +475,7 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in cout << "Artifact: " << artifact_name << endl; } } + cout << endl; } int main (int argc, const char* argv[]) @@ -479,7 +487,7 @@ int main (int argc, const char* argv[]) string creature_type = "Dwarf"; string creature_id = ""; - int creature_id_int = 0; + int creature_id_int = NOT_SET; bool find_nonicks = false; bool find_nicks = false; bool remove_skills = false; @@ -639,6 +647,7 @@ int main (int argc, const char* argv[]) { creature_id = argv[i+1]; sscanf(argv[i+1], "%d", &creature_id_int); + creature_type = ""; // if -i is given, match all creatures i++; } else @@ -742,10 +751,9 @@ int main (int argc, const char* argv[]) bool hasnick = (creature.name.nickname[0] != '\0'); if ( - // Check for -i - (creature_id.empty() || creature_idx == creature_id_int) - // Check for -c - && (creature_type.empty() || toCaps(string(Materials->raceEx[creature.race].rawname)) == toCaps(creature_type)) + // Check for -i and -c + (creature_idx == creature_id_int + || toCaps(string(Materials->raceEx[creature.race].rawname)) == toCaps(creature_type)) // Check for -nn && ((find_nonicks == true && hasnick == false) || (find_nicks == true && hasnick == true) @@ -766,8 +774,8 @@ int main (int argc, const char* argv[]) || set_mood ); - // 96=Child, 97=Baby - if (creature.profession == 96 || creature.profession == 97) + if (toCaps(creature_type) == "Dwarf" + && (creature.profession == PROFESSION_CHILD || creature.profession == PROFESSION_BABY)) { dochange = false; } @@ -921,7 +929,6 @@ int main (int argc, const char* argv[]) } printCreature(DF,creature,creature_idx); } /* End remove skills/labors */ - cout << endl; } /* if (print creature) */ } /* End for(all creatures) */ } /* End if (we need to walk creatures) */ From c3f7d6f2b2db8efc580efd3843c4ea4a1c650430 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Thu, 14 Apr 2011 14:53:55 +0200 Subject: [PATCH 09/13] Switch -c all to show all creatures --- tools/playground/creature.cpp | 63 +++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/tools/playground/creature.cpp b/tools/playground/creature.cpp index 66e6351a0..47f702cdc 100644 --- a/tools/playground/creature.cpp +++ b/tools/playground/creature.cpp @@ -21,8 +21,15 @@ * - Revive creature(s) with --revive * - Show skills/labors only when -ss/-sl/-v is given or a skill/labor is changed * - Allow multiple -i switches + * - Make -1 the default for everything but -i + * - Imply -i if first argument is a number + * - Search for nick/profession if first argument is a string without - (i.e. no switch) + * - Switch --showhappy + * - Switch --makefriendly + * - Switch --listskills, showing first 3 important skills * Done: + * - Switch -c all shows all creatures * - Rename from skillmodify.cpp to creature.cpp * - Kill creature(s) with --kill * - Hide skills with level 0 and 0 experience points @@ -136,29 +143,30 @@ void usage(int argc, const char * argv[]) << argv[0] << " [option 1] [option 2] [...]" << endl << endl << "Display options:" << endl - << "-q : Suppress \"Press any key to continue\" at program termination" << endl - << "-v : Increase verbosity" << endl - << "-c creature : Only show/modify this creature type instead of dwarfes" << endl - << "-1/--summary : Only display one line per creature" << endl - << "-i id : Only show/modify creature with this id" << endl - << "-nn/--nonicks : Only show/modify creatures with no custom nickname (migrants)" << endl - << "--nicks : Only show/modify creatures with custom nickname" << endl - << "-ll : List available labors" << endl - << "--showdead : Also show/modify dead creatures" << endl - << "--showallflags: Show all flags of a creature" << endl + << "-q : Suppress \"Press any key to continue\" at program termination" << endl + << "-v : Increase verbosity" << endl + << "-c creature : Show/modify this creature type instead of dwarfes ('all' to show all creatures)" << endl + << "-1/--summary : Only display one line per creature" << endl + << "-i id : Only show/modify creature with this id" << endl + << "-nn/--nonicks : Only show/modify creatures with no custom nickname (migrants)" << endl + << "--nicks : Only show/modify creatures with custom nickname" << endl + << "-ll/--listlabors: List available labors" << endl + << "--showdead : Also show/modify dead creatures" << endl + << "--showallflags : Show all flags of a creature" << endl << endl << "Modifying options:" << endl - << "-al : Add labor to creature" << endl - << "-rl : Remove labor from creature" << endl - << "-ras : Remove all skills from creature" << endl - << "-ral : Remove all labors from creature" << endl - << "-ah : Add hauler labors (stone hauling, etc.) to creature" << endl - << "-rh : Remove hauler labors (stone hauling, etc.) from creature" << endl - << "--setmood : Set mood to n (-1 = no mood, max=4, buggy!)" << endl - << "--kill : Kill creature(s) (may need to be called multiple times)" << endl - // Doesn't work, because hapiness is recalculated + << "-al : Add labor to creature" << endl + << "-rl : Remove labor from creature" << endl + << "-ras : Remove all skills from creature" << endl + << "-ral : Remove all labors from creature" << endl + << "-ah : Add hauler labors (stone hauling, etc.) to creature" << endl + << "-rh : Remove hauler labors (stone hauling, etc.) from creature" << endl + // Disabling mood doesn't work as intented + << "--setmood : Set mood to n (-1 = no mood, max=4, buggy!)" << endl + << "--kill : Kill creature(s) (may need to be called multiple times)" << endl + // Setting happiness doesn't work, because hapiness is recalculated //<< "--sethappiness : Set happiness to n" << endl - << "-f : Force an action" << endl + << "-f : Force an action" << endl << endl << "Example 1: Show all dwarfs" << endl << argv[0] << " -c Dwarf" << endl @@ -566,7 +574,7 @@ int main (int argc, const char* argv[]) force_massdesignation = true; } // list labors - else if(arg_cur == "-ll") + else if(arg_cur == "-ll" || arg_cur == "--listlabors") { list_labors = true; } @@ -753,7 +761,8 @@ int main (int argc, const char* argv[]) if ( // Check for -i and -c (creature_idx == creature_id_int - || toCaps(string(Materials->raceEx[creature.race].rawname)) == toCaps(creature_type)) + || toCaps(string(Materials->raceEx[creature.race].rawname)) == toCaps(creature_type) + || "All" == toCaps(creature_type)) // Check for -nn && ((find_nonicks == true && hasnick == false) || (find_nicks == true && hasnick == true) @@ -850,8 +859,18 @@ int main (int argc, const char* argv[]) if (set_mood) { + /* Doesn't really work to disable a mood */ cout << "Setting mood to " << set_mood_n << "..." << endl; Creatures->WriteMood(creature_idx, set_mood_n); + DFHack::t_creaturflags1 f1 = creature.flags1; + DFHack::t_creaturflags2 f2 = creature.flags2; + f1.bits.has_mood = (set_mood_n == NO_MOOD ? 0 : 1); + if (!Creatures->WriteFlags(creature_idx, f1.whole, f2.whole)) + { + cout << "Error writing creature flags!" << endl; + } + creature.flags1 = f1; + creature.flags2 = f2; } if (set_happiness) From 634ead79a84882cc9b446c6e61e7a3aafd96a782 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Thu, 14 Apr 2011 18:12:58 +0200 Subject: [PATCH 10/13] Allow comma separated list of IDs for -i --- tools/playground/creature.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tools/playground/creature.cpp b/tools/playground/creature.cpp index 47f702cdc..e4a387334 100644 --- a/tools/playground/creature.cpp +++ b/tools/playground/creature.cpp @@ -20,7 +20,6 @@ * - Set nickname with --setnick (only if -i is given) * - Revive creature(s) with --revive * - Show skills/labors only when -ss/-sl/-v is given or a skill/labor is changed - * - Allow multiple -i switches * - Make -1 the default for everything but -i * - Imply -i if first argument is a number * - Search for nick/profession if first argument is a string without - (i.e. no switch) @@ -29,7 +28,8 @@ * - Switch --listskills, showing first 3 important skills * Done: - * - Switch -c all shows all creatures + * - Allow comma separated list of IDs for -i + * - '-c all' shows all creatures * - Rename from skillmodify.cpp to creature.cpp * - Kill creature(s) with --kill * - Hide skills with level 0 and 0 experience points @@ -247,6 +247,19 @@ bool is_in(int m, int set[], int set_size) return false; } +int * find_int(std::vector v, int comp) +{ + for (int i=0; i creature_id; bool find_nonicks = false; bool find_nicks = false; bool remove_skills = false; @@ -653,8 +665,13 @@ int main (int argc, const char* argv[]) } else if(arg_cur == "-i" && i < argc-1) { - creature_id = argv[i+1]; - sscanf(argv[i+1], "%d", &creature_id_int); + std::stringstream ss(argv[i+1]); + int num; + while (ss >> num) { + creature_id.push_back(num); + ss.ignore(1); + } + creature_type = ""; // if -i is given, match all creatures i++; } @@ -760,7 +777,7 @@ int main (int argc, const char* argv[]) if ( // Check for -i and -c - (creature_idx == creature_id_int + (NULL != find_int(creature_id, creature_idx) || toCaps(string(Materials->raceEx[creature.race].rawname)) == toCaps(creature_type) || "All" == toCaps(creature_type)) // Check for -nn @@ -790,7 +807,7 @@ int main (int argc, const char* argv[]) } bool allow_massdesignation = - !creature_id.empty() || toCaps(creature_type) != "Dwarf" || find_nonicks == true || force_massdesignation; + creature_id.size()==0 || toCaps(creature_type) != "Dwarf" || find_nonicks == true || force_massdesignation; if (dochange == true && allow_massdesignation == false) { cout From fc185eefdd2adefe4629c124b46bca1e23e805da Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Thu, 14 Apr 2011 23:38:27 +0200 Subject: [PATCH 11/13] Add/update definitions in Memory.xml --- Memory.xml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Memory.xml b/Memory.xml index bb0c78fdd..e6f313731 100644 --- a/Memory.xml +++ b/Memory.xml @@ -285,10 +285,10 @@ - + - + @@ -299,11 +299,11 @@ - + - + @@ -313,7 +313,7 @@ - + @@ -329,23 +329,23 @@ - - - + + + - - - - - - + + + + + + - + @@ -353,7 +353,7 @@ - + @@ -423,7 +423,7 @@ - + From e6a66206357f0f4fdc06d7af7ddd39e2bc5ab40f Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Fri, 15 Apr 2011 00:47:09 +0200 Subject: [PATCH 12/13] Add empty jobs. --- Memory.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Memory.xml b/Memory.xml index e6f313731..e947bc204 100644 --- a/Memory.xml +++ b/Memory.xml @@ -310,10 +310,12 @@ + + - + @@ -329,9 +331,9 @@ - - - + + + From cff85edf88732f37fa961669e8aad4eacc8751e4 Mon Sep 17 00:00:00 2001 From: Raoul XQ Date: Fri, 15 Apr 2011 00:47:48 +0200 Subject: [PATCH 13/13] Patch to detect empty job ID Will output job ID instead. --- tools/playground/creature.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/playground/creature.cpp b/tools/playground/creature.cpp index e4a387334..1aa49797e 100644 --- a/tools/playground/creature.cpp +++ b/tools/playground/creature.cpp @@ -147,7 +147,7 @@ void usage(int argc, const char * argv[]) << "-v : Increase verbosity" << endl << "-c creature : Show/modify this creature type instead of dwarfes ('all' to show all creatures)" << endl << "-1/--summary : Only display one line per creature" << endl - << "-i id : Only show/modify creature with this id" << endl + << "-i id1[,id2,...]: Only show/modify creature with this id" << endl << "-nn/--nonicks : Only show/modify creatures with no custom nickname (migrants)" << endl << "--nicks : Only show/modify creatures with custom nickname" << endl << "-ll/--listlabors: List available labors" << endl @@ -174,8 +174,8 @@ void usage(int argc, const char * argv[]) << "Example 2: Show all Yaks" << endl << argv[0] << " -c Yak" << endl << endl - << "Example 3: Remove all skills from dwarf with id 32" << endl - << argv[0] << " -i 32 -ras" << endl + << "Example 3: Remove all skills from dwarfs 15 and 32" << endl + << argv[0] << " -i 15,32 -ras" << endl << endl << "Example 4: Remove all skills and labors from dwarfs with no custom nickname" << endl << argv[0] << " -c DWARF -nn -ras -ral" << endl @@ -310,6 +310,15 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, in if(creature.current_job.active) { job=mem->getJob(creature.current_job.jobId); + int p=job.size(); + while (p>0 && (job[p]==' ' || job[p]=='\t')) + p--; + if (p <= 1) + { + stringstream ss; + ss << creature.current_job.jobId; + job = ss.str(); + } } if (showfirstlineonly) @@ -673,6 +682,7 @@ int main (int argc, const char* argv[]) } creature_type = ""; // if -i is given, match all creatures + showdead = true; i++; } else