Add naval AA upgrades to warships#3566
Conversation
|
|
WalkthroughThis 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 Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/client/graphics/layers/UnitDisplay.test.ts (1)
5-24: Prefer testing the emittedToggleStructureEvent.These assertions only exercise a private helper through
as any, so they will still pass if the@mouseenterwiring stops emitting the right event. Rendering one item and checking the emittedstructureTypeswould 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()andsrc/client/graphics/layers/StructureDrawingUtils.tsnow 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
📒 Files selected for processing (16)
src/client/graphics/layers/NukeTrajectoryPreviewLayer.tssrc/client/graphics/layers/SAMRadiusLayer.tssrc/client/graphics/layers/StructureDrawingUtils.tssrc/client/graphics/layers/StructureIconsLayer.tssrc/client/graphics/layers/UILayer.tssrc/client/graphics/layers/UnitDisplay.tssrc/core/configuration/DefaultConfig.tssrc/core/execution/SAMLauncherExecution.tssrc/core/execution/WarshipExecution.tssrc/core/execution/utils/AirDefenseUtils.tssrc/core/game/GameView.tssrc/core/game/UnitImpl.tstests/Warship.test.tstests/client/graphics/layers/NukeTrajectoryPreviewLayer.test.tstests/client/graphics/layers/SAMRadiusLayer.test.tstests/client/graphics/layers/UnitDisplay.test.ts
|
please add some images/videos and ensure the description is following the the template |
|
Feature is not in scopre or approved |
Description:
npm testandnpm run build-prod.Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
Just reply here