OU_CART.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. // Filename : OU_CART.CPP
  21. // Description : Explosive Cart
  22. #include <OU_CART.h>
  23. // --------- define constant --------//
  24. #define EXPLODE_RANGE 1
  25. #define EXPLODE_DAMAGE 50
  26. #define CHAIN_TRIGGER_RANGE 2
  27. UnitExpCart::UnitExpCart() : Unit()
  28. {
  29. triggered = 0;
  30. }
  31. UnitExpCart::~UnitExpCart()
  32. {
  33. }
  34. int UnitExpCart::process_die()
  35. {
  36. if(triggered && cur_frame == 3)
  37. {
  38. short x, y;
  39. short x1 = next_x_loc();
  40. short x2 = x1;
  41. short y1 = next_y_loc();
  42. short y2 = y1;
  43. x1 -= CHAIN_TRIGGER_RANGE;
  44. x2 += CHAIN_TRIGGER_RANGE;
  45. y1 -= CHAIN_TRIGGER_RANGE;
  46. y2 += CHAIN_TRIGGER_RANGE;
  47. if(x1 < 0)
  48. x1 = 0;
  49. if(x2 >= world.max_x_loc)
  50. x2 = world.max_x_loc-1;
  51. if(y1 < 0)
  52. y1 = 0;
  53. if(y2 >= world.max_y_loc)
  54. y2 = world.max_y_loc-1;
  55. for( y = y1; y <= y2; ++y)
  56. {
  57. for( x = x1; x <= x2; ++x)
  58. {
  59. Location *locPtr = world.get_loc(x,y);
  60. if( locPtr->has_unit(UNIT_LAND) )
  61. {
  62. Unit *unitPtr = unit_array[locPtr->unit_recno(UNIT_LAND)];
  63. if( unitPtr->unit_id == UNIT_EXPLOSIVE_CART )
  64. ((UnitExpCart *)unitPtr)->trigger_explode();
  65. }
  66. }
  67. }
  68. }
  69. if(triggered && (cur_frame == 3 || cur_frame == 7) )
  70. {
  71. short x, y;
  72. short x1 = next_x_loc();
  73. short x2 = x1;
  74. short y1 = next_y_loc();
  75. short y2 = y1;
  76. x1 -= EXPLODE_RANGE;
  77. x2 += EXPLODE_RANGE;
  78. y1 -= EXPLODE_RANGE;
  79. y2 += EXPLODE_RANGE;
  80. if(x1 < 0)
  81. x1 = 0;
  82. if(x2 >= world.max_x_loc)
  83. x2 = world.max_x_loc-1;
  84. if(y1 < 0)
  85. y1 = 0;
  86. if(y2 >= world.max_y_loc)
  87. y2 = world.max_y_loc-1;
  88. if( cur_frame == 3)
  89. {
  90. for( y = y1; y <= y2; ++y)
  91. {
  92. for( x = x1; x <= x2; ++x)
  93. {
  94. Location *locPtr = world.get_loc(x,y);
  95. if( locPtr->has_unit(UNIT_LAND) )
  96. {
  97. hit_target(this, unit_array[locPtr->unit_recno(UNIT_LAND)], (float) EXPLODE_DAMAGE);
  98. }
  99. else if( locPtr->has_unit(UNIT_SEA) )
  100. {
  101. hit_target(this, unit_array[locPtr->unit_recno(UNIT_SEA)], (float) EXPLODE_DAMAGE);
  102. }
  103. else if( locPtr->is_wall() )
  104. {
  105. hit_wall(this, x, y, (float) EXPLODE_DAMAGE);
  106. }
  107. else if( locPtr->is_plant() )
  108. {
  109. locPtr->remove_plant();
  110. world.plant_count--;
  111. }
  112. else
  113. {
  114. hit_building(this, x, y, (float) EXPLODE_DAMAGE);
  115. }
  116. }
  117. }
  118. }
  119. else if(cur_frame == 7)
  120. {
  121. for( y = y1; y <= y2; ++y)
  122. {
  123. for( x = x1; x <= x2; ++x)
  124. {
  125. Location *locPtr = world.get_loc(x,y);
  126. // ##### begin Gilbert 30/10 ######//
  127. int fl = (abs(x - next_x_loc()) + abs(y - next_y_loc())) * -30 + 80;
  128. if( locPtr->can_set_fire() && locPtr->fire_str() < fl )
  129. locPtr->set_fire_str(fl);
  130. if( locPtr->fire_src() > 0 )
  131. locPtr->set_fire_src(1); // such that the fire will be put out quickly
  132. // ##### end Gilbert 30/10 ######//
  133. }
  134. }
  135. }
  136. }
  137. return Unit::process_die();
  138. }
  139. void UnitExpCart::trigger_explode()
  140. {
  141. if( hit_points > 0) // so dying cart cannot be triggered
  142. {
  143. triggered = 1;
  144. hit_points = (float) 0;
  145. }
  146. }