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