Skip to content

refactor: unify transport point calculation - #138

Merged
KagamiChan merged 4 commits into
masterfrom
refactor/tp-calculation
Sep 15, 2026
Merged

KagamiChan merged 4 commits into
masterfrom
refactor/tp-calculation

Conversation

@KagamiChan

@KagamiChan KagamiChan commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Consolidate ordinary and tank transport into one formula-driven calculation, using Poi's existing ship and equipment member/master pairs directly. TP no longer depends on lib-battle view models, a TP adapter, or intermediate normalized objects.

  • Apply private rule data to ship/equipment-category base values and item-specific bonuses.
  • Use the same scoring function for planned and deliverable TP, excluding ineligible ships before evaluating the Kinu Kai Ni bonus.
  • Preserve separate main/escort fleet rounding, the existing once-per-task-force Kinu bonus, and cargo-only display behavior. An eligible Kinu retains the bonus even if another Kinu has retreated.
  • Read ship types and equipment categories from master data, and HP, ship identity, retreat IDs, and equipment identity from member data. Poi's equipment selector already includes the expansion slot.
  • Remove the duplicated legacy calculation entry points and the TP adapter.
  • Encapsulate TP selectors, mode selection, visibility, icons, and A-rank tooltips in the standalone TransportPoints component. BattleViewArea only supplies sortieState; rendering uses planned/deliverable directly without an intermediate display model.
  • Add English TP formula notes, including source links, contribution tables, cross-source discrepancies, and explicitly unresolved rules. The notes document formulas, not implementation design.

Implements the refactoring suggestion on #137, updated to use existing Poi inputs without an adapter.

Scope and evidence

This does not introduce new map rules or a landing-point snapshot mechanism. Eligibility still uses Poi member HP rather than simulated battle HP. Existing rounding and Kinu behavior are preserved without presenting them as fully established source rules.

The formula document was recovered, and the complete ordinary/tank tables on Zekamashi were rechecked on 2026-09-15. The Japanese Wiki recheck was blocked by a verification page; its earlier 2026-09-01 notes are retained with that limitation stated. The English Wiki was not rechecked this time.

Validation

  • npm run validate passed: typecheck, lint, full coverage suite, production build, Storybook build, and package dry-run.
  • Full test suite: 11 files, 93 tests passed.
  • TP calculator: 100% statement/line coverage; 85.71% branch coverage.
  • Tests cover equipment-category bases and tank bonuses, fractional contributions, per-fleet rounding, Kinu eligibility/order, raw HP boundaries, member-ID retreat, empty ship/equipment slots, missing ship master data, and expansion-slot equipment counted once.
  • Rendered component tests cover port dual indicators, numeric/string map IDs, cargo and zero-total hiding, retreat-dependent values, and A-rank tooltips. Missing Poi runtime modules are mocked only in tests, with narrowly scoped Vitest resolution.
  • Recorded fleet examples remain normal TP 205 and tank TP 446 / 468.

Existing non-failing module-type and Storybook chunk-size warnings remain. The package dry-run also includes local generated coverage/Storybook output under the existing packaging configuration; those outputs are not included in this PR, and packaging changes are out of scope.

@petit-chiba petit-chiba Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:

No actionable findings.

The refactor preserves prior behavior in src/utils/transport.ts and the new src/utils/transport-adapter.ts: per-fleet flooring, the ship-type and equipment-category tables, the tank item-bonus table and the unscaled Kinu bonus, HP/retreat eligibility (retreat IDs are member ship IDs), expansion-slot de-duplication (transformToLibBattleClass nulls the ex slot inside poi_slot and exposes it only as poi_slot_ex), and the cargo-presence display gate all reproduce the pre-refactor implementation. The sole behavioral change is the intended one: deliverable (and thus the view's actual) now grants the Kinu +8 whenever an eligible Kinu participates instead of binding it to the first Kinu in array order, so a retreated first Kinu no longer suppresses a still-present second one. The recorded 205/446/468 fixtures still hold under the normalized input path.

@petit-chiba petit-chiba Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:

No actionable findings.

The direct-from-Poi calculateTransport path reproduces the pre-refactor behavior: the ship-type and equipment-category tables, the tank 0.75 base scaling plus item-specific bonuses, per-fleet Math.floor (verified against the recorded 205 / 446 fixtures), HP/retreat eligibility, and the cargo-presence gate on total all match the prior implementation. The only functional change is the intended one: the Kinu Kai Ni +8 is now granted whenever an eligible Kinu participates rather than being bound to the first Kinu in array order, so a retreated first Kinu no longer suppresses a still-present second one. Expansion-slot and empty-slot handling stays single-count through the aligned selector arrays, and the removed getTransportPoint / getTransportPointFromFleets entry points have no remaining callers (utils/index.ts re-exports the module, but nothing imports the deleted symbols).

@petit-chiba petit-chiba Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review:

No actionable findings.

The extracted TransportPoints component (src/views/transport-points.tsx:66) reproduces the pre-extraction path exactly: the hasTransportCargo && planned > 0 visibility gate, the deliverable / planned label, and the Math.floor(deliverable * 0.7) A-rank tooltip all match the former displayedTP/shownTP logic in battle-view-area.tsx, and the moved inEvent/escapedShipId/tankTransportMaps selectors are unchanged. calculateTransport (src/utils/transport.ts:191) keeps per-fleet flooring, reads ship type/equipment category from master data and identity/HP from member data, counts the expansion slot once, and grants the unscaled Kinu +8 once per task force; the only functional change is the intended one where an eligible Kinu retains the bonus when another Kinu retreated. git grep confirms the removed getTransportPoint/getTransportPointFromFleets/transportPoints/isTankTransportMap/TPResult exports have no remaining callers, and the new vitest.config.ts host-module stubs are only consumed by the new test (no other test imports those host modules), so no reachable correctness, security, or CI defect is introduced.

@KagamiChan
KagamiChan merged commit e0deeca into master Sep 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant