⬆️ ⬇️

Caesar III Reverse Engineering (Part 2, Drawing the City)

I hope that the previous post Back-engineering of Caesar III , where the algorithm for obtaining textures from the resources of the original game was described, was favorably received by the masters. In this article I will describe the format of the maps, the selection algorithm and the order of the tiles to draw, the formation of the final texture.









')

If you know what a tile is, then you can skip the next section.

Tiles

A tile is a fixed-size picture, formed so that when drawing next to other tiles, a solid image without “seams” is obtained. Here is an example of grass textures from the game Caesar III







If you draw them side by side in a certain order and add some textures with trees, you will get some area of ​​earth.







You probably noticed that the presented images are not square, but diamond-shaped. This is done in order to give the image a sense of volume (depth). Such a tile looks rotated by one angle to the viewer and, as it were, going deep, the two-dimensional picture acquired a third dimension. To create a volume effect, the width should be less than about half the length. The base of the tile in the game Caesar III is 58x30 pixels, this is the minimum size of the tile with which the game engine operates. At the first stages of the development of the remake, one unpleasant effect was obtained, the textures in the game were created without taking into account transparency and their output to the screen without additional processing led to the following result.







The way out of this situation is the following: either use a mask, for example, the color of the leftmost character is assumed to be transparent, or textures are complemented with an alpha channel. In the original game, the first version was used, the second version is used in the remake: textures are prepared at the stage of loading resources.



Map

A map is an array defining the position of tiles on a layer and their parameters. In the simplest case, the map is an MxN matrix, where each of its elements contains an identifier (number, number) from the conditional “tile palette”. Tiles do not necessarily have a sequential sequence number, tile numbers are divided into several intervals and named spaces. For example, the tiles of land, trees, water, rifts and grass have indices from land1a_00001 to land1a_00303. In the game Caesar III, it is allowed to use square maps of sizes from 30x30 to 160x160 tiles. The tile is located on the map so that its upper boundary is "north."







In order to draw the tiles on the screen, you need to consider the distance to it, if you just draw the tiles in the order of their placement on the map, you get an abracadabra, as part of the tiles was not drawn in due time.







In what sequence to draw the tiles shows the following image.







1. The first figure shows the order of drawing tiles on a 2D map, to create a depth effect.

2. In the second figure, the order of drawing tiles on a 2.5D map is shown, given that the higher the tile is located, the earlier it should be drawn.







This image is made up of the following tiles drawn in the correct order.







In the general case, the code for generating indexes of tiles for drawing will be as follows:



Look
//   ""  tilemap map; //  tilearray tiles; //  for( j=0; y < map_size; j++ ) { for( t=0; t <= j; t++ ) { tiles.append( map[ t , map_size - 1 - ( j - t ) ]; } } //   ""  for( i=1; i < map_size; i++ ) { for( int t=0; t < map_size-i; t++ ) { tiles.append( map[ i + t, t ] ); } } 




Drawing city

Additional conditions that arise when drawing a city.

1. The map contains not only static tiles of earth, grass, buildings, but also mobile objects (people, animals, animation)

2. There are objects through which you can pass (arch, gate, barn)

3. Additional animation of tiles and objects

4. Non-square objects



These conditions complicate the drawing process and generate additional drawing rules.

1. Moving characters on an isometric map is not just. The map is rotated “inwards” and its absolute vertical size does not coincide with the horizontal size. Therefore, “walking up” any walking object should move accordingly, in the simplest case, two steps to the side are one step deep.

2. The moving object can be located in different parts of the tile and is drawn after the main image of the tile is displayed, which can cause display artifacts, for example: a chariot travels over the gate. It costs drawing additional sprites that will be shown after drawing moving objects.



+ =



3. Animation can go beyond the size of the main image, here you should take into account such a feature that it (animation) can go up and to the right, but not down and to the left, otherwise it will be covered by the following tiles.

4. For the most part, square objects are used in the game, but there are also extended ones, in order to simplify the drawing algorithm, they are beaten into smaller (square) parts, for example, a hippodrome.



= + +



How to draw

1. For the first pass, “flat” tiles and moving objects on them are drawn.

2. For the second pass, tiles are drawn, whose images may extend beyond the base of the tile.

3. Additional animation is drawn for tiles that have such a flag.

Anticipating possible questions. This algorithm was restored from the original game, as far as I could understand it, maybe it will be changed in later versions. Tips on organizing a rendering cycle are welcome.



Caesar III Game Card Format

Directly to the objects that will be displayed in the city, the first five data blocks are in the * .map file. We read from the beginning of the file, read the data one after another without gaps.



short tile_id [26244] - contains the identifiers of the elements, each identifier corresponds to its own texture. For example, the group of identifiers 246-548, corresponds to the textures land1a_00001-land1a_00303, these are the textures of the earth, trees, etc., which were described above.

byte edge_data [26244] - the array contains information about the size of the object for which the texture is selected in the tile_id array

short terrain_info [26244] - the array contains surface characteristics for a particular tile, ground, water, road, wall, etc. ( full information on these flags )

byte minimap_info [26244] - basic information for constructing a minimap, also participates in some calculations during the game, speaking a sort of an array of "random numbers".

byte height_info [26244] - this array describes the height of the tile above the surface, 0 for the ground, 1 - 15 pixels, 2 - 30 pixels, and so on.



Practical use

More information about the game Caesar III and the development of the remake can be found in our wiki at bitbucket.org .

Special thanks to Bianca van Schaik for the help in writing the article and the materials provided.



And finally, a small test screenshot, Etruscan spearmen rampant in the city of fountains:



Source: https://habr.com/ru/post/222943/



All Articles