8 default_player_alpha = cvar("g_balance_cloaked_alpha");
12 default_player_alpha = cvar("g_player_alpha");
13 if(default_player_alpha <= 0)
14 default_player_alpha = 1;
22 cvar_set("_sv_init", "0");
23 tokenize(cvar_string("g_maplist"));
24 if(argv(0) != GetMapname())
26 cvar_set("nextmap", argv(0));
32 float world_already_spawned;
33 void worldspawn (void)
35 if(world_already_spawned)
36 error("world already spawned - you may have EXACTLY ONE worldspawn!");
37 world_already_spawned = TRUE;
38 // Precache all player models
39 // Workaround for "invisible players"
40 precache_model("models/player/carni.zym");
41 precache_model("models/player/crash.zym");
42 precache_model("models/player/grunt.zym");
43 precache_model("models/player/headhunter.zym");
44 precache_model("models/player/insurrectionist.zym");
45 precache_model("models/player/jeandarc.zym");
46 precache_model("models/player/lurk.zym");
47 precache_model("models/player/lycanthrope.zym");
48 precache_model("models/player/marine.zym");
49 precache_model("models/player/nexus.zym");
50 precache_model("models/player/pyria.zym");
51 precache_model("models/player/shock.zym");
52 precache_model("models/player/skadi.zym");
53 precache_model("models/player/specop.zym");
54 precache_model("models/player/visitant.zym");
56 //precache_model ("progs/beam.mdl");
57 precache_model ("models/bullet.mdl");
58 precache_model ("models/casing_bronze.mdl");
59 precache_model ("models/casing_shell.mdl");
60 precache_model ("models/casing_steel.mdl");
61 precache_model ("models/ebomb.mdl");
62 precache_model ("models/elaser.mdl");
63 precache_model ("models/flash.md3");
64 precache_model ("models/gibs/bloodyskull.md3");
65 precache_model ("models/gibs/chunk.mdl");
66 precache_model ("models/gibs/eye.md3");
67 precache_model ("models/gibs/gib1.md3");
68 //precache_model ("models/gibs/gib2.md3");
69 //precache_model ("models/gibs/gib3.md3");
70 //precache_model ("models/gibs/gib4.md3");
71 precache_model ("models/gibs/gib5.md3");
72 //precache_model ("models/gibs/gib6.md3");
73 precache_model ("models/gibs/gib1.mdl");
74 precache_model ("models/gibs/gib2.mdl");
75 precache_model ("models/gibs/gib3.mdl");
76 precache_model ("models/grenademodel.md3");
77 precache_model ("models/hagarmissile.mdl");
78 precache_model ("models/items/a_bullets.mdl");
79 precache_model ("models/items/a_cells.md3");
80 precache_model ("models/items/a_rockets.md3");
81 precache_model ("models/items/a_shells.md3");
82 precache_model ("models/items/g_a1.md3");
83 precache_model ("models/items/g_a25.md3");
84 precache_model ("models/items/g_h1.md3");
85 precache_model ("models/items/g_h25.md3");
86 precache_model ("models/items/g_h100.md3");
87 precache_model ("models/items/g_invincible.md3");
88 precache_model ("models/items/g_strength.md3");
89 precache_model ("models/laser.mdl");
90 precache_model ("models/misc/chatbubble.spr");
91 precache_model ("models/misc/teambubble.spr");
92 precache_model ("models/nexflash.md3");
93 precache_model ("models/plasma.mdl");
94 precache_model ("models/plasmatrail.mdl");
95 precache_model ("models/rocket.md3");
96 //precache_model ("models/sprites/grenexpl.spr");
97 precache_model ("models/runematch/rune.mdl");
98 precache_model ("models/runematch/curse.mdl");
99 //precache_model ("models/sprites/hagar.spr");
100 //precache_model ("models/sprites/muzzleflash.spr32");
101 //precache_model ("models/sprites/electrocombo.spr32");
102 //precache_model ("models/sprites/plasmahitwall.spr32");
103 //precache_model ("models/sprites/plasmashot.spr32");
104 //precache_model ("models/sprites/rockexpl.spr");
105 precache_model ("models/tracer.mdl");
106 precache_model ("models/uziflash.md3");
107 precache_model ("models/weapons/g_crylink.md3");
108 precache_model ("models/weapons/g_electro.md3");
109 precache_model ("models/weapons/g_gl.md3");
110 precache_model ("models/weapons/g_hagar.md3");
111 precache_model ("models/weapons/g_nex.md3");
112 precache_model ("models/weapons/g_rl.md3");
113 precache_model ("models/weapons/g_shotgun.md3");
114 precache_model ("models/weapons/g_uzi.md3");
115 precache_model ("models/weapons/v_crylink.md3");
116 precache_model ("models/weapons/v_electro.md3");
117 precache_model ("models/weapons/v_gl.md3");
118 precache_model ("models/weapons/v_hagar.md3");
119 precache_model ("models/weapons/v_laser.md3");
120 precache_model ("models/weapons/v_nex.md3");
121 precache_model ("models/weapons/v_rl.md3");
122 precache_model ("models/weapons/v_shotgun.md3");
123 precache_model ("models/weapons/v_uzi.md3");
124 precache_model ("models/weapons/w_crylink.zym");
125 precache_model ("models/weapons/w_electro.zym");
126 precache_model ("models/weapons/w_gl.zym");
127 precache_model ("models/weapons/w_hagar.zym");
128 precache_model ("models/weapons/w_laser.zym");
129 precache_model ("models/weapons/w_nex.zym");
130 precache_model ("models/weapons/w_rl.zym");
131 precache_model ("models/weapons/w_shotgun.zym");
132 precache_model ("models/weapons/w_uzi.zym");
134 // laser for laser-guided weapons
135 precache_model ("models/laser_dot.mdl");
137 precache_sound ("misc/null.wav");
138 precache_sound ("misc/armor1.wav");
139 precache_sound ("misc/armor25.wav");
140 precache_sound ("misc/armorimpact.wav");
141 precache_sound ("misc/bodyimpact1.wav");
142 precache_sound ("misc/bodyimpact2.wav");
143 precache_sound ("misc/gib.wav");
144 precache_sound ("misc/gib_splat01.wav");
145 precache_sound ("misc/gib_splat02.wav");
146 precache_sound ("misc/gib_splat03.wav");
147 precache_sound ("misc/gib_splat04.wav");
148 //precache_sound ("misc/h2ohit.wav");
149 precache_sound ("misc/hit.wav");
150 precache_sound ("misc/footstep01.wav");
151 precache_sound ("misc/footstep02.wav");
152 precache_sound ("misc/footstep03.wav");
153 precache_sound ("misc/footstep04.wav");
154 precache_sound ("misc/footstep05.wav");
155 precache_sound ("misc/footstep06.wav");
156 precache_sound ("misc/hitground1.ogg");
157 precache_sound ("misc/hitground2.ogg");
158 precache_sound ("misc/hitground3.ogg");
159 precache_sound ("misc/hitground4.ogg");
160 precache_sound ("misc/itempickup.ogg");
161 precache_sound ("misc/itemrespawn.ogg");
162 precache_sound ("misc/jumppad.ogg");
163 precache_sound ("misc/mediumhealth.ogg");
164 precache_sound ("misc/megahealth.ogg");
165 precache_sound ("misc/minihealth.ogg");
166 precache_sound ("misc/powerup.ogg");
167 precache_sound ("misc/powerup_shield.ogg");
168 precache_sound ("misc/talk.wav");
169 precache_sound ("misc/teleport.ogg");
170 precache_sound ("plats/medplat1.wav");
171 precache_sound ("plats/medplat2.wav");
172 precache_sound ("player/lava.wav");
173 precache_sound ("player/slime.wav");
174 precache_sound ("weapons/crylink_fire.ogg");
175 precache_sound ("weapons/electro_bounce.ogg");
176 precache_sound ("weapons/electro_fire.ogg");
177 precache_sound ("weapons/electro_fire2.ogg");
178 precache_sound ("weapons/electro_fly.wav");
179 precache_sound ("weapons/electro_impact.ogg");
180 precache_sound ("weapons/electro_impact_combo.ogg");
181 //precache_sound ("weapons/grenade_bounce.ogg");
182 precache_sound ("weapons/grenade_bounce1.ogg");
183 precache_sound ("weapons/grenade_bounce2.ogg");
184 precache_sound ("weapons/grenade_bounce3.ogg");
185 precache_sound ("weapons/grenade_fire.ogg");
186 precache_sound ("weapons/grenade_impact.ogg");
187 precache_sound ("weapons/hagar_fire.ogg");
188 precache_sound ("weapons/hagexp1.ogg");
189 precache_sound ("weapons/hagexp2.ogg");
190 precache_sound ("weapons/hagexp3.ogg");
191 precache_sound ("weapons/hook_fire.ogg");
192 precache_sound ("weapons/hook_impact.ogg");
193 precache_sound ("weapons/lasergun_fire.ogg");
194 precache_sound ("weapons/laserimpact.ogg");
195 precache_sound ("weapons/nexfire.ogg");
196 precache_sound ("weapons/neximpact.ogg");
197 precache_sound ("weapons/ric1.ogg");
198 precache_sound ("weapons/ric2.ogg");
199 precache_sound ("weapons/ric3.ogg");
200 precache_sound ("weapons/rocket_fire.ogg");
201 precache_sound ("weapons/rocket_fly.wav");
202 precache_sound ("weapons/rocket_impact.ogg");
203 precache_sound ("weapons/rocket_det.ogg");
204 precache_sound ("weapons/shotgun_fire.ogg");
205 precache_sound ("weapons/tink1.ogg");
206 precache_sound ("weapons/uzi_fire.ogg");
207 precache_sound ("weapons/weapon_switch.ogg");
208 precache_sound ("weapons/weaponpickup.ogg");
209 precache_sound ("weapons/strength_fire.ogg");
211 //precache_sound ("announce/male/kill10.ogg");
212 //precache_sound ("announce/male/kill15.ogg");
213 //precache_sound ("announce/male/kill20.ogg");
214 //precache_sound ("announce/male/kill25.ogg");
215 //precache_sound ("announce/male/kill3.ogg");
216 //precache_sound ("announce/male/kill30.ogg");
217 //precache_sound ("announce/male/kill4.ogg");
218 //precache_sound ("announce/male/kill5.ogg");
219 //precache_sound ("announce/male/kill6.ogg");
220 //precache_sound ("announce/male/mapkill1.ogg");
221 //precache_sound ("announce/robotic/last_second_save.ogg");
222 //precache_sound ("announce/robotic/narrowly_averted.ogg");
223 //precache_sound ("minstagib/mockery.ogg");
225 // announcer sounds - male
226 precache_sound ("announcer/male/03kills.ogg");
227 precache_sound ("announcer/male/05kills.ogg");
228 precache_sound ("announcer/male/10kills.ogg");
229 precache_sound ("announcer/male/15kills.ogg");
230 precache_sound ("announcer/male/20kills.ogg");
231 precache_sound ("announcer/male/25kills.ogg");
232 precache_sound ("announcer/male/30kills.ogg");
233 precache_sound ("announcer/male/botlike.ogg");
234 precache_sound ("announcer/male/electrobitch.ogg");
235 precache_sound ("announcer/male/welcome.ogg");
236 precache_sound ("announcer/male/yoda.ogg");
238 // announcer sounds - robotic
239 precache_sound ("announcer/robotic/1fragleft.ogg");
240 precache_sound ("announcer/robotic/1minuteremains.ogg");
241 precache_sound ("announcer/robotic/2fragsleft.ogg");
242 precache_sound ("announcer/robotic/3fragsleft.ogg");
243 precache_sound ("announcer/robotic/lastsecond.ogg");
244 precache_sound ("announcer/robotic/narrowly.ogg");
246 // plays music for the level if there is any
249 precache_sound (self.noise);
250 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
256 // 1 FLICKER (first variety)
257 lightstyle(1, "mmnmmommommnonmmonqnmmo");
259 // 2 SLOW STRONG PULSE
260 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
262 // 3 CANDLE (first variety)
263 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
266 lightstyle(4, "mamamamamama");
269 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
271 // 6 FLICKER (second variety)
272 lightstyle(6, "nmonqnmomnmomomno");
274 // 7 CANDLE (second variety)
275 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
277 // 8 CANDLE (third variety)
278 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
280 // 9 SLOW STROBE (fourth variety)
281 lightstyle(9, "aaaaaaaazzzzzzzz");
283 // 10 FLUORESCENT FLICKER
284 lightstyle(10, "mmamammmmammamamaaamammma");
286 // 11 SLOW PULSE NOT FADE TO BLACK
287 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
289 // styles 32-62 are assigned by the light program for switchable lights
296 lms_lowest_lives = 0;
301 if(cvar("g_campaign"))
305 //if (cvar("g_domination"))
309 head = nextent(world);
314 head = nextent(head);
317 GameLogInit(); // prepare everything
318 if(cvar("sv_eventlog"))
321 GameLogEcho(":logversion:2", FALSE);
322 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
323 s = strcat(s, ftos(random()));
324 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
325 s = ":gameinfo:mutators:LIST";
326 if(cvar("g_grappling_hook"))
327 s = strcat(s, ":grappling_hook");
328 if(!cvar("g_use_ammunition"))
329 s = strcat(s, ":no_use_ammunition");
330 if(!cvar("g_pickup_items"))
331 s = strcat(s, ":no_pickup_items");
332 if(cvar("g_instagib"))
333 s = strcat(s, ":instagib");
334 if(cvar("g_rocketarena"))
335 s = strcat(s, ":rockerarena");
337 s = strcat(s, ":nixnex");
338 if(cvar("g_vampire"))
339 s = strcat(s, ":vampire");
340 if(cvar("g_laserguided_missile"))
341 s = strcat(s, ":laserguided_missile");
342 if(cvar("g_norecoil"))
343 s = strcat(s, ":norecoil");
345 s = strcat(s, ":midair");
346 if(cvar("g_minstagib"))
347 s = strcat(s, ":minstagib");
348 GameLogEcho(s, FALSE);
349 GameLogEcho(":gameinfo:end", FALSE);
352 cvar_set("nextmap", "");
356 if(cvar("g_campaign"))
365 float( string pFilename ) TryFile =
368 dprint("TryFile(\"", pFilename, "\")\n");
369 lHandle = fopen( pFilename, FILE_READ );
370 if( lHandle != -1 ) {
380 if (game == GAME_DEATHMATCH)
381 return strcat("dm_", mapname);
382 else if (game == GAME_TEAM_DEATHMATCH)
383 return strcat("tdm_", mapname);
384 else if (game == GAME_DOMINATION)
385 return strcat("dom_", mapname);
386 else if (game == GAME_CTF)
387 return strcat("ctf_", mapname);
388 else if (game == GAME_RUNEMATCH)
389 return strcat("rune_", mapname);
390 else if (game == GAME_LMS)
391 return strcat("lms_", mapname);
392 return strcat("dm_", mapname);
395 float Map_Count, Map_Current;
396 string Map_Current_Name;
398 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
399 float GetMaplistPosition()
405 for(pos = 0; pos < Map_Count; ++pos)
409 // resume normal maplist rotation if current map is not in g_maplist
410 return cvar("g_maplist_index");
413 float MapHasRightSize(string map)
415 // open map size restriction file
417 dprint("opensize "); dprint(map);
418 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
421 float mapmin, mapmax;
423 mapmin = stof(fgets(fh));
424 mapmax = stof(fgets(fh));
426 if(player_count < mapmin)
428 dprint("not enough\n");
431 if(player_count > mapmax)
433 dprint("too many\n");
436 dprint("right size\n");
439 dprint(": not found\n");
443 string Map_Filename(float position)
445 return strcat("maps/", argv(position), ".mapcfg");
448 float(float position, float pass) Map_Check =
452 map_next = argv(position);
454 if(map_next == Map_Current_Name) // same map again in first pass?
456 filename = Map_Filename(position);
457 if(TryFile(filename))
461 if(MapHasRightSize(argv(position)))
466 dprint( "Couldn't find '", filename, "'..\n" );
471 void(float position) Map_Goto =
473 cvar_set("g_maplist_index", ftos(position));
474 localcmd(strcat("exec \"", Map_Filename(position) ,"\"\n"));
477 // return codes of map selectors:
478 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
479 // -2 = permanent failure
480 float() MaplistMethod_Iterate = // usual method
484 for(pass = 1; pass <= 2; ++pass)
486 for(i = 1; i < Map_Count; ++i)
489 mapindex = math_mod(i + Map_Current, Map_Count);
490 if(Map_Check(mapindex, pass))
497 float() MaplistMethod_Repeat = // fallback method
499 if(Map_Check(Map_Current, 2))
504 float() MaplistMethod_Random = // random map selection
510 for(i = 0; i <= imax; ++i)
513 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
514 if(Map_Check(mapindex, 1))
520 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
521 // the exponent sets a bias on the map selection:
522 // the higher the exponent, the
524 float i, j, imax, insertpos;
529 return 0; // only one map, then always play this one
531 for(i = 0; i <= imax; ++i)
535 // now reinsert this at another position
536 insertpos = pow(random(), 1 / exponent); // ]0, 1]
537 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
538 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
539 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
541 // insert the current map there
543 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
544 newlist = strcat(newlist, "'", argv(j), "'");
545 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
546 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
547 newlist = strcat(newlist, "'", argv(j), "'");
548 cvar_set("g_maplist", newlist);
549 Map_Count = tokenize(newlist);
551 // NOTE: the selected map has just been inserted at (insertpos-1)th position
552 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
553 if(Map_Check(Map_Current, 1))
559 void() Maplist_Init =
562 temp = cvar_string("g_maplist");
563 Map_Count = tokenize(temp);
566 bprint( "Maplist is empty! Resetting it to default map list.\n" );
567 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
568 Map_Count = tokenize(temp);
571 error("empty maplist, cannot select a new map");
572 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
574 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
575 // this may or may not be correct, but who cares, in the worst case a map
576 // isn't chosen in the first pass that should have been
581 //local string nextmap;
582 //local float n, nummaps;
585 if (alreadychangedlevel)
587 alreadychangedlevel = TRUE;
589 if(cvar("g_campaign"))
591 CampaignPostIntermission();
595 if (cvar("samelevel")) // if samelevel is set, stay on same level
597 // this does not work because it tries to exec maps/nexdm01.mapcfg (which doesn't exist, it should be trying maps/dm_nexdm01.mapcfg for example)
598 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
599 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
600 localcmd("restart\n");
601 //changelevel (mapname);
605 // if an exit cfg is defined by exiting map, exec it.
606 exit_cfg = cvar_string("exit_cfg");
608 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
610 localcmd("exec game_reset.cfg\n");
613 if (cvar("lastlevel"))
615 localcmd(strcat("set lastlevel 0\n"));
616 localcmd(strcat("togglemenu\n"));
623 // cvar "nextmap" always gets priority
624 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
626 localcmd(strcat("exec \"maps/", cvar_string("nextmap"), ".mapcfg\"\n"));
630 for(allowReset = 1; allowReset >= 0; --allowReset)
636 if(cvar("g_maplist_shuffle") > 0)
637 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
640 if(cvar("g_maplist_selectrandom"))
641 nextMap = MaplistMethod_Random();
644 nextMap = MaplistMethod_Iterate();
647 nextMap = MaplistMethod_Repeat();
654 else // PERMANENT FAILURE
658 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
659 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
663 error("Everything is broken - not even the default map list works. Please report this to the developers.");
675 When the player presses attack or jump, change to the next level
678 void() IntermissionThink =
680 if(cvar("sv_autoscreenshot"))
684 if(clienttype(self) == CLIENTTYPE_REAL)
685 stuffcmd(self, "screenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
689 if (time < intermission_exittime)
692 if (time < intermission_exittime + 10 && !self.button0 && !self.button1 && !self.button2 && !self.button3)
702 Returns the entity to view from
706 entity() FindIntermission =
711 // look for info_intermission first
712 spot = find (world, classname, "info_intermission");
714 { // pick a random one
718 spot = find (spot, classname, "info_intermission");
720 spot = find (spot, classname, "info_intermission");
726 // then look for the start position
727 spot = find (world, classname, "info_player_start");
731 // testinfo_player_start is only found in regioned levels
732 spot = find (world, classname, "testplayerstart");
736 // then look for the start position
737 spot = find (world, classname, "info_player_deathmatch");
741 //objerror ("FindIntermission: no spot");
747 ===============================================================================
751 ===============================================================================
759 if(cvar("_printstats"))
760 cvar_set("_printstats", "0");
769 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
771 if(cvar("sv_eventlog") && gameover)
772 GameLogEcho(s, FALSE);
773 else if(cvar("sv_logscores_console"))
774 ServerConsoleEcho(s, FALSE);
775 if(cvar("sv_logscores_file"))
777 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
778 fputs(file, strcat(s, "\n"));
781 other = findchainflags(flags, FL_CLIENT);
784 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
786 s = strcat(":player:", ftos(other.frags), ":");
787 s = strcat(s, ftos(other.deaths), ":");
788 s = strcat(s, ftos(rint(time - other.jointime)), ":");
789 s = strcat(s, ftos(other.team), ":");
791 if(cvar("sv_logscores_file"))
792 fputs(file, strcat(s, other.netname, "\n"));
793 if(cvar("sv_eventlog") && gameover)
794 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
795 else if(cvar("sv_logscores_console"))
796 ServerConsoleEcho(strcat(s, other.netname), TRUE);
801 if(cvar("sv_eventlog") && gameover)
802 GameLogEcho(":end", FALSE);
803 else if(cvar("sv_logscores_console"))
804 ServerConsoleEcho(":end", FALSE);
805 if(cvar("sv_logscores_file"))
807 fputs(file, ":end\n");
814 go to the next level for deathmatch
815 only called if a time or frag limit has expired
821 intermission_running = 1;
823 // enforce a wait time before allowing changelevel
825 intermission_exittime = time + cvar("sv_mapchange_delay");
827 intermission_exittime = -60;
829 WriteByte (MSG_ALL, SVC_CDTRACK);
830 WriteByte (MSG_ALL, 3);
831 WriteByte (MSG_ALL, 3);
833 //pos = FindIntermission ();
839 if(cvar("sv_eventlog"))
840 GameLogEcho(":gameover", FALSE);
844 other = findchainflags(flags, FL_CLIENT);
845 while (other != world)
847 //other.nextthink = time + 0.5;
848 other.takedamage = DAMAGE_NO;
849 other.solid = SOLID_NOT;
850 other.movetype = MOVETYPE_NONE;
851 other.angles = other.v_angle;
852 other.angles_x = other.angles_x * -1;
853 other.cnt = time + 0.5; // used for autoscreenshot
858 bprint(strcat(other.netname, " ^7wins.\n"));
863 other.modelindex = 0;
864 other.weaponentity = world; // remove weapon model
865 other.view_ofs = '0 0 0';
866 other.angles = other.v_angle = pos.mangle;
869 other.angles = other.v_angle = pos.angles;
870 other.v_angle_x = other.v_angle_x * -1;
872 other.fixangle = TRUE; // turn this way immediately
873 setorigin (other, pos.origin);
879 if(cvar("g_campaign"))
880 CampaignPreIntermission();
882 WriteByte (MSG_ALL, SVC_INTERMISSION);
889 Exit deathmatch games upon conditions
892 void() CheckRules_Player =
894 if (gameover) // someone else quit the game already
897 // fixme: don't check players; instead check dom_team and ctf_team entities
898 // (div0: and that in CheckRules_World please)
901 float checkrules_oneminutewarning;
902 float checkrules_leaderfrags;
903 float tdm_max_score, tdm_old_score;
905 float checkrules_equality;
906 float checkrules_overtimewarning;
907 float checkrules_overtimeend;
909 void() InitiateOvertime =
911 if(!checkrules_overtimeend)
912 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
915 float WINNING_NO = 0; // no winner, but time limits may terminate the game
916 float WINNING_YES = 1; // winner found
917 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
918 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
920 float(float fraglimitreached, float equality) GetWinningCode =
924 return WINNING_STARTOVERTIME;
926 return WINNING_NEVER;
934 // set the .winning flag for exactly those players with a given field value
935 void(.float field, float value) SetWinners =
938 head = findchain(classname, "player");
941 head.winning = (head.field == value);
946 // set the .winning flag for those players with a given field value
947 void(.float field, float value) AddWinners =
950 head = findchain(classname, "player");
953 if(head.field == value)
959 // clear the .winning flags
960 void(void) ClearWinners =
963 head = findchain(classname, "player");
971 // LMS winning condition: game terminates if and only if there's at most one
972 // one player who's living lives. Top two scores being equal cancels the time
974 float() WinningCondition_LMS =
978 if(lms_dead_count < 0)
981 if(player_count > 1 && lms_dead_count >= player_count - 1)
982 return WINNING_YES; // He's the last man standing!
984 if((player_count == 1 && lms_dead_count == 1))
985 return WINNING_YES; // All dead... (n:n is handled by the test above)
987 // dprint("player count = "); dprint(ftos(player_count));
988 // dprint(", dead count = "); dprint(ftos(lms_dead_count));
991 // When we get here, we have at least two players who are actually LIVING,
992 // or one player who is still waiting for a victim to join the server. Now
993 // check if the top two players have equal score.
995 checkrules_leaderfrags = 0;
996 head = findchain(classname, "player");
997 checkrules_equality = FALSE;
1000 if(head.frags > checkrules_leaderfrags)
1002 checkrules_leaderfrags = head.frags;
1003 checkrules_equality = FALSE;
1005 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1006 checkrules_equality = TRUE;
1010 SetWinners(frags, checkrules_leaderfrags);
1012 // The top two players have the same amount of lives? No timelimit then,
1013 // enter overtime...
1015 if(checkrules_equality)
1016 return WINNING_NEVER;
1018 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1022 // DM winning condition: game terminates if a player reached the fraglimit,
1023 // unless the first two players have the same score. The latter case also
1024 // breaks the time limit.
1025 float(float fraglimit) WinningCondition_MaxIndividualScore =
1027 float checkrules_oldleaderfrags;
1030 checkrules_oldleaderfrags = checkrules_leaderfrags;
1031 checkrules_leaderfrags = 0;
1032 head = findchain(classname, "player");
1033 checkrules_equality = FALSE;
1036 if(head.frags > checkrules_leaderfrags)
1038 checkrules_leaderfrags = head.frags;
1039 checkrules_equality = FALSE;
1041 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1042 checkrules_equality = TRUE;
1046 if(checkrules_leaderfrags > 0)
1047 SetWinners(frags, checkrules_leaderfrags);
1051 if (!cvar("g_runematch"))
1052 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1054 if (checkrules_leaderfrags == fraglimit - 1)
1055 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1056 else if (checkrules_leaderfrags == fraglimit - 2)
1057 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1058 else if (checkrules_leaderfrags == fraglimit - 3)
1059 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1062 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1065 float(float fraglimit) WinningConditionBase_Teamplay =
1067 tdm_old_score = tdm_max_score;
1068 tdm_max_score = max(team1_score, team2_score, team3_score, team4_score);
1070 checkrules_equality =
1075 (team1_score == tdm_max_score)
1076 + (team2_score == tdm_max_score)
1077 + (team3_score == tdm_max_score)
1078 + (team4_score == tdm_max_score)
1082 if(tdm_max_score > 0)
1084 if(team1_score == tdm_max_score)
1085 AddWinners(team, COLOR_TEAM1);
1086 if(team2_score == tdm_max_score)
1087 AddWinners(team, COLOR_TEAM2);
1088 if(team3_score == tdm_max_score)
1089 AddWinners(team, COLOR_TEAM3);
1090 if(team4_score == tdm_max_score)
1091 AddWinners(team, COLOR_TEAM4);
1094 if(!cvar("g_runematch") && !cvar("g_domination"))
1095 if(tdm_max_score != tdm_old_score)
1097 if(tdm_max_score == fraglimit - 1)
1098 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1099 else if(tdm_max_score == fraglimit - 2)
1100 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1101 else if(tdm_max_score == fraglimit - 3)
1102 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1105 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1108 // TDM winning condition: game terminates if a team's score sum reached the
1109 // fraglimit, unless the first two teams have the same total score. The latter
1110 // case also breaks the time limit.
1111 float(float fraglimit) WinningCondition_MaxTeamSum =
1115 team1_score = team2_score = team3_score = team4_score = 0;
1117 head = findchain(classname, "player");
1120 if(head.team == COLOR_TEAM1)
1121 team1_score += head.frags;
1122 else if(head.team == COLOR_TEAM2)
1123 team2_score += head.frags;
1124 else if(head.team == COLOR_TEAM3)
1125 team3_score += head.frags;
1126 else if(head.team == COLOR_TEAM4)
1127 team4_score += head.frags;
1131 return WinningConditionBase_Teamplay(fraglimit);
1134 // DOM/CTF winning condition: game terminates if the max of a team's players'
1135 // score reached the fraglimit, unless the first two teams have the same
1136 // maximum score. The latter case also breaks the time limit.
1137 float(float fraglimit) WinningCondition_MaxTeamMax =
1141 team1_score = team2_score = team3_score = team4_score = 0;
1143 head = findchain(classname, "player");
1146 if(head.team == COLOR_TEAM1)
1148 if(head.frags > team1_score)
1149 team1_score = head.frags;
1151 else if(head.team == COLOR_TEAM2)
1153 if(head.frags > team2_score)
1154 team2_score = head.frags;
1156 else if(head.team == COLOR_TEAM3)
1158 if(head.frags > team3_score)
1159 team3_score = head.frags;
1161 else if(head.team == COLOR_TEAM4)
1163 if(head.frags > team4_score)
1164 team4_score = head.frags;
1169 return WinningConditionBase_Teamplay(fraglimit);
1172 void PrintScoreboardFor(string name, string colorcode, float whichteam)
1179 head = find(world, classname, "player");
1182 if(!whichteam || head.team == whichteam)
1186 ServerConsoleEcho(strcat(" ", colorcode, name, ":"), FALSE);
1188 fragtotal = fragtotal + head.frags;
1189 s = ftos(head.frags);
1190 s = strcat(s, "/", ftos(head.deaths));
1191 s = strcat(s, " @ ", ftos(head.ping));
1192 if(clienttype(head) == CLIENTTYPE_BOT)
1193 s = strcat(s, "botms");
1195 s = strcat(s, "ms");
1196 ServerConsoleEcho(strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"), TRUE);
1198 head = find(head, classname, "player");
1200 if(whichteam && found)
1201 ServerConsoleEcho(strcat(colorcode, " (total: ", ftos(fragtotal), ")"), FALSE);
1204 void PrintScoreboard()
1206 ServerConsoleEcho("Scoreboard:", FALSE);
1209 PrintScoreboardFor("Red", "^1", COLOR_TEAM1);
1210 PrintScoreboardFor("Blue", "^4", COLOR_TEAM2);
1211 PrintScoreboardFor("Pink", "^6", COLOR_TEAM3);
1212 PrintScoreboardFor("Yellow", "^3", COLOR_TEAM4);
1216 PrintScoreboardFor("", "^7", 0);
1218 ServerConsoleEcho(".", FALSE);
1221 void RemoveFromMaplist(string m)
1228 litems = tokenize(cvar_string("g_maplist"));
1231 for(i = 0; i < litems; ++i)
1234 result = strcat(result);
1238 result = strcat(result, "'", argv(i), "'");
1241 cvar_set("g_maplist", result);
1242 ServerConsoleEcho(strcat("Removed ", ftos(found), " items."), FALSE);
1245 void AddToMaplist(string m)
1254 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1256 ServerConsoleEcho("Map not found.", FALSE);
1260 litems = tokenize(cvar_string("g_maplist"));
1261 if(cvar("g_maplist_shuffle"))
1262 ipos = ceil(random() * (litems + 1)) - 1;
1267 for(i = 0; i < litems; ++i)
1272 result = strcat(result, "'", m, "'");
1275 result = strcat(result, "'", argv(i), "'");
1280 result = strcat(result, "'", m, "'");
1283 cvar_set("g_maplist", result);
1284 ServerConsoleEcho("Map added.", FALSE);
1287 ServerConsoleEcho("Map already in list.", FALSE);
1290 void ShuffleMaplist()
1298 result = cvar_string("g_maplist");
1299 litems = tokenize(result);
1301 for(start = 0; start < litems - 1; ++start)
1305 // select a random item
1306 selected = ceil(random() * (litems - start) + start) - 1;
1308 // shift this item to the place start
1309 for(i = 0; i < start; ++i)
1310 result = strcat(result, "'", argv(i), "'");
1311 result = strcat(result, "'", argv(selected), "'");
1312 for(i = start; i < litems; ++i)
1314 result = strcat(result, "'", argv(i), "'");
1316 litems = tokenize(result);
1318 //dprint(result, "\n");
1321 cvar_set("g_maplist", result);
1328 Exit deathmatch games upon conditions
1331 void() CheckRules_World =
1334 local float timelimit;
1335 local float fraglimit;
1341 if (intermission_running)
1342 if (time >= intermission_exittime + 60)
1348 if (gameover) // someone else quit the game already
1353 if(cvar("_scoreboard"))
1355 cvar_set("_scoreboard", "0");
1359 // automatically shuffle when setting g_maplist_shuffle
1360 if(cvar_string("_g_maplist_add") != "")
1362 AddToMaplist(cvar_string("_g_maplist_add"));
1363 cvar_set("_g_maplist_add", "");
1365 if(cvar_string("_g_maplist_remove") != "")
1367 RemoveFromMaplist(cvar_string("_g_maplist_remove"));
1368 cvar_set("_g_maplist_remove", "");
1370 if(cvar("_g_maplist_shufflenow") || (cvar("g_maplist_shuffle") && !cvar("_g_maplist_have_shuffled")))
1373 localcmd("set _g_maplist_shufflenow 0\nset _g_maplist_have_shuffled 1\necho Shuffled map list.\n");
1375 if(cvar("_g_maplist_have_shuffled"))
1376 if(!cvar("g_maplist_shuffle"))
1377 localcmd("set _g_maplist_have_shuffled 0\n");
1379 timelimit = cvar("timelimit") * 60;
1380 fraglimit = cvar("fraglimit");
1382 if (timelimit && time >= timelimit)
1385 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1391 if(!checkrules_overtimewarning && checkrules_overtimeend)
1393 checkrules_overtimewarning = TRUE;
1394 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1395 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1398 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1400 checkrules_oneminutewarning = TRUE;
1401 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1404 status = WINNING_NO;
1407 status = WinningCondition_LMS();
1413 if(cvar("g_tdm") || cvar("g_runematch") || cvar("g_ctf") || cvar("g_domination"))
1414 status = WinningCondition_MaxTeamSum(fraglimit);
1416 // status = WinningCondition_MaxTeamMax(fraglimit);
1419 dprint("div0: How can this happen?\n");
1420 status = WinningCondition_MaxTeamMax(fraglimit);
1424 status = WinningCondition_MaxIndividualScore(fraglimit);
1427 if(status == WINNING_STARTOVERTIME)
1429 status = WINNING_NEVER;
1433 if(status == WINNING_NEVER)
1434 // equality cases! Nobody wins if the overtime ends in a draw.
1437 if(checkrules_overtimeend)
1438 if(status != WINNING_NEVER)
1439 status = WINNING_YES;
1441 if(status == WINNING_YES)