Loading
#openttdcoop - Paste
Archives
Trending
Docs
Login
ABAP
ActionScript
ActionScript 3
Ada
AIMMS3
ALGOL 68
Apache configuration
AppleScript
Apt sources
ARM ASSEMBLER
ASM
ASP
asymptote
Autoconf
Autohotkey
AutoIt
AviSynth
awk
BASCOM AVR
Bash
Basic4GL
BibTeX
BlitzBasic
bnf
Boo
Brainfuck
C
C#
C (LoadRunner)
C (Mac)
C (WinAPI)
C++
C++ (Qt)
C++ (WinAPI)
CAD DCL
CAD Lisp
CFDG
ChaiScript
Chapel
CIL
Clojure
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
Dart
DCL
DCPU-16 Assembly
DCS
Delphi
Diff
DIV
DOS
dot
E
ECMAScript
Eiffel
eMail (mbox)
EPC
Erlang
Euphoria
EZT
F#
Falcon
FO (abas-ERP)
Formula One
Fortran
FreeBasic
FreeSWITCH
GADV 4CS
GAMBAS
GDB
genero
Genie
glSlang
GML
GNU/Octave
GNU Gettext
GNU make
Gnuplot
Go
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML
HTML5
Icon
INI
Inno
INTERCAL
Io
ISPF Panel
J
Java
Java(TM) 2 Platform Standard Edition 5.0
Javascript
JCL
jQuery
KiXtart
KLone C
KLone C++
LaTeX
LDIF
Liberty BASIC
Lisp
LLVM Intermediate Representation
Locomotive Basic
Logtalk
LOLcode
Lotus Notes @Formulas
LotusScript
LScript
LSL2
Lua
MagikSF
MapBasic
Matlab M
Microchip Assembler
Microsoft Registry
mIRC Scripting
MMIX
Modula-2
Modula-3
MOS 6502 (6510) ACME Cross Assembler format
MOS 6502 (6510) Kick Assembler format
MOS 6502 (6510) TASM/64TASS 1.46 Assembler format
Motorola 68000 - HiSoft Devpac ST 2 Assembler format
Motorola 68000 Assembler
MXML
MySQL
Nagios
NetRexx
newlisp
nginx
Nimrod
NML NewGRF Meta Language
NSIS
Oberon-2
Objeck Programming Language
Objective-C
OCaml
OCaml (brief)
ooRexx
OpenBSD Packet Filter
OpenOffice.org Basic
Oracle 8 SQL
Oracle 11 SQL
Oxygene
OZ
ParaSail
PARI/GP
Pascal
PCRE
per
Perl
Perl 6
PHP
PHP (brief)
PIC16
Pike
Pixel Bender 1.0
PL/I
PL/SQL
PostgreSQL
PostScript
POVRAY
PowerBuilder
PowerShell
ProFTPd configuration
Progress
Prolog
PROPERTIES
ProvideX
Puppet
PureBasic
Python
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
R / S+
Racket
Rails
RBScript
REBOL
rexx
robots.txt
RPM Specification File
Ruby
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty
SPARK
SPARQL
SQL
Squirrel Script
Squirrel Script with OpenTTD AI/GS
StandardML
StoneScript
SystemVerilog
T-SQL
TCL
Tera Term Macro
Text
thinBasic
TypoScript
Unicon (Unified Extended Dialect of Icon)
Uno Idl
Unreal Script
UPC
Urbi
Vala
vb.net
VBScript
Vedit macro language
Verilog
VHDL
Vim Script
Visual Basic
Visual Fox Pro
Visual Prolog
Whitespace
Whois (RPSL format)
Winbatch
X++
XBasic
XML
Xorg configuration
YAML
ZiLOG Z80 Assembler
ZXBasic
Index: src/newgrf.cpp =================================================================== --- src/newgrf.cpp (revision 27506) +++ src/newgrf.cpp (working copy) @@ -1402,7 +1402,7 @@ break; case 0x12: // SFX - rvi->sfx = buf->ReadByte(); + rvi->sfx = GetNewGRFSoundId(_cur.grffile, buf->ReadByte()); break; case PROP_ROADVEH_POWER: // Power in units of 10 HP. @@ -1590,7 +1590,7 @@ break; case 0x10: // SFX - svi->sfx = buf->ReadByte(); + svi->sfx = GetNewGRFSoundId(_cur.grffile, buf->ReadByte()); break; case 0x11: { // Cargoes available for refitting @@ -1758,7 +1758,7 @@ break; case 0x12: // SFX - avi->sfx = buf->ReadByte(); + avi->sfx = GetNewGRFSoundId(_cur.grffile, buf->ReadByte()); break; case 0x13: { // Cargoes available for refitting Index: src/newgrf_sound.cpp =================================================================== --- src/newgrf_sound.cpp (revision 27506) +++ src/newgrf_sound.cpp (working copy) @@ -161,7 +161,23 @@ return false; } +/** + * Resolve NewGRF sounds IDs. + * @param file NewGRF to get sound from. + * @param sound_id GRF-specific sound ID. (GRF-local for IDs above ORIGINAL_SAMPLE_COUNT) + * @return Translated (global) sound ID, or INVALID_SOUND. + */ +SoundID GetNewGRFSoundId(const GRFFile *file, SoundID sound_id) +{ + /* Global sound? */ + if (sound_id < ORIGINAL_SAMPLE_COUNT) return sound_id; + sound_id -= ORIGINAL_SAMPLE_COUNT; + if (file == NULL || sound_id >= file->num_sounds) return INVALID_SOUND; + + return file->sound_offset + sound_id; +} + /** * Checks whether a NewGRF wants to play a different vehicle sound effect. * @param v Vehicle to play sound effect for. @@ -185,15 +201,11 @@ /* Play default sound if callback fails */ if (callback == CALLBACK_FAILED) return false; - if (callback >= ORIGINAL_SAMPLE_COUNT) { - callback -= ORIGINAL_SAMPLE_COUNT; + callback = GetNewGRFSoundId(file, callback); - /* Play no sound if result is out of range */ - if (callback > file->num_sounds) return true; + /* Play no sound, if result is invalid */ + if (callback == INVALID_SOUND) return true; - callback += file->sound_offset; - } - assert(callback < GetNumSounds()); SndPlayVehicleFx(callback, v); return true; @@ -207,11 +219,8 @@ */ void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile) { - if (sound_id >= ORIGINAL_SAMPLE_COUNT) { - sound_id -= ORIGINAL_SAMPLE_COUNT; - if (sound_id > file->num_sounds) return; - sound_id += file->sound_offset; - } + sound_id = GetNewGRFSoundId(file, sound_id); + if (sound_id == INVALID_SOUND) return; assert(sound_id < GetNumSounds()); SndPlayTileFx(sound_id, tile); Index: src/newgrf_sound.h =================================================================== --- src/newgrf_sound.h (revision 27506) +++ src/newgrf_sound.h (working copy) @@ -33,6 +33,7 @@ SoundEntry *AllocateSound(uint num); void InitializeSoundPool(); bool LoadNewGRFSound(SoundEntry *sound); +SoundID GetNewGRFSoundId(const struct GRFFile *file, SoundID sound_id); SoundEntry *GetSound(SoundID sound_id); uint GetNumSounds(); bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event); Index: src/sound_type.h =================================================================== --- src/sound_type.h (revision 27506) +++ src/sound_type.h (working copy) @@ -119,4 +119,6 @@ typedef uint16 SoundID; +static const SoundID INVALID_SOUND = 0xFFFF; + #endif /* SOUND_TYPE_H */
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever