2022-11-17 13:21:03 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleObstacleController.h, part of VCMI engine
|
2022-11-17 13:21:03 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2022-11-29 02:00:08 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-11-25 00:26:14 +02:00
|
|
|
struct BattleHex;
|
2022-11-29 02:00:08 +02:00
|
|
|
struct CObstacleInstance;
|
2023-03-26 18:57:21 +02:00
|
|
|
class JsonNode;
|
|
|
|
class ObstacleChanges;
|
2023-01-18 17:32:57 +02:00
|
|
|
class Point;
|
2022-11-29 02:00:08 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-11-17 19:36:25 +02:00
|
|
|
class IImage;
|
2022-12-11 22:09:57 +02:00
|
|
|
class Canvas;
|
2022-11-17 19:36:25 +02:00
|
|
|
class CAnimation;
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleInterface;
|
|
|
|
class BattleRenderer;
|
2022-11-17 19:36:25 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// Controls all currently active projectiles on the battlefield
|
|
|
|
/// (with exception of moat, which is apparently handled by siege controller)
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleObstacleController
|
2022-11-17 13:21:03 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleInterface & owner;
|
2022-11-17 19:36:25 +02:00
|
|
|
|
2022-12-21 17:02:53 +02:00
|
|
|
/// total time, in seconds, since start of battle. Used for animating obstacles
|
|
|
|
float timePassed;
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// cached animations of all obstacles in current battle
|
|
|
|
std::map<std::string, std::shared_ptr<CAnimation>> animationsCache;
|
|
|
|
|
|
|
|
/// list of all obstacles that are currently being rendered
|
2022-11-17 19:36:25 +02:00
|
|
|
std::map<si32, std::shared_ptr<CAnimation>> obstacleAnimations;
|
2022-11-25 00:26:14 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void loadObstacleImage(const CObstacleInstance & oi);
|
|
|
|
|
2022-11-25 00:26:14 +02:00
|
|
|
std::shared_ptr<IImage> getObstacleImage(const CObstacleInstance & oi);
|
|
|
|
Point getObstaclePosition(std::shared_ptr<IImage> image, const CObstacleInstance & obstacle);
|
2023-03-26 18:57:21 +02:00
|
|
|
Point getObstaclePosition(std::shared_ptr<IImage> image, const JsonNode & obstacle);
|
2022-11-25 00:26:14 +02:00
|
|
|
|
2022-11-17 19:36:25 +02:00
|
|
|
public:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleObstacleController(BattleInterface & owner);
|
2022-11-17 19:36:25 +02:00
|
|
|
|
2022-12-21 17:02:53 +02:00
|
|
|
/// called every frame
|
2023-05-13 22:38:57 +02:00
|
|
|
void tick(uint32_t msPassed);
|
2022-12-21 17:02:53 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// call-in from network pack, add newly placed obstacles with any required animations
|
2022-12-01 22:06:42 +02:00
|
|
|
void obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & oi);
|
2022-12-11 23:16:23 +02:00
|
|
|
|
2023-03-26 18:57:21 +02:00
|
|
|
/// call-in from network pack, remove required obstacles with any required animations
|
|
|
|
void obstacleRemoved(const std::vector<ObstacleChanges> & obstacles);
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// renders all "absolute" obstacles
|
2023-01-05 14:16:01 +02:00
|
|
|
void showAbsoluteObstacles(Canvas & canvas);
|
2022-11-17 19:36:25 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// adds all non-"absolute" visible obstacles for rendering
|
2022-12-09 13:26:17 +02:00
|
|
|
void collectRenderableObjects(BattleRenderer & renderer);
|
2022-11-17 13:21:03 +02:00
|
|
|
};
|