forked from ShakaUVM/CustomTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGR.QC
361 lines (340 loc) · 13.9 KB
/
AGR.QC
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// AGR.QC ver. January 29, 2009
// Author: Pulseczar
//
// Implementation of OneManClan's infamous Attackers Go Red CTF mode
// I tried to fit everything I could into this file. The things
// that could not go here can be found by searching for 'PZ'.
#ifdef OMGWTFBBQ
//=================================================================
// globals defined in defs.qc
//=================================================================
// cvars - requires 'localinfo' to set these
float agr; // globar cvar, just on or off (requires 'localinfo agr 1' to be on)
float agr_frags; // frags blue gets for successfully defending for agr_minutes minutes
float agr_minutes; // number of minutes blue has to defend in order to be rewarded frags
float agr_teamfrags; // overrides the serverinfo 'teamfrags' (or 't') var when AGR is active,
// which controls whether or not each players' frags are equal to their
// team's score (has to be set to '1' to be on)
// globals
float timeToRewardBlue; // don't try to set it (it's set by functions)
float agrTimerRunning; // boolean
float agrTimeOfLastSound; // in seconds, what the timer was on last timer sound
// define vars
#define AGR_ROTATION_OFF #TRUE // on a map triggered by map rotation, AGR is never on
// #define AGR_WHEN_BLUE_SCORES_RETURN_FLAG
#endif
//=================================================================
// called every frame in StartFrame(); maintains flag
// capture timer; awards blue team points for successfully
// defending for required time; stops the AGR timer if red or blue
// have 0 players
//=================================================================
void() AGR_think =
{
local string temp;
local entity bluePlayer;
local float timeLeft; // time left on the map
local float timeAccumulated; // amount of time blue has defended this 'clock cycle'
local float amtBlueCanScore; // max amount blue can score with time left
local float timesBlueCanScore; // max number of times blue can score with time left
if (agr)
{
if (playersOnTeam1 && playersOnTeam2)
{
if (agrTimerRunning)
{
if (timeToRewardBlue <= time) // has blue successfully defended for agr_minutes minutes?
{
// give frags to blue players
TeamFortress_TeamIncreaseScore(1, agr_frags);
bluePlayer = find(world, classname, "player");
while (bluePlayer)
{
if (bluePlayer.team_no == 1)
{
bluePlayer.real_frags = bluePlayer.real_frags + agr_frags;
if (!(toggleflags & #TFLAG_TEAMFRAGS))
bluePlayer.frags = bluePlayer.real_frags;
}
CenterPrint(bluePlayer, " Blue Successfully Defends! \n");
// ^ not necessarily a blue player
bluePlayer = find(bluePlayer, classname, "player");
}
bprint(#PRINT_HIGH, "\n Blue Successfully Defends \n");
bprint(#PRINT_HIGH, "Blue is awarded ");
temp = ftos(agr_frags); temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, temp);
bprint(#PRINT_HIGH, " frags for\nsuccessfully defending for ");
temp = ftos(agr_minutes); temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, temp); bprint(#PRINT_HIGH, " minutes!\n");
bprint(#PRINT_HIGH, "\n");
TeamFortress_TeamShowScores(2, 1, agr_frags);
BroadcastSound("boss2/pop2.wav");
AGR_resetTimer();
}
AGR_playTimerSounds();
// check to see if the game should end because blue
// doesn't have enough time to catch up to red in score
if (timelimit != 0)
{
timeLeft = (timelimit - time) / 60;
timeAccumulated = (agr_minutes*60 - (timeToRewardBlue - time)) / 60;
timesBlueCanScore = (timeLeft + timeAccumulated) / agr_minutes;
timesBlueCanScore = floor(timesBlueCanScore);
amtBlueCanScore = timesBlueCanScore * agr_frags;
if (team1score + amtBlueCanScore < team2score)
{
local float integer, fraction;
bprint(#PRINT_HIGH, "\n Red Wins The Game! \n");
bprint(#PRINT_HIGH, "Blue can't catch up to Red's score in the ");
integer = floor(timeLeft); fraction = timeLeft - integer;
fraction = fraction * 10; fraction = floor(fraction);
temp = ftos(integer); temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, temp); bprint(#PRINT_HIGH, ".");
temp = ftos(fraction); temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, temp);
bprint(#PRINT_HIGH, "\nminutes remaining. Blue can only score ");
temp = ftos(amtBlueCanScore); temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, temp); bprint(#PRINT_HIGH, " points.\n");
bprint(#PRINT_HIGH, "\n");
BroadcastSound("boss2/pop2.wav");
NextLevel(); // end the map
}
}
}
else if (prematch < time)
AGR_startTimer();
}
else if (agrTimerRunning)
AGR_stopTimer();
}
};
//=================================================================
// called by the localinfo key initializing function
//=================================================================
void() AGR_initialize =
{
local string st;
local float force_agr;
st = infokey(world, "agr"); // ARE YOU HAPPY, OMC?? :P
if (st == string_null) st = "0"; // sets default
agr = stof(st);
if (agr != 1) agr = 0; // has to be set to 1 to engage AGR
//WK 5-15-08 Added command to force on AGR regardless of vote setting, for Phrosty
st = infokey(world, "force_agr");
if (st == string_null) st = "0"; // sets default
force_agr = stof(st);
if (force_agr == 1) agr = 1; // Override AGR setting if 1
if (agr)
{
st = infokey(world, "agr_frags");
if (st == string_null) st = "10"; // sets default
agr_frags = stof(st);
if (agr_frags < 0) agr_frags = 0; // the allowed minimum
st = infokey(world, "agr_minutes");
if (st == string_null) st = "5"; // sets default
agr_minutes = stof(st);
if (agr_minutes < 0) agr_minutes = 0; // the allowed minimum
st = infokey(world, "agr_teamfrags");
if (st == string_null) st = "1"; //WK 5-15-08 Teamfrags on by default now in AGR mode
agr_teamfrags = stof(st);
if (agr_teamfrags != 1) agr_teamfrags = 0;
}
};
//=================================================================
// starts the flag capture timer
//=================================================================
void() AGR_startTimer =
{
if (prematch >= time) return;
local string temp;
local entity player;
timeToRewardBlue = time + agr_minutes*60; // set the defender's reward timer
agrTimerRunning = 1;
temp = ftos(agr_minutes);
temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, "\n ÁÇÒ Timer Started \n");
bprint(#PRINT_HIGH, "Blue must successfully defend their\nflag for ");
bprint(#PRINT_HIGH, temp); bprint(#PRINT_HIGH, " minutes, in order to score.\n");
bprint(#PRINT_HIGH, "\n");
BroadcastSound("misc/runekey.wav");
player = find(world, classname, "player");
while (player)
{
CenterPrint(player, " ÁÇÒ Timer Started \n");
player = find(player, classname, "player");
}
};
//=================================================================
// stops the flag capture timer; returns blue flag to its base
//=================================================================
void() AGR_stopTimer =
{
local entity player;
local entity blueFlag;
agrTimerRunning = 0;
bprint(#PRINT_HIGH, "\n ÁÇÒ Timer Stopped \n");
bprint(#PRINT_HIGH, "The flag capture timer has been stopped.\n");
if (playersOnTeam1 == 0)
bprint(#PRINT_HIGH, "Blue has no players.\n");
else if (playersOnTeam2 == 0)
bprint(#PRINT_HIGH, "Red has no players.\n");
bprint(#PRINT_HIGH, "\n");
BroadcastSound("doors/runeuse.wav");
player = find(world, classname, "player");
while (player)
{
CenterPrint(player, " ÁÇÒ Timer Stopped \n");
player = find(player, classname, "player");
}
// return blue flag to its base
blueFlag = find(world, classname, "item_tfgoal");
while (blueFlag)
{
if (blueFlag.team_no == 2)
{
self = blueFlag;
// both ways returns the flag
if (self.goal_state == #TFGS_ACTIVE && self.owner != world) // a player has it
tfgoalitem_RemoveFromPlayer(self, self.owner, 1);
else
tfgoalitem_remove();
break;
}
blueFlag = find(blueFlag, classname, "item_tfgoal");
}
};
//=================================================================
// used when teams score; resets the timer for which blue has to
// successfully defend; (may return blue flag to its base)
//=================================================================
void() AGR_resetTimer =
{
local string temp;
timeToRewardBlue = time + agr_minutes*60;
bprint(#PRINT_HIGH, "\n ÁÇÒ Timer Reset \n");
bprint(#PRINT_HIGH, "The flag capture timer has been reset.\nRed has ");
temp = ftos(agr_minutes); temp = colstr(temp, #COLSTR_NUMBER);
bprint(#PRINT_HIGH, temp); bprint(#PRINT_HIGH, " minutes to capture Blue's flag.\n");
bprint(#PRINT_HIGH, "\n");
BroadcastSound("doors/runeuse.wav");
#ifdef AGR_WHEN_BLUE_SCORES_RETURN_FLAG
local entity blueFlag;
// return blue flag to its base
blueFlag = find(world, classname, "item_tfgoal");
while (blueFlag)
{
if (blueFlag.team_no == 2)
{
self = blueFlag;
// both ways returns the flag
if (self.goal_state == #TFGS_ACTIVE && self.owner != world) // a player has it
tfgoalitem_RemoveFromPlayer(self, self.owner, 1);
else
tfgoalitem_remove();
break;
}
blueFlag = find(blueFlag, classname, "item_tfgoal");
}
#endif
};
//=================================================================
// checks to see if it's time to play a timer sound, and if so,
// plays it
//=================================================================
void() AGR_playTimerSounds =
{
if (!agrTimerRunning) return;
local float minutes, seconds; // minutes:seconds of the flag timer
local float totalSeconds;
totalSeconds = timeToRewardBlue - floor(time);
if (agrTimeOfLastSound == totalSeconds) return;
minutes = floor(totalSeconds / 60);
seconds = totalSeconds - (60 * floor(totalSeconds / 60)); // sec = totalSec mod 60
seconds = floor(seconds);
if (minutes == 3 && seconds == 0)
{BroadcastSound("agr/cd3min.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 1 && seconds == 0)
{BroadcastSound("agr/cd1min.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 30)
{BroadcastSound("agr/cd30sec.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 10)
{BroadcastSound("agr/cd10.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 9)
{BroadcastSound("agr/cd9.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 8)
{BroadcastSound("agr/cd8.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 7)
{BroadcastSound("agr/cd7.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 6)
{BroadcastSound("agr/cd6.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 5)
{BroadcastSound("agr/cd5.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 4)
{BroadcastSound("agr/cd4.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 3)
{BroadcastSound("agr/cd3.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 2)
{BroadcastSound("agr/cd2.wav"); agrTimeOfLastSound = totalSeconds;}
else if (minutes == 0 && seconds == 1)
{BroadcastSound("agr/cd1.wav"); agrTimeOfLastSound = totalSeconds;}
};
//=================================================================
// alerts the joining player of AGR being active
//=================================================================
void() AGR_introducePlayer =
{
sprint(self, #PRINT_HIGH, " Áôôáãëåòó Çï Òåä enabled \n");
sprint(self, #PRINT_HIGH, "To be an attacker, go Red, else go Blue and defend.\n");
if (!agrTimerRunning)
sprint(self, #PRINT_HIGH, "The timer for flag capture has not started yet.\n");
sprint(self, #PRINT_HIGH, "\n");
stuffcmd(self, "play agr/redonoffense.wav\n");
};
//=================================================================
// prints the remaining time on the flag capture timer, when the
// 'inv' function is called
//=================================================================
void() AGR_invPrint =
{
local string temp;
local float x, y;
sprint(self, #PRINT_HIGH, "\nÁÇÒ Capture Timer: ");
if (agrTimerRunning)
{
x = timeToRewardBlue - time; // in seconds
// convert to min:sec
y = floor(x / 60);
temp = ftos(y); temp = colstr(temp, #COLSTR_NUMBER);
sprint2(self, #PRINT_HIGH, temp, ":"); // minutes
y = x - (60 * floor(x / 60)); // y = x mod 60
y = floor(y);
if (y < 10)
sprint(self, #PRINT_HIGH, ""); // padding zero
temp = ftos(y); temp = colstr(temp, #COLSTR_NUMBER);
sprint(self, #PRINT_HIGH, temp); // seconds
sprint(self, #PRINT_HIGH, " remaining");
}
else
sprint(self, #PRINT_HIGH, "timer stopped");
};
//=================================================================
// called in WorldSpawn()
//=================================================================
void() AGR_precacheSounds =
{
precache_sound2("agr/redonoffense.wav");
precache_sound2("agr/cd3min.wav");
precache_sound2("agr/cd1min.wav");
precache_sound2("agr/cd30sec.wav");
precache_sound2("agr/cd10.wav");
precache_sound2("agr/cd9.wav");
precache_sound2("agr/cd8.wav");
precache_sound2("agr/cd7.wav");
precache_sound2("agr/cd6.wav");
precache_sound2("agr/cd5.wav");
precache_sound2("agr/cd4.wav");
precache_sound2("agr/cd3.wav");
precache_sound2("agr/cd2.wav");
precache_sound2("agr/cd1.wav");
};