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