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