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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/*
Hooks between start destinations and GOKZ.
*/
static Regex RE_BonusStart;
static bool startExists[GOKZ_MAX_COURSES];
static float startOrigin[GOKZ_MAX_COURSES][3];
static float startAngles[GOKZ_MAX_COURSES][3];
// Used for SearchStart
static Regex RE_BonusStartButton;
static Regex RE_BonusStartZone;
static CourseTimerType startType[GOKZ_MAX_COURSES];
static float searchStartOrigin[GOKZ_MAX_COURSES][3];
static float searchStartAngles[GOKZ_MAX_COURSES][3];
// =====[ EVENTS ]=====
void OnPluginStart_MapStarts()
{
RE_BonusStart = CompileRegex(GOKZ_BONUS_START_NAME_REGEX);
RE_BonusStartButton = CompileRegex(GOKZ_BONUS_START_BUTTON_NAME_REGEX);
RE_BonusStartZone = CompileRegex(GOKZ_BONUS_START_ZONE_NAME_REGEX);
}
void OnEntitySpawned_MapStarts(int entity)
{
char buffer[32];
GetEntityClassname(entity, buffer, sizeof(buffer));
if (!StrEqual("info_teleport_destination", buffer, false))
{
return;
}
if (GetEntityName(entity, buffer, sizeof(buffer)) == 0)
{
return;
}
if (StrEqual(GOKZ_START_NAME, buffer, false))
{
StoreStart(0, entity);
}
else
{
int course = GetStartBonusNumber(entity);
if (GOKZ_IsValidCourse(course, true))
{
StoreStart(course, entity);
}
}
}
void OnEntitySpawnedPost_MapStarts(int entity)
{
char buffer[32];
GetEntityClassname(entity, buffer, sizeof(buffer));
if (StrEqual("trigger_multiple", buffer, false))
{
bool isStartZone;
if (GetEntityName(entity, buffer, sizeof(buffer)) != 0)
{
if (StrEqual(GOKZ_START_ZONE_NAME, buffer, false))
{
isStartZone = true;
StoreSearchStart(0, entity, CourseTimerType_ZoneNew);
}
else if (GetStartZoneBonusNumber(entity) != -1)
{
int course = GetStartZoneBonusNumber(entity);
if (GOKZ_IsValidCourse(course, true))
{
isStartZone = true;
StoreSearchStart(course, entity, CourseTimerType_ZoneNew);
}
}
}
if (!isStartZone)
{
TimerButtonTrigger trigger;
if (IsTimerButtonTrigger(entity, trigger) && trigger.isStartTimer)
{
StoreSearchStart(trigger.course, entity, CourseTimerType_ZoneLegacy);
}
}
}
else if (StrEqual("func_button", buffer, false))
{
bool isStartButton;
if (GetEntityName(entity, buffer, sizeof(buffer)) != 0)
{
if (StrEqual(GOKZ_START_BUTTON_NAME, buffer, false))
{
isStartButton = true;
StoreSearchStart(0, entity, CourseTimerType_Button);
}
else
{
int course = GetStartButtonBonusNumber(entity);
if (GOKZ_IsValidCourse(course, true))
{
isStartButton = true;
StoreSearchStart(course, entity, CourseTimerType_Button);
}
}
}
if (!isStartButton)
{
TimerButtonTrigger trigger;
if (IsTimerButtonTrigger(entity, trigger) && trigger.isStartTimer)
{
StoreSearchStart(trigger.course, entity, CourseTimerType_Button);
}
}
}
}
void OnMapStart_MapStarts()
{
for (int course = 0; course < GOKZ_MAX_COURSES; course++)
{
startExists[course] = false;
startType[course] = CourseTimerType_None;
}
}
bool GetMapStartPosition(int course, float origin[3], float angles[3])
{
if (!startExists[course])
{
return false;
}
origin = startOrigin[course];
angles = startAngles[course];
return true;
}
bool GetSearchStartPosition(int course, float origin[3], float angles[3])
{
if (startType[course] == CourseTimerType_None)
{
return false;
}
origin = searchStartOrigin[course];
angles = searchStartAngles[course];
return true;
}
// =====[ PRIVATE ]=====
static void StoreStart(int course, int entity)
{
float origin[3], angles[3];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", origin);
GetEntPropVector(entity, Prop_Data, "m_angRotation", angles);
angles[2] = 0.0; // Roll should always be 0.0
startExists[course] = true;
startOrigin[course] = origin;
startAngles[course] = angles;
}
static void StoreSearchStart(int course, int entity, CourseTimerType type)
{
// If StoreSearchStart is called, then there is at least an end position (even though it might not be a valid one)
if (startType[course] < CourseTimerType_Default)
{
startType[course] = CourseTimerType_Default;
}
// Real zone is always better than "fake" zones which are better than buttons
// as the buttons found in a map with fake zones aren't meant to be visible.
if (startType[course] >= type)
{
return;
}
float origin[3], distFromCenter[3];
GetEntityPositions(entity, origin, searchStartOrigin[course], searchStartAngles[course], distFromCenter);
// If it is a button or the center of the center of the zone is invalid
if (type == CourseTimerType_Button || !IsSpawnValid(searchStartOrigin[course]))
{
// Attempt with various positions around the entity, pick the first valid one.
if (!FindValidPositionAroundTimerEntity(entity, searchStartOrigin[course], searchStartAngles[course], type == CourseTimerType_Button))
{
searchStartOrigin[course][2] -= 64.0; // Move the origin down so the eye position is directly on top of the button/zone.
return;
}
}
// Only update the CourseTimerType if a valid position is found.
startType[course] = type;
}
static int GetStartBonusNumber(int entity)
{
return GOKZ_MatchIntFromEntityName(entity, RE_BonusStart, 1);
}
static int GetStartButtonBonusNumber(int entity)
{
return GOKZ_MatchIntFromEntityName(entity, RE_BonusStartButton, 1);
}
static int GetStartZoneBonusNumber(int entity)
{
return GOKZ_MatchIntFromEntityName(entity, RE_BonusStartZone, 1);
}
|