forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreaturemanager.cpp
More file actions
1428 lines (1290 loc) · 52.4 KB
/
creaturemanager.cpp
File metadata and controls
1428 lines (1290 loc) · 52.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************
* 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
* - Ghosts/Merchants/etc. should be tagged as not own creatures
* - Filter by nickname with -n
* - Filter by first name with -fn
* - 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)
* - Show skills/labors only when -ss/-sl/-v is given or a skill/labor is changed
* - 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 (show dwarf's experiences which make her un-/happy)
* - Switch --makefriendly
* - Switch --listskills, showing first 3 important skills
* Done:
* - More space for "Current Job"
* - Attempted to revive creature(s) with --revive, but it doesn't work (flag is there but invisible)
* - Switch -rcs, remove civil skills
* - Switch -rms, remove military skills (who would want that?)
* - 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
* - 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)
* - 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
* - Hide hauler labors when +sh is given
* - Add -v for verbose
* - Override forbidden mass-designation with -f
* - Option to add/remove single labors
* - Switches -ras and rl should only be possible with -nn or -i
* - Switch -rh removes hauler jobs
* - Dead creatures should not be displayed
* - Childs should not get labors assigned to
* - Babies should not get labors assigned to
* - Switch -al <n> adds labor number n
* - Switch -rl <n> removes labor number n
* - Switch -ral removes all labors
* - Switch -ll lists all available labors
*********************************************
*/
#include <iostream>
#include <climits>
#include <string.h>
#include <vector>
#include <locale>
#include <stdio.h>
using namespace std;
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
#include <modules/Units.h>
/* Note about magic numbers:
* If you have an idea how to better solve this, tell me. Currently I'd be
* either dependent on Toady One's implementation (#defining numbers) or
* Memory.xml (#defining text). I voted for Toady One's numbers to be more
* stable, but could be wrong.
*
* Ideally there would be a flag "is_military" or "is_social" in Memory.xml.
*/
/* Social skills */
#define SKILL_PERSUASION 72
#define SKILL_NEGOTIATION 73
#define SKILL_JUDGING_INTENT 74
#define SKILL_INTIMIDATION 79
#define SKILL_CONVERSATION 80
#define SKILL_COMEDY 81
#define SKILL_FLATTERY 82
#define SKILL_CONSOLING 83
#define SKILL_PACIFICATION 84
/* Misc skills */
#define SKILL_WEAPONSMITHING 27
#define SKILL_ARMORSMITHING 28
#define SKILL_RECORD_KEEPING 77
#define SKILL_WAX_WORKING 115
/* Some military skills */
#define SKILL_COORDINATION 95
#define SKILL_BALANCE 96
#define SKILL_LEADERSHIP 97
#define SKILL_TEACHING 98
#define SKILL_FIGHTING 99
#define SKILL_ARCHERY 100
#define SKILL_WRESTLING 101
#define SKILL_BITING 102
#define SKILL_STRIKING 103
#define SKILL_KICKING 104
#define SKILL_DODGING 105
#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 PROFESSION_CHILD 96
#define PROFESSION_BABY 97
#define NOT_SET INT_MIN
#define MAX_MOOD 4
#define NO_MOOD -1
bool quiet=true;
bool verbose = false;
bool showhauler = true;
bool showsocial = false;
bool showfirstlineonly = false;
bool showdead = false;
bool showallflags = false;
int hauler_labors[] = {
LABOR_STONE_HAULING
,LABOR_WOOD_HAULING
,LABOR_BURIAL
,LABOR_FOOD_HAULING
,LABOR_REFUSE_HAULING
,LABOR_ITEM_HAULING
,LABOR_FURNITURE_HAULING
,LABOR_ANIMAL_HAULING
,LABOR_CLEANING
,LABOR_FEED_PATIENTS_PRISONERS
,LABOR_RECOVERING_WOUNDED
};
int social_skills[] =
{
SKILL_PERSUASION
,SKILL_NEGOTIATION
,SKILL_JUDGING_INTENT
,SKILL_INTIMIDATION
,SKILL_CONVERSATION
,SKILL_COMEDY
,SKILL_FLATTERY
,SKILL_CONSOLING
,SKILL_PACIFICATION
};
int military_skills[] =
{
SKILL_COORDINATION
,SKILL_BALANCE
,SKILL_LEADERSHIP
,SKILL_TEACHING
,SKILL_FIGHTING
,SKILL_ARCHERY
,SKILL_WRESTLING
,SKILL_BITING
,SKILL_STRIKING
,SKILL_KICKING
,SKILL_DODGING
};
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
<< endl
<< "Choosing which creatures to display and/or modify "
<< "(note that all criteria" << endl << "must match, so adding "
<< " more narrows things down):" << endl
<< "-i id1[,id2,...]: Only show/modify creature with this id" << endl
<< "-c creature : Show/modify this creature type instead of dwarves" << endl
<< " ('all' to show all creatures)" << endl
<< "-nn/--nonicks : Only show/modify creatures with no custom nickname (migrants)" << endl
<< "--nicks : Only show/modify creatures with custom nickname" << endl
<< "--showdead : Also show/modify dead creatures" << endl
<< "--type : Show/modify all creatures of given type" << endl
<< " : Can be used multiple times" << endl
<< " types:" << endl
<< " * dead: all dead creatures" << endl
<< " * demon: all demons" << endl
<< " * diplomat: all diplomats" << endl
<< " * FB: all forgotten beasts" << endl
<< " * female: all female creatures" << endl
<< " * ghost: all ghosts" << endl
<< " * male: all male creatures" << endl
<< " * merchants: all merchants (including pack animals)" << endl
<< " * neuter: all neuter creatuers" << endl
<< " * pregnant: all pregnant creatures" << endl
<< " * tame: all tame creatues" << endl
<< " * wild: all wild creatures" << endl
<< endl
<< "What information to display:" << endl
<< "-saf : Show all flags of a creature" << endl
<< "--showallflags : Show all flags of a creature" << endl
<< "-ll/--listlabors: List available labors" << endl
<< "-ss : Show social skills" << endl
<< "+sh : Hide hauler labors" << endl
<< "-1/--summary : Only display one line per creature" << endl
<< endl
<< "Options to modify selected creatures:" << endl
<< "-al <n> : Add labor <n> to creature" << endl
<< "-rl <n> : Remove labor <n> from creature" << endl
<< "-ras : Remove all skills from creature (i.e. set them to zero)" << endl
<< "-rcs : Remove civil skills from creature (i.e. set them to zero)" << endl
<< "-rms : Remove military skills from creature (i.e. set them to zero)" << 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 <n> : Set mood to n (-1 = no mood, max=4, buggy!)" << endl
<< "--kill : Kill creature(s) (leaves behind corpses)" << endl
<< "--erase : Remove creature(s) from game without killing" << endl
<< "--tame : Tames animals, recruits intelligent creatures." << endl
<< "--slaugher : Mark a creature for slaughter, even sentients" << endl
<< "--butcher : Same as --slaugher" << endl
// Doesn't seem to work
//<< "--revive : Attempt to revive creature(s) (remove dead and killed flag)" << endl
// Setting happiness doesn't work really, because hapiness is recalculated
//<< "--sethappiness <n> : Set happiness to n" << endl
<< "-f : Force an action" << endl
<< endl
<< "Examples:" << endl
<< endl
<< "Show all dwarfs:" << endl
<< argv[0] << " -c Dwarf" << endl
<< endl
<< "Show summary of all creatures (spoiler: includes unknown creatures):" << endl
<< argv[0] << " -1 -c all" << endl
<< endl
<< "Kill that nasty ogre" << endl
<< argv[0] << " -i 52 --kill" << endl
<< endl
<< "Check that the ogre is really dead" << endl
<< argv[0] << " -c ogre --showdead" << endl
<< endl
<< "Remove all skills from dwarfs 15 and 32:" << endl
<< argv[0] << " -i 15,32 -ras" << endl
<< endl
<< "Remove all skills and labors from dwarfs with no custom nickname:" << endl
<< argv[0] << " -c DWARF -nn -ras -ral" << endl
<< endl
<< "Add hauling labors to all dwarfs without nickname (e.g. migrants):" << endl
<< argv[0] << " -c DWARF -nn -ah" << endl
<< endl
<< "Show list of labor ids:" << endl
<< argv[0] << " -c DWARF -ll" << endl
<< endl
<< "Add engraving labor to all dwarfs without nickname (get the labor id from the list above):" << endl
<< argv[0] << " -c DWARF -nn -al 13" << endl
<< endl
<< "Make Urist, Stodir and Ingish miners:" << endl
<< argv[0] << " -i 31,42,77 -al 0" << endl
<< endl
<< "Make all demons friendly:" << endl
<< argv[0] << " --type demon --tame" << endl
;
if (quiet == false) {
cout << "Press any key to continue" << endl;
cin.ignore();
}
}
DFHack::Materials * Materials;
DFHack::VersionInfo *mem;
DFHack::Creatures * Creatures = NULL;
// Note that toCaps() changes the string itself and I'm using it a few times in
// an unsafe way below. Didn't crash yet however.
std::string toCaps(std::string s)
{
const int length = s.length();
std::locale loc("");
bool caps=true;
if (length == 0) {
return s;
}
for(int i=0; i!=length ; ++i)
{
if (caps)
{
s[i] = std::toupper(s[i],loc);
caps = false;
}
else if (s[i] == '_' || s[i] == ' ')
{
s[i] = ' ';
caps = true;
}
else
{
s[i] = std::tolower(s[i],loc);
}
}
return s;
}
int strtoint(const string &str)
{
stringstream ss(str);
int result;
return ss >> result ? result : -1;
}
// A C++ standard library function should be used instead
bool is_in(int m, int set[], int set_size)
{
for (int i=0; i<set_size; i++)
{
if (m == set[i])
return true;
}
return false;
}
int * find_int(std::vector<int> v, int comp)
{
for (size_t i=0; i<v.size(); i++)
{
//fprintf(stderr, "Comparing %d with %d and returning %x...\n", v[i], comp, &v[i]);
if (v[i] == comp)
return &v[i];
}
return NULL;
}
void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature, int index)
{
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])
{
name = creature.name.nickname;
}
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);
}
}
}
string profession="";
try {
profession = mem->getProfession(creature.profession);
}
catch (exception& e)
{
cout << "Error retrieving creature profession: " << e.what() << endl;
}
if(creature.custom_profession[0])
{
profession = creature.custom_profession;
}
string jobid;
stringstream ss;
ss << "(" << creature.current_job.jobId << ")";
jobid = ss.str();
string job="No Job/On Break" + (creature.current_job.jobId == 0 ? "" : jobid);
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) // Display numeric jobID if unknown job
{
job = jobid;
}
}
if (showfirstlineonly)
{
printf("%3d", index);
printf(" %-17s", type.c_str());
printf(" %-24s", name.c_str());
printf(" %-16s", toCaps(profession).c_str());
printf(" %-38s", job.c_str());
printf(" %5d", creature.happiness);
if (showdead)
{
printf(" %-5s", creature.flags1.bits.dead ? "Dead" : "Alive");
}
printf("\n");
return;
}
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());
printf(", Happiness: %d", creature.happiness);
printf("\n");
printf("Origin: %p\n", creature.origin);
printf("Civ #: %d\n", creature.civ);
}
if((creature.mood != NO_MOOD) && (creature.mood<=MAX_MOOD))
{
cout << "Creature is in a strange mood (mood=" << creature.mood << "), skill: " << mem->getSkill(creature.mood_skill) << endl;
vector<DFHack::t_material> mymat;
if(Creatures->ReadJob(&creature, mymat))
{
for(unsigned int i = 0; i < mymat.size(); i++)
{
printf("\t%s(%d)\t%d %d %d - %.8x\n", Materials->getDescription(mymat[i]).c_str(), mymat[i].itemType, mymat[i].subType, mymat[i].subIndex, mymat[i].index, mymat[i].flags);
}
}
}
if(creature.has_default_soul)
{
// Print out skills
int skillid;
int skillrating;
int skillexperience;
string skillname;
cout << setiosflags(ios::left);
for(unsigned int i = 0; i < creature.defaultSoul.numSkills;i++)
{
skillid = creature.defaultSoul.skills[i].id;
bool is_social = is_in(skillid, social_skills, sizeof(social_skills)/sizeof(social_skills[0]));
if (!is_social || (is_social && showsocial))
{
skillrating = creature.defaultSoul.skills[i].rating;
skillexperience = creature.defaultSoul.skills[i].experience;
try
{
skillname = mem->getSkill(skillid);
}
catch(DFHack::Error::AllMemdef &e)
{
skillname = "Unknown skill";
cout << e.what() << endl;
}
if (skillrating > 0 || skillexperience > 0)
{
cout << "(Skill " << int(skillid) << ") " << setw(16) << skillname << ": "
<< skillrating << "/" << skillexperience << endl;
}
}
}
for(unsigned int i = 0; i < NUM_CREATURE_LABORS;i++)
{
if(!creature.labors[i])
continue;
string laborname;
try
{
laborname = mem->getLabor(i);
}
catch(exception &)
{
laborname = "(Undefined)";
}
bool is_labor = is_in(i, hauler_labors, sizeof(hauler_labors)/sizeof(hauler_labors[0]));
if (!is_labor || (is_labor && showhauler))
cout << "(Labor " << i << ") " << setw(16) << laborname << endl;
}
}
if (creature.pregnancy_timer > 0)
cout << "Pregnant: " << creature.pregnancy_timer << " ticks to "
<< "birth." << endl;
if (showallflags)
{
DFHack::t_creaturflags1 f1 = creature.flags1;
DFHack::t_creaturflags2 f2 = creature.flags2;
DFHack::t_creaturflags3 f3 = creature.flags3;
if(f1.bits.dead){cout << "Flag: dead" << endl; }
if(f1.bits.had_mood){cout<<toCaps("Flag: had_mood") << endl; }
if(f1.bits.marauder){cout<<toCaps("Flag: marauder") << endl; }
if(f1.bits.drowning){cout<<toCaps("Flag: drowning") << endl; }
if(f1.bits.merchant){cout<<toCaps("Flag: merchant") << endl; }
if(f1.bits.forest){cout<<toCaps("Flag: forest") << endl; }
if(f1.bits.left){cout<<toCaps("Flag: left") << endl; }
if(f1.bits.rider){cout<<toCaps("Flag: rider") << endl; }
if(f1.bits.incoming){cout<<toCaps("Flag: incoming") << endl; }
if(f1.bits.diplomat){cout<<toCaps("Flag: diplomat") << endl; }
if(f1.bits.zombie){cout<<toCaps("Flag: zombie") << endl; }
if(f1.bits.skeleton){cout<<toCaps("Flag: skeleton") << endl; }
if(f1.bits.can_swap){cout<<toCaps("Flag: can_swap") << endl; }
if(f1.bits.on_ground){cout<<toCaps("Flag: on_ground") << endl; }
if(f1.bits.projectile){cout<<toCaps("Flag: projectile") << endl; }
if(f1.bits.active_invader){cout<<toCaps("Flag: active_invader") << endl; }
if(f1.bits.hidden_in_ambush){cout<<toCaps("Flag: hidden_in_ambush") << endl; }
if(f1.bits.invader_origin){cout<<toCaps("Flag: invader_origin") << endl; }
if(f1.bits.coward){cout<<toCaps("Flag: coward") << endl; }
if(f1.bits.hidden_ambusher){cout<<toCaps("Flag: hidden_ambusher") << endl; }
if(f1.bits.invades){cout<<toCaps("Flag: invades") << endl; }
if(f1.bits.check_flows){cout<<toCaps("Flag: check_flows") << endl; }
if(f1.bits.ridden){cout<<toCaps("Flag: ridden") << endl; }
if(f1.bits.caged){cout<<toCaps("Flag: caged") << endl; }
if(f1.bits.tame){cout<<toCaps("Flag: tame") << endl; }
if(f1.bits.chained){cout<<toCaps("Flag: chained") << endl; }
if(f1.bits.royal_guard){cout<<toCaps("Flag: royal_guard") << endl; }
if(f1.bits.fortress_guard){cout<<toCaps("Flag: fortress_guard") << endl; }
if(f1.bits.suppress_wield){cout<<toCaps("Flag: suppress_wield") << endl; }
if(f1.bits.important_historical_figure){cout<<toCaps("Flag: important_historical_figure") << endl; }
if(f2.bits.swimming){cout<<toCaps("Flag: swimming") << endl; }
if(f2.bits.sparring){cout<<toCaps("Flag: sparring") << endl; }
if(f2.bits.no_notify){cout<<toCaps("Flag: no_notify") << endl; }
if(f2.bits.unused){cout<<toCaps("Flag: unused") << endl; }
if(f2.bits.calculated_nerves){cout<<toCaps("Flag: calculated_nerves") << endl; }
if(f2.bits.calculated_bodyparts){cout<<toCaps("Flag: calculated_bodyparts") << endl; }
if(f2.bits.important_historical_figure){cout<<toCaps("Flag: important_historical_figure") << endl; }
if(f2.bits.killed){cout<<toCaps("Flag: killed") << endl; }
if(f2.bits.cleanup_1){cout<<toCaps("Flag: cleanup_1") << endl; }
if(f2.bits.cleanup_2){cout<<toCaps("Flag: cleanup_2") << endl; }
if(f2.bits.cleanup_3){cout<<toCaps("Flag: cleanup_3") << endl; }
if(f2.bits.for_trade){cout<<toCaps("Flag: for_trade") << endl; }
if(f2.bits.trade_resolved){cout<<toCaps("Flag: trade_resolved") << endl; }
if(f2.bits.has_breaks){cout<<toCaps("Flag: has_breaks") << endl; }
if(f2.bits.gutted){cout<<toCaps("Flag: gutted") << endl; }
if(f2.bits.circulatory_spray){cout<<toCaps("Flag: circulatory_spray") << endl; }
if(f2.bits.locked_in_for_trading){cout<<toCaps("Flag: locked_in_for_trading") << endl; }
if(f2.bits.slaughter){cout<<toCaps("Flag: slaughter") << endl; }
if(f2.bits.underworld){cout<<toCaps("Flag: underworld") << endl; }
if(f2.bits.resident){cout<<toCaps("Flag: resident") << endl; }
if(f2.bits.cleanup_4){cout<<toCaps("Flag: cleanup_4") << endl; }
if(f2.bits.calculated_insulation){cout<<toCaps("Flag: calculated_insulation") << endl; }
if(f2.bits.visitor_uninvited){cout<<toCaps("Flag: visitor_uninvited") << endl; }
if(f2.bits.visitor){cout<<toCaps("Flag: visitor") << endl; }
if(f2.bits.calculated_inventory){cout<<toCaps("Flag: calculated_inventory") << endl; }
if(f2.bits.vision_good){cout<<toCaps("Flag: vision_good") << endl; }
if(f2.bits.vision_damaged){cout<<toCaps("Flag: vision_damaged") << endl; }
if(f2.bits.vision_missing){cout<<toCaps("Flag: vision_missing") << endl; }
if(f2.bits.breathing_good){cout<<toCaps("Flag: breathing_good") << endl; }
if(f2.bits.breathing_problem){cout<<toCaps("Flag: breathing_problem") << endl; }
if(f2.bits.roaming_wilderness_population_source){cout<<toCaps("Flag: roaming_wilderness_population_source") << endl; }
if(f2.bits.roaming_wilderness_population_source_not_a_map_feature){cout<<toCaps("Flag: roaming_wilderness_population_source_not_a_map_feature") << endl; }
if(f3.bits.announce_titan){cout<<toCaps("Flag: announce_titan") << endl; }
if(f3.bits.scuttle){cout<<toCaps("Flag: scuttle") << endl; }
if(f3.bits.ghostly){cout<<toCaps("Flag: ghostly") << endl; }
}
else
{
/* 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.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; }
/* 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; }
/* FLAGS 3 */
if(creature.flags3.bits.ghostly) { cout << "Flag: Ghost" << endl; }
if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) )
{
string artifact_name = Tran->TranslateName(creature.artifact_name,false);
cout << "Artifact: " << artifact_name << endl;
}
}
cout << endl;
}
class creature_filter
{
public:
enum sex_filter
{
SEX_FEMALE = 0,
SEX_MALE = 1,
SEX_ANY = 254, // Our magin number for ignoring sex.
SEX_NEUTER = 255
};
bool dead;
bool demon;
bool diplomat;
bool find_nonicks;
bool find_nicks;
bool forgotten_beast;
bool ghost;
bool merchant;
bool pregnant;
bool tame;
bool wild;
sex_filter sex;
string creature_type;
std::vector<int> creature_id;
#define DEFAULT_CREATURE_STR "Default"
creature_filter()
{
// By default we only select dwarves, except that if we use the
// --type option we want to default to everyone. So we start out
// with a special string, and if remains unchanged after all
// the options have been processed we turn it to DWARF.
creature_type = DEFAULT_CREATURE_STR;
dead = false;
demon = false;
diplomat = false;
find_nonicks = false;
find_nicks = false;
forgotten_beast = false;
ghost = false;
merchant = false;
pregnant = false;
sex = SEX_ANY;
tame = false;
wild = false;
}
// If the creature type is still the default, then change it to allow
// for all creatures. If the creature type has been explicitly set,
// then don't alter it.
void defaultTypeToAll()
{
if (creature_type == DEFAULT_CREATURE_STR)
creature_type = "";
}
// If the creature type is still the default, change it to DWARF
void defaultTypeToDwarf()
{
if (creature_type == DEFAULT_CREATURE_STR)
creature_type = "Dwarf";
}
void process_type(string type)
{
type = toCaps(type);
// If we're going by type, then by default all species are
// permitted.
defaultTypeToAll();
if (type == "Dead")
{
dead = true;
showdead = true;
}
else if (type == "Demon")
demon = true;
else if (type == "Diplomat")
diplomat = true;
else if (type == "Fb" || type == "Beast")
forgotten_beast = true;
else if (type == "Ghost")
ghost = true;
else if (type == "Merchant")
merchant = true;
else if (type == "Pregnant")
pregnant = true;
else if (type == "Tame")
tame = true;
else if (type == "Wild")
wild = true;
else if (type == "Male")
sex = SEX_MALE;
else if (type == "Female")
sex = SEX_FEMALE;
else if (type == "Neuter")
sex = SEX_NEUTER;
else
{
cerr << "ERROR: Unknown type '" << type << "'" << endl;
}
}
void doneProcessingOptions()
{
string temp = toCaps(creature_type);
creature_type = temp;
defaultTypeToDwarf();
}
bool creatureMatches(const DFHack::t_creature & creature,
uint32_t creature_idx)
{
// A list of ids overrides everything else.
if (creature_id.size() > 0)
return (find_int(creature_id, creature_idx));
// If it's not a list of ids, it has not match all given criteria.
const DFHack::t_creaturflags1 &f1 = creature.flags1;
const DFHack::t_creaturflags2 &f2 = creature.flags2;
const DFHack::t_creaturflags3 &f3 = creature.flags3;
if(f1.bits.dead && !showdead)
return false;
bool hasnick = (creature.name.nickname[0] != '\0');
if(hasnick && find_nonicks)
return false;
if(!hasnick && find_nicks)
return false;
string race_name = string(Materials->raceEx[creature.race].rawname);
if(!creature_type.empty() && creature_type != toCaps(race_name))
return false;
if(dead && !f1.bits.dead)
return false;
if(demon && !f2.bits.underworld)
return false;
if(diplomat && !f1.bits.diplomat)
return false;
if(forgotten_beast && !f2.bits.visitor_uninvited)
return false;
if(ghost && !f3.bits.ghostly)
return false;
if(merchant && !f1.bits.merchant)
return false;
if(pregnant && creature.pregnancy_timer == 0)
return false;
if (sex != SEX_ANY && creature.sex != (uint8_t) sex)
return false;
if(tame && !f1.bits.tame)
return false;
if(wild && !f2.bits.roaming_wilderness_population_source &&
!f2.bits.roaming_wilderness_population_source_not_a_map_feature)
{
return false;
}
return true;
}
};
int main (int argc, const char* argv[])
{
// let's be more useful when double-clicked on windows
#ifndef LINUX_BUILD
quiet = false;
#endif
creature_filter filter;
bool remove_skills = false;
bool remove_civil_skills = false;
bool remove_military_skills = false;
bool remove_labors = false;
bool kill_creature = false;
bool erase_creature = false;
bool revive_creature = false;
bool make_hauler = false;
bool remove_hauler = false;
bool add_labor = false;
int add_labor_n = NOT_SET;
bool remove_labor = false;
int remove_labor_n = NOT_SET;
bool set_happiness = false;
int set_happiness_n = NOT_SET;
bool set_mood = false;
int set_mood_n = NOT_SET;
bool list_labors = false;
bool force_massdesignation = false;
bool tame_creature = false;
bool slaughter_creature = false;
if (argc == 1) {
usage(argc, argv);
return 1;
}
for(int i = 1; i < argc; i++)
{
string arg_cur = argv[i];
string arg_next = "";
int arg_next_int = NOT_SET;
/* Check if argv[i+1] is a number >= 0 */
if (i < argc-1) {
arg_next = argv[i+1];
arg_next_int = strtoint(arg_next);
if (arg_next != "0" && arg_next_int == 0) {
arg_next_int = NOT_SET;
}
}
if(arg_cur == "-q")
{
quiet = true;
}
else if(arg_cur == "+q")
{
quiet = false;
}
else if(arg_cur == "-v")
{
verbose = true;
}
else if(arg_cur == "-1" || arg_cur == "--summary")
{
showfirstlineonly = true;
}
else if(arg_cur == "-ss" || arg_cur == "--showsocial")
{
showsocial = true;
}
else if(arg_cur == "+sh" || arg_cur == "-nosh" || arg_cur == "--noshowhauler")
{
showhauler = false;
}
else if(arg_cur == "--showdead")
{
showdead = true;
}
else if(arg_cur == "--showallflags" || arg_cur == "-saf")
{
showallflags = true;
}
else if(arg_cur == "-ras")
{
remove_skills = true;
}
else if(arg_cur == "-rcs")
{
remove_civil_skills = true;
}
else if(arg_cur == "-rms")
{
remove_military_skills = true;
}
else if(arg_cur == "-f")
{
force_massdesignation = true;
}
// list labors
else if(arg_cur == "-ll" || arg_cur == "--listlabors")
{
list_labors = true;
}
// add single labor
else if(arg_cur == "-al" && i < argc-1)
{
if (arg_next_int == NOT_SET || arg_next_int >= NUM_CREATURE_LABORS) {
usage(argc, argv);
return 1;
}
add_labor = true;
add_labor_n = arg_next_int;
i++;
}
// remove single labor
else if(arg_cur == "-rl" && i < argc-1)
{
if (arg_next_int == NOT_SET || arg_next_int >= NUM_CREATURE_LABORS) {
usage(argc, argv);
return 1;
}
remove_labor = true;
remove_labor_n = arg_next_int;
i++;
}
else if(arg_cur == "--setmood" && i < argc-1)
{
if (arg_next_int < NO_MOOD || arg_next_int > MAX_MOOD) {
usage(argc, argv);
return 1;
}
set_mood = true;
set_mood_n = arg_next_int;
i++;
}
else if(arg_cur == "--sethappiness" && i < argc-1)
{
if (arg_next_int < 1 || arg_next_int >= 2000) {
usage(argc, argv);
return 1;
}
set_happiness = true;
set_happiness_n = arg_next_int;
i++;
}
else if(arg_cur == "--kill")
{
kill_creature = true;
showallflags = true;
showdead = true;
}
else if(arg_cur == "--erase")
{
erase_creature = true;
showallflags = true;
showdead = true;
}
else if(arg_cur == "--revive")
{
revive_creature = true;
showdead = true;
showallflags = true;
}
else if(arg_cur == "-ral")
{
remove_labors = true;
}
else if(arg_cur == "-ah")
{
make_hauler = true;
}
else if(arg_cur == "-rh")
{
remove_hauler = true;
}
else if(arg_cur == "-nn" || arg_cur == "--nonicks")
{
filter.find_nonicks = true;
}
else if(arg_cur == "--nicks")
{
filter.find_nicks = true;
}
else if(arg_cur == "-c" && i < argc-1)
{
filter.creature_type = argv[i+1];
i++;
}
else if(arg_cur == "-i" && i < argc-1)
{
std::stringstream ss(argv[i+1]);
int num;
while (ss >> num) {
filter.creature_id.push_back(num);
ss.ignore(1);
}
filter.creature_type = ""; // if -i is given, match all creatures
showdead = true;
i++;