Refactor inventory, improve item reference validity, fix #503

Refactor the inventory class to use std::lists rather than std::vectors.

Make it so that sorting and restacking an inventory does not require item creation/deletion, hence making item references valid for a longer amount of time.

Close #503, thanks to item references being valid now.

I would like to remove as many index-taking methods as I can, but ran into some difficulties due to the way the inventory UI code is written.