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