Unify character casts, reorganize checks

Silencing clang warning by casting to int is hardly an example of the most readable code. This uses casts to `unsigned char` which make comments redundant.

Also there's no point in checking the range all the time when this can be done in a test (entities set doesn't change between runs).