Răsfoiți Sursa

Use HeroTypeID instead of int

Ivan Savenko 2 ani în urmă
părinte
comite
0fdbf54937

+ 1 - 1
client/lobby/CBonusSelection.cpp

@@ -82,7 +82,7 @@ CBonusSelection::CBonusSelection()
 
 	mapName = std::make_shared<CLabel>(481, 219, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->mi->getName());
 	labelMapDescription = std::make_shared<CLabel>(481, 253, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[496]);
-	mapDescription = std::make_shared<CTextBox>("", Rect(480, 280, 286, 117), 1);
+	mapDescription = std::make_shared<CTextBox>("", Rect(480, 278, 292, 108), 1);
 
 	labelChooseBonus = std::make_shared<CLabel>(511, 432, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[71]);
 	groupBonuses = std::make_shared<CToggleGroup>(std::bind(&IServerAPI::setCampaignBonus, CSH, _1));

+ 2 - 0
lib/GameConstants.cpp

@@ -38,6 +38,8 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
+const HeroTypeID HeroTypeID::NONE = HeroTypeID(-1);
+
 const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2);
 const SlotID SlotID::SUMMONED_SLOT_PLACEHOLDER = SlotID(-3);
 const SlotID SlotID::WAR_MACHINES_SLOT = SlotID(-4);

+ 2 - 0
lib/GameConstants.h

@@ -329,6 +329,8 @@ class HeroTypeID : public BaseForID<HeroTypeID, si32>
 	///json serialization helpers
 	static si32 decode(const std::string & identifier);
 	static std::string encode(const si32 index);
+
+	DLL_LINKAGE static const HeroTypeID NONE;
 };
 
 class SlotID : public BaseForID<SlotID, si32>

+ 7 - 7
lib/gameState/CGameState.cpp

@@ -177,18 +177,18 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native,
 	return ret;
 }
 
-int CGameState::pickNextHeroType(const PlayerColor & owner)
+HeroTypeID CGameState::pickNextHeroType(const PlayerColor & owner)
 {
 	const PlayerSettings &ps = scenarioOps->getIthPlayersSettings(owner);
 	if(ps.hero >= 0 && !isUsedHero(HeroTypeID(ps.hero))) //we haven't used selected hero
 	{
-		return ps.hero;
+		return HeroTypeID(ps.hero);
 	}
 
 	return pickUnusedHeroTypeRandomly(owner);
 }
 
-int CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
+HeroTypeID CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
 {
 	//list of available heroes for this faction and others
 	std::vector<HeroTypeID> factionHeroes;
@@ -206,23 +206,23 @@ int CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
 	// select random hero native to "our" faction
 	if(!factionHeroes.empty())
 	{
-		return RandomGeneratorUtil::nextItem(factionHeroes, getRandomGenerator())->getNum();
+		return *RandomGeneratorUtil::nextItem(factionHeroes, getRandomGenerator());
 	}
 
 	logGlobal->warn("Cannot find free hero of appropriate faction for player %s - trying to get first available...", owner.getStr());
 	if(!otherHeroes.empty())
 	{
-		return RandomGeneratorUtil::nextItem(otherHeroes, getRandomGenerator())->getNum();
+		return *RandomGeneratorUtil::nextItem(otherHeroes, getRandomGenerator());
 	}
 
 	logGlobal->error("No free allowed heroes!");
 	auto notAllowedHeroesButStillBetterThanCrash = getUnusedAllowedHeroes(true);
 	if(!notAllowedHeroesButStillBetterThanCrash.empty())
-		return notAllowedHeroesButStillBetterThanCrash.begin()->getNum();
+		return *notAllowedHeroesButStillBetterThanCrash.begin();
 
 	logGlobal->error("No free heroes at all!");
 	assert(0); //current code can't handle this situation
-	return -1; // no available heroes at all
+	return HeroTypeID::NONE; // no available heroes at all
 }
 
 std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)

+ 2 - 2
lib/gameState/CGameState.h

@@ -215,8 +215,8 @@ private:
 	bool isUsedHero(const HeroTypeID & hid) const; //looks in heroes and prisons
 	std::set<HeroTypeID> getUnusedAllowedHeroes(bool alsoIncludeNotAllowed = false) const;
 	std::pair<Obj,int> pickObject(CGObjectInstance *obj); //chooses type of object to be randomized, returns <type, subtype>
-	int pickUnusedHeroTypeRandomly(const PlayerColor & owner); // picks a unused hero type randomly
-	int pickNextHeroType(const PlayerColor & owner); // picks next free hero type of the H3 hero init sequence -> chosen starting hero, then unused hero type randomly
+	HeroTypeID pickUnusedHeroTypeRandomly(const PlayerColor & owner); // picks a unused hero type randomly
+	HeroTypeID pickNextHeroType(const PlayerColor & owner); // picks next free hero type of the H3 hero init sequence -> chosen starting hero, then unused hero type randomly
 	UpgradeInfo fillUpgradeInfo(const CStackInstance &stack) const;
 
 	// ---- data -----