2 void PingPLReport_Think()
\r
7 delta = 3 / maxclients;
\r
8 if(delta < sys_frametime)
\r
10 self.nextthink = time + delta;
\r
12 e = edict_num(self.cnt + 1);
\r
13 if(clienttype(e) == CLIENTTYPE_REAL)
\r
15 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
\r
16 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
\r
17 WriteByte(MSG_BROADCAST, self.cnt);
\r
18 WriteShort(MSG_BROADCAST, max(1, e.ping));
\r
19 WriteByte(MSG_BROADCAST, ceil(e.ping_packetloss * 255));
\r
20 WriteByte(MSG_BROADCAST, ceil(e.ping_movementloss * 255));
\r
24 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
\r
25 WriteByte(MSG_BROADCAST, TE_CSQC_PINGPLREPORT);
\r
26 WriteByte(MSG_BROADCAST, self.cnt);
\r
27 WriteShort(MSG_BROADCAST, 0);
\r
28 WriteByte(MSG_BROADCAST, 0);
\r
29 WriteByte(MSG_BROADCAST, 0);
\r
31 self.cnt = mod(self.cnt + 1, maxclients);
\r
33 void PingPLReport_Spawn()
\r
35 pingplreport = spawn();
\r
36 pingplreport.classname = "pingplreport";
\r
37 pingplreport.think = PingPLReport_Think;
\r
38 pingplreport.nextthink = time;
\r
41 entity otherplreport;
\r
42 void OtherPLReport_Think()
\r
46 self.nextthink = time;
\r
48 e = edict_num(self.cnt + 1);
\r
49 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
\r
50 WriteByte(MSG_BROADCAST, TE_CSQC_OTHERPLREPORT);
\r
51 WriteByte(MSG_BROADCAST, self.cnt);
\r
52 if(e.stat_eaten) // tempt hackers less by only sending the info of eaten players
\r
54 if(cvar("g_vore_showhealth"))
\r
55 WriteByte(MSG_BROADCAST, e.health);
\r
57 WriteByte(MSG_BROADCAST, 0);
\r
58 WriteByte(MSG_BROADCAST, num_for_edict(e.predator));
\r
62 WriteByte(MSG_BROADCAST, 0);
\r
63 WriteByte(MSG_BROADCAST, 0);
\r
65 self.cnt = mod(self.cnt + 1, maxclients);
\r
68 void OtherPLReport_Spawn()
\r
70 otherplreport = spawn();
\r
71 otherplreport.classname = "otherplreport";
\r
72 otherplreport.think = OtherPLReport_Think;
\r
73 otherplreport.nextthink = time;
\r
76 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
\r
77 string redirection_target;
\r
78 float world_initialized;
\r
80 string GetMapname();
\r
81 string GetGametype();
\r
83 void ShuffleMaplist()
\r
84 float() DoNextMapOverride;
\r
86 void SetDefaultAlpha()
\r
88 if(cvar("g_running_guns"))
\r
90 default_player_alpha = -1;
\r
91 default_weapon_alpha = +1;
\r
95 default_player_alpha = cvar("g_balance_cloaked_alpha");
\r
96 default_weapon_alpha = default_player_alpha;
\r
100 default_player_alpha = cvar("g_player_alpha");
\r
101 if(default_player_alpha == 0)
\r
102 default_player_alpha = 1;
\r
103 default_weapon_alpha = default_player_alpha;
\r
107 void fteqcc_testbugs()
\r
111 if(!cvar("developer_fteqccbugs"))
\r
114 dprint("*** fteqcc test: checking for bugs...\n");
\r
118 if(sqrt(a) - sqrt(b - a) == 0)
\r
119 dprint("*** fteqcc test: found same-function-twice bug\n");
\r
121 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
\r
124 world.enemy = world;
\r
125 world.enemy.cnt += 10;
\r
126 if(world.cnt > 0.2 || world.cnt < -0.2) // don't error out if it's just roundoff errors
\r
127 dprint("*** fteqcc test: found += bug\n");
\r
129 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
\r
134 * Takes care of pausing and unpausing the game.
\r
135 * Centerprints the information about an upcoming or active timeout to all active
\r
136 * players. Also plays reminder sounds.
\r
138 void timeoutHandler_Think() {
\r
139 local string timeStr;
\r
141 if (timeoutStatus == 1) {
\r
142 if (remainingLeadTime > 0) {
\r
143 //centerprint the information to every player
\r
144 timeStr = getTimeoutText(0);
\r
145 FOR_EACH_REALCLIENT(plr) {
\r
146 if(plr.classname == "player") {
\r
147 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
\r
150 remainingLeadTime -= 1;
\r
151 //think again in 1 second:
\r
152 self.nextthink = time + 1;
\r
155 //now pause the game:
\r
157 //reset all the flood variables
\r
158 FOR_EACH_CLIENT(plr) {
\r
159 plr.nickspamcount = plr.nickspamtime = plr.floodcontrol_chat = plr.floodcontrol_chatteam = plr.floodcontrol_chattell = plr.floodcontrol_voice = plr.floodcontrol_voiceteam = 0;
\r
161 cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
\r
162 //copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
\r
163 FOR_EACH_REALPLAYER(plr) {
\r
164 plr.lastV_angle = plr.v_angle;
\r
166 self.nextthink = time;
\r
169 else if (timeoutStatus == 2) {
\r
170 if (remainingTimeoutTime > 0) {
\r
171 timeStr = getTimeoutText(0);
\r
172 FOR_EACH_REALCLIENT(plr) {
\r
173 if(plr.classname == "player") {
\r
174 centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
\r
177 if(remainingTimeoutTime == cvar("sv_timeout_resumetime")) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
\r
178 Announce("prepareforbattle");
\r
180 remainingTimeoutTime -= 1;
\r
181 self.nextthink = time + TIMEOUT_SLOWMO_VALUE;
\r
184 //unpause the game again
\r
185 remainingTimeoutTime = timeoutStatus = 0;
\r
186 cvar_set("slowmo", ftos(orig_slowmo));
\r
187 //and unlock the fixed view again once there is no timeout active anymore
\r
188 FOR_EACH_REALPLAYER(plr) {
\r
189 plr.fixangle = FALSE;
\r
191 //get rid of the countdown message
\r
192 FOR_EACH_REALCLIENT(plr) {
\r
193 if(plr.classname == "player") {
\r
194 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
\r
202 else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
\r
203 FOR_EACH_REALCLIENT(plr) {
\r
204 if(plr.classname == "player") {
\r
205 centerprint_atprio(plr, CENTERPRIO_SPAM, "");
\r
213 void GotoFirstMap()
\r
216 if(cvar("_sv_init"))
\r
218 // cvar_set("_sv_init", "0");
\r
219 // we do NOT set this to 0 any more, so someone "accidentally" changing
\r
220 // to this "init" map on a dedicated server will cause no permanent
\r
222 if(cvar("g_maplist_shuffle"))
\r
224 n = tokenizebyseparator(cvar_string("g_maplist"), " ");
\r
225 cvar_set("g_maplist_index", ftos(n - 1)); // jump to map 0 in GotoNextMap
\r
227 MapInfo_Enumerate();
\r
228 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
\r
230 if(!DoNextMapOverride())
\r
238 self.nextthink = time;
\r
242 self.nextthink = time + 1;
\r
243 print("Waiting for _sv_init being set to 1 by initialization scripts...\n");
\r
247 void cvar_changes_init()
\r
254 strunzone(cvar_changes);
\r
255 cvar_changes = string_null;
\r
258 buf_cvarlist(h, "", "_"); // exclude all _ cvars as they are temporary
\r
259 n = buf_getsize(h);
\r
261 for(i = 0; i < n; ++i)
\r
263 k = bufstr_get(h, i);
\r
265 #define BADPREFIX(p) if(substring(k, 0, strlen(p)) == p) continue
\r
266 #define BADCVAR(p) if(k == p) continue
\r
268 BADPREFIX("csqc_");
\r
269 BADPREFIX("cvar_check_");
\r
270 BADCVAR("gamecfg");
\r
271 BADCVAR("g_configversion");
\r
272 BADCVAR("g_maplist_index");
\r
273 BADCVAR("halflifebsp");
\r
278 BADPREFIX("g_campaign");
\r
281 BADPREFIX("menu_");
\r
282 BADPREFIX("net_slist_");
\r
284 BADPREFIX("sbar_");
\r
286 BADPREFIX("userbind");
\r
289 BADPREFIX("crosshair");
\r
290 BADCVAR("mod_q3bsp_lightmapmergepower");
\r
291 BADCVAR("mod_q3bsp_nolightmaps");
\r
294 BADCVAR("serverconfig");
\r
295 BADPREFIX("g_ban_");
\r
296 BADPREFIX("g_chat_flood_");
\r
297 BADPREFIX("g_voice_flood_");
\r
298 BADPREFIX("rcon_");
\r
299 BADPREFIX("settemp_");
\r
300 BADPREFIX("sv_allowdownloads_");
\r
301 BADPREFIX("sv_autodemo");
\r
302 BADPREFIX("sv_curl_");
\r
303 BADPREFIX("sv_eventlog");
\r
304 BADPREFIX("sv_logscores_");
\r
305 BADPREFIX("sv_master");
\r
306 BADCVAR("g_banned_list");
\r
307 BADCVAR("log_dest_udp");
\r
308 BADCVAR("log_file");
\r
309 BADCVAR("net_address");
\r
311 BADCVAR("savedgamecfg");
\r
312 BADCVAR("sv_heartbeatperiod");
\r
313 BADCVAR("sv_vote_master_password");
\r
314 BADCVAR("sys_colortranslation");
\r
315 BADCVAR("sys_specialcharactertranslation");
\r
316 BADCVAR("timestamps");
\r
319 BADCVAR("timelimit");
\r
320 BADCVAR("fraglimit");
\r
321 BADCVAR("g_arena");
\r
323 BADCVAR("g_assault");
\r
326 BADCVAR("g_domination");
\r
327 BADCVAR("g_keyhunt");
\r
328 BADCVAR("g_keyhunt_teams");
\r
329 BADCVAR("g_onslaught");
\r
334 BADCVAR("teamplay");
\r
337 BADCVAR("hostname");
\r
338 BADCVAR("g_maplist");
\r
339 BADCVAR("g_maplist_mostrecent");
\r
340 BADCVAR("sv_motd");
\r
344 v = cvar_string(k);
\r
345 d = cvar_defstring(k);
\r
348 cvar_changes = strcat(cvar_changes, k, " \"", v, "\" // \"", d, "\"\n");
\r
349 if(strlen(cvar_changes) > 16384)
\r
351 cvar_changes = "// too many settings have been changed to show them here\n";
\r
357 if(cvar_changes == "")
\r
358 cvar_changes = "// this server runs at default settings\n";
\r
360 cvar_changes = strcat("// this server runs at modified settings:\n", cvar_changes);
\r
361 cvar_changes = strzone(cvar_changes);
\r
364 void detect_maptype()
\r
373 o_x += random() * (world.maxs_x - world.mins_x);
\r
374 o_y += random() * (world.maxs_y - world.mins_y);
\r
375 o_z += random() * (world.maxs_z - world.mins_z);
\r
377 tracebox(o, PL_MIN, PL_MAX, o - '0 0 32768', MOVE_WORLDONLY, world);
\r
378 if(trace_fraction == 1)
\r
383 for(i = 0; i < 64; i += 4)
\r
385 tracebox(o, '-1 -1 -1' * i, '1 1 1' * i, o - '0 0 32768', MOVE_WORLDONLY, world);
\r
386 if(trace_fraction == 1)
\r
388 print(ftos(i), " -> ", vtos(trace_endpos), "\n");
\r
397 float RandomSeed_Send(entity to, float sf)
\r
399 WriteByte(MSG_ENTITY, ENT_CLIENT_RANDOMSEED);
\r
400 WriteShort(MSG_ENTITY, self.cnt);
\r
403 void RandomSeed_Think()
\r
405 self.cnt = bound(0, floor(random() * 65536), 65535);
\r
406 self.nextthink = time + 5;
\r
408 self.SendFlags |= 1;
\r
410 void RandomSeed_Spawn()
\r
412 randomseed = spawn();
\r
413 randomseed.think = RandomSeed_Think;
\r
414 Net_LinkEntity(randomseed, FALSE, 0, RandomSeed_Send);
\r
419 self.think(); // sets random seed and nextthink
\r
423 void spawnfunc___init_dedicated_server(void)
\r
425 // handler for _init/_init map (only for dedicated server initialization)
\r
427 world_initialized = -1; // don't complain
\r
428 cvar = cvar_normal;
\r
429 cvar_string = cvar_string_normal;
\r
430 cvar_set = cvar_set_normal;
\r
432 remove = remove_unsafely;
\r
436 e.think = GotoFirstMap;
\r
437 e.nextthink = time; // this is usually 1 at this point
\r
440 e.classname = "info_player_deathmatch"; // safeguard against player joining
\r
442 self.classname = "worldspawn"; // safeguard against various stuff ;)
\r
444 MapInfo_Enumerate();
\r
445 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
\r
448 void Map_MarkAsRecent(string m);
\r
449 float world_already_spawned;
\r
450 void RegisterWeapons();
\r
451 void Nagger_Init();
\r
452 void ClientInit_Spawn();
\r
453 void WeaponStats_Init();
\r
454 void WeaponStats_Shutdown();
\r
455 void spawnfunc_worldspawn (void)
\r
457 float fd, l, i, j, n;
\r
460 cvar = cvar_normal;
\r
461 cvar_string = cvar_string_normal;
\r
462 cvar_set = cvar_set_normal;
\r
464 if(world_already_spawned)
\r
465 error("world already spawned - you may have EXACTLY ONE worldspawn!");
\r
466 world_already_spawned = TRUE;
\r
468 remove = remove_safely; // during spawning, watch what you remove!
\r
470 check_unacceptable_compiler_bugs();
\r
472 compressShortVector_init();
\r
475 head = nextent(world);
\r
480 head = nextent(head);
\r
483 // needs to be done so early as they would still spawn
\r
486 ServerProgsDB = db_load("server.db");
\r
488 TemporaryDB = db_create();
\r
491 TODO sound pack system
\r
492 // initialize sound pack system
\r
493 soundpack = cvar_string("g_soundpack");
\r
494 if(soundpack != "")
\r
495 soundpack = strcat(soundpack, "/");
\r
496 soundpack = strzone(soundpack);
\r
500 lightstyle(0, "m");
\r
502 // 1 FLICKER (first variety)
\r
503 lightstyle(1, "mmnmmommommnonmmonqnmmo");
\r
505 // 2 SLOW STRONG PULSE
\r
506 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
\r
508 // 3 CANDLE (first variety)
\r
509 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
\r
512 lightstyle(4, "mamamamamama");
\r
514 // 5 GENTLE PULSE 1
\r
515 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
\r
517 // 6 FLICKER (second variety)
\r
518 lightstyle(6, "nmonqnmomnmomomno");
\r
520 // 7 CANDLE (second variety)
\r
521 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
\r
523 // 8 CANDLE (third variety)
\r
524 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
\r
526 // 9 SLOW STROBE (fourth variety)
\r
527 lightstyle(9, "aaaaaaaazzzzzzzz");
\r
529 // 10 FLUORESCENT FLICKER
\r
530 lightstyle(10, "mmamammmmammamamaaamammma");
\r
532 // 11 SLOW PULSE NOT FADE TO BLACK
\r
533 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
\r
535 // styles 32-62 are assigned by the spawnfunc_light program for switchable lights
\r
538 lightstyle(63, "a");
\r
540 if(cvar("g_campaign"))
\r
543 Map_MarkAsRecent(mapname);
\r
545 precache_model ("null"); // we need this one before InitGameplayMode
\r
546 InitGameplayMode();
\r
551 bot_waypoints_for_items = cvar("g_waypoints_for_items");
\r
552 if(bot_waypoints_for_items == 1)
\r
553 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
\r
554 bot_waypoints_for_items = 0;
\r
556 // for setting by mapinfo
\r
557 q3acompat_machineshotgunswap = cvar("sv_q3acompat_machineshotgunswap");
\r
558 cvar_set("sv_q3acompat_machineshotgunswap", "0");
\r
562 WaypointSprite_Init();
\r
564 //if (g_domination)
\r
567 GameLogInit(); // prepare everything
\r
568 if(cvar("sv_eventlog"))
\r
570 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
\r
571 s = strcat(s, ftos(random()));
\r
572 matchid = strzone(s);
\r
574 GameLogEcho(strcat(":gamestart:", GetGametype(), "_", GetMapname(), ":", s));
\r
575 s = ":gameinfo:mutators:LIST";
\r
576 if(!cvar("g_use_ammunition"))
\r
577 s = strcat(s, ":no_use_ammunition");
\r
578 if(!cvar("g_pickup_items"))
\r
579 s = strcat(s, ":no_pickup_items");
\r
580 if(cvar("g_vampire"))
\r
581 s = strcat(s, ":vampire");
\r
582 if(cvar("g_norecoil"))
\r
583 s = strcat(s, ":norecoil");
\r
584 if(cvar("g_midair"))
\r
585 s = strcat(s, ":midair");
\r
587 GameLogEcho(":gameinfo:end");
\r
590 matchid = strzone(ftos(random()));
\r
592 cvar_set("nextmap", "");
\r
596 if(cvar("g_campaign"))
\r
597 CampaignPostInit();
\r
603 MapInfo_Enumerate();
\r
604 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
\r
606 if(whichpack(strcat("maps/", mapname, ".cfg")) != "")
\r
608 fd = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
\r
611 while((s = fgets(fd)))
\r
613 l = tokenize_console(s);
\r
616 if(argv(0) == "cd")
\r
618 print("Found ^1DEPRECATED^7 cd loop command in .cfg file; put this line in mapinfo instead:\n");
\r
619 print(" cdtrack ", argv(2), "\n");
\r
621 else if(argv(0) == "fog")
\r
623 print("Found ^1DEPRECATED^7 fog command in .cfg file; put this line in worldspawn in the .map/.bsp/.ent file instead:\n");
\r
624 print(" \"fog\" \"", s, "\"\n");
\r
626 else if(argv(0) == "set")
\r
628 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
\r
629 print(" clientsettemp_for_type all ", argv(1), " ", argv(2), "\n");
\r
631 else if(argv(0) != "//")
\r
633 print("Found ^1DEPRECATED^7 set command in .cfg file; put this line in mapinfo instead:\n");
\r
634 print(" clientsettemp_for_type all ", argv(0), " ", argv(1), "\n");
\r
641 WeaponStats_Init();
\r
643 addstat(STAT_WEAPONS, AS_INT, weapons);
\r
644 addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
\r
645 addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
\r
646 addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
\r
649 addstat(STAT_STRENGTH_FINISHED, AS_FLOAT, strength_finished);
\r
650 addstat(STAT_INVINCIBLE_FINISHED, AS_FLOAT, invincible_finished);
\r
651 addstat(STAT_PRESSED_KEYS, AS_FLOAT, pressedkeys);
\r
652 addstat(STAT_FUEL, AS_INT, ammo_fuel);
\r
653 addstat(STAT_DAMAGE_HITS, AS_INT, stat_hit);
\r
654 addstat(STAT_DAMAGE_FIRED, AS_INT, stat_fired);
\r
655 addstat(STAT_SHOTORG, AS_INT, stat_shotorg);
\r
656 addstat(STAT_LEADLIMIT, AS_FLOAT, stat_leadlimit);
\r
657 addstat(STAT_WEAPON_CLIPLOAD, AS_INT, clip_load);
\r
658 addstat(STAT_WEAPON_CLIPSIZE, AS_INT, clip_size);
\r
659 addstat(STAT_LAST_PICKUP, AS_FLOAT, last_pickup);
\r
660 addstat(STAT_WINNING, AS_FLOAT, winning);
\r
661 addstat(STAT_VORE_LOAD, AS_INT, stat_stomachload);
\r
662 addstat(STAT_VORE_CANSWALLOW, AS_INT, stat_canswallow);
\r
663 addstat(STAT_VORE_DIGESTING, AS_INT, stat_digesting);
\r
664 addstat(STAT_VORE_EATEN, AS_INT, stat_eaten);
\r
665 addstat(STAT_VORE_CANLEAVE, AS_INT, stat_canleave);
\r
667 next_pingtime = time + 5;
\r
668 InitializeEntity(self, cvar_changes_init, INITPRIO_CVARS);
\r
672 lsmaps_reply = "^7Maps available: ";
\r
673 lsnewmaps_reply = "^7Maps without a record set: ";
\r
674 for(i = 0, j = 0; i < MapInfo_count; ++i)
\r
676 if(MapInfo_Get_ByID(i))
\r
677 if not(MapInfo_Map_flags & (MAPINFO_FLAG_HIDDEN | MAPINFO_FLAG_FORBIDDEN))
\r
684 lsmaps_reply = strcat(lsmaps_reply, col, MapInfo_Map_bspname, " ");
\r
685 if(g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))))
\r
686 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
\r
687 else if(g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))))
\r
688 lsnewmaps_reply = strcat(lsnewmaps_reply, col, MapInfo_Map_bspname, " ");
\r
691 lsmaps_reply = strzone(strcat(lsmaps_reply, "\n"));
\r
692 if (!g_race && !g_cts)
\r
693 lsnewmaps_reply = "Need to be playing race or CTS for lsnewmaps to work.";
\r
694 lsnewmaps_reply = strzone(strcat(lsnewmaps_reply, "\n"));
\r
696 maplist_reply = "^7Maps in list: ";
\r
697 n = tokenize_console(cvar_string("g_maplist"));
\r
698 for(i = 0, j = 0; i < n; ++i)
\r
700 if(MapInfo_CheckMap(argv(i)))
\r
706 maplist_reply = strcat(maplist_reply, col, argv(i), " ");
\r
710 maplist_reply = strzone(strcat(maplist_reply, "\n"));
\r
711 MapInfo_ClearTemps();
\r
713 for(i = 0; i < 10; ++i)
\r
715 records_reply[i] = strzone(getrecords(i));
\r
718 rankings_reply = strzone(getrankings());
\r
720 ClientInit_Spawn();
\r
721 RandomSeed_Spawn();
\r
722 PingPLReport_Spawn();
\r
723 OtherPLReport_Spawn();
\r
727 localcmd("\n_sv_hook_gamestart ", GetGametype(), ";");
\r
728 if(cvar("g_campaign"))
\r
729 localcmd("\n_sv_hook_campaign_gamestart ", GetGametype(), ";");
\r
731 world_initialized = 1;
\r
734 void spawnfunc_light (void)
\r
736 //makestatic (self); // Who the f___ did that?
\r
740 float TryFile( string pFilename )
\r
742 local float lHandle;
\r
743 dprint("TryFile(\"", pFilename, "\")\n");
\r
744 lHandle = fopen( pFilename, FILE_READ );
\r
745 if( lHandle != -1 ) {
\r
753 string GetGametype()
\r
755 return GametypeNameFromType(game);
\r
758 string getmapname_stored;
\r
759 string GetMapname()
\r
764 float Map_Count, Map_Current;
\r
765 string Map_Current_Name;
\r
767 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
\r
768 float GetMaplistPosition()
\r
773 map = GetMapname();
\r
774 idx = cvar("g_maplist_index");
\r
777 if(idx < Map_Count)
\r
778 if(map == argv(idx))
\r
781 for(pos = 0; pos < Map_Count; ++pos)
\r
782 if(map == argv(pos))
\r
785 // resume normal maplist rotation if current map is not in g_maplist
\r
789 float MapHasRightSize(string map)
\r
792 if(currentbots || cvar("bot_number") || player_count < cvar("minplayers"))
\r
793 if(cvar("g_maplist_check_waypoints"))
\r
795 dprint("checkwp "); dprint(map);
\r
796 fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ);
\r
799 dprint(": no waypoints\n");
\r
802 dprint(": has waypoints\n");
\r
806 // open map size restriction file
\r
807 dprint("opensize "); dprint(map);
\r
808 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
\r
811 float mapmin, mapmax;
\r
813 mapmin = stof(fgets(fh));
\r
814 mapmax = stof(fgets(fh));
\r
816 if(player_count < mapmin)
\r
818 dprint("not enough\n");
\r
821 if(player_count > mapmax)
\r
823 dprint("too many\n");
\r
826 dprint("right size\n");
\r
829 dprint(": not found\n");
\r
833 string Map_Filename(float position)
\r
835 return strcat("maps/", argv(position), ".bsp");
\r
838 string strwords(string s, float w)
\r
841 for(endpos = 0; w && endpos >= 0; --w)
\r
842 endpos = strstrofs(s, " ", endpos + 1);
\r
846 return substring(s, 0, endpos);
\r
849 float strhasword(string s, string w)
\r
851 return strstrofs(strcat(" ", s, " "), strcat(" ", w, " "), 0) >= 0;
\r
854 void Map_MarkAsRecent(string m)
\r
856 cvar_set("g_maplist_mostrecent", strwords(strcat(m, " ", cvar_string("g_maplist_mostrecent")), max(0, cvar("g_maplist_mostrecent_count"))));
\r
859 float Map_IsRecent(string m)
\r
861 return strhasword(cvar_string("g_maplist_mostrecent"), m);
\r
864 float Map_Check(float position, float pass)
\r
868 map_next = argv(position);
\r
871 if(Map_IsRecent(map_next))
\r
874 filename = Map_Filename(position);
\r
875 if(MapInfo_CheckMap(map_next))
\r
879 if(MapHasRightSize(map_next))
\r
884 dprint( "Couldn't select '", filename, "'..\n" );
\r
889 void Map_Goto_SetStr(string nextmapname)
\r
891 if(getmapname_stored != "")
\r
892 strunzone(getmapname_stored);
\r
893 if(nextmapname == "")
\r
894 getmapname_stored = "";
\r
896 getmapname_stored = strzone(nextmapname);
\r
899 void Map_Goto_SetFloat(float position)
\r
901 cvar_set("g_maplist_index", ftos(position));
\r
902 Map_Goto_SetStr(argv(position));
\r
905 void GameResetCfg()
\r
907 // settings persist, except...
\r
908 localcmd("\nsettemp_restore\n");
\r
914 MapInfo_LoadMap(getmapname_stored);
\r
917 // return codes of map selectors:
\r
918 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
\r
919 // -2 = permanent failure
\r
920 float() MaplistMethod_Iterate = // usual method
\r
924 for(pass = 1; pass <= 2; ++pass)
\r
926 for(i = 1; i < Map_Count; ++i)
\r
929 mapindex = mod(i + Map_Current, Map_Count);
\r
930 if(Map_Check(mapindex, pass))
\r
937 float() MaplistMethod_Repeat = // fallback method
\r
939 if(Map_Check(Map_Current, 2))
\r
940 return Map_Current;
\r
944 float() MaplistMethod_Random = // random map selection
\r
950 for(i = 0; i <= imax; ++i)
\r
953 mapindex = mod(Map_Current + floor(random() * (Map_Count - 1) + 1), Map_Count); // any OTHER map
\r
954 if(Map_Check(mapindex, 1))
\r
960 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
\r
961 // the exponent sets a bias on the map selection:
\r
962 // the higher the exponent, the less likely "shortly repeated" same maps are
\r
964 float i, j, imax, insertpos;
\r
968 for(i = 0; i <= imax; ++i)
\r
972 // now reinsert this at another position
\r
973 insertpos = pow(random(), 1 / exponent); // ]0, 1]
\r
974 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
\r
975 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
\r
976 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
\r
978 // insert the current map there
\r
980 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
\r
981 newlist = strcat(newlist, " ", argv(j));
\r
982 newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map
\r
983 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
\r
984 newlist = strcat(newlist, " ", argv(j));
\r
985 newlist = substring(newlist, 1, strlen(newlist) - 1);
\r
986 cvar_set("g_maplist", newlist);
\r
987 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
\r
989 // NOTE: the selected map has just been inserted at (insertpos-1)th position
\r
990 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
\r
991 if(Map_Check(Map_Current, 1))
\r
992 return Map_Current;
\r
997 void Maplist_Init()
\r
999 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
\r
1000 if(Map_Count == 0)
\r
1002 bprint( "Maplist is empty! Resetting it to default map list.\n" );
\r
1003 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
\r
1004 if(cvar("g_maplist_shuffle"))
\r
1006 localcmd("\nmenu_cmd sync\n");
\r
1007 Map_Count = tokenizebyseparator(cvar_string("g_maplist"), " ");
\r
1009 if(Map_Count == 0)
\r
1010 error("empty maplist, cannot select a new map");
\r
1011 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
\r
1013 if(Map_Current_Name)
\r
1014 strunzone(Map_Current_Name);
\r
1015 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
\r
1016 // this may or may not be correct, but who cares, in the worst case a map
\r
1017 // isn't chosen in the first pass that should have been
\r
1020 string GetNextMap()
\r
1028 if(cvar("g_maplist_shuffle") > 0)
\r
1029 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
\r
1032 if(cvar("g_maplist_selectrandom"))
\r
1033 nextMap = MaplistMethod_Random();
\r
1036 nextMap = MaplistMethod_Iterate();
\r
1039 nextMap = MaplistMethod_Repeat();
\r
1043 Map_Goto_SetFloat(nextMap);
\r
1044 return getmapname_stored;
\r
1050 float DoNextMapOverride()
\r
1052 if(cvar("g_campaign"))
\r
1054 if(cvar("g_campaign_changelevel"))
\r
1056 CampaignPostIntermission();
\r
1057 alreadychangedlevel = TRUE;
\r
1061 localcmd("togglemenu 1\n");
\r
1063 if(cvar("quit_when_empty"))
\r
1065 if(player_count <= currentbots)
\r
1067 localcmd("quit\n");
\r
1068 alreadychangedlevel = TRUE;
\r
1072 if(cvar_string("quit_and_redirect") != "")
\r
1074 redirection_target = strzone(cvar_string("quit_and_redirect"));
\r
1075 alreadychangedlevel = TRUE;
\r
1078 if (cvar("samelevel")) // if samelevel is set, stay on same level
\r
1080 // 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)
\r
1081 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
\r
1082 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
\r
1083 localcmd("restart\n");
\r
1084 //changelevel (mapname);
\r
1085 alreadychangedlevel = TRUE;
\r
1088 if(cvar_string("nextmap") != "")
\r
1089 if(MapInfo_CheckMap(cvar_string("nextmap")))
\r
1091 Map_Goto_SetStr(cvar_string("nextmap"));
\r
1093 alreadychangedlevel = TRUE;
\r
1096 if(cvar("lastlevel"))
\r
1099 localcmd("set lastlevel 0\ntogglemenu\n");
\r
1100 alreadychangedlevel = TRUE;
\r
1106 void GotoNextMap()
\r
1108 //local string nextmap;
\r
1109 //local float n, nummaps;
\r
1111 if (alreadychangedlevel)
\r
1113 alreadychangedlevel = TRUE;
\r
1119 for(allowReset = 1; allowReset >= 0; --allowReset)
\r
1121 nextMap = GetNextMap();
\r
1127 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
\r
1128 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
\r
1129 if(cvar("g_maplist_shuffle"))
\r
1131 localcmd("\nmenu_cmd sync\n");
\r
1135 error("Everything is broken - not even the default map list works. Please report this to the developers.");
\r
1147 When the player presses attack or jump, change to the next level
\r
1150 .float autoscreenshot;
\r
1151 void() MapVote_Start;
\r
1152 void() MapVote_Think;
\r
1153 float mapvote_initialized;
\r
1154 void IntermissionThink()
\r
1156 FixIntermissionClient(self);
\r
1158 if(cvar("sv_autoscreenshot"))
\r
1159 if(self.autoscreenshot > 0)
\r
1160 if(time > self.autoscreenshot)
\r
1162 self.autoscreenshot = -1;
\r
1163 if(clienttype(self) == CLIENTTYPE_REAL)
\r
1164 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
\r
1168 if (time < intermission_exittime)
\r
1171 if(!mapvote_initialized)
\r
1172 if (time < intermission_exittime + 10 && !self.BUTTON_ATCK && !self.BUTTON_JUMP && !self.BUTTON_ATCK2 && !self.BUTTON_JETPACK && !self.BUTTON_USE)
\r
1182 Returns the entity to view from
\r
1186 entity FindIntermission()
\r
1188 local entity spot;
\r
1191 // look for info_intermission first
\r
1192 spot = find (world, classname, "info_intermission");
\r
1194 { // pick a random one
\r
1195 cyc = random() * 4;
\r
1198 spot = find (spot, classname, "info_intermission");
\r
1200 spot = find (spot, classname, "info_intermission");
\r
1206 // then look for the start position
\r
1207 spot = find (world, classname, "info_player_start");
\r
1211 // testinfo_player_start is only found in regioned levels
\r
1212 spot = find (world, classname, "testplayerstart");
\r
1216 // then look for the start position
\r
1217 spot = find (world, classname, "info_player_deathmatch");
\r
1221 //objerror ("FindIntermission: no spot");
\r
1227 ===============================================================================
\r
1231 ===============================================================================
\r
1234 void DumpStats(float final)
\r
1238 local float to_console;
\r
1239 local float to_eventlog;
\r
1240 local float to_file;
\r
1243 to_console = cvar("sv_logscores_console");
\r
1244 to_eventlog = cvar("sv_eventlog");
\r
1245 to_file = cvar("sv_logscores_file");
\r
1249 to_console = TRUE; // always print printstats replies
\r
1250 to_eventlog = FALSE; // but never print them to the event log
\r
1254 if(cvar("sv_eventlog_console"))
\r
1255 to_console = FALSE; // otherwise we get the output twice
\r
1261 s = strcat(s, GetGametype(), "_", GetMapname(), ":", ftos(rint(time)));
\r
1269 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
\r
1273 fputs(file, strcat(s, "\n"));
\r
1276 s = strcat(":labels:player:", GetPlayerScoreString(world, 0));
\r
1282 fputs(file, strcat(s, "\n"));
\r
1284 FOR_EACH_CLIENT(other)
\r
1286 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
\r
1288 s = strcat(":player:see-labels:", GetPlayerScoreString(other, 0), ":");
\r
1289 s = strcat(s, ftos(rint(time - other.jointime)), ":");
\r
1290 if(other.classname == "player" || g_arena || g_ca || g_lms)
\r
1291 s = strcat(s, ftos(other.team), ":");
\r
1293 s = strcat(s, "spectator:");
\r
1296 print(s, other.netname, "\n");
\r
1298 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname));
\r
1300 fputs(file, strcat(s, other.netname, "\n"));
\r
1306 s = strcat(":labels:teamscores:", GetTeamScoreString(0, 0));
\r
1312 fputs(file, strcat(s, "\n"));
\r
1314 for(i = 1; i < 16; ++i)
\r
1316 s = strcat(":teamscores:see-labels:", GetTeamScoreString(i, 0));
\r
1317 s = strcat(s, ":", ftos(i));
\r
1323 fputs(file, strcat(s, "\n"));
\r
1330 GameLogEcho(":end");
\r
1333 fputs(file, ":end\n");
\r
1338 void FixIntermissionClient(entity e)
\r
1340 if(!e.autoscreenshot) // initial call
\r
1342 e.angles = e.v_angle;
\r
1343 e.angles_x = -e.angles_x;
\r
1344 e.autoscreenshot = time + 0.8; // used for autoscreenshot
\r
1346 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
\r
1347 e.solid = SOLID_NOT;
\r
1348 e.movetype = MOVETYPE_NONE;
\r
1349 e.takedamage = DAMAGE_NO;
\r
1350 if(e.weaponentity)
\r
1352 e.weaponentity.effects = EF_NODRAW;
\r
1353 if (e.weaponentity.weaponentity)
\r
1354 e.weaponentity.weaponentity.effects = EF_NODRAW;
\r
1356 if(clienttype(e) == CLIENTTYPE_REAL)
\r
1358 stuffcmd(e, "\nscr_printspeed 1000000\n");
\r
1360 WriteByte(MSG_ONE, SVC_INTERMISSION);
\r
1364 //e.velocity = '0 0 0';
\r
1365 //e.fixangle = TRUE;
\r
1367 // TODO halt weapon animation
\r
1372 go to the next level for deathmatch
\r
1373 only called if a time or frag limit has expired
\r
1381 intermission_running = 1;
\r
1383 // enforce a wait time before allowing changelevel
\r
1384 if(player_count > 0)
\r
1385 intermission_exittime = time + cvar("sv_mapchange_delay");
\r
1387 intermission_exittime = -1;
\r
1390 WriteByte (MSG_ALL, SVC_CDTRACK);
\r
1391 WriteByte (MSG_ALL, 3);
\r
1392 WriteByte (MSG_ALL, 3);
\r
1393 // done in FixIntermission
\r
1396 //pos = FindIntermission ();
\r
1402 if(cvar("sv_eventlog"))
\r
1403 GameLogEcho(":gameover");
\r
1409 // save the stats to a text file on the client
\r
1410 // stuffcmd(other, log_stats "stats/file_name");
\r
1412 // stuffcmd(other, log_stats "");
\r
1413 // use a filename similar to the demo name
\r
1414 // string file_name;
\r
1415 // file_name = strcat("\nlog_file \"stats/", strftime(TRUE, "%Y-%m-%d_%H-%M"), "_", mapname, ".txt\""); // open the log file
\r
1417 // write a stats parser for the menu
\r
1419 if(cvar("sv_accuracy_data_send")) {
\r
1420 string stats_to_send;
\r
1422 FOR_EACH_CLIENT(other) { // make the string to send
\r
1423 FixIntermissionClient(other);
\r
1425 if(other.cvar_cl_accuracy_data_share) {
\r
1426 stats_to_send = strcat(stats_to_send, ":hits:", other.netname);
\r
1428 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
\r
1429 stats_to_send = strcat(stats_to_send, ":", ftos(other.stats_hit[i-1]));
\r
1431 stats_to_send = strcat(stats_to_send, "\n:fired:", other.netname);
\r
1433 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
\r
1434 stats_to_send = strcat(stats_to_send, ":", ftos(other.stats_fired[i-1]));
\r
1436 stats_to_send = strcat(stats_to_send, "\n");
\r
1440 FOR_EACH_REALCLIENT(other) { // only spam humans
\r
1441 Score_NicePrint(other); // print the score
\r
1443 if(other.cvar_cl_accuracy_data_receive) // send the stats string to all the willing clients
\r
1444 bprint(stats_to_send);
\r
1446 } else { // ye olde message
\r
1447 FOR_EACH_PLAYER(other) {
\r
1448 FixIntermissionClient(other);
\r
1451 bprint(other.netname, " ^7wins.\n");
\r
1455 if(cvar("g_campaign"))
\r
1456 CampaignPreIntermission();
\r
1458 localcmd("\nsv_hook_gameend;");
\r
1459 if(cvar("g_campaign"))
\r
1460 localcmd("\nsv_hook_campaign_gameend;");
\r
1467 Exit deathmatch games upon conditions
\r
1470 void CheckRules_Player()
\r
1472 if (gameover) // someone else quit the game already
\r
1475 if(self.deadflag == DEAD_NO)
\r
1476 self.play_time += frametime;
\r
1478 // fixme: don't check players; instead check spawnfunc_dom_team and spawnfunc_ctf_team entities
\r
1479 // (div0: and that in CheckRules_World please)
\r
1482 float checkrules_equality;
\r
1483 float checkrules_suddendeathwarning;
\r
1484 float checkrules_suddendeathend;
\r
1485 float checkrules_overtimesadded; //how many overtimes have been already added
\r
1487 float WINNING_NO = 0; // no winner, but time limits may terminate the game
\r
1488 float WINNING_YES = 1; // winner found
\r
1489 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
\r
1490 float WINNING_STARTSUDDENDEATHOVERTIME = 3; // no winner, enter suddendeath overtime NOW
\r
1492 float InitiateSuddenDeath()
\r
1494 // Check first whether normal overtimes could be added before initiating suddendeath mode
\r
1495 // - for this timelimit_overtime needs to be >0 of course
\r
1496 // - also check the winning condition calculated in the previous frame and only add normal overtime
\r
1497 // again, if at the point at which timelimit would be extended again, still no winner was found
\r
1498 if ((checkrules_overtimesadded >= 0) && (checkrules_overtimesadded < cvar("timelimit_overtimes")) && cvar("timelimit_overtime") && !(g_race && !g_race_qualifying))
\r
1500 return 1; // need to call InitiateOvertime later
\r
1504 if(!checkrules_suddendeathend)
\r
1506 checkrules_suddendeathend = time + 60 * cvar("timelimit_suddendeath");
\r
1507 if(g_race && !g_race_qualifying)
\r
1508 race_StartCompleting();
\r
1514 void InitiateOvertime() // ONLY call this if InitiateSuddenDeath returned true
\r
1516 ++checkrules_overtimesadded;
\r
1517 //add one more overtime by simply extending the timelimit
\r
1519 tl = cvar("timelimit");
\r
1520 tl += cvar("timelimit_overtime");
\r
1521 cvar_set("timelimit", ftos(tl));
\r
1522 string minutesPlural;
\r
1523 if (cvar("timelimit_overtime") == 1)
\r
1524 minutesPlural = " ^3minute";
\r
1526 minutesPlural = " ^3minutes";
\r
1530 "^3Now playing ^1OVERTIME^3!\n\n^3Added ^1",
\r
1531 ftos(cvar("timelimit_overtime")),
\r
1538 float GetWinningCode(float fraglimitreached, float equality)
\r
1541 if(fraglimitreached)
\r
1542 return WINNING_STARTSUDDENDEATHOVERTIME;
\r
1544 return WINNING_NEVER;
\r
1546 if(fraglimitreached)
\r
1547 return WINNING_YES;
\r
1549 return WINNING_NO;
\r
1552 // set the .winning flag for exactly those players with a given field value
\r
1553 void SetWinners(.float field, float value)
\r
1556 FOR_EACH_PLAYER(head)
\r
1557 head.winning = (head.field == value);
\r
1560 // set the .winning flag for those players with a given field value
\r
1561 void AddWinners(.float field, float value)
\r
1564 FOR_EACH_PLAYER(head)
\r
1565 if(head.field == value)
\r
1569 // clear the .winning flags
\r
1570 void ClearWinners(void)
\r
1573 FOR_EACH_PLAYER(head)
\r
1577 // Onslaught winning condition:
\r
1578 // game terminates if only one team has a working generator (or none)
\r
1579 float WinningCondition_Onslaught()
\r
1582 local float t1, t2, t3, t4;
\r
1584 WinningConditionHelper(); // set worldstatus
\r
1587 return WINNING_NO;
\r
1589 // first check if the game has ended
\r
1590 t1 = t2 = t3 = t4 = 0;
\r
1591 head = find(world, classname, "onslaught_generator");
\r
1594 if (head.health > 0)
\r
1596 if (head.team == COLOR_TEAM1) t1 = 1;
\r
1597 if (head.team == COLOR_TEAM2) t2 = 1;
\r
1598 if (head.team == COLOR_TEAM3) t3 = 1;
\r
1599 if (head.team == COLOR_TEAM4) t4 = 1;
\r
1601 head = find(head, classname, "onslaught_generator");
\r
1603 if (t1 + t2 + t3 + t4 < 2)
\r
1605 // game over, only one team remains (or none)
\r
1607 if (t1) SetWinners(team, COLOR_TEAM1);
\r
1608 if (t2) SetWinners(team, COLOR_TEAM2);
\r
1609 if (t3) SetWinners(team, COLOR_TEAM3);
\r
1610 if (t4) SetWinners(team, COLOR_TEAM4);
\r
1611 dprint("Have a winner, ending game.\n");
\r
1612 return WINNING_YES;
\r
1615 // Two or more teams remain
\r
1616 return WINNING_NO;
\r
1619 float LMS_NewPlayerLives()
\r
1622 fl = cvar("fraglimit");
\r
1626 // first player has left the game for dying too much? Nobody else can get in.
\r
1627 if(lms_lowest_lives < 1)
\r
1630 if(!cvar("g_lms_join_anytime"))
\r
1631 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
\r
1634 return bound(1, lms_lowest_lives, fl);
\r
1637 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
\r
1638 // they win. Otherwise the defending team wins once the timelimit passes.
\r
1639 void assault_new_round();
\r
1640 float WinningCondition_Assault()
\r
1642 local float status;
\r
1644 WinningConditionHelper(); // set worldstatus
\r
1646 status = WINNING_NO;
\r
1647 // as the timelimit has not yet passed just assume the defending team will win
\r
1648 if(assault_attacker_team == COLOR_TEAM1)
\r
1650 SetWinners(team, COLOR_TEAM2);
\r
1654 SetWinners(team, COLOR_TEAM1);
\r
1658 ent = find(world, classname, "target_assault_roundend");
\r
1661 if(ent.winning) // round end has been triggered by attacking team
\r
1663 bprint("ASSAULT: round completed...\n");
\r
1664 SetWinners(team, assault_attacker_team);
\r
1666 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
\r
1668 if(ent.cnt == 1) // this was the second round
\r
1670 status = WINNING_YES;
\r
1674 local entity oldself;
\r
1677 assault_new_round();
\r
1686 // LMS winning condition: game terminates if and only if there's at most one
\r
1687 // one player who's living lives. Top two scores being equal cancels the time
\r
1689 float WinningCondition_LMS()
\r
1691 entity head, head2;
\r
1692 float have_player;
\r
1693 float have_players;
\r
1696 have_player = FALSE;
\r
1697 have_players = FALSE;
\r
1698 l = LMS_NewPlayerLives();
\r
1700 head = find(world, classname, "player");
\r
1702 have_player = TRUE;
\r
1703 head2 = find(head, classname, "player");
\r
1705 have_players = TRUE;
\r
1709 // we have at least one player
\r
1712 // two or more active players - continue with the game
\r
1716 // exactly one player?
\r
1719 SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
\r
1723 // game still running (that is, nobody got removed from the game by a frag yet)? then continue
\r
1724 return WINNING_NO;
\r
1729 // and assign him his first place
\r
1730 PlayerScore_Add(head, SP_LMS_RANK, 1);
\r
1731 return WINNING_YES;
\r
1737 // nobody is playing at all...
\r
1740 // wait for players...
\r
1744 // SNAFU (maybe a draw game?)
\r
1746 dprint("No players, ending game.\n");
\r
1747 return WINNING_YES;
\r
1751 // When we get here, we have at least two players who are actually LIVING,
\r
1752 // now check if the top two players have equal score.
\r
1753 WinningConditionHelper();
\r
1756 if(WinningConditionHelper_winner)
\r
1757 WinningConditionHelper_winner.winning = TRUE;
\r
1758 if(WinningConditionHelper_topscore == WinningConditionHelper_secondscore)
\r
1759 return WINNING_NEVER;
\r
1761 // Top two have different scores? Way to go for our beloved TIMELIMIT!
\r
1762 return WINNING_NO;
\r
1765 void ShuffleMaplist()
\r
1767 cvar_set("g_maplist", shufflewords(cvar_string("g_maplist")));
\r
1770 float leaderfrags;
\r
1771 float WinningCondition_Scores(float limit, float leadlimit)
\r
1773 // TODO make everything use THIS winning condition (except LMS)
\r
1774 WinningConditionHelper();
\r
1778 team1_score = TeamScore_GetCompareValue(COLOR_TEAM1);
\r
1779 team2_score = TeamScore_GetCompareValue(COLOR_TEAM2);
\r
1780 team3_score = TeamScore_GetCompareValue(COLOR_TEAM3);
\r
1781 team4_score = TeamScore_GetCompareValue(COLOR_TEAM4);
\r
1785 if(WinningConditionHelper_winner)
\r
1786 WinningConditionHelper_winner.winning = 1;
\r
1787 if(WinningConditionHelper_winnerteam >= 0)
\r
1788 SetWinners(team, WinningConditionHelper_winnerteam);
\r
1790 if(WinningConditionHelper_lowerisbetter)
\r
1792 WinningConditionHelper_topscore = -WinningConditionHelper_topscore;
\r
1793 WinningConditionHelper_secondscore = -WinningConditionHelper_secondscore;
\r
1797 if(WinningConditionHelper_zeroisworst)
\r
1798 leadlimit = 0; // not supported in this mode
\r
1800 if(g_dm || g_tdm || g_arena || g_ca || (g_race && !g_race_qualifying))
\r
1801 // these modes always score in increments of 1, thus this makes sense
\r
1803 if(leaderfrags != WinningConditionHelper_topscore)
\r
1805 leaderfrags = WinningConditionHelper_topscore;
\r
1808 if (leaderfrags == limit - 1)
\r
1809 Announce("1fragleft");
\r
1810 else if (leaderfrags == limit - 2)
\r
1811 Announce("2fragsleft");
\r
1812 else if (leaderfrags == limit - 3)
\r
1813 Announce("3fragsleft");
\r
1817 return GetWinningCode(
\r
1818 WinningConditionHelper_topscore &&
\r
1820 (limit && (WinningConditionHelper_topscore >= limit))
\r
1822 (leadlimit && (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit))
\r
1824 WinningConditionHelper_equality
\r
1828 float WinningCondition_Race(float fraglimit)
\r
1836 FOR_EACH_PLAYER(p)
\r
1839 if(p.race_completed)
\r
1843 return WINNING_YES;
\r
1844 wc = WinningCondition_Scores(fraglimit, 0);
\r
1846 // ALWAYS initiate overtime, unless EVERYONE has finished the race!
\r
1847 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
\r
1848 // do NOT support equality when the laps are all raced!
\r
1849 return WINNING_STARTSUDDENDEATHOVERTIME;
\r
1851 return WINNING_NEVER;
\r
1855 void ReadyRestart();
\r
1856 float WinningCondition_QualifyingThenRace(float limit)
\r
1859 wc = WinningCondition_Scores(limit, 0);
\r
1861 // NEVER initiate overtime
\r
1862 if(wc == WINNING_YES || wc == WINNING_STARTSUDDENDEATHOVERTIME)
\r
1864 return WINNING_YES;
\r
1870 float WinningCondition_RanOutOfSpawns()
\r
1874 if(have_team_spawns <= 0)
\r
1875 return WINNING_NO;
\r
1877 if(!some_spawn_has_been_used)
\r
1878 return WINNING_NO;
\r
1880 team1_score = team2_score = team3_score = team4_score = 0;
\r
1882 FOR_EACH_PLAYER(head) if(head.deadflag == DEAD_NO)
\r
1884 if(head.team == COLOR_TEAM1)
\r
1886 else if(head.team == COLOR_TEAM2)
\r
1888 else if(head.team == COLOR_TEAM3)
\r
1890 else if(head.team == COLOR_TEAM4)
\r
1894 for(head = world; (head = find(head, classname, "info_player_deathmatch")) != world; )
\r
1896 if(head.team == COLOR_TEAM1)
\r
1898 else if(head.team == COLOR_TEAM2)
\r
1900 else if(head.team == COLOR_TEAM3)
\r
1902 else if(head.team == COLOR_TEAM4)
\r
1907 if(team1_score + team2_score + team3_score + team4_score == 0)
\r
1909 checkrules_equality = TRUE;
\r
1910 return WINNING_YES;
\r
1912 else if(team1_score + team2_score + team3_score + team4_score == 1)
\r
1915 if(team1_score) t = COLOR_TEAM1;
\r
1916 if(team2_score) t = COLOR_TEAM2;
\r
1917 if(team3_score) t = COLOR_TEAM3;
\r
1918 if(team4_score) t = COLOR_TEAM4;
\r
1919 CheckAllowedTeams(world);
\r
1920 for(i = 0; i < MAX_TEAMSCORE; ++i)
\r
1922 if(t != COLOR_TEAM1) if(c1 >= 0) TeamScore_AddToTeam(COLOR_TEAM1, i, -1000);
\r
1923 if(t != COLOR_TEAM2) if(c2 >= 0) TeamScore_AddToTeam(COLOR_TEAM2, i, -1000);
\r
1924 if(t != COLOR_TEAM3) if(c3 >= 0) TeamScore_AddToTeam(COLOR_TEAM3, i, -1000);
\r
1925 if(t != COLOR_TEAM4) if(c4 >= 0) TeamScore_AddToTeam(COLOR_TEAM4, i, -1000);
\r
1928 AddWinners(team, t);
\r
1929 return WINNING_YES;
\r
1932 return WINNING_NO;
\r
1939 Exit deathmatch games upon conditions
\r
1942 void CheckRules_World()
\r
1951 SetDefaultAlpha();
\r
1954 MapVote_Think should now do that part
\r
1955 if (intermission_running)
\r
1956 if (time >= intermission_exittime + 60)
\r
1958 if(!DoNextMapOverride())
\r
1964 if (gameover) // someone else quit the game already
\r
1966 if(player_count == 0) // Nobody there? Then let's go to the next map
\r
1968 // this will actually check the player count in the next frame
\r
1969 // again, but this shouldn't hurt
\r
1973 timelimit = cvar("timelimit") * 60;
\r
1974 fraglimit = cvar("fraglimit");
\r
1975 leadlimit = cvar("leadlimit");
\r
1977 if(inWarmupStage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
\r
1980 timelimit = 0; // timelimit is not made for warmup
\r
1982 fraglimit = 0; // no fraglimit for now
\r
1983 leadlimit = 0; // no leadlimit for now
\r
1987 timelimit = 0; // ONS has its own overtime rule
\r
1991 timelimit += game_starttime;
\r
1993 else if (timelimit < 0)
\r
2000 float wantovertime;
\r
2003 if(checkrules_suddendeathend)
\r
2005 if(!checkrules_suddendeathwarning)
\r
2007 checkrules_suddendeathwarning = TRUE;
\r
2008 if(g_race && !g_race_qualifying)
\r
2009 bcenterprint("^3Everyone, finish your lap! The race is over!");
\r
2011 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
\r
2016 if (timelimit && time >= timelimit)
\r
2018 if(g_race && (g_race_qualifying == 2) && timelimit > 0)
\r
2020 float totalplayers;
\r
2021 float playerswithlaps;
\r
2022 float readyplayers;
\r
2024 totalplayers = playerswithlaps = readyplayers = 0;
\r
2025 FOR_EACH_PLAYER(head)
\r
2028 if(PlayerScore_Add(head, SP_RACE_FASTEST, 0))
\r
2029 ++playerswithlaps;
\r
2034 // at least 2 of the players have completed a lap: start the RACE
\r
2035 // otherwise, the players should end the qualifying on their own
\r
2036 if(readyplayers || playerswithlaps >= 2)
\r
2038 checkrules_suddendeathend = 0;
\r
2039 ReadyRestart(); // go to race
\r
2043 wantovertime |= InitiateSuddenDeath();
\r
2046 wantovertime |= InitiateSuddenDeath();
\r
2050 if (checkrules_suddendeathend && time >= checkrules_suddendeathend)
\r
2056 float checkrules_status;
\r
2057 checkrules_status = WinningCondition_RanOutOfSpawns();
\r
2058 if(checkrules_status == WINNING_YES)
\r
2060 bprint("Hey! Someone ran out of spawns!\n");
\r
2062 else if(g_race && !g_race_qualifying && timelimit >= 0)
\r
2064 checkrules_status = WinningCondition_Race(fraglimit);
\r
2065 //print("WC_RACE yields ", ftos(checkrules_status), "\n");
\r
2067 else if(g_race && g_race_qualifying == 2 && timelimit >= 0)
\r
2069 checkrules_status = WinningCondition_QualifyingThenRace(fraglimit);
\r
2070 //print("WC_QUALIFYING_THEN_RACE yields ", ftos(checkrules_status), "\n");
\r
2072 else if(g_assault)
\r
2074 checkrules_status = WinningCondition_Assault(); // TODO remove this?
\r
2078 checkrules_status = WinningCondition_LMS();
\r
2080 else if (g_onslaught)
\r
2082 checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
\r
2086 checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
\r
2087 //print("WC_SCORES yields ", ftos(checkrules_status), "\n");
\r
2090 if(checkrules_status == WINNING_STARTSUDDENDEATHOVERTIME)
\r
2092 checkrules_status = WINNING_NEVER;
\r
2093 checkrules_overtimesadded = -1;
\r
2094 wantovertime |= InitiateSuddenDeath();
\r
2097 if(checkrules_status == WINNING_NEVER)
\r
2098 // equality cases! Nobody wins if the overtime ends in a draw.
\r
2103 if(checkrules_status == WINNING_NEVER)
\r
2104 InitiateOvertime();
\r
2106 checkrules_status = WINNING_YES;
\r
2109 if(checkrules_suddendeathend)
\r
2110 if(checkrules_status != WINNING_NEVER || time >= checkrules_suddendeathend)
\r
2111 checkrules_status = WINNING_YES;
\r
2113 if(checkrules_status == WINNING_YES)
\r
2115 //print("WINNING\n");
\r
2120 float mapvote_nextthink;
\r
2121 float mapvote_initialized;
\r
2122 float mapvote_keeptwotime;
\r
2123 float mapvote_timeout;
\r
2124 string mapvote_message;
\r
2125 #define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
\r
2126 string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
\r
2127 float mapvote_screenshot_dirs_count;
\r
2129 float mapvote_count;
\r
2130 float mapvote_count_real;
\r
2131 string mapvote_maps[MAPVOTE_COUNT];
\r
2132 float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
\r
2133 string mapvote_maps_pakfile[MAPVOTE_COUNT];
\r
2134 float mapvote_maps_suggested[MAPVOTE_COUNT];
\r
2135 string mapvote_suggestions[MAPVOTE_COUNT];
\r
2136 float mapvote_suggestion_ptr;
\r
2137 float mapvote_maxlen;
\r
2138 float mapvote_voters;
\r
2139 float mapvote_votes[MAPVOTE_COUNT];
\r
2140 float mapvote_run;
\r
2141 float mapvote_detail;
\r
2142 float mapvote_abstain;
\r
2145 void MapVote_ClearAllVotes()
\r
2147 FOR_EACH_CLIENT(other)
\r
2148 other.mapvote = 0;
\r
2151 string MapVote_Suggest(string m)
\r
2155 return "That's not how to use this command.";
\r
2156 if(!cvar("g_maplist_votable_suggestions"))
\r
2157 return "Suggestions are not accepted on this server.";
\r
2158 if(mapvote_initialized)
\r
2159 return "Can't suggest - voting is already in progress!";
\r
2160 m = MapInfo_FixName(m);
\r
2162 return "The map you suggested is not available on this server.";
\r
2163 if(!cvar("g_maplist_votable_suggestions_override_mostrecent"))
\r
2164 if(Map_IsRecent(m))
\r
2165 return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
\r
2167 if(!MapInfo_CheckMap(m))
\r
2168 return "The map you suggested does not support the current game mode.";
\r
2169 for(i = 0; i < mapvote_suggestion_ptr; ++i)
\r
2170 if(mapvote_suggestions[i] == m)
\r
2171 return "This map was already suggested.";
\r
2172 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
\r
2174 i = floor(random() * mapvote_suggestion_ptr);
\r
2178 i = mapvote_suggestion_ptr;
\r
2179 mapvote_suggestion_ptr += 1;
\r
2181 if(mapvote_suggestions[i] != "")
\r
2182 strunzone(mapvote_suggestions[i]);
\r
2183 mapvote_suggestions[i] = strzone(m);
\r
2184 if(cvar("sv_eventlog"))
\r
2185 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid)));
\r
2186 return strcat("Suggestion of ", m, " accepted.");
\r
2189 void MapVote_AddVotable(string nextMap, float isSuggestion)
\r
2192 string pakfile, mapfile;
\r
2196 for(j = 0; j < mapvote_count; ++j)
\r
2197 if(mapvote_maps[j] == nextMap)
\r
2199 if(strlen(nextMap) > mapvote_maxlen)
\r
2200 mapvote_maxlen = strlen(nextMap);
\r
2201 mapvote_maps[mapvote_count] = strzone(nextMap);
\r
2202 mapvote_maps_suggested[mapvote_count] = isSuggestion;
\r
2204 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
\r
2206 mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
\r
2207 pakfile = whichpack(strcat(mapfile, ".tga"));
\r
2209 pakfile = whichpack(strcat(mapfile, ".jpg"));
\r
2211 pakfile = whichpack(strcat(mapfile, ".png"));
\r
2215 if(i >= mapvote_screenshot_dirs_count)
\r
2216 i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
\r
2217 for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
\r
2218 pakfile = substring(pakfile, o, -1);
\r
2220 mapvote_maps_screenshot_dir[mapvote_count] = i;
\r
2221 mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
\r
2223 mapvote_count += 1;
\r
2226 void MapVote_Spawn();
\r
2227 void MapVote_Init()
\r
2232 if(cvar("g_campaign"))
\r
2235 MapVote_ClearAllVotes();
\r
2237 mapvote_count = 0;
\r
2238 mapvote_detail = !cvar("g_maplist_votable_nodetail");
\r
2239 mapvote_abstain = cvar("g_maplist_votable_abstain");
\r
2241 if(mapvote_abstain)
\r
2242 nmax = min(MAPVOTE_COUNT - 1, cvar("g_maplist_votable"));
\r
2244 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
\r
2245 smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
\r
2247 // we need this for AddVotable, as that cycles through the screenshot dirs
\r
2248 mapvote_screenshot_dirs_count = tokenize_console(cvar_string("g_maplist_votable_screenshot_dir"));
\r
2249 if(mapvote_screenshot_dirs_count == 0)
\r
2250 mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
\r
2251 mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
\r
2252 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
\r
2253 mapvote_screenshot_dirs[i] = strzone(argv(i));
\r
2255 if(mapvote_suggestion_ptr)
\r
2256 for(i = 0; i < 100 && mapvote_count < smax; ++i)
\r
2257 MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
\r
2259 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
\r
2260 MapVote_AddVotable(GetNextMap(), FALSE);
\r
2262 if(mapvote_count == 0)
\r
2264 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
\r
2265 cvar_set("g_maplist", MapInfo_ListAllowedMaps(MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags()));
\r
2266 if(cvar("g_maplist_shuffle"))
\r
2268 localcmd("\nmenu_cmd sync\n");
\r
2269 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
\r
2270 MapVote_AddVotable(GetNextMap(), FALSE);
\r
2273 mapvote_count_real = mapvote_count;
\r
2274 if(mapvote_abstain)
\r
2275 MapVote_AddVotable("don't care", 0);
\r
2277 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
\r
2279 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
\r
2280 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
\r
2281 if(mapvote_count_real < 3 || mapvote_keeptwotime <= time)
\r
2282 mapvote_keeptwotime = 0;
\r
2283 mapvote_message = "Choose a map and press its key!";
\r
2288 void MapVote_SendPicture(float id)
\r
2290 msg_entity = self;
\r
2291 WriteByte(MSG_ONE, SVC_TEMPENTITY);
\r
2292 WriteByte(MSG_ONE, TE_CSQC_PICTURE);
\r
2293 WriteByte(MSG_ONE, id);
\r
2294 WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
\r
2297 float GameCommand_MapVote(string cmd)
\r
2299 if(!intermission_running)
\r
2302 if(cmd == "mv_getpic")
\r
2304 MapVote_SendPicture(stof(argv(1)));
\r
2311 float MapVote_GetMapMask()
\r
2313 float mask, i, power;
\r
2315 for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2)
\r
2316 if(mapvote_maps[i] != "")
\r
2321 entity mapvote_ent;
\r
2322 float MapVote_SendEntity(entity to, float sf)
\r
2327 sf &~= 2; // if we send 1, we don't need to also send 2
\r
2329 WriteByte(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
\r
2330 WriteByte(MSG_ENTITY, sf);
\r
2334 // flag 1 == initialization
\r
2335 for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
\r
2336 WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
\r
2337 WriteString(MSG_ENTITY, "");
\r
2338 WriteByte(MSG_ENTITY, mapvote_count);
\r
2339 WriteByte(MSG_ENTITY, mapvote_abstain);
\r
2340 WriteByte(MSG_ENTITY, mapvote_detail);
\r
2341 WriteCoord(MSG_ENTITY, mapvote_timeout);
\r
2342 if(mapvote_count <= 8)
\r
2343 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
\r
2345 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
\r
2346 for(i = 0; i < mapvote_count; ++i)
\r
2347 if(mapvote_maps[i] != "")
\r
2349 if(mapvote_abstain && i == mapvote_count - 1)
\r
2351 WriteString(MSG_ENTITY, ""); // abstain needs no text
\r
2352 WriteString(MSG_ENTITY, ""); // abstain needs no pack
\r
2353 WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
\r
2357 WriteString(MSG_ENTITY, mapvote_maps[i]);
\r
2358 WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
\r
2359 WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
\r
2366 // flag 2 == update of mask
\r
2367 if(mapvote_count <= 8)
\r
2368 WriteByte(MSG_ENTITY, MapVote_GetMapMask());
\r
2370 WriteShort(MSG_ENTITY, MapVote_GetMapMask());
\r
2375 if(mapvote_detail)
\r
2376 for(i = 0; i < mapvote_count; ++i)
\r
2377 if(mapvote_maps[i] != "")
\r
2378 WriteByte(MSG_ENTITY, mapvote_votes[i]);
\r
2380 WriteByte(MSG_ENTITY, to.mapvote);
\r
2386 void MapVote_Spawn()
\r
2388 Net_LinkEntity(mapvote_ent = spawn(), FALSE, 0, MapVote_SendEntity);
\r
2391 void MapVote_TouchMask()
\r
2393 mapvote_ent.SendFlags |= 2;
\r
2396 void MapVote_TouchVotes(entity voter)
\r
2398 mapvote_ent.SendFlags |= 4;
\r
2401 float MapVote_Finished(float mappos)
\r
2407 if(cvar("sv_eventlog"))
\r
2409 result = strcat(":vote:finished:", mapvote_maps[mappos]);
\r
2410 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
\r
2411 didntvote = mapvote_voters;
\r
2412 for(i = 0; i < mapvote_count; ++i)
\r
2413 if(mapvote_maps[i] != "")
\r
2415 didntvote -= mapvote_votes[i];
\r
2418 result = strcat(result, ":", mapvote_maps[i]);
\r
2419 result = strcat(result, ":", ftos(mapvote_votes[i]));
\r
2422 result = strcat(result, ":didn't vote:", ftos(didntvote));
\r
2424 GameLogEcho(result);
\r
2425 if(mapvote_maps_suggested[mappos])
\r
2426 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
\r
2429 FOR_EACH_REALCLIENT(other)
\r
2430 FixClientCvars(other);
\r
2432 Map_Goto_SetStr(mapvote_maps[mappos]);
\r
2434 alreadychangedlevel = TRUE;
\r
2437 void MapVote_CheckRules_1()
\r
2441 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
\r
2443 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
\r
2444 mapvote_votes[i] = 0;
\r
2447 mapvote_voters = 0;
\r
2448 FOR_EACH_REALCLIENT(other)
\r
2453 i = other.mapvote - 1;
\r
2454 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
\r
2455 mapvote_votes[i] = mapvote_votes[i] + 1;
\r
2460 float MapVote_CheckRules_2()
\r
2463 float firstPlace, secondPlace;
\r
2464 float firstPlaceVotes, secondPlaceVotes;
\r
2465 float mapvote_voters_real;
\r
2468 if(mapvote_count_real == 1)
\r
2469 return MapVote_Finished(0);
\r
2471 mapvote_voters_real = mapvote_voters;
\r
2472 if(mapvote_abstain)
\r
2473 mapvote_voters_real -= mapvote_votes[mapvote_count - 1];
\r
2475 RandomSelection_Init();
\r
2476 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
\r
2477 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
\r
2478 firstPlace = RandomSelection_chosen_float;
\r
2479 firstPlaceVotes = RandomSelection_best_priority;
\r
2480 //dprint("First place: ", ftos(firstPlace), "\n");
\r
2481 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
\r
2483 RandomSelection_Init();
\r
2484 for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "")
\r
2485 if(i != firstPlace)
\r
2486 RandomSelection_Add(world, i, string_null, 1, mapvote_votes[i]);
\r
2487 secondPlace = RandomSelection_chosen_float;
\r
2488 secondPlaceVotes = RandomSelection_best_priority;
\r
2489 //dprint("Second place: ", ftos(secondPlace), "\n");
\r
2490 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
\r
2492 if(firstPlace == -1)
\r
2493 error("No first place in map vote... WTF?");
\r
2495 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
\r
2496 return MapVote_Finished(firstPlace);
\r
2498 if(mapvote_keeptwotime)
\r
2499 if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
\r
2502 MapVote_TouchMask();
\r
2503 mapvote_message = "Now decide between the TOP TWO!";
\r
2504 mapvote_keeptwotime = 0;
\r
2505 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
\r
2506 result = strcat(result, ":", ftos(firstPlaceVotes));
\r
2507 result = strcat(result, ":", mapvote_maps[secondPlace]);
\r
2508 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
\r
2509 didntvote = mapvote_voters;
\r
2510 for(i = 0; i < mapvote_count; ++i)
\r
2511 if(mapvote_maps[i] != "")
\r
2513 didntvote -= mapvote_votes[i];
\r
2514 if(i != firstPlace)
\r
2515 if(i != secondPlace)
\r
2517 result = strcat(result, ":", mapvote_maps[i]);
\r
2518 result = strcat(result, ":", ftos(mapvote_votes[i]));
\r
2519 if(i < mapvote_count_real)
\r
2521 strunzone(mapvote_maps[i]);
\r
2522 mapvote_maps[i] = "";
\r
2523 strunzone(mapvote_maps_pakfile[i]);
\r
2524 mapvote_maps_pakfile[i] = "";
\r
2528 result = strcat(result, ":didn't vote:", ftos(didntvote));
\r
2529 if(cvar("sv_eventlog"))
\r
2530 GameLogEcho(result);
\r
2535 void MapVote_Tick()
\r
2540 keeptwo = mapvote_keeptwotime;
\r
2541 MapVote_CheckRules_1(); // count
\r
2542 if(MapVote_CheckRules_2()) // decide
\r
2546 FOR_EACH_REALCLIENT(other)
\r
2548 // hide scoreboard again
\r
2549 if(other.health != 2342)
\r
2551 other.health = 2342;
\r
2552 other.impulse = 0;
\r
2553 if(clienttype(other) == CLIENTTYPE_REAL)
\r
2555 msg_entity = other;
\r
2556 WriteByte(MSG_ONE, SVC_FINALE);
\r
2557 WriteString(MSG_ONE, "");
\r
2561 // clear possibly invalid votes
\r
2562 if(mapvote_maps[other.mapvote - 1] == "")
\r
2563 other.mapvote = 0;
\r
2564 // use impulses as new vote
\r
2565 if(other.impulse >= 1 && other.impulse <= mapvote_count)
\r
2566 if(mapvote_maps[other.impulse - 1] != "")
\r
2568 other.mapvote = other.impulse;
\r
2569 MapVote_TouchVotes(other);
\r
2571 other.impulse = 0;
\r
2577 MapVote_CheckRules_1(); // just count
\r
2579 void MapVote_Start()
\r
2584 MapInfo_Enumerate();
\r
2585 if(MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
\r
2586 mapvote_run = TRUE;
\r
2588 void MapVote_Think()
\r
2593 if(alreadychangedlevel)
\r
2596 if(time < mapvote_nextthink)
\r
2598 //dprint("tick\n");
\r
2600 mapvote_nextthink = time + 0.5;
\r
2602 if(!mapvote_initialized)
\r
2604 if(cvar("rescan_pending") == 1)
\r
2606 cvar_set("rescan_pending", "2");
\r
2607 localcmd("fs_rescan\nrescan_pending 3\n");
\r
2610 else if(cvar("rescan_pending") == 2)
\r
2614 else if(cvar("rescan_pending") == 3)
\r
2616 // now build missing mapinfo files
\r
2617 if(!MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1))
\r
2620 // we're done, start the timer
\r
2621 cvar_set("rescan_pending", "0");
\r
2624 mapvote_initialized = TRUE;
\r
2625 if(DoNextMapOverride())
\r
2627 if(!cvar("g_maplist_votable") || player_count <= 0)
\r
2638 string GotoMap(string m)
\r
2640 if(!MapInfo_CheckMap(m))
\r
2641 return "The map you chose is not available on this server.";
\r
2642 cvar_set("nextmap", m);
\r
2643 cvar_set("timelimit", "-1");
\r
2644 if(mapvote_initialized || alreadychangedlevel)
\r
2646 if(DoNextMapOverride())
\r
2647 return "Map switch initiated.";
\r
2649 return "Hm... no. For some reason I like THIS map more.";
\r
2652 return "Map switch will happen after scoreboard.";
\r
2659 FOR_EACH_REALCLIENT(self)
\r
2661 if(self.classname == "spectator")
\r
2663 if(self.enemy.typehitsound)
\r
2664 play2(self, "misc/typehit.wav");
\r
2665 else if(self.enemy.hitsound && self.cvar_cl_hitsound)
\r
2666 play2(self, "misc/hit.wav");
\r
2670 if(self.typehitsound)
\r
2671 play2(self, "misc/typehit.wav");
\r
2672 else if(self.hitsound && self.cvar_cl_hitsound)
\r
2673 play2(self, "misc/hit.wav");
\r
2676 altime = time + frametime * (1 + cvar("g_antilag_nudge"));
\r
2677 // add 1 frametime because after this, engine SV_Physics
\r
2678 // increases time by a frametime and then networks the frame
\r
2679 // add another frametime because client shows everything with
\r
2680 // 1 frame of lag (cl_nolerp 0). The last +1 however should not be
\r
2682 FOR_EACH_CLIENT(self)
\r
2684 self.hitsound = FALSE;
\r
2685 self.typehitsound = FALSE;
\r
2686 antilag_record(self, altime);
\r
2692 * RedirectionThink:
\r
2693 * returns TRUE if redirecting
\r
2695 float redirection_timeout;
\r
2696 float redirection_nextthink;
\r
2697 float RedirectionThink()
\r
2699 float clients_found;
\r
2701 if(redirection_target == "")
\r
2704 if(!redirection_timeout)
\r
2706 cvar_set("sv_public", "-2");
\r
2707 redirection_timeout = time + 0.6; // this will only try twice... should be able to keep more clients
\r
2708 if(redirection_target == "self")
\r
2709 bprint("^3SERVER NOTICE:^7 restarting the server\n");
\r
2711 bprint("^3SERVER NOTICE:^7 redirecting everyone to ", redirection_target, "\n");
\r
2714 if(time < redirection_nextthink)
\r
2717 redirection_nextthink = time + 1;
\r
2719 clients_found = 0;
\r
2720 FOR_EACH_REALCLIENT(self)
\r
2722 print("Redirecting: sending connect command to ", self.netname, "\n");
\r
2723 if(redirection_target == "self")
\r
2724 stuffcmd(self, "\ndisconnect; reconnect\n");
\r
2726 stuffcmd(self, strcat("\ndisconnect; connect ", redirection_target, "\n"));
\r
2730 print("Redirecting: ", ftos(clients_found), " clients left.\n");
\r
2732 if(time > redirection_timeout || clients_found == 0)
\r
2733 localcmd("\nwait; wait; wait; quit\n");
\r
2738 void TargetMusic_RestoreGame();
\r
2739 void RestoreGame()
\r
2741 // Loaded from a save game
\r
2742 // some things then break, so let's work around them...
\r
2744 // Progs DB (capture records)
\r
2745 ServerProgsDB = db_load("server.db");
\r
2748 MapInfo_Shutdown();
\r
2749 MapInfo_Enumerate();
\r
2750 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 1);
\r
2751 WeaponStats_Init();
\r
2753 TargetMusic_RestoreGame();
\r
2756 void SV_Shutdown()
\r
2758 if(gameover > 1) // shutting down already?
\r
2761 gameover = 2; // 2 = server shutting down
\r
2763 if(world_initialized > 0)
\r
2765 world_initialized = 0;
\r
2766 print("Saving persistent data...\n");
\r
2768 if(!cheatcount_total)
\r
2769 db_save(ServerProgsDB, "server.db");
\r
2770 if(cvar("developer"))
\r
2771 db_save(TemporaryDB, "server-temp.db");
\r
2772 CheatShutdown(); // must be after cheatcount check
\r
2773 db_close(ServerProgsDB);
\r
2774 db_close(TemporaryDB);
\r
2776 // tell the bot system the game is ending now
\r
2779 WeaponStats_Shutdown();
\r
2780 MapInfo_Shutdown();
\r
2782 else if(world_initialized == 0)
\r
2784 print("NOTE: crashed before even initializing the world, not saving persistent data\n");
\r