1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #562 from dydzio0614/BattleIntroFix

Battle action start on client after intro sound
This commit is contained in:
Alexander Shishkin
2019-03-24 10:36:01 +03:00
committed by GitHub
2 changed files with 25 additions and 13 deletions

View File

@@ -104,7 +104,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet *army1, const CCreatureSet
currentlyHoveredHex(-1), attackingHex(-1), stackCanCastSpell(false), creatureCasting(false), spellDestSelectMode(false), spellToCast(nullptr), sp(nullptr), currentlyHoveredHex(-1), attackingHex(-1), stackCanCastSpell(false), creatureCasting(false), spellDestSelectMode(false), spellToCast(nullptr), sp(nullptr),
creatureSpellToCast(-1), creatureSpellToCast(-1),
siegeH(nullptr), attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0), siegeH(nullptr), attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0),
myTurn(false), moveStarted(false), moveSoundHander(-1), bresult(nullptr) myTurn(false), moveStarted(false), moveSoundHander(-1), bresult(nullptr), battleActionsStarted(false)
{ {
OBJ_CONSTRUCTION; OBJ_CONSTRUCTION;
@@ -400,22 +400,25 @@ CBattleInterface::CBattleInterface(const CCreatureSet *army1, const CCreatureSet
bTacticNextStack(); bTacticNextStack();
CCS->musich->stopMusic(); CCS->musich->stopMusic();
battleIntroSoundChannel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds);
int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds); auto onIntroPlayed = [&]()
auto onIntroPlayed = []() {
if(LOCPLINT->battleInt)
{ {
if (LOCPLINT->battleInt)
CCS->musich->playMusicFromSet("battle", true); CCS->musich->playMusicFromSet("battle", true);
battleActionsStarted = true;
blockUI(settings["session"]["spectate"].Bool());
battleIntroSoundChannel = -1;
}
}; };
CCS->soundh->setCallback(channel, onIntroPlayed); CCS->soundh->setCallback(battleIntroSoundChannel, onIntroPlayed);
memset(stackCountOutsideHexes, 1, GameConstants::BFIELD_SIZE *sizeof(bool)); //initialize array with trues memset(stackCountOutsideHexes, 1, GameConstants::BFIELD_SIZE *sizeof(bool)); //initialize array with trues
currentAction = INVALID; currentAction = INVALID;
selectedAction = INVALID; selectedAction = INVALID;
addUsedEvents(RCLICK | MOVE | KEYBOARD); addUsedEvents(RCLICK | MOVE | KEYBOARD);
blockUI(true);
blockUI(settings["session"]["spectate"].Bool());
} }
CBattleInterface::~CBattleInterface() CBattleInterface::~CBattleInterface()
@@ -571,6 +574,9 @@ void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key)
} }
else if (key.keysym.sym == SDLK_ESCAPE) else if (key.keysym.sym == SDLK_ESCAPE)
{ {
if(!battleActionsStarted)
CCS->soundh->stopSound(battleIntroSoundChannel);
else
endCastingSpell(); endCastingSpell();
} }
} }
@@ -1630,6 +1636,9 @@ void CBattleInterface::setHoveredStack(const CStack *stack)
void CBattleInterface::activateStack() void CBattleInterface::activateStack()
{ {
if(!battleActionsStarted)
return; //"show" function should re-call this function
myTurn = true; myTurn = true;
if (!!attackerInt && defenderInt) //hotseat -> need to pick which interface "takes over" as active if (!!attackerInt && defenderInt) //hotseat -> need to pick which interface "takes over" as active
curInt = attackerInt->playerID == stackToActivate->owner ? attackerInt : defenderInt; curInt = attackerInt->playerID == stackToActivate->owner ? attackerInt : defenderInt;
@@ -2079,7 +2088,7 @@ bool CBattleInterface::canStackMoveHere(const CStack * activeStack, BattleHex my
void CBattleInterface::handleHex(BattleHex myNumber, int eventType) void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
{ {
if (!myTurn) //we are not permit to do anything if (!myTurn || !battleActionsStarted) //we are not permit to do anything
return; return;
// This function handles mouse move over hexes and l-clicking on them. // This function handles mouse move over hexes and l-clicking on them.
@@ -3039,6 +3048,7 @@ void CBattleInterface::show(SDL_Surface *to)
showBattlefieldObjects(to); showBattlefieldObjects(to);
showProjectiles(to); showProjectiles(to);
if(battleActionsStarted)
updateBattleAnimations(); updateBattleAnimations();
SDL_SetClipRect(to, &buf); //restoring previous clip_rect SDL_SetClipRect(to, &buf); //restoring previous clip_rect
@@ -3046,7 +3056,7 @@ void CBattleInterface::show(SDL_Surface *to)
showInterface(to); showInterface(to);
//activation of next stack //activation of next stack
if (pendingAnims.empty() && stackToActivate != nullptr) if (pendingAnims.empty() && stackToActivate != nullptr && battleActionsStarted) //FIXME: watch for recursive infinite loop here when working with this file, this needs rework anyway...
{ {
activateStack(); activateStack();

View File

@@ -175,6 +175,8 @@ private:
PossibleActions currentAction; //action that will be performed on l-click PossibleActions currentAction; //action that will be performed on l-click
PossibleActions selectedAction; //last action chosen (and saved) by player PossibleActions selectedAction; //last action chosen (and saved) by player
PossibleActions illegalAction; //most likely action that can't be performed here PossibleActions illegalAction; //most likely action that can't be performed here
bool battleActionsStarted; //used for delaying battle actions until intro sound stops
int battleIntroSoundChannel; //required as variable for disabling it via ESC key
void setActiveStack(const CStack *stack); void setActiveStack(const CStack *stack);
void setHoveredStack(const CStack *stack); void setHoveredStack(const CStack *stack);