CBattleProjectileController.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. struct Point;
  13. struct SDL_Surface;
  14. class CAnimation;
  15. class CStack;
  16. class CBattleInterface;
  17. /// Small struct which is needed for drawing the parabolic trajectory of the catapult cannon
  18. struct CatapultProjectileInfo
  19. {
  20. CatapultProjectileInfo(const Point &from, const Point &dest);
  21. double facA, facB, facC;
  22. double calculateY(double x);
  23. };
  24. /// Small struct which contains information about the position and the velocity of a projectile
  25. struct ProjectileInfo
  26. {
  27. double x0, y0; //initial position on the screen
  28. double x, y; //position on the screen
  29. double dx, dy; //change in position in one step
  30. int step, lastStep; //to know when finish showing this projectile
  31. int creID; //ID of creature that shot this projectile
  32. int stackID; //ID of stack
  33. int frameNum; //frame to display form projectile animation
  34. //bool spin; //if true, frameNum will be increased
  35. bool shotDone; // actual shot already done, projectile is flying
  36. bool reverse; //if true, projectile will be flipped by vertical asix
  37. std::shared_ptr<CatapultProjectileInfo> catapultInfo; // holds info about the parabolic trajectory of the cannon
  38. };
  39. class CBattleProjectileController
  40. {
  41. CBattleInterface * owner;
  42. std::map<int, std::shared_ptr<CAnimation>> idToProjectile;
  43. std::map<int, std::vector<CCreature::CreatureAnimation::RayColor>> idToRay;
  44. std::list<ProjectileInfo> projectiles; //projectiles flying on battlefield
  45. public:
  46. CBattleProjectileController(CBattleInterface * owner);
  47. void showProjectiles(SDL_Surface *to);
  48. void initStackProjectile(const CStack * stack);
  49. void fireStackProjectile(const CStack * stack);
  50. bool hasActiveProjectile(const CStack * stack);
  51. void createProjectile(const CStack * shooter, const CStack * target, Point from, Point dest);
  52. };