mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
growth handicap
This commit is contained in:
parent
6273e678a4
commit
ec005593d3
@ -801,14 +801,19 @@ OptionsTab::HandicapWindow::HandicapWindow()
|
||||
|
||||
addUsedEvents(LCLICK);
|
||||
|
||||
pos = Rect(0, 0, 590, 100 + SEL->getStartInfo()->playerInfos.size() * 30);
|
||||
pos = Rect(0, 0, 650, 100 + SEL->getStartInfo()->playerInfos.size() * 30);
|
||||
|
||||
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), pos);
|
||||
backgroundTexture->setPlayerColor(PlayerColor(1));
|
||||
|
||||
labels.push_back(std::make_shared<CLabel>(pos.w / 2 + 8, 15, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.handicap")));
|
||||
|
||||
auto columns = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS, EGameResID::NONE};
|
||||
enum Columns : int32_t
|
||||
{
|
||||
INCOME = 1000,
|
||||
GROWTH = 2000,
|
||||
};
|
||||
auto columns = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS, Columns::INCOME, Columns::GROWTH};
|
||||
|
||||
int i = 0;
|
||||
for(auto & pInfo : SEL->getStartInfo()->playerInfos)
|
||||
@ -817,8 +822,9 @@ OptionsTab::HandicapWindow::HandicapWindow()
|
||||
anim.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ITGFLAGS"), player.getNum(), 0, 7, 57 + i * 30));
|
||||
for(int j = 0; j < columns.size(); j++)
|
||||
{
|
||||
bool isIncome = int(columns[j]) == Columns::INCOME;
|
||||
bool isGrowth = int(columns[j]) == Columns::GROWTH;
|
||||
EGameResID resource = columns[j];
|
||||
bool isIncome = resource == EGameResID::NONE;
|
||||
|
||||
const PlayerSettings &ps = SEL->getStartInfo()->getIthPlayersSettings(player);
|
||||
|
||||
@ -826,6 +832,8 @@ OptionsTab::HandicapWindow::HandicapWindow()
|
||||
{
|
||||
if(isIncome)
|
||||
labels.push_back(std::make_shared<CLabel>(30 + j * 70, 35, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("core.jktext.32")));
|
||||
else if(isGrowth)
|
||||
labels.push_back(std::make_shared<CLabel>(30 + j * 70, 35, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("core.genrltxt.194")));
|
||||
else
|
||||
anim.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SMALRES"), GameResID(resource), 0, 45 + j * 70, 35));
|
||||
}
|
||||
@ -833,15 +841,15 @@ OptionsTab::HandicapWindow::HandicapWindow()
|
||||
auto area = Rect(30 + j * 70, 60 + i * 30, 50, 16);
|
||||
textinputbackgrounds.push_back(std::make_shared<TransparentFilledRectangle>(area.resize(3), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64)));
|
||||
textinputs[player][resource] = std::make_shared<CTextInput>(area, FONT_SMALL, ETextAlignment::CENTERLEFT, true);
|
||||
textinputs[player][resource]->setText(std::to_string(isIncome ? ps.handicap.percentIncome : ps.handicap.startBonus[resource]));
|
||||
textinputs[player][resource]->setCallback([this, player, resource, isIncome](const std::string & s){
|
||||
textinputs[player][resource]->setText(std::to_string(isIncome ? ps.handicap.percentIncome : (isGrowth ? ps.handicap.percentGrowth : ps.handicap.startBonus[resource])));
|
||||
textinputs[player][resource]->setCallback([this, player, resource, isIncome, isGrowth](const std::string & s){
|
||||
std::string tmp = s;
|
||||
bool negative = std::count_if( s.begin(), s.end(), []( char c ){ return c == '-'; }) == 1 && !isIncome;
|
||||
bool negative = std::count_if( s.begin(), s.end(), []( char c ){ return c == '-'; }) == 1 && !isIncome && !isGrowth;
|
||||
tmp.erase(std::remove_if(tmp.begin(), tmp.end(), [](char c) { return !isdigit(c); }), tmp.end());
|
||||
tmp = tmp.substr(0, isIncome ? 3 : 5);
|
||||
tmp = tmp.substr(0, isIncome || isGrowth ? 3 : 5);
|
||||
textinputs[player][resource]->setText(tmp.length() == 0 ? "0" : (negative ? "-" : "") + std::to_string(stoi(tmp)));
|
||||
});
|
||||
if(isIncome)
|
||||
if(isIncome || isGrowth)
|
||||
labels.push_back(std::make_shared<CLabel>(area.topRight().x, area.center().y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, "%"));
|
||||
}
|
||||
i++;
|
||||
@ -852,15 +860,19 @@ OptionsTab::HandicapWindow::HandicapWindow()
|
||||
{
|
||||
TResources resources = TResources();
|
||||
int income = 100;
|
||||
int growth = 100;
|
||||
for (const auto& resource : player.second)
|
||||
{
|
||||
bool isIncome = resource.first == EGameResID::NONE;
|
||||
bool isIncome = int(resource.first) == Columns::INCOME;
|
||||
bool isGrowth = int(resource.first) == Columns::GROWTH;
|
||||
if(isIncome)
|
||||
income = std::stoi(resource.second->getText());
|
||||
else if(isGrowth)
|
||||
growth = std::stoi(resource.second->getText());
|
||||
else
|
||||
resources[resource.first] = std::stoi(resource.second->getText());
|
||||
}
|
||||
CSH->setPlayerHandicap(player.first, PlayerSettings::Handicap{resources, income});
|
||||
CSH->setPlayerHandicap(player.first, PlayerSettings::Handicap{resources, income, growth});
|
||||
}
|
||||
|
||||
close();
|
||||
@ -1011,14 +1023,14 @@ 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]);
|
||||
|
||||
labelHandicap = std::make_shared<CMultiLineLabel>(Rect(57, 24, 47, (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());
|
||||
labelHandicap = std::make_shared<CMultiLineLabel>(Rect(57, 24, 47, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, s->handicap.startBonus.empty() && s->handicap.percentIncome == 100 && s->handicap.percentGrowth == 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), [](){
|
||||
if(!CSH->isHost())
|
||||
return;
|
||||
|
||||
GH.windows().createAndPushWindow<HandicapWindow>();
|
||||
}, [this](){
|
||||
if(s->handicap.startBonus.empty() && s->handicap.percentIncome == 100)
|
||||
if(s->handicap.startBonus.empty() && s->handicap.percentIncome == 100 && s->handicap.percentGrowth == 100)
|
||||
CRClickPopup::createAndPush(MetaString::createFromTextID("core.help.124.help").toString());
|
||||
else
|
||||
{
|
||||
@ -1039,6 +1051,13 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
|
||||
str.appendRawString(": ");
|
||||
str.appendRawString(std::to_string(s->handicap.percentIncome) + "%");
|
||||
}
|
||||
if(s->handicap.percentGrowth != 100)
|
||||
{
|
||||
str.appendRawString("\n");
|
||||
str.appendTextID("core.genrltxt.194");
|
||||
str.appendRawString(": ");
|
||||
str.appendRawString(std::to_string(s->handicap.percentGrowth) + "%");
|
||||
}
|
||||
CRClickPopup::createAndPush(str.toString());
|
||||
}
|
||||
});
|
||||
|
@ -25,7 +25,7 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
PlayerSettings::PlayerSettings()
|
||||
: bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), 100}), compOnly(false)
|
||||
: bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), 100, 100}), compOnly(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,7 @@ struct DLL_LINKAGE PlayerSettings
|
||||
struct Handicap {
|
||||
TResources startBonus;
|
||||
int percentIncome;
|
||||
int percentGrowth;
|
||||
} handicap;
|
||||
|
||||
std::string name;
|
||||
@ -101,6 +102,7 @@ struct DLL_LINKAGE PlayerSettings
|
||||
{
|
||||
h & handicap.startBonus;
|
||||
h & handicap.percentIncome;
|
||||
h & handicap.percentGrowth;
|
||||
}
|
||||
else
|
||||
h & handicapLegacy;
|
||||
|
@ -137,6 +137,14 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
|
||||
const int base = creature->getGrowth();
|
||||
int castleBonus = 0;
|
||||
|
||||
if(tempOwner.isValidPlayer())
|
||||
{
|
||||
auto * playerSettings = cb->getPlayerSettings(tempOwner);
|
||||
ret.percent = playerSettings->handicap.percentGrowth;
|
||||
}
|
||||
else
|
||||
ret.percent = 100;
|
||||
|
||||
ret.entries.emplace_back(VLC->generaltexth->allTexts[590], base); // \n\nBasic growth %d"
|
||||
|
||||
if (hasBuilt(BuildingID::CASTLE))
|
||||
@ -1261,7 +1269,7 @@ int GrowthInfo::totalGrowth() const
|
||||
for(const Entry &entry : entries)
|
||||
ret += entry.count;
|
||||
|
||||
return ret;
|
||||
return ret * percent / 100;
|
||||
}
|
||||
|
||||
void CGTownInstance::fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const
|
||||
|
@ -41,6 +41,7 @@ struct DLL_LINKAGE GrowthInfo
|
||||
|
||||
std::vector<Entry> entries;
|
||||
int totalGrowth() const;
|
||||
int percent;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CGTownInstance : public CGDwelling, public IShipyard, public IMarket, public INativeTerrainProvider, public ICreatureUpgrader
|
||||
|
@ -293,6 +293,7 @@ struct DLL_LINKAGE LobbySetPlayerHandicap : public CLobbyPackToServer
|
||||
h & color;
|
||||
h & handicap.startBonus;
|
||||
h & handicap.percentIncome;
|
||||
h & handicap.percentGrowth;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -786,7 +786,7 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap
|
||||
str.appendName(color);
|
||||
str.appendRawString(":");
|
||||
|
||||
if(handicap.startBonus.empty() && handicap.percentIncome == 100)
|
||||
if(handicap.startBonus.empty() && handicap.percentIncome == 100 && handicap.percentGrowth == 100)
|
||||
{
|
||||
str.appendRawString(" ");
|
||||
str.appendTextID("core.genrltxt.523");
|
||||
@ -809,6 +809,13 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap
|
||||
str.appendRawString(":");
|
||||
str.appendRawString(std::to_string(handicap.percentIncome) + "%");
|
||||
}
|
||||
if(handicap.percentGrowth != 100)
|
||||
{
|
||||
str.appendRawString(" ");
|
||||
str.appendTextID("core.genrltxt.194");
|
||||
str.appendRawString(":");
|
||||
str.appendRawString(std::to_string(handicap.percentGrowth) + "%");
|
||||
}
|
||||
announceTxt(str);
|
||||
}
|
||||
|
||||
@ -1059,7 +1066,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 != 100)
|
||||
if(!pi.second.handicap.startBonus.empty() || pi.second.handicap.percentIncome != 100 || pi.second.handicap.percentGrowth != 100)
|
||||
{
|
||||
MetaString str;
|
||||
str.appendTextID("vcmi.lobby.handicap");
|
||||
@ -1081,6 +1088,13 @@ void CVCMIServer::multiplayerWelcomeMessage()
|
||||
str.appendRawString(":");
|
||||
str.appendRawString(std::to_string(pi.second.handicap.percentIncome) + "%");
|
||||
}
|
||||
if(pi.second.handicap.percentGrowth != 100)
|
||||
{
|
||||
str.appendRawString(" ");
|
||||
str.appendTextID("core.genrltxt.194");
|
||||
str.appendRawString(":");
|
||||
str.appendRawString(std::to_string(pi.second.handicap.percentGrowth) + "%");
|
||||
}
|
||||
gh->playerMessages->broadcastSystemMessage(str);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user