Scanning For Stations

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
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Scanning For Stations

Post by reylas »

Question, I want to scan a town to see if competitors have already built in the town, but I have run across something funny.

I used to scan each tile, looking for a AIStation.GetStationID, then checking to see if AIStation.IsValidStation, but now I notice that IsValidStation only returns true if it is a valid station and you are the owner.

Now I am having trouble looking for stations in a town. Any advice on finding a station that isnt mine?

Thanks,
MarkS
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Scanning For Stations

Post by Yexo »

Simple: you can't. For industries you have AIIndustry::GetAmountOfStationsAround (IndustryID industry_id), but no such thing is available for towns.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Scanning For Stations

Post by reylas »

Yexo wrote:Simple: you can't. For industries you have AIIndustry::GetAmountOfStationsAround (IndustryID industry_id), but no such thing is available for towns.

So there is no way for me to avoid towns that other people have developed in? I would like to try to start in a town that no one else is in to try to get some profit before I go colliding with other players.

Ok,
Thanks,
Marks
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Scanning For Stations

Post by Yexo »

Nope, but any decent town with a high enough population generates so much passengers that your opponents won't be able to transport it all. Even if you developed this, your opponents may have build a station in the time you needed to find a route.
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: Scanning For Stations

Post by GeekToo »

For Convoy I use this:

Code: Select all

tl2.AddRectangle(AITown.GetLocation(town_it) + AIMap.GetTileIndex(-8, -8),
		 			   					  AITown.GetLocation(town_it) + AIMap.GetTileIndex(8, 8));
tl2.Valuate(AIRoad.IsRoadStationTile);
tl2.KeepValue(1);
town_it is the town under investigation, tl2 is a tilelist, if it does contain items ( tl2.Count() > 0 ) I skip the town on non-agressive setting ( i.e. trying to avoid other players stations)
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Scanning For Stations

Post by reylas »

GeekToo wrote:For Convoy I use this:

Code: Select all

tl2.AddRectangle(AITown.GetLocation(town_it) + AIMap.GetTileIndex(-8, -8),
		 			   					  AITown.GetLocation(town_it) + AIMap.GetTileIndex(8, 8));
tl2.Valuate(AIRoad.IsRoadStationTile);
tl2.KeepValue(1);
town_it is the town under investigation, tl2 is a tilelist, if it does contain items ( tl2.Count() > 0 ) I skip the town on non-agressive setting ( i.e. trying to avoid other players stations)
Does that actually work for Non-Road Station bus stations? I thought that was for finding road tiles that have drive through stations on them. I will try that tonight.

Thanks,
MarkS
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: Scanning For Stations

Post by GeekToo »

reylas wrote:
Does that actually work for Non-Road Station bus stations? I thought that was for finding road tiles that have drive through stations on them. I will try that tonight.
Don't know what you mean with non road station bus stations, but it does work for non drive though bus stations, ie normal bus stations
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Scanning For Stations

Post by reylas »

GeekToo wrote:
reylas wrote:
Does that actually work for Non-Road Station bus stations? I thought that was for finding road tiles that have drive through stations on them. I will try that tonight.
Don't know what you mean with non road station bus stations, but it does work for non drive though bus stations, ie normal bus stations
Actually, you are correct, (not that you wouldn't be) :) it did find *any* station. Which is funny, IsRoadDepotTile does not find my Depots. I need to look into that one more, it is like it did not recognise that a road depot tile has a road underneath.

Thanks, that got me what I needed.

MarkS
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Scanning For Stations

Post by Yexo »

reylas wrote:Actually, you are correct, (not that you wouldn't be) :) it did find *any* station. Which is funny, IsRoadDepotTile does not find my Depots. I need to look into that one more, it is like it did not recognise that a road depot tile has a road underneath.
If you still find that the IsRoadDepotTile does not behave as it should, please report it as a bug (either post here again or join irc).
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Scanning For Stations

Post by reylas »

Yexo wrote:
reylas wrote:Actually, you are correct, (not that you wouldn't be) :) it did find *any* station. Which is funny, IsRoadDepotTile does not find my Depots. I need to look into that one more, it is like it did not recognise that a road depot tile has a road underneath.
If you still find that the IsRoadDepotTile does not behave as it should, please report it as a bug (either post here again or join irc).
Maybe I just misunderstand how it should work. I looped through all my road tiles trying to find a depot on one of them. I used IsRoadTile to find road tiles, then I used IsRoadDepotTile if IsRoadTile came back true. IsRoadDepotTile never returned true. So for me either IsRoadTile never returned true for a tile with a Road Depot on it, or IsRoadDepotTile never returned true for a Road Depot Tile.

At the time, I assumed that IsRoadDepotTile was meant for some strange Road Depot that could be built on existing roads (like a drive through bus station). So I changed my function to work and assumed that IsRoadStationTile was for drive through bus stations as well. That is why I asked in this thread. GeekToo changed my mind on how IsRoadStationTile worked, so I wrote a test and sure enough it worked.

So, that makes me feel that IsRoadTile is not returning true for a tile with a Road Depot on it. That makes more sense than the other. I thought, since for a while we had to build the road first before we built a station, that that is how IsRoadStationTile worked, so it only made sense that IsRoadDepotTile worked the same way. But it did not.

I have a few errands to run this morning, so when I get back, I will write a test script for IsRoadDepotTile, to check my theory. Then I will file a bug report based on that. If you read this and I am wrong on how that should work, let me know. But as I said, GeekToo showed me that IsRoadDepotTile worked that way so I would assume that IsRoadDepotTile did as well.

Thanks,
MarkS
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Scanning For Stations

Post by Yexo »

Ok, so sum up how IsRoadTile works (to save you from testing :p ), it returns true on the following tiles:
- A normal road tile
- A tile with tram tracks.
- A tile with both road and trams track.
- A drive-through road stop
- A drive-through tram stop
- A combined drive-through road / tram stop

It returns false for other tiles, including:
- A normal road stop (non-drive through)
- A road depot

IsRoadDepotTile on the other hand should return true only for road depots. Note that this will also return true for road depot that are not from your company.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: Scanning For Stations

Post by reylas »

Ok, then that explains it. I assuming there was a road tile underneath since in the beginning we had to build a road in order to place a station. My road depot scanner was failing since I was checking all road tiles for a depot sitting on them. That is why I assumed IsRoadStationTile would not work either.

That pacifies me, so no bug. I will rewrite my Depot Code to find a connected Road Depot.

Oh, and the reason why I started scanning for other companies stations is this. I start my games @1930. I want my AI to be able to handle not having certain cargos and vehicles. At that time frame, there are no other vehicles beside buses. And with my 128x128 map with small cities, I am lucky if I have 2 towns with 500 people in them. It takes several years for 1 bus company to make a profit. It is almost impossible with two sharing a *home* city.

Thanks for your help.
MarkS
wilco_moerman
Engineer
Engineer
Posts: 70
Joined: 05 Jun 2008 15:51

Re: Scanning For Stations

Post by wilco_moerman »

reylas wrote: Maybe I just misunderstand how it should work. I looped through all my road tiles trying to find a depot on one of them. I used IsRoadTile to find road tiles, then I used IsRoadDepotTile if IsRoadTile came back true. IsRoadDepotTile never returned true. So for me either IsRoadTile never returned true for a tile with a Road Depot on it, or IsRoadDepotTile never returned true for a Road Depot Tile.
apparently a tile with a depot on it, does not count as a road-tile, even though the graphics suggest otherwise. Appearances can be deceiving :)
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Scanning For Stations

Post by Yexo »

wilco_moerman wrote:
reylas wrote: Maybe I just misunderstand how it should work. I looped through all my road tiles trying to find a depot on one of them. I used IsRoadTile to find road tiles, then I used IsRoadDepotTile if IsRoadTile came back true. IsRoadDepotTile never returned true. So for me either IsRoadTile never returned true for a tile with a Road Depot on it, or IsRoadDepotTile never returned true for a Road Depot Tile.
apparently a tile with a depot on it, does not count as a road-tile, even though the graphics suggest otherwise. Appearances can be deceiving :)
Don't look only at the graphics, but read the documentation:
static bool AIRoad::IsRoadTile ( TileIndex tile ) [static]

Checks whether the given tile is actually a tile with road that can be used to traverse a tile.

This excludes road depots and 'normal' road stations, but includes drive through stations.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Google Adsense [Bot] and 32 guests