From 268e0c8c44a3ca8e1504e840b2ab2836b4b40adb Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Wed, 24 Jul 2024 01:34:29 +0200 Subject: [PATCH] change data structure --- client/lobby/OptionsTab.cpp | 17 ++++++++++++----- lib/StartInfo.cpp | 2 +- lib/StartInfo.h | 2 +- server/CGameHandler.cpp | 2 +- server/CVCMIServer.cpp | 26 ++++++++++++++++++++------ 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index 029f8a737..d773abe8d 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -923,31 +923,38 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con } labelWhoCanPlay = std::make_shared(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]); - labelHandicap = std::make_shared(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, s->handicap.startBonus.empty() && s->handicap.percentIncome.empty() ? CGI->generaltexth->arraytxt[210] : MetaString::createFromTextID("vcmi.lobby.handicap").toString()); + labelHandicap = std::make_shared(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, s->handicap.startBonus.empty() && s->handicap.percentIncome == 100 ? CGI->generaltexth->arraytxt[210] : MetaString::createFromTextID("vcmi.lobby.handicap").toString()); handicap = std::make_shared(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), [this](){ if(!CSH->isHost()) return; TResources resourcesStart = TResources(); resourcesStart[EGameResID::GOLD] = 50000; - TResources resourcesPercent = TResources(); //reset 100 % to 0!!! + int resourcesPercent = 120; CSH->setPlayerHandicap(s->color, PlayerSettings::Handicap{resourcesStart, resourcesPercent}); }, [this](){ - if(s->handicap.startBonus.empty() && s->handicap.percentIncome.empty()) + if(s->handicap.startBonus.empty() && s->handicap.percentIncome == 100) CRClickPopup::createAndPush(MetaString::createFromTextID("core.help.124.help").toString()); else { auto str = MetaString::createFromTextID("vcmi.lobby.handicap"); str.appendRawString(":\n"); for(auto & res : EGameResID::ALL_RESOURCES()) - if(s->handicap.startBonus[res] != 0 || s->handicap.percentIncome[res] != 0) + if(s->handicap.startBonus[res] != 0) { str.appendRawString("\n"); str.appendName(res); str.appendRawString(": "); - str.appendRawString(std::to_string(s->handicap.startBonus[res]) + "|" + std::to_string(s->handicap.percentIncome[res] == 0 ? 100 : s->handicap.percentIncome[res]) + "%"); + str.appendRawString(std::to_string(s->handicap.startBonus[res])); } + if(s->handicap.percentIncome != 100) + { + str.appendRawString("\n"); + str.appendTextID("core.jktext.32"); + str.appendRawString(": "); + str.appendRawString(std::to_string(s->handicap.percentIncome) + "%"); + } CRClickPopup::createAndPush(str.toString()); } }); diff --git a/lib/StartInfo.cpp b/lib/StartInfo.cpp index 1b3bb7491..87155c4e1 100644 --- a/lib/StartInfo.cpp +++ b/lib/StartInfo.cpp @@ -25,7 +25,7 @@ VCMI_LIB_NAMESPACE_BEGIN PlayerSettings::PlayerSettings() - : bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), TResources()}), compOnly(false) + : bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), 100}), compOnly(false) { } diff --git a/lib/StartInfo.h b/lib/StartInfo.h index 3da49ab13..c6257a3a3 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -82,7 +82,7 @@ struct DLL_LINKAGE PlayerSettings EHandicap handicapLegacy;//0-no, 1-mild, 2-severe struct Handicap { TResources startBonus; - TResources percentIncome; + int percentIncome; } handicap; std::string name; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 33fdba01d..e048da358 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1431,7 +1431,7 @@ void CGameHandler::giveResource(PlayerColor player, GameResID which, int val) // auto * playerSettings = gs->scenarioOps->getPlayersSettings(player); TResources resources; - resources[which] = val * (playerSettings->handicap.percentIncome[which] == 0 ? 100 : playerSettings->handicap.percentIncome[which]) / 100; + resources[which] = val * playerSettings->handicap.percentIncome / 100; giveResources(player, resources); } diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 9df8b156e..285b57c46 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -784,7 +784,7 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap str.appendName(color); str.appendRawString(":"); - if(handicap.startBonus.empty() && handicap.percentIncome.empty()) + if(handicap.startBonus.empty() && handicap.percentIncome == 100) { str.appendRawString(" "); str.appendTextID("core.genrltxt.523"); @@ -793,13 +793,20 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap } for(auto & res : EGameResID::ALL_RESOURCES()) - if(handicap.startBonus[res] != 0 && handicap.percentIncome[res] != 0) + if(handicap.startBonus[res] != 0) { str.appendRawString(" "); str.appendName(res); str.appendRawString(":"); - str.appendRawString(std::to_string(handicap.startBonus[res]) + "|" + std::to_string(handicap.percentIncome[res] == 0 ? 100 : handicap.percentIncome[res]) + "%"); + str.appendRawString(std::to_string(handicap.startBonus[res])); } + if(handicap.percentIncome != 100) + { + str.appendRawString(" "); + str.appendTextID("core.jktext.32"); + str.appendRawString(":"); + str.appendRawString(std::to_string(handicap.percentIncome) + "%"); + } announceTxt(str); } @@ -1050,7 +1057,7 @@ void CVCMIServer::multiplayerWelcomeMessage() gh->playerMessages->broadcastSystemMessage("Use '!help' to list available commands"); for (const auto & pi : si->playerInfos) - if(!pi.second.handicap.startBonus.empty() || !pi.second.handicap.percentIncome.empty()) + if(!pi.second.handicap.startBonus.empty() || pi.second.handicap.percentIncome != 100) { MetaString str; str.appendTextID("vcmi.lobby.handicap"); @@ -1058,13 +1065,20 @@ void CVCMIServer::multiplayerWelcomeMessage() str.appendName(pi.first); str.appendRawString(":"); for(auto & res : EGameResID::ALL_RESOURCES()) - if(pi.second.handicap.startBonus[res] != 0 || pi.second.handicap.percentIncome[res] != 0) + if(pi.second.handicap.startBonus[res] != 0) { str.appendRawString(" "); str.appendName(res); str.appendRawString(":"); - str.appendRawString(std::to_string(pi.second.handicap.startBonus[res]) + "|" + std::to_string(pi.second.handicap.percentIncome[res] == 0 ? 100 : pi.second.handicap.percentIncome[res]) + "%"); + str.appendRawString(std::to_string(pi.second.handicap.startBonus[res])); } + if(pi.second.handicap.percentIncome != 100) + { + str.appendRawString(" "); + str.appendTextID("core.jktext.32"); + str.appendRawString(":"); + str.appendRawString(std::to_string(pi.second.handicap.percentIncome) + "%"); + } gh->playerMessages->broadcastSystemMessage(str); }