]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_world.c
set classname to droppedweapon again after spawning a dropped weapon just to be absol...
[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 1
302
303                 //local entity pos;
304                 local float fh;
305                 local string line;
306
307                 // restart current map if no cycle is found
308                 nextmap = strzone(mapname);
309                 fh = fopen("maplist.cfg", FILE_READ);
310                 if (fh >= 0)
311                 {
312                         while (1)
313                         {
314                                 line = fgets(fh);
315                                 if (nextmap == mapname)
316                                 {
317                                         strunzone(nextmap);
318                                         nextmap = strzone(line);
319                                 }
320                                 if (!line)
321                                         break;
322                                 if (line == mapname)
323                                 {
324                                         line = fgets(fh);
325                                         if (!line)
326                                                 break;
327                                         strunzone(nextmap);
328                                         nextmap = strzone(line);
329                                         break;
330                                 }
331                         }
332                         fclose(fh);
333                 }
334                 changelevel (nextmap);
335                 strunzone(nextmap);
336
337                 // method 2
338                 //nextmap = Nex_RotateMapList();
339                 //changelevel (nextmap);
340                 //strunzone (nextmap);
341                 // method 3
342                 /*
343                 s = cvar_string("g_maplist");
344                 nummaps = tokenize(s);
345                 // if no map list, restart current one
346                 nextmap = mapname;
347                 if (nummaps >= 1)
348                 {
349                         n = 0;
350                         while (n < nummaps)
351                         {
352                                 if (argv(n) == mapname)
353                                         break;
354                                 n = n + 1;
355                         }
356                         n = n + 1;
357                         if (n >= nummaps)
358                                 n = 0;
359                         nextmap = argv(n);
360                 }
361                 changelevel (nextmap);
362                 */
363         }
364 };
365
366
367 /*
368 ============
369 IntermissionThink
370
371 When the player presses attack or jump, change to the next level
372 ============
373 */
374 void() IntermissionThink =
375 {
376         if (time < intermission_exittime)
377                 return;
378
379         if (time < intermission_exittime + 10 && !self.button0 && !self.button1 && !self.button2 && !self.button3)
380                 return;
381
382         GotoNextMap ();
383 };
384
385 /*
386 ============
387 FindIntermission
388
389 Returns the entity to view from
390 ============
391 */
392 /*
393 entity() FindIntermission =
394 {
395         local   entity spot;
396         local   float cyc;
397
398 // look for info_intermission first
399         spot = find (world, classname, "info_intermission");
400         if (spot)
401         {       // pick a random one
402                 cyc = random() * 4;
403                 while (cyc > 1)
404                 {
405                         spot = find (spot, classname, "info_intermission");
406                         if (!spot)
407                                 spot = find (spot, classname, "info_intermission");
408                         cyc = cyc - 1;
409                 }
410                 return spot;
411         }
412
413 // then look for the start position
414         spot = find (world, classname, "info_player_start");
415         if (spot)
416                 return spot;
417
418 // testinfo_player_start is only found in regioned levels
419         spot = find (world, classname, "testplayerstart");
420         if (spot)
421                 return spot;
422
423 // then look for the start position
424         spot = find (world, classname, "info_player_deathmatch");
425         if (spot)
426                 return spot;
427
428         //objerror ("FindIntermission: no spot");
429         return world;
430 };
431 */
432
433 /*
434 ===============================================================================
435
436 RULES
437
438 ===============================================================================
439 */
440
441 /*
442 go to the next level for deathmatch
443 only called if a time or frag limit has expired
444 */
445 void() NextLevel =
446 {
447         gameover = TRUE;
448
449         intermission_running = 1;
450
451 // enforce a wait time before allowing changelevel
452         intermission_exittime = time + 5;
453
454         WriteByte (MSG_ALL, SVC_CDTRACK);
455         WriteByte (MSG_ALL, 3);
456         WriteByte (MSG_ALL, 3);
457
458         //pos = FindIntermission ();
459
460         other = find (world, classname, "player");
461         while (other != world)
462         {
463                 //other.nextthink = time + 0.5;
464                 other.takedamage = DAMAGE_NO;
465                 other.solid = SOLID_NOT;
466                 other.movetype = MOVETYPE_NONE;
467                 other.angles = other.v_angle;
468                 other.angles_x = other.angles_x * -1;
469                 /*
470                 if (pos != world);
471                 {
472                         other.modelindex = 0;
473                         other.weaponentity = world; // remove weapon model
474                         other.view_ofs = '0 0 0';
475                         other.angles = other.v_angle = pos.mangle;
476                         if (!other.angles)
477                         {
478                                 other.angles = other.v_angle = pos.angles;
479                                 other.v_angle_x = other.v_angle_x * -1;
480                         }
481                         other.fixangle = TRUE;          // turn this way immediately
482                         setorigin (other, pos.origin);
483                 }
484                 */
485                 other = find (other, classname, "player");
486         }
487
488         WriteByte (MSG_ALL, SVC_INTERMISSION);
489 };
490
491 /*
492 ============
493 CheckRules_Player
494
495 Exit deathmatch games upon conditions
496 ============
497 */
498 void() CheckRules_Player =
499 {
500         local float fraglimit;
501
502         if (gameover)   // someone else quit the game already
503                 return;
504
505         fraglimit = cvar("fraglimit");
506         if (fraglimit && self.frags >= fraglimit)
507         {
508                 NextLevel ();
509                 return;
510         }
511 };
512
513 float checkrules_oneminutewarning;
514 float checkrules_leaderfrags;
515 entity checkrules_leader;
516
517 /*
518 ============
519 CheckRules_World
520
521 Exit deathmatch games upon conditions
522 ============
523 */
524 void() CheckRules_World =
525 {
526         local float timelimit;
527         local float fraglimit;
528         local float checkrules_oldleaderfrags;
529         local entity checkrules_oldleader;
530         local entity head;
531
532         if (intermission_running)
533         if (time >= intermission_exittime + 60)
534         {
535                 GotoNextMap();
536                 return;
537         }
538
539         if (gameover)   // someone else quit the game already
540                 return;
541
542         timelimit = cvar("timelimit") * 60;
543         fraglimit = cvar("fraglimit");
544
545         if (timelimit && time >= timelimit)
546         {
547                 NextLevel ();
548                 return;
549         }
550
551         if (!checkrules_oneminutewarning && timelimit && time > timelimit - 60)
552         {
553                 checkrules_oneminutewarning = TRUE;
554                 sound(world, CHAN_AUTO, "announcer/1minuteremains.wav", 1, ATTN_NONE);
555         }
556
557         checkrules_oldleader = checkrules_leader;
558         checkrules_oldleaderfrags = checkrules_leaderfrags;
559         checkrules_leaderfrags = 0;
560         checkrules_leader = world;
561         head = findchain(classname, "player");
562         while (head)
563         {
564                 if (checkrules_leaderfrags < head.frags)
565                 {
566                         checkrules_leaderfrags = head.frags;
567                         checkrules_leader = head;
568                 }
569                 head = head.chain;
570         }
571         if (checkrules_leaderfrags <= 0)
572         {
573                 checkrules_leader = world;
574                 checkrules_leaderfrags = 0;
575         }
576         checkrules_leaderfrags = floor(checkrules_leaderfrags);
577         if (checkrules_leaderfrags != checkrules_oldleaderfrags)
578         {
579                 if (checkrules_leaderfrags == fraglimit - 1)
580                         sound(world, CHAN_AUTO, "announcer/1fragleft.wav", 1, ATTN_NONE);
581                 else if (checkrules_leaderfrags == fraglimit - 2)
582                         sound(world, CHAN_AUTO, "announcer/2fragsleft.wav", 1, ATTN_NONE);
583                 else if (checkrules_leaderfrags == fraglimit - 3)
584                         sound(world, CHAN_AUTO, "announcer/3fragsleft.wav", 1, ATTN_NONE);
585         }
586 //      if (checkrules_leader != checkrules_oldleader)// && checkrules_leaderfrags > checkrules_oldleaderfrags)
587 //              bprint("^1",checkrules_leader.netname, " has taken the lead with ", ftos(checkrules_leaderfrags), " frags\n");
588 };