Audio Track changes when entering Specific Environments
by Titak and Raymond

With the help of conditions (using variables), TriggerGroups and GlobalTriggers it is possible to change the audio when Lara enters another environment. Normally, when for example Lara goes from outside to inside, you can easily trigger a new background audiotrack using the appropriate Sound flipeffecttriggers. But when Lara is going into water for example, you can not set these triggers. In this tutorial I am going to describe how to change the background audio track when going underwater. This tutorial is the result of a cooperation between Raymond and myself. Raymond helped me out with the experiments I started for my own levels, when things turned out to be more complicated than anticipated at first. So, many thanks go to Raymond for making this possible!

Situation 1

In SITUATION 1 I am assuming that you are only going to use one ambient background track for when Lara is in a dry room.
So there is no change in background audio during the level

Audio Stuff

In this tutorial I use 107.wav as default background audio and 102.wav will be the underwater ambience audio track.

In the script you always have the following line:
Level= DATA\mylevel,107
107 is the default background audio for the level.
It plays on channel 1.
Since I want this audiotrack to change to another track when going underwater I also want this underwater audio to play on channel 1.

Now, go into the room editor and export the following triggers:

; Exporting: TRIGGER(358:0) for FLIPEFFECT(68)
; <#> : Sound. (CD) Play <&>CD track in (E) way on channel1
; <&> : AUDIO\102
; (E) : Looped playback
; Values to add in script command: $2000, 68, $166

; Exporting: TRIGGER(363:0) for FLIPEFFECT(68)
; <#> : Sound. (CD) Play <&>CD track in (E) way on channel1
; <&> : AUDIO\107
; (E) : Looped playback
; Values to add in script command: $2000, 68, $16B


In your script make the following TriggerGroups with the triggers you just exported:
TriggerGroup= 1, $2000, 68, $166 ; play audio 102.wav
TriggerGroup= 2, $2000, 68, $16B ; play audio 107.wav

Environmental Conditions Stuff

The game needs to know whether or not Lara is underwater so it will know which background audio track to play.
For this we are going to use the fact that each environment has a certain value in the game.
In this case we are going to copy this value to a numeric variable in the Savegame Memory zone.
We will use this value later on as a condition to tell the engine when the underwater ambient track 102 should play and when track 107 should play.

The script for this is:
TriggerGroup= 3, $2000, 244, $852
; Exporting: TRIGGER(2128:0) for FLIPEFFECT(244)
; <#> : Variables. Memory. Copy to <&>Numeric Variable the (E)Savegame Memory value
; <&> : Local Short Beta1
; (E) : Lara. Environment where lara is. (ground, underwater ecc,) (Short)
; Values to add in script command: $2000, 244, $852
GlobalTrigger= 1, IGNORE, GT_ALWAYS, IGNORE, IGNORE, 3, IGNORE


I'm using the GlobalTrigger so I don't have to place a trigger for TG3 in the prj.

When checking the value of LocalShortBeta1 ingame with the Diagnostics enabled you will see that this value is 1 when Lara is completely underwater.
This will be used for our condition.
So export the following trigger:
[1]; Exporting: CONDITION(43:60) for PARAMETER(80)
; <#> : Local Short Beta1
; <&> : Variables. The <#>Numeric Variable is = than (E)Value
; (E) : Value= 1
; Values to add in script command: $8000, 82, $12B[/I]

We need to have a condition that this variable has value 1 AND we need a condition that this variable does not have value 1
So make the following TriggerGroups with the exported values:
TriggerGroup= 4, $8000, 82, $12B ; condition that Local Short Beta1 has value 1
TriggerGroup= 5, $8000 + TGROUP_NOT, 82, $12B ; condition that Local Short Beta1 does NOT have value 1

Putting it All Together

Now for the final touches: the GlobalTriggers which are needed to make it all work! We have already established that audio track 102 has to play when Lara is underwater. Underwater is when Local Short Beta1 has value 1.
So we need to put TG4 and TG1 in one GlobalTrigger:
TriggerGroup= 4, $8000, 82, $12B ; condition that Local Short Beta1 has value 1
TriggerGroup= 1, $2000, 68, $166 ; play audio 102.wav
GlobalTrigger= 2, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 4, 1, -1


And audiotrack 107 has to play when Lara is on dry land, which means that Local Short Beta1 does NOT have value 1.
So we need to put TG5 and TG2 into a second GlobalTrigger:
TriggerGroup= 5, $8000 + TGROUP_NOT, 82, $12B ; condition that Local Short Beta1 does NOT have value 1
TriggerGroup= 2, $2000, 68, $16B ; play audio 107.wav
GlobalTrigger= 3, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 5, 2, -1

So the total script looks like this:

TriggerGroup=      3, $2000, 244, $852 ; Copy the SaveGame Memory value for 
"Environment where lara is" to Local Short Beta1
GlobalTrigger=   1, IGNORE, GT_ALWAYS, IGNORE, IGNORE, 3, IGNORE

TriggerGroup=   4, $8000, 82, $12B ; condition that Local Short Beta1 has value 1
TriggerGroup=  1, $2000, 68, $166 ; play audio 102.wav
GlobalTrigger=  2, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 4, 1, -1

TriggerGroup=   5, $8000 + TGROUP_NOT, 82, $12B ; condition that Local Short Beta1
does NOT have value 1
TriggerGroup=  2, $2000, 68, $16B ; play audio 107.wav
GlobalTrigger=  3, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 5, 2, -1

Situation 2

For SITUATION 2 I am going to explain which extra steps need to be taken when you change the background audio st some point in the level.
Like for example when Lara goes from inside, dry cave-like ambience, to outside, rain ambience.

Audio Stuff

102.wav - underwater ambience
107.wav - default background audio
106.wav - another background track which should be triggered when Lara goes outside.

; Exporting: TRIGGER(358:0) for FLIPEFFECT(68)
; <#> : Sound. (CD) Play <&>CD track in (E) way on channel1
; <&> : AUDIO\102
; (E) : Looped playback
; Values to add in script command: $2000, 68, $166

; Exporting: TRIGGER(363:0) for FLIPEFFECT(68)
; <#> : Sound. (CD) Play <&>CD track in (E) way on channel1
; <&> : AUDIO\107
; (E) : Looped playback
; Values to add in script command: $2000, 68, $16B

; Exporting: TRIGGER(363:0) for FLIPEFFECT(68)
; <#> : Sound. (CD) Play <&>CD track in (E) way on channel1
; <&> : AUDIO\106
; (E) : Looped playback
; Values to add in script command: $2000, 68, $16A


Extra Variables Stuff

For the game to know which of the background tracks whould be played when Lara is NOT underwater we need some additional variables stuff which also needs to be used as an extra condition.
So, instead of triggering the audio we are going to set a bit in a variable.
In this case I chose Local Byte Delta4 to avoid a conflict with the Local Short Beta1 which we also need again.
Export the following triggers and make two TriggerGroups with them:
; Exporting: TRIGGER(331:0) for FLIPEFFECT(234)
; <#> : Variables. Numeric. Set in <&>Variable the (E)bit
; <&> : Local Byte Delta4
; (E) : Bit 1 ($00000002 ; 2)
; Values to add in script command: $2000, 234, $14B
TriggerGroup= 6, $2000, 234, $14B

; Exporting: TRIGGER(331:0) for FLIPEFFECT(235)
; <#> : Variables. Numeric. Clear in <&>Variable the (E)bit
; <&> : Local Byte Delta4
; (E) : Bit 1 ($00000002 ; 2)
; Values to add in script command: $2000, 235, $14B
TriggerGroup= 7, $2000, 235, $14B


Also export the following condition triggers:
; Exporting: CONDITION(44:60) for PARAMETER(68)
; <#> : Local Byte Delta4
; <&> : Variables. The <#>Numeric Variable has the (E)Bit set
; (E) : Bit 1 ($00000002 ; 2)
; Values to add in script command: $8000, 75, $12C

; Exporting: CONDITION(45:60) for PARAMETER(75)
; <#> : Local Byte Delta4
; <&> : Variables. The <#>Numeric Variable has the (E)Bit clear
; (E) : Bit 1 ($00000002 ; 2)
; Values to add in script command: $8000, 75, $12D


Place flipeffect triggers for these TG's on the tiles where you would normally place the Sound flipeffect triggers for audio 107 and 106.
So now you place flipeffecttriggers for TG6 where you want to activate audio 107 and you place flipeffecttriggers for TG7 where you want to activate audio 106.
If the level starts with the default audio 107 (from the script) you don't have to place a trigger for TG7 under LARA because the bit is cleared by default at the start fo the level.

Putting it All Together

The first part of the script is the same as in SITUATION 1:
TriggerGroup= 3, $2000, 244, $852 ; Copy the SaveGame Memory value for "Environment where lara is" to Local Short Beta1
GlobalTrigger= 1, IGNORE, GT_ALWAYS, IGNORE, IGNORE, 3, IGNORE

TriggerGroup= 4, $8000, 82, $12B ; condition that Local Short Beta1 has value 1
TriggerGroup= 1, $2000, 68, $166 ; play audio 102.wav
GlobalTrigger= 2, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 4, 1, -1


Instead of just 1 more GlobalTrigger, like in SITUATION 1, we now need two extra GlobalTriggers.
The extra conditions we exported before are now added to the condition TG we also used in SITUATION 1:
TriggerGroup= 5, $8000 + TGROUP_NOT, 82, $12B, $8000, 75, $12D ; Local Short Beta1 is NOT 1, Local Byte Delta4 has bit 1 cleared
TriggerGroup= 2, $2000, 68, $16B ; play audio 107.wav
GlobalTrigger= 3, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 5, 2, -1

TriggerGroup= 8, $8000 + TGROUP_NOT, 82, $12B, $8000, 75, $12C ; Local Short Beta1 is NOT 1, Local Byte Delta4 has bit 1 set
TriggerGroup= 9, $2000, 68, $16A ; play audio 106.wav
GlobalTrigger= 4, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 8, 9, -1


So the total script looks like this:

; ---- place triggers for TG6 and TG7 in your prj 
TriggerGroup=  6, $2000, 234, $14B
TriggerGroup= 7, $2000, 235, $14B

TriggerGroup=      3, $2000, 244, $852 ; Copy the SaveGame Memory value for
"Environment where lara is" to Local Short Beta1
GlobalTrigger=   1, IGNORE, GT_ALWAYS, IGNORE, IGNORE, 3, IGNORE

TriggerGroup=   4, $8000, 82, $12B ; condition that Local Short Beta1 has value 1
TriggerGroup=  1, $2000, 68, $166 ; play audio 102.wav
GlobalTrigger=  2, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 4, 1, -1

TriggerGroup=   5, $8000 + TGROUP_NOT, 82, $12B, $8000, 75, $12D ; Local Short Beta1
is NOT 1, Local Byte Delta4 has bit 1 cleared
TriggerGroup=  2, $2000, 68, $16B ; play audio 107.wav
GlobalTrigger=  3, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 5, 2, -1

TriggerGroup=   8, $8000 + TGROUP_NOT, 82, $12B, $8000, 75, $12C  ; Local Short Beta1
is NOT 1, Local Byte Delta4 has bit 1 set
TriggerGroup=   9, $2000, 68, $16A ; play audio 106.wav
GlobalTrigger=  4, FGT_SINGLE_SHOT_RESUMED, GT_CONDITION_GROUP, IGNORE, 8, 9, -1