Advertisement
dcomicboy

help

Jan 4th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. void CClientWeapon::ChangeAmmoWithReload( uint8 nNewAmmoId, bool bForce /*=false*/ )
  2. {
  3. // Update the player's stats...
  4. if ( ( W_RELOADING == GetState() ) && !bForce )
  5. {
  6. return;
  7. }
  8.  
  9. if ( CanChangeToAmmo( nNewAmmoId ) && ( nNewAmmoId != m_nAmmoId ) )
  10. {
  11. ASSERT( 0 != g_pWeaponMgr );
  12. m_nAmmoId = nNewAmmoId;
  13. m_pAmmo = g_pWeaponMgr->GetAmmo( m_nAmmoId );
  14.  
  15. // Make sure we reset the anis (the ammo may override the
  16. // weapon animations)...
  17. InitAnimations( true );
  18.  
  19. if ( m_pAmmo->pAniOverrides )
  20. {
  21. // If we're not using the defaults play the new select ani...
  22. Select();
  23. }
  24. else
  25. {
  26. // Do normal reload...
  27. ReloadClip( true, -1, true, true );
  28.  
  29. // Add a message so the user knows he switched ammo (sometimes it
  30. // isn't that obvious)...
  31.  
  32. if (strlen(m_pAmmo->szShortName))
  33. {
  34. char szMsg[128];
  35. FormatString(IDS_CHANGING_AMMO, szMsg, sizeof(szMsg), m_pAmmo->szShortName);
  36. std::string icon = m_pAmmo->GetNormalIcon();
  37. g_pPickupMsgs->AddMessage(szMsg, icon.c_str());
  38. }
  39. }
  40. }
  41. }
  42.  
  43.  
  44. // ----------------------------------------------------------------------- //
  45. //
  46. // ROUTINE: CClientWeapon::ChangeAmmoImmediate()
  47. //
  48. // PURPOSE: Change to the specified ammo type
  49. //
  50. // ----------------------------------------------------------------------- //
  51.  
  52. void CClientWeapon::ChangeAmmoImmediate( uint8 nNewAmmoId, int nAmmoAmount /*=-1*/, bool bForce /*=false*/ )
  53. {
  54. // Update the player's stats...
  55. if ( ( W_RELOADING == GetState() ) && !bForce )
  56. {
  57. return;
  58. }
  59.  
  60. if ( CanChangeToAmmo( nNewAmmoId ) && ( nNewAmmoId != m_nAmmoId ) )
  61. {
  62. ASSERT( 0 != g_pWeaponMgr );
  63. m_nAmmoId = nNewAmmoId;
  64. m_pAmmo = g_pWeaponMgr->GetAmmo( m_nAmmoId );
  65.  
  66. // Make sure we reset the anis (the ammo may override the
  67. // weapon animations)...
  68. InitAnimations( true );
  69.  
  70. if ( m_pAmmo->pAniOverrides )
  71. {
  72. // If we're not using the defaults play the new select ani...
  73. Select();
  74. }
  75. else
  76. {
  77. // Do normal reload...
  78. ReloadClip( false, nAmmoAmount /*-1*/, true, true );
  79. }
  80. }
  81. else
  82. {
  83. // Update the hud to reflect the new ammo amount...
  84. g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmoAmount );
  85. g_pPlayerStats->UpdatePlayerWeapon( m_nWeaponId, m_nAmmoId );
  86. }
  87. }
  88.  
  89.  
  90. // ----------------------------------------------------------------------- //
  91. //
  92. // ROUTINE: CWeapon::ReloadClip
  93. //
  94. // PURPOSE: Fill the clip
  95. //
  96. // ----------------------------------------------------------------------- //
  97.  
  98. void CClientWeapon::ReloadClip( bool bPlayReload /*=true*/,
  99. int nNewAmmo /*=-1*/,
  100. bool bForce /*=false*/,
  101. bool bNotifyServer /*=false*/)
  102. {
  103. // Can't reload clip while deselecting the weapon...
  104.  
  105. if ( W_DESELECT == GetState() ) return;
  106.  
  107. // get all the ammo the player possesses
  108. int nAmmoCount = g_pPlayerStats->GetAmmoCount( m_nAmmoId );
  109.  
  110. // Get an intermediate amount of ammo. If the nNewAmmo has
  111. // been specified, use that value. Otherwise use the total
  112. // amount of ammo on the player.
  113. int nAmmo = nNewAmmo >= 0 ? nNewAmmo : nAmmoCount;
  114.  
  115. // Get how many shots are in a clip.
  116. int nShotsPerClip = m_pWeapon->nShotsPerClip;
  117.  
  118. // Update the player's stats...
  119. // note: the ammo amount we pass may be too much but
  120. // these functions figure out what the max really is,
  121. // and then we do the same thing later
  122.  
  123. // UpdateAmmo does a lot of stuff, one of those is passing in
  124. // how much ammo you have. If you specify an amount that is
  125. // more or less, it will consider this the new amount of
  126. // ammo that you have on you and adjust things accordingly.
  127. g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmo );
  128.  
  129.  
  130. // This will set the player stats to the specified weapon and
  131. // ammo id. In this case, use the current ones.
  132. g_pPlayerStats->UpdatePlayerWeapon( m_nWeaponId, m_nAmmoId );
  133.  
  134. // Make sure we can reload the clip...
  135. if ( !bForce )
  136. {
  137. // Already reloading...
  138. if ( m_hObject && ( W_RELOADING == GetState() ) )
  139. {
  140. return;
  141. }
  142.  
  143. // Clip is full...
  144. if ( ( m_nAmmoInClip == nShotsPerClip ) || ( m_nAmmoInClip == nAmmoCount ) )
  145. {
  146. return;
  147. }
  148. }
  149.  
  150. if ( ( nAmmo > 0 ) && ( nShotsPerClip > 0 ) )
  151. {
  152. // The amount of ammo we give the player due
  153. // of the reload is tracked with m_nNewAmmoInClip.
  154. // Set the new ammo to the lesser vaule of
  155. // either the max clip size of the amount of ammo
  156. // on the player.
  157. if ( nAmmo < nShotsPerClip )
  158. {
  159. m_nNewAmmoInClip = nAmmo;
  160. }
  161. else
  162. {
  163. m_nNewAmmoInClip = nShotsPerClip;
  164. }
  165.  
  166. if( bNotifyServer )
  167. {
  168. // Let the server know we are reloading the clip...
  169.  
  170. CAutoMessage cMsg;
  171. cMsg.Writeuint8( MID_WEAPON_RELOAD );
  172. cMsg.Writeuint8( m_nAmmoId ); // We maybe switching ammo
  173. g_pLTClient->SendToServer( cMsg.Read(), MESSAGE_GUARANTEED );
  174. }
  175.  
  176.  
  177. // check for a valid reload animation
  178. if ( bPlayReload && ( INVALID_ANI != GetReloadAni() ) )
  179. {
  180. // setting the state will "queue" the animation to
  181. // start playing on the next update
  182. SetState( W_RELOADING );
  183. return;
  184. }
  185. else
  186. {
  187. // there is no reload animation, so just put
  188. // the right amount in the clip directly
  189. m_nAmmoInClip = m_nNewAmmoInClip;
  190. }
  191. }
  192. }
  193.  
  194.  
  195. // ----------------------------------------------------------------------- //
  196. //
  197. // ROUTINE: CClientWeapon::DecrementAmmo
  198. //
  199. // PURPOSE: Decrement the weapon's ammo count
  200. //
  201. // ----------------------------------------------------------------------- //
  202.  
  203. void CClientWeapon::DecrementAmmo()
  204. {
  205. // Hide the necessary pieces...
  206. SpecialShowPieces(false);
  207.  
  208. int nAmmo;
  209. bool bInfiniteAmmo = ( g_bInfiniteAmmo || ( !!( m_pWeapon->bInfiniteAmmo ) ) );
  210. if ( bInfiniteAmmo )
  211. {
  212. nAmmo = INFINITE_AMMO_AMOUNT;
  213. }
  214. else
  215. {
  216. nAmmo = g_pPlayerStats->GetAmmoCount( m_nAmmoId );
  217. }
  218.  
  219. int nShotsPerClip = m_pWeapon->nShotsPerClip;
  220.  
  221. if ( 0 < m_nAmmoInClip )
  222. {
  223. if ( 0 < nShotsPerClip )
  224. {
  225. // decrease the ammo in the clip only if the clip
  226. // is non-zero
  227. --m_nAmmoInClip;
  228. }
  229.  
  230. if ( !bInfiniteAmmo )
  231. {
  232. // we are not using infinite ammo, update the current amount
  233. --nAmmo;
  234.  
  235. // Update our stats. This will ensure that our stats are always
  236. // accurate (even in multiplayer)...
  237. g_pPlayerStats->UpdateAmmo( m_nWeaponId, m_nAmmoId, nAmmo, LTFALSE, LTFALSE );
  238. }
  239. }
  240.  
  241. // Check to see if we need to reload...
  242. if ( 0 < nShotsPerClip )
  243. {
  244. if ( 0 >= m_nAmmoInClip )
  245. {
  246. ReloadClip( true, nAmmo );
  247. }
  248. }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement