Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

603 lines
16 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef SFHUDRADAR_H_
  7. #define SFHUDRADAR_H_
  8. #include "hud.h"
  9. #include "hud_element_helper.h"
  10. #include "scaleformui/scaleformui.h"
  11. #include "sfhudflashinterface.h"
  12. #include "c_cs_hostage.h"
  13. #define MAX_LOCATION_TEXT_LENGTH 100
  14. #define MAX_DECOYS 30
  15. class SFHudRadar : public SFHudFlashInterface
  16. {
  17. // this manages the display of the players and hostages
  18. // in the radar
  19. protected:
  20. enum ICON_PACK_TYPE
  21. {
  22. ICON_PACK_PLAYER,
  23. ICON_PACK_HOSTAGE,
  24. ICON_PACK_DECOY,
  25. ICON_PACK_DEFUSER,
  26. };
  27. enum
  28. {
  29. R_BELOW = 0,
  30. R_SAMELEVEL = 1,
  31. R_ABOVE = 2,
  32. };
  33. // each enum represents an icon that this class is managing
  34. enum PLAYER_ICON_INDICES
  35. {
  36. PI_PLAYER_NUMBER,
  37. PI_PLAYER_LETTER,
  38. PI_FIRST_ROTATED,
  39. PI_PLAYER_INDICATOR = PI_FIRST_ROTATED,
  40. PI_SPEAKING,
  41. PI_SPEAKING_OFFMAP,
  42. PI_ABOVE,
  43. PI_BELOW,
  44. PI_HOSTAGE_MOVING,
  45. PI_HOSTAGE_MOVING_OFFMAP,
  46. PI_CT,
  47. PI_CT_OFFMAP,
  48. PI_CT_DEAD,
  49. PI_CT_GHOST,
  50. PI_T,
  51. PI_T_OFFMAP,
  52. PI_T_DEAD,
  53. PI_T_GHOST,
  54. PI_ENEMY,
  55. PI_ENEMY_OFFMAP,
  56. PI_ENEMY_DEAD,
  57. PI_ENEMY_GHOST,
  58. PI_HOSTAGE,
  59. PI_HOSTAGE_OFFMAP,
  60. PI_HOSTAGE_DEAD,
  61. PI_HOSTAGE_GHOST,
  62. PI_DIRECTION_INDICATOR,
  63. PI_DEFUSER,
  64. PI_SELECTED,
  65. PI_VIEWFRUSTRUM,
  66. PI_ENEMY_SEELOCAL,
  67. PI_NUM_ICONS
  68. };
  69. class SFHudRadarIconPackage
  70. {
  71. public:
  72. SFHudRadarIconPackage();
  73. ~SFHudRadarIconPackage();
  74. // zero all the internal variables
  75. void ClearAll( void );
  76. // get handles to the icons which will all be children
  77. // of the iconPackage handle
  78. void Init( IScaleformUI* pui, SFVALUE iconPackage );
  79. // release all the handles, and clear all the variables
  80. // used when removing players or changing maps
  81. void NukeFromOrbit( SFHudRadar* pSFUI );
  82. // reset all variables to their start of round values
  83. void StartRound( void );
  84. // set the states for this player
  85. void SetIsPlayer( bool value );
  86. void SetIsSelected( bool value );
  87. void SetIsSpeaking ( bool value );
  88. void SetIsOffMap( bool value );
  89. void SetIsAboveOrBelow( int value );
  90. void SetIsMovingHostage( bool value );
  91. void SetIsDead( bool value );
  92. void SetIsRescued( bool value );
  93. void SetPlayerTeam( int team );
  94. void SetGrenadeExpireTime( float value );
  95. void SetIsSpotted( bool value );
  96. void SetIsSpottedByFriendsOnly( bool value );
  97. void SetAlpha( float newAlpha );
  98. void SetIsOnLocalTeam( bool value );
  99. void SetIsBot( bool value );
  100. void SetIsControlledBot( void );
  101. void SetIsDefuse( bool bValue );
  102. // given the current set of states, decide which
  103. // icons should be shown and which should be hidden
  104. void SetupIconsFromStates( void );
  105. // each bit in newFlags represents the visibility of one of the
  106. // icons in the PLAYER_ICON_INDICES. If the bit is on, the icon
  107. // is shown.
  108. void SetVisibilityFlags( int newFlags );
  109. void UpdateIconsPostion( void );
  110. bool IsHostageType( void ) { return m_IconPackType == ICON_PACK_HOSTAGE;}
  111. bool IsDecoyType( void ) { return m_IconPackType == ICON_PACK_DECOY;}
  112. bool IsPlayerType( void ) { return m_IconPackType == ICON_PACK_PLAYER;}
  113. bool IsDefuserType( void ) { return m_IconPackType == ICON_PACK_DEFUSER;}
  114. bool IsVisible( void );
  115. public:
  116. // pointer to scaleform
  117. IScaleformUI* m_pScaleformUI;
  118. // the parent for all the icons
  119. SFVALUE m_IconPackage;
  120. SFVALUE m_IconPackageRotate;
  121. // the handles for all the icons listed in PLAYER_ICON_INDICES
  122. SFVALUE m_Icons[PI_NUM_ICONS];
  123. // the location and position of this player/hostage
  124. // only updated when the player is spotted
  125. Vector m_Position; // current x,y pos
  126. QAngle m_Angle; // view origin 0..360
  127. // HUD Position, rotation and scale - used to update the position of the visible icons
  128. Vector m_HudPosition;
  129. float m_HudRotation;
  130. float m_HudScale;
  131. // ignore visibility updates until a little time has passed
  132. // this keeps track of when the round started
  133. float m_fRoundStartTime;
  134. // the time at which this player/hostage died ( or was rescued )
  135. // used to calculate the alpha of the X icon.
  136. float m_fDeadTime;
  137. // the time at which the player / hostage was last spotted
  138. // used to fade out the ? icon
  139. float m_fGhostTime;
  140. // the alpha currently used to display all icons
  141. // used to lazy update the actual scaleform value
  142. float m_fCurrentAlpha;
  143. // last time we applied this color to the movie
  144. float m_fLastColorUpdate;
  145. // each bit represents one of the PLAYER_ICON_INDICES
  146. // used to lazy update the visibility of the icons in scaleform
  147. int m_iCurrentVisibilityFlags;
  148. // the index of this player/hostage in the radar.
  149. // used to create the instance name of the icon package in flash
  150. int m_iIndex;
  151. // set from the player objects UserID or EntityID ( for the hostages ). Lets us find the radar
  152. // object that represents a player / hostage
  153. int m_iEntityID;
  154. // state variables used to keep track of the player / hostage state
  155. // so we know which icon( s ) to show
  156. int m_Health; // 0..100, 7 bit
  157. wchar_t m_wcName[MAX_PLAYER_NAME_LENGTH+1];
  158. // the base icon for the player
  159. int m_iPlayerType; // will be PI_CT, PI_T, or PI_HOSTAGE
  160. int m_nAboveOrBelow;// R_BELOW = 0,R_SAMELEVEL = 1,R_ABOVE = 2,
  161. float m_fGrenExpireTime;
  162. ICON_PACK_TYPE m_IconPackType;
  163. bool m_bIsActive : 1;
  164. bool m_bOffMap : 1;
  165. bool m_bIsPlayer : 1;
  166. bool m_bIsSelected : 1;
  167. bool m_bIsSpeaking : 1;
  168. bool m_bIsDead : 1;
  169. bool m_bIsBot : 1;
  170. bool m_bIsMovingHostage : 1;
  171. bool m_bIsSpotted : 1;
  172. bool m_bIsSpottedByFriendsOnly : 1;
  173. bool m_bIsRescued : 1;
  174. bool m_bIsOnLocalTeam : 1;
  175. bool m_bIsDefuser : 1;
  176. bool m_bHostageIsUsed : 1;
  177. // don't put anything new after the bitfields or suffer the Wrath of the Compiler!
  178. };
  179. // this little class manages the display of the hostage
  180. // indicators in the panel
  181. class SFHudRadarHostageIcons
  182. {
  183. public:
  184. enum HOSTAGE_ICON_INDICES
  185. {
  186. HI_DEAD,
  187. HI_RESCUED,
  188. HI_ALIVE,
  189. HI_TRANSIT,
  190. HI_NUM_ICONS,
  191. HI_UNUSED = HI_NUM_ICONS,
  192. };
  193. public:
  194. SFHudRadarHostageIcons();
  195. ~SFHudRadarHostageIcons();
  196. void Init( IScaleformUI* scaleformui, SFVALUE iconPackage );
  197. void ReleaseHandles( SFHudRadar* pradar );
  198. void SetStatus( int status );
  199. public:
  200. IScaleformUI* m_pScaleformUI;
  201. // the parent object of all the icons
  202. SFVALUE m_IconPackage;
  203. // the icons which represent each of the HOSTAGE_ICON_INDICES
  204. SFVALUE m_Icons[HI_NUM_ICONS];
  205. // the index of the icon that is currently shown
  206. int m_iCurrentIcon;
  207. };
  208. // this just keeps track of the bombzone and hostagezone
  209. // icons that are shown on the radar
  210. struct SFHudRadarGoalIcon
  211. {
  212. Vector m_Position;
  213. SFVALUE m_Icon;
  214. };
  215. public:
  216. explicit SFHudRadar( const char *value );
  217. virtual ~SFHudRadar();
  218. // These overload the CHudElement class
  219. virtual void ProcessInput( void );
  220. virtual void LevelInit( void );
  221. virtual void LevelShutdown( void );
  222. virtual void SetActive( bool bActive );
  223. virtual void Init( void );
  224. virtual bool ShouldDraw( void );
  225. virtual void Reset( void )
  226. {
  227. SetActive( true );
  228. }
  229. // these overload the ScaleformFlashInterfaceMixin class
  230. virtual void FlashLoaded( void );
  231. virtual void FlashReady( void );
  232. virtual bool PreUnloadFlash( void );
  233. void MapLoaded( SCALEFORM_CALLBACK_ARGS_DECL );
  234. // overloads for the CGameEventListener class
  235. virtual void FireGameEvent( IGameEvent *event );
  236. bool MsgFunc_ProcessSpottedEntityUpdate( const CCSUsrMsg_ProcessSpottedEntityUpdate &msg );
  237. void ShowRadar( bool value ) {m_bShowRadar = value;}
  238. bool IsRadarShown( void ) {return m_bShowRadar;}
  239. void ResizeHud( void );
  240. void SwitchRadarToRound( bool toRound );
  241. CUserMessageBinder m_UMCMsgProcessSpottedEntityUpdate;
  242. bool m_bRound; // Is the radar round ( otherwise square )
  243. protected:
  244. void ResetRadar( bool bResetGlobalStates = true );
  245. void ResetForNewMap( void );
  246. void ResetRound( void );
  247. void SetMap( const char* pMapName );
  248. void WorldToRadar( const Vector& ptin, Vector& ptout );
  249. void RadarToHud( const Vector& ptin, Vector& ptout );
  250. void LazyCreateGoalIcons( void );
  251. void FlashLoadMap( const char* pMapName );
  252. void FlashUpdateMapLayer( int layerIdx );
  253. void InitIconPackage( SFHudRadarIconPackage* pPlayer, int iAbsoluteIndex, ICON_PACK_TYPE packType );
  254. void RemoveIconPackage( SFHudRadarIconPackage* pPlayer );
  255. SFHudRadarIconPackage* CreatePlayer( int index );
  256. void ResetPlayer( int index );
  257. void RemovePlayer( int index );
  258. SFHudRadarIconPackage* CreateHostage( int index );
  259. void ResetHostage( int index );
  260. void RemoveHostage( int index );
  261. void RemoveStaleHostages( void );
  262. void RemoveAllHostages( void );
  263. SFHudRadarIconPackage* CreateDecoy( int index );
  264. void RemoveAllDecoys( void );
  265. void RemoveDecoy( int index );
  266. SFHudRadarIconPackage * CreateDefuser( int nEntityID );
  267. SFHudRadarIconPackage * GetDefuser( int nEntityID, bool bCreateIfNotFound = false );
  268. void SetDefuserPos( int nEntityID, int x, int y, int z, int a );
  269. void UpdateAllDefusers( void );
  270. void RemoveAllDefusers( void );
  271. void RemoveDefuser( int index );
  272. bool LazyUpdateIconArray( SFHudRadarIconPackage* pArray, int lastIndex );
  273. virtual bool LazyCreateIconPackage( SFHudRadarIconPackage* pPackage );
  274. void LazyCreatePlayerIcons( void );
  275. void SetPlayerTeam( int index, int team );
  276. int GetPlayerIndexFromUserID( int userID );
  277. int GetHostageIndexFromHostageEntityID( int entityID );
  278. int GetDecoyIndexFromEntityID( int entityID );
  279. int GetDefuseIndexFromEntityID( int nEntityID );
  280. void ApplySpectatorModes( void );
  281. void PositionRadarViewpoint( void );
  282. void PlaceGoalIcons( void );
  283. void Show( bool show );
  284. void PlacePlayers();
  285. void PlaceHostages();
  286. void SetIconPackagePosition( SFHudRadarIconPackage* pPackage );
  287. void UpdateMiscIcons( void );
  288. void SetVisibilityFlags( int newFlags );
  289. void SetupIconsFromStates( void );
  290. void SetLocationText( wchar_t *newText );
  291. void ResetRoundVariables( bool bResetGlobalStates = true );
  292. void UpdateDecoys( void );
  293. void UpdateAllPlayerNumbers( void );
  294. void UpdatePlayerNumber( SFHudRadarIconPackage* pPackage );
  295. SFHudRadarIconPackage* GetRadarPlayer( int index );
  296. SFHudRadarIconPackage* GetRadarHostage( int index );
  297. SFHudRadarIconPackage* GetRadarDecoy( int index );
  298. SFHudRadarIconPackage* GetRadarDefuser( int index );
  299. SFHudRadarIconPackage* GetRadarHeight( int index );
  300. protected:
  301. // these are the icons used individually by the radar and panel
  302. enum RADAR_ICON_INDICES
  303. {
  304. RI_BOMB_IS_PLANTED,
  305. RI_BOMB_IS_PLANTED_MEDIUM,
  306. RI_BOMB_IS_PLANTED_FAST,
  307. RI_IN_HOSTAGE_ZONE,
  308. RI_DASHBOARD,
  309. RI_BOMB_ICON_PLANTED,
  310. RI_BOMB_ICON_DROPPED,
  311. RI_BOMB_ICON_BOMB_CT,
  312. RI_BOMB_ICON_BOMB_T,
  313. RI_BOMB_ICON_BOMB_ABOVE,
  314. RI_BOMB_ICON_BOMB_BELOW,
  315. RI_BOMB_ICON_PACKAGE,
  316. RI_DEFUSER_ICON_DROPPED,
  317. RI_DEFUSER_ICON_PACKAGE,
  318. RI_NUM_ICONS,
  319. };
  320. enum
  321. {
  322. MAX_BOMB_ZONES = 2,
  323. };
  324. int m_nCurrentRadarVerticalSection;
  325. struct HudRadarLevelVerticalSection_t
  326. {
  327. int m_nSectionIndex;
  328. char m_szSectionName[MAX_MAP_NAME];
  329. float m_flSectionAltitudeFloor;
  330. float m_flSectionAltitudeCeiling;
  331. HudRadarLevelVerticalSection_t()
  332. {
  333. m_nSectionIndex = 0;
  334. m_szSectionName[0] = 0;
  335. m_flSectionAltitudeFloor = 0;
  336. m_flSectionAltitudeCeiling = 0;
  337. }
  338. };
  339. CUtlVector< HudRadarLevelVerticalSection_t > m_vecRadarVerticalSections;
  340. // this holds the names and indexes of the messages we receive so that
  341. // we don't have to do a whole bunch of string compares to find them
  342. static CUtlMap<const char*, int> m_messageMap;
  343. // these are used to scale world coordinates to radar coordinates
  344. Vector m_MapOrigin;
  345. float m_fMapSize;
  346. float m_fRadarSize;
  347. float m_fPixelToRadarScale;
  348. float m_fWorldToPixelScale;
  349. float m_fWorldToRadarScale;
  350. // this is center of the radar in world and map coordinates
  351. Vector m_RadarViewpointWorld;
  352. Vector m_RadarViewpointMap;
  353. float m_RadarRotation;
  354. // the current position of the bomb
  355. Vector m_BombPosition;
  356. // the last time the bomb was seen. Used to fade
  357. // out the bomb icon after it has dropped out of sight
  358. float m_fBombSeenTime;
  359. float m_fBombAlpha;
  360. // the current position of the defuser
  361. Vector m_DefuserPosition;
  362. // the last time the defuser was seen. Used to fade
  363. // out the defuser icon after it has dropped out of sight
  364. float m_fDefuserSeenTime;
  365. float m_fDefuserAlpha;
  366. // a bitmap of the icons that are currently beeing shown.
  367. // each bit corresponds to one the RADAR_ICON_INDICES
  368. int m_iCurrentVisibilityFlags;
  369. // the handles to the RADAR_ICON_INDICES icons
  370. SFVALUE m_Icons[RI_NUM_ICONS];
  371. // Background panel
  372. SFVALUE m_BackgroundPanel;
  373. // handles to the radar movie clips in flash.
  374. // there is a rotation and a translation layer each for the icons and for the background map.
  375. // The map and the icons have separate layers because the map is behind a mask layer, and the
  376. // icons are not.
  377. // the root of the entire radar and dashboard
  378. SFVALUE m_RadarModule;
  379. // the root of the radar part of the module
  380. SFVALUE m_Radar;
  381. // the layers that handle the icons
  382. SFVALUE m_IconTranslation;
  383. SFVALUE m_IconRotation;
  384. // the layers that handle the map
  385. SFVALUE m_MapRotation;
  386. SFVALUE m_MapTranslation;
  387. // handles to the actual bomb zone and hostage icons that are defined
  388. // in the flash file
  389. SFVALUE m_HostageZoneIcons[MAX_HOSTAGE_RESCUES];
  390. SFVALUE m_BombZoneIcons[MAX_BOMB_ZONES];
  391. // "handle" to the text that holds the current location
  392. ISFTextObject* m_LocationText;
  393. // the last index of an active player in the m_Players array
  394. int m_iLastPlayerIndex;
  395. // the last index of an active hostage in the m_Hostages array
  396. int m_iLastHostageIndex;
  397. // the last index of an active decoy in the m_Decoys array
  398. int m_iLastDecoyIndex;
  399. // the last index of an active defuser in the m_Defuser array
  400. int m_iLastDefuserIndex;
  401. // keeps the state information and icon handles for the players
  402. SFHudRadarIconPackage m_Players[MAX_PLAYERS];
  403. // keeps the state information and icon handles for the hostages
  404. SFHudRadarIconPackage m_Hostages[MAX_HOSTAGES];
  405. // keeps the state information and icon handles for the decoys
  406. SFHudRadarIconPackage m_Decoys[MAX_DECOYS];
  407. // keeps the state information and icon handles for the decoys
  408. SFHudRadarIconPackage m_Defusers[MAX_PLAYERS];
  409. // the handles to the hostage status icons that appear beneath the dashboard
  410. SFHudRadarHostageIcons m_HostageStatusIcons[MAX_HOSTAGES];
  411. // a goal icon is either a bomb-area or a hostage-area icon
  412. // This array holds the positions / handles of the ones that are active for the current map
  413. int m_iNumGoalIcons;
  414. SFHudRadarGoalIcon m_GoalIcons[MAX_HOSTAGE_RESCUES + MAX_BOMB_ZONES];
  415. // the current observer mode. Figures into the placement of the center of the radar
  416. // and a few other things
  417. int m_iObserverMode;
  418. // there is a loaded and a desired so that we don't load the same map twice, and so that we
  419. // can request that a map be loaded before the flash stuff is able to actually load it.
  420. char m_cLoadedMapName[MAX_MAP_NAME+1];
  421. char m_cDesiredMapName[MAX_MAP_NAME+1];
  422. // the name of our current location
  423. wchar_t m_wcLocationString[MAX_LOCATION_TEXT_LENGTH+1];
  424. // keeps track of weather flash is ready or not and if it's currently being loaded
  425. bool m_bFlashLoading : 1;
  426. bool m_bFlashReady : 1;
  427. // this is set by a con command to hide the whole radar
  428. bool m_bShowRadar : 1;
  429. bool m_bVisible;
  430. bool m_bShowViewFrustrum;
  431. // set to true in spectator mode if we're not in pro mode
  432. bool m_bShowAll : 1;
  433. // keep track of whether we've already gotten all the goal icons and player icons from the
  434. // flash file. This is necessary because some of the level information is loaded before
  435. // flash is ready
  436. bool m_bGotGoalIcons : 1;
  437. bool m_bGotPlayerIcons : 1;
  438. // state information about which icons should be displayed
  439. bool m_bShowingHostageZone : 1;
  440. bool m_bBombPlanted : 1;
  441. bool m_bBombDropped : 1;
  442. bool m_bBombDefused : 1;
  443. bool m_bBombExploded : 1;
  444. bool m_bShowBombHighlight : 1;
  445. bool m_bShowingDashboard : 1;
  446. bool m_bBombIsSpotted : 1;
  447. int m_nBombEntIndex;
  448. int m_nBombHolderUserId;
  449. bool m_bTrackDefusers;
  450. // entities spotted last ProcessSpottedEntityUpdate
  451. CBitVec<MAX_EDICTS> m_EntitySpotted;
  452. };
  453. #endif /* SFHUDRADAR_H_ */