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.

162 lines
4.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "dod_playerclass_info_parse.h"
  8. #include "dod_shareddefs.h"
  9. #include "weapon_dodbase.h"
  10. #include <KeyValues.h>
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. FilePlayerClassInfo_t* CreatePlayerClassInfo()
  14. {
  15. return new CDODPlayerClassInfo;
  16. }
  17. CDODPlayerClassInfo::CDODPlayerClassInfo()
  18. {
  19. m_iTeam= TEAM_UNASSIGNED;
  20. m_iPrimaryWeapon= WEAPON_NONE;
  21. m_iSecondaryWeapon= WEAPON_NONE;
  22. m_iMeleeWeapon= WEAPON_NONE;
  23. m_iNumGrensType1 = 0;
  24. m_iGrenType1 = WEAPON_NONE;
  25. m_iNumGrensType2 = 0;
  26. m_iGrenType2 = WEAPON_NONE;
  27. m_iNumBandages = 0;
  28. m_iHelmetGroup= HELMET_GROUP_0;
  29. m_iHairGroup= HELMET_GROUP_0;
  30. m_iDropHelmet = HELMET_ALLIES;
  31. m_szLimitCvar[0] = '\0';
  32. m_bClassLimitMGMerge = false;
  33. }
  34. int AliasToWeaponID( const char *alias )
  35. {
  36. if (alias)
  37. {
  38. for( int i=0; s_WeaponAliasInfo[i] != NULL; ++i )
  39. if (!Q_stricmp( s_WeaponAliasInfo[i], alias ))
  40. return i;
  41. }
  42. return WEAPON_NONE;
  43. }
  44. void CDODPlayerClassInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName )
  45. {
  46. BaseClass::Parse( pKeyValuesData, szWeaponName );
  47. m_iTeam= pKeyValuesData->GetInt( "team", TEAM_UNASSIGNED );
  48. // Figure out what team can have this player class
  49. m_iTeam = TEAM_UNASSIGNED;
  50. const char *pTeam = pKeyValuesData->GetString( "team", NULL );
  51. if ( pTeam )
  52. {
  53. if ( Q_stricmp( pTeam, "ALLIES" ) == 0 )
  54. {
  55. m_iTeam = TEAM_ALLIES;
  56. }
  57. else if ( Q_stricmp( pTeam, "AXIS" ) == 0 )
  58. {
  59. m_iTeam = TEAM_AXIS;
  60. }
  61. else
  62. {
  63. Assert( false );
  64. }
  65. }
  66. else
  67. {
  68. Assert( false );
  69. }
  70. const char *pszPrimaryWeapon = pKeyValuesData->GetString( "primaryweapon", NULL );
  71. m_iPrimaryWeapon = AliasToWeaponID( pszPrimaryWeapon );
  72. Assert( m_iPrimaryWeapon != WEAPON_NONE ); // require player to have a primary weapon
  73. const char *pszSecondaryWeapon = pKeyValuesData->GetString( "secondaryweapon", NULL );
  74. if ( pszSecondaryWeapon )
  75. {
  76. m_iSecondaryWeapon = AliasToWeaponID( pszSecondaryWeapon );
  77. Assert( m_iSecondaryWeapon != WEAPON_NONE );
  78. }
  79. else
  80. m_iSecondaryWeapon = WEAPON_NONE;
  81. const char *pszMeleeWeapon = pKeyValuesData->GetString( "meleeweapon", NULL );
  82. if ( pszMeleeWeapon )
  83. {
  84. m_iMeleeWeapon = AliasToWeaponID( pszMeleeWeapon );
  85. Assert( m_iMeleeWeapon != WEAPON_NONE );
  86. }
  87. else
  88. m_iMeleeWeapon = WEAPON_NONE;
  89. m_iNumGrensType1 = pKeyValuesData->GetInt( "numgrens", 0 );
  90. if ( m_iNumGrensType1 > 0 )
  91. {
  92. const char *pszGrenType1 = pKeyValuesData->GetString( "grenadetype", NULL );
  93. m_iGrenType1 = AliasToWeaponID( pszGrenType1 );
  94. Assert( m_iGrenType1 != WEAPON_NONE );
  95. }
  96. m_iNumGrensType2 = pKeyValuesData->GetInt( "numgrens2", 0 );
  97. if ( m_iNumGrensType2 > 0 )
  98. {
  99. const char *pszGrenType2 = pKeyValuesData->GetString( "grenadetype2", NULL );
  100. m_iGrenType2 = AliasToWeaponID( pszGrenType2 );
  101. Assert( m_iGrenType2 != WEAPON_NONE );
  102. }
  103. m_iNumBandages = pKeyValuesData->GetInt( "numbandages", 0 );
  104. m_iHelmetGroup = pKeyValuesData->GetInt( "helmetgroup", 0 );
  105. m_iHairGroup = pKeyValuesData->GetInt( "hairgroup", 0 );
  106. // Which helmet model to generate
  107. const char *pszHelmetModel = pKeyValuesData->GetString( "drophelmet", "HELMET_ALLIES" );
  108. if( pszHelmetModel )
  109. {
  110. if ( Q_stricmp( pszHelmetModel, "HELMET_ALLIES" ) == 0 )
  111. {
  112. m_iDropHelmet = HELMET_ALLIES;
  113. }
  114. else if ( Q_stricmp( pszHelmetModel, "HELMET_AXIS" ) == 0 )
  115. {
  116. m_iDropHelmet = HELMET_AXIS;
  117. }
  118. else
  119. {
  120. Assert( false );
  121. }
  122. }
  123. else
  124. {
  125. Assert( false );
  126. }
  127. Q_strncpy( m_szLimitCvar, pKeyValuesData->GetString( "limitcvar", "!! Missing limit cvar on Player Class" ), sizeof(m_szLimitCvar) );
  128. Assert( Q_strlen( m_szLimitCvar ) > 0 && "Every class must specify a limitcvar" );
  129. m_bClassLimitMGMerge = ( pKeyValuesData->GetInt( "mergemgclass" ) > 0 );
  130. // HUD player status health images (when the player is hurt)
  131. Q_strncpy( m_szClassHealthImage, pKeyValuesData->GetString( "healthimage", "white" ), sizeof( m_szClassHealthImage ) );
  132. Q_strncpy( m_szClassHealthImageBG, pKeyValuesData->GetString( "healthimagebg", "white" ), sizeof( m_szClassHealthImageBG ) );
  133. }