1 float SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS = 1;
5 void HandleMaplistShuffleCommands();
6 float() DoNextMapOverride;
10 if(cvar("g_running_guns"))
12 default_player_alpha = -1;
13 default_weapon_alpha = +1;
15 else if(cvar("g_cloaked"))
17 default_player_alpha = cvar("g_balance_cloaked_alpha");
18 default_weapon_alpha = default_player_alpha;
22 default_player_alpha = cvar("g_player_alpha");
23 if(default_player_alpha <= 0)
24 default_player_alpha = 1;
25 default_weapon_alpha = default_player_alpha;
29 void fteqcc_testbugs()
33 if(!cvar("developer_fteqccbugs"))
36 dprint("*** fteqcc test: checking for bugs...\n");
40 if(sqrt(a) - sqrt(b - a) == 0)
41 dprint("*** fteqcc test: found same-function-twice bug\n");
43 dprint("*** fteqcc test: same-function-twice bug got FINALLY FIXED! HOORAY!\n");
47 world.enemy.frags += 10;
48 if(world.frags > 0.2 || world.frags < -0.2) // don't error out if it's just roundoff errors
49 dprint("*** fteqcc test: found += bug\n");
51 dprint("*** fteqcc test: += bug got FINALLY FIXED! HOORAY!\n");
59 cvar_set("_sv_init", "0");
60 HandleMaplistShuffleCommands();
61 tokenize(cvar_string("g_maplist"));
62 if(argv(0) != GetMapname())
64 cvar_set("nextmap", argv(0));
65 if(!DoNextMapOverride())
71 float world_already_spawned;
72 void worldspawn (void)
76 if(world_already_spawned)
77 error("world already spawned - you may have EXACTLY ONE worldspawn!");
78 world_already_spawned = TRUE;
80 // first detect the map type
81 if(cvar("halflifebsp"))
83 maptype = MAPTYPE_HLBSP;
87 str = getsurfacetexture(world, 0);
88 dprint("maptype test texture string = ", str, "\n");
89 if(strstr(str, "/", 0) >= 0)
90 maptype = MAPTYPE_Q3BSP;
91 else if(str == "NULL") // GtkRadiant-ism
92 maptype = MAPTYPE_Q3BSP;
93 else if(str == "notexture") // q3map2-ism
94 maptype = MAPTYPE_Q3BSP;
96 maptype = MAPTYPE_Q1BSP;
98 dprint("Detected map type: ", ftos(maptype), "\n");
100 // Precache all player models
101 // Workaround for "invisible players"
102 precache_model("models/player/carni.zym");
103 precache_model("models/player/crash.zym");
104 precache_model("models/player/grunt.zym");
105 precache_model("models/player/headhunter.zym");
106 precache_model("models/player/insurrectionist.zym");
107 precache_model("models/player/jeandarc.zym");
108 precache_model("models/player/lurk.zym");
109 precache_model("models/player/lycanthrope.zym");
110 precache_model("models/player/marine.zym");
111 precache_model("models/player/nexus.zym");
112 precache_model("models/player/pyria.zym");
113 precache_model("models/player/shock.zym");
114 precache_model("models/player/skadi.zym");
115 precache_model("models/player/specop.zym");
116 precache_model("models/player/visitant.zym");
118 //precache_model ("progs/beam.mdl");
119 precache_model ("models/bullet.mdl");
120 precache_model ("models/casing_bronze.mdl");
121 precache_model ("models/casing_shell.mdl");
122 precache_model ("models/casing_steel.mdl");
123 precache_model ("models/ebomb.mdl");
124 precache_model ("models/elaser.mdl");
125 precache_model ("models/flash.md3");
126 precache_model ("models/gibs/bloodyskull.md3");
127 precache_model ("models/gibs/chunk.mdl");
128 precache_model ("models/gibs/eye.md3");
129 precache_model ("models/gibs/gib1.md3");
130 //precache_model ("models/gibs/gib2.md3");
131 //precache_model ("models/gibs/gib3.md3");
132 //precache_model ("models/gibs/gib4.md3");
133 precache_model ("models/gibs/gib5.md3");
134 //precache_model ("models/gibs/gib6.md3");
135 precache_model ("models/gibs/gib1.mdl");
136 precache_model ("models/gibs/gib2.mdl");
137 precache_model ("models/gibs/gib3.mdl");
138 precache_model ("models/grenademodel.md3");
139 precache_model ("models/hagarmissile.mdl");
140 precache_model ("models/items/a_bullets.mdl");
141 precache_model ("models/items/a_cells.md3");
142 precache_model ("models/items/a_rockets.md3");
143 precache_model ("models/items/a_shells.md3");
144 precache_model ("models/items/g_a1.md3");
145 precache_model ("models/items/g_a25.md3");
146 precache_model ("models/items/g_h1.md3");
147 precache_model ("models/items/g_h25.md3");
148 precache_model ("models/items/g_h100.md3");
149 precache_model ("models/items/g_invincible.md3");
150 precache_model ("models/items/g_strength.md3");
151 precache_model ("models/laser.mdl");
152 precache_model ("models/misc/chatbubble.spr");
153 precache_model ("models/misc/teambubble.spr");
154 precache_model ("models/nexflash.md3");
155 precache_model ("models/plasma.mdl");
156 precache_model ("models/plasmatrail.mdl");
157 precache_model ("models/rocket.md3");
158 //precache_model ("models/sprites/grenexpl.spr");
159 precache_model ("models/runematch/rune.mdl");
160 precache_model ("models/runematch/curse.mdl");
161 //precache_model ("models/sprites/hagar.spr");
162 //precache_model ("models/sprites/muzzleflash.spr32");
163 //precache_model ("models/sprites/electrocombo.spr32");
164 //precache_model ("models/sprites/plasmahitwall.spr32");
165 //precache_model ("models/sprites/plasmashot.spr32");
166 //precache_model ("models/sprites/rockexpl.spr");
167 precache_model ("models/tracer.mdl");
168 precache_model ("models/uziflash.md3");
169 precache_model ("models/weapons/g_crylink.md3");
170 precache_model ("models/weapons/g_electro.md3");
171 precache_model ("models/weapons/g_gl.md3");
172 precache_model ("models/weapons/g_hagar.md3");
173 precache_model ("models/weapons/g_nex.md3");
174 precache_model ("models/weapons/g_rl.md3");
175 precache_model ("models/weapons/g_shotgun.md3");
176 precache_model ("models/weapons/g_uzi.md3");
177 precache_model ("models/weapons/v_crylink.md3");
178 precache_model ("models/weapons/v_electro.md3");
179 precache_model ("models/weapons/v_gl.md3");
180 precache_model ("models/weapons/v_hagar.md3");
181 precache_model ("models/weapons/v_laser.md3");
182 precache_model ("models/weapons/v_nex.md3");
183 precache_model ("models/weapons/v_rl.md3");
184 precache_model ("models/weapons/v_shotgun.md3");
185 precache_model ("models/weapons/v_uzi.md3");
186 precache_model ("models/weapons/w_crylink.zym");
187 precache_model ("models/weapons/w_electro.zym");
188 precache_model ("models/weapons/w_gl.zym");
189 precache_model ("models/weapons/w_hagar.zym");
190 precache_model ("models/weapons/w_laser.zym");
191 precache_model ("models/weapons/w_nex.zym");
192 precache_model ("models/weapons/w_rl.zym");
193 precache_model ("models/weapons/w_shotgun.zym");
194 precache_model ("models/weapons/w_uzi.zym");
196 // laser for laser-guided weapons
197 precache_model ("models/laser_dot.mdl");
199 precache_sound ("misc/null.wav");
200 precache_sound ("misc/armor1.wav");
201 precache_sound ("misc/armor25.wav");
202 precache_sound ("misc/armorimpact.wav");
203 precache_sound ("misc/bodyimpact1.wav");
204 precache_sound ("misc/bodyimpact2.wav");
205 precache_sound ("misc/gib.wav");
206 precache_sound ("misc/gib_splat01.wav");
207 precache_sound ("misc/gib_splat02.wav");
208 precache_sound ("misc/gib_splat03.wav");
209 precache_sound ("misc/gib_splat04.wav");
210 //precache_sound ("misc/h2ohit.wav");
211 precache_sound ("misc/hit.wav");
212 precache_sound ("misc/footstep01.wav");
213 precache_sound ("misc/footstep02.wav");
214 precache_sound ("misc/footstep03.wav");
215 precache_sound ("misc/footstep04.wav");
216 precache_sound ("misc/footstep05.wav");
217 precache_sound ("misc/footstep06.wav");
218 precache_sound ("misc/hitground1.ogg");
219 precache_sound ("misc/hitground2.ogg");
220 precache_sound ("misc/hitground3.ogg");
221 precache_sound ("misc/hitground4.ogg");
222 precache_sound ("misc/itempickup.ogg");
223 precache_sound ("misc/itemrespawn.ogg");
224 precache_sound ("misc/jumppad.ogg");
225 precache_sound ("misc/mediumhealth.ogg");
226 precache_sound ("misc/megahealth.ogg");
227 precache_sound ("misc/minihealth.ogg");
228 precache_sound ("misc/powerup.ogg");
229 precache_sound ("misc/powerup_shield.ogg");
230 precache_sound ("misc/talk.wav");
231 precache_sound ("misc/teleport.ogg");
232 precache_sound ("plats/medplat1.wav");
233 precache_sound ("plats/medplat2.wav");
234 precache_sound ("player/lava.wav");
235 precache_sound ("player/slime.wav");
236 precache_sound ("weapons/crylink_fire.ogg");
237 precache_sound ("weapons/electro_bounce.ogg");
238 precache_sound ("weapons/electro_fire.ogg");
239 precache_sound ("weapons/electro_fire2.ogg");
240 precache_sound ("weapons/electro_fly.wav");
241 precache_sound ("weapons/electro_impact.ogg");
242 precache_sound ("weapons/electro_impact_combo.ogg");
243 //precache_sound ("weapons/grenade_bounce.ogg");
244 precache_sound ("weapons/grenade_bounce1.ogg");
245 precache_sound ("weapons/grenade_bounce2.ogg");
246 precache_sound ("weapons/grenade_bounce3.ogg");
247 precache_sound ("weapons/grenade_bounce4.ogg");
248 precache_sound ("weapons/grenade_bounce5.ogg");
249 precache_sound ("weapons/grenade_bounce6.ogg");
250 precache_sound ("weapons/grenade_fire.ogg");
251 precache_sound ("weapons/grenade_impact.ogg");
252 precache_sound ("weapons/hagar_fire.ogg");
253 precache_sound ("weapons/hagexp1.ogg");
254 precache_sound ("weapons/hagexp2.ogg");
255 precache_sound ("weapons/hagexp3.ogg");
256 precache_sound ("weapons/hook_fire.ogg");
257 precache_sound ("weapons/hook_impact.ogg");
258 precache_sound ("weapons/lasergun_fire.ogg");
259 precache_sound ("weapons/laserimpact.ogg");
260 precache_sound ("weapons/nexfire.ogg");
261 precache_sound ("weapons/neximpact.ogg");
262 precache_sound ("weapons/ric1.ogg");
263 precache_sound ("weapons/ric2.ogg");
264 precache_sound ("weapons/ric3.ogg");
265 precache_sound ("weapons/rocket_fire.ogg");
266 precache_sound ("weapons/rocket_fly.wav");
267 precache_sound ("weapons/rocket_impact.ogg");
268 precache_sound ("weapons/rocket_det.ogg");
269 precache_sound ("weapons/shotgun_fire.ogg");
270 precache_sound ("weapons/tink1.ogg");
271 precache_sound ("weapons/uzi_fire.ogg");
272 precache_sound ("weapons/weapon_switch.ogg");
273 precache_sound ("weapons/weaponpickup.ogg");
274 precache_sound ("weapons/strength_fire.ogg");
276 //precache_sound ("announce/male/kill10.ogg");
277 //precache_sound ("announce/male/kill15.ogg");
278 //precache_sound ("announce/male/kill20.ogg");
279 //precache_sound ("announce/male/kill25.ogg");
280 //precache_sound ("announce/male/kill3.ogg");
281 //precache_sound ("announce/male/kill30.ogg");
282 //precache_sound ("announce/male/kill4.ogg");
283 //precache_sound ("announce/male/kill5.ogg");
284 //precache_sound ("announce/male/kill6.ogg");
285 //precache_sound ("announce/male/mapkill1.ogg");
286 //precache_sound ("announce/robotic/last_second_save.ogg");
287 //precache_sound ("announce/robotic/narrowly_averted.ogg");
288 //precache_sound ("minstagib/mockery.ogg");
290 // announcer sounds - male
291 precache_sound ("announcer/male/03kills.ogg");
292 precache_sound ("announcer/male/05kills.ogg");
293 precache_sound ("announcer/male/10kills.ogg");
294 precache_sound ("announcer/male/15kills.ogg");
295 precache_sound ("announcer/male/20kills.ogg");
296 precache_sound ("announcer/male/25kills.ogg");
297 precache_sound ("announcer/male/30kills.ogg");
298 precache_sound ("announcer/male/botlike.ogg");
299 precache_sound ("announcer/male/electrobitch.ogg");
300 precache_sound ("announcer/male/welcome.ogg");
301 precache_sound ("announcer/male/yoda.ogg");
303 // announcer sounds - robotic
304 precache_sound ("announcer/robotic/1fragleft.ogg");
305 precache_sound ("announcer/robotic/1minuteremains.ogg");
306 precache_sound ("announcer/robotic/2fragsleft.ogg");
307 precache_sound ("announcer/robotic/3fragsleft.ogg");
308 precache_sound ("announcer/robotic/lastsecond.ogg");
309 precache_sound ("announcer/robotic/narrowly.ogg");
310 precache_sound ("announcer/robotic/1.ogg");
311 precache_sound ("announcer/robotic/2.ogg");
312 precache_sound ("announcer/robotic/3.ogg");
313 precache_sound ("announcer/robotic/4.ogg");
314 precache_sound ("announcer/robotic/5.ogg");
315 precache_sound ("announcer/robotic/6.ogg");
316 precache_sound ("announcer/robotic/7.ogg");
317 precache_sound ("announcer/robotic/8.ogg");
318 precache_sound ("announcer/robotic/9.ogg");
319 precache_sound ("announcer/robotic/10.ogg");
321 // plays music for the level if there is any
324 precache_sound (self.noise);
325 ambientsound ('0 0 0', self.noise, 1.00, ATTN_NONE);
331 // 1 FLICKER (first variety)
332 lightstyle(1, "mmnmmommommnonmmonqnmmo");
334 // 2 SLOW STRONG PULSE
335 lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
337 // 3 CANDLE (first variety)
338 lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
341 lightstyle(4, "mamamamamama");
344 lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
346 // 6 FLICKER (second variety)
347 lightstyle(6, "nmonqnmomnmomomno");
349 // 7 CANDLE (second variety)
350 lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
352 // 8 CANDLE (third variety)
353 lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
355 // 9 SLOW STROBE (fourth variety)
356 lightstyle(9, "aaaaaaaazzzzzzzz");
358 // 10 FLUORESCENT FLICKER
359 lightstyle(10, "mmamammmmammamamaaamammma");
361 // 11 SLOW PULSE NOT FADE TO BLACK
362 lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
364 // styles 32-62 are assigned by the light program for switchable lights
369 registercvar("_g_maplist_shufflenow", "0");
370 registercvar("_g_maplist_have_shuffled", "0");
371 registercvar("_g_maplist_add", "");
372 registercvar("_g_maplist_remove", "");
373 registercvar("_g_maplist_putfirst", "");
376 lms_lowest_lives = 0;
381 bot_waypoints_for_items = cvar("g_waypoints_for_items");
382 if(bot_waypoints_for_items == 1)
383 if(self.spawnflags & SPAWNFLAG_NO_WAYPOINTS_FOR_ITEMS)
384 bot_waypoints_for_items = 0;
386 if(cvar("g_campaign"))
390 //if (cvar("g_domination"))
394 head = nextent(world);
399 head = nextent(head);
402 GameLogInit(); // prepare everything
403 if(cvar("sv_eventlog"))
406 GameLogEcho(":logversion:2", FALSE);
407 s = strcat(cvar_string("sv_eventlog_files_counter"), ".");
408 s = strcat(s, ftos(random()));
409 GameLogEcho(strcat(":gamestart:", GetMapname(), ":", s), FALSE);
410 s = ":gameinfo:mutators:LIST";
411 if(cvar("g_grappling_hook"))
412 s = strcat(s, ":grappling_hook");
413 if(!cvar("g_use_ammunition"))
414 s = strcat(s, ":no_use_ammunition");
415 if(!cvar("g_pickup_items"))
416 s = strcat(s, ":no_pickup_items");
417 if(cvar("g_instagib"))
418 s = strcat(s, ":instagib");
419 if(cvar("g_rocketarena"))
420 s = strcat(s, ":rockerarena");
422 s = strcat(s, ":nixnex");
423 if(cvar("g_vampire"))
424 s = strcat(s, ":vampire");
425 if(cvar("g_laserguided_missile"))
426 s = strcat(s, ":laserguided_missile");
427 if(cvar("g_norecoil"))
428 s = strcat(s, ":norecoil");
430 s = strcat(s, ":midair");
431 if(cvar("g_minstagib"))
432 s = strcat(s, ":minstagib");
433 GameLogEcho(s, FALSE);
434 GameLogEcho(":gameinfo:end", FALSE);
437 cvar_set("nextmap", "");
441 if(cvar("g_campaign"))
449 //makestatic (self); // Who the f___ did that?
453 float( string pFilename ) TryFile =
456 dprint("TryFile(\"", pFilename, "\")\n");
457 lHandle = fopen( pFilename, FILE_READ );
458 if( lHandle != -1 ) {
468 if (game == GAME_DEATHMATCH)
470 else if (game == GAME_TEAM_DEATHMATCH)
472 else if (game == GAME_DOMINATION)
474 else if (game == GAME_CTF)
476 else if (game == GAME_RUNEMATCH)
478 else if (game == GAME_LMS)
483 string getmapname_stored;
486 if(getmapname_stored == "")
487 getmapname_stored = strzone(strcat(GetGametype(), "_", mapname));
488 return getmapname_stored;
491 float Map_Count, Map_Current;
492 string Map_Current_Name;
494 // NOTE: this now expects the map list to be already tokenize()d and the count in Map_Count
495 float GetMaplistPosition()
501 idx = cvar("g_maplist_index");
508 for(pos = 0; pos < Map_Count; ++pos)
512 // resume normal maplist rotation if current map is not in g_maplist
516 float MapHasRightSize(string map)
518 // open map size restriction file
520 dprint("opensize "); dprint(map);
521 fh = fopen(strcat("maps/", map, ".sizes"), FILE_READ);
524 float mapmin, mapmax;
526 mapmin = stof(fgets(fh));
527 mapmax = stof(fgets(fh));
529 if(player_count < mapmin)
531 dprint("not enough\n");
534 if(player_count > mapmax)
536 dprint("too many\n");
539 dprint("right size\n");
542 dprint(": not found\n");
546 string Map_Filename(float position)
549 return strcat("maps/", argv(position), ".mapcfg");
552 float(float position, float pass) Map_Check =
556 map_next = argv(position);
558 if(map_next == Map_Current_Name) // same map again in first pass?
560 filename = Map_Filename(position);
561 if(TryFile(filename))
565 if(MapHasRightSize(argv(position)))
570 dprint( "Couldn't find '", filename, "'..\n" );
575 void(string nextmapname) Map_Goto_SetStr =
577 if(getmapname_stored != "")
578 strunzone(getmapname_stored);
579 if(nextmapname == "")
580 getmapname_stored = "";
582 getmapname_stored = strzone(nextmapname);
585 void(float position) Map_Goto_SetFloat =
587 cvar_set("g_maplist_index", ftos(position));
588 Map_Goto_SetStr(argv(position));
591 void() GameResetCfg =
593 // if an exit cfg is defined by exiting map, exec it.
595 exit_cfg = cvar_string("exit_cfg");
597 localcmd(strcat("exec \"", exit_cfg, "\"\n"));
599 localcmd("exec game_reset.cfg\n");
605 localcmd(strcat("exec \"maps/", getmapname_stored ,".mapcfg\"\n"));
608 // return codes of map selectors:
609 // -1 = temporary failure (that is, try some method that is guaranteed to succeed)
610 // -2 = permanent failure
611 float() MaplistMethod_Iterate = // usual method
615 for(pass = 1; pass <= 2; ++pass)
617 for(i = 1; i < Map_Count; ++i)
620 mapindex = math_mod(i + Map_Current, Map_Count);
621 if(Map_Check(mapindex, pass))
628 float() MaplistMethod_Repeat = // fallback method
630 if(Map_Check(Map_Current, 2))
635 float() MaplistMethod_Random = // random map selection
641 for(i = 0; i <= imax; ++i)
644 mapindex = math_mod(Map_Current + ceil(random() * (Map_Count - 1)), Map_Count); // any OTHER map
645 if(Map_Check(mapindex, 1))
651 float(float exponent) MaplistMethod_Shuffle = // more clever shuffling
652 // the exponent sets a bias on the map selection:
653 // the higher the exponent, the
655 float i, j, imax, insertpos;
660 return 0; // only one map, then always play this one
662 for(i = 0; i <= imax; ++i)
666 // now reinsert this at another position
667 insertpos = pow(random(), 1 / exponent); // ]0, 1]
668 insertpos = insertpos * (Map_Count - 1); // ]0, Map_Count - 1]
669 insertpos = ceil(insertpos) + 1; // {2, 3, 4, ..., Map_Count}
670 dprint("SHUFFLE: insert pos = ", ftos(insertpos), "\n");
672 // insert the current map there
674 for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above
675 newlist = strcat(newlist, "'", argv(j), "'");
676 newlist = strcat(newlist, "'", argv(0), "'"); // now insert the just selected map
677 for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last
678 newlist = strcat(newlist, "'", argv(j), "'");
679 cvar_set("g_maplist", newlist);
680 Map_Count = tokenize(newlist);
682 // NOTE: the selected map has just been inserted at (insertpos-1)th position
683 Map_Current = insertpos - 1; // this is not really valid, but this way the fallback has a chance of working
684 if(Map_Check(Map_Current, 1))
690 void() Maplist_Init =
693 temp = cvar_string("g_maplist");
694 Map_Count = tokenize(temp);
697 bprint( "Maplist is empty! Resetting it to default map list.\n" );
698 cvar_set("g_maplist", temp = cvar_string("g_maplist_defaultlist"));
699 Map_Count = tokenize(temp);
702 error("empty maplist, cannot select a new map");
703 Map_Current = bound(0, GetMaplistPosition(), Map_Count - 1);
705 Map_Current_Name = strzone(argv(Map_Current)); // will be automatically freed on exit thanks to DP
706 // this may or may not be correct, but who cares, in the worst case a map
707 // isn't chosen in the first pass that should have been
710 string() GetNextMap =
718 if(cvar("g_maplist_shuffle") > 0)
719 nextMap = MaplistMethod_Shuffle(cvar("g_maplist_shuffle") + 1);
722 if(cvar("g_maplist_selectrandom"))
723 nextMap = MaplistMethod_Random();
726 nextMap = MaplistMethod_Iterate();
729 nextMap = MaplistMethod_Repeat();
733 Map_Goto_SetFloat(nextMap);
734 return getmapname_stored;
740 float() DoNextMapOverride =
742 if(cvar("g_campaign"))
744 CampaignPostIntermission();
747 if(cvar("quit_when_empty"))
749 if(player_count <= currentbots)
755 if (cvar("samelevel")) // if samelevel is set, stay on same level
757 // 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)
758 //localcmd(strcat("exec \"maps/", mapname, ".mapcfg\"\n"));
759 // so instead just restart the current map using the restart command (DOES NOT WORK PROPERLY WITH exit_cfg STUFF)
760 localcmd("restart\n");
761 //changelevel (mapname);
764 if(cvar_string("nextmap") != "")
765 if(TryFile(strcat("maps/", cvar_string("nextmap"), ".mapcfg")))
767 Map_Goto_SetStr(cvar_string("nextmap"));
771 if(cvar("lastlevel"))
774 localcmd("set lastlevel 0\ntogglemenu\n");
782 //local string nextmap;
783 //local float n, nummaps;
785 if (alreadychangedlevel)
787 alreadychangedlevel = TRUE;
793 for(allowReset = 1; allowReset >= 0; --allowReset)
795 nextMap = GetNextMap();
801 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
802 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
806 error("Everything is broken - not even the default map list works. Please report this to the developers.");
818 When the player presses attack or jump, change to the next level
821 .float autoscreenshot;
822 void() MapVote_Think;
823 float mapvote_initialized;
824 void() IntermissionThink =
826 FixIntermissionClient(self);
828 if(cvar("sv_autoscreenshot"))
829 if(self.autoscreenshot)
830 if(time > self.autoscreenshot)
832 self.autoscreenshot = FALSE;
833 if(clienttype(self) == CLIENTTYPE_REAL)
834 stuffcmd(self, "\nscreenshot\necho \"^5A screenshot has been taken at request of the server.\"\n");
838 if (time < intermission_exittime)
841 if(!mapvote_initialized)
842 if (time < intermission_exittime + 10 && !self.button0 && !self.button2 && !self.button3 && !self.button6 && !self.buttonuse)
845 if(intermission_exittime >= 0)
853 Returns the entity to view from
857 entity() FindIntermission =
862 // look for info_intermission first
863 spot = find (world, classname, "info_intermission");
865 { // pick a random one
869 spot = find (spot, classname, "info_intermission");
871 spot = find (spot, classname, "info_intermission");
877 // then look for the start position
878 spot = find (world, classname, "info_player_start");
882 // testinfo_player_start is only found in regioned levels
883 spot = find (world, classname, "testplayerstart");
887 // then look for the start position
888 spot = find (world, classname, "info_player_deathmatch");
892 //objerror ("FindIntermission: no spot");
898 ===============================================================================
902 ===============================================================================
910 if(cvar("_printstats"))
911 cvar_set("_printstats", "0");
920 s = strcat(s, GetMapname(), ":", ftos(rint(time)));
922 if(cvar("sv_eventlog") && gameover)
923 GameLogEcho(s, FALSE);
924 else if(cvar("sv_logscores_console"))
925 ServerConsoleEcho(s, FALSE);
926 if(cvar("sv_logscores_file"))
928 file = fopen(cvar_string("sv_logscores_filename"), FILE_APPEND);
929 fputs(file, strcat(s, "\n"));
932 FOR_EACH_CLIENT(other)
934 if ((clienttype(other) == CLIENTTYPE_REAL) || (clienttype(other) == CLIENTTYPE_BOT && cvar("sv_logscores_bots")))
936 s = strcat(":player:", ftos(other.frags), ":");
937 s = strcat(s, ftos(other.deaths), ":");
938 s = strcat(s, ftos(rint(time - other.jointime)), ":");
939 s = strcat(s, ftos(other.team), ":");
941 if(cvar("sv_logscores_file"))
942 fputs(file, strcat(s, other.netname, "\n"));
943 if(cvar("sv_eventlog") && gameover)
944 GameLogEcho(strcat(s, ftos(other.playerid), ":", other.netname), TRUE);
945 else if(cvar("sv_logscores_console"))
946 ServerConsoleEcho(strcat(s, other.netname), TRUE);
950 if(cvar("sv_eventlog") && gameover)
951 GameLogEcho(":end", FALSE);
952 else if(cvar("sv_logscores_console"))
953 ServerConsoleEcho(":end", FALSE);
954 if(cvar("sv_logscores_file"))
956 fputs(file, ":end\n");
961 void FixIntermissionClient(entity e)
963 if(!e.autoscreenshot) // initial call
965 e.angles = e.v_angle;
966 e.angles_x = -e.angles_x;
967 e.autoscreenshot = time + 0.8; // used for autoscreenshot
969 // first intermission phase; voting phase has positive health (used to decide whether to send SVC_FINALE or not)
971 e.movetype = MOVETYPE_NONE;
972 e.takedamage = DAMAGE_NO;
974 e.weaponentity.effects = EF_NODRAW;
975 stuffcmd(e, "\nscr_printspeed 1000000\n");
976 if(clienttype(e) == CLIENTTYPE_REAL)
979 WriteByte(MSG_ONE, SVC_INTERMISSION);
983 //e.velocity = '0 0 0';
986 // TODO halt weapon animation
991 go to the next level for deathmatch
992 only called if a time or frag limit has expired
1003 intermission_running = 1;
1005 // enforce a wait time before allowing changelevel
1006 if(player_count > 0)
1007 intermission_exittime = time + cvar("sv_mapchange_delay");
1009 intermission_exittime = -60;
1011 WriteByte (MSG_ALL, SVC_CDTRACK);
1012 WriteByte (MSG_ALL, 3);
1013 WriteByte (MSG_ALL, 3);
1015 //pos = FindIntermission ();
1021 if(cvar("sv_eventlog"))
1022 GameLogEcho(":gameover", FALSE);
1027 FOR_EACH_CLIENT(other)
1029 if(maxTotalFrags < other.totalfrags)
1030 maxTotalFrags = other.totalfrags;
1031 if(minTotalFrags > other.totalfrags)
1032 minTotalFrags = other.totalfrags;
1035 FOR_EACH_CLIENT(other)
1037 FixIntermissionClient(other);
1042 bprint(other.netname, " ^7wins.\n");
1046 score = (other.frags - minTotalFrags) / max(maxTotalFrags - minTotalFrags, 1);
1047 f = bound(0, other.play_time / max(time, 1), 1);
1048 // store some statistics?
1052 if(cvar("g_campaign"))
1053 CampaignPreIntermission();
1055 // WriteByte (MSG_ALL, SVC_INTERMISSION);
1062 Exit deathmatch games upon conditions
1065 void() CheckRules_Player =
1067 if (gameover) // someone else quit the game already
1070 if(self.deadflag == DEAD_NO)
1071 self.play_time += frametime;
1073 // fixme: don't check players; instead check dom_team and ctf_team entities
1074 // (div0: and that in CheckRules_World please)
1077 float checkrules_oneminutewarning;
1078 float checkrules_leaderfrags;
1079 float tdm_max_score, tdm_old_score;
1081 float checkrules_equality;
1082 float checkrules_overtimewarning;
1083 float checkrules_overtimeend;
1085 void() InitiateOvertime =
1087 if(!checkrules_overtimeend)
1088 checkrules_overtimeend = time + 60 * cvar("timelimit_maxovertime");
1091 float WINNING_NO = 0; // no winner, but time limits may terminate the game
1092 float WINNING_YES = 1; // winner found
1093 float WINNING_NEVER = 2; // no winner, enter overtime if time limit is reached
1094 float WINNING_STARTOVERTIME = 3; // no winner, enter overtime NOW
1096 float(float fraglimitreached, float equality) GetWinningCode =
1099 if(fraglimitreached)
1100 return WINNING_STARTOVERTIME;
1102 return WINNING_NEVER;
1104 if(fraglimitreached)
1110 // set the .winning flag for exactly those players with a given field value
1111 void(.float field, float value) SetWinners =
1114 FOR_EACH_PLAYER(head)
1115 head.winning = (head.field == value);
1118 // set the .winning flag for those players with a given field value
1119 void(.float field, float value) AddWinners =
1122 FOR_EACH_PLAYER(head)
1123 if(head.field == value)
1127 // clear the .winning flags
1128 void(void) ClearWinners =
1131 FOR_EACH_PLAYER(head)
1135 float() LMS_NewPlayerLives =
1138 fl = cvar("fraglimit");
1142 // first player has left the game for dying too much? Nobody else can get in.
1143 if(lms_lowest_lives < 1)
1146 if(!cvar("g_lms_join_anytime"))
1147 if(lms_lowest_lives < fl - cvar("g_lms_last_join"))
1150 return bound(1, lms_lowest_lives, fl);
1153 // LMS winning condition: game terminates if and only if there's at most one
1154 // one player who's living lives. Top two scores being equal cancels the time
1156 float() WinningCondition_LMS =
1163 have_player = FALSE;
1164 have_players = FALSE;
1165 l = LMS_NewPlayerLives();
1167 head = find(world, classname, "player");
1170 head = find(head, classname, "player");
1172 have_players = TRUE;
1176 // we have at least one player
1179 // two or more active players - continue with the game
1183 // exactly one player?
1186 // but no game has taken place yet
1191 ClearWinners(); SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out
1192 dprint("Have a winner, ending game.\n");
1199 // nobody is playing at all...
1202 // wait for players...
1206 // SNAFU (maybe a draw game?)
1208 dprint("No players, ending game.\n");
1213 // When we get here, we have at least two players who are actually LIVING,
1214 // or one player who is still waiting for a victim to join the server. Now
1215 // check if the top two players have equal score.
1217 checkrules_leaderfrags = 0;
1218 checkrules_equality = FALSE;
1219 FOR_EACH_PLAYER(head)
1221 if(head.frags > checkrules_leaderfrags)
1223 checkrules_leaderfrags = head.frags;
1224 checkrules_equality = FALSE;
1226 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1227 checkrules_equality = TRUE;
1230 SetWinners(frags, checkrules_leaderfrags);
1232 // The top two players have the same amount of lives? No timelimit then,
1233 // enter overtime...
1235 if(checkrules_equality)
1236 return WINNING_NEVER;
1238 // Top two have different scores? Way to go for our beloved TIMELIMIT!
1242 // DM winning condition: game terminates if a player reached the fraglimit,
1243 // unless the first two players have the same score. The latter case also
1244 // breaks the time limit.
1245 float(float fraglimit) WinningCondition_MaxIndividualScore =
1247 float checkrules_oldleaderfrags;
1250 checkrules_oldleaderfrags = checkrules_leaderfrags;
1251 checkrules_leaderfrags = 0;
1252 checkrules_equality = FALSE;
1253 FOR_EACH_PLAYER(head)
1255 if(head.frags > checkrules_leaderfrags)
1257 checkrules_leaderfrags = head.frags;
1258 checkrules_equality = FALSE;
1260 else if(head.frags > 0 && head.frags == checkrules_leaderfrags)
1261 checkrules_equality = TRUE;
1264 if(checkrules_leaderfrags > 0)
1265 SetWinners(frags, checkrules_leaderfrags);
1269 if (!cvar("g_runematch"))
1270 if (checkrules_leaderfrags != checkrules_oldleaderfrags)
1272 if (checkrules_leaderfrags == fraglimit - 1)
1273 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1274 else if (checkrules_leaderfrags == fraglimit - 2)
1275 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1276 else if (checkrules_leaderfrags == fraglimit - 3)
1277 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1280 return GetWinningCode(fraglimit && checkrules_leaderfrags >= fraglimit, checkrules_equality);
1283 float(float fraglimit) WinningConditionBase_Teamplay =
1285 tdm_old_score = tdm_max_score;
1286 tdm_max_score = max4(team1_score, team2_score, team3_score, team4_score);
1288 checkrules_equality =
1293 (team1_score == tdm_max_score)
1294 + (team2_score == tdm_max_score)
1295 + (team3_score == tdm_max_score)
1296 + (team4_score == tdm_max_score)
1300 if(tdm_max_score > 0)
1302 if(team1_score == tdm_max_score)
1303 AddWinners(team, COLOR_TEAM1);
1304 if(team2_score == tdm_max_score)
1305 AddWinners(team, COLOR_TEAM2);
1306 if(team3_score == tdm_max_score)
1307 AddWinners(team, COLOR_TEAM3);
1308 if(team4_score == tdm_max_score)
1309 AddWinners(team, COLOR_TEAM4);
1312 if(!cvar("g_runematch") && !cvar("g_domination"))
1313 if(tdm_max_score != tdm_old_score)
1315 if(tdm_max_score == fraglimit - 1)
1316 sound(world, CHAN_AUTO, "announcer/robotic/1fragleft.ogg", 1, ATTN_NONE);
1317 else if(tdm_max_score == fraglimit - 2)
1318 sound(world, CHAN_AUTO, "announcer/robotic/2fragsleft.ogg", 1, ATTN_NONE);
1319 else if(tdm_max_score == fraglimit - 3)
1320 sound(world, CHAN_AUTO, "announcer/robotic/3fragsleft.ogg", 1, ATTN_NONE);
1323 return GetWinningCode(fraglimit && tdm_max_score >= fraglimit, checkrules_equality);
1326 // TDM winning condition: game terminates if a team's score sum reached the
1327 // fraglimit, unless the first two teams have the same total score. The latter
1328 // case also breaks the time limit.
1329 float(float fraglimit) WinningCondition_MaxTeamSum =
1333 team1_score = team2_score = team3_score = team4_score = 0;
1335 FOR_EACH_PLAYER(head)
1337 if(head.team == COLOR_TEAM1)
1338 team1_score += head.frags;
1339 else if(head.team == COLOR_TEAM2)
1340 team2_score += head.frags;
1341 else if(head.team == COLOR_TEAM3)
1342 team3_score += head.frags;
1343 else if(head.team == COLOR_TEAM4)
1344 team4_score += head.frags;
1347 return WinningConditionBase_Teamplay(fraglimit);
1350 // DOM/CTF winning condition: game terminates if the max of a team's players'
1351 // score reached the fraglimit, unless the first two teams have the same
1352 // maximum score. The latter case also breaks the time limit.
1353 float(float fraglimit) WinningCondition_MaxTeamMax =
1357 team1_score = team2_score = team3_score = team4_score = 0;
1359 FOR_EACH_PLAYER(head)
1361 if(head.team == COLOR_TEAM1)
1363 if(head.frags > team1_score)
1364 team1_score = head.frags;
1366 else if(head.team == COLOR_TEAM2)
1368 if(head.frags > team2_score)
1369 team2_score = head.frags;
1371 else if(head.team == COLOR_TEAM3)
1373 if(head.frags > team3_score)
1374 team3_score = head.frags;
1376 else if(head.team == COLOR_TEAM4)
1378 if(head.frags > team4_score)
1379 team4_score = head.frags;
1383 return WinningConditionBase_Teamplay(fraglimit);
1386 void print_to(entity e, string s)
1389 sprint(e, strcat(s, "\n"));
1391 ServerConsoleEcho(s, TRUE);
1394 void PrintScoreboardFor(entity e, string name, string colorcode, float whichteam)
1404 FOR_EACH_PLAYER(head)
1406 if(!whichteam || head.team == whichteam)
1410 print_to(e, strcat(" ", colorcode, name, ":"));
1412 fragtotal = fragtotal + head.frags;
1413 s = ftos(head.frags);
1414 s = strcat(s, "/", ftos(head.deaths));
1415 s = strcat(s, " @ ", ftos(head.ping));
1416 if(clienttype(head) == CLIENTTYPE_BOT)
1417 s = strcat(s, "botms");
1419 s = strcat(s, "ms");
1420 v = PlayerValue(head);
1422 s = strcat(s, " / ", ftos(v));
1423 print_to(e, strcat(" ", colorcode, head.netname, colorcode, " (", s, ")"));
1426 if(whichteam && found)
1428 s = ftos(fragtotal);
1429 s = strcat(s, " / ", ftos(teamvalue));
1430 print_to(e, strcat(colorcode, " (total: ", s, ")"));
1434 void PrintScoreboard(entity e)
1436 print_to(e, strcat("Time: ", ftos(time / 60)));
1437 print_to(e, strcat("Timelimit: ", ftos(cvar("timelimit"))));
1438 print_to(e, strcat("Fraglimit: ", ftos(cvar("fraglimit"))));
1439 print_to(e, "Scoreboard:");
1442 PrintScoreboardFor(e, "Red", "^1", COLOR_TEAM1);
1443 PrintScoreboardFor(e, "Blue", "^4", COLOR_TEAM2);
1444 PrintScoreboardFor(e, "Pink", "^6", COLOR_TEAM3);
1445 PrintScoreboardFor(e, "Yellow", "^3", COLOR_TEAM4);
1449 PrintScoreboardFor(e, "", "^7", 0);
1454 void RemoveFromMaplist(string m)
1461 litems = tokenize(cvar_string("g_maplist"));
1464 for(i = 0; i < litems; ++i)
1467 result = strcat1(result);
1471 result = strcat(result, "'", argv(i), "'");
1474 cvar_set("g_maplist", result);
1475 ServerConsoleEcho(strcat("Removed ", ftos(found), " items."), FALSE);
1478 void AddToMaplist(string m)
1487 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1489 ServerConsoleEcho("Map not found.", FALSE);
1493 litems = tokenize(cvar_string("g_maplist"));
1494 if(cvar("g_maplist_shuffle"))
1495 ipos = ceil(random() * (litems + 1)) - 1;
1500 for(i = 0; i < litems; ++i)
1505 result = strcat(result, "'", m, "'");
1508 result = strcat(result, "'", argv(i), "'");
1513 result = strcat(result, "'", m, "'");
1516 cvar_set("g_maplist", result);
1517 ServerConsoleEcho("Map added.", FALSE);
1520 ServerConsoleEcho("Map already in list.", FALSE);
1523 void MakeFirstInMaplist(string m)
1525 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1527 ServerConsoleEcho("Map not found.", FALSE);
1532 RemoveFromMaplist(m);
1533 cvar_set("g_maplist", strcat("'", m, "'", cvar_string("g_maplist")));
1536 ServerConsoleEcho("Map added as first one.", FALSE);
1539 void ShuffleMaplist()
1547 result = cvar_string("g_maplist");
1548 litems = tokenize(result);
1550 for(start = 0; start < litems - 1; ++start)
1554 // select a random item
1555 selected = ceil(random() * (litems - start) + start) - 1;
1557 // shift this item to the place start
1558 for(i = 0; i < start; ++i)
1559 result = strcat(result, "'", argv(i), "'");
1560 result = strcat(result, "'", argv(selected), "'");
1561 for(i = start; i < litems; ++i)
1563 result = strcat(result, "'", argv(i), "'");
1565 litems = tokenize(result);
1567 //dprint(result, "\n");
1570 cvar_set("g_maplist", result);
1573 void() HandleMaplistShuffleCommands =
1575 // automatically shuffle when setting g_maplist_shuffle
1576 if(cvar_string("_g_maplist_add") != "")
1578 AddToMaplist(cvar_string("_g_maplist_add"));
1579 cvar_set("_g_maplist_add", "");
1581 if(cvar_string("_g_maplist_remove") != "")
1583 RemoveFromMaplist(cvar_string("_g_maplist_remove"));
1584 cvar_set("_g_maplist_remove", "");
1586 if(cvar_string("_g_maplist_putfirst") != "")
1588 MakeFirstInMaplist(cvar_string("_g_maplist_putfirst"));
1589 cvar_set("_g_maplist_putfirst", "");
1591 if(cvar("_g_maplist_shufflenow") || (cvar("g_maplist_shuffle") && !cvar("_g_maplist_have_shuffled")))
1594 cvar_set("_g_maplist_shufflenow", "0");
1595 cvar_set("_g_maplist_have_shuffled", "1");
1596 ServerConsoleEcho("Shuffled map list.", FALSE);
1598 if(cvar("_g_maplist_have_shuffled"))
1599 if(!cvar("g_maplist_shuffle"))
1600 cvar_set("_g_maplist_have_shuffled", "0");
1607 Exit deathmatch games upon conditions
1610 void() CheckRules_World =
1613 local float timelimit;
1614 local float fraglimit;
1620 if (intermission_running)
1621 if (time >= intermission_exittime + 60)
1623 if(!DoNextMapOverride())
1628 if (gameover) // someone else quit the game already
1633 if(cvar("_scoreboard"))
1635 cvar_set("_scoreboard", "0");
1636 PrintScoreboard(world);
1639 HandleMaplistShuffleCommands();
1641 timelimit = cvar("timelimit") * 60;
1642 fraglimit = cvar("fraglimit");
1644 if(checkrules_overtimeend)
1646 if(!checkrules_overtimewarning)
1648 checkrules_overtimewarning = TRUE;
1649 //sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1650 bcenterprint("^3Now playing ^1OVERTIME^3!\n\n^3Keep fragging until we have a ^1winner^3!");
1655 if (timelimit && time >= timelimit)
1659 if (checkrules_overtimeend && time >= checkrules_overtimeend)
1665 if (!checkrules_oneminutewarning && timelimit > 0 && time > timelimit - 60)
1667 checkrules_oneminutewarning = TRUE;
1668 sound(world, CHAN_AUTO, "announcer/robotic/1minuteremains.ogg", 1, ATTN_NONE);
1671 status = WINNING_NO;
1674 status = WinningCondition_LMS();
1680 if(cvar("g_tdm") || cvar("g_runematch") || cvar("g_ctf") || cvar("g_domination"))
1681 status = WinningCondition_MaxTeamSum(fraglimit);
1683 // status = WinningCondition_MaxTeamMax(fraglimit);
1686 dprint("div0: How can this happen?\n");
1687 status = WinningCondition_MaxTeamMax(fraglimit);
1691 status = WinningCondition_MaxIndividualScore(fraglimit);
1694 if(status == WINNING_STARTOVERTIME)
1696 status = WINNING_NEVER;
1700 if(status == WINNING_NEVER)
1701 // equality cases! Nobody wins if the overtime ends in a draw.
1704 if(checkrules_overtimeend)
1705 if(status != WINNING_NEVER || time >= checkrules_overtimeend)
1706 status = WINNING_YES;
1708 if(status == WINNING_YES)
1712 float randsel_value;
1713 float randsel_priority;
1714 float randsel_count;
1718 randsel_priority = -1;
1721 void RandSel_Add(float priority, float value)
1723 if(priority > randsel_priority)
1725 randsel_priority = priority;
1726 randsel_value = value;
1729 else if(priority == randsel_priority)
1732 if(ceil(random() * randsel_count) == 1)
1733 randsel_value = value;
1737 float mapvote_nextthink;
1738 float mapvote_initialized;
1739 float mapvote_keeptwotime;
1740 float mapvote_timeout;
1741 string mapvote_message;
1743 #define MAPVOTE_COUNT 10
1744 float mapvote_count;
1745 string mapvote_maps[MAPVOTE_COUNT];
1746 float mapvote_maps_suggested[MAPVOTE_COUNT];
1747 string mapvote_suggestions[MAPVOTE_COUNT];
1748 float mapvote_suggestion_ptr;
1749 string mapvote_fillstr;
1750 float mapvote_maxlen;
1751 float mapvote_voters;
1752 float mapvote_votes[MAPVOTE_COUNT];
1755 void MapVote_ClearAllVotes()
1757 FOR_EACH_CLIENT(other)
1761 string MapVote_Suggest(string m)
1765 return "That's not how to use this command.";
1766 if(!cvar("g_maplist_votable_suggestions"))
1767 return "Suggestions are not accepted on this server.";
1768 if(mapvote_initialized)
1769 return "Can't suggest - voting is already in progress!";
1770 if(!TryFile(strcat("maps/", m, ".mapcfg")))
1771 return "The map you suggested is not available on this server.";
1772 for(i = 0; i < mapvote_suggestion_ptr; ++i)
1773 if(mapvote_suggestions[i] == m)
1774 return "This map was already suggested.";
1775 if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
1777 i = ceil(random() * mapvote_suggestion_ptr) - 1;
1781 i = mapvote_suggestion_ptr;
1782 mapvote_suggestion_ptr += 1;
1784 if(mapvote_suggestions[i] != "")
1785 strunzone(mapvote_suggestions[i]);
1786 mapvote_suggestions[i] = strzone(m);
1787 GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(self.playerid), ":", self.netname), TRUE);
1788 return "Suggestion accepted.";
1791 void MapVote_AddVotable(string nextMap, float isSuggestion)
1796 for(j = 0; j < mapvote_count; ++j)
1797 if(mapvote_maps[j] == nextMap)
1799 if(strlen(nextMap) > mapvote_maxlen)
1800 mapvote_maxlen = strlen(nextMap);
1801 mapvote_maps[mapvote_count] = strzone(nextMap);
1802 mapvote_maps_suggested[mapvote_count] = isSuggestion;
1811 MapVote_ClearAllVotes();
1813 nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
1814 smax = min(nmax, cvar("g_maplist_votable_suggestions"));
1817 for(i = 0; i < 100 && mapvote_count < smax; ++i)
1818 MapVote_AddVotable(mapvote_suggestions[ceil(random() * mapvote_suggestion_ptr) - 1], TRUE);
1820 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1821 MapVote_AddVotable(GetNextMap(), FALSE);
1823 if(mapvote_count == 0)
1825 bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
1826 cvar_set("g_maplist", cvar_string("g_maplist_defaultlist"));
1827 for(i = 0; i < 100 && mapvote_count < nmax; ++i)
1828 MapVote_AddVotable(GetNextMap(), FALSE);
1831 //dprint("mapvote count is ", ftos(mapvote_count), "\n");
1833 mapvote_fillstr = " ";
1834 while(strlen(mapvote_fillstr) < mapvote_maxlen + 16)
1835 mapvote_fillstr = strcat(mapvote_fillstr, mapvote_fillstr);
1836 mapvote_fillstr = strzone(mapvote_fillstr);
1838 mapvote_keeptwotime = time + cvar("g_maplist_votable_keeptwotime");
1839 mapvote_timeout = time + cvar("g_maplist_votable_timeout");
1840 if(mapvote_count < 3 || mapvote_keeptwotime <= time)
1841 mapvote_keeptwotime = 0;
1842 mapvote_message = "Choose a map and press its key!";
1844 float MapVote_Finished(float mappos)
1849 result = strcat(":vote:finished:", mapvote_maps[mappos]);
1850 result = strcat(result, ":", ftos(mapvote_votes[mappos]), "::");
1851 for(i = 0; i < mapvote_count; ++i)
1853 if(mapvote_maps[i] != "")
1855 result = strcat(result, ":", mapvote_maps[i]);
1856 result = strcat(result, ":", ftos(mapvote_votes[i]));
1858 GameLogEcho(result, FALSE);
1859 if(mapvote_maps_suggested[mappos])
1860 GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]), FALSE);
1862 FOR_EACH_REALCLIENT(other)
1863 FixClientCvars(other);
1865 Map_Goto_SetStr(mapvote_maps[mappos]);
1869 void MapVote_CheckRules_1()
1873 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1875 //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
1876 mapvote_votes[i] = 0;
1880 FOR_EACH_REALCLIENT(other)
1885 i = other.mapvote - 1;
1886 //dprint("Player ", other.netname, " vote = ", ftos(other.mapvote - 1), "\n");
1887 mapvote_votes[i] = mapvote_votes[i] + 1;
1892 float MapVote_CheckRules_2()
1895 float firstPlace, secondPlace;
1896 float firstPlaceVotes, secondPlaceVotes;
1900 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1901 RandSel_Add(mapvote_votes[i], i);
1902 firstPlace = randsel_value;
1903 firstPlaceVotes = randsel_priority;
1904 //dprint("First place: ", ftos(firstPlace), "\n");
1905 //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
1908 for(i = 0; i < mapvote_count; ++i) if(mapvote_maps[i] != "")
1910 RandSel_Add(mapvote_votes[i], i);
1911 secondPlace = randsel_value;
1912 secondPlaceVotes = randsel_priority;
1913 //dprint("Second place: ", ftos(secondPlace), "\n");
1914 //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
1916 if(firstPlace == -1)
1917 error("No first place in map vote... WTF?");
1919 if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters - firstPlaceVotes) < firstPlaceVotes)
1920 return MapVote_Finished(firstPlace);
1922 if(mapvote_keeptwotime)
1923 if(time > mapvote_keeptwotime || (mapvote_voters - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
1925 mapvote_message = "Now decide between the TOP TWO!";
1926 mapvote_keeptwotime = 0;
1927 result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
1928 result = strcat(result, ":", ftos(firstPlaceVotes));
1929 result = strcat(result, ":", mapvote_maps[secondPlace]);
1930 result = strcat(result, ":", ftos(secondPlaceVotes), "::");
1931 for(i = 0; i < mapvote_count; ++i)
1933 if(i != secondPlace)
1934 if(mapvote_maps[i] != "")
1936 result = strcat(result, ":", mapvote_maps[i]);
1937 result = strcat(result, ":", ftos(mapvote_votes[i]));
1938 strunzone(mapvote_maps[i]);
1939 mapvote_maps[i] = "";
1941 GameLogEcho(result, FALSE);
1953 keeptwo = mapvote_keeptwotime;
1954 MapVote_CheckRules_1(); // count
1955 if(MapVote_CheckRules_2()) // decide
1958 FOR_EACH_REALCLIENT(other)
1960 // hide scoreboard again
1961 if(other.health != 2342)
1963 other.health = 2342;
1965 if(clienttype(other) == CLIENTTYPE_REAL)
1967 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");
1969 WriteByte(MSG_ONE, SVC_FINALE);
1970 WriteString(MSG_ONE, "");
1974 // notify about keep-two
1975 if(keeptwo != 0 && mapvote_keeptwotime == 0)
1976 stuffcmd(other, "\nplay2 misc/invshot.wav\n");
1978 // clear possibly invalid votes
1979 if(mapvote_maps[other.mapvote - 1] == "")
1981 // use impulses as new vote
1982 if(other.impulse >= 1 && other.impulse <= mapvote_count)
1983 if(mapvote_maps[other.impulse - 1] != "")
1984 other.mapvote = other.impulse;
1988 MapVote_CheckRules_1(); // just count
1990 FOR_EACH_REALCLIENT(other)
1992 // display voting screen
1993 msgstr = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
1994 msgstr = substring(msgstr, 0, strlen(msgstr) - mapvote_count);
1995 msgstr = strcat(msgstr, mapvote_message);
1996 msgstr = strcat(msgstr, "\n\n");
1997 for(i = 0; i < mapvote_count; ++i)
1998 if(mapvote_maps[i] == "")
1999 msgstr = strcat(msgstr, "\n");
2002 tmp = mapvote_maps[i];
2003 tmp = strcat(tmp, substring(mapvote_fillstr, 0, mapvote_maxlen - strlen(tmp)));
2004 tmp = strcat(ftos(math_mod(i + 1, 10)), ": ", tmp);
2005 tmp = strcat(tmp, " ^2(", ftos(mapvote_votes[i]), " vote");
2006 if(mapvote_votes[i] != 1)
2007 tmp = strcat(tmp, "s");
2008 tmp = strcat(tmp, ")");
2009 tmp = strcat(tmp, substring(mapvote_fillstr, 0, mapvote_maxlen + 15 - strlen(tmp)));
2010 if(other.mapvote == i + 1)
2011 msgstr = strcat(msgstr, "^3> ", tmp, "\n");
2013 msgstr = strcat(msgstr, "^7 ", tmp, "\n");
2015 i = ceil(mapvote_timeout - time);
2016 msgstr = strcat(msgstr, "\n\n", ftos(i), " second");
2018 msgstr = strcat(msgstr, "s");
2019 msgstr = strcat(msgstr, " left");
2021 centerprint_atprio(other, CENTERPRIO_MAPVOTE, msgstr);
2024 void MapVote_Think()
2026 if(alreadychangedlevel)
2029 if(time < mapvote_nextthink)
2033 mapvote_nextthink = time + 0.5;
2035 if(!mapvote_initialized)
2037 mapvote_initialized = TRUE;
2038 if(DoNextMapOverride())
2040 alreadychangedlevel = TRUE;
2043 if(!cvar("g_maplist_votable"))
2056 float beamindex_modulo;
2064 value = cvar_string("_entityboxes_for");
2068 i = beamindex_modulo;
2069 beamindex_modulo += 1;
2070 if(beamindex_modulo >= 32)
2071 beamindex_modulo = 0;
2072 for(e = world; (e = find(e, classname, value)) != world; )
2080 te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1');
2081 te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1', ma_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1');
2082 te_lightning1(world, mi_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1');
2083 te_lightning1(world, mi_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2084 te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', mi_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1');
2085 te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1', mi_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2086 te_lightning1(world, ma_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1');
2087 te_lightning1(world, ma_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2088 te_lightning1(world, mi_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', mi_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1');
2089 te_lightning1(world, mi_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1', mi_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');
2090 te_lightning1(world, ma_x * '1 0 0' + mi_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + mi_y * '0 1 0' + ma_z * '0 0 1');
2091 te_lightning1(world, ma_x * '1 0 0' + ma_y * '0 1 0' + mi_z * '0 0 1', ma_x * '1 0 0' + ma_y * '0 1 0' + ma_z * '0 0 1');