]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/g_world.c
Got rid of sparks
[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/player/marine.zym");
13         precache_model ("models/player/specop.zym");
14         precache_model ("models/player/mulder.zym");
15         precache_model ("models/player/insurrectionist.zym");
16         precache_model ("models/player/fshock.zym");
17         //precache_model ("models/player/grunt.zym");
18         //precache_model ("models/player/pyria.zym");
19         precache_model ("models/player/lurk.zym");
20         precache_model ("models/player/visitant.zym");
21         precache_model ("models/player/headhunter.zym");
22         //precache_model ("models/player/jeandarc.zym");
23         precache_model ("models/player/robot.zym");
24         //precache_model ("models/player/lycanthrope.zym");
25         //precache_model ("models/player/shock.zym");
26         //precache_model ("models/player/carni.zym");
27
28         precache_model ("models/misc/chatbubble.spr");
29
30         precache_model ("models/weapons/g_shotgun.md3");
31         precache_model ("models/weapons/g_uzi.md3");
32         precache_model ("models/weapons/g_gl.md3");
33         precache_model ("models/weapons/g_electro.md3");
34         precache_model ("models/weapons/g_crylink.md3");
35         precache_model ("models/weapons/g_nex.md3");
36         precache_model ("models/weapons/g_hagar.md3");
37         precache_model ("models/weapons/g_rl.md3");
38
39         precache_model ("models/weapons/v_laser.md3");
40         precache_model ("models/weapons/v_shotgun.md3");
41         precache_model ("models/weapons/v_uzi.md3");
42         precache_model ("models/weapons/v_gl.md3");
43         precache_model ("models/weapons/v_electro.md3");
44         precache_model ("models/weapons/v_crylink.md3");
45         precache_model ("models/weapons/v_nex.md3");
46         precache_model ("models/weapons/v_hagar.md3");
47         precache_model ("models/weapons/v_rl.md3");
48
49         precache_model ("models/sprites/plasmahitwall.spr32");
50         precache_model ("models/sprites/muzzleflash.spr32");
51         precache_model ("models/sprites/plasmashot.spr32");
52         precache_model ("models/sprites/dpexplosion1.spr32");
53         precache_model ("models/sprites/dpexplosion2.spr32");
54
55         precache_model ("models/grenademodel.md3");
56         precache_model ("models/hagarmissile.mdl");
57         precache_model ("models/rocket.md3");
58         precache_model ("models/bullet.mdl");
59         precache_model ("models/casing_bronze.mdl");
60         precache_model ("models/casing_shell.mdl");
61         precache_model ("models/casing_steel.mdl");
62         precache_model ("models/beam.mdl");
63         precache_model ("models/flash.md3");
64         precache_model ("models/nexflash.md3");
65         precache_model ("models/laser.mdl");
66         precache_model ("models/elaser.mdl");
67         precache_model ("models/ebomb.mdl");
68         precache_model ("models/plasma.mdl");
69         precache_model ("models/plasmatrail.mdl");
70         precache_model ("models/tracer.mdl");
71
72         precache_model ("models/items/g_h1.md3");
73         precache_model ("models/items/g_h25.md3");
74         precache_model ("models/items/g_h100.md3");
75
76         precache_model ("models/items/g_a1.md3");
77         precache_model ("models/items/g_a25.md3");
78
79         precache_model ("models/weapons/w_uzi.zym");
80         precache_model ("models/weapons/w_laser.zym");
81         precache_model ("models/weapons/w_shotgun.zym");
82         precache_model ("models/weapons/w_gl.zym");
83         precache_model ("models/weapons/w_electro.zym");
84         precache_model ("models/weapons/w_crylink.zym");
85         precache_model ("models/weapons/w_nex.zym");
86         precache_model ("models/weapons/w_hagar.zym");
87         precache_model ("models/weapons/w_rl.zym");
88
89         precache_model ("models/items/a_shells.md3");
90         precache_model ("models/items/a_cells.md3");
91         precache_model ("models/items/a_rockets.md3");
92         precache_model ("models/items/a_bullets.mdl");
93
94         precache_model ("models/items/g_strength.md3");
95         precache_model ("models/items/g_invincible.md3");
96
97         precache_model ("models/gibs/eye.md3");
98         precache_model ("models/gibs/gib1.md3");
99         precache_model ("models/gibs/gib2.md3");
100         precache_model ("models/gibs/gib3.md3");
101         precache_model ("models/gibs/gib4.md3");
102         precache_model ("models/gibs/gib5.md3");
103         precache_model ("models/gibs/gib6.md3");
104         precache_model ("models/gibs/chunk.mdl");
105         precache_model ("models/gibs/bloodyskull.md3");
106
107         precache_sound ("weapons/lasergun_fire.wav");
108         precache_sound ("weapons/laserimpact.wav");
109         precache_sound ("weapons/uzi_fire.wav");
110         precache_sound ("weapons/shotgun_fire.wav");
111         precache_sound ("weapons/grenade_fire.wav");
112         precache_sound ("weapons/grenade_impact.wav");
113         precache_sound ("weapons/grenade_bounce.wav");
114         precache_sound ("weapons/nexfire.wav");
115         precache_sound ("weapons/neximpact.wav");
116         precache_sound ("weapons/electro_fire.wav");
117         precache_sound ("weapons/electro_fly.wav");
118         precache_sound ("weapons/missile_fly.wav");
119         precache_sound ("weapons/rocket_fire.wav");
120         precache_sound ("weapons/rocket_impact.wav");
121         precache_sound ("weapons/hagar_fire.wav");
122         precache_sound ("weapons/hagar_fire2.wav");
123         precache_sound ("weapons/hagexp1.wav");
124         precache_sound ("weapons/hagexp2.wav");
125         precache_sound ("weapons/hagexp3.wav");
126         precache_sound ("weapons/ric1.wav");
127         precache_sound ("weapons/ric2.wav");
128         precache_sound ("weapons/ric3.wav");
129         precache_sound ("weapons/weaponpickup.wav");
130         precache_sound ("weapons/crylink.wav");
131         precache_sound ("weapons/crylink2.wav");
132         precache_sound ("weapons/plasmahit.wav");
133         precache_sound ("weapons/uzi_fire_secondary.wav");
134         precache_sound ("weapons/tink1.wav");
135         precache_sound ("weapons/weapon_switch.wav");
136
137         precache_sound ("misc/itempickup.wav");
138         precache_sound ("misc/bodyimpact1.wav");
139         precache_sound ("misc/bodyimpact2.wav");
140         precache_sound ("misc/armorimpact.wav");
141         precache_sound ("misc/hit.wav");
142         precache_sound ("misc/teleport.wav");
143         precache_sound ("misc/megahealth.wav");
144         precache_sound ("misc/mediumhealth.wav");
145         precache_sound ("misc/gib.wav");
146         precache_sound ("misc/jumppad.wav");
147         precache_sound ("misc/hitground1.wav");
148         precache_sound ("misc/hitground2.wav");
149         precache_sound ("misc/hitground3.wav");
150         precache_sound ("misc/hitground4.wav");
151         precache_sound ("misc/talk.wav");
152         precache_sound ("misc/gib_splat01.wav");
153         precache_sound ("misc/gib_splat02.wav");
154         precache_sound ("misc/gib_splat03.wav");
155         precache_sound ("misc/gib_splat04.wav");
156         precache_sound ("misc/powerup.wav");
157
158         precache_sound ("misc/itemrespawn.wav");
159
160
161         // plays music for the level if there is any
162         if (self.noise)
163         {
164                 precache_sound (self.noise);
165                 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
166         }
167
168                 // 0 normal
169         lightstyle(0, "m");
170
171         // 1 FLICKER (first variety)
172         lightstyle(1, "mmnmmommommnonmmonqnmmo");
173
174         // 2 SLOW STRONG PULSE
175         lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
176
177         // 3 CANDLE (first variety)
178         lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
179
180         // 4 FAST STROBE
181         lightstyle(4, "mamamamamama");
182
183         // 5 GENTLE PULSE 1
184         lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
185
186         // 6 FLICKER (second variety)
187         lightstyle(6, "nmonqnmomnmomomno");
188
189         // 7 CANDLE (second variety)
190         lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
191
192         // 8 CANDLE (third variety)
193         lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
194
195         // 9 SLOW STROBE (fourth variety)
196         lightstyle(9, "aaaaaaaazzzzzzzz");
197
198         // 10 FLUORESCENT FLICKER
199         lightstyle(10, "mmamammmmammamamaaamammma");
200
201         // 11 SLOW PULSE NOT FADE TO BLACK
202         lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
203
204         // styles 32-62 are assigned by the light program for switchable lights
205
206         // 63 testing
207         lightstyle(63, "a");
208
209         if (cvar("g_domination"))
210                 dom_init();
211 }
212
213 void light (void)
214 {
215         makestatic (self);
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 void() GotoNextMap =
306 {
307         local string nextmap;
308         if (alreadychangedlevel)
309                 return;
310         alreadychangedlevel = TRUE;
311         if (cvar("samelevel"))  // if samelevel is set, stay on same level
312                 changelevel (mapname);
313         else
314         {
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 = mapname;
322                 fh = fopen("maplist.cfg", FILE_READ);
323                 if (fh >= 0)
324                 {
325                         while (1)
326                         {
327                                 line = fgets(fh);
328                                 if (!line)
329                                         break;
330                                 if (line == mapname)
331                                 {
332                                         line = fgets(fh);
333                                         if (!line)
334                                                 break;
335                                         nextmap = line;
336                                         break;
337                                 }
338                         }
339                         fclose(fh);
340                 }
341                 changelevel (nextmap);
342                 */
343
344                 nextmap = Nex_RotateMapList();
345                 changelevel (nextmap);
346                 strunzone (nextmap);
347         }
348 };
349
350
351 /*
352 ============
353 IntermissionThink
354
355 When the player presses attack or jump, change to the next level
356 ============
357 */
358 void() IntermissionThink =
359 {
360         if (time < intermission_exittime)
361                 return;
362
363         if (time < intermission_exittime + 10 && !self.button0 && !self.button1 && !self.button2 && !self.button3)
364                 return;
365
366         GotoNextMap ();
367 };
368
369 /*
370 ============
371 FindIntermission
372
373 Returns the entity to view from
374 ============
375 */
376 /*
377 entity() FindIntermission =
378 {
379         local   entity spot;
380         local   float cyc;
381
382 // look for info_intermission first
383         spot = find (world, classname, "info_intermission");
384         if (spot)
385         {       // pick a random one
386                 cyc = random() * 4;
387                 while (cyc > 1)
388                 {
389                         spot = find (spot, classname, "info_intermission");
390                         if (!spot)
391                                 spot = find (spot, classname, "info_intermission");
392                         cyc = cyc - 1;
393                 }
394                 return spot;
395         }
396
397 // then look for the start position
398         spot = find (world, classname, "info_player_start");
399         if (spot)
400                 return spot;
401
402 // testinfo_player_start is only found in regioned levels
403         spot = find (world, classname, "testplayerstart");
404         if (spot)
405                 return spot;
406
407 // then look for the start position
408         spot = find (world, classname, "info_player_deathmatch");
409         if (spot)
410                 return spot;
411
412         //objerror ("FindIntermission: no spot");
413         return world;
414 };
415 */
416
417 /*
418 ===============================================================================
419
420 RULES
421
422 ===============================================================================
423 */
424
425 /*
426 go to the next level for deathmatch
427 only called if a time or frag limit has expired
428 */
429 void() NextLevel =
430 {
431         gameover = TRUE;
432
433         intermission_running = 1;
434
435 // enforce a wait time before allowing changelevel
436         intermission_exittime = time + 5;
437
438         WriteByte (MSG_ALL, SVC_CDTRACK);
439         WriteByte (MSG_ALL, 3);
440         WriteByte (MSG_ALL, 3);
441
442         //pos = FindIntermission ();
443
444         other = find (world, classname, "player");
445         while (other != world)
446         {
447                 //other.nextthink = time + 0.5;
448                 other.takedamage = DAMAGE_NO;
449                 other.solid = SOLID_NOT;
450                 other.movetype = MOVETYPE_NONE;
451                 other.angles = other.v_angle;
452                 other.angles_x = other.angles_x * -1;
453                 /*
454                 if (pos != world);
455                 {
456                         other.modelindex = 0;
457                         other.weaponentity = world; // remove weapon model
458                         other.view_ofs = '0 0 0';
459                         other.angles = other.v_angle = pos.mangle;
460                         if (!other.angles)
461                         {
462                                 other.angles = other.v_angle = pos.angles;
463                                 other.v_angle_x = other.v_angle_x * -1;
464                         }
465                         other.fixangle = TRUE;          // turn this way immediately
466                         setorigin (other, pos.origin);
467                 }
468                 */
469                 other = find (other, classname, "player");
470         }
471
472         WriteByte (MSG_ALL, SVC_INTERMISSION);
473 };
474
475 /*
476 ============
477 CheckRules
478
479 Exit deathmatch games upon conditions
480 ============
481 */
482 void() CheckRules =
483 {
484         local   float           timelimit;
485         local   float           fraglimit;
486
487         if (intermission_running)
488         if (time >= intermission_exittime + 60)
489         {
490                 GotoNextMap();
491                 return;
492         }
493
494         if (gameover)   // someone else quit the game already
495                 return;
496
497         timelimit = cvar("timelimit") * 60;
498         fraglimit = cvar("fraglimit");
499
500         if (timelimit && time >= timelimit)
501         {
502                 NextLevel ();
503                 return;
504         }
505
506         if (fraglimit && self.frags >= fraglimit)
507         {
508                 NextLevel ();
509                 return;
510         }
511 };