logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Adding new combat units

CF new Units

Adding the missile unit 'type'

A missile, bomb, or torpedo is a new 'type' of unit that will only 'live' for one turn after it leaves it's transport (i.e. after it's launched or dropped). This means CF source has to be modified and CF rebuilt, however the changes are trivial because the original source code is REALLY well coded (which makes adding a new definition and testing for it dead easy !). The only thing that took time was finding the 'right' place in the source code to 'kill' the missile (it has to die AFTER the combat phase :-) )

A unit of type=missile will typically also have 'type=aircraft' set (so it's move ignores terrain costs) - since it will 'self-destruct' the 'target' doesn't need the ability to attack air units). Actual missiles and bombs will have a complete list of 'terrain=' permissions, whilst Torpedoes (and Depth-charges) will be limited to 'terrain=water' plus 'terrain=deepwater' (and have no 'attack' value against air or ground). Bombs (and depth-charges) will have speed=1 (and no attack against air).

Start by defining a new 'type' (flag) for 'missile', then change the unit definitions compiler to 'detect' the new type and set the flag :-

To define the missile 'type' flag, in gamedefs.h, add :-
#define U_MISSILE 0x00000800
When the unit definitions file (.usrc) is compiled, units of type = missile have to be 'built' with the new flag set by makunitset.cpp. After :-
if ( key == "type" ) {
add :-
else if ( val == "missile" ) t.AddFlags( U_MISSILE );

The final change is to game.cpp source - it has to 'spot' when a missile has been launched and kill it AFTER combat (there is no need to check whose turn it is, missiles always die on the same turn they are launched)

Start by adding a definition to 'detect' if the unit is of type missile in unit.h add :-
bool IsMissile( void ) const { return (u_flags & U_MISSILE) != 0; }
At the end of the turn after combat, any missile NOT in a transporter or shop (i.e. one that is not 'sheltered'), is destroyed. In game.cpp, at about line 777, after :-
while ( u ) {
next = static_cast(u->Next());
add :-
// detect misslie, not in transport or shop :- if ( u->IsMissile() && !u->IsSheltered() ) { // and kill it u->SetFlags( U_DESTROYED ) ; }

Now recompile CF and makunits ... and go set up the unit defs and artowkr and that's it !

Missiles will be type = aircraft (you also have to set the complete list of 'terrain = ')
 
Depending on the missile, you can set different 'attack' values for each target type :-
power(ground) = nn
power(ship) = nn
power(air) = nn
 
Note that, since the missile/torpedo/bomb 'auto-destructs', it is not necessary for the 'target' to have the ability to 'counter-attack' the missile (which will be of type=aircraft)

New unit artwotk

The Unit artwork source (default = CFUnits.bmp) contains the 'icons' for the existing 24 units. Each unit is defined 12 times = once for each of the 6 'facings' in brown (player 1, rebels) and then again in blue (player 2, empire). So there are 288 different 'icons' in total.

The Unit definitions source (default = default.usrc) defines the unit characteristics (type, move, attack, defense etc) and 'links' the each of the 24 unit definitions to the start of a set of 12 icons, counting from '0'. So Infantry is 'icon = 0', Medium Tanks is 'icon = 12', and so on, up to the last set of 12 (Aircraft Carriers, 'icon = 276').

It's not possible to limit a Unit to 'one side only', however, the other sides .bmp icons (for that unit) could be set to a red 'X' (to 'prompt' you when Map making using CoMET)
 
Alternatively, because the unit 'bit map' icons are defined on a 'transparent background', it is possible to make the other players 'choice' invisible (i.e. define the shape for the other player as 'empty space')
 
Note: this allows invisible ('stealth', or 'submerged submarine') units to be defined !

New units should be 'defined' in sets of 4 = if not, you will find the CoMET 'unit select' menu 'wraps-round' (and re-displays the first bmps at the bottom). Also, you must define each new unit in units.src = otherwise they will not appear in CoMET's unit selection window**. The first new unit will use a set of 12 new icons starting at '288' (the next starts at 300, then 312 & the 4th, will start with 324 and so on).

**The unit icons are 'loaded' when edwindow.cpp creates the editing window.
 
The units panel (UnitWidget) is actually created in \src\comet\gfxwidget.cpp, however the contents (unit icons) exceeds the panel size, so have to be 'scrolled' from memory in lines of 4.
 
If you don't stick to 'sets of 4' new units, the 'wrap around' will produce some very odd results

Demo new Unit icons (bmp)

Generally, to build your own 'scenario' (eg 'WW2 - Dieppe Raid'), it is necessary to define multiple new Units (for a start, Landing Craft :-) ). So what follows is really just a demonstration of 'how to do it'

You can download the demonstration new unit bmp file by Right clicking and selecting 'Save As' DemoCFUnits.bmp

Image
Landing Craft (see Note)
Transport Helicopters (Infantry, Light Anti-Tank guns)
Light Anti-Tank gun (to go with the Transport Helicopter)
Self-Propelled Guns

Landing Craft is a transporter limited to Infantry Light Anti-tank and Medium Tanks, terrain water & shallowwater (which allows them to move up rivers !). They can be carried by Transport Ships (which are limited to deep and medium water).

Image
Cruise Missile (defense = 1, high attack and 'reasonable' speed)
AA Missile (I changed the AA Missile Battery to a 'transporter' for missiles)
Mobile Workshop (see Note)
Long Range AA Missile

Note. This is a transporter with 'medic' = repair functionality, with 'minweight' and 'maxweight' set to limit repair to AFV's (Tanks). It still 'costs 5 crystals' to 'repair' a unit, so the Workshop has to be supplied with crystals (it can start with a limited number, and Trucks (or other transport units) used to deliver more - in which case the Workshop min/max weight must be set to allow the 'delivery' unit to 'enter')

Image
Missile Radar (Move=0, see Note 1)
Anti-tank Missile / RPG (Note 2)
Torpedo
Guided Missile Cruiser

Note 1. In theory, defining a Missile Radar as a Unit would allows it to be carried and deployed, however there's a problem with missiles - if these were carried to the unit, the carrier could just launch them instead. So this ends up as a 'static' Unit with a fixed number of missiles (not ideal, since the A.I. will just 'launch' the lot on turn 1) will or must be 'linked' to the 'real' Missile Site (shop) terrain tile using 'Events' (so destroy the Radar, destroy the site) == see New Terrain Tiles
Note 2. The Anti-tank missile let's me define Helicopter Gunships and Infantry as 'transporter', the Torpedo goes with the Bomber, Torpedo Boat and Submarine whilst Guided Missile Cruiser is 'self explanatory'

Image
ASW Frigate
Depth charge (a type of mine)
Pontoon Bridge (limiter to shallow water, see Note)
Truck / Pontoon transporter (see Note)

Note. When a 'scenario' is set-up to use Pontoons, the Map must be built so that there is only a few places where a Pontoon bridge can be 'deployed' (from it's Transport, or from a Landing Craft). The Events system can then be used to 'monitor' these places and, when a Pontoon Unit appears in one of the 'watched' hex's, it is 'converted' into a Pontoon Tile (i.e. the Pontoon Unit is 'destroyed' and the shallow water tile is replaced with a pontoon bridge tile). This is has to be done if other units to cross the pontoon bridge (since no unit is permitted to move through another)

Image
Coastal Artillery
Beach defences (mined)
Pillbox (see Note)
(spare)

Note. Both Coastal Artillery and the Pill box are 'transports' (but have 'move = 0') so they can act as 'bunkers' into which Infantry and Light AT guns can 'hide' from naval units bombarding coastal defences

Limiting missiles/bombs to specific transporters

To ensure Bombers could 'drop' Mines & launch Torpedoes & Cruise Missiles - but not AA missiles - whilst Fighters could use short range AA missiles (only), and Interceptors & AA Missile Battery both had the choice of mixing both long & short AA Missiles required a lot of 'playing around' with all the unit 'weights' (since 'minweight' and 'maxweight' is used to control all the 'transporter' types, not just those already mentioned).

Remember - units of type=missile will 'auto-destruct' at the end of the turn they leave their transport.

Building the units 'compiled' file

Before your new Unit icons (CFUnits.bmp) can be used, they must have a matching 'definition' in the ".usrc" file. The best way to define units is to create a spreadsheet (and then use a QBasic utility to 'convert' the .csv into a new .usrc file). For a spreadsheet of my current Unit definitions, Right click and 'save link as' demo-Units.xls

Assuming you have modified the default files (CFUnits.bmp default.usrc) in the CF source & /gfx folder, to build a new 'default.units' (compiled units) file :-
 
From a cmd window, navigate to the CF \tools folder and type:
mkunitset default.usrc default.units ../gfx where ../gfx is the location of the .bmp icon files

You can Right click and 'save link as' here for mkunitset.exe


Clicking "Next >>" (Nav bar, left) will take you to my 'New Terrain Tiles' page

Next page :- Missiles - (new Units)

[top]