ValueSet& Variables::Values::GetValue (int type) { CS_ASSERT ((type >= valueFirst) && (type <= valueLast)); const uint flag = 1 << type; if (!(valueFlags & flag)) { uint count = ValueCount (valueFlags); SetValueIndex (type, count); valueFlags |= flag; if (count >= inlinedSets) { ValueSetChain** d = &multiValues; while (*d != 0) { d = &(*d)->nextPlease; } *d = ValChainAlloc().Alloc(); return (*d)->vs; } } uint index = GetValueIndex (type); if (index < inlinedSets) return inlineValues[index]; else return GetMultiValue (index - inlinedSets); }
void Enchantment::SetSafeValueIndex(int index) { GameData::EnchantmentData data; if (!GameData::Get().GetDataFor(Id, data)) { // Unsafe since we don't have data SetValueIndex(index); return; } if (data.MinValue.empty()) { // Not sure if this is possible, but do it unsafely anyway SetValueIndex(index); return; } // Check bounds auto safeIndex = std::max(0, std::min(static_cast<int>(data.MinValue.size()) - 1, index)); SetValueIndex(safeIndex); }