1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Remove few more implicit conversions

This commit is contained in:
Ivan Savenko 2023-11-08 16:13:08 +02:00
parent 34338f4eaa
commit 13763cad8e
17 changed files with 50 additions and 54 deletions

View File

@ -235,38 +235,30 @@ void CBonusSelection::createBonusesIcons()
break;
case CampaignBonusType::RESOURCE:
{
int serialResID = 0;
desc.appendLocalString(EMetaText::GENERAL_TXT, 717);
switch(bonDescs[i].info1)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
serialResID = bonDescs[i].info1;
break;
case 0xFD: //wood + ore
serialResID = 7;
break;
case 0xFE: //rare resources
serialResID = 8;
{
desc.replaceLocalString(EMetaText::GENERAL_TXT, 721);
picNumber = 7;
break;
}
picNumber = serialResID;
case 0xFE: //wood + ore
{
desc.replaceLocalString(EMetaText::GENERAL_TXT, 722);
picNumber = 8;
break;
}
default:
{
desc.replaceName(GameResID(bonDescs[i].info1));
picNumber = bonDescs[i].info1;
}
}
desc.appendLocalString(EMetaText::GENERAL_TXT, 717);
desc.replaceNumber(bonDescs[i].info2);
if(serialResID <= 6)
{
desc.replaceLocalString(EMetaText::RES_NAMES, serialResID);
}
else
{
desc.replaceLocalString(EMetaText::GENERAL_TXT, 714 + serialResID);
}
break;
}
case CampaignBonusType::HEROES_FROM_PREVIOUS_SCENARIO:

View File

@ -122,17 +122,17 @@ TurnTimerInfo CGameInfoCallback::getPlayerTurnTime(PlayerColor color) const
return TurnTimerInfo{};
}
const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(int identifier) const
const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(ObjectInstanceID identifier) const
{
if(gs->map->questIdentifierToId.empty())
{
//assume that it is VCMI map and quest identifier equals instance identifier
return getObj(ObjectInstanceID(identifier), true);
return getObj(identifier, true);
}
else
{
ERROR_RET_VAL_IF(!vstd::contains(gs->map->questIdentifierToId, identifier), "There is no object with such quest identifier!", nullptr);
return getObj(gs->map->questIdentifierToId[identifier]);
ERROR_RET_VAL_IF(!vstd::contains(gs->map->questIdentifierToId, identifier.getNum()), "There is no object with such quest identifier!", nullptr);
return getObj(gs->map->questIdentifierToId[identifier.getNum()]);
}
}

View File

@ -93,7 +93,7 @@ public:
// std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
// const CGObjectInstance * getTopObj (int3 pos) const;
// PlayerColor getOwner(ObjectInstanceID heroID) const;
// const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed)
// const CGObjectInstance *getObjByQuestIdentifier(ObjectInstanceID identifier) const; //nullptr if object has been removed (eg. killed)
//map
// int3 guardingCreaturePosition (int3 pos) const;
@ -190,7 +190,7 @@ public:
virtual std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
virtual const CGObjectInstance * getTopObj (int3 pos) const;
virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
virtual const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed)
virtual const CGObjectInstance *getObjByQuestIdentifier(ObjectInstanceID identifier) const; //nullptr if object has been removed (eg. killed)
//map
virtual int3 guardingCreaturePosition (int3 pos) const;

View File

@ -114,8 +114,6 @@ std::string MetaString::getLocalString(const std::pair<EMetaText, ui32> & txt) c
{
case EMetaText::GENERAL_TXT:
return VLC->generaltexth->translate("core.genrltxt", ser);
case EMetaText::RES_NAMES:
return VLC->generaltexth->translate("core.restypes", ser);
case EMetaText::ARRAY_TXT:
return VLC->generaltexth->translate("core.arraytxt", ser);
case EMetaText::ADVOB_TXT:
@ -374,6 +372,11 @@ void MetaString::replaceName(const SpellID & id)
replaceTextID(id.toEntity(VLC)->getNameTextID());
}
void MetaString::replaceName(const GameResID& id)
{
replaceTextID(TextIdentifier("core.restypes", id.getNum()).get());
}
void MetaString::replaceNameSingular(const CreatureID & id)
{
replaceTextID(id.toEntity(VLC)->getNameSingularTextID());

View File

@ -21,13 +21,13 @@ class MapObjectSubID;
class PlayerColor;
class SecondarySkill;
class SpellID;
class GameResID;
using TQuantity = si32;
/// Strings classes that can be used as replacement in MetaString
enum class EMetaText : uint8_t
{
GENERAL_TXT = 1,
RES_NAMES,
ARRAY_TXT,
ADVOB_TXT,
JK_TXT
@ -97,6 +97,7 @@ public:
void replaceName(const PlayerColor& id);
void replaceName(const SecondarySkill& id);
void replaceName(const SpellID& id);
void replaceName(const GameResID& id);
/// Replaces first '%s' placeholder with singular or plural name depending on creatures count
void replaceName(const CreatureID & id, TQuantity count);

View File

@ -189,8 +189,8 @@ void CGameStateCampaign::placeCampaignHeroes()
auto it = gameState->scenarioOps->playerInfos.find(playerColor);
if(it != gameState->scenarioOps->playerInfos.end())
{
auto heroTypeId = campaignBonus->info2;
if(heroTypeId == 0xffff) // random bonus hero
HeroTypeID heroTypeId = HeroTypeID(campaignBonus->info2);
if(heroTypeId.getNum() == 0xffff) // random bonus hero
{
heroTypeId = gameState->pickUnusedHeroTypeRandomly(playerColor);
}

View File

@ -23,7 +23,7 @@ struct DLL_LINKAGE SThievesGuildInfo
std::map<PlayerColor, InfoAboutHero> colorToBestHero; //maps player's color to his best heros'
std::map<PlayerColor, EAiTactic> personality; // color to personality // ai tactic
std::map<PlayerColor, si32> bestCreature; // color to ID // id or -1 if not known
std::map<PlayerColor, CreatureID> bestCreature; // color to ID // id or -1 if not known
// template <typename Handler> void serialize(Handler &h, const int version)
// {

View File

@ -273,7 +273,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
iw.components.emplace_back(ComponentType::RESOURCE, it, bc->resources[it]);
loot.appendRawString("%d %s");
loot.replaceNumber(bc->resources[it]);
loot.replaceLocalString(EMetaText::RES_NAMES, it);
loot.replaceName(it);
cb->giveResource(hero->getOwner(), it, bc->resources[it]);
}
}

View File

@ -242,13 +242,13 @@ void CQuest::addTextReplacements(MetaString & text, std::vector<Component> & com
if(mission.resources.nonZero())
{
MetaString loot;
for(int i = 0; i < 7; ++i)
for(auto i : GameResID::ALL_RESOURCES())
{
if(mission.resources[i])
{
loot.appendRawString("%d %s");
loot.replaceNumber(mission.resources[i]);
loot.replaceLocalString(EMetaText::RES_NAMES, i);
loot.replaceName(i);
}
}
text.replaceRawString(loot.buildList());

View File

@ -320,7 +320,7 @@ void CGResource::collectRes(const PlayerColor & player) const
{
sii.type = EInfoWindowMode::INFO;
sii.text.appendLocalString(EMetaText::ADVOB_TXT,113);
sii.text.replaceLocalString(EMetaText::RES_NAMES, resourceID());
sii.text.replaceName(resourceID());
}
sii.components.emplace_back(ComponentType::RESOURCE, resourceID(), amount);
sii.soundID = soundBase::pickup01 + CRandomGenerator::getDefault().nextInt(6);

View File

@ -26,9 +26,9 @@ CIdentifierStorage::CIdentifierStorage()
{
//TODO: moddable spell schools
for (auto i = 0; i < GameConstants::DEFAULT_SCHOOLS; ++i)
registerObject(ModScope::scopeBuiltin(), "spellSchool", SpellConfig::SCHOOL[i].jsonName, SpellConfig::SCHOOL[i].id);
registerObject(ModScope::scopeBuiltin(), "spellSchool", SpellConfig::SCHOOL[i].jsonName, SpellConfig::SCHOOL[i].id.getNum());
registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool(SpellSchool::ANY));
registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool::ANY.getNum());
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
registerObject(ModScope::scopeBuiltin(), "resource", GameConstants::RESOURCE_NAMES[i], i);

View File

@ -1971,9 +1971,9 @@ void HeroVisit::applyGs(CGameState *gs)
void SetAvailableArtifacts::applyGs(CGameState * gs) const
{
if(id >= 0)
if(id != ObjectInstanceID::NONE)
{
if(auto * bm = dynamic_cast<CGBlackMarket *>(gs->map->objects[id].get()))
if(auto * bm = dynamic_cast<CGBlackMarket *>(gs->getObjInstance(id)))
{
bm->artifacts = arts;
}

View File

@ -325,7 +325,7 @@ void CMapGenOptions::resetPlayersMap()
}
else
{
logGlobal->warn("Adding settings for player %s", color.encode(color));
logGlobal->warn("Adding settings for player %s", color);
// Usually, all players should be initialized in initPlayersMap()
CPlayerSettings settings;
players[color] = settings;

View File

@ -182,7 +182,7 @@ void CMapGenerator::addPlayerInfo()
{
// Teams are already configured in CMapGenOptions. However, it's not the case when it comes to map editor
std::set<int> teamsTotal;
std::set<TeamID> teamsTotal;
if (mapGenOptions.arePlayersCustomized())
{
@ -284,7 +284,7 @@ void CMapGenerator::addPlayerInfo()
player.team = TeamID(*itTeam);
teamNumbers[j].erase(itTeam);
}
teamsTotal.insert(player.team.getNum());
teamsTotal.insert(player.team);
map->getMap(this).players[pSettings.getColor().getNum()] = player;
}

View File

@ -223,7 +223,7 @@ void TownPlacer::addNewTowns(int count, bool hasFort, const PlayerColor & player
}
}
si32 TownPlacer::getRandomTownType(bool matchUndergroundType)
FactionID TownPlacer::getRandomTownType(bool matchUndergroundType)
{
auto townTypesAllowed = (!zone.getTownTypes().empty() ? zone.getTownTypes() : zone.getDefaultTownTypes());
if(matchUndergroundType)

View File

@ -28,7 +28,7 @@ public:
protected:
void cleanupBoundaries(const rmg::Object & rmgObject);
void addNewTowns(int count, bool hasFort, const PlayerColor & player, ObjectManager & manager);
si32 getRandomTownType(bool matchUndergroundType = false);
FactionID getRandomTownType(bool matchUndergroundType = false);
void placeTowns(ObjectManager & manager);
bool placeMines(ObjectManager & manager);
int3 placeMainTown(ObjectManager & manager, CGTownInstance & town);

View File

@ -30,8 +30,8 @@ public:
EXPECT_CALL(spellMock, forEachSchool(NotNull())).Times(AtLeast(1)).WillRepeatedly([](const spells::Spell::SchoolCallback & cb)
{
bool stop = false;
cb(SpellSchool(SpellSchool::AIR), stop);
cb(SpellSchool(SpellSchool::FIRE), stop);
cb(SpellSchool::AIR, stop);
cb(SpellSchool::FIRE, stop);
});
EXPECT_CALL(mechanicsMock, isPositiveSpell()).WillRepeatedly(Return(isPositive));