Diving submarines

CF submarines

Adding the submarine unit 'type'

As with missiles, the 'easy' way to dive your subs is to simply define a new unit 'type' (unit flags are held in a 'long' = 32bit word, so there are plently 'spare'). You then modify the artwork (units.bmp) to add the 'transpartent' icon ato the start of the file (so it's loaction can be 'hard coded' into the source game.cpp).

Then 'all' that's needed is to modify the game.cpp code (at about line 777) to 'hide' enemy subs at the end of their go

On the first game turn, the first player will see enemy Subs that have been 'predeployed' = unless, in CoMET, you pre-deploy subs with the 'transparent' artwork icon
Of course, whilst this 'works' fine, it does mean that once deployed in CoMET you can't actually 'see' them :-)

To define the sub 'type' flag, in gamedefs.h, add :-

#define U_SUBMARINE 0x00001000

When the unit definitions file (.usrc) is compiled, units of type = submarine have to be 'built' with the new flag set by makunitset.cpp. After :-
if ( key == "type" ) {
add :-

else if ( val == "submarine" ) t.AddFlags( U_SUBMARINE );

The final change is to game.cpp source - it has to 'spot' when this players submarine is in water/deepwater and dive it before the next players turn or surface it (so the next player can see their own subs or enemy subs in shallow water)

Start by adding a definition to 'detect' if the unit is of type submarine in /source/comet/unit.h add :-

Now the complicated part. A unit game object has a 'u_type' value which is a 'pointer' (*prefix) into the unit type definition array (UnitType). These pointers are generated when the map is compiled (by looking up each units name in the compiled units file).

SO - what we need to do is change the u_type pointer from 'submarine' to 'transparent' and back again. This means 'saving' the two pointers generated when the map is created by cfed i.e. adding them to the 'map' (or mission') header. They wil then be carried forward into the current game.

At the end of the turn, any submarine of the current player in water/deepwater is dived, all others surfaced. In game.cpp, at about line 777, in the section :-
while ( u ) {
next = static_cast(u->Next());
add :-