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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CObstacleInstance.h"
|
|
|
|
#include "../CHeroHandler.h"
|
|
|
|
#include "../CTownHandler.h"
|
2022-09-15 10:06:54 +02:00
|
|
|
#include "../ObstacleHandler.h"
|
2017-07-13 10:26:03 +02:00
|
|
|
#include "../VCMI_Lib.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../NetPacksBase.h"
|
|
|
|
|
|
|
|
#include "../serializer/JsonDeserializer.h"
|
|
|
|
#include "../serializer/JsonSerializer.h"
|
2012-12-19 17:54:10 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-09-15 10:06:54 +02:00
|
|
|
const ObstacleInfo & CObstacleInstance::getInfo() const
|
2012-04-23 23:20:43 +03:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
assert( obstacleType == USUAL || obstacleType == ABSOLUTE_OBSTACLE);
|
|
|
|
|
2022-09-15 10:06:54 +02:00
|
|
|
return *Obstacle(ID).getInfo();
|
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::visibleForSide(ui8 side, bool hasNativeStack) const
|
|
|
|
{
|
|
|
|
//by default obstacle is visible for everyone
|
|
|
|
return true;
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int CObstacleInstance::getAnimationYOffset(int imageHeight) const
|
|
|
|
{
|
|
|
|
int offset = imageHeight % 42;
|
|
|
|
if(obstacleType == CObstacleInstance::USUAL)
|
|
|
|
{
|
|
|
|
if(getInfo().blockedTiles.front() < 0 || offset > 37) //second or part is for holy ground ID=62,65,63
|
|
|
|
offset -= 42;
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
bool CObstacleInstance::stopsMovement() const
|
2012-05-05 00:16:39 +03:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return 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
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return obstacleType == USUAL || obstacleType == ABSOLUTE_OBSTACLE ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CObstacleInstance::triggersEffects() const
|
|
|
|
{
|
|
|
|
return false;
|
2012-05-18 23:50:16 +03:00
|
|
|
}
|
2012-05-05 00:16:39 +03:00
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
SpellCreatedObstacle::SpellCreatedObstacle()
|
2017-07-20 06:08:49 +02:00
|
|
|
: turnsRemaining(-1),
|
|
|
|
casterSpellPower(0),
|
|
|
|
spellLevel(0),
|
|
|
|
casterSide(0),
|
|
|
|
hidden(false),
|
|
|
|
passable(false),
|
|
|
|
trigger(false),
|
|
|
|
trap(false),
|
|
|
|
removeOnTrigger(false),
|
|
|
|
revealed(false),
|
|
|
|
animationYOffset(0)
|
2012-05-18 23:50:16 +03:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
obstacleType = SPELL_CREATED;
|
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
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
//we hide mines and not discovered quicksands
|
|
|
|
//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 || !hidden || revealed || hasNativeStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpellCreatedObstacle::blocksTiles() const
|
|
|
|
{
|
|
|
|
return !passable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpellCreatedObstacle::stopsMovement() const
|
|
|
|
{
|
|
|
|
return trap;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpellCreatedObstacle::triggersEffects() const
|
|
|
|
{
|
|
|
|
return trigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpellCreatedObstacle::toInfo(ObstacleChanges & info)
|
|
|
|
{
|
|
|
|
info.id = uniqueID;
|
|
|
|
info.operation = ObstacleChanges::EOperation::ADD;
|
|
|
|
|
|
|
|
info.data.clear();
|
|
|
|
JsonSerializer ser(nullptr, info.data);
|
|
|
|
ser.serializeStruct("obstacle", *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpellCreatedObstacle::fromInfo(const ObstacleChanges & info)
|
|
|
|
{
|
|
|
|
uniqueID = info.id;
|
|
|
|
|
2020-02-12 19:12:12 +02:00
|
|
|
if(info.operation != ObstacleChanges::EOperation::ADD && info.operation != ObstacleChanges::EOperation::UPDATE)
|
|
|
|
logGlobal->error("ADD or UPDATE operation expected");
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
JsonDeserializer deser(nullptr, info.data);
|
|
|
|
deser.serializeStruct("obstacle", *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpellCreatedObstacle::serializeJson(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
handler.serializeInt("spell", ID);
|
|
|
|
handler.serializeInt("position", pos);
|
|
|
|
|
|
|
|
handler.serializeInt("turnsRemaining", turnsRemaining);
|
|
|
|
handler.serializeInt("casterSpellPower", casterSpellPower);
|
|
|
|
handler.serializeInt("spellLevel", spellLevel);
|
|
|
|
handler.serializeInt("casterSide", casterSide);
|
|
|
|
|
|
|
|
handler.serializeBool("hidden", hidden);
|
2020-02-12 19:12:12 +02:00
|
|
|
handler.serializeBool("revealed", revealed);
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeBool("passable", passable);
|
|
|
|
handler.serializeBool("trigger", trigger);
|
|
|
|
handler.serializeBool("trap", trap);
|
|
|
|
handler.serializeBool("removeOnTrigger", removeOnTrigger);
|
|
|
|
|
2022-12-12 21:17:15 +02:00
|
|
|
handler.serializeString("appearSound", appearSound);
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeString("appearAnimation", appearAnimation);
|
2022-12-17 19:37:00 +02:00
|
|
|
handler.serializeString("triggerSound", triggerSound);
|
|
|
|
handler.serializeString("triggerAnimation", triggerAnimation);
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeString("animation", animation);
|
|
|
|
|
|
|
|
handler.serializeInt("animationYOffset", animationYOffset);
|
|
|
|
|
2012-05-05 00:16:39 +03:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
JsonArraySerializer customSizeJson = handler.enterArray("customSize");
|
|
|
|
customSizeJson.syncSize(customSize, JsonNode::JsonType::DATA_INTEGER);
|
|
|
|
|
|
|
|
for(size_t index = 0; index < customSizeJson.size(); index++)
|
|
|
|
customSizeJson.serializeInt(index, customSize.at(index));
|
2012-05-18 23:50:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BattleHex> SpellCreatedObstacle::getAffectedTiles() const
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return customSize;
|
2012-05-05 00:16:39 +03:00
|
|
|
}
|
2012-05-18 23:50:16 +03:00
|
|
|
|
|
|
|
void SpellCreatedObstacle::battleTurnPassed()
|
|
|
|
{
|
|
|
|
if(turnsRemaining > 0)
|
|
|
|
turnsRemaining--;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int SpellCreatedObstacle::getAnimationYOffset(int imageHeight) const
|
|
|
|
{
|
|
|
|
int offset = imageHeight % 42;
|
|
|
|
|
|
|
|
if(obstacleType == CObstacleInstance::SPELL_CREATED)
|
|
|
|
{
|
|
|
|
offset += animationYOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2012-05-18 23:50:16 +03:00
|
|
|
std::vector<BattleHex> MoatObstacle::getAffectedTiles() const
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return (*VLC->townh)[ID]->town->moatHexes;
|
2012-07-19 21:52:44 +03:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|