Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sun May 19, 2013 8:07 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sun Apr 03, 2011 9:45 pm 
Offline
Engineer
Engineer

Joined: Sun Apr 03, 2011 9:38 pm
Posts: 4
Hej guys,

i started to write an AI on my own.
I simply started with a Car Depot building. But my AI doesn't build it.
Here is the Code.

Code:
 function TestAI::BuildSomething()
 {
   local firstTile = AIMap.GetTileIndex(2,2);
   local secondTile = AIMap.GetTileIndex(2,3);
   
   AIRoad.BuildRoadDepot(firstTile, secondTile);   
 }


I wonder why this won't work?! The terrain is flat and buildable. If I change the depot build command to the HQ build command, the AI will build its home. But neither depot nor road.
:?

Thanks for help.


Top
 Profile  
 
PostPosted: Sun Apr 03, 2011 9:57 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
When anything related to building on the map, buying vehicles, changes orders etc. doesn't work try to find out why first. The easiest way you can do that is by printing the error message to the AI debug log. You can do that like this:
Code:
AILog.Error(AIError.GetLastErrorString());


Before building anything related to roads you must first call AIRoad::SetCurrentRoadType


Top
 Profile  
 
PostPosted: Sun Apr 03, 2011 10:05 pm 
Offline
Engineer
Engineer

Joined: Sun Apr 03, 2011 9:38 pm
Posts: 4
Thanks for the clue! :)
The road type was missing.

:bow:


Top
 Profile  
 
PostPosted: Sun Apr 03, 2011 10:33 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 3986
Location: /home/sweden
Also IIRC you have to call AIController.Sleep(1); before doing the first action (DoCommand) as the first tick doesn't allow any actions/DoCommands.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
 Profile  
 
PostPosted: Tue Apr 05, 2011 10:26 pm 
Offline
Engineer
Engineer

Joined: Sun Apr 03, 2011 9:38 pm
Posts: 4
Hej,
I've got a new Problem :D
These Enumerators are really confusing.

Code:
aSlope = AITile.GetSlope(aTile);

(Enumerators of Slops)
So far. So good. But what is now inside "aSlope"? There is a number. But I don't know what to do with it. When I've got a SLOPE_NW on my screen, it returns number 9?! :?


Top
 Profile  
 
PostPosted: Tue Apr 05, 2011 10:30 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
It's actually a bitmask.

SLOPE_NW = SLOPE_N | SLOPE_W;


Top
 Profile  
 
PostPosted: Fri Apr 08, 2011 7:14 pm 
Offline
Engineer
Engineer

Joined: Sun Apr 03, 2011 9:38 pm
Posts: 4
Thanks for your fast reply. It helped me a lot!

Another question: Why are these two lines the same:
(both are initiated with local tileList = AITileList(); )
Code:
tileList.AddRectangle(start, end);

Code:
tileList.AddRectangle(end, start);

Both lists start with the end tile?!?!


Top
 Profile  
 
PostPosted: Fri Apr 08, 2011 7:55 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
If you want to sort the list you have to use the AIList.Sort() function. By default lists are sorted ascending by item.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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-2013 phpBB Group

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