-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathg_newtarg.c
431 lines (368 loc) · 7.49 KB
/
g_newtarg.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
/*
* =======================================================================
*
* Rogue specific targets.
*
* =======================================================================
*/
#include "header/local.h"
/*
* QUAKED target_steam (1 0 0) (-8 -8 -8) (8 8 8)
* Creates a steam effect (particles w/ velocity in a line).
*
* speed = velocity of particles (default 50)
* count = number of particles (default 32)
* sounds = color of particles (default 8 for steam)
* the color range is from this color to this color + 6
* wait = seconds to run before stopping (overrides default
* value derived from func_timer)
*
* best way to use this is to tie it to a func_timer that "pokes"
* it every second (or however long you set the wait time, above)
*
* note that the width of the base is proportional to the speed
* good colors to use:
* 6-9 - varying whites (darker to brighter)
* 224 - sparks
* 176 - blue water
* 80 - brown water
* 208 - slime
* 232 - blood
*/
void
use_target_steam(edict_t *self, edict_t *other, edict_t *activator /* unused */)
{
static int nextid;
vec3_t point;
if (!self)
{
return;
}
if (nextid > 20000)
{
nextid = nextid % 20000;
}
nextid++;
/* automagically set wait from func_timer unless they set it
already, or default to 1000 if not called by a func_timer */
if (!self->wait)
{
if (other)
{
self->wait = other->wait * 1000;
}
else
{
self->wait = 1000;
}
}
if (self->enemy)
{
VectorMA(self->enemy->absmin, 0.5, self->enemy->size, point);
VectorSubtract(point, self->s.origin, self->movedir);
VectorNormalize(self->movedir);
}
VectorMA(self->s.origin, self->plat2flags * 0.5, self->movedir, point);
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_STEAM);
if (self->wait > 100)
{
gi.WriteShort(nextid);
gi.WriteByte(self->count);
gi.WritePosition(self->s.origin);
gi.WriteDir(self->movedir);
gi.WriteByte(self->sounds & 0xff);
gi.WriteShort((short int)(self->plat2flags));
gi.WriteLong((int)(self->wait));
}
else
{
gi.WriteShort((short int)-1);
gi.WriteByte(self->count);
gi.WritePosition(self->s.origin);
gi.WriteDir(self->movedir);
gi.WriteByte(self->sounds & 0xff);
gi.WriteShort((short int)(self->plat2flags));
}
gi.multicast(self->s.origin, MULTICAST_PVS);
}
void
target_steam_start(edict_t *self)
{
edict_t *ent;
if (!self)
{
return;
}
self->use = use_target_steam;
if (self->target)
{
ent = G_Find(NULL, FOFS(targetname), self->target);
if (!ent)
{
gi.dprintf("%s at %s: %s is a bad target\n", self->classname,
vtos(self->s.origin), self->target);
}
self->enemy = ent;
}
else
{
G_SetMovedir(self->s.angles, self->movedir);
}
if (!self->count)
{
self->count = 32;
}
if (!self->plat2flags)
{
self->plat2flags = 75;
}
if (!self->sounds)
{
self->sounds = 8;
}
if (self->wait)
{
self->wait *= 1000; /* we want it in milliseconds, not seconds */
}
/* paranoia is good */
self->sounds &= 0xff;
self->count &= 0xff;
self->svflags = SVF_NOCLIENT;
gi.linkentity(self);
}
void
SP_target_steam(edict_t *self)
{
self->plat2flags = self->speed;
if (self->target)
{
self->think = target_steam_start;
self->nextthink = level.time + 1;
}
else
{
target_steam_start(self);
}
}
void
target_anger_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
{
edict_t *target;
edict_t *t;
if (!self)
{
return;
}
t = NULL;
target = G_Find(t, FOFS(targetname), self->killtarget);
if (target && self->target)
{
/* Make whatever a "good guy" so the monster will try to kill it! */
target->monsterinfo.aiflags |= AI_GOOD_GUY;
target->svflags |= SVF_MONSTER;
target->health = 300;
t = NULL;
while ((t = G_Find(t, FOFS(targetname), self->target)))
{
if (t == self)
{
gi.dprintf("WARNING: entity used itself.\n");
}
else
{
if (t->use)
{
if (t->health < 0)
{
return;
}
t->enemy = target;
t->monsterinfo.aiflags |= AI_TARGET_ANGER;
FoundTarget(t);
}
}
if (!self->inuse)
{
gi.dprintf("entity was removed while using targets\n");
return;
}
}
}
}
/*
* QUAKED target_anger (1 0 0) (-8 -8 -8) (8 8 8)
*
* This trigger will cause an entity to be angry at another entity when a player touches it.
* Target the entity you want to anger, and killtarget the entity you want it to be angry at.
*
* target - entity to piss off
* killtarget - entity to be pissed off at
*/
void
SP_target_anger(edict_t *self)
{
if (!self)
{
return;
}
if (!self->target)
{
gi.dprintf("target_anger without target!\n");
G_FreeEdict(self);
return;
}
if (!self->killtarget)
{
gi.dprintf("target_anger without killtarget!\n");
G_FreeEdict(self);
return;
}
self->use = target_anger_use;
self->svflags = SVF_NOCLIENT;
}
void
target_killplayers_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
{
int i;
edict_t *ent, *player;
if (!self)
{
return;
}
/* kill the players */
for (i = 0; i < game.maxclients; i++)
{
player = &g_edicts[1 + i];
if (!player->inuse)
{
continue;
}
/* nail it */
T_Damage(player, self, self, vec3_origin, self->s.origin, vec3_origin,
100000, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
}
/* kill any visible monsters */
for (ent = g_edicts; ent < &g_edicts[globals.num_edicts]; ent++)
{
if (!ent->inuse)
{
continue;
}
if (ent->health < 1)
{
continue;
}
if (!ent->takedamage)
{
continue;
}
for (i = 0; i < game.maxclients; i++)
{
player = &g_edicts[1 + i];
if (!player->inuse)
{
continue;
}
if (visible(player, ent))
{
T_Damage(ent, self, self, vec3_origin, ent->s.origin, vec3_origin,
ent->health, 0, DAMAGE_NO_PROTECTION, MOD_TELEFRAG);
break;
}
}
}
}
/*
* QUAKED target_killplayers (1 0 0) (-8 -8 -8) (8 8 8)
*
* When triggered, this will kill all the players on the map.
*/
void
SP_target_killplayers(edict_t *self)
{
if (!self)
{
return;
}
self->use = target_killplayers_use;
self->svflags = SVF_NOCLIENT;
}
/*
* QUAKED target_blacklight (1 0 1) (-16 -16 -24) (16 16 24)
*
* Pulsing black light with sphere in the center
*/
void
blacklight_think(edict_t *self)
{
if (!self)
{
return;
}
self->s.angles[0] = rand() % 360;
self->s.angles[1] = rand() % 360;
self->s.angles[2] = rand() % 360;
self->nextthink = level.time + 0.1;
}
void
SP_target_blacklight(edict_t *ent)
{
if (!ent)
{
return;
}
if (deathmatch->value)
{
/* auto-remove for deathmatch */
G_FreeEdict(ent);
return;
}
VectorClear(ent->mins);
VectorClear(ent->maxs);
ent->s.effects |= (EF_TRACKERTRAIL | EF_TRACKER);
ent->think = blacklight_think;
ent->s.modelindex = gi.modelindex("models/items/spawngro2/tris.md2");
ent->s.frame = 1;
ent->nextthink = level.time + 0.1;
gi.linkentity(ent);
}
/*
* QUAKED target_orb (1 0 1) (-16 -16 -24) (16 16 24)
*
* Translucent pulsing orb with speckles
*/
void
orb_think(edict_t *self)
{
if (!self)
{
return;
}
self->s.angles[0] = rand() % 360;
self->s.angles[1] = rand() % 360;
self->s.angles[2] = rand() % 360;
self->nextthink = level.time + 0.1;
}
void
SP_target_orb(edict_t *ent)
{
if (!ent)
{
return;
}
if (deathmatch->value)
{
/* auto-remove for deathmatch */
G_FreeEdict(ent);
return;
}
VectorClear(ent->mins);
VectorClear(ent->maxs);
ent->think = orb_think;
ent->nextthink = level.time + 0.1;
ent->s.modelindex = gi.modelindex("models/items/spawngro2/tris.md2");
ent->s.frame = 2;
ent->s.effects |= EF_SPHERETRANS;
gi.linkentity(ent);
}