|
@@ -51,9 +51,50 @@ void BattleProcessor::engageIntoBattle(PlayerColor player)
|
|
gameHandler->sendAndApply(&pb);
|
|
gameHandler->sendAndApply(&pb);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void BattleProcessor::restartBattlePrimary(const BattleID & battleID, const CArmedInstance *army1, const CArmedInstance *army2, int3 tile,
|
|
|
|
+ const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank,
|
|
|
|
+ const CGTownInstance *town)
|
|
|
|
+{
|
|
|
|
+ auto battle = gameHandler->gameState()->getBattle(battleID);
|
|
|
|
+
|
|
|
|
+ auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
|
|
|
+
|
|
|
|
+ assert(lastBattleQuery);
|
|
|
|
+
|
|
|
|
+ //existing battle query for retying auto-combat
|
|
|
|
+ if(lastBattleQuery)
|
|
|
|
+ {
|
|
|
|
+ const CGHeroInstance*heroes[2];
|
|
|
|
+ heroes[0] = hero1;
|
|
|
|
+ heroes[1] = hero2;
|
|
|
|
+
|
|
|
|
+ for(int i : {0, 1})
|
|
|
|
+ {
|
|
|
|
+ if(heroes[i])
|
|
|
|
+ {
|
|
|
|
+ SetMana restoreInitialMana;
|
|
|
|
+ restoreInitialMana.val = lastBattleQuery->initialHeroMana[i];
|
|
|
|
+ restoreInitialMana.hid = heroes[i]->id;
|
|
|
|
+ gameHandler->sendAndApply(&restoreInitialMana);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ lastBattleQuery->result = std::nullopt;
|
|
|
|
+
|
|
|
|
+ assert(lastBattleQuery->belligerents[0] == battle->sides[0].armyObject);
|
|
|
|
+ assert(lastBattleQuery->belligerents[1] == battle->sides[1].armyObject);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BattleCancelled bc;
|
|
|
|
+ bc.battleID = battleID;
|
|
|
|
+ gameHandler->sendAndApply(&bc);
|
|
|
|
+
|
|
|
|
+ startBattlePrimary(army1, army2, tile, hero1, hero2, creatureBank, town);
|
|
|
|
+}
|
|
|
|
+
|
|
void BattleProcessor::startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile,
|
|
void BattleProcessor::startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile,
|
|
const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank,
|
|
const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank,
|
|
- const CGTownInstance *town) //use hero=nullptr for no hero
|
|
|
|
|
|
+ const CGTownInstance *town)
|
|
{
|
|
{
|
|
assert(gameHandler->gameState()->getBattle(army1->getOwner()) == nullptr);
|
|
assert(gameHandler->gameState()->getBattle(army1->getOwner()) == nullptr);
|
|
assert(gameHandler->gameState()->getBattle(army2->getOwner()) == nullptr);
|
|
assert(gameHandler->gameState()->getBattle(army2->getOwner()) == nullptr);
|
|
@@ -61,10 +102,10 @@ void BattleProcessor::startBattlePrimary(const CArmedInstance *army1, const CArm
|
|
engageIntoBattle(army1->tempOwner);
|
|
engageIntoBattle(army1->tempOwner);
|
|
engageIntoBattle(army2->tempOwner);
|
|
engageIntoBattle(army2->tempOwner);
|
|
|
|
|
|
- static const CArmedInstance *armies[2];
|
|
|
|
|
|
+ const CArmedInstance *armies[2];
|
|
armies[0] = army1;
|
|
armies[0] = army1;
|
|
armies[1] = army2;
|
|
armies[1] = army2;
|
|
- static const CGHeroInstance*heroes[2];
|
|
|
|
|
|
+ const CGHeroInstance*heroes[2];
|
|
heroes[0] = hero1;
|
|
heroes[0] = hero1;
|
|
heroes[1] = hero2;
|
|
heroes[1] = hero2;
|
|
|
|
|
|
@@ -75,35 +116,21 @@ void BattleProcessor::startBattlePrimary(const CArmedInstance *army1, const CArm
|
|
|
|
|
|
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
|
auto lastBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battle->sides[0].color));
|
|
|
|
|
|
- //existing battle query for retying auto-combat
|
|
|
|
- if(lastBattleQuery)
|
|
|
|
|
|
+ if (lastBattleQuery)
|
|
|
|
+ {
|
|
|
|
+ lastBattleQuery->battleID = battleID;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
|
|
+ auto newBattleQuery = std::make_shared<CBattleQuery>(gameHandler, battle);
|
|
|
|
+
|
|
|
|
+ // store initial mana to reset if battle has been restarted
|
|
for(int i : {0, 1})
|
|
for(int i : {0, 1})
|
|
- {
|
|
|
|
if(heroes[i])
|
|
if(heroes[i])
|
|
- {
|
|
|
|
- SetMana restoreInitialMana;
|
|
|
|
- restoreInitialMana.val = lastBattleQuery->initialHeroMana[i];
|
|
|
|
- restoreInitialMana.hid = heroes[i]->id;
|
|
|
|
- gameHandler->sendAndApply(&restoreInitialMana);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ newBattleQuery->initialHeroMana[i] = heroes[i]->mana;
|
|
|
|
|
|
- lastBattleQuery->battleID = battle->getBattleID();
|
|
|
|
- lastBattleQuery->result = std::nullopt;
|
|
|
|
- lastBattleQuery->belligerents[0] = battle->sides[0].armyObject;
|
|
|
|
- lastBattleQuery->belligerents[1] = battle->sides[1].armyObject;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- auto nextBattleQuery = std::make_shared<CBattleQuery>(gameHandler, battle);
|
|
|
|
- for(int i : {0, 1})
|
|
|
|
- {
|
|
|
|
- if(heroes[i])
|
|
|
|
- {
|
|
|
|
- nextBattleQuery->initialHeroMana[i] = heroes[i]->mana;
|
|
|
|
- }
|
|
|
|
|
|
+ gameHandler->queries->addQuery(newBattleQuery);
|
|
}
|
|
}
|
|
- gameHandler->queries->addQuery(nextBattleQuery);
|
|
|
|
|
|
|
|
flowProcessor->onBattleStarted(*battle);
|
|
flowProcessor->onBattleStarted(*battle);
|
|
}
|
|
}
|