OSPREDBG.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifdef NO_DEBUG_SEARCH
  21. #undef err_when
  22. #undef err_here
  23. #undef err_if
  24. #undef err_else
  25. #undef err_now
  26. #define err_when(cond)
  27. #define err_here()
  28. #define err_if(cond)
  29. #define err_else
  30. #define err_now(msg)
  31. #undef DEBUG
  32. #endif
  33. #include <OSPREUSE.h>
  34. #ifdef DEBUG
  35. #include <OSYS.h>
  36. static ResultNode* debugSrePtr; // for debug only
  37. static ResultNode* debugSreNode1;
  38. static ResultNode* debugSreNode2;
  39. static int debugSreCount;
  40. static int debugSreVX, debugSreVY; // for debug only
  41. //------------- function debug_check() --------------//
  42. void SeekPathReuse::debug_check()
  43. {
  44. debugSreNode1 = path_reuse_result_node_ptr;
  45. debugSreNode2 = path_reuse_result_node_ptr+1;
  46. for(debugSreCount=1; debugSreCount<num_of_result_node; debugSreCount++, debugSreNode1++, debugSreNode2++)
  47. {
  48. err_when(debugSreNode1->node_x<0 || debugSreNode1->node_x>=MAX_WORLD_X_LOC ||
  49. debugSreNode1->node_y<0 || debugSreNode1->node_y>=MAX_WORLD_Y_LOC);
  50. debugSreVX = debugSreNode2->node_x - debugSreNode1->node_x;
  51. debugSreVY = debugSreNode2->node_y - debugSreNode1->node_y;
  52. err_when(debugSreVX!=0 && debugSreVY!=0 && (abs(debugSreVX)!=abs(debugSreVY)));
  53. }
  54. err_when(debugSreNode1->node_x<0 || debugSreNode1->node_x>=MAX_WORLD_X_LOC ||
  55. debugSreNode1->node_y<0 || debugSreNode1->node_y>=MAX_WORLD_Y_LOC);
  56. }
  57. //-------------- function debug_check_magnitude() ---------------//
  58. void SeekPathReuse::debug_check_magnitude(int x1, int y1, int x2, int y2)
  59. {
  60. debugSreVX = x1-x2;
  61. debugSreVY = y1-y2;
  62. err_when(debugSreVX!=0 && debugSreVY!=0 && abs(debugSreVX)!=abs(debugSreVY));
  63. }
  64. //------------ function debug_check_smode_node() -------------//
  65. void SeekPathReuse::debug_check_smode_node(int x, int y)
  66. {
  67. if(reuse_search_sub_mode!=SEARCH_SUB_MODE_PASSABLE)
  68. return;
  69. Location *locPtr = world.get_loc(x, y);
  70. if(locPtr->power_nation_recno && !reuse_nation_passable[locPtr->power_nation_recno])
  71. err_here();
  72. }
  73. //------------- function debug_check_sub_mode_path() -------------//
  74. void SeekPathReuse::debug_check_sub_mode_path(ResultNode *nodeArray, int count)
  75. {
  76. ResultNode *debugSreNode1 = nodeArray;
  77. ResultNode *debugSreNode2 = debugSreNode1+1;
  78. int checkXLoc, checkYLoc, magn;
  79. for(int di=1; di<count; di++, debugSreNode1++, debugSreNode2++)
  80. {
  81. checkXLoc = debugSreNode1->node_x;
  82. checkYLoc = debugSreNode1->node_y;
  83. debugSreVX = debugSreNode2->node_x - debugSreNode1->node_x;
  84. debugSreVY = debugSreNode2->node_y - debugSreNode1->node_y;
  85. magn = (abs(debugSreVX) >= abs(debugSreVY)) ? abs(debugSreVX) : abs(debugSreVY);
  86. if(debugSreVX) debugSreVX /= abs(debugSreVX);
  87. if(debugSreVY) debugSreVY /= abs(debugSreVY);
  88. if(!magn)
  89. continue;
  90. for(int dj=0; dj<magn; dj++)
  91. {
  92. checkXLoc += debugSreVX;
  93. checkYLoc += debugSreVY;
  94. debug_check_smode_node(checkXLoc, checkYLoc);
  95. }
  96. }
  97. }
  98. #endif