2012-12-19 17:54:10 +03:00
|
|
|
/*
|
|
|
|
* CObstacleInstance.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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
#include "BattleHex.h"
|
2012-12-19 17:54:10 +03:00
|
|
|
|
2022-08-28 00:45:13 +02:00
|
|
|
struct ObstacleInfo;
|
2017-07-20 06:08:49 +02:00
|
|
|
class ObstacleChanges;
|
|
|
|
class JsonSerializeFormat;
|
2011-05-10 01:20:47 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
struct DLL_LINKAGE CObstacleInstance
|
2011-05-10 01:20:47 +03:00
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
BattleHex pos; //position on battlefield, typically left bottom corner
|
|
|
|
ui8 obstacleType; //if true, then position is meaningless
|
2012-04-23 22:56:37 +03:00
|
|
|
si32 uniqueID;
|
|
|
|
si32 ID; //ID of obstacle (defines type of it)
|
|
|
|
|
2012-05-05 00:16:39 +03:00
|
|
|
enum EObstacleType
|
|
|
|
{
|
2012-07-19 21:52:44 +03:00
|
|
|
//ABSOLUTE needs an underscore because it's a Win
|
2017-07-20 06:08:49 +02:00
|
|
|
USUAL, ABSOLUTE_OBSTACLE, SPELL_CREATED, MOAT
|
2012-05-05 00:16:39 +03:00
|
|
|
};
|
2012-04-23 22:56:37 +03:00
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
CObstacleInstance();
|
|
|
|
virtual ~CObstacleInstance();
|
|
|
|
|
2022-08-28 00:45:13 +02:00
|
|
|
const ObstacleInfo &getInfo() const; //allowed only when not generated by spell (usual or absolute)
|
2012-05-18 23:50:16 +03:00
|
|
|
|
|
|
|
std::vector<BattleHex> getBlockedTiles() const;
|
|
|
|
std::vector<BattleHex> getStoppingTile() const; //hexes that will stop stack move
|
|
|
|
|
|
|
|
//The two functions below describe how the obstacle affects affected tiles
|
|
|
|
//additional effects (like hurting stack or disappearing) are hardcoded for appropriate obstacleTypes
|
2017-07-20 06:08:49 +02:00
|
|
|
virtual bool blocksTiles() const;
|
|
|
|
virtual bool stopsMovement() const; //if unit stepping onto obstacle, can't continue movement (in general, doesn't checks for the side)
|
|
|
|
virtual bool triggersEffects() const;
|
2012-07-19 21:52:44 +03:00
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
virtual std::vector<BattleHex> getAffectedTiles() const;
|
|
|
|
virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
|
|
|
|
|
|
|
|
virtual void battleTurnPassed(){};
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
virtual int getAnimationYOffset(int imageHeight) const;
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & ID;
|
|
|
|
h & pos;
|
|
|
|
h & obstacleType;
|
|
|
|
h & uniqueID;
|
2012-05-18 23:50:16 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE MoatObstacle : CObstacleInstance
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
|
2012-05-18 23:50:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
int32_t turnsRemaining;
|
|
|
|
int32_t casterSpellPower;
|
|
|
|
int32_t spellLevel;
|
2012-05-05 00:16:39 +03:00
|
|
|
si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
bool hidden;
|
|
|
|
bool passable;
|
|
|
|
bool trigger;
|
|
|
|
bool trap;
|
|
|
|
bool removeOnTrigger;
|
|
|
|
|
|
|
|
bool revealed;
|
|
|
|
|
|
|
|
std::string appearAnimation;
|
|
|
|
std::string animation;
|
|
|
|
|
|
|
|
int animationYOffset;
|
|
|
|
|
|
|
|
std::vector<BattleHex> customSize;
|
2012-07-19 21:52:44 +03:00
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
SpellCreatedObstacle();
|
2012-05-05 00:16:39 +03:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<BattleHex> getAffectedTiles() const override;
|
|
|
|
bool visibleForSide(ui8 side, bool hasNativeStack) const override;
|
|
|
|
|
|
|
|
bool blocksTiles() const override;
|
|
|
|
bool stopsMovement() const override;
|
|
|
|
bool triggersEffects() const override;
|
|
|
|
|
|
|
|
void battleTurnPassed() override;
|
|
|
|
|
|
|
|
int getAnimationYOffset(int imageHeight) const override;
|
2012-07-19 21:52:44 +03:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void toInfo(ObstacleChanges & info);
|
|
|
|
void fromInfo(const ObstacleChanges & info);
|
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2012-04-23 22:56:37 +03:00
|
|
|
|
2011-05-10 01:20:47 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
h & static_cast<CObstacleInstance&>(*this);
|
2017-07-31 15:35:42 +02:00
|
|
|
h & turnsRemaining;
|
|
|
|
h & casterSpellPower;
|
|
|
|
h & spellLevel;
|
|
|
|
h & casterSide;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
h & hidden;
|
|
|
|
h & passable;
|
|
|
|
h & trigger;
|
|
|
|
h & trap;
|
|
|
|
|
|
|
|
h & customSize;
|
2011-05-10 01:20:47 +03:00
|
|
|
}
|
2012-05-18 23:50:16 +03:00
|
|
|
};
|