CleverRaven/Cataclysm-DDA — pull request #8710 by BevapDin (2014-08-26 21:38:18+00:00)
Title: NPC: don't add charges to the starting weapon when it has no valid default ammo

Fixes #8653 - the cause for the crash is fixed, but the existing save does still crash. One has to remove the offending npc from the overmap file (`o.0.0`).

Cause for the crash is that the starting weapon of the npc is loaded with its default ammo, but this specific npc got a LACP laser pistol, which uses UPS charges. The previous code in `npc::starting_weapon` sets `item::charges` to `it_gun::clip` (full magazine) and sets up `item::curammo` to the default ammo of that ammo type.

The UPS ammo type does not have a default ammo and `item::curammo` ends up being NULL. This leads to a crash in `item::weight()` where it is assumed that if the item is a gun and has charges, it must have a valid `curammo`.

The same assumption is made elsewhere (adding a check in `item::weight` leads to some debug messages (`npc::confident_range`) and another crash when the npc tries to fire its gun). Therefor I just fixed the base cause of the bug.