mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-27 21:49:10 +02:00
Merge pull request #3563 from Laserlicht/quick_combat
quick combat vs ai
This commit is contained in:
commit
48006307e1
@ -1131,15 +1131,6 @@ void AIGateway::battleEnd(const BattleID & battleID, const BattleResult * br, Qu
|
||||
logAi->debug("Player %d (%s): I %s the %s!", playerID, playerID.toString(), (won ? "won" : "lost"), battlename);
|
||||
battlename.clear();
|
||||
|
||||
if (queryID != QueryID::NONE)
|
||||
{
|
||||
status.addQuery(queryID, "Combat result dialog");
|
||||
const int confirmAction = 0;
|
||||
requestActionASAP([=]()
|
||||
{
|
||||
answerQuery(queryID, confirmAction);
|
||||
});
|
||||
}
|
||||
CAdventureAI::battleEnd(battleID, br, queryID);
|
||||
}
|
||||
|
||||
|
@ -1608,15 +1608,6 @@ void VCAI::battleEnd(const BattleID & battleID, const BattleResult * br, QueryID
|
||||
logAi->debug("Player %d (%s): I %s the %s!", playerID, playerID.toString(), (won ? "won" : "lost"), battlename);
|
||||
battlename.clear();
|
||||
|
||||
if (queryID != QueryID::NONE)
|
||||
{
|
||||
status.addQuery(queryID, "Combat result dialog");
|
||||
const int confirmAction = 0;
|
||||
requestActionASAP([=]()
|
||||
{
|
||||
answerQuery(queryID, confirmAction);
|
||||
});
|
||||
}
|
||||
CAdventureAI::battleEnd(battleID, br, queryID);
|
||||
}
|
||||
|
||||
|
@ -585,14 +585,26 @@ void CClient::battleStarted(const BattleInfo * info)
|
||||
def = std::dynamic_pointer_cast<CPlayerInterface>(playerint[rightSide.color]);
|
||||
|
||||
//Remove player interfaces for auto battle (quickCombat option)
|
||||
if(att && att->isAutoFightOn)
|
||||
if((att && att->isAutoFightOn) || (def && def->isAutoFightOn))
|
||||
{
|
||||
if (att->cb->getBattle(info->battleID)->battleGetTacticDist())
|
||||
auto endTacticPhaseIfEligible = [info](const CPlayerInterface * interface)
|
||||
{
|
||||
auto side = att->cb->getBattle(info->battleID)->playerToSide(att->playerID);
|
||||
auto action = BattleAction::makeEndOFTacticPhase(*side);
|
||||
att->cb->battleMakeTacticAction(info->battleID, action);
|
||||
}
|
||||
if (interface->cb->getBattle(info->battleID)->battleGetTacticDist())
|
||||
{
|
||||
auto side = interface->cb->getBattle(info->battleID)->playerToSide(interface->playerID);
|
||||
|
||||
if(interface->playerID == info->sides[info->tacticsSide].color)
|
||||
{
|
||||
auto action = BattleAction::makeEndOFTacticPhase(*side);
|
||||
interface->cb->battleMakeTacticAction(info->battleID, action);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if(att && att->isAutoFightOn)
|
||||
endTacticPhaseIfEligible(att.get());
|
||||
else // def && def->isAutoFightOn
|
||||
endTacticPhaseIfEligible(def.get());
|
||||
|
||||
att.reset();
|
||||
def.reset();
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "../queries/QueriesProcessor.h"
|
||||
#include "../queries/BattleQueries.h"
|
||||
|
||||
#include "../../lib/CPlayerState.h"
|
||||
#include "../../lib/TerrainHandler.h"
|
||||
#include "../../lib/battle/CBattleInfoCallback.h"
|
||||
#include "../../lib/battle/CObstacleInstance.h"
|
||||
@ -63,6 +64,8 @@ void BattleProcessor::restartBattlePrimary(const BattleID & battleID, const CArm
|
||||
auto battle = gameHandler->gameState()->getBattle(battleID);
|
||||
|
||||
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
||||
if(!lastBattleQuery)
|
||||
lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[1].color));
|
||||
|
||||
assert(lastBattleQuery);
|
||||
|
||||
@ -130,6 +133,8 @@ void BattleProcessor::startBattlePrimary(const CArmedInstance *army1, const CArm
|
||||
}
|
||||
|
||||
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
||||
if(!lastBattleQuery)
|
||||
lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[1].color));
|
||||
|
||||
if (lastBattleQuery)
|
||||
{
|
||||
@ -183,7 +188,13 @@ BattleID BattleProcessor::setupBattle(int3 tile, const CArmedInstance *armies[2]
|
||||
engageIntoBattle(bs.info->sides[1].color);
|
||||
|
||||
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(bs.info->sides[0].color));
|
||||
bs.info->replayAllowed = lastBattleQuery == nullptr && !bs.info->sides[1].color.isValidPlayer();
|
||||
if(!lastBattleQuery)
|
||||
lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(bs.info->sides[1].color));
|
||||
bool isDefenderHuman = bs.info->sides[1].color.isValidPlayer() && gameHandler->getPlayerState(bs.info->sides[1].color)->isHuman();
|
||||
bool isAttackerHuman = gameHandler->getPlayerState(bs.info->sides[0].color)->isHuman();
|
||||
|
||||
bool onlyOnePlayerHuman = isDefenderHuman != isAttackerHuman;
|
||||
bs.info->replayAllowed = lastBattleQuery == nullptr && onlyOnePlayerHuman;
|
||||
|
||||
gameHandler->sendAndApply(&bs);
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../../lib/ArtifactUtils.h"
|
||||
#include "../../lib/CStack.h"
|
||||
#include "../../lib/CPlayerState.h"
|
||||
#include "../../lib/GameSettings.h"
|
||||
#include "../../lib/battle/CBattleInfoCallback.h"
|
||||
#include "../../lib/battle/IBattleState.h"
|
||||
@ -256,6 +257,8 @@ void BattleResultProcessor::endBattle(const CBattleInfoCallback & battle)
|
||||
battleResult->exp[1] = heroDefender->calculateXp(battleResult->exp[1]);
|
||||
|
||||
auto battleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle.sideToPlayer(0)));
|
||||
if(!battleQuery)
|
||||
battleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle.sideToPlayer(1)));
|
||||
if (!battleQuery)
|
||||
{
|
||||
logGlobal->error("Cannot find battle query!");
|
||||
@ -272,7 +275,13 @@ void BattleResultProcessor::endBattle(const CBattleInfoCallback & battle)
|
||||
finishingBattles[battle.getBattle()->getBattleID()] = std::make_unique<FinishingBattleHelper>(battle, *battleResult, queriedPlayers);
|
||||
|
||||
// in battles against neutrals, 1st player can ask to replay battle manually
|
||||
if (!battle.sideToPlayer(1).isValidPlayer())
|
||||
const auto * attackerPlayer = gameHandler->getPlayerState(battle.getBattle()->getSidePlayer(BattleSide::ATTACKER));
|
||||
const auto * defenderPlayer = gameHandler->getPlayerState(battle.getBattle()->getSidePlayer(BattleSide::DEFENDER));
|
||||
bool isAttackerHuman = attackerPlayer && attackerPlayer->isHuman();
|
||||
bool isDefenderHuman = defenderPlayer && defenderPlayer->isHuman();
|
||||
bool onlyOnePlayerHuman = isAttackerHuman != isDefenderHuman;
|
||||
// in battles against neutrals attacker can ask to replay battle manually, additionally in battles against AI player human side can also ask for replay
|
||||
if(onlyOnePlayerHuman)
|
||||
{
|
||||
auto battleDialogQuery = std::make_shared<CBattleDialogQuery>(gameHandler, battle.getBattle());
|
||||
battleResult->queryID = battleDialogQuery->queryID;
|
||||
@ -299,6 +308,8 @@ void BattleResultProcessor::endBattle(const CBattleInfoCallback & battle)
|
||||
void BattleResultProcessor::endBattleConfirm(const CBattleInfoCallback & battle)
|
||||
{
|
||||
auto battleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle.sideToPlayer(0)));
|
||||
if(!battleQuery)
|
||||
battleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle.sideToPlayer(1)));
|
||||
if(!battleQuery)
|
||||
{
|
||||
logGlobal->trace("No battle query, battle end was confirmed by another player");
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "../battles/BattleProcessor.h"
|
||||
|
||||
#include "../../lib/battle/IBattleState.h"
|
||||
#include "../../lib/battle/SideInBattle.h"
|
||||
#include "../../lib/CPlayerState.h"
|
||||
#include "../../lib/mapObjects/CGObjectInstance.h"
|
||||
#include "../../lib/networkPacks/PacksForServer.h"
|
||||
#include "../../lib/serializer/Cast.h"
|
||||
@ -83,6 +85,9 @@ CBattleDialogQuery::CBattleDialogQuery(CGameHandler * owner, const IBattleInfo *
|
||||
|
||||
void CBattleDialogQuery::onRemoval(PlayerColor color)
|
||||
{
|
||||
if (!gh->getPlayerState(color)->isHuman())
|
||||
return;
|
||||
|
||||
assert(answer);
|
||||
if(*answer == 1)
|
||||
{
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
class IBattleInfo;
|
||||
struct SideInBattle;
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
class CBattleQuery : public CQuery
|
||||
|
Loading…
x
Reference in New Issue
Block a user