Counter Strike : Global Offensive Source Code
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.

59 lines
1.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "tier0/platform.h"
  8. #include "tier2/interval.h"
  9. #include "tier1/strtools.h"
  10. #include "vstdlib/random.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //-----------------------------------------------------------------------------
  14. // Purpose:
  15. // Input : *pString -
  16. // Output : interval_t
  17. //-----------------------------------------------------------------------------
  18. interval_t ReadInterval( const char *pString )
  19. {
  20. interval_t tmp;
  21. tmp.start = 0;
  22. tmp.range = 0;
  23. char tempString[128];
  24. Q_strncpy( tempString, pString, sizeof(tempString) );
  25. char *token = strtok( tempString, "," );
  26. if ( token )
  27. {
  28. tmp.start = atof( token );
  29. token = strtok( NULL, "," );
  30. if ( token )
  31. {
  32. tmp.range = atof( token ) - tmp.start;
  33. }
  34. }
  35. return tmp;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. // Input : &interval -
  40. // Output : float
  41. //-----------------------------------------------------------------------------
  42. float RandomInterval( const interval_t &interval )
  43. {
  44. float out = interval.start;
  45. if ( interval.range != 0 )
  46. {
  47. out += RandomFloat( 0, interval.range );
  48. }
  49. return out;
  50. }