Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Jan 16, 2019 11:22 am

All times are UTC




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Patch] all_ais commands
PostPosted: Tue Nov 16, 2010 12:08 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Feb 15, 2003 5:32 pm
Posts: 1139
Location: Paris, France
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)


Attachments:
cmd_all_ais_r21200.patch [3.65 KiB]
Downloaded 86 times
Top
   
PostPosted: Tue Nov 16, 2010 4:08 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Thu Jun 25, 2009 4:42 pm
Posts: 2365
Location: Location, Location
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

_________________
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


Top
   
PostPosted: Tue Nov 16, 2010 6:04 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Feb 15, 2003 5:32 pm
Posts: 1139
Location: Paris, France
Ok for the argument, i'll try to change it.

I agree with "xxx_all_ai" without the "s".


Top
   
PostPosted: Tue Nov 16, 2010 6:24 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Feb 15, 2003 5:32 pm
Posts: 1139
Location: Paris, France
Here is the update.

But I have a problem with some "magic code" :

Code:
   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.


Attachments:
cmd_all_ai_r21211.patch [4.36 KiB]
Downloaded 82 times
Top
   
PostPosted: Wed Nov 17, 2010 7:37 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Feb 15, 2003 5:32 pm
Posts: 1139
Location: Paris, France
Here is an update.

Quote:
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:
   /* 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 82 times
Top
   
PostPosted: Wed Nov 17, 2010 8:38 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Thu Jun 25, 2009 4:42 pm
Posts: 2365
Location: Location, Location
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 :lol: )

_________________
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


Top
   
PostPosted: Wed Nov 17, 2010 9:35 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Feb 15, 2003 5:32 pm
Posts: 1139
Location: Paris, France
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 <


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: BeSt-Com, Google Adsense [Bot], JGR and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.