-
Notifications
You must be signed in to change notification settings - Fork 2
/
KillData.cpp
153 lines (134 loc) · 2.97 KB
/
KillData.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// wxWindows includes
#include <wx/string.h>
#include <wx/arrstr.h>
#include <wx/dynarray.h>
// Statsgen includes
#include "KillData.h"
#include "GlobalStatistics.h"
KillData::KillData()
{
}
KillData::~KillData()
{
}
char *KillData::KillTypeText()
{
char *retVal;
switch (KillType(gameType,playerIndex))
{
case KILL_TYPE_KILL:
retVal=KILL_TYPE_STRING_KILL;
break;
case KILL_TYPE_DEATH:
retVal=KILL_TYPE_STRING_DEATH;
break;
case KILL_TYPE_TEAMKILL:
retVal=KILL_TYPE_STRING_TEAMKILL;
break;
case KILL_TYPE_TEAMKILLVICTIM:
retVal=KILL_TYPE_STRING_TEAMKILLVICTIM;
break;
case KILL_TYPE_TEAMSWAP:
retVal=KILL_TYPE_STRING_TEAMSWAP;
break;
case KILL_TYPE_SUICIDE:
retVal=KILL_TYPE_STRING_SUICIDE;
break;
default:
retVal=KILL_TYPE_STRING_UNKNOWN;
break;
}
return (retVal);
}
KillTypes KillData::KillType(int gameType,int playerIndexIn)
{
KillTypes retVal;
// Make this read from config eventually
if (playerIndexIn==playerIndex)
{
// This is probably a kill
retVal=KILL_TYPE_KILL;
}
else
{
// This is probably a death
retVal=KILL_TYPE_DEATH;
}
if (playerIndex==targetIndex)
{
retVal=KILL_TYPE_SUICIDE;
if (globalStatistics.IsTeamSwapWeapon(playerWeapon))
{
retVal=KILL_TYPE_TEAMSWAP;
}
}
if (playerIndex!=targetIndex)
{
if (playerTeam==targetTeam)
{
if (!globalStatistics.IsDeathmatchGametype(gameType))
{
if (playerIndex==playerIndexIn)
{
retVal=KILL_TYPE_TEAMKILL;
}
else
{
retVal=KILL_TYPE_TEAMKILLVICTIM;
}
}
}
}
return (retVal);
}
wxString KillData::SQLTableName()
{
wxString tableName="killdata";
return (tableName);
}
wxString KillData::SQLCreateTable()
{
wxString SQL;
SQL.Printf("create table %s"
"("
"roundindex integer,"
"killidx integer,"
"playerindex integer,"
"playerclass integer,"
"playerteam integer,"
"playerweapon integer,"
"playerammo integer,"
"targetindex integer,"
"targetclass integer,"
"targetteam integer,"
"targetlocation integer,"
"%s"
")",
SQLTableName().GetData(),
StatsgenDatabase::StringFieldDefinition("killtype","killtype",FIELD_WIDTH_KILL_TYPE).GetData()
);
return SQL;
}
bool KillData::WriteToDatabase(int roundIndex,int itemIndex)
{
wxString SQL;
bool retVal=true;
Player player;
Player target;
player=globalStatistics.playerList.Item(playerIndex);
target=globalStatistics.playerList.Item(targetIndex);
SQL.Printf("insert into %s"
"(roundindex,killidx,playerindex,playerclass,playerteam,"
"playerweapon,playerammo,targetindex,targetclass,"
"targetteam,targetlocation,killtype)"
"values"
"('%d','%d','%d','%d','%d',"
"'%d','%d','%d','%d',"
"'%d','%d','%s')",
SQLTableName().GetData(),
roundIndex,itemIndex,player.actualPlayerIndex,playerClass,playerTeam,
playerWeapon,playerAmmo,target.actualPlayerIndex,targetClass,
targetTeam,targetLocation,KillTypeText());
globalStatistics.statsgenDatabase.SimpleExecute(SQL);
return retVal;
}