1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
2 string redirection_target;
3 float world_initialized;
9 float() DoNextMapOverride;
11 void SetDefaultAlpha()
13 if(cvar("g_running_guns"))
15 default_player_alpha = -1;
16 default_weapon_alpha = +1;
20 default_player_alpha = cvar("g_balance_cloaked_alpha");
21 default_weapon_alpha = default_player_alpha;
25 default_player_alpha = cvar("g_player_alpha");
26 if(default_player_alpha <= 0)
27 default_player_alpha = 1;
28 default_weapon_alpha = default_player_alpha;
32 void fteqcc_testbugs()
36 if(!cvar("developer_fteqccbugs"))
39 dprint("*** fteqcc test: checking for bugs...\n");
43 if(sqrt(a) - sqrt(b - a) == 0)
44 dprint("*** fteqcc test: found same-function-twice bug\n");
46 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
50 world.enemy.cnt += 10;
51 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
52 dprint("*** fteqcc test: found += bug\n");
54 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
59 * Takes care of pausing and unpausing the game.
60 * Centerprints the information about an upcoming or active timeout to all active
61 * players. Also plays reminder sounds.
63 void timeoutHandler_Think() {
66 if (timeoutStatus == 1) {
67 if (remainingLeadTime > 0) {
68 //centerprint the information to every player
69 timeStr = getTimeoutText(0);
70 FOR_EACH_REALCLIENT(plr) {
71 if(plr.classname == "player") {
72 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
75 remainingLeadTime -= 1;
76 //think again in 1 second:
77 self.nextthink = time + 1;
82 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
83 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
84 FOR_EACH_REALPLAYER(plr) {
85 plr.lastV_angle = plr.v_angle;
87 self.nextthink = time;
90 else if (timeoutStatus == 2) {
91 if (remainingTimeoutTime > 0) {
92 timeStr = getTimeoutText(0);
93 FOR_EACH_REALCLIENT(plr) {
94 if(plr.classname == "player") {
95 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
98 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
99 play2all("announcer/robotic/prepareforbattle.wav");
101 remainingTimeoutTime -= 1;
102 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
105 //unpause the game again
106 remainingTimeoutTime = timeoutStatus = 0;
107 cvar_set("slowmo", ftos(orig_slowmo));
108 //and unlock the fixed view again once there is no timeout active anymore
109 FOR_EACH_REALPLAYER(plr) {
110 plr.fixangle = FALSE;
112 //get rid of the countdown message
113 FOR_EACH_REALCLIENT(plr) {
114 if(plr.classname == "player") {
115 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
123 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
124 FOR_EACH_REALCLIENT(plr) {
125 if(plr.classname == "player") {
126 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
138 cvar_set("_sv_init", "0");
139 if(cvar("g_maplist_shuffle"))
141 tokenizebyseparator(cvar_string("g_maplist"), " ");
143 cvar_set("nextmap", argv(0));
146 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 0);
148 if(!DoNextMapOverride())
157 void cvar_changes_init()
164 strunzone(cvar_changes);
165 cvar_changes = string_null;
166 fh = fopen("cvars.txt", FILE_READ);
169 while((s = fgets(fh)))
171 n = tokenize_sane(s);
178 d = cvar_defstring(k);
181 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
182 if(strlen(cvar_changes) > 16384)
184 cvar_changes = "// too many settings have been changed to show them here\n";
190 if(cvar_changes == "")
191 cvar_changes = "// this server runs at default settings\n";
193 cvar_changes = strcat("// this server runs at modified settings:\n", cvar_changes);
194 cvar_changes = strzone(cvar_changes);
197 void detect_maptype()
206 o_x += random() * (world.maxs_x - world.mins_x);
207 o_y += random() * (world.maxs_y - world.mins_y);
208 o_z += random() * (world.maxs_z - world.mins_z);
210 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
211 if(trace_fraction == 1)
216 for(i = 0; i < 64; i += 4)
218 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
219 if(trace_fraction == 1)
221 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
229 float world_already_spawned;
230 void RegisterWeapons();
232 void spawnfunc_worldspawn (void)
234 float fd, l, i, j, n;
237 dprint_load(); // load dprint status from cvar
239 if(world_already_spawned)
240 error("world already spawned - you may have EXACTLY ONE worldspawn!");
241 world_already_spawned = TRUE;
243 remove = remove_safely; // during spawning, watch what you remove!
245 if(cvar_string("cvar_check_default") != "bypass")
247 if(cvar_string("cvar_check_default") != CVAR_CHECK_DEFAULT)
248 error("Config file mismatch! Please update defaultNexuiz.cfg to match the QuakeC code!");
250 if(cvar_string("cvar_check_weapons") != CVAR_CHECK_WEAPONS)
251 error("Config file mismatch! Please update weapons.cfg and weaponsPro.cfg to match the QuakeC code!");
254 compressShortVector_init();
257 head = nextent(world);
262 head = nextent(head);
265 // needs to be done so early as they would still spawn
270 world_initialized = -1; // don't complain
275 ServerProgsDB = db_create();
277 ServerProgsDB = db_load("server.db");
279 TemporaryDB = db_create();
282 TODO sound pack system
283 // initialize sound pack system
284 soundpack = cvar_string("g_soundpack");
286 soundpack = strcat(soundpack, "/");
287 soundpack = strzone(soundpack);
293 // 1 FLICKER (first variety)
294 lightstyle(1, "mmnmmommommnonmmonqnmmo");
296 // 2 SLOW STRONG PULSE
297 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
299 // 3 CANDLE (first variety)
300 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
303 lightstyle(4, "mamamamamama");
306 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
308 // 6 FLICKER (second variety)
309 lightstyle(6, "nmonqnmomnmomomno");
311 // 7 CANDLE (second variety)
312 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
314 // 8 CANDLE (third variety)
315 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
317 // 9 SLOW STROBE (fourth variety)
318 lightstyle(9, "aaaaaaaazzzzzzzz");
320 // 10 FLUORESCENT FLICKER
321 lightstyle(10, "mmamammmmammamamaaamammma");
323 // 11 SLOW PULSE NOT FADE TO BLACK
324 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
326 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
331 if(cvar("g_campaign"))
339 bot_waypoints_for_items = cvar("g_waypoints_for_items");
340 if(bot_waypoints_for_items == 1)
341 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
342 bot_waypoints_for_items = 0;
344 // for setting by mapinfo
345 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
346 cvar_set("sv_q3acompat_machineshotgunswap", "0");
350 WaypointSprite_Init();
355 GameLogInit(); // prepare everything
356 if(cvar("sv_eventlog"))
358 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
359 s = strcat(s, ftos(random()));
360 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
361 s = ":gameinfo:mutators:LIST";
362 if(cvar("g_grappling_hook"))
363 s = strcat(s, ":grappling_hook");
364 if(!cvar("g_use_ammunition"))
365 s = strcat(s, ":no_use_ammunition");
366 if(!cvar("g_pickup_items"))
367 s = strcat(s, ":no_pickup_items");
368 if(cvar("g_instagib"))
369 s = strcat(s, ":instagib");
370 if(cvar_string("g_weaponarena") != "0")
371 s = strcat(s, ":", cvar_string("g_weaponarena"), " arena");
373 s = strcat(s, ":nixnex");
374 if(cvar("g_vampire"))
375 s = strcat(s, ":vampire");
376 if(cvar("g_laserguided_missile"))
377 s = strcat(s, ":laserguided_missile");
378 if(cvar("g_norecoil"))
379 s = strcat(s, ":norecoil");
381 s = strcat(s, ":midair");
382 if(cvar("g_minstagib"))
383 s = strcat(s, ":minstagib");
385 GameLogEcho(":gameinfo:end");
388 cvar_set("nextmap", "");
392 if(cvar("g_campaign"))
399 //initialise globals related to sv_timeout
400 sys_ticrate = cvar("sys_ticrate");
401 orig_slowmo = cvar("slowmo");
404 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
406 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
408 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
411 while((s = fgets(fd)))
413 l = tokenize_sane(s);
418 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
419 print(" cdtrack ", argv(2), "\n");
421 else if(argv(0) == "fog")
423 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
424 print(" \"fog\" \"", s, "\"\n");
426 else if(argv(0) == "set")
428 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
429 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
431 else if(argv(0) != "//")
433 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
434 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
441 addstat(STAT_SYS_TICRATE, AS_FLOAT, stat_sys_ticrate);
442 addstat(STAT_WEAPONS, AS_INT, weapons);
443 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
444 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
447 next_pingtime = time + 5;
448 InitializeEntity(self, cvar_changes_init, INITPRIO_CVARS);
452 lsmaps_reply = "^7Maps available: ";
453 for(i = 0, j = 0; i < MapInfo_count; ++i)
455 if(MapInfo_Get_ByID(i))
456 if not(MapInfo_Map_flags & MAPINFO_FLAG_HIDDEN)
463 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
466 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
468 maplist_reply = "^7Maps in list: ";
469 n = tokenize_sane(cvar_string("g_maplist"));
470 for(i = 0, j = 0; i < n; ++i)
472 if(MapInfo_CheckMap(argv(i)))
478 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
482 maplist_reply = strzone(strcat(maplist_reply, "\n"));
484 records_reply = strzone(getrecords());
486 world_initialized = 1;
489 void spawnfunc_light (void)
491 //makestatic (self); // Who the f___ did that?
495 float TryFile( string pFilename )
498 dprint("TryFile(\"", pFilename, "\")\n");
499 lHandle = fopen( pFilename, FILE_READ );
500 if( lHandle != -1 ) {
510 return GametypeNameFromType(game);
513 string getmapname_stored;
519 float Map_Count, Map_Current;
520 string Map_Current_Name;
522 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
523 float GetMaplistPosition()
529 idx = cvar("g_maplist_index");
536 for(pos = 0; pos < Map_Count; ++pos)
540 // resume normal maplist rotation if current map is not in g_maplist
544 float MapHasRightSize(string map)
547 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
548 if(cvar("g_maplist_check_waypoints"))
550 dprint("checkwp "); dprint(map);
551 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
554 dprint(": no waypoints\n");
557 dprint(": has waypoints\n");
561 // open map size restriction file
562 dprint("opensize "); dprint(map);
563 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
566 float mapmin, mapmax;
568 mapmin = stof(fgets(fh));
569 mapmax = stof(fgets(fh));
571 if(player_count < mapmin)
573 dprint("not enough\n");
576 if(player_count > mapmax)
578 dprint("too many\n");
581 dprint("right size\n");
584 dprint(": not found\n");
588 string Map_Filename(float position)
590 return strcat("maps/", argv(position), ".bsp");
593 string strwords(string s, float w)
596 for(endpos = 0; w && endpos >= 0; --w)
597 endpos = strstrofs(s, " ", endpos + 1);
601 return substring(s, 0, endpos);
604 float strhasword(string s, string w)
606 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
609 void Map_MarkAsRecent(string m)
611 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), cvar("g_maplist_mostrecent_count")));
614 float Map_IsRecent(string m)
616 return strhasword(cvar_string("g_maplist_mostrecent"), m);
619 float Map_Check(float position, float pass)
623 map_next = argv(position);
626 if(map_next == Map_Current_Name) // same map again in first pass?
628 if(Map_IsRecent(map_next))
631 filename = Map_Filename(position);
632 if(MapInfo_CheckMap(map_next))
636 if(MapHasRightSize(map_next))
641 dprint( "Couldn't select '", filename, "'..\n" );
646 void Map_Goto_SetStr(string nextmapname)
648 if(getmapname_stored != "")
649 strunzone(getmapname_stored);
650 if(nextmapname == "")
651 getmapname_stored = "";
653 getmapname_stored = strzone(nextmapname);
656 void Map_Goto_SetFloat(float position)
658 cvar_set("g_maplist_index", ftos(position));
659 Map_Goto_SetStr(argv(position));
664 // settings persist, except...
665 if(cvar("g_campaign"))
666 localcmd("\nexec mutator_reset.cfg\n");
667 localcmd("\nsettemp_restore\n");
672 Map_MarkAsRecent(getmapname_stored);
674 MapInfo_LoadMap(getmapname_stored);
677 // return codes of map selectors:
678 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
679 // -2 = permanent failure
680 float() MaplistMethod_Iterate = // usual method
684 for(pass = 1; pass <= 2; ++pass)
686 for(i = 1; i < Map_Count; ++i)
689 mapindex = mod(i + Map_Current, Map_Count);
690 if(Map_Check(mapindex, pass))
697 float() MaplistMethod_Repeat = // fallback method
699 if(Map_Check(Map_Current, 2))
704 float() MaplistMethod_Random = // random map selection
710 for(i = 0; i <= imax; ++i)
713 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
714 if(Map_Check(mapindex, 1))
720 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
721 // the exponent sets a bias on the map selection:
722 // the higher the exponent, the less likely "shortly repeated" same maps are
724 float i, j, imax, insertpos;
728 for(i = 0; i <= imax; ++i)
732 // now reinsert this at another position
733 insertpos = pow(random(), 1 / exponent); // ]0, 1]
734 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
735 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
736 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
738 // insert the current map there
740 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
741 newlist = strcat(newlist, " ", argv(j));
742 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
743 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
744 newlist = strcat(newlist, " ", argv(j));
745 newlist = substring(newlist, 1, strlen(newlist) - 1);
746 cvar_set("g_maplist", newlist);
747 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
749 // NOTE: the selected map has just been inserted at (insertpos-1)th position
750 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
751 if(Map_Check(Map_Current, 1))
759 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
762 bprint( "Maplist is empty! Resetting it to default map list.\n" );
763 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
765 localcmd("\nmenu_cmd sync\n");
766 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
769 error("empty maplist, cannot select a new map");
770 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
773 strunzone(Map_Current_Name);
774 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
775 // this may or may not be correct, but who cares, in the worst case a map
776 // isn't chosen in the first pass that should have been
787 if(cvar("g_maplist_shuffle") > 0)
788 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
791 if(cvar("g_maplist_selectrandom"))
792 nextMap = MaplistMethod_Random();
795 nextMap = MaplistMethod_Iterate();
798 nextMap = MaplistMethod_Repeat();
802 Map_Goto_SetFloat(nextMap);
803 return getmapname_stored;
809 float DoNextMapOverride()
811 if(cvar("g_campaign"))
813 CampaignPostIntermission();
814 alreadychangedlevel = TRUE;
817 if(cvar("quit_when_empty"))
819 if(player_count <= currentbots)
822 alreadychangedlevel = TRUE;
826 if(cvar_string("quit_and_redirect") != "")
828 redirection_target = strzone(cvar_string("quit_and_redirect"));
829 alreadychangedlevel = TRUE;
832 if (cvar("samelevel")) // if samelevel is set, stay on same level
834 // 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)
835 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
836 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
837 localcmd("restart\n");
838 //changelevel (mapname);
839 alreadychangedlevel = TRUE;
842 if(cvar_string("nextmap") != "")
843 if(MapInfo_CheckMap(cvar_string("nextmap")))
845 Map_Goto_SetStr(cvar_string("nextmap"));
847 alreadychangedlevel = TRUE;
850 if(cvar("lastlevel"))
853 localcmd("set lastlevel 0\ntogglemenu\n");
854 alreadychangedlevel = TRUE;
862 //local string nextmap;
863 //local float n, nummaps;
865 if (alreadychangedlevel)
867 alreadychangedlevel = TRUE;
873 for(allowReset = 1; allowReset >= 0; --allowReset)
875 nextMap = GetNextMap();
881 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
882 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
884 localcmd("\nmenu_cmd sync\n");
888 error("Everything is broken - not even the default map list works. Please report this to the developers.");
900 When the player presses attack or jump, change to the next level
903 .float autoscreenshot;
904 void() MapVote_Start;
905 void() MapVote_Think;
906 float mapvote_initialized;
907 void IntermissionThink()
909 FixIntermissionClient(self);
911 if(cvar("sv_autoscreenshot"))
912 if(self.autoscreenshot > 0)
913 if(time > self.autoscreenshot)
915 self.autoscreenshot = -1;
916 if(clienttype(self) == CLIENTTYPE_REAL)
917 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
921 if (time < intermission_exittime)
924 if(!mapvote_initialized)
925 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_HOOK && !self.BUTTON_USE)
935 Returns the entity to view from
939 entity FindIntermission()
944 // look for info_intermission first
945 spot = find (world, classname, "info_intermission");
947 { // pick a random one
951 spot = find (spot, classname, "info_intermission");
953 spot = find (spot, classname, "info_intermission");
959 // then look for the start position
960 spot = find (world, classname, "info_player_start");
964 // testinfo_player_start is only found in regioned levels
965 spot = find (world, classname, "testplayerstart");
969 // then look for the start position
970 spot = find (world, classname, "info_player_deathmatch");
974 //objerror ("FindIntermission: no spot");
980 ===============================================================================
984 ===============================================================================
987 void DumpStats(float final)
991 local float to_console;
992 local float to_eventlog;
996 to_console = cvar("sv_logscores_console");
997 to_eventlog = cvar("sv_eventlog");
998 to_file = cvar("sv_logscores_file");
1002 to_console = TRUE; // always print printstats replies
1003 to_eventlog = FALSE; // but never print them to the event log
1007 if(cvar("sv_eventlog_console"))
1008 to_console = FALSE; // otherwise we get the output twice
1014 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
1022 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
1026 fputs(file, strcat(s, "\n"));
1029 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
1035 fputs(file, strcat(s, "\n"));
1037 FOR_EACH_CLIENT(other)
1039 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
1041 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
1042 s = strcat(s, ftos(rint(time - other.jointime)), ":");
1043 if(other.classname == "player" || g_arena || g_lms)
1044 s = strcat(s, ftos(other.team), ":");
1046 s = strcat(s, "spectator:");
1049 print(s, other.netname, "\n");
1051 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
1053 fputs(file, strcat(s, other.netname, "\n"));
1059 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
1065 fputs(file, strcat(s, "\n"));
1067 for(i = 1; i < 16; ++i)
1069 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
1070 s = strcat(s, ":", ftos(i));
1076 fputs(file, strcat(s, "\n"));
1083 GameLogEcho(":end");
1086 fputs(file, ":end\n");
1091 void FixIntermissionClient(entity e)
1094 if(!e.autoscreenshot) // initial call
1096 e.angles = e.v_angle;
1097 e.angles_x = -e.angles_x;
1098 e.autoscreenshot = time + 0.8; // used for autoscreenshot
1100 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
1101 e.solid = SOLID_NOT;
1102 e.movetype = MOVETYPE_NONE;
1103 e.takedamage = DAMAGE_NO;
1105 e.weaponentity.effects = EF_NODRAW;
1106 if(clienttype(e) == CLIENTTYPE_REAL)
1108 stuffcmd(e, "\nscr_printspeed 1000000\n");
1109 s = cvar_string("sv_intermission_cdtrack");
1111 stuffcmd(e, strcat("\ncd loop ", s, "\n"));
1113 WriteByte(MSG_ONE, SVC_INTERMISSION);
1117 //e.velocity = '0 0 0';
1118 //e.fixangle = TRUE;
1120 // TODO halt weapon animation
1125 go to the next level for deathmatch
1126 only called if a time or frag limit has expired
1130 float minTotalFrags;
1131 float maxTotalFrags;
1137 intermission_running = 1;
1139 // enforce a wait time before allowing changelevel
1140 if(player_count > 0)
1141 intermission_exittime = time + cvar("sv_mapchange_delay");
1143 intermission_exittime = -1;
1146 WriteByte (MSG_ALL, SVC_CDTRACK);
1147 WriteByte (MSG_ALL, 3);
1148 WriteByte (MSG_ALL, 3);
1149 // done in FixIntermission
1152 //pos = FindIntermission ();
1158 if(cvar("sv_eventlog"))
1159 GameLogEcho(":gameover");
1163 FOR_EACH_CLIENT(other)
1165 FixIntermissionClient(other);
1168 bprint(other.netname, " ^7wins.\n");
1173 FOR_EACH_PLAYER(other)
1175 if(maxTotalFrags < other.totalfrags)
1176 maxTotalFrags = other.totalfrags;
1177 if(minTotalFrags > other.totalfrags)
1178 minTotalFrags = other.totalfrags;
1183 FOR_EACH_PLAYER(other)
1185 score = (other.totalfrags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1186 f = bound(0, other.play_time / max(time, 1), 1);
1187 // store some statistics?
1191 if(cvar("g_campaign"))
1192 CampaignPreIntermission();
1194 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1201 Exit deathmatch games upon conditions
1204 void CheckRules_Player()
1206 if (gameover) // someone else quit the game already
1209 if(self.deadflag == DEAD_NO)
1210 self.play_time += frametime;
1212 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
1213 // (div0: and that in CheckRules_World please)
1216 float checkrules_oneminutewarning;
1218 float checkrules_equality;
1219 float checkrules_overtimewarning;
1220 float checkrules_overtimeend;
1222 void InitiateOvertime()
1224 if(!checkrules_overtimeend)
1225 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1228 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1229 float WINNING_YES = 1; // winner found
1230 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1231 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1233 float GetWinningCode(float fraglimitreached, float equality)
1236 if(fraglimitreached)
1237 return WINNING_STARTOVERTIME;
1239 return WINNING_NEVER;
1241 if(fraglimitreached)
1247 // set the .winning flag for exactly those players with a given field value
1248 void SetWinners(.float field, float value)
1251 FOR_EACH_PLAYER(head)
1252 head.winning = (head.field == value);
1255 // set the .winning flag for those players with a given field value
1256 void AddWinners(.float field, float value)
1259 FOR_EACH_PLAYER(head)
1260 if(head.field == value)
1264 // clear the .winning flags
1265 void ClearWinners(void)
1268 FOR_EACH_PLAYER(head)
1272 // Onslaught winning condition:
1273 // game terminates if only one team has a working generator (or none)
1274 float WinningCondition_Onslaught()
1277 local float t1, t2, t3, t4;
1279 WinningConditionHelper(); // set worldstatus
1281 // first check if the game has ended
1282 t1 = t2 = t3 = t4 = 0;
1283 head = find(world, classname, "onslaught_generator");
1286 if (head.health > 0)
1288 if (head.team == COLOR_TEAM1) t1 = 1;
1289 if (head.team == COLOR_TEAM2) t2 = 1;
1290 if (head.team == COLOR_TEAM3) t3 = 1;
1291 if (head.team == COLOR_TEAM4) t4 = 1;
1293 head = find(head, classname, "onslaught_generator");
1295 if (t1 + t2 + t3 + t4 < 2)
1297 // game over, only one team remains (or none)
1299 if (t1) SetWinners(team, COLOR_TEAM1);
1300 if (t2) SetWinners(team, COLOR_TEAM2);
1301 if (t3) SetWinners(team, COLOR_TEAM3);
1302 if (t4) SetWinners(team, COLOR_TEAM4);
1303 dprint("Have a winner, ending game.\n");
1307 // Two or more teams remain
1311 float LMS_NewPlayerLives()
1314 fl = cvar("fraglimit");
1318 // first player has left the game for dying too much? Nobody else can get in.
1319 if(lms_lowest_lives < 1)
1322 if(!cvar("g_lms_join_anytime"))
1323 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1326 return bound(1, lms_lowest_lives, fl);
1329 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
1330 // they win. Otherwise the defending team wins once the timelimit passes.
1331 void assault_new_round();
1332 float WinningCondition_Assault()
1336 WinningConditionHelper(); // set worldstatus
1338 status = WINNING_NO;
1339 // as the timelimit has not yet passed just assume the defending team will win
1340 if(assault_attacker_team == COLOR_TEAM1)
1342 SetWinners(team, COLOR_TEAM2);
1346 SetWinners(team, COLOR_TEAM1);
1350 ent = find(world, classname, "target_assault_roundend");
1353 if(ent.winning) // round end has been triggered by attacking team
1355 bprint("ASSAULT: round completed...\n");
1356 SetWinners(team, assault_attacker_team);
1358 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
1360 if(ent.cnt == 1) // this was the second round
1362 status = WINNING_YES;
1366 local entity oldself;
1369 assault_new_round();
1378 // LMS winning condition: game terminates if and only if there's at most one
1379 // one player who's living lives. Top two scores being equal cancels the time
1381 float WinningCondition_LMS()
1388 have_player = FALSE;
1389 have_players = FALSE;
1390 l = LMS_NewPlayerLives();
1392 head = find(world, classname, "player");
1395 head2 = find(head, classname, "player");
1397 have_players = TRUE;
1401 // we have at least one player
1404 // two or more active players - continue with the game
1408 // exactly one player?
1411 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1415 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
1421 // and assign him his first place
1422 PlayerScore_Add(head, SP_LMS_RANK, 1);
1429 // nobody is playing at all...
1432 // wait for players...
1436 // SNAFU (maybe a draw game?)
1438 dprint("No players, ending game.\n");
1443 // When we get here, we have at least two players who are actually LIVING,
1444 // now check if the top two players have equal score.
1445 WinningConditionHelper();
1448 if(WinningConditionHelper_winner)
1449 WinningConditionHelper_winner.winning = TRUE;
1450 if(WinningConditionHelper_equality)
1451 return WINNING_NEVER;
1453 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1457 void ShuffleMaplist()
1465 result = cvar_string("g_maplist");
1466 litems = tokenizebyseparator(result, " ");
1468 for(start = 0; start < litems - 1; ++start)
1472 // select a random item
1473 selected = floor(random() * (litems - start) + start);
1475 // shift this item to the place start
1476 for(i = 0; i < start; ++i)
1477 result = strcat(result, " ", argv(i));
1478 result = strcat(result, " ", argv(selected));
1479 for(i = start; i < litems; ++i)
1481 result = strcat(result, " ", argv(i));
1482 result = substring(result, 1, strlen(result) - 1);
1484 litems = tokenizebyseparator(result, " ");
1486 //dprint(result, "\n");
1489 cvar_set("g_maplist", result);
1493 float WinningCondition_Scores(float limit)
1495 // TODO make everything use THIS winning condition (except LMS)
1496 WinningConditionHelper();
1500 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
1501 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
1502 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
1503 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
1507 if(WinningConditionHelper_winner)
1508 WinningConditionHelper_winner.winning = 1;
1509 if(WinningConditionHelper_winnerteam >= 0)
1510 SetWinners(team, WinningConditionHelper_winnerteam);
1512 if(WinningConditionHelper_lowerisbetter)
1514 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
1518 if(g_dm || g_tdm || g_arena || (g_race && !g_race_qualifying))
1519 // these modes always score in increments of 1, thus this makes sense
1521 if(leaderfrags != WinningConditionHelper_topscore)
1523 leaderfrags = WinningConditionHelper_topscore;
1525 if (leaderfrags == limit - 1)
1526 play2all("announcer/robotic/1fragleft.wav");
1527 else if (leaderfrags == limit - 2)
1528 play2all("announcer/robotic/2fragsleft.wav");
1529 else if (leaderfrags == limit - 3)
1530 play2all("announcer/robotic/3fragsleft.wav");
1534 return GetWinningCode(limit && WinningConditionHelper_topscore && (WinningConditionHelper_topscore >= limit), WinningConditionHelper_equality);
1537 float WinningCondition_Race(float fraglimit)
1541 wc = WinningCondition_Scores(fraglimit);
1543 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
1544 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1545 // do NOT support equality when the laps are all raced!
1548 if not(p.race_completed)
1549 return WINNING_STARTOVERTIME;
1555 void ReadyRestart();
1556 float WinningCondition_QualifyingThenRace(float limit)
1559 wc = WinningCondition_Scores(limit);
1561 // NEVER initiate overtime
1562 if(wc == WINNING_YES || wc == WINNING_STARTOVERTIME)
1570 float WinningCondition_RanOutOfSpawns()
1574 if(!have_team_spawns)
1577 if(!some_spawn_has_been_used)
1580 team1_score = team2_score = team3_score = team4_score = 0;
1582 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
1584 if(head.team == COLOR_TEAM1)
1586 else if(head.team == COLOR_TEAM2)
1588 else if(head.team == COLOR_TEAM3)
1590 else if(head.team == COLOR_TEAM4)
1594 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
1596 if(head.team == COLOR_TEAM1)
1598 else if(head.team == COLOR_TEAM2)
1600 else if(head.team == COLOR_TEAM3)
1602 else if(head.team == COLOR_TEAM4)
1607 if(team1_score + team2_score + team3_score + team4_score == 0)
1609 checkrules_equality = TRUE;
1612 else if(team1_score + team2_score + team3_score + team4_score == 1)
1615 if(team1_score) t = COLOR_TEAM1;
1616 if(team2_score) t = COLOR_TEAM2;
1617 if(team3_score) t = COLOR_TEAM3;
1618 if(team4_score) t = COLOR_TEAM4;
1619 CheckAllowedTeams(world);
1620 for(i = 0; i < MAX_TEAMSCORE; ++i)
1622 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
1623 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
1624 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
1625 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
1628 AddWinners(team, t);
1639 Exit deathmatch games upon conditions
1642 void CheckRules_World()
1645 local float timelimit;
1646 local float fraglimit;
1654 MapVote_Think should now do that part
1655 if (intermission_running)
1656 if (time >= intermission_exittime + 60)
1658 if(!DoNextMapOverride())
1664 if (gameover) // someone else quit the game already
1666 if(player_count == 0) // Nobody there? Then let's go to the next map
1668 // this will actually check the player count in the next frame
1669 // again, but this shouldn't hurt
1673 timelimit = cvar("timelimit") * 60;
1674 fraglimit = cvar("fraglimit");
1676 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
1679 timelimit = 0; // timelimit is not made for warmup
1681 fraglimit = 0; // no fraglimit for now
1685 timelimit += game_starttime;
1687 if(checkrules_overtimeend)
1689 if(!checkrules_overtimewarning)
1691 checkrules_overtimewarning = TRUE;
1692 //announceall("announcer/robotic/1minuteremains.wav");
1693 if(g_race && !g_race_qualifying)
1694 bcenterprint("^3Everyone, finish your lap! The race is over!");
1696 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1701 if (timelimit && time >= timelimit)
1703 if(g_race && g_race_qualifying == 2 && timelimit > 0)
1706 float playerswithlaps;
1709 totalplayers = playerswithlaps = readyplayers = 0;
1710 FOR_EACH_PLAYER(head)
1713 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
1719 // at least 2/3 of the players have completed a lap: start the RACE
1720 // otherwise, the players should end the qualifying on their own
1721 if(readyplayers || ((totalplayers >= 3) && (playerswithlaps * 3 >= totalplayers * 2)))
1723 checkrules_overtimeend = 0;
1724 ReadyRestart(); // go to race
1734 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1740 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1742 checkrules_oneminutewarning = TRUE;
1743 play2all("announcer/robotic/1minuteremains.wav");
1746 status = WinningCondition_RanOutOfSpawns();
1747 if(status == WINNING_YES)
1749 bprint("Hey! Someone ran out of spawns!\n");
1751 else if(g_race && !g_race_qualifying && timelimit >= 0)
1753 status = WinningCondition_Race(fraglimit);
1755 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
1757 status = WinningCondition_QualifyingThenRace(fraglimit);
1761 status = WinningCondition_Assault(); // TODO remove this?
1765 status = WinningCondition_LMS();
1767 else if (g_onslaught)
1769 status = WinningCondition_Onslaught(); // TODO remove this?
1773 status = WinningCondition_Scores(fraglimit);
1776 if(status == WINNING_STARTOVERTIME)
1778 status = WINNING_NEVER;
1782 if(status == WINNING_NEVER)
1783 // equality cases! Nobody wins if the overtime ends in a draw.
1786 if(checkrules_overtimeend)
1787 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1788 status = WINNING_YES;
1790 if(status == WINNING_YES)
1794 float mapvote_nextthink;
1795 float mapvote_initialized;
1796 float mapvote_keeptwotime;
1797 float mapvote_timeout;
1798 string mapvote_message;
1799 string mapvote_screenshot_dir;
1801 float mapvote_count;
1802 float mapvote_count_real;
1803 string mapvote_maps[MAPVOTE_COUNT];
1804 float mapvote_maps_suggested[MAPVOTE_COUNT];
1805 string mapvote_suggestions[MAPVOTE_COUNT];
1806 float mapvote_suggestion_ptr;
1807 float mapvote_maxlen;
1808 float mapvote_voters;
1809 float mapvote_votes[MAPVOTE_COUNT];
1811 float mapvote_detail;
1812 float mapvote_abstain;
1813 float mapvote_dirty;
1816 void MapVote_ClearAllVotes()
1818 FOR_EACH_CLIENT(other)
1822 string MapVote_Suggest(string m)
1826 return "That's not how to use this command.";
1827 if(!cvar("g_maplist_votable_suggestions"))
1828 return "Suggestions are not accepted on this server.";
1829 if(mapvote_initialized)
1830 return "Can't suggest - voting is already in progress!";
1831 m = MapInfo_FixName(m);
1833 return "The map you suggested is not available on this server.";
1834 if(!cvar("g_maplist_votable_override_mostrecent"))
1836 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
1838 if(!MapInfo_CheckMap(m))
1839 return "The map you suggested does not support the current game mode.";
1840 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1841 if(mapvote_suggestions[i] == m)
1842 return "This map was already suggested.";
1843 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1845 i = floor(random() * mapvote_suggestion_ptr);
1849 i = mapvote_suggestion_ptr;
1850 mapvote_suggestion_ptr += 1;
1852 if(mapvote_suggestions[i] != "")
1853 strunzone(mapvote_suggestions[i]);
1854 mapvote_suggestions[i] = strzone(m);
1855 if(cvar("sv_eventlog"))
1856 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
1857 return strcat("Suggestion of ", m, " accepted.");
1860 void MapVote_AddVotable(string nextMap, float isSuggestion)
1865 for(j = 0; j < mapvote_count; ++j)
1866 if(mapvote_maps[j] == nextMap)
1868 if(strlen(nextMap) > mapvote_maxlen)
1869 mapvote_maxlen = strlen(nextMap);
1870 mapvote_maps[mapvote_count] = strzone(nextMap);
1871 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1875 void MapVote_SendData(float target);
1881 MapVote_ClearAllVotes();
1884 mapvote_detail = !cvar("g_maplist_votable_nodetail");
1885 mapvote_abstain = cvar("g_maplist_votable_abstain");
1888 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
1890 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1891 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
1893 if(mapvote_suggestion_ptr)
1894 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1895 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
1897 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1898 MapVote_AddVotable(GetNextMap(), FALSE);
1900 if(mapvote_count == 0)
1902 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1903 cvar_set("g_maplist", MapInfo_ListAllowedMaps(0, MAPINFO_FLAG_HIDDEN));
1905 localcmd("\nmenu_cmd sync\n");
1906 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1907 MapVote_AddVotable(GetNextMap(), FALSE);
1910 mapvote_count_real = mapvote_count;
1912 MapVote_AddVotable("don't care", 0);
1914 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1916 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1917 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1918 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
1919 mapvote_keeptwotime = 0;
1920 mapvote_message = "Choose a map and press its key!";
1922 mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
1923 if(mapvote_screenshot_dir == "")
1924 mapvote_screenshot_dir = "maps";
1925 mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
1927 if(!cvar("g_maplist_textonly"))
1928 MapVote_SendData(MSG_ALL);
1931 void MapVote_SendPicture(float id)
1934 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1935 WriteByte(MSG_ONE, TE_CSQC_MAPVOTE);
1936 WriteByte(MSG_ONE, MAPVOTE_NET_PIC);
1937 WriteByte(MSG_ONE, id);
1938 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
1941 float GameCommand_MapVote(string cmd)
1943 if(!intermission_running)
1945 if(!cvar("g_maplist_textonly"))
1947 if(cmd == "mv_getpic")
1949 MapVote_SendPicture(stof(argv(1)));
1957 float MapVote_GetMapMask()
1959 float mask, i, power;
1961 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
1962 if(mapvote_maps[i] != "")
1967 void MapVote_SendData(float targ)
1969 string mapfile, pakfile;
1971 WriteByte(targ, SVC_TEMPENTITY);
1972 WriteByte(targ, TE_CSQC_CONFIG);
1973 WriteString(targ, "mv_screenshot_dir");
1974 WriteString(targ, mapvote_screenshot_dir);
1976 WriteByte(targ, SVC_TEMPENTITY);
1977 WriteByte(targ, TE_CSQC_MAPVOTE);
1978 WriteByte(targ, MAPVOTE_NET_INIT);
1980 WriteByte(targ, mapvote_count);
1981 WriteByte(targ, mapvote_abstain);
1982 WriteByte(targ, mapvote_detail);
1983 WriteCoord(targ, mapvote_timeout);
1984 if(mapvote_count <= 8)
1985 WriteByte(targ, MapVote_GetMapMask());
1987 WriteShort(targ, MapVote_GetMapMask());
1988 for(i = 0; i < mapvote_count; ++i)
1989 if(mapvote_maps[i] != "")
1991 WriteString(targ, mapvote_maps[i]);
1992 mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
1993 pakfile = whichpack(strcat(mapfile, ".tga"));
1995 pakfile = whichpack(strcat(mapfile, ".jpg"));
1997 pakfile = whichpack(strcat(mapfile, ".png"));
1998 print("pakfile is ", pakfile, "\n");
1999 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
2000 pakfile = substring(pakfile, o, 999);
2001 WriteString(targ, pakfile);
2005 void MapVote_UpdateData(float targ)
2008 WriteByte(targ, SVC_TEMPENTITY);
2009 WriteByte(targ, TE_CSQC_MAPVOTE);
2010 WriteByte(targ, MAPVOTE_NET_UPDATE);
2011 if(mapvote_count <= 8)
2012 WriteByte(targ, MapVote_GetMapMask());
2014 WriteShort(targ, MapVote_GetMapMask());
2016 for(i = 0; i < mapvote_count; ++i)
2017 if(mapvote_maps[i] != "")
2018 WriteByte(targ, mapvote_votes[i]);
2021 void MapVote_TellVote(float targ, float vote)
2023 WriteByte(targ, SVC_TEMPENTITY);
2024 WriteByte(targ, TE_CSQC_MAPVOTE);
2025 WriteByte(targ, MAPVOTE_NET_OWNVOTE);
2026 WriteByte(targ, vote);
2029 float MapVote_Finished(float mappos)
2035 if(cvar("sv_eventlog"))
2037 result = strcat(":vote:finished:", mapvote_maps[mappos]);
2038 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
2039 didntvote = mapvote_voters;
2040 for(i = 0; i < mapvote_count; ++i)
2041 if(mapvote_maps[i] != "")
2043 didntvote -= mapvote_votes[i];
2046 result = strcat(result, ":", mapvote_maps[i]);
2047 result = strcat(result, ":", ftos(mapvote_votes[i]));
2050 result = strcat(result, ":didn't vote:", ftos(didntvote));
2052 GameLogEcho(result);
2053 if(mapvote_maps_suggested[mappos])
2054 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
2057 FOR_EACH_REALCLIENT(other)
2058 FixClientCvars(other);
2060 Map_Goto_SetStr(mapvote_maps[mappos]);
2062 alreadychangedlevel = TRUE;
2065 void MapVote_CheckRules_1()
2069 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
2071 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
2072 mapvote_votes[i] = 0;
2076 FOR_EACH_REALCLIENT(other)
2081 i = other.mapvote - 1;
2082 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
2083 mapvote_votes[i] = mapvote_votes[i] + 1;
2088 float MapVote_CheckRules_2()
2091 float firstPlace, secondPlace;
2092 float firstPlaceVotes, secondPlaceVotes;
2093 float mapvote_voters_real;
2096 mapvote_voters_real = mapvote_voters;
2098 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
2100 RandomSelection_Init();
2101 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2102 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2103 firstPlace = RandomSelection_chosen_float;
2104 firstPlaceVotes = RandomSelection_best_priority;
2105 //dprint("First place: ", ftos(firstPlace), "\n");
2106 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
2108 RandomSelection_Init();
2109 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
2111 RandomSelection_Add(world, i, 1, mapvote_votes[i]);
2112 secondPlace = RandomSelection_chosen_float;
2113 secondPlaceVotes = RandomSelection_best_priority;
2114 //dprint("Second place: ", ftos(secondPlace), "\n");
2115 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
2117 if(firstPlace == -1)
2118 error("No first place in map vote... WTF?");
2120 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
2121 return MapVote_Finished(firstPlace);
2123 if(mapvote_keeptwotime)
2124 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
2127 mapvote_dirty = TRUE;
2128 mapvote_message = "Now decide between the TOP TWO!";
2129 mapvote_keeptwotime = 0;
2130 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
2131 result = strcat(result, ":", ftos(firstPlaceVotes));
2132 result = strcat(result, ":", mapvote_maps[secondPlace]);
2133 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
2134 didntvote = mapvote_voters;
2135 for(i = 0; i < mapvote_count; ++i)
2136 if(mapvote_maps[i] != "")
2138 didntvote -= mapvote_votes[i];
2140 if(i != secondPlace)
2142 result = strcat(result, ":", mapvote_maps[i]);
2143 result = strcat(result, ":", ftos(mapvote_votes[i]));
2144 if(i < mapvote_count_real)
2146 strunzone(mapvote_maps[i]);
2147 mapvote_maps[i] = "";
2151 result = strcat(result, ":didn't vote:", ftos(didntvote));
2152 if(cvar("sv_eventlog"))
2153 GameLogEcho(result);
2166 keeptwo = mapvote_keeptwotime;
2167 MapVote_CheckRules_1(); // count
2168 if(MapVote_CheckRules_2()) // decide
2172 FOR_EACH_REALCLIENT(other)
2174 // hide scoreboard again
2175 if(other.health != 2342)
2177 other.health = 2342;
2179 if(clienttype(other) == CLIENTTYPE_REAL)
2181 if(cvar("g_maplist_textonly"))
2182 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");
2185 WriteByte(MSG_ONE, SVC_FINALE);
2186 WriteString(MSG_ONE, "");
2190 // notify about keep-two
2191 if(keeptwo != 0 && mapvote_keeptwotime == 0)
2192 play2(other, "misc/invshot.wav");
2194 // clear possibly invalid votes
2195 if(mapvote_maps[other.mapvote - 1] == "")
2197 // use impulses as new vote
2198 if(other.impulse >= 1 && other.impulse <= mapvote_count)
2199 if(mapvote_maps[other.impulse - 1] != "")
2201 other.mapvote = other.impulse;
2203 mapvote_dirty = TRUE;
2206 MapVote_TellVote(MSG_ONE, other.mapvote);
2214 MapVote_CheckRules_1(); // just count
2216 if(!cvar("g_maplist_textonly"))
2217 if(mapvote_dirty) // 1 if "keeptwo" or "impulse" happened before
2219 MapVote_UpdateData(MSG_BROADCAST);
2220 mapvote_dirty = FALSE;
2223 if(cvar("g_maplist_textonly"))
2225 FOR_EACH_REALCLIENT(other)
2227 // display voting screen
2228 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
2229 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
2231 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
2232 msgstr = strcat(msgstr, mapvote_message);
2233 msgstr = strcat(msgstr, "\n\n");
2234 for(i = 0; i < mapvote_count; ++i)
2235 if(mapvote_maps[i] == "")
2236 msgstr = strcat(msgstr, "\n");
2239 tmp = mapvote_maps[i];
2240 tmp = strpad(mapvote_maxlen, tmp);
2241 tmp = strcat(ftos(mod(i + 1, 10)), ": ", tmp);
2244 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2245 if(mapvote_votes[i] != 1)
2246 tmp = strcat(tmp, "s");
2247 tmp = strcat(tmp, ")");
2248 tmp = strpad(mapvote_maxlen + 15, tmp);
2251 if(i == mapvote_count - 1)
2252 msgstr = strcat(msgstr, "\n");
2253 if(other.mapvote == i + 1)
2254 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2256 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2259 msgstr = strcat(msgstr, "\n\n^2", ftos(totalvotes), " vote");
2261 msgstr = strcat(msgstr, "s");
2262 msgstr = strcat(msgstr, " cast");
2263 i = ceil(mapvote_timeout - time);
2264 msgstr = strcat(msgstr, "\n", ftos(i), " second");
2266 msgstr = strcat(msgstr, "s");
2267 msgstr = strcat(msgstr, " left");
2269 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2273 void MapVote_Start()
2278 MapInfo_Enumerate();
2279 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1))
2282 void MapVote_Think()
2287 if(alreadychangedlevel)
2290 if(time < mapvote_nextthink)
2294 mapvote_nextthink = time + 0.5;
2296 if(!mapvote_initialized)
2298 mapvote_initialized = TRUE;
2299 if(DoNextMapOverride())
2301 if(!cvar("g_maplist_votable") || player_count <= 0)
2312 string GotoMap(string m)
2314 if(!MapInfo_CheckMap(m))
2315 return "The map you chose is not available on this server.";
2316 cvar_set("nextmap", m);
2317 cvar_set("timelimit", "-1");
2318 if(mapvote_initialized || alreadychangedlevel)
2320 if(DoNextMapOverride())
2321 return "Map switch initiated.";
2323 return "Hm... no. For some reason I like THIS map more.";
2326 return "Map switch will happen after scoreboard.";
2332 FOR_EACH_REALCLIENT(self)
2334 if(self.classname == "spectator")
2336 if(self.enemy.typehitsound)
2337 play2(self, "misc/typehit.wav");
2338 else if(self.enemy.hitsound)
2339 play2(self, "misc/hit.wav");
2343 if(self.typehitsound)
2344 play2(self, "misc/typehit.wav");
2345 else if(self.hitsound)
2346 play2(self, "misc/hit.wav");
2349 FOR_EACH_CLIENT(self)
2351 self.hitsound = FALSE;
2352 self.typehitsound = FALSE;
2359 * returns TRUE if redirecting
2361 float redirection_timeout;
2362 float redirection_nextthink;
2363 float RedirectionThink()
2365 float clients_found;
2367 if(redirection_target == "")
2370 if(!redirection_timeout)
2372 cvar_set("sv_public", "-2");
2373 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
2374 if(redirection_target == "self")
2375 bprint("^3SERVER NOTICE:^7 restarting the server\n");
2377 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
2380 if(time < redirection_nextthink)
2383 redirection_nextthink = time + 1;
2386 FOR_EACH_REALCLIENT(self)
2388 print("Redirecting: sending connect command to ", self.netname, "\n");
2389 if(redirection_target == "self")
2390 stuffcmd(self, "\ndisconnect; reconnect\n");
2392 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
2396 print("Redirecting: ", ftos(clients_found), " clients left.\n");
2398 if(time > redirection_timeout || clients_found == 0)
2399 localcmd("\nwait; wait; wait; quit\n");
2406 // Loaded from a save game
2407 // some things then break, so let's work around them...
2409 // Progs DB (capture records)
2411 ServerProgsDB = db_create();
2413 ServerProgsDB = db_load("server.db");
2417 MapInfo_Enumerate();
2418 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), 0, (g_maplist_allow_hidden ? MAPINFO_FLAG_HIDDEN : 0), 1);
2423 if(world_initialized > 0)
2425 world_initialized = 0;
2426 print("Saving persistent data...\n");
2429 db_save(ServerProgsDB, "server.db");
2430 if(cvar("developer"))
2431 db_save(TemporaryDB, "server-temp.db");
2432 db_close(ServerProgsDB);
2433 db_close(TemporaryDB);
2435 // tell the bot system the game is ending now
2440 else if(world_initialized == 0)
2442 print("NOTE: crashed before even initializing the world, not saving persistent data\n");