diff --git a/docs/Whats-New.md b/docs/Whats-New.md index 35d764b597..e07ea75f3f 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -710,6 +710,7 @@ Phobos fixes: - Fixed the bug where the `.SubjectToGround` of the Trajectory type did not consider bridges (by Noble_Fish) - AttachEffect `DisableWeapons=true` now makes `Gattling=yes` rate tick down and stops the sounds from playing (by Starkku) - Fixed cells with `CanBeBuiltOn=true` TerrainTypes on them not being considered valid build locations by AI (by Starkku) +- Fixed the bug where `WeaponRange.AllowWeapons` and `WeaponRange.DisallowWeapons` only support weapons listed in the `[WeaponTypes]` list (by Noble_Fish) Fixes / interactions with other extensions: - Taking over Ares' AlphaImage respawn logic to reduce lags from it (by NetsuNegi) diff --git a/src/Utilities/TemplateDef.h b/src/Utilities/TemplateDef.h index 856355209f..ec0fd1e1a7 100644 --- a/src/Utilities/TemplateDef.h +++ b/src/Utilities/TemplateDef.h @@ -1679,6 +1679,40 @@ void __declspec(noinline) ValueableVector::Read(INI_EX& parser, const char* p } } +// Specialization: use FindOrAllocate for weapon vectors, avoiding dependency on [WeaponTypes] registration +template <> +inline void ValueableVector::Read(INI_EX& parser, const char* pSection, const char* pKey) +{ + if (parser.ReadString(pSection, pKey)) + { + this->clear(); + char* str = parser.value(); + char* context = nullptr; + for (char* cur = strtok_s(str, Phobos::readDelims, &context); cur; cur = strtok_s(nullptr, Phobos::readDelims, &context)) + { + if (auto pWeapon = WeaponTypeClass::FindOrAllocate(cur)) + this->push_back(pWeapon); + } + } +} + +// Specialization: use FindOrAllocate for warhead vectors, avoiding dependency on [Warheads] table +template <> +inline void ValueableVector::Read(INI_EX& parser, const char* pSection, const char* pKey) +{ + if (parser.ReadString(pSection, pKey)) + { + this->clear(); + char* str = parser.value(); + char* context = nullptr; + for (char* cur = strtok_s(str, Phobos::readDelims, &context); cur; cur = strtok_s(nullptr, Phobos::readDelims, &context)) + { + if (auto pWarhead = WarheadTypeClass::FindOrAllocate(cur)) + this->push_back(pWarhead); + } + } +} + template bool ValueableVector::Load(PhobosStreamReader& Stm, bool RegisterForChange) {