# Hangar repair and construction

The service screens operate on GO's shell HERC records, distinct from the live
simulator damage arrays. Their prices come from CFG/DAMAGE.DAT and the eight
chassis price/duration entries. Original-code comparisons are retained alongside
the C++ fixtures; the comparison installation and its saves are never modified.

## Detailed repair (MENU1920)

GO 0x2f1aa saves all 33 condition words and the current material budget.
The 0x2f8d4 handler edits nine internal components, six armour groups, or the
chassis's equipment mounts. Armour groups average their constituent surfaces
when read and set all those surfaces together when changed.

Condition bands begin at 91, 75, 52, 1 and 0. Plus charges the difference to the
next threshold (or 100) with integer truncation. Equal available material is
sufficient here; the separate Repair All routine uses a strict greater-than
test. Minus reverses increases only as far as the state when this dialog opened,
including its band-dependent refund rules. Cancel restores every condition and
the budget, including the selected pilot's share.

Two peculiarities are confirmed by running the original handler:

- Equipment repair quotes use the mount index in the weapon-price table, rather
  than the weapon ID fitted there (0x38bb9). Whole-HERC repair uses the weapon ID.
- If the budget has changed when Proceed is pressed, the selected component is
  set from the current condition selector once more, without another charge.
  For example an internal component at 10 reaches 52 after one paid increase,
  then reaches 75 on Proceed. Selecting a different row before accepting can
  redirect this last change. This behaviour is retained in the faithful port.

The allocated counter and quote are signed 16-bit values. The transaction
captures retain them after every event rather than deriving them from a final
condition alone.

## Unassigned-HERC corruption

Original 0x29bf3 locates the pilot assigned to the selected HERC, then writes its
remaining repair share at crew_state + 0x35 + pilot * 0x25. A missing assignment
returns -1, so this writes four bytes at crew_state + 0x10: the crew-count and
crew-cursor words. The detailed editor also updates shares using the current
cursor without a negative-index guard.

The capture tool includes a direct original-code demonstration of this write.
The C++ port performs the repair and budget transaction but skips the pilot-share
write when there is no assigned pilot. It does not reproduce header corruption.
This is a deliberate bounded-memory departure, not an alternate repair economy.

## Repair policy

The three original button labels describe the player's responsibility:
REPAIRS ALL selects policy 0 (no automatic repairs); REPAIR MINE selects policy 1
(wingmates are repaired automatically); AUTO REPAIR selects policy 2 (all active,
assigned pilots are repaired automatically). Choosing a policy returns directly
to the repair screen. Escape does not dismiss the original preference selector.

## Construction and scrap

The eight chassis cost 50, 60, 80, 100, 120, 140, 170 and 200 thousand material
units. Construction takes 1, 1, 2, 2, 2, 3, 3 and 3 mission returns respectively.
The reserved construction slot is excluded from ordinary HERC cycling.

A freshly constructed record has empty mounts, zero missile-value words,
condition 100 except the unused pilot condition at zero, and extra word 2.
The construction timer prevents assignment before completion.

Scrapping returns mounted equipment with condition at least 80 to the inventory
head. Worse equipment instead yields its condition-scaled price. Chassis
material comes from the six armour and nine internal component groups. A build
cancellation supplies its construction-value credit instead. The scrap warning
quotes chassis material only; it does not include damaged-weapon credit.
Cancellation can leave the empty construction slot reserved. Original 0x29e01
checks whether a HERC actually occupies it and otherwise does nothing. The port
now does the same, rather than rejecting this valid empty reservation.

MENU2000 cycles only through unlocked chassis. While a HERC is being built, the
cycle controls are disabled and BUILD becomes SCRAP. Cancellation re-enables
cycling but does not recompute whether the refunded material covers another
build. Pressing BUILD immediately can therefore overdraw material after a
partially completed build was scrapped. The original unsigned budget checks then
see that wrapped balance. This sequence is captured and retained.

The BLUEHERX.DBA blueprint and the mass/speed/mount tables at 0x808a8, 0x808c8
and 0x803c8 drive the construction panel. Its text and progress presentation is
0x2845c. The separate registered SALVAGE layout 2010 is not the ordinary build
allocation step: the retained build-click capture remains in screen 2000.

## Verification boundary

- capture_component_repair_fixtures.py: 128 original event sequences, 5,323 edits,
  including selection, all three groups, increases, refunds, acceptance and
  cancellation. Constructor, pricing and condition handlers run unchanged.
- capture_hangar_transactions.py: all eight original construction records and
  128 scrap/cancel transactions, including equipment-stack order, selected HERC,
  assignments, budget and construction counters.
- capture_construction_menu.py: 96 original screen sequences, 1,424 events,
  including unlocked-chassis cycling, exact affordability, build/cancel, resumed
  partial construction, button states and the overdraw quirk.
- The earlier hangar-service check covers 6,400 whole-repair quotes, 1,280
  transactions, three policies and 25 construction-progress states.

UI control drawing, final bay-art refresh, and object deallocation are explicit
capture boundaries. These tests compare service state. SHELL.md describes the
separate artwork and resident-animation comparisons.
