Laserlicht 1 рік тому
батько
коміт
bfd1e8a7c8

+ 1 - 1
AI/Nullkiller/Analyzers/BuildAnalyzer.cpp

@@ -317,7 +317,7 @@ void BuildAnalyzer::updateDailyIncome()
 
 		if(mine)
 		{
-			dailyIncome[mine->producedResource.getNum()] += mine->producedQuantity;
+			dailyIncome[mine->producedResource.getNum()] += mine->getProducedQuantity();
 		}
 	}
 

+ 1 - 1
client/lobby/OptionsTab.cpp

@@ -804,7 +804,7 @@ OptionsTab::HandicapWindow::HandicapWindow()
 	pos = Rect(0, 0, 590, 100 + SEL->getStartInfo()->playerInfos.size() * 30);
 
 	backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), pos);
-	backgroundTexture->playerColored(PlayerColor(1));
+	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")));
 

+ 6 - 4
client/windows/CKingdomInterface.cpp

@@ -37,6 +37,7 @@
 #include "../../lib/CHeroHandler.h"
 #include "../../lib/GameSettings.h"
 #include "../../lib/CSkillHandler.h"
+#include "../../lib/StartInfo.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CGTownInstance.h"
 #include "../../lib/mapObjects/MiscObjects.h"
@@ -586,15 +587,16 @@ void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstan
 			minesCount[mine->producedResource]++;
 
 			if (mine->producedResource == EGameResID::GOLD)
-				totalIncome += mine->producedQuantity;
+				totalIncome += mine->getProducedQuantity();
 		}
 	}
 
 	//Heroes can produce gold as well - skill, specialty or arts
 	std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
+	auto * playerSettings = LOCPLINT->cb->getPlayerSettings(LOCPLINT->playerID);
 	for(auto & hero : heroes)
 	{
-		totalIncome += hero->valOfBonuses(Selector::typeSubtype(BonusType::GENERATE_RESOURCE, BonusSubtypeID(GameResID(EGameResID::GOLD))));
+		totalIncome += hero->valOfBonuses(Selector::typeSubtype(BonusType::GENERATE_RESOURCE, BonusSubtypeID(GameResID(EGameResID::GOLD)))) * playerSettings->handicap.percentIncome / 100;
 	}
 
 	//Add town income of all towns
@@ -605,8 +607,8 @@ void CKingdomInterface::generateMinesList(const std::vector<const CGObjectInstan
 	}
 
 	//if player has some modded boosts we want to show that as well
-	totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD)));
-	totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size();
+	totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * playerSettings->handicap.percentIncome / 100;
+	totalIncome += LOCPLINT->cb->getPlayerState(LOCPLINT->playerID)->valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(GameResID(EGameResID::GOLD))) * towns.size() * playerSettings->handicap.percentIncome / 100;
 
 	for(int i=0; i<7; i++)
 	{

+ 4 - 4
lib/gameState/CGameState.cpp

@@ -1618,7 +1618,7 @@ struct statsHLP
 	}
 
 	// get total gold income
-	static int getIncome(const PlayerState * ps)
+	static int getIncome(const PlayerState * ps, int percentIncome)
 	{
 		int totalIncome = 0;
 		const CGObjectInstance * heroOrTown = nullptr;
@@ -1626,7 +1626,7 @@ struct statsHLP
 		//Heroes can produce gold as well - skill, specialty or arts
 		for(const auto & h : ps->heroes)
 		{
-			totalIncome += h->valOfBonuses(Selector::typeSubtype(BonusType::GENERATE_RESOURCE, BonusSubtypeID(GameResID(GameResID::GOLD))));
+			totalIncome += h->valOfBonuses(Selector::typeSubtype(BonusType::GENERATE_RESOURCE, BonusSubtypeID(GameResID(GameResID::GOLD)))) * percentIncome / 100;
 
 			if(!heroOrTown)
 				heroOrTown = h;
@@ -1661,7 +1661,7 @@ struct statsHLP
 				assert(mine);
 
 				if (mine->producedResource == EGameResID::GOLD)
-					totalIncome += mine->producedQuantity;
+					totalIncome += mine->getProducedQuantity();
 			}
 		}
 
@@ -1751,7 +1751,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
 	}
 	if(level >= 5) //income
 	{
-		FILL_FIELD(income, statsHLP::getIncome(&g->second))
+		FILL_FIELD(income, statsHLP::getIncome(&g->second, scenarioOps->getIthPlayersSettings(g->second.color).handicap.percentIncome))
 	}
 	if(level >= 2) //best hero's stats
 	{

+ 4 - 0
lib/mapObjects/CGTownInstance.cpp

@@ -215,6 +215,10 @@ TResources CGTownInstance::dailyIncome() const
 			ret += p.second->produce;
 		}
 	}
+
+	auto playerSettings = cb->gameState()->scenarioOps->getIthPlayersSettings(getOwner());
+	for(TResources::nziterator it(ret); it.valid(); it++)
+		ret[it->resType] = ret[it->resType] * playerSettings.handicap.percentIncome / 100;
 	return ret;
 }
 

+ 9 - 2
lib/mapObjects/MiscObjects.cpp

@@ -23,6 +23,7 @@
 #include "../gameState/CGameState.h"
 #include "../mapping/CMap.h"
 #include "../CPlayerState.h"
+#include "../StartInfo.h"
 #include "../serializer/JsonSerializeFormat.h"
 #include "../mapObjectConstructors/AObjectTypeHandler.h"
 #include "../mapObjectConstructors/CObjectClassesHandler.h"
@@ -103,7 +104,7 @@ void CGMine::newTurn(vstd::RNG & rand) const
 	if (tempOwner == PlayerColor::NEUTRAL)
 		return;
 
-	cb->giveResource(tempOwner, producedResource, producedQuantity);
+	cb->giveResource(tempOwner, producedResource, getProducedQuantity());
 }
 
 void CGMine::initObj(vstd::RNG & rand)
@@ -177,7 +178,7 @@ void CGMine::flagMine(const PlayerColor & player) const
 	iw.type = EInfoWindowMode::AUTO;
 	iw.text.appendTextID(TextIdentifier("core.mineevnt", producedResource.getNum()).get()); //not use subID, abandoned mines uses default mine texts
 	iw.player = player;
-	iw.components.emplace_back(ComponentType::RESOURCE_PER_DAY, producedResource, producedQuantity);
+	iw.components.emplace_back(ComponentType::RESOURCE_PER_DAY, producedResource, getProducedQuantity());
 	cb->showInfoDialog(&iw);
 }
 
@@ -195,6 +196,12 @@ ui32 CGMine::defaultResProduction() const
 	}
 }
 
+ui32 CGMine::getProducedQuantity() const
+{
+	auto * playerSettings = cb->getPlayerSettings(getOwner());
+	return producedQuantity * playerSettings->handicap.percentIncome / 100;
+}
+
 void CGMine::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
 {
 	if(result.winner == 0) //attacker won

+ 1 - 0
lib/mapObjects/MiscObjects.h

@@ -181,6 +181,7 @@ public:
 		h & abandonedMineResources;
 	}
 	ui32 defaultResProduction() const;
+	ui32 getProducedQuantity() const;
 
 protected:
 	void serializeJsonOptions(JsonSerializeFormat & handler) override;

+ 7 - 7
server/CGameHandler.cpp

@@ -760,6 +760,8 @@ void CGameHandler::onNewTurn()
 			continue;
 
 		assert(elem.first.isValidPlayer());//illegal player number!
+			
+		auto playerSettings = gameState()->scenarioOps->getIthPlayersSettings(elem.first);
 
 		std::pair<PlayerColor, si32> playerGold(elem.first, elem.second.resources[EGameResID::GOLD]);
 		hadGold.insert(playerGold);
@@ -773,8 +775,8 @@ void CGameHandler::onNewTurn()
 		{
 			for (GameResID k = GameResID::WOOD; k < GameResID::COUNT; k++)
 			{
-				n.res[elem.first][k] += elem.second.valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(k));
-				n.res[elem.first][k] += elem.second.valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(k)) * elem.second.towns.size();
+				n.res[elem.first][k] += elem.second.valOfBonuses(BonusType::RESOURCES_CONSTANT_BOOST, BonusSubtypeID(k)) * playerSettings.handicap.percentIncome / 100;
+				n.res[elem.first][k] += elem.second.valOfBonuses(BonusType::RESOURCES_TOWN_MULTIPLYING_BOOST, BonusSubtypeID(k)) * elem.second.towns.size() * playerSettings.handicap.percentIncome / 100;
 			}
 
 			if(newWeek) //weekly crystal generation if 1 or more crystal dragons in any hero army or town garrison
@@ -806,7 +808,7 @@ void CGameHandler::onNewTurn()
 					}
 				}
 				if(hasCrystalGenCreature)
-					n.res[elem.first][EGameResID::CRYSTAL] += 3;
+					n.res[elem.first][EGameResID::CRYSTAL] += 3 * playerSettings.handicap.percentIncome / 100;
 			}
 		}
 
@@ -828,7 +830,7 @@ void CGameHandler::onNewTurn()
 			{
 				for (GameResID k = GameResID::WOOD; k < GameResID::COUNT; k++)
 				{
-					n.res[elem.first][k] += h->valOfBonuses(BonusType::GENERATE_RESOURCE, BonusSubtypeID(k));
+					n.res[elem.first][k] += h->valOfBonuses(BonusType::GENERATE_RESOURCE, BonusSubtypeID(k)) * playerSettings.handicap.percentIncome / 100;
 				}
 			}
 		}
@@ -1428,10 +1430,8 @@ 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 * playerSettings->handicap.percentIncome / 100;
+	resources[which] = val;
 	giveResources(player, resources);
 }