Home and Links
 Your PC and Security
 Server NAS
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

New terrain tiles for Crimson Fields

CF Tiles

How do you add extra tiles ?

A1. The tile artwork in CFTiles.bmp contains the 'icons' for 384 tiles in 16 rows of 24. The first 8 tiles (000-007) are 'reserved' for program use. Terrain tiles thus start at 008 (HQ entrance, FNA (brown) South facing)

The Tile definitions, held in default.tsrc, are automatically assigned Tile ID codes in order starting from 000. Each definition has a reference to one of the tile icon bmp's. Combat maps terrain (map raw) use the Tile ID codes, not the bmp artwork references

For a full description, see my CF terrain tile definitions page

The tile icons are displayed in ID sequence order. To make it easy to choose tiles for a new map, similar tiles are defined in 'sets' (i.e. grouped together = all buildings, then grass, hills, roads, rails, rivers etc.)

Whilst are a few 'spare' positions (6) and some of the bmp's are 'unused' (7 are not referenced in any definition), to get enough space for the 'beaches' set I added an extra row (24)

What changes did you make to the buildings?

One of the first things I did when modifying the terrain tile set was to 'fix' the buildings :-

First, the 3 pointless 'Neutral' HQ entrances were deleted and replaced by 2 South facing HQ entrances (i.e. one in each of Player 1 & 2 colours), leaving 1 'spare'.

Next, the 'Factory' & 'Depot' tile sets (6 & 3) were taken together with the 'under-construction' tiles (4) and used to create a full set of Player 1, 2 and Neutral, N,S,E & W facing Factory 'entrances' (12 tiles), leaving a second 'spare'.

The two 'spares' were then used as Factory specific E & W 'sides' (the 'generic' N & S HQ 'side' artwork tiles being used for N & S factory 'sides').

Adding or removing a tile from the .tsrc sequence would result in all the 'maps' picking up incorrect icon's for every tile, so the tiles had to be kept in the same place as much as possible. Even so, just fixing the Depot/Factory 'set' involved quite a lot of 'search & replace' on all the existing map definitions *.src files just to 'sort out' the depot's and factories

Due to the large number of maps involved (> 100, when including the Battle Isle sets), a VB Script was written to do the 'replacements' (after doing a 'search & replace in files' to convert the unix 'LineFeed' to a Windows 'CarriageReturn / LineFeed' pair).

'Neutral HQ' and 'Depot' tiles were replaced by 'Neutral factory' tiles. The 'Building under construction' tiles were replaced by 'mountains'.

As already noted, the 'function' of a building is defined independently of it's icon. The difference between a 'factory' and a 'depot' is that one 'generates crystals' and 'builds' (or 'buys') units whilst the other is simply a 'store' with a unit 'repair' capability

What other changes did you make ?

Tile icons can be placed anywhere in the bmp file. Grouping them together just makes it easier to ensure none of the required 'facings' are 'missed out'

I wanted to offer desert / beach landing maps, so needed a totally new set of desert and beach tiles.

Image The 6 existing tiles consisting of one hex edge grass (5 edges water) where modified to remove the 'grass' (so 1 side sand, 5 sides water))

The remainder of the water <> beach were added, 18 tiles, being 3 sets of 6 (i.e. a set of '2 hex sides beach', '3 sides beach' and '4 sides beach')

One all sand tile plus a set of 6, half sand / half grass tiles (to support sand<>grass terrain transition)

To repair bridges, a set of 3 'Pontoon over water' tiles are required.

Image Assault from the sea' is restricted to North <> South, requiring one each of Pontoon to 'North beach to water', 'South beach to water', 'South grass beach to water' & 'North grass beach to water'.

Some additional 'house' tiles were added (at the 'spare' positions after the woods tiles).

One final spare tile became an additional 'rocks' tile

How do you add new terrain 'types' ?

One of the more annoying restrictions is the lack of a 'hills' terrain type - which makes it hard to control unit movement realistically.

The 'solution' of classifying hills as 'rough' only partially 'works' (since allowing Artillery up hills then allows it into rough - and allowing Hovercraft into rough then allows them up hills).

Terrain and Unit 'allowed into' definitions are processed by the tools\mktileset.cpp & mkunitset.cpp. The 'values' for the terrain types are found in src\common\gamedefs.h

Examination of gamedefs.h shows that each terrain 'type' is assigned it's own 'bit'. A 16 bit number is used, however since 'building entrance' is defined as bit 14 (rather than bit 15) it is assumed the 'terrain code' is a 'signed' number. This means that a there is 'space' for only 2 new terrain types (bit 12 = 0x1000 & bit 13 = 0x2000). I decided to add 'hills' as bit 12 :-
#define TT_HILLS 0x1000

Further examination reveals that 'rough' terrain is set to bit 4 i.e. t.tt_type = TT_BARRICADES. Whilst terrain tiles depicting tank traps (and walls) do exist, the name 'barricades' is not used. I thus decided to 'resurrect' the name 'barricades' thus allowing 'rough' terrain to be separated out as a distinct type
#define TT_ROUGH 0x2000

In mktileset.cpp, replace line 238 "else if ( val == "rough" ) t.tt_type |= TT_BARRICADES;" with :-
else if ( val == "barricades" ) t.tt_type |= TT_BARRICADES;
else if ( val == "rough" ) t.tt_type |= TT_ROUGH;
else if ( val == "hills" ) t.tt_type |= TT_HILLS;

In mkunitset.cpp, replace line 323 "else if ( val == "rough" ) t.AddTerrain( TT_BARRICADES );" with :-
else if ( val == "barricades" ) t.AddTerrain( TT_BARRICADES );
else if ( val == "rough" ) t.AddTerrain( TT_ROUGH );
else if ( val == "hills" ) t.AddTerrain( TT_HILLS );

How do you generate a new default.tiles 'compiled' file ?

A1. The simplest approach is to 'make' / 'make install' the entire Crimson Fields Source (it doesn't take long). This ensure that any new 'types' are picked up

A2. If the ONLY changes are to the artwork (tile bmp images) or the definitions (and the map have already been adjusted = see below) you can simply rebuild the 'default.tiles'. Navigate to the \tools folder and to generate the default.tiles, use :-

mktileset ../gfx/CFTiles.bmp default.tsrc default.tiles

How do I adjust the map .src files ?

My 'tile swap' QBasic script (and a 'tiles swap' list) can be found in my CF 0.6.0 new Units and Tiles 'pack'(right click and 'save link as' to download the .zip from here) pack

If you 'add' or 'remove' definitions, all the tile ID codes from that point on will be changed .. this will mean that all existing maps (.src / .lev) will 'pick up' the 'wrong' terrain tiles. Whilst it's possible to 'hand edit' the map .src to change a few tile codes this can be a real pain. Far better is to 'script' the changes and automate the whole process

Notepad++ has a 'replace in files' function. This is fine for changing one or two ID codes, but can be a right pain when you have a dozen to change, especially if your need to 'swap over' two codes (eg existing code 10 to new 20 and existing 20 to new code 10)

Scripting the changes is, of course, harder than it sounds :-)

What's the problem with 'scripting' changes ?

The *.src file in the /levels/ folder use the hex code '0A' as the 'line terminator'. Whilst Notepad++ is OK with this, other text edit software may not be - and, for sure, any QBasic script will 'fall over' with an 'Out of string space' error when trying to 'read' (line input) from the *.src files.

Fortunately, CoMET on Windows correctly uses '0D'+'0A' when 'Exporting' a .lev map as a 'source' file. So 'all' you have to do is 'Load' the .lev version of the existing map files and then 'Export' them as .src - and CoMET will then create an 0D+0A formatted file, which you can then process using QBasic scripts

Another way to 'fix' the line ends is to open the map '.src' in Windows 'Wordpad' and then 'save as' 'Text Document MSDOS format' which will change the line end codes to CR+LF (note that neither Notepad nor Notepad++ will change the line ends)

How do I 'compile' a modified map .src file ?

Of course CoMET can't load a source (.src) file, only a .lev version. So after 'processing' (eg swapping tile numbers around) the next step is to 'compile' the .src to .lev using the 'cfed' utility together with the new default.tiles & default.units

Assuming your modified .src is in the /levels folder (and that your new unit + tile set is in the 'next folder up'), to compile 'name.src' into 'name.lev', 'cd' to /levels and type :-
cfed {name}.src --tiles ..\default.tiles --units ..\default.units

Clicking "Next >>" (nav bar, left) will take you to my first 'demo' = crimson-0.6.0.exe Page

Next page :- Repair and Construction