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
|
/*
Categorises jumps into tiers based on their distance.
Tier thresholds are loaded from a config.
*/
static float distanceTiers[JUMPTYPE_COUNT - 3][MODE_COUNT][DISTANCETIER_COUNT];
// =====[ PUBLIC ]=====
int GetDistanceTier(int jumpType, int mode, float distance, float offset = 0.0)
{
// No tiers given for 'Invalid' jumps.
if (jumpType == JumpType_Invalid || jumpType == JumpType_FullInvalid
|| jumpType == JumpType_Fall || jumpType == JumpType_Other
|| jumpType != JumpType_LadderJump && offset < -JS_OFFSET_EPSILON
|| distance > JS_MAX_JUMP_DISTANCE)
{
// TODO Give a tier to "Other" jumps
// TODO Give a tier to offset jumps
return DistanceTier_None;
}
// Get highest tier distance that the jump beats
int tier = DistanceTier_None;
while (tier + 1 < DISTANCETIER_COUNT && distance >= GetDistanceTierDistance(jumpType, mode, tier + 1))
{
tier++;
}
return tier;
}
float GetDistanceTierDistance(int jumpType, int mode, int tier)
{
return distanceTiers[jumpType][mode][tier];
}
bool LoadBroadcastTiers()
{
char chatTier[16], soundTier[16];
KeyValues kv = new KeyValues("broadcast");
if (!kv.ImportFromFile(JS_CFG_BROADCAST))
{
return false;
}
kv.GetString("chat", chatTier, sizeof(chatTier), "ownage");
kv.GetString("sound", soundTier, sizeof(chatTier), "");
for (int tier = 0; tier < sizeof(gC_DistanceTierKeys); tier++)
{
if (StrEqual(chatTier, gC_DistanceTierKeys[tier]))
{
gI_JSOptionDefaults[JSOption_MinChatBroadcastTier] = tier;
}
if (StrEqual(soundTier, gC_DistanceTierKeys[tier]))
{
gI_JSOptionDefaults[JSOption_MinSoundBroadcastTier] = tier;
}
}
delete kv;
return true;
}
// =====[ EVENTS ]=====
void OnMapStart_DistanceTiers()
{
if (!LoadDistanceTiers())
{
SetFailState("Failed to load file: \"%s\".", JS_CFG_TIERS);
}
}
// =====[ PRIVATE ]=====
static bool LoadDistanceTiers()
{
KeyValues kv = new KeyValues("tiers");
if (!kv.ImportFromFile(JS_CFG_TIERS))
{
return false;
}
// It's a bit of a hack to exclude non-tiered jumptypes
for (int jumpType = 0; jumpType < sizeof(gC_JumpTypeKeys) - 3; jumpType++)
{
if (!kv.JumpToKey(gC_JumpTypeKeys[jumpType]))
{
return false;
}
for (int mode = 0; mode < MODE_COUNT; mode++)
{
if (!kv.JumpToKey(gC_ModeKeys[mode]))
{
return false;
}
for (int tier = DistanceTier_Meh; tier < DISTANCETIER_COUNT; tier++)
{
distanceTiers[jumpType][mode][tier] = kv.GetFloat(gC_DistanceTierKeys[tier]);
}
kv.GoBack();
}
kv.GoBack();
}
delete kv;
return true;
}
|