AIStation.GetLocation

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:

AIStation.GetLocation

Post by Kev! »

Howdy,

It's me again. You guys are great, so I am back with another question....

I get a station id from AIStationList(AIStation.STATION_AIRPORT)...but when I AIStation.GetLocation() on it...I get the location of the attached bus station... ?( Is there an easy way to get the top tile of the airport? Cuz I need to upgrade it. Some non brute force method?

Please advise,
Kev!

P.S. Today is the anniversary of my birth, so be nice to me? :roll:
I DO like a nice caboose...
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: AIStation.GetLocation

Post by krinn »

- grab tiles around your station
- valuate them with AIStation.GetStationID
- KeepValue(yourstationid) // if you follow the logic, now you have all tiles that belong to your stationid
- Valuate(AIStation.HasStationType,AIStation.ROADTYPE_ROAD)
- RemoveValue(1);
- Sort(AIList.SORT_BY_VALUE,false);
- first tile is at Begin()


I don't know if we have an easier way, but it's pretty simple like that already.
Happy birthday
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Re: AIStation.GetLocation

Post by Kev! »

Howdy,

So if I sort a list of tiles the first one is always top left?

I had tried this...

function TopTile(s,stype)
{
local tlist = AITileList_StationType(s, stype);

tlist.Valuate(AIMap.GetTileX);
tlist.Sort(AIList.SORT_BY_VALUE, true);
tlist.KeepValue(tlist.GetValue(tlist.Begin()));
tlist.Valuate(AIMap.GetTileY);
tlist.Sort(AIList.SORT_BY_VALUE, true);
tlist.KeepValue(tlist.GetValue(tlist.Begin()));

return tlist.Begin();
}


but yours looks better!

function TopTile(s,stype)
{
local tlist = AITileList_StationType(s, stype);

tlist.Sort(AIList.SORT_BY_VALUE, false);

return tlist.Begin();
}

Thanks!

Kev!
I DO like a nice caboose...
User avatar
Kev!
Engineer
Engineer
Posts: 37
Joined: 21 Jun 2011 16:30
Location: In Da House!
Contact:

Re: AIStation.GetLocation

Post by Kev! »

Howdy,


uh....I had to use true...If anyone is interested...

tlist.Sort(AIList.SORT_BY_VALUE, true);


Kev!
I DO like a nice caboose...
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: AIStation.GetLocation

Post by planetmaker »

Often undervalued, but I truely appreciate that you post the solution also and especially when you found it yourself :-) - others still might profit from it :-)
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: AIStation.GetLocation

Post by krinn »

good you sort it out, sorry for the mistake.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: AIStation.GetLocation

Post by Zuu »

I have a function for this: SuperLib.Airport.GetAirportTile(station_id)

Basically the same implementation as already mentioned. I just mention it if you are interested in the SuperLib library.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests