This code fragment defines the fundamental data structures for programming the supply determination routines.
===========
Code: Select all
// ****************************************************************************
// There are 3 TLinkType's used in determining supply: Basic, Rail, and
// Overseas. A series of links, or perhaps just one link, connects a supply
// source to a unit or another supply source. These are called
// TSupplyConnection's herein. A series of supply connections is called a
// TSupplyPath, which connects a unit to a primary supply source.
// ****************************************************************************
TSupplyLinkTypes = (sltBasic, sltRail, sltOverseas);
// ****************************************************************************
// Nodes are the end points of a supply link. Besides a unit or supply source,
// nodes can also be ports or simply a rail hex that is being used to start or
// end a link. For example, an HQ that is not in a rail hex usually traces a
// Basic link from itself to a rail hex. The next link is often a Rail link
// from the rail hex to a primary supply source.
// ****************************************************************************
TNodeTypes = (nodStaticPrimary, nodHQPrimaryTurn, nodHQPrimaryImpulse,
nodStaticSecondary, nodHQSecondary, nodStaticTertiary, nodHQTertiary,
nodPort, nodRailHex, nodUnit);
// ****************************************************************************
// A TSupplyLink is exclusively of one LinkType. That is, it is either purely
// Basic hexes, connected Rail hexes, or Sea areas. LandLink stores the Basic
// and Rail hexes that make up the link, while SeaLink stores the sea areas that
// make up a sea area link. Only one of those two lists is ever used in a
// TSupplyLink. The other is nil. Simply put, a link connects one node to
// another. Note that a Overseas link, by definition, uses the single instance
// of overseas link permitted in a supply path.
// ****************************************************************************
TSupplyLink = record
LinkType: TSupplyLinkTypes;
Valid: Boolean; // Whether the link is functioning or cut.
Validated: Boolean; // Flag used when determining which links are valid
StartNode: TSmallPoint; // Column, Row
StartNodeType: TNodeTypes;
EndNode: TSmallPoint; // Column, Row
EndNodeType: TNodeTypes;
LandLink: THexList; // The path as a TDataTable of hexes
SeaLink: TSeaAreaList; // The path as a (sorted) list of sea area IDs
BasicHexCount: 0..4; // The # of basic hexes used by the link.
end;
// ****************************************************************************
// Class TSuppyLinkList
// ****************************************************************************
TSupplyLinkList = class(TObjectTable)
// ****************************************************************************
// This class contains a list of supply links (Item[index]) that make up a
// TSupplyConnection. The reason more than 1 link may be involved is that the
// connection may be comprised of Basic, Rail, and/or Overseas links.
// However, there may never be more than one overseas link in a connection.
// Also the total number of Basic hexes is a maximum of 4.
// ****************************************************************************
private
function GetItem(const Index: Longint): TSupplyLink;
public
constructor Create;
destructor Destroy; override;
property Item[const Index: Longint]: TSupplyLink read GetItem; default;
end;
// ****************************************************************************
// TConnectionTypes identify what is connecting to what.
// ****************************************************************************
TConnectionTypes = (ptUnitPrimary, ptUnitSecondary, ptUnitTertiary,
ptSecondaryPrimary, ptTertiarySecondary, ptTertirayTertiary);
// ****************************************************************************
// A TSupplyConnection is a portion (or all) of a full supply path. It has an
// associated ConnectionType that identifies what is being connect to what:
// from a unit to primary, secondary, or tertiary supply source,
// from a secondary to a primary, or
// from a tertiary to a secondary or another tertiary.
//
// A TSupplyConnection can contain a maximum total of 4 Basic hexes, summed over
// all TSupplyLink's.
// ****************************************************************************
TSupplyConnection = record
ConnectionType: TConnectionTypes;
Overseas: Boolean; // Whether this connection includes an overseas link
Links: TSupplyLinkList;
Valid: Boolean; // Whether the connection is functioning or cut.
Validated: Boolean; // Flag used when determining valid connections.
end;
// ****************************************************************************
// Class TSuppyPath
// ****************************************************************************
TSuppyPath = class(TObjectTable)
// ****************************************************************************
// This class contains a list of supply connections (Item[index]) which connect
// a unit to a primary supply source. A TSuppyPath has the following
// restrictions. it can contain:
// (1) only one instance of an overseas link,
// (2) only one connection of type ptSecondaryPrimary.
//
// Note that a TSupplyPath may contain more than 4 Basic hexes in total, since
// that constraint applies to each TSupplyConnection, but not a TSupplyPath.
// ****************************************************************************
private
function GetItem(const Index: Longint): TSupplyConnection;
public
constructor Create;
destructor Destroy; override;
property Item[const Index: Longint]: TSupplyConnection read GetItem; default;
end;


