Converts most map->grid accesses to wrapper functions.

This'll make it easier to scale this up to 3d, and also to change the way submaps are stored and accessed.

Preliminary work for #6818 

Note that I've made sure to use the const qualifier on the submap pointers to ensure we don't unnecessarily lose performance on these accesses. This way, it should in theory be at least as fast as the array lookups.