Unit Types (struct unit_type)
The 28 unit types are 34-byte records in utypes[28] (GAME.C, DGROUP
112A).
struct unit_type {
char name[12];
int obsolete_by;
int domain; /* 0 land, 1 air, 2 sea */
int moves;
int fuel;
int attack;
int defense;
int cost;
int sight;
int capacity;
int role;
int prereq;
};
| Field | Meaning |
|---|---|
obsolete_by | Advance that makes the type obsolete; 127 for none |
domain | 0 land, 1 air, 2 sea |
moves | Moves per turn; ai_turn() multiplies by 3 |
fuel | Turns an aircraft may stay airborne (Fighter 1, Bomber 2, Nuclear 1) |
attack, defense | Combat factors |
cost | Production cost in tens of shields |
sight | Bit 1 (value 2) widens sight from the 3 × 3 to the 5 × 5 square |
capacity | Land units a ship carries |
role | Category used by the AI (roles) |
prereq | Advance needed to build the type; −1 for none |
GAME.C declares its own copy of the structure with fields w2–w10 in
the same positions. The table, in ID order:
struct unit_type utypes[28] = {
{ "Settlers", 127, 0, 1, 0, 0, 1, 4, 0, 0, 0, -1 },
{ "Militia", 34, 0, 1, 0, 1, 1, 1, 0, 0, 2, -1 },
{ "Phalanx", 34, 0, 1, 0, 1, 2, 2, 0, 0, 2, 17 },
{ "Legion", 64, 0, 1, 0, 3, 1, 2, 0, 0, 1, 18 },
{ "Musketeers", 64, 0, 1, 0, 2, 3, 3, 0, 0, 2, 34 },
{ "Riflemen", 127, 0, 1, 0, 3, 5, 3, 0, 0, 2, 64 },
{ "Cavalry", 64, 0, 2, 0, 2, 1, 2, 0, 0, 1, 31 },
{ "Knights", 58, 0, 2, 0, 4, 2, 4, 0, 0, 1, 62 },
{ "Catapult", 48, 0, 1, 0, 6, 1, 4, 0, 0, 1, 9 },
{ "Cannon", 63, 0, 1, 0, 8, 1, 4, 0, 0, 1, 48 },
{ "Chariot", 62, 0, 2, 0, 4, 1, 4, 0, 0, 1, 33 },
{ "Armor", 127, 0, 3, 0, 10, 5, 8, 0, 0, 1, 58 },
{ "Mech. Inf.", 127, 0, 3, 0, 6, 6, 5, 0, 0, 2, 65 },
{ "Artillery", 127, 0, 2, 0, 12, 2, 6, 0, 0, 1, 63 },
{ "Fighter", 127, 1, 10, 1, 4, 2, 6, 2, 0, 4, 38 },
{ "Bomber", 127, 1, 8, 2, 12, 1, 12, 2, 0, 1, 39 },
{ "Trireme", 8, 2, 3, 0, 1, 0, 4, 0, 2, 5, 7 },
{ "Sail", 14, 2, 3, 0, 1, 1, 4, 0, 3, 5, 8 },
{ "Frigate", 35, 2, 3, 0, 2, 2, 4, 0, 4, 5, 14 },
{ "Ironclad", 37, 2, 4, 0, 4, 4, 6, 0, 0, 3, 23 },
{ "Cruiser", 127, 2, 6, 0, 6, 6, 8, 3, 0, 3, 37 },
{ "Battleship", 127, 2, 4, 0, 18, 12, 16, 3, 0, 3, 52 },
{ "Submarine", 127, 2, 3, 0, 8, 2, 5, 3, 0, 3, 41 },
{ "Carrier", 127, 2, 5, 0, 1, 12, 16, 3, 0, 3, 39 },
{ "Transport", 127, 2, 4, 0, 0, 3, 5, 0, 8, 5, 35 },
{ "Nuclear", 127, 1, 16, 1, 99, 0, 16, 0, 0, 1, 46 },
{ "Diplomat", 127, 0, 2, 0, 0, 0, 3, 0, 0, 6, 22 },
{ "Caravan", 127, 0, 1, 0, 0, 1, 5, 0, 0, 6, 24 },
};
Building a type
find_slot() in ECONOMY.C offers a unit type when the civilization
knows its prerequisite and does not know its obsolescence advance. Ships
need a coastal city (status bit 0x02). Nuclear units also need the
Manhattan Project to have been built by someone and the owner to know
Nuclear Fission.
The AI disbands obsolete units over time (see Unit AI). The game does not upgrade them.
Special abilities
The table gives few abilities directly; most are tests on type numbers in the code:
| Type | Behaviour |
|---|---|
| Settlers (0) | Only type that builds cities, joins them and changes terrain |
| Fighter (14) | Only type that may attack aircraft outside a city |
| Bomber (15) | Its movement ends after an attack |
| Trireme (16) | A human Trireme that ends its move with no land next to it is lost half the time (*TRIREME) |
| Submarine (22) | Cannot attack land. Not seen beyond adjacent tiles, and does not see beyond them itself |
| Carrier (23) | Carries any number of aircraft (its capacity is 0), and refuels them |
| Nuclear (25) | Entering a foreign city detonates it (atom()) |
| Diplomat (26) | Enters foreign cities for the Diplomat menu and bribes units by moving onto them. Ignores zones of control. The Barbarians’ leader is a Diplomat. |
| Caravan (27) | Establishes trade routes or helps build a wonder. Ignores zones of control. |
Attack factor 12 (Artillery and Bomber) ignores City Walls; see Combat.
Capacities are Trireme 2, Sail 3, Frigate 4 and Transport 8. Fighters, Bombers and the Cruiser, Battleship, Submarine and Carrier have sight bit 1; aboard ships, the wider sight covers only ocean.