From: Mattia Basaglia Date: Thu, 9 Jul 2015 08:11:05 +0000 (+0200) Subject: Turn mapvote availability into a flag X-Git-Tag: xonotic-v0.8.1~43^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d444a32fddce0912e10b02361b5ea5b89ffbd857;p=xonotic%2Fxonotic-data.pk3dir.git Turn mapvote availability into a flag --- diff --git a/qcsrc/client/mapvoting.qc b/qcsrc/client/mapvoting.qc index 869efe5e9..bcbf1863a 100644 --- a/qcsrc/client/mapvoting.qc +++ b/qcsrc/client/mapvoting.qc @@ -18,8 +18,8 @@ string mv_pics[MAPVOTE_COUNT]; string mv_pk3[MAPVOTE_COUNT]; float mv_preview[MAPVOTE_COUNT]; float mv_votes[MAPVOTE_COUNT]; -float mv_avail[MAPVOTE_COUNT]; -float mv_avail_start[MAPVOTE_COUNT]; +float mv_flags[MAPVOTE_COUNT]; +float mv_flags_start[MAPVOTE_COUNT]; entity mv_pk3list; float mv_abstain; float mv_ownvote; @@ -51,7 +51,7 @@ string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, v { if(_count == 1) post = _(" (1 vote)"); - else if(_count >= 0 && mv_avail[id] == GTV_AVAILABLE) + else if(_count >= 0 && (mv_flags[id] & GTV_AVAILABLE)) post = sprintf(_(" (%d votes)"), _count); else post = ""; @@ -70,7 +70,7 @@ string GameTypeVote_DescriptionByID(int id) vector MapVote_RGB(int id) { - if(mv_avail[id] != GTV_AVAILABLE) + if(!(mv_flags[id] & GTV_AVAILABLE)) return '1 1 1'; if(id == mv_ownvote) return '0 1 0'; @@ -93,14 +93,14 @@ void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string g vector offset = pos; float nlines = 0; - if(mv_avail_start[id] != GTV_AVAILABLE) + if(!(mv_flags_start[id] & GTV_AVAILABLE)) alpha = 0.2; - else if ( mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha) + else if ( !(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha) alpha = mv_top2_alpha; else alpha = 1; - if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE) + if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE)) { drawfill(rect_pos, rect_size, '1 1 1', 0.1, DRAWFLAG_NORMAL); } @@ -195,7 +195,7 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin text_size = stringwidth(label, false, hud_fontsize); float theAlpha; - if (mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha) + if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha) theAlpha = mv_top2_alpha; else theAlpha = 1; @@ -225,7 +225,7 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin else drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL); - if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE) + if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE)) drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL); } @@ -500,12 +500,17 @@ void MapVote_ReadMask() mask = ReadLong(); for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2) - mv_avail[i] = (mask & power) ? GTV_AVAILABLE : GTV_FORBIDDEN; + { + if ( mask & power ) + mv_flags[i] |= GTV_AVAILABLE; + else + mv_flags[i] &= ~GTV_AVAILABLE; + } } else { for(i = 0; i < mv_num_maps; ++i ) - mv_avail[i] = ReadByte(); + mv_flags[i] = ReadByte(); } } @@ -573,7 +578,7 @@ void MapVote_Init() MapVote_ReadMask(); for(i = 0; i < mv_num_maps; ++i ) - mv_avail_start[i] = mv_avail[i]; + mv_flags_start[i] = mv_flags[i]; // Assume mv_pk3list is world, there should only be 1 mapvote per round mv_pk3list = world; // I'm still paranoid! @@ -588,7 +593,7 @@ void MapVote_Init() mv_maps[i] = map; mv_pk3[i] = pk3; - mv_avail[i] = ReadByte(); + mv_flags[i] = ReadByte(); if(gametypevote) { @@ -627,7 +632,7 @@ int MapVote_MoveLeft(int pos) imp = mv_num_maps - 1; else imp = pos < 1 ? mv_num_maps - 1 : pos - 1; - if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote ) + if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) imp = MapVote_MoveLeft(imp); return imp; } @@ -638,7 +643,7 @@ int MapVote_MoveRight(int pos) imp = 0; else imp = pos >= mv_num_maps - 1 ? 0 : pos + 1; - if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote ) + if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) imp = MapVote_MoveRight(imp); return imp; } @@ -657,7 +662,7 @@ int MapVote_MoveUp(int pos) imp -= mv_columns; } } - if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote ) + if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) imp = MapVote_MoveUp(imp); return imp; } @@ -672,7 +677,7 @@ int MapVote_MoveDown(int pos) if ( imp >= mv_num_maps ) imp = imp % mv_columns; } - if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote ) + if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote ) imp = MapVote_MoveDown(imp); return imp; } @@ -765,7 +770,7 @@ void MapVote_UpdateVotes() int i; for(i = 0; i < mv_num_maps; ++i) { - if(mv_avail[i] == GTV_AVAILABLE) + if(mv_flags[i] & GTV_AVAILABLE) { if(mv_detail) mv_votes[i] = ReadByte(); diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 8c7cb6b3a..79889d50c 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -320,8 +320,7 @@ const int URI_GET_UPDATENOTIFICATION = 33; const int URI_GET_URLLIB = 128; const int URI_GET_URLLIB_END = 191; -// gametype votes -const int GTV_AVAILABLE = 0; -// for later use in per-map gametype filtering -const int GTV_FORBIDDEN = 2; +// gametype vote flags +const int GTV_FORBIDDEN = 0; // Cannot be voted +const int GTV_AVAILABLE = 1; // Can be voted #endif diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index 12564938f..8d5fe604b 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -30,7 +30,7 @@ string mapvote_suggestions[MAPVOTE_COUNT]; float mapvote_suggestion_ptr; float mapvote_voters; float mapvote_selections[MAPVOTE_COUNT]; -float mapvote_maps_availability[MAPVOTE_COUNT]; +float mapvote_maps_flags[MAPVOTE_COUNT]; float mapvote_run; float mapvote_detail; float mapvote_abstain; @@ -51,7 +51,7 @@ float GameTypeVote_Type_FromString(string type_name) return type; } -float GameTypeVote_AvailabilityStatus(string gtname) +int GameTypeVote_AvailabilityStatus(string gtname) { float type = GameTypeVote_Type_FromString(gtname); if( type == 0 ) @@ -189,7 +189,7 @@ void MapVote_AddVotable(string nextMap, float isSuggestion) mapvote_maps_screenshot_dir[mapvote_count] = i; mapvote_maps_pakfile[mapvote_count] = strzone(pakfile); - mapvote_maps_availability[mapvote_count] = GTV_AVAILABLE; + mapvote_maps_flags[mapvote_count] = GTV_AVAILABLE; mapvote_count += 1; } @@ -271,7 +271,7 @@ void MapVote_WriteMask() float mask,power; mask = 0; for(i = 0, power = 1; i < mapvote_count; ++i, power *= 2) - if(mapvote_maps_availability[i] == GTV_AVAILABLE ) + if(mapvote_maps_flags[i] & GTV_AVAILABLE ) mask |= power; if(mapvote_count < 8) @@ -284,7 +284,7 @@ void MapVote_WriteMask() else { for ( i = 0; i < mapvote_count; ++i ) - WriteByte(MSG_ENTITY, mapvote_maps_availability[i]); + WriteByte(MSG_ENTITY, mapvote_maps_flags[i]); } } @@ -326,6 +326,7 @@ float MapVote_SendEntity(entity to, int sf) MapVote_WriteMask(); + // Send data for the vote options for(i = 0; i < mapvote_count; ++i) { if(mapvote_abstain && i == mapvote_count - 1) @@ -340,7 +341,7 @@ float MapVote_SendEntity(entity to, int sf) WriteString(MSG_ENTITY, mapvote_maps[i]); WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]); WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]); - WriteByte(MSG_ENTITY, mapvote_maps_availability[i]); + WriteByte(MSG_ENTITY, mapvote_maps_flags[i]); } } } @@ -355,7 +356,7 @@ float MapVote_SendEntity(entity to, int sf) { if(mapvote_detail) for(i = 0; i < mapvote_count; ++i) - if ( mapvote_maps_availability[i] == GTV_AVAILABLE ) + if ( mapvote_maps_flags[i] == GTV_AVAILABLE ) WriteByte(MSG_ENTITY, mapvote_selections[i]); WriteByte(MSG_ENTITY, to.mapvote); @@ -394,7 +395,7 @@ float MapVote_Finished(float mappos) result = strcat(result, ":", ftos(mapvote_selections[mappos]), "::"); didntvote = mapvote_voters; for(i = 0; i < mapvote_count; ++i) - if(mapvote_maps_availability[i] == GTV_AVAILABLE ) + if(mapvote_maps_flags[i] & GTV_AVAILABLE ) { didntvote -= mapvote_selections[i]; if(i != mappos) @@ -443,7 +444,7 @@ void MapVote_CheckRules_1() float i; for(i = 0; i < mapvote_count; ++i) - if( mapvote_maps_availability[i] == GTV_AVAILABLE ) + if( mapvote_maps_flags[i] & GTV_AVAILABLE ) { //dprint("Map ", ftos(i), ": "); dprint(mapvote_maps[i], "\n"); mapvote_selections[i] = 0; @@ -481,7 +482,7 @@ float MapVote_CheckRules_2() currentPlace = 0; currentVotes = -1; for(i = 0; i < mapvote_count_real; ++i) - if ( mapvote_maps_availability[i] == GTV_AVAILABLE ) + if ( mapvote_maps_flags[i] & GTV_AVAILABLE ) { RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]); if ( gametypevote && mapvote_maps[i] == MapInfo_Type_ToString(MapInfo_CurrentGametype()) ) @@ -502,7 +503,7 @@ float MapVote_CheckRules_2() RandomSelection_Init(); for(i = 0; i < mapvote_count_real; ++i) if(i != firstPlace) - if ( mapvote_maps_availability[i] == GTV_AVAILABLE ) + if ( mapvote_maps_flags[i] & GTV_AVAILABLE ) RandomSelection_Add(world, i, string_null, 1, mapvote_selections[i]); secondPlace = RandomSelection_chosen_float; secondPlaceVotes = RandomSelection_best_priority; @@ -537,7 +538,7 @@ float MapVote_CheckRules_2() result = strcat(result, ":", ftos(mapvote_selections[i])); if(i < mapvote_count_real) { - mapvote_maps_availability[i] = GTV_FORBIDDEN; + mapvote_maps_flags[i] &= ~GTV_AVAILABLE; } } } @@ -576,11 +577,11 @@ void MapVote_Tick() } // clear possibly invalid votes - if ( mapvote_maps_availability[other.mapvote-1] != GTV_AVAILABLE ) + if ( !(mapvote_maps_flags[other.mapvote-1] & GTV_AVAILABLE) ) other.mapvote = 0; // use impulses as new vote if(other.impulse >= 1 && other.impulse <= mapvote_count) - if( mapvote_maps_availability[other.impulse - 1] == GTV_AVAILABLE ) + if( mapvote_maps_flags[other.impulse - 1] & GTV_AVAILABLE ) { other.mapvote = other.impulse; MapVote_TouchVotes(other); @@ -727,7 +728,7 @@ float GameTypeVote_AddVotable(string nextMode) mapvote_maps_screenshot_dir[mapvote_count] = 0; mapvote_maps_pakfile[mapvote_count] = strzone(""); - mapvote_maps_availability[mapvote_count] = GameTypeVote_AvailabilityStatus(nextMode); + mapvote_maps_flags[mapvote_count] = GameTypeVote_AvailabilityStatus(nextMode); mapvote_count += 1; @@ -755,7 +756,7 @@ float GameTypeVote_Start() for(j = 0; j < n; ++j) { if ( GameTypeVote_AddVotable(argv(j)) ) - if ( mapvote_maps_availability[j] == GTV_AVAILABLE ) + if ( mapvote_maps_flags[j] & GTV_AVAILABLE ) { really_available++; which_available = j;