2022-11-17 23:57:51 +02:00
|
|
|
/*
|
|
|
|
* CBattleFieldController.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/battle/BattleHex.h"
|
|
|
|
#include "../gui/CIntObject.h"
|
|
|
|
|
2022-11-29 02:00:08 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class CStack;
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-11-17 23:57:51 +02:00
|
|
|
struct SDL_Surface;
|
|
|
|
struct Rect;
|
|
|
|
struct Point;
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
class ClickableHex;
|
2022-12-11 22:09:57 +02:00
|
|
|
class Canvas;
|
2022-11-25 11:46:47 +02:00
|
|
|
class IImage;
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleInterface;
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleFieldController : public CIntObject
|
2022-11-17 23:57:51 +02:00
|
|
|
{
|
2022-12-09 13:26:17 +02:00
|
|
|
BattleInterface * owner;
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-11-25 11:46:47 +02:00
|
|
|
std::shared_ptr<IImage> background;
|
|
|
|
std::shared_ptr<IImage> cellBorder;
|
|
|
|
std::shared_ptr<IImage> cellShade;
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-11 22:09:57 +02:00
|
|
|
std::unique_ptr<Canvas> cellBorders;
|
2022-11-25 11:46:47 +02:00
|
|
|
|
|
|
|
/// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
|
2022-12-11 22:09:57 +02:00
|
|
|
std::unique_ptr<Canvas> backgroundWithHexes;
|
2022-11-25 11:46:47 +02:00
|
|
|
|
|
|
|
//BattleHex previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
|
|
|
|
//BattleHex currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
|
2022-11-17 23:57:51 +02:00
|
|
|
BattleHex attackingHex; //hex from which the stack would perform attack with current cursor
|
|
|
|
|
|
|
|
std::vector<BattleHex> occupyableHexes; //hexes available for active stack
|
|
|
|
std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes; // hexes that when in front of a unit cause it's amount box to move back
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
std::vector<std::shared_ptr<ClickableHex>> bfield; //11 lines, 17 hexes on each
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-11 22:09:57 +02:00
|
|
|
void showHighlightedHex(Canvas & to, BattleHex hex, bool darkBorder);
|
2022-11-25 11:46:47 +02:00
|
|
|
|
|
|
|
std::set<BattleHex> getHighlightedHexesStackRange();
|
|
|
|
std::set<BattleHex> getHighlightedHexesSpellRange();
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-11 22:09:57 +02:00
|
|
|
void showBackground(Canvas & canvas);
|
|
|
|
void showBackgroundImage(Canvas & canvas);
|
|
|
|
void showBackgroundImageWithHexes(Canvas & canvas);
|
|
|
|
void showHighlightedHexes(Canvas & canvas);
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-11-27 23:42:18 +02:00
|
|
|
public:
|
2022-12-09 13:26:17 +02:00
|
|
|
BattleFieldController(BattleInterface * owner);
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-11-27 23:42:18 +02:00
|
|
|
void redrawBackgroundWithHexes();
|
2022-12-11 22:09:57 +02:00
|
|
|
void renderBattlefield(Canvas & canvas);
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-11-25 11:46:47 +02:00
|
|
|
Rect hexPositionLocal(BattleHex hex) const;
|
2022-11-17 23:57:51 +02:00
|
|
|
Rect hexPosition(BattleHex hex) const;
|
|
|
|
bool isPixelInHex(Point const & position);
|
|
|
|
|
|
|
|
BattleHex getHoveredHex();
|
|
|
|
|
|
|
|
void setBattleCursor(BattleHex myNumber);
|
|
|
|
BattleHex fromWhichHexAttack(BattleHex myNumber);
|
|
|
|
bool isTileAttackable(const BattleHex & number) const;
|
|
|
|
bool stackCountOutsideHex(const BattleHex & number) const;
|
|
|
|
};
|