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.

136 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "sdk_playerclass_info_parse.h"
  8. #include "weapon_sdkbase.h"
  9. #include <KeyValues.h>
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //Tony; due to the nature of the base code.. I must do this !
  13. FilePlayerClassInfo_t* CreatePlayerClassInfo()
  14. {
  15. #if defined ( SDK_USE_PLAYERCLASSES )
  16. return new CSDKPlayerClassInfo;
  17. #else
  18. return new FilePlayerClassInfo_t;
  19. #endif
  20. }
  21. #if defined ( SDK_USE_PLAYERCLASSES )
  22. CSDKPlayerClassInfo::CSDKPlayerClassInfo()
  23. {
  24. m_iTeam= TEAM_UNASSIGNED;
  25. m_iPrimaryWeapon= WEAPON_NONE;
  26. m_iSecondaryWeapon= WEAPON_NONE;
  27. m_iMeleeWeapon= WEAPON_NONE;
  28. m_iNumGrensType1 = 0;
  29. m_iGrenType1 = WEAPON_NONE;
  30. m_iNumGrensType2 = 0;
  31. m_iGrenType2 = WEAPON_NONE;
  32. m_szLimitCvar[0] = '\0';
  33. m_flRunSpeed = SDK_DEFAULT_PLAYER_RUNSPEED;
  34. m_flSprintSpeed = SDK_DEFAULT_PLAYER_RUNSPEED;
  35. m_flProneSpeed = SDK_DEFAULT_PLAYER_RUNSPEED;
  36. m_iArmor = 0;
  37. }
  38. void CSDKPlayerClassInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName )
  39. {
  40. BaseClass::Parse( pKeyValuesData, szWeaponName );
  41. m_iTeam= pKeyValuesData->GetInt( "team", TEAM_UNASSIGNED );
  42. // Figure out what team can have this player class
  43. m_iTeam = TEAM_UNASSIGNED;
  44. //Tony; don't check for teams unless we're using teams. You could do a free for all, but class / character based game if you wanted.
  45. #ifdef SDK_USE_TEAMS
  46. const char *pTeam = pKeyValuesData->GetString( "team", NULL );
  47. if ( pTeam )
  48. {
  49. if ( Q_stricmp( pTeam, "BLUE" ) == 0 )
  50. {
  51. m_iTeam = SDK_TEAM_BLUE;
  52. }
  53. else if ( Q_stricmp( pTeam, "RED" ) == 0 )
  54. {
  55. m_iTeam = SDK_TEAM_RED;
  56. }
  57. else
  58. {
  59. Assert( false );
  60. }
  61. }
  62. else
  63. {
  64. Assert( false );
  65. }
  66. #endif
  67. const char *pszPrimaryWeapon = pKeyValuesData->GetString( "primaryweapon", NULL );
  68. m_iPrimaryWeapon = AliasToWeaponID( pszPrimaryWeapon );
  69. Assert( m_iPrimaryWeapon != WEAPON_NONE ); // require player to have a primary weapon
  70. const char *pszSecondaryWeapon = pKeyValuesData->GetString( "secondaryweapon", NULL );
  71. if ( pszSecondaryWeapon )
  72. {
  73. m_iSecondaryWeapon = AliasToWeaponID( pszSecondaryWeapon );
  74. // Assert( m_iSecondaryWeapon != WEAPON_NONE );
  75. }
  76. else
  77. m_iSecondaryWeapon = WEAPON_NONE;
  78. const char *pszMeleeWeapon = pKeyValuesData->GetString( "meleeweapon", NULL );
  79. if ( pszMeleeWeapon )
  80. {
  81. m_iMeleeWeapon = AliasToWeaponID( pszMeleeWeapon );
  82. // Assert( m_iMeleeWeapon != WEAPON_NONE );
  83. }
  84. else
  85. m_iMeleeWeapon = WEAPON_NONE;
  86. m_iNumGrensType1 = pKeyValuesData->GetInt( "numgrens", 0 );
  87. if ( m_iNumGrensType1 > 0 )
  88. {
  89. const char *pszGrenType1 = pKeyValuesData->GetString( "grenadetype", NULL );
  90. m_iGrenType1 = AliasToWeaponID( pszGrenType1 );
  91. // Assert( m_iGrenType1 != WEAPON_NONE );
  92. }
  93. m_iNumGrensType2 = pKeyValuesData->GetInt( "numgrens2", 0 );
  94. if ( m_iNumGrensType2 > 0 )
  95. {
  96. const char *pszGrenType2 = pKeyValuesData->GetString( "grenadetype2", NULL );
  97. m_iGrenType2 = AliasToWeaponID( pszGrenType2 );
  98. // Assert( m_iGrenType2 != WEAPON_NONE );
  99. }
  100. Q_strncpy( m_szLimitCvar, pKeyValuesData->GetString( "limitcvar", "!! Missing limit cvar on Player Class" ), sizeof(m_szLimitCvar) );
  101. Assert( Q_strlen( m_szLimitCvar ) > 0 && "Every class must specify a limitcvar" );
  102. // HUD player status health images (when the player is hurt)
  103. Q_strncpy( m_szClassImage, pKeyValuesData->GetString( "classimage", "white" ), sizeof( m_szClassImage ) );
  104. Q_strncpy( m_szClassImageBG, pKeyValuesData->GetString( "classimagebg", "white" ), sizeof( m_szClassImageBG ) );
  105. m_flRunSpeed = pKeyValuesData->GetFloat( "RunSpeed", SDK_DEFAULT_PLAYER_RUNSPEED );
  106. m_flSprintSpeed = pKeyValuesData->GetFloat( "SprintSpeed", SDK_DEFAULT_PLAYER_RUNSPEED );
  107. m_flProneSpeed = pKeyValuesData->GetFloat( "ProneSpeed", SDK_DEFAULT_PLAYER_RUNSPEED );
  108. m_iArmor = pKeyValuesData->GetInt( "armor", 0 );
  109. }
  110. #endif // SDK_USE_PLAYERCLASSES