1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-23 12:08:45 +02:00

Implemented fly movement sound

This commit is contained in:
Ivan Savenko 2023-06-21 17:10:26 +03:00
parent f7b27da00e
commit 90c68588f9

View File

@ -1922,10 +1922,27 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
for (auto & elem : path.nodes) for (auto & elem : path.nodes)
elem.coord = h->convertFromVisitablePos(elem.coord); elem.coord = h->convertFromVisitablePos(elem.coord);
TerrainId currentTerrain = ETerrainId::NONE; int soundChannel = -1;
TerrainId newTerrain; std::string soundName;
bool wasOnRoad = true;
int sh = -1; auto getMovementSoundFor = [&](const CGHeroInstance * hero, int3 posPrev, int3 posNext) -> std::string
{
// flying movement sound
if (hero->hasBonusOfType(BonusType::FLYING_MOVEMENT))
return "HORSE10.wav";
auto prevTile = cb->getTile(h->convertToVisitablePos(posPrev));
auto nextTile = cb->getTile(h->convertToVisitablePos(posNext));
auto prevRoad = prevTile->roadType;
auto nextRoad = nextTile->roadType;
bool movingOnRoad = prevRoad->getId() != Road::NO_ROAD && nextRoad->getId() != Road::NO_ROAD;
if (movingOnRoad)
return nextTile->terType->horseSound;
else
return nextTile->terType->horseSoundPenalty;
};
auto canStop = [&](CGPathNode * node) -> bool auto canStop = [&](CGPathNode * node) -> bool
{ {
@ -1943,18 +1960,13 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
int3 prevCoord = path.nodes[i].coord; int3 prevCoord = path.nodes[i].coord;
int3 nextCoord = path.nodes[i-1].coord; int3 nextCoord = path.nodes[i-1].coord;
auto prevRoad = cb->getTile(h->convertToVisitablePos(prevCoord))->roadType;
auto nextRoad = cb->getTile(h->convertToVisitablePos(nextCoord))->roadType;
bool movingOnRoad = prevRoad->getId() != Road::NO_ROAD && nextRoad->getId() != Road::NO_ROAD;
auto prevObject = getObj(prevCoord, prevCoord == h->pos); auto prevObject = getObj(prevCoord, prevCoord == h->pos);
auto nextObjectTop = getObj(nextCoord, false); auto nextObjectTop = getObj(nextCoord, false);
auto nextObject = getObj(nextCoord, true); auto nextObject = getObj(nextCoord, true);
auto destTeleportObj = getDestTeleportObj(prevObject, nextObjectTop, nextObject); auto destTeleportObj = getDestTeleportObj(prevObject, nextObjectTop, nextObject);
if (isTeleportAction(path.nodes[i-1].action) && destTeleportObj != nullptr) if (isTeleportAction(path.nodes[i-1].action) && destTeleportObj != nullptr)
{ {
CCS->soundh->stopSound(sh); CCS->soundh->stopSound(soundChannel);
destinationTeleport = destTeleportObj->id; destinationTeleport = destTeleportObj->id;
destinationTeleportPos = nextCoord; destinationTeleportPos = nextCoord;
doMovement(h->pos, false); doMovement(h->pos, false);
@ -1966,10 +1978,8 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
} }
if(i != path.nodes.size() - 1) if(i != path.nodes.size() - 1)
{ {
if (movingOnRoad) soundName = getMovementSoundFor(h, prevCoord, nextCoord);
sh = CCS->soundh->playSound(VLC->terrainTypeHandler->getById(currentTerrain)->horseSound, -1); soundChannel = CCS->soundh->playSound(soundName, -1);
else
sh = CCS->soundh->playSound(VLC->terrainTypeHandler->getById(currentTerrain)->horseSoundPenalty, -1);
} }
continue; continue;
} }
@ -1980,23 +1990,16 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
break; break;
} }
{
// Start a new sound for the hero movement or let the existing one carry on. // Start a new sound for the hero movement or let the existing one carry on.
#if 0 std::string newSoundName = getMovementSoundFor(h, prevCoord, nextCoord);
// TODO
if (hero is flying && sh == -1) if(newSoundName != soundName)
sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
#endif
{ {
newTerrain = cb->getTile(h->convertToVisitablePos(prevCoord))->terType->getId(); soundName = newSoundName;
if(newTerrain != currentTerrain || wasOnRoad != movingOnRoad)
{ CCS->soundh->stopSound(soundChannel);
CCS->soundh->stopSound(sh); soundChannel = CCS->soundh->playSound(soundName, -1);
if (movingOnRoad)
sh = CCS->soundh->playSound(VLC->terrainTypeHandler->getById(newTerrain)->horseSound, -1);
else
sh = CCS->soundh->playSound(VLC->terrainTypeHandler->getById(newTerrain)->horseSoundPenalty, -1);
currentTerrain = newTerrain;
wasOnRoad = movingOnRoad;
} }
} }
@ -2022,7 +2025,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
break; break;
} }
CCS->soundh->stopSound(sh); CCS->soundh->stopSound(soundChannel);
} }
//Update cursor so icon can change if needed when it reappears; doesn;'t apply if a dialog box pops up at the end of the movement //Update cursor so icon can change if needed when it reappears; doesn;'t apply if a dialog box pops up at the end of the movement