Page 1 of 1
[Patch] all_ais commands
Posted: 16 Nov 2010 12:08
by MagicBuzz
Hello,
According the
FS#4216, I designed a small patch that introduce three new console commands in order to manage all AIs at the same time.
start_all_ais
stop_all_ais
reload_all_ais
Those three commands haven't arguments.
start_all_ais starts any unstarted AI (will start the same number of AI that the competitors parameter)
stop_all_ais stops any running AI.
reload_all_ais stops then starts any running AI. This doesn't impact non-running AIs.
-- Edit : Fixed a warning when compiling (uint and int comparision)
Re: [Patch] all_ais commands
Posted: 16 Nov 2010 16:08
by Lord Aro
Nice!
I haven't tested it yet, but i think the staet_all_ais should have an argument of whether to start as many as the player has specified (in difficulty settings) or total possible ais (14)
Another thought, perhaps they would be better named ###_all_ai as for me, ais doesn't look right in lower case
Re: [Patch] all_ais commands
Posted: 16 Nov 2010 18:04
by MagicBuzz
Ok for the argument, i'll try to change it.
I agree with "xxx_all_ai" without the "s".
Re: [Patch] all_ais commands
Posted: 16 Nov 2010 18:24
by MagicBuzz
Here is the update.
But I have a problem with some "magic code" :
Code: Select all
FOR_ALL_COMPANIES(c) {
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.
Re: [Patch] all_ais commands
Posted: 17 Nov 2010 07:37
by MagicBuzz
Here is an update.
Change:
- Renamed start_all_ais by start_all_ai
- Renamed stop_all_ais by stop_all_ai
- Renamed reload_all_ais by reload_all_ai
=> AIs in lower case doesn't look natural
Added Feature:
- start_all_ai now supports an argument <AI count>. It's the desired total AI count.
Fix:
- start_all_ai now doesn't start more AIs than desired. IE when already running AIs, it will start <AI count> - <Already running AIs> new AIs.
In order to properly count the already running AIs, I replaced the previous FOR loop with magical code with some cleaner and humanproof code.
Code: Select all
/* Total AI to start is total_ai_count - current running AIs count */
int new_ai_count = total_ai_count;
Company *c;
FOR_ALL_COMPANIES(c) {
if (Company::IsValidAiID(c->index)) {
new_ai_count--;
}
}
[...]
/* Start the desired AIs */
for (int i = 0; i < new_ai_count; i++) {
DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
}
Re: [Patch] all_ais commands
Posted: 17 Nov 2010 08:38
by Lord Aro
Lookin good!
Two things occur to me:
1. Are the commands like others, in that you can also use 'startallai', without the underscores
2. In the for loop that starts the AIs, shouldn't it be 'i <= ####' (can't remember the variable name

)
Re: [Patch] all_ais commands
Posted: 17 Nov 2010 09:35
by MagicBuzz
1/ I didn't know that. Anyway, I tested and "startallai", "stopallai" and "reloadallai" are working
2/ the for loop may stop at <= ### if it was starting at 1, but it starts at 0, so the condition is well <