Team Fortress 2 Source Code as on 22/4/2020
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.

279 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Team management class. Contains all the details for a specific team
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tfc_team.h"
  9. #include "entitylist.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // Datatable
  13. IMPLEMENT_SERVERCLASS_ST(CTFCTeam, DT_TFCTeam)
  14. END_SEND_TABLE()
  15. LINK_ENTITY_TO_CLASS( tfc_team_manager, CTFCTeam );
  16. Vector rgbcolors[5];
  17. team_color_t teamcolors[5][PC_LASTCLASS]; // Colors for each of the 4 teams
  18. int number_of_teams = 0; // This is incremented for each map as info_player_teamspawn are created.
  19. const char *teamnames[5] =
  20. {
  21. "spectator",
  22. "blue",
  23. "red",
  24. "yellow",
  25. "green"
  26. };
  27. //========================================================================
  28. // Set the color for the team corresponding to the no passed in, to team_no
  29. void TeamFortress_TeamSetColor()
  30. {
  31. // Blue Team
  32. teamcolors[1][PC_SCOUT].topColor = 153;
  33. teamcolors[1][PC_SCOUT].bottomColor = 139;
  34. teamcolors[1][PC_SNIPER].topColor = 153;
  35. teamcolors[1][PC_SNIPER].bottomColor = 145;
  36. teamcolors[1][PC_SOLDIER].topColor = 153;
  37. teamcolors[1][PC_SOLDIER].bottomColor = 130;
  38. teamcolors[1][PC_DEMOMAN].topColor = 153;
  39. teamcolors[1][PC_DEMOMAN].bottomColor = 145;
  40. teamcolors[1][PC_MEDIC].topColor = 153;
  41. teamcolors[1][PC_MEDIC].bottomColor = 140;
  42. teamcolors[1][PC_HWGUY].topColor = 148;
  43. teamcolors[1][PC_HWGUY].bottomColor = 138;
  44. teamcolors[1][PC_PYRO].topColor = 140;
  45. teamcolors[1][PC_PYRO].bottomColor = 145;
  46. teamcolors[1][PC_SPY].topColor = 150;
  47. teamcolors[1][PC_SPY].bottomColor = 145;
  48. teamcolors[1][PC_ENGINEER].topColor = 140;
  49. teamcolors[1][PC_ENGINEER].bottomColor = 148;
  50. teamcolors[1][PC_CIVILIAN].topColor = 150;
  51. teamcolors[1][PC_CIVILIAN].bottomColor = 140;
  52. #ifdef TFCTODO // sentry colors
  53. teamcolors[1][SENTRY_COLOR].topColor = 150;
  54. teamcolors[1][SENTRY_COLOR].bottomColor = 0;
  55. teamcolors[2][SENTRY_COLOR].topColor = 250;
  56. teamcolors[2][SENTRY_COLOR].bottomColor = 0;
  57. teamcolors[3][SENTRY_COLOR].topColor = 45;
  58. teamcolors[3][SENTRY_COLOR].bottomColor = 0;
  59. teamcolors[4][SENTRY_COLOR].topColor = 100;
  60. teamcolors[4][SENTRY_COLOR].bottomColor = 0;
  61. #endif
  62. // Red Team
  63. teamcolors[2][PC_SCOUT].topColor = 255;
  64. teamcolors[2][PC_SCOUT].bottomColor = 10;
  65. teamcolors[2][PC_SNIPER].topColor = 255;
  66. teamcolors[2][PC_SNIPER].bottomColor = 10;
  67. teamcolors[2][PC_SOLDIER].topColor = 250;
  68. teamcolors[2][PC_SOLDIER].bottomColor = 28;
  69. teamcolors[2][PC_DEMOMAN].topColor = 255;
  70. teamcolors[2][PC_DEMOMAN].bottomColor = 20;
  71. teamcolors[2][PC_MEDIC].topColor = 255;
  72. teamcolors[2][PC_MEDIC].bottomColor = 250;
  73. teamcolors[2][PC_HWGUY].topColor = 255;
  74. teamcolors[2][PC_HWGUY].bottomColor = 25;
  75. teamcolors[2][PC_PYRO].topColor = 250;
  76. teamcolors[2][PC_PYRO].bottomColor = 25;
  77. teamcolors[2][PC_SPY].topColor = 250;
  78. teamcolors[2][PC_SPY].bottomColor = 240;
  79. teamcolors[2][PC_ENGINEER].topColor = 5;
  80. teamcolors[2][PC_ENGINEER].bottomColor = 250;
  81. teamcolors[2][PC_CIVILIAN].topColor = 250;
  82. teamcolors[2][PC_CIVILIAN].bottomColor = 240;
  83. // Yellow Team
  84. teamcolors[3][PC_SCOUT].topColor = 45;
  85. teamcolors[3][PC_SCOUT].bottomColor = 35;
  86. teamcolors[3][PC_SNIPER].topColor = 45;
  87. teamcolors[3][PC_SNIPER].bottomColor = 35;
  88. teamcolors[3][PC_SOLDIER].topColor = 45;
  89. teamcolors[3][PC_SOLDIER].bottomColor = 35;
  90. teamcolors[3][PC_DEMOMAN].topColor = 45;
  91. teamcolors[3][PC_DEMOMAN].bottomColor = 35;
  92. teamcolors[3][PC_MEDIC].topColor = 45;
  93. teamcolors[3][PC_MEDIC].bottomColor = 35;
  94. teamcolors[3][PC_HWGUY].topColor = 45;
  95. teamcolors[3][PC_HWGUY].bottomColor = 40;
  96. teamcolors[3][PC_PYRO].topColor = 45;
  97. teamcolors[3][PC_PYRO].bottomColor = 35;
  98. teamcolors[3][PC_SPY].topColor = 45;
  99. teamcolors[3][PC_SPY].bottomColor = 35;
  100. teamcolors[3][PC_ENGINEER].topColor = 45;
  101. teamcolors[3][PC_ENGINEER].bottomColor = 45;
  102. teamcolors[3][PC_CIVILIAN].topColor = 45;
  103. teamcolors[3][PC_CIVILIAN].bottomColor = 35;
  104. // Green Team
  105. teamcolors[4][PC_SCOUT].topColor = 100;
  106. teamcolors[4][PC_SCOUT].bottomColor = 90;
  107. teamcolors[4][PC_SNIPER].topColor = 80;
  108. teamcolors[4][PC_SNIPER].bottomColor = 90;
  109. teamcolors[4][PC_SOLDIER].topColor = 100;
  110. teamcolors[4][PC_SOLDIER].bottomColor = 40;
  111. teamcolors[4][PC_DEMOMAN].topColor = 100;
  112. teamcolors[4][PC_DEMOMAN].bottomColor = 90;
  113. teamcolors[4][PC_MEDIC].topColor = 100;
  114. teamcolors[4][PC_MEDIC].bottomColor = 90;
  115. teamcolors[4][PC_HWGUY].topColor = 100;
  116. teamcolors[4][PC_HWGUY].bottomColor = 90;
  117. teamcolors[4][PC_PYRO].topColor = 100;
  118. teamcolors[4][PC_PYRO].bottomColor = 50;
  119. teamcolors[4][PC_SPY].topColor = 100;
  120. teamcolors[4][PC_SPY].bottomColor = 90;
  121. teamcolors[4][PC_ENGINEER].topColor = 100;
  122. teamcolors[4][PC_ENGINEER].bottomColor = 90;
  123. teamcolors[4][PC_CIVILIAN].topColor = 100;
  124. teamcolors[4][PC_CIVILIAN].bottomColor = 90;
  125. rgbcolors[0] = Vector( 255, 255, 255 ); // White for non-owned
  126. rgbcolors[1] = Vector( 0, 0, 255 );
  127. rgbcolors[2] = Vector( 255, 0, 0 );
  128. rgbcolors[3] = Vector( 255, 255, 30 );
  129. rgbcolors[4] = Vector( 0, 255, 0 );
  130. }
  131. class CColorInitializer
  132. {
  133. public:
  134. CColorInitializer()
  135. {
  136. TeamFortress_TeamSetColor();
  137. }
  138. } g_ColorInitializer;
  139. //-----------------------------------------------------------------------------
  140. // Purpose: Get a pointer to the specified TF team manager
  141. //-----------------------------------------------------------------------------
  142. CTFCTeam *GetGlobalTFCTeam( int iIndex )
  143. {
  144. return (CTFCTeam*)GetGlobalTeam( iIndex );
  145. }
  146. // Display all the Team Scores
  147. void TeamFortress_TeamShowScores(BOOL bLong, CBasePlayer *pPlayer)
  148. {
  149. for (int i = 1; i < g_Teams.Count(); i++)
  150. {
  151. if (!bLong)
  152. {
  153. // Dump short scores
  154. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs("%s: %d\n", g_szTeamColors[i], GetGlobalTeam(i)->GetScore()) );
  155. }
  156. else
  157. {
  158. // Dump long scores
  159. if (pPlayer == NULL)
  160. UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs("Team %d (%s): %d\n", i, g_szTeamColors[i], GetGlobalTeam(i)->GetScore()) );
  161. else // Print to just one client
  162. ClientPrint( pPlayer, HUD_PRINTNOTIFY, UTIL_VarArgs("Team %d (%s): %d\n", i, g_szTeamColors[i], GetGlobalTeam(i)->GetScore()) );
  163. }
  164. }
  165. }
  166. //=========================================================================
  167. // Return the score/frags of a team, depending on whether TeamFrags is on
  168. int TeamFortress_TeamGetScoreFrags(int tno)
  169. {
  170. CTeam *pTeam = GetGlobalTeam( tno );
  171. if ( pTeam )
  172. {
  173. return pTeam->GetScore();
  174. }
  175. else
  176. {
  177. Assert( false );
  178. return -1;
  179. }
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose: Needed because this is an entity, but should never be used
  183. //-----------------------------------------------------------------------------
  184. void CTFCTeam::Init( const char *pName, int iNumber )
  185. {
  186. BaseClass::Init( pName, iNumber );
  187. // Only detect changes every half-second.
  188. NetworkProp()->SetUpdateInterval( 0.75f );
  189. }
  190. color32 CTFCTeam::GetTeamColor()
  191. {
  192. int i = GetTeamNumber();
  193. if ( i >= 0 && i < ARRAYSIZE( rgbcolors ) )
  194. {
  195. return Vector255ToRGBColor( rgbcolors[i] );
  196. }
  197. else
  198. {
  199. Assert( false );
  200. color32 x;
  201. memset( &x, 0, sizeof( x ) );
  202. return x;
  203. }
  204. }
  205. color32 Vector255ToRGBColor( const Vector &vColor )
  206. {
  207. color32 ret;
  208. ret.a = 0;
  209. ret.r = (byte)vColor.x;
  210. ret.g = (byte)vColor.y;
  211. ret.b = (byte)vColor.z;
  212. return ret;
  213. }