Xonotic
mapvoting.qc File Reference
+ Include dependency graph for mapvoting.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool GameTypeVote_AddVotable (string nextMode)
 
int GameTypeVote_AvailabilityStatus (string type_name)
 
bool GameTypeVote_Finished (int pos)
 
int GameTypeVote_GetMask ()
 
string GameTypeVote_MapInfo_FixName (string m)
 
void GameTypeVote_SendOption (int i)
 
bool GameTypeVote_SetGametype (Gametype type)
 
bool GameTypeVote_Start ()
 
Gametype GameTypeVote_Type_FromString (string type_name)
 Returns the gamtype ID from its name, if type_name isn't a real gametype it checks for sv_vote_gametype_(type_name)_type. More...
 
void MapVote_AddVotable (string nextMap, bool isSuggestion)
 
void MapVote_CheckRules_1 ()
 
bool MapVote_CheckRules_2 ()
 
void MapVote_ClearAllVotes ()
 
bool MapVote_Finished (int mappos)
 
void MapVote_Init ()
 
bool MapVote_SendEntity (entity this, entity to, int sf)
 
void MapVote_SendOption (int i)
 
void MapVote_SendPicture (entity to, int id)
 
void MapVote_Spawn ()
 
void MapVote_Start ()
 
string MapVote_Suggest (entity this, string m)
 
void MapVote_Think ()
 
void MapVote_Tick ()
 
void MapVote_TouchMask ()
 
void MapVote_TouchVotes (entity voter)
 
void MapVote_UnzoneStrings ()
 
void MapVote_WriteMask ()
 

Variables

bool gametypevote_finished
 
int mapvote
 
bool mapvote_abstain
 
int mapvote_count
 
int mapvote_count_real
 
bool mapvote_detail
 
entity mapvote_ent
 
float mapvote_keeptwotime
 
string mapvote_maps [MAPVOTE_COUNT]
 
int mapvote_maps_flags [MAPVOTE_COUNT]
 
string mapvote_maps_pakfile [MAPVOTE_COUNT]
 
int mapvote_maps_screenshot_dir [MAPVOTE_COUNT]
 
bool mapvote_maps_suggested [MAPVOTE_COUNT]
 
float mapvote_nextthink
 
bool mapvote_run
 
string mapvote_screenshot_dirs [MAPVOTE_SCREENSHOT_DIRS_COUNT]
 
const int MAPVOTE_SCREENSHOT_DIRS_COUNT = 4
 
int mapvote_screenshot_dirs_count
 
int mapvote_selections [MAPVOTE_COUNT]
 
int mapvote_suggestion_ptr
 
string mapvote_suggestions [MAPVOTE_COUNT]
 
float mapvote_timeout
 
int mapvote_voters
 

Function Documentation

◆ GameTypeVote_AddVotable()

bool GameTypeVote_AddVotable ( string  nextMode)

Definition at line 751 of file mapvoting.qc.

References GameTypeVote_AvailabilityStatus(), GameTypeVote_Type_FromString(), mapvote_count, mapvote_maps, mapvote_maps_flags, mapvote_maps_pakfile, mapvote_maps_screenshot_dir, mapvote_maps_suggested, NULL, and strzone().

Referenced by GameTypeVote_Start().

752 {
753  if ( nextMode == "" || GameTypeVote_Type_FromString(nextMode) == NULL )
754  return false;
755 
756  for(int j = 0; j < mapvote_count; ++j)
757  if(mapvote_maps[j] == nextMode)
758  return false;
759 
760  mapvote_maps[mapvote_count] = strzone(nextMode);
762 
766 
767  mapvote_count += 1;
768 
769  return true;
770 
771 }
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
Gametype GameTypeVote_Type_FromString(string type_name)
Returns the gamtype ID from its name, if type_name isn&#39;t a real gametype it checks for sv_vote_gamety...
Definition: mapvoting.qc:49
bool mapvote_maps_suggested[MAPVOTE_COUNT]
Definition: mapvoting.qc:32
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
int GameTypeVote_AvailabilityStatus(string type_name)
Definition: mapvoting.qc:58
int mapvote_maps_screenshot_dir[MAPVOTE_COUNT]
Definition: mapvoting.qc:30
#define NULL
Definition: post.qh:17
int mapvote_count
Definition: mapvoting.qc:27
string mapvote_maps_pakfile[MAPVOTE_COUNT]
Definition: mapvoting.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_AvailabilityStatus()

int GameTypeVote_AvailabilityStatus ( string  type_name)

Definition at line 58 of file mapvoting.qc.

References autocvar_nextmap, cvar_string(), MapInfo_Get_ByName(), MapInfo_Map_supportedGametypes, MapInfo_Type_FromString(), NULL, and strcat().

Referenced by GameTypeVote_AddVotable().

59 {
60  int flag = GTV_FORBIDDEN;
61 
62  Gametype type = MapInfo_Type_FromString(type_name, false);
63  if ( type == NULL )
64  {
66  strcat("sv_vote_gametype_",type_name,"_type")), false);
67  flag |= GTV_CUSTOM;
68  }
69 
70  if( type == NULL )
71  return flag;
72 
73  if ( autocvar_nextmap != "" )
74  {
76  return flag;
77  if (!(MapInfo_Map_supportedGametypes & type.m_flags))
78  return flag;
79  }
80 
81  return flag | GTV_AVAILABLE;
82 }
string autocvar_nextmap
Definition: intermission.qh:4
int MapInfo_Map_supportedGametypes
Definition: mapinfo.qh:13
Gametype MapInfo_Type_FromString(string gtype, bool dowarn)
Definition: mapinfo.qc:589
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int MapInfo_Get_ByName(string pFilename, float pAllowGenerate, Gametype pGametypeToSet)
Definition: mapinfo.qc:1067
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_Finished()

bool GameTypeVote_Finished ( int  pos)

Definition at line 733 of file mapvoting.qc.

References gametypevote, gametypevote_finished, GameTypeVote_SetGametype(), GameTypeVote_Type_FromString(), localcmd, LOG_TRACE, and mapvote_maps.

Referenced by MapVote_Finished().

734 {
736  return false;
737 
738  localcmd("sv_vote_gametype_hook_all\n");
739  localcmd("sv_vote_gametype_hook_", mapvote_maps[pos], "\n");
740 
742  {
743  LOG_TRACE("Selected gametype is not supported by any map");
744  }
745 
746  gametypevote_finished = true;
747 
748  return true;
749 }
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
bool GameTypeVote_SetGametype(Gametype type)
Definition: mapvoting.qc:697
Gametype GameTypeVote_Type_FromString(string type_name)
Returns the gamtype ID from its name, if type_name isn&#39;t a real gametype it checks for sv_vote_gamety...
Definition: mapvoting.qc:49
float gametypevote
Definition: mapvoting.qc:40
#define LOG_TRACE(...)
Definition: log.qh:81
bool gametypevote_finished
Definition: mapvoting.qc:732
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_GetMask()

int GameTypeVote_GetMask ( )

Definition at line 84 of file mapvoting.qc.

References argv(), autocvar_sv_vote_gametype_options, GameTypeVote_Type_FromString(), min(), and tokenizebyseparator.

Referenced by GameTypeVote_MapInfo_FixName().

85 {
86  int n, j, gametype_mask;
88  n = min(MAPVOTE_COUNT, n);
89  gametype_mask = 0;
90  for(j = 0; j < n; ++j)
91  gametype_mask |= GameTypeVote_Type_FromString(argv(j)).m_flags;
92  return gametype_mask;
93 }
Gametype GameTypeVote_Type_FromString(string type_name)
Returns the gamtype ID from its name, if type_name isn&#39;t a real gametype it checks for sv_vote_gamety...
Definition: mapvoting.qc:49
string autocvar_sv_vote_gametype_options
Definition: mapvoting.qh:24
#define tokenizebyseparator
Definition: dpextensions.qh:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_MapInfo_FixName()

string GameTypeVote_MapInfo_FixName ( string  m)

Definition at line 95 of file mapvoting.qc.

References _MapInfo_FilterGametype(), autocvar_sv_vote_gametype, GameTypeVote_GetMask(), MapInfo_Enumerate(), MapInfo_FixName(), MapInfo_ForbiddenFlags(), and MapInfo_RequiredFlags().

Referenced by DoNextMapOverride(), GotoMap(), and MapVote_Suggest().

96 {
98  {
101  }
102  return MapInfo_FixName(m);
103 }
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
int GameTypeVote_GetMask()
Definition: mapvoting.qc:84
string MapInfo_FixName(string s)
Definition: mapinfo.qc:1134
float _MapInfo_FilterGametype(int pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition: mapinfo.qc:162
void MapInfo_Enumerate()
Definition: mapinfo.qc:115
bool autocvar_sv_vote_gametype
Definition: mapvoting.qh:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_SendOption()

void GameTypeVote_SendOption ( int  i)

Definition at line 315 of file mapvoting.qc.

References cvar_string(), mapvote_abstain, mapvote_count, mapvote_maps, mapvote_maps_flags, strcat(), WriteByte(), and WriteString().

Referenced by MapVote_SendEntity().

316 {
317  // abstain
318  if(mapvote_abstain && i == mapvote_count - 1)
319  {
320  WriteString(MSG_ENTITY, ""); // abstain needs no text
321  WriteByte(MSG_ENTITY, GTV_AVAILABLE);
322  }
323  else
324  {
325  string type_name = mapvote_maps[i];
326  WriteString(MSG_ENTITY, type_name);
327  WriteByte(MSG_ENTITY, mapvote_maps_flags[i]);
328  if ( mapvote_maps_flags[i] & GTV_CUSTOM )
329  {
330  WriteString(MSG_ENTITY, cvar_string(
331  strcat("sv_vote_gametype_",type_name,"_name")));
332  WriteString(MSG_ENTITY, cvar_string(
333  strcat("sv_vote_gametype_",type_name,"_description")));
334  WriteString(MSG_ENTITY, cvar_string(
335  strcat("sv_vote_gametype_",type_name,"_type")));
336  }
337  }
338 }
bool mapvote_abstain
Definition: mapvoting.qc:40
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int mapvote_count
Definition: mapvoting.qc:27
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_SetGametype()

bool GameTypeVote_SetGametype ( Gametype  type)

Definition at line 697 of file mapvoting.qc.

References autocvar_g_maplist_shuffle, bprint(), cvar_set(), getlsmaps(), MapInfo_count, MapInfo_CurrentFeatures(), MapInfo_CurrentGametype(), MapInfo_Enumerate(), MapInfo_FilterGametype(), MapInfo_ForbiddenFlags(), MapInfo_ListAllowedMaps(), MapInfo_RequiredFlags(), MapInfo_SwitchGameType(), MapInfo_Type_ToString(), ShuffleMaplist(), strunzone(), and strzone().

Referenced by GameTypeVote_Finished().

698 {
699  if (MapInfo_CurrentGametype() == type)
700  return true;
701 
703 
705 
708  if(MapInfo_count > 0)
709  {
710  // update lsmaps in case the gametype changed, this way people can easily list maps for it
711  if(lsmaps_reply != "") { strunzone(lsmaps_reply); }
712  lsmaps_reply = strzone(getlsmaps());
713  bprint("Game type successfully switched to ", MapInfo_Type_ToString(type), "\n");
714  }
715  else
716  {
717  bprint("Cannot use this game type: no map for it found\n");
718  MapInfo_SwitchGameType(tsave);
720  return false;
721  }
722 
723  //localcmd("gametype ", MapInfo_Type_ToString(type), "\n");
724 
727  ShuffleMaplist();
728 
729  return true;
730 }
string MapInfo_Type_ToString(Gametype t)
Definition: mapinfo.qc:616
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
float MapInfo_count
Definition: mapinfo.qh:144
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int MapInfo_CurrentFeatures()
Definition: mapinfo.qc:1140
string MapInfo_ListAllowedMaps(Gametype type, float pRequiredFlags, float pForbiddenFlags)
Definition: mapinfo.qc:1202
void ShuffleMaplist()
float autocvar_g_maplist_shuffle
Definition: mapvoting.qh:9
float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition: mapinfo.qc:158
void MapInfo_Enumerate()
Definition: mapinfo.qc:115
string getlsmaps()
Definition: getreplies.qc:253
void MapInfo_SwitchGameType(Gametype t)
Definition: mapinfo.qc:1178
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_Start()

bool GameTypeVote_Start ( )

Definition at line 773 of file mapvoting.qc.

References argv(), autocvar_g_maplist_votable_nodetail, autocvar_sv_vote_gametype_keeptwotime, autocvar_sv_vote_gametype_options, autocvar_sv_vote_gametype_timeout, gametypevote, GameTypeVote_AddVotable(), MapInfo_CurrentGametype(), MapInfo_Type_ToString(), mapvote_abstain, MapVote_ClearAllVotes(), mapvote_count, mapvote_count_real, mapvote_detail, MapVote_Finished(), mapvote_keeptwotime, mapvote_maps, mapvote_maps_flags, MapVote_Spawn(), mapvote_timeout, MapVote_UnzoneStrings(), min(), strunzone(), strzone(), time, and tokenizebyseparator.

Referenced by MapVote_Think().

774 {
777 
778  mapvote_count = 0;
780  mapvote_abstain = false;
782 
784  n = min(MAPVOTE_COUNT, n);
785 
786  int really_available, which_available;
787  really_available = 0;
788  which_available = -1;
789  for(int j = 0; j < n; ++j)
790  {
791  if ( GameTypeVote_AddVotable(argv(j)) )
792  if ( mapvote_maps_flags[j] & GTV_AVAILABLE )
793  {
794  really_available++;
795  which_available = j;
796  }
797  }
798 
800 
801  gametypevote = 1;
802 
803  if ( really_available == 0 )
804  {
805  if ( mapvote_count > 0 )
808  //GameTypeVote_Finished(0);
809  MapVote_Finished(0);
810  return false;
811  }
812  if ( really_available == 1 )
813  {
814  //GameTypeVote_Finished(which_available);
815  MapVote_Finished(which_available);
816  return false;
817  }
818 
820 
824 
825  MapVote_Spawn();
826 
827  return true;
828 }
bool mapvote_abstain
Definition: mapvoting.qc:40
string MapInfo_Type_ToString(Gametype t)
Definition: mapinfo.qc:616
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
void MapVote_Spawn()
Definition: mapvoting.qc:407
float autocvar_sv_vote_gametype_timeout
Definition: mapvoting.qh:23
int mapvote_count_real
Definition: mapvoting.qc:28
void MapVote_UnzoneStrings()
Definition: mapvoting.qc:110
string autocvar_sv_vote_gametype_options
Definition: mapvoting.qh:24
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
bool MapVote_Finished(int mappos)
Definition: mapvoting.qc:422
bool autocvar_g_maplist_votable_nodetail
Definition: mapvoting.qh:13
int mapvote_count
Definition: mapvoting.qc:27
float gametypevote
Definition: mapvoting.qc:40
bool GameTypeVote_AddVotable(string nextMode)
Definition: mapvoting.qc:751
#define tokenizebyseparator
Definition: dpextensions.qh:21
float autocvar_sv_vote_gametype_keeptwotime
Definition: mapvoting.qh:25
bool mapvote_detail
Definition: mapvoting.qc:39
float time
Definition: csprogsdefs.qc:16
void MapVote_ClearAllVotes()
Definition: mapvoting.qc:105
float mapvote_keeptwotime
Definition: mapvoting.qc:21
float mapvote_timeout
Definition: mapvoting.qc:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GameTypeVote_Type_FromString()

Gametype GameTypeVote_Type_FromString ( string  type_name)

Returns the gamtype ID from its name, if type_name isn't a real gametype it checks for sv_vote_gametype_(type_name)_type.

Definition at line 49 of file mapvoting.qc.

References cvar_string(), MapInfo_Type_FromString(), NULL, and strcat().

Referenced by GameTypeVote_AddVotable(), GameTypeVote_Finished(), and GameTypeVote_GetMask().

50 {
51  Gametype type = MapInfo_Type_FromString(type_name, false);
52  if (type == NULL)
54  strcat("sv_vote_gametype_",type_name,"_type")), false);
55  return type;
56 }
Gametype MapInfo_Type_FromString(string gtype, bool dowarn)
Definition: mapinfo.qc:589
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_AddVotable()

void MapVote_AddVotable ( string  nextMap,
bool  isSuggestion 
)

Definition at line 159 of file mapvoting.qc.

References MapInfo_CheckMap(), mapvote_count, mapvote_maps, mapvote_maps_flags, mapvote_maps_pakfile, mapvote_maps_screenshot_dir, mapvote_maps_suggested, mapvote_screenshot_dirs, mapvote_screenshot_dirs_count, strcat(), string_null, strstrofs, strzone(), and substring().

Referenced by MapVote_Init().

160 {
161  int j, i, o;
162  string pakfile, mapfile;
163 
164  if(nextMap == "")
165  return;
166  for(j = 0; j < mapvote_count; ++j)
167  if(mapvote_maps[j] == nextMap)
168  return;
169  // suggestions might be no longer valid/allowed after gametype switch!
170  if(isSuggestion)
171  if(!MapInfo_CheckMap(nextMap))
172  return;
173  mapvote_maps[mapvote_count] = strzone(nextMap);
174  mapvote_maps_suggested[mapvote_count] = isSuggestion;
175 
176  pakfile = string_null;
177  for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
178  {
179  mapfile = strcat(mapvote_screenshot_dirs[i], "/", nextMap);
180  pakfile = whichpack(strcat(mapfile, ".tga"));
181  if(pakfile == "")
182  pakfile = whichpack(strcat(mapfile, ".jpg"));
183  if(pakfile == "")
184  pakfile = whichpack(strcat(mapfile, ".png"));
185  if(pakfile != "")
186  break;
187  }
188  if(i >= mapvote_screenshot_dirs_count)
189  i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
190  for(o = strstrofs(pakfile, "/", 0)+1; o > 0; o = strstrofs(pakfile, "/", 0)+1)
191  pakfile = substring(pakfile, o, -1);
192 
195  mapvote_maps_flags[mapvote_count] = GTV_AVAILABLE;
196 
197  mapvote_count += 1;
198 }
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
string string_null
Definition: nil.qh:9
string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT]
Definition: mapvoting.qc:24
int mapvote_screenshot_dirs_count
Definition: mapvoting.qc:25
bool mapvote_maps_suggested[MAPVOTE_COUNT]
Definition: mapvoting.qc:32
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int mapvote_maps_screenshot_dir[MAPVOTE_COUNT]
Definition: mapvoting.qc:30
#define strstrofs
Definition: dpextensions.qh:42
int mapvote_count
Definition: mapvoting.qc:27
float MapInfo_CheckMap(string s)
Definition: mapinfo.qc:1170
string mapvote_maps_pakfile[MAPVOTE_COUNT]
Definition: mapvoting.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_CheckRules_1()

void MapVote_CheckRules_1 ( )

Definition at line 480 of file mapvoting.qc.

References FOREACH_CLIENT, IS_REAL_CLIENT, mapvote_count, mapvote_maps_flags, mapvote_selections, and mapvote_voters.

Referenced by MapVote_Tick().

481 {
482  for (int i = 0; i < mapvote_count; ++i)
483  if (mapvote_maps_flags[i] & GTV_AVAILABLE)
484  {
485  //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n");
486  mapvote_selections[i] = 0;
487  }
488 
489  mapvote_voters = 0;
491  ++mapvote_voters;
492  if (it.mapvote)
493  {
494  int idx = it.mapvote - 1;
495  //dprint("Player ", it.netname, " vote = ", ftos(idx), "\n");
496  ++mapvote_selections[idx];
497  }
498  });
499 }
int mapvote_voters
Definition: mapvoting.qc:35
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
int mapvote_selections[MAPVOTE_COUNT]
Definition: mapvoting.qc:36
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
int mapvote_count
Definition: mapvoting.qc:27
+ Here is the caller graph for this function:

◆ MapVote_CheckRules_2()

bool MapVote_CheckRules_2 ( )

Definition at line 501 of file mapvoting.qc.

References autocvar_sv_eventlog, autocvar_sv_vote_gametype_default_current, error(), ftos(), GameLogEcho(), gametypevote, MapInfo_CurrentGametype(), MapInfo_Type_ToString(), mapvote_abstain, mapvote_count, mapvote_count_real, MapVote_Finished(), mapvote_keeptwotime, mapvote_maps, mapvote_maps_flags, mapvote_selections, mapvote_timeout, MapVote_TouchMask(), mapvote_voters, RandomSelection_AddFloat, RandomSelection_best_priority, RandomSelection_chosen_float, RandomSelection_Init(), result, strcat(), and time.

Referenced by MapVote_Tick().

502 {
503  int i;
504  int firstPlace, secondPlace, currentPlace;
505  int firstPlaceVotes, secondPlaceVotes, currentVotes;
506  int mapvote_voters_real;
507  string result;
508 
509  if(mapvote_count_real == 1)
510  return MapVote_Finished(0);
511 
512  mapvote_voters_real = mapvote_voters;
513  if(mapvote_abstain)
514  mapvote_voters_real -= mapvote_selections[mapvote_count - 1];
515 
517  currentPlace = 0;
518  currentVotes = -1;
519  for(i = 0; i < mapvote_count_real; ++i)
520  if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
521  {
524  {
525  currentVotes = mapvote_selections[i];
526  currentPlace = i;
527  }
528  }
529  firstPlaceVotes = RandomSelection_best_priority;
530  if ( autocvar_sv_vote_gametype_default_current && firstPlaceVotes == 0 )
531  firstPlace = currentPlace;
532  else
533  firstPlace = RandomSelection_chosen_float;
534 
535  //dprint("First place: ", ftos(firstPlace), "\n");
536  //dprint("First place votes: ", ftos(firstPlaceVotes), "\n");
537 
539  for(i = 0; i < mapvote_count_real; ++i)
540  if(i != firstPlace)
541  if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
543  secondPlace = RandomSelection_chosen_float;
544  secondPlaceVotes = RandomSelection_best_priority;
545  //dprint("Second place: ", ftos(secondPlace), "\n");
546  //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n");
547 
548  if(firstPlace == -1)
549  error("No first place in map vote... WTF?");
550 
551  if(secondPlace == -1 || time > mapvote_timeout || (mapvote_voters_real - firstPlaceVotes) < firstPlaceVotes)
552  return MapVote_Finished(firstPlace);
553 
555  if(time > mapvote_keeptwotime || (mapvote_voters_real - firstPlaceVotes - secondPlaceVotes) < secondPlaceVotes)
556  {
559  result = strcat(":vote:keeptwo:", mapvote_maps[firstPlace]);
560  result = strcat(result, ":", ftos(firstPlaceVotes));
561  result = strcat(result, ":", mapvote_maps[secondPlace]);
562  result = strcat(result, ":", ftos(secondPlaceVotes), "::");
563  int didntvote = mapvote_voters;
564  for(i = 0; i < mapvote_count; ++i)
565  {
566  didntvote -= mapvote_selections[i];
567  if(i != firstPlace)
568  if(i != secondPlace)
569  {
570  result = strcat(result, ":", mapvote_maps[i]);
571  result = strcat(result, ":", ftos(mapvote_selections[i]));
572  if(i < mapvote_count_real)
573  {
574  mapvote_maps_flags[i] &= ~GTV_AVAILABLE;
575  }
576  }
577  }
578  result = strcat(result, ":didn't vote:", ftos(didntvote));
580  GameLogEcho(result);
581  }
582 
583  return false;
584 }
bool mapvote_abstain
Definition: mapvoting.qc:40
string MapInfo_Type_ToString(Gametype t)
Definition: mapinfo.qc:616
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
int mapvote_voters
Definition: mapvoting.qc:35
void MapVote_TouchMask()
Definition: mapvoting.qc:412
ERASEABLE void RandomSelection_Init()
Definition: random.qc:4
int mapvote_count_real
Definition: mapvoting.qc:28
bool autocvar_sv_vote_gametype_default_current
Definition: mapvoting.qh:26
float RandomSelection_chosen_float
Definition: random.qh:6
entity result
Definition: promise.qc:43
int mapvote_selections[MAPVOTE_COUNT]
Definition: mapvoting.qc:36
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
bool MapVote_Finished(int mappos)
Definition: mapvoting.qc:422
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void GameLogEcho(string s)
Definition: gamelog.qc:12
int mapvote_count
Definition: mapvoting.qc:27
float gametypevote
Definition: mapvoting.qc:40
#define RandomSelection_AddFloat(f, weight, priority)
Definition: random.qh:15
bool autocvar_sv_eventlog
Definition: gamelog.qh:3
float time
Definition: csprogsdefs.qc:16
float mapvote_keeptwotime
Definition: mapvoting.qc:21
float mapvote_timeout
Definition: mapvoting.qc:22
float RandomSelection_best_priority
Definition: random.qh:4
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_ClearAllVotes()

void MapVote_ClearAllVotes ( )

Definition at line 105 of file mapvoting.qc.

References FOREACH_CLIENT.

Referenced by GameTypeVote_Start(), and MapVote_Init().

106 {
107  FOREACH_CLIENT(true, { it.mapvote = 0; });
108 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
+ Here is the caller graph for this function:

◆ MapVote_Finished()

bool MapVote_Finished ( int  mappos)

Definition at line 422 of file mapvoting.qc.

References alreadychangedlevel, autocvar_nextmap, autocvar_sv_eventlog, FixClientCvars(), FOREACH_CLIENT, ftos(), GameLogEcho(), gametypevote, GameTypeVote_Finished(), IS_REAL_CLIENT, Map_Goto(), Map_Goto_SetStr(), mapvote_count, MapVote_Init(), mapvote_maps, mapvote_maps_flags, mapvote_maps_suggested, mapvote_selections, mapvote_voters, result, and strcat().

Referenced by GameTypeVote_Start(), and MapVote_CheckRules_2().

423 {
425  return false;
426 
427  string result;
428  int i;
429  int didntvote;
430 
432  {
433  result = strcat(":vote:finished:", mapvote_maps[mappos]);
434  result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::");
435  didntvote = mapvote_voters;
436  for(i = 0; i < mapvote_count; ++i)
437  if(mapvote_maps_flags[i] & GTV_AVAILABLE )
438  {
439  didntvote -= mapvote_selections[i];
440  if(i != mappos)
441  {
442  result = strcat(result, ":", mapvote_maps[i]);
443  result = strcat(result, ":", ftos(mapvote_selections[i]));
444  }
445  }
446  result = strcat(result, ":didn't vote:", ftos(didntvote));
447 
448  GameLogEcho(result);
449  if(mapvote_maps_suggested[mappos])
450  GameLogEcho(strcat(":vote:suggestion_accepted:", mapvote_maps[mappos]));
451  }
452 
454 
455  if(gametypevote)
456  {
457  if ( GameTypeVote_Finished(mappos) )
458  {
459  gametypevote = false;
460  if(autocvar_nextmap != "")
461  {
463  Map_Goto(0);
464  alreadychangedlevel = true;
465  return true;
466  }
467  else
468  MapVote_Init();
469  }
470  return false;
471  }
472 
473  Map_Goto_SetStr(mapvote_maps[mappos]);
474  Map_Goto(0);
475  alreadychangedlevel = true;
476 
477  return true;
478 }
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
int mapvote_voters
Definition: mapvoting.qc:35
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
void Map_Goto_SetStr(string nextmapname)
entity result
Definition: promise.qc:43
string autocvar_nextmap
Definition: intermission.qh:4
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
int mapvote_selections[MAPVOTE_COUNT]
Definition: mapvoting.qc:36
bool mapvote_maps_suggested[MAPVOTE_COUNT]
Definition: mapvoting.qc:32
void Map_Goto(float reinit)
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
bool GameTypeVote_Finished(int pos)
Definition: mapvoting.qc:733
void GameLogEcho(string s)
Definition: gamelog.qc:12
int mapvote_count
Definition: mapvoting.qc:27
float gametypevote
Definition: mapvoting.qc:40
bool alreadychangedlevel
Definition: intermission.qh:11
void MapVote_Init()
Definition: mapvoting.qc:663
bool autocvar_sv_eventlog
Definition: gamelog.qh:3
void FixClientCvars(entity e)
Definition: client.qc:947
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Init()

void MapVote_Init ( )

Definition at line 200 of file mapvoting.qc.

References argv(), autocvar_g_maplist_shuffle, autocvar_g_maplist_votable, autocvar_g_maplist_votable_abstain, autocvar_g_maplist_votable_keeptwotime, autocvar_g_maplist_votable_nodetail, autocvar_g_maplist_votable_screenshot_dir, autocvar_g_maplist_votable_suggestions, autocvar_g_maplist_votable_timeout, boolean, bprint(), cvar_set(), floor(), GetNextMap(), localcmd, MapInfo_CurrentGametype(), MapInfo_ForbiddenFlags(), MapInfo_ListAllowedMaps(), MapInfo_RequiredFlags(), mapvote_abstain, MapVote_AddVotable(), MapVote_ClearAllVotes(), mapvote_count, mapvote_count_real, mapvote_detail, mapvote_keeptwotime, mapvote_screenshot_dirs, MAPVOTE_SCREENSHOT_DIRS_COUNT, mapvote_screenshot_dirs_count, MapVote_Spawn(), mapvote_suggestion_ptr, mapvote_suggestions, mapvote_timeout, MapVote_UnzoneStrings(), min(), random(), ShuffleMaplist(), strzone(), time, and tokenize_console.

201 {
202  int i;
203  int nmax, smax;
204 
207 
208  mapvote_count = 0;
211 
212  if(mapvote_abstain)
213  nmax = min(MAPVOTE_COUNT - 1, autocvar_g_maplist_votable);
214  else
215  nmax = min(MAPVOTE_COUNT, autocvar_g_maplist_votable);
217 
218  // we need this for AddVotable, as that cycles through the screenshot dirs
221  mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
223  for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
225 
227  for(i = 0; i < 100 && mapvote_count < smax; ++i)
229 
230  for(i = 0; i < 100 && mapvote_count < nmax; ++i)
231  MapVote_AddVotable(GetNextMap(), false);
232 
233  if(mapvote_count == 0)
234  {
235  bprint( "Maplist contains no single playable map! Resetting it to default map list.\n" );
238  ShuffleMaplist();
239  localcmd("\nmenu_cmd sync\n");
240  for(i = 0; i < 100 && mapvote_count < nmax; ++i)
241  MapVote_AddVotable(GetNextMap(), false);
242  }
243 
245  if(mapvote_abstain)
246  MapVote_AddVotable("don't care", false);
247 
248  //dprint("mapvote count is ", ftos(mapvote_count), "\n");
249 
254 
255  MapVote_Spawn();
256 }
bool mapvote_abstain
Definition: mapvoting.qc:40
bool autocvar_g_maplist_votable_suggestions
Definition: mapvoting.qh:15
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
float autocvar_g_maplist_votable_keeptwotime
Definition: mapvoting.qh:12
int mapvote_suggestion_ptr
Definition: mapvoting.qc:34
string mapvote_suggestions[MAPVOTE_COUNT]
Definition: mapvoting.qc:33
void MapVote_Spawn()
Definition: mapvoting.qc:407
#define autocvar_g_maplist_votable
Definition: mapvoting.qh:10
string GetNextMap()
int mapvote_count_real
Definition: mapvoting.qc:28
string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT]
Definition: mapvoting.qc:24
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
const int MAPVOTE_SCREENSHOT_DIRS_COUNT
Definition: mapvoting.qc:23
string autocvar_g_maplist_votable_screenshot_dir
Definition: mapvoting.qh:14
int mapvote_screenshot_dirs_count
Definition: mapvoting.qc:25
void MapVote_UnzoneStrings()
Definition: mapvoting.qc:110
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
string MapInfo_ListAllowedMaps(Gametype type, float pRequiredFlags, float pForbiddenFlags)
Definition: mapinfo.qc:1202
void ShuffleMaplist()
bool autocvar_g_maplist_votable_nodetail
Definition: mapvoting.qh:13
float autocvar_g_maplist_votable_timeout
Definition: mapvoting.qh:17
void MapVote_AddVotable(string nextMap, bool isSuggestion)
Definition: mapvoting.qc:159
int mapvote_count
Definition: mapvoting.qc:27
#define tokenize_console
Definition: dpextensions.qh:24
bool autocvar_g_maplist_votable_abstain
Definition: mapvoting.qh:11
float autocvar_g_maplist_shuffle
Definition: mapvoting.qh:9
bool mapvote_detail
Definition: mapvoting.qc:39
float time
Definition: csprogsdefs.qc:16
void MapVote_ClearAllVotes()
Definition: mapvoting.qc:105
#define boolean(value)
Definition: bool.qh:9
float mapvote_keeptwotime
Definition: mapvoting.qc:21
float mapvote_timeout
Definition: mapvoting.qc:22
+ Here is the call graph for this function:

◆ MapVote_SendEntity()

bool MapVote_SendEntity ( entity  this,
entity  to,
int  sf 
)

Definition at line 340 of file mapvoting.qc.

References autocvar_nextmap, autocvar_sv_vote_gametype, gametypevote, GameTypeVote_SendOption(), MapInfo_CurrentGametype(), MapInfo_Type_ToText(), mapvote_abstain, mapvote_count, mapvote_detail, mapvote_maps_flags, mapvote_screenshot_dirs, mapvote_screenshot_dirs_count, mapvote_selections, MapVote_SendOption(), mapvote_timeout, MapVote_WriteMask(), WriteByte(), WriteCoord(), and WriteString().

Referenced by MapVote_Spawn().

341 {
342  int i;
343 
344  if(sf & 1)
345  sf &= ~2; // if we send 1, we don't need to also send 2
346 
347  WriteHeader(MSG_ENTITY, ENT_CLIENT_MAPVOTE);
348  WriteByte(MSG_ENTITY, sf);
349 
350  if(sf & 1)
351  {
352  // flag 1 == initialization
353  for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
354  WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
355  WriteString(MSG_ENTITY, "");
356  WriteByte(MSG_ENTITY, mapvote_count);
357  WriteByte(MSG_ENTITY, mapvote_abstain);
358  WriteByte(MSG_ENTITY, mapvote_detail);
359  WriteCoord(MSG_ENTITY, mapvote_timeout);
360 
361  if ( gametypevote )
362  {
363  // gametype vote
364  WriteByte(MSG_ENTITY, 1);
365  WriteString(MSG_ENTITY, autocvar_nextmap);
366  }
367  else if ( autocvar_sv_vote_gametype )
368  {
369  // map vote but gametype has been chosen via voting screen
370  WriteByte(MSG_ENTITY, 2);
372  }
373  else
374  WriteByte(MSG_ENTITY, 0); // map vote
375 
377 
378  // Send data for the vote options
379  for(i = 0; i < mapvote_count; ++i)
380  {
381  if(gametypevote)
383  else
385  }
386  }
387 
388  if(sf & 2)
389  {
390  // flag 2 == update of mask
392  }
393 
394  if(sf & 4)
395  {
396  if(mapvote_detail)
397  for(i = 0; i < mapvote_count; ++i)
398  if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
399  WriteByte(MSG_ENTITY, mapvote_selections[i]);
400 
401  WriteByte(MSG_ENTITY, to.mapvote);
402  }
403 
404  return true;
405 }
bool mapvote_abstain
Definition: mapvoting.qc:40
void GameTypeVote_SendOption(int i)
Definition: mapvoting.qc:315
void MapVote_WriteMask()
Definition: mapvoting.qc:267
string MapInfo_Type_ToText(Gametype t)
Definition: mapinfo.qc:621
string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT]
Definition: mapvoting.qc:24
entity to
Definition: self.qh:96
int mapvote_screenshot_dirs_count
Definition: mapvoting.qc:25
string autocvar_nextmap
Definition: intermission.qh:4
void MapVote_SendOption(int i)
Definition: mapvoting.qc:295
int mapvote_selections[MAPVOTE_COUNT]
Definition: mapvoting.qc:36
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
int mapvote_count
Definition: mapvoting.qc:27
float gametypevote
Definition: mapvoting.qc:40
bool mapvote_detail
Definition: mapvoting.qc:39
float mapvote_timeout
Definition: mapvoting.qc:22
bool autocvar_sv_vote_gametype
Definition: mapvoting.qh:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_SendOption()

void MapVote_SendOption ( int  i)

Definition at line 295 of file mapvoting.qc.

References mapvote_abstain, mapvote_count, mapvote_maps, mapvote_maps_pakfile, mapvote_maps_screenshot_dir, WriteByte(), and WriteString().

Referenced by MapVote_SendEntity().

296 {
297  // abstain
298  if(mapvote_abstain && i == mapvote_count - 1)
299  {
300  WriteString(MSG_ENTITY, ""); // abstain needs no text
301  WriteString(MSG_ENTITY, ""); // abstain needs no pack
302  WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
303  }
304  else
305  {
306  WriteString(MSG_ENTITY, mapvote_maps[i]);
307  WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
308  WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
309  }
310 }
bool mapvote_abstain
Definition: mapvoting.qc:40
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
int mapvote_maps_screenshot_dir[MAPVOTE_COUNT]
Definition: mapvoting.qc:30
int mapvote_count
Definition: mapvoting.qc:27
string mapvote_maps_pakfile[MAPVOTE_COUNT]
Definition: mapvoting.qc:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_SendPicture()

void MapVote_SendPicture ( entity  to,
int  id 
)

Definition at line 258 of file mapvoting.qc.

References mapvote_maps, mapvote_maps_screenshot_dir, mapvote_screenshot_dirs, msg_entity, MSG_ONE, strcat(), to, and WriteByte().

Referenced by ClientCommand_mv_getpicture().

259 {
260  msg_entity = to;
261  WriteHeader(MSG_ONE, TE_CSQC_PICTURE);
262  WriteByte(MSG_ONE, id);
264 }
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT]
Definition: mapvoting.qc:24
entity to
Definition: self.qh:96
entity msg_entity
Definition: progsdefs.qc:63
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int mapvote_maps_screenshot_dir[MAPVOTE_COUNT]
Definition: mapvoting.qc:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Spawn()

void MapVote_Spawn ( )

Definition at line 407 of file mapvoting.qc.

References mapvote_ent, and MapVote_SendEntity().

Referenced by GameTypeVote_Start(), and MapVote_Init().

408 {
409  Net_LinkEntity(mapvote_ent = new(mapvote_ent), false, 0, MapVote_SendEntity);
410 }
entity mapvote_ent
Definition: mapvoting.qc:43
bool MapVote_SendEntity(entity this, entity to, int sf)
Definition: mapvoting.qc:340
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Start()

void MapVote_Start ( )

Definition at line 632 of file mapvoting.qc.

References MapInfo_CurrentFeatures(), MapInfo_CurrentGametype(), MapInfo_Enumerate(), MapInfo_FilterGametype(), MapInfo_ForbiddenFlags(), MapInfo_RequiredFlags(), and mapvote_run.

Referenced by CheckRules_World(), and IntermissionThink().

633 {
634  // if mapvote is already running, don't do this initialization again
635  if(mapvote_run) { return; }
636 
637  // don't start mapvote until after playerstats gamereport is sent
638  if(PlayerStats_GameReport_DelayMapVote) { return; }
639 
642  mapvote_run = true;
643 }
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
bool mapvote_run
Definition: mapvoting.qc:38
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int MapInfo_CurrentFeatures()
Definition: mapinfo.qc:1140
float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition: mapinfo.qc:158
void MapInfo_Enumerate()
Definition: mapinfo.qc:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Suggest()

string MapVote_Suggest ( entity  this,
string  m 
)

Definition at line 119 of file mapvoting.qc.

References autocvar_g_maplist_votable_suggestions, autocvar_g_maplist_votable_suggestions_override_mostrecent, autocvar_sv_eventlog, autocvar_sv_vote_gametype, floor(), ftos(), GameLogEcho(), gametypevote, GameTypeVote_MapInfo_FixName(), Map_IsRecent(), MapInfo_CheckMap(), mapvote_initialized, mapvote_suggestion_ptr, mapvote_suggestions, playerid, random(), strcat(), strunzone(), and strzone().

Referenced by ClientCommand_suggestmap().

120 {
121  int i;
122  if(m == "")
123  return "That's not how to use this command.";
125  return "Suggestions are not accepted on this server.";
127  if(!gametypevote)
128  return "Can't suggest - voting is already in progress!";
130  if (!m)
131  return "The map you suggested is not available on this server.";
133  if(Map_IsRecent(m))
134  return "This server does not allow for recent maps to be played again. Please be patient for some rounds.";
135 
137  if(!MapInfo_CheckMap(m))
138  return "The map you suggested does not support the current game mode.";
139  for(i = 0; i < mapvote_suggestion_ptr; ++i)
140  if(mapvote_suggestions[i] == m)
141  return "This map was already suggested.";
142  if(mapvote_suggestion_ptr >= MAPVOTE_COUNT)
143  {
144  i = floor(random() * mapvote_suggestion_ptr);
145  }
146  else
147  {
149  mapvote_suggestion_ptr += 1;
150  }
151  if(mapvote_suggestions[i] != "")
155  GameLogEcho(strcat(":vote:suggested:", m, ":", ftos(this.playerid)));
156  return strcat("Suggestion of ", m, " accepted.");
157 }
bool autocvar_g_maplist_votable_suggestions
Definition: mapvoting.qh:15
int mapvote_suggestion_ptr
Definition: mapvoting.qc:34
string mapvote_suggestions[MAPVOTE_COUNT]
Definition: mapvoting.qc:33
int playerid
Definition: client.qh:78
string GameTypeVote_MapInfo_FixName(string m)
Definition: mapvoting.qc:95
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
void GameLogEcho(string s)
Definition: gamelog.qc:12
float MapInfo_CheckMap(string s)
Definition: mapinfo.qc:1170
bool Map_IsRecent(string m)
float gametypevote
Definition: mapvoting.qc:40
bool autocvar_g_maplist_votable_suggestions_override_mostrecent
Definition: mapvoting.qh:16
float mapvote_initialized
Definition: mapvoting.qh:39
bool autocvar_sv_eventlog
Definition: gamelog.qh:3
bool autocvar_sv_vote_gametype
Definition: mapvoting.qh:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Think()

void MapVote_Think ( )

Definition at line 645 of file mapvoting.qc.

References alreadychangedlevel, autocvar_g_maplist_votable, autocvar_nextmap, autocvar_rescan_pending, autocvar_sv_vote_gametype, cvar_set(), DoNextMapOverride(), GameTypeVote_Start(), GotoNextMap(), localcmd, MapInfo_CurrentFeatures(), MapInfo_CurrentGametype(), MapInfo_FilterGametype(), MapInfo_ForbiddenFlags(), MapInfo_RequiredFlags(), MapVote_Init(), mapvote_initialized, mapvote_nextthink, mapvote_run, MapVote_Tick(), player_count, and time.

Referenced by CheckRules_World().

646 {
647  if(!mapvote_run)
648  return;
649 
651  return;
652 
653  if(time < mapvote_nextthink)
654  return;
655  //dprint("tick\n");
656 
657  mapvote_nextthink = time + 0.5;
658 
660  {
661  if(autocvar_rescan_pending == 1)
662  {
663  cvar_set("rescan_pending", "2");
664  localcmd("fs_rescan\nrescan_pending 3\n");
665  return;
666  }
667  else if(autocvar_rescan_pending == 2)
668  {
669  return;
670  }
671  else if(autocvar_rescan_pending == 3)
672  {
673  // now build missing mapinfo files
675  return;
676 
677  // we're done, start the timer
678  cvar_set("rescan_pending", "0");
679  }
680 
681  mapvote_initialized = true;
682  if(DoNextMapOverride(0))
683  return;
685  {
686  GotoNextMap(0);
687  return;
688  }
689 
691  else if(autocvar_nextmap == "") { MapVote_Init(); }
692  }
693 
694  MapVote_Tick();
695 }
void MapVote_Tick()
Definition: mapvoting.qc:586
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
bool mapvote_run
Definition: mapvoting.qc:38
void GotoNextMap(float reinit)
#define autocvar_g_maplist_votable
Definition: mapvoting.qh:10
int player_count
Definition: api.qh:103
bool GameTypeVote_Start()
Definition: mapvoting.qc:773
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
string autocvar_nextmap
Definition: intermission.qh:4
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int MapInfo_CurrentFeatures()
Definition: mapinfo.qc:1140
float DoNextMapOverride(float reinit)
float mapvote_nextthink
Definition: mapvoting.qc:20
bool alreadychangedlevel
Definition: intermission.qh:11
void MapVote_Init()
Definition: mapvoting.qc:663
float mapvote_initialized
Definition: mapvoting.qh:39
float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition: mapinfo.qc:158
float time
Definition: csprogsdefs.qc:16
bool autocvar_sv_vote_gametype
Definition: mapvoting.qh:22
int autocvar_rescan_pending
Definition: mapvoting.qh:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Tick()

void MapVote_Tick ( )

Definition at line 586 of file mapvoting.qc.

References CS(), FOREACH_CLIENT, GetResource(), impulse, IS_REAL_CLIENT, MapVote_CheckRules_1(), MapVote_CheckRules_2(), mapvote_count, mapvote_maps_flags, MapVote_TouchVotes(), msg_entity, MSG_ONE, RES_HEALTH, SetResourceExplicit(), SVC_FINALE, WriteByte(), and WriteString().

Referenced by MapVote_Think().

587 {
588 
589  MapVote_CheckRules_1(); // count
590  if(MapVote_CheckRules_2()) // decide
591  return;
592 
593  int totalvotes = 0;
594  FOREACH_CLIENT(true, {
595  if(!IS_REAL_CLIENT(it))
596  {
597  // apply the same special health value to bots too for consistency's sake
598  if(GetResource(it, RES_HEALTH) != 2342)
599  SetResourceExplicit(it, RES_HEALTH, 2342);
600  continue;
601  }
602  // hide scoreboard again
603  if(GetResource(it, RES_HEALTH) != 2342)
604  {
605  SetResourceExplicit(it, RES_HEALTH, 2342); // health in the voting phase
606  CS(it).impulse = 0;
607 
608  msg_entity = it;
610  WriteString(MSG_ONE, "");
611  }
612 
613  // clear possibly invalid votes
614  if ( !(mapvote_maps_flags[it.mapvote-1] & GTV_AVAILABLE) )
615  it.mapvote = 0;
616  // use impulses as new vote
617  if(CS(it).impulse >= 1 && CS(it).impulse <= mapvote_count)
618  if( mapvote_maps_flags[CS(it).impulse - 1] & GTV_AVAILABLE )
619  {
620  it.mapvote = CS(it).impulse;
621  MapVote_TouchVotes(it);
622  }
623  CS(it).impulse = 0;
624 
625  if(it.mapvote)
626  ++totalvotes;
627  });
628 
629  MapVote_CheckRules_1(); // just count
630 }
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
void MapVote_CheckRules_1()
Definition: mapvoting.qc:480
ClientState CS(Client this)
Definition: state.qh:47
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float impulse
Definition: progsdefs.qc:158
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
RES_HEALTH
Definition: ent_cs.qc:126
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
entity msg_entity
Definition: progsdefs.qc:63
int mapvote_count
Definition: mapvoting.qc:27
bool MapVote_CheckRules_2()
Definition: mapvoting.qc:501
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
void MapVote_TouchVotes(entity voter)
Definition: mapvoting.qc:417
float SVC_FINALE
Definition: progsdefs.qc:341
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_TouchMask()

void MapVote_TouchMask ( )

Definition at line 412 of file mapvoting.qc.

References mapvote_ent.

Referenced by MapVote_CheckRules_2().

413 {
414  mapvote_ent.SendFlags |= 2;
415 }
entity mapvote_ent
Definition: mapvoting.qc:43
+ Here is the caller graph for this function:

◆ MapVote_TouchVotes()

void MapVote_TouchVotes ( entity  voter)

Definition at line 417 of file mapvoting.qc.

References mapvote_ent.

Referenced by MapVote_Tick().

418 {
419  mapvote_ent.SendFlags |= 4;
420 }
entity mapvote_ent
Definition: mapvoting.qc:43
+ Here is the caller graph for this function:

◆ MapVote_UnzoneStrings()

void MapVote_UnzoneStrings ( )

Definition at line 110 of file mapvoting.qc.

References mapvote_count, mapvote_maps, mapvote_maps_pakfile, and strfree.

Referenced by GameTypeVote_Start(), and MapVote_Init().

111 {
112  for(int j = 0; j < mapvote_count; ++j)
113  {
114  strfree(mapvote_maps[j]);
116  }
117 }
string mapvote_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:29
int mapvote_count
Definition: mapvoting.qc:27
string mapvote_maps_pakfile[MAPVOTE_COUNT]
Definition: mapvoting.qc:31
#define strfree(this)
Definition: string.qh:56
+ Here is the caller graph for this function:

◆ MapVote_WriteMask()

void MapVote_WriteMask ( )

Definition at line 267 of file mapvoting.qc.

References BIT, mapvote_count, mapvote_maps_flags, WriteByte(), WriteLong(), and WriteShort().

Referenced by MapVote_SendEntity().

268 {
269  if ( mapvote_count < 24 )
270  {
271  int mask = 0;
272  for(int j = 0; j < mapvote_count; ++j)
273  {
274  if(mapvote_maps_flags[j] & GTV_AVAILABLE)
275  mask |= BIT(j);
276  }
277 
278  if(mapvote_count < 8)
279  WriteByte(MSG_ENTITY, mask);
280  else if (mapvote_count < 16)
281  WriteShort(MSG_ENTITY,mask);
282  else
283  WriteLong(MSG_ENTITY, mask);
284  }
285  else
286  {
287  for (int j = 0; j < mapvote_count; ++j)
288  WriteByte(MSG_ENTITY, mapvote_maps_flags[j]);
289  }
290 }
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
int mapvote_maps_flags[MAPVOTE_COUNT]
Definition: mapvoting.qc:37
int mapvote_count
Definition: mapvoting.qc:27
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ gametypevote_finished

bool gametypevote_finished

Definition at line 732 of file mapvoting.qc.

Referenced by GameTypeVote_Finished().

◆ mapvote

int mapvote

Definition at line 41 of file mapvoting.qc.

◆ mapvote_abstain

◆ mapvote_count

◆ mapvote_count_real

int mapvote_count_real

Definition at line 28 of file mapvoting.qc.

Referenced by GameTypeVote_Start(), MapVote_CheckRules_2(), and MapVote_Init().

◆ mapvote_detail

bool mapvote_detail

Definition at line 39 of file mapvoting.qc.

Referenced by GameTypeVote_Start(), MapVote_Init(), and MapVote_SendEntity().

◆ mapvote_ent

entity mapvote_ent

Definition at line 43 of file mapvoting.qc.

Referenced by MapVote_Spawn(), MapVote_TouchMask(), and MapVote_TouchVotes().

◆ mapvote_keeptwotime

float mapvote_keeptwotime

Definition at line 21 of file mapvoting.qc.

Referenced by GameTypeVote_Start(), MapVote_CheckRules_2(), and MapVote_Init().

◆ mapvote_maps

◆ mapvote_maps_flags

◆ mapvote_maps_pakfile

string mapvote_maps_pakfile[MAPVOTE_COUNT]

◆ mapvote_maps_screenshot_dir

int mapvote_maps_screenshot_dir[MAPVOTE_COUNT]

◆ mapvote_maps_suggested

bool mapvote_maps_suggested[MAPVOTE_COUNT]

Definition at line 32 of file mapvoting.qc.

Referenced by GameTypeVote_AddVotable(), MapVote_AddVotable(), and MapVote_Finished().

◆ mapvote_nextthink

float mapvote_nextthink

Definition at line 20 of file mapvoting.qc.

Referenced by MapVote_Think().

◆ mapvote_run

bool mapvote_run

Definition at line 38 of file mapvoting.qc.

Referenced by MapVote_Start(), and MapVote_Think().

◆ mapvote_screenshot_dirs

string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT]

◆ MAPVOTE_SCREENSHOT_DIRS_COUNT

const int MAPVOTE_SCREENSHOT_DIRS_COUNT = 4

Definition at line 23 of file mapvoting.qc.

Referenced by MapVote_Init().

◆ mapvote_screenshot_dirs_count

int mapvote_screenshot_dirs_count

Definition at line 25 of file mapvoting.qc.

Referenced by MapVote_AddVotable(), MapVote_Init(), and MapVote_SendEntity().

◆ mapvote_selections

int mapvote_selections[MAPVOTE_COUNT]

◆ mapvote_suggestion_ptr

int mapvote_suggestion_ptr

Definition at line 34 of file mapvoting.qc.

Referenced by MapVote_Init(), and MapVote_Suggest().

◆ mapvote_suggestions

string mapvote_suggestions[MAPVOTE_COUNT]

Definition at line 33 of file mapvoting.qc.

Referenced by MapVote_Init(), and MapVote_Suggest().

◆ mapvote_timeout

float mapvote_timeout

◆ mapvote_voters

int mapvote_voters

Definition at line 35 of file mapvoting.qc.

Referenced by MapVote_CheckRules_1(), MapVote_CheckRules_2(), and MapVote_Finished().