-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathmain.qc
More file actions
660 lines (528 loc) · 17.8 KB
/
main.qc
File metadata and controls
660 lines (528 loc) · 17.8 KB
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
/*
server/main.qc
mostly functions that will be called from the engine and are
expected to exist
Copyright (C) 2021-2024 NZ:P Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
void() LS_Setup;
void() PU_Init;
void() Compat_Init;
void() Gamemode_Init;
void() Gamemode_Frame;
void() SUB_Remove = {remove(self);}
string(string current_tune) Gamemode_GetSplashTune;
.float gungame_weapon_idx;
.float gungame_score_threshold;
//called when starting server/loading the map
void() main =
{
cheats_have_been_activated = false;
global_trace_damage_multiplier = 1;
}
float ai_delay_time;
float time_before_gamestart;
//
// Way_SetBrushEntNonSolid(ent_name)
// FIXME: Move this elsewhere..
// Wrapper for finding brush ents of classname
// and making them non-solid. For use only
// with Waypoint Mode.
//
void(string ent_name) Way_SetBrushEntNonSolid =
{
entity ent = find(world, classname, ent_name);
while(ent != world) {
ent.solid = SOLID_NOT;
ent.touch = SUB_Null;
ent = find(ent, classname, ent_name);
}
}
//called for each frame that QC runs
float zombie_cleaned_w;
void() StartFrame =
{
framecount = framecount + 1;
if (waypoint_mode) {
if (!zombie_cleaned_w) {
entity zent;
zent = find (world, classname, "ai_zombie");
while (zent)
{
remove (zent);
zent = find (zent, classname, "ai_zombie");
}
zombie_cleaned_w = true;
zent = find (world, classname, "waypoint");
while (zent)
{
if (zent.targetname != "")
setmodel(zent, "models/way/normal_way_door.spr");
else
setmodel(zent, "models/way/normal_way.spr");
zent = find (zent, classname, "waypoint");
}
Way_SetBrushEntNonSolid("door_nzp_cost");
Way_SetBrushEntNonSolid("door_nzp");
Way_SetBrushEntNonSolid("door");
}
return;
}
// Start completely blacked out
//if (time < 5)
if (roundinit) {
Round_Core();
if (ai_delay_time < time) {
Do_Zombie_AI ();
// This determines the delay between each AI's update sequence.
// It needs to be variable -- the more AI, the smaller this number
// should end up being, or else you'll have AI completely stall
// waiting for it's chance in the spotlight.
// -----
#ifdef FTE
// On FTE, resources are available to make this super short (0.01s,
// meaning all 24 ai update 4 times a second).
ai_delay_time = time + 0.01;
#else
// On other platforms, have this be 0.03 / ai factor / 12.
// This means that:
// AI Updates at ~30Hz with 12 Zombies
// AI Updates at ~45Hz with 18 Zombies
// AI Updates at ~60Hz with 24 Zombies
ai_delay_time = time + (0.03 / (nzp_maxai()/12));
#endif // FTE
}
} else {
if (!time_before_gamestart) {
entity SpawnedIn;
SpawnedIn = find(world, classname, "player");
if (SpawnedIn) {
entity hellhound = find(world, classname, "spawn_dog");
if (hellhound != world)
map_has_hellhounds = true;
Compat_Init();
updateDogRound();
time_before_gamestart = time + 3;
}
return;
} else if (time_before_gamestart < time) {
InitRounds();
nzp_screenflash(world, SCREENFLASH_COLOR_BLACK, 1, SCREENFLASH_FADE_OUT);
if (cvar("sv_startround") == 0) {
string splash_tune = "sounds/rounds/splash.wav";
splash_tune = Gamemode_GetSplashTune(splash_tune);
Rounds_PlayTransition(splash_tune);
}
entity players = find(world, classname, "player");
while(players != world) {
if (players.name != "")
nzp_setplayername(players, players.name);
nzp_setclientmode(cvar("sv_gamemode"));
players = find(players, classname, "player");
}
} else {
nzp_screenflash(world, SCREENFLASH_COLOR_BLACK, 90, SCREENFLASH_FADE_OUT);
}
}
Gamemode_Frame();
}
string(string s) precache_model = #20;
void() precaches =
{
precache_model ("models/player.mdl");
//
// Models
//
// sprites
precache_model ("models/sprites/sprkle.spr");
precache_model ("models/sprites/explosion.spr");
precache_model ("models/sprites/null.spr");
precache_model ("models/sprites/lightning.spr");
if (cvar("waypoint_mode")) {
precache_model ("models/way/current_way.spr");
precache_model ("models/way/current_way_door.spr");
precache_model ("models/way/last_way.spr");
precache_model ("models/way/last_way_door.spr");
precache_model ("models/way/normal_way.spr");
precache_model ("models/way/normal_way_door.spr");
precache_model ("models/way/way_jump.spr");
precache_model ("models/way/way_land.spr");
}
// zombie
precache_model ("models/ai/zfull.mdl");
precache_model ("models/ai/zal(.mdl");
precache_model ("models/ai/zar(.mdl");
precache_model ("models/ai/zb%.mdl");
precache_model ("models/ai/zh^.mdl");
// For debugging zombie AI
if (cvar("developer")) {
precache_model ("models/way/normal_way.spr");
}
// zombie crawler
precache_model ("models/ai/zcfull.mdl");
precache_model ("models/ai/zbc%.mdl");
precache_model ("models/ai/zalc(.mdl");
precache_model ("models/ai/zarc(.mdl");
precache_model ("models/ai/zhc^.mdl");
// start weapons
precache_model ("models/weapons/m1911/v_colt.mdl");
precache_model ("models/weapons/m1911/g_colt.mdl");
precache_model ("models/weapons/knife/v_knife.mdl");
precache_model ("models/weapons/grenade/v_grenade.mdl");
precache_model ("models/weapons/grenade/g_grenade.mdl");
precache_extra (W_BIATCH);
#ifdef FTE
// FTE only has co-op, so don't precache morphine elsewhere.
precache_model ("models/weapons/morphine/v_morphine.mdl");
#endif // FTE
//
// Sounds
//
// player-made
#ifdef FTE
precache_sound("sounds/player/footstep1.wav");
precache_sound("sounds/player/footstep2.wav");
precache_sound("sounds/player/footstep3.wav");
precache_sound("sounds/player/footstep4.wav");
precache_sound("sounds/player/footstep5.wav");
#endif // FTE
precache_sound("sounds/player/jump.wav");
precache_sound("sounds/player/land.wav");
precache_sound("sounds/player/pain4.wav");
// weapons
precache_sound("sounds/weapons/colt/magin.wav");
precache_sound("sounds/weapons/colt/magout.wav");
precache_sound("sounds/weapons/colt/shoot.wav");
precache_sound("sounds/weapons/colt/slide.wav");
precache_sound("sounds/weapons/papfire.wav");
// grenade
precache_sound("sounds/weapons/grenade/prime.wav");
precache_sound("sounds/weapons/grenade/throw.wav");
precache_sound("sounds/weapons/grenade/explode.wav");
// melee
precache_sound("sounds/weapons/knife/knife_hitbod.wav");
precache_sound("sounds/weapons/knife/knife.wav");
precache_sound("sounds/weapons/knife/knife_hit.wav");
// tunes
precache_sound("sounds/rounds/eround.wav");
precache_sound("sounds/rounds/nround.wav");
precache_sound("sounds/rounds/splash.wav");
precache_sound("sounds/music/end.wav");
// purchasing
precache_sound("sounds/misc/ching.wav");
precache_sound("sounds/misc/buy.wav");
precache_sound("sounds/misc/denybuy.wav");
// power-ups
precache_sound("sounds/pu/pickup.wav");
precache_sound("sounds/pu/powerup.wav");
precache_sound("sounds/pu/drop.wav");
precache_sound("sounds/pu/byebye.wav");
// zombie walk
precache_sound("sounds/zombie/w0.wav");
precache_sound("sounds/zombie/w1.wav");
precache_sound("sounds/zombie/w2.wav");
precache_sound("sounds/zombie/w3.wav");
precache_sound("sounds/zombie/w4.wav");
precache_sound("sounds/zombie/w5.wav");
precache_sound("sounds/zombie/w6.wav");
precache_sound("sounds/zombie/w7.wav");
precache_sound("sounds/zombie/w8.wav");
precache_sound("sounds/zombie/w9.wav");
// zombie run
precache_sound("sounds/zombie/r0.wav");
precache_sound("sounds/zombie/r1.wav");
precache_sound("sounds/zombie/r2.wav");
precache_sound("sounds/zombie/r3.wav");
precache_sound("sounds/zombie/r4.wav");
precache_sound("sounds/zombie/r5.wav");
precache_sound("sounds/zombie/r6.wav");
precache_sound("sounds/zombie/r7.wav");
precache_sound("sounds/zombie/r8.wav");
precache_sound("sounds/zombie/r9.wav");
// zombie swipe
precache_sound("sounds/zombie/a0.wav");
precache_sound("sounds/zombie/a1.wav");
precache_sound("sounds/zombie/a2.wav");
precache_sound("sounds/zombie/a3.wav");
precache_sound("sounds/zombie/a4.wav");
precache_sound("sounds/zombie/a5.wav");
precache_sound("sounds/zombie/a6.wav");
precache_sound("sounds/zombie/a7.wav");
// zombie death
precache_sound("sounds/zombie/d0.wav");
precache_sound("sounds/zombie/d1.wav");
precache_sound("sounds/zombie/d2.wav");
precache_sound("sounds/zombie/d3.wav");
precache_sound("sounds/zombie/d4.wav");
precache_sound("sounds/zombie/d5.wav");
precache_sound("sounds/zombie/d6.wav");
precache_sound("sounds/zombie/d7.wav");
// zombie taunt
precache_sound("sounds/zombie/t0.wav");
precache_sound("sounds/zombie/t1.wav");
precache_sound("sounds/zombie/t2.wav");
precache_sound("sounds/zombie/t3.wav");
precache_sound("sounds/zombie/t4.wav");
// zombie footsteps
precache_sound("sounds/zombie/s0.wav");
precache_sound("sounds/zombie/s1.wav");
precache_sound("sounds/zombie/sc0.wav");
precache_sound("sounds/zombie/sc1.wav");
// null
precache_sound("sounds/null.wav");
}
//called when map loaded
void() worldspawn =
{
precaches();
// Define all of our Light Styles
LS_Setup();
// Init Power-Ups
PU_Init();
#ifdef FTE
clientstat(STAT_CURRENTMAG, EV_FLOAT, weapons[0].weapon_magazine);
clientstat(STAT_CURRENTMAG2, EV_FLOAT, weapons[0].weapon_magazine_left);
clientstat(STAT_POINTS, EV_FLOAT, points);
clientstat(STAT_WEAPON2FRAME, EV_FLOAT, weapon2frame);
clientstat(STAT_WEAPON2MODELI, EV_FLOAT, weapon2modelindex);
clientstat(STAT_WEAPONSKIN, EV_FLOAT, weaponskin);
clientstat(STAT_GRENADES, EV_FLOAT, primary_grenades);
clientstat(STAT_SECGRENADES, EV_FLOAT, secondary_grenades);
clientstat(STAT_PROGRESSBAR, EV_FLOAT, progress_bar_percent);
clientstat(STAT_WEAPONDURATION, EV_FLOAT, weapon_animduration);
clientstat(STAT_WEAPON2DURATION, EV_FLOAT, weapon2_animduration);
clientstat(STAT_WEAPONZOOM, EV_FLOAT, zoom);
clientstat(STAT_INSTA, EV_FLOAT, insta_icon);
clientstat(STAT_X2, EV_FLOAT, x2_icon);
clientstat(STAT_SPECTATING, EV_FLOAT, is_spectator);
clientstat(STAT_PLAYERNUM, EV_FLOAT, playernum);
clientstat(STAT_PLAYERSTANCE, EV_FLOAT, stance);
clientstat(STAT_FACINGENEMY, EV_FLOAT, facingenemy);
clientstat(STAT_VIEWZOOM, EV_FLOAT, viewzoom);
clientstat(STAT_MAXHEALTH, EV_FLOAT, max_health);
clientstat(STAT_PERKS, EV_FLOAT, perks);
clientstat(STAT_TOTALSCORE, EV_FLOAT, score);
clientstat(STAT_WEAPONNAME, EV_STRING, Weapon_Name);
clientstat(STAT_WEAPONNAMETOUCH, EV_STRING, Weapon_Name_Touch);
clientstat(STAT_WEAPONTIER, EV_FLOAT, weapon_tier);
clientstat(STAT_VIEWMODEL_EFFECTS, EV_FLOAT, viewmodel_effects);
clientstat(STAT_VIEWMODEL2_EFFECTS, EV_FLOAT, viewmodel2_effects);
// Gun Game
clientstat(STAT_GUNGAME_IDX, EV_FLOAT, gungame_weapon_idx);
clientstat(STAT_GUNGAME_SCOREGOAL, EV_FLOAT, gungame_score_threshold);
autocvar(sv_enablechatplugins, 0);
autocvar(sv_maprotationbasename, "map_rotation");
autocvar(sv_maprotationmode, 0);
autocvar(sv_gamemode, 0);
autocvar(sv_difficulty, 0);
autocvar(sv_startround, 0);
autocvar(sv_magic, 1);
autocvar(sv_headshotonly, 0);
autocvar(sv_maxai, 24);
autocvar(sv_fastrounds, 0);
autocvar(sv_spoofmonth, 0);
current_month_of_year = nzp_getmonthofyear();
#endif // FTE
mappath = strcat("maps/", mapname);
mappath = strzone(mappath);
LoadWaypointData();
Zoning_LoadData();
Zoning_SpawnEnts();
//set game elements
G_PRONEPOINTS = 0;
G_STARTWEAPON[0] = W_COLT;
G_STARTWEAPON[1] = 8;
G_STARTWEAPON[2] = 32;
G_WORLDTEXT = 1;
G_PERKS = 0;
G_PERKPOWER = 0;
game_modifier_can_melee = true;
game_modifier_can_use_equipment = true;
game_modifier_can_earn_misc_score = true;
game_modifier_powerup_free_perk = false;
game_modifier_powerup_max_ammo = true;
game_modifier_powerup_weapon_upgrade = false;
game_modifier_powerup_random_weapon = false;
game_modifier_powerup_bonus_points = false;
game_modifier_powerup_toast_for_all = false;
game_modifier_can_packapunch = true;
game_modifier_grenades_explode_on_contact = false;
game_modifier_packapunch_uses_tiers = false;
game_modifier_packapunch_is_instant = false;
game_modifier_maxammo_fills_magazine = false;
game_modifier_hellhound_fog_color = "200 525 54 55 60";
game_modifier_default_fog_color = world.fog;
game_modifier_perk_purchase_limit = 8;
game_modifier_cost_multiplier = 1;
sprint_max_time = 4.0;
//
// World Gravity Multiplier
//
// FIXME: This should technically poll sv_gravity but
// we do not currently enforce a default that resets
// on a new server.
float sv_gravity = 800;
// worldspawn "gravity" field is a multiplier to be applied
// to sv_gravity.
if (!world.gravity) world.gravity = 1;
world.gravity = clamp(world.gravity, 0.1, 2);
// Update the cvar for the server.
cvar_set("sv_gravity", ftos(sv_gravity * world.gravity));
#ifdef FTE
// We need to get the currently loaded map's pretty name
// (if it exists) so we can send it to clients or broadcast
// it.
string mapname_pretty;
float map_txt_file = fopen(sprintf("maps/%s.txt", mapname), FILE_READ);
if (map_txt_file == -1) {
mapname_pretty = mapname;
} else {
mapname_pretty = strtrim((fgets(map_txt_file)));
fclose(map_txt_file);
}
cvar_set("mapname_pretty", mapname_pretty);
localcmd(sprintf("serverinfo mapname_pretty %s\n", mapname_pretty));
#endif // FTE
Gamemode_Init();
}
void() SpectatorConnect =
{
bprint(PRINT_HIGH, self.netname);
bprint(PRINT_HIGH, " has joined the spectators.\n");
}
void() RelinkZombies =
{
entity ent,ent2;
local float i;
local vector min, max;
//warn
ent = ent2 = world;
while ((ent = find (ent, classname, "ai_zombie")))
{
if(ent.currentHitBoxSetup == 0)//empty bbox, we don't care to update
continue;
#ifdef FTE
// This is just a weird hack we do to avoid spamming other clients in co-op with
// the update positions for limbs. Brings bandwidth from 90kbps->30kbps without
// a tick rate limit. 30kbps->12kbps with a tickrate of 20Hz. Basically, like we
// do other platforms for render speedups, if a zombie has all of its limbs dont
// bother drawing them all separately. draw one full mesh instead, then when it
// has been gibbed, then begin drawing separately -- cypress
if (ent.larm.deadflag && ent.rarm.deadflag && ent.head.deadflag) {
setmodel(ent.larm, "");
setmodel(ent.rarm, "");
setmodel(ent.head, "");
if (ent.crawling == 1)
setmodel(ent, "models/ai/zcfull.mdl");
else
setmodel(ent, "models/ai/zfull.mdl");
} else if (!(ent.crawling == 1 && ent.model == "models/ai/zbc%.mdl") || !(ent.model == "models/ai/zb%.mdl")) {
if (ent.crawling == 1)
setmodel(ent, "models/ai/zbc%.mdl");
else
setmodel(ent, "models/ai/zb%.mdl");
if (ent.larm.deadflag) {
if (ent.crawling == 1)
setmodel(ent.larm, "models/ai/zalc(.mdl");
else
setmodel(ent.larm, "models/ai/zal(.mdl");
}
if (ent.rarm.deadflag) {
if (ent.crawling == 1)
setmodel(ent.rarm, "models/ai/zarc(.mdl");
else
setmodel(ent.rarm, "models/ai/zar(.mdl");
}
if (ent.head.deadflag) {
if (ent.crawling == 1)
setmodel(ent.head, "models/ai/zhc^.mdl");
else
setmodel(ent.head, "models/ai/zh^.mdl");
}
}
#endif // FTE
makevectors (ent.angles);
for(i = 0; i < 3; i++)
{
if(i == 0)
ent2 = ent.head;
if(i == 1)
ent2 = ent.larm;
if(i == 2)
ent2 = ent.rarm;
if (ent2)
{
//setorigin (ent.head, ent.origin + v_right * ent.head.view_ofs_x + v_forward * ent.head.view_ofs_y + v_up * ent.head.view_ofs_z);
setorigin (ent2, ent.origin);
//fixme, move angles set and frame set to below the continue, we only want to update origin (maybe angles too?)
ent2.angles = ent.angles;
if(ent2.deadflag)
ent2.frame = ent.frame;
//if(OnlyOrigin)
// continue;
min = ent2.bbmins + (v_right * ent2.view_ofs_x) + (v_forward * ent2.view_ofs_y) + (v_up * ent2.view_ofs_z);
max = ent2.bbmaxs + (v_right * ent2.view_ofs_x) + (v_forward * ent2.view_ofs_y) + (v_up * ent2.view_ofs_z);
if(min_x > max_x) { min_x += max_x; max_x = min_x - max_x; min_x -= max_x; }
if(min_y > max_y) { min_y += max_y; max_y = min_y - max_y; min_y -= max_y; }
if(min_z > max_z) { min_z += max_z; max_z = min_z - max_z; min_z -= max_z; }
setsize(ent2,min,max);
}
}
}
}
void() LinkZombiesHitbox =
{
entity ent,ent2;
local float i;
local vector min, max;
//warn
ent = ent2 = world;
while ((ent = find (ent, classname, "ai_zombie")))
{
if(ent.currentHitBoxSetup == 0)//empty bbox, we don't care to update
continue;
makevectors (ent.angles);
for(i = 0; i < 3; i++)
{
if(i == 0)
ent2 = ent.head;
if(i == 1)
ent2 = ent.larm;
if(i == 2)
ent2 = ent.rarm;
if (ent2)
{
ent2.angles = ent.angles;
if(ent2.deadflag)
ent2.frame = ent.frame;
//if(OnlyOrigin)
// continue;
min = ent2.bbmins + (v_right * ent2.view_ofs_x) + (v_forward * ent2.view_ofs_y) + (v_up * ent2.view_ofs_z);
max = ent2.bbmaxs + (v_right * ent2.view_ofs_x) + (v_forward * ent2.view_ofs_y) + (v_up * ent2.view_ofs_z);
if(min_x > max_x) { min_x += max_x; max_x = min_x - max_x; min_x -= max_x; }
if(min_y > max_y) { min_y += max_y; max_y = min_y - max_y; min_y -= max_y; }
if(min_z > max_z) { min_z += max_z; max_z = min_z - max_z; min_z -= max_z; }
setsize(ent2,min,max);
}
}
}
}
void() EndFrame =
{
RelinkZombies();
if (cheats_have_been_activated == false && cvar("sv_cheats") == 1) {
cheats_have_been_activated = true;
}
};