Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


dalerank

Member Since 18 Mar 2011
Offline Last Active Oct 27 2014 03:29 PM

#5181939 Reverse-engineering Caesar III (Draw city)

Posted by dalerank on 21 September 2014 - 01:21 PM

Created by dalerank
Translated by Anastasia Smolskaya

I hope that the previous post Back-Engineering Caesar III, with the description of the algorithm of creating textures from the resources of the original game was welcomed by the inhabitants of habrahabr.ru. This article describes the format of maps, algorithm of selection and order of tiles for drawing, creation of the final texture.

548fe94ac86b7849c40361db95020a48.jpg

If you are familiar with tiles you can skip the following part of the article.
 
Tiles
Tile is a picture of a fixed size created so that while you draw near other tiles you don’t create any “stiches”. Here is an example of grass from the game Caesar III©

e8f45088f7bb8264022f0802336b5d9d.pngc99835a7a20b3f0872735f134d8a41d4.pngf1c94f9131045f295f86d72a04878b6d.png19c06ac2ad3ae9ff69ecc30baa3094b1.png

If you put them together in a definite order and add a little bit of texture with trees then you’ll get some part of surface. And if you add to this picturesque image another kind of tile, say, the one that depicts a road, you can put together a basic map.
 
0be7463187f6e117ba00ea8a75071324.png    5b7c92d96959fcaadf311b2e2180a683.png

You have probably noticed that the presented tiles have a shape of a diamond not a square. The purpose of this is to create the image with dimension (depth). That kind of tile looks as if it was turned to the viewer and as if it spreads to the depth, bidirectional image gets third dimension. To create the effect of dimension the width should be two times less than the length of the image. Tile base in the game Caesar III is 58x30 pixels, this is the minimal size of the tile which is operated by the game engine. On the first phases of remake creation we got one unpleasant effect, textures in the game are created without taking into account transparency and when displayed on the screen without additional processing we got the following result.

1f4cb2f94ffecfc0020eac3920a8f44f.png

The way out is as follows: you can use a mask, for example the color of the farthest left symbol is taken as transparent or textures should be complemented with an alpha channel. In the original game we used the first option, in the remake – the second: textures are prepared at the stage of resources upload.

Map
Map is an array that defines the position of the tiles on the layer and their parameters. In the simplest case the map is a matrix MxN with each element having an identifier (number, figure) from the so called “tiles palette”. Tiles do not necessarily have successive position number, numbers of tiles are divided between several intervals and named areas. Thus, for example, tiles of earth, trees, water, cracks and grass have the indexes from land1a_00001 to land1a_00303. In the game Caesar III it is allowed to use square maps from 30х30 to 160х160 tiles. Tiles are positioned the map so that its upper boundary is the “north”.
944b0659be7c1fab7fa7e6cbc97cf0df.jpg

In order to draw the tiles on the screen it is important to take in account the distance to it, if you just draw tiles in the order they are placed on the map you’ll get a misconvention because some part of tiles was not drawn in time.
32b59e2147d77ccf20016b142d02c4ce.png


The order for drawing tiles is shown by the following image.
bd78a9a62a648a5a6e05897025db0a48.jpg

1. The first image shows the order of drawing tiles on 2D map for creating dimension effect.
2. The second image shows the order of drawing tiles on 2.5D map knowing that the higher is the tile the earlier it should be drawn.
de74dbc49c4eada6dfc703e7c95d7075.png


This image is generated from the following tiles drawn in the correct order.
694cc12cad6be63938768f7e79e92046.png


Drawing a town
Additional conditions that occur while drawing a town.
1. On the map there are not only static tiles of earth, grass, buildings, but also dynamic objects (people, animals, animation)
2. There are objects for passing through (archways, gates, barn)
3. Additional animation of tiles and objects
4. Nonsquare objects

These conditions complicate the process of drawing and create additional rules for drawing.
1. Moving objects on isometric map needs some tricks to happen. The map is turned “inwards” and its absolute size vertically does not correspond to the horizontal size. Therefore, any dynamic object should appropriately move “up”, in the simplest case for each two steps aside there is one step inward.
2. A dynamic object can be in the different parts of tile and it is drawn after the main tile is shown which can create the artifacts of imaging, for example, a cart moves above the gates. This can be neutralized by drawing additional sprites which will be shown after drawing dynamic objects.

cc76d441fc7ba1e5adee5222446c3034.png+1d09a934b57a38342cc77b123fe3b5ea.png=58b5f38729c5982b2548c0a715d5483c.png

3. Animation can exceed the size of the main image and here you should remember the feature that animation can go up and down or it’ll be covered by other tiles.
4. In majority of cases the game uses square objects but there are extended ones to simplify the algorithm of drawing, they are divided into smaller (square) parts, for example, hippodrome.

61a6c466740f1f46540c6172a980514a.png+ec7bb7244b3d743a8990789d894e039c.png+93c02e83a0684d8fe134f13d1fbd3f2b.png=2e066efcdd9d5db9422ec5ed6ae5d006.png

How to draw
1. At first you should draw “flat” tiles and dynamic objects on the,
2. Secondly, you should draw tiles which images can exceed the tile base.
3. Then you draw the additional animation for tiles, which have the following flag
This algorithm was retrieved from the original game as much as I could understand it, though it may be changed in the later versions. Advice on the drawing cycle is welcome.

Map format of Caesar III
The objects that are shown in the town in file *.map include first five data blocks. Read from the beginning of the file, read the data one by one without gaps.

short tile_id[26244] — contains identification elements, each identificator corresponds to its texture. For example, identificators group 246-548 corresponds to textures land1a_00001-land1a_00303, these are textures of earth, trees, etc., which were described before.
byte edge_data[26244] — the array contains information about the size of the object which has  texture in the array tile_id
short terrain_info[26244] — the array contains characteristics of surfaces for each tile, earth, water, road, wall, etc. (complete info here)
byte minimap_info[26244] — basic info for creating a mini map, it also takes part in some calculation during the game as a so called array of “random numbers”.
byte height_info[26244] — this array describes the height of the tile over the surface, 0 – for land, 1 – 15 pixels, 2 – 30 pixels and so on.

Application
More details about the game Caesar III© and the development of the remake can be found on our wiki at bitbucket.org.
Special thanks to Bianca van Schaik for help in writing the article and providing materials.

And in the end a small test screenshot that depicts Etrurian spearmen vandalize the City of Fountains:
60980b50a1c7fdcc61d8ef6576475ff6.jpg




PARTNERS