hudinfo.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/hudinfo.cpp $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 1/03/02 8:16p $*
  29. * *
  30. * $Revision:: 17 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "hudinfo.h"
  36. #include "combat.h"
  37. #include "ccamera.h"
  38. #include "gametype.h"
  39. #include "debug.h"
  40. /*
  41. **
  42. */
  43. GameObjReference HUDInfo::WeaponTargetObject;
  44. Vector3 HUDInfo::WeaponTargetPosition( 0,0,0 );
  45. GameObjReference HUDInfo::InfoObject;
  46. float HUDInfo::InfoObjectTimer;
  47. bool HUDInfo::DisplayActionBar = false;
  48. float HUDInfo::ActionStatusValue = 0;
  49. bool HUDInfo::IsHUDHelpTextDirty = true;
  50. WideStringClass HUDInfo::HUDHelpText;
  51. Vector3 HUDInfo::HUDHelpTextColor (1.0F, 1.0F, 1.0F);
  52. bool HUDInfo::IsMCT = false;
  53. /*
  54. **
  55. */
  56. void HUDInfo::Set_Info_Object( DamageableGameObj * obj, bool is_mct )
  57. {
  58. static void * last_info_object = NULL;
  59. static float last_info_health = 0;
  60. // Debug_Say(( "--- Info Object %s\n", obj ? obj->Get_Definition().Get_Name() : "NONE" ));
  61. IsMCT = is_mct;
  62. if ( obj != NULL && obj->As_BuildingGameObj() != NULL ) {
  63. if ( last_info_object == obj ) {
  64. // Don't re-select buildings unless it has been damaged
  65. if ( last_info_health == obj->Get_Defense_Object()->Get_Health() ) {
  66. // Only in single player and only non mct
  67. if ( !is_mct && IS_MISSION ) {
  68. return;
  69. }
  70. }
  71. }
  72. }
  73. if ( obj != NULL ) {
  74. last_info_object = obj;
  75. last_info_health = obj->Get_Defense_Object()->Get_Health();
  76. }
  77. InfoObject = obj;
  78. InfoObjectTimer = 0;
  79. // Debug_Say(( "Set Info Object %s\n", obj ? obj->Get_Definition().Get_Name() : "NONE" ));
  80. }
  81. /*
  82. **
  83. */
  84. void HUDInfo::Update_Info_Object( void )
  85. {
  86. // Timeout info for buildings only
  87. DamageableGameObj * info = Get_Info_Object();
  88. // Forget Building as soon as we are off them (in MP)
  89. if ( !IS_MISSION && info != NULL && info->As_BuildingGameObj() != NULL ) {
  90. if ( HUDInfo::InfoObjectTimer > 0 ) {
  91. InfoObject = NULL;
  92. info = NULL;
  93. }
  94. }
  95. // Forget Dead
  96. if ( info != NULL && info->Get_Defense_Object()->Get_Health() == 0 ) {
  97. InfoObject = NULL;
  98. info = NULL;
  99. }
  100. // if ( info != NULL && info->As_BuildingGameObj() == NULL ) {
  101. if ( info != NULL ) {
  102. HUDInfo::InfoObjectTimer += TimeManager::Get_Frame_Seconds();
  103. if ( HUDInfo::InfoObjectTimer > 5 ) {
  104. InfoObject = NULL;
  105. info = NULL;
  106. } else {
  107. // Forget him if we fall off target
  108. #if 0
  109. if ( info->As_PhysicalGameObj() != NULL ) {
  110. Vector3 obj_pos = info->As_PhysicalGameObj()->Get_Bullseye_Position();
  111. Vector3 screen_pos;
  112. if (COMBAT_CAMERA->Project(screen_pos, obj_pos) == CameraClass::INSIDE_FRUSTUM) {
  113. #else
  114. if ( info->As_PhysicalGameObj() != NULL && info->As_PhysicalGameObj()->Peek_Physical_Object() != NULL ) {
  115. AABoxClass bounds = info->As_PhysicalGameObj()->Peek_Physical_Object()->Get_Cull_Box();
  116. if ( !COMBAT_CAMERA->Cull_Box( bounds ) ) {
  117. #endif
  118. #if 0
  119. Vector2 reticle_offset = COMBAT_CAMERA->Get_Camera_Target_2D_Offset();
  120. screen_pos.X -= reticle_offset.X;
  121. screen_pos.Y -= reticle_offset.Y;
  122. screen_pos.Z = 0;
  123. if ( screen_pos.Length() > 0.25f ) {
  124. if ( HUDInfo::InfoObjectTimer > 0.5f ) {
  125. InfoObject = NULL;
  126. }
  127. }
  128. #endif
  129. } else {
  130. InfoObject = NULL;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. void HUDInfo::Set_Weapon_Target_Object( DamageableGameObj * obj )
  137. {
  138. // Debug_Say(( "Set Weapon Target %s\n", obj ? obj->Get_Definition().Get_Name() : "NONE" ));
  139. WeaponTargetObject = obj;
  140. }