This repository was archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg_newfnc.c
456 lines (382 loc) · 11.1 KB
/
g_newfnc.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
#include "g_local.h"
//void plat_CalcMove (edict_t *ent, vec3_t dest, void(*func)(edict_t*));
void fd_secret_move1(edict_t *self);
void fd_secret_move2(edict_t *self);
void fd_secret_move3(edict_t *self);
void fd_secret_move4(edict_t *self);
void fd_secret_move5(edict_t *self);
void fd_secret_move6(edict_t *self);
void fd_secret_done(edict_t *self);
/*
=============================================================================
SECRET DOORS
=============================================================================
*/
#define SEC_OPEN_ONCE 1 // stays open
#define SEC_1ST_LEFT 2 // 1st move is left of arrow
#define SEC_1ST_DOWN 4 // 1st move is down from arrow
#define SEC_NO_SHOOT 8 // only opened by trigger
#define SEC_YES_SHOOT 16 // shootable even if targeted
#define SEC_MOVE_RIGHT 32
#define SEC_MOVE_FORWARD 64
#define STATE_TOP 0
#define STATE_BOTTOM 1
#define STATE_UP 2
#define STATE_DOWN 3
#define STATE_LOWEST 4
void fd_secret_use (edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *ent;
// gi.dprintf("fd_secret_use\n");
if (self->flags & FL_TEAMSLAVE)
return;
// trigger all paired doors
for (ent = self ; ent ; ent = ent->teamchain)
{
if (self->moveinfo.state == STATE_LOWEST)
{
ent->moveinfo.state = STATE_DOWN;
Move_Calc(ent, ent->pos1, fd_secret_move1);
}
else if (self->moveinfo.state == STATE_TOP) //Knightmare added
{
self->moveinfo.state = STATE_UP;
Move_Calc(self, self->pos1, fd_secret_move5);
}
}
}
void fd_secret_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
// gi.dprintf("fd_secret_killed\n");
self->health = self->max_health;
self->takedamage = DAMAGE_NO;
if (self->flags & FL_TEAMSLAVE && self->teammaster && self->teammaster->takedamage != DAMAGE_NO)
fd_secret_killed (self->teammaster, inflictor, attacker, damage, point);
else
fd_secret_use (self, inflictor, attacker);
}
// Wait after first movement...
void fd_secret_move1(edict_t *self)
{
// gi.dprintf("fd_secret_move1\n");
self->nextthink = level.time + 1.0;
self->think = fd_secret_move2;
self->moveinfo.state = STATE_BOTTOM;
}
// Start moving sideways w/sound...
void fd_secret_move2(edict_t *self)
{
// gi.dprintf("fd_secret_move2\n");
self->moveinfo.state = STATE_UP;
Move_Calc(self, self->pos2, fd_secret_move3);
}
// Wait here until time to go back...
void fd_secret_move3(edict_t *self)
{
// gi.dprintf("fd_secret_move3\n");
if (!(self->spawnflags & SEC_OPEN_ONCE))
{
self->nextthink = level.time + self->wait;
self->think = fd_secret_move4;
}
self->moveinfo.state = STATE_TOP;
}
// Move backward...
void fd_secret_move4(edict_t *self)
{
// gi.dprintf("fd_secret_move4\n");
self->moveinfo.state = STATE_UP;
Move_Calc(self, self->pos1, fd_secret_move5);
}
// Wait 1 second...
void fd_secret_move5(edict_t *self)
{
// gi.dprintf("fd_secret_move5\n");
self->nextthink = level.time + 1.0;
self->think = fd_secret_move6;
self->moveinfo.state = STATE_BOTTOM;
}
void fd_secret_move6(edict_t *self)
{
// gi.dprintf("fd_secret_move6\n");
self->moveinfo.state = STATE_DOWN;
Move_Calc(self, self->pos0, fd_secret_done);
}
void fd_secret_done(edict_t *self)
{
// gi.dprintf("fd_secret_done\n");
if (!self->targetname || self->spawnflags & SEC_YES_SHOOT)
{
self->health = 1;
self->takedamage = DAMAGE_YES;
self->die = fd_secret_killed;
}
self->moveinfo.state = STATE_LOWEST;
}
void secret_blocked(edict_t *self, edict_t *other)
{
if (!(self->flags & FL_TEAMSLAVE))
T_Damage (other, self, self, self->pos0, other->s.origin, self->pos0, self->dmg, 0, 0, MOD_CRUSH);
// if (time < self->attack_finished)
// return;
// self->attack_finished = time + 0.5;
// T_Damage (other, self, self, self->dmg);
}
/*
================
secret_touch
Prints messages
================
*/
void secret_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other->health <= 0)
return;
if (!(other->client))
return;
if (self->monsterinfo.attack_finished > level.time)
return;
self->monsterinfo.attack_finished = level.time + 2;
if (self->message)
{
gi.centerprintf (other, self->message);
// fixme - put this sound back??
// gi.sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM);
}
}
/*QUAKED func_door_secret2 (0 .5 .8) ? OPEN_ONCE 1st_LEFT 1st_DOWN NO_SHOOT ALWAYS_SHOOT SLIDE_RIGHT SLIDE_FORWARD
Basic secret door. Slides back, then to the left. Angle determines direction.
FLAGS:
OPEN_ONCE = Stay open, never close
1st_LEFT = 1st move is left/right of arrow
1st_DOWN = 1st move is forwards/backwards
NO_SHOOT = not implemented yet
ALWAYS_SHOOT = even if targeted, keep shootable
SLIDE_RIGHT = the sideways move will be to right of arrow
SLIDE_FORWARD = the to/fro move will be forward
VALUES:
wait = # of seconds before coming back (5 default)
dmg = damage to inflict when blocked (2 default)
width- override how far the door pops out
length- override how far the door slides
*/
void SP_func_door_secret2 (edict_t *ent)
{
vec3_t forward, right, up;
// float lrSize, fbSize;
ent->class_id = ENTITY_FUNC_DOOR_SECRET2;
ent->moveinfo.sound_start = gi.soundindex ("doors/dr1_strt.wav");
ent->moveinfo.sound_middle = gi.soundindex ("doors/dr1_mid.wav");
ent->moveinfo.sound_end = gi.soundindex ("doors/dr1_end.wav");
if (!ent->dmg)
ent->dmg = 2;
AngleVectors(ent->s.angles, forward, right, up);
VectorCopy(ent->s.origin, ent->pos0);
VectorCopy(ent->s.angles, ent->move_angles);
G_SetMovedir (ent->s.angles, ent->movedir);
ent->movetype = MOVETYPE_PUSH;
ent->solid = SOLID_BSP;
gi.setmodel (ent, ent->model);
if (ent->move_angles[1] == 0 || ent->move_angles[1] == 180)
{
if (!ent->width)
ent->width = ent->size[1] - 2; //was lrSize
if (!ent->length)
ent->length = ent->size[0] - 2; //was fbSize
}
else if(ent->move_angles[1] == 90 || ent->move_angles[1] == 270)
{
if (!ent->width)
ent->width = ent->size[0] - 2; //was lrSize
if (!ent->length)
ent->length = ent->size[1] - 2; //was fbSize
}
else
gi.dprintf("Secret door not at 0,90,180,270!\n");
if (ent->spawnflags & SEC_MOVE_FORWARD)
VectorScale(forward, ent->length, forward);
else
VectorScale(forward, ent->length * -1 , forward);
if (ent->spawnflags & SEC_MOVE_RIGHT)
VectorScale(right, ent->width, right);
else
VectorScale(right, ent->width * -1, right);
if(ent->spawnflags & SEC_1ST_DOWN)
{
VectorAdd(ent->s.origin, forward, ent->pos1); //was ent->moveinfo.start_origin
VectorAdd(ent->pos1, right, ent->pos2); //was ent->moveinfo.end_origin
}
else
{
VectorAdd(ent->s.origin, right, ent->pos1); //was ent->moveinfo.start_origin
VectorAdd(ent->pos1, forward, ent->pos2); //was ent->moveinfo.end_origin
}
ent->touch = secret_touch;
ent->blocked = secret_blocked;
ent->use = fd_secret_use;
ent->moveinfo.speed = 50;
ent->moveinfo.accel = 50;
ent->moveinfo.decel = 50;
ent->moveinfo.state = STATE_LOWEST;
if (!ent->targetname || ent->spawnflags & SEC_YES_SHOOT)
{
ent->health = 1;
ent->max_health = ent->health;
ent->takedamage = DAMAGE_YES;
ent->die = fd_secret_killed;
}
if (!ent->wait)
ent->wait = 5; // 5 seconds before closing
ent->postthink = train_move_children; //Knightmare- now supports movewith
gi.linkentity(ent);
}
// ==================================================
#define FWALL_START_ON 1
void force_wall_think(edict_t *self)
{
if (self->solid == SOLID_BSP)
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_FORCEWALL);
gi.WritePosition (self->pos1);
gi.WritePosition (self->pos2);
gi.WriteByte (self->style);
gi.multicast (self->offset, MULTICAST_PVS);
}
self->think = force_wall_think;
self->nextthink = level.time + 0.1;
}
void force_wall_use (edict_t *self, edict_t *other, edict_t *activator)
{
if (self->solid == SOLID_NOT)
{
self->wait = 0;
self->think = force_wall_think;
self->nextthink = level.time + FRAMETIME;
self->solid = SOLID_BSP;
KillBox(self); // Is this appropriate?
gi.linkentity (self);
}
else
{
self->wait = 1;
self->think = NULL;
self->nextthink = 0;
self->solid = SOLID_NOT;
gi.linkentity( self );
}
}
void force_wall_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (!self->dmg)
return;
if (!other->takedamage)
return;
if (self->timestamp > level.time)
return;
self->timestamp = level.time + 1;
if (!(self->spawnflags & 4))
{
if ((level.framenum % 10) == 0)
gi.sound (other, CHAN_AUTO, self->noise_index, 1, ATTN_NORM, 0);
}
T_Damage (other, self, self, self->pos0, other->s.origin, self->pos0, self->dmg, self->dmg, 0, MOD_TRIGGER_HURT);
}
/*QUAKED func_force_wall (1 0 1) ? START_ON
A vertical particle force wall. Turns on and solid when triggered.
If someone is in the force wall when it turns on, they're telefragged.
START_ON - forcewall begins activated. triggering will turn it off.
style - color of particles to use.
0: black
208: green
215: white
220: yellow
240: red
241: blue
224: orange
*/
void SP_func_force_wall(edict_t *ent)
{
ent->class_id = ENTITY_FUNC_FORCE_WALL;
gi.setmodel (ent, ent->model);
ent->offset[0] = (ent->absmax[0] + ent->absmin[0]) / 2;
ent->offset[1] = (ent->absmax[1] + ent->absmin[1]) / 2;
ent->offset[2] = (ent->absmax[2] + ent->absmin[2]) / 2;
ent->pos1[2] = ent->absmax[2];
ent->pos2[2] = ent->absmax[2];
if(ent->size[0] > ent->size[1])
{
ent->pos1[0] = ent->absmin[0];
ent->pos2[0] = ent->absmax[0];
ent->pos1[1] = ent->offset[1];
ent->pos2[1] = ent->offset[1];
}
else
{
ent->pos1[0] = ent->offset[0];
ent->pos2[0] = ent->offset[0];
ent->pos1[1] = ent->absmin[1];
ent->pos2[1] = ent->absmax[1];
}
if(!ent->style)
ent->style = 208;
ent->movetype = MOVETYPE_NONE;
ent->wait = 1;
if(ent->spawnflags & FWALL_START_ON)
{
ent->solid = SOLID_BSP;
ent->think = force_wall_think;
ent->nextthink = level.time + FRAMETIME;
}
else
ent->solid = SOLID_NOT;
ent->use = force_wall_use;
ent->touch = force_wall_touch;
ent->svflags = SVF_NOCLIENT;
gi.linkentity(ent);
}
/*======================================================================================*/
/*QUAKED func_dm_wall (1 0 1) ?
When the number of clients that connect to the server is less than
the value in maxclient, the wall will appear and cut off areas of
the map. This only applies when the level is first loaded, so if
2 players start, the map will be sized to 2 player. If another 16
connect then it'll be a bit frantic (haha)
count - number of clients before disappearing
*/
/*
FIXME : Make a spawnflag to check if the designer wants to use an effect.
actually make this a point entity so ANY entity can be set up like this.
i.e. one could target func_walls, weapons, ammo and health and have a different
setup depending on the number of clients conncted.
*/
void SP_func_dm_wall (edict_t *self)
{
qboolean spawn = false;
//if it was lower than this something went very wrong.
if (self->count > 2)
{
if (self->count > game.maxclients)
{
spawn = true;
}
}
else
{
gi.dprintf("func_dm_wall with a count less than 2 at %s");
G_FreeEdict(self);
return;
}
if (spawn)
{
self->movetype = MOVETYPE_PUSH;
gi.setmodel (self, self->model);
self->solid = SOLID_BSP;
gi.linkentity (self);
}
else
{
G_FreeEdict(self);
return;
}
}