Package megamek.common.board
Class BridgeConstruction
java.lang.Object
megamek.common.board.BridgeConstruction
Validates sites for and places single-hex bridges that are constructed during a game, as opposed to bridges that are
part of the board file. Used by Bridge-Building Engineer infantry (TO:AUE p.152) and intended for reuse by vehicle
Bridge-Layer equipment (TM p.242). Placement rules (TO:AUE p.152): a bridge may be placed in any water hex that
connects to at least one land hex or another bridge, or across a dry canyon of any depth (a hex below its rims). A
single-hex span changes at most one level (the multi-level bridge rule of at most 1 level per hex), so its two
mount banks must be within one level; a deeper canyon-floor or deep-water far side is exempt and continued by a
further span. A building hex cannot be bridged. Note: ramping multi-hex bridges (a sloped deck) are not modelled -
each bridge hex has a single flat deck level.
The Construction Factor of the new bridge is supplied by the caller, since it differs by source: engineers raise bridges with CF 15/40 (doubled over water), while Bridge-Layer equipment deploys bridges with its own CF values and no water doubling.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe reason a hex is or is not a valid bridge-repair site, so callers can explain a rejection to the player.static enumThe reason a bridge site is or is not buildable, so callers can explain a rejection to the player. -
Method Summary
Modifier and TypeMethodDescriptionbridgeRepairIssue(Board board, Coords target, int exits) Checks whether a single destroyed bridge section may be rebuilt in the target hex (unofficial bridge-repair option).bridgeSiteIssue(Board board, Coords target, int exits) static intexitsFor(int firstDirection, int secondDirection) static booleanisAnchoringBank(Hex bank, Hex targetHex) static booleanisBridgeRepairSite(Board board, Coords target, int exits) static booleanisOverWater(Hex hex) static booleanisValidBridgeExits(int exits) static booleanisValidBridgeSite(Board board, Coords target, int exits) Checks whether a single-hex bridge with the given orientation may be constructed in the target hex (TO:AUE p.152): the hex exists and holds no structure, both banks are on the board, and at least one bank anchors the span (land/rim over a canyon, or a bridge).static IBuildingplaceBridge(Board board, Coords target, int exits, int bridgeType, int cf) Places a finished single-hex bridge in the target hex: adds the bridge terrain, registers the bridge as a board structure so it can take damage and collapse, and recomputes terrain exits around the hex.static IBuildingplaceRepairedBridge(Board board, Coords target, int exits, int bridgeType, int cf) Rebuilds a single destroyed bridge section in the gap hex (unofficial repair option): adds the bridge terrain at the surviving span's deck height so the section reconnects, registers it as a board structure, and recomputes terrain exits.
-
Method Details
-
isValidBridgeExits
public static boolean isValidBridgeExits(int exits) - Parameters:
exits- the exits bitmask to check- Returns:
trueif the bitmask describes a legal single-hex bridge orientation: exactly two distinct connected hexsides. Opposite sides give a straight bridge; non-opposite sides give a curved bridge. The finished bridge uses the tileset image matching this exits value.
-
exitsFor
public static int exitsFor(int firstDirection, int secondDirection) - Parameters:
firstDirection- one connected hexside direction (0-5)secondDirection- the other connected hexside direction (0-5)- Returns:
- The exits bitmask connecting the two given hexsides.
-
isValidBridgeSite
Checks whether a single-hex bridge with the given orientation may be constructed in the target hex (TO:AUE p.152): the hex exists and holds no structure, both banks are on the board, and at least one bank anchors the span (land/rim over a canyon, or a bridge). If both banks are mount points they must be within one level (a single-hex span changes at most one level); a deeper canyon-floor or deep-water far side is exempt (chaining).- Parameters:
board- the board to build ontarget- the hex the bridge would be placed in, or null (returnsfalse)exits- exits bitmask of the two hexsides the bridge would connect- Returns:
trueif the bridge may be constructed there.
-
bridgeSiteIssue
public static BridgeConstruction.BridgeSiteIssue bridgeSiteIssue(Board board, @Nullable Coords target, int exits) - Parameters:
board- the board to build ontarget- the hex the bridge would be placed in, or nullexits- exits bitmask of the two hexsides the bridge would connect- Returns:
- Why the site is or is not buildable (see
BridgeConstruction.BridgeSiteIssue). The single source of truth for bridge placement validity;isValidBridgeSite(megamek.common.board.Board, megamek.common.board.Coords, int)returns whether this isVALID.
-
isAnchoringBank
- Parameters:
bank- a hex adjacent to a bridge site (e.g. the bridgelayer's own hex)targetHex- the hex a bridge would be placed in- Returns:
- whether the bank can anchor a bridge in the target hex: over water it must be land/shallow (or already hold a bridge); over a dry gap it must be a rim higher than the target floor (or hold a bridge). Exposes the internal anchor test for callers that must require a specific bank to anchor - e.g. the AVLB bridgelayer's own hex, which must be a rim/land rather than the canyon floor. TM p.242 / TW.
-
isOverWater
- Parameters:
hex- the hex to check- Returns:
trueif the hex is a water hex for bridge purposes. A water hex (Total Warfare p.32) is one covered by a stream, river, swamp, pond or lake, so this is any hex holding water of any depth (streams/rivers/ponds/lakes), a swamp, or rapids. A bridge may be placed in any water hex (when adjacent to a land hex or another bridge), and a bridge over water gains double CF from its flotation devices. Shared by Bridge-Building Engineers (TO:AUE p.152) and the Bridge-Layer / AVLB (TM p.242 / TW) so both use the same water-hex definition.
-
placeBridge
Places a finished single-hex bridge in the target hex: adds the bridge terrain, registers the bridge as a board structure so it can take damage and collapse, and recomputes terrain exits around the hex. The deck sits at the lower anchoring rim (the two rims are within one level) so units cross at grade and a chain of spans stays level. The caller is responsible for validating the site withisValidBridgeSite(Board, Coords, int)and for sending the changed hex and the new building to the clients.- Parameters:
board- the board to build ontarget- the hex the bridge is placed inexits- exits bitmask of the two hexsides the bridge connectsbridgeType- the bridge type as aBuildingTypevalue (1 = light, 2 = medium)cf- the Construction Factor of the new bridge- Returns:
- The newly registered bridge structure, for sending to the clients.
-
isBridgeRepairSite
- Parameters:
board- the board to repair ontarget- the gap hex the section would be rebuilt in, or nullexits- exits bitmask of the two hexsides the repaired section would connect- Returns:
trueif a destroyed bridge section may be rebuilt in the target hex (unofficial). SeebridgeRepairIssue(Board, Coords, int)for the full set of conditions.
-
bridgeRepairIssue
public static BridgeConstruction.BridgeRepairIssue bridgeRepairIssue(Board board, @Nullable Coords target, int exits) Checks whether a single destroyed bridge section may be rebuilt in the target hex (unofficial bridge-repair option). A repair fills a gap - a hex that currently holds no structure - and must reconnect the broken run: at least one connected neighbor is a surviving span of a bridge pointing back into the hex (that span also fixes the repaired deck height, so the section lines up with the rest of the bridge), and the far side either continues the bridge with another surviving span or reaches a bank a unit can step on/off of. A gap flanked only by banks is a fresh build, not a repair, and a span whose far side is open water or deep canyon with no bank cannot be repaired (the run is rebuilt inward from a span or bank). Any underlying rubble or water left by the collapse is preserved.- Parameters:
board- the board to repair ontarget- the gap hex the section would be rebuilt in, or nullexits- exits bitmask of the two hexsides the repaired section would connect- Returns:
- Why the site is or is not a repairable gap (see
BridgeConstruction.BridgeRepairIssue).
-
placeRepairedBridge
public static IBuilding placeRepairedBridge(Board board, Coords target, int exits, int bridgeType, int cf) Rebuilds a single destroyed bridge section in the gap hex (unofficial repair option): adds the bridge terrain at the surviving span's deck height so the section reconnects, registers it as a board structure, and recomputes terrain exits. Underlying rubble or water left by the collapse is preserved (only bridge terrain is added). The caller is responsible for validating the site withisBridgeRepairSite(Board, Coords, int)and for sending the changed hex and the new structure to the clients.- Parameters:
board- the board to repair ontarget- the gap hex the section is rebuilt inexits- exits bitmask of the two hexsides the repaired section connectsbridgeType- the bridge type as aBuildingTypevalue (1 = light, 2 = medium)cf- the Construction Factor of the rebuilt section- Returns:
- The newly registered bridge structure, for sending to the clients.
-