EldrickTobin

wagonshot.cpp RC2 a plugin for DFHack

Mar 22nd, 2012
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. // Wagonshot is based on code from "probe.cpp" by peterix.
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <climits>
  5. #include <vector>
  6. #include <string>
  7. #include <sstream>
  8. #include <ctime>
  9. #include <cstdio>
  10. using namespace std;
  11.  
  12. #include "Core.h"
  13. #include "Console.h"
  14. #include "Export.h"
  15. #include "PluginManager.h"
  16. #include "modules/Units.h"
  17. #include "modules/Maps.h"
  18. #include "modules/Gui.h"
  19. #include "modules/Materials.h"
  20. #include "modules/MapCache.h"
  21. #include "MiscUtils.h"
  22.  
  23. #include "df/world.h"
  24.  
  25.  
  26. using std::vector;
  27. using std::string;
  28. using namespace DFHack;
  29. using namespace df::enums;
  30. using df::global::world;
  31.  
  32. DFHACK_PLUGIN("wagonshot");
  33.  
  34. command_result wagonshot (color_ostream &out, std::vector <std::string> & parameters);
  35.  
  36. // Mandatory init function. If you have some global state, create it here.
  37. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
  38. {
  39. // Fill the command list with your commands.
  40. commands.clear();
  41. commands.push_back(PluginCommand(
  42. "wagonshot",
  43. "End the target violently.",
  44. wagonshot, false,
  45. " In a perfect world you wouldn't need to kill critters bursting into your fortress. But this isn't a perfect world. So drop a wagon on them.\n"
  46. ));
  47. return CR_OK;
  48. }
  49.  
  50. DFhackCExport command_result plugin_shutdown ( color_ostream &out )
  51. {
  52. return CR_OK;
  53. }
  54.  
  55. command_result wagonshot (color_ostream &out, vector <string> & parameters)
  56. {
  57. CoreSuspender suspend;
  58. int32_t cursorX, cursorY, cursorZ;
  59. Gui::getCursorCoords(cursorX,cursorY,cursorZ);
  60. if(cursorX == -30000)
  61. {
  62. out.printerr("No cursor; place cursor over creature to murder.\n");
  63. }
  64. else
  65. {
  66. for(size_t i = 0; i < world->units.all.size(); i++)
  67. {
  68. df::unit * unit = world->units.all[i];
  69. if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
  70. {
  71. if (parameters.size() == 1 && (parameters[0] == "--kill" || parameters[0] == "-k"))
  72. {
  73. unit->flags3.bits.scuttle = 1;
  74. //out.print("Boom! Wagonshot!\n");
  75. continue;
  76. }
  77. else
  78. {
  79. out.print("'wagonshot --kill' short and sweet\n(or 'wagonshot -k' even shorter). No condiments needed. That's what the wagon provides.\nNow show me where we drop the wagon.\n");
  80. break;
  81. }
  82. }
  83. }
  84. }
  85. return CR_OK;
  86. }
Add Comment
Please, Sign In to add comment