EldrickTobin

wagonshotarray.cpp RC1 a plugin for DFHack

Feb 23rd, 2012
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. //wagonshotarray is based on wagonshot.
  2. //wagonshot is based on code from "probe.cpp" by peterix.
  3. #include <algorithm> // for std::transform
  4. #include <assert.h>
  5. #include <climits>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <ctime>
  9. #include <iomanip>
  10. #include <iostream>
  11. #include <iterator>
  12. #include <list>
  13. #include <sstream>
  14. #include <stdlib.h> // for rand()
  15. #include <string>
  16. #include <vector>
  17. using namespace std;
  18.  
  19. #include "Core.h"
  20. #include "Console.h"
  21. #include "Export.h"
  22. #include "PluginManager.h"
  23. #include "modules/Units.h"
  24. #include "modules/Maps.h"
  25. #include "modules/Gui.h"
  26. #include "modules/Materials.h"
  27. #include "modules/MapCache.h"
  28. #include "MiscUtils.h"
  29.  
  30. #include "DFHack.h"
  31. #include "DataDefs.h"
  32. #include <df/caste_raw.h>
  33. #include <df/creature_raw.h>
  34. #include <set>
  35.  
  36. #include "df/world.h"
  37.  
  38. using std::set;
  39. using std::vector;
  40. using std::string;
  41. using namespace DFHack;
  42. using namespace df::enums;
  43. using df::global::world;
  44. using df::global::ui;
  45.  
  46. DFHACK_PLUGIN("wagonshotarray");
  47.  
  48. command_result wagonshotarray (color_ostream &out, std::vector <std::string> & parameters);
  49.  
  50. // Mandatory init function. If you have some global state, create it here.
  51. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
  52. {
  53. // Fill the command list with your commands.
  54. commands.clear();
  55. commands.push_back(PluginCommand(
  56. "wagonshotarray",
  57. "End the targets violently.",
  58. wagonshotarray, false,
  59. " In a perfect world you wouldn't need to kill critters by the wagonload that are bursting into your fortress.\nBut this isn't a perfect world. So drop some wagons on them.\n\n'wagonshotarray' takes no arguments. Just cursor over your target, and the wagons will do the rest.\n"
  60. ));
  61. return CR_OK;
  62. }
  63.  
  64. DFhackCExport command_result plugin_shutdown ( color_ostream &out )
  65. {
  66. return CR_OK;
  67. }
  68.  
  69. command_result wagonshotarray (color_ostream &out, vector <string> & parameters)
  70. {
  71. CoreSuspender suspend;
  72. int32_t cursorX, cursorY, cursorZ;
  73. Gui::getCursorCoords(cursorX,cursorY,cursorZ);
  74. uint32_t totalcount = 0; //Scuttle Counter.
  75. std::basic_string<char, std::char_traits<char>, std::allocator<char>> targetted, istarget;
  76. set<int> targetIDs;
  77. if (!parameters.empty()) //Takes no parameters. 'wagonshotarray' is a mouthful as it is.
  78. return CR_WRONG_USAGE;
  79. if(cursorX == -30000)
  80. {
  81. out.printerr("No cursor; place cursor over creature to murder it and its buds.\n");
  82. }
  83. else
  84. {
  85. for(size_t i = 0; i < world->units.all.size(); i++)
  86. {
  87. df::unit * unit = world->units.all[i];
  88. if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ && unit->civ_id != ui->civ_id) //make sure they are NOT 'friendlies'
  89. {
  90. targetted = world->raws.creatures.all[Units::GetCreature(i)->race]->creature_id.c_str();
  91. //out.print("Targetting: %s\n",targetted.c_str()); //Now to just apply flags3.bits.scuttle = 1; to every id that is a 'targetted' and totalcount++ the shebang.
  92. for(size_t j = 0; j < world->units.all.size(); j++)
  93. {
  94. df::unit * unit2 = world->units.all[j];
  95. istarget = world->raws.creatures.all[Units::GetCreature(j)->race]->creature_id.c_str();
  96. if(unit2->civ_id != ui->civ_id && istarget == targetted && (unit2->flags2.bits.killed != 1 || unit2->flags1.bits.dead != 1))
  97. {
  98. unit2->flags3.bits.scuttle = 1;
  99. totalcount++;
  100. continue;
  101. }
  102. }
  103. continue;
  104. }
  105. if (unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ && unit->civ_id == ui->civ_id) //you've targetted a friendly.
  106. {
  107. out.print("I know them! I'm not dropping a wagon on any one of them even if they kill YOU.\n");
  108. continue;
  109. }
  110. }
  111. //out.print("Boom! Wagonshot! Every single %s we could see has a wagon on'em.\nBy my count that was %d in total.\n", targetted.c_str(), totalcount);
  112. }
  113. return CR_OK;
  114. }
Add Comment
Please, Sign In to add comment