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