4
Fork 0

Moved combat music control to a separate quest

remove-levelsystem
Eddoursul 4 months ago
parent 173fccda26
commit a5929ffdb3
  1. BIN
      CombatMusicControl.esp
  2. BIN
      scripts/_00E_CombatMusicControl.pex
  3. BIN
      scripts/_00E_EnderalControls.pex
  4. BIN
      scripts/_00e_combatsoundtrackscript.pex
  5. BIN
      scripts/_00e_epupdatefunctions.pex
  6. BIN
      scripts/_00e_mqp02_functions.pex
  7. BIN
      scripts/_00e_playerfunctions.pex
  8. 159
      source/scripts/_00E_CombatMusicControl.psc
  9. 2
      source/scripts/_00E_EnderalControls.psc
  10. 6
      source/scripts/_00e_combatsoundtrackscript.psc
  11. 2
      source/scripts/_00e_epupdatefunctions.psc
  12. 1
      source/scripts/_00e_mqp02_functions.psc
  13. 157
      source/scripts/_00e_playerfunctions.psc

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,159 @@
Scriptname _00E_CombatMusicControl extends Quest Hidden
MusicType[] ActiveCombatMusics
MusicType[] StoppingCombatMusics
Int StoppingCombatMusicCounter = 0
Int Property COMBAT_MUSIC_LOCK_NONE = 0 AutoReadOnly
Int Property COMBAT_MUSIC_LOCK_START = 1 AutoReadOnly
Int Property COMBAT_MUSIC_LOCK_STOP = 2 AutoReadOnly
Int Property COMBAT_MUSIC_LOCK_FAILSAFE = 3 AutoReadOnly
Int CombatMusicLockLevel = 0 ; = COMBAT_MUSIC_LOCK_NONE
Event OnInit()
; Yes, OnInit() runs in idle quests as well
InitCombatMusic() ; also called from OnPlayerLoadGame() in _00E_PlayerFunctions
EndEvent
Function InitCombatMusic()
If ActiveCombatMusics.Length == 0
ActiveCombatMusics = _NewMusicArray()
EndIf
If StoppingCombatMusics.Length == 0
StoppingCombatMusics = _NewMusicArray()
EndIf
If StoppingCombatMusicCounter > 0 || ActiveCombatMusics[0]
GoToState("CombatMusicTracking")
EndIf
EndFunction
Bool Function StartCombatMusic(MusicType newMusic)
; Debug.Trace(self + ", StartCombatMusic, newMusic = " + newMusic)
Bool result = False
While CombatMusicLockLevel > COMBAT_MUSIC_LOCK_NONE
Utility.Wait(0.03) ; wait for two frames
EndWhile
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_START
Int Index = _AddUniqueMusicToArray(ActiveCombatMusics, newMusic)
If Index >= 0
ActiveCombatMusics[Index].Add()
result = (Index == 0) ; Is this the first combat music in this fight?
EndIf
StoppingCombatMusicCounter = 0
GoToState("CombatMusicTracking")
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_NONE
Return result
EndFunction
Function StopCombatMusic()
; Debug.Trace(self + ", StopCombatMusic")
While CombatMusicLockLevel > COMBAT_MUSIC_LOCK_NONE
If CombatMusicLockLevel == COMBAT_MUSIC_LOCK_START || CombatMusicLockLevel == COMBAT_MUSIC_LOCK_STOP
Return
EndIf
Utility.Wait(0.03)
EndWhile
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_STOP
Int Index = 0
While Index < ActiveCombatMusics.Length && ActiveCombatMusics[Index]
ActiveCombatMusics[Index].Remove()
_AddUniqueMusicToArray(StoppingCombatMusics, ActiveCombatMusics[Index])
Index += 1
EndWhile
ActiveCombatMusics = _NewMusicArray()
StoppingCombatMusicCounter = 8
GoToState("CombatMusicTracking")
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_NONE
EndFunction
State CombatMusicTracking
Event OnBeginState()
RegisterForSingleUpdate(3.5)
EndEvent
Event OnEndState()
UnregisterForUpdate()
EndEvent
Event OnUpdate()
; Debug.Trace("_00E_PlayerFunctions, OnUpdate")
RegisterForSingleUpdate(3.5)
If (Game.GetForm(0x14) as Actor).IsInCombat() || CombatMusicLockLevel > COMBAT_MUSIC_LOCK_NONE
Return
EndIf
If StoppingCombatMusicCounter > 0
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_FAILSAFE
; Debug.Trace(self + ", OnUpdate: failsaving")
Int Index = 0
While Index < StoppingCombatMusics.Length && StoppingCombatMusics[Index]
StoppingCombatMusics[Index].Add()
StoppingCombatMusics[Index].Remove()
Index += 1
EndWhile
StoppingCombatMusicCounter -= 1
If StoppingCombatMusicCounter <= 0
StoppingCombatMusics = _NewMusicArray()
EndIf
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_NONE
ElseIf ActiveCombatMusics[0] ; Failsafe in case StopCombatMusic is not called for whatever reason
StopCombatMusic()
Else
GoToState("")
EndIf
EndEvent
EndState
MusicType[] Function _NewMusicArray()
Return New MusicType[10]
EndFunction
Int Function _AddUniqueMusicToArray(MusicType[] musics, MusicType newMusic)
Int n = musics.Length
Int Index = 0
; Loop through array until we reach the end or newMusic or an empty entry
While Index < n && musics[Index] != newMusic && musics[Index] != None
Index += 1
EndWhile
If Index < n && musics[Index] == None
musics[Index] = newMusic
Return Index
Else
Return -1
EndIf
EndFunction

@ -9,3 +9,5 @@ _00E_TeleportControl Property TeleportControl Auto
_00E_SafeItemRemove Property SafeItemRemove Auto
_00E_VisionControl Property VisionControl Auto
_00E_CombatMusicControl Property CombatMusicControl Auto

@ -6,7 +6,7 @@ Event OnUpdate()
RegisterForSingleUpdate(2.0)
ElseIf Triggered
Triggered = False
(player as _00E_PlayerFunctions).StopCombatMusic()
_00E_PlayerFunctions.GetCombatMusicControl().StopCombatMusic()
EndIf
EndEvent
@ -20,9 +20,9 @@ Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
Actor player = Game.GetPlayer()
If akTarget == player
Int encounterLevel = GetLevel()
If encounterLevel >= 20 || (encounterLevel >= (PlayerLevel.GetValue() - 15)) || HasKeyword(ActorTypeBoss) ; Frage ab ob Gegnerstufe über Spielerstufe oder Boss ist, wenn ja spiele Combatmusic
If encounterLevel >= 20 || (encounterLevel >= (PlayerLevel.GetValue() - 15)) || HasKeyword(ActorTypeBoss) ; Frage ab ob Gegnerstufe über Spielerstufe oder Boss ist, wenn ja spiele Combatmusic
If Triggered == False ; player.IsInCombat() &&
Triggered = (player as _00E_PlayerFunctions).StartCombatMusic(_00E_Music_Combat_Regular)
Triggered = _00E_PlayerFunctions.GetCombatMusicControl().StartCombatMusic(_00E_Music_Combat_Regular)
If Triggered
RegisterForSingleUpdate(5.0)
EndIf

@ -22,7 +22,6 @@ int QuestsCompletedCounter = 0
Event OnInit()
if Self == Player
GoToState("RealPlayer")
(Player as _00E_PlayerFunctions).InitCombatMusic()
RegisterForSingleUpdate(2.0)
Endif
EndEvent
@ -33,7 +32,6 @@ Event OnPlayerLoadGame()
GoToState("RealPlayer")
EndIf
UpdateLevelUpSystem() ; Failsafe and version update
(Player as _00E_PlayerFunctions).InitCombatMusic() ; Version update from 1.5.2.0 or earlier
UnregisterForUpdate()
RegisterForSingleUpdate(3.5)
EndIf

@ -1,7 +1,6 @@
Scriptname _00E_MQP02_Functions extends Quest Conditional
Import Utility
Import _00E_QuestFunctions
;=====================================================================================
; EVENTS

@ -21,6 +21,7 @@ Event OnPlayerLoadGame()
if ControlRepository == None
ControlRepository = Game.GetForm(0x493C2) as _00E_EnderalControls
endif
GetCombatMusicControl().InitCombatMusic()
EndEvent
_00E_SkillControl function GetSkillControl() Global
@ -31,6 +32,10 @@ _00E_VisionControl function GetVisionControl() Global
return (Game.GetForm(0x14) as _00E_PlayerFunctions).ControlRepository.VisionControl
endfunction
_00E_CombatMusicControl function GetCombatMusicControl() Global
return (Game.GetForm(0x14) as _00E_PlayerFunctions).ControlRepository.CombatMusicControl
endfunction
_00E_FadeToBlackControl function GetFadeToBlackControl() Global
return (Game.GetForm(0x14) as _00E_PlayerFunctions).ControlRepository.FadeToBlackControl
endfunction
@ -103,155 +108,3 @@ Function ReequipTorches(Form[] equippedTorches)
iHand += 1
EndWhile
EndFunction
;=====================================================================================
; Combat music control
;=====================================================================================
MusicType[] ActiveCombatMusics
MusicType[] StoppingCombatMusics
Int StoppingCombatMusicCounter = 0
Int Property COMBAT_MUSIC_LOCK_NONE = 0 AutoReadOnly
Int Property COMBAT_MUSIC_LOCK_START = 1 AutoReadOnly
Int Property COMBAT_MUSIC_LOCK_STOP = 2 AutoReadOnly
Int Property COMBAT_MUSIC_LOCK_FAILSAFE = 3 AutoReadOnly
Int CombatMusicLockLevel = 0 ; = COMBAT_MUSIC_LOCK_NONE
Function InitCombatMusic()
If ActiveCombatMusics.Length == 0
ActiveCombatMusics = _NewMusicArray()
EndIf
If StoppingCombatMusics.Length == 0
StoppingCombatMusics = _NewMusicArray()
EndIf
If StoppingCombatMusicCounter > 0 || ActiveCombatMusics[0]
GoToState("CombatMusicTracking")
EndIf
EndFunction
Bool Function StartCombatMusic(MusicType newMusic)
; Debug.Trace(self + ", StartCombatMusic, newMusic = " + newMusic)
Bool result = False
While CombatMusicLockLevel > COMBAT_MUSIC_LOCK_NONE
Utility.Wait(0.03) ; wait for two frames
EndWhile
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_START
Int Index = _AddUniqueMusicToArray(ActiveCombatMusics, newMusic)
If Index >= 0
ActiveCombatMusics[Index].Add()
result = (Index == 0) ; Is this the first combat music in this fight?
EndIf
StoppingCombatMusicCounter = 0
GoToState("CombatMusicTracking")
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_NONE
Return result
EndFunction
Function StopCombatMusic()
; Debug.Trace(self + ", StopCombatMusic")
While CombatMusicLockLevel > COMBAT_MUSIC_LOCK_NONE
If CombatMusicLockLevel == COMBAT_MUSIC_LOCK_START || CombatMusicLockLevel == COMBAT_MUSIC_LOCK_STOP
Return
EndIf
Utility.Wait(0.03)
EndWhile
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_STOP
Int Index = 0
While Index < ActiveCombatMusics.Length && ActiveCombatMusics[Index]
ActiveCombatMusics[Index].Remove()
_AddUniqueMusicToArray(StoppingCombatMusics, ActiveCombatMusics[Index])
Index += 1
EndWhile
ActiveCombatMusics = _NewMusicArray()
StoppingCombatMusicCounter = 8
GoToState("CombatMusicTracking")
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_NONE
EndFunction
State CombatMusicTracking
Event OnUpdate()
; _00E_EPUpdateFunctions that is also attached to the player, does the job of registering for updates.
; That's why there is no RegisterForUpdate anywhere in this script.
; Debug.Trace("_00E_PlayerFunctions, OnUpdate")
If IsInCombat() || CombatMusicLockLevel > COMBAT_MUSIC_LOCK_NONE
Return
EndIf
If StoppingCombatMusicCounter > 0
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_FAILSAFE
; Debug.Trace(self + ", OnUpdate: failsaving")
Int Index = 0
While Index < StoppingCombatMusics.Length && StoppingCombatMusics[Index]
StoppingCombatMusics[Index].Add()
StoppingCombatMusics[Index].Remove()
Index += 1
EndWhile
StoppingCombatMusicCounter -= 1
If StoppingCombatMusicCounter <= 0
StoppingCombatMusics = _NewMusicArray()
EndIf
CombatMusicLockLevel = COMBAT_MUSIC_LOCK_NONE
ElseIf ActiveCombatMusics[0] ; Failsafe in case StopCombatMusic is not called for whatever reason
StopCombatMusic()
Else
GoToState("")
EndIf
EndEvent
EndState
MusicType[] Function _NewMusicArray()
Return New MusicType[10]
EndFunction
Int Function _AddUniqueMusicToArray(MusicType[] musics, MusicType newMusic)
Int n = musics.Length
Int Index = 0
; Loop through array until we reach the end or newMusic or an empty entry
While Index < n && musics[Index] != newMusic && musics[Index] != None
Index += 1
EndWhile
If Index < n && musics[Index] == None
musics[Index] = newMusic
Return Index
Else
Return -1
EndIf
EndFunction

Loading…
Cancel
Save