OEFFECT.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 : OEFFECT.CPP
  21. // Description : effect array
  22. // note : Effect and effect_array are not saved
  23. #include <OEFFECT.h>
  24. // ------- Begin of function Effect::Effect -------//
  25. Effect::Effect() : Sprite()
  26. {
  27. layer = 1; // default in land display layer
  28. life = 0; // disappear when life < 0
  29. }
  30. // ------- End of function Effect::Effect -------//
  31. // ------- Begin of function Effect::~Effect -------//
  32. Effect::~Effect()
  33. {
  34. }
  35. // ------- End of function Effect::~Effect -------//
  36. // ------- Begin of function Effect::init -------//
  37. //
  38. // for directed effect, put initAction as SPRITE_IDLE and set appropriate initDir
  39. // undirected effect, put initAction as SPRITE_DIE and set initDir to 0
  40. // to find the life of sprite automatically, set effectLife to 0 or negative
  41. //
  42. void Effect::init(short spriteId, short startX, short startY, char initAction, char initDir, char dispLayer, int effectLife)
  43. {
  44. sprite_id = spriteId;
  45. cur_x = startX;
  46. cur_y = startY;
  47. go_x = next_x = cur_x;
  48. go_y = next_y = cur_y;
  49. cur_attack = 0;
  50. err_when( initAction != SPRITE_IDLE && initAction != SPRITE_DIE);
  51. cur_action = initAction;
  52. cur_dir = initDir;
  53. cur_frame = 1;
  54. //----- clone vars from sprite_res for fast access -----//
  55. sprite_info = sprite_res[sprite_id];
  56. sprite_info->load_bitmap_res();
  57. // -------- adjust cur_dir -----------//
  58. if( sprite_info->turn_resolution <= 1)
  59. cur_dir = 0;
  60. final_dir = cur_dir;
  61. //------------- init other vars --------------//
  62. remain_attack_delay = 0;
  63. remain_frames_per_step = sprite_info->frames_per_step;
  64. layer = dispLayer;
  65. if( effectLife > 0)
  66. life = effectLife;
  67. else
  68. {
  69. switch( cur_action )
  70. {
  71. case SPRITE_IDLE:
  72. life = sprite_info->stop_array[cur_dir].frame_count - cur_frame;
  73. break;
  74. case SPRITE_DIE:
  75. life = sprite_info->die.frame_count - cur_frame;
  76. break;
  77. default:
  78. err_here();
  79. }
  80. }
  81. }
  82. // ------- End of function Effect::init -------//
  83. // ------- Begin of function Effect::pre_process -------//
  84. void Effect::pre_process()
  85. {
  86. if( --life < 0)
  87. {
  88. effect_array.del(sprite_recno);
  89. return;
  90. }
  91. }
  92. // ------- End of function Effect::pre_process -------//
  93. // ------- Begin of function Effect::process_idle -------//
  94. void Effect::process_idle()
  95. {
  96. if( ++cur_frame > cur_sprite_stop()->frame_count )
  97. cur_frame = 1;
  98. }
  99. // ------- End of function Effect::process_idle -------//
  100. // ------- Begin of function Effect::process_die -------//
  101. int Effect::process_die()
  102. {
  103. if( ++cur_frame > cur_sprite_die()->frame_count )
  104. cur_frame = 1;
  105. return 0;
  106. }
  107. // ------- End of function Effect::process_die -------//
  108. // ------- Begin of function Effect::create -------//
  109. void Effect::create(short spriteId, short startX, short startY, char initAction, char initDir, char dispLayer, int effectLife)
  110. {
  111. Effect *effectPtr = new Effect;
  112. effectPtr->init(spriteId, startX, startY, initAction, initDir, dispLayer, effectLife);
  113. effect_array.add(effectPtr);
  114. }
  115. // ------- End of function Effect::create -------//