OB_PROJ.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 : OB_PROJ.CPP
  21. // Description : header file for Projectile
  22. // Owner : Gilbert
  23. #include <OB_PROJ.h>
  24. // the height of projectile is as follow :
  25. // z = z_coff * (cur_step+1) * (total_step+1 - cur_step ));
  26. // the gradient of projectile is
  27. // dz/d(cur_step) = z_coff * (total_step - 2 * (cur_step) );
  28. // if dz/d(cur_step) >= 10.0 use upward frame,
  29. // if dz/d(cur_step) <= -10.0 use downward frame,
  30. // actual bullet (x,y,z) is drawn at (x, y - z)
  31. // shadow is drawn at set_cur(x - z/8, y - z/6);
  32. // --------- Begin of function Projectile::Projectile --------//
  33. Projectile::Projectile() : Bullet(), act_bullet(), bullet_shadow()
  34. {
  35. act_bullet.sprite_recno = 0;
  36. bullet_shadow.sprite_recno = 0;
  37. }
  38. // --------- End of function Projectile::Projectile --------//
  39. // --------- Begin of function Projectile::~Projectile --------//
  40. Projectile::~Projectile()
  41. {
  42. deinit();
  43. }
  44. // --------- End of function Projectile::~Projectile --------//
  45. // --------- Begin of function Projectile::init --------//
  46. //### begin alex 3/5 ###//
  47. void Projectile::init(char parentType, short parentRecno, short targetXLoc, short targetYLoc, char targetMobileType)
  48. {
  49. Bullet::init(parentType, parentRecno, targetXLoc, targetYLoc, targetMobileType);
  50. //#### end alex 3/5 ####//
  51. short spriteId = sprite_info->get_sub_sprite_info(1)->sprite_id;
  52. act_bullet.init( spriteId, cur_x_loc(), cur_y_loc() );
  53. short shadowSpriteId = sprite_info->get_sub_sprite_info(2)->sprite_id;
  54. bullet_shadow.init( shadowSpriteId, cur_x_loc(), cur_y_loc() );
  55. // calculate z_coff;
  56. z_coff = (float)1.0;
  57. /*
  58. float dz = z_coff * total_step;
  59. if( dz >= 10.0)
  60. cur_dir = cur_dir & 7 | 8; // pointing up
  61. else if( dz <= -10.0)
  62. cur_dir = cur_dir & 7 | 16; // pointing down
  63. else
  64. cur_dir &= 7;
  65. */
  66. // --------- recalcuate spriteFrame pointer ----------//
  67. SpriteFrame* spriteFrame = cur_sprite_frame();
  68. }
  69. // --------- End of function Projectile::init --------//
  70. // --------- Begin of function Projectile::deinit --------//
  71. void Projectile::deinit()
  72. {
  73. }
  74. // --------- End of function Projectile::deinit --------//
  75. // --------- Begin of function Projectile::draw --------//
  76. void Projectile::draw()
  77. {
  78. short z = short(z_coff * (cur_step+1) * (total_step+1 - cur_step ));
  79. if(z < 0)
  80. z = 0;
  81. // does not draw itself but the shadow and the actual bullet
  82. if( cur_action == SPRITE_MOVE )
  83. {
  84. // -------- update cur_frame ----------//
  85. float dz = z_coff * (total_step - 2 * (cur_step) );
  86. if( dz >= 10.0)
  87. final_dir = (final_dir & 7 )| 8; // pointing up
  88. else if( dz <= -10.0)
  89. final_dir = (final_dir & 7 )| 16; // pointing down
  90. else
  91. final_dir &= 7;
  92. // ------- update bullet_shadow coordinate --------//
  93. err_when((bullet_shadow.sprite_info)->need_turning);
  94. bullet_shadow.set_dir(final_dir);
  95. bullet_shadow.cur_frame = cur_frame;
  96. bullet_shadow.cur_action = SPRITE_MOVE;
  97. bullet_shadow.set_cur(cur_x - z / 8, cur_y - z / 6);
  98. // ------- update act_bullet coordinate --------//
  99. err_when((act_bullet.sprite_info)->need_turning);
  100. act_bullet.set_dir(final_dir);
  101. act_bullet.cur_frame = cur_frame;
  102. act_bullet.cur_action = SPRITE_MOVE;
  103. act_bullet.set_cur(cur_x, cur_y - z);
  104. bullet_shadow.draw();
  105. act_bullet.draw();
  106. // restore cur_dir
  107. set_dir((final_dir&7));
  108. }
  109. else
  110. {
  111. // ###### begin Gilbert 17/10 #########//
  112. char finalDirBackup = final_dir;
  113. if( cur_action == SPRITE_DIE )
  114. set_dir((final_dir & 7) | 16); // downward direction
  115. Bullet::draw();
  116. if( cur_action == SPRITE_DIE )
  117. set_dir(finalDirBackup); // downward direction
  118. // ###### end Gilbert 17/10 #########//
  119. }
  120. }
  121. // --------- End of function Projectile::draw --------//
  122. // --------- Begin of function Projectile::display_layer --------//
  123. char Projectile::display_layer()
  124. {
  125. //### begin alex 3/5 ###//
  126. if(mobile_type == UNIT_AIR || target_mobile_type==UNIT_AIR)
  127. //#### end alex 3/5 ####//
  128. return 8;
  129. else
  130. return 2;
  131. }
  132. // --------- End of function Projectile::display_layer --------//