OSNOWG.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 : OSNOWG.CPP
  21. // Description : the bitmap of a snow ground bitmap
  22. // Owner : Gilbert
  23. #include <OSNOWG.h>
  24. #include <OSNOWRES.h>
  25. #include <OWEATHER.h>
  26. #include <OWORLDMT.h>
  27. // ------- Define constant --------//
  28. #define SCAN_DENSITY 4
  29. #define INC_SNOW_CONSTANT 8
  30. #define INC_SNOW_RATE 8
  31. #define MAX_SNOW_THICKNESS 0x1800
  32. #define DEC_SNOW_RATE 10
  33. #define SNOW_GRADE_FACTOR 0x200
  34. // ------- Begin of function SnowGround::init --------//
  35. //
  36. // initialize a snowGround
  37. // <short> absX,absY absolute coordinate (pixels on the map)
  38. // [short] snowMapId snow bitmap id, (default : choose randomly)
  39. //
  40. void SnowGround::init(short absX, short absY, int snowMapId)
  41. {
  42. abs_x = absX;
  43. abs_y = absY;
  44. snow_map_id = snowMapId ? snowMapId : snow_res.rand_root(m.random(1000));
  45. minor_hp = 0;
  46. SnowInfo *snowInfo = snow_res[snow_map_id];
  47. abs_x1 = abs_x + snowInfo->offset_x;
  48. abs_y1 = abs_y + snowInfo->offset_y;
  49. abs_x2 = abs_x1 + snowInfo->bitmap_width()-1;
  50. abs_y2 = abs_y1 + snowInfo->bitmap_height()-1;
  51. }
  52. // ------- End of function SnowGround::init --------//
  53. // ------- Begin of function SnowGround::grow --------//
  54. void SnowGround::grow(int rate)
  55. {
  56. minor_hp += rate;
  57. if( minor_hp > 100)
  58. {
  59. minor_hp -= 100;
  60. snow_map_id = snow_res[snow_map_id]->rand_next(m.random(1000));
  61. SnowInfo *snowInfo = snow_res[snow_map_id];
  62. abs_x1 = abs_x + snowInfo->offset_x;
  63. abs_x1 = abs_y + snowInfo->offset_y;
  64. abs_x2 = abs_x1 + snowInfo->bitmap_width()-1;
  65. abs_y2 = abs_y1 + snowInfo->bitmap_height()-1;
  66. }
  67. }
  68. // ------- End of function SnowGround::grow --------//
  69. // ------- Begin of function SnowGround::dying --------//
  70. int SnowGround::dying(int rate)
  71. {
  72. minor_hp -= rate;
  73. if( minor_hp < 0)
  74. {
  75. if( snow_res[snow_map_id]->is_root() )
  76. {
  77. snow_map_id = 0;
  78. return 1;
  79. }
  80. else
  81. {
  82. minor_hp += 100;
  83. snow_map_id = snow_res[snow_map_id]->rand_prev(m.random(1000));
  84. SnowInfo *snowInfo = snow_res[snow_map_id];
  85. abs_x1 = abs_x + snowInfo->offset_x;
  86. abs_x1 = abs_y + snowInfo->offset_y;
  87. abs_x2 = abs_x1 + snowInfo->bitmap_width()-1;
  88. abs_y2 = abs_y1 + snowInfo->bitmap_height()-1;
  89. }
  90. }
  91. return 0;
  92. }
  93. // ------- End of function SnowGround::dying --------//
  94. // ------- Begin of function SnowGroundArray::init ------//
  95. void SnowGroundArray::init(long initSnowScale, long anyNumber)
  96. {
  97. snow_thick = initSnowScale * MAX_SNOW_THICKNESS / 8;
  98. snow_pattern = (anyNumber & 255) + 1;
  99. }
  100. // ------- End of function SnowGroundArray::init ------//
  101. // ------ Begin of function SnowGroundArray::inc_snow -----//
  102. void SnowGroundArray::inc_snow(int snowScale)
  103. {
  104. if( snowScale > 0)
  105. {
  106. snow_thick += (snowScale + INC_SNOW_CONSTANT ) * INC_SNOW_RATE;
  107. if( snow_thick > MAX_SNOW_THICKNESS )
  108. snow_thick = MAX_SNOW_THICKNESS;
  109. }
  110. }
  111. // ------ End of function SnowGroundArray::inc_snow -----//
  112. // ------ Begin of function SnowGroundArray::dec_snow -----//
  113. void SnowGroundArray::dec_snow(int decRate)
  114. {
  115. decRate *= DEC_SNOW_RATE;
  116. if( snow_thick > 0)
  117. {
  118. if( snow_thick <= decRate )
  119. {
  120. snow_thick = 0;
  121. snow_pattern = (snow_pattern & 255) + 1;
  122. }
  123. else
  124. {
  125. snow_thick -= decRate;
  126. }
  127. }
  128. }
  129. // ------ End of function SnowGroundArray::dec_snow -----//
  130. // ------ Begin of function SnowGroundArray::process -----//
  131. void SnowGroundArray::process()
  132. {
  133. int snowScale = weather.snow_scale();
  134. if( snowScale > 0)
  135. {
  136. inc_snow(snowScale);
  137. }
  138. else
  139. {
  140. dec_snow(weather.temp_c() );
  141. }
  142. }
  143. // ------ End of function SnowGroundArray::process -----//
  144. // ------ Begin of function SnowGroundArray::has_snow -------//
  145. int SnowGroundArray::has_snow(short x, short y)
  146. {
  147. seed = (snow_pattern << 16) + (x+y+257)*(5*x+y+1);
  148. (void) rand_seed();
  149. long height = (rand_seed() & 0xffff) - (0xffff - snow_thick);
  150. if( height <= 0)
  151. return 0;
  152. int snowGrade = height / SNOW_GRADE_FACTOR;
  153. SnowInfo *snowInfo = snow_res[snow_res.rand_root(rand_seed()/4)];
  154. for( ; snowGrade > 0; --snowGrade)
  155. {
  156. snowInfo = snowInfo->rand_next_ptr(rand_seed()/4);
  157. }
  158. return snowInfo->snow_map_id;
  159. }
  160. // ------ End of function SnowGroundArray::has_snow -------//
  161. // ------ Begin of function SnowGroundArray::random -------//
  162. unsigned SnowGroundArray::rand_seed()
  163. {
  164. #define MULTIPLIER 0x015a4e35L
  165. #define INCREMENT 1
  166. seed = MULTIPLIER * seed + INCREMENT;
  167. return seed;
  168. }
  169. // ------ End of function SnowGroundArray::random -------//