check dynamic casts for null

This probably isn't an issue, but it was spotted by coverity
and its easy to fixup. Who knows, someone might have accidentally
broken this in the future somehow.
fix a bug which could cause the terrain_builder to crash

The terrain builder logic assumes that the min_types list is
empty whenever the min_constraint pointer is null, and based on
this, dereferences the pointer. However, in subsequent passes of
the outer loop the pointer is initialized to null while the list
is not cleared. According to coverity this can actually cause
a null pointer dereference in explicit cases.

We fix it by explicitly re-initializing the list on each pass.