2010-12-25 21:23:30 +02:00
|
|
|
/*
|
2015-12-08 08:53:14 +02:00
|
|
|
* BattleAction.cpp, part of VCMI engine
|
2010-12-25 21:23:30 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2010-12-25 03:43:40 +02:00
|
|
|
|
2017-07-01 20:05:10 +02:00
|
|
|
#include "StdInc.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "BattleAction.h"
|
2017-06-29 01:02:05 +02:00
|
|
|
#include "../CStack.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
|
2013-02-04 00:05:44 +03:00
|
|
|
using namespace Battle;
|
|
|
|
|
2013-11-06 16:42:58 +03:00
|
|
|
BattleAction::BattleAction():
|
|
|
|
side(-1),
|
|
|
|
stackNumber(-1),
|
|
|
|
actionType(INVALID),
|
|
|
|
destinationTile(-1),
|
|
|
|
additionalInfo(-1),
|
|
|
|
selectedStack(-1)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:50:35 +02:00
|
|
|
BattleAction BattleAction::makeHeal(const CStack * healer, const CStack * healed)
|
2013-08-25 16:03:29 +03:00
|
|
|
{
|
|
|
|
BattleAction ba;
|
2017-07-01 10:34:00 +02:00
|
|
|
ba.side = healer->side;
|
2013-08-25 16:03:29 +03:00
|
|
|
ba.actionType = STACK_HEAL;
|
|
|
|
ba.stackNumber = healer->ID;
|
|
|
|
ba.destinationTile = healed->position;
|
|
|
|
return ba;
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:50:35 +02:00
|
|
|
BattleAction BattleAction::makeDefend(const CStack * stack)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
BattleAction ba;
|
2017-07-01 10:34:00 +02:00
|
|
|
ba.side = stack->side;
|
2010-12-25 03:43:40 +02:00
|
|
|
ba.actionType = DEFEND;
|
|
|
|
ba.stackNumber = stack->ID;
|
|
|
|
return ba;
|
|
|
|
}
|
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
|
2017-07-15 13:08:20 +02:00
|
|
|
BattleAction BattleAction::makeMeleeAttack(const CStack * stack, const CStack * attacked, BattleHex attackFrom)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
BattleAction ba;
|
2017-07-01 10:34:00 +02:00
|
|
|
ba.side = stack->side;
|
2011-01-07 12:48:31 +02:00
|
|
|
ba.actionType = WALK_AND_ATTACK;
|
2010-12-25 03:43:40 +02:00
|
|
|
ba.stackNumber = stack->ID;
|
2011-01-08 20:33:40 +02:00
|
|
|
ba.destinationTile = attackFrom;
|
2011-01-07 12:48:31 +02:00
|
|
|
ba.additionalInfo = attacked->position;
|
2010-12-25 03:43:40 +02:00
|
|
|
return ba;
|
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
2017-06-26 18:50:35 +02:00
|
|
|
BattleAction BattleAction::makeWait(const CStack * stack)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
BattleAction ba;
|
2017-07-01 10:34:00 +02:00
|
|
|
ba.side = stack->side;
|
2010-12-25 03:43:40 +02:00
|
|
|
ba.actionType = WAIT;
|
|
|
|
ba.stackNumber = stack->ID;
|
|
|
|
return ba;
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:50:35 +02:00
|
|
|
BattleAction BattleAction::makeShotAttack(const CStack * shooter, const CStack * target)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
BattleAction ba;
|
2017-07-01 10:34:00 +02:00
|
|
|
ba.side = shooter->side;
|
2010-12-25 03:43:40 +02:00
|
|
|
ba.actionType = SHOOT;
|
|
|
|
ba.stackNumber = shooter->ID;
|
|
|
|
ba.destinationTile = target->position;
|
|
|
|
return ba;
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:50:35 +02:00
|
|
|
BattleAction BattleAction::makeMove(const CStack * stack, BattleHex dest)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
BattleAction ba;
|
2017-07-01 10:34:00 +02:00
|
|
|
ba.side = stack->side;
|
2010-12-25 03:43:40 +02:00
|
|
|
ba.actionType = WALK;
|
|
|
|
ba.stackNumber = stack->ID;
|
|
|
|
ba.destinationTile = dest;
|
|
|
|
return ba;
|
2011-02-12 18:12:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BattleAction BattleAction::makeEndOFTacticPhase(ui8 side)
|
|
|
|
{
|
|
|
|
BattleAction ba;
|
|
|
|
ba.side = side;
|
|
|
|
ba.actionType = END_TACTIC_PHASE;
|
|
|
|
return ba;
|
|
|
|
}
|
2013-11-09 19:25:20 +03:00
|
|
|
|
2017-08-11 13:38:10 +02:00
|
|
|
std::string BattleAction::toString() const
|
2013-11-09 19:25:20 +03:00
|
|
|
{
|
|
|
|
std::stringstream actionTypeStream;
|
2017-08-11 13:38:10 +02:00
|
|
|
actionTypeStream << actionType;
|
|
|
|
|
|
|
|
boost::format fmt("{BattleAction: side '%d', stackNumber '%d', actionType '%s', destinationTile '%s', additionalInfo '%d', selectedStack '%d'}");
|
|
|
|
fmt % static_cast<int>(side) % stackNumber % actionTypeStream.str() % destinationTile % additionalInfo % selectedStack;
|
|
|
|
return fmt.str();
|
|
|
|
}
|
2013-11-09 19:25:20 +03:00
|
|
|
|
2017-08-11 13:38:10 +02:00
|
|
|
std::ostream & operator<<(std::ostream & os, const BattleAction & ba)
|
|
|
|
{
|
|
|
|
os << ba.toString();
|
|
|
|
return os;
|
2013-11-09 19:25:20 +03:00
|
|
|
}
|