CBattleProjectileController.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. struct Point;
  14. struct SDL_Surface;
  15. class CAnimation;
  16. class CCanvas;
  17. class CStack;
  18. class CBattleInterface;
  19. /// Small struct which contains information about the position and the velocity of a projectile
  20. struct ProjectileBase
  21. {
  22. virtual ~ProjectileBase() = default;
  23. virtual void show(std::shared_ptr<CCanvas> canvas) = 0;
  24. Point from; // initial position on the screen
  25. Point dest; // target position on the screen
  26. int step; // current step counter
  27. int steps; // total number of steps/frames to show
  28. int shooterID; // ID of shooter stack
  29. bool playing; // if set to true, projectile animation is playing, e.g. flying to target
  30. };
  31. struct ProjectileMissile : ProjectileBase
  32. {
  33. void show(std::shared_ptr<CCanvas> canvas) override;
  34. std::shared_ptr<CAnimation> animation;
  35. int frameNum; // frame to display from projectile animation
  36. bool reverse; // if true, projectile will be flipped by vertical axis
  37. };
  38. struct ProjectileCatapult : ProjectileMissile
  39. {
  40. void show(std::shared_ptr<CCanvas> canvas) override;
  41. int wallDamageAmount;
  42. };
  43. struct ProjectileRay : ProjectileBase
  44. {
  45. void show(std::shared_ptr<CCanvas> canvas) override;
  46. std::vector<CCreature::CreatureAnimation::RayColor> rayConfig;
  47. };
  48. class CBattleProjectileController
  49. {
  50. CBattleInterface * owner;
  51. /// all projectiles loaded during current battle
  52. std::map<std::string, std::shared_ptr<CAnimation>> projectilesCache;
  53. // std::map<int, std::shared_ptr<CAnimation>> idToProjectile;
  54. // std::map<int, std::vector<CCreature::CreatureAnimation::RayColor>> idToRay;
  55. /// projectiles currently flying on battlefield
  56. std::vector<std::shared_ptr<ProjectileBase>> projectiles;
  57. std::shared_ptr<CAnimation> getProjectileImage(const CStack * stack);
  58. void initStackProjectile(const CStack * stack);
  59. bool stackUsesRayProjectile(const CStack * stack);
  60. bool stackUsesMissileProjectile(const CStack * stack);
  61. void showProjectile(std::shared_ptr<CCanvas> canvas, std::shared_ptr<ProjectileBase> projectile);
  62. const CCreature * getShooter(const CStack * stack);
  63. public:
  64. CBattleProjectileController(CBattleInterface * owner);
  65. void showProjectiles(std::shared_ptr<CCanvas> canvas);
  66. bool hasActiveProjectile(const CStack * stack);
  67. void emitStackProjectile(const CStack * stack);
  68. void createProjectile(const CStack * shooter, const CStack * target, Point from, Point dest);
  69. };