1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
7 float() DoNextMapOverride;
11 if(cvar("g_running_guns"))
13 default_player_alpha = -1;
14 default_weapon_alpha = +1;
16 else if(cvar("g_cloaked"))
18 default_player_alpha = cvar("g_balance_cloaked_alpha");
19 default_weapon_alpha = default_player_alpha;
23 default_player_alpha = cvar("g_player_alpha");
24 if(default_player_alpha <= 0)
25 default_player_alpha = 1;
26 default_weapon_alpha = default_player_alpha;
30 void fteqcc_testbugs()
34 if(!cvar("developer_fteqccbugs"))
37 dprint("*** fteqcc test: checking for bugs...\n");
41 if(sqrt(a) - sqrt(b - a) == 0)
42 dprint("*** fteqcc test: found same-function-twice bug\n");
44 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
48 world.enemy.frags += 10;
49 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
50 dprint("*** fteqcc test: found += bug\n");
52 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
60 cvar_set("_sv_init", "0");
61 if(cvar("g_maplist_shuffle"))
63 tokenize(cvar_string("g_maplist"));
64 if(argv(0) != GetMapname())
66 cvar_set("nextmap", argv(0));
67 if(!DoNextMapOverride())
73 float world_already_spawned;
74 void worldspawn (void)
76 if(world_already_spawned)
77 error("world already spawned - you may have EXACTLY ONE worldspawn!");
78 world_already_spawned = TRUE;
81 TODO sound pack system
82 // initialize sound pack system
83 soundpack = cvar_string("g_soundpack");
85 soundpack = strcat(soundpack, "/");
86 soundpack = strzone(soundpack);
89 // Precache all player models
90 // Workaround for "invisible players"
91 precache_model("models/player/carni.zym");
92 precache_model("models/player/crash.zym");
93 precache_model("models/player/grunt.zym");
94 precache_model("models/player/headhunter.zym");
95 precache_model("models/player/insurrectionist.zym");
96 precache_model("models/player/jeandarc.zym");
97 precache_model("models/player/lurk.zym");
98 precache_model("models/player/lycanthrope.zym");
99 precache_model("models/player/marine.zym");
100 precache_model("models/player/nexus.zym");
101 precache_model("models/player/pyria.zym");
102 precache_model("models/player/shock.zym");
103 precache_model("models/player/skadi.zym");
104 precache_model("models/player/specop.zym");
105 precache_model("models/player/visitant.zym");
107 //precache_model ("progs/beam.mdl");
108 precache_model ("models/bullet.mdl");
109 precache_model ("models/casing_bronze.mdl");
110 precache_model ("models/casing_shell.mdl");
111 precache_model ("models/casing_steel.mdl");
112 precache_model ("models/ebomb.mdl");
113 precache_model ("models/elaser.mdl");
114 precache_model ("models/flash.md3");
115 precache_model ("models/gibs/bloodyskull.md3");
116 precache_model ("models/gibs/chunk.mdl");
117 precache_model ("models/gibs/eye.md3");
118 precache_model ("models/gibs/gib1.md3");
119 //precache_model ("models/gibs/gib2.md3");
120 //precache_model ("models/gibs/gib3.md3");
121 //precache_model ("models/gibs/gib4.md3");
122 precache_model ("models/gibs/gib5.md3");
123 //precache_model ("models/gibs/gib6.md3");
124 precache_model ("models/gibs/gib1.mdl");
125 precache_model ("models/gibs/gib2.mdl");
126 precache_model ("models/gibs/gib3.mdl");
127 precache_model ("models/grenademodel.md3");
128 precache_model ("models/hagarmissile.mdl");
129 precache_model ("models/items/a_bullets.mdl");
130 precache_model ("models/items/a_cells.md3");
131 precache_model ("models/items/a_rockets.md3");
132 precache_model ("models/items/a_shells.md3");
133 precache_model ("models/items/g_a1.md3");
134 precache_model ("models/items/g_a25.md3");
135 precache_model ("models/items/g_h1.md3");
136 precache_model ("models/items/g_h25.md3");
137 precache_model ("models/items/g_h100.md3");
138 precache_model ("models/items/g_invincible.md3");
139 precache_model ("models/items/g_strength.md3");
140 precache_model ("models/laser.mdl");
141 precache_model ("models/misc/chatbubble.spr");
142 precache_model ("models/misc/teambubble.spr");
143 precache_model ("models/nexflash.md3");
144 precache_model ("models/plasma.mdl");
145 precache_model ("models/plasmatrail.mdl");
146 precache_model ("models/rocket.md3");
147 //precache_model ("models/sprites/grenexpl.spr");
148 precache_model ("models/runematch/rune.mdl");
149 precache_model ("models/runematch/curse.mdl");
150 //precache_model ("models/sprites/hagar.spr");
151 //precache_model ("models/sprites/muzzleflash.spr32");
152 //precache_model ("models/sprites/electrocombo.spr32");
153 //precache_model ("models/sprites/plasmahitwall.spr32");
154 //precache_model ("models/sprites/plasmashot.spr32");
155 //precache_model ("models/sprites/rockexpl.spr");
156 precache_model ("models/tracer.mdl");
157 precache_model ("models/uziflash.md3");
158 precache_model ("models/weapons/g_crylink.md3");
159 precache_model ("models/weapons/g_electro.md3");
160 precache_model ("models/weapons/g_gl.md3");
161 precache_model ("models/weapons/g_hagar.md3");
162 precache_model ("models/weapons/g_nex.md3");
163 precache_model ("models/weapons/g_rl.md3");
164 precache_model ("models/weapons/g_shotgun.md3");
165 precache_model ("models/weapons/g_uzi.md3");
166 precache_model ("models/weapons/v_crylink.md3");
167 precache_model ("models/weapons/v_electro.md3");
168 precache_model ("models/weapons/v_gl.md3");
169 precache_model ("models/weapons/v_hagar.md3");
170 precache_model ("models/weapons/v_laser.md3");
171 precache_model ("models/weapons/v_nex.md3");
172 precache_model ("models/weapons/v_rl.md3");
173 precache_model ("models/weapons/v_shotgun.md3");
174 precache_model ("models/weapons/v_uzi.md3");
175 precache_model ("models/weapons/w_crylink.zym");
176 precache_model ("models/weapons/w_electro.zym");
177 precache_model ("models/weapons/w_gl.zym");
178 precache_model ("models/weapons/w_hagar.zym");
179 precache_model ("models/weapons/w_laser.zym");
180 precache_model ("models/weapons/w_nex.zym");
181 precache_model ("models/weapons/w_rl.zym");
182 precache_model ("models/weapons/w_shotgun.zym");
183 precache_model ("models/weapons/w_uzi.zym");
185 // laser for laser-guided weapons
186 precache_model ("models/laser_dot.mdl");
188 precache_sound ("misc/null.wav");
189 precache_sound ("misc/armor1.wav");
190 precache_sound ("misc/armor25.wav");
191 precache_sound ("misc/armorimpact.wav");
192 precache_sound ("misc/bodyimpact1.wav");
193 precache_sound ("misc/bodyimpact2.wav");
194 precache_sound ("misc/gib.wav");
195 precache_sound ("misc/gib_splat01.wav");
196 precache_sound ("misc/gib_splat02.wav");
197 precache_sound ("misc/gib_splat03.wav");
198 precache_sound ("misc/gib_splat04.wav");
199 //precache_sound ("misc/h2ohit.wav");
200 precache_sound ("misc/hit.wav");
201 precache_sound ("misc/footstep01.wav");
202 precache_sound ("misc/footstep02.wav");
203 precache_sound ("misc/footstep03.wav");
204 precache_sound ("misc/footstep04.wav");
205 precache_sound ("misc/footstep05.wav");
206 precache_sound ("misc/footstep06.wav");
207 precache_sound ("misc/hitground1.wav");
208 precache_sound ("misc/hitground2.wav");
209 precache_sound ("misc/hitground3.wav");
210 precache_sound ("misc/hitground4.wav");
211 precache_sound ("misc/itempickup.wav");
212 precache_sound ("misc/itemrespawn.wav");
213 precache_sound ("misc/jumppad.wav");
214 precache_sound ("misc/mediumhealth.wav");
215 precache_sound ("misc/megahealth.wav");
216 precache_sound ("misc/minihealth.wav");
217 precache_sound ("misc/powerup.wav");
218 precache_sound ("misc/powerup_shield.wav");
219 precache_sound ("misc/talk.wav");
220 precache_sound ("misc/teleport.wav");
221 precache_sound ("plats/medplat1.wav");
222 precache_sound ("plats/medplat2.wav");
223 precache_sound ("player/lava.wav");
224 precache_sound ("player/slime.wav");
225 precache_sound ("weapons/crylink_fire.wav");
226 precache_sound ("weapons/electro_bounce.wav");
227 precache_sound ("weapons/electro_fire.wav");
228 precache_sound ("weapons/electro_fire2.wav");
229 precache_sound ("weapons/electro_fly.wav");
230 precache_sound ("weapons/electro_impact.wav");
231 precache_sound ("weapons/electro_impact_combo.wav");
232 //precache_sound ("weapons/grenade_bounce.wav");
233 precache_sound ("weapons/grenade_bounce1.wav");
234 precache_sound ("weapons/grenade_bounce2.wav");
235 precache_sound ("weapons/grenade_bounce3.wav");
236 precache_sound ("weapons/grenade_bounce4.wav");
237 precache_sound ("weapons/grenade_bounce5.wav");
238 precache_sound ("weapons/grenade_bounce6.wav");
239 precache_sound ("weapons/grenade_fire.wav");
240 precache_sound ("weapons/grenade_impact.wav");
241 precache_sound ("weapons/hagar_fire.wav");
242 precache_sound ("weapons/hagexp1.wav");
243 precache_sound ("weapons/hagexp2.wav");
244 precache_sound ("weapons/hagexp3.wav");
245 precache_sound ("weapons/hook_fire.wav");
246 precache_sound ("weapons/hook_impact.wav");
247 precache_sound ("weapons/lasergun_fire.wav");
248 precache_sound ("weapons/laserimpact.wav");
249 precache_sound ("weapons/nexfire.wav");
250 precache_sound ("weapons/neximpact.wav");
251 precache_sound ("weapons/ric1.wav");
252 precache_sound ("weapons/ric2.wav");
253 precache_sound ("weapons/ric3.wav");
254 precache_sound ("weapons/rocket_fire.wav");
255 precache_sound ("weapons/rocket_fly.wav");
256 precache_sound ("weapons/rocket_impact.wav");
257 precache_sound ("weapons/rocket_det.wav");
258 precache_sound ("weapons/shotgun_fire.wav");
259 precache_sound ("weapons/tink1.wav");
260 precache_sound ("weapons/uzi_fire.wav");
261 precache_sound ("weapons/weapon_switch.wav");
262 precache_sound ("weapons/weaponpickup.wav");
263 precache_sound ("weapons/strength_fire.wav");
265 //precache_sound ("announce/male/kill10.wav");
266 //precache_sound ("announce/male/kill15.wav");
267 //precache_sound ("announce/male/kill20.wav");
268 //precache_sound ("announce/male/kill25.wav");
269 //precache_sound ("announce/male/kill3.wav");
270 //precache_sound ("announce/male/kill30.wav");
271 //precache_sound ("announce/male/kill4.wav");
272 //precache_sound ("announce/male/kill5.wav");
273 //precache_sound ("announce/male/kill6.wav");
274 //precache_sound ("announce/male/mapkill1.wav");
275 //precache_sound ("announce/robotic/last_second_save.wav");
276 //precache_sound ("announce/robotic/narrowly_averted.wav");
277 //precache_sound ("minstagib/mockery.wav");
279 // announcer sounds - male
280 precache_sound ("announcer/male/03kills.wav");
281 precache_sound ("announcer/male/05kills.wav");
282 precache_sound ("announcer/male/10kills.wav");
283 precache_sound ("announcer/male/15kills.wav");
284 precache_sound ("announcer/male/20kills.wav");
285 precache_sound ("announcer/male/25kills.wav");
286 precache_sound ("announcer/male/30kills.wav");
287 precache_sound ("announcer/male/botlike.wav");
288 precache_sound ("announcer/male/electrobitch.wav");
289 precache_sound ("announcer/male/welcome.wav");
290 precache_sound ("announcer/male/yoda.wav");
292 // announcer sounds - robotic
293 precache_sound ("announcer/robotic/1fragleft.wav");
294 precache_sound ("announcer/robotic/1minuteremains.wav");
295 precache_sound ("announcer/robotic/2fragsleft.wav");
296 precache_sound ("announcer/robotic/3fragsleft.wav");
297 precache_sound ("announcer/robotic/lastsecond.wav");
298 precache_sound ("announcer/robotic/narrowly.wav");
299 precache_sound ("announcer/robotic/1.wav");
300 precache_sound ("announcer/robotic/2.wav");
301 precache_sound ("announcer/robotic/3.wav");
302 precache_sound ("announcer/robotic/4.wav");
303 precache_sound ("announcer/robotic/5.wav");
304 precache_sound ("announcer/robotic/6.wav");
305 precache_sound ("announcer/robotic/7.wav");
306 precache_sound ("announcer/robotic/8.wav");
307 precache_sound ("announcer/robotic/9.wav");
308 precache_sound ("announcer/robotic/10.wav");
310 // plays music for the level if there is any
313 precache_sound (self.noise);
314 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
320 // 1 FLICKER (first variety)
321 lightstyle(1, "mmnmmommommnonmmonqnmmo");
323 // 2 SLOW STRONG PULSE
324 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
326 // 3 CANDLE (first variety)
327 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
330 lightstyle(4, "mamamamamama");
333 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
335 // 6 FLICKER (second variety)
336 lightstyle(6, "nmonqnmomnmomomno");
338 // 7 CANDLE (second variety)
339 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
341 // 8 CANDLE (third variety)
342 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
344 // 9 SLOW STROBE (fourth variety)
345 lightstyle(9, "aaaaaaaazzzzzzzz");
347 // 10 FLUORESCENT FLICKER
348 lightstyle(10, "mmamammmmammamamaaamammma");
350 // 11 SLOW PULSE NOT FADE TO BLACK
351 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
353 // styles 32-62 are assigned by the light program for switchable lights
359 lms_lowest_lives = 0;
364 bot_waypoints_for_items = cvar("g_waypoints_for_items");
365 if(bot_waypoints_for_items == 1)
366 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
367 bot_waypoints_for_items = 0;
369 if(cvar("g_campaign"))
374 WaypointSprite_Init();
376 //if (cvar("g_domination"))
380 head = nextent(world);
385 head = nextent(head);
388 GameLogInit(); // prepare everything
389 if(cvar("sv_eventlog"))
392 GameLogEcho(":logversion:2", FALSE);
393 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
394 s = strcat(s, ftos(random()));
395 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
396 s = ":gameinfo:mutators:LIST";
397 if(cvar("g_grappling_hook"))
398 s = strcat(s, ":grappling_hook");
399 if(!cvar("g_use_ammunition"))
400 s = strcat(s, ":no_use_ammunition");
401 if(!cvar("g_pickup_items"))
402 s = strcat(s, ":no_pickup_items");
403 if(cvar("g_instagib"))
404 s = strcat(s, ":instagib");
405 if(cvar("g_rocketarena"))
406 s = strcat(s, ":rockerarena");
408 s = strcat(s, ":nixnex");
409 if(cvar("g_vampire"))
410 s = strcat(s, ":vampire");
411 if(cvar("g_laserguided_missile"))
412 s = strcat(s, ":laserguided_missile");
413 if(cvar("g_norecoil"))
414 s = strcat(s, ":norecoil");
416 s = strcat(s, ":midair");
417 if(cvar("g_minstagib"))
418 s = strcat(s, ":minstagib");
419 GameLogEcho(s, FALSE);
420 GameLogEcho(":gameinfo:end", FALSE);
423 cvar_set("nextmap", "");
427 if(cvar("g_campaign"))
437 //makestatic (self); // Who the f___ did that?
441 float( string pFilename ) TryFile =
444 dprint("TryFile(\"", pFilename, "\")\n");
445 lHandle = fopen( pFilename, FILE_READ );
446 if( lHandle != -1 ) {
456 if (game == GAME_DEATHMATCH)
458 else if (game == GAME_TEAM_DEATHMATCH)
460 else if (game == GAME_DOMINATION)
462 else if (game == GAME_CTF)
464 else if (game == GAME_RUNEMATCH)
466 else if (game == GAME_LMS)
468 else if (game == GAME_KEYHUNT)
473 string getmapname_stored;
476 if(getmapname_stored == "")
477 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
478 return getmapname_stored;
481 float Map_Count, Map_Current;
482 string Map_Current_Name;
484 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
485 float GetMaplistPosition()
491 idx = cvar("g_maplist_index");
498 for(pos = 0; pos < Map_Count; ++pos)
502 // resume normal maplist rotation if current map is not in g_maplist
506 float MapHasRightSize(string map)
508 // open map size restriction file
510 dprint("opensize "); dprint(map);
511 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
514 float mapmin, mapmax;
516 mapmin = stof(fgets(fh));
517 mapmax = stof(fgets(fh));
519 if(player_count < mapmin)
521 dprint("not enough\n");
524 if(player_count > mapmax)
526 dprint("too many\n");
529 dprint("right size\n");
532 dprint(": not found\n");
536 string Map_Filename(float position)
539 return strcat("maps/", argv(position), ".mapcfg");
542 float(float position, float pass) Map_Check =
546 map_next = argv(position);
548 if(map_next == Map_Current_Name) // same map again in first pass?
550 filename = Map_Filename(position);
551 if(TryFile(filename))
555 if(MapHasRightSize(argv(position)))
560 dprint( "Couldn't find '", filename, "'..\n" );
565 void(string nextmapname) Map_Goto_SetStr =
567 if(getmapname_stored != "")
568 strunzone(getmapname_stored);
569 if(nextmapname == "")
570 getmapname_stored = "";
572 getmapname_stored = strzone(nextmapname);
575 void(float position) Map_Goto_SetFloat =
577 cvar_set("g_maplist_index", ftos(position));
578 Map_Goto_SetStr(argv(position));
581 void() GameResetCfg =
583 // if an exit cfg is defined by exiting map, exec it.
585 exit_cfg = cvar_string("exit_cfg");
587 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
589 localcmd("exec game_reset.cfg\n");
595 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
598 // return codes of map selectors:
599 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
600 // -2 = permanent failure
601 float() MaplistMethod_Iterate = // usual method
605 for(pass = 1; pass <= 2; ++pass)
607 for(i = 1; i < Map_Count; ++i)
610 mapindex = math_mod(i + Map_Current, Map_Count);
611 if(Map_Check(mapindex, pass))
618 float() MaplistMethod_Repeat = // fallback method
620 if(Map_Check(Map_Current, 2))
625 float() MaplistMethod_Random = // random map selection
631 for(i = 0; i <= imax; ++i)
634 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
635 if(Map_Check(mapindex, 1))
641 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
642 // the exponent sets a bias on the map selection:
643 // the higher the exponent, the less likely "shortly repeated" same maps are
645 float i, j, imax, insertpos;
650 return 0; // only one map, then always play this one
652 for(i = 0; i <= imax; ++i)
656 // now reinsert this at another position
657 insertpos = pow(random(), 1 / exponent); // ]0, 1]
658 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
659 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
660 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
662 // insert the current map there
664 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
665 newlist = strcat(newlist, "'", argv(j), "'");
666 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
667 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
668 newlist = strcat(newlist, "'", argv(j), "'");
669 cvar_set("g_maplist", newlist);
670 Map_Count = tokenize(newlist);
672 // NOTE: the selected map has just been inserted at (insertpos-1)th position
673 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
674 if(Map_Check(Map_Current, 1))
680 void() Maplist_Init =
683 temp = cvar_string("g_maplist");
684 Map_Count = tokenize(temp);
687 bprint( "Maplist is empty! Resetting it to default map list.\n" );
688 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
689 Map_Count = tokenize(temp);
692 error("empty maplist, cannot select a new map");
693 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
695 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
696 // this may or may not be correct, but who cares, in the worst case a map
697 // isn't chosen in the first pass that should have been
700 string() GetNextMap =
708 if(cvar("g_maplist_shuffle") > 0)
709 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
712 if(cvar("g_maplist_selectrandom"))
713 nextMap = MaplistMethod_Random();
716 nextMap = MaplistMethod_Iterate();
719 nextMap = MaplistMethod_Repeat();
723 Map_Goto_SetFloat(nextMap);
724 return getmapname_stored;
730 float() DoNextMapOverride =
732 if(cvar("g_campaign"))
734 CampaignPostIntermission();
737 if(cvar("quit_when_empty"))
739 if(player_count <= currentbots)
745 if(cvar_string("quit_and_redirect") != "")
747 redirection_target = strzone(cvar_string("quit_and_redirect"));
750 if (cvar("samelevel")) // if samelevel is set, stay on same level
752 // 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)
753 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
754 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
755 localcmd("restart\n");
756 //changelevel (mapname);
759 if(cvar_string("nextmap") != "")
760 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
762 Map_Goto_SetStr(cvar_string("nextmap"));
766 if(cvar("lastlevel"))
769 localcmd("set lastlevel 0\ntogglemenu\n");
777 //local string nextmap;
778 //local float n, nummaps;
780 if (alreadychangedlevel)
782 alreadychangedlevel = TRUE;
788 for(allowReset = 1; allowReset >= 0; --allowReset)
790 nextMap = GetNextMap();
796 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
797 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
801 error("Everything is broken - not even the default map list works. Please report this to the developers.");
813 When the player presses attack or jump, change to the next level
816 .float autoscreenshot;
817 void() MapVote_Think;
818 float mapvote_initialized;
819 void() IntermissionThink =
821 FixIntermissionClient(self);
823 if(cvar("sv_autoscreenshot"))
824 if(self.autoscreenshot > 0)
825 if(time > self.autoscreenshot)
827 self.autoscreenshot = -1;
828 if(clienttype(self) == CLIENTTYPE_REAL)
829 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
833 if (time < intermission_exittime)
836 if(!mapvote_initialized)
837 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
840 if(intermission_exittime >= 0)
848 Returns the entity to view from
852 entity() FindIntermission =
857 // look for info_intermission first
858 spot = find (world, classname, "info_intermission");
860 { // pick a random one
864 spot = find (spot, classname, "info_intermission");
866 spot = find (spot, classname, "info_intermission");
872 // then look for the start position
873 spot = find (world, classname, "info_player_start");
877 // testinfo_player_start is only found in regioned levels
878 spot = find (world, classname, "testplayerstart");
882 // then look for the start position
883 spot = find (world, classname, "info_player_deathmatch");
887 //objerror ("FindIntermission: no spot");
893 ===============================================================================
897 ===============================================================================
900 void(float final) DumpStats =
904 local float to_console;
905 local float to_eventlog;
908 to_console = cvar("sv_logscores_console");
909 to_eventlog = cvar("sv_eventlog");
910 to_file = cvar("sv_logscores_file");
914 to_console = TRUE; // always print printstats replies
915 to_eventlog = FALSE; // but never print them to the event log
919 if(cvar("sv_eventlog_console"))
920 to_console = FALSE; // otherwise we get the output twice
926 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
929 ServerConsoleEcho(s, FALSE);
931 GameLogEcho(s, FALSE);
934 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
938 fputs(file, strcat(s, "\n"));
941 FOR_EACH_CLIENT(other)
943 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
945 s = strcat(":player:", ftos(other.frags), ":");
946 s = strcat(s, ftos(other.deaths), ":");
947 s = strcat(s, ftos(rint(time - other.jointime)), ":");
948 s = strcat(s, ftos(other.team), ":");
951 ServerConsoleEcho(strcat(s, other.netname), TRUE);
953 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
955 fputs(file, strcat(s, other.netname, "\n"));
960 ServerConsoleEcho(":end", FALSE);
962 GameLogEcho(":end", FALSE);
965 fputs(file, ":end\n");
970 void FixIntermissionClient(entity e)
972 if(!e.autoscreenshot) // initial call
974 e.angles = e.v_angle;
975 e.angles_x = -e.angles_x;
976 e.autoscreenshot = time + 0.8; // used for autoscreenshot
978 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
980 e.movetype = MOVETYPE_NONE;
981 e.takedamage = DAMAGE_NO;
983 e.weaponentity.effects = EF_NODRAW;
984 stuffcmd(e, "\nscr_printspeed 1000000\n");
985 if(clienttype(e) == CLIENTTYPE_REAL)
988 WriteByte(MSG_ONE, SVC_INTERMISSION);
992 //e.velocity = '0 0 0';
995 // TODO halt weapon animation
1000 go to the next level for deathmatch
1001 only called if a time or frag limit has expired
1005 float minTotalFrags;
1006 float maxTotalFrags;
1012 intermission_running = 1;
1014 // enforce a wait time before allowing changelevel
1015 if(player_count > 0)
1016 intermission_exittime = time + cvar("sv_mapchange_delay");
1018 intermission_exittime = -60;
1020 WriteByte (MSG_ALL, SVC_CDTRACK);
1021 WriteByte (MSG_ALL, 3);
1022 WriteByte (MSG_ALL, 3);
1024 //pos = FindIntermission ();
1030 if(cvar("sv_eventlog"))
1031 GameLogEcho(":gameover", FALSE);
1036 FOR_EACH_CLIENT(other)
1038 if(maxTotalFrags < other.totalfrags)
1039 maxTotalFrags = other.totalfrags;
1040 if(minTotalFrags > other.totalfrags)
1041 minTotalFrags = other.totalfrags;
1044 FOR_EACH_CLIENT(other)
1046 FixIntermissionClient(other);
1051 bprint(other.netname, " ^7wins.\n");
1055 score = (other.frags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1056 f = bound(0, other.play_time / max(time, 1), 1);
1057 // store some statistics?
1061 if(cvar("g_campaign"))
1062 CampaignPreIntermission();
1064 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1071 Exit deathmatch games upon conditions
1074 void() CheckRules_Player =
1076 if (gameover) // someone else quit the game already
1079 if(self.deadflag == DEAD_NO)
1080 self.play_time += frametime;
1082 // fixme: don't check players; instead check dom_team and ctf_team entities
1083 // (div0: and that in CheckRules_World please)
1086 float checkrules_oneminutewarning;
1087 float checkrules_leaderfrags;
1088 float tdm_max_score, tdm_old_score;
1090 float checkrules_equality;
1091 float checkrules_overtimewarning;
1092 float checkrules_overtimeend;
1094 void() InitiateOvertime =
1096 if(!checkrules_overtimeend)
1097 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1100 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1101 float WINNING_YES = 1; // winner found
1102 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1103 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1105 float(float fraglimitreached, float equality) GetWinningCode =
1108 if(fraglimitreached)
1109 return WINNING_STARTOVERTIME;
1111 return WINNING_NEVER;
1113 if(fraglimitreached)
1119 // set the .winning flag for exactly those players with a given field value
1120 void(.float field, float value) SetWinners =
1123 FOR_EACH_PLAYER(head)
1124 head.winning = (head.field == value);
1127 // set the .winning flag for those players with a given field value
1128 void(.float field, float value) AddWinners =
1131 FOR_EACH_PLAYER(head)
1132 if(head.field == value)
1136 // clear the .winning flags
1137 void(void) ClearWinners =
1140 FOR_EACH_PLAYER(head)
1144 float() LMS_NewPlayerLives =
1147 fl = cvar("fraglimit");
1151 // first player has left the game for dying too much? Nobody else can get in.
1152 if(lms_lowest_lives < 1)
1155 if(!cvar("g_lms_join_anytime"))
1156 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1159 return bound(1, lms_lowest_lives, fl);
1162 // LMS winning condition: game terminates if and only if there's at most one
1163 // one player who's living lives. Top two scores being equal cancels the time
1165 float() WinningCondition_LMS =
1172 have_player = FALSE;
1173 have_players = FALSE;
1174 l = LMS_NewPlayerLives();
1176 head = find(world, classname, "player");
1179 head = find(head, classname, "player");
1181 have_players = TRUE;
1185 // we have at least one player
1188 // two or more active players - continue with the game
1192 // exactly one player?
1195 // but no game has taken place yet
1200 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1201 dprint("Have a winner, ending game.\n");
1208 // nobody is playing at all...
1211 // wait for players...
1215 // SNAFU (maybe a draw game?)
1217 dprint("No players, ending game.\n");
1222 // When we get here, we have at least two players who are actually LIVING,
1223 // or one player who is still waiting for a victim to join the server. Now
1224 // check if the top two players have equal score.
1226 checkrules_leaderfrags = 0;
1227 checkrules_equality = FALSE;
1228 FOR_EACH_PLAYER(head)
1230 if(head.frags > checkrules_leaderfrags)
1232 checkrules_leaderfrags = head.frags;
1233 checkrules_equality = FALSE;
1235 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1236 checkrules_equality = TRUE;
1239 SetWinners(frags, checkrules_leaderfrags);
1241 // The top two players have the same amount of lives? No timelimit then,
1242 // enter overtime...
1244 if(checkrules_equality)
1245 return WINNING_NEVER;
1247 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1251 // DM winning condition: game terminates if a player reached the fraglimit,
1252 // unless the first two players have the same score. The latter case also
1253 // breaks the time limit.
1254 float(float fraglimit) WinningCondition_MaxIndividualScore =
1256 float checkrules_oldleaderfrags;
1259 checkrules_oldleaderfrags = checkrules_leaderfrags;
1260 checkrules_leaderfrags = 0;
1261 checkrules_equality = FALSE;
1262 FOR_EACH_PLAYER(head)
1264 if(head.frags > checkrules_leaderfrags)
1266 checkrules_leaderfrags = head.frags;
1267 checkrules_equality = FALSE;
1269 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1270 checkrules_equality = TRUE;
1273 if(checkrules_leaderfrags > 0)
1274 SetWinners(frags, checkrules_leaderfrags);
1278 if (!cvar("g_runematch"))
1279 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1281 if (checkrules_leaderfrags == fraglimit - 1)
1282 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1283 else if (checkrules_leaderfrags == fraglimit - 2)
1284 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1285 else if (checkrules_leaderfrags == fraglimit - 3)
1286 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1289 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1292 float(float fraglimit) WinningConditionBase_Teamplay =
1294 tdm_old_score = tdm_max_score;
1295 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1297 checkrules_equality =
1302 (team1_score == tdm_max_score)
1303 + (team2_score == tdm_max_score)
1304 + (team3_score == tdm_max_score)
1305 + (team4_score == tdm_max_score)
1309 if(tdm_max_score > 0)
1311 if(team1_score == tdm_max_score)
1312 AddWinners(team, COLOR_TEAM1);
1313 if(team2_score == tdm_max_score)
1314 AddWinners(team, COLOR_TEAM2);
1315 if(team3_score == tdm_max_score)
1316 AddWinners(team, COLOR_TEAM3);
1317 if(team4_score == tdm_max_score)
1318 AddWinners(team, COLOR_TEAM4);
1321 if(!cvar("g_runematch") && !cvar("g_domination"))
1322 if(tdm_max_score != tdm_old_score)
1324 if(tdm_max_score == fraglimit - 1)
1325 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1326 else if(tdm_max_score == fraglimit - 2)
1327 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1328 else if(tdm_max_score == fraglimit - 3)
1329 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1332 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1335 // TDM winning condition: game terminates if a team's score sum reached the
1336 // fraglimit, unless the first two teams have the same total score. The latter
1337 // case also breaks the time limit.
1338 float(float fraglimit) WinningCondition_MaxTeamSum =
1342 team1_score = team2_score = team3_score = team4_score = 0;
1344 FOR_EACH_PLAYER(head)
1346 if(head.team == COLOR_TEAM1)
1347 team1_score += head.frags;
1348 else if(head.team == COLOR_TEAM2)
1349 team2_score += head.frags;
1350 else if(head.team == COLOR_TEAM3)
1351 team3_score += head.frags;
1352 else if(head.team == COLOR_TEAM4)
1353 team4_score += head.frags;
1356 return WinningConditionBase_Teamplay(fraglimit);
1359 // DOM/CTF winning condition: game terminates if the max of a team's players'
1360 // score reached the fraglimit, unless the first two teams have the same
1361 // maximum score. The latter case also breaks the time limit.
1362 float(float fraglimit) WinningCondition_MaxTeamMax =
1366 team1_score = team2_score = team3_score = team4_score = 0;
1368 FOR_EACH_PLAYER(head)
1370 if(head.team == COLOR_TEAM1)
1372 if(head.frags > team1_score)
1373 team1_score = head.frags;
1375 else if(head.team == COLOR_TEAM2)
1377 if(head.frags > team2_score)
1378 team2_score = head.frags;
1380 else if(head.team == COLOR_TEAM3)
1382 if(head.frags > team3_score)
1383 team3_score = head.frags;
1385 else if(head.team == COLOR_TEAM4)
1387 if(head.frags > team4_score)
1388 team4_score = head.frags;
1392 return WinningConditionBase_Teamplay(fraglimit);
1395 void print_to(entity e, string s)
1398 sprint(e, strcat(s, "\n"));
1400 ServerConsoleEcho(s, TRUE);
1403 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1413 FOR_EACH_PLAYER(head)
1415 if(!whichteam || head.team == whichteam)
1419 print_to(e, strcat(" ", colorcode, name, ":"));
1421 fragtotal = fragtotal + head.frags;
1422 s = ftos(head.frags);
1423 s = strcat(s, "/", ftos(head.deaths));
1424 s = strcat(s, " @ ", ftos(head.ping));
1425 if(clienttype(head) == CLIENTTYPE_BOT)
1426 s = strcat(s, "botms");
1428 s = strcat(s, "ms");
1429 v = PlayerValue(head);
1431 s = strcat(s, " / ", ftos(v));
1432 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1435 if(whichteam && found)
1437 s = ftos(fragtotal);
1438 s = strcat(s, " / ", ftos(teamvalue));
1439 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1443 void PrintScoreboard(entity e)
1445 print_to(e, strcat("Time: ", ftos(time / 60)));
1446 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1447 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1448 print_to(e, "Scoreboard:");
1451 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1452 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1453 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM3);
1454 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM4);
1458 PrintScoreboardFor(e, "", "^7", 0);
1463 void ShuffleMaplist()
1471 result = cvar_string("g_maplist");
1472 litems = tokenize(result);
1474 for(start = 0; start < litems - 1; ++start)
1478 // select a random item
1479 selected = ceil(random() * (litems - start) + start) - 1;
1481 // shift this item to the place start
1482 for(i = 0; i < start; ++i)
1483 result = strcat(result, "'", argv(i), "'");
1484 result = strcat(result, "'", argv(selected), "'");
1485 for(i = start; i < litems; ++i)
1487 result = strcat(result, "'", argv(i), "'");
1489 litems = tokenize(result);
1491 //dprint(result, "\n");
1494 cvar_set("g_maplist", result);
1501 Exit deathmatch games upon conditions
1504 void() CheckRules_World =
1507 local float timelimit;
1508 local float fraglimit;
1514 if (intermission_running)
1515 if (time >= intermission_exittime + 60)
1517 if(!DoNextMapOverride())
1522 if (gameover) // someone else quit the game already
1525 timelimit = cvar("timelimit") * 60;
1526 fraglimit = cvar("fraglimit");
1528 if(checkrules_overtimeend)
1530 if(!checkrules_overtimewarning)
1532 checkrules_overtimewarning = TRUE;
1533 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1534 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1539 if (timelimit && time >= timelimit)
1543 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1549 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1551 checkrules_oneminutewarning = TRUE;
1552 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1555 status = WINNING_NO;
1558 status = WinningCondition_LMS();
1564 if(cvar("g_tdm") || cvar("g_runematch") || cvar("g_ctf") || cvar("g_domination") || cvar("g_keyhunt"))
1565 status = WinningCondition_MaxTeamSum(fraglimit);
1567 // status = WinningCondition_MaxTeamMax(fraglimit);
1570 dprint("div0: How can this happen?\n");
1571 status = WinningCondition_MaxTeamMax(fraglimit);
1575 status = WinningCondition_MaxIndividualScore(fraglimit);
1578 if(status == WINNING_STARTOVERTIME)
1580 status = WINNING_NEVER;
1584 if(status == WINNING_NEVER)
1585 // equality cases! Nobody wins if the overtime ends in a draw.
1588 if(checkrules_overtimeend)
1589 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1590 status = WINNING_YES;
1592 if(status == WINNING_YES)
1596 float randsel_value;
1597 float randsel_priority;
1598 float randsel_count;
1602 randsel_priority = -1;
1605 void RandSel_Add(float priority, float value)
1607 if(priority > randsel_priority)
1609 randsel_priority = priority;
1610 randsel_value = value;
1613 else if(priority == randsel_priority)
1616 if(ceil(random() * randsel_count) == 1)
1617 randsel_value = value;
1621 float mapvote_nextthink;
1622 float mapvote_initialized;
1623 float mapvote_keeptwotime;
1624 float mapvote_timeout;
1625 string mapvote_message;
1627 #define MAPVOTE_COUNT 10
1628 float mapvote_count;
1629 string mapvote_maps[MAPVOTE_COUNT];
1630 float mapvote_maps_suggested[MAPVOTE_COUNT];
1631 string mapvote_suggestions[MAPVOTE_COUNT];
1632 float mapvote_suggestion_ptr;
1633 string mapvote_fillstr;
1634 float mapvote_maxlen;
1635 float mapvote_voters;
1636 float mapvote_votes[MAPVOTE_COUNT];
1639 void MapVote_ClearAllVotes()
1641 FOR_EACH_CLIENT(other)
1645 string MapVote_Suggest(string m)
1649 return "That's not how to use this command.";
1650 if(!cvar("g_maplist_votable_suggestions"))
1651 return "Suggestions are not accepted on this server.";
1652 if(mapvote_initialized)
1653 return "Can't suggest - voting is already in progress!";
1654 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1655 return "The map you suggested is not available on this server.";
1656 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1657 if(mapvote_suggestions[i] == m)
1658 return "This map was already suggested.";
1659 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1661 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1665 i = mapvote_suggestion_ptr;
1666 mapvote_suggestion_ptr += 1;
1668 if(mapvote_suggestions[i] != "")
1669 strunzone(mapvote_suggestions[i]);
1670 mapvote_suggestions[i] = strzone(m);
1671 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1672 return "Suggestion accepted.";
1675 void MapVote_AddVotable(string nextMap, float isSuggestion)
1680 for(j = 0; j < mapvote_count; ++j)
1681 if(mapvote_maps[j] == nextMap)
1683 if(strlen(nextMap) > mapvote_maxlen)
1684 mapvote_maxlen = strlen(nextMap);
1685 mapvote_maps[mapvote_count] = strzone(nextMap);
1686 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1695 MapVote_ClearAllVotes();
1697 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1698 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1701 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1702 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1704 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1705 MapVote_AddVotable(GetNextMap(), FALSE);
1707 if(mapvote_count == 0)
1709 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1710 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1711 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1712 MapVote_AddVotable(GetNextMap(), FALSE);
1715 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1717 mapvote_fillstr = " ";
1718 while(strlen(mapvote_fillstr) < mapvote_maxlen + 16)
1719 mapvote_fillstr = strcat(mapvote_fillstr, mapvote_fillstr);
1720 mapvote_fillstr = strzone(mapvote_fillstr);
1722 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1723 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1724 if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1725 mapvote_keeptwotime = 0;
1726 mapvote_message = "Choose a map and press its key!";
1728 float MapVote_Finished(float mappos)
1733 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1734 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1735 for(i = 0; i < mapvote_count; ++i)
1737 if(mapvote_maps[i] != "")
1739 result = strcat(result, ":", mapvote_maps[i]);
1740 result = strcat(result, ":", ftos(mapvote_votes[i]));
1742 GameLogEcho(result, FALSE);
1743 if(mapvote_maps_suggested[mappos])
1744 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1746 FOR_EACH_REALCLIENT(other)
1747 FixClientCvars(other);
1749 Map_Goto_SetStr(mapvote_maps[mappos]);
1753 void MapVote_CheckRules_1()
1757 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1759 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1760 mapvote_votes[i] = 0;
1764 FOR_EACH_REALCLIENT(other)
1769 i = other.mapvote - 1;
1770 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1771 mapvote_votes[i] = mapvote_votes[i] + 1;
1776 float MapVote_CheckRules_2()
1779 float firstPlace, secondPlace;
1780 float firstPlaceVotes, secondPlaceVotes;
1784 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1785 RandSel_Add(mapvote_votes[i], i);
1786 firstPlace = randsel_value;
1787 firstPlaceVotes = randsel_priority;
1788 //dprint("First place: ", ftos(firstPlace), "\n");
1789 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1792 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1794 RandSel_Add(mapvote_votes[i], i);
1795 secondPlace = randsel_value;
1796 secondPlaceVotes = randsel_priority;
1797 //dprint("Second place: ", ftos(secondPlace), "\n");
1798 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1800 if(firstPlace == -1)
1801 error("No first place in map vote... WTF?");
1803 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1804 return MapVote_Finished(firstPlace);
1806 if(mapvote_keeptwotime)
1807 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1809 mapvote_message = "Now decide between the TOP TWO!";
1810 mapvote_keeptwotime = 0;
1811 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1812 result = strcat(result, ":", ftos(firstPlaceVotes));
1813 result = strcat(result, ":", mapvote_maps[secondPlace]);
1814 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1815 for(i = 0; i < mapvote_count; ++i)
1817 if(i != secondPlace)
1818 if(mapvote_maps[i] != "")
1820 result = strcat(result, ":", mapvote_maps[i]);
1821 result = strcat(result, ":", ftos(mapvote_votes[i]));
1822 strunzone(mapvote_maps[i]);
1823 mapvote_maps[i] = "";
1825 GameLogEcho(result, FALSE);
1837 keeptwo = mapvote_keeptwotime;
1838 MapVote_CheckRules_1(); // count
1839 if(MapVote_CheckRules_2()) // decide
1842 FOR_EACH_REALCLIENT(other)
1844 // hide scoreboard again
1845 if(other.health != 2342)
1847 other.health = 2342;
1849 if(clienttype(other) == CLIENTTYPE_REAL)
1851 stuffcmd(other, "\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
1853 WriteByte(MSG_ONE, SVC_FINALE);
1854 WriteString(MSG_ONE, "");
1858 // notify about keep-two
1859 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1860 play2(other, "misc/invshot.wav");
1862 // clear possibly invalid votes
1863 if(mapvote_maps[other.mapvote - 1] == "")
1865 // use impulses as new vote
1866 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1867 if(mapvote_maps[other.impulse - 1] != "")
1868 other.mapvote = other.impulse;
1872 MapVote_CheckRules_1(); // just count
1874 FOR_EACH_REALCLIENT(other)
1876 // display voting screen
1877 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1878 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1879 msgstr = strcat(msgstr, mapvote_message);
1880 msgstr = strcat(msgstr, "\n\n");
1881 for(i = 0; i < mapvote_count; ++i)
1882 if(mapvote_maps[i] == "")
1883 msgstr = strcat(msgstr, "\n");
1886 tmp = mapvote_maps[i];
1887 tmp = strcat(tmp, substring(mapvote_fillstr, 0, mapvote_maxlen - strlen(tmp)));
1888 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
1889 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1890 if(mapvote_votes[i] != 1)
1891 tmp = strcat(tmp, "s");
1892 tmp = strcat(tmp, ")");
1893 tmp = strcat(tmp, substring(mapvote_fillstr, 0, mapvote_maxlen + 15 - strlen(tmp)));
1894 if(other.mapvote == i + 1)
1895 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
1897 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
1899 i = ceil(mapvote_timeout - time);
1900 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
1902 msgstr = strcat(msgstr, "s");
1903 msgstr = strcat(msgstr, " left");
1905 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
1908 void MapVote_Think()
1910 if(alreadychangedlevel)
1913 if(time < mapvote_nextthink)
1917 mapvote_nextthink = time + 0.5;
1919 if(!mapvote_initialized)
1921 mapvote_initialized = TRUE;
1922 if(DoNextMapOverride())
1924 alreadychangedlevel = TRUE;
1927 if(!cvar("g_maplist_votable"))
1942 FOR_EACH_REALCLIENT(self)
1944 if(self.classname == "spectator")
1946 if(self.enemy.hitsound)
1947 play2(self, "misc/hit.wav");
1952 play2(self, "misc/hit.wav");
1955 FOR_EACH_CLIENT(self)
1956 self.hitsound = FALSE;
1962 * returns TRUE if redirecting
1964 float redirection_timeout;
1965 float redirection_nextthink;
1966 float RedirectionThink()
1968 float clients_found;
1970 if(redirection_target == "")
1973 if(!redirection_timeout)
1975 cvar_set("sv_public", "-2");
1976 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
1977 if(redirection_target == "self")
1978 bprint("^3SERVER NOTICE:^7 restarting the server\n");
1980 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
1983 if(time < redirection_nextthink)
1986 redirection_nextthink = time + 1;
1989 FOR_EACH_REALCLIENT(self)
1991 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
1992 if(redirection_target == "self")
1993 stuffcmd(self, "\ndisconnect; reconnect\n");
1995 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
1999 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2001 if(time > redirection_timeout || clients_found == 0)
2002 localcmd("\nwait; wait; wait; quit\n");