Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
intermission.qc
Go to the documentation of this file.
1#include "intermission.qh"
2
3#include <common/mapinfo.qh>
5#include <common/util.qh>
6#include <server/bot/api.qh>
8#include <server/campaign.qh>
9#include <server/client.qh>
11#include <server/world.qh>
12
14{
15 stuffcmd(pl, sprintf("\nsettemp _nextmap %s\n", get_nextmap()));
16}
17
18void Set_NextMap(string mapname)
19{
20 if (mapname != "")
22 else
24
26}
27
32
33string GetMapname()
34{
35 return mapname;
36}
37
39
40// NOTE: this now expects the map list to be already tokenized and the count in Map_Count
42{
43 string map = GetMapname();
45
46 if(idx >= 0)
47 {
48 if(idx < Map_Count)
49 {
50 if(map == bufstr_get(maplist_buffer, idx))
51 {
52 return idx;
53 }
54 }
55 }
56
57 for(int pos = 0; pos < Map_Count; ++pos)
58 {
59 if(map == bufstr_get(maplist_buffer, pos))
60 return pos;
61 }
62
63 // resume normal maplist rotation if current map is not in g_maplist
64 return idx;
65}
66
67bool MapHasRightSize(string map)
68{
69 int minplayers = max(0, floor(autocvar_minplayers));
70 if (teamplay)
73 && (currentbots || autocvar_bot_number || player_count < minplayers))
74 {
75 string checkwp_msg = strcat("checkwp ", map);
76 if(!fexists(strcat("maps/", map, ".waypoints")))
77 {
78 LOG_TRACE(checkwp_msg, ": no waypoints");
79 return false;
80 }
81 LOG_TRACE(checkwp_msg, ": has waypoints");
82 }
83
85 return true;
86
87 // open map size restriction file (sets map_minplayers and map_maxplayers)
88 if(!MapReadSizes(map))
89 return true; // map has no size restrictions
90
91 string checksize_msg = strcat("MapHasRightSize ", map);
92 int pcount = player_count;
93
95 pcount -= currentbots;
96 pcount -= rint(cvar("g_maplist_sizes_specparty") * pcount);
98 pcount = min(pcount, GetPlayerLimit()); // bind it to the player limit so that forced spectators don't influence the limits
99
100 // ensure small maps can be selected when pcount is low
102 map_minplayers = 0;
103
104 if(pcount < map_minplayers)
105 {
106 LOG_TRACE(checksize_msg, ": not enough");
107 return false;
108 }
109 if(map_maxplayers && pcount > map_maxplayers)
110 {
111 LOG_TRACE(checksize_msg, ": too many");
112 return false;
113 }
114 LOG_TRACE(checksize_msg, ": right size");
115 return true;
116}
117
118string Map_Filename(string m)
119{
120 return strcat("maps/", m, ".bsp");
121}
122
123void Map_MarkAsRecent(string m)
124{
126}
127
128bool Map_IsRecent(string m)
129{
131 return false;
133}
134
135bool Map_Check(string m, int pass)
136{
137 if(pass <= 1)
138 {
139 if(Map_IsRecent(m))
140 return false;
141 }
142 if(MapInfo_CheckMap(m))
143 {
144 if(pass == 2)
145 return true;
146 // MapInfo_Map_flags was set by MapInfo_CheckMap()
148 return false;
149 if(MapHasRightSize(m))
150 return true;
151 return false;
152 }
153 else
154 {
155 string filename = Map_Filename(m);
156 LOG_DEBUG( "Couldn't select '", filename, "'..." );
157 }
158
159 return false;
160}
161
162void Map_Goto_SetStr(string nextmapname)
163{
164 if(getmapname_stored != "")
166 if(nextmapname == "")
168 else
169 getmapname_stored = strzone(nextmapname);
170}
171
172void Map_Goto_SetIndex(int position)
173{
174 Map_Current = position;
175 cvar_set("g_maplist_index", ftos(position));
176 Map_Goto_SetStr(bufstr_get(maplist_buffer, position));
177}
178
179void Map_Goto(float reinit)
180{
182}
183
184// return codes of map selectors:
185// -1 = temporary failure (that is, try some method that is guaranteed to succeed)
186// -2 = permanent failure
187int MaplistMethod_Iterate(void) // usual method
188{
189 int attempts = 42; // skip advanced checks if this many maps fail
190
191 LOG_TRACE("Trying MaplistMethod_Iterate");
192
193 for(int i = 1; i < Map_Count; ++i)
194 {
195 int mapindex = (i + Map_Current) % Map_Count;
196 if(Map_Check(bufstr_get(maplist_buffer, mapindex), 1))
197 return mapindex;
198
199 --attempts;
200 if(attempts <= 0)
201 {
202 LOG_DEBUG("MaplistMethod_Iterate: Couldn't find a suitable map, falling back to next valid");
203 break;
204 }
205 }
206
207 // failing that, just accept the next map in the list
208 int mapindex = (1 + Map_Current) % Map_Count;
209 return mapindex;
210}
211
212int MaplistMethod_Repeat(void) // fallback method
213{
214 LOG_TRACE("Trying MaplistMethod_Repeat");
215
216 if(Map_Check(bufstr_get(maplist_buffer, Map_Current), 2))
217 return Map_Current;
218 return -2;
219}
220
221int MaplistMethod_Random(void) // random map selection
222{
223 int i, imax;
224
225 LOG_TRACE("Trying MaplistMethod_Random");
226
227 imax = 42;
228
229 for(i = 0; i <= imax; ++i)
230 {
231 int mapindex = (Map_Current + floor(random() * (Map_Count - 1) + 1)) % Map_Count; // any OTHER map
232 if(Map_Check(bufstr_get(maplist_buffer, mapindex), 1))
233 return mapindex;
234 }
235 return -1;
236}
237
238// NOTE: call Maplist_Close when you're done!
240{
241 bool have_maps = false;
242 if(autocvar_g_maplist != "")
243 {
244 // make sure there is at least one playable map in the list
245 bool needtrim = false;
247 {
248 if(!fexists(Map_Filename(it)))
249 {
250 needtrim = true;
251 if(have_maps)
252 break;
253 continue;
254 }
255 if(have_maps || !Map_Check(it, 2))
256 continue;
257 have_maps = true;
258 if(needtrim)
259 break;
260 });
261
262 // additionally trim any non-existent maps
263 if(needtrim)
264 {
265 int trimmedmaps = 0;
266 string newmaplist = "";
268 {
269 if(!fexists(Map_Filename(it)))
270 {
271 ++trimmedmaps;
272 continue;
273 }
274 newmaplist = cons(newmaplist, it);
275 });
276 cvar_set("g_maplist", newmaplist);
277 LOG_DEBUGF("Maplist_Init: trimmed %d missing maps from the list", trimmedmaps);
278 }
279 }
280
281 if (!have_maps)
282 {
283 bprint( "Maplist contains no usable maps! Resetting it to default map list.\n" );
286 localcmd("\nmenu_cmd sync\n");
287 }
288
290
291 int _cnt = 0;
293 {
294 // NOTE: inlined maplist_shuffle function to avoid a second buffer, keep both in sync
296 {
297 int _j = floor(random() * (_cnt + 1));
298 if(_j != _cnt)
299 bufstr_set(maplist_buffer, _cnt, bufstr_get(maplist_buffer, _j));
300 bufstr_set(maplist_buffer, _j, it);
301 ++_cnt;
302 }
303 else
304 bufstr_set(maplist_buffer, i, it);
305 });
306
307 Map_Count = buf_getsize(maplist_buffer);
308
309 if(Map_Count == 0)
310 error("empty maplist, cannot select a new map");
311
313
314 return Map_Count;
315}
316
318{
319 buf_del(maplist_buffer);
320}
321
322// NOTE: call Maplist_Init() before making GetNextMap() call(s)
323string GetNextMap(void)
324{
325 int nextMap = -1;
326
327 if(nextMap == -1 && autocvar_g_maplist_selectrandom)
328 nextMap = MaplistMethod_Random();
329
330 if(nextMap == -1)
331 nextMap = MaplistMethod_Iterate();
332
333 if(nextMap == -1)
334 nextMap = MaplistMethod_Repeat();
335
336 if(nextMap >= 0)
337 {
338 Map_Goto_SetIndex(nextMap);
339 return getmapname_stored;
340 }
341
342 return "";
343}
344
345float DoNextMapOverride(float reinit)
346{
348 {
350 alreadychangedlevel = true;
351 return true;
352 }
354 {
356 {
357 localcmd("quit\n");
358 alreadychangedlevel = true;
359 return true;
360 }
361 }
363 {
365 alreadychangedlevel = true;
366 return true;
367 }
368 if (!reinit && autocvar_samelevel) // if samelevel is set, stay on same level
369 {
370 localcmd("restart\n");
371 alreadychangedlevel = true;
372 return true;
373 }
374 if(get_nextmap() != "")
375 {
377 if (m != get_nextmap())
378 Set_NextMap(m);
379
380 if(!m || gametypevote)
381 return false;
383 {
385 return false;
386 }
387
388 if(MapInfo_CheckMap(m))
389 {
391 Map_Goto(reinit);
392 alreadychangedlevel = true;
393 return true;
394 }
395 }
396 if(!reinit && autocvar_lastlevel)
397 {
399 localcmd("set lastlevel 0\ntogglemenu 1\n");
400 alreadychangedlevel = true;
401 return true;
402 }
403 return false;
404}
405
406void GotoNextMap(float reinit)
407{
408 //string nextmap;
409 //float n, nummaps;
410 //string s;
412 return;
413 alreadychangedlevel = true;
414
415 Maplist_Init();
416 string nextMap = GetNextMap();
418 if(nextMap == "")
419 error("Everything is broken - cannot find a next map. Please report this to the developers.");
420 Map_Goto(reinit);
421}
422
423string GotoMap(string m)
424{
426 if (!m)
427 return "The map you suggested is not available on this server.";
429 if (!MapInfo_CheckMap(m))
430 return "The map you suggested does not support the current gametype.";
431 if (m != get_nextmap())
432 Set_NextMap(m);
434 cvar_set("_endmatch", "1");
436 {
437 if(DoNextMapOverride(0))
438 return "Map switch initiated.";
439 else
440 return "Hm... no. For some reason I like THIS map more.";
441 }
442 else
443 return "Map switch will happen after scoreboard.";
444}
445
446
447/*
448============
449IntermissionThink
450
451When the player presses attack or jump, change to the next level
452============
453*/
456{
458
459 float server_screenshot = (autocvar_sv_autoscreenshot && CS_CVAR(this).cvar_cl_autoscreenshot);
460 float client_screenshot = (CS_CVAR(this).cvar_cl_autoscreenshot == 2);
461
462 if( (server_screenshot || client_screenshot)
463 && ((this.autoscreenshot > 0) && (time > this.autoscreenshot)) )
464 {
465 this.autoscreenshot = -1;
466 if(IS_REAL_CLIENT(this))
467 {
468 // in old clients "cl_autoscreenshot_screenshot_s %s %s;" takes the screenshot
469 // "cl_autoscreenshot_screenshot %s %s;" does nothing because the cl_autoscreenshot_screenshot alias
470 // doesn't exist; the cl_autoscreenshot_screenshot dummy cvar is created
471 // so that "cl_autoscreenshot_screenshot %s %s" doesn't print any warning in console
472
473 // in new clients "cl_autoscreenshot_screenshot %s %s;" takes the screenshot
474 // even if the cl_autoscreenshot_screenshot cvar is created, only the cl_autoscreenshot_screenshot alias
475 // is executed since only the alias is executed if a cvar with the same name exists
476 // cl_autoscreenshot_screenshot_s is not run as cl_autoscreenshot_screenshot alias clears it
477 // (it doesn't delete it so that "unalias cl_autoscreenshot_screenshot_s;" doesn't print any warning)
478
479 // this stuffcmd is needed only for Xonotic 0.8.6 or lower
480 // the s in cl_autoscreenshot_screenshot_s stands for server alias (alias name can't be longer than 32)
481 stuffcmd(this, sprintf("\n"
482 "alias cl_autoscreenshot_screenshot_s \"screenshot screenshots/autoscreenshot/%s-%s.jpg\";"
483 "set cl_autoscreenshot_screenshot 0;", GetMapname(), matchid));
484
485 // keep only this stuffcmd after the next release
486 stuffcmd(this, sprintf("\ncl_autoscreenshot_screenshot %s %s;"
487 "echo \"^5A screenshot has been taken at request of the server.\"\n", GetMapname(), matchid));
488
489 // this stuffcmd is needed only for Xonotic 0.8.6 or lower
490 stuffcmd(this, "\n"
491 "cl_autoscreenshot_screenshot_s %s %s;"
492 "unset cl_autoscreenshot_screenshot;"
493 "unalias cl_autoscreenshot_screenshot_s;");
494 }
495 return;
496 }
497
499 return;
500
503 return;
504
506}
507
509{
510 if(!e.autoscreenshot) // initial call
511 {
512 e.autoscreenshot = time + 0.1;
513 SetResourceExplicit(e, RES_HEALTH, -2342); // health in the first intermission phase
514 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
515 {
516 .entity weaponentity = weaponentities[slot];
517 if(e.(weaponentity))
518 {
519 e.(weaponentity).effects = EF_NODRAW;
520 if (e.(weaponentity).weaponchild)
521 e.(weaponentity).weaponchild.effects = EF_NODRAW;
522 }
523 }
524 if(IS_REAL_CLIENT(e))
525 {
526 stuffcmd(e, "\nscr_printspeed 1000000\n");
530 });
532 {
533 stuffcmd(e, sprintf("\ncd loop %s\n", RandomSelection_chosen_string));
534 }
535 msg_entity = e;
537 }
538 }
539}
int currentbots
Definition api.qh:104
int player_count
Definition api.qh:103
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
bool gametypevote
#define PHYS_INPUT_BUTTON_JUMP(s)
Definition player.qh:153
#define PHYS_INPUT_BUTTON_HOOK(s)
Definition player.qh:157
#define PHYS_INPUT_BUTTON_USE(s)
Definition player.qh:160
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition player.qh:152
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition player.qh:154
int cvar_settemp_restore()
Definition util.qc:857
string mapname
float effects
float time
const float EF_NODRAW
int autocvar_bot_number
Definition cvars.qh:64
int autocvar_minplayers
Definition cvars.qh:68
int autocvar_minplayers_per_team
Definition cvars.qh:69
#define buf_create
#define pass(name, colormin, colormax)
WriteByte(chan, ent.angles.y/DEC_FACTOR)
SetResourceExplicit(ent, RES_ARMOR, ReadByte() *DEC_FACTOR)) ENTCS_PROP(NAME
ERASEABLE bool fexists(string f)
Definition file.qh:4
string Map_Filename(string m)
void Maplist_Close()
void Set_NextMap(string mapname)
string GetMapname()
void Map_Goto_SetIndex(int position)
int Map_Current
void FixIntermissionClient(entity e)
void IntermissionThink(entity this)
int Map_Count
bool MapHasRightSize(string map)
void Map_Goto_SetStr(string nextmapname)
float autoscreenshot
int MaplistMethod_Iterate(void)
bool Map_IsRecent(string m)
int GetMaplistPosition()
string GotoMap(string m)
int MaplistMethod_Random(void)
int Maplist_Init(void)
bool Map_Check(string m, int pass)
string GetGametype()
int MaplistMethod_Repeat(void)
void Map_Goto(float reinit)
string GetNextMap(void)
float DoNextMapOverride(float reinit)
void Send_NextMap_To_Player(entity pl)
void Map_MarkAsRecent(string m)
void GotoNextMap(float reinit)
string autocvar_sv_intermission_cdtrack
bool intermission_running
float intermission_exittime
string _nextmap
bool autocvar_samelevel
bool alreadychangedlevel
bool autocvar_lastlevel
#define get_nextmap()
int maplist_buffer
bool autocvar_sv_autoscreenshot
#define FOREACH_WORD(words, cond, body)
Definition iter.qh:33
#define LOG_TRACE(...)
Definition log.qh:74
#define LOG_DEBUG(...)
Definition log.qh:78
#define LOG_DEBUGF(...)
Definition log.qh:79
bool MapReadSizes(string map)
Definition mapinfo.qc:1401
float MapInfo_CheckMap(string s)
Definition mapinfo.qc:1502
int MapInfo_RequiredFlags()
Definition mapinfo.qc:1670
string MapInfo_Type_ToString(Gametype t)
Definition mapinfo.qc:655
void MapInfo_LoadMap(string s, float reinit)
Definition mapinfo.qc:1514
Gametype MapInfo_CurrentGametype()
Definition mapinfo.qc:1482
int MapInfo_ForbiddenFlags()
Definition mapinfo.qc:1655
string MapInfo_ListAllowedMaps(Gametype type, float pRequiredFlags, float pForbiddenFlags)
Definition mapinfo.qc:1533
float _MapInfo_GetTeamPlayBool(Gametype t)
Definition mapinfo.qc:538
int map_minplayers
Definition mapinfo.qh:190
Gametype MapInfo_LoadedGametype
Definition mapinfo.qh:220
int map_maxplayers
Definition mapinfo.qh:191
int MapInfo_Map_flags
Definition mapinfo.qh:15
const int MAPINFO_FLAG_DONOTWANT
Definition mapinfo.qh:164
bool autocvar_g_campaign
Definition menu.qc:752
void localcmd(string command,...)
void cvar_set(string name, string value)
float MSG_ONE
Definition menudefs.qc:56
float bound(float min, float value, float max)
float cvar(string name)
float random(void)
void bprint(string text,...)
float min(float f,...)
void strunzone(string s)
float rint(float f)
string ftos(float f)
float floor(float f)
string strzone(string s)
float max(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define error
Definition pre.qh:6
entity msg_entity
Definition progsdefs.qc:63
float SVC_INTERMISSION
Definition progsdefs.qc:340
#define stuffcmd(cl,...)
Definition progsdefs.qh:23
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
string RandomSelection_chosen_string
Definition random.qh:7
#define RandomSelection_AddString(s, weight, priority)
Definition random.qh:16
#define AVAILABLE_TEAMS
Number of teams that exist currently.
void CampaignPostIntermission()
Definition campaign.qc:240
int GetPlayerLimit()
Definition client.qc:2156
#define CS_CVAR(this)
Definition state.qh:51
ERASEABLE string strwords(string s, int w)
Definition string.qh:365
#define strfree(this)
Definition string.qh:57
#define strhasword(s, w)
Definition string.qh:375
#define strcpy(this, s)
Definition string.qh:51
ERASEABLE string cons(string a, string b)
Definition string.qh:277
string GameTypeVote_MapInfo_FixName(string m)
void MapVote_Start()
float autocvar_g_maplist_shuffle
bool autocvar_g_maplist_check_waypoints
bool autocvar_sv_vote_gametype
bool mapvote_initialized
int autocvar_g_maplist_index
int autocvar_g_maplist_mostrecent_count
bool autocvar_g_maplist_sizes_count_maxplayers
bool autocvar_g_maplist_ignore_sizes
bool autocvar_g_maplist_sizes_count_bots
#define autocvar_g_maplist
string getmapname_stored
string autocvar_g_maplist_mostrecent
bool autocvar_g_maplist_selectrandom
bool teamplay
Definition teams.qh:59
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:52
entity weaponchild
Definition all.qh:400
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
string matchid
Definition world.qh:63
string autocvar_quit_and_redirect
Definition world.qh:13
bool autocvar_quit_when_empty
Definition world.qh:15
bool autocvar_sv_dedicated
Definition world.qh:41
string redirection_target
Definition world.qh:67