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.

575 lines
16 KiB

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