-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSECURITY.QC
309 lines (271 loc) · 8.19 KB
/
SECURITY.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
/*======================================================
SECURITY.QC Custom TeamFortress v3.1
(c) Craig Hauser 26/3/00
========================================================
Functions for the security camera
======================================================*/
void() Security_Camera_Idle;
float() Security_Camera_FindTarget;
void() Security_Camera_Pain;
void() Security_Camera_Die;
void() Security_Camera_PrintTarget;
void() Security_Camera_Spawn;
float() Security_Camera_FindFakeTarget;
void() SecurityCameraTossTouch;
//used for print
string(float tno) GetTrueTeamName;
string(float pc) TeamFortress_GetClassName;
string(float pc) TeamFortress_GetJobName;
//===================================================================
void() Security_Camera_Idle =
{
if (Security_Camera_FindTarget())
self.nextthink = time + 2; //CH if found wait 2 sec before do another check
else
self.nextthink = time + 0.5; //CH else 2 checks per sec
self.think = Security_Camera_Idle;
};
//========
float() Security_Camera_FindTarget =
{
local entity client;
local float r, gotone, loopc;
if (self.is_malfunctioning & #SCREWUP_TWO) // SB how tragic, camera can't see
return #FALSE;
if (self.is_malfunctioning & #SCREWUP_THREE) // oh no, we're reading incorrect signals
{
if (Security_Camera_FindFakeTarget())
return #TRUE;
else
return #FALSE;
}
// Try a few checks to make it react faster
r = 0;
loopc = 0;
gotone = #FALSE;
local float trange; //- OfN - Hack
trange=1000;
if (self.all_active & #IMPROVED_ONE)
trange=1250;
//CH Theortetically this will check every client on the server now
while (loopc < 32 && gotone == #FALSE)
{
client = checkclient();
gotone = #TRUE;
if (!client)
gotone = #FALSE;
if (!Pharse_Client(client, self, 1, trange, 0, 1))
gotone = #FALSE;
loopc = loopc + 1;
if (gotone) loopc = 1000;
}
if (!gotone)
return #FALSE;
// Found a Target
self.enemy = client;
if (self.enemy.classname != "player")
{
self.enemy = self.enemy.enemy;
if (self.enemy.classname != "player")
{
self.enemy = world;
return #FALSE;
}
}
// Spotted sound
if (self.heat == 3) { //CH so it does not beep all the time.
sound (self, #CHAN_WEAPON, "weapons/cambeep.wav", 1, #ATTN_NORM);
self.heat = 0;
}
else
self.heat = self.heat + 1;
Security_Camera_PrintTarget ();
return #TRUE;
};
float() Security_Camera_FindFakeTarget =
{
local entity client;
local float r, gotone, loopc;
if (self.is_malfunctioning & #SCREWUP_THREE) // SB how tragic, camera can't see
return #FALSE;
// Try a few checks to make it react faster
r = 0;
loopc = 0;
gotone = #FALSE;
// Pick a random client
while (loopc < 32 && gotone == #FALSE)
{
client = checkclient();
gotone = #TRUE;
if (!client)
gotone = #FALSE;
if (random() < 0.05)
gotone = #FALSE;
if (client.playerclass == #PC_UNDEFINED) {
return #FALSE;
}
if (client.done_custom & #CUSTOM_BUILDING) {
return #FALSE;
}
if (client.health <= 0) {
return #FALSE;
}
if (!client.is_connected) {
return #FALSE;
}
loopc = loopc + 1;
if (gotone) loopc = 1000;
}
if (!gotone)
return #FALSE;
// Found a Target
self.enemy = client;
if (self.enemy.classname != "player")
{
self.enemy = self.enemy.enemy;
if (self.enemy.classname != "player")
{
self.enemy = world;
return #FALSE;
}
}
// Spotted sound
if (self.heat == 3) { //CH so it does not beep all the time.
sound (self, #CHAN_WEAPON, "weapons/cambeep.wav", 1, #ATTN_NORM);
self.heat = 0;
}
else
self.heat = self.heat + 1;
if (!(self.is_malfunctioning & #SCREWUP_ONE))
Security_Camera_PrintTarget ();
return #TRUE;
};
//========
void() Security_Camera_Pain =
{
sound (self, #CHAN_WEAPON, "weapons/cambeep.wav", 1, #ATTN_NORM);
};
//======
void() Security_Camera_Die =
{
sprint(self.real_owner, #PRINT_HIGH, "Your security camera was destroyed.\n");
self.real_owner.has_camera = #FALSE;
// ThrowGib("progs/tgib1.mdl", -70);
// ThrowGib("progs/tgib2.mdl", -70);
// ThrowGib("progs/tgib3.mdl", -70);
WriteByte (#MSG_BROADCAST, #SVC_TEMPENTITY);
WriteByte (#MSG_BROADCAST, #TE_EXPLOSION);
WriteCoord (#MSG_BROADCAST, self.origin_x);
WriteCoord (#MSG_BROADCAST, self.origin_y);
WriteCoord (#MSG_BROADCAST, self.origin_z);
#ifdef QUAKE_WORLD
multicast (self.origin, #MULTICAST_PHS);
dremove(self);
#else
BecomeExplosion ();
#endif
//SwitchFromCamera();
};
//==========
//Prints the person to owner/team
//Outputs: "<>SECURITY CAMERA<> Team_color class/job (netname)\n"
void() Security_Camera_PrintTarget =
{
local string st;
sprint(self.real_owner, #PRINT_HIGH, "ÓÅÃÕÒÉÔÙ ÃÁÍÅÒÁ "); //<>Security camera<>
st = GetTrueTeamName(self.enemy.team_no);
sprint(self.real_owner, #PRINT_HIGH, st);
sprint(self.real_owner, #PRINT_HIGH, " ");
if (self.enemy.playerclass != #PC_CUSTOM)
st = TeamFortress_GetClassName(self.enemy.playerclass);
else
st = TeamFortress_GetJobName(self.enemy.job);
sprint(self.real_owner, #PRINT_HIGH, st);
sprint(self.real_owner, #PRINT_HIGH, " (");
sprint(self.real_owner, #PRINT_HIGH, self.enemy.netname);
sprint(self.real_owner, #PRINT_HIGH, ")\n");
};
//==========
void() Security_Camera_Spawn =
{
if (self.ammo_cells < #BUILD_COST_CAMERA)
{
sprint(self,#PRINT_HIGH,"Not enough cells to build a Security Camera\n");
}
else
{
self.ammo_cells = self.ammo_cells - #BUILD_COST_CAMERA;
self.has_camera = #TRUE;
newmis = spawn();
newmis.movetype = #MOVETYPE_BOUNCE;
setsize (newmis, '0 0 0', '0 0 0');
// setsize (newmis, '-8 -8 -8', '8 8 8');
newmis.solid = #SOLID_BBOX;
newmis.takedamage = #DAMAGE_AIM;
newmis.classname = "building_camera";
newmis.netname = "security_camera";
newmis.flags = newmis.flags | #FL_MACHINE;
setorigin (newmis, self.origin);
newmis.owner = world;
newmis.real_owner = self;
makevectors (self.v_angle);
newmis.avelocity = '0 0 0';
newmis.velocity = v_forward*800 + v_up * 200 + v_right*10 + v_up*10;
newmis.angles = '0 0 0';
newmis.angles_y = anglemod(self.angles_y + 180);
// newmis.skin = 1;
newmis.th_die = Security_Camera_Die; // Death function
newmis.th_pain = Security_Camera_Pain;
newmis.mdl = "progs/camera.mdl"; //CH temp model
setmodel (newmis, newmis.mdl);
newmis.team_no = self.team_no;
newmis.colormap = self.colormap;
newmis.heat = 0; //Beeps
newmis.health = newmis.max_health = #BUILD_HEALTH_CAMERA;
newmis.touch = SecurityCameraTossTouch;
newmis.all_active=0; // OfN - reset HACKER improvements
W_SetCurrentAmmo();
}
};
//========
void() SecurityCameraTossTouch =
{
if (other != world || other == self.real_owner)
return;
if (pointcontents(self.origin) == #CONTENT_SKY || pointcontents(self.origin + '0 0 2') == #CONTENT_SKY || pointcontents(self.origin) == #CONTENT_SOLID)
{
Security_Camera_Die();
return;
}
//CH sees where landed and adjusts to proper things
if (pointcontents(self.origin + '0 0 1') == #CONTENT_SOLID)
self.origin = self.origin - '0 0 12';
if (pointcontents(self.origin - '0 0 1') == #CONTENT_SOLID)
self.origin = self.origin + '0 0 4';
if (pointcontents(self.origin + '0 1 0') == #CONTENT_SOLID)
self.origin = self.origin - '0 16 0';
if (pointcontents(self.origin - '0 1 0') == #CONTENT_SOLID)
self.origin = self.origin + '0 16 0';
if (pointcontents(self.origin + '1 0 0') == #CONTENT_SOLID)
self.origin = self.origin - '16 0 0';
if (pointcontents(self.origin + '1 0 0') == #CONTENT_SOLID)
self.origin = self.origin + '16 0 0';
setorigin (self, self.origin);
if (pointcontents(self.origin) == #CONTENT_SKY || pointcontents(self.origin + '0 0 2') == #CONTENT_SKY || pointcontents(self.origin) == #CONTENT_SOLID)
{
Security_Camera_Die();
return;
}
sprint (self.real_owner, #PRINT_HIGH, "You finish building the Security Camera.\n");
teamprefixsprint(self.real_owner.team_no,self.real_owner); //- OfN
teamsprint(self.real_owner.team_no, self.real_owner, self.real_owner.netname);
teamsprint(self.real_owner.team_no, self.real_owner, " has built a Security Camera.\n");
self.real_owner.option = time + 2; // so ppl cant destroy it for 2 seconds
self.movetype = #MOVETYPE_NONE;
setsize (self, '-16 -16 -6', '16 16 10');
self.solid = #SOLID_BBOX;
self.takedamage = #DAMAGE_AIM;
sound (self, #CHAN_WEAPON, "weapons/guerset.wav", 1, #ATTN_NORM);
self.think = Security_Camera_Idle;
self.nextthink = time + 1;
};