Scanning For Stations
Moderator: OpenTTD Developers
Scanning For Stations
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
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
Re: Scanning For Stations
Simple: you can't. For industries you have AIIndustry::GetAmountOfStationsAround (IndustryID industry_id), but no such thing is available for towns.
Re: Scanning For Stations
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
Re: Scanning For Stations
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.
Re: Scanning For Stations
For Convoy I use this:
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)
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);
Re: Scanning For 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.GeekToo wrote:For Convoy I use this:
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)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);
Thanks,
MarkS
Re: Scanning For Stations
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 stationsreylas 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.
Re: Scanning For 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.GeekToo wrote: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 stationsreylas 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.
Thanks, that got me what I needed.
MarkS
Re: Scanning For Stations
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 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.
Re: Scanning For Stations
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.Yexo wrote: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 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.
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
Re: Scanning For Stations
Ok, so sum up how IsRoadTile works (to save you from testing ), 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.
- 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.
Re: Scanning For Stations
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
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
-
- Engineer
- Posts: 70
- Joined: 05 Jun 2008 15:51
Re: Scanning For Stations
apparently a tile with a depot on it, does not count as a road-tile, even though the graphics suggest otherwise. Appearances can be deceivingreylas 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.
Nunc dimittis servum tuum Domine secundum verbum tuum in pace
Re: Scanning For Stations
Don't look only at the graphics, but read the documentation:wilco_moerman wrote:apparently a tile with a depot on it, does not count as a road-tile, even though the graphics suggest otherwise. Appearances can be deceivingreylas 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.
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.
Who is online
Users browsing this forum: Google Adsense [Bot] and 32 guests