2012-04-23 23:20:43 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CObstacleInstance.h"
|
|
|
|
#include "CHeroHandler.h"
|
|
|
|
#include "VCMI_Lib.h"
|
2012-05-18 23:50:16 +03:00
|
|
|
#include "CSpellHandler.h"
|
2012-04-23 23:20:43 +03:00
|
|
|
|
2012-12-19 17:54:10 +03:00
|
|
|
/*
|
|
|
|
* CObstacleInstance.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-23 23:20:43 +03:00
|
|
|
CObstacleInstance::CObstacleInstance()
|
|
|
|
{
|
2012-05-05 00:16:39 +03:00
|
|
|
obstacleType = USUAL;
|
2012-05-18 23:50:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CObstacleInstance::~CObstacleInstance()
|
|
|
|
{
|
|
|
|
|
2012-04-23 23:20:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const CObstacleInfo & CObstacleInstance::getInfo() const
|
|
|
|
{
|
2012-05-05 00:16:39 +03:00
|
|
|
switch(obstacleType)
|
|
|
|
{
|
|
|
|
case ABSOLUTE_OBSTACLE:
|
2012-04-23 23:20:43 +03:00
|
|
|
return VLC->heroh->absoluteObstacles[ID];
|
2012-05-05 00:16:39 +03:00
|
|
|
case USUAL:
|
|
|
|
return VLC->heroh->obstacles[ID];
|
2012-05-18 23:50:16 +03:00
|
|
|
case MOAT:
|
|
|
|
assert(0);
|
2012-05-05 00:16:39 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2012-04-23 23:20:43 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
std::vector<BattleHex> CObstacleInstance::getBlockedTiles() const
|
|
|
|
{
|
|
|
|
if(blocksTiles())
|
|
|
|
return getAffectedTiles();
|
|
|
|
return std::vector<BattleHex>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BattleHex> CObstacleInstance::getStoppingTile() const
|
|
|
|
{
|
|
|
|
if(stopsMovement())
|
|
|
|
return getAffectedTiles();
|
|
|
|
return std::vector<BattleHex>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BattleHex> CObstacleInstance::getAffectedTiles() const
|
2012-04-23 23:20:43 +03:00
|
|
|
{
|
2012-05-05 00:16:39 +03:00
|
|
|
switch(obstacleType)
|
|
|
|
{
|
|
|
|
case ABSOLUTE_OBSTACLE:
|
|
|
|
case USUAL:
|
|
|
|
return getInfo().getBlocked(pos);
|
2012-05-18 23:50:16 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
2012-07-19 21:52:44 +03:00
|
|
|
return std::vector<BattleHex>();
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
2012-05-18 23:50:16 +03:00
|
|
|
}
|
2012-05-05 00:16:39 +03:00
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
// bool CObstacleInstance::spellGenerated() const
|
|
|
|
// {
|
|
|
|
// if(obstacleType == USUAL || obstacleType == ABSOLUTE_OBSTACLE)
|
|
|
|
// return false;
|
2012-07-19 21:52:44 +03:00
|
|
|
//
|
2012-05-18 23:50:16 +03:00
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
bool CObstacleInstance::visibleForSide(ui8 side, bool hasNativeStack) const
|
|
|
|
{
|
|
|
|
//by default obstacle is visible for everyone
|
|
|
|
return true;
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
bool CObstacleInstance::stopsMovement() const
|
2012-05-05 00:16:39 +03:00
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
return obstacleType == QUICKSAND || obstacleType == MOAT;
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
bool CObstacleInstance::blocksTiles() const
|
2012-05-05 00:16:39 +03:00
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
return obstacleType == USUAL || obstacleType == ABSOLUTE_OBSTACLE || obstacleType == FORCE_FIELD;
|
|
|
|
}
|
2012-05-05 00:16:39 +03:00
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
SpellCreatedObstacle::SpellCreatedObstacle()
|
|
|
|
{
|
|
|
|
casterSide = -1;
|
|
|
|
spellLevel = -1;
|
|
|
|
casterSpellPower = -1;
|
|
|
|
turnsRemaining = -1;
|
|
|
|
visibleForAnotherSide = -1;
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
bool SpellCreatedObstacle::visibleForSide(ui8 side, bool hasNativeStack) const
|
2012-05-05 00:16:39 +03:00
|
|
|
{
|
|
|
|
switch(obstacleType)
|
|
|
|
{
|
2012-05-18 23:50:16 +03:00
|
|
|
case FIRE_WALL:
|
|
|
|
case FORCE_FIELD:
|
|
|
|
//these are always visible
|
2012-05-05 00:16:39 +03:00
|
|
|
return true;
|
2012-05-18 23:50:16 +03:00
|
|
|
case QUICKSAND:
|
|
|
|
case LAND_MINE:
|
2012-05-05 00:16:39 +03:00
|
|
|
//we hide mines and not discovered quicksands
|
2012-05-18 23:50:16 +03:00
|
|
|
//quicksands are visible to the caster or if owned unit stepped into that particular patch
|
|
|
|
//additionally if side has a native unit, mines/quicksands will be visible
|
|
|
|
return casterSide == side || visibleForAnotherSide || hasNativeStack;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2012-07-19 21:52:44 +03:00
|
|
|
return false;
|
2012-05-18 23:50:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BattleHex> SpellCreatedObstacle::getAffectedTiles() const
|
|
|
|
{
|
|
|
|
switch(obstacleType)
|
|
|
|
{
|
|
|
|
case QUICKSAND:
|
|
|
|
case LAND_MINE:
|
|
|
|
case FIRE_WALL:
|
|
|
|
return std::vector<BattleHex>(1, pos);
|
|
|
|
case FORCE_FIELD:
|
|
|
|
return VLC->spellh->spells[Spells::FORCE_FIELD]->rangeInHexes(pos, spellLevel, casterSide);
|
|
|
|
//TODO Fire Wall
|
|
|
|
default:
|
|
|
|
assert(0);
|
2012-07-19 21:52:44 +03:00
|
|
|
return std::vector<BattleHex>();
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
|
|
|
}
|
2012-05-18 23:50:16 +03:00
|
|
|
|
|
|
|
void SpellCreatedObstacle::battleTurnPassed()
|
|
|
|
{
|
|
|
|
if(turnsRemaining > 0)
|
|
|
|
turnsRemaining--;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BattleHex> MoatObstacle::getAffectedTiles() const
|
|
|
|
{
|
|
|
|
//rrr... need initializer lists
|
|
|
|
static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181};
|
2012-06-23 20:19:50 +03:00
|
|
|
return std::vector<BattleHex>(moatHexes, moatHexes + ARRAY_COUNT(moatHexes));
|
2012-07-19 21:52:44 +03:00
|
|
|
}
|