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.

500 lines
17 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "singleplay_gamerules.h"
  8. #ifdef CLIENT_DLL
  9. #else
  10. #include "player.h"
  11. #include "basecombatweapon.h"
  12. #include "gamerules.h"
  13. #include "game.h"
  14. #include "items.h"
  15. #endif
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. //=========================================================
  19. //=========================================================
  20. bool CSingleplayRules::IsMultiplayer( void )
  21. {
  22. return false;
  23. }
  24. // Needed during the conversion, but once DMG_* types have been fixed, this isn't used anymore.
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. int CSingleplayRules::Damage_GetTimeBased( void )
  29. {
  30. int iDamage = ( DMG_PARALYZE | DMG_NERVEGAS | DMG_POISON | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN );
  31. return iDamage;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. int CSingleplayRules::Damage_GetShouldGibCorpse( void )
  37. {
  38. int iDamage = ( DMG_CRUSH | DMG_FALL | DMG_BLAST | DMG_SONIC | DMG_CLUB );
  39. return iDamage;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. int CSingleplayRules::Damage_GetShowOnHud( void )
  45. {
  46. int iDamage = ( DMG_POISON | DMG_ACID | DMG_DROWN | DMG_BURN | DMG_SLOWBURN | DMG_NERVEGAS | DMG_RADIATION | DMG_SHOCK );
  47. return iDamage;
  48. }
  49. //-----------------------------------------------------------------------------
  50. // Purpose:
  51. //-----------------------------------------------------------------------------
  52. int CSingleplayRules::Damage_GetNoPhysicsForce( void )
  53. {
  54. int iTimeBasedDamage = Damage_GetTimeBased();
  55. int iDamage = ( DMG_FALL | DMG_BURN | DMG_PLASMA | DMG_DROWN | iTimeBasedDamage | DMG_CRUSH | DMG_PHYSGUN | DMG_PREVENT_PHYSICS_FORCE );
  56. return iDamage;
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. int CSingleplayRules::Damage_GetShouldNotBleed( void )
  62. {
  63. int iDamage = ( DMG_POISON | DMG_ACID );
  64. return iDamage;
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. // Input : iDmgType -
  69. // Output : Returns true on success, false on failure.
  70. //-----------------------------------------------------------------------------
  71. bool CSingleplayRules::Damage_IsTimeBased( int iDmgType )
  72. {
  73. // Damage types that are time-based.
  74. return ( ( iDmgType & ( DMG_PARALYZE | DMG_NERVEGAS | DMG_POISON | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN ) ) != 0 );
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. // Input : iDmgType -
  79. // Output : Returns true on success, false on failure.
  80. //-----------------------------------------------------------------------------
  81. bool CSingleplayRules::Damage_ShouldGibCorpse( int iDmgType )
  82. {
  83. // Damage types that gib the corpse.
  84. return ( ( iDmgType & ( DMG_CRUSH | DMG_FALL | DMG_BLAST | DMG_SONIC | DMG_CLUB ) ) != 0 );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose:
  88. // Input : iDmgType -
  89. // Output : Returns true on success, false on failure.
  90. //-----------------------------------------------------------------------------
  91. bool CSingleplayRules::Damage_ShowOnHUD( int iDmgType )
  92. {
  93. // Damage types that have client HUD art.
  94. return ( ( iDmgType & ( DMG_POISON | DMG_ACID | DMG_DROWN | DMG_BURN | DMG_SLOWBURN | DMG_NERVEGAS | DMG_RADIATION | DMG_SHOCK ) ) != 0 );
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. // Input : iDmgType -
  99. // Output : Returns true on success, false on failure.
  100. //-----------------------------------------------------------------------------
  101. bool CSingleplayRules::Damage_NoPhysicsForce( int iDmgType )
  102. {
  103. // Damage types that don't have to supply a physics force & position.
  104. int iTimeBasedDamage = Damage_GetTimeBased();
  105. return ( ( iDmgType & ( DMG_FALL | DMG_BURN | DMG_PLASMA | DMG_DROWN | iTimeBasedDamage | DMG_CRUSH | DMG_PHYSGUN | DMG_PREVENT_PHYSICS_FORCE ) ) != 0 );
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. // Input : iDmgType -
  110. // Output : Returns true on success, false on failure.
  111. //-----------------------------------------------------------------------------
  112. bool CSingleplayRules::Damage_ShouldNotBleed( int iDmgType )
  113. {
  114. // Damage types that don't make the player bleed.
  115. return ( ( iDmgType & ( DMG_POISON | DMG_ACID ) ) != 0 );
  116. }
  117. #ifdef CLIENT_DLL
  118. #else
  119. extern CGameRules *g_pGameRules;
  120. extern bool g_fGameOver;
  121. //=========================================================
  122. //=========================================================
  123. CSingleplayRules::CSingleplayRules( void )
  124. {
  125. RefreshSkillData( true );
  126. }
  127. //=========================================================
  128. //=========================================================
  129. void CSingleplayRules::Think ( void )
  130. {
  131. BaseClass::Think();
  132. }
  133. //=========================================================
  134. //=========================================================
  135. bool CSingleplayRules::IsDeathmatch ( void )
  136. {
  137. return false;
  138. }
  139. //=========================================================
  140. //=========================================================
  141. bool CSingleplayRules::IsCoOp( void )
  142. {
  143. return false;
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Purpose: Determine whether the player should switch to the weapon passed in
  147. // Output : Returns true on success, false on failure.
  148. //-----------------------------------------------------------------------------
  149. bool CSingleplayRules::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon )
  150. {
  151. //Must have ammo
  152. if ( ( pWeapon->HasAnyAmmo() == false ) && ( pPlayer->GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) <= 0 ) )
  153. return false;
  154. //Always take a loaded gun if we have nothing else
  155. if ( pPlayer->GetActiveWeapon() == NULL )
  156. return true;
  157. // The given weapon must allow autoswitching to it from another weapon.
  158. if ( !pWeapon->AllowsAutoSwitchTo() )
  159. return false;
  160. // The active weapon must allow autoswitching from it.
  161. if ( !pPlayer->GetActiveWeapon()->AllowsAutoSwitchFrom() )
  162. return false;
  163. //Don't switch if our current gun doesn't want to be holstered
  164. if ( pPlayer->GetActiveWeapon()->CanHolster() == false )
  165. return false;
  166. //Only switch if the weapon is better than what we're using
  167. if ( ( pWeapon != pPlayer->GetActiveWeapon() ) && ( pWeapon->GetWeight() <= pPlayer->GetActiveWeapon()->GetWeight() ) )
  168. return false;
  169. return true;
  170. }
  171. //-----------------------------------------------------------------------------
  172. // Purpose: Find the next best weapon to use and return it.
  173. //-----------------------------------------------------------------------------
  174. CBaseCombatWeapon *CSingleplayRules::GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon )
  175. {
  176. if ( pCurrentWeapon && !pCurrentWeapon->AllowsAutoSwitchFrom() )
  177. return NULL;
  178. CBaseCombatWeapon *pBestWeapon = NULL;
  179. CBaseCombatWeapon *pWeapon;
  180. int nBestWeight = -1;
  181. //Search for the best weapon to use next based on its weight
  182. for ( int i = 0; i < pPlayer->WeaponCount(); i++ )
  183. {
  184. pWeapon = pPlayer->GetWeapon(i);
  185. if ( pWeapon == NULL )
  186. continue;
  187. // If we have an active weapon and this weapon doesn't allow autoswitching away
  188. // from another weapon, skip it.
  189. if ( pCurrentWeapon && !pWeapon->AllowsAutoSwitchTo() )
  190. continue;
  191. // Must be eligible for switching to.
  192. if (!pPlayer->Weapon_CanSwitchTo(pWeapon))
  193. continue;
  194. // Must be of higher quality.
  195. if ( pWeapon->GetWeight() <= nBestWeight )
  196. continue;
  197. // We must have primary ammo
  198. if ( pWeapon->UsesClipsForAmmo1() && pWeapon->Clip1() <= 0 && !pPlayer->GetAmmoCount( pWeapon->GetPrimaryAmmoType() ) )
  199. continue;
  200. // This is a better candidate than what we had.
  201. nBestWeight = pWeapon->GetWeight();
  202. pBestWeapon = pWeapon;
  203. }
  204. return pBestWeapon;
  205. }
  206. //-----------------------------------------------------------------------------
  207. // Purpose:
  208. // Output : Returns true on success, false on failure.
  209. //-----------------------------------------------------------------------------
  210. bool CSingleplayRules::SwitchToNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon )
  211. {
  212. CBaseCombatWeapon *pWeapon = GetNextBestWeapon( pPlayer, pCurrentWeapon );
  213. if ( pWeapon != NULL )
  214. return pPlayer->Weapon_Switch( pWeapon );
  215. return false;
  216. }
  217. //=========================================================
  218. //=========================================================
  219. bool CSingleplayRules::ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
  220. {
  221. return true;
  222. }
  223. void CSingleplayRules::InitHUD( CBasePlayer *pl )
  224. {
  225. }
  226. //=========================================================
  227. //=========================================================
  228. void CSingleplayRules::ClientDisconnected( edict_t *pClient )
  229. {
  230. }
  231. //=========================================================
  232. //=========================================================
  233. float CSingleplayRules::FlPlayerFallDamage( CBasePlayer *pPlayer )
  234. {
  235. // subtract off the speed at which a player is allowed to fall without being hurt,
  236. // so damage will be based on speed beyond that, not the entire fall
  237. pPlayer->m_Local.m_flFallVelocity -= PLAYER_MAX_SAFE_FALL_SPEED;
  238. return pPlayer->m_Local.m_flFallVelocity * DAMAGE_FOR_FALL_SPEED;
  239. }
  240. //=========================================================
  241. //=========================================================
  242. bool CSingleplayRules::AllowDamage( CBaseEntity *pVictim, const CTakeDamageInfo &info )
  243. {
  244. return true;
  245. }
  246. //=========================================================
  247. //=========================================================
  248. void CSingleplayRules::PlayerSpawn( CBasePlayer *pPlayer )
  249. {
  250. // Player no longer gets all weapons to start.
  251. // He has to pick them up now. Use impulse 101
  252. // to give him all weapons
  253. }
  254. //=========================================================
  255. //=========================================================
  256. bool CSingleplayRules::AllowAutoTargetCrosshair( void )
  257. {
  258. return ( IsSkillLevel(SKILL_EASY) );
  259. }
  260. //=========================================================
  261. //=========================================================
  262. int CSingleplayRules::GetAutoAimMode()
  263. {
  264. return sk_autoaim_mode.GetInt();
  265. }
  266. //=========================================================
  267. //=========================================================
  268. bool CSingleplayRules::FPlayerCanRespawn( CBasePlayer *pPlayer )
  269. {
  270. return true;
  271. }
  272. //=========================================================
  273. //=========================================================
  274. float CSingleplayRules::FlPlayerSpawnTime( CBasePlayer *pPlayer )
  275. {
  276. return gpGlobals->curtime;//now!
  277. }
  278. //=========================================================
  279. // IPointsForKill - how many points awarded to anyone
  280. // that kills this player?
  281. //=========================================================
  282. int CSingleplayRules::IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled )
  283. {
  284. return 1;
  285. }
  286. //=========================================================
  287. // PlayerKilled - someone/something killed this player
  288. //=========================================================
  289. void CSingleplayRules::PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info )
  290. {
  291. }
  292. //=========================================================
  293. // Deathnotice
  294. //=========================================================
  295. void CSingleplayRules::DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info )
  296. {
  297. }
  298. //=========================================================
  299. // FlWeaponRespawnTime - what is the time in the future
  300. // at which this weapon may spawn?
  301. //=========================================================
  302. float CSingleplayRules::FlWeaponRespawnTime( CBaseCombatWeapon *pWeapon )
  303. {
  304. return -1;
  305. }
  306. //=========================================================
  307. // FlWeaponRespawnTime - Returns 0 if the weapon can respawn
  308. // now, otherwise it returns the time at which it can try
  309. // to spawn again.
  310. //=========================================================
  311. float CSingleplayRules::FlWeaponTryRespawn( CBaseCombatWeapon *pWeapon )
  312. {
  313. return 0;
  314. }
  315. //=========================================================
  316. // VecWeaponRespawnSpot - where should this weapon spawn?
  317. // Some game variations may choose to randomize spawn locations
  318. //=========================================================
  319. Vector CSingleplayRules::VecWeaponRespawnSpot( CBaseCombatWeapon *pWeapon )
  320. {
  321. return pWeapon->GetAbsOrigin();
  322. }
  323. //=========================================================
  324. // WeaponShouldRespawn - any conditions inhibiting the
  325. // respawning of this weapon?
  326. //=========================================================
  327. int CSingleplayRules::WeaponShouldRespawn( CBaseCombatWeapon *pWeapon )
  328. {
  329. return GR_WEAPON_RESPAWN_NO;
  330. }
  331. //=========================================================
  332. //=========================================================
  333. bool CSingleplayRules::CanHaveItem( CBasePlayer *pPlayer, CItem *pItem )
  334. {
  335. return true;
  336. }
  337. //=========================================================
  338. //=========================================================
  339. void CSingleplayRules::PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem )
  340. {
  341. }
  342. //=========================================================
  343. //=========================================================
  344. int CSingleplayRules::ItemShouldRespawn( CItem *pItem )
  345. {
  346. return GR_ITEM_RESPAWN_NO;
  347. }
  348. //=========================================================
  349. // At what time in the future may this Item respawn?
  350. //=========================================================
  351. float CSingleplayRules::FlItemRespawnTime( CItem *pItem )
  352. {
  353. return -1;
  354. }
  355. //=========================================================
  356. // Where should this item respawn?
  357. // Some game variations may choose to randomize spawn locations
  358. //=========================================================
  359. Vector CSingleplayRules::VecItemRespawnSpot( CItem *pItem )
  360. {
  361. return pItem->GetAbsOrigin();
  362. }
  363. //=========================================================
  364. // What angles should this item use to respawn?
  365. //=========================================================
  366. QAngle CSingleplayRules::VecItemRespawnAngles( CItem *pItem )
  367. {
  368. return pItem->GetAbsAngles();
  369. }
  370. //=========================================================
  371. //=========================================================
  372. bool CSingleplayRules::IsAllowedToSpawn( CBaseEntity *pEntity )
  373. {
  374. return true;
  375. }
  376. //=========================================================
  377. //=========================================================
  378. void CSingleplayRules::PlayerGotAmmo( CBaseCombatCharacter *pPlayer, char *szName, int iCount )
  379. {
  380. }
  381. //=========================================================
  382. //=========================================================
  383. float CSingleplayRules::FlHealthChargerRechargeTime( void )
  384. {
  385. return 0;// don't recharge
  386. }
  387. //=========================================================
  388. //=========================================================
  389. int CSingleplayRules::DeadPlayerWeapons( CBasePlayer *pPlayer )
  390. {
  391. return GR_PLR_DROP_GUN_NO;
  392. }
  393. //=========================================================
  394. //=========================================================
  395. int CSingleplayRules::DeadPlayerAmmo( CBasePlayer *pPlayer )
  396. {
  397. return GR_PLR_DROP_AMMO_NO;
  398. }
  399. //=========================================================
  400. //=========================================================
  401. int CSingleplayRules::PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget )
  402. {
  403. // why would a single player in half life need this?
  404. return GR_NOTTEAMMATE;
  405. }
  406. //=========================================================
  407. //=========================================================
  408. bool CSingleplayRules::PlayerCanHearChat( CBasePlayer *pListener, CBasePlayer *pSpeaker )
  409. {
  410. return ( PlayerRelationship( pListener, pSpeaker ) == GR_TEAMMATE );
  411. }
  412. //=========================================================
  413. //=========================================================
  414. bool CSingleplayRules::FAllowNPCs( void )
  415. {
  416. return true;
  417. }
  418. #endif