]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_world.c
rewrote maplist handling to use g_maplist cvar (note: no support for multiple instanc...
[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 ("misc/itemrespawn.wav");
147
148
149         // plays music for the level if there is any
150         if (self.noise)
151         {
152                 precache_sound (self.noise);
153                 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
154         }
155
156                 // 0 normal
157         lightstyle(0, "m");
158
159         // 1 FLICKER (first variety)
160         lightstyle(1, "mmnmmommommnonmmonqnmmo");
161
162         // 2 SLOW STRONG PULSE
163         lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
164
165         // 3 CANDLE (first variety)
166         lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
167
168         // 4 FAST STROBE
169         lightstyle(4, "mamamamamama");
170
171         // 5 GENTLE PULSE 1
172         lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
173
174         // 6 FLICKER (second variety)
175         lightstyle(6, "nmonqnmomnmomomno");
176
177         // 7 CANDLE (second variety)
178         lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
179
180         // 8 CANDLE (third variety)
181         lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
182
183         // 9 SLOW STROBE (fourth variety)
184         lightstyle(9, "aaaaaaaazzzzzzzz");
185
186         // 10 FLUORESCENT FLICKER
187         lightstyle(10, "mmamammmmammamamaaamammma");
188
189         // 11 SLOW PULSE NOT FADE TO BLACK
190         lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
191
192         // styles 32-62 are assigned by the light program for switchable lights
193
194         // 63 testing
195         lightstyle(63, "a");
196
197         if (cvar("g_domination"))
198                 dom_init();
199 }
200
201 void light (void)
202 {
203         makestatic (self);
204 }
205
206 /*
207 // reads and alters data/maplist.cfg (sliding it one line), and returns a
208 // strzoned string containing the next map
209 #define MAPLIST "maplist.cfg"
210 string() Nex_RotateMapList =
211 {
212         local float lHandle;
213         local string lNextMap;
214         local string lCurrentMap;
215         local string lBuffer;
216
217         lHandle = fopen( MAPLIST, FILE_READ );
218         if( lHandle < 0 ) {
219                 fclose( lHandle );
220                 // restart the current map if no other map is not found
221                 return strzone( mapname );
222         }
223
224         // get the first line that will be moved to the end later
225         lCurrentMap = strzone( fgets( lHandle ) );
226         if( !lCurrentMap ) {
227                 fclose( lHandle );
228                 // restart the current map if no other map is not found
229                 return strzone( mapname );
230         }
231
232         // now get the second line which is the map that should be loaded next
233         lBuffer = fgets( lHandle );
234         // if there isnt a second line, nothing needs to be rotated
235         if( !lBuffer ) {
236                 fclose( lHandle );
237                 strunzone( lCurrentMap );
238                 // restart the current map if no other map is not found
239                 return strzone( mapname );
240         }
241
242         // since lBuffer holds the next map, it is assigned to nextmap
243         lNextMap = strzone( lBuffer );
244
245         // since fgets uses its own buffer we need to move lBuffer to a tempstring
246         // before reading the next line (or lBuffer will be lost)
247         lBuffer = strcat( lBuffer );
248
249         // read in the rest of the list
250         while( 1 )  {
251                 local string lLine;
252
253                 lLine = fgets( lHandle );
254                 if( !lLine ) {
255                         break;
256                 }
257
258                 lBuffer = strcat( lBuffer, "\n", lLine );
259         }
260         // rotate the list
261         lBuffer = strcat( lBuffer, "\n", lCurrentMap );
262
263         // dismiss lCurrentmap now
264         strunzone( lCurrentMap );
265
266         // and close the file handle
267         fclose( lHandle );
268
269         // open the maplist for output this one
270         lHandle = fopen( MAPLIST, FILE_WRITE );
271         if( lHandle < 0 ) {
272                 // this shouldnt happen!
273                 // print a warning/error message
274                 dprint( "Couldn't open ", MAPLIST, " for output!\n" );
275
276                 strunzone( lNextMap );
277
278                 // we return the currently running map
279                 return strzone( mapname );
280         }
281
282         fputs( lHandle, lBuffer );
283
284         fclose( lHandle );
285
286         return lNextMap;
287 };
288 */
289
290 float gameover;
291 float intermission_running;
292 float intermission_exittime;
293 float alreadychangedlevel;
294
295 void() GotoNextMap =
296 {
297         local string nextmap;
298         local float n, nummaps;
299         local string s;
300         if (alreadychangedlevel)
301                 return;
302         alreadychangedlevel = TRUE;
303         if (cvar("samelevel"))  // if samelevel is set, stay on same level
304                 changelevel (mapname);
305         else
306         {
307                 // method 1
308                 /*
309                 //local entity pos;
310                 local float fh;
311                 local string line;
312
313                 // restart current map if no cycle is found
314                 nextmap = mapname;
315                 fh = fopen("maplist.cfg", FILE_READ);
316                 if (fh >= 0)
317                 {
318                         while (1)
319                         {
320                                 line = fgets(fh);
321                                 if (!line)
322                                         break;
323                                 if (line == mapname)
324                                 {
325                                         line = fgets(fh);
326                                         if (!line)
327                                                 break;
328                                         nextmap = line;
329                                         break;
330                                 }
331                         }
332                         fclose(fh);
333                 }
334                 changelevel (nextmap);
335                 */
336                 // method 2
337                 //nextmap = Nex_RotateMapList();
338                 //changelevel (nextmap);
339                 //strunzone (nextmap);
340                 // method 3
341                 s = cvar_string("g_maplist");
342                 nummaps = tokenize(s);
343                 // if no map list, restart current one
344                 nextmap = mapname;
345                 if (nummaps >= 1)
346                 {
347                         n = 0;
348                         while (n < nummaps)
349                         {
350                                 if (argv(n) == mapname)
351                                         break;
352                                 n = n + 1;
353                         }
354                         n = n + 1;
355                         if (n >= nummaps)
356                                 n = 0;
357                         nextmap = argv(n);
358                 }
359                 changelevel (nextmap);
360         }
361 };
362
363
364 /*
365 ============
366 IntermissionThink
367
368 When the player presses attack or jump, change to the next level
369 ============
370 */
371 void() IntermissionThink =
372 {
373         if (time < intermission_exittime)
374                 return;
375
376         if (time < intermission_exittime + 10 && !self.button0 && !self.button1 && !self.button2 && !self.button3)
377                 return;
378
379         GotoNextMap ();
380 };
381
382 /*
383 ============
384 FindIntermission
385
386 Returns the entity to view from
387 ============
388 */
389 /*
390 entity() FindIntermission =
391 {
392         local   entity spot;
393         local   float cyc;
394
395 // look for info_intermission first
396         spot = find (world, classname, "info_intermission");
397         if (spot)
398         {       // pick a random one
399                 cyc = random() * 4;
400                 while (cyc > 1)
401                 {
402                         spot = find (spot, classname, "info_intermission");
403                         if (!spot)
404                                 spot = find (spot, classname, "info_intermission");
405                         cyc = cyc - 1;
406                 }
407                 return spot;
408         }
409
410 // then look for the start position
411         spot = find (world, classname, "info_player_start");
412         if (spot)
413                 return spot;
414
415 // testinfo_player_start is only found in regioned levels
416         spot = find (world, classname, "testplayerstart");
417         if (spot)
418                 return spot;
419
420 // then look for the start position
421         spot = find (world, classname, "info_player_deathmatch");
422         if (spot)
423                 return spot;
424
425         //objerror ("FindIntermission: no spot");
426         return world;
427 };
428 */
429
430 /*
431 ===============================================================================
432
433 RULES
434
435 ===============================================================================
436 */
437
438 /*
439 go to the next level for deathmatch
440 only called if a time or frag limit has expired
441 */
442 void() NextLevel =
443 {
444         gameover = TRUE;
445
446         intermission_running = 1;
447
448 // enforce a wait time before allowing changelevel
449         intermission_exittime = time + 5;
450
451         WriteByte (MSG_ALL, SVC_CDTRACK);
452         WriteByte (MSG_ALL, 3);
453         WriteByte (MSG_ALL, 3);
454
455         //pos = FindIntermission ();
456
457         other = find (world, classname, "player");
458         while (other != world)
459         {
460                 //other.nextthink = time + 0.5;
461                 other.takedamage = DAMAGE_NO;
462                 other.solid = SOLID_NOT;
463                 other.movetype = MOVETYPE_NONE;
464                 other.angles = other.v_angle;
465                 other.angles_x = other.angles_x * -1;
466                 /*
467                 if (pos != world);
468                 {
469                         other.modelindex = 0;
470                         other.weaponentity = world; // remove weapon model
471                         other.view_ofs = '0 0 0';
472                         other.angles = other.v_angle = pos.mangle;
473                         if (!other.angles)
474                         {
475                                 other.angles = other.v_angle = pos.angles;
476                                 other.v_angle_x = other.v_angle_x * -1;
477                         }
478                         other.fixangle = TRUE;          // turn this way immediately
479                         setorigin (other, pos.origin);
480                 }
481                 */
482                 other = find (other, classname, "player");
483         }
484
485         WriteByte (MSG_ALL, SVC_INTERMISSION);
486 };
487
488 /*
489 ============
490 CheckRules
491
492 Exit deathmatch games upon conditions
493 ============
494 */
495 void() CheckRules =
496 {
497         local   float           timelimit;
498         local   float           fraglimit;
499
500         if (intermission_running)
501         if (time >= intermission_exittime + 60)
502         {
503                 GotoNextMap();
504                 return;
505         }
506
507         if (gameover)   // someone else quit the game already
508                 return;
509
510         timelimit = cvar("timelimit") * 60;
511         fraglimit = cvar("fraglimit");
512
513         if (timelimit && time >= timelimit)
514         {
515                 NextLevel ();
516                 return;
517         }
518
519         if (fraglimit && self.frags >= fraglimit)
520         {
521                 NextLevel ();
522                 return;
523         }
524 };