BattleObstacleController.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * BattleObstacleController.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. VCMI_LIB_NAMESPACE_BEGIN
  12. struct BattleHex;
  13. struct CObstacleInstance;
  14. class JsonNode;
  15. class ObstacleChanges;
  16. class Point;
  17. VCMI_LIB_NAMESPACE_END
  18. class IImage;
  19. class Canvas;
  20. class CAnimation;
  21. class BattleInterface;
  22. class BattleRenderer;
  23. /// Controls all currently active projectiles on the battlefield
  24. /// (with exception of moat, which is apparently handled by siege controller)
  25. class BattleObstacleController
  26. {
  27. BattleInterface & owner;
  28. /// total time, in seconds, since start of battle. Used for animating obstacles
  29. float timePassed;
  30. /// cached animations of all obstacles in current battle
  31. std::map<std::string, std::shared_ptr<CAnimation>> animationsCache;
  32. /// list of all obstacles that are currently being rendered
  33. std::map<si32, std::shared_ptr<CAnimation>> obstacleAnimations;
  34. void loadObstacleImage(const CObstacleInstance & oi);
  35. std::shared_ptr<IImage> getObstacleImage(const CObstacleInstance & oi);
  36. Point getObstaclePosition(std::shared_ptr<IImage> image, const CObstacleInstance & obstacle);
  37. Point getObstaclePosition(std::shared_ptr<IImage> image, const JsonNode & obstacle);
  38. public:
  39. BattleObstacleController(BattleInterface & owner);
  40. /// called every frame
  41. void tick(uint32_t msPassed);
  42. /// call-in from network pack, add newly placed obstacles with any required animations
  43. void obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & oi);
  44. /// call-in from network pack, remove required obstacles with any required animations
  45. void obstacleRemoved(const std::vector<ObstacleChanges> & obstacles);
  46. /// renders all "absolute" obstacles
  47. void showAbsoluteObstacles(Canvas & canvas);
  48. /// adds all non-"absolute" visible obstacles for rendering
  49. void collectRenderableObjects(BattleRenderer & renderer);
  50. };