ORAIN2.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 : ORAIN2.CPP
  21. // Description : class Rain
  22. // Ownership : Gilbert
  23. #include <ORAIN.h>
  24. #include <OVGABUF.h>
  25. //------- Begin of function Rain::start_rain --------------//
  26. //
  27. // short density = no. of drop created per turn (usually 2 to 12)
  28. // double slop = slop of the rain drop, 0.0 if no wind (fall vertically)
  29. // +ve for right, -ve for left.
  30. void Rain::start_rain(int x1, int y1, int x2, int y2, short density, double slope)
  31. {
  32. bound_x1 = x1;
  33. bound_y1 = y1;
  34. bound_x2 = x2;
  35. bound_y2 = y2;
  36. wind_slope = slope;
  37. drop_per_turn = density;
  38. clear();
  39. last_drop = -1;
  40. }
  41. //------- End of function Rain::start_rain --------------//
  42. //------- Begin of function Rain::clear --------------//
  43. //
  44. void Rain::clear()
  45. {
  46. for(int i = 0; i < MAX_RAINDROP; ++i)
  47. {
  48. drop_flag[i] = 0;
  49. spot_flag[i] = 0;
  50. }
  51. active_drop = 0;
  52. active_spot = 0;
  53. }
  54. //------- End of function Rain::clear --------------//
  55. //------- Begin of function Rain::stop_rain --------------//
  56. //
  57. void Rain::stop_rain()
  58. {
  59. drop_per_turn = 0;
  60. }
  61. //------- End of function Rain::stop_rain --------------//
  62. //------- Begin of function Rain::new_drops --------------//
  63. //
  64. void Rain::new_drops()
  65. {
  66. short dropRemain = drop_per_turn;
  67. short maxScan = MAX_RAINDROP;
  68. short i = last_drop;
  69. while(dropRemain > 0 && maxScan-- > 0)
  70. {
  71. i = (i + 1) % MAX_RAINDROP;
  72. if( !drop_flag[i])
  73. {
  74. short fromX = bound_x1+rand_seed()%(bound_x2-bound_x1);
  75. short height = (bound_y2-bound_y1)/8 + rand_seed()%(((bound_y2-bound_y1)*7)/8);
  76. short speed = height / 4;
  77. drop[i].init(this, fromX, (short)bound_y1, short(fromX+height*wind_slope),
  78. short(bound_y1+height), speed );
  79. drop_flag[i] = 1;
  80. active_drop++;
  81. dropRemain--;
  82. last_drop = i;
  83. }
  84. }
  85. }
  86. //------- End of function Rain::new_drops --------------//
  87. //------- Begin of function Rain::new_spot ---------//
  88. void Rain::new_spot(short x, short y)
  89. {
  90. short spotRemain = 1;
  91. short maxScan = MAX_RAINDROP;
  92. short i = last_spot;
  93. while(spotRemain > 0 && maxScan-- > 0)
  94. {
  95. i = (i + 1) % MAX_RAINDROP;
  96. if( !spot_flag[i])
  97. {
  98. spot[i].init(this, x,y, drop_per_turn>4 ? 6:4);
  99. spot_flag[i] = 1;
  100. active_spot++;
  101. spotRemain--;
  102. last_spot = i;
  103. }
  104. }
  105. }
  106. //------- End of function Rain::new_spot ---------//
  107. //------- Begin of function Rain::draw_step --------------//
  108. // note : call Rain::new_drops before Rain::draw_step
  109. //
  110. void Rain::draw_step(VgaBuf *vgabuf)
  111. {
  112. // --------- draw rain spot ------- //
  113. int i;
  114. for(i = 0; i < MAX_RAINDROP; ++i)
  115. {
  116. if( spot_flag[i])
  117. {
  118. spot[i].draw_step(vgabuf);
  119. spot_flag[i] = !spot[i].is_goal();
  120. }
  121. }
  122. // --------- draw rain drop ------- //
  123. for(i = 0; i < MAX_RAINDROP; ++i)
  124. {
  125. if(drop_flag[i])
  126. {
  127. drop[i].draw_step(vgabuf);
  128. if( drop[i].is_goal() )
  129. {
  130. new_spot(drop[i].dest_x, drop[i].dest_y);
  131. drop_flag[i] = 0;
  132. }
  133. }
  134. }
  135. }
  136. //------- End of function Rain::draw_step --------------//
  137. //------- Begin of function Rain::is_all_clear --------------//
  138. //
  139. int Rain::is_all_clear()
  140. {
  141. int count = 0;
  142. int i;
  143. for(i = 0; i < MAX_RAINDROP; ++i)
  144. if(drop_flag[i])
  145. count++;
  146. // update active_drop;
  147. active_drop = count;
  148. int count2 = 0;
  149. for(i = 0; i < MAX_RAINDROP; ++i)
  150. if(spot_flag[i])
  151. count2++;
  152. // update active_spot;
  153. active_spot = count2;
  154. return (count+count2 > 0);
  155. }
  156. //------- End of function Rain::is_all_clear --------------//
  157. //------- Begin of function Rain::rand_seed --------------//
  158. //
  159. unsigned Rain::rand_seed()
  160. {
  161. #define MULTIPLIER 0x015a4e35L
  162. #define INCREMENT 1
  163. seed = MULTIPLIER * seed + INCREMENT;
  164. return seed;
  165. }
  166. //------- End of function Rain::rand_seed --------------//