1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-27 21:49:10 +02:00

Fixed bug 143 and possibly 142.

This commit is contained in:
Frank Zago 2009-10-12 05:00:28 +00:00
parent a2861a82d2
commit c2cb7be227
5 changed files with 56 additions and 62 deletions

View File

@ -461,13 +461,13 @@ bool CDefenceAnim::init()
if(killed) if(killed)
{ {
CGI->soundh->playSound(attacked->creature->sounds.killed); CGI->soundh->playSound(battle_sound(attacked->creature, killed));
owner->creAnims[stackID]->setType(5); //death owner->creAnims[stackID]->setType(5); //death
} }
else else
{ {
// TODO: this block doesn't seems correct if the unit is defending. // TODO: this block doesn't seems correct if the unit is defending.
CGI->soundh->playSound(attacked->creature->sounds.wince); CGI->soundh->playSound(battle_sound(attacked->creature, wince));
owner->creAnims[stackID]->setType(3); //getting hit owner->creAnims[stackID]->setType(3); //getting hit
} }
@ -566,7 +566,7 @@ bool CBattleStackMoved::init()
//unit reversed //unit reversed
if(owner->moveSh <= 0) if(owner->moveSh <= 0)
owner->moveSh = CGI->soundh->playSound(movedStack->creature->sounds.move, -1); owner->moveSh = CGI->soundh->playSound(battle_sound(movedStack->creature, move), -1);
//step shift calculation //step shift calculation
posX = owner->creAnims[stackID]->pos.x, posY = owner->creAnims[stackID]->pos.y; // for precise calculations ;] posX = owner->creAnims[stackID]->pos.x, posY = owner->creAnims[stackID]->pos.y; // for precise calculations ;]
@ -682,8 +682,7 @@ bool CBattleMoveStart::init()
return false; return false;
} }
if (movedStack->creature->sounds.startMoving) CGI->soundh->playSound(battle_sound(movedStack->creature, startMoving));
CGI->soundh->playSound(movedStack->creature->sounds.startMoving);
return true; return true;
} }
@ -728,11 +727,7 @@ bool CBattleMoveEnd::init()
return false; return false;
} }
CGI->soundh->playSound(battle_sound(movedStack->creature, endMoving));
if (movedStack->creature->sounds.endMoving)
{
CGI->soundh->playSound(movedStack->creature->sounds.endMoving);
}
owner->creAnims[stackID]->setType(21); owner->creAnims[stackID]->setType(21);
@ -779,15 +774,16 @@ void CBattleAttack::nextFrame()
// twice. The following is just a workaround until // twice. The following is just a workaround until
// that is fixed. Once done, we can get rid of // that is fixed. Once done, we can get rid of
// sh // sh
if (sh == -1) if (sh == -1) {
sh = CGI->soundh->playSound(attackingStack->creature->sounds.shoot); sh = CGI->soundh->playSound(battle_sound(attackingStack->creature, shoot));
}
owner->creAnims[stackID]->setType(group); owner->creAnims[stackID]->setType(group);
} }
else else
{ {
// TODO: see comment above // TODO: see comment above
if (sh == -1) if (sh == -1)
sh = CGI->soundh->playSound(attackingStack->creature->sounds.attack); sh = CGI->soundh->playSound(battle_sound(attackingStack->creature, attack));
static std::map<int, int> dirToType = boost::assign::map_list_of (0, 11)(1, 11)(2, 12)(3, 13)(4, 13)(5, 12); static std::map<int, int> dirToType = boost::assign::map_list_of (0, 11)(1, 11)(2, 12)(3, 13)(4, 13)(5, 12);
int type; //dependent on attack direction int type; //dependent on attack direction
@ -4039,4 +4035,4 @@ CStackQueue::StackBox::~StackBox()
void CStackQueue::StackBox::hover( bool on ) void CStackQueue::StackBox::hover( bool on )
{ {
} }

View File

@ -202,16 +202,6 @@ void CCreatureHandler::loadCreatures()
CCreature ncre; CCreature ncre;
ncre.cost.resize(RESOURCE_QUANTITY); ncre.cost.resize(RESOURCE_QUANTITY);
ncre.level=0; ncre.level=0;
ncre.sounds.attack = soundBase::invalid;
ncre.sounds.defend = soundBase::invalid;
ncre.sounds.killed = soundBase::invalid;
ncre.sounds.move = soundBase::invalid;
ncre.sounds.shoot = soundBase::invalid;
ncre.sounds.wince = soundBase::invalid;
ncre.sounds.ext1 = soundBase::invalid;
ncre.sounds.ext2 = soundBase::invalid;
ncre.sounds.startMoving = soundBase::invalid;
ncre.sounds.endMoving = soundBase::invalid;
int befi=i; int befi=i;
for(i; i<andame; ++i) for(i; i<andame; ++i)

View File

@ -45,26 +45,6 @@ public:
int troopCountLocationOffset, attackClimaxFrame; int troopCountLocationOffset, attackClimaxFrame;
///end of anim info ///end of anim info
// Sound infos
class sounds {
public:
soundBase::soundID attack;
soundBase::soundID defend;
soundBase::soundID killed; // was killed died
soundBase::soundID move;
soundBase::soundID shoot; // range attack
soundBase::soundID wince; // attacked but did not die
soundBase::soundID ext1; // creature specific extension
soundBase::soundID ext2; // creature specific extension
soundBase::soundID startMoving; // usually same as ext1
soundBase::soundID endMoving; // usually same as ext2
template <typename Handler> void serialize(Handler &h, const int version)
{
h & attack & defend & killed & move & shoot & wince & ext1 & ext2 & startMoving & endMoving;
}
} sounds;
bool isDoubleWide() const; //returns true if unit is double wide on battlefield bool isDoubleWide() const; //returns true if unit is double wide on battlefield
bool isFlying() const; //returns true if it is a flying unit bool isFlying() const; //returns true if it is a flying unit
bool isShooting() const; //returns true if unit can shoot bool isShooting() const; //returns true if unit can shoot
@ -95,8 +75,6 @@ public:
& timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance & timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
& upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY & upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
& missleFrameAngles & troopCountLocationOffset & attackClimaxFrame; & missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
h & sounds;
} }
}; };

View File

@ -154,6 +154,8 @@ void CSoundHandler::initCreaturesSounds(std::vector<CCreature> &creatures)
std::ifstream ifs(DATA_DIR "/config/cr_sounds.txt"); std::ifstream ifs(DATA_DIR "/config/cr_sounds.txt");
std::string line; std::string line;
CBattleSounds.resize(creatures.size());
while(getline(ifs, line)) while(getline(ifs, line))
{ {
std::string cname="", attack="", defend="", killed="", move="", std::string cname="", attack="", defend="", killed="", move="",
@ -179,27 +181,25 @@ void CSoundHandler::initCreaturesSounds(std::vector<CCreature> &creatures)
continue; continue;
} }
CCreature &c = creatures[id]; if (CBattleSounds[id].killed != soundBase::invalid)
if (c.sounds.killed != soundBase::invalid)
tlog1 << "Creature << " << cname << " already has sounds" << std::endl; tlog1 << "Creature << " << cname << " already has sounds" << std::endl;
c.sounds.attack = getSoundID(attack); CBattleSounds[id].attack = getSoundID(attack);
c.sounds.defend = getSoundID(defend); CBattleSounds[id].defend = getSoundID(defend);
c.sounds.killed = getSoundID(killed); CBattleSounds[id].killed = getSoundID(killed);
c.sounds.move = getSoundID(move); CBattleSounds[id].move = getSoundID(move);
c.sounds.shoot = getSoundID(shoot); CBattleSounds[id].shoot = getSoundID(shoot);
c.sounds.wince = getSoundID(wince); CBattleSounds[id].wince = getSoundID(wince);
c.sounds.ext1 = getSoundID(ext1); CBattleSounds[id].ext1 = getSoundID(ext1);
c.sounds.ext2 = getSoundID(ext2); CBattleSounds[id].ext2 = getSoundID(ext2);
// Special creatures // Special creatures
if (c.idNumber == 55 || // Archdevil if (id == 55 || // Archdevil
c.idNumber == 62 || // Vampire id == 62 || // Vampire
c.idNumber == 62) // Vampire Lord id == 62) // Vampire Lord
{ {
c.sounds.startMoving = c.sounds.ext1; CBattleSounds[id].startMoving = CBattleSounds[id].ext1;
c.sounds.endMoving = c.sounds.ext2; CBattleSounds[id].endMoving = CBattleSounds[id].ext2;
} }
} }
} }

View File

@ -23,6 +23,32 @@ struct _Mix_Music;
typedef struct _Mix_Music Mix_Music; typedef struct _Mix_Music Mix_Music;
struct Mix_Chunk; struct Mix_Chunk;
// Sound infos for creatures in combat
struct CreaturesBattleSounds {
soundBase::soundID attack;
soundBase::soundID defend;
soundBase::soundID killed; // was killed or died
soundBase::soundID move;
soundBase::soundID shoot; // range attack
soundBase::soundID wince; // attacked but did not die
soundBase::soundID ext1; // creature specific extension
soundBase::soundID ext2; // creature specific extension
soundBase::soundID startMoving; // usually same as ext1
soundBase::soundID endMoving; // usually same as ext2
CreaturesBattleSounds(): attack(soundBase::invalid),
defend(soundBase::invalid),
killed(soundBase::invalid),
move(soundBase::invalid),
shoot(soundBase::invalid),
wince(soundBase::invalid),
ext1(soundBase::invalid),
ext2(soundBase::invalid),
startMoving(soundBase::invalid),
endMoving(soundBase::invalid) {};
};
class CAudioBase { class CAudioBase {
protected: protected:
bool initialized; bool initialized;
@ -61,12 +87,16 @@ public:
int playSound(soundBase::soundID soundID, int repeats=0); int playSound(soundBase::soundID soundID, int repeats=0);
int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec); int playSoundFromSet(std::vector<soundBase::soundID> &sound_vec);
void stopSound(int handler); void stopSound(int handler);
std::vector <struct CreaturesBattleSounds> CBattleSounds;
// Sets // Sets
std::vector<soundBase::soundID> pickupSounds; std::vector<soundBase::soundID> pickupSounds;
std::vector<soundBase::soundID> horseSounds; std::vector<soundBase::soundID> horseSounds;
}; };
// Helper
#define battle_sound(creature,what_sound) CGI->soundh->CBattleSounds[(creature)->idNumber].what_sound
class CMusicHandler: public CAudioBase class CMusicHandler: public CAudioBase
{ {
private: private: