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;
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));
70 while(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures()))
75 if(!DoNextMapOverride())
81 float world_already_spawned;
82 void worldspawn (void)
84 float globhandle, i, n;
86 dprint_load(); // load dprint status from cvar
88 if(world_already_spawned)
89 error("world already spawned - you may have EXACTLY ONE worldspawn!");
90 world_already_spawned = TRUE;
92 sv_cheats = cvar("sv_cheats");
95 TODO sound pack system
96 // initialize sound pack system
97 soundpack = cvar_string("g_soundpack");
99 soundpack = strcat(soundpack, "/");
100 soundpack = strzone(soundpack);
103 // gamemode related things
104 precache_model ("models/misc/chatbubble.spr");
105 precache_model ("models/misc/teambubble.spr");
106 if (cvar("g_runematch"))
108 precache_model ("models/runematch/curse.mdl");
109 precache_model ("models/runematch/rune.mdl");
112 // Precache all player models if desired
113 if (cvar("sv_precacheplayermodels"))
115 globhandle = search_begin("models/player/*.zym", TRUE, FALSE);
116 n = search_getsize(globhandle);
117 for(i = 0; i < n; ++i)
119 //print(search_getfilename(globhandle, i), "\n");
120 precache_model(search_getfilename(globhandle, i));
122 search_end(globhandle);
123 //precache_model("models/player/carni.zym");
124 //precache_model("models/player/crash.zym");
125 //precache_model("models/player/grunt.zym");
126 //precache_model("models/player/headhunter.zym");
127 //precache_model("models/player/insurrectionist.zym");
128 //precache_model("models/player/jeandarc.zym");
129 //precache_model("models/player/lurk.zym");
130 //precache_model("models/player/lycanthrope.zym");
131 //precache_model("models/player/marine.zym");
132 //precache_model("models/player/nexus.zym");
133 //precache_model("models/player/pyria.zym");
134 //precache_model("models/player/shock.zym");
135 //precache_model("models/player/skadi.zym");
136 //precache_model("models/player/specop.zym");
137 //precache_model("models/player/visitant.zym");
142 precache_sound ("misc/footstep01.wav");
143 precache_sound ("misc/footstep02.wav");
144 precache_sound ("misc/footstep03.wav");
145 precache_sound ("misc/footstep04.wav");
146 precache_sound ("misc/footstep05.wav");
147 precache_sound ("misc/footstep06.wav");
150 // gore and miscellaneous sounds
151 //precache_sound ("misc/h2ohit.wav");
152 precache_model ("models/gibs/bloodyskull.md3");
153 precache_model ("models/gibs/chunk.mdl");
154 precache_model ("models/gibs/eye.md3");
155 precache_model ("models/gibs/gib1.md3");
156 precache_model ("models/gibs/gib1.mdl");
157 precache_model ("models/gibs/gib2.mdl");
158 precache_model ("models/gibs/gib3.mdl");
159 precache_model ("models/gibs/gib5.md3");
160 precache_model ("models/hook.md3");
161 precache_sound ("misc/armorimpact.wav");
162 precache_sound ("misc/bodyimpact1.wav");
163 precache_sound ("misc/bodyimpact2.wav");
164 precache_sound ("misc/gib.wav");
165 precache_sound ("misc/gib_splat01.wav");
166 precache_sound ("misc/gib_splat02.wav");
167 precache_sound ("misc/gib_splat03.wav");
168 precache_sound ("misc/gib_splat04.wav");
169 precache_sound ("misc/hit.wav");
170 precache_sound ("misc/hitground1.wav");
171 precache_sound ("misc/hitground2.wav");
172 precache_sound ("misc/hitground3.wav");
173 precache_sound ("misc/hitground4.wav");
174 precache_sound ("misc/null.wav");
175 precache_sound ("misc/spawn.wav");
176 precache_sound ("misc/talk.wav");
177 precache_sound ("misc/teleport.wav");
178 precache_sound ("player/lava.wav");
179 precache_sound ("player/slime.wav");
181 // announcer sounds - male
182 //precache_sound ("announcer/male/electrobitch.wav");
183 precache_sound ("announcer/male/03kills.wav");
184 precache_sound ("announcer/male/05kills.wav");
185 precache_sound ("announcer/male/10kills.wav");
186 precache_sound ("announcer/male/15kills.wav");
187 precache_sound ("announcer/male/20kills.wav");
188 precache_sound ("announcer/male/25kills.wav");
189 precache_sound ("announcer/male/30kills.wav");
190 precache_sound ("announcer/male/botlike.wav");
191 precache_sound ("announcer/male/yoda.wav");
193 // announcer sounds - robotic
194 precache_sound ("announcer/robotic/1fragleft.wav");
195 precache_sound ("announcer/robotic/1minuteremains.wav");
196 precache_sound ("announcer/robotic/2fragsleft.wav");
197 precache_sound ("announcer/robotic/3fragsleft.wav");
200 precache_sound ("announcer/robotic/lastsecond.wav");
201 precache_sound ("announcer/robotic/narrowly.wav");
202 precache_sound ("announcer/robotic/1.wav");
203 precache_sound ("announcer/robotic/2.wav");
204 precache_sound ("announcer/robotic/3.wav");
205 precache_sound ("announcer/robotic/4.wav");
206 precache_sound ("announcer/robotic/5.wav");
207 precache_sound ("announcer/robotic/6.wav");
208 precache_sound ("announcer/robotic/7.wav");
209 precache_sound ("announcer/robotic/8.wav");
210 precache_sound ("announcer/robotic/9.wav");
211 precache_sound ("announcer/robotic/10.wav");
214 // common weapon precaches
215 precache_sound ("weapons/weapon_switch.wav");
216 precache_sound ("weapons/weaponpickup.wav");
217 if (g_grappling_hook)
219 precache_sound ("weapons/hook_fire.wav"); // hook
220 precache_sound ("weapons/hook_impact.wav"); // hook
223 if (cvar("sv_precacheweapons") || g_nixnex)
225 //precache weapon models/sounds
228 while (wep <= WEP_LAST)
230 weapon_action(wep, WR_PRECACHE);
235 // plays music for the level if there is any
238 precache_sound (self.noise);
239 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
245 // 1 FLICKER (first variety)
246 lightstyle(1, "mmnmmommommnonmmonqnmmo");
248 // 2 SLOW STRONG PULSE
249 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
251 // 3 CANDLE (first variety)
252 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
255 lightstyle(4, "mamamamamama");
258 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
260 // 6 FLICKER (second variety)
261 lightstyle(6, "nmonqnmomnmomomno");
263 // 7 CANDLE (second variety)
264 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
266 // 8 CANDLE (third variety)
267 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
269 // 9 SLOW STROBE (fourth variety)
270 lightstyle(9, "aaaaaaaazzzzzzzz");
272 // 10 FLUORESCENT FLICKER
273 lightstyle(10, "mmamammmmammamamaaamammma");
275 // 11 SLOW PULSE NOT FADE TO BLACK
276 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
278 // styles 32-62 are assigned by the light program for switchable lights
284 lms_lowest_lives = 0;
289 bot_waypoints_for_items = cvar("g_waypoints_for_items");
290 if(bot_waypoints_for_items == 1)
291 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
292 bot_waypoints_for_items = 0;
294 if(cvar("g_campaign"))
299 WaypointSprite_Init();
301 //if (cvar("g_domination"))
305 head = nextent(world);
310 head = nextent(head);
313 GameLogInit(); // prepare everything
314 if(cvar("sv_eventlog"))
317 GameLogEcho(":logversion:2", FALSE);
318 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
319 s = strcat(s, ftos(random()));
320 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
321 s = ":gameinfo:mutators:LIST";
323 s = strcat(s, ":grappling_hook");
324 if(!cvar("g_use_ammunition"))
325 s = strcat(s, ":no_use_ammunition");
326 if(!cvar("g_pickup_items"))
327 s = strcat(s, ":no_pickup_items");
329 s = strcat(s, ":instagib");
331 s = strcat(s, ":rockerarena");
333 s = strcat(s, ":nixnex");
335 s = strcat(s, ":vampire");
336 if(g_laserguided_missile)
337 s = strcat(s, ":laserguided_missile");
339 s = strcat(s, ":norecoil");
341 s = strcat(s, ":midair");
343 s = strcat(s, ":minstagib");
344 GameLogEcho(s, FALSE);
345 GameLogEcho(":gameinfo:end", FALSE);
348 cvar_set("nextmap", "");
352 if(cvar("g_campaign"))
363 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures());
369 //makestatic (self); // Who the f___ did that?
373 float( string pFilename ) TryFile =
376 dprint("TryFile(\"", pFilename, "\")\n");
377 lHandle = fopen( pFilename, FILE_READ );
378 if( lHandle != -1 ) {
388 if (game == GAME_DEATHMATCH)
390 else if (game == GAME_TEAM_DEATHMATCH)
392 else if (game == GAME_DOMINATION)
394 else if (game == GAME_CTF)
396 else if (game == GAME_RUNEMATCH)
398 else if (game == GAME_LMS)
400 else if (game == GAME_KEYHUNT)
402 else if (game == GAME_ONSLAUGHT)
404 else if (game == GAME_ASSAULT)
409 float IsSameGametype(string mapcfgname)
412 return TRUE; // can't change game type by map name here
416 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
422 string getmapname_stored;
428 if(getmapname_stored == "")
429 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
430 return getmapname_stored;
434 float Map_Count, Map_Current;
435 string Map_Current_Name;
437 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
438 float GetMaplistPosition()
444 idx = cvar("g_maplist_index");
451 for(pos = 0; pos < Map_Count; ++pos)
455 // resume normal maplist rotation if current map is not in g_maplist
459 float MapHasRightSize(string map)
461 // open map size restriction file
463 dprint("opensize "); dprint(map);
464 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
467 float mapmin, mapmax;
469 mapmin = stof(fgets(fh));
470 mapmax = stof(fgets(fh));
472 if(player_count < mapmin)
474 dprint("not enough\n");
477 if(player_count > mapmax)
479 dprint("too many\n");
482 dprint("right size\n");
485 dprint(": not found\n");
491 string Map_Filename(float position)
494 return strcat("maps/", argv(position), ".mapcfg");
498 string strwords(string s, float w)
501 for(endpos = 0; w && endpos >= 0; --w)
502 endpos = strstrofs(s, " ", endpos + 1);
506 return substring(s, 0, endpos);
509 float strhasword(string s, string w)
511 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
514 void Map_MarkAsRecent(string m)
516 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
519 float Map_IsRecent(string m)
521 return strhasword(cvar_string("g_maplist_mostrecent"), m);
524 float(float position, float pass) Map_Check =
528 map_next = argv(position);
531 if(map_next == Map_Current_Name) // same map again in first pass?
533 if(Map_IsRecent(map_next))
537 if(MapInfo_CheckMap(argv(position)))
539 filename = Map_Filename(position);
540 if(TryFile(filename))
545 if(MapHasRightSize(argv(position)))
550 dprint( "Couldn't find '", filename, "'..\n" );
555 void(string nextmapname) Map_Goto_SetStr =
557 if(getmapname_stored != "")
558 strunzone(getmapname_stored);
559 if(nextmapname == "")
560 getmapname_stored = "";
562 getmapname_stored = strzone(nextmapname);
565 void(float position) Map_Goto_SetFloat =
567 cvar_set("g_maplist_index", ftos(position));
568 Map_Goto_SetStr(argv(position));
571 void() GameResetCfg =
574 // settings persist, except...
575 if(cvar("g_campaign"))
576 localcmd("\nexec mutator_reset.cfg\n");
577 localcmd("\nsettemp_restore\n");
579 // if an exit cfg is defined by exiting map, exec it.
581 exit_cfg = cvar_string("exit_cfg");
583 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
585 localcmd("exec game_reset.cfg\n");
593 Map_MarkAsRecent(getmapname_stored);
596 MapInfo_LoadMap(getmapname_stored);
598 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
602 // return codes of map selectors:
603 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
604 // -2 = permanent failure
605 float() MaplistMethod_Iterate = // usual method
609 for(pass = 1; pass <= 2; ++pass)
611 for(i = 1; i < Map_Count; ++i)
614 mapindex = math_mod(i + Map_Current, Map_Count);
615 if(Map_Check(mapindex, pass))
622 float() MaplistMethod_Repeat = // fallback method
624 if(Map_Check(Map_Current, 2))
629 float() MaplistMethod_Random = // random map selection
635 for(i = 0; i <= imax; ++i)
638 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
639 if(Map_Check(mapindex, 1))
645 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
646 // the exponent sets a bias on the map selection:
647 // the higher the exponent, the less likely "shortly repeated" same maps are
649 float i, j, imax, insertpos;
654 return 0; // only one map, then always play this one
656 for(i = 0; i <= imax; ++i)
660 // now reinsert this at another position
661 insertpos = pow(random(), 1 / exponent); // ]0, 1]
662 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
663 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
664 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
666 // insert the current map there
669 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
670 newlist = strcat(newlist, " ", argv(j));
671 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
672 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
673 newlist = strcat(newlist, " ", argv(j));
674 newlist = substring(newlist, 1, strlen(newlist) - 1);
676 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
677 newlist = strcat(newlist, "'", argv(j), "'");
678 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
679 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
680 newlist = strcat(newlist, "'", argv(j), "'");
682 cvar_set("g_maplist", newlist);
683 Map_Count = tokenize(newlist);
685 // NOTE: the selected map has just been inserted at (insertpos-1)th position
686 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
687 if(Map_Check(Map_Current, 1))
693 void() Maplist_Init =
696 temp = cvar_string("g_maplist");
697 Map_Count = tokenize(temp);
700 bprint( "Maplist is empty! Resetting it to default map list.\n" );
702 cvar_set("g_maplist", temp = MapInfo_ListAllowedMaps());
703 localcmd("\nmenu_cmd sync\n");
705 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
707 Map_Count = tokenize(temp);
710 error("empty maplist, cannot select a new map");
711 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
713 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
714 // this may or may not be correct, but who cares, in the worst case a map
715 // isn't chosen in the first pass that should have been
718 string() GetNextMap =
726 if(cvar("g_maplist_shuffle") > 0)
727 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
730 if(cvar("g_maplist_selectrandom"))
731 nextMap = MaplistMethod_Random();
734 nextMap = MaplistMethod_Iterate();
737 nextMap = MaplistMethod_Repeat();
741 Map_Goto_SetFloat(nextMap);
742 return getmapname_stored;
748 float() DoNextMapOverride =
752 if(cvar("g_campaign"))
754 CampaignPostIntermission();
755 alreadychangedlevel = TRUE;
758 if(cvar("quit_when_empty"))
760 if(player_count <= currentbots)
763 alreadychangedlevel = TRUE;
767 if(cvar_string("quit_and_redirect") != "")
769 redirection_target = strzone(cvar_string("quit_and_redirect"));
770 alreadychangedlevel = TRUE;
773 if (cvar("samelevel")) // if samelevel is set, stay on same level
775 // 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)
776 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
777 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
778 localcmd("restart\n");
779 //changelevel (mapname);
780 alreadychangedlevel = TRUE;
783 if(cvar_string("nextmap") != "")
785 if(MapInfo_CheckMap(cvar_string("nextmap")))
787 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
790 Map_Goto_SetStr(cvar_string("nextmap"));
792 alreadychangedlevel = TRUE;
795 if(cvar("lastlevel"))
798 localcmd("set lastlevel 0\ntogglemenu\n");
799 alreadychangedlevel = TRUE;
807 //local string nextmap;
808 //local float n, nummaps;
810 if (alreadychangedlevel)
812 alreadychangedlevel = TRUE;
818 for(allowReset = 1; allowReset >= 0; --allowReset)
820 nextMap = GetNextMap();
826 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
828 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
829 localcmd("\nmenu_cmd sync\n");
831 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
836 error("Everything is broken - not even the default map list works. Please report this to the developers.");
848 When the player presses attack or jump, change to the next level
851 .float autoscreenshot;
852 void() MapVote_Start;
853 void() MapVote_Think;
854 float mapvote_initialized;
855 void() IntermissionThink =
857 FixIntermissionClient(self);
859 if(cvar("sv_autoscreenshot"))
860 if(self.autoscreenshot > 0)
861 if(time > self.autoscreenshot)
863 self.autoscreenshot = -1;
864 if(clienttype(self) == CLIENTTYPE_REAL)
865 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
869 if (time < intermission_exittime)
872 if(!mapvote_initialized)
873 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
883 Returns the entity to view from
887 entity() FindIntermission =
892 // look for info_intermission first
893 spot = find (world, classname, "info_intermission");
895 { // pick a random one
899 spot = find (spot, classname, "info_intermission");
901 spot = find (spot, classname, "info_intermission");
907 // then look for the start position
908 spot = find (world, classname, "info_player_start");
912 // testinfo_player_start is only found in regioned levels
913 spot = find (world, classname, "testplayerstart");
917 // then look for the start position
918 spot = find (world, classname, "info_player_deathmatch");
922 //objerror ("FindIntermission: no spot");
928 ===============================================================================
932 ===============================================================================
935 void(float final) DumpStats =
939 local float to_console;
940 local float to_eventlog;
943 to_console = cvar("sv_logscores_console");
944 to_eventlog = cvar("sv_eventlog");
945 to_file = cvar("sv_logscores_file");
949 to_console = TRUE; // always print printstats replies
950 to_eventlog = FALSE; // but never print them to the event log
954 if(cvar("sv_eventlog_console"))
955 to_console = FALSE; // otherwise we get the output twice
961 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
964 ServerConsoleEcho(s, FALSE);
966 GameLogEcho(s, FALSE);
969 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
973 fputs(file, strcat(s, "\n"));
976 FOR_EACH_CLIENT(other)
978 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
980 s = strcat(":player:", ftos(other.frags), ":");
981 s = strcat(s, ftos(other.deaths), ":");
982 s = strcat(s, ftos(rint(time - other.jointime)), ":");
983 s = strcat(s, ftos(other.team), ":");
986 ServerConsoleEcho(strcat(s, other.netname), TRUE);
988 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
990 fputs(file, strcat(s, other.netname, "\n"));
995 ServerConsoleEcho(":end", FALSE);
997 GameLogEcho(":end", FALSE);
1000 fputs(file, ":end\n");
1005 void FixIntermissionClient(entity e)
1007 if(!e.autoscreenshot) // initial call
1009 e.angles = e.v_angle;
1010 e.angles_x = -e.angles_x;
1011 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1013 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1014 e.solid = SOLID_NOT;
1015 e.movetype = MOVETYPE_NONE;
1016 e.takedamage = DAMAGE_NO;
1018 e.weaponentity.effects = EF_NODRAW;
1019 stuffcmd(e, "\nscr_printspeed 1000000\n");
1020 if(clienttype(e) == CLIENTTYPE_REAL)
1023 WriteByte(MSG_ONE, SVC_INTERMISSION);
1027 //e.velocity = '0 0 0';
1028 //e.fixangle = TRUE;
1030 // TODO halt weapon animation
1035 go to the next level for deathmatch
1036 only called if a time or frag limit has expired
1040 float minTotalFrags;
1041 float maxTotalFrags;
1047 intermission_running = 1;
1049 // enforce a wait time before allowing changelevel
1050 if(player_count > 0)
1051 intermission_exittime = time + cvar("sv_mapchange_delay");
1053 intermission_exittime = -1;
1055 WriteByte (MSG_ALL, SVC_CDTRACK);
1056 WriteByte (MSG_ALL, 3);
1057 WriteByte (MSG_ALL, 3);
1059 //pos = FindIntermission ();
1065 if(cvar("sv_eventlog"))
1066 GameLogEcho(":gameover", FALSE);
1070 FOR_EACH_CLIENT(other)
1072 FixIntermissionClient(other);
1075 bprint(other.netname, " ^7wins.\n");
1080 FOR_EACH_PLAYER(other)
1082 if(maxTotalFrags < other.totalfrags)
1083 maxTotalFrags = other.totalfrags;
1084 if(minTotalFrags > other.totalfrags)
1085 minTotalFrags = other.totalfrags;
1090 FOR_EACH_PLAYER(other)
1092 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1093 f = bound(0, other.play_time / max(time, 1), 1);
1094 // store some statistics?
1098 if(cvar("g_campaign"))
1099 CampaignPreIntermission();
1101 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1108 Exit deathmatch games upon conditions
1111 void() CheckRules_Player =
1113 if (gameover) // someone else quit the game already
1116 if(self.deadflag == DEAD_NO)
1117 self.play_time += frametime;
1119 // fixme: don't check players; instead check dom_team and ctf_team entities
1120 // (div0: and that in CheckRules_World please)
1123 float checkrules_oneminutewarning;
1124 float checkrules_leaderfrags;
1125 float tdm_max_score, tdm_old_score;
1127 float checkrules_equality;
1128 float checkrules_overtimewarning;
1129 float checkrules_overtimeend;
1131 void() InitiateOvertime =
1133 if(!checkrules_overtimeend)
1134 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1137 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1138 float WINNING_YES = 1; // winner found
1139 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1140 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1142 float(float fraglimitreached, float equality) GetWinningCode =
1145 if(fraglimitreached)
1146 return WINNING_STARTOVERTIME;
1148 return WINNING_NEVER;
1150 if(fraglimitreached)
1156 // set the .winning flag for exactly those players with a given field value
1157 void(.float field, float value) SetWinners =
1160 FOR_EACH_PLAYER(head)
1161 head.winning = (head.field == value);
1164 // set the .winning flag for those players with a given field value
1165 void(.float field, float value) AddWinners =
1168 FOR_EACH_PLAYER(head)
1169 if(head.field == value)
1173 // clear the .winning flags
1174 void(void) ClearWinners =
1177 FOR_EACH_PLAYER(head)
1181 // Onslaught winning condition:
1182 // game terminates if only one team has a working generator (or none)
1183 float() WinningCondition_Onslaught =
1186 local float t1, t2, t3, t4;
1187 // first check if the game has ended
1188 t1 = t2 = t3 = t4 = 0;
1189 head = find(world, classname, "onslaught_generator");
1192 if (head.health > 0)
1194 if (head.team == COLOR_TEAM1) t1 = 1;
1195 if (head.team == COLOR_TEAM2) t2 = 1;
1196 if (head.team == COLOR_TEAM3) t3 = 1;
1197 if (head.team == COLOR_TEAM4) t4 = 1;
1199 head = find(head, classname, "onslaught_generator");
1201 if (t1 + t2 + t3 + t4 < 2)
1203 // game over, only one team remains (or none)
1205 if (t1) SetWinners(team, COLOR_TEAM1);
1206 if (t2) SetWinners(team, COLOR_TEAM2);
1207 if (t3) SetWinners(team, COLOR_TEAM3);
1208 if (t4) SetWinners(team, COLOR_TEAM4);
1209 dprint("Have a winner, ending game.\n");
1213 // Two or more teams remain
1217 float() LMS_NewPlayerLives =
1220 fl = cvar("fraglimit");
1224 // first player has left the game for dying too much? Nobody else can get in.
1225 if(lms_lowest_lives < 1)
1228 if(!cvar("g_lms_join_anytime"))
1229 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1232 return bound(1, lms_lowest_lives, fl);
1235 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1236 // they win. Otherwise the defending team wins once the timelimit passes.
1237 void assault_new_round();
1238 float() WinningCondition_Assault =
1241 status = WINNING_NO;
1243 // as the timelimit has not yet passed just assume the defending team will win
1244 if(assault_attacker_team == COLOR_TEAM1)
1246 SetWinners(team, COLOR_TEAM2);
1250 SetWinners(team, COLOR_TEAM1);
1254 ent = find(world, classname, "target_assault_roundend");
1257 if(ent.winning) // round end has been triggered by attacking team
1259 SetWinners(team, assault_attacker_team);
1260 if(assault_attacker_team == COLOR_TEAM1)
1262 team1_score = team1_score + 50;
1266 team2_score = team2_score + 50;
1269 if(ent.cnt == 1) // this was the second round
1271 status = WINNING_YES;
1275 cvar_set("timelimit", ftos((2*time)/60));
1276 assault_new_round();
1286 // LMS winning condition: game terminates if and only if there's at most one
1287 // one player who's living lives. Top two scores being equal cancels the time
1289 float() WinningCondition_LMS =
1296 have_player = FALSE;
1297 have_players = FALSE;
1298 l = LMS_NewPlayerLives();
1300 head = find(world, classname, "player");
1303 head = find(head, classname, "player");
1305 have_players = TRUE;
1309 // we have at least one player
1312 // two or more active players - continue with the game
1316 // exactly one player?
1319 // but no game has taken place yet
1324 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1325 dprint("Have a winner, ending game.\n");
1332 // nobody is playing at all...
1335 // wait for players...
1339 // SNAFU (maybe a draw game?)
1341 dprint("No players, ending game.\n");
1346 // When we get here, we have at least two players who are actually LIVING,
1347 // or one player who is still waiting for a victim to join the server. Now
1348 // check if the top two players have equal score.
1350 checkrules_leaderfrags = 0;
1351 checkrules_equality = FALSE;
1352 FOR_EACH_PLAYER(head)
1354 if(head.frags > checkrules_leaderfrags)
1356 checkrules_leaderfrags = head.frags;
1357 checkrules_equality = FALSE;
1359 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1360 checkrules_equality = TRUE;
1363 SetWinners(frags, checkrules_leaderfrags);
1365 // The top two players have the same amount of lives? No timelimit then,
1366 // enter overtime...
1368 if(checkrules_equality)
1369 return WINNING_NEVER;
1371 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1375 // DM winning condition: game terminates if a player reached the fraglimit,
1376 // unless the first two players have the same score. The latter case also
1377 // breaks the time limit.
1378 float(float fraglimit) WinningCondition_MaxIndividualScore =
1380 float checkrules_oldleaderfrags;
1383 checkrules_oldleaderfrags = checkrules_leaderfrags;
1384 checkrules_leaderfrags = 0;
1385 checkrules_equality = FALSE;
1386 FOR_EACH_PLAYER(head)
1388 if(head.frags > checkrules_leaderfrags)
1390 checkrules_leaderfrags = head.frags;
1391 checkrules_equality = FALSE;
1393 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1394 checkrules_equality = TRUE;
1397 if(checkrules_leaderfrags > 0)
1398 SetWinners(frags, checkrules_leaderfrags);
1402 if (!cvar("g_runematch"))
1403 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1405 if (checkrules_leaderfrags == fraglimit - 1)
1406 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1407 else if (checkrules_leaderfrags == fraglimit - 2)
1408 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1409 else if (checkrules_leaderfrags == fraglimit - 3)
1410 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1413 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1416 float(float fraglimit) WinningConditionBase_Teamplay =
1418 tdm_old_score = tdm_max_score;
1419 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1421 checkrules_equality =
1426 (team1_score == tdm_max_score)
1427 + (team2_score == tdm_max_score)
1428 + (team3_score == tdm_max_score)
1429 + (team4_score == tdm_max_score)
1433 if(tdm_max_score > 0)
1435 if(team1_score == tdm_max_score)
1436 AddWinners(team, COLOR_TEAM1);
1437 if(team2_score == tdm_max_score)
1438 AddWinners(team, COLOR_TEAM2);
1439 if(team3_score == tdm_max_score)
1440 AddWinners(team, COLOR_TEAM3);
1441 if(team4_score == tdm_max_score)
1442 AddWinners(team, COLOR_TEAM4);
1445 if(!cvar("g_runematch") && !cvar("g_domination"))
1446 if(tdm_max_score != tdm_old_score)
1448 if(tdm_max_score == fraglimit - 1)
1449 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1450 else if(tdm_max_score == fraglimit - 2)
1451 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1452 else if(tdm_max_score == fraglimit - 3)
1453 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1456 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1459 // TDM winning condition: game terminates if a team's score sum reached the
1460 // fraglimit, unless the first two teams have the same total score. The latter
1461 // case also breaks the time limit.
1462 float(float fraglimit) WinningCondition_MaxTeamSum =
1466 team1_score = team2_score = team3_score = team4_score = 0;
1468 FOR_EACH_PLAYER(head)
1470 if(head.team == COLOR_TEAM1)
1471 team1_score += head.frags;
1472 else if(head.team == COLOR_TEAM2)
1473 team2_score += head.frags;
1474 else if(head.team == COLOR_TEAM3)
1475 team3_score += head.frags;
1476 else if(head.team == COLOR_TEAM4)
1477 team4_score += head.frags;
1480 return WinningConditionBase_Teamplay(fraglimit);
1483 // DOM/CTF winning condition: game terminates if the max of a team's players'
1484 // score reached the fraglimit, unless the first two teams have the same
1485 // maximum score. The latter case also breaks the time limit.
1486 float(float fraglimit) WinningCondition_MaxTeamMax =
1490 team1_score = team2_score = team3_score = team4_score = 0;
1492 FOR_EACH_PLAYER(head)
1494 if(head.team == COLOR_TEAM1)
1496 if(head.frags > team1_score)
1497 team1_score = head.frags;
1499 else if(head.team == COLOR_TEAM2)
1501 if(head.frags > team2_score)
1502 team2_score = head.frags;
1504 else if(head.team == COLOR_TEAM3)
1506 if(head.frags > team3_score)
1507 team3_score = head.frags;
1509 else if(head.team == COLOR_TEAM4)
1511 if(head.frags > team4_score)
1512 team4_score = head.frags;
1516 return WinningConditionBase_Teamplay(fraglimit);
1519 void print_to(entity e, string s)
1522 sprint(e, strcat(s, "\n"));
1524 ServerConsoleEcho(s, TRUE);
1527 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1537 FOR_EACH_PLAYER(head)
1539 if(!whichteam || head.team == whichteam)
1543 print_to(e, strcat(" ", colorcode, name, ":"));
1545 fragtotal = fragtotal + head.frags;
1546 s = ftos(head.frags);
1547 s = strcat(s, "/", ftos(head.deaths));
1548 s = strcat(s, " @ ", ftos(head.ping));
1549 if(clienttype(head) == CLIENTTYPE_BOT)
1550 s = strcat(s, "botms");
1552 s = strcat(s, "ms");
1553 v = PlayerValue(head);
1555 s = strcat(s, " / ", ftos(v));
1556 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1559 if(whichteam && found)
1561 s = ftos(fragtotal);
1562 s = strcat(s, " / ", ftos(teamvalue));
1563 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1567 void PrintScoreboard(entity e)
1569 print_to(e, strcat("Time: ", ftos(time / 60)));
1570 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1571 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1572 print_to(e, "Scoreboard:");
1575 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1576 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1577 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1578 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1582 PrintScoreboardFor(e, "", "^7", 0);
1587 void ShuffleMaplist()
1595 result = cvar_string("g_maplist");
1596 litems = tokenize(result);
1598 for(start = 0; start < litems - 1; ++start)
1602 // select a random item
1603 selected = ceil(random() * (litems - start) + start) - 1;
1605 // shift this item to the place start
1607 for(i = 0; i < start; ++i)
1608 result = strcat(result, " ", argv(i));
1609 result = strcat(result, " ", argv(selected));
1610 for(i = start; i < litems; ++i)
1612 result = strcat(result, " ", argv(i));
1613 result = substring(result, 1, strlen(result) - 1);
1615 for(i = 0; i < start; ++i)
1616 result = strcat(result, "'", argv(i), "'");
1617 result = strcat(result, "'", argv(selected), "'");
1618 for(i = start; i < litems; ++i)
1620 result = strcat(result, "'", argv(i), "'");
1623 litems = tokenize(result);
1625 //dprint(result, "\n");
1628 cvar_set("g_maplist", result);
1635 Exit deathmatch games upon conditions
1638 void() CheckRules_World =
1641 local float timelimit;
1642 local float fraglimit;
1650 MapVote_Think should now do that part
1651 if (intermission_running)
1652 if (time >= intermission_exittime + 60)
1654 if(!DoNextMapOverride())
1660 if (gameover) // someone else quit the game already
1662 if(player_count == 0) // Nobody there? Then let's go to the next map
1664 // this will actually check the player count in the next frame
1665 // again, but this shouldn't hurt
1669 timelimit = cvar("timelimit") * 60;
1670 fraglimit = cvar("fraglimit");
1672 if(checkrules_overtimeend)
1674 if(!checkrules_overtimewarning)
1676 checkrules_overtimewarning = TRUE;
1677 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1678 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1683 if (timelimit && time >= timelimit)
1687 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1693 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1695 checkrules_oneminutewarning = TRUE;
1696 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1699 status = WINNING_NO;
1702 status = WinningCondition_Assault();
1706 status = WinningCondition_LMS();
1708 else if (g_onslaught)
1710 status = WinningCondition_Onslaught();
1716 if(g_tdm || cvar("g_runematch") || g_ctf || cvar("g_domination") || g_keyhunt)
1717 status = WinningCondition_MaxTeamSum(fraglimit);
1719 // status = WinningCondition_MaxTeamMax(fraglimit);
1722 dprint("div0: How can this happen?\n");
1723 status = WinningCondition_MaxTeamMax(fraglimit);
1727 status = WinningCondition_MaxIndividualScore(fraglimit);
1730 if(status == WINNING_STARTOVERTIME)
1732 status = WINNING_NEVER;
1736 if(status == WINNING_NEVER)
1737 // equality cases! Nobody wins if the overtime ends in a draw.
1740 if(checkrules_overtimeend)
1741 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1742 status = WINNING_YES;
1744 if(status == WINNING_YES)
1748 float randsel_value;
1749 float randsel_priority;
1750 float randsel_count;
1754 randsel_priority = -1;
1757 void RandSel_Add(float priority, float value)
1759 if(priority > randsel_priority)
1761 randsel_priority = priority;
1762 randsel_value = value;
1765 else if(priority == randsel_priority)
1768 if(ceil(random() * randsel_count) == 1)
1769 randsel_value = value;
1773 float mapvote_nextthink;
1774 float mapvote_initialized;
1775 float mapvote_keeptwotime;
1776 float mapvote_timeout;
1777 string mapvote_message;
1779 #define MAPVOTE_COUNT 10
1780 float mapvote_count;
1781 string mapvote_maps[MAPVOTE_COUNT];
1782 float mapvote_maps_suggested[MAPVOTE_COUNT];
1783 string mapvote_suggestions[MAPVOTE_COUNT];
1784 float mapvote_suggestion_ptr;
1785 float mapvote_maxlen;
1786 float mapvote_voters;
1787 float mapvote_votes[MAPVOTE_COUNT];
1791 void MapVote_ClearAllVotes()
1793 FOR_EACH_CLIENT(other)
1797 string MapVote_Suggest(string m)
1801 return "That's not how to use this command.";
1802 if(!cvar("g_maplist_votable_suggestions"))
1803 return "Suggestions are not accepted on this server.";
1804 if(mapvote_initialized)
1805 return "Can't suggest - voting is already in progress!";
1807 m = MapInfo_FixName(m);
1809 return "The map you suggested is not available on this server.";
1811 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1812 if(!IsSameGametype(m))
1813 return "This server does not allow changing the game type by map suggestions.";
1814 if(!cvar("g_maplist_votable_override_mostrecent"))
1816 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1819 if(!MapInfo_CheckMap(m))
1820 return "The map you suggested does not support the current game mode.";
1822 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1823 return "The map you suggested is not available on this server.";
1825 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1826 if(mapvote_suggestions[i] == m)
1827 return "This map was already suggested.";
1828 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1830 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1834 i = mapvote_suggestion_ptr;
1835 mapvote_suggestion_ptr += 1;
1837 if(mapvote_suggestions[i] != "")
1838 strunzone(mapvote_suggestions[i]);
1839 mapvote_suggestions[i] = strzone(m);
1840 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1841 return "Suggestion accepted.";
1844 void MapVote_AddVotable(string nextMap, float isSuggestion)
1849 for(j = 0; j < mapvote_count; ++j)
1850 if(mapvote_maps[j] == nextMap)
1852 if(strlen(nextMap) > mapvote_maxlen)
1853 mapvote_maxlen = strlen(nextMap);
1854 mapvote_maps[mapvote_count] = strzone(nextMap);
1855 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1864 MapVote_ClearAllVotes();
1866 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1867 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1870 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1871 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1873 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1874 MapVote_AddVotable(GetNextMap(), FALSE);
1876 if(mapvote_count == 0)
1878 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1880 cvar_set("g_maplist", MapInfo_ListAllowedMaps());
1881 localcmd("\nmenu_cmd sync\n");
1883 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1885 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1886 MapVote_AddVotable(GetNextMap(), FALSE);
1889 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1891 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1892 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1893 if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1894 mapvote_keeptwotime = 0;
1895 mapvote_message = "Choose a map and press its key!";
1897 float MapVote_Finished(float mappos)
1902 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1903 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1904 for(i = 0; i < mapvote_count; ++i)
1906 if(mapvote_maps[i] != "")
1908 result = strcat(result, ":", mapvote_maps[i]);
1909 result = strcat(result, ":", ftos(mapvote_votes[i]));
1911 GameLogEcho(result, FALSE);
1912 if(mapvote_maps_suggested[mappos])
1913 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1915 FOR_EACH_REALCLIENT(other)
1916 FixClientCvars(other);
1918 Map_Goto_SetStr(mapvote_maps[mappos]);
1920 alreadychangedlevel = TRUE;
1923 void MapVote_CheckRules_1()
1927 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1929 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1930 mapvote_votes[i] = 0;
1934 FOR_EACH_REALCLIENT(other)
1939 i = other.mapvote - 1;
1940 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1941 mapvote_votes[i] = mapvote_votes[i] + 1;
1946 float MapVote_CheckRules_2()
1949 float firstPlace, secondPlace;
1950 float firstPlaceVotes, secondPlaceVotes;
1954 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1955 RandSel_Add(mapvote_votes[i], i);
1956 firstPlace = randsel_value;
1957 firstPlaceVotes = randsel_priority;
1958 //dprint("First place: ", ftos(firstPlace), "\n");
1959 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1962 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1964 RandSel_Add(mapvote_votes[i], i);
1965 secondPlace = randsel_value;
1966 secondPlaceVotes = randsel_priority;
1967 //dprint("Second place: ", ftos(secondPlace), "\n");
1968 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1970 if(firstPlace == -1)
1971 error("No first place in map vote... WTF?");
1973 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1974 return MapVote_Finished(firstPlace);
1976 if(mapvote_keeptwotime)
1977 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1979 mapvote_message = "Now decide between the TOP TWO!";
1980 mapvote_keeptwotime = 0;
1981 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1982 result = strcat(result, ":", ftos(firstPlaceVotes));
1983 result = strcat(result, ":", mapvote_maps[secondPlace]);
1984 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1985 for(i = 0; i < mapvote_count; ++i)
1987 if(i != secondPlace)
1988 if(mapvote_maps[i] != "")
1990 result = strcat(result, ":", mapvote_maps[i]);
1991 result = strcat(result, ":", ftos(mapvote_votes[i]));
1992 strunzone(mapvote_maps[i]);
1993 mapvote_maps[i] = "";
1995 GameLogEcho(result, FALSE);
2007 keeptwo = mapvote_keeptwotime;
2008 MapVote_CheckRules_1(); // count
2009 if(MapVote_CheckRules_2()) // decide
2012 FOR_EACH_REALCLIENT(other)
2014 // hide scoreboard again
2015 if(other.health != 2342)
2017 other.health = 2342;
2019 if(clienttype(other) == CLIENTTYPE_REAL)
2021 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");
2023 WriteByte(MSG_ONE, SVC_FINALE);
2024 WriteString(MSG_ONE, "");
2026 for(i = 0; i < mapvote_count; ++i)
2027 if(mapvote_maps[i] != "")
2029 tmp = mapvote_maps[i];
2030 sprint(other, strcat("map voting: type ^1impulse ", ftos(i+1), "^7 to vote for ", tmp, "\n"));
2036 // notify about keep-two
2037 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2038 play2(other, "misc/invshot.wav");
2040 // clear possibly invalid votes
2041 if(mapvote_maps[other.mapvote - 1] == "")
2043 // use impulses as new vote
2044 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2045 if(mapvote_maps[other.impulse - 1] != "")
2046 other.mapvote = other.impulse;
2050 MapVote_CheckRules_1(); // just count
2052 FOR_EACH_REALCLIENT(other)
2054 // display voting screen
2055 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2056 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2057 msgstr = strcat(msgstr, mapvote_message);
2058 msgstr = strcat(msgstr, "\n\n");
2059 for(i = 0; i < mapvote_count; ++i)
2060 if(mapvote_maps[i] == "")
2061 msgstr = strcat(msgstr, "\n");
2064 tmp = mapvote_maps[i];
2065 tmp = strpad(mapvote_maxlen, tmp);
2066 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
2067 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2068 if(mapvote_votes[i] != 1)
2069 tmp = strcat(tmp, "s");
2070 tmp = strcat(tmp, ")");
2071 tmp = strpad(mapvote_maxlen + 15, tmp);
2072 if(other.mapvote == i + 1)
2073 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2075 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2077 i = ceil(mapvote_timeout - time);
2078 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
2080 msgstr = strcat(msgstr, "s");
2081 msgstr = strcat(msgstr, " left");
2083 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2086 void MapVote_Start()
2092 MapInfo_Enumerate();
2093 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures()))
2097 void MapVote_Think()
2102 if(alreadychangedlevel)
2105 if(time < mapvote_nextthink)
2109 mapvote_nextthink = time + 0.5;
2111 if(!mapvote_initialized)
2113 mapvote_initialized = TRUE;
2114 if(DoNextMapOverride())
2116 if(!cvar("g_maplist_votable") || player_count <= 0)
2127 string GotoMap(string m)
2130 if(!MapInfo_CheckMap(m))
2132 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2134 return "The map you chose is not available on this server.";
2135 cvar_set("nextmap", m);
2136 cvar_set("timelimit", "-1");
2137 if(mapvote_initialized || alreadychangedlevel)
2139 if(DoNextMapOverride())
2140 return "Map switch initiated.";
2142 return "Hm... no. For some reason I like THIS map more.";
2145 return "Map switch will happen after scoreboard.";
2151 FOR_EACH_REALCLIENT(self)
2153 if(self.classname == "spectator")
2155 if(self.enemy.hitsound)
2156 play2(self, "misc/hit.wav");
2161 play2(self, "misc/hit.wav");
2164 FOR_EACH_CLIENT(self)
2165 self.hitsound = FALSE;
2171 * returns TRUE if redirecting
2173 float redirection_timeout;
2174 float redirection_nextthink;
2175 float RedirectionThink()
2177 float clients_found;
2179 if(redirection_target == "")
2182 if(!redirection_timeout)
2184 cvar_set("sv_public", "-2");
2185 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2186 if(redirection_target == "self")
2187 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2189 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2192 if(time < redirection_nextthink)
2195 redirection_nextthink = time + 1;
2198 FOR_EACH_REALCLIENT(self)
2200 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2201 if(redirection_target == "self")
2202 stuffcmd(self, "\ndisconnect; reconnect\n");
2204 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2208 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2210 if(time > redirection_timeout || clients_found == 0)
2211 localcmd("\nwait; wait; wait; quit\n");