Hello,
I am just adjusting the more heightlevels patch to the freeform map edges patch. What makes me trouble are slopes at the map edges.
Example: Consider a 256x256 map. z(x,y) is the height at position (x,y). Let z(154,255)=22, z(155,255)=22, z(156,255)=21. So (155,255) has slope NE. If you scroll southeast, you have to paint the black area properly in order to avoid glitches resulting from areas of the map still being displayed where now black area has to be painted.
My idea to deal with this is assigning points outside the map a height as well, based on the heights at the map edges. Then, I can paint black tiles with the correct slope there. For example, for the tiles mentioned above (y now is any number > 255), z(154,y)=22, z(155,y)=22, z(156,y)=21. This way, any tile southeast of the map at y position 155 would be a Slope NE. Same for the areas northeast, northwest and southwest of the map. I wrote an alternative TileHeightOutsideMap function as follows:
Code:
static inline uint TileHeightOutsideMap(int x, int y)
{
if (x < 1) {
if (y < 1) {
return TileHeight(TileXY(1, 1));
} else if (y < (int)MapMaxY()) {
return TileHeight(TileXY(1, y));
} else {
return TileHeight(TileXY(1, (int)MapMaxY()));
}
} else if (x < (int)MapMaxX()) {
if (y < 1) {
return TileHeight(TileXY(x, 1));
} else if (y < (int)MapMaxY()) {
return TileHeight(TileXY(x, y));
} else {
return TileHeight(TileXY(x, (int)MapMaxY()));
}
} else {
if (y < 1) {
return TileHeight(TileXY((int)MapMaxX(), 1));
} else if (y < (int)MapMaxY()) {
return TileHeight(TileXY((int)MapMaxX(), y));
} else {
return TileHeight(TileXY((int)MapMaxX(), (int)MapMaxY()));
}
}
}
Based on this concept of heights outside map, I can rewrite the painting code in viewport.cpp for tiles outside map as follows:
Code:
} else {
// We are outside the map => paint black
tile_info.tile = 0;
tile_info.tileh = GetTileSlopeOutsideMap(tile_info.x, tile_info.y, &tile_info.z);
tile_type = MP_VOID;
}
I am pretty sure that this works, except for one problem. The drawing procedure for the black tile called some lines later unfortunately ignores the slope and paints the tile like if it is flat. See attached screenshot for what I mean.
I think, what we would need here, are just black images for the slopes NE, SW, NW, SE (and/or make the painting code paint them

). What I unfortunately not know is how to implement them. If I get it right, the solution originally implemented in the freeform map edges patch for the problem I described above is the following code:
Code:
} else {
if (!_settings_game.construction.freeform_edges || (TileX(tile) != 0 && TileY(tile) != 0)) {
if (x_cur == ((int)MapMaxX() - 1) * TILE_SIZE || y_cur == ((int)MapMaxY() - 1) * TILE_SIZE) {
uint maxh = max<uint>(TileHeight(tile), 1);
for (uint h = 0; h < maxh; h++) {
DrawGroundSpriteAt(SPR_SHADOW_CELL, PAL_NONE, ti.x, ti.y, h * TILE_HEIGHT);
}
}
ti.tile = tile;
ti.tileh = GetTileSlope(tile, &ti.z);
tt = GetTileType(tile);
}
}
So you simply paint: For each tile in the black area, one black tile per height level of that tile. I don't think that painting that many images is resonable with more height levels.
So: Can anyone help solving the problem I described above?
Attachment:
File comment: Glitches at the map edge.
Unbenannt, 16. Nov 1962.png [78.3 KiB]
Downloaded 75 times