EldrickTobin

See I didn't do much at all...

Feb 21st, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. // Headshot 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 DFHack::Simple;
  30. using namespace df::enums;
  31. using df::global::world;
  32.  
  33. command_result headshot (Core * c, std::vector <std::string> & parameters);
  34.  
  35. DFhackCExport const char * plugin_name ( void )
  36. {
  37. return "headshot";
  38. }
  39.  
  40. // Mandatory init function. If you have some global state, create it here.
  41. DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
  42. {
  43. // Fill the command list with your commands.
  44. commands.clear();
  45. commands.push_back(PluginCommand(
  46. "headshot", "End the target violently.",
  47. headshot, false,
  48. " 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"
  49. ));
  50. return CR_OK;
  51. }
  52.  
  53. DFhackCExport command_result plugin_shutdown ( Core * c )
  54. {
  55. return CR_OK;
  56. }
  57.  
  58. command_result headshot (Core * c, vector <string> & parameters)
  59. {
  60. Console & con = c->con;
  61. CoreSuspender suspend(c);
  62. DFHack::Gui *Gui = c->getGui();
  63. int32_t cursorX, cursorY, cursorZ;
  64. Gui->getCursorCoords(cursorX,cursorY,cursorZ);
  65. if(cursorX == -30000)
  66. {
  67. con.printerr("No cursor; place cursor over creature to murder.\n");
  68. }
  69. else
  70. {
  71. for(size_t i = 0; i < world->units.all.size(); i++)
  72. {
  73. df::unit * unit = world->units.all[i];
  74. if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
  75. {
  76. if (parameters.size() == 1 && (parameters[0] == "--kill" || parameters[0] == "-k"))
  77. {
  78. unit->flags3.bits.scuttle = 1;
  79. con.print("Boom! Headshot!\n");
  80. break;
  81. }
  82. else
  83. {
  84. con.print("'headshot --kill' short and sweet\n(or 'headshot -k' even shorter). No condiments needed. That's what the wagon provides.\nNow show me where we drop the wagon.\n");
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. return CR_OK;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment