1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
5 void HandleMaplistShuffleCommands();
9 if(cvar("g_running_guns"))
11 default_player_alpha = -1;
12 default_weapon_alpha = +1;
14 else if(cvar("g_cloaked"))
16 default_player_alpha = cvar("g_balance_cloaked_alpha");
17 default_weapon_alpha = default_player_alpha;
21 default_player_alpha = cvar("g_player_alpha");
22 if(default_player_alpha <= 0)
23 default_player_alpha = 1;
24 default_weapon_alpha = default_player_alpha;
28 void fteqcc_testbugs()
32 if(!cvar("developer_fteqccbugs"))
35 dprint("*** fteqcc test: checking for bugs...\n");
39 if(sqrt(a) - sqrt(b - a) == 0)
40 dprint("*** fteqcc test: found same-function-twice bug\n");
42 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
46 world.enemy.frags += 10;
47 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
48 dprint("*** fteqcc test: found += bug\n");
50 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
58 cvar_set("_sv_init", "0");
59 HandleMaplistShuffleCommands();
60 tokenize(cvar_string("g_maplist"));
61 if(argv(0) != GetMapname())
63 cvar_set("nextmap", argv(0));
69 float world_already_spawned;
70 void worldspawn (void)
72 if(world_already_spawned)
73 error("world already spawned - you may have EXACTLY ONE worldspawn!");
74 world_already_spawned = TRUE;
75 // Precache all player models
76 // Workaround for "invisible players"
77 precache_model("models/player/carni.zym");
78 precache_model("models/player/crash.zym");
79 precache_model("models/player/grunt.zym");
80 precache_model("models/player/headhunter.zym");
81 precache_model("models/player/insurrectionist.zym");
82 precache_model("models/player/jeandarc.zym");
83 precache_model("models/player/lurk.zym");
84 precache_model("models/player/lycanthrope.zym");
85 precache_model("models/player/marine.zym");
86 precache_model("models/player/nexus.zym");
87 precache_model("models/player/pyria.zym");
88 precache_model("models/player/shock.zym");
89 precache_model("models/player/skadi.zym");
90 precache_model("models/player/specop.zym");
91 precache_model("models/player/visitant.zym");
93 //precache_model ("progs/beam.mdl");
94 precache_model ("models/bullet.mdl");
95 precache_model ("models/casing_bronze.mdl");
96 precache_model ("models/casing_shell.mdl");
97 precache_model ("models/casing_steel.mdl");
98 precache_model ("models/ebomb.mdl");
99 precache_model ("models/elaser.mdl");
100 precache_model ("models/flash.md3");
101 precache_model ("models/gibs/bloodyskull.md3");
102 precache_model ("models/gibs/chunk.mdl");
103 precache_model ("models/gibs/eye.md3");
104 precache_model ("models/gibs/gib1.md3");
105 //precache_model ("models/gibs/gib2.md3");
106 //precache_model ("models/gibs/gib3.md3");
107 //precache_model ("models/gibs/gib4.md3");
108 precache_model ("models/gibs/gib5.md3");
109 //precache_model ("models/gibs/gib6.md3");
110 precache_model ("models/gibs/gib1.mdl");
111 precache_model ("models/gibs/gib2.mdl");
112 precache_model ("models/gibs/gib3.mdl");
113 precache_model ("models/grenademodel.md3");
114 precache_model ("models/hagarmissile.mdl");
115 precache_model ("models/items/a_bullets.mdl");
116 precache_model ("models/items/a_cells.md3");
117 precache_model ("models/items/a_rockets.md3");
118 precache_model ("models/items/a_shells.md3");
119 precache_model ("models/items/g_a1.md3");
120 precache_model ("models/items/g_a25.md3");
121 precache_model ("models/items/g_h1.md3");
122 precache_model ("models/items/g_h25.md3");
123 precache_model ("models/items/g_h100.md3");
124 precache_model ("models/items/g_invincible.md3");
125 precache_model ("models/items/g_strength.md3");
126 precache_model ("models/laser.mdl");
127 precache_model ("models/misc/chatbubble.spr");
128 precache_model ("models/misc/teambubble.spr");
129 precache_model ("models/nexflash.md3");
130 precache_model ("models/plasma.mdl");
131 precache_model ("models/plasmatrail.mdl");
132 precache_model ("models/rocket.md3");
133 //precache_model ("models/sprites/grenexpl.spr");
134 precache_model ("models/runematch/rune.mdl");
135 precache_model ("models/runematch/curse.mdl");
136 //precache_model ("models/sprites/hagar.spr");
137 //precache_model ("models/sprites/muzzleflash.spr32");
138 //precache_model ("models/sprites/electrocombo.spr32");
139 //precache_model ("models/sprites/plasmahitwall.spr32");
140 //precache_model ("models/sprites/plasmashot.spr32");
141 //precache_model ("models/sprites/rockexpl.spr");
142 precache_model ("models/tracer.mdl");
143 precache_model ("models/uziflash.md3");
144 precache_model ("models/weapons/g_crylink.md3");
145 precache_model ("models/weapons/g_electro.md3");
146 precache_model ("models/weapons/g_gl.md3");
147 precache_model ("models/weapons/g_hagar.md3");
148 precache_model ("models/weapons/g_nex.md3");
149 precache_model ("models/weapons/g_rl.md3");
150 precache_model ("models/weapons/g_shotgun.md3");
151 precache_model ("models/weapons/g_uzi.md3");
152 precache_model ("models/weapons/v_crylink.md3");
153 precache_model ("models/weapons/v_electro.md3");
154 precache_model ("models/weapons/v_gl.md3");
155 precache_model ("models/weapons/v_hagar.md3");
156 precache_model ("models/weapons/v_laser.md3");
157 precache_model ("models/weapons/v_nex.md3");
158 precache_model ("models/weapons/v_rl.md3");
159 precache_model ("models/weapons/v_shotgun.md3");
160 precache_model ("models/weapons/v_uzi.md3");
161 precache_model ("models/weapons/w_crylink.zym");
162 precache_model ("models/weapons/w_electro.zym");
163 precache_model ("models/weapons/w_gl.zym");
164 precache_model ("models/weapons/w_hagar.zym");
165 precache_model ("models/weapons/w_laser.zym");
166 precache_model ("models/weapons/w_nex.zym");
167 precache_model ("models/weapons/w_rl.zym");
168 precache_model ("models/weapons/w_shotgun.zym");
169 precache_model ("models/weapons/w_uzi.zym");
171 // laser for laser-guided weapons
172 precache_model ("models/laser_dot.mdl");
174 precache_sound ("misc/null.wav");
175 precache_sound ("misc/armor1.wav");
176 precache_sound ("misc/armor25.wav");
177 precache_sound ("misc/armorimpact.wav");
178 precache_sound ("misc/bodyimpact1.wav");
179 precache_sound ("misc/bodyimpact2.wav");
180 precache_sound ("misc/gib.wav");
181 precache_sound ("misc/gib_splat01.wav");
182 precache_sound ("misc/gib_splat02.wav");
183 precache_sound ("misc/gib_splat03.wav");
184 precache_sound ("misc/gib_splat04.wav");
185 //precache_sound ("misc/h2ohit.wav");
186 precache_sound ("misc/hit.wav");
187 precache_sound ("misc/footstep01.wav");
188 precache_sound ("misc/footstep02.wav");
189 precache_sound ("misc/footstep03.wav");
190 precache_sound ("misc/footstep04.wav");
191 precache_sound ("misc/footstep05.wav");
192 precache_sound ("misc/footstep06.wav");
193 precache_sound ("misc/hitground1.ogg");
194 precache_sound ("misc/hitground2.ogg");
195 precache_sound ("misc/hitground3.ogg");
196 precache_sound ("misc/hitground4.ogg");
197 precache_sound ("misc/itempickup.ogg");
198 precache_sound ("misc/itemrespawn.ogg");
199 precache_sound ("misc/jumppad.ogg");
200 precache_sound ("misc/mediumhealth.ogg");
201 precache_sound ("misc/megahealth.ogg");
202 precache_sound ("misc/minihealth.ogg");
203 precache_sound ("misc/powerup.ogg");
204 precache_sound ("misc/powerup_shield.ogg");
205 precache_sound ("misc/talk.wav");
206 precache_sound ("misc/teleport.ogg");
207 precache_sound ("plats/medplat1.wav");
208 precache_sound ("plats/medplat2.wav");
209 precache_sound ("player/lava.wav");
210 precache_sound ("player/slime.wav");
211 precache_sound ("weapons/crylink_fire.ogg");
212 precache_sound ("weapons/electro_bounce.ogg");
213 precache_sound ("weapons/electro_fire.ogg");
214 precache_sound ("weapons/electro_fire2.ogg");
215 precache_sound ("weapons/electro_fly.wav");
216 precache_sound ("weapons/electro_impact.ogg");
217 precache_sound ("weapons/electro_impact_combo.ogg");
218 //precache_sound ("weapons/grenade_bounce.ogg");
219 precache_sound ("weapons/grenade_bounce1.ogg");
220 precache_sound ("weapons/grenade_bounce2.ogg");
221 precache_sound ("weapons/grenade_bounce3.ogg");
222 precache_sound ("weapons/grenade_bounce4.ogg");
223 precache_sound ("weapons/grenade_bounce5.ogg");
224 precache_sound ("weapons/grenade_bounce6.ogg");
225 precache_sound ("weapons/grenade_fire.ogg");
226 precache_sound ("weapons/grenade_impact.ogg");
227 precache_sound ("weapons/hagar_fire.ogg");
228 precache_sound ("weapons/hagexp1.ogg");
229 precache_sound ("weapons/hagexp2.ogg");
230 precache_sound ("weapons/hagexp3.ogg");
231 precache_sound ("weapons/hook_fire.ogg");
232 precache_sound ("weapons/hook_impact.ogg");
233 precache_sound ("weapons/lasergun_fire.ogg");
234 precache_sound ("weapons/laserimpact.ogg");
235 precache_sound ("weapons/nexfire.ogg");
236 precache_sound ("weapons/neximpact.ogg");
237 precache_sound ("weapons/ric1.ogg");
238 precache_sound ("weapons/ric2.ogg");
239 precache_sound ("weapons/ric3.ogg");
240 precache_sound ("weapons/rocket_fire.ogg");
241 precache_sound ("weapons/rocket_fly.wav");
242 precache_sound ("weapons/rocket_impact.ogg");
243 precache_sound ("weapons/rocket_det.ogg");
244 precache_sound ("weapons/shotgun_fire.ogg");
245 precache_sound ("weapons/tink1.ogg");
246 precache_sound ("weapons/uzi_fire.ogg");
247 precache_sound ("weapons/weapon_switch.ogg");
248 precache_sound ("weapons/weaponpickup.ogg");
249 precache_sound ("weapons/strength_fire.ogg");
251 //precache_sound ("announce/male/kill10.ogg");
252 //precache_sound ("announce/male/kill15.ogg");
253 //precache_sound ("announce/male/kill20.ogg");
254 //precache_sound ("announce/male/kill25.ogg");
255 //precache_sound ("announce/male/kill3.ogg");
256 //precache_sound ("announce/male/kill30.ogg");
257 //precache_sound ("announce/male/kill4.ogg");
258 //precache_sound ("announce/male/kill5.ogg");
259 //precache_sound ("announce/male/kill6.ogg");
260 //precache_sound ("announce/male/mapkill1.ogg");
261 //precache_sound ("announce/robotic/last_second_save.ogg");
262 //precache_sound ("announce/robotic/narrowly_averted.ogg");
263 //precache_sound ("minstagib/mockery.ogg");
265 // announcer sounds - male
266 precache_sound ("announcer/male/03kills.ogg");
267 precache_sound ("announcer/male/05kills.ogg");
268 precache_sound ("announcer/male/10kills.ogg");
269 precache_sound ("announcer/male/15kills.ogg");
270 precache_sound ("announcer/male/20kills.ogg");
271 precache_sound ("announcer/male/25kills.ogg");
272 precache_sound ("announcer/male/30kills.ogg");
273 precache_sound ("announcer/male/botlike.ogg");
274 precache_sound ("announcer/male/electrobitch.ogg");
275 precache_sound ("announcer/male/welcome.ogg");
276 precache_sound ("announcer/male/yoda.ogg");
278 // announcer sounds - robotic
279 precache_sound ("announcer/robotic/1fragleft.ogg");
280 precache_sound ("announcer/robotic/1minuteremains.ogg");
281 precache_sound ("announcer/robotic/2fragsleft.ogg");
282 precache_sound ("announcer/robotic/3fragsleft.ogg");
283 precache_sound ("announcer/robotic/lastsecond.ogg");
284 precache_sound ("announcer/robotic/narrowly.ogg");
285 precache_sound ("announcer/robotic/1.ogg");
286 precache_sound ("announcer/robotic/2.ogg");
287 precache_sound ("announcer/robotic/3.ogg");
288 precache_sound ("announcer/robotic/4.ogg");
289 precache_sound ("announcer/robotic/5.ogg");
290 precache_sound ("announcer/robotic/6.ogg");
291 precache_sound ("announcer/robotic/7.ogg");
292 precache_sound ("announcer/robotic/8.ogg");
293 precache_sound ("announcer/robotic/9.ogg");
294 precache_sound ("announcer/robotic/10.ogg");
296 // plays music for the level if there is any
299 precache_sound (self.noise);
300 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
306 // 1 FLICKER (first variety)
307 lightstyle(1, "mmnmmommommnonmmonqnmmo");
309 // 2 SLOW STRONG PULSE
310 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
312 // 3 CANDLE (first variety)
313 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
316 lightstyle(4, "mamamamamama");
319 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
321 // 6 FLICKER (second variety)
322 lightstyle(6, "nmonqnmomnmomomno");
324 // 7 CANDLE (second variety)
325 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
327 // 8 CANDLE (third variety)
328 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
330 // 9 SLOW STROBE (fourth variety)
331 lightstyle(9, "aaaaaaaazzzzzzzz");
333 // 10 FLUORESCENT FLICKER
334 lightstyle(10, "mmamammmmammamamaaamammma");
336 // 11 SLOW PULSE NOT FADE TO BLACK
337 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
339 // styles 32-62 are assigned by the light program for switchable lights
344 registercvar("_g_maplist_shufflenow", "0");
345 registercvar("_g_maplist_have_shuffled", "0");
348 lms_lowest_lives = 0;
353 bot_waypoints_for_items = cvar("g_waypoints_for_items");
354 if(bot_waypoints_for_items == 1)
355 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
356 bot_waypoints_for_items = 0;
358 if(cvar("g_campaign"))
362 //if (cvar("g_domination"))
366 head = nextent(world);
371 head = nextent(head);
374 GameLogInit(); // prepare everything
375 if(cvar("sv_eventlog"))
378 GameLogEcho(":logversion:2", FALSE);
379 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
380 s = strcat(s, ftos(random()));
381 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
382 s = ":gameinfo:mutators:LIST";
383 if(cvar("g_grappling_hook"))
384 s = strcat(s, ":grappling_hook");
385 if(!cvar("g_use_ammunition"))
386 s = strcat(s, ":no_use_ammunition");
387 if(!cvar("g_pickup_items"))
388 s = strcat(s, ":no_pickup_items");
389 if(cvar("g_instagib"))
390 s = strcat(s, ":instagib");
391 if(cvar("g_rocketarena"))
392 s = strcat(s, ":rockerarena");
394 s = strcat(s, ":nixnex");
395 if(cvar("g_vampire"))
396 s = strcat(s, ":vampire");
397 if(cvar("g_laserguided_missile"))
398 s = strcat(s, ":laserguided_missile");
399 if(cvar("g_norecoil"))
400 s = strcat(s, ":norecoil");
402 s = strcat(s, ":midair");
403 if(cvar("g_minstagib"))
404 s = strcat(s, ":minstagib");
405 GameLogEcho(s, FALSE);
406 GameLogEcho(":gameinfo:end", FALSE);
409 cvar_set("nextmap", "");
413 if(cvar("g_campaign"))
421 //makestatic (self); // Who the f___ did that?
425 float( string pFilename ) TryFile =
428 dprint("TryFile(\"", pFilename, "\")\n");
429 lHandle = fopen( pFilename, FILE_READ );
430 if( lHandle != -1 ) {
440 if (game == GAME_DEATHMATCH)
442 else if (game == GAME_TEAM_DEATHMATCH)
444 else if (game == GAME_DOMINATION)
446 else if (game == GAME_CTF)
448 else if (game == GAME_RUNEMATCH)
450 else if (game == GAME_LMS)
457 return strcat(GetGametype(), "_", mapname);
460 float Map_Count, Map_Current;
461 string Map_Current_Name;
463 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
464 float GetMaplistPosition()
470 idx = cvar("g_maplist_index");
477 for(pos = 0; pos < Map_Count; ++pos)
481 // resume normal maplist rotation if current map is not in g_maplist
485 float MapHasRightSize(string map)
487 // open map size restriction file
489 dprint("opensize "); dprint(map);
490 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
493 float mapmin, mapmax;
495 mapmin = stof(fgets(fh));
496 mapmax = stof(fgets(fh));
498 if(player_count < mapmin)
500 dprint("not enough\n");
503 if(player_count > mapmax)
505 dprint("too many\n");
508 dprint("right size\n");
511 dprint(": not found\n");
515 string Map_Filename(float position)
517 return strcat("maps/", argv(position), ".mapcfg");
520 float(float position, float pass) Map_Check =
524 map_next = argv(position);
526 if(map_next == Map_Current_Name) // same map again in first pass?
528 filename = Map_Filename(position);
529 if(TryFile(filename))
533 if(MapHasRightSize(argv(position)))
538 dprint( "Couldn't find '", filename, "'..\n" );
543 void(float position) Map_Goto =
545 cvar_set("g_maplist_index", ftos(position));
546 localcmd(strcat("exec \"", Map_Filename(position) ,"\"\n"));
549 // return codes of map selectors:
550 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
551 // -2 = permanent failure
552 float() MaplistMethod_Iterate = // usual method
556 for(pass = 1; pass <= 2; ++pass)
558 for(i = 1; i < Map_Count; ++i)
561 mapindex = math_mod(i + Map_Current, Map_Count);
562 if(Map_Check(mapindex, pass))
569 float() MaplistMethod_Repeat = // fallback method
571 if(Map_Check(Map_Current, 2))
576 float() MaplistMethod_Random = // random map selection
582 for(i = 0; i <= imax; ++i)
585 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
586 if(Map_Check(mapindex, 1))
592 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
593 // the exponent sets a bias on the map selection:
594 // the higher the exponent, the
596 float i, j, imax, insertpos;
601 return 0; // only one map, then always play this one
603 for(i = 0; i <= imax; ++i)
607 // now reinsert this at another position
608 insertpos = pow(random(), 1 / exponent); // ]0, 1]
609 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
610 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
611 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
613 // insert the current map there
615 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
616 newlist = strcat(newlist, "'", argv(j), "'");
617 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
618 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
619 newlist = strcat(newlist, "'", argv(j), "'");
620 cvar_set("g_maplist", newlist);
621 Map_Count = tokenize(newlist);
623 // NOTE: the selected map has just been inserted at (insertpos-1)th position
624 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
625 if(Map_Check(Map_Current, 1))
631 void() Maplist_Init =
634 temp = cvar_string("g_maplist");
635 Map_Count = tokenize(temp);
638 bprint( "Maplist is empty! Resetting it to default map list.\n" );
639 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
640 Map_Count = tokenize(temp);
643 error("empty maplist, cannot select a new map");
644 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
646 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
647 // this may or may not be correct, but who cares, in the worst case a map
648 // isn't chosen in the first pass that should have been
653 //local string nextmap;
654 //local float n, nummaps;
657 if (alreadychangedlevel)
659 alreadychangedlevel = TRUE;
661 if(cvar("g_campaign"))
663 CampaignPostIntermission();
667 if(cvar("quit_when_empty"))
669 if(player_count <= currentbots)
676 if (cvar("samelevel")) // if samelevel is set, stay on same level
678 // 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)
679 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
680 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
681 localcmd("restart\n");
682 //changelevel (mapname);
686 // if an exit cfg is defined by exiting map, exec it.
687 exit_cfg = cvar_string("exit_cfg");
689 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
691 localcmd("exec game_reset.cfg\n");
694 if (cvar("lastlevel"))
696 localcmd(strcat("set lastlevel 0\n"));
697 localcmd(strcat("togglemenu\n"));
704 // cvar "nextmap" always gets priority
705 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
707 localcmd(strcat("exec \"maps/", cvar_string("nextmap"), ".mapcfg\"\n"));
711 for(allowReset = 1; allowReset >= 0; --allowReset)
717 if(cvar("g_maplist_shuffle") > 0)
718 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
721 if(cvar("g_maplist_selectrandom"))
722 nextMap = MaplistMethod_Random();
725 nextMap = MaplistMethod_Iterate();
728 nextMap = MaplistMethod_Repeat();
735 else // PERMANENT FAILURE
739 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
740 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
744 error("Everything is broken - not even the default map list works. Please report this to the developers.");
756 When the player presses attack or jump, change to the next level
759 .float autoscreenshot;
760 void() IntermissionThink =
762 if(cvar("sv_autoscreenshot"))
763 if(self.autoscreenshot)
764 if(time > self.autoscreenshot)
766 self.autoscreenshot = FALSE;
767 if(clienttype(self) == CLIENTTYPE_REAL)
768 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
772 if (time < intermission_exittime)
775 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
785 Returns the entity to view from
789 entity() FindIntermission =
794 // look for info_intermission first
795 spot = find (world, classname, "info_intermission");
797 { // pick a random one
801 spot = find (spot, classname, "info_intermission");
803 spot = find (spot, classname, "info_intermission");
809 // then look for the start position
810 spot = find (world, classname, "info_player_start");
814 // testinfo_player_start is only found in regioned levels
815 spot = find (world, classname, "testplayerstart");
819 // then look for the start position
820 spot = find (world, classname, "info_player_deathmatch");
824 //objerror ("FindIntermission: no spot");
830 ===============================================================================
834 ===============================================================================
842 if(cvar("_printstats"))
843 cvar_set("_printstats", "0");
852 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
854 if(cvar("sv_eventlog") && gameover)
855 GameLogEcho(s, FALSE);
856 else if(cvar("sv_logscores_console"))
857 ServerConsoleEcho(s, FALSE);
858 if(cvar("sv_logscores_file"))
860 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
861 fputs(file, strcat(s, "\n"));
864 other = findchainflags(flags, FL_CLIENT);
867 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
869 s = strcat(":player:", ftos(other.frags), ":");
870 s = strcat(s, ftos(other.deaths), ":");
871 s = strcat(s, ftos(rint(time - other.jointime)), ":");
872 s = strcat(s, ftos(other.team), ":");
874 if(cvar("sv_logscores_file"))
875 fputs(file, strcat(s, other.netname, "\n"));
876 if(cvar("sv_eventlog") && gameover)
877 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
878 else if(cvar("sv_logscores_console"))
879 ServerConsoleEcho(strcat(s, other.netname), TRUE);
884 if(cvar("sv_eventlog") && gameover)
885 GameLogEcho(":end", FALSE);
886 else if(cvar("sv_logscores_console"))
887 ServerConsoleEcho(":end", FALSE);
888 if(cvar("sv_logscores_file"))
890 fputs(file, ":end\n");
897 go to the next level for deathmatch
898 only called if a time or frag limit has expired
904 intermission_running = 1;
906 // enforce a wait time before allowing changelevel
908 intermission_exittime = time + cvar("sv_mapchange_delay");
910 intermission_exittime = -60;
912 WriteByte (MSG_ALL, SVC_CDTRACK);
913 WriteByte (MSG_ALL, 3);
914 WriteByte (MSG_ALL, 3);
916 //pos = FindIntermission ();
922 if(cvar("sv_eventlog"))
923 GameLogEcho(":gameover", FALSE);
927 other = findchainflags(flags, FL_CLIENT);
928 while (other != world)
930 //other.nextthink = time + 0.5;
931 other.takedamage = DAMAGE_NO;
932 other.solid = SOLID_NOT;
933 other.movetype = MOVETYPE_NONE;
934 other.angles = other.v_angle;
935 other.angles_x = other.angles_x * -1;
936 other.autoscreenshot = time + 0.8; // used for autoscreenshot
941 bprint(strcat(other.netname, " ^7wins.\n"));
946 other.modelindex = 0;
947 other.weaponentity = world; // remove weapon model
948 other.view_ofs = '0 0 0';
949 other.angles = other.v_angle = pos.mangle;
952 other.angles = other.v_angle = pos.angles;
953 other.v_angle_x = other.v_angle_x * -1;
955 other.fixangle = TRUE; // turn this way immediately
956 setorigin (other, pos.origin);
962 if(cvar("g_campaign"))
963 CampaignPreIntermission();
965 WriteByte (MSG_ALL, SVC_INTERMISSION);
972 Exit deathmatch games upon conditions
975 void() CheckRules_Player =
977 if (gameover) // someone else quit the game already
980 // fixme: don't check players; instead check dom_team and ctf_team entities
981 // (div0: and that in CheckRules_World please)
984 float checkrules_oneminutewarning;
985 float checkrules_leaderfrags;
986 float tdm_max_score, tdm_old_score;
988 float checkrules_equality;
989 float checkrules_overtimewarning;
990 float checkrules_overtimeend;
992 void() InitiateOvertime =
994 if(!checkrules_overtimeend)
995 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
998 float WINNING_NO = 0; // no winner, but time limits may terminate the game
999 float WINNING_YES = 1; // winner found
1000 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1001 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1003 float(float fraglimitreached, float equality) GetWinningCode =
1006 if(fraglimitreached)
1007 return WINNING_STARTOVERTIME;
1009 return WINNING_NEVER;
1011 if(fraglimitreached)
1017 // set the .winning flag for exactly those players with a given field value
1018 void(.float field, float value) SetWinners =
1021 head = findchain(classname, "player");
1024 head.winning = (head.field == value);
1029 // set the .winning flag for those players with a given field value
1030 void(.float field, float value) AddWinners =
1033 head = findchain(classname, "player");
1036 if(head.field == value)
1042 // clear the .winning flags
1043 void(void) ClearWinners =
1046 head = findchain(classname, "player");
1054 float() LMS_NewPlayerLives =
1057 fl = cvar("fraglimit");
1061 // first player has left the game for dying too much? Nobody else can get in.
1062 if(lms_lowest_lives < 1)
1065 if(!cvar("g_lms_join_anytime"))
1066 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1069 return bound(1, lms_lowest_lives, fl);
1072 // LMS winning condition: game terminates if and only if there's at most one
1073 // one player who's living lives. Top two scores being equal cancels the time
1075 float() WinningCondition_LMS =
1082 have_player = FALSE;
1083 have_players = FALSE;
1084 l = LMS_NewPlayerLives();
1086 head = find(world, classname, "player");
1089 head = find(head, classname, "player");
1091 have_players = TRUE;
1095 // we have at least one player
1098 // two or more active players - continue with the game
1102 // exactly one player?
1105 // but no game has taken place yet
1110 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1111 dprint("Have a winner, ending game.\n");
1118 // nobody is playing at all...
1121 // wait for players...
1125 // SNAFU (maybe a draw game?)
1127 dprint("No players, ending game.\n");
1132 // When we get here, we have at least two players who are actually LIVING,
1133 // or one player who is still waiting for a victim to join the server. Now
1134 // check if the top two players have equal score.
1136 checkrules_leaderfrags = 0;
1137 head = findchain(classname, "player");
1138 checkrules_equality = FALSE;
1141 if(head.frags > checkrules_leaderfrags)
1143 checkrules_leaderfrags = head.frags;
1144 checkrules_equality = FALSE;
1146 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1147 checkrules_equality = TRUE;
1151 SetWinners(frags, checkrules_leaderfrags);
1153 // The top two players have the same amount of lives? No timelimit then,
1154 // enter overtime...
1156 if(checkrules_equality)
1157 return WINNING_NEVER;
1159 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1163 // DM winning condition: game terminates if a player reached the fraglimit,
1164 // unless the first two players have the same score. The latter case also
1165 // breaks the time limit.
1166 float(float fraglimit) WinningCondition_MaxIndividualScore =
1168 float checkrules_oldleaderfrags;
1171 checkrules_oldleaderfrags = checkrules_leaderfrags;
1172 checkrules_leaderfrags = 0;
1173 head = findchain(classname, "player");
1174 checkrules_equality = FALSE;
1177 if(head.frags > checkrules_leaderfrags)
1179 checkrules_leaderfrags = head.frags;
1180 checkrules_equality = FALSE;
1182 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1183 checkrules_equality = TRUE;
1187 if(checkrules_leaderfrags > 0)
1188 SetWinners(frags, checkrules_leaderfrags);
1192 if (!cvar("g_runematch"))
1193 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1195 if (checkrules_leaderfrags == fraglimit - 1)
1196 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1197 else if (checkrules_leaderfrags == fraglimit - 2)
1198 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1199 else if (checkrules_leaderfrags == fraglimit - 3)
1200 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1203 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1206 float(float fraglimit) WinningConditionBase_Teamplay =
1208 tdm_old_score = tdm_max_score;
1209 tdm_max_score = max(team1_score, team2_score, team3_score, team4_score);
1211 checkrules_equality =
1216 (team1_score == tdm_max_score)
1217 + (team2_score == tdm_max_score)
1218 + (team3_score == tdm_max_score)
1219 + (team4_score == tdm_max_score)
1223 if(tdm_max_score > 0)
1225 if(team1_score == tdm_max_score)
1226 AddWinners(team, COLOR_TEAM1);
1227 if(team2_score == tdm_max_score)
1228 AddWinners(team, COLOR_TEAM2);
1229 if(team3_score == tdm_max_score)
1230 AddWinners(team, COLOR_TEAM3);
1231 if(team4_score == tdm_max_score)
1232 AddWinners(team, COLOR_TEAM4);
1235 if(!cvar("g_runematch") && !cvar("g_domination"))
1236 if(tdm_max_score != tdm_old_score)
1238 if(tdm_max_score == fraglimit - 1)
1239 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1240 else if(tdm_max_score == fraglimit - 2)
1241 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1242 else if(tdm_max_score == fraglimit - 3)
1243 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1246 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1249 // TDM winning condition: game terminates if a team's score sum reached the
1250 // fraglimit, unless the first two teams have the same total score. The latter
1251 // case also breaks the time limit.
1252 float(float fraglimit) WinningCondition_MaxTeamSum =
1256 team1_score = team2_score = team3_score = team4_score = 0;
1258 head = findchain(classname, "player");
1261 if(head.team == COLOR_TEAM1)
1262 team1_score += head.frags;
1263 else if(head.team == COLOR_TEAM2)
1264 team2_score += head.frags;
1265 else if(head.team == COLOR_TEAM3)
1266 team3_score += head.frags;
1267 else if(head.team == COLOR_TEAM4)
1268 team4_score += head.frags;
1272 return WinningConditionBase_Teamplay(fraglimit);
1275 // DOM/CTF winning condition: game terminates if the max of a team's players'
1276 // score reached the fraglimit, unless the first two teams have the same
1277 // maximum score. The latter case also breaks the time limit.
1278 float(float fraglimit) WinningCondition_MaxTeamMax =
1282 team1_score = team2_score = team3_score = team4_score = 0;
1284 head = findchain(classname, "player");
1287 if(head.team == COLOR_TEAM1)
1289 if(head.frags > team1_score)
1290 team1_score = head.frags;
1292 else if(head.team == COLOR_TEAM2)
1294 if(head.frags > team2_score)
1295 team2_score = head.frags;
1297 else if(head.team == COLOR_TEAM3)
1299 if(head.frags > team3_score)
1300 team3_score = head.frags;
1302 else if(head.team == COLOR_TEAM4)
1304 if(head.frags > team4_score)
1305 team4_score = head.frags;
1310 return WinningConditionBase_Teamplay(fraglimit);
1313 void PrintScoreboardFor(string name, string colorcode, float whichteam)
1320 head = find(world, classname, "player");
1323 if(!whichteam || head.team == whichteam)
1327 ServerConsoleEcho(strcat(" ", colorcode, name, ":"), FALSE);
1329 fragtotal = fragtotal + head.frags;
1330 s = ftos(head.frags);
1331 s = strcat(s, "/", ftos(head.deaths));
1332 s = strcat(s, " @ ", ftos(head.ping));
1333 if(clienttype(head) == CLIENTTYPE_BOT)
1334 s = strcat(s, "botms");
1336 s = strcat(s, "ms");
1337 ServerConsoleEcho(strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"), TRUE);
1339 head = find(head, classname, "player");
1341 if(whichteam && found)
1342 ServerConsoleEcho(strcat(colorcode, " (total: ", ftos(fragtotal), ")"), FALSE);
1345 void PrintScoreboard()
1347 ServerConsoleEcho("Scoreboard:", FALSE);
1350 PrintScoreboardFor("Red", "^1", COLOR_TEAM1);
1351 PrintScoreboardFor("Blue", "^4", COLOR_TEAM2);
1352 PrintScoreboardFor("Pink", "^6", COLOR_TEAM3);
1353 PrintScoreboardFor("Yellow", "^3", COLOR_TEAM4);
1357 PrintScoreboardFor("", "^7", 0);
1359 ServerConsoleEcho(".", FALSE);
1362 void RemoveFromMaplist(string m)
1369 litems = tokenize(cvar_string("g_maplist"));
1372 for(i = 0; i < litems; ++i)
1375 result = strcat(result);
1379 result = strcat(result, "'", argv(i), "'");
1382 cvar_set("g_maplist", result);
1383 ServerConsoleEcho(strcat("Removed ", ftos(found), " items."), FALSE);
1386 void AddToMaplist(string m)
1395 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1397 ServerConsoleEcho("Map not found.", FALSE);
1401 litems = tokenize(cvar_string("g_maplist"));
1402 if(cvar("g_maplist_shuffle"))
1403 ipos = ceil(random() * (litems + 1)) - 1;
1408 for(i = 0; i < litems; ++i)
1413 result = strcat(result, "'", m, "'");
1416 result = strcat(result, "'", argv(i), "'");
1421 result = strcat(result, "'", m, "'");
1424 cvar_set("g_maplist", result);
1425 ServerConsoleEcho("Map added.", FALSE);
1428 ServerConsoleEcho("Map already in list.", FALSE);
1431 void ShuffleMaplist()
1439 result = cvar_string("g_maplist");
1440 litems = tokenize(result);
1442 for(start = 0; start < litems - 1; ++start)
1446 // select a random item
1447 selected = ceil(random() * (litems - start) + start) - 1;
1449 // shift this item to the place start
1450 for(i = 0; i < start; ++i)
1451 result = strcat(result, "'", argv(i), "'");
1452 result = strcat(result, "'", argv(selected), "'");
1453 for(i = start; i < litems; ++i)
1455 result = strcat(result, "'", argv(i), "'");
1457 litems = tokenize(result);
1459 //dprint(result, "\n");
1462 cvar_set("g_maplist", result);
1465 void() HandleMaplistShuffleCommands =
1467 // automatically shuffle when setting g_maplist_shuffle
1468 if(cvar_string("_g_maplist_add") != "")
1470 AddToMaplist(cvar_string("_g_maplist_add"));
1471 cvar_set("_g_maplist_add", "");
1473 if(cvar_string("_g_maplist_remove") != "")
1475 RemoveFromMaplist(cvar_string("_g_maplist_remove"));
1476 cvar_set("_g_maplist_remove", "");
1478 if(cvar("_g_maplist_shufflenow") || (cvar("g_maplist_shuffle") && !cvar("_g_maplist_have_shuffled")))
1481 cvar_set("_g_maplist_shufflenow", "0");
1482 cvar_set("_g_maplist_have_shuffled", "1");
1483 ServerConsoleEcho("Shuffled map list.", FALSE);
1485 if(cvar("_g_maplist_have_shuffled"))
1486 if(!cvar("g_maplist_shuffle"))
1487 cvar_set("_g_maplist_have_shuffled", "0");
1494 Exit deathmatch games upon conditions
1497 void() CheckRules_World =
1500 local float timelimit;
1501 local float fraglimit;
1507 if (intermission_running)
1508 if (time >= intermission_exittime + 60)
1514 if (gameover) // someone else quit the game already
1519 if(cvar("_scoreboard"))
1521 cvar_set("_scoreboard", "0");
1525 HandleMaplistShuffleCommands();
1527 timelimit = cvar("timelimit") * 60;
1528 fraglimit = cvar("fraglimit");
1530 if (timelimit && time >= timelimit)
1533 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1539 if(!checkrules_overtimewarning && checkrules_overtimeend)
1541 checkrules_overtimewarning = TRUE;
1542 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1543 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1546 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1548 checkrules_oneminutewarning = TRUE;
1549 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1552 status = WINNING_NO;
1555 status = WinningCondition_LMS();
1561 if(cvar("g_tdm") || cvar("g_runematch") || cvar("g_ctf") || cvar("g_domination"))
1562 status = WinningCondition_MaxTeamSum(fraglimit);
1564 // status = WinningCondition_MaxTeamMax(fraglimit);
1567 dprint("div0: How can this happen?\n");
1568 status = WinningCondition_MaxTeamMax(fraglimit);
1572 status = WinningCondition_MaxIndividualScore(fraglimit);
1575 if(status == WINNING_STARTOVERTIME)
1577 status = WINNING_NEVER;
1581 if(status == WINNING_NEVER)
1582 // equality cases! Nobody wins if the overtime ends in a draw.
1585 if(checkrules_overtimeend)
1586 if(status != WINNING_NEVER)
1587 status = WINNING_YES;
1589 if(status == WINNING_YES)