Fix a loop closure bug in the weapons code.

Fixes #6597. Fixes #6599.
Minor style fixes.
Merge pull request #6612 from pchote/fix-warheads

Fix a loop closure bug in the weapons code.