summaryrefslogtreecommitdiff
path: root/utils/tfstats/util.h
blob: de460c585e1c40ad559a0cae8c93f464323691e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Util.h and Util.cpp provide lots of helper stuff for TFStats to work
//
// $Workfile:     $
// $Date:         $
//
//------------------------------------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#ifndef UTIL_H
#define UTIL_H
#ifdef WIN32
#pragma once
#endif
#pragma warning (disable:4786)
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
using std::string;
using std::map;

#ifdef WIN32
#include <direct.h>
#include <time.h>
#else
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define PERMIT (S_IRWXU|S_IRWXG|S_IRWXO)
#endif

//leave these global
enum Consts
{
	TEAM_BLUE=0,
	TEAM_RED,
	TEAM_GREEN,
	TEAM_YELLOW,
	TEAM_NONE=4,
	MAX_TEAMS=4,
	ALL_TEAMS=4,
};

//Player Class support
enum player_class
{
	PC_UNDEFINED=0,
	PC_SCOUT,
	PC_SNIPER,
	PC_SOLDIER,
	PC_DEMOMAN,
	PC_MEDIC,
	PC_HWGUY,
	PC_PYRO,
	PC_SPY,
	PC_ENGINEER,
	PC_CIVILIAN,
	PC_RANDOM,
	PC_OBSERVER,
};

//english names, indexed by above enumeration
extern char* plrClassNames[];
//linear search, ack.
player_class playerClassNameToClassID(const char* plrClass);


//time support functions
#include <time.h>

class Util
{
public:
	//get hours from time_t number
	static int time_t2hours(time_t tmr);
	//get minutes from time_t number
	static int time_t2mins(time_t tmr);
	//get seconds from time_t number
	static int time_t2secs(time_t tmr);

	//friendly english stuff
	static char* Months[];
	static char* numberSuffixes[];
	static char* daysofWeek[];
	static char* ampm[];

	static void debug_dir_printf(PRINTF_FORMAT_STRING char* fmt,...);

	static void str2lowercase(char* out, const char* in);

		//friendly weapon names so users don't have to look at names like "gl_grenade"
	static const string& getFriendlyWeaponName(const string& s);
	static void initFriendlyWeaponNameTable();
	//map of team colors, indexed by team ID
	static const char* teamcolormap[];
	
	static map<string,string> frWeapNmTbl;
	static int string2svrID(string s);
	
	
	static const char* makeDurationString(time_t start, time_t end,char* out,char* tostr=" - ");
};



#endif // UTIL_H