Avoid out-of-bounds read

There's only defTeamColorCount colors stored in the array; make sure the
index is within that range.
Remove UB (++x %= y)

A construct like ++x %= y assigns to x twice between sequence points.
Introduce a sequence point here to make the behavior well-defined.