-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdwm.c
556 lines (472 loc) · 13.5 KB
/
dwm.c
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
// This file contains the new explosions and some other crap
// I would have put it right in its right place
// But I'm a lazy bastard. Deal with it
#include "g_local.h"
void BecomeNewExplosion (edict_t *ent);
/*
=================
Grenade_Explode
New grenade explosion. Creates ~12 new entities (9 debris, 1 flash, 1 sound + 1 sound per client).
(Id barrel explosion creates 15)
=================
*/
void Grenade_Explode (edict_t *ent)
{
int mod;
// Set up the means of death.
mod = MOD_CLUSTER;
if ((int)fragban->value & WB_CLUSTERGRENADE)
mod |= MOD_NOFRAG;
// do blast damage
T_RadiusDamage(ent, ent->owner, ent->dmg, NULL, ent->dmg_radius, mod);
// shake view
T_ShockWave(ent, 255, 1024);
// let blast move items
T_ShockItems(ent);
// explode and destroy grenade
BecomeNewExplosion (ent);
}
/*
=================
rocket_touch
Grenade explosion + a few glowing trails. Creates ~15 new entities.
=================
*/
void rocket_touch (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
{
int i;
vec3_t org;
float spd;
vec3_t origin;
int mod;
// can't be hit by own rocket
if (other == ent->owner)
return;
// can't hit sky
if (surf && (surf->flags & SURF_SKY))
{
G_FreeEdict (ent);
return;
}
// noise if hits other player
if (ent->owner->client)
PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
// calculate position for the explosion entity
VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
// impact damage
if (other->takedamage)
{
// Set up the means of death.
mod = MOD_ROCKET;
if ((int)fragban->value & WB_ROCKETLAUNCHER)
mod |= MOD_NOFRAG;
T_Damage (other, ent, ent->owner, ent->velocity, ent->s.origin,
plane->normal, ent->dmg, 0, 0, mod);
}
// make some glowing shrapnel
spd = 15.0 * ent->dmg / 200;
for (i = 0; i < 3; i++)
{
org[0] = ent->s.origin[0] + crandom() * ent->size[0];
org[1] = ent->s.origin[1] + crandom() * ent->size[1];
org[2] = ent->s.origin[2] + crandom() * ent->size[2];
ThrowShrapnel4 (ent, "models/objects/debris2/tris.md2", spd, org);
}
make_debris (ent);
mod = MOD_R_SPLASH;
if ((int)fragban->value & WB_ROCKETLAUNCHER)
mod |= MOD_NOFRAG;
T_RadiusDamage(ent, ent->owner, ent->radius_dmg, other, ent->dmg_radius,
mod);
T_ShockItems(ent);
T_ShockWave(ent, 255, 1024);
BecomeNewExplosion (ent);
}
/*
=================
make_debris
=================
*/
void make_debris (edict_t *ent)
{
vec3_t org;
vec3_t origin;
float spd;
// calculate position for the explosion entity
VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
// make a few big chunks
spd = .5 * (float)ent->dmg / 200.0;
org[0] = ent->s.origin[0] + crandom() * ent->size[0];
org[1] = ent->s.origin[1] + crandom() * ent->size[1];
org[2] = ent->s.origin[2] + crandom() * ent->size[2];
ThrowShrapnel (ent, "models/objects/debris1/tris.md2", spd, org);
spd = 1.5 * (float)ent->dmg / 200.0;
VectorCopy (ent->absmin, org);
ThrowShrapnel (ent, "models/objects/debris2/tris.md2", spd, org);
spd = 1.5 * (float)ent->dmg / 200.0;
VectorCopy (ent->absmin, org);
ThrowShrapnel (ent, "models/objects/debris3/tris.md2", spd, org);
}
/*
============
T_ShockWave
Knocks view around a bit. Based on T_RadiusDamage.
============
*/
void T_ShockWave (edict_t *inflictor, float damage, float radius)
{
float points;
edict_t *ent = NULL;
vec3_t v;
vec3_t dir;
float SHOCK_TIME = 0.1;
while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL)
{
if (!ent->takedamage)
continue;
if (!ent->client)
continue;
VectorAdd (ent->mins, ent->maxs, v);
VectorMA (ent->s.origin, 0.5, v, v);
VectorSubtract (inflictor->s.origin, v, v);
points = .5*(damage - 0.5 * VectorLength (v));
if (points < .5)
points = .5;
if (points > 10)
points = 10;
if (points > 0)
{
VectorSubtract (ent->s.origin, inflictor->s.origin, dir);
ent->client->v_dmg_pitch = -points;
ent->client->v_dmg_roll = 0;
ent->client->v_dmg_time = level.time + SHOCK_TIME;
ent->client->kick_origin[2] = -points*4;
}
}
}
/*
============
T_ShockItems
Lets explosions move items. Based on T_RadiusDamage.
TODO: Reorient items after coming to rest?
============
*/
void T_ShockItems (edict_t *inflictor)
{
float points;
edict_t *ent = NULL;
vec3_t v;
vec3_t dir;
vec3_t kvel;
float mass;
float radius=255;
float damage=100;
while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL)
{
if (ent->item
&& strcmp (ent->classname, "info_player_deathmatch") != 0)
{
VectorAdd (ent->mins, ent->maxs, v);
VectorMA (ent->s.origin, 0.5, v, v);
VectorSubtract (inflictor->s.origin, v, v);
points = damage - 0.5 * VectorLength (v);
if (ent->mass < 25)
mass = 25;
else
mass = ent->mass;
if (points > 0)
{
VectorSubtract (ent->s.origin, inflictor->s.origin, dir);
ent->movetype = MOVETYPE_BOUNCE;
// any problem w/leaving this changed?
VectorScale (dir, 3.0 * (float)points / mass, kvel);
VectorAdd (ent->velocity, kvel, ent->velocity);
if (!(ent->svflags & SVF_MONSTER))
VectorAdd (ent->avelocity, 1.5*kvel, ent->avelocity);
//TODO: check groundentity & lower s.origin to keep objects from sticking to floor?
ent->velocity[2]+=10;
gi.linkentity (ent);
}
}
}
}
/*
=================
BecomeNewExplosion
=================
*/
void BecomeNewExplosion (edict_t *ent)
{
vec3_t origin;
// calculate position for the explosion entity
VectorMA (ent->s.origin, -0.02, ent->velocity, origin);
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_EXPLOSION1);
gi.WritePosition (ent->s.origin);
gi.multicast (ent->s.origin, MULTICAST_PVS);
// send flash & bang
gi.WriteByte (svc_muzzleflash);
gi.WriteShort (ent-g_edicts);
// any way to get a mz flash without hearing the weapon?
gi.WriteByte (MZ_CHAINGUN2);
gi.multicast (ent->s.origin, MULTICAST_PVS);
// any other way to make this loud enough?
BigBang (ent);
// destroy object
G_FreeEdict (ent);
}
/*
=============
isvisible
This is the ai.c visible function
=============
*/
qboolean isvisible (edict_t *self, edict_t *other)
{
vec3_t spot1;
vec3_t spot2;
trace_t trace;
VectorCopy (self->s.origin, spot1);
spot1[2] += self->viewheight;
VectorCopy (other->s.origin, spot2);
spot2[2] += other->viewheight;
trace = gi.trace (spot1, vec3_origin, vec3_origin, spot2, self, MASK_OPAQUE);
if (trace.fraction == 1.0)
return true;
return false;
}
/*
=================
BigBang
Loud bang.
=================
*/
void BigBang (edict_t *ent)
{
int i;
edict_t *ear;
float radius=1024;
vec3_t d;
gi.sound (ent, CHAN_ITEM, gi.soundindex ("weapons/rocklx1a.wav"), 1, ATTN_NORM, 0);
// Unfortunately, this sounds weak, so check each client to see if
// it is within the blast radius or in line of sight; if so,
// send each client a loud ATTN_STATIC bang
ear = &g_edicts[0];
for (i=0 ; i<globals.num_edicts ; i++, ear++)
{
if (!ear->inuse)
continue;
if (!ear->client)
continue;
VectorSubtract (ear->s.origin, ent->s.origin, d);
if ((VectorLength(d) < radius) | (isvisible(ent, ear)))
gi.sound (ear, CHAN_VOICE, gi.soundindex ("weapons/rocklx1a.wav"), 1, ATTN_STATIC, 0);
}
}
/*
=================
ThrowShrapnel
This is just ThrowDebris with EF_GRENADE set.
Note: if debris is created before calling T_Damage,
setting DAMAGE_YES will give an orange splash effect.
=================
*/
void ThrowShrapnel (edict_t *self, char *modelname, float speed, vec3_t origin)
{
edict_t *chunk;
vec3_t v;
chunk = G_Spawn();
VectorCopy (origin, chunk->s.origin);
gi.setmodel (chunk, modelname);
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 + 100 * crandom();
VectorMA (self->velocity, speed, v, chunk->velocity);
chunk->movetype = MOVETYPE_BOUNCE;
chunk->solid = SOLID_NOT;
chunk->avelocity[0] = random()*600;
chunk->avelocity[1] = random()*600;
chunk->avelocity[2] = random()*600;
chunk->think = G_FreeEdict;
chunk->nextthink = level.time + 5 + random()* 5;
chunk->s.frame = 0;
chunk->flags = 0;
chunk->classname = "debris";
chunk->takedamage = DAMAGE_NO;
chunk->die = misc_die;
chunk->s.effects |= EF_GRENADE;
gi.linkentity (chunk);
}
/*
=================
ThrowShrapnel2
Less persistent
=================
*/
void ThrowShrapnel2 (edict_t *self, char *modelname, float speed, vec3_t origin)
{
edict_t *chunk;
vec3_t v;
chunk = G_Spawn();
VectorCopy (origin, chunk->s.origin);
gi.setmodel (chunk, modelname);
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 * crandom();
VectorMA (self->velocity, speed, v, chunk->velocity);
chunk->movetype = MOVETYPE_BOUNCE;
chunk->solid = SOLID_NOT;
chunk->avelocity[0] = random()*600;
chunk->avelocity[1] = random()*600;
chunk->avelocity[2] = random()*600;
chunk->think = G_FreeEdict;
chunk->nextthink = level.time + .5 + random()*.5;
chunk->s.frame = 0;
chunk->flags = 0;
chunk->classname = "debris";
chunk->takedamage = DAMAGE_NO;
chunk->die = misc_die;
chunk->s.effects |= EF_GRENADE;
gi.linkentity (chunk);
}
/*
=================
ThrowShrapnel3
Least persistent
=================
*/
void ThrowShrapnel3 (edict_t *self, char *modelname, float speed, vec3_t origin)
{
edict_t *chunk;
vec3_t v;
chunk = G_Spawn();
VectorCopy (origin, chunk->s.origin);
gi.setmodel (chunk, modelname);
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 * crandom();
VectorMA (self->velocity, speed, v, chunk->velocity);
chunk->movetype = MOVETYPE_BOUNCE;
chunk->solid = SOLID_NOT;
chunk->avelocity[0] = random()*600;
chunk->avelocity[1] = random()*600;
chunk->avelocity[2] = random()*600;
chunk->think = G_FreeEdict;
chunk->nextthink = level.time + random()*.3;
chunk->s.frame = 0;
chunk->flags = 0;
chunk->classname = "debris";
chunk->takedamage = DAMAGE_NO;
chunk->die = misc_die;
chunk->s.effects |= EF_GRENADE;
gi.linkentity (chunk);
}
/*
=================
ThrowShrapnel4
Medium persistence with glowing trail effect
=================
*/
void ThrowShrapnel4 (edict_t *self, char *modelname, float speed, vec3_t origin)
{
edict_t *chunk;
vec3_t v;
chunk = G_Spawn();
VectorCopy (origin, chunk->s.origin);
gi.setmodel (chunk, modelname);
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 * crandom();
VectorMA (self->velocity, speed, v, chunk->velocity);
chunk->movetype = MOVETYPE_BOUNCE;
chunk->solid = SOLID_NOT;
chunk->avelocity[0] = random()*600;
chunk->avelocity[1] = random()*600;
chunk->avelocity[2] = random()*600;
chunk->think = G_FreeEdict;
chunk->nextthink = level.time + random()*2;
chunk->s.frame = 0;
chunk->flags = 0;
chunk->classname = "debris";
chunk->takedamage = DAMAGE_NO;
chunk->die = misc_die;
chunk->s.effects |= EF_GRENADE | EF_ROCKET;
gi.linkentity (chunk);
}
/*
=================
barrel_explode
Added ShockItems, ShockWave, changed
some ThrowDebris to ThrowShrapnel
=================
*/
void barrel_explode (edict_t *self)
{
vec3_t org;
float spd;
vec3_t save;
int i;
T_RadiusDamage (self, self->activator, self->dmg, NULL, self->dmg+40, MOD_BARREL);
T_ShockItems(self);
T_ShockWave(self, 255, 1024);
VectorCopy (self->s.origin, save);
VectorMA (self->absmin, 0.5, self->size, self->s.origin);
// a few big chunks
spd = 1.5 * (float)self->dmg / 200.0;
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
// bottom corners
spd = 1.75 * (float)self->dmg / 200.0;
VectorCopy (self->absmin, org);
ThrowShrapnel (self, "models/objects/debris3/tris.md2", spd, org);
VectorCopy (self->absmin, org);
org[0] += self->size[0];
ThrowShrapnel (self, "models/objects/debris3/tris.md2", spd, org);
VectorCopy (self->absmin, org);
org[1] += self->size[1];
ThrowShrapnel (self, "models/objects/debris3/tris.md2", spd, org);
VectorCopy (self->absmin, org);
org[0] += self->size[0];
org[1] += self->size[1];
ThrowShrapnel (self, "models/objects/debris3/tris.md2", spd, org);
// a bunch of little chunks
spd = 10 * self->dmg / 200;
for (i = 0; i < 8; i++)
{
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowShrapnel3 (self, "models/objects/debris2/tris.md2", spd, org);
}
VectorCopy (save, self->s.origin);
if (self->groundentity)
BecomeExplosion2 (self);
else
BecomeExplosion1 (self);
}
/*
=================
target_explosion_explode
Added ShockWave
=================
*/
void target_explosion_explode (edict_t *self)
{
float save;
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_EXPLOSION1);
gi.WritePosition (self->s.origin);
gi.multicast (self->s.origin, MULTICAST_PHS);
T_RadiusDamage (self, self->activator, self->dmg, NULL, self->dmg+40, MOD_UNKNOWN);
T_ShockWave(self, 255, 1024);
save = self->delay;
self->delay = 0;
G_UseTargets (self, self->activator);
self->delay = save;
}