-
Notifications
You must be signed in to change notification settings - Fork 17
/
buttons.qc
537 lines (465 loc) · 13.4 KB
/
buttons.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/*
===========================================
BUTTONS
button and multiple button
for all your button
===========================================
*/
void() button_wait = // hit top
{
self.state = STATE_TOP;
self.nextthink = self.ltime + self.wait;
self.think = button_return;
activator = self.enemy;
self.frame = 1; // use alternate textures
if (self.customflags & CFL_LOCKED) return;
if (!SUB_UseTargetsAlt(target2))
SUB_UseTargets();
}
void() button_done = // hit bottom
{
self.frame = 0; // use normal textures
self.state = STATE_BOTTOM;
if (self.customflags & CFL_LOCKED) return;
SUB_UseTargetsAlt(target4);
}
void() button_return = // go down
{
if (self.customflags & CFL_LOCKED) return;
self.state = STATE_DOWN;
SUB_CalcMove (self.pos1, self.speed, button_done);
self.frame = 0; // use normal textures
if (self.health)
self.takedamage = DAMAGE_YES; // can be shot again
SUB_UseTargetsAlt(target3);
}
void() button_blocked =
{ // do nothing, just don't ome all the way back out
}
void() button_fire = // go up
{
if (self.customflags & CFL_LOCKED) return;
if (self.state == STATE_UP || self.state == STATE_TOP)
return;
if (self.noise != string_null)
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
self.state = STATE_UP;
SUB_UseTargetsAlt(target);
SUB_CalcMove (self.pos2, self.speed, button_wait);
}
void() button_use =
{
if (self.customflags & CFL_LOCKED) return;
self.enemy = activator;
if (self.state == STATE_UP || self.state == STATE_DOWN)
return;
button_fire ();
}
void() button_touch =
{
if (self.customflags & CFL_LOCKED) return;
if (other.classname != "player" || other.health <= 0)
return;
self.enemy = other;
button_fire ();
}
// must preserve locked status until the end of the move so none of the four alt targets fire
void() button_done_unlock =
{
button_done();
self.customflags = not(self.customflags,CFL_LOCKED);
}
void(float unlock) button_lock =
{
if (unlock)
{
if (self.max_health)
{
self.takedamage = DAMAGE_YES;
self.health = self.max_health;
}
self.frame = 0; // use normal textures
self.state = STATE_DOWN;
SUB_CalcMove (self.pos1, self.speed, button_done_unlock);
}
else
{
self.customflags |= CFL_LOCKED;
if (self.max_health)
self.takedamage = DAMAGE_NO;
self.state = STATE_UP;
SUB_CalcMove (self.pos2, self.speed, button_wait);
}
}
// failed experiment: this check kept moving farther and farther away from
// button_killed until it had to go in every projectile's touch function, so
// that the blood vs greydust feedback was correct. too much complexity.
/*
float(entity inflictor, entity attacker) button_check_attacker =
{
if (attacker.classname != "player")
return FALSE;
switch(self.weapon) {
// axe/lg/shotguns are instant, can just check immediate status
case 1:
return (self.customflags & CFL_AXEHITME);
case 2:
case 3:
return (attacker.weapon == IT_SHOTGUN || attacker.weapon == IT_SUPER_SHOTGUN);
case 8:
return (self.customflags & CFL_ZAPPED);
// projectiles must be checked directly since the player can fire and then switch weapons
case 4:
case 5:
return (inflictor.classname == "spike");
case 6:
return (inflictor.classname == "grenade");
case 7:
return (inflictor.classname == "rocket");
}
return FALSE;
}
*/
void() button_killed =
{
if (self.customflags & CFL_LOCKED) return;
self.enemy = damage_attacker;
self.health = self.max_health;
self.takedamage = DAMAGE_NO; // wil be reset upon return
button_fire();
}
void(entity b) button_force =
{
b.enemy = self;
SUB_CallAsSelf(button_fire, b);
}
void() button_sounds =
{
if (self.sounds == 0)
{
self.noise = "buttons/airbut1.wav";
}
else if (self.sounds == 1)
{
self.noise = "buttons/switch21.wav";
}
else if (self.sounds == 2)
{
self.noise = "buttons/switch02.wav";
}
else if (self.sounds == 3)
{
self.noise = "buttons/switch04.wav";
}
else if (self.sounds == 4)
{
self.noise = "misc/trigger1.wav";
}
precache_sound_safe (self.noise);
}
/*QUAKED func_button (0 .5 .8) ? - - - - - - - START_INVIS
When a button is touched, it moves some distance in the direction of its angle, triggers all of its targets, waits some time, then returns to its original position where it can be triggered again.
Acts as if touched when triggered. Will depress itself when locked by a target_lock to look inactive.
"angle" determines the opening direction
"target" all entities with a matching targetname will be used
"speed" override the default 40 speed
"wait" override the default 1 second wait (-1 = never return)
"lip" override the default 4 pixel lip remaining at end of move
"health" if set, the button must be killed instead of touched
"sounds"
0) steam metal
1) wooden clunk
2) metallic click
3) in-out
4) trigger noise (big light switch)
Alt Target Pattern: 'target' when touched, 'target2' when fully depressed, 'target3' when returning, 'target4' when fully out.
*/
/*FGD
@SolidClass base(Appearflags, Angle, Target, Targetname, Func, FuncInvis, AltTarget) = func_button :
"Button. When a button is touched, it moves some distance in the direction of its angle, triggers all of its targets, waits some time, then returns to its original position where it can be triggered again.
Acts as if touched when triggered. Depresses itself when locked by a target_lock to look inactive.
Alt Target Pattern: 'target' when touched, 'target2' when fully depressed, 'target3' when returning, 'target4' when fully out."
[
speed(integer) : "Speed" : 40
health(integer) : "Health (shootable if > 0)"
lip(integer) : "Lip remaining at end of move" : 4
distance(string) : "Distance to travel (overrides Lip)" : "0.0"
sounds(choices) : "Sounds" =
[
-1 : "None/Custom (set 'noise')"
0 : "Steam metal"
1 : "Wooden clunk"
2 : "Metallic clink"
3 : "In-out"
4 : "Trigger noise (big light switch)"
]
wait(string) : "Delay before reset" : "1"
message(string) : "Message"
noise(string) : "Wav to play if sounds is -1"
]
*/
void() func_button =
{
if (!SUB_ShouldSpawn()) return;
button_sounds();
SetMovedir ();
if (!self.speed)
self.speed = 40;
if (!self.wait)
self.wait = 1;
if (!self.lip)
self.lip = 4;
self.state = STATE_BOTTOM;
if (self.spawnflags & 128)
self.use = func_button_spawn;
else
func_button_spawn();
}
void() func_button_spawn =
{
self.movetype = MOVETYPE_PUSH;
self.solid = SOLID_BSP;
setmodel (self, self.model);
// after setmodel so self.size is set
self.distance = zeroconvertdefault(self.distance,
fabs(self.movedir*self.size) - self.lip);
self.pos1 = self.origin;
self.pos2 = self.pos1 + self.movedir * self.distance;
self.blocked = button_blocked;
self.use = button_use;
self.lock = button_lock;
if (self.health)
{
self.max_health = self.health;
self.th_die = button_killed;
self.takedamage = DAMAGE_YES;
}
else
self.touch = button_touch;
// do proper lock stuff in case the untriggered entity was locked
if (self.customflags & CFL_LOCKED)
button_lock(FALSE);
}
/*
===========================================
SKILL BUTTON
special button that has to react to other skill buttons being pressed,
and the skill cvar changing at the console, and not be stupid about it
supports door fade lighting
hides like a locked button but doesn't count as locked status
registers itself with a global ent as a skill entity, chains itself
startframe checks for cvar change and walks the chain flipping status
===========================================
*/
entity skill_head;
void() skillbutton_go_up =
{
if (self.state == STATE_UP || self.state == STATE_TOP) return;
float spd;
self.state = STATE_UP;
self.frame = 1;
if (self.max_health)
self.takedamage = DAMAGE_NO;
if (initCleanup || time < 1.2)
spd = A_SHITLOAD;
else
{
if (self.noise != string_null)
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
spd = self.speed;
}
SUB_CalcMoveLight(self.pos1, self.pos2, spd, skillbutton_hit_top, FALSE);
SUB_UseTargetsAlt(target);
}
void() skillbutton_hit_top =
{
self.state = STATE_TOP;
if (!SUB_UseTargetsAlt(target2))
SUB_UseTargetsSilent();
bmodel_lightstyle(self, 0);
// special message handling:
// one button will always be set at map start, and we don't want a mystery message
// printing when the start map loads announcing the skill you already have set at
// the console
if (self.enemy && self.enemy.classname == "player")
{
centerprintall(self.message);
self.enemy = world;
}
}
void() skillbutton_go_down =
{
if (self.state == STATE_DOWN || self.state == STATE_BOTTOM) return;
float spd;
self.state = STATE_DOWN;
self.enemy = world;
if (initCleanup || time < 1.2)
spd = A_SHITLOAD;
else
spd = self.speed2;
SUB_CalcMoveLight(self.pos2, self.pos1, spd, skillbutton_hit_bottom, TRUE);
SUB_UseTargetsAlt(target3);
}
void() skillbutton_hit_bottom =
{
self.state = STATE_BOTTOM;
self.frame = 0;
bmodel_lightstyle(self, 1);
if (self.max_health)
{
self.takedamage = DAMAGE_YES;
self.health = self.max_health;
}
SUB_UseTargetsAlt(target4);
}
void() skillbutton_activate =
{
float match;
// skill_str is already set immediately after loading a game, and is always
// set by activating a skill-changing entity, so it's the most accurate
match = ((skill_str == string_null && skill == self.strength) ||
(skill_str != string_null && skill_str == self.netname));
if (match)
skillbutton_go_up();
else
skillbutton_go_down();
}
void() skillbutton_touch =
{
if (!CheckValidTouch()) return;
if (self.state != STATE_BOTTOM) return;
self.enemy = other;
skill_set(self.netname);
}
void() skillbutton_use =
{
self.enemy = activator;
skill_set(self.netname);
}
void() skillbutton_die =
{
self.enemy = damage_attacker;
skill_set(self.netname);
}
/*QUAKED func_button_skill (0 .5 .8) ? EASY NORMAL HARD NIGHTMARE SILENT
Special button for selecting skill level. Will always be pressed when the skill corresponding to the chosen spawnflag is set. Changes its state automatically when other skill buttons are pressed, when trigger_setskills are touched, or when skill is changed live at the console.
"message" override message printed to clients when button is touched or used (or use SILENT spawnflag for no message)
"angle" determines the opening direction
"target" all entities with a matching targetname will be used
"speed" override the default 40 speed
"wait" override the default 1 second wait (-1 = never return)
"lip" override the default 4 pixel lip remaining at end of move
"health" if set, the button must be killed instead of touched
"sounds"
0) steam metal
1) wooden clunk
2) metallic click
3) in-out
4) trigger noise (big light switch)
Alt Target Pattern: 'target' when touched, 'target2' when fully depressed, 'target3' when returning, 'target4' when fully out.
*/
/*FGD
@SolidClass base(Appearflags, Angle, Target, Func, AltTarget) = func_button_skill :
"Special button for selecting skill level. Will always be pressed when the skill corresponding to the chosen spawnflag is set. Changes its state automatically when other skill buttons are pressed, when trigger_setskills are touched, or when skill is changed live at the console.
Alt Target Pattern: 'target' when touched, 'target2' when fully depressed, 'target3' when returning, 'target4' when fully out."
[
spawnflags(Flags) = [
1 : "Easy" : 0
2 : "Normal" : 1
4 : "Hard" : 0
8 : "Nightmaaare" : 0
16 : "No centerprint" : 0
]
speed(integer) : "Speed" : 40
health(integer) : "Health (shootable if > 0)"
lip(integer) : "Lip remaining at end of move" : 4
distance(string) : "Distance to travel (overrides Lip)" : "0.0"
sounds(choices) : "Sounds" =
[
-1 : "None/Custom (set 'noise')"
0 : "Steam metal"
1 : "Wooden clunk"
2 : "Metallic clink"
3 : "In-out"
4 : "Trigger noise (big light switch)"
]
message(string) : "Override skill selected message"
noise(string) : "Wav to play if sounds is -1"
]
*/void() func_button_skill =
{
if (!SUB_ShouldSpawn()) return;
button_sounds();
SetMovedir ();
if (!self.speed)
self.speed = 40;
if (!self.speed2)
self.speed2 = self.speed;
if (!self.lip)
self.lip = 4;
if (skill_head)
self.owner = skill_head;
skill_head = self;
if (self.style || self.switchshadstyle)
{
if (self.style < 0)
{
self.style *= -1;
self.customflags |= CFL_INVLIGHT;
}
bmodel_lightstyle(self, 1);
}
self.state = STATE_BOTTOM;
self.movetype = MOVETYPE_PUSH;
self.solid = SOLID_BSP;
setmodel (self, self.model);
self.distance = zeroconvertdefault(self.distance,
fabs(self.movedir*self.size) - self.lip);
self.pos1 = self.origin;
self.pos2 = self.pos1 + self.movedir * self.distance;
self.blocked = button_blocked;
self.use = skillbutton_use;
if (self.health)
{
self.max_health = self.health;
self.th_die = skillbutton_die;
self.takedamage = DAMAGE_YES;
}
else
self.touch = skillbutton_touch;
if (self.spawnflags & 1)
{
self.strength = 0;
self.netname = "0";
}
else if (self.spawnflags & 4)
{
self.strength = 2;
self.netname = "2";
}
else if (self.spawnflags & 8)
{
self.strength = 3;
self.netname = "3";
}
else // 2 or default
{
self.strength = 1;
self.netname = "1";
}
if (self.spawnflags & 16) // silent
self.message = string_null;
else if (self.message == string_null)
{
if (self.spawnflags & 1)
self.message = "EASY skill selected";
else if (self.spawnflags & 4)
self.message = "HARD skill selected";
else if (self.spawnflags & 8)
self.message = "\bNIGHTMARE\b skill selected";
else // 2 or default
self.message = "NORMAL skill selected";
}
self.think = skillbutton_activate; // assume correct position and set up any related target states
self.nextthink = self.ltime + 0.2;
}