CBattleProjectileController.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * CBattleSiegeController.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../../lib/CCreatureHandler.h"
  12. #include "../gui/Geometries.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CStack;
  15. class CSpell;
  16. VCMI_LIB_NAMESPACE_END
  17. struct Point;
  18. struct SDL_Surface;
  19. class CAnimation;
  20. class CCanvas;
  21. class CBattleInterface;
  22. /// Small struct which contains information about the position and the velocity of a projectile
  23. struct ProjectileBase
  24. {
  25. virtual ~ProjectileBase() = default;
  26. virtual void show(std::shared_ptr<CCanvas> canvas) = 0;
  27. Point from; // initial position on the screen
  28. Point dest; // target position on the screen
  29. int step; // current step counter
  30. int steps; // total number of steps/frames to show
  31. int shooterID; // ID of shooter stack
  32. bool playing; // if set to true, projectile animation is playing, e.g. flying to target
  33. };
  34. struct ProjectileMissile : ProjectileBase
  35. {
  36. void show(std::shared_ptr<CCanvas> canvas) override;
  37. std::shared_ptr<CAnimation> animation;
  38. int frameNum; // frame to display from projectile animation
  39. bool reverse; // if true, projectile will be flipped by vertical axis
  40. };
  41. struct ProjectileAnimatedMissile : ProjectileMissile
  42. {
  43. void show(std::shared_ptr<CCanvas> canvas) override;
  44. float frameProgress;
  45. };
  46. struct ProjectileCatapult : ProjectileBase
  47. {
  48. void show(std::shared_ptr<CCanvas> canvas) override;
  49. std::shared_ptr<CAnimation> animation;
  50. int frameNum; // frame to display from projectile animation
  51. };
  52. struct ProjectileRay : ProjectileBase
  53. {
  54. void show(std::shared_ptr<CCanvas> canvas) override;
  55. std::vector<CCreature::CreatureAnimation::RayColor> rayConfig;
  56. };
  57. class CBattleProjectileController
  58. {
  59. CBattleInterface * owner;
  60. /// all projectiles loaded during current battle
  61. std::map<std::string, std::shared_ptr<CAnimation>> projectilesCache;
  62. // std::map<int, std::shared_ptr<CAnimation>> idToProjectile;
  63. // std::map<int, std::vector<CCreature::CreatureAnimation::RayColor>> idToRay;
  64. /// projectiles currently flying on battlefield
  65. std::vector<std::shared_ptr<ProjectileBase>> projectiles;
  66. std::shared_ptr<CAnimation> getProjectileImage(const CStack * stack);
  67. std::shared_ptr<CAnimation> createProjectileImage(const std::string & path );
  68. void initStackProjectile(const CStack * stack);
  69. bool stackUsesRayProjectile(const CStack * stack);
  70. bool stackUsesMissileProjectile(const CStack * stack);
  71. void showProjectile(std::shared_ptr<CCanvas> canvas, std::shared_ptr<ProjectileBase> projectile);
  72. const CCreature * getShooter(const CStack * stack);
  73. int computeProjectileFrameID( Point from, Point dest, const CStack * stack);
  74. int computeProjectileFlightTime( Point from, Point dest, double speed);
  75. public:
  76. CBattleProjectileController(CBattleInterface * owner);
  77. void showProjectiles(std::shared_ptr<CCanvas> canvas);
  78. bool hasActiveProjectile(const CStack * stack);
  79. void emitStackProjectile(const CStack * stack);
  80. void createProjectile(const CStack * shooter, const CStack * target, Point from, Point dest);
  81. void createSpellProjectile(const CStack * shooter, const CStack * target, Point from, Point dest, const CSpell * spell);
  82. void createCatapultProjectile(const CStack * shooter, Point from, Point dest);
  83. };