Quick suggestion (didn't examine things in detail): instead of looking for a free dot by going through everything, hold a stack for free dots.
I.e. push onto the stack when you do:
m_colour[i] = 0;
And when you need one, pop.
More fireworks (long source code included)