Skip to content

Fights between ships and the sea: line of sight and reach - #1632

Open
DavideRei wants to merge 1 commit into
Sphereserver:devfrom
DavideRei:fix/ship-sea-los-and-range
Open

DavideRei wants to merge 1 commit into
Sphereserver:devfrom
DavideRei:fix/ship-sea-los-and-range

Conversation

@DavideRei

@DavideRei DavideRei commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

The hull of a ship is made of impassable pieces, so CanSeeLOS between a char on the deck and a char in the water was always blocked: sea monsters never attacked the sailors, and the sailors couldn't target them. The same between the crews of two ships, with spells and ranged weapons (#470). The pieces of the ships the two are on don't block the line of sight anymore (and on a tall piece, like a mast, the walk keeps its height).

Even with the line of sight, a swimming creature can't get adjacent to who stands on the deck, and the other way round. Fight_CalcRange gets the target: when one of the two is on a ship and the other is an NPC able to swim outside of it, the reach is at least 3 tiles.


Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation update
  • Build / CI change
  • Other (please describe): behaviour change

Related Issues

Fixes #470 (attacking from a ship still needs COMBAT_ALLOWHITFROMSHIP, as before).


Testing

  • Compiled with MSVC 2022 (Windows x64, Release) on top of the current dev.
  • Test script below (pr_test_1632.scp), run with and without this PR on a test shard: 5 PASS with the PR; on current dev the 3 [BUG] tests FAIL and the 2 [SANITY] ones pass.
  • The ship and sea part has been running on our shard (a private fork kept aligned with dev). The two ships part is new and was not tested in game with a client.

Checklist

  • Code compiles successfully
  • Changes follow the project's coding style
  • No unrelated code was modified
  • Documentation updated where necessary (Changelog.txt)
  • This PR does not introduce breaking changes (or they are documented)

Additional Notes

If #1631 (floors line of sight) is merged too, its check should skip the pieces of the ship (fShipPiece).

Test script, in the same format as the pr_test.scp of #1627: run .pt_run_all as a GM, anywhere. It uses an NPC (GMs see through everything outside of a fight) and the old line of sight (AdvancedLos=0 for NPCs). Two small ships are created side by side in open water found on map 0, and removed at the end.

pr_test_1632.scp
// =============================================================================
// pr_test_1632.scp  -  line of sight between ships and the sea (PR #1632, issue #470)
//
// USE ON A TEST SHARD ONLY.
//
// AUTOMATED (as a GM, anywhere):
//     .pt_run_all
//   Results go to the server console and to your client as system messages.
//   Tests that need things which could not be set up report SKIP, not PASS.
//   The tests marked [BUG] should FAIL where the bug exists and PASS with the fix.
//   The [SANITY] ones pass on both.
//
// Uses the old line of sight (AdvancedLos=0 for NPCs) and an NPC, because GMs see
// through everything outside of a fight. Two small ships (m_small_ship_n) are created
// side by side in open water found on map 0, with one free water tile between them.
// An NPC on the deck of the first ship checks the line of sight to the water between
// the ships and to the deck of the second one. Everything is removed at the end.
// =============================================================================

[DEFNAME pt_test_defs]
PT_SEA_X0   64
PT_SEA_X1   6000
PT_SEA_Y0   64
PT_SEA_Y1   4000
PT_SEA_STEP 64


// -----------------------------------------------------------------------------
// Helpers
// -----------------------------------------------------------------------------
[FUNCTION PT_ASSERT]
// usage: PT_ASSERT <test_name_no_spaces>,<0|1>
IF (<ARGV[1]>)
    VAR.PT_PASS=<EVAL <VAR.PT_PASS>+1>
    SERV.LOG [PT] PASS: <ARGV[0]>
    SRC.SYSMESSAGE PASS: <ARGV[0]>
ELSE
    VAR.PT_FAIL=<EVAL <VAR.PT_FAIL>+1>
    SERV.LOG [PT] **FAIL**: <ARGV[0]>
    SRC.SYSMESSAGE FAIL: <ARGV[0]>
ENDIF

[FUNCTION PT_SKIP]
VAR.PT_SKIPPED=<EVAL <VAR.PT_SKIPPED>+1>
SERV.LOG [PT] SKIP: <ARGS>
SRC.SYSMESSAGE SKIP: <ARGS>

[FUNCTION PT_RUN_ALL]
VAR.PT_PASS=0
VAR.PT_FAIL=0
VAR.PT_SKIPPED=0
SERV.LOG [PT] ---- Line of sight between ships and the sea ----
PT_SHIP_LOS
SERV.LOG [PT] DONE: pass=<VAR.PT_PASS> fail=<VAR.PT_FAIL> skipped=<VAR.PT_SKIPPED>
SRC.SYSMESSAGE DONE: pass=<VAR.PT_PASS> fail=<VAR.PT_FAIL> skipped=<VAR.PT_SKIPPED>


// -----------------------------------------------------------------------------
// ARGV[0]=x, ARGV[1]=y: 1 if the 13x13 area around it is water (checked every 2 tiles)
// -----------------------------------------------------------------------------
[FUNCTION PT_IS_SEA]
LOCAL.DX=-6
WHILE (<dLOCAL.DX> <= 6)
    LOCAL.DY=-6
    WHILE (<dLOCAL.DY> <= 6)
        LOCAL.T=<SERV.MAP(<EVAL <ARGV[0]>+<dLOCAL.DX>>,<EVAL <ARGV[1]>+<dLOCAL.DY>>,-5,0).TYPE>
        IF !(STRMATCH(t_water,<LOCAL.T>))
            RETURN 0
        ENDIF
        LOCAL.DY=<EVAL <dLOCAL.DY>+2>
    ENDWHILE
    LOCAL.DX=<EVAL <dLOCAL.DX>+2>
ENDWHILE
RETURN 1

// Sets VAR.PT_SEAX/PT_SEAY to the center of some open water on map 0 and returns 1, or returns 0
[FUNCTION PT_FIND_SEA]
LOCAL.X=<DEF.PT_SEA_X0>
WHILE (<dLOCAL.X> <= <DEF.PT_SEA_X1>)
    LOCAL.Y=<DEF.PT_SEA_Y0>
    WHILE (<dLOCAL.Y> <= <DEF.PT_SEA_Y1>)
        IF (<PT_IS_SEA <dLOCAL.X>,<dLOCAL.Y>>)
            VAR.PT_SEAX=<dLOCAL.X>
            VAR.PT_SEAY=<dLOCAL.Y>
            RETURN 1
        ENDIF
        LOCAL.Y=<EVAL <dLOCAL.Y>+<DEF.PT_SEA_STEP>>
    ENDWHILE
    LOCAL.X=<EVAL <dLOCAL.X>+<DEF.PT_SEA_STEP>>
ENDWHILE
RETURN 0

// ARGV[0]=x: creates a small ship facing north at x,PT_SEAY and returns its uid (0 if it wasn't placed)
[FUNCTION PT_NEW_SHIP]
SERV.NEWITEM m_small_ship_n
LOCAL.SHIP=<NEW.UID>
UID.<dLOCAL.SHIP>.P=<ARGV[0]>,<VAR.PT_SEAY>,-5,0
UID.<dLOCAL.SHIP>.MULTICREATE <UID>
IF (<UID.<dLOCAL.SHIP>.P.X>!=<ARGV[0]>)
    UID.<dLOCAL.SHIP>.REMOVE
    RETURN 0
ENDIF
RETURN <dLOCAL.SHIP>


// -----------------------------------------------------------------------------
// Ship 1 at x-3 and ship 2 at x+3 (hulls x-5..x-1 and x+1..x+5), water at x.
// From the deck of ship 1 the line passes through the side of ship 1 (to the water),
// and through the sides of both ships (to the deck of ship 2).
// -----------------------------------------------------------------------------
[FUNCTION PT_SHIP_LOS]
IF !(<PT_FIND_SEA>)
    PT_SKIP ship_los (no open water found in the search area)
    RETURN 0
ENDIF
LOCAL.S1=<PT_NEW_SHIP <EVAL <VAR.PT_SEAX>-3>>
LOCAL.S2=<PT_NEW_SHIP <EVAL <VAR.PT_SEAX>+3>>
IF !((<dLOCAL.S1>) && (<dLOCAL.S2>))
    PT_SKIP ship_los (the ships could not be placed)
    IF (<dLOCAL.S1>)
        UID.<dLOCAL.S1>.REMOVE
    ENDIF
    IF (<dLOCAL.S2>)
        UID.<dLOCAL.S2>.REMOVE
    ENDIF
    RETURN 0
ENDIF
SERV.LOG [PT]   ship 1 <dLOCAL.S1> at <UID.<dLOCAL.S1>.P>, ship 2 <dLOCAL.S2> at <UID.<dLOCAL.S2>.P>

SERV.NEWNPC c_man
LOCAL.A=<NEW.UID>
UID.<dLOCAL.A>.P=<UID.<dLOCAL.S1>.P>
SERV.LOG [PT]   npc at <UID.<dLOCAL.A>.P>, region <UID.<dLOCAL.A>.REGION.NAME> flags <UID.<dLOCAL.A>.REGION.FLAGS>
// [SANITY] the NPC is on the first ship
PT_ASSERT ship_los_sanity_npc_on_ship,<EVAL (<UID.<dLOCAL.A>.REGION.FLAGS> & region_flag_ship)!=0>

// [SANITY] on its own deck (2 tiles towards the bow)
LOCAL.R=<UID.<dLOCAL.A>.CANSEELOS <UID.<dLOCAL.S1>.P.X>,<EVAL <UID.<dLOCAL.S1>.P.Y>-2>,<UID.<dLOCAL.S1>.P.Z>,0>
SERV.LOG [PT]   own deck: <dLOCAL.R>
PT_ASSERT ship_los_sanity_own_deck,<dLOCAL.R>

// [BUG] the water between the two ships, beyond the side of its own ship
LOCAL.R=<UID.<dLOCAL.A>.CANSEELOS <VAR.PT_SEAX>,<VAR.PT_SEAY>,-5,0>
SERV.LOG [PT]   water: <dLOCAL.R>
PT_ASSERT ship_los_deck_to_water,<dLOCAL.R>

// [BUG] the deck of the other ship, beyond the sides of both ships (#470)
LOCAL.R=<UID.<dLOCAL.A>.CANSEELOS <UID.<dLOCAL.S2>.P>>
SERV.LOG [PT]   other ship: <dLOCAL.R>
PT_ASSERT ship_los_deck_to_other_ship,<dLOCAL.R>

// [BUG] and back: from the deck of the other ship to the deck of the first one
UID.<dLOCAL.A>.P=<UID.<dLOCAL.S2>.P>
LOCAL.R=<UID.<dLOCAL.A>.CANSEELOS <UID.<dLOCAL.S1>.P>>
SERV.LOG [PT]   back to ship 1 from <UID.<dLOCAL.A>.P>: <dLOCAL.R>
PT_ASSERT ship_los_other_ship_to_deck,<dLOCAL.R>

UID.<dLOCAL.A>.REMOVE
UID.<dLOCAL.S1>.REMOVE
UID.<dLOCAL.S2>.REMOVE

🤖 Generated with Claude Code

@mtwango

mtwango commented Nov 20, 2026

Copy link
Copy Markdown
Member

related #470

The hull of a ship is made of impassable pieces, so CanSeeLOS between a char on the deck and a char in the water was
always blocked: sea monsters never attacked the sailors, and the sailors couldn't target them. The same between the
crews of two ships (Sphereserver#470). The pieces of the ships the two are on don't block the line of sight anymore (and on a tall
piece, like a mast, the walk keeps its height).

Even with the line of sight, a swimming creature can't get adjacent to who stands on the deck, and the other way round.
Fight_CalcRange gets the target: when one of the two is on a ship and the other is an NPC able to swim outside of it,
the reach is at least 3 tiles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DavideRei
DavideRei force-pushed the fix/ship-sea-los-and-range branch from baac4fd to 23797e4 Compare November 29, 2026 09:06
@DavideRei

Copy link
Copy Markdown
Contributor Author

Yes, it's the same problem. This PR fixed the line of sight between a ship and the sea in the old LOS (as noted in #470, AdvancedLos already let it through), but between two ships only the pieces of the attacker's ship were skipped, so the hull of the other ship still blocked. Now the pieces of both ships are skipped, so it fixes #470 too. COMBAT_ALLOWHITFROMSHIP is still needed to attack from a ship, as before.

I added a test script to the description (pr_test_1632.scp): on current dev the 3 [BUG] tests fail, with the PR all 5 pass. I also rebased the branch on the current dev.

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.

2 participants