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));
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");
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");
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 (g_grappling_hook)
211 precache_sound ("weapons/hook_fire.wav"); // hook
212 precache_sound ("weapons/hook_impact.wav"); // hook
215 if (cvar("sv_precacheweapons") || 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";
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");
321 s = strcat(s, ":instagib");
323 s = strcat(s, ":rockerarena");
325 s = strcat(s, ":nixnex");
327 s = strcat(s, ":vampire");
328 if(g_laserguided_missile)
329 s = strcat(s, ":laserguided_missile");
331 s = strcat(s, ":norecoil");
333 s = strcat(s, ":midair");
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)
402 if(substring(mapcfgname, 0, strlen(gt) + 1) == strcat(gt, "_"))
408 string getmapname_stored;
413 if(getmapname_stored == "")
414 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
415 return getmapname_stored;
419 float Map_Count, Map_Current;
420 string Map_Current_Name;
422 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
423 float GetMaplistPosition()
429 idx = cvar("g_maplist_index");
436 for(pos = 0; pos < Map_Count; ++pos)
440 // resume normal maplist rotation if current map is not in g_maplist
444 float MapHasRightSize(string map)
446 // open map size restriction file
448 dprint("opensize "); dprint(map);
449 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
452 float mapmin, mapmax;
454 mapmin = stof(fgets(fh));
455 mapmax = stof(fgets(fh));
457 if(player_count < mapmin)
459 dprint("not enough\n");
462 if(player_count > mapmax)
464 dprint("too many\n");
467 dprint("right size\n");
470 dprint(": not found\n");
476 string Map_Filename(float position)
479 return strcat("maps/", argv(position), ".mapcfg");
483 string strwords(string s, float w)
486 for(endpos = 0; w && endpos >= 0; --w)
487 endpos = strstrofs(s, " ", endpos + 1);
491 return substring(s, 0, endpos);
494 float strhasword(string s, string w)
496 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
499 void Map_MarkAsRecent(string m)
501 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
504 float Map_IsRecent(string m)
506 return strhasword(cvar_string("g_maplist_mostrecent"), m);
509 float(float position, float pass) Map_Check =
513 map_next = argv(position);
516 if(map_next == Map_Current_Name) // same map again in first pass?
518 if(Map_IsRecent(map_next))
523 filename = Map_Filename(position);
524 if(TryFile(filename))
529 if(MapHasRightSize(argv(position)))
534 dprint( "Couldn't find '", filename, "'..\n" );
539 void(string nextmapname) Map_Goto_SetStr =
541 if(getmapname_stored != "")
542 strunzone(getmapname_stored);
543 if(nextmapname == "")
544 getmapname_stored = "";
546 getmapname_stored = strzone(nextmapname);
549 void(float position) Map_Goto_SetFloat =
551 cvar_set("g_maplist_index", ftos(position));
552 Map_Goto_SetStr(argv(position));
555 void() GameResetCfg =
557 // if an exit cfg is defined by exiting map, exec it.
559 exit_cfg = cvar_string("exit_cfg");
561 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
563 localcmd("exec game_reset.cfg\n");
570 Map_MarkAsRecent(getmapname_stored);
574 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
578 // return codes of map selectors:
579 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
580 // -2 = permanent failure
581 float() MaplistMethod_Iterate = // usual method
585 for(pass = 1; pass <= 2; ++pass)
587 for(i = 1; i < Map_Count; ++i)
590 mapindex = math_mod(i + Map_Current, Map_Count);
591 if(Map_Check(mapindex, pass))
598 float() MaplistMethod_Repeat = // fallback method
600 if(Map_Check(Map_Current, 2))
605 float() MaplistMethod_Random = // random map selection
611 for(i = 0; i <= imax; ++i)
614 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
615 if(Map_Check(mapindex, 1))
621 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
622 // the exponent sets a bias on the map selection:
623 // the higher the exponent, the less likely "shortly repeated" same maps are
625 float i, j, imax, insertpos;
630 return 0; // only one map, then always play this one
632 for(i = 0; i <= imax; ++i)
636 // now reinsert this at another position
637 insertpos = pow(random(), 1 / exponent); // ]0, 1]
638 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
639 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
640 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
642 // insert the current map there
644 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
645 newlist = strcat(newlist, "'", argv(j), "'");
646 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
647 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
648 newlist = strcat(newlist, "'", argv(j), "'");
649 cvar_set("g_maplist", newlist);
650 Map_Count = tokenize(newlist);
652 // NOTE: the selected map has just been inserted at (insertpos-1)th position
653 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
654 if(Map_Check(Map_Current, 1))
660 void() Maplist_Init =
663 temp = cvar_string("g_maplist");
664 Map_Count = tokenize(temp);
667 bprint( "Maplist is empty! Resetting it to default map list.\n" );
670 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
672 Map_Count = tokenize(temp);
675 error("empty maplist, cannot select a new map");
676 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
678 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
679 // this may or may not be correct, but who cares, in the worst case a map
680 // isn't chosen in the first pass that should have been
683 string() GetNextMap =
691 if(cvar("g_maplist_shuffle") > 0)
692 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
695 if(cvar("g_maplist_selectrandom"))
696 nextMap = MaplistMethod_Random();
699 nextMap = MaplistMethod_Iterate();
702 nextMap = MaplistMethod_Repeat();
706 Map_Goto_SetFloat(nextMap);
707 return getmapname_stored;
713 float() DoNextMapOverride =
717 if(cvar("g_campaign"))
719 CampaignPostIntermission();
720 alreadychangedlevel = TRUE;
723 if(cvar("quit_when_empty"))
725 if(player_count <= currentbots)
728 alreadychangedlevel = TRUE;
732 if(cvar_string("quit_and_redirect") != "")
734 redirection_target = strzone(cvar_string("quit_and_redirect"));
735 alreadychangedlevel = TRUE;
738 if (cvar("samelevel")) // if samelevel is set, stay on same level
740 // 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)
741 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
742 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
743 localcmd("restart\n");
744 //changelevel (mapname);
745 alreadychangedlevel = TRUE;
748 if(cvar_string("nextmap") != "")
751 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
754 Map_Goto_SetStr(cvar_string("nextmap"));
756 alreadychangedlevel = TRUE;
759 if(cvar("lastlevel"))
762 localcmd("set lastlevel 0\ntogglemenu\n");
763 alreadychangedlevel = TRUE;
771 //local string nextmap;
772 //local float n, nummaps;
774 if (alreadychangedlevel)
776 alreadychangedlevel = TRUE;
782 for(allowReset = 1; allowReset >= 0; --allowReset)
784 nextMap = GetNextMap();
790 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
793 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
798 error("Everything is broken - not even the default map list works. Please report this to the developers.");
810 When the player presses attack or jump, change to the next level
813 .float autoscreenshot;
814 void() MapVote_Start;
815 void() MapVote_Think;
816 float mapvote_initialized;
817 void() IntermissionThink =
819 FixIntermissionClient(self);
821 if(cvar("sv_autoscreenshot"))
822 if(self.autoscreenshot > 0)
823 if(time > self.autoscreenshot)
825 self.autoscreenshot = -1;
826 if(clienttype(self) == CLIENTTYPE_REAL)
827 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
831 if (time < intermission_exittime)
834 if(!mapvote_initialized)
835 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
845 Returns the entity to view from
849 entity() FindIntermission =
854 // look for info_intermission first
855 spot = find (world, classname, "info_intermission");
857 { // pick a random one
861 spot = find (spot, classname, "info_intermission");
863 spot = find (spot, classname, "info_intermission");
869 // then look for the start position
870 spot = find (world, classname, "info_player_start");
874 // testinfo_player_start is only found in regioned levels
875 spot = find (world, classname, "testplayerstart");
879 // then look for the start position
880 spot = find (world, classname, "info_player_deathmatch");
884 //objerror ("FindIntermission: no spot");
890 ===============================================================================
894 ===============================================================================
897 void(float final) DumpStats =
901 local float to_console;
902 local float to_eventlog;
905 to_console = cvar("sv_logscores_console");
906 to_eventlog = cvar("sv_eventlog");
907 to_file = cvar("sv_logscores_file");
911 to_console = TRUE; // always print printstats replies
912 to_eventlog = FALSE; // but never print them to the event log
916 if(cvar("sv_eventlog_console"))
917 to_console = FALSE; // otherwise we get the output twice
923 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
926 ServerConsoleEcho(s, FALSE);
928 GameLogEcho(s, FALSE);
931 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
935 fputs(file, strcat(s, "\n"));
938 FOR_EACH_CLIENT(other)
940 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
942 s = strcat(":player:", ftos(other.frags), ":");
943 s = strcat(s, ftos(other.deaths), ":");
944 s = strcat(s, ftos(rint(time - other.jointime)), ":");
945 s = strcat(s, ftos(other.team), ":");
948 ServerConsoleEcho(strcat(s, other.netname), TRUE);
950 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
952 fputs(file, strcat(s, other.netname, "\n"));
957 ServerConsoleEcho(":end", FALSE);
959 GameLogEcho(":end", FALSE);
962 fputs(file, ":end\n");
967 void FixIntermissionClient(entity e)
969 if(!e.autoscreenshot) // initial call
971 e.angles = e.v_angle;
972 e.angles_x = -e.angles_x;
973 e.autoscreenshot = time + 0.8; // used for autoscreenshot
975 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
977 e.movetype = MOVETYPE_NONE;
978 e.takedamage = DAMAGE_NO;
980 e.weaponentity.effects = EF_NODRAW;
981 stuffcmd(e, "\nscr_printspeed 1000000\n");
982 if(clienttype(e) == CLIENTTYPE_REAL)
985 WriteByte(MSG_ONE, SVC_INTERMISSION);
989 //e.velocity = '0 0 0';
992 // TODO halt weapon animation
997 go to the next level for deathmatch
998 only called if a time or frag limit has expired
1002 float minTotalFrags;
1003 float maxTotalFrags;
1009 intermission_running = 1;
1011 // enforce a wait time before allowing changelevel
1012 if(player_count > 0)
1013 intermission_exittime = time + cvar("sv_mapchange_delay");
1015 intermission_exittime = -1;
1017 WriteByte (MSG_ALL, SVC_CDTRACK);
1018 WriteByte (MSG_ALL, 3);
1019 WriteByte (MSG_ALL, 3);
1021 //pos = FindIntermission ();
1027 if(cvar("sv_eventlog"))
1028 GameLogEcho(":gameover", FALSE);
1032 FOR_EACH_CLIENT(other)
1034 FixIntermissionClient(other);
1037 bprint(other.netname, " ^7wins.\n");
1042 FOR_EACH_PLAYER(other)
1044 if(maxTotalFrags < other.totalfrags)
1045 maxTotalFrags = other.totalfrags;
1046 if(minTotalFrags > other.totalfrags)
1047 minTotalFrags = other.totalfrags;
1052 FOR_EACH_PLAYER(other)
1054 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1055 f = bound(0, other.play_time / max(time, 1), 1);
1056 // store some statistics?
1060 if(cvar("g_campaign"))
1061 CampaignPreIntermission();
1063 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1070 Exit deathmatch games upon conditions
1073 void() CheckRules_Player =
1075 if (gameover) // someone else quit the game already
1078 if(self.deadflag == DEAD_NO)
1079 self.play_time += frametime;
1081 // fixme: don't check players; instead check dom_team and ctf_team entities
1082 // (div0: and that in CheckRules_World please)
1085 float checkrules_oneminutewarning;
1086 float checkrules_leaderfrags;
1087 float tdm_max_score, tdm_old_score;
1089 float checkrules_equality;
1090 float checkrules_overtimewarning;
1091 float checkrules_overtimeend;
1093 void() InitiateOvertime =
1095 if(!checkrules_overtimeend)
1096 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1099 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1100 float WINNING_YES = 1; // winner found
1101 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1102 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1104 float(float fraglimitreached, float equality) GetWinningCode =
1107 if(fraglimitreached)
1108 return WINNING_STARTOVERTIME;
1110 return WINNING_NEVER;
1112 if(fraglimitreached)
1118 // set the .winning flag for exactly those players with a given field value
1119 void(.float field, float value) SetWinners =
1122 FOR_EACH_PLAYER(head)
1123 head.winning = (head.field == value);
1126 // set the .winning flag for those players with a given field value
1127 void(.float field, float value) AddWinners =
1130 FOR_EACH_PLAYER(head)
1131 if(head.field == value)
1135 // clear the .winning flags
1136 void(void) ClearWinners =
1139 FOR_EACH_PLAYER(head)
1143 // Onslaught winning condition:
1144 // game terminates if only one team has a working generator (or none)
1145 float() WinningCondition_Onslaught =
1148 local float t1, t2, t3, t4;
1149 // first check if the game has ended
1150 t1 = t2 = t3 = t4 = 0;
1151 head = find(world, classname, "onslaught_generator");
1154 if (head.health > 0)
1156 if (head.team == COLOR_TEAM1) t1 = 1;
1157 if (head.team == COLOR_TEAM2) t2 = 1;
1158 if (head.team == COLOR_TEAM3) t3 = 1;
1159 if (head.team == COLOR_TEAM4) t4 = 1;
1161 head = find(head, classname, "onslaught_generator");
1163 if (t1 + t2 + t3 + t4 < 2)
1165 // game over, only one team remains (or none)
1167 if (t1) SetWinners(team, COLOR_TEAM1);
1168 if (t2) SetWinners(team, COLOR_TEAM2);
1169 if (t3) SetWinners(team, COLOR_TEAM3);
1170 if (t4) SetWinners(team, COLOR_TEAM4);
1171 dprint("Have a winner, ending game.\n");
1175 // Two or more teams remain
1179 float() LMS_NewPlayerLives =
1182 fl = cvar("fraglimit");
1186 // first player has left the game for dying too much? Nobody else can get in.
1187 if(lms_lowest_lives < 1)
1190 if(!cvar("g_lms_join_anytime"))
1191 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1194 return bound(1, lms_lowest_lives, fl);
1197 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1198 // they win. Otherwise the defending team wins once the timelimit passes.
1199 void assault_new_round();
1200 float() WinningCondition_Assault =
1203 status = WINNING_NO;
1205 // as the timelimit has not yet passed just assume the defending team will win
1206 if(assault_attacker_team == COLOR_TEAM1)
1208 SetWinners(team, COLOR_TEAM2);
1212 SetWinners(team, COLOR_TEAM1);
1216 ent = find(world, classname, "target_assault_roundend");
1219 if(ent.winning) // round end has been triggered by attacking team
1221 SetWinners(team, assault_attacker_team);
1222 if(assault_attacker_team == COLOR_TEAM1)
1224 team1_score = team1_score + 50;
1228 team2_score = team2_score + 50;
1231 if(ent.cnt == 1) // this was the second round
1233 status = WINNING_YES;
1237 cvar_set("timelimit", ftos((2*time)/60));
1238 assault_new_round();
1248 // LMS winning condition: game terminates if and only if there's at most one
1249 // one player who's living lives. Top two scores being equal cancels the time
1251 float() WinningCondition_LMS =
1258 have_player = FALSE;
1259 have_players = FALSE;
1260 l = LMS_NewPlayerLives();
1262 head = find(world, classname, "player");
1265 head = find(head, classname, "player");
1267 have_players = TRUE;
1271 // we have at least one player
1274 // two or more active players - continue with the game
1278 // exactly one player?
1281 // but no game has taken place yet
1286 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1287 dprint("Have a winner, ending game.\n");
1294 // nobody is playing at all...
1297 // wait for players...
1301 // SNAFU (maybe a draw game?)
1303 dprint("No players, ending game.\n");
1308 // When we get here, we have at least two players who are actually LIVING,
1309 // or one player who is still waiting for a victim to join the server. Now
1310 // check if the top two players have equal score.
1312 checkrules_leaderfrags = 0;
1313 checkrules_equality = FALSE;
1314 FOR_EACH_PLAYER(head)
1316 if(head.frags > checkrules_leaderfrags)
1318 checkrules_leaderfrags = head.frags;
1319 checkrules_equality = FALSE;
1321 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1322 checkrules_equality = TRUE;
1325 SetWinners(frags, checkrules_leaderfrags);
1327 // The top two players have the same amount of lives? No timelimit then,
1328 // enter overtime...
1330 if(checkrules_equality)
1331 return WINNING_NEVER;
1333 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1337 // DM winning condition: game terminates if a player reached the fraglimit,
1338 // unless the first two players have the same score. The latter case also
1339 // breaks the time limit.
1340 float(float fraglimit) WinningCondition_MaxIndividualScore =
1342 float checkrules_oldleaderfrags;
1345 checkrules_oldleaderfrags = checkrules_leaderfrags;
1346 checkrules_leaderfrags = 0;
1347 checkrules_equality = FALSE;
1348 FOR_EACH_PLAYER(head)
1350 if(head.frags > checkrules_leaderfrags)
1352 checkrules_leaderfrags = head.frags;
1353 checkrules_equality = FALSE;
1355 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1356 checkrules_equality = TRUE;
1359 if(checkrules_leaderfrags > 0)
1360 SetWinners(frags, checkrules_leaderfrags);
1364 if (!cvar("g_runematch"))
1365 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1367 if (checkrules_leaderfrags == fraglimit - 1)
1368 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1369 else if (checkrules_leaderfrags == fraglimit - 2)
1370 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1371 else if (checkrules_leaderfrags == fraglimit - 3)
1372 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1375 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1378 float(float fraglimit) WinningConditionBase_Teamplay =
1380 tdm_old_score = tdm_max_score;
1381 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1383 checkrules_equality =
1388 (team1_score == tdm_max_score)
1389 + (team2_score == tdm_max_score)
1390 + (team3_score == tdm_max_score)
1391 + (team4_score == tdm_max_score)
1395 if(tdm_max_score > 0)
1397 if(team1_score == tdm_max_score)
1398 AddWinners(team, COLOR_TEAM1);
1399 if(team2_score == tdm_max_score)
1400 AddWinners(team, COLOR_TEAM2);
1401 if(team3_score == tdm_max_score)
1402 AddWinners(team, COLOR_TEAM3);
1403 if(team4_score == tdm_max_score)
1404 AddWinners(team, COLOR_TEAM4);
1407 if(!cvar("g_runematch") && !cvar("g_domination"))
1408 if(tdm_max_score != tdm_old_score)
1410 if(tdm_max_score == fraglimit - 1)
1411 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.wav", 1, ATTN_NONE);
1412 else if(tdm_max_score == fraglimit - 2)
1413 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.wav", 1, ATTN_NONE);
1414 else if(tdm_max_score == fraglimit - 3)
1415 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.wav", 1, ATTN_NONE);
1418 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1421 // TDM winning condition: game terminates if a team's score sum reached the
1422 // fraglimit, unless the first two teams have the same total score. The latter
1423 // case also breaks the time limit.
1424 float(float fraglimit) WinningCondition_MaxTeamSum =
1428 team1_score = team2_score = team3_score = team4_score = 0;
1430 FOR_EACH_PLAYER(head)
1432 if(head.team == COLOR_TEAM1)
1433 team1_score += head.frags;
1434 else if(head.team == COLOR_TEAM2)
1435 team2_score += head.frags;
1436 else if(head.team == COLOR_TEAM3)
1437 team3_score += head.frags;
1438 else if(head.team == COLOR_TEAM4)
1439 team4_score += head.frags;
1442 return WinningConditionBase_Teamplay(fraglimit);
1445 // DOM/CTF winning condition: game terminates if the max of a team's players'
1446 // score reached the fraglimit, unless the first two teams have the same
1447 // maximum score. The latter case also breaks the time limit.
1448 float(float fraglimit) WinningCondition_MaxTeamMax =
1452 team1_score = team2_score = team3_score = team4_score = 0;
1454 FOR_EACH_PLAYER(head)
1456 if(head.team == COLOR_TEAM1)
1458 if(head.frags > team1_score)
1459 team1_score = head.frags;
1461 else if(head.team == COLOR_TEAM2)
1463 if(head.frags > team2_score)
1464 team2_score = head.frags;
1466 else if(head.team == COLOR_TEAM3)
1468 if(head.frags > team3_score)
1469 team3_score = head.frags;
1471 else if(head.team == COLOR_TEAM4)
1473 if(head.frags > team4_score)
1474 team4_score = head.frags;
1478 return WinningConditionBase_Teamplay(fraglimit);
1481 void print_to(entity e, string s)
1484 sprint(e, strcat(s, "\n"));
1486 ServerConsoleEcho(s, TRUE);
1489 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1499 FOR_EACH_PLAYER(head)
1501 if(!whichteam || head.team == whichteam)
1505 print_to(e, strcat(" ", colorcode, name, ":"));
1507 fragtotal = fragtotal + head.frags;
1508 s = ftos(head.frags);
1509 s = strcat(s, "/", ftos(head.deaths));
1510 s = strcat(s, " @ ", ftos(head.ping));
1511 if(clienttype(head) == CLIENTTYPE_BOT)
1512 s = strcat(s, "botms");
1514 s = strcat(s, "ms");
1515 v = PlayerValue(head);
1517 s = strcat(s, " / ", ftos(v));
1518 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1521 if(whichteam && found)
1523 s = ftos(fragtotal);
1524 s = strcat(s, " / ", ftos(teamvalue));
1525 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1529 void PrintScoreboard(entity e)
1531 print_to(e, strcat("Time: ", ftos(time / 60)));
1532 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1533 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1534 print_to(e, "Scoreboard:");
1537 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1538 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1539 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM3);
1540 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM4);
1544 PrintScoreboardFor(e, "", "^7", 0);
1549 void ShuffleMaplist()
1557 result = cvar_string("g_maplist");
1558 litems = tokenize(result);
1560 for(start = 0; start < litems - 1; ++start)
1564 // select a random item
1565 selected = ceil(random() * (litems - start) + start) - 1;
1567 // shift this item to the place start
1568 for(i = 0; i < start; ++i)
1569 result = strcat(result, "'", argv(i), "'");
1570 result = strcat(result, "'", argv(selected), "'");
1571 for(i = start; i < litems; ++i)
1573 result = strcat(result, "'", argv(i), "'");
1575 litems = tokenize(result);
1577 //dprint(result, "\n");
1580 cvar_set("g_maplist", result);
1587 Exit deathmatch games upon conditions
1590 void() CheckRules_World =
1593 local float timelimit;
1594 local float fraglimit;
1602 MapVote_Think should now do that part
1603 if (intermission_running)
1604 if (time >= intermission_exittime + 60)
1606 if(!DoNextMapOverride())
1612 if (gameover) // someone else quit the game already
1614 if(player_count == 0) // Nobody there? Then let's go to the next map
1616 // this will actually check the player count in the next frame
1617 // again, but this shouldn't hurt
1621 timelimit = cvar("timelimit") * 60;
1622 fraglimit = cvar("fraglimit");
1624 if(checkrules_overtimeend)
1626 if(!checkrules_overtimewarning)
1628 checkrules_overtimewarning = TRUE;
1629 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1630 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1635 if (timelimit && time >= timelimit)
1639 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1645 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1647 checkrules_oneminutewarning = TRUE;
1648 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.wav", 1, ATTN_NONE);
1651 status = WINNING_NO;
1654 status = WinningCondition_Assault();
1658 status = WinningCondition_LMS();
1660 else if (g_onslaught)
1662 status = WinningCondition_Onslaught();
1668 if(g_tdm || cvar("g_runematch") || g_ctf || cvar("g_domination") || g_keyhunt)
1669 status = WinningCondition_MaxTeamSum(fraglimit);
1671 // status = WinningCondition_MaxTeamMax(fraglimit);
1674 dprint("div0: How can this happen?\n");
1675 status = WinningCondition_MaxTeamMax(fraglimit);
1679 status = WinningCondition_MaxIndividualScore(fraglimit);
1682 if(status == WINNING_STARTOVERTIME)
1684 status = WINNING_NEVER;
1688 if(status == WINNING_NEVER)
1689 // equality cases! Nobody wins if the overtime ends in a draw.
1692 if(checkrules_overtimeend)
1693 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1694 status = WINNING_YES;
1696 if(status == WINNING_YES)
1700 float randsel_value;
1701 float randsel_priority;
1702 float randsel_count;
1706 randsel_priority = -1;
1709 void RandSel_Add(float priority, float value)
1711 if(priority > randsel_priority)
1713 randsel_priority = priority;
1714 randsel_value = value;
1717 else if(priority == randsel_priority)
1720 if(ceil(random() * randsel_count) == 1)
1721 randsel_value = value;
1725 float mapvote_nextthink;
1726 float mapvote_initialized;
1727 float mapvote_keeptwotime;
1728 float mapvote_timeout;
1729 string mapvote_message;
1731 #define MAPVOTE_COUNT 10
1732 float mapvote_count;
1733 string mapvote_maps[MAPVOTE_COUNT];
1734 float mapvote_maps_suggested[MAPVOTE_COUNT];
1735 string mapvote_suggestions[MAPVOTE_COUNT];
1736 float mapvote_suggestion_ptr;
1737 float mapvote_maxlen;
1738 float mapvote_voters;
1739 float mapvote_votes[MAPVOTE_COUNT];
1743 void MapVote_ClearAllVotes()
1745 FOR_EACH_CLIENT(other)
1749 string MapVote_Suggest(string m)
1753 return "That's not how to use this command.";
1754 if(!cvar("g_maplist_votable_suggestions"))
1755 return "Suggestions are not accepted on this server.";
1756 if(mapvote_initialized)
1757 return "Can't suggest - voting is already in progress!";
1758 if(!cvar("g_maplist_votable_suggestions_change_gametype"))
1759 if(!IsSameGametype(m))
1760 return "This server does not allow changing the game type by map suggestions.";
1761 if(!cvar("g_maplist_votable_override_mostrecent"))
1763 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1767 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1769 return "The map you suggested is not available on this server.";
1770 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1771 if(mapvote_suggestions[i] == m)
1772 return "This map was already suggested.";
1773 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1775 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1779 i = mapvote_suggestion_ptr;
1780 mapvote_suggestion_ptr += 1;
1782 if(mapvote_suggestions[i] != "")
1783 strunzone(mapvote_suggestions[i]);
1784 mapvote_suggestions[i] = strzone(m);
1785 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1786 return "Suggestion accepted.";
1789 void MapVote_AddVotable(string nextMap, float isSuggestion)
1794 for(j = 0; j < mapvote_count; ++j)
1795 if(mapvote_maps[j] == nextMap)
1797 if(strlen(nextMap) > mapvote_maxlen)
1798 mapvote_maxlen = strlen(nextMap);
1799 mapvote_maps[mapvote_count] = strzone(nextMap);
1800 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1809 MapVote_ClearAllVotes();
1811 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1812 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1815 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1816 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1818 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1819 MapVote_AddVotable(GetNextMap(), FALSE);
1821 if(mapvote_count == 0)
1823 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1826 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1828 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1829 MapVote_AddVotable(GetNextMap(), FALSE);
1832 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1834 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1835 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1836 if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1837 mapvote_keeptwotime = 0;
1838 mapvote_message = "Choose a map and press its key!";
1840 float MapVote_Finished(float mappos)
1845 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1846 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1847 for(i = 0; i < mapvote_count; ++i)
1849 if(mapvote_maps[i] != "")
1851 result = strcat(result, ":", mapvote_maps[i]);
1852 result = strcat(result, ":", ftos(mapvote_votes[i]));
1854 GameLogEcho(result, FALSE);
1855 if(mapvote_maps_suggested[mappos])
1856 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1858 FOR_EACH_REALCLIENT(other)
1859 FixClientCvars(other);
1861 Map_Goto_SetStr(mapvote_maps[mappos]);
1863 alreadychangedlevel = TRUE;
1866 void MapVote_CheckRules_1()
1870 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1872 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1873 mapvote_votes[i] = 0;
1877 FOR_EACH_REALCLIENT(other)
1882 i = other.mapvote - 1;
1883 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1884 mapvote_votes[i] = mapvote_votes[i] + 1;
1889 float MapVote_CheckRules_2()
1892 float firstPlace, secondPlace;
1893 float firstPlaceVotes, secondPlaceVotes;
1897 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1898 RandSel_Add(mapvote_votes[i], i);
1899 firstPlace = randsel_value;
1900 firstPlaceVotes = randsel_priority;
1901 //dprint("First place: ", ftos(firstPlace), "\n");
1902 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1905 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1907 RandSel_Add(mapvote_votes[i], i);
1908 secondPlace = randsel_value;
1909 secondPlaceVotes = randsel_priority;
1910 //dprint("Second place: ", ftos(secondPlace), "\n");
1911 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1913 if(firstPlace == -1)
1914 error("No first place in map vote... WTF?");
1916 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1917 return MapVote_Finished(firstPlace);
1919 if(mapvote_keeptwotime)
1920 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1922 mapvote_message = "Now decide between the TOP TWO!";
1923 mapvote_keeptwotime = 0;
1924 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1925 result = strcat(result, ":", ftos(firstPlaceVotes));
1926 result = strcat(result, ":", mapvote_maps[secondPlace]);
1927 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1928 for(i = 0; i < mapvote_count; ++i)
1930 if(i != secondPlace)
1931 if(mapvote_maps[i] != "")
1933 result = strcat(result, ":", mapvote_maps[i]);
1934 result = strcat(result, ":", ftos(mapvote_votes[i]));
1935 strunzone(mapvote_maps[i]);
1936 mapvote_maps[i] = "";
1938 GameLogEcho(result, FALSE);
1950 keeptwo = mapvote_keeptwotime;
1951 MapVote_CheckRules_1(); // count
1952 if(MapVote_CheckRules_2()) // decide
1955 FOR_EACH_REALCLIENT(other)
1957 // hide scoreboard again
1958 if(other.health != 2342)
1960 other.health = 2342;
1962 if(clienttype(other) == CLIENTTYPE_REAL)
1964 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");
1966 WriteByte(MSG_ONE, SVC_FINALE);
1967 WriteString(MSG_ONE, "");
1969 for(i = 0; i < mapvote_count; ++i)
1970 if(mapvote_maps[i] != "")
1972 tmp = mapvote_maps[i];
1973 sprint(other, strcat("map voting: type ^1impulse ", ftos(i+1), "^7 to vote for ", tmp, "\n"));
1979 // notify about keep-two
1980 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1981 play2(other, "misc/invshot.wav");
1983 // clear possibly invalid votes
1984 if(mapvote_maps[other.mapvote - 1] == "")
1986 // use impulses as new vote
1987 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1988 if(mapvote_maps[other.impulse - 1] != "")
1989 other.mapvote = other.impulse;
1993 MapVote_CheckRules_1(); // just count
1995 FOR_EACH_REALCLIENT(other)
1997 // display voting screen
1998 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1999 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2000 msgstr = strcat(msgstr, mapvote_message);
2001 msgstr = strcat(msgstr, "\n\n");
2002 for(i = 0; i < mapvote_count; ++i)
2003 if(mapvote_maps[i] == "")
2004 msgstr = strcat(msgstr, "\n");
2007 tmp = mapvote_maps[i];
2008 tmp = strpad(mapvote_maxlen, tmp);
2009 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
2010 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2011 if(mapvote_votes[i] != 1)
2012 tmp = strcat(tmp, "s");
2013 tmp = strcat(tmp, ")");
2014 tmp = strpad(mapvote_maxlen + 15, tmp);
2015 if(other.mapvote == i + 1)
2016 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2018 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2020 i = ceil(mapvote_timeout - time);
2021 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
2023 msgstr = strcat(msgstr, "s");
2024 msgstr = strcat(msgstr, " left");
2026 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2029 void MapVote_Start()
2033 void MapVote_Think()
2038 if(alreadychangedlevel)
2041 if(time < mapvote_nextthink)
2045 mapvote_nextthink = time + 0.5;
2047 if(!mapvote_initialized)
2049 mapvote_initialized = TRUE;
2050 if(DoNextMapOverride())
2052 if(!cvar("g_maplist_votable") || player_count <= 0)
2063 string GotoMap(string m)
2067 if(!TryFile(strcat("maps/", m, ".mapcfg")))
2069 return "The map you chose is not available on this server.";
2070 cvar_set("nextmap", m);
2071 cvar_set("timelimit", "-1");
2072 if(mapvote_initialized || alreadychangedlevel)
2074 if(DoNextMapOverride())
2075 return "Map switch initiated.";
2077 return "Hm... no. For some reason I like THIS map more.";
2080 return "Map switch will happen after scoreboard.";
2086 FOR_EACH_REALCLIENT(self)
2088 if(self.classname == "spectator")
2090 if(self.enemy.hitsound)
2091 play2(self, "misc/hit.wav");
2096 play2(self, "misc/hit.wav");
2099 FOR_EACH_CLIENT(self)
2100 self.hitsound = FALSE;
2106 * returns TRUE if redirecting
2108 float redirection_timeout;
2109 float redirection_nextthink;
2110 float RedirectionThink()
2112 float clients_found;
2114 if(redirection_target == "")
2117 if(!redirection_timeout)
2119 cvar_set("sv_public", "-2");
2120 redirection_timeout = time + 0.5; // this will only try twice... should be able to keep more clients
2121 if(redirection_target == "self")
2122 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2124 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2127 if(time < redirection_nextthink)
2130 redirection_nextthink = time + 1;
2133 FOR_EACH_REALCLIENT(self)
2135 ServerConsoleEcho(strcat("Redirecting: sending connect command to ", self.netname), FALSE);
2136 if(redirection_target == "self")
2137 stuffcmd(self, "\ndisconnect; reconnect\n");
2139 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2143 ServerConsoleEcho(strcat("Redirecting: ", ftos(clients_found), " clients left."), FALSE);
2145 if(time > redirection_timeout || clients_found == 0)
2146 localcmd("\nwait; wait; wait; quit\n");