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.

114 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Util.h and Util.cpp provide lots of helper stuff for TFStats to work
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //------------------------------------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef UTIL_H
  14. #define UTIL_H
  15. #ifdef WIN32
  16. #pragma once
  17. #endif
  18. #pragma warning (disable:4786)
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string>
  22. #include <map>
  23. using std::string;
  24. using std::map;
  25. #ifdef WIN32
  26. #include <direct.h>
  27. #include <time.h>
  28. #else
  29. #include <unistd.h>
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32. #include <fcntl.h>
  33. #define PERMIT (S_IRWXU|S_IRWXG|S_IRWXO)
  34. #endif
  35. //leave these global
  36. enum Consts
  37. {
  38. TEAM_BLUE=0,
  39. TEAM_RED,
  40. TEAM_GREEN,
  41. TEAM_YELLOW,
  42. TEAM_NONE=4,
  43. MAX_TEAMS=4,
  44. ALL_TEAMS=4,
  45. };
  46. //Player Class support
  47. enum player_class
  48. {
  49. PC_UNDEFINED=0,
  50. PC_SCOUT,
  51. PC_SNIPER,
  52. PC_SOLDIER,
  53. PC_DEMOMAN,
  54. PC_MEDIC,
  55. PC_HWGUY,
  56. PC_PYRO,
  57. PC_SPY,
  58. PC_ENGINEER,
  59. PC_CIVILIAN,
  60. PC_RANDOM,
  61. PC_OBSERVER,
  62. };
  63. //english names, indexed by above enumeration
  64. extern char* plrClassNames[];
  65. //linear search, ack.
  66. player_class playerClassNameToClassID(const char* plrClass);
  67. //time support functions
  68. #include <time.h>
  69. class Util
  70. {
  71. public:
  72. //get hours from time_t number
  73. static int time_t2hours(time_t tmr);
  74. //get minutes from time_t number
  75. static int time_t2mins(time_t tmr);
  76. //get seconds from time_t number
  77. static int time_t2secs(time_t tmr);
  78. //friendly english stuff
  79. static char* Months[];
  80. static char* numberSuffixes[];
  81. static char* daysofWeek[];
  82. static char* ampm[];
  83. static void debug_dir_printf(PRINTF_FORMAT_STRING char* fmt,...);
  84. static void str2lowercase(char* out, const char* in);
  85. //friendly weapon names so users don't have to look at names like "gl_grenade"
  86. static const string& getFriendlyWeaponName(const string& s);
  87. static void initFriendlyWeaponNameTable();
  88. //map of team colors, indexed by team ID
  89. static const char* teamcolormap[];
  90. static map<string,string> frWeapNmTbl;
  91. static int string2svrID(string s);
  92. static const char* makeDurationString(time_t start, time_t end,char* out,char* tostr=" - ");
  93. };
  94. #endif // UTIL_H