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