EldrickTobin

fixhappiness.cpp RC1 - a plugin for DFHack

Apr 4th, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. // Fix Happiness - Dwarven Brainwashing. Based in part on cprobe by peterix
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <assert.h>
  6. #include <climits>
  7. #include <stdlib.h> // for rand()
  8. #include <algorithm> // for std::transform
  9. #include <vector>
  10. #include <list>
  11. #include <iterator>
  12. using namespace std;
  13.  
  14. #include "DFHack.h"
  15. #include "Core.h"
  16. #include "Console.h"
  17. #include "Export.h"
  18. #include "PluginManager.h"
  19. #include "DataDefs.h"
  20. #include <df/caste_raw.h>
  21. #include <df/creature_raw.h>
  22. #include <df/unit.h>
  23.  
  24. #include "df/world.h"
  25. #include "df/historical_entity.h"
  26. #include "df/entity_raw.h"
  27. #include "df/entity_position.h"
  28. #include "df/entity_position_responsibility.h"
  29. #include "df/entity_position_assignment.h"
  30.  
  31. #include <set>
  32.  
  33. using std::set;
  34. using std::vector;
  35. using std::string;
  36. using namespace DFHack;
  37. using namespace df::enums;
  38. using df::global::world;
  39. using df::global::ui;
  40.  
  41.  
  42.  
  43. command_result civilizationdump (color_ostream &out, std::vector <std::string> & parameters);
  44. command_result fixhappiness (color_ostream &out, vector <string> & parameters);
  45.  
  46. DFHACK_PLUGIN("fixhappiness");
  47.  
  48. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
  49. {
  50. commands.push_back(PluginCommand(
  51. "fixhappiness",
  52. "For fixing the happiness of the discontented simply target with cursor and invoke",
  53. fixhappiness, false,
  54. "\n"
  55. "Place the Cursor on a distraught unit. Invoke command. They are now Happiness 100 and have forgotten why they were upset.\n"
  56. "Note: Avoid use on happy units as it will blast their pleasant thoughts away.\n"
  57. ));
  58. return CR_OK;
  59. }
  60.  
  61. DFhackCExport command_result plugin_shutdown ( color_ostream &out )
  62. {
  63. return CR_OK;
  64. }
  65.  
  66. command_result fixhappiness (color_ostream &out, vector <string> & parameters)
  67. {
  68. CoreSuspender suspend;
  69. int32_t cursorX, cursorY, cursorZ;
  70. Gui::getCursorCoords(cursorX,cursorY,cursorZ);
  71. if(cursorX == -30000)
  72. {
  73. out.printerr("No cursor; place cursor over creature to probe.\n");
  74. }
  75. else
  76. {
  77. for(size_t i = 0; i < world->units.all.size(); i++)
  78. {
  79. df::unit * unit = world->units.all[i];
  80. if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
  81. {
  82. if(unit->status.happiness >= 101)
  83. continue;
  84. out.print("fixing happiness... for unit id:%d aka %s\n", unit->id, Translation::TranslateName(&unit->name, false).c_str());
  85. for(auto iter = unit->status.recent_events.begin(); iter != unit->status.recent_events.end(); iter++)
  86. { //0-129, 212-216, 220-221 are bad mmmkay... aka if unit->status.recent_events[*].type = 0-129, 212-216, 220-221 then delete the bugger.
  87. delete *iter;
  88. }
  89. unit->status.recent_events.clear();
  90. unit->status.happiness = 100;
  91. continue;
  92. }
  93. }
  94. }
  95. return CR_OK;
  96. }
Add Comment
Please, Sign In to add comment