diff --git a/data/libs/Ship.lua b/data/libs/Ship.lua index b1858ab744..99e3fb25b9 100644 --- a/data/libs/Ship.lua +++ b/data/libs/Ship.lua @@ -53,11 +53,15 @@ function Ship:UpdateWeaponSlots() for _, slot in ipairs(equipSet:GetAllSlotsOfType("weapon", true)) do if not slot.gimbal then - print('Missing hardpoint gimbal on ship {} for slot {}' % { self.shipId, slot.id }) + logWarning('Missing hardpoint gimbal on ship {} for slot {}' % { self.shipId, slot.id }) end local gimbal = Vector2(table.unpack(slot.gimbal or { 1, 1 })) - gunManager:AddWeaponMount(slot.id, slot.tag, gimbal) + local ok = gunManager:AddWeaponMount(slot.id, slot.tag, gimbal) + + if not ok then + logWarning('Unable to add weapon mount slot {} on ship {}' % { slot.id, self.shipId }) + end end end diff --git a/src/ship/GunManager.cpp b/src/ship/GunManager.cpp index dcaec1c985..b00d966613 100644 --- a/src/ship/GunManager.cpp +++ b/src/ship/GunManager.cpp @@ -133,16 +133,17 @@ bool GunManager::AddWeaponMount(StringName id, StringName tagName, vector2f gimb return result.second; } -void GunManager::RemoveWeaponMount(StringName id) +bool GunManager::RemoveWeaponMount(StringName id) { auto iter = m_mounts.find(id); if (iter == m_mounts.end()) - return; + return false; if (IsWeaponMounted(id)) - return; + return false; m_mounts.erase(iter); + return true; } bool GunManager::MountWeapon(StringName hardpoint, const WeaponData &gunData) diff --git a/src/ship/GunManager.h b/src/ship/GunManager.h index a8bf261534..4be57ef8d5 100644 --- a/src/ship/GunManager.h +++ b/src/ship/GunManager.h @@ -142,7 +142,8 @@ class GunManager : public LuaWrappable { bool AddWeaponMount(StringName id, StringName tagName, vector2f gimbalLimitDegrees); // Remove a weapon mount from this gun manager. // The caller should always ensure that the weapon mount is empty before calling this function. - void RemoveWeaponMount(StringName id); + // Returns false if the mount does not exist or is not empty. + bool RemoveWeaponMount(StringName id); // Attach a weapon to a specific mount. // Returns false if the hardpoint cannot be found or the weapon could not be mounted.