1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/lib/battle/CObstacleInstance.h
AlexVinS 0b70baa95e Spells configuration version 2 (effect-based)
* Indirect spell effects loading
* Json serializer improvements
* spell->canBeCastAt do not allow useless cast for any spell
* Added proxy caster class for spell-created obstacles
* Handle damage from spell-created obstacles inside mechanics
* Experimental GameState integration/regression tests
* Ignore mod settings and load only "vcmi" mod when running tests
* fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests)
* Huge improvements of BattleAI regarding spell casts
* AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells.
* Possible fix for https://bugs.vcmi.eu/view.php?id=1811
* CStack factored out to several classes
* [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional
* [Battle] Allowed BattleAction have multiple destinations
* [Spells] Converted limit|immunity to target condition
* [Spells] Use partial configuration reload for backward compatibility handling
* [Tests] Started tests for CUnitState
* Partial fixes of fire shield effect
* [Battle] Do HP calculations in 64 bits
* [BattleAI] Use threading for spell cast evaluation
* [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state)
* Implemented https://bugs.vcmi.eu/view.php?id=2811
* plug rare freeze when hypnotized unit shots vertically
* Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense
* [BattleAI] Try to not waste a cast if battle is actually won already
* Extended JsonSerializeFormat API
* fixed https://bugs.vcmi.eu/view.php?id=2847
* Any unit effect can be now chained (not only damage like Chain Lightning)
** only damage effect for now actually uses "chainFactor"
* Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2018-02-08 11:37:21 +03:00

121 lines
3.2 KiB
C++

/*
* 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
*
*/
#pragma once
#include "BattleHex.h"
struct CObstacleInfo;
class ObstacleChanges;
class JsonSerializeFormat;
struct DLL_LINKAGE CObstacleInstance
{
BattleHex pos; //position on battlefield, typically left bottom corner
ui8 obstacleType; //if true, then position is meaningless
si32 uniqueID;
si32 ID; //ID of obstacle (defines type of it)
enum EObstacleType
{
//ABSOLUTE needs an underscore because it's a Win
USUAL, ABSOLUTE_OBSTACLE, SPELL_CREATED, MOAT
};
CObstacleInstance();
virtual ~CObstacleInstance();
const CObstacleInfo &getInfo() const; //allowed only when not generated by spell (usual or absolute)
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
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;
virtual std::vector<BattleHex> getAffectedTiles() const;
virtual bool visibleForSide(ui8 side, bool hasNativeStack) const; //0 attacker
virtual void battleTurnPassed(){};
virtual int getAnimationYOffset(int imageHeight) const;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ID;
h & pos;
h & obstacleType;
h & uniqueID;
}
};
struct DLL_LINKAGE MoatObstacle : CObstacleInstance
{
std::vector<BattleHex> getAffectedTiles() const override; //for special effects (not blocking)
};
struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
{
int32_t turnsRemaining;
int32_t casterSpellPower;
int32_t spellLevel;
si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
bool hidden;
bool passable;
bool trigger;
bool trap;
bool removeOnTrigger;
bool revealed;
std::string appearAnimation;
std::string animation;
int animationYOffset;
std::vector<BattleHex> customSize;
SpellCreatedObstacle();
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;
void toInfo(ObstacleChanges & info);
void fromInfo(const ObstacleChanges & info);
void serializeJson(JsonSerializeFormat & handler);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CObstacleInstance&>(*this);
h & turnsRemaining;
h & casterSpellPower;
h & spellLevel;
h & casterSide;
h & hidden;
h & passable;
h & trigger;
h & trap;
h & customSize;
}
};