Weapon can belong to any type of WorldObject. Why restrict m_owner to be a ship? Since you need a ship in this special case a few lines above, retrieve the the WorldObject the Gun belongs to there hardpoint()->components()->worldObject() and check+cast it to a Ship. If it is not a ship, don't check for friendlyfire.