mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-28 23:06:24 +02:00
0b70baa95e
* 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
173 lines
4.1 KiB
C++
173 lines
4.1 KiB
C++
/*
|
|
* BattleAction.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 "BattleAction.h"
|
|
#include "Unit.h"
|
|
#include "CBattleInfoCallback.h"
|
|
|
|
static const int32_t INVALID_UNIT_ID = -1000;
|
|
|
|
BattleAction::BattleAction():
|
|
side(-1),
|
|
stackNumber(-1),
|
|
actionType(EActionType::INVALID),
|
|
actionSubtype(-1)
|
|
{
|
|
}
|
|
|
|
BattleAction BattleAction::makeHeal(const battle::Unit * healer, const battle::Unit * healed)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = healer->unitSide();
|
|
ba.actionType = EActionType::STACK_HEAL;
|
|
ba.stackNumber = healer->unitId();
|
|
ba.aimToUnit(healed);
|
|
return ba;
|
|
}
|
|
|
|
BattleAction BattleAction::makeDefend(const battle::Unit * stack)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = stack->unitSide();
|
|
ba.actionType = EActionType::DEFEND;
|
|
ba.stackNumber = stack->unitId();
|
|
return ba;
|
|
}
|
|
|
|
BattleAction BattleAction::makeMeleeAttack(const battle::Unit * stack, BattleHex destination, BattleHex attackFrom, bool returnAfterAttack)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = stack->unitSide(); //FIXME: will it fail if stack mind controlled?
|
|
ba.actionType = EActionType::WALK_AND_ATTACK;
|
|
ba.stackNumber = stack->unitId();
|
|
ba.aimToHex(attackFrom);
|
|
ba.aimToHex(destination);
|
|
if(returnAfterAttack && stack->hasBonusOfType(Bonus::RETURN_AFTER_STRIKE))
|
|
ba.aimToHex(stack->getPosition());
|
|
return ba;
|
|
}
|
|
|
|
BattleAction BattleAction::makeWait(const battle::Unit * stack)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = stack->unitSide();
|
|
ba.actionType = EActionType::WAIT;
|
|
ba.stackNumber = stack->unitId();
|
|
return ba;
|
|
}
|
|
|
|
BattleAction BattleAction::makeShotAttack(const battle::Unit * shooter, const battle::Unit * target)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = shooter->unitSide();
|
|
ba.actionType = EActionType::SHOOT;
|
|
ba.stackNumber = shooter->unitId();
|
|
ba.aimToUnit(target);
|
|
return ba;
|
|
}
|
|
|
|
BattleAction BattleAction::makeMove(const battle::Unit * stack, BattleHex dest)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = stack->unitSide();
|
|
ba.actionType = EActionType::WALK;
|
|
ba.stackNumber = stack->unitId();
|
|
ba.aimToHex(dest);
|
|
return ba;
|
|
}
|
|
|
|
BattleAction BattleAction::makeEndOFTacticPhase(ui8 side)
|
|
{
|
|
BattleAction ba;
|
|
ba.side = side;
|
|
ba.actionType = EActionType::END_TACTIC_PHASE;
|
|
return ba;
|
|
}
|
|
|
|
std::string BattleAction::toString() const
|
|
{
|
|
std::stringstream actionTypeStream;
|
|
actionTypeStream << actionType;
|
|
|
|
std::stringstream targetStream;
|
|
|
|
for(const DestinationInfo & info : target)
|
|
{
|
|
if(info.unitValue == INVALID_UNIT_ID)
|
|
{
|
|
targetStream << info.hexValue;
|
|
}
|
|
else
|
|
{
|
|
targetStream << info.unitValue;
|
|
targetStream << "@";
|
|
targetStream << info.hexValue;
|
|
}
|
|
targetStream << ",";
|
|
}
|
|
|
|
boost::format fmt("{BattleAction: side '%d', stackNumber '%d', actionType '%s', actionSubtype '%d', target {%s}}");
|
|
fmt % static_cast<int>(side) % stackNumber % actionTypeStream.str() % actionSubtype % targetStream.str();
|
|
return fmt.str();
|
|
}
|
|
|
|
void BattleAction::aimToHex(const BattleHex & destination)
|
|
{
|
|
DestinationInfo info;
|
|
info.hexValue = destination;
|
|
info.unitValue = INVALID_UNIT_ID;
|
|
|
|
target.push_back(info);
|
|
}
|
|
|
|
void BattleAction::aimToUnit(const battle::Unit * destination)
|
|
{
|
|
DestinationInfo info;
|
|
info.hexValue = destination->getPosition();
|
|
info.unitValue = destination->unitId();
|
|
|
|
target.push_back(info);
|
|
}
|
|
|
|
battle::Target BattleAction::getTarget(const CBattleInfoCallback * cb) const
|
|
{
|
|
battle::Target ret;
|
|
|
|
for(auto & destination : target)
|
|
{
|
|
if(destination.unitValue == INVALID_UNIT_ID)
|
|
ret.emplace_back(destination.hexValue);
|
|
else
|
|
ret.emplace_back(cb->battleGetUnitByID(destination.unitValue));
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void BattleAction::setTarget(const battle::Target & target_)
|
|
{
|
|
target.clear();
|
|
for(auto & destination : target_)
|
|
{
|
|
if(destination.unitValue == nullptr)
|
|
aimToHex(destination.hexValue);
|
|
else
|
|
aimToUnit(destination.unitValue);
|
|
}
|
|
}
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, const BattleAction & ba)
|
|
{
|
|
os << ba.toString();
|
|
return os;
|
|
}
|