[Patch] all_ais commands
Moderator: OpenTTD Developers
[Patch] all_ais commands
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)
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)
- Attachments
-
- cmd_all_ais_r21200.patch
- (3.65 KiB) Downloaded 174 times
Re: [Patch] all_ais commands
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
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
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: [Patch] all_ais commands
Ok for the argument, i'll try to change it.
I agree with "xxx_all_ai" without the "s".
I agree with "xxx_all_ai" without the "s".
Re: [Patch] all_ais commands
Here is the update.
But I have a problem with some "magic code" :
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.
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);
}
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.
- Attachments
-
- cmd_all_ai_r21211.patch
- (4.36 KiB) Downloaded 166 times
Re: [Patch] all_ais commands
Here is an update.
In order to properly count the already running AIs, I replaced the previous FOR loop with magical code with some cleaner and humanproof code.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.
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);
}
- Attachments
-
- cmd_all_ai_r21218.patch
- (4.85 KiB) Downloaded 168 times
Re: [Patch] all_ais commands
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 )
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 )
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Re: [Patch] all_ais commands
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 <
2/ the for loop may stop at <= ### if it was starting at 1, but it starts at 0, so the condition is well <
Who is online
Users browsing this forum: No registered users and 45 guests