advancedcommunication.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. class AdvancedCommunication extends EntityAI
  2. {
  3. static ref map<typename, ref TInputActionMap> m_AdvComTypeActionsMap = new map<typename, ref TInputActionMap>;
  4. TInputActionMap m_InputActionMap;
  5. bool m_ActionsInitialize;
  6. void AdvancedCommunication()
  7. {
  8. if (!GetGame().IsDedicatedServer())
  9. {
  10. if(GetGame().GetPlayer())
  11. {
  12. m_ActionsInitialize = false;
  13. }
  14. }
  15. }
  16. //HUD
  17. /*
  18. protected Hud GetHud( PlayerBase player )
  19. {
  20. if ( !player )
  21. {
  22. return NULL;
  23. }
  24. return player.m_Hud;
  25. }
  26. void DisplayRadioInfo( string message, PlayerBase player )
  27. {
  28. Hud hud;
  29. if ( player )
  30. {
  31. hud = GetHud( player );
  32. }
  33. if ( hud )
  34. {
  35. hud.SetWalkieTalkieText( message );
  36. hud.ShowWalkieTalkie( 3 );
  37. }
  38. }
  39. */
  40. //control transmitter via user actions
  41. void TurnOnTransmitter()
  42. {
  43. GetCompEM().SwitchOn();
  44. }
  45. void TurnOffTransmitter()
  46. {
  47. GetCompEM().SwitchOff();
  48. }
  49. void InitializeActions()
  50. {
  51. m_InputActionMap = m_AdvComTypeActionsMap.Get( this.Type() );
  52. if(!m_InputActionMap)
  53. {
  54. TInputActionMap iam = new TInputActionMap;
  55. m_InputActionMap = iam;
  56. SetActions();
  57. m_AdvComTypeActionsMap.Insert(this.Type(), m_InputActionMap);
  58. }
  59. }
  60. override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
  61. {
  62. if(!m_ActionsInitialize)
  63. {
  64. m_ActionsInitialize = true;
  65. InitializeActions();
  66. }
  67. actions = m_InputActionMap.Get(action_input_type);
  68. }
  69. void SetActions()
  70. {
  71. AddAction(ActionTurnOnTransmitterOnGround);
  72. AddAction(ActionTurnOffTransmitterOnGround);
  73. AddAction(ActionDetachPowerSourceFromPanel);
  74. }
  75. void AddAction(typename actionName)
  76. {
  77. ActionBase action = ActionManagerBase.GetAction(actionName);
  78. if (!action)
  79. {
  80. Debug.LogError("Action " + actionName + " dosn't exist!");
  81. return;
  82. }
  83. typename ai = action.GetInputType();
  84. if (!ai)
  85. {
  86. m_ActionsInitialize = false;
  87. return;
  88. }
  89. array<ActionBase_Basic> action_array = m_InputActionMap.Get( ai );
  90. if (!action_array)
  91. {
  92. action_array = new array<ActionBase_Basic>;
  93. m_InputActionMap.Insert(ai, action_array);
  94. }
  95. if ( LogManager.IsActionLogEnable() )
  96. {
  97. Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action" );
  98. }
  99. action_array.Insert(action);
  100. }
  101. void RemoveAction(typename actionName)
  102. {
  103. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  104. ActionBase action = player.GetActionManager().GetAction(actionName);
  105. typename ai = action.GetInputType();
  106. array<ActionBase_Basic> action_array = m_InputActionMap.Get( ai );
  107. if (action_array)
  108. {
  109. action_array.RemoveItem(action);
  110. }
  111. }
  112. }
  113. class PASReceiver extends AdvancedCommunication
  114. {
  115. override bool IsInventoryVisible()
  116. {
  117. return false;
  118. }
  119. };
  120. class PASBroadcaster extends AdvancedCommunication
  121. {
  122. proto native void SwitchOn(bool onOff);
  123. proto native bool IsOn();
  124. };
  125. class StaticTransmitter extends AdvancedCommunication
  126. {
  127. proto native void SwitchOn(bool onOff);
  128. proto native bool IsOn();
  129. proto native void SetNextChannel();
  130. proto native void SetPrevChannel();
  131. proto native float GetTunedFrequency();
  132. proto native void EnableBroadcast(bool state);
  133. proto native void EnableReceive(bool state);
  134. proto native bool IsBroadcasting();
  135. proto native bool IsReceiving();
  136. proto native int GetTunedFrequencyIndex();
  137. proto native void SetFrequencyByIndex(int index);
  138. };