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 float globhandle, i, n;
78 dprint_load(); // load dprint status from cvar
80 if(world_already_spawned)
81 error("world already spawned - you may have EXACTLY ONE worldspawn!");
82 world_already_spawned = TRUE;
84 sv_cheats = cvar("sv_cheats");
87 TODO sound pack system
88 // initialize sound pack system
89 soundpack = cvar_string("g_soundpack");
91 soundpack = strcat(soundpack, "/");
92 soundpack = strzone(soundpack);
95 // gamemode related things
96 precache_model ("models/misc/chatbubble.spr");
97 precache_model ("models/misc/teambubble.spr");
98 if (cvar("g_runematch"))
100 precache_model ("models/runematch/curse.mdl");
101 precache_model ("models/runematch/rune.mdl");
104 // Precache all player models if desired
105 if (cvar("sv_precacheplayermodels"))
107 globhandle = search_begin("models/player/*.zym", TRUE, FALSE);
108 n = search_getsize(globhandle);
109 for(i = 0; i < n; ++i)
111 //print(search_getfilename(globhandle, i), "\n");
112 precache_model(search_getfilename(globhandle, i));
114 search_end(globhandle);
115 //precache_model("models/player/carni.zym");
116 //precache_model("models/player/crash.zym");
117 //precache_model("models/player/grunt.zym");
118 //precache_model("models/player/headhunter.zym");
119 //precache_model("models/player/insurrectionist.zym");
120 //precache_model("models/player/jeandarc.zym");
121 //precache_model("models/player/lurk.zym");
122 //precache_model("models/player/lycanthrope.zym");
123 //precache_model("models/player/marine.zym");
124 //precache_model("models/player/nexus.zym");
125 //precache_model("models/player/pyria.zym");
126 //precache_model("models/player/shock.zym");
127 //precache_model("models/player/skadi.zym");
128 //precache_model("models/player/specop.zym");
129 //precache_model("models/player/visitant.zym");
132 if (cvar("g_footsteps"))
134 precache_sound ("misc/footstep01.wav");
135 precache_sound ("misc/footstep02.wav");
136 precache_sound ("misc/footstep03.wav");
137 precache_sound ("misc/footstep04.wav");
138 precache_sound ("misc/footstep05.wav");
139 precache_sound ("misc/footstep06.wav");
142 // gore and miscellaneous sounds
143 //precache_sound ("misc/h2ohit.wav");
144 precache_model ("models/gibs/bloodyskull.md3");
145 precache_model ("models/gibs/chunk.mdl");
146 precache_model ("models/gibs/eye.md3");
147 precache_model ("models/gibs/gib1.md3");
148 precache_model ("models/gibs/gib1.mdl");
149 precache_model ("models/gibs/gib2.mdl");
150 precache_model ("models/gibs/gib3.mdl");
151 precache_model ("models/gibs/gib5.md3");
152 precache_model ("models/hook.md3");
153 precache_sound ("misc/armorimpact.wav");
154 precache_sound ("misc/bodyimpact1.wav");
155 precache_sound ("misc/bodyimpact2.wav");
156 precache_sound ("misc/gib.wav");
157 precache_sound ("misc/gib_splat01.wav");
158 precache_sound ("misc/gib_splat02.wav");
159 precache_sound ("misc/gib_splat03.wav");
160 precache_sound ("misc/gib_splat04.wav");
161 precache_sound ("misc/hit.wav");
162 precache_sound ("misc/hitground1.wav");
163 precache_sound ("misc/hitground2.wav");
164 precache_sound ("misc/hitground3.wav");
165 precache_sound ("misc/hitground4.wav");
166 precache_sound ("misc/null.wav");
167 precache_sound ("misc/spawn.wav");
168 precache_sound ("misc/talk.wav");
169 precache_sound ("misc/teleport.wav");
170 precache_sound ("player/lava.wav");
171 precache_sound ("player/slime.wav");
173 // announcer sounds - male
174 //precache_sound ("announcer/male/electrobitch.wav");
175 precache_sound ("announcer/male/03kills.wav");
176 precache_sound ("announcer/male/05kills.wav");
177 precache_sound ("announcer/male/10kills.wav");
178 precache_sound ("announcer/male/15kills.wav");
179 precache_sound ("announcer/male/20kills.wav");
180 precache_sound ("announcer/male/25kills.wav");
181 precache_sound ("announcer/male/30kills.wav");
182 precache_sound ("announcer/male/botlike.wav");
183 precache_sound ("announcer/male/yoda.wav");
185 // announcer sounds - robotic
186 precache_sound ("announcer/robotic/1fragleft.wav");
187 precache_sound ("announcer/robotic/1minuteremains.wav");
188 precache_sound ("announcer/robotic/2fragsleft.wav");
189 precache_sound ("announcer/robotic/3fragsleft.wav");
190 if (cvar("g_minstagib"))
192 precache_sound ("announcer/robotic/lastsecond.wav");
193 precache_sound ("announcer/robotic/narrowly.wav");
194 precache_sound ("announcer/robotic/1.wav");
195 precache_sound ("announcer/robotic/2.wav");
196 precache_sound ("announcer/robotic/3.wav");
197 precache_sound ("announcer/robotic/4.wav");
198 precache_sound ("announcer/robotic/5.wav");
199 precache_sound ("announcer/robotic/6.wav");
200 precache_sound ("announcer/robotic/7.wav");
201 precache_sound ("announcer/robotic/8.wav");
202 precache_sound ("announcer/robotic/9.wav");
203 precache_sound ("announcer/robotic/10.wav");
206 // common weapon precaches
207 precache_sound ("weapons/weapon_switch.wav");
208 precache_sound ("weapons/weaponpickup.wav");
209 if (cvar("g_grappling_hook"))
211 precache_sound ("weapons/hook_fire.wav"); // hook
212 precache_sound ("weapons/hook_impact.wav"); // hook
215 if (cvar("sv_precacheweapons") || cvar("g_nixnex"))
217 //precache weapon models/sounds
220 while (wep <= WEP_LAST)
222 weapon_action(wep, WR_PRECACHE);
227 // plays music for the level if there is any
230 precache_sound (self.noise);
231 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
237 // 1 FLICKER (first variety)
238 lightstyle(1, "mmnmmommommnonmmonqnmmo");
240 // 2 SLOW STRONG PULSE
241 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
243 // 3 CANDLE (first variety)
244 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
247 lightstyle(4, "mamamamamama");
250 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
252 // 6 FLICKER (second variety)
253 lightstyle(6, "nmonqnmomnmomomno");
255 // 7 CANDLE (second variety)
256 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
258 // 8 CANDLE (third variety)
259 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
261 // 9 SLOW STROBE (fourth variety)
262 lightstyle(9, "aaaaaaaazzzzzzzz");
264 // 10 FLUORESCENT FLICKER
265 lightstyle(10, "mmamammmmammamamaaamammma");
267 // 11 SLOW PULSE NOT FADE TO BLACK
268 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
270 // styles 32-62 are assigned by the light program for switchable lights
276 lms_lowest_lives = 0;
281 bot_waypoints_for_items = cvar("g_waypoints_for_items");
282 if(bot_waypoints_for_items == 1)
283 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
284 bot_waypoints_for_items = 0;
286 if(cvar("g_campaign"))
291 WaypointSprite_Init();
293 //if (cvar("g_domination"))
297 head = nextent(world);
302 head = nextent(head);
305 GameLogInit(); // prepare everything
306 if(cvar("sv_eventlog"))
309 GameLogEcho(":logversion:2", FALSE);
310 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
311 s = strcat(s, ftos(random()));
312 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
313 s = ":gameinfo:mutators:LIST";
314 if(cvar("g_grappling_hook"))
315 s = strcat(s, ":grappling_hook");
316 if(!cvar("g_use_ammunition"))
317 s = strcat(s, ":no_use_ammunition");
318 if(!cvar("g_pickup_items"))
319 s = strcat(s, ":no_pickup_items");
320 if(cvar("g_instagib"))
321 s = strcat(s, ":instagib");
322 if(cvar("g_rocketarena"))
323 s = strcat(s, ":rockerarena");
325 s = strcat(s, ":nixnex");
326 if(cvar("g_vampire"))
327 s = strcat(s, ":vampire");
328 if(cvar("g_laserguided_missile"))
329 s = strcat(s, ":laserguided_missile");
330 if(cvar("g_norecoil"))
331 s = strcat(s, ":norecoil");
333 s = strcat(s, ":midair");
334 if(cvar("g_minstagib"))
335 s = strcat(s, ":minstagib");
336 GameLogEcho(s, FALSE);
337 GameLogEcho(":gameinfo:end", FALSE);
340 cvar_set("nextmap", "");
344 if(cvar("g_campaign"))
356 //makestatic (self); // Who the f___ did that?
360 float( string pFilename ) TryFile =
363 dprint("TryFile(\"", pFilename, "\")\n");
364 lHandle = fopen( pFilename, FILE_READ );
365 if( lHandle != -1 ) {
375 if (game == GAME_DEATHMATCH)
377 else if (game == GAME_TEAM_DEATHMATCH)
379 else if (game == GAME_DOMINATION)
381 else if (game == GAME_CTF)
383 else if (game == GAME_RUNEMATCH)
385 else if (game == GAME_LMS)
387 else if (game == GAME_KEYHUNT)
389 else if (game == GAME_ONSLAUGHT)
391 else if (game == GAME_ASSAULT)
396 float IsSameGametype(string mapcfgname)
400 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
405 string getmapname_stored;
408 if(getmapname_stored == "")
409 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
410 return getmapname_stored;
413 float Map_Count, Map_Current;
414 string Map_Current_Name;
416 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
417 float GetMaplistPosition()
423 idx = cvar("g_maplist_index");
430 for(pos = 0; pos < Map_Count; ++pos)
434 // resume normal maplist rotation if current map is not in g_maplist
438 float MapHasRightSize(string map)
440 // open map size restriction file
442 dprint("opensize "); dprint(map);
443 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
446 float mapmin, mapmax;
448 mapmin = stof(fgets(fh));
449 mapmax = stof(fgets(fh));
451 if(player_count < mapmin)
453 dprint("not enough\n");
456 if(player_count > mapmax)
458 dprint("too many\n");
461 dprint("right size\n");
464 dprint(": not found\n");
468 string Map_Filename(float position)
471 return strcat("maps/", argv(position), ".mapcfg");
474 string strwords(string s, float w)
477 for(endpos = 0; w && endpos >= 0; --w)
478 endpos = strstrofs(s, " ", endpos + 1);
482 return substring(s, 0, endpos);
485 float strhasword(string s, string w)
487 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
490 void Map_MarkAsRecent(string m)
492 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
495 float Map_IsRecent(string m)
497 return strhasword(cvar_string("g_maplist_mostrecent"), m);
500 float(float position, float pass) Map_Check =
504 map_next = argv(position);
507 if(map_next == Map_Current_Name) // same map again in first pass?
509 if(Map_IsRecent(map_next))
512 filename = Map_Filename(position);
513 if(TryFile(filename))
517 if(MapHasRightSize(argv(position)))
522 dprint( "Couldn't find '", filename, "'..\n" );
527 void(string nextmapname) Map_Goto_SetStr =
529 if(getmapname_stored != "")
530 strunzone(getmapname_stored);
531 if(nextmapname == "")
532 getmapname_stored = "";
534 getmapname_stored = strzone(nextmapname);
537 void(float position) Map_Goto_SetFloat =
539 cvar_set("g_maplist_index", ftos(position));
540 Map_Goto_SetStr(argv(position));
543 void() GameResetCfg =
545 // if an exit cfg is defined by exiting map, exec it.
547 exit_cfg = cvar_string("exit_cfg");
549 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
551 localcmd("exec game_reset.cfg\n");
558 Map_MarkAsRecent(getmapname_stored);
560 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
563 // return codes of map selectors:
564 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
565 // -2 = permanent failure
566 float() MaplistMethod_Iterate = // usual method
570 for(pass = 1; pass <= 2; ++pass)
572 for(i = 1; i < Map_Count; ++i)
575 mapindex = math_mod(i + Map_Current, Map_Count);
576 if(Map_Check(mapindex, pass))
583 float() MaplistMethod_Repeat = // fallback method
585 if(Map_Check(Map_Current, 2))
590 float() MaplistMethod_Random = // random map selection
596 for(i = 0; i <= imax; ++i)
599 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
600 if(Map_Check(mapindex, 1))
606 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
607 // the exponent sets a bias on the map selection:
608 // the higher the exponent, the less likely "shortly repeated" same maps are
610 float i, j, imax, insertpos;
615 return 0; // only one map, then always play this one
617 for(i = 0; i <= imax; ++i)
621 // now reinsert this at another position
622 insertpos = pow(random(), 1 / exponent); // ]0, 1]
623 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
624 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
625 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
627 // insert the current map there
629 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
630 newlist = strcat(newlist, "'", argv(j), "'");
631 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
632 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
633 newlist = strcat(newlist, "'", argv(j), "'");
634 cvar_set("g_maplist", newlist);
635 Map_Count = tokenize(newlist);
637 // NOTE: the selected map has just been inserted at (insertpos-1)th position
638 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
639 if(Map_Check(Map_Current, 1))
645 void() Maplist_Init =
648 temp = cvar_string("g_maplist");
649 Map_Count = tokenize(temp);
652 bprint( "Maplist is empty! Resetting it to default map list.\n" );
653 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
654 Map_Count = tokenize(temp);
657 error("empty maplist, cannot select a new map");
658 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
660 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
661 // this may or may not be correct, but who cares, in the worst case a map
662 // isn't chosen in the first pass that should have been
665 string() GetNextMap =
673 if(cvar("g_maplist_shuffle") > 0)
674 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
677 if(cvar("g_maplist_selectrandom"))
678 nextMap = MaplistMethod_Random();
681 nextMap = MaplistMethod_Iterate();
684 nextMap = MaplistMethod_Repeat();
688 Map_Goto_SetFloat(nextMap);
689 return getmapname_stored;
695 float() DoNextMapOverride =
699 if(cvar("g_campaign"))
701 CampaignPostIntermission();
702 alreadychangedlevel = TRUE;
705 if(cvar("quit_when_empty"))
707 if(player_count <= currentbots)
710 alreadychangedlevel = TRUE;
714 if(cvar_string("quit_and_redirect") != "")
716 redirection_target = strzone(cvar_string("quit_and_redirect"));
717 alreadychangedlevel = TRUE;
720 if (cvar("samelevel")) // if samelevel is set, stay on same level
722 // 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)
723 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
724 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
725 localcmd("restart\n");
726 //changelevel (mapname);
727 alreadychangedlevel = TRUE;
730 if(cvar_string("nextmap") != "")
731 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
733 Map_Goto_SetStr(cvar_string("nextmap"));
735 alreadychangedlevel = TRUE;
738 if(cvar("lastlevel"))
741 localcmd("set lastlevel 0\ntogglemenu\n");
742 alreadychangedlevel = TRUE;
750 //local string nextmap;
751 //local float n, nummaps;
753 if (alreadychangedlevel)
755 alreadychangedlevel = TRUE;
761 for(allowReset = 1; allowReset >= 0; --allowReset)
763 nextMap = GetNextMap();
769 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
770 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
774 error("Everything is broken - not even the default map list works. Please report this to the developers.");
786 When the player presses attack or jump, change to the next level
789 .float autoscreenshot;
790 void() MapVote_Start;
791 void() MapVote_Think;
792 float mapvote_initialized;
793 void() IntermissionThink =
795 FixIntermissionClient(self);
797 if(cvar("sv_autoscreenshot"))
798 if(self.autoscreenshot > 0)
799 if(time > self.autoscreenshot)
801 self.autoscreenshot = -1;
802 if(clienttype(self) == CLIENTTYPE_REAL)
803 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
807 if (time < intermission_exittime)
810 if(!mapvote_initialized)
811 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
821 Returns the entity to view from
825 entity() FindIntermission =
830 // look for info_intermission first
831 spot = find (world, classname, "info_intermission");
833 { // pick a random one
837 spot = find (spot, classname, "info_intermission");
839 spot = find (spot, classname, "info_intermission");
845 // then look for the start position
846 spot = find (world, classname, "info_player_start");
850 // testinfo_player_start is only found in regioned levels
851 spot = find (world, classname, "testplayerstart");
855 // then look for the start position
856 spot = find (world, classname, "info_player_deathmatch");
860 //objerror ("FindIntermission: no spot");
866 ===============================================================================
870 ===============================================================================
873 void(float final) DumpStats =
877 local float to_console;
878 local float to_eventlog;
881 to_console = cvar("sv_logscores_console");
882 to_eventlog = cvar("sv_eventlog");
883 to_file = cvar("sv_logscores_file");
887 to_console = TRUE; // always print printstats replies
888 to_eventlog = FALSE; // but never print them to the event log
892 if(cvar("sv_eventlog_console"))
893 to_console = FALSE; // otherwise we get the output twice
899 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
902 ServerConsoleEcho(s, FALSE);
904 GameLogEcho(s, FALSE);
907 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
911 fputs(file, strcat(s, "\n"));
914 FOR_EACH_CLIENT(other)
916 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
918 s = strcat(":player:", ftos(other.frags), ":");
919 s = strcat(s, ftos(other.deaths), ":");
920 s = strcat(s, ftos(rint(time - other.jointime)), ":");
921 s = strcat(s, ftos(other.team), ":");
924 ServerConsoleEcho(strcat(s, other.netname), TRUE);
926 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
928 fputs(file, strcat(s, other.netname, "\n"));
933 ServerConsoleEcho(":end", FALSE);
935 GameLogEcho(":end", FALSE);
938 fputs(file, ":end\n");
943 void FixIntermissionClient(entity e)
945 if(!e.autoscreenshot) // initial call
947 e.angles = e.v_angle;
948 e.angles_x = -e.angles_x;
949 e.autoscreenshot = time + 0.8; // used for autoscreenshot
951 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
953 e.movetype = MOVETYPE_NONE;
954 e.takedamage = DAMAGE_NO;
956 e.weaponentity.effects = EF_NODRAW;
957 stuffcmd(e, "\nscr_printspeed 1000000\n");
958 if(clienttype(e) == CLIENTTYPE_REAL)
961 WriteByte(MSG_ONE, SVC_INTERMISSION);
965 //e.velocity = '0 0 0';
968 // TODO halt weapon animation
973 go to the next level for deathmatch
974 only called if a time or frag limit has expired
985 intermission_running = 1;
987 // enforce a wait time before allowing changelevel
989 intermission_exittime = time + cvar("sv_mapchange_delay");
991 intermission_exittime = -1;
993 WriteByte (MSG_ALL, SVC_CDTRACK);
994 WriteByte (MSG_ALL, 3);
995 WriteByte (MSG_ALL, 3);
997 //pos = FindIntermission ();
1003 if(cvar("sv_eventlog"))
1004 GameLogEcho(":gameover", FALSE);
1008 FOR_EACH_CLIENT(other)
1010 FixIntermissionClient(other);
1013 bprint(other.netname, " ^7wins.\n");
1018 FOR_EACH_PLAYER(other)
1020 if(maxTotalFrags < other.totalfrags)
1021 maxTotalFrags = other.totalfrags;
1022 if(minTotalFrags > other.totalfrags)
1023 minTotalFrags = other.totalfrags;
1028 FOR_EACH_PLAYER(other)
1030 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1031 f = bound(0, other.play_time / max(time, 1), 1);
1032 // store some statistics?
1036 if(cvar("g_campaign"))
1037 CampaignPreIntermission();
1039 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1046 Exit deathmatch games upon conditions
1049 void() CheckRules_Player =
1051 if (gameover) // someone else quit the game already
1054 if(self.deadflag == DEAD_NO)
1055 self.play_time += frametime;
1057 // fixme: don't check players; instead check dom_team and ctf_team entities
1058 // (div0: and that in CheckRules_World please)
1061 float checkrules_oneminutewarning;
1062 float checkrules_leaderfrags;
1063 float tdm_max_score, tdm_old_score;
1065 float checkrules_equality;
1066 float checkrules_overtimewarning;
1067 float checkrules_overtimeend;
1069 void() InitiateOvertime =
1071 if(!checkrules_overtimeend)
1072 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1075 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1076 float WINNING_YES = 1; // winner found
1077 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1078 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1080 float(float fraglimitreached, float equality) GetWinningCode =
1083 if(fraglimitreached)
1084 return WINNING_STARTOVERTIME;
1086 return WINNING_NEVER;
1088 if(fraglimitreached)
1094 // set the .winning flag for exactly those players with a given field value
1095 void(.float field, float value) SetWinners =
1098 FOR_EACH_PLAYER(head)
1099 head.winning = (head.field == value);
1102 // set the .winning flag for those players with a given field value
1103 void(.float field, float value) AddWinners =
1106 FOR_EACH_PLAYER(head)
1107 if(head.field == value)
1111 // clear the .winning flags
1112 void(void) ClearWinners =
1115 FOR_EACH_PLAYER(head)
1119 // Onslaught winning condition:
1120 // game terminates if only one team has a working generator (or none)
1121 float() WinningCondition_Onslaught =
1124 local float t1, t2, t3, t4;
1125 // first check if the game has ended
1126 t1 = t2 = t3 = t4 = 0;
1127 head = find(world, classname, "onslaught_generator");
1130 if (head.health > 0)
1132 if (head.team == COLOR_TEAM1) t1 = 1;
1133 if (head.team == COLOR_TEAM2) t2 = 1;
1134 if (head.team == COLOR_TEAM3) t3 = 1;
1135 if (head.team == COLOR_TEAM4) t4 = 1;
1137 head = find(head, classname, "onslaught_generator");
1139 if (t1 + t2 + t3 + t4 < 2)
1141 // game over, only one team remains (or none)
1143 if (t1) SetWinners(team, COLOR_TEAM1);
1144 if (t2) SetWinners(team, COLOR_TEAM2);
1145 if (t3) SetWinners(team, COLOR_TEAM3);
1146 if (t4) SetWinners(team, COLOR_TEAM4);
1147 dprint("Have a winner, ending game.\n");
1151 // Two or more teams remain
1155 float() LMS_NewPlayerLives =
1158 fl = cvar("fraglimit");
1162 // first player has left the game for dying too much? Nobody else can get in.
1163 if(lms_lowest_lives < 1)
1166 if(!cvar("g_lms_join_anytime"))
1167 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1170 return bound(1, lms_lowest_lives, fl);
1173 // LMS winning condition: game terminates if and only if there's at most one
1174 // one player who's living lives. Top two scores being equal cancels the time
1176 float() WinningCondition_LMS =
1183 have_player = FALSE;
1184 have_players = FALSE;
1185 l = LMS_NewPlayerLives();
1187 head = find(world, classname, "player");
1190 head = find(head, classname, "player");
1192 have_players = TRUE;
1196 // we have at least one player
1199 // two or more active players - continue with the game
1203 // exactly one player?
1206 // but no game has taken place yet
1211 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1212 dprint("Have a winner, ending game.\n");
1219 // nobody is playing at all...
1222 // wait for players...
1226 // SNAFU (maybe a draw game?)
1228 dprint("No players, ending game.\n");
1233 // When we get here, we have at least two players who are actually LIVING,
1234 // or one player who is still waiting for a victim to join the server. Now
1235 // check if the top two players have equal score.
1237 checkrules_leaderfrags = 0;
1238 checkrules_equality = FALSE;
1239 FOR_EACH_PLAYER(head)
1241 if(head.frags > checkrules_leaderfrags)
1243 checkrules_leaderfrags = head.frags;
1244 checkrules_equality = FALSE;
1246 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1247 checkrules_equality = TRUE;
1250 SetWinners(frags, checkrules_leaderfrags);
1252 // The top two players have the same amount of lives? No timelimit then,
1253 // enter overtime...
1255 if(checkrules_equality)
1256 return WINNING_NEVER;
1258 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1262 // DM winning condition: game terminates if a player reached the fraglimit,
1263 // unless the first two players have the same score. The latter case also
1264 // breaks the time limit.
1265 float(float fraglimit) WinningCondition_MaxIndividualScore =
1267 float checkrules_oldleaderfrags;
1270 checkrules_oldleaderfrags = checkrules_leaderfrags;
1271 checkrules_leaderfrags = 0;
1272 checkrules_equality = FALSE;
1273 FOR_EACH_PLAYER(head)
1275 if(head.frags > checkrules_leaderfrags)
1277 checkrules_leaderfrags = head.frags;
1278 checkrules_equality = FALSE;
1280 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1281 checkrules_equality = TRUE;
1284 if(checkrules_leaderfrags > 0)
1285 SetWinners(frags, checkrules_leaderfrags);
1289 if (!cvar("g_runematch"))
1290 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1292 if (checkrules_leaderfrags == fraglimit - 1)
1293 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1294 else if (checkrules_leaderfrags == fraglimit - 2)
1295 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1296 else if (checkrules_leaderfrags == fraglimit - 3)
1297 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1300 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1303 float(float fraglimit) WinningConditionBase_Teamplay =
1305 tdm_old_score = tdm_max_score;
1306 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1308 checkrules_equality =
1313 (team1_score == tdm_max_score)
1314 + (team2_score == tdm_max_score)
1315 + (team3_score == tdm_max_score)
1316 + (team4_score == tdm_max_score)
1320 if(tdm_max_score > 0)
1322 if(team1_score == tdm_max_score)
1323 AddWinners(team, COLOR_TEAM1);
1324 if(team2_score == tdm_max_score)
1325 AddWinners(team, COLOR_TEAM2);
1326 if(team3_score == tdm_max_score)
1327 AddWinners(team, COLOR_TEAM3);
1328 if(team4_score == tdm_max_score)
1329 AddWinners(team, COLOR_TEAM4);
1332 if(!cvar("g_runematch") && !cvar("g_domination"))
1333 if(tdm_max_score != tdm_old_score)
1335 if(tdm_max_score == fraglimit - 1)
1336 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1337 else if(tdm_max_score == fraglimit - 2)
1338 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1339 else if(tdm_max_score == fraglimit - 3)
1340 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1343 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1346 // TDM winning condition: game terminates if a team's score sum reached the
1347 // fraglimit, unless the first two teams have the same total score. The latter
1348 // case also breaks the time limit.
1349 float(float fraglimit) WinningCondition_MaxTeamSum =
1353 team1_score = team2_score = team3_score = team4_score = 0;
1355 FOR_EACH_PLAYER(head)
1357 if(head.team == COLOR_TEAM1)
1358 team1_score += head.frags;
1359 else if(head.team == COLOR_TEAM2)
1360 team2_score += head.frags;
1361 else if(head.team == COLOR_TEAM3)
1362 team3_score += head.frags;
1363 else if(head.team == COLOR_TEAM4)
1364 team4_score += head.frags;
1367 return WinningConditionBase_Teamplay(fraglimit);
1370 // DOM/CTF winning condition: game terminates if the max of a team's players'
1371 // score reached the fraglimit, unless the first two teams have the same
1372 // maximum score. The latter case also breaks the time limit.
1373 float(float fraglimit) WinningCondition_MaxTeamMax =
1377 team1_score = team2_score = team3_score = team4_score = 0;
1379 FOR_EACH_PLAYER(head)
1381 if(head.team == COLOR_TEAM1)
1383 if(head.frags > team1_score)
1384 team1_score = head.frags;
1386 else if(head.team == COLOR_TEAM2)
1388 if(head.frags > team2_score)
1389 team2_score = head.frags;
1391 else if(head.team == COLOR_TEAM3)
1393 if(head.frags > team3_score)
1394 team3_score = head.frags;
1396 else if(head.team == COLOR_TEAM4)
1398 if(head.frags > team4_score)
1399 team4_score = head.frags;
1403 return WinningConditionBase_Teamplay(fraglimit);
1406 void print_to(entity e, string s)
1409 sprint(e, strcat(s, "\n"));
1411 ServerConsoleEcho(s, TRUE);
1414 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1424 FOR_EACH_PLAYER(head)
1426 if(!whichteam || head.team == whichteam)
1430 print_to(e, strcat(" ", colorcode, name, ":"));
1432 fragtotal = fragtotal + head.frags;
1433 s = ftos(head.frags);
1434 s = strcat(s, "/", ftos(head.deaths));
1435 s = strcat(s, " @ ", ftos(head.ping));
1436 if(clienttype(head) == CLIENTTYPE_BOT)
1437 s = strcat(s, "botms");
1439 s = strcat(s, "ms");
1440 v = PlayerValue(head);
1442 s = strcat(s, " / ", ftos(v));
1443 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1446 if(whichteam && found)
1448 s = ftos(fragtotal);
1449 s = strcat(s, " / ", ftos(teamvalue));
1450 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1454 void PrintScoreboard(entity e)
1456 print_to(e, strcat("Time: ", ftos(time / 60)));
1457 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1458 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1459 print_to(e, "Scoreboard:");
1462 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1463 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1464 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1465 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1469 PrintScoreboardFor(e, "", "^7", 0);
1474 void ShuffleMaplist()
1482 result = cvar_string("g_maplist");
1483 litems = tokenize(result);
1485 for(start = 0; start < litems - 1; ++start)
1489 // select a random item
1490 selected = ceil(random() * (litems - start) + start) - 1;
1492 // shift this item to the place start
1493 for(i = 0; i < start; ++i)
1494 result = strcat(result, "'", argv(i), "'");
1495 result = strcat(result, "'", argv(selected), "'");
1496 for(i = start; i < litems; ++i)
1498 result = strcat(result, "'", argv(i), "'");
1500 litems = tokenize(result);
1502 //dprint(result, "\n");
1505 cvar_set("g_maplist", result);
1512 Exit deathmatch games upon conditions
1515 void() CheckRules_World =
1518 local float timelimit;
1519 local float fraglimit;
1527 MapVote_Think should now do that part
1528 if (intermission_running)
1529 if (time >= intermission_exittime + 60)
1531 if(!DoNextMapOverride())
1537 if (gameover) // someone else quit the game already
1539 if(player_count == 0) // Nobody there? Then let's go to the next map
1541 // this will actually check the player count in the next frame
1542 // again, but this shouldn't hurt
1546 timelimit = cvar("timelimit") * 60;
1547 fraglimit = cvar("fraglimit");
1549 if(checkrules_overtimeend)
1551 if(!checkrules_overtimewarning)
1553 checkrules_overtimewarning = TRUE;
1554 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1555 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1560 if (timelimit && time >= timelimit)
1564 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1570 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1572 checkrules_oneminutewarning = TRUE;
1573 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1576 status = WINNING_NO;
1579 status = WinningCondition_LMS();
1581 else if (cvar("g_onslaught"))
1583 status = WinningCondition_Onslaught();
1589 if(cvar("g_tdm") || cvar("g_runematch") || cvar("g_ctf") || cvar("g_domination") || cvar("g_keyhunt"))
1590 status = WinningCondition_MaxTeamSum(fraglimit);
1592 // status = WinningCondition_MaxTeamMax(fraglimit);
1595 dprint("div0: How can this happen?\n");
1596 status = WinningCondition_MaxTeamMax(fraglimit);
1600 status = WinningCondition_MaxIndividualScore(fraglimit);
1603 if(status == WINNING_STARTOVERTIME)
1605 status = WINNING_NEVER;
1609 if(status == WINNING_NEVER)
1610 // equality cases! Nobody wins if the overtime ends in a draw.
1613 if(checkrules_overtimeend)
1614 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1615 status = WINNING_YES;
1617 if(status == WINNING_YES)
1621 float randsel_value;
1622 float randsel_priority;
1623 float randsel_count;
1627 randsel_priority = -1;
1630 void RandSel_Add(float priority, float value)
1632 if(priority > randsel_priority)
1634 randsel_priority = priority;
1635 randsel_value = value;
1638 else if(priority == randsel_priority)
1641 if(ceil(random() * randsel_count) == 1)
1642 randsel_value = value;
1646 float mapvote_nextthink;
1647 float mapvote_initialized;
1648 float mapvote_keeptwotime;
1649 float mapvote_timeout;
1650 string mapvote_message;
1652 #define MAPVOTE_COUNT 10
1653 float mapvote_count;
1654 string mapvote_maps[MAPVOTE_COUNT];
1655 float mapvote_maps_suggested[MAPVOTE_COUNT];
1656 string mapvote_suggestions[MAPVOTE_COUNT];
1657 float mapvote_suggestion_ptr;
1658 float mapvote_maxlen;
1659 float mapvote_voters;
1660 float mapvote_votes[MAPVOTE_COUNT];
1664 void MapVote_ClearAllVotes()
1666 FOR_EACH_CLIENT(other)
1670 string MapVote_Suggest(string m)
1674 return "That's not how to use this command.";
1675 if(!cvar("g_maplist_votable_suggestions"))
1676 return "Suggestions are not accepted on this server.";
1677 if(mapvote_initialized)
1678 return "Can't suggest - voting is already in progress!";
1679 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1680 if(!IsSameGametype(m))
1681 return "This server does not allow changing the game type by map suggestions.";
1682 if(!cvar("g_maplist_votable_override_mostrecent"))
1684 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1686 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1687 return "The map you suggested is not available on this server.";
1688 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1689 if(mapvote_suggestions[i] == m)
1690 return "This map was already suggested.";
1691 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1693 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1697 i = mapvote_suggestion_ptr;
1698 mapvote_suggestion_ptr += 1;
1700 if(mapvote_suggestions[i] != "")
1701 strunzone(mapvote_suggestions[i]);
1702 mapvote_suggestions[i] = strzone(m);
1703 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1704 return "Suggestion accepted.";
1707 void MapVote_AddVotable(string nextMap, float isSuggestion)
1712 for(j = 0; j < mapvote_count; ++j)
1713 if(mapvote_maps[j] == nextMap)
1715 if(strlen(nextMap) > mapvote_maxlen)
1716 mapvote_maxlen = strlen(nextMap);
1717 mapvote_maps[mapvote_count] = strzone(nextMap);
1718 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1727 MapVote_ClearAllVotes();
1729 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1730 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1733 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1734 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1736 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1737 MapVote_AddVotable(GetNextMap(), FALSE);
1739 if(mapvote_count == 0)
1741 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1742 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1743 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1744 MapVote_AddVotable(GetNextMap(), FALSE);
1747 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1749 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1750 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1751 if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1752 mapvote_keeptwotime = 0;
1753 mapvote_message = "Choose a map and press its key!";
1755 float MapVote_Finished(float mappos)
1760 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1761 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1762 for(i = 0; i < mapvote_count; ++i)
1764 if(mapvote_maps[i] != "")
1766 result = strcat(result, ":", mapvote_maps[i]);
1767 result = strcat(result, ":", ftos(mapvote_votes[i]));
1769 GameLogEcho(result, FALSE);
1770 if(mapvote_maps_suggested[mappos])
1771 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1773 FOR_EACH_REALCLIENT(other)
1774 FixClientCvars(other);
1776 Map_Goto_SetStr(mapvote_maps[mappos]);
1778 alreadychangedlevel = TRUE;
1781 void MapVote_CheckRules_1()
1785 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1787 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1788 mapvote_votes[i] = 0;
1792 FOR_EACH_REALCLIENT(other)
1797 i = other.mapvote - 1;
1798 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1799 mapvote_votes[i] = mapvote_votes[i] + 1;
1804 float MapVote_CheckRules_2()
1807 float firstPlace, secondPlace;
1808 float firstPlaceVotes, secondPlaceVotes;
1812 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1813 RandSel_Add(mapvote_votes[i], i);
1814 firstPlace = randsel_value;
1815 firstPlaceVotes = randsel_priority;
1816 //dprint("First place: ", ftos(firstPlace), "\n");
1817 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1820 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1822 RandSel_Add(mapvote_votes[i], i);
1823 secondPlace = randsel_value;
1824 secondPlaceVotes = randsel_priority;
1825 //dprint("Second place: ", ftos(secondPlace), "\n");
1826 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1828 if(firstPlace == -1)
1829 error("No first place in map vote... WTF?");
1831 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1832 return MapVote_Finished(firstPlace);
1834 if(mapvote_keeptwotime)
1835 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1837 mapvote_message = "Now decide between the TOP TWO!";
1838 mapvote_keeptwotime = 0;
1839 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1840 result = strcat(result, ":", ftos(firstPlaceVotes));
1841 result = strcat(result, ":", mapvote_maps[secondPlace]);
1842 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1843 for(i = 0; i < mapvote_count; ++i)
1845 if(i != secondPlace)
1846 if(mapvote_maps[i] != "")
1848 result = strcat(result, ":", mapvote_maps[i]);
1849 result = strcat(result, ":", ftos(mapvote_votes[i]));
1850 strunzone(mapvote_maps[i]);
1851 mapvote_maps[i] = "";
1853 GameLogEcho(result, FALSE);
1865 keeptwo = mapvote_keeptwotime;
1866 MapVote_CheckRules_1(); // count
1867 if(MapVote_CheckRules_2()) // decide
1870 FOR_EACH_REALCLIENT(other)
1872 // hide scoreboard again
1873 if(other.health != 2342)
1875 other.health = 2342;
1877 if(clienttype(other) == CLIENTTYPE_REAL)
1879 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");
1881 WriteByte(MSG_ONE, SVC_FINALE);
1882 WriteString(MSG_ONE, "");
1884 for(i = 0; i < mapvote_count; ++i)
1885 if(mapvote_maps[i] != "")
1887 tmp = mapvote_maps[i];
1888 sprint(other, strcat("map voting: type ^1impulse ", ftos(i+1), "^7 to vote for ", tmp, "\n"));
1894 // notify about keep-two
1895 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1896 play2(other, "misc/invshot.wav");
1898 // clear possibly invalid votes
1899 if(mapvote_maps[other.mapvote - 1] == "")
1901 // use impulses as new vote
1902 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1903 if(mapvote_maps[other.impulse - 1] != "")
1904 other.mapvote = other.impulse;
1908 MapVote_CheckRules_1(); // just count
1910 FOR_EACH_REALCLIENT(other)
1912 // display voting screen
1913 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1914 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1915 msgstr = strcat(msgstr, mapvote_message);
1916 msgstr = strcat(msgstr, "\n\n");
1917 for(i = 0; i < mapvote_count; ++i)
1918 if(mapvote_maps[i] == "")
1919 msgstr = strcat(msgstr, "\n");
1922 tmp = mapvote_maps[i];
1923 tmp = strpad(mapvote_maxlen, tmp);
1924 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
1925 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
1926 if(mapvote_votes[i] != 1)
1927 tmp = strcat(tmp, "s");
1928 tmp = strcat(tmp, ")");
1929 tmp = strpad(mapvote_maxlen + 15, tmp);
1930 if(other.mapvote == i + 1)
1931 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
1933 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
1935 i = ceil(mapvote_timeout - time);
1936 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
1938 msgstr = strcat(msgstr, "s");
1939 msgstr = strcat(msgstr, " left");
1941 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
1944 void MapVote_Start()
1948 void MapVote_Think()
1953 if(alreadychangedlevel)
1956 if(time < mapvote_nextthink)
1960 mapvote_nextthink = time + 0.5;
1962 if(!mapvote_initialized)
1964 mapvote_initialized = TRUE;
1965 if(DoNextMapOverride())
1967 if(!cvar("g_maplist_votable") || player_count <= 0)
1978 string GotoMap(string m)
1980 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1981 return "The map you chose is not available on this server.";
1982 cvar_set("nextmap", m);
1983 cvar_set("timelimit", "-1");
1984 if(mapvote_initialized || alreadychangedlevel)
1986 if(DoNextMapOverride())
1987 return "Map switch initiated.";
1989 return "Hm... no. For some reason I like THIS map more.";
1992 return "Map switch will happen after scoreboard.";
1998 FOR_EACH_REALCLIENT(self)
2000 if(self.classname == "spectator")
2002 if(self.enemy.hitsound)
2003 play2(self, "misc/hit.wav");
2008 play2(self, "misc/hit.wav");
2011 FOR_EACH_CLIENT(self)
2012 self.hitsound = FALSE;
2018 * returns TRUE if redirecting
2020 float redirection_timeout;
2021 float redirection_nextthink;
2022 float RedirectionThink()
2024 float clients_found;
2026 if(redirection_target == "")
2029 if(!redirection_timeout)
2031 cvar_set("sv_public", "-2");
2032 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2033 if(redirection_target == "self")
2034 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2036 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2039 if(time < redirection_nextthink)
2042 redirection_nextthink = time + 1;
2045 FOR_EACH_REALCLIENT(self)
2047 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2048 if(redirection_target == "self")
2049 stuffcmd(self, "\ndisconnect; reconnect\n");
2051 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2055 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2057 if(time > redirection_timeout || clients_found == 0)
2058 localcmd("\nwait; wait; wait; quit\n");