Comment by TapamN

7 years ago

I'm also actually working on an unreleased to-be-open-source SimCity 2000 clone in C++ (which I am planning to call 21st Century Micropolis, after the existing, official open-source SimCity Classic release called Micropolis), so I've looked into how SC2K renders the screen. I'll describe it for drawing the whole map, since it's simpler, but you'd want to modify it to draw only the visible parts in an actual game.

Directions are relative to the screen, not the grid.

10 Clear the screen and set a pointer to the top corner of the map

20 If the pointed tile belongs to terrain or the leftmost tile of a building, draw it on top of what we already have on screen. (Note that for tiles that belong to a building, but aren't the leftmost tile, we do nothing) (1x1 buildings always count as a leftmost tile)

30 If we are at the last row, exit

40 If we are at the end of the row, go to the leftmost tile of the row below, and jump to 20

50 Otherwise step one tile to the right, and jump to 20

That's it.

One wrinkle in getting the exact same output as the original has to do with the magic eraser tool, which basically hacks the map and forcibly resets a tile to it's blank state, even if it's supposed to belong to a building. If the leftmost tile of a 2x2, 3x3, or 4x4 building has been magically erased, the entire building disappears. If you magic erase a tile below the leftmost tile, or to the right of it, you will draw ground tiles over the building. Erasing tiles above the leftmost tile's waterline has no visible effect. Magically erased tiles can also have things built onto them. This algorithm gets these cases correct.

Thanks! How do you handle different terrain heights?

  • Terrain height just changes the Y position when where you draw. Draw order is still the same. The formula for tile map space to screen space is:

    scrx = mapy16 - mapx16;

    scry = mapx8 + mapy8 - GetSurfaceHeight(mapx,mapy)*12;

    IIRC, this assumes origin is in top most tile, with increasing Y going down. So each step the terrain increases, you move the tile you draw up 12 pixels higher from the lowest point.