Scripts/Misc: Fix static analysis issues

Replace CAST_AI() macro with ENSURE_AI() dynamic_cast is not supposed to return NULL.