I think this whole mammoth, from line 2379 to here, should be moved out to a separate function in `cItem`, possibly making it available to plugins, too, but especially moving it out. It should also be possible to shrink it a bit.

I think this signature should be sufficient:
```cpp
/** Enchants the item using the specified number of XP levels.
Returns true if item enchanted, false if not. */
bool cItem::EnchantByXPLevels(int a_NumXPLevels)
```