Here is the update.
But I have a problem with some "magic code" :
if (n >= max) break;
if (c->index > n++) continue;
/* Start a new AI company */
DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
If max = 4 and there is already 2 AI competitor, then the computer will start 4 new competitors instead of 2 new.
I can't figure out why it does this. In fact, I don't understand what c->index is.
I thought it was 0 if no AI was controlling the company (empty slot) and N if an AI control it (with N = the position in the companies array). But it looks like I'm wrong.
It produces another bug : when no parameter is set, the typing several times "start_all_ai" will start 14 AIs, as it doesn't take care of the currently running AIs.