1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/*
* TurnInfo.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
*
*/
#include "StdInc.h"
#include "TurnInfo.h"
#include "../IGameCallback.h"
#include "../IGameSettings.h"
#include "../TerrainHandler.h"
#include "../VCMI_Lib.h"
#include "../bonuses/BonusList.h"
#include "../json/JsonNode.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/MiscObjects.h"
VCMI_LIB_NAMESPACE_BEGIN
TConstBonusListPtr TurnInfoBonusList::getBonusList(const CGHeroInstance * target, const CSelector & bonusSelector)
{
std::lock_guard guard(bonusListMutex);
if (target->getTreeVersion() == bonusListVersion)
return bonusList;
bonusList = target->getBonuses(bonusSelector);
bonusListVersion = target->getTreeVersion();
return bonusList;
}
int TurnInfo::hasWaterWalking() const
{
return waterWalkingTest;
}
int TurnInfo::hasFlyingMovement() const
{
return flyingMovementTest;
}
int TurnInfo::hasNoTerrainPenalty(const TerrainId &terrain) const
{
return noterrainPenalty[terrain.num];
}
int TurnInfo::hasFreeShipBoarding() const
{
return freeShipBoardingTest;
}
int TurnInfo::getFlyingMovementValue() const
{
return flyingMovementValue;
}
int TurnInfo::getWaterWalkingValue() const
{
return waterWalkingValue;
}
int TurnInfo::getRoughTerrainDiscountValue() const
{
return roughTerrainDiscountValue;
}
int TurnInfo::getMovePointsLimitLand() const
{
return movePointsLimitLand;
}
int TurnInfo::getMovePointsLimitWater() const
{
return movePointsLimitWater;
}
TurnInfo::TurnInfo(TurnInfoCache * sharedCache, const CGHeroInstance * target, int Turn)
: target(target)
, noterrainPenalty(VLC->terrainTypeHandler->size())
{
CSelector daySelector = Selector::days(Turn);
int lowestSpeed;
if (target->getTreeVersion() == sharedCache->heroLowestSpeedVersion)
{
lowestSpeed = sharedCache->heroLowestSpeedValue;
}
else
{
lowestSpeed = target->getLowestCreatureSpeed();
sharedCache->heroLowestSpeedValue = lowestSpeed;
sharedCache->heroLowestSpeedVersion = target->getTreeVersion();
}
{
static const CSelector selector = Selector::type()(BonusType::WATER_WALKING);
const auto & bonuses = sharedCache->waterWalking.getBonusList(target, selector);
waterWalkingTest = bonuses->getFirst(daySelector) != nullptr;
waterWalkingValue = bonuses->valOfBonuses(daySelector);
}
{
static const CSelector selector = Selector::type()(BonusType::FLYING_MOVEMENT);
const auto & bonuses = sharedCache->flyingMovement.getBonusList(target, selector);
flyingMovementTest = bonuses->getFirst(daySelector) != nullptr;
flyingMovementValue = bonuses->valOfBonuses(daySelector);
}
{
static const CSelector selector = Selector::type()(BonusType::FREE_SHIP_BOARDING);
const auto & bonuses = sharedCache->freeShipBoarding.getBonusList(target, selector);
freeShipBoardingTest = bonuses->getFirst(daySelector) != nullptr;
}
{
static const CSelector selector = Selector::type()(BonusType::ROUGH_TERRAIN_DISCOUNT);
const auto & bonuses = sharedCache->roughTerrainDiscount.getBonusList(target, selector);
roughTerrainDiscountValue = bonuses->valOfBonuses(daySelector);
}
{
static const CSelector selector = Selector::typeSubtype(BonusType::MOVEMENT, BonusCustomSubtype::heroMovementSea);
const auto & vectorSea = target->cb->getSettings().getValue(EGameSettings::HEROES_MOVEMENT_POINTS_SEA).Vector();
const auto & bonuses = sharedCache->movementPointsLimitWater.getBonusList(target, selector);
int baseMovementPointsSea;
if (lowestSpeed < vectorSea.size())
baseMovementPointsSea = vectorSea[lowestSpeed].Integer();
else
baseMovementPointsSea = vectorSea.back().Integer();
movePointsLimitWater = bonuses->valOfBonuses(daySelector, baseMovementPointsSea);
}
{
static const CSelector selector = Selector::typeSubtype(BonusType::MOVEMENT, BonusCustomSubtype::heroMovementLand);
const auto & vectorLand = target->cb->getSettings().getValue(EGameSettings::HEROES_MOVEMENT_POINTS_LAND).Vector();
const auto & bonuses = sharedCache->movementPointsLimitLand.getBonusList(target, selector);
int baseMovementPointsLand;
if (lowestSpeed < vectorLand.size())
baseMovementPointsLand = vectorLand[lowestSpeed].Integer();
else
baseMovementPointsLand = vectorLand.back().Integer();
movePointsLimitLand = bonuses->valOfBonuses(daySelector, baseMovementPointsLand);
}
{
static const CSelector selector = Selector::type()(BonusType::NO_TERRAIN_PENALTY);
const auto & bonuses = sharedCache->noTerrainPenalty.getBonusList(target, selector);
for (const auto & bonus : *bonuses)
{
TerrainId affectedTerrain = bonus->subtype.as<TerrainId>();
noterrainPenalty.at(affectedTerrain.num) = true;
}
const auto nativeTerrain = target->getNativeTerrain();
if (nativeTerrain.hasValue())
noterrainPenalty.at(nativeTerrain.num) = true;
if (nativeTerrain == ETerrainId::ANY_TERRAIN)
boost::range::fill(noterrainPenalty, true);
}
}
bool TurnInfo::isLayerAvailable(const EPathfindingLayer & layer) const
{
switch(layer.toEnum())
{
case EPathfindingLayer::AIR:
if(target && target->boat && target->boat->layer == EPathfindingLayer::AIR)
break;
if(!hasFlyingMovement())
return false;
break;
case EPathfindingLayer::WATER:
if(target && target->boat && target->boat->layer == EPathfindingLayer::WATER)
break;
if(!hasWaterWalking())
return false;
break;
}
return true;
}
int TurnInfo::getMaxMovePoints(const EPathfindingLayer & layer) const
{
return layer == EPathfindingLayer::SAIL ? getMovePointsLimitWater() : getMovePointsLimitLand();
}
VCMI_LIB_NAMESPACE_END
|