BattleObstacleController.h 2.0 KB

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