OROCK.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 : OROCK.CPP
  21. // Description : class Rock and RockArray
  22. // Owner : Gilbert
  23. #include <OROCK.h>
  24. #include <OROCKRES.h>
  25. // --------- define constant ----------//
  26. #define ROCK_ALT_PATH 19
  27. Rock::Rock(short rockRecno, short xLoc, short yLoc)
  28. {
  29. init( rockRecno, xLoc, yLoc );
  30. }
  31. void Rock::init(short rockRecno, short xLoc, short yLoc)
  32. {
  33. rock_recno = rockRecno;
  34. loc_x = xLoc;
  35. loc_y = yLoc;
  36. seed = (xLoc + yLoc + 3) * ( 2 * xLoc + 7 * yLoc + 5);
  37. // ------- random frame, random initial delay_remain -----//
  38. RockInfo *rockInfo = rock_res.get_rock_info(rockRecno);
  39. cur_frame = 1 + (char) random(rockInfo->max_frame);
  40. char initDelayCount = rock_res.get_anim_info(
  41. rock_res.get_anim_recno(rockRecno, cur_frame))->delay;
  42. delay_remain = 1 + (char) random(initDelayCount);
  43. }
  44. unsigned Rock::random(unsigned bound)
  45. {
  46. #define MULTIPLIER 0x015a4e35L
  47. #define INCREMENT 1
  48. seed = MULTIPLIER * seed + INCREMENT;
  49. return seed % bound;
  50. }
  51. void Rock::process()
  52. {
  53. if( --delay_remain <= 0)
  54. {
  55. cur_frame = rock_res.choose_next(rock_recno, cur_frame, random(ROCK_ALT_PATH) );
  56. delay_remain = rock_res.get_anim_info(rock_res.get_anim_recno(rock_recno, cur_frame))->delay;
  57. }
  58. }
  59. void Rock::draw()
  60. {
  61. rock_res.draw(rock_recno, loc_x, loc_y, cur_frame);
  62. }
  63. void Rock::draw_block(short xLoc, short yLoc)
  64. {
  65. rock_res.draw_block(rock_recno, xLoc, yLoc, xLoc-loc_x, yLoc-loc_y, cur_frame);
  66. }
  67. RockArray::RockArray(int initArraySize) : DynArrayB(sizeof(Rock),initArraySize, DEFAULT_REUSE_INTERVAL_DAYS)
  68. {
  69. }
  70. void RockArray::init()
  71. {
  72. zap();
  73. }
  74. void RockArray::deinit()
  75. {
  76. }
  77. void RockArray::process()
  78. {
  79. Rock* rockPtr;
  80. for( int i = 1; i <= size(); ++i)
  81. {
  82. if( (rockPtr = (Rock *)get(i)) != NULL)
  83. {
  84. rockPtr->process();
  85. }
  86. }
  87. }