-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspawn.qc
823 lines (667 loc) · 16.4 KB
/
spawn.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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
struct spawn_field_t
{
string key;
string field;
bool ignore;
};
API_FUNC static spawn_field_t spawn_fields[] =
{
{ "classname" },
{ "model" },
{ "spawnflags" },
{ "speed" },
{ "accel" },
{ "decel" },
{ "target" },
{ "targetname" },
{ "pathtarget" },
{ "deathtarget" },
{ "killtarget" },
{ "combattarget" },
{ "message" },
{ "team" },
{ "wait" },
{ "delay" },
{ "random", "rand" },
{ "move_origin" },
{ "move_angles" },
{ "style" },
{ "count" },
{ "health" },
{ "sounds" },
{ "dmg" },
{ "mass" },
{ "volume" },
{ "attenuation" },
{ "map" },
{ "origin", "s.origin" },
{ "angles", "s.angles" },
{ "light", "", true },
};
API_FUNC static void(entity ent) SP_func_group =
{
G_FreeEdict(ent);
}
static bool(string key, string value, entity ent) ED_ParseField =
{
for (int i = 0; i < spawn_fields.length; i++)
{
if (!striequals(spawn_fields[i].key, key))
continue;
if (!spawn_fields[i].ignore)
entity_key_parse(ent, spawn_fields[i].field ?: spawn_fields[i].key, value);
return true;
}
return false;
};
static bool(string key, string value) ED_ParseSpawnTemp =
{
return struct_key_parse("st", key, value);
};
static inline void() ClearSpawnTemp =
{
memclear(&st, sizeof(st));
}
static void(string entities, inout int entities_offset, entity ent) ED_ParseEdict =
{
bool init = false;
// go through all the dictionary pairs
while (true)
{
// parse key
string key = strtok(entities, entities_offset);
if (key == "}")
break;
else if (strempty(key))
gi.error(__FUNC__": EOF without closing brace");
init = true;
// keynames with a leading underscore are used for utility comments,
// and are immediately discarded by quake
if (strat(key, 0) == '_')
{
strtok(entities, entities_offset);
continue;
}
string value = strtok(entities, entities_offset);
if (!ED_ParseField(key, value, ent) && !ED_ParseSpawnTemp(key, value))
gi.dprintf(__FUNC__": %s is not a field\n", key);
}
// QC-specific hack to support .angle
if (st.angle)
ent.s.angles[YAW] = st.angle;
if (!init)
G_FreeEdict(ent);
};
// these are only used by the spawn function
#ifdef SINGLE_PLAYER
const int SPAWNFLAG_NOT_EASY = 0x00000100;
const int SPAWNFLAG_NOT_MEDIUM = 0x00000200;
const int SPAWNFLAG_NOT_HARD = 0x00000400;
#endif
const int SPAWNFLAG_NOT_DEATHMATCH = 0x00000800;
#ifdef SINGLE_PLAYER
const int SPAWNFLAG_NOT_COOP = 0x00001000;
#endif
const int SPAWNFLAG_NOT_MASK = 0x00001F00; // mask of all of the NOT_ flags
/*
===============
ED_CallSpawn
Finds the spawn function for the entity and calls it
===============
*/
bool(entity ent) ED_CallSpawn =
{
if (!ent.classname)
{
gi.dprintf("ED_CallSpawn: NULL classname\n");
G_FreeEdict(ent);
return false;
}
#ifdef GROUND_ZERO
ent.gravityVector = MOVEDIR_DOWN;
if (ent.classname == "weapon_nailgun")
ent.classname = GetItemByIndex(ITEM_ETF_RIFLE)->classname;
if (ent.classname == "ammo_nails")
ent.classname = GetItemByIndex(ITEM_FLECHETTES)->classname;
if (ent.classname == "weapon_heatbeam")
ent.classname = GetItemByIndex(ITEM_PLASMA_BEAM)->classname;
#endif
// check item spawn functions
gitem_t *itemid = FindItemByClassname(ent.classname);
if (itemid)
{
SpawnItem(ent, itemid);
return true;
}
void(entity) spawnfunc = func_get(va("SP_%s", ent.classname));
if (spawnfunc)
{
spawnfunc(ent);
return true;
}
gi.dprintf("%s doesn't have a spawn function\n", ent.classname);
G_FreeEdict(ent);
return false;
}
/*
================
G_FindTeams
Chain together all entities with a matching team field.
All but the first will have the FL_TEAMSLAVE flag set.
All but the last will have the teamchain field set to the next one
================
*/
// Paril: it took me a while to sus out what exactly this function was for in
// Ground Zero, but basically it was to fix their mappers' bad teams. Maybe they
// were broken later on or grouped wrong and it caused issues? Anyways,
// basically it re-ordered teams with trains so that a train was always
// at the front and synced up their speeds.
static void G_FixTeams (void)
{
int c = 0;
for (int i = 1; i < globals.num_edicts; i++)
{
entity e = itoe(i);
if (!e.teammaster)
continue;
entity master = e.teammaster;
// already a train, so don't worry about us
if (master.classname == "func_train")
continue;
entity first_train = world;
for (entity e2 = master; e2; e2 = e2.teamchain)
{
if (e2.classname == "func_train")
{
first_train = e2;
break;
}
}
// no train in this team
if (!first_train)
continue;
c++;
entity prev = world;
// got one! we have to reposition this train to be the master now.
// swap all of the masters out, and store the guy before the train
for (entity e2 = master; e2; e2 = e2.teamchain)
{
entity next = e2.teamchain;
e2.teammaster = first_train;
// copy over movetype and speed
e2.movetype = MOVETYPE_PUSH;
e2.speed = first_train.speed;
// reached the guy before first_train
if (e2.teamchain == first_train)
prev = e2;
}
// shim us in
if (!prev)
gi.error("wat");
// master = old teammaster
// prev = guy before first_train
// first_train = first.. train
prev.teamchain = master;
entity old_master_next = master.teamchain;
master.teamchain = first_train.teamchain;
first_train.teamchain = old_master_next;
// remove our slave flag
first_train.flags &= ~FL_TEAMSLAVE;
// give the old master the flag
master.flags |= FL_TEAMSLAVE;
}
gi.dprintf ("%i teams repaired\n", c);
}
static void() G_FindTeams =
{
entity e, e2, chain;
int i, j;
int c, c2;
c = 0;
c2 = 0;
for (i = 1; i < globals.num_edicts; i++)
{
e = itoe(i);
if (!e.inuse)
continue;
if (!e.team)
continue;
if (e.flags & FL_TEAMSLAVE)
continue;
chain = e;
e.teammaster = e;
e.teamchain = 0;
c++;
c2++;
for (j = i + 1; j < globals.num_edicts ; j++)
{
e2 = itoe(j);
if (!e2.inuse)
continue;
if (!e2.team)
continue;
if (e2.flags & FL_TEAMSLAVE)
continue;
if (e.team == e2.team) {
c2++;
chain.teamchain = e2;
e2.teammaster = e;
e2.teamchain = 0;
chain = e2;
e2.flags |= FL_TEAMSLAVE;
}
}
}
gi.dprintf("%i teams with %i entities\n", c, c2);
G_FixTeams();
}
/*
==============
SpawnEntities
Creates a server's entity / program execution context by
parsing textual entity definitions out of an ent file.
==============
*/
void PreSpawnEntities()
{
#ifdef SINGLE_PLAYER
SaveClientData();
#endif
}
void(string mapname, string entities, string spawnpoint) SpawnEntities =
{
int entities_offset = 0;
#ifdef SINGLE_PLAYER
int skill_level = skill.intVal;
if (skill_level < 0)
skill_level = 0;
if (skill_level > 3)
skill_level = 3;
if (skill.intVal != skill_level)
gi.cvar_forceset("skill", itos(skill_level));
#endif
memclear(&level, sizeof(level));
level.mapname = mapname;
game.spawnpoint = spawnpoint;
entity ent = world;
int inhibit = 0;
// parse ents
while (1)
{
string token = strtok(entities, entities_offset);
if (entities_offset < 0)
break;
if (token != "{")
gi.error(__FUNC__": found %s when expecting {", token);
if (ent.inuse)
ent = G_Spawn();
else
{
G_FreeEdict(ent);
G_InitEdict(ent);
}
ED_ParseEdict(entities, entities_offset, ent);
#ifdef SINGLE_PLAYER
// yet another map hack
if (striequals(level.mapname, "command") && striequals(ent.classname, "trigger_once") && striequals(ent.model, "*27"))
ent.spawnflags &= ~SPAWNFLAG_NOT_HARD;
#endif
// remove things (except the world) from different skill levels or deathmatch
if (ent != world)
{
#ifdef SINGLE_PLAYER
if (deathmatch.intVal)
{
#endif
if (ent.spawnflags & SPAWNFLAG_NOT_DEATHMATCH)
{
G_FreeEdict(ent);
inhibit++;
continue;
}
#ifdef SINGLE_PLAYER
}
else
{
#ifdef GROUND_ZERO
if (coop.intVal && (ent.spawnflags & SPAWNFLAG_NOT_COOP))
{
G_FreeEdict (ent);
inhibit++;
continue;
}
// TODO: there was a block here about (EASY | MED | HARD) meaning that it's coop-only.
// is this true in only rogue maps?
#endif
if (((skill_level == 0) && (ent.spawnflags & SPAWNFLAG_NOT_EASY)) ||
((skill_level == 1) && (ent.spawnflags & SPAWNFLAG_NOT_MEDIUM)) ||
(((skill_level == 2) || (skill_level == 3)) && (ent.spawnflags & SPAWNFLAG_NOT_HARD)))
{
G_FreeEdict(ent);
inhibit++;
continue;
}
}
#endif
ent.spawnflags &= ~SPAWNFLAG_NOT_MASK;
}
if (!ED_CallSpawn(ent))
inhibit++;
#ifdef GROUND_ZERO
else
ent.s.renderfx |= RF_IR_VISIBLE;
#endif
ClearSpawnTemp();
}
ClearSpawnTemp();
gi.dprintf("%i entities inhibited\n", inhibit);
G_FindTeams();
#ifdef SINGLE_PLAYER
PlayerTrail_Init();
#ifdef GROUND_ZERO
if (!deathmatch.intVal)
InitHintPaths();
#endif
#endif
#ifdef CTF
CTFSpawn();
#endif
};
void() PostSpawnEntities =
{
};
#ifdef SINGLE_PLAYER
//===================================================================
PROGS_LOCAL_STATIC const string single_statusbar =
"yb -24 "
// health
"xv 0 "
"hnum "
"xv 50 "
"pic 0 "
// ammo
"if 2 "
" xv 100 "
" anum "
" xv 150 "
" pic 2 "
"endif "
// armor
"if 4 "
" xv 200 "
" rnum "
" xv 250 "
" pic 4 "
"endif "
// selected item
"if 6 "
" xv 296 "
" pic 6 "
"endif "
"yb -50 "
// picked up item
"if 7 "
" xv 0 "
" pic 7 "
" xv 26 "
" yb -42 "
" stat_string 8 "
" yb -50 "
"endif "
// timer
"if 9 "
" xv 262 "
" num 2 10 "
" xv 296 "
" pic 9 "
"endif "
// help / weapon icon
"if 11 "
" xv 148 "
" pic 11 "
"endif "
;
#endif
PROGS_LOCAL_STATIC const string dm_statusbar =
"yb -24 "
// health
"xv 0 "
"hnum "
"xv 50 "
"pic 0 "
// ammo
"if 2 "
" xv 100 "
" anum "
" xv 150 "
" pic 2 "
"endif "
// armor
"if 4 "
" xv 200 "
" rnum "
" xv 250 "
" pic 4 "
"endif "
// selected item
"if 6 "
" xv 296 "
" pic 6 "
"endif "
"yb -50 "
// picked up item
"if 7 "
" xv 0 "
" pic 7 "
" xv 26 "
" yb -42 "
" stat_string 8 "
" yb -50 "
"endif "
// timer
"if 9 "
" xv 246 "
" num 2 10 "
" xv 296 "
" pic 9 "
"endif "
// help / weapon icon
"if 11 "
" xv 148 "
" pic 11 "
"endif "
// frags
"xr -50 "
"yt 2 "
"num 3 14 "
// spectator
"if 17 "
"xv 0 "
"yb -58 "
"string2 \"SPECTATOR MODE\" "
"endif "
// chase camera
"if 16 "
"xv 0 "
"yb -68 "
"string \"Chasing\" "
"xv 64 "
"stat_string 16 "
"endif "
;
/*QUAKED worldspawn (0 0 0) ?
Only used for the world.
"sky" environment map name
"skyaxis" vector axis for rotating sky
"skyrotate" speed of rotation in degrees/second
"sounds" music cd track number
"gravity" 800 is default gravity
"message" text to print at user logon
*/
API_FUNC static void(entity ent) SP_worldspawn =
{
ent.movetype = MOVETYPE_PUSH;
ent.solid = SOLID_BSP;
ent.inuse = true; // since the world doesn't use G_Spawn()
ent.s.modelindex = 1; // world model is always index 1
//---------------
// reserve some spots for dead player bodies for coop / deathmatch
InitBodyQue();
// set configstrings for items
SetItemNames();
if (st.nextmap)
level.nextmap = st.nextmap;
// make some data visible to the server
if (ent.message)
{
gi.configstring(CS_NAME, ent.message);
level.level_name = ent.message;
}
else
level.level_name = level.mapname;
if (st.sky)
gi.configstring(CS_SKY, st.sky);
else
gi.configstring(CS_SKY, "unit1_");
gi.configstring(CS_SKYROTATE, va("%f", st.skyrotate));
gi.configstring(CS_SKYAXIS, va("%f %f %f", st.skyaxis[0], st.skyaxis[1], st.skyaxis[2]));
gi.configstring(CS_CDTRACK, va("%i", ent.sounds));
gi.configstring(CS_MAXCLIENTS, va("%i", game.maxclients));
// status bar program
#ifdef SINGLE_PLAYER
if (!deathmatch.intVal)
gi.configstring(CS_STATUSBAR, single_statusbar);
else
#endif
#ifdef CTF
if (ctf.intVal)
{
gi.configstring(CS_STATUSBAR, ctf_statusbar);
CTFPrecache();
}
else
#endif
gi.configstring(CS_STATUSBAR, dm_statusbar);
// help icon for statusbar
gi.imageindex("i_help");
level.pic_health = gi.imageindex("i_health");
gi.imageindex("help");
gi.imageindex("field_3");
if (!st.gravity)
gi.cvar_set("sv_gravity", "800");
else
gi.cvar_set("sv_gravity", st.gravity);
snd_fry = gi.soundindex("player/fry.wav"); // standing in lava / slime
PrecacheItem(GetItemByIndex(ITEM_BLASTER));
gi.soundindex("player/lava1.wav");
gi.soundindex("player/lava2.wav");
gi.soundindex("misc/pc_up.wav");
gi.soundindex("misc/talk1.wav");
gi.soundindex("misc/udeath.wav");
// gibs
gi.soundindex("items/respawn1.wav");
// sexed sounds
gi.soundindex("*death1.wav");
gi.soundindex("*death2.wav");
gi.soundindex("*death3.wav");
gi.soundindex("*death4.wav");
gi.soundindex("*fall1.wav");
gi.soundindex("*fall2.wav");
gi.soundindex("*gurp1.wav"); // drowning damage
gi.soundindex("*gurp2.wav");
gi.soundindex("*jump1.wav"); // player jump
gi.soundindex("*pain25_1.wav");
gi.soundindex("*pain25_2.wav");
gi.soundindex("*pain50_1.wav");
gi.soundindex("*pain50_2.wav");
gi.soundindex("*pain75_1.wav");
gi.soundindex("*pain75_2.wav");
gi.soundindex("*pain100_1.wav");
gi.soundindex("*pain100_2.wav");
// sexed models
// THIS ORDER MUST MATCH THE DEFINES IN g_local.h
// you can add more, max 19 (pete change)
gi.modelindex("#w_blaster.md2");
gi.modelindex("#w_shotgun.md2");
gi.modelindex("#w_sshotgun.md2");
gi.modelindex("#w_machinegun.md2");
gi.modelindex("#w_chaingun.md2");
gi.modelindex("#a_grenades.md2");
gi.modelindex("#w_glauncher.md2");
gi.modelindex("#w_rlauncher.md2");
gi.modelindex("#w_hyperblaster.md2");
gi.modelindex("#w_railgun.md2");
gi.modelindex("#w_bfg.md2");
#ifdef THE_RECKONING
gi.modelindex ("#w_phalanx.md2");
gi.modelindex ("#w_ripper.md2");
#endif
#ifdef GROUND_ZERO
gi.modelindex ("#w_disrupt.md2");
gi.modelindex ("#w_etfrifle.md2");
gi.modelindex ("#w_plasma.md2");
gi.modelindex ("#w_plauncher.md2");
gi.modelindex ("#w_chainfist.md2");
#endif
#ifdef GRAPPLE
gi.modelindex ("#w_grapple.md2");
#endif
//-------------------
gi.soundindex("player/gasp1.wav"); // gasping for air
gi.soundindex("player/gasp2.wav"); // head breaking surface, not gasping
gi.soundindex("player/watr_in.wav"); // feet hitting water
gi.soundindex("player/watr_out.wav"); // feet leaving water
gi.soundindex("player/watr_un.wav"); // head going underwater
gi.soundindex("player/u_breath1.wav");
gi.soundindex("player/u_breath2.wav");
gi.soundindex("items/pkup.wav"); // bonus item pickup
gi.soundindex("world/land.wav"); // landing thud
gi.soundindex("misc/h2ohit1.wav"); // landing splash
gi.soundindex("items/damage.wav");
#ifdef GROUND_ZERO
gi.soundindex ("misc/ddamage1.wav");
#endif
gi.soundindex("items/protect.wav");
gi.soundindex("items/protect4.wav");
gi.soundindex("weapons/noammo.wav");
#ifdef SINGLE_PLAYER
gi.soundindex("infantry/inflies1.wav");
#endif
sm_meat_index = gi.modelindex("models/objects/gibs/sm_meat/tris.md2");
gi.modelindex("models/objects/gibs/arm/tris.md2");
gi.modelindex("models/objects/gibs/bone/tris.md2");
gi.modelindex("models/objects/gibs/bone2/tris.md2");
gi.modelindex("models/objects/gibs/chest/tris.md2");
gi.modelindex("models/objects/gibs/skull/tris.md2");
gi.modelindex("models/objects/gibs/head2/tris.md2");
//
// Setup light animation tables. 'a' is total darkness, 'z' is doublebright.
//
// 0 normal
gi.configstring(CS_LIGHTS + 0, "m");
// 1 FLICKER (first variety)
gi.configstring(CS_LIGHTS + 1, "mmnmmommommnonmmonqnmmo");
// 2 SLOW STRONG PULSE
gi.configstring(CS_LIGHTS + 2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
// 3 CANDLE (first variety)
gi.configstring(CS_LIGHTS + 3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
// 4 FAST STROBE
gi.configstring(CS_LIGHTS + 4, "mamamamamama");
// 5 GENTLE PULSE 1
gi.configstring(CS_LIGHTS + 5, "jklmnopqrstuvwxyzyxwvutsrqponmlkj");
// 6 FLICKER (second variety)
gi.configstring(CS_LIGHTS + 6, "nmonqnmomnmomomno");
// 7 CANDLE (second variety)
gi.configstring(CS_LIGHTS + 7, "mmmaaaabcdefgmmmmaaaammmaamm");
// 8 CANDLE (third variety)
gi.configstring(CS_LIGHTS + 8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
// 9 SLOW STROBE (fourth variety)
gi.configstring(CS_LIGHTS + 9, "aaaaaaaazzzzzzzz");
// 10 FLUORESCENT FLICKER
gi.configstring(CS_LIGHTS + 10, "mmamammmmammamamaaamammma");
// 11 SLOW PULSE NOT FADE TO BLACK
gi.configstring(CS_LIGHTS + 11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
// styles 32-62 are assigned by the light program for switchable lights
// 63 testing
gi.configstring(CS_LIGHTS + 63, "a");
}