Tile Ownership(ai builds station adjacent to other players)

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Tile Ownership(ai builds station adjacent to other players)

Post by Kev! »

Howdy,

You guys helped me out a while back, so here I am like a bad penny.

My ai builds road stations adjacent to other players existing stations with the entrance blocked. How can I determine if there is someone elses station at the tile where my entrance will be?

Thanks in advance,
Kev! ?(
I DO like a nice caboose...
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Tile Ownership(ai builds station adjacent to other playe

Post by Zuu »

When you build a road station, you have to specify the front tile. In case of a drive through stop, you may be interested to also identify the back tile, which is possible as you have the stop tile and the front tile and know that the back tile is at the opposite side of the front tile.

You can check if it is possible to build a road from front_tile to stop_tile. Another option is to check the ownership of front_tile. There is also AITile.IsStationTile which you can use to specifically check for existence of stations.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Re: Tile Ownership(ai builds station adjacent to other playe

Post by Kev! »

Howdy,

Thank you, Zuu, for your response. Could you clarify?

IsStationTile is good.

Do you mean to use AreRoadTilesConnected or CanBuildConnectedRoadPartsHere to check if it is possible to build a road to my stop?

what is the method to check the ownership of the tile?

Thanks s much,
Kev!
I DO like a nice caboose...
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Tile Ownership(ai builds station adjacent to other playe

Post by Zuu »

Kev! wrote:what is the method to check the ownership of the tile?
AITile.GetOwner

Kev! wrote:Do you mean to use AreRoadTilesConnected or CanBuildConnectedRoadPartsHere to check if it is possible to build a road to my stop?
Which one to use depend on if there is a road yet or not. Do you want to detect the block before it happens, or after it has happened? (or possible both - but then you might need to implement them at separate segments of your code and for each segment you are only doing one thing)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: Tile Ownership(ai builds station adjacent to other playe

Post by krinn »

Because how you wish implement that in your AI it would be hard to answer your question, per example, you didn't tell us if building a station near another one is a wanted feature or an unexpected/unlucky one and problematic for you.

- If building next to a station isn't a problem, you don't really have to check if it's a station or not, but if the tile is usable : it depend again on what you wish your AI to be able to do :
* i need a road, any : so just test if it's a road in front
* i need a road, but i must own it : test if it's a road and owner
* i need a place where i could build a road : then test if it's buildable
* i need a place where i will be able to build a road : it's the hardest part, a water tile won't be buildable as-is, but with investing money, it would. The heuristic to find what conditions you find acceptable for your AI is the key.

- If building next to a station is a problem, IsStationTile is enough to answer you, see my loop at line 159 : http://dev.openttdcoop.org/projects/ai- ... uilder.nut and "voisin" is french for neighbor

- If building next to a station you own isn't a problem (to extend a previous station per example), then you need to detect the station, the ownership of the station and that station ID too.
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Re: Tile Ownership(ai builds station adjacent to other playe

Post by Kev! »

Howdy,

Thank you both for your input.

I can't believe i missed AITile.GetOwner...duh! :oops:

AITile.IsStationTile is the easiest for my situation.


Thanks again,
Kev!
I DO like a nice caboose...
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 20 guests