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

Adding Hills as a new terrain type

CF code for Hills

Adding a new terrain 'type'

One of my more annoying restrictions is the lack of 'hills' as a terrain type. We have 'rough' and then 'mountains' - 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 );

The movement code has to be checked just in case, but once the terrain bit patterns are set up everything else should just falls into place.

Next subject :- CF Ancients