unitcoordinationzonemgr.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : combat *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/unitcoordinationzonemgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/15/01 3:55p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "unitcoordinationzonemgr.h"
  36. #include "transition.h"
  37. #include "obbox.h"
  38. #include "aabox.h"
  39. #include "combat.h"
  40. #include "pscene.h"
  41. #include "staticanimphys.h"
  42. #include "elevator.h"
  43. //////////////////////////////////////////////////////////////////////
  44. // Static member initialization
  45. //////////////////////////////////////////////////////////////////////
  46. DynamicVectorClass<AABoxClass> UnitCoordinationZoneMgr::ZoneList;
  47. //////////////////////////////////////////////////////////////////////
  48. //
  49. // Build_Zones
  50. //
  51. //////////////////////////////////////////////////////////////////////
  52. void
  53. UnitCoordinationZoneMgr::Build_Zones (void)
  54. {
  55. Reset ();
  56. //
  57. // Build the zone lists for both ladder and elevators
  58. //
  59. Detect_Ladder_Zones ();
  60. Detect_Elevator_Zones ();
  61. return ;
  62. }
  63. //////////////////////////////////////////////////////////////////////
  64. //
  65. // Reset
  66. //
  67. //////////////////////////////////////////////////////////////////////
  68. void
  69. UnitCoordinationZoneMgr::Reset (void)
  70. {
  71. ZoneList.Delete_All ();
  72. return ;
  73. }
  74. //////////////////////////////////////////////////////////////////////
  75. //
  76. // Detect_Ladder_Zones
  77. //
  78. //////////////////////////////////////////////////////////////////////
  79. void
  80. UnitCoordinationZoneMgr::Detect_Ladder_Zones (void)
  81. {
  82. //
  83. // Build the list of transitions
  84. //
  85. DynamicVectorClass<TransitionInstanceClass *> transition_list;
  86. TransitionManager::Build_Ladder_List (transition_list);
  87. //
  88. // Now, add a zone around the entrance and exit for each transition
  89. //
  90. for (int index = 0; index < transition_list.Count (); index ++) {
  91. TransitionInstanceClass *transition = transition_list[index];
  92. //
  93. // Convert the obbox to an aabox
  94. //
  95. const OBBoxClass &zone_box = transition->Get_Zone ();
  96. AABoxClass zone_box_as_aabox;
  97. zone_box_as_aabox.Center = zone_box.Center;
  98. zone_box.Compute_Axis_Aligned_Extent (&zone_box_as_aabox.Extent);
  99. //
  100. // Start a new zone centered about the ending transform for the ladder and
  101. // including the trigger zone
  102. //
  103. AABoxClass new_zone;
  104. new_zone.Center.Set (transition->Get_Ending_TM ().Get_Translation ());
  105. new_zone.Add_Box (zone_box_as_aabox);
  106. //
  107. // Add this zone to our list
  108. //
  109. ZoneList.Add (new_zone);
  110. }
  111. return ;
  112. }
  113. //////////////////////////////////////////////////////////////////////
  114. //
  115. // Detect_Elevator_Zones
  116. //
  117. //////////////////////////////////////////////////////////////////////
  118. void
  119. UnitCoordinationZoneMgr::Detect_Elevator_Zones (void)
  120. {
  121. RefPhysListIterator iterator = COMBAT_SCENE->Get_Static_Anim_Object_Iterator ();
  122. //
  123. // Loop over all the static anim objects in the world
  124. //
  125. for (iterator.First (); iterator.Is_Done () == false; iterator.Next ()) {
  126. StaticAnimPhysClass *phys_obj = (StaticAnimPhysClass *)iterator.Peek_Obj ();
  127. if (phys_obj != NULL && phys_obj->As_ElevatorPhysClass () != NULL) {
  128. //
  129. // Dig out the definition for this elevator
  130. //
  131. ElevatorPhysClass *elevator = phys_obj->As_ElevatorPhysClass ();
  132. const ElevatorPhysDefClass *definition = elevator->Get_ElevatorPhysDef ();
  133. //
  134. // Add a coordination zone for each of our trigger zones
  135. //
  136. for (int index = 0; index < ZONE_MAX; index ++) {
  137. const OBBoxClass &obj_space_zone = definition->Get_Zone ((ELEVATOR_ZONE)index);
  138. OBBoxClass world_space_zone;
  139. OBBoxClass::Transform (elevator->Get_Transform (), obj_space_zone, &world_space_zone);
  140. //
  141. // Convert the obbox to an aabox
  142. //
  143. AABoxClass zone_box_as_aabox;
  144. zone_box_as_aabox.Center = world_space_zone.Center;
  145. world_space_zone.Compute_Axis_Aligned_Extent (&zone_box_as_aabox.Extent);
  146. //
  147. // Add this box to our list
  148. //
  149. ZoneList.Add (zone_box_as_aabox);
  150. }
  151. }
  152. }
  153. return ;
  154. }
  155. //////////////////////////////////////////////////////////////////////
  156. //
  157. // Is_Unit_In_Zone
  158. //
  159. //////////////////////////////////////////////////////////////////////
  160. bool
  161. UnitCoordinationZoneMgr::Is_Unit_In_Zone (const Vector3 &pos)
  162. {
  163. bool retval = false;
  164. //
  165. // Simply check each zone to see if the point lies inside the box
  166. //
  167. for (int index = 0; !retval && index < ZoneList.Count (); index ++) {
  168. retval = ZoneList[index].Contains (pos);
  169. }
  170. return retval;
  171. }
  172. //////////////////////////////////////////////////////////////////////
  173. //
  174. // Display_Debug_Boxes
  175. //
  176. //////////////////////////////////////////////////////////////////////
  177. void
  178. UnitCoordinationZoneMgr::Display_Debug_Boxes (void)
  179. {
  180. //
  181. // Pretty simple, just add a debug box for each zone
  182. //
  183. for (int index = 0; index < ZoneList.Count (); index ++) {
  184. PhysicsSceneClass::Get_Instance ()->Add_Debug_AABox (ZoneList[index], Vector3 (1.0F, 0.0F, 0.25F));
  185. }
  186. return ;
  187. }