Slopes

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

Slopes

Post by reylas »

I am having slope problems and was wondering if anyone would look at what I have and see if they can explain it. I was trying to build a bus station and connecting road but was not getting the bus station oriented in the correct direction. Basically, I look for a build-able tile next to a road tile then level it if need be then build a station. This tile happens to have two neighbor road tiles, but cannot build a road. If you look at the screenshot at the tile with a sign with a minus after it, that is the tile I am trying to build on. The first number of the sign represents a slope, while the second represents the height.

So I figured, no problem, just check the slope and height to check for a road on my level. But when I tried, I never could get it to work. So I wrote a little function to build signs to help me out. What I found was that the slopes and heights do not really match what the graphics were showing.

For instance. To the SE of the - tile, it shows a slope of 2, height of 5. So it thinks the height is the same as my station (-) tile. But the tile to the south of my tile shows a slope of 4 and a height of 5 as well. But the foundation clearly shows it sloping to the west. But the next tile shows a slope of 0 and a height of 5. So two tiles with a slope of 2 and 4 slope to a tile that is level with a height the same as it is. If you look at the two houses to the SW of my tile (-), they show slopes, but non matching heights. Plus the road to the south of my tile clearly shows a graphic for a sloping road. But the road ends up with the same height on both ends of the slope, but the tile to the SW of my (-) tile shows the same height, but is sloped?

Does that make any sense? Or am I looking at it wrong. I am trying to figure out how to not build if the road tile cannot be connected to, but with the slopes not matching and the heights the same, I cannot figure it out.

Sorry to be so winded.

MarkS
Attachments
Unnamed, 24th Jan 1934.png
Screenshot showing bad slopes.
(545.17 KiB) Downloaded 115 times
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Here is the same town without signs. That way you can compare the spot I want to build with the road to it's SE. They should be the same, but they are not. But drive down the little hill, and you are at the same level as the spot I want to build.

MarkS
Attachments
Mendingtown Transport, 3rd Feb 1934.png
(560.55 KiB) Downloaded 63 times
User avatar
YukonRob
Transport Coordinator
Transport Coordinator
Posts: 290
Joined: 31 Jul 2007 00:58
Location: North of 63

Re: NoAI Branch - An AI Framework

Post by YukonRob »

I think you are being confused by the foundations. It looks like the slope/height are returning the original ground values before foundations are built, try removing the road, buildings etc. in the photo and then compare the heights to the terrain.
HTH,
Rob
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: NoAI Branch - An AI Framework

Post by Roujin »

Don't know if that helps you, but afaik the height is the height of the northern corner of the tile.

So to get proper information of a tile "A", i'd get the tileheight of A, A+(0,1), A+(1,0) and A+(1,1).
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

reylas wrote:I am having slope problems and was wondering if anyone would look at what I have and see if they can explain it. I was trying to build a bus station and connecting road but was not getting the bus station oriented in the correct direction. Basically, I look for a build-able tile next to a road tile then level it if need be then build a station. This tile happens to have two neighbor road tiles, but cannot build a road. If you look at the screenshot at the tile with a sign with a minus after it, that is the tile I am trying to build on. The first number of the sign represents a slope, while the second represents the height.

So I figured, no problem, just check the slope and height to check for a road on my level. But when I tried, I never could get it to work. So I wrote a little function to build signs to help me out. What I found was that the slopes and heights do not really match what the graphics were showing.

For instance. To the SE of the - tile, it shows a slope of 2, height of 5. So it thinks the height is the same as my station (-) tile. But the tile to the south of my tile shows a slope of 4 and a height of 5 as well. But the foundation clearly shows it sloping to the west. But the next tile shows a slope of 0 and a height of 5. So two tiles with a slope of 2 and 4 slope to a tile that is level with a height the same as it is. If you look at the two houses to the SW of my tile (-), they show slopes, but non matching heights. Plus the road to the south of my tile clearly shows a graphic for a sloping road. But the road ends up with the same height on both ends of the slope, but the tile to the SW of my (-) tile shows the same height, but is sloped?

Does that make any sense? Or am I looking at it wrong. I am trying to figure out how to not build if the road tile cannot be connected to, but with the slopes not matching and the heights the same, I cannot figure it out.

Sorry to be so winded.

MarkS
As far as I can tell from the screenshot both the tile you want to build the stop on and the road are flat, and both the same height, so slopes shouldn't be an issue.

Make sure you build the road from the tile you want the bus stop on, to the road, then build the bus stop.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

[quote="Ralph]
As far as I can tell from the screenshot both the tile you want to build the stop on and the road are flat, and both the same height, so slopes shouldn't be an issue.

Make sure you build the road from the tile you want the bus stop on, to the road, then build the bus stop.[/quote]


That is the problem.. It codes like it should work, but it looks like it wont. And it does not. I cannot build a road there.

MarkS.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Roujin wrote:Don't know if that helps you, but afaik the height is the height of the northern corner of the tile.

So to get proper information of a tile "A", i'd get the tileheight of A, A+(0,1), A+(1,0) and A+(1,1).
Ok, that helps A LOT, that is good information to know. But, it still does not make sense. Another example. If you look at the tile directly below the tile I want to build, it has a sign of 4,5. Meaning Slope_E, height of 5. But the tile to the SW of that, (turn in the road) has a slope of 0 meaning flat, but a height of 5. The wiki states that Slope_E would mean that the east point of the tile would be the highest spot on that tile. But it is the *same* height as the one with the turn in the road. So in order for the road to have been built, should the tile not have a slope of 12? 12 would mean N and E which would match the road incline.

Plus the tile I want to connect to (2,5) has a slope of 2 or Slope_S. meaning it slopes up to the southern point, which means it's Southern tip is higher than its western tip. So how could that road be there if that is the case?

Or am I not understanding the numbers?

Sorry to be a bother, I really am enjoying making AI's

Marks
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

reylas wrote:[
Try your Building operation then check for an error with AILog.Info(AIError.GetLastErrorString())

maybe something there.
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: NoAI Branch - An AI Framework

Post by Zutty »

As Roujin pointed out, the height of a tile is measured at the north corner. If your AI is trying to connect to the road to the SE then it SHOULD fail as the road on that tile is raised on foundations. You can get the selection routine to discount this tile if you consider two things. A) The direction of the road on that tile, and B) The direction of the slope on that tile. When considering whether or not a road can connect to any adjacent road, the slopes are more important than the tile height.

Since the slope has just one corner raised then the road on it could go in either direction. If the road was facing towards the proposed bus station tile then that site WOULD be valid, but because the road is facing in the other direction then the bus station faces the foundation and can't connect to the road.

In general terms...
- A road on a slope can face either N-S or E-W. Because of the way tiles fit together this is all we need to know.
- If the road on a slope is moving parallel to the proposed station tile then discount it.
- If the road on a slope is moving towards/away from the proposed station tile then consider it
- - On a slope with two corners raised the road can only go in the direction of the slope on the tile, so test that (easier!).
- - On a slope with one corner raised the road can go either way so we must test the road itself (need to query adjacent road tiles).

I hope that makes sense.
PathZilla - A networking AI - Now with tram support.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Zutty wrote:As Roujin pointed out, the height of a tile is measured at the north corner. If your AI is trying to connect to the road to the SE then it SHOULD fail as the road on that tile is raised on foundations. You can get the selection routine to discount this tile if you consider two things. A) The direction of the road on that tile, and B) The direction of the slope on that tile. When considering whether or not a road can connect to any adjacent road, the slopes are more important than the tile height.

Since the slope has just one corner raised then the road on it could go in either direction. If the road was facing towards the proposed bus station tile then that site WOULD be valid, but because the road is facing in the other direction then the bus station faces the foundation and can't connect to the road.

In general terms...
- A road on a slope can face either N-S or E-W. Because of the way tiles fit together this is all we need to know.
- If the road on a slope is moving parallel to the proposed station tile then discount it.
- If the road on a slope is moving towards/away from the proposed station tile then consider it
- - On a slope with two corners raised the road can only go in the direction of the slope on the tile, so test that (easier!).
- - On a slope with one corner raised the road can go either way so we must test the road itself (need to query adjacent road tiles).

I hope that makes sense.
I understand what you are saying, I just can't see how my situation matches it. Either the height of the two tiles or the slope of the road tile does not jive. Talking about only two tiles there, (0,5 -) and the (2,5) to the southeast of it, They both have the same height, and their shared border is level (only slope is a two which is south on the road tile).

A. There seems to be a foundation there that does not make sense.
B. If the slope is to the South, meaning the southern point is higher, then how can the road be there anyway?
C. Since my tile is perfectly level, and the tile I want to connect to is the same height with only a slope on the southern point, how come I cannot build there? The road seems to me should not be there.

Also, if you look to the north east, you will see a slope of 27. Is that possible?

I understand that it is a half road on that tile, but the road is in the slope, that would imply that the west point must be sloped as well correct?

MarkS.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Ok, one more question. So does that mean a road, house, or tree tile does not have to be level? So if a house is there, then the house may be level ( as shown by the foundations) but the underlying tile is still sloped?

If that is the case, then that changes A LOT. I could see that with houses, but would a road not have to level the tile underneath (or at least the section covered by a road?

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

Re: NoAI Branch - An AI Framework

Post by Yexo »

reylas wrote:Ok, one more question. So does that mean a road, house, or tree tile does not have to be level? So if a house is there, then the house may be level ( as shown by the foundations) but the underlying tile is still sloped?

If that is the case, then that changes A LOT. I could see that with houses, but would a road not have to level the tile underneath (or at least the section covered by a road?

MarkS.
That is indeed the case. Every occasion you see foundations, the underlying tile isn't flat. This is the same with houses and roads. So even if a road seems to be flat, the tile underneed need not also be flat.
reylas
Engineer
Engineer
Posts: 52
Joined: 22 Dec 2007 01:04

Re: NoAI Branch - An AI Framework

Post by reylas »

Yexo wrote:
reylas wrote:Ok, one more question. So does that mean a road, house, or tree tile does not have to be level? So if a house is there, then the house may be level ( as shown by the foundations) but the underlying tile is still sloped?

If that is the case, then that changes A LOT. I could see that with houses, but would a road not have to level the tile underneath (or at least the section covered by a road?

MarkS.
That is indeed the case. Every occasion you see foundations, the underlying tile isn't flat. This is the same with houses and roads. So even if a road seems to be flat, the tile underneed need not also be flat.
Ok, so is there anyway to tell if a tile has a foundation on it? According to the slope of the tile, I should be able to build, but I cannot. In code the only way I can tell I cannot build is to build and then fail. That is tough since I really need to build to the north east but my program found the south east tile first. There has to be some way of seeing before hand that that tile is not connectable by slope. A pathfinder will need that.

MarkS
User avatar
Ralph
Engineer
Engineer
Posts: 87
Joined: 21 Jun 2004 15:25

Re: NoAI Branch - An AI Framework

Post by Ralph »

reylas wrote:
Ok, so is there anyway to tell if a tile has a foundation on it? According to the slope of the tile, I should be able to build, but I cannot. In code the only way I can tell I cannot build is to build and then fail. That is tough since I really need to build to the north east but my program found the south east tile first. There has to be some way of seeing before hand that that tile is not connectable by slope. A pathfinder will need that.

MarkS
For houses: Not that I can think of.
For Roads: Get the slope, and check which adjacent tiles it is connected to with AreRoadTilesConnected, then combine the information to determine if that road layout on that slope would require foundations (look for road running, parallel to the slope, etc), roads and slopes are not a trivial problem, it took me much trail and error to get it right.
Finaldeath
Engineer
Engineer
Posts: 72
Joined: 09 Apr 2006 23:49
Location: UK
Contact:

Re: NoAI Branch - An AI Framework

Post by Finaldeath »

Yeah, I am going to have fun on slopes once I get around to it. Will add info to the wiki once I get some code going.

Considering this very very important information, can the API be updated to reflect it?

Needs a comment like "The exact height of a tile returned is the northern corner point of a tile, the slope directions must be used to check weather a flat building will be on this level exactly or +/- 1 of this level height." or something. I think. I am not sure, but I guess actually it will only ever be up to 1 higher (a north point being lower then any of the rest).

Perhaps some function to return the highest point of all 4 corners would remove the unnecessary need to check every corner, and it's slope type, just to get the highest point, since for simple applications like "Build a bus depot" you only need the highest height to check against nearby roads to see if it connects etc. GetHighestHeight() perhaps.

Only a quick idea, it might be that the actual code to get the highest point is easier then I imagine. I'm mainly working on water AI right now ;)
Finaldeath
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 33 guests