Skip to content

Add naval AA upgrades to warships#3566

Closed
PGrayCS wants to merge 1 commit intoopenfrontio:mainfrom
PGrayCS:feat/mobile-naval-aa-warships
Closed

Add naval AA upgrades to warships#3566
PGrayCS wants to merge 1 commit intoopenfrontio:mainfrom
PGrayCS:feat/mobile-naval-aa-warships

Conversation

@PGrayCS
Copy link
Copy Markdown
Contributor

@PGrayCS PGrayCS commented Apr 2, 2026

Description:

  • Make warships upgradable and give level 2+ warships SAM-style interception against sea-targeted nukes.
  • Share air-defense targeting logic between SAM launchers and upgraded warships, including MIRV warhead handling.
  • Update client air-defense visuals and nuke trajectory preview to include upgraded warships.
  • No new user-facing strings were added.
  • Verified locally with npm test and npm run build-prod.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

Just reply here

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Walkthrough

This pull request extends warship units with air defense capabilities, allowing them to intercept incoming missiles when upgraded. The changes unify SAM launcher and warship targeting logic into a shared AirDefenseTargetingSystem, update visual rendering layers to display both unit types, and introduce warship-specific interception handling for MIRV warheads with cooldown management.

Changes

Cohort / File(s) Summary
Air Defense Targeting System
src/core/execution/utils/AirDefenseUtils.ts
New module introducing AirDefenseTargetingSystem class and findMirvWarheadTargets helper to centralize interception target selection logic, with caching of precomputed nuke interception tiles and validation against current game state.
Warship & SAM Execution
src/core/execution/WarshipExecution.ts, src/core/execution/SAMLauncherExecution.ts
Refactored SAMLauncher's internal targeting system into the shared AirDefenseTargetingSystem. Added handleAirDefense() to warship with MIRV detection, missile launching, cooldown tracking, and SAM target acquisition; updated SAMLauncher to use the new system and extracted MIRV filtering into utility function.
Trajectory & Range Visualization
src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts, src/client/graphics/layers/SAMRadiusLayer.ts, src/client/graphics/layers/StructureDrawingUtils.ts
Extended interception and range display to handle both UnitType.SAMLauncher and UnitType.Warship. Added ocean-tile and level-gating rules for warship interception; updated range visualization to track both unit types and compute circles accordingly.
UI & Structure Layers
src/client/graphics/layers/StructureIconsLayer.ts, src/client/graphics/layers/UILayer.ts, src/client/graphics/layers/UnitDisplay.ts
Updated ghost range resolution to recognize warships as air-defense units; added missile loading bar for upgraded warships; refactored structure hover toggling into a helper mapping warship hovers to port + warship structures.
Configuration & Game State
src/core/configuration/DefaultConfig.ts, src/core/game/GameView.ts, src/core/game/UnitImpl.ts
Marked warships as upgradable; unified SAM cooldown handling for both SAMLauncher and Warship; extended missile timer queue management to warships on level changes.
Test Coverage
tests/Warship.test.ts, tests/client/graphics/layers/NukeTrajectoryPreviewLayer.test.ts, tests/client/graphics/layers/SAMRadiusLayer.test.ts, tests/client/graphics/layers/UnitDisplay.test.ts
Added warship upgrade mechanics tests, interception coverage (single/multiple warships, MIRV warheads), range visualization tests for upgraded warships, and UI hover behavior tests.

Sequence Diagram

sequenceDiagram
    actor TickLoop as Tick Loop
    participant WE as WarshipExecution
    participant ADTS as AirDefenseTargetingSystem
    participant TargetDB as Target Units
    participant ME as SAMMissileExecution

    TickLoop->>WE: tick(ticks)
    alt Non-TradeShip Target
        WE->>WE: Perform patrol/shoot logic
    end
    
    WE->>WE: handleAirDefense(ticks)
    
    alt Warship Level > 1
        WE->>ADTS: new AirDefenseTargetingSystem
        ADTS->>TargetDB: Search MIRVs within range
        
        alt MIRVs Found
            ADTS-->>WE: MIRV list
            WE->>WE: Delete warheads, record stat
            WE->>WE: Display intercept message
        else No MIRVs
            ADTS->>TargetDB: Find single target via cache
            ADTS-->>WE: AirDefenseTarget
            WE->>ME: Enqueue SAMMissileExecution
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

⚓ A warship rises, hull ablaze with might,
Once just a trader sailing through the night,
Now missiles sing when atom bombs draw near,
Two SAMs in one, a dual-front frontier! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding upgrade capability to warships that enables anti-air (AA) interception at higher levels.
Description check ✅ Passed The pull request description clearly outlines the key changes: making warships upgradable, adding SAM-style interception for level 2+ warships, sharing air-defense targeting logic, and updating client visuals.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
tests/client/graphics/layers/UnitDisplay.test.ts (1)

5-24: Prefer testing the emitted ToggleStructureEvent.

These assertions only exercise a private helper through as any, so they will still pass if the @mouseenter wiring stops emitting the right event. Rendering one item and checking the emitted structureTypes would cover the real behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/client/graphics/layers/UnitDisplay.test.ts` around lines 5 - 24, The
tests currently call the private helper hoverStructureTypes on UnitDisplay
directly; instead render a UnitDisplay instance (or the component that contains
the unit element), simulate a `@mouseenter` on a warship and a nuke unit, and
assert the emitted ToggleStructureEvent payload (the structureTypes field)
matches expected arrays; locate the UnitDisplay component and its event emitter
(ToggleStructureEvent) and replace the direct hoverStructureTypes calls with DOM
event simulation that checks the emitted event.structureTypes for
UnitType.Warship, UnitType.AtomBomb and UnitType.HydrogenBomb cases so the test
verifies the actual `@mouseenter` wiring rather than a private helper.
src/client/graphics/layers/StructureIconsLayer.ts (1)

565-584: Consider sharing the air-defense range rule.

resolveGhostRangeLevel() and src/client/graphics/layers/StructureDrawingUtils.ts now both encode the same “warships only have AA range above level 1” rule. A small shared helper would make the ghost preview and the actual range renderer harder to drift apart.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/client/graphics/layers/StructureIconsLayer.ts` around lines 565 - 584,
Extract the duplicated “warships only have AA range above level 1” logic into a
single helper (e.g., getAirDefenseRangeLevel or airDefenseRangeApplies) and use
it from resolveGhostRangeLevel and the code in StructureDrawingUtils;
specifically, replace the inline checks in resolveGhostRangeLevel (the
UnitType.SAMLauncher / UnitType.Warship branch and the canUpgrade handling that
returns existing.level()+1 or 1/undefined) with a call to the new helper so both
the ghost preview (resolveGhostRangeLevel) and the renderer
(StructureDrawingUtils) share the same rule implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/client/graphics/layers/StructureIconsLayer.ts`:
- Around line 565-584: Extract the duplicated “warships only have AA range above
level 1” logic into a single helper (e.g., getAirDefenseRangeLevel or
airDefenseRangeApplies) and use it from resolveGhostRangeLevel and the code in
StructureDrawingUtils; specifically, replace the inline checks in
resolveGhostRangeLevel (the UnitType.SAMLauncher / UnitType.Warship branch and
the canUpgrade handling that returns existing.level()+1 or 1/undefined) with a
call to the new helper so both the ghost preview (resolveGhostRangeLevel) and
the renderer (StructureDrawingUtils) share the same rule implementation.

In `@tests/client/graphics/layers/UnitDisplay.test.ts`:
- Around line 5-24: The tests currently call the private helper
hoverStructureTypes on UnitDisplay directly; instead render a UnitDisplay
instance (or the component that contains the unit element), simulate a
`@mouseenter` on a warship and a nuke unit, and assert the emitted
ToggleStructureEvent payload (the structureTypes field) matches expected arrays;
locate the UnitDisplay component and its event emitter (ToggleStructureEvent)
and replace the direct hoverStructureTypes calls with DOM event simulation that
checks the emitted event.structureTypes for UnitType.Warship, UnitType.AtomBomb
and UnitType.HydrogenBomb cases so the test verifies the actual `@mouseenter`
wiring rather than a private helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90ef326b-8c44-481c-bd65-22fb28e212e4

📥 Commits

Reviewing files that changed from the base of the PR and between 21c2861 and c53a87c.

📒 Files selected for processing (16)
  • src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts
  • src/client/graphics/layers/SAMRadiusLayer.ts
  • src/client/graphics/layers/StructureDrawingUtils.ts
  • src/client/graphics/layers/StructureIconsLayer.ts
  • src/client/graphics/layers/UILayer.ts
  • src/client/graphics/layers/UnitDisplay.ts
  • src/core/configuration/DefaultConfig.ts
  • src/core/execution/SAMLauncherExecution.ts
  • src/core/execution/WarshipExecution.ts
  • src/core/execution/utils/AirDefenseUtils.ts
  • src/core/game/GameView.ts
  • src/core/game/UnitImpl.ts
  • tests/Warship.test.ts
  • tests/client/graphics/layers/NukeTrajectoryPreviewLayer.test.ts
  • tests/client/graphics/layers/SAMRadiusLayer.test.ts
  • tests/client/graphics/layers/UnitDisplay.test.ts

@github-project-automation github-project-automation bot moved this from Triage to Final Review in OpenFront Release Management Apr 2, 2026
@ryanbarlow97
Copy link
Copy Markdown
Contributor

please add some images/videos and ensure the description is following the the template

@evanpelle
Copy link
Copy Markdown
Collaborator

Feature is not in scopre or approved

@evanpelle evanpelle closed this Apr 3, 2026
@github-project-automation github-project-automation bot moved this from Final Review to Complete in OpenFront Release Management Apr 3, 2026
@PGrayCS PGrayCS deleted the feat/mobile-naval-aa-warships branch April 3, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

4 participants