1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Replace vector[] with range-checking vector.at()

This commit is contained in:
Ivan Savenko 2024-01-04 23:52:57 +02:00
parent 3b66701ffe
commit 63a2ed7cf8
2 changed files with 15 additions and 15 deletions

View File

@ -69,7 +69,7 @@ int ISelectionScreenInfo::getCurrentDifficulty()
PlayerInfo ISelectionScreenInfo::getPlayerInfo(PlayerColor color)
{
return getMapInfo()->mapHeader->players[color.getNum()];
return getMapInfo()->mapHeader->players.at(color.getNum());
}
CSelectionBase::CSelectionBase(ESelectionScreen type)

View File

@ -291,28 +291,28 @@ void CObjectClassesHandler::loadObject(std::string scope, std::string name, cons
void CObjectClassesHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
{
assert(objects[index] == nullptr); // ensure that this id was not loaded before
assert(objects.at(index) == nullptr); // ensure that this id was not loaded before
objects[index] = loadFromJson(scope, data, name, index);
VLC->identifiersHandler->registerObject(scope, "object", name, objects[index]->id);
objects.at(index) = loadFromJson(scope, data, name, index);
VLC->identifiersHandler->registerObject(scope, "object", name, objects.at(index)->id);
}
void CObjectClassesHandler::loadSubObject(const std::string & identifier, JsonNode config, MapObjectID ID, MapObjectSubID subID)
{
config.setType(JsonNode::JsonType::DATA_STRUCT); // ensure that input is not NULL
assert(objects[ID.getNum()]);
assert(objects.at(ID.getNum()));
if ( subID.getNum() >= objects[ID.getNum()]->objects.size())
objects[ID.getNum()]->objects.resize(subID.getNum()+1);
if ( subID.getNum() >= objects.at(ID.getNum())->objects.size())
objects.at(ID.getNum())->objects.resize(subID.getNum()+1);
JsonUtils::inherit(config, objects.at(ID.getNum())->base);
loadSubObject(config.meta, identifier, config, objects[ID.getNum()].get(), subID.getNum());
loadSubObject(config.meta, identifier, config, objects.at(ID.getNum()).get(), subID.getNum());
}
void CObjectClassesHandler::removeSubObject(MapObjectID ID, MapObjectSubID subID)
{
assert(objects[ID.getNum()]);
objects[ID.getNum()]->objects[subID.getNum()] = nullptr;
assert(objects.at(ID.getNum()));
objects.at(ID.getNum())->objects.at(subID.getNum()) = nullptr;
}
TObjectTypeHandler CObjectClassesHandler::getHandlerFor(MapObjectID type, MapObjectSubID subtype) const
@ -345,11 +345,11 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(const std::string & scop
std::optional<si32> id = VLC->identifiers()->getIdentifier(scope, "object", type);
if(id)
{
const auto & object = objects[id.value()];
const auto & object = objects.at(id.value());
std::optional<si32> subID = VLC->identifiers()->getIdentifier(scope, object->getJsonKey(), subtype);
if (subID)
return object->objects[subID.value()];
return object->objects.at(subID.value());
}
std::string errorString = "Failed to find object of type " + type + "::" + subtype;
@ -480,8 +480,8 @@ std::string CObjectClassesHandler::getObjectName(MapObjectID type, MapObjectSubI
if (handler && handler->hasNameTextID())
return handler->getNameTranslated();
if (objects[type.getNum()])
return objects[type.getNum()]->getNameTranslated();
if (objects.at(type.getNum()))
return objects.at(type.getNum())->getNameTranslated();
return objects.front()->getNameTranslated();
}
@ -495,7 +495,7 @@ SObjectSounds CObjectClassesHandler::getObjectSounds(MapObjectID type, MapObject
if(type == Obj::PRISON || type == Obj::HERO || type == Obj::SPELL_SCROLL)
subtype = 0;
if(objects[type.getNum()])
if(objects.at(type.getNum()))
return getHandlerFor(type, subtype)->getSounds();
else
return objects.front()->objects.front()->getSounds();