/
linkfly
/
MasterKnight
Обзор
Документация
Войти
/
linkfly
/
MasterKnight
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
Source/Multiplayer/Private/MapsVotes.cpp
83 строки
2 KB
Сергей Катревич
Fixed AI moving
24 апр 2026, 19:54
24 апр 2026, 19:54
ffdd6c2
Код
Авторство
О чём код?
// Fill out your copyright notice in the Description page of Project Settings. #include "MapsVotes.h" #include "Misc/AssetUtils.h" #include "Widgets/Data/ListMapItemData.h" #include "Widgets/Data/MapsForMultiplayerData.h" DEFINE_LOG_CATEGORY_STATIC(LogMapsVotes, Log, All); void UMapsVotes::InitActiveVotes() { if (!MapsForMultiplayer) { UE_LOGFMT(LogMapsVotes, Error, "[{0}] MapsForMultiplayer is invalid", __FUNCTION__); return; } for (auto MapDataItem : MapsForMultiplayer->ListMaps) { if (!IsValid(MapDataItem)) { UE_LOGFMT(LogMapsVotes, Error, "[{0}] MapDataItem is invalid", __FUNCTION__); return; } FString MapPath = GetMapPath(MapDataItem->Map); if (MapPath.IsEmpty()) { UE_LOGFMT(LogMapsVotes, Error, "[{0}] Failed MapPath", __FUNCTION__); return; } ActiveVotes.Add(MapPath, 0); } } bool UMapsVotes::AddVote(const FString& MapPath) { if (!ActiveVotes.Contains(MapPath)) return false; ++ActiveVotes[MapPath]; return true; } bool UMapsVotes::RemoveVote(const FString& MapPath) { if (!ActiveVotes.Contains(MapPath)) return false; --ActiveVotes[MapPath]; return true; } FString UMapsVotes::GetMapPath(TSoftObjectPtr<UWorld> MapWorld) { if (MapWorld.IsNull()) return {}; FText CurMapNameText = FText::FromString(UAssetUtils::GetSoftMapPath(MapWorld)); return CurMapNameText.ToString(); } bool UMapsVotes::CheckAllVotes(int32 MaxVotablePlayers, FString& MaxVotesMap) { if (ActiveVotes.IsEmpty()) return false; FString CurMaxVotesMap; int32 CurMaxVotes = 0; int32 AllVotes = 0; for (auto MapDataItem : ActiveVotes) { int32 CurVotes = MapDataItem.Value; AllVotes += CurVotes; if (MapDataItem.Value > CurMaxVotes) { CurMaxVotesMap = MapDataItem.Key; CurMaxVotes = CurVotes; } } if (AllVotes == 0 || (AllVotes < MaxVotablePlayers)) return false; if (CurMaxVotesMap.IsEmpty()) return false; MaxVotesMap = CurMaxVotesMap; return true; }