# HG changeset patch # User nemo # Date 1313969344 14400 # Node ID e35ba2a400d8bc95dc0eafa0da0c1f529998581e # Parent c18aed7ad618459e576f62ddf82ca9ec56b5589c Try to avoid overlapping voices for major statements (not things like byebye or oof) diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/GSHandlers.inc Sun Aug 21 19:29:04 2011 -0400 @@ -2300,8 +2300,7 @@ Gear^.doStep := @doStepFirePunchWork; DrawTunnel(HHGear^.X - int2hwFloat(cHHRadius), HHGear^.Y + _1, _0_5, _0, cHHRadius * 4, 5); - PlaySound(TSound(ord(sndFirePunch1) + GetRandom(6)), HHGear^.Hedgehog^.Team^. - voicepack) + AddVoice(TSound(ord(sndFirePunch1) + GetRandom(6)), HHGear^.Hedgehog^.Team^.voicepack) end; //////////////////////////////////////////////////////////////////////////////// diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/HHHandlers.inc Sun Aug 21 19:29:04 2011 -0400 @@ -215,7 +215,7 @@ if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then xx:= - xx; if Ammoz[CurAmmoType].Ammo.AttackVoice <> sndNone then - PlaySound(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack); + AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack); // Initiating alt attack if (CurAmmoGear <> nil) and diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uGame.pas --- a/hedgewars/uGame.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uGame.pas Sun Aug 21 19:29:04 2011 -0400 @@ -45,7 +45,7 @@ if isSpeed then Lag:= Lag * 10 else if cOnlyStats then Lag:= High(LongInt); - +PlayNextVoice; i:= 1; while (GameState <> gsExit) and (i <= Lag) do begin diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uGears.pas Sun Aug 21 19:29:04 2011 -0400 @@ -962,11 +962,11 @@ and (not PlacingHogs) and (CurrentHedgehog^.Gear <> nil) and ((CurrentHedgehog^.Gear^.State and gstAttacked) = 0) then - PlaySound(sndHurry, CurrentTeam^.voicepack); + AddVoice(sndHurry, CurrentTeam^.voicepack); if ReadyTimeLeft > 0 then begin if ReadyTimeLeft = 2000 then - PlaySound(sndComeonthen, CurrentTeam^.voicepack); + AddVoice(sndComeonthen, CurrentTeam^.voicepack); dec(ReadyTimeLeft) end else @@ -1850,7 +1850,7 @@ FindPlace(FollowGear, true, 0, LAND_WIDTH); if (FollowGear <> nil) then - PlaySound(sndReinforce, CurrentTeam^.voicepack) + AddVoice(sndReinforce, CurrentTeam^.voicepack) end end; diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uScript.pas Sun Aug 21 19:29:04 2011 -0400 @@ -1106,7 +1106,7 @@ begin gear:= GearByUID(lua_tointeger(L, 2)); if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then - PlaySound(TSound(lua_tointeger(L, 1)),gear^.Hedgehog^.Team^.Voicepack) + AddVoice(TSound(lua_tointeger(L, 1)),gear^.Hedgehog^.Team^.Voicepack) end else LuaError('Lua: Wrong number of parameters passed to PlaySound!'); lc_playsound:= 0; diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uSound.pas --- a/hedgewars/uSound.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uSound.pas Sun Aug 21 19:29:04 2011 -0400 @@ -77,6 +77,9 @@ procedure StopSound(chn: LongInt); procedure StopSound(chn, fadems: LongInt); +procedure AddVoice(snd: TSound; voicepack: PVoicepack); +procedure PlayNextVoice; + // MISC @@ -255,9 +258,9 @@ exit; if (voicepack <> nil) then - begin + begin if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then - begin + begin s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName; WriteToConsole(msgLoading + s + ' '); @@ -266,22 +269,49 @@ WriteLnToConsole(msgFailed) else WriteLnToConsole(msgOK) - end; + end; lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1) - end + end else - begin + begin if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then - begin + begin s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName; WriteToConsole(msgLoading + s + ' '); defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1); TryDo(defVoicepack^.chunks[snd] <> nil, msgFailed, true); WriteLnToConsole(msgOK); - end; + end; lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1) - end; + end; +end; + +procedure AddVoice(snd: TSound; voicepack: PVoicepack); +var i : LongInt; +begin + i:= 0; + while (i<8) and (VoiceList[i].snd <> sndNone) do inc(i); + + VoiceList[i].snd:= snd; + VoiceList[i].voicepack:= voicepack; +end; + +procedure PlayNextVoice; +var i : LongInt; +begin + if (LastVoice.snd <> sndNone) and (lastChan[LastVoice.snd] <> -1) and (Mix_Playing(lastChan[LastVoice.snd]) <> 0) then exit; + i:= 0; + while (i<8) and (VoiceList[i].snd = sndNone) do inc(i); + + if (VoiceList[i].snd <> sndNone) then + begin + LastVoice.snd:= VoiceList[i].snd; + LastVoice.voicepack:= VoiceList[i].voicepack; + VoiceList[i].snd:= sndNone; + PlaySound(LastVoice.snd, LastVoice.voicepack) + end + else LastVoice.snd:= sndNone; end; function LoopSound(snd: TSound): LongInt; diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uStats.pas --- a/hedgewars/uStats.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uStats.pas Sun Aug 21 19:29:04 2011 -0400 @@ -99,11 +99,11 @@ inc(CurrentHedgehog^.stats.FinishedTurns); if (CurrentHedgehog^.stats.DamageGiven = DamageTotal) and (DamageTotal > 0) then - PlaySound(sndFirstBlood, CurrentTeam^.voicepack) + AddVoice(sndFirstBlood, CurrentTeam^.voicepack) else if CurrentHedgehog^.stats.StepDamageRecv > 0 then begin - PlaySound(sndStupid, PreviousTeam^.voicepack); + AddVoice(sndStupid, PreviousTeam^.voicepack); if CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then AddCaption(Format(GetEventString(eidHurtSelf), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage); end @@ -111,32 +111,32 @@ else if DamageClan <> 0 then if DamageTotal > DamageClan then if random(2) = 0 then - PlaySound(sndNutter, CurrentTeam^.voicepack) + AddVoice(sndNutter, CurrentTeam^.voicepack) else - PlaySound(sndWatchIt, vpHurtSameClan) + AddVoice(sndWatchIt, vpHurtSameClan) else if random(2) = 0 then - PlaySound(sndSameTeam, vpHurtSameClan) + AddVoice(sndSameTeam, vpHurtSameClan) else - PlaySound(sndTraitor, vpHurtSameClan) + AddVoice(sndTraitor, vpHurtSameClan) else if CurrentHedgehog^.stats.StepDamageGiven <> 0 then if Kills > 0 then - PlaySound(sndEnemyDown, CurrentTeam^.voicepack) + AddVoice(sndEnemyDown, CurrentTeam^.voicepack) else - PlaySound(sndRegret, vpHurtEnemy) + AddVoice(sndRegret, vpHurtEnemy) else if AmmoDamagingUsed then - PlaySound(sndMissed, PreviousTeam^.voicepack) + AddVoice(sndMissed, PreviousTeam^.voicepack) else if (AmmoUsedCount > 0) and not isTurnSkipped then // nothing ? else if isTurnSkipped then begin - PlaySound(sndBoring, PreviousTeam^.voicepack); + AddVoice(sndBoring, PreviousTeam^.voicepack); AddCaption(Format(GetEventString(eidTurnSkipped), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage); end else if not PlacingHogs then - PlaySound(sndCoward, PreviousTeam^.voicepack); + AddVoice(sndCoward, PreviousTeam^.voicepack); end; diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uTeams.pas Sun Aug 21 19:29:04 2011 -0400 @@ -81,9 +81,9 @@ if (Gear <> nil) then Gear^.State:= gstWinner; if Flawless then - PlaySound(sndFlawless, Teams[0]^.voicepack) + AddVoice(sndFlawless, Teams[0]^.voicepack) else - PlaySound(sndVictory, Teams[0]^.voicepack); + AddVoice(sndVictory, Teams[0]^.voicepack); AddCaption(s, cWhiteColor, capgrpGameState); SendStat(siGameResult, s); @@ -257,16 +257,16 @@ if (TurnTimeLeft > 0) and (CurrentHedgehog^.BotLevel = 0) then begin if CurrentTeam^.ExtDriven then - PlaySound(sndIllGetYou, CurrentTeam^.voicepack) + AddVoice(sndIllGetYou, CurrentTeam^.voicepack) else - PlaySound(sndYesSir, CurrentTeam^.voicepack); + AddVoice(sndYesSir, CurrentTeam^.voicepack); if PlacingHogs or (cHedgehogTurnTime < 1000000) then ReadyTimeLeft:= cReadyDelay; AddCaption(Format(shortstring(trmsg[sidReady]), CurrentTeam^.TeamName), cWhiteColor, capgrpGameState) end else begin if TurnTimeLeft > 0 then - PlaySound(sndIllGetYou, CurrentTeam^.voicepack); + AddVoice(sndIllGetYou, CurrentTeam^.voicepack); ReadyTimeLeft:= 0 end; diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uTypes.pas --- a/hedgewars/uTypes.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uTypes.pas Sun Aug 21 19:29:04 2011 -0400 @@ -314,6 +314,11 @@ chunks: array [TSound] of PMixChunk; end; + TVoice = record + snd: TSound; + voicepack: PVoicePack; + end; + PHHAmmo = ^THHAmmo; THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo; diff -r c18aed7ad618 -r e35ba2a400d8 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Sun Aug 21 15:11:00 2011 -0400 +++ b/hedgewars/uVariables.pas Sun Aug 21 19:29:04 2011 -0400 @@ -210,6 +210,17 @@ cTagsMasks : array[0..15] of byte = (7, 0, 0, 0, 15, 6, 4, 5, 0, 0, 0, 0, 0, 14, 12, 13); cTagsMasksNoHealth: array[0..15] of byte = (3, 2, 11, 1, 0, 0, 0, 0, 0, 10, 0, 9, 0, 0, 0, 0); + VoiceList : array[0..7] of TVoice = ( + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil), + ( snd: sndNone; voicepack: nil)); + LastVoice : TVoice = ( snd: sndNone; voicepack: nil ); + Fontz: array[THWFont] of THHFont = ( (Handle: nil; Height: 12;