Difference between revisions of "Callback: Sound effect"
(update link) |
(more strict var 10/18 masking) |
||
(One intermediate revision by one other user not shown) | |||
Line 2: | Line 2: | ||
This callback is called for all vehicles and as generic callback for bridges, for various events that support playing sound effects. |
This callback is called for all vehicles and as generic callback for bridges, for various events that support playing sound effects. |
||
− | The type of event is stored in variable 10. |
+ | The type of event is stored in the lowest byte of variable 10. |
The 15-bit return value is the sound effect number. Values from 0 to 72 (dec) are TTD's built-in sound effects, values beyond that |
The 15-bit return value is the sound effect number. Values from 0 to 72 (dec) are TTD's built-in sound effects, values beyond that |
||
Line 11: | Line 11: | ||
{| |- |
{| |- |
||
− | ! |
+ | !Lowest byte of variable 10!!Event |
|- |
|- |
||
|1||Start sound, called when leaving a station or depot, take-off sound for planes |
|1||Start sound, called when leaving a station or depot, take-off sound for planes |
||
Line 23: | Line 23: | ||
|5||Touchdown sound, for planes only (obviously) |
|5||Touchdown sound, for planes only (obviously) |
||
|- |
|- |
||
− | |6|| |
+ | |6||Visual effect generation (steam plume, diesel smoke, electric spark) |
|- |
|- |
||
|7||Running sound, called every 16 engine ticks if in motion |
|7||Running sound, called every 16 engine ticks if in motion |
||
Line 31: | Line 31: | ||
|9||Load/unload sound, called when consist loads or unloads cargo |
|9||Load/unload sound, called when consist loads or unloads cargo |
||
|- |
|- |
||
− | |10||Bridge sound, called as generic feature 06 callback every time a consist moves on a bridge. Variables 40+x, 60+x and 80+x refer to the vehicle and bits 0..7 of variable 18 hold the bridge type |
+ | |10||Bridge sound, called as generic feature 06 callback every time a consist moves on a bridge. Variables 40+x, 60+x and 80+x refer to the vehicle, and bits 0..7 of variable 18 hold the bridge type |
|} |
|} |
||
Latest revision as of 12:24, 18 April 2015
Sound effect (33)
This callback is called for all vehicles and as generic callback for bridges, for various events that support playing sound effects. The type of event is stored in the lowest byte of variable 10.
The 15-bit return value is the sound effect number. Values from 0 to 72 (dec) are TTD's built-in sound effects, values beyond that refer to the sounds from Action 11.
If the callback returns a failure code (not a callback result), the default TTD sound effect will be played. If the callback returns a sound number that is neither a TTD sound, nor a sound from action 11, nothing will be played.
Lowest byte of variable 10 | Event |
---|---|
1 | Start sound, called when leaving a station or depot, take-off sound for planes |
2 | Tunnel sound, called when vehicle enters tunnel |
3 | Breakdown sound, called when vehicle breaks down (not for planes) |
4 | Running sound, called once per engine tick, but no more than once per vehicle motion |
5 | Touchdown sound, for planes only (obviously) |
6 | Visual effect generation (steam plume, diesel smoke, electric spark) |
7 | Running sound, called every 16 engine ticks if in motion |
8 | Stopped sound, called every 16 engine ticks if stopped (e.g. at signal/in station) |
9 | Load/unload sound, called when consist loads or unloads cargo |
10 | Bridge sound, called as generic feature 06 callback every time a consist moves on a bridge. Variables 40+x, 60+x and 80+x refer to the vehicle, and bits 0..7 of variable 18 hold the bridge type |
For the running sounds, it is advisable to check the motion counter and to only return a successful sound effect number every so many vehicle motion ticks. This way, the sounds will be played more frequently the faster the train is. Alternatively, you can check the tick counter variable and play the sound effect every so many engine ticks, so that it is played at a constant rate, or, of course, switch between both modes depending on vehicle speed.
Note that if the planespeed switch is active, planes move the given number of times per engine tick. This means that their motion counter increases faster than for other vehicles, and thus to get reliable sound effects you need to divide the motion counter by the planespeed setting (readable via action D) before checking the value.