| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /*
- * BattleSiegeController.h, part of VCMI engine
- *
- * 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
- #include "../../lib/CCreatureHandler.h"
- #include "../gui/Geometries.h"
- VCMI_LIB_NAMESPACE_BEGIN
- class CStack;
- class CSpell;
- VCMI_LIB_NAMESPACE_END
- struct Point;
- class CAnimation;
- class Canvas;
- class BattleInterface;
- /// Base class for projectiles
- struct ProjectileBase
- {
- virtual ~ProjectileBase() = default;
- virtual void show(Canvas & canvas) = 0;
- Point from; // initial position on the screen
- Point dest; // target position on the screen
- int step; // current step counter
- int steps; // total number of steps/frames to show
- int shooterID; // ID of shooter stack
- bool playing; // if set to true, projectile animation is playing, e.g. flying to target
- };
- /// Projectile for most shooters - render pre-selected frame moving in straight line from origin to destination
- struct ProjectileMissile : ProjectileBase
- {
- void show(Canvas & canvas) override;
- std::shared_ptr<CAnimation> animation;
- int frameNum; // frame to display from projectile animation
- bool reverse; // if true, projectile will be flipped by vertical axis
- };
- /// Projectile for spell - render animation moving in straight line from origin to destination
- struct ProjectileAnimatedMissile : ProjectileMissile
- {
- void show(Canvas & canvas) override;
- float frameProgress;
- };
- /// Projectile for catapult - render spinning projectile moving at parabolic trajectory to its destination
- struct ProjectileCatapult : ProjectileBase
- {
- void show(Canvas & canvas) override;
- std::shared_ptr<CAnimation> animation;
- int frameNum; // frame to display from projectile animation
- };
- /// Projectile for mages/evil eye - render ray expanding from origin position to destination
- struct ProjectileRay : ProjectileBase
- {
- void show(Canvas & canvas) override;
- std::vector<CCreature::CreatureAnimation::RayColor> rayConfig;
- };
- /// Class that manages all ongoing projectiles in the game
- /// ... even though in H3 only 1 projectile can be on screen at any point of time
- class BattleProjectileController
- {
- BattleInterface & owner;
- /// all projectiles loaded during current battle
- std::map<std::string, std::shared_ptr<CAnimation>> projectilesCache;
- /// projectiles currently flying on battlefield
- std::vector<std::shared_ptr<ProjectileBase>> projectiles;
- std::shared_ptr<CAnimation> getProjectileImage(const CStack * stack);
- std::shared_ptr<CAnimation> createProjectileImage(const std::string & path );
- void initStackProjectile(const CStack * stack);
- bool stackUsesRayProjectile(const CStack * stack) const;
- bool stackUsesMissileProjectile(const CStack * stack) const;
- void showProjectile(Canvas & canvas, std::shared_ptr<ProjectileBase> projectile);
- const CCreature & getShooter(const CStack * stack) const;
- int computeProjectileFrameID( Point from, Point dest, const CStack * stack);
- int computeProjectileFlightTime( Point from, Point dest, double speed);
- public:
- BattleProjectileController(BattleInterface & owner);
- /// renders all currently active projectiles
- void showProjectiles(Canvas & canvas);
- /// returns true if stack has projectile that is yet to hit target
- bool hasActiveProjectile(const CStack * stack) const;
- /// starts rendering previously created projectile
- void emitStackProjectile(const CStack * stack);
- /// creates (but not emits!) projectile and initializes it based on parameters
- void createProjectile(const CStack * shooter, Point from, Point dest);
- void createSpellProjectile(const CStack * shooter, Point from, Point dest, const CSpell * spell);
- void createCatapultProjectile(const CStack * shooter, Point from, Point dest);
- };
|