transmitterbase.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //TRANSMITTER BASE
  2. class TransmitterBase extends ItemTransmitter
  3. {
  4. //Sounds
  5. string SOUND_RADIO_TURNED_ON = "";
  6. protected EffectSound m_SoundLoop;
  7. // --- SYSTEM EVENTS
  8. override void OnStoreSave( ParamsWriteContext ctx )
  9. {
  10. super.OnStoreSave( ctx );
  11. //store tuned frequency
  12. ctx.Write( GetTunedFrequencyIndex() );
  13. }
  14. override bool OnStoreLoad( ParamsReadContext ctx, int version )
  15. {
  16. if ( !super.OnStoreLoad( ctx, version ) )
  17. return false;
  18. //--- Transmitter data ---
  19. //load and set tuned frequency
  20. int tuned_frequency_idx;
  21. if ( !ctx.Read( tuned_frequency_idx ) )
  22. {
  23. SetFrequencyByIndex( 0 ); //set default
  24. return false;
  25. }
  26. SetFrequencyByIndex( tuned_frequency_idx );
  27. //---
  28. return true;
  29. }
  30. override bool IsTransmitter()
  31. {
  32. return true;
  33. }
  34. //--- ACTIONS
  35. void SetNextFrequency( PlayerBase player = NULL )
  36. {
  37. SetNextChannel();
  38. /*
  39. if ( player )
  40. {
  41. DisplayRadioInfo( GetTunedFrequency().ToString(), player );
  42. }
  43. */
  44. }
  45. //--- HUD
  46. /*
  47. protected Hud GetHud( PlayerBase player )
  48. {
  49. if ( !player )
  50. {
  51. return NULL;
  52. }
  53. return player.m_Hud;
  54. }
  55. void DisplayRadioInfo( string message, PlayerBase player )
  56. {
  57. Hud hud;
  58. if ( player )
  59. {
  60. hud = GetHud( player );
  61. }
  62. if ( hud )
  63. {
  64. hud.SetWalkieTalkieText( message );
  65. hud.ShowWalkieTalkie( 3 );
  66. }
  67. }
  68. */
  69. //--- POWER EVENTS
  70. override void OnSwitchOn()
  71. {
  72. if ( !GetCompEM().CanWork() )
  73. {
  74. GetCompEM().SwitchOff();
  75. }
  76. }
  77. override void OnWorkStart()
  78. {
  79. //turn on broadcasting/receiving
  80. EnableBroadcast ( true );
  81. EnableReceive ( true );
  82. SwitchOn ( true );
  83. //play sound
  84. SoundTurnedOnNoiseStart();
  85. }
  86. override void OnWorkStop()
  87. {
  88. //auto switch off (EM)
  89. GetCompEM().SwitchOff();
  90. //turn off broadcasting/receiving
  91. EnableBroadcast ( false );
  92. EnableReceive ( false );
  93. SwitchOn ( false );
  94. //stop sound
  95. SoundTurnedOnNoiseStop();
  96. }
  97. //================================================================
  98. // SOUNDS
  99. //================================================================
  100. //Static noise when the radio is turned on
  101. protected void SoundTurnedOnNoiseStart()
  102. {
  103. PlaySoundSetLoop( m_SoundLoop, SOUND_RADIO_TURNED_ON, 1.0, 1.0 );
  104. }
  105. protected void SoundTurnedOnNoiseStop()
  106. {
  107. StopSoundSet( m_SoundLoop );
  108. }
  109. override void SetActions()
  110. {
  111. super.SetActions();
  112. AddAction(ActionTurnOnTransmitter);
  113. AddAction(ActionTurnOffTransmitter);
  114. AddAction(ActionTuneFrequency);
  115. }
  116. }