2022-11-17 23:57:51 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleFieldController.h, part of VCMI engine
|
2022-11-17 23:57:51 +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
|
|
|
|
|
|
|
|
#include "../../lib/battle/BattleHex.h"
|
|
|
|
#include "../gui/CIntObject.h"
|
|
|
|
|
2022-11-29 02:00:08 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class CStack;
|
2023-01-17 22:01:35 +02:00
|
|
|
class Rect;
|
|
|
|
class Point;
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2023-01-18 17:32:57 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-12-21 17:02:53 +02:00
|
|
|
class BattleHero;
|
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-11 23:16:23 +02:00
|
|
|
/// Handles battlefield grid as well as rendering of background layer of battle interface
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleFieldController : public CIntObject
|
2022-11-17 23:57:51 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +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-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
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// hex from which the stack would perform attack with current cursor
|
|
|
|
BattleHex attackingHex;
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// hexes to which currently active stack can move
|
|
|
|
std::vector<BattleHex> occupyableHexes;
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// hexes that when in front of a unit cause it's amount box to move back
|
|
|
|
std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;
|
|
|
|
|
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-12-18 19:00:06 +02:00
|
|
|
std::set<BattleHex> getHighlightedHexesMovementTarget();
|
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);
|
2023-03-29 12:03:40 +02:00
|
|
|
void updateAccessibleHexes();
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-19 01:12:26 +02:00
|
|
|
BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
|
2022-12-21 17:02:53 +02:00
|
|
|
|
2023-02-02 15:49:23 +02:00
|
|
|
void mouseMoved(const Point & cursorPosition) override;
|
2023-01-29 14:34:47 +02:00
|
|
|
void clickLeft(tribool down, bool previousState) override;
|
|
|
|
void clickRight(tribool down, bool previousState) override;
|
|
|
|
|
2022-12-21 17:02:53 +02:00
|
|
|
void showAll(SDL_Surface * to) override;
|
|
|
|
void show(SDL_Surface * to) override;
|
2022-11-27 23:42:18 +02:00
|
|
|
public:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleFieldController(BattleInterface & owner);
|
2022-11-17 23:57:51 +02:00
|
|
|
|
2022-12-21 17:02:53 +02:00
|
|
|
void createHeroes();
|
|
|
|
|
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-12-11 23:16:23 +02:00
|
|
|
/// Returns position of hex relative to owner (BattleInterface)
|
2022-11-25 11:46:47 +02:00
|
|
|
Rect hexPositionLocal(BattleHex hex) const;
|
2022-12-11 23:16:23 +02:00
|
|
|
|
|
|
|
/// Returns position of hex relative to game window
|
|
|
|
Rect hexPositionAbsolute(BattleHex hex) const;
|
|
|
|
|
|
|
|
/// Checks whether selected pixel is transparent, uses local coordinates of a hex
|
2022-11-17 23:57:51 +02:00
|
|
|
bool isPixelInHex(Point const & position);
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// Returns ID of currently hovered hex or BattleHex::INVALID if none
|
2022-11-17 23:57:51 +02:00
|
|
|
BattleHex getHoveredHex();
|
|
|
|
|
2022-12-11 23:16:23 +02:00
|
|
|
/// returns true if selected tile can be attacked in melee by current stack
|
2022-11-17 23:57:51 +02:00
|
|
|
bool isTileAttackable(const BattleHex & number) const;
|
2022-12-11 23:16:23 +02:00
|
|
|
|
|
|
|
/// returns true if stack should render its stack count image in default position - outside own hex
|
2022-11-17 23:57:51 +02:00
|
|
|
bool stackCountOutsideHex(const BattleHex & number) const;
|
2022-12-11 23:16:23 +02:00
|
|
|
|
|
|
|
void setBattleCursor(BattleHex myNumber);
|
|
|
|
BattleHex fromWhichHexAttack(BattleHex myNumber);
|
2022-11-17 23:57:51 +02:00
|
|
|
};
|