Skip to content

RESTEST: a bare ID is an item, like in RESCOUNT - #1653

Open
DavideRei wants to merge 1 commit into
Sphereserver:devfrom
DavideRei:fix/restest-bare-item-id
Open

DavideRei wants to merge 1 commit into
Sphereserver:devfrom
DavideRei:fix/restest-bare-item-id

Conversation

@DavideRei

@DavideRei DavideRei commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #1430. RESTEST loaded its resource list with RES_UNKNOWN, so an item given by number (RESTEST 1 01034, or a def holding a hex ID) failed with "Bad resource list id" and returned 0, while RESCOUNT reads a number as an item ID (ResourceGetID(RES_ITEMDEF, ...)).

CResourceQty::Load and CResourceQtyArray::Load take an optional default type for bare IDs (default RES_UNKNOWN, the current behaviour). RESTEST passes RES_ITEMDEF, like RESCOUNT. The other lists that only take items do the same: CONSUME (chars), CONTCONSUME (containers), RESOURCES of ITEMDEF/CHARDEF and RESOURCES of SPELL (reagents). The lists that mix different types (SKILLMAKE, SKILLTEST, DESIRES, AVERSIONS, RANDGROUP RESOURCES) are unchanged: there a bare ID is still refused, since it could be a skill, a char or an item. A defname still carries its own type (skills, typedefs, etc.), and a bare ID of 0 is still refused with the same error.

Note: with two numbers the first one is the quantity ("qty id"), as before.


Type of Change

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

Related Issues

Fixes #1430


Testing

  • Compiled with MSVC 2022 (Windows x64, Release) on top of the current dev.
  • Test script below (pr_test_1653.scp), run with and without this PR on a test shard: 7 PASS with the PR; on current dev the 4 [BUG] tests FAIL (with "Bad resource list id") and the 3 [SANITY] ones pass, including RESTEST with a typedef.
  • RESOURCES of SPELL is not covered by the script (it would need a test spell): it goes through the same CResourceQtyArray::Load as the ITEMDEF one.

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

Test script, in the same format as the pr_test.scp of #1627: run .pt_run_all as a GM, anywhere. It puts a saw (01034) in the backpack and removes it at the end; its ITEMDEF gives RESOURCES by number, so on dev it logs "Bad resource list id" when the scripts are loaded.

pr_test_1653.scp
// =============================================================================
// pr_test_1653.scp  -  a bare item ID in resource lists (PR #1653, issue #1430)
//
// 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.
//
// A saw (item 01034) is put in the backpack of the GM, then it is looked for and
// consumed giving its number instead of its defname. The itemdef below gives its
// RESOURCES by number too: on dev it logs "Bad resource list id" when the scripts
// are loaded. The items created are removed at the end.
// =============================================================================

[ITEMDEF i_pt_1653_made]
ID=01034
NAME=pt_1653 test item
RESOURCES=2 01034


// -----------------------------------------------------------------------------
// 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] ---- Bare item ID in resource lists ----
PT_BARE_ID
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>

// Puts a new saw (01034) in the backpack and returns its uid
[FUNCTION PT_NEW_SAW]
SERV.NEWITEM 01034
NEW.CONT=<FINDLAYER.21.UID>
RETURN <NEW.UID>


// -----------------------------------------------------------------------------
[FUNCTION PT_BARE_ID]
IF !(<FINDLAYER.21.UID>)
    PT_SKIP bare_id (no backpack)
    RETURN 0
ENDIF
// start with no saws in the backpack
WHILE (<RESCOUNT 01034> > 0)
    FINDID.01034.REMOVE
ENDWHILE
LOCAL.SAW=<PT_NEW_SAW>
LOCAL.TYPE=<UID.<dLOCAL.SAW>.TYPE>
SERV.LOG [PT]   saw <dLOCAL.SAW> id=<UID.<dLOCAL.SAW>.ID> type=<LOCAL.TYPE>

// [SANITY] RESCOUNT already reads a number as an item
PT_ASSERT bare_id_sanity_rescount,<EVAL <RESCOUNT 01034>==1>
// [SANITY] a defname carries its own type: item and typedef
PT_ASSERT bare_id_sanity_restest_defname,<EVAL <RESTEST 1 i_saw>==1>
PT_ASSERT bare_id_sanity_restest_typedef,<EVAL <RESTEST 1 <LOCAL.TYPE>>==1>

// [BUG] RESTEST with the number (#1430)
PT_ASSERT bare_id_restest,<EVAL <RESTEST 1 01034>==1>

// [BUG] CONSUME with the number
CONSUME 1 01034
PT_ASSERT bare_id_consume,<EVAL <RESCOUNT 01034>==0>
IF (<RESCOUNT 01034> > 0)
    FINDID.01034.REMOVE
ENDIF

// [BUG] CONTCONSUME with the number, on the backpack
LOCAL.SAW=<PT_NEW_SAW>
FINDLAYER.21.CONTCONSUME 1 01034
PT_ASSERT bare_id_contconsume,<EVAL <RESCOUNT 01034>==0>
IF (<RESCOUNT 01034> > 0)
    FINDID.01034.REMOVE
ENDIF

// [BUG] RESOURCES of an itemdef given by number
LOCAL.RES=<SERV.ITEMDEF.i_pt_1653_made.RESOURCES>
SERV.LOG [PT]   i_pt_1653_made RESOURCES=<LOCAL.RES>
PT_ASSERT bare_id_itemdef_resources,<EVAL STRMATCH(*i_saw*,<LOCAL.RES>)>

🤖 Generated with Claude Code

@mtwango

mtwango commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

This would be good to implement in other places, where CResourceQtyArray::Load is used and expects items (if there are any).

@mtwango

mtwango commented Nov 6, 2026

Copy link
Copy Markdown
Member

And what will happen, if I try to search for resource different from item? Like <src.restest 1 t_saw>

RESTEST loaded its list with RES_UNKNOWN, so an item given by number
(01034, or a def holding a hex ID) failed with 'Bad resource list id'
and returned 0, while RESCOUNT reads it as an item. CResourceQtyArray::Load
takes the type to give to bare IDs; RESTEST passes RES_ITEMDEF.

The other lists that only take items do the same: CONSUME, CONTCONSUME,
RESOURCES of ITEMDEF/CHARDEF and of SPELL. The lists that mix different
types (SKILLMAKE, SKILLTEST, DESIRES, AVERSIONS, RANDGROUP) keep refusing
a bare ID.

Fixes Sphereserver#1430

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DavideRei
DavideRei force-pushed the fix/restest-bare-item-id branch from 7944ef8 to bc933c6 Compare November 29, 2026 09:14
@DavideRei

Copy link
Copy Markdown
Contributor Author

About <src.restest 1 t_saw>: nothing changes for it. The default type is used only for a bare number. A defname carries its own type, so a typedef is still a typedef and counts the items of that type, as before (the same for skills and the other types). An unknown name still fails with "Bad resource list id" and returns 0.

About the other places: all of them refused a bare number with that same error, because a number has no resource type.

  • Four of them expect only items, and there a bare number is now read as an item, as in RESTEST: CONSUME (chars), CONTCONSUME (containers), RESOURCES of ITEMDEF/CHARDEF and RESOURCES of SPELL (reagents). It only turns an error into a working list.
  • The others mix different types (SKILLMAKE, SKILLTEST, DESIRES/AVERSIONS, RANDGROUP): there a bare number could be a skill, a char or an item, so I left them as they are.

I added a test script to the description (pr_test_1653.scp, RESTEST with a typedef included): on current dev the 4 [BUG] tests fail, with the PR all 7 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