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.

359 lines
13 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entity that propagates general data needed by clients for every player.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_objective_resource.h"
  9. #include "shareddefs.h"
  10. #include "player_vs_environment/tf_population_manager.h"
  11. #include <coordsize.h>
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. void SendProxy_String_tToString( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
  15. // Datatable
  16. IMPLEMENT_SERVERCLASS_ST( CTFObjectiveResource, DT_TFObjectiveResource )
  17. SendPropInt( SENDINFO(m_nMannVsMachineMaxWaveCount), 9, SPROP_UNSIGNED ),
  18. SendPropInt( SENDINFO(m_nMannVsMachineWaveCount), 9, SPROP_UNSIGNED ),
  19. SendPropInt( SENDINFO(m_nMannVsMachineWaveEnemyCount), 16, SPROP_UNSIGNED ),
  20. SendPropInt( SENDINFO(m_nMvMWorldMoney), 16, SPROP_UNSIGNED ),
  21. SendPropFloat( SENDINFO( m_flMannVsMachineNextWaveTime ) ),
  22. SendPropBool( SENDINFO( m_bMannVsMachineBetweenWaves ) ),
  23. SendPropInt( SENDINFO(m_nFlagCarrierUpgradeLevel), 4, SPROP_UNSIGNED ),
  24. SendPropFloat( SENDINFO( m_flMvMBaseBombUpgradeTime ) ),
  25. SendPropFloat( SENDINFO( m_flMvMNextBombUpgradeTime ) ),
  26. SendPropStringT ( SENDINFO( m_iszMvMPopfileName ) ),
  27. SendPropInt( SENDINFO(m_iChallengeIndex), 16 ),
  28. SendPropInt( SENDINFO(m_nMvMEventPopfileType), 4, SPROP_UNSIGNED ),
  29. SendPropArray3( SENDINFO_ARRAY3( m_nMannVsMachineWaveClassCounts ), SendPropInt( SENDINFO_ARRAY( m_nMannVsMachineWaveClassCounts ), 16 ) ),
  30. SendPropArray( SendPropString( SENDINFO_ARRAY( m_iszMannVsMachineWaveClassNames ), 0, SendProxy_String_tToString ), m_iszMannVsMachineWaveClassNames ),
  31. SendPropArray3( SENDINFO_ARRAY3( m_nMannVsMachineWaveClassFlags ), SendPropInt( SENDINFO_ARRAY( m_nMannVsMachineWaveClassFlags ), 10, SPROP_UNSIGNED ) ),
  32. SendPropArray3( SENDINFO_ARRAY3( m_nMannVsMachineWaveClassCounts2 ), SendPropInt( SENDINFO_ARRAY( m_nMannVsMachineWaveClassCounts2 ), 16 ) ),
  33. SendPropArray( SendPropString( SENDINFO_ARRAY( m_iszMannVsMachineWaveClassNames2 ), 0, SendProxy_String_tToString ), m_iszMannVsMachineWaveClassNames2 ),
  34. SendPropArray3( SENDINFO_ARRAY3( m_nMannVsMachineWaveClassFlags2 ), SendPropInt( SENDINFO_ARRAY( m_nMannVsMachineWaveClassFlags2 ), 10, SPROP_UNSIGNED ) ),
  35. SendPropArray3( SENDINFO_ARRAY3( m_bMannVsMachineWaveClassActive ), SendPropBool( SENDINFO_ARRAY( m_bMannVsMachineWaveClassActive ) ) ),
  36. SendPropArray3( SENDINFO_ARRAY3( m_bMannVsMachineWaveClassActive2 ), SendPropBool( SENDINFO_ARRAY( m_bMannVsMachineWaveClassActive2 ) ) ),
  37. END_SEND_TABLE()
  38. BEGIN_DATADESC( CTFObjectiveResource )
  39. DEFINE_FIELD( m_nMannVsMachineMaxWaveCount, FIELD_INTEGER ),
  40. DEFINE_FIELD( m_nMannVsMachineWaveCount, FIELD_INTEGER ),
  41. DEFINE_FIELD( m_nMannVsMachineWaveEnemyCount, FIELD_INTEGER ),
  42. DEFINE_FIELD( m_nMvMWorldMoney, FIELD_INTEGER ),
  43. DEFINE_FIELD( m_flMannVsMachineNextWaveTime, FIELD_TIME ),
  44. DEFINE_FIELD( m_bMannVsMachineBetweenWaves, FIELD_BOOLEAN ),
  45. DEFINE_AUTO_ARRAY( m_nMannVsMachineWaveClassCounts, FIELD_INTEGER ),
  46. DEFINE_AUTO_ARRAY( m_iszMannVsMachineWaveClassNames, FIELD_STRING ),
  47. DEFINE_AUTO_ARRAY( m_nMannVsMachineWaveClassFlags, FIELD_INTEGER ),
  48. DEFINE_AUTO_ARRAY( m_nMannVsMachineWaveClassCounts2, FIELD_INTEGER ),
  49. DEFINE_AUTO_ARRAY( m_iszMannVsMachineWaveClassNames2, FIELD_STRING ),
  50. DEFINE_AUTO_ARRAY( m_nMannVsMachineWaveClassFlags2, FIELD_INTEGER ),
  51. DEFINE_AUTO_ARRAY( m_bMannVsMachineWaveClassActive, FIELD_BOOLEAN ),
  52. DEFINE_AUTO_ARRAY( m_bMannVsMachineWaveClassActive2, FIELD_BOOLEAN ),
  53. END_DATADESC()
  54. LINK_ENTITY_TO_CLASS( tf_objective_resource, CTFObjectiveResource );
  55. //-----------------------------------------------------------------------------
  56. // Purpose:
  57. //-----------------------------------------------------------------------------
  58. CTFObjectiveResource::CTFObjectiveResource()
  59. {
  60. m_nMannVsMachineMaxWaveCount = 0;
  61. m_nMannVsMachineWaveCount = 0;
  62. m_nMannVsMachineWaveEnemyCount = 0;
  63. m_nMvMWorldMoney = 0;
  64. m_flMannVsMachineNextWaveTime = 0;
  65. m_bMannVsMachineBetweenWaves = false;
  66. m_nFlagCarrierUpgradeLevel = 0;
  67. m_flMvMBaseBombUpgradeTime = 0;
  68. m_flMvMNextBombUpgradeTime = 0;
  69. m_iChallengeIndex = -1;
  70. SetMvMPopfileName( MAKE_STRING( "" ) );
  71. m_nMvMEventPopfileType.Set( MVM_EVENT_POPFILE_NONE );
  72. int i = 0;
  73. for ( i = 0 ; i < m_nMannVsMachineWaveClassCounts.Count() ; ++i )
  74. {
  75. m_nMannVsMachineWaveClassCounts.GetForModify( i ) = 0;
  76. }
  77. for ( i = 0 ; i < m_nMannVsMachineWaveClassCounts2.Count() ; ++i )
  78. {
  79. m_nMannVsMachineWaveClassCounts2.GetForModify( i ) = 0;
  80. }
  81. for ( i = 0 ; i < m_nMannVsMachineWaveClassFlags.Count() ; ++i )
  82. {
  83. m_nMannVsMachineWaveClassFlags.GetForModify( i ) = MVM_CLASS_FLAG_NONE;
  84. }
  85. for ( i = 0 ; i < m_nMannVsMachineWaveClassFlags2.Count() ; ++i )
  86. {
  87. m_nMannVsMachineWaveClassFlags2.GetForModify( i ) = MVM_CLASS_FLAG_NONE;
  88. }
  89. for ( i = 0 ; i < m_iszMannVsMachineWaveClassNames.Count() ; ++i )
  90. {
  91. m_iszMannVsMachineWaveClassNames.GetForModify( i ) = NULL_STRING;
  92. }
  93. for ( i = 0 ; i < m_iszMannVsMachineWaveClassNames2.Count() ; ++i )
  94. {
  95. m_iszMannVsMachineWaveClassNames2.GetForModify( i ) = NULL_STRING;
  96. }
  97. for ( i = 0 ; i < m_bMannVsMachineWaveClassActive.Count() ; ++i )
  98. {
  99. m_bMannVsMachineWaveClassActive.GetForModify( i ) = false;
  100. }
  101. for ( i = 0 ; i < m_bMannVsMachineWaveClassActive2.Count() ; ++i )
  102. {
  103. m_bMannVsMachineWaveClassActive2.GetForModify( i ) = false;
  104. }
  105. m_teleporterString = AllocPooledString( "teleporter" );
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. //-----------------------------------------------------------------------------
  110. CTFObjectiveResource::~CTFObjectiveResource()
  111. {
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose:
  115. //-----------------------------------------------------------------------------
  116. void CTFObjectiveResource::Spawn( void )
  117. {
  118. BaseClass::Spawn();
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. //-----------------------------------------------------------------------------
  123. void CTFObjectiveResource::ClearMannVsMachineWaveClassFlags( void )
  124. {
  125. int i = 0;
  126. for ( i = 0 ; i < m_nMannVsMachineWaveClassFlags.Count() ; ++i )
  127. {
  128. m_nMannVsMachineWaveClassFlags.GetForModify( i ) = MVM_CLASS_FLAG_NONE;
  129. }
  130. for ( i = 0 ; i < m_nMannVsMachineWaveClassFlags2.Count() ; ++i )
  131. {
  132. m_nMannVsMachineWaveClassFlags2.GetForModify( i ) = MVM_CLASS_FLAG_NONE;
  133. }
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose:
  137. //-----------------------------------------------------------------------------
  138. void CTFObjectiveResource::AddMannVsMachineWaveClassFlags( int nIndex, unsigned int iFlags )
  139. {
  140. if ( nIndex < m_nMannVsMachineWaveClassFlags.Count() )
  141. {
  142. m_nMannVsMachineWaveClassFlags.GetForModify( nIndex ) |= iFlags;
  143. return;
  144. }
  145. nIndex -= m_nMannVsMachineWaveClassFlags.Count();
  146. if ( nIndex < m_nMannVsMachineWaveClassFlags2.Count() )
  147. {
  148. m_nMannVsMachineWaveClassFlags2.GetForModify( nIndex ) |= iFlags;
  149. }
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose:
  153. //-----------------------------------------------------------------------------
  154. int CTFObjectiveResource::GetMannVsMachineWaveClassCount( int nIndex )
  155. {
  156. if ( nIndex < m_nMannVsMachineWaveClassCounts.Count() )
  157. {
  158. return m_nMannVsMachineWaveClassCounts[ nIndex ];
  159. }
  160. nIndex -= m_nMannVsMachineWaveClassCounts.Count();
  161. if ( nIndex < m_nMannVsMachineWaveClassCounts2.Count() )
  162. {
  163. return m_nMannVsMachineWaveClassCounts2[ nIndex ];
  164. }
  165. return 0;
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose:
  169. //-----------------------------------------------------------------------------
  170. void CTFObjectiveResource::SetMannVsMachineWaveClassActive( string_t iszClassIconName, bool bActive /*= true*/ )
  171. {
  172. for ( int i = 0 ; i < m_iszMannVsMachineWaveClassNames.Count() ; ++i )
  173. {
  174. if ( ( m_iszMannVsMachineWaveClassNames[ i ] == iszClassIconName ) )
  175. {
  176. m_bMannVsMachineWaveClassActive.GetForModify( i ) = bActive;
  177. return;
  178. }
  179. }
  180. for ( int i = 0 ; i < m_iszMannVsMachineWaveClassNames2.Count() ; ++i )
  181. {
  182. if ( ( m_iszMannVsMachineWaveClassNames2[ i ] == iszClassIconName ) )
  183. {
  184. m_bMannVsMachineWaveClassActive2.GetForModify( i ) = bActive;
  185. return;
  186. }
  187. }
  188. }
  189. //-----------------------------------------------------------------------------
  190. // Purpose:
  191. //-----------------------------------------------------------------------------
  192. void CTFObjectiveResource::SetMannVsMachineWaveClassCount( int nIndex, int nCount )
  193. {
  194. if ( nIndex < m_nMannVsMachineWaveClassCounts.Count() )
  195. {
  196. m_nMannVsMachineWaveClassCounts.GetForModify( nIndex ) = nCount;
  197. return;
  198. }
  199. nIndex -= m_nMannVsMachineWaveClassCounts.Count();
  200. if ( nIndex < m_nMannVsMachineWaveClassCounts2.Count() )
  201. {
  202. m_nMannVsMachineWaveClassCounts2.GetForModify( nIndex ) = nCount;
  203. }
  204. }
  205. //-----------------------------------------------------------------------------
  206. // Purpose:
  207. //-----------------------------------------------------------------------------
  208. void CTFObjectiveResource::SetMannVsMachineWaveClassName( int nIndex, string_t iszClassIconName )
  209. {
  210. if ( nIndex < m_iszMannVsMachineWaveClassNames.Count() )
  211. {
  212. m_iszMannVsMachineWaveClassNames.GetForModify( nIndex ) = iszClassIconName;
  213. return;
  214. }
  215. nIndex -= m_iszMannVsMachineWaveClassNames.Count();
  216. if ( nIndex < m_iszMannVsMachineWaveClassNames2.Count() )
  217. {
  218. m_iszMannVsMachineWaveClassNames2.GetForModify( nIndex ) = iszClassIconName;
  219. }
  220. }
  221. //-----------------------------------------------------------------------------
  222. // Purpose:
  223. //-----------------------------------------------------------------------------
  224. void CTFObjectiveResource::IncrementMannVsMachineWaveClassCount( string_t iszClassIconName, unsigned int iFlags )
  225. {
  226. int i = 0;
  227. for ( i = 0 ; i < m_iszMannVsMachineWaveClassNames.Count() ; ++i )
  228. {
  229. if ( ( m_iszMannVsMachineWaveClassNames[ i ] == iszClassIconName ) && ( m_nMannVsMachineWaveClassFlags[ i ] & iFlags ) )
  230. {
  231. m_nMannVsMachineWaveClassCounts.GetForModify( i ) += 1;
  232. if ( m_nMannVsMachineWaveClassCounts[ i ] <= 0 )
  233. {
  234. m_nMannVsMachineWaveClassCounts.GetForModify( i ) = 1;
  235. }
  236. return;
  237. }
  238. }
  239. for ( i = 0 ; i < m_iszMannVsMachineWaveClassNames2.Count() ; ++i )
  240. {
  241. if ( ( m_iszMannVsMachineWaveClassNames2[ i ] == iszClassIconName ) && ( m_nMannVsMachineWaveClassFlags2[ i ] & iFlags ) )
  242. {
  243. m_nMannVsMachineWaveClassCounts2.GetForModify( i ) += 1;
  244. if ( m_nMannVsMachineWaveClassCounts2[ i ] <= 0 )
  245. {
  246. m_nMannVsMachineWaveClassCounts2.GetForModify( i ) = 1;
  247. }
  248. return;
  249. }
  250. }
  251. }
  252. //-----------------------------------------------------------------------------
  253. // Purpose:
  254. //-----------------------------------------------------------------------------
  255. void CTFObjectiveResource::DecrementMannVsMachineWaveClassCount( string_t iszClassIconName, unsigned int iFlags )
  256. {
  257. int i = 0;
  258. for ( i = 0 ; i < m_iszMannVsMachineWaveClassNames.Count() && i < m_nMannVsMachineWaveClassFlags.Count() && i < m_nMannVsMachineWaveClassCounts.Count() ; ++i )
  259. {
  260. if ( ( m_iszMannVsMachineWaveClassNames[ i ] == iszClassIconName ) && ( m_nMannVsMachineWaveClassFlags[ i ] & iFlags ) )
  261. {
  262. m_nMannVsMachineWaveClassCounts.GetForModify( i ) -= 1;
  263. if ( m_nMannVsMachineWaveClassCounts[ i ] < 0 )
  264. {
  265. m_nMannVsMachineWaveClassCounts.GetForModify( i ) = 0;
  266. }
  267. if ( !m_nMannVsMachineWaveClassCounts[ i ] )
  268. {
  269. SetMannVsMachineWaveClassActive( iszClassIconName, false );
  270. }
  271. return;
  272. }
  273. }
  274. for ( i = 0 ; i < m_iszMannVsMachineWaveClassNames2.Count() && i < m_nMannVsMachineWaveClassFlags2.Count() && i < m_nMannVsMachineWaveClassCounts2.Count() ; ++i )
  275. {
  276. if ( ( m_iszMannVsMachineWaveClassNames2[ i ] == iszClassIconName ) && ( m_nMannVsMachineWaveClassFlags2[ i ] & iFlags ) )
  277. {
  278. m_nMannVsMachineWaveClassCounts2.GetForModify( i ) -= 1;
  279. if ( m_nMannVsMachineWaveClassCounts2[ i ] < 0 )
  280. {
  281. m_nMannVsMachineWaveClassCounts2.GetForModify( i ) = 0;
  282. }
  283. if ( !m_nMannVsMachineWaveClassCounts2[ i ] )
  284. {
  285. SetMannVsMachineWaveClassActive( iszClassIconName, false );
  286. }
  287. return;
  288. }
  289. }
  290. }
  291. //-----------------------------------------------------------------------------
  292. // Purpose:
  293. //-----------------------------------------------------------------------------
  294. void CTFObjectiveResource::IncrementTeleporterCount()
  295. {
  296. IncrementMannVsMachineWaveClassCount( m_teleporterString, MVM_CLASS_FLAG_MISSION );
  297. }
  298. //-----------------------------------------------------------------------------
  299. // Purpose:
  300. //-----------------------------------------------------------------------------
  301. void CTFObjectiveResource::DecrementTeleporterCount()
  302. {
  303. DecrementMannVsMachineWaveClassCount( m_teleporterString, MVM_CLASS_FLAG_MISSION );
  304. }