]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/gamec/g_world.c
weaponsounds, defaultmodel, electrocombo, specmode and weaponmodel colors
[divverent/nexuiz.git] / data / qcsrc / gamec / g_world.c
1
2 void worldspawn (void)
3 {
4
5         // Precache all player models
6         // Workaround for "invisible players"
7         precache_model("models/player/carni.zym");
8         precache_model("models/player/crash.zym");
9         precache_model("models/player/grunt.zym");
10         precache_model("models/player/headhunter.zym");
11         precache_model("models/player/insurrectionist.zym");
12         precache_model("models/player/jeandarc.zym");
13         precache_model("models/player/lurk.zym");
14         precache_model("models/player/lycanthrope.zym");
15         precache_model("models/player/marine.zym");
16         precache_model("models/player/nexus.zym");
17         precache_model("models/player/pyria.zym");
18         precache_model("models/player/shock.zym");
19         precache_model("models/player/skadi.zym");
20         precache_model("models/player/specop.zym");
21         precache_model("models/player/visitant.zym");
22
23         //precache_model ("progs/beam.mdl");
24         precache_model ("models/bullet.mdl");
25         precache_model ("models/casing_bronze.mdl");
26         precache_model ("models/casing_shell.mdl");
27         precache_model ("models/casing_steel.mdl");
28         precache_model ("models/ebomb.mdl");
29         precache_model ("models/elaser.mdl");
30         precache_model ("models/flash.md3");
31         precache_model ("models/gibs/bloodyskull.md3");
32         precache_model ("models/gibs/chunk.mdl");
33         precache_model ("models/gibs/eye.md3");
34         precache_model ("models/gibs/gib1.md3");
35         precache_model ("models/gibs/gib2.md3");
36         precache_model ("models/gibs/gib3.md3");
37         precache_model ("models/gibs/gib4.md3");
38         precache_model ("models/gibs/gib5.md3");
39         precache_model ("models/gibs/gib6.md3");
40         precache_model ("models/grenademodel.md3");
41         precache_model ("models/hagarmissile.mdl");
42         precache_model ("models/items/a_bullets.mdl");
43         precache_model ("models/items/a_cells.md3");
44         precache_model ("models/items/a_rockets.md3");
45         precache_model ("models/items/a_shells.md3");
46         precache_model ("models/items/g_a1.md3");
47         precache_model ("models/items/g_a25.md3");
48         precache_model ("models/items/g_h1.md3");
49         precache_model ("models/items/g_h25.md3");
50         precache_model ("models/items/g_h100.md3");
51         precache_model ("models/items/g_invincible.md3");
52         precache_model ("models/items/g_strength.md3");
53         precache_model ("models/laser.mdl");
54         precache_model ("models/misc/chatbubble.spr");
55         precache_model ("models/nexflash.md3");
56         precache_model ("models/plasma.mdl");
57         precache_model ("models/plasmatrail.mdl");
58         precache_model ("models/rocket.md3");
59         precache_model ("models/sprites/grenadeexplosion.spr32");
60         precache_model ("models/sprites/hagarexplosion.spr32");
61         precache_model ("models/sprites/muzzleflash.spr32");
62         precache_model ("models/sprites/electrocombo.spr32");
63         //precache_model ("models/sprites/plasmahitwall.spr32");
64         //precache_model ("models/sprites/plasmashot.spr32");
65         precache_model ("models/sprites/rocketexplosion.spr32");
66         precache_model ("models/tracer.mdl");
67         precache_model ("models/uziflash.md3");
68         precache_model ("models/weapons/g_crylink.md3");
69         precache_model ("models/weapons/g_electro.md3");
70         precache_model ("models/weapons/g_gl.md3");
71         precache_model ("models/weapons/g_hagar.md3");
72         precache_model ("models/weapons/g_nex.md3");
73         precache_model ("models/weapons/g_rl.md3");
74         precache_model ("models/weapons/g_shotgun.md3");
75         precache_model ("models/weapons/g_uzi.md3");
76         precache_model ("models/weapons/v_crylink.md3");
77         precache_model ("models/weapons/v_electro.md3");
78         precache_model ("models/weapons/v_gl.md3");
79         precache_model ("models/weapons/v_hagar.md3");
80         precache_model ("models/weapons/v_laser.md3");
81         precache_model ("models/weapons/v_nex.md3");
82         precache_model ("models/weapons/v_rl.md3");
83         precache_model ("models/weapons/v_shotgun.md3");
84         precache_model ("models/weapons/v_uzi.md3");
85         precache_model ("models/weapons/w_crylink.zym");
86         precache_model ("models/weapons/w_electro.zym");
87         precache_model ("models/weapons/w_gl.zym");
88         precache_model ("models/weapons/w_hagar.zym");
89         precache_model ("models/weapons/w_laser.zym");
90         precache_model ("models/weapons/w_nex.zym");
91         precache_model ("models/weapons/w_rl.zym");
92         precache_model ("models/weapons/w_shotgun.zym");
93         precache_model ("models/weapons/w_uzi.zym");
94
95         // laser for laser-guided weapons
96         precache_model ("models/laser_dot.mdl");
97
98         precache_sound ("announcer/1fragleft.wav");
99         precache_sound ("announcer/1minuteremains.wav");
100         precache_sound ("announcer/2fragsleft.wav");
101         precache_sound ("announcer/3fragsleft.wav");
102         precache_sound ("announcer/welcometonexuiz.wav");
103         precache_sound ("misc/armor1.wav");
104         precache_sound ("misc/armor25.wav");
105         precache_sound ("misc/armorimpact.wav");
106         precache_sound ("misc/bodyimpact1.wav");
107         precache_sound ("misc/bodyimpact2.wav");
108         precache_sound ("misc/gib.wav");
109         precache_sound ("misc/gib_splat01.wav");
110         precache_sound ("misc/gib_splat02.wav");
111         precache_sound ("misc/gib_splat03.wav");
112         precache_sound ("misc/gib_splat04.wav");
113         //precache_sound ("misc/h2ohit.wav");
114         precache_sound ("misc/hit.wav");
115         precache_sound ("misc/hitground1.wav");
116         precache_sound ("misc/hitground2.wav");
117         precache_sound ("misc/hitground3.wav");
118         precache_sound ("misc/hitground4.wav");
119         precache_sound ("misc/itempickup.wav");
120         precache_sound ("misc/itemrespawn.wav");
121         precache_sound ("misc/jumppad.wav");
122         precache_sound ("misc/mediumhealth.wav");
123         precache_sound ("misc/megahealth.wav");
124         precache_sound ("misc/minihealth.wav");
125         precache_sound ("misc/powerup.wav");
126         precache_sound ("misc/talk.wav");
127         precache_sound ("misc/teleport.wav");
128         precache_sound ("plats/medplat1.wav");
129         precache_sound ("plats/medplat2.wav");
130         precache_sound ("player/lava.wav");
131         precache_sound ("player/slime.wav");
132         precache_sound ("weapons/crylink.ogg");
133         precache_sound ("weapons/crylink2.ogg");
134         precache_sound ("weapons/electro_bounce.ogg");
135         precache_sound ("weapons/electro_fire.ogg");
136         precache_sound ("weapons/electro_fire2.ogg");
137         precache_sound ("weapons/electro_fly.wav");
138         precache_sound ("weapons/electro_impact.ogg");
139         precache_sound ("weapons/electro_impact_combo.ogg");
140         precache_sound ("weapons/grenade_bounce.ogg");
141         precache_sound ("weapons/grenade_fire.ogg");
142         precache_sound ("weapons/grenade_impact.ogg");
143         precache_sound ("weapons/hagar_fire.ogg");
144         precache_sound ("weapons/hagexp1.ogg");
145         precache_sound ("weapons/hagexp2.ogg");
146         precache_sound ("weapons/hagexp3.ogg");
147         precache_sound ("weapons/lasergun_fire.ogg");
148         precache_sound ("weapons/laserimpact.ogg");
149         precache_sound ("weapons/nexfire.ogg");
150         precache_sound ("weapons/neximpact.ogg");
151         precache_sound ("weapons/ric1.wav");
152         precache_sound ("weapons/ric2.wav");
153         precache_sound ("weapons/ric3.wav");
154         precache_sound ("weapons/rocket_fire.wav");
155         precache_sound ("weapons/rocket_fly.wav");
156         precache_sound ("weapons/rocket_impact.wav");
157         precache_sound ("weapons/shotgun_fire.wav");
158         precache_sound ("weapons/tink1.wav");
159         precache_sound ("weapons/uzi_fire.wav");
160         precache_sound ("weapons/weapon_switch.wav");
161         precache_sound ("weapons/weaponpickup.wav");
162
163
164
165         // plays music for the level if there is any
166         if (self.noise)
167         {
168                 precache_sound (self.noise);
169                 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
170         }
171
172                 // 0 normal
173         lightstyle(0, "m");
174
175         // 1 FLICKER (first variety)
176         lightstyle(1, "mmnmmommommnonmmonqnmmo");
177
178         // 2 SLOW STRONG PULSE
179         lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
180
181         // 3 CANDLE (first variety)
182         lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
183
184         // 4 FAST STROBE
185         lightstyle(4, "mamamamamama");
186
187         // 5 GENTLE PULSE 1
188         lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
189
190         // 6 FLICKER (second variety)
191         lightstyle(6, "nmonqnmomnmomomno");
192
193         // 7 CANDLE (second variety)
194         lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
195
196         // 8 CANDLE (third variety)
197         lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
198
199         // 9 SLOW STROBE (fourth variety)
200         lightstyle(9, "aaaaaaaazzzzzzzz");
201
202         // 10 FLUORESCENT FLICKER
203         lightstyle(10, "mmamammmmammamamaaamammma");
204
205         // 11 SLOW PULSE NOT FADE TO BLACK
206         lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
207
208         // styles 32-62 are assigned by the light program for switchable lights
209
210         // 63 testing
211         lightstyle(63, "a");
212
213         InitGameplayMode();
214         //if (cvar("g_domination"))
215         //      dom_init();
216 }
217
218 void light (void)
219 {
220         makestatic (self);
221 }
222
223
224 // reads and alters data/maplist.cfg (sliding it one line), and returns a
225 // strzoned string containing the next map
226 string() Nex_RotateMapList =
227 {
228         local float lHandle;
229         local string lNextMap;
230         local string lCurrentMap;
231         local string lBuffer;
232
233         lHandle = fopen( "maplist.cfg", FILE_READ );
234         if( lHandle < 0 ) {
235                 fclose( lHandle );
236                 // restart the current map if no other map is not found
237                 return strzone( mapname );
238         }
239
240         // get the first line that will be moved to the end later
241         lCurrentMap = strzone( fgets( lHandle ) );
242         if( !lCurrentMap ) {
243                 fclose( lHandle );
244                 // restart the current map if no other map is not found
245                 return strzone( mapname );
246         }
247
248         // now get the second line which is the map that should be loaded next
249         lBuffer = fgets( lHandle );
250         // if there isnt a second line, nothing needs to be rotated
251         if( !lBuffer ) {
252                 fclose( lHandle );
253                 strunzone( lCurrentMap );
254                 // restart the current map if no other map is not found
255                 return strzone( mapname );
256         }
257
258         // since lBuffer holds the next map, it is assigned to nextmap
259         lNextMap = strzone( lBuffer );
260
261         // since fgets uses its own buffer we need to move lBuffer to a tempstring
262         // before reading the next line (or lBuffer will be lost)
263         lBuffer = strcat( lBuffer );
264
265         // read in the rest of the list
266         while( 1 )  {
267                 local string lLine;
268
269                 lLine = fgets( lHandle );
270                 if( !lLine ) {
271                         break;
272                 }
273
274                 lBuffer = strcat( lBuffer, "\n", lLine );
275         }
276         // rotate the list
277         lBuffer = strcat( lBuffer, "\n", lCurrentMap );
278
279         // dismiss lCurrentmap now
280         strunzone( lCurrentMap );
281
282         // and close the file handle
283         fclose( lHandle );
284
285         // open the maplist for output this one
286         lHandle = fopen( "maplist.cfg", FILE_WRITE );
287         if( lHandle < 0 ) {
288                 // this shouldnt happen!
289                 // print a warning/error message
290                 dprint( "Couldn't open ", "maplist.cfg", " for output!\n" );
291
292                 strunzone( lNextMap );
293
294                 // we return the currently running map
295                 return strzone( mapname );
296         }
297
298         fputs( lHandle, lBuffer );
299
300         fclose( lHandle );
301
302         return lNextMap;
303 };
304
305 void() GotoNextMap =
306 {
307         //local string nextmap;
308         //local float n, nummaps;
309         //local string s;
310         string exit_cfg;
311         if (alreadychangedlevel)
312                 return;
313         alreadychangedlevel = TRUE;
314
315         // if an exit cfg is defined by exiting map, exec it.
316         exit_cfg = cvar_string("exit_cfg");
317         if(exit_cfg != "")
318                 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
319
320         ResetGameCvars();
321
322
323         if (cvar("samelevel"))  // if samelevel is set, stay on same level
324         {
325                 localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
326                 //changelevel (mapname);
327         }
328         else
329         {
330                 // method 0
331                 local float lCurrent;
332                 local float lSize;
333
334                 lSize = tokenize( cvar_string( "g_maplist" ) );
335                 lCurrent = cvar( "g_maplist_index" );
336
337                 lCurrent = lCurrent + 1;
338                 if( lCurrent >= lSize ) {
339                         lCurrent = 0;
340                 }
341
342                 cvar_set( "g_maplist_index", ftos( lCurrent ) );
343
344
345                 localcmd(strcat("exec \"maps/", argv( lCurrent ), ".mapcfg\"\n"));
346                 //changelevel( argv( lCurrent ) );
347
348
349                 /*
350                 // method 1
351
352                 //local entity pos;
353                 local float fh;
354                 local string line;
355
356                 // restart current map if no cycle is found
357                 nextmap = strzone(mapname);
358                 fh = fopen("maplist.cfg", FILE_READ);
359                 if (fh >= 0)
360                 {
361                         while (1)
362                         {
363                                 line = fgets(fh);
364                                 if (nextmap == mapname)
365                                 {
366                                         strunzone(nextmap);
367                                         nextmap = strzone(line);
368                                 }
369                                 if (!line)
370                                         break;
371                                 if (line == mapname)
372                                 {
373                                         line = fgets(fh);
374                                         if (!line)
375                                                 break;
376                                         strunzone(nextmap);
377                                         nextmap = strzone(line);
378                                         break;
379                                 }
380                         }
381                         fclose(fh);
382                 }
383                 changelevel (nextmap);
384                 strunzone(nextmap);*/
385
386                 // method 2
387                 //nextmap = Nex_RotateMapList();
388                 //changelevel (nextmap);
389                 //strunzone (nextmap);
390                 // method 3
391                 /*
392                 s = cvar_string("g_maplist");
393                 nummaps = tokenize(s);
394                 // if no map list, restart current one
395                 nextmap = mapname;
396                 if (nummaps >= 1)
397                 {
398                         n = 0;
399                         while (n < nummaps)
400                         {
401                                 if (argv(n) == mapname)
402                                         break;
403                                 n = n + 1;
404                         }
405                         n = n + 1;
406                         if (n >= nummaps)
407                                 n = 0;
408                         nextmap = argv(n);
409                 }
410                 changelevel (nextmap);
411                 */
412         }
413 };
414
415
416 /*
417 ============
418 IntermissionThink
419
420 When the player presses attack or jump, change to the next level
421 ============
422 */
423 void() IntermissionThink =
424 {
425         if (time < intermission_exittime)
426                 return;
427
428         if (time < intermission_exittime + 10 && !self.button0 && !self.button1 && !self.button2 && !self.button3)
429                 return;
430
431         GotoNextMap ();
432 };
433
434 /*
435 ============
436 FindIntermission
437
438 Returns the entity to view from
439 ============
440 */
441 /*
442 entity() FindIntermission =
443 {
444         local   entity spot;
445         local   float cyc;
446
447 // look for info_intermission first
448         spot = find (world, classname, "info_intermission");
449         if (spot)
450         {       // pick a random one
451                 cyc = random() * 4;
452                 while (cyc > 1)
453                 {
454                         spot = find (spot, classname, "info_intermission");
455                         if (!spot)
456                                 spot = find (spot, classname, "info_intermission");
457                         cyc = cyc - 1;
458                 }
459                 return spot;
460         }
461
462 // then look for the start position
463         spot = find (world, classname, "info_player_start");
464         if (spot)
465                 return spot;
466
467 // testinfo_player_start is only found in regioned levels
468         spot = find (world, classname, "testplayerstart");
469         if (spot)
470                 return spot;
471
472 // then look for the start position
473         spot = find (world, classname, "info_player_deathmatch");
474         if (spot)
475                 return spot;
476
477         //objerror ("FindIntermission: no spot");
478         return world;
479 };
480 */
481
482 /*
483 ===============================================================================
484
485 RULES
486
487 ===============================================================================
488 */
489
490 /*
491 go to the next level for deathmatch
492 only called if a time or frag limit has expired
493 */
494 void() NextLevel =
495 {
496         gameover = TRUE;
497
498         intermission_running = 1;
499
500 // enforce a wait time before allowing changelevel
501         intermission_exittime = time + 5;
502
503         WriteByte (MSG_ALL, SVC_CDTRACK);
504         WriteByte (MSG_ALL, 3);
505         WriteByte (MSG_ALL, 3);
506
507         //pos = FindIntermission ();
508
509         other = find (world, classname, "player");
510         while (other != world)
511         {
512                 //other.nextthink = time + 0.5;
513                 other.takedamage = DAMAGE_NO;
514                 other.solid = SOLID_NOT;
515                 other.movetype = MOVETYPE_NONE;
516                 other.angles = other.v_angle;
517                 other.angles_x = other.angles_x * -1;
518                 /*
519                 if (pos != world);
520                 {
521                         other.modelindex = 0;
522                         other.weaponentity = world; // remove weapon model
523                         other.view_ofs = '0 0 0';
524                         other.angles = other.v_angle = pos.mangle;
525                         if (!other.angles)
526                         {
527                                 other.angles = other.v_angle = pos.angles;
528                                 other.v_angle_x = other.v_angle_x * -1;
529                         }
530                         other.fixangle = TRUE;          // turn this way immediately
531                         setorigin (other, pos.origin);
532                 }
533                 */
534                 other = find (other, classname, "player");
535         }
536
537         WriteByte (MSG_ALL, SVC_INTERMISSION);
538 };
539
540 /*
541 ============
542 CheckRules_Player
543
544 Exit deathmatch games upon conditions
545 ============
546 */
547 void() CheckRules_Player =
548 {
549         local float fraglimit;
550
551         if (gameover)   // someone else quit the game already
552                 return;
553
554         // fixme: don't check players; instead check dom_team and ctf_team entities
555
556         fraglimit = cvar("fraglimit");
557
558         if(cvar("g_domination"))
559         {
560                 // fixme: check team frags, not players!
561                 if (fraglimit && self.frags >= fraglimit)
562                 {
563                         NextLevel ();
564                         return;
565                 }
566         }
567         else
568         {
569                 if (fraglimit && self.frags >= fraglimit)
570                 {
571                         NextLevel ();
572                         return;
573                 }
574         }
575 };
576
577 float checkrules_oneminutewarning;
578 float checkrules_leaderfrags;
579 entity checkrules_leader;
580
581 /*
582 ============
583 CheckRules_World
584
585 Exit deathmatch games upon conditions
586 ============
587 */
588 void() CheckRules_World =
589 {
590         local float timelimit;
591         local float fraglimit;
592         local float checkrules_oldleaderfrags;
593         local entity checkrules_oldleader;
594         local entity head;
595
596         if (intermission_running)
597         if (time >= intermission_exittime + 60)
598         {
599                 GotoNextMap();
600                 return;
601         }
602
603         if (gameover)   // someone else quit the game already
604                 return;
605
606         timelimit = cvar("timelimit") * 60;
607         fraglimit = cvar("fraglimit");
608
609         if (timelimit && time >= timelimit)
610         {
611                 NextLevel ();
612                 return;
613         }
614
615         if (!checkrules_oneminutewarning && timelimit && time > timelimit - 60)
616         {
617                 checkrules_oneminutewarning = TRUE;
618                 sound(world, CHAN_AUTO, "announcer/1minuteremains.wav", 1, ATTN_NONE);
619         }
620
621         checkrules_oldleader = checkrules_leader;
622         checkrules_oldleaderfrags = checkrules_leaderfrags;
623         checkrules_leaderfrags = 0;
624         checkrules_leader = world;
625         head = findchain(classname, "player");
626         while (head)
627         {
628                 if (checkrules_leaderfrags < head.frags)
629                 {
630                         checkrules_leaderfrags = head.frags;
631                         checkrules_leader = head;
632                 }
633                 head = head.chain;
634         }
635         if (checkrules_leaderfrags <= 0)
636         {
637                 checkrules_leader = world;
638                 checkrules_leaderfrags = 0;
639         }
640         checkrules_leaderfrags = floor(checkrules_leaderfrags);
641         if (checkrules_leaderfrags != checkrules_oldleaderfrags)
642         {
643                 if (checkrules_leaderfrags == fraglimit - 1)
644                         sound(world, CHAN_AUTO, "announcer/1fragleft.wav", 1, ATTN_NONE);
645                 else if (checkrules_leaderfrags == fraglimit - 2)
646                         sound(world, CHAN_AUTO, "announcer/2fragsleft.wav", 1, ATTN_NONE);
647                 else if (checkrules_leaderfrags == fraglimit - 3)
648                         sound(world, CHAN_AUTO, "announcer/3fragsleft.wav", 1, ATTN_NONE);
649         }
650 //      if (checkrules_leader != checkrules_oldleader)// && checkrules_leaderfrags > checkrules_oldleaderfrags)
651 //              bprint("^1",checkrules_leader.netname, " has taken the lead with ", ftos(checkrules_leaderfrags), " frags\n");
652 };