1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

change data structure

This commit is contained in:
Laserlicht 2024-07-24 01:34:29 +02:00
parent fa7153b577
commit 268e0c8c44
5 changed files with 35 additions and 14 deletions

View File

@ -923,31 +923,38 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
} }
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]); labelWhoCanPlay = std::make_shared<CMultiLineLabel>(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<CMultiLineLabel>(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<CMultiLineLabel>(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<LRClickableArea>(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), [this](){ handicap = std::make_shared<LRClickableArea>(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), [this](){
if(!CSH->isHost()) if(!CSH->isHost())
return; return;
TResources resourcesStart = TResources(); TResources resourcesStart = TResources();
resourcesStart[EGameResID::GOLD] = 50000; resourcesStart[EGameResID::GOLD] = 50000;
TResources resourcesPercent = TResources(); //reset 100 % to 0!!! int resourcesPercent = 120;
CSH->setPlayerHandicap(s->color, PlayerSettings::Handicap{resourcesStart, resourcesPercent}); CSH->setPlayerHandicap(s->color, PlayerSettings::Handicap{resourcesStart, resourcesPercent});
}, [this](){ }, [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()); CRClickPopup::createAndPush(MetaString::createFromTextID("core.help.124.help").toString());
else else
{ {
auto str = MetaString::createFromTextID("vcmi.lobby.handicap"); auto str = MetaString::createFromTextID("vcmi.lobby.handicap");
str.appendRawString(":\n"); str.appendRawString(":\n");
for(auto & res : EGameResID::ALL_RESOURCES()) 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.appendRawString("\n");
str.appendName(res); str.appendName(res);
str.appendRawString(": "); 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()); CRClickPopup::createAndPush(str.toString());
} }
}); });

View File

@ -25,7 +25,7 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
PlayerSettings::PlayerSettings() PlayerSettings::PlayerSettings()
: bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), TResources()}), compOnly(false) : bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), 100}), compOnly(false)
{ {
} }

View File

@ -82,7 +82,7 @@ struct DLL_LINKAGE PlayerSettings
EHandicap handicapLegacy;//0-no, 1-mild, 2-severe EHandicap handicapLegacy;//0-no, 1-mild, 2-severe
struct Handicap { struct Handicap {
TResources startBonus; TResources startBonus;
TResources percentIncome; int percentIncome;
} handicap; } handicap;
std::string name; std::string name;

View File

@ -1431,7 +1431,7 @@ void CGameHandler::giveResource(PlayerColor player, GameResID which, int val) //
auto * playerSettings = gs->scenarioOps->getPlayersSettings(player); auto * playerSettings = gs->scenarioOps->getPlayersSettings(player);
TResources resources; 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); giveResources(player, resources);
} }

View File

@ -784,7 +784,7 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap
str.appendName(color); str.appendName(color);
str.appendRawString(":"); str.appendRawString(":");
if(handicap.startBonus.empty() && handicap.percentIncome.empty()) if(handicap.startBonus.empty() && handicap.percentIncome == 100)
{ {
str.appendRawString(" "); str.appendRawString(" ");
str.appendTextID("core.genrltxt.523"); str.appendTextID("core.genrltxt.523");
@ -793,13 +793,20 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap
} }
for(auto & res : EGameResID::ALL_RESOURCES()) for(auto & res : EGameResID::ALL_RESOURCES())
if(handicap.startBonus[res] != 0 && handicap.percentIncome[res] != 0) if(handicap.startBonus[res] != 0)
{ {
str.appendRawString(" "); str.appendRawString(" ");
str.appendName(res); str.appendName(res);
str.appendRawString(":"); 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); announceTxt(str);
} }
@ -1050,7 +1057,7 @@ void CVCMIServer::multiplayerWelcomeMessage()
gh->playerMessages->broadcastSystemMessage("Use '!help' to list available commands"); gh->playerMessages->broadcastSystemMessage("Use '!help' to list available commands");
for (const auto & pi : si->playerInfos) 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; MetaString str;
str.appendTextID("vcmi.lobby.handicap"); str.appendTextID("vcmi.lobby.handicap");
@ -1058,13 +1065,20 @@ void CVCMIServer::multiplayerWelcomeMessage()
str.appendName(pi.first); str.appendName(pi.first);
str.appendRawString(":"); str.appendRawString(":");
for(auto & res : EGameResID::ALL_RESOURCES()) 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.appendRawString(" ");
str.appendName(res); str.appendName(res);
str.appendRawString(":"); 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); gh->playerMessages->broadcastSystemMessage(str);
} }