1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Remove few more implicit conversions

This commit is contained in:
Ivan Savenko 2023-11-05 19:13:18 +02:00
parent abad4b01ce
commit 34338f4eaa
14 changed files with 48 additions and 36 deletions

View File

@ -77,7 +77,7 @@ void CSkill::registerIcons(const IconRegistar & cb) const
{
for(int level = 1; level <= 3; level++)
{
int frame = 2 + level + 3 * id;
int frame = 2 + level + 3 * id.getNum();
const LevelInfo & skillAtLevel = at(level);
cb(frame, 0, "SECSK32", skillAtLevel.iconSmall);
cb(frame, 0, "SECSKILL", skillAtLevel.iconMedium);

View File

@ -144,12 +144,12 @@ CFaction::~CFaction()
int32_t CFaction::getIndex() const
{
return index;
return index.getNum();
}
int32_t CFaction::getIconIndex() const
{
return index; //???
return index.getNum(); //???
}
std::string CFaction::getJsonKey() const
@ -172,8 +172,8 @@ void CFaction::registerIcons(const IconRegistar & cb) const
cb(info.icons[1][0] + 2, 0, "ITPA", info.iconSmall[1][0]);
cb(info.icons[1][1] + 2, 0, "ITPA", info.iconSmall[1][1]);
cb(index, 1, "CPRSMALL", info.towerIconSmall);
cb(index, 1, "TWCRPORT", info.towerIconLarge);
cb(index.getNum(), 1, "CPRSMALL", info.towerIconSmall);
cb(index.getNum(), 1, "TWCRPORT", info.towerIconLarge);
}
}
@ -734,7 +734,7 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
ret->town->buildings[ret->bid] = ret;
registerObject(source.meta, ret->town->getBuildingScope(), ret->identifier, ret->bid);
registerObject(source.meta, ret->town->getBuildingScope(), ret->identifier, ret->bid.getNum());
}
void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
@ -1115,10 +1115,10 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
if (object->town)
{
auto & info = object->town->clientInfo;
info.icons[0][0] = 8 + object->index * 4 + 0;
info.icons[0][1] = 8 + object->index * 4 + 1;
info.icons[1][0] = 8 + object->index * 4 + 2;
info.icons[1][1] = 8 + object->index * 4 + 3;
info.icons[0][0] = 8 + object->index.getNum() * 4 + 0;
info.icons[0][1] = 8 + object->index.getNum() * 4 + 1;
info.icons[1][0] = 8 + object->index.getNum() * 4 + 2;
info.icons[1][1] = 8 + object->index.getNum() * 4 + 3;
VLC->identifiers()->requestIdentifier(scope, "object", "town", [=](si32 index)
{
@ -1142,7 +1142,7 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
});
}
registerObject(scope, "faction", name, object->index);
registerObject(scope, "faction", name, object->index.getNum());
}
void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
@ -1158,10 +1158,10 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
if (object->town)
{
auto & info = object->town->clientInfo;
info.icons[0][0] = (GameConstants::F_NUMBER + object->index) * 2 + 0;
info.icons[0][1] = (GameConstants::F_NUMBER + object->index) * 2 + 1;
info.icons[1][0] = object->index * 2 + 0;
info.icons[1][1] = object->index * 2 + 1;
info.icons[0][0] = (GameConstants::F_NUMBER + object->index.getNum()) * 2 + 0;
info.icons[0][1] = (GameConstants::F_NUMBER + object->index.getNum()) * 2 + 1;
info.icons[1][0] = object->index.getNum() * 2 + 0;
info.icons[1][1] = object->index.getNum() * 2 + 1;
VLC->identifiers()->requestIdentifier(scope, "object", "town", [=](si32 index)
{
@ -1173,7 +1173,7 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
});
}
registerObject(scope, "faction", name, object->index);
registerObject(scope, "faction", name, object->index.getNum());
}
void CTownHandler::loadRandomFaction()

View File

@ -571,6 +571,12 @@ public:
static std::string encode(int32_t index);
static si32 decode(const std::string & identifier);
// TODO: Remove
constexpr operator int32_t () const
{
return num;
}
};
class MapObjectSubID : public Identifier<MapObjectSubID>
@ -594,6 +600,12 @@ public:
this->num = value.getNum();
return *this;
}
// TODO: Remove
constexpr operator int32_t () const
{
return num;
}
};
class DLL_LINKAGE RoadId : public Identifier<RoadId>

View File

@ -52,10 +52,10 @@ public:
num += change;
}
constexpr operator int32_t () const
{
return num;
}
// constexpr operator int32_t () const
// {
// return num;
// }
friend std::ostream& operator<<(std::ostream& os, const IdentifierBase& dt)
{

View File

@ -117,7 +117,7 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
tmpl->readTxt(parser);
parser.endLine();
std::pair<si32, si32> key(tmpl->id.num, tmpl->subid);
std::pair key(tmpl->id, tmpl->subid);
legacyTemplates.insert(std::make_pair(key, std::shared_ptr<const ObjectTemplate>(tmpl)));
}

View File

@ -74,7 +74,7 @@ class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase
std::map<std::string, std::function<TObjectTypeHandler()> > handlerConstructors;
/// container with H3 templates, used only during loading, no need to serialize it
using TTemplatesContainer = std::multimap<std::pair<si32, si32>, std::shared_ptr<const ObjectTemplate>>;
using TTemplatesContainer = std::multimap<std::pair<MapObjectID, MapObjectSubID>, std::shared_ptr<const ObjectTemplate>>;
TTemplatesContainer legacyTemplates;
TObjectTypeHandler loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index);

View File

@ -49,7 +49,7 @@ CGDwelling::~CGDwelling() = default;
FactionID CGDwelling::randomizeFaction(CRandomGenerator & rand)
{
if (ID == Obj::RANDOM_DWELLING_FACTION)
return FactionID(subID);
return FactionID(subID.getNum());
assert(ID == Obj::RANDOM_DWELLING || ID == Obj::RANDOM_DWELLING_LVL);
assert(randomizationInfo.has_value());
@ -138,7 +138,7 @@ void CGDwelling::pickRandomObject(CRandomGenerator & rand)
auto testID = [&](const Obj & primaryID) -> MapObjectSubID
{
auto dwellingIDs = VLC->objtypeh->knownSubObjects(primaryID);
for (si32 entry : dwellingIDs)
for (MapObjectSubID entry : dwellingIDs)
{
const auto * handler = dynamic_cast<const DwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(primaryID, entry).get());

View File

@ -43,8 +43,8 @@ class DLL_LINKAGE ObjectTemplate
public:
/// H3 ID/subID of this object
Obj id;
si32 subid;
MapObjectID id;
MapObjectSubID subid;
/// print priority, objects with higher priority will be print first, below everything else
si32 printPriority;
/// animation file that should be used to display object

View File

@ -707,7 +707,7 @@ void CMapLoaderH3M::readDisposedHeroes()
for(int g = 0; g < disp; ++g)
{
map->disposedHeroes[g].heroId = reader->readHero();
map->disposedHeroes[g].portrait.setNum(reader->readHeroPortrait());
map->disposedHeroes[g].portrait = reader->readHeroPortrait();
map->disposedHeroes[g].name = readLocalizedString(TextIdentifier("header", "heroes", map->disposedHeroes[g].heroId));
reader->readBitmaskPlayers(map->disposedHeroes[g].players, false);
}

View File

@ -127,10 +127,10 @@ rmg::Area & Zone::freePaths()
FactionID Zone::getTownType() const
{
return FactionID(townType);
return townType;
}
void Zone::setTownType(si32 town)
void Zone::setTownType(FactionID town)
{
townType = town;
}

View File

@ -59,7 +59,7 @@ public:
void fractalize();
FactionID getTownType() const;
void setTownType(si32 town);
void setTownType(FactionID town);
TerrainId getTerrainType() const;
void setTerrainType(TerrainId terrain);
@ -108,7 +108,7 @@ protected:
std::vector<int3> possibleQuestArtifactPos;
//template info
si32 townType;
FactionID townType;
TerrainId terrainType;
};

View File

@ -179,7 +179,7 @@ void TownPlacer::addNewTowns(int count, bool hasFort, const PlayerColor & player
{
for(int i = 0; i < count; i++)
{
si32 subType = zone.getTownType();
FactionID subType = zone.getTownType();
if(totalTowns>0)
{

View File

@ -155,8 +155,8 @@ void TreasurePlacer::addAllPossibleObjects()
if(dwellingType == Obj::CREATURE_GENERATOR1)
{
//don't spawn original "neutral" dwellings that got replaced by Conflux dwellings in AB
static int elementalConfluxROE[] = {7, 13, 16, 47};
for(int & i : elementalConfluxROE)
static MapObjectSubID elementalConfluxROE[] = {7, 13, 16, 47};
for(auto const & i : elementalConfluxROE)
vstd::erase_if_present(subObjects, i);
}
@ -918,7 +918,7 @@ char TreasurePlacer::dump(const int3 & t)
return Modificator::dump(t);
}
void ObjectInfo::setTemplates(si32 type, si32 subtype, TerrainId terrainType)
void ObjectInfo::setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainId terrainType)
{
auto templHandler = VLC->objtypeh->getHandlerFor(type, subtype);
if(!templHandler)

View File

@ -29,7 +29,7 @@ struct ObjectInfo
//ui32 maxPerMap; //unused
std::function<CGObjectInstance *()> generateObject;
void setTemplates(si32 type, si32 subtype, TerrainId terrain);
void setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainId terrain);
};
class TreasurePlacer: public Modificator