Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SCRIPT_START
{
LVAR_INT scplayer
LVAR_INT hAudiostream bIsAudioPlaying
LVAR_FLOAT fLastExplosion_X fLastExplosion_Y fLastExplosion_Z
LVAR_FLOAT fLast_fLastExplosion_X fLast_fLastExplosion_Y fLast_fLastExplosion_Z
LVAR_FLOAT fPlayer_X fPlayer_Y fPlayer_Z
LVAR_FLOAT fDistance fMinDistance fDivDistance fVolume fNewVolume fTempVolume fSetVolume fIniVolume
LVAR_FLOAT fSfxVolume fRadioVolume fDefaultSfxVolume fDefaultRadioVolume
CONST_INT RADIO_VOLUME_ADDRESS 0xB5FCC8
CONST_INT SFX_VOLUME_ADDRESS 0xB5FCCC
CONST_INT STATE_STOP 0
CONST_INT STATE_PLAY 1
CONST_INT STATE_PAUSE 2
CONST_INT STATE_RESUME 3
///////////////////////////////////////////////////////////////////////////////////////////////////
IF NOT READ_FLOAT_FROM_INI_FILE "cleo/Ear Ringing.ini" "Settings" "Volume" (fIniVolume)
fIniVolume = 1.0
ENDIF
IF NOT READ_FLOAT_FROM_INI_FILE "cleo/Ear Ringing.ini" "Settings" "MinDistance" (fMinDistance)
fMinDistance = 15.0
ENDIF
fDivDistance = fMinDistance * 0.7
///////////////////////////////////////////////////////////////////////////////////////////////////
GET_PLAYER_CHAR 0 scplayer
main_loop:
WAIT 0
GOSUB ProcessVolume
IF IS_PLAYER_PLAYING 0
GOSUB GetLastExplosionCoord
IF GOSUB IsNewExplosion
GOSUB StoreNewExplosion
IF GOSUB IsExplosionNearPlayer
GOSUB CalculateVolume
IF bIsAudioPlaying = FALSE
GOSUB PlayAudio
ENDIF
ENDIF
ENDIF
ENDIF
GOTO main_loop
///////////////////////////////////////////////////////////////////////////////////////////////////
PlayAudio:
LOAD_AUDIO_STREAM "cleo/cleo_sounds/ear_ringing.wav" hAudiostream
SET_AUDIO_STREAM_LOOPED hAudiostream ON
SET_AUDIO_STREAM_VOLUME hAudiostream fVolume
SET_AUDIO_STREAM_STATE hAudiostream STATE_PLAY
bIsAudioPlaying = TRUE
RETURN
ProcessVolume:
IF bIsAudioPlaying = TRUE
fVolume -=@ 0.001
IF fVolume > 0.0
GOSUB UpdateAudiostreamVolume
fTempVolume = 1.0
fTempVolume -= fVolume
fSFXvolume = fDefaultSfxVolume
fSFXvolume *= fTempVolume
IF fSFXvolume < 0.0
fSFXvolume = 0.0
ENDIF
WRITE_MEMORY SFX_VOLUME_ADDRESS 4 fSFXvolume FALSE
fRadiovolume = fDefaultRadioVolume
fRadiovolume *= fTempVolume
IF fRadiovolume < 0.0
fRadiovolume = 0.0
ENDIF
WRITE_MEMORY RADIO_VOLUME_ADDRESS 4 fRadiovolume FALSE
ELSE
REMOVE_AUDIO_STREAM hAudiostream
WRITE_MEMORY SFX_VOLUME_ADDRESS 4 fDefaultSfxVolume FALSE
WRITE_MEMORY RADIO_VOLUME_ADDRESS 4 fDefaultRadioVolume FALSE
bIsAudioPlaying = FALSE
ENDIF
ELSE
GOSUB UpdateDefaultVolumeSetting
ENDIF
RETURN
UpdateAudiostreamVolume:
fSetVolume = fVolume
IF fSetVolume > 1.0
fSetVolume = 1.0
ENDIF
fSetVolume /= fIniVolume
SET_AUDIO_STREAM_VOLUME hAudiostream fSetVolume
RETURN
UpdateDefaultVolumeSetting:
READ_MEMORY SFX_VOLUME_ADDRESS 4 FALSE (fDefaultSfxVolume)
READ_MEMORY RADIO_VOLUME_ADDRESS 4 FALSE (fDefaultRadioVolume)
RETURN
CalculateVolume:
fNewVolume = fMinDistance
fNewVolume -= fDistance
fNewVolume /= fDivDistance
IF fNewVolume < 0.1
fNewVolume = 0.1
ENDIF
IF fNewVolume > fVolume
fVolume = fNewVolume
ENDIF
RETURN
GetLastExplosionCoord:
READ_MEMORY 0xC88954 4 FALSE (fLastExplosion_X)
READ_MEMORY 0xC88958 4 FALSE (fLastExplosion_Y)
READ_MEMORY 0xC8895C 4 FALSE (fLastExplosion_Z)
RETURN
IsNewExplosion:
IF NOT fLast_fLastExplosion_X = fLastExplosion_X
OR NOT fLast_fLastExplosion_Y = fLastExplosion_Y
OR NOT fLast_fLastExplosion_Z = fLastExplosion_Z
IS_PC_VERSION
ELSE
IS_AUSTRALIAN_GAME
ENDIF
RETURN
StoreNewExplosion:
fLast_fLastExplosion_X = fLastExplosion_X
fLast_fLastExplosion_Y = fLastExplosion_Y
fLast_fLastExplosion_Z = fLastExplosion_Z
RETURN
IsExplosionNearPlayer:
GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS scplayer 0.0 1.0 0.0 (fPlayer_X fPlayer_Y fPlayer_Z)
GET_DISTANCE_BETWEEN_COORDS_3D (fLastExplosion_X fLastExplosion_Y fLastExplosion_Z) (fPlayer_X fPlayer_Y fPlayer_Z) (fDistance)
IF fDistance < fMinDistance
IS_PC_VERSION
ELSE
IS_AUSTRALIAN_GAME
ENDIF
RETURN
}
SCRIPT_END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment