mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
handycap percent
This commit is contained in:
parent
48eacbf830
commit
832e1531fc
@ -497,7 +497,7 @@ void CServerHandler::setPlayerName(PlayerColor color, const std::string & name)
|
||||
sendLobbyPack(lspn);
|
||||
}
|
||||
|
||||
void CServerHandler::setPlayerHandicap(PlayerColor color, TResources handicap) const
|
||||
void CServerHandler::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap handicap) const
|
||||
{
|
||||
LobbySetPlayerHandicap lsph;
|
||||
lsph.color = color;
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
virtual void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const = 0;
|
||||
virtual void setPlayer(PlayerColor color) const = 0;
|
||||
virtual void setPlayerName(PlayerColor color, const std::string & name) const = 0;
|
||||
virtual void setPlayerHandicap(PlayerColor color, TResources handicap) const = 0;
|
||||
virtual void setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap handicap) const = 0;
|
||||
virtual void setPlayerOption(ui8 what, int32_t value, PlayerColor player) const = 0;
|
||||
virtual void setDifficulty(int to) const = 0;
|
||||
virtual void setTurnTimerInfo(const TurnTimerInfo &) const = 0;
|
||||
@ -193,7 +193,7 @@ public:
|
||||
void setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts = {}) const override;
|
||||
void setPlayer(PlayerColor color) const override;
|
||||
void setPlayerName(PlayerColor color, const std::string & name) const override;
|
||||
void setPlayerHandicap(PlayerColor color, TResources handicap) const override;
|
||||
void setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap handicap) const override;
|
||||
void setPlayerOption(ui8 what, int32_t value, PlayerColor player) const override;
|
||||
void setDifficulty(int to) const override;
|
||||
void setTurnTimerInfo(const TurnTimerInfo &) const override;
|
||||
|
@ -25,7 +25,7 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
PlayerSettings::PlayerSettings()
|
||||
: bonus(PlayerStartingBonus::RANDOM), color(0), handicap(TResources()), compOnly(false)
|
||||
: bonus(PlayerStartingBonus::RANDOM), color(0), handicap({TResources(), TResources()}), compOnly(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,10 @@ struct DLL_LINKAGE PlayerSettings
|
||||
PlayerColor color; //from 0 -
|
||||
enum EHandicap {NO_HANDICAP, MILD, SEVERE};
|
||||
EHandicap handicapLegacy;//0-no, 1-mild, 2-severe
|
||||
TResources handicap;
|
||||
struct Handicap {
|
||||
TResources startBonus;
|
||||
TResources percentIncome;
|
||||
} handicap;
|
||||
|
||||
std::string name;
|
||||
std::set<ui8> connectedPlayerIDs; //Empty - AI, or connectrd player ids
|
||||
@ -95,7 +98,10 @@ struct DLL_LINKAGE PlayerSettings
|
||||
h & bonus;
|
||||
h & color;
|
||||
if (h.version >= Handler::Version::PLAYER_HANDICAP)
|
||||
h & handicap;
|
||||
{
|
||||
h & handicap.startBonus;
|
||||
h & handicap.percentIncome;
|
||||
}
|
||||
else
|
||||
h & handicapLegacy;
|
||||
h & name;
|
||||
|
@ -394,7 +394,7 @@ void CGameState::initDifficulty()
|
||||
|
||||
//handicap
|
||||
const PlayerSettings &ps = scenarioOps->getIthPlayersSettings(state.color);
|
||||
state.resources += ps.handicap;
|
||||
state.resources += ps.handicap.startBonus;
|
||||
|
||||
//set global bonuses
|
||||
for(auto & jsonBonus : json["globalBonuses"].Vector())
|
||||
|
@ -284,14 +284,15 @@ struct DLL_LINKAGE LobbySetPlayerName : public CLobbyPackToServer
|
||||
struct DLL_LINKAGE LobbySetPlayerHandicap : public CLobbyPackToServer
|
||||
{
|
||||
PlayerColor color = PlayerColor::CANNOT_DETERMINE;
|
||||
TResources handicap = TResources();
|
||||
PlayerSettings::Handicap handicap = PlayerSettings::Handicap();
|
||||
|
||||
void visitTyped(ICPackVisitor & visitor) override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
h & color;
|
||||
h & handicap;
|
||||
h & handicap.startBonus;
|
||||
h & handicap.percentIncome;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1428,8 +1428,10 @@ void CGameHandler::giveResource(PlayerColor player, GameResID which, int val) //
|
||||
{
|
||||
if (!val) return; //don't waste time on empty call
|
||||
|
||||
auto * playerSettings = gs->scenarioOps->getPlayersSettings(player);
|
||||
|
||||
TResources resources;
|
||||
resources[which] = val;
|
||||
resources[which] = val * (playerSettings->handicap.percentIncome[which] == 0 ? 1 : playerSettings->handicap.percentIncome[which] / 100);
|
||||
giveResources(player, resources);
|
||||
}
|
||||
|
||||
|
@ -624,8 +624,6 @@ void CVCMIServer::updateStartInfoOnMapChange(std::shared_ptr<CMapInfo> mapInfo,
|
||||
pset.heroNameTextId = pinfo.mainCustomHeroNameTextId;
|
||||
pset.heroPortrait = pinfo.mainCustomHeroPortrait;
|
||||
}
|
||||
|
||||
pset.handicap = PlayerSettings::NO_HANDICAP;
|
||||
}
|
||||
|
||||
if(mi->isRandomMap && mapGenOpts)
|
||||
@ -765,7 +763,7 @@ void CVCMIServer::setPlayerName(PlayerColor color, std::string name)
|
||||
setPlayerConnectedId(player, nameID);
|
||||
}
|
||||
|
||||
void CVCMIServer::setPlayerHandicap(PlayerColor color, TResources handicap)
|
||||
void CVCMIServer::setPlayerHandicap(PlayerColor color, PlayerSettings::Handicap handicap)
|
||||
{
|
||||
if(color == PlayerColor::CANNOT_DETERMINE)
|
||||
return;
|
||||
@ -786,7 +784,7 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, TResources handicap)
|
||||
str.appendName(color);
|
||||
str.appendRawString(":");
|
||||
|
||||
if(handicap.empty())
|
||||
if(handicap.startBonus.empty() && handicap.percentIncome.empty())
|
||||
{
|
||||
str.appendRawString(" ");
|
||||
str.appendTextID("core.genrltxt.523");
|
||||
@ -795,12 +793,12 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, TResources handicap)
|
||||
}
|
||||
|
||||
for(auto & res : EGameResID::ALL_RESOURCES())
|
||||
if(handicap[res] != 0)
|
||||
if(handicap.startBonus[res] != 0 && handicap.percentIncome[res] != 0)
|
||||
{
|
||||
str.appendRawString(" ");
|
||||
str.appendName(res);
|
||||
str.appendRawString(":");
|
||||
str.appendRawString(std::to_string(handicap[res]));
|
||||
str.appendRawString(std::to_string(handicap.startBonus[res]) + "|" + std::to_string(handicap.percentIncome[res] == 0 ? 100 : handicap.percentIncome[res]) + "%");
|
||||
}
|
||||
announceTxt(str);
|
||||
}
|
||||
@ -1052,7 +1050,7 @@ void CVCMIServer::multiplayerWelcomeMessage()
|
||||
gh->playerMessages->broadcastSystemMessage("Use '!help' to list available commands");
|
||||
|
||||
for (const auto & pi : si->playerInfos)
|
||||
if(!pi.second.handicap.empty())
|
||||
if(!pi.second.handicap.startBonus.empty() || !pi.second.handicap.percentIncome.empty())
|
||||
{
|
||||
MetaString str;
|
||||
str.appendTextID("vcmi.lobby.handicap");
|
||||
@ -1060,12 +1058,12 @@ void CVCMIServer::multiplayerWelcomeMessage()
|
||||
str.appendName(pi.first);
|
||||
str.appendRawString(":");
|
||||
for(auto & res : EGameResID::ALL_RESOURCES())
|
||||
if(pi.second.handicap[res] != 0)
|
||||
if(pi.second.handicap.startBonus[res] != 0 || pi.second.handicap.percentIncome[res] != 0)
|
||||
{
|
||||
str.appendRawString(" ");
|
||||
str.appendName(res);
|
||||
str.appendRawString(":");
|
||||
str.appendRawString(std::to_string(pi.second.handicap[res]));
|
||||
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]) + "%");
|
||||
}
|
||||
gh->playerMessages->broadcastSystemMessage(str);
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
// Work with LobbyInfo
|
||||
void setPlayer(PlayerColor clickedColor);
|
||||
void setPlayerName(PlayerColor player, std::string name);
|
||||
void setPlayerHandicap(PlayerColor player, TResources handicap);
|
||||
void setPlayerHandicap(PlayerColor player, PlayerSettings::Handicap handicap);
|
||||
void optionNextHero(PlayerColor player, int dir); //dir == -1 or +1
|
||||
void optionSetHero(PlayerColor player, HeroTypeID id);
|
||||
HeroTypeID nextAllowedHero(PlayerColor player, HeroTypeID id, int direction);
|
||||
|
Loading…
x
Reference in New Issue
Block a user