From 67eaef3520000539e9feea0b47074bb1a1877948 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 17 Aug 2023 20:20:12 +0300 Subject: [PATCH] Fixed few more discovered regressions --- lib/NetPacksLib.cpp | 53 +++++++++++--------- server/battles/BattleActionProcessor.cpp | 5 -- server/battles/BattleFlowProcessor.cpp | 2 +- server/processors/PlayerMessageProcessor.cpp | 22 ++++++-- server/processors/PlayerMessageProcessor.h | 2 +- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 402be6fa1..eb6aa28e4 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -2284,32 +2284,35 @@ void StartAction::applyGs(CGameState *gs) return; } - [[maybe_unused]] bool heroAction = ba.actionType == EActionType::HERO_SPELL || ba.actionType ==EActionType::SURRENDER || ba.actionType ==EActionType::RETREAT || ba.actionType == EActionType::END_TACTIC_PHASE; - - assert(st || heroAction); // stack must exists for all non-hero actions - - if(ba.actionType == EActionType::HERO_SPELL) - gs->curB->sides[ba.side].usedSpellsHistory.push_back(ba.spell); - - switch(ba.actionType) + if (ba.isUnitAction()) { - case EActionType::DEFEND: - st->waiting = false; - st->defending = true; - st->defendingAnim = true; - break; - case EActionType::WAIT: - st->defendingAnim = false; - st->waiting = true; - st->waitedThisTurn = true; - break; - case EActionType::HERO_SPELL: //no change in current stack state - break; - default: //any active stack action - attack, catapult, heal, spell... - st->waiting = false; - st->defendingAnim = false; - st->movedThisRound = true; - break; + assert(st); // stack must exists for all non-hero actions + + switch(ba.actionType) + { + case EActionType::DEFEND: + st->waiting = false; + st->defending = true; + st->defendingAnim = true; + break; + case EActionType::WAIT: + st->defendingAnim = false; + st->waiting = true; + st->waitedThisTurn = true; + break; + case EActionType::HERO_SPELL: //no change in current stack state + break; + default: //any active stack action - attack, catapult, heal, spell... + st->waiting = false; + st->defendingAnim = false; + st->movedThisRound = true; + break; + } + } + else + { + if(ba.actionType == EActionType::HERO_SPELL) + gs->curB->sides[ba.side].usedSpellsHistory.push_back(ba.spell); } } diff --git a/server/battles/BattleActionProcessor.cpp b/server/battles/BattleActionProcessor.cpp index e9903ddf3..bddabd8b7 100644 --- a/server/battles/BattleActionProcessor.cpp +++ b/server/battles/BattleActionProcessor.cpp @@ -58,11 +58,6 @@ bool BattleActionProcessor::doEmptyAction(const BattleAction & ba) bool BattleActionProcessor::doEndTacticsAction(const BattleAction & ba) { - if (gameHandler->gameState()->curB->tacticDistance == 0) - { - gameHandler->complain("Cannot end tactics mode - no tactics!"); - return false; - } return true; } diff --git a/server/battles/BattleFlowProcessor.cpp b/server/battles/BattleFlowProcessor.cpp index 53bcac325..3cbe14402 100644 --- a/server/battles/BattleFlowProcessor.cpp +++ b/server/battles/BattleFlowProcessor.cpp @@ -547,7 +547,7 @@ void BattleFlowProcessor::onActionMade(const BattleAction &ba) { // this is action made by hero AND unit is alive (e.g. not killed by casted spell) // keep current active stack for next action - setActiveStack(actedStack); + setActiveStack(activeStack); return; } } diff --git a/server/processors/PlayerMessageProcessor.cpp b/server/processors/PlayerMessageProcessor.cpp index d077233c8..75e4217fc 100644 --- a/server/processors/PlayerMessageProcessor.cpp +++ b/server/processors/PlayerMessageProcessor.cpp @@ -213,15 +213,27 @@ void PlayerMessageProcessor::cheatGiveMachines(PlayerColor player, const CGHeroI gameHandler->giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::FIRST_AID_TENT], ArtifactPosition::MACH3); } -void PlayerMessageProcessor::cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero) +void PlayerMessageProcessor::cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero, std::vector words) { if (!hero) return; - for(int g = 7; g < VLC->arth->objects.size(); ++g) //including artifacts from mods + if (!words.empty()) { - if(VLC->arth->objects[g]->canBePutAt(hero)) - gameHandler->giveHeroNewArtifact(hero, VLC->arth->objects[g], ArtifactPosition::FIRST_AVAILABLE); + for (auto const & word : words) + { + auto artID = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "artifact", word, false); + if(artID && VLC->arth->objects[*artID]) + gameHandler->giveHeroNewArtifact(hero, VLC->arth->objects[*artID], ArtifactPosition::FIRST_AVAILABLE); + } + } + else + { + for(int g = 7; g < VLC->arth->objects.size(); ++g) //including artifacts from mods + { + if(VLC->arth->objects[g]->canBePutAt(hero)) + gameHandler->giveHeroNewArtifact(hero, VLC->arth->objects[g], ArtifactPosition::FIRST_AVAILABLE); + } } } @@ -434,7 +446,7 @@ void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, Pla const auto & doCheatGiveArmyCustom = [&]() { cheatGiveArmy(player, hero, words); }; const auto & doCheatGiveArmyFixed = [&](std::vector customWords) { cheatGiveArmy(player, hero, customWords); }; const auto & doCheatGiveMachines = [&]() { cheatGiveMachines(player, hero); }; - const auto & doCheatGiveArtifacts = [&]() { cheatGiveArtifacts(player, hero); }; + const auto & doCheatGiveArtifacts = [&]() { cheatGiveArtifacts(player, hero, words); }; const auto & doCheatLevelup = [&]() { cheatLevelup(player, hero, words); }; const auto & doCheatExperience = [&]() { cheatExperience(player, hero, words); }; const auto & doCheatMovement = [&]() { cheatMovement(player, hero, words); }; diff --git a/server/processors/PlayerMessageProcessor.h b/server/processors/PlayerMessageProcessor.h index 4c0f725ab..d8f9e9878 100644 --- a/server/processors/PlayerMessageProcessor.h +++ b/server/processors/PlayerMessageProcessor.h @@ -31,7 +31,7 @@ class PlayerMessageProcessor void cheatBuildTown(PlayerColor player, const CGTownInstance * town); void cheatGiveArmy(PlayerColor player, const CGHeroInstance * hero, std::vector words); void cheatGiveMachines(PlayerColor player, const CGHeroInstance * hero); - void cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero); + void cheatGiveArtifacts(PlayerColor player, const CGHeroInstance * hero, std::vector words); void cheatLevelup(PlayerColor player, const CGHeroInstance * hero, std::vector words); void cheatExperience(PlayerColor player, const CGHeroInstance * hero, std::vector words); void cheatMovement(PlayerColor player, const CGHeroInstance * hero, std::vector words);