Page 1 of 7

Freeform map edges (in trunk since 15190)

Posted: 11 Dec 2008 20:38
by Yexo
The attached patch removes the need for the map edges to be water. You can raise the land / build on it what you want.

No known issues

If you have any suggestions / comments, please let me know.

Latest patch can be downloaded from http://bugs.openttd.org/task/2541

Edit: Fixed a lot of asserts that could happen when you let a train run towards a map edge. Also the map generator is updated so it generates landscapes with land at the borders now. Attached is a screenshot that show how it works and a windows binary.

Changes in r14668_v2:
- Incorporated SmatZ changes to fix the graphical glitch at the southern borders
- Fixed a bug where terragenesis could generate tiles with a height difference of 2 between two neighbouring corners.
- Added a gui option in the map generation window to choose what borders should be water and what borders should be land.
The binary is now v2, the zip still has the same name though.

Changes in r14675_v3:
- When loading a heightmap the border now depends on the heightmap instead of always water.
- Lighthouses are only build near water
- Stations can now be built at tile 0 without errors.
- Loading old (TTD) savegames was broken, now fixed again (thanks SmatZ)

Changes in r14677_v4:
- It was impossible to terraform south-border tiles in the scenario editor
- The white dot drawn when terraforming is now drawn at the correct height for the south-border tiles.

Changes in r14677_v5:
- Lots of bugfixes of bugs reported by Progman, see http://www.tt-forums.net/viewtopic.php?p=751289#p751289 for a complete list.
- Flat tiles at the map edge with height = 0 will get flooded (to prevent maps without any water at all).

Changes in r14577_v6:
- Removed a lot of IsValidTile checks and make GetTileType return MP_VOID for tiles > MapSize()

Changes in r14685_v7:
- Fixed segfault with fences on nw border.

Changes in r14772_v8:
- Tiles at the north edges will be MP_VOID when the patch is enabled.
- Removed lots of IsValidTile calls due to the previous change.
- New patch setting (under construction) to enable/disable terraforming the map edges.
- Known issue: small graphical glitch at the north edges.
- Removed the GetTileType hack introduced in v6.

Changes in r14840_v9:
- Enabling the setting in a running game would fail most of the time.

Changes in r14840_v10:
- Fix the graphical glitch at the north edges (SmatZ)
- A bit of cleanup (removing some unneeded IsValidTile checks)

See http://www.tt-forums.net/viewtopic.php?p=754862#p754862 for the latest patch (some fixes by SmatZ) and a windows/linux binary.
Changes:
- Fix an issue were you couldn't select tiles at the north border if they were raised more than a few height levels.
- Fix a crash if rails tiles went towards an edge of the map (introduced in v10).

Changes in v12:
- MP_VOID tiles could be seen as land for newgrf files (see r14415). (thanks SmatZ)

Changes in v13:
Update to r14905
minor cleanup

Re: Freeform map edges

Posted: 11 Dec 2008 21:15
by CommanderZ
Oh, this is great! Going to try it once I have some time. Did you modify the map generator too?

Re: Freeform map edges

Posted: 11 Dec 2008 21:24
by Yexo
I've not yet modified the map generator, but I'll definitely do that (if you don't do so first :p)

Re: Freeform map edges

Posted: 12 Dec 2008 11:57
by CommanderZ
Yexo wrote:I've not yet modified the map generator, but I'll definitely do that (if you don't do so first :p)
If you want me to... :P

For TGen it is a little change in tgp.cpp...if I recall it well, all you have to do is commenting one or two function calls in terrain normalization function (it is called normalizeHeightmap or something like that).

Re: Freeform map edges

Posted: 13 Dec 2008 00:59
by Yexo
Patch updated. I've modified to the map generator, see http://www.tt-forums.net/download/file.php?id=102995

I've attached a windows binary to the first post.

Re: Freeform map edges

Posted: 13 Dec 2008 11:15
by CommanderZ
Beautiful. OTTD terrain posibilities are now really leaping forward.

What about adding a select box into the map generator taht would activate this?

Re: Freeform map edges

Posted: 13 Dec 2008 11:18
by Hyronymus
Very nice, someone finally did it :).

Re: Freeform map edges

Posted: 13 Dec 2008 11:38
by Zephyris
How well bug tested is this? I thought some algorithms required a sea level edge square to prevent wraparound, or is there a special invisible square for this?

Re: Freeform map edges

Posted: 13 Dec 2008 12:03
by Roujin
IIRC on the bottom left and bottom right edges, there's a row of invisible tiles, but not on the top left and top right edge.

Re: Freeform map edges

Posted: 13 Dec 2008 12:12
by Zephyris
Ah cool, should be ok then...

Re: Freeform map edges

Posted: 13 Dec 2008 12:22
by Terkhen
Yexo wrote:- You'll get graphical glitches if you raise any tiles at the south-east or south-west edge of the map. If there is anyone with an idea of how to solve this, be my guest. I don't know where to start :(
I have tried the patch with the water edges grf, and it seems that there's a not drawn slope between the map tiles and the usually invisible edge tiles. Here's a screenshot:

Re: Freeform map edges

Posted: 13 Dec 2008 12:29
by CommanderZ
I'm not really sure what the patch is supposed to do with the grf :)

Re: Freeform map edges

Posted: 13 Dec 2008 12:30
by SmatZ
Hello,

I like this patch :) Though it doesn't compile for me: (gcc 4.3.2, amd64)

Warnings:

Code: Select all

src/ai/default/default.cpp: In function 'void AiStateRemoveStation(Company*)':
src/ai/default/default.cpp:3677: warning: 'tile' may be used uninitialized in this function

src/terraform_cmd.cpp: In function 'CommandCost TerraformTileHeight(TerraformerState*, TileIndex, int)':
src/terraform_cmd.cpp:192: warning: comparison between signed and unsigned integer expressions
src/terraform_cmd.cpp:193: warning: comparison between signed and unsigned integer expressions
Errors:

Code: Select all

src/roadveh_cmd.cpp: In function 'Trackdir RoadFindPathToDest(Vehicle*, TileIndex, DiagDirection)':
src/roadveh_cmd.cpp:1196: error: jump to label 'found_best_track'
src/roadveh_cmd.cpp:1042: error:   from here
src/roadveh_cmd.cpp:1047: error:   crosses initialization of 'TrackdirBits trackdirs'
src/roadveh_cmd.cpp:1046: error:   crosses initialization of 'TrackdirBits red_signals'
src/roadveh_cmd.cpp:1045: error:   crosses initialization of 'TrackStatus ts'
edit: fixing that error is quite easy :)

Re: Freeform map edges

Posted: 13 Dec 2008 12:43
by SmatZ
Attached patch fixes compilation for me and probably makes those glitches disappear ;)

(maybe a hack, maybe not working. further issue may be not marking border tiles dirty, if this patch doesn't fix all cases )

edit: fixed one case
It doesn't look good when non-black void tiles are used... maybe SPR_SHADOW_CELL could be replaced by different sprite.

Re: Freeform map edges

Posted: 13 Dec 2008 13:48
by Terkhen
CommanderZ wrote:I'm not really sure what the patch is supposed to do with the grf :)
I meant that the invisible edge tiles are still at height 0. There's a "cliff" between real map tiles and invisible edge tiles. The space between tiles isn't drawn (even if it was meant to be black) and that's what creates the glitches. I used the grf just to see the height of the invisible tiles.

Re: Freeform map edges

Posted: 13 Dec 2008 23:15
by Yexo
Updated the patch, see first post for new diff and changelog. Big thanks to SmatZ for fixing the graphical glitches.
Zephyris wrote:How well bug tested is this? I thought some algorithms required a sea level edge square to prevent wraparound, or is there a special invisible square for this?
As much as possible :) Only currently known bug is that building a station at tile 0 gives strange results.
Roujin wrote:IIRC on the bottom left and bottom right edges, there's a row of invisible tiles, but not on the top left and top right edge.
Correct.
Terkhen wrote:I have tried the patch with the water edges grf, and it seems that there's a not drawn slope between the map tiles and the usually invisible edge tiles. Here's a screenshot:
Where can I find said grf?

Re: Freeform map edges

Posted: 13 Dec 2008 23:26
by Terkhen
Here.

I'm going to try the new version right now :D

Edit: I can't compile it with MinGW in windows vista.

Code: Select all

[SRC] Compiling ai/ai.cpp
make[1]: execvp: g++: Invalid argument
make[1]: *** [ai/ai.o] Error 127
I've never seen this error, and I can't find a solution. What can be causing it? :?

Re: Freeform map edges

Posted: 14 Dec 2008 13:47
by PhilSophus
Terkhen wrote:

Code: Select all

[SRC] Compiling ai/ai.cpp
make[1]: execvp: g++: Invalid argument
make[1]: *** [ai/ai.o] Error 127
I've never seen this error, and I can't find a solution. What can be causing it? :?
That looks as if there is something wrong with your gcc installation rather than with the patch (did you try compiling clean trunk? Probably the same happens). execvp is a function replacing the currently running executable by another one (I'd guess in this case the gcc frontend calling the g++ backend).

Re: Freeform map edges

Posted: 14 Dec 2008 15:31
by Terkhen
Clean trunk compilation runs with no problems at all. The same is true for every other patch I use. I think the error happens with the first file that isn't at the src folder.

Re: Freeform map edges

Posted: 14 Dec 2008 15:43
by Yexo
I have no idea what can be causing that error, but my patch doesn't change ai.cpp at all.