Repository navigation
fix(trade): the change warning stays within its slots and keeps a worse item's alert - #1038
Conversation
…se item's alert CTrade::AlertYourTradeInven kept the types of the unchanged items in a 10-entry array, but the partner can offer up to 32 items, so an 11th unchanged item wrote past it. And one unchanged item reset the alert for the whole window, so the confirm button stopped asking while another item was still marked as worse. The marking now lives in UI::Inventory::MarkWorseOffers, sized to the trade slots, and the alert comes from the items it still marks. Fixes Mutizens#1000 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc76vw5pccV4yoka9Yt7
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 33a2ea3969
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Mosch0512
left a comment
There was a problem hiding this comment.
Verdict: changes requested. The fix is right: the 10-entry array is gone, the arrays are sized to the 32 trade slots, and the alert now comes from the items that are still marked, so an unchanged item of another type no longer turns the warning off. Both bugs from #1000 are fixed. Two things from docs/CODING_RULES.md before merge:
- Required: the new code is in
UI::Inventory, but it is trade code and the trade file next to it usesUI::Trade(§7). - Required: the rule for when the trade window warns changed, and nothing in
docs/describes it (§11).
Non-blocking:
- The tests cover only
MarkWorseOffers; the comparison inCheckAgainstYourInvenBackUpand the overflow fix have no test. - The window remembers at most one copy per item type, so the loop over copies and its comments can be simpler.
- Small cleanups: the rescan in
MarkWorseOffers, the new member inTrade.h, the bareCompareItemcodes, and the cut-off PR title. - Three older bugs in the same feature, outside this diff, fine as follow-ups (details below).
CI hasn't run on this PR yet (it waits for a maintainer's approval). I ran CI's clang-format 21.1.8 check on the changed lines and it passes. I didn't build the branch.
6a. Third-party trade requests break the remembered items (Follow-up, pre-existing): ProcessToReceiveTradeRequest (Trade.cpp:692) copies the requester's name into m_szYourID before the Accepted handler compares it with the partner (Trade.cpp:732). Example: A trades with B, B offers Wings of Elf +3, the trade is cancelled, so A remembers the wings. If C then requests a trade and A accepts, the names match ("C" and "C"), the memory is kept, and C's Wings of Elf +1 is marked worse than B's wings. If A declines C instead and then trades with B again, "C" and "B" differ, the memory is cleared, and B's swap to Wings +1 isn't warned about. The original client (ee2c7a35, CNewUITrade::ProcessToReceiveTradeRequest) does the same. Keeping the last partner's name in its own member would fix it.
6b. The warning box can open with nothing marked (Follow-up, pre-existing): AlertTrade (Trade.cpp:675) still sets m_bTradeAlert = true on every confirm click. When A confirms and then unchecks, or B changes the zen (BothReset clears m_bMyConfirm without a new AlertYourTradeInven), A's next confirm click shows "The levels and options of some items have been changed in trade" with no item marked. The same flag also decides whether ProcessClosing clears the memory (Trade.cpp:558). A separate flag for "confirmed once", and a check of the marks at Trade.cpp:186, would keep the two apart.
6c. Null pointer on a remove for an empty slot (Follow-up, pre-existing): BackUpYourInven(int) (Trade.cpp:754) passes FindItem's result on without a check, and BackUpYourInven(ITEM*) reads pYourItemObj->Type at line 760. A "partner item removed" packet for a slot without an item crashes the client.
PR title(body note, not inline): the commit subject is 84 characters, so GitHub cut the title at "keeps a wor…" and moved the rest into the description. A shorter title (e.g. "fix(trade): keep the change warning in its slots and on worse items") would read better in the PR list and the merge commit. The template's Summary section is still empty.
- The worse-offer rule lives in UI::Trade, next to TradeUpdates.h. - docs/trade-window.md documents which items are remembered, when an item is marked, when the mark clears and when the confirm button asks. - The check against the remembered copy is a helper in Trade.cpp, so Trade.h no longer includes TradeWorseOffers.h. It finds the one copy of the type and names CompareItem's result codes. - MarkWorseOffers collects the unchanged types once. - The full-window test now has 15 unchanged types, more than the ten the original client could hold, and one worse item that stays marked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc76CH3CGWUp5r4XmXWK
- A trade request from a third player no longer overwrites the last partner's name, so declining it keeps the remembered items of that partner. - The warning dialog no longer opens with nothing marked: pressing the trade button set the warning flag, which also stood for "forget the remembered items on close". That is now its own flag, m_bForgetBackUpOnClose. - A remove packet for a slot the partner's grid shows empty is ignored instead of dereferencing a null item. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0333ddc36e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thanks for the review! Pushed 2075aba:
Left as is: the out-parameter of |
|
On top of 2075aba (the required changes), I pushed 0333ddc with the three follow-ups you listed, since they're all in the same warning:
Also updated the title and filled in the Summary. |
Mosch0512
left a comment
There was a problem hiding this comment.
Verdict: changes requested. Thanks, every point from the first round is fixed: the code is in UI::Trade, docs/trade-window.md describes the warning, the two meanings of m_bTradeAlert are split, a third player's request no longer overwrites the partner's name, the empty-slot remove can't crash, and the comparison is a free function with named result codes. Two things before merge:
- Required: if the warning dialog is still open when the trade closes, its OK button runs
AlertTradeafterwards. That setsm_bForgetBackUpOnClose, and the next trade with a different player then keeps the old partner's items and marks the new partner's items against them (inline atTrade.cpp:753). - Required:
docs/trade-window.mdsays a few things the code doesn't do: which items are remembered, how copies are compared, and that a cancelled trade always remembers the items (inline).
Non-blocking:
- Cancelling with Escape or by walking away loses the remembered items (inline at
Trade.cpp:580). This is older than the PR, so a follow-up is fine, but the docs shouldn't promise otherwise. CheckAgainstRememberedand this round's fixes have no tests.- Small cleanups: a vector allocation on each call, bare
CompareItemcodes still inBackUpYourInven, two header comments, the span-length contract, and three fixes in one commit.
CI still hasn't run on this PR (it waits for a maintainer's approval). I ran CI's clang-format 21.1.8 check on the changed lines and it passes. I didn't build the branch.
Commits (Non-blocking): 0333ddc36 holds three separate fixes (the flag split, the partner name on a request, the empty-slot guard). AGENTS.md asks for one concern per commit; splitting them would make each one easy to revert on its own. Fine to leave if the PR gets squashed anyway.
| wcsncpy(szTempID, std::wstring(partner.name).c_str(), MAX_USERNAME_SIZE); | ||
|
|
||
| if (!m_bTradeAlert && ::wcscmp(m_szYourID, szTempID)) | ||
| if (!m_bForgetBackUpOnClose && ::wcscmp(m_szYourID, szTempID)) |
There was a problem hiding this comment.
Required: this check can now be skipped by a click that comes after the trade closed. The warning dialog (GenericConfirmDialog, opened at line 217) isn't closed when the trade window closes, and its onPrimary still calls AlertTrade, which sets m_bForgetBackUpOnClose = true (line 697). Example: A trades with B, B swaps the +9 wings for +7 wings, A clicks confirm and the dialog opens. B cancels: the window closes, the Cancelled path (line 889) clears the flag and remembers B's items. A now clicks OK in the dialog that is still open, and the flag is true again. A then trades with C: the names differ, but !m_bForgetBackUpOnClose is false, so B's items stay remembered and C's +7 wings are marked worse than B's +9 wings. (The click also sends a button-state packet outside a trade.)
The partner check doesn't need the flag at all: a different partner should always clear the memory, and with the same partner ProcessClosing has already cleared it when it should. So if (::wcscmp(m_szYourID, szTempID)) InitYourInvenBackUp(); fixes it. Closing the dialog in ProcessClosing would also stop the stray packet.
| - when the partner takes an item out of the trade window; | ||
| - when a trade with the partner is cancelled, all items they offered. | ||
|
|
||
| Only valuable items are remembered: pets and riding items, jewels, wings and |
There was a problem hiding this comment.
Required: "Only valuable items are remembered" isn't true yet. BackUpYourInven (Trade.cpp:781 and :784) still checks Type >= ITEM_JEWEL_OF_GUARDIAN and Type >= ITEM_CAPE_OF_LORD, so every item from Cape of Lord on is remembered, potions and scrolls included. That's #946, still open. Either say that every item from that point on is remembered for now, or leave the list out and describe it once #946 lands.
| - when a trade with the partner is cancelled, all items they offered. | ||
|
|
||
| Only valuable items are remembered: pets and riding items, jewels, wings and | ||
| capes, socketed (combined) jewels, and items above +4 or with excellent |
There was a problem hiding this comment.
Required (part of the docs fix, see line 14): "socketed (combined) jewels" is COMGEM::isCompiledGem, which means jewel bundles (10 Jewels of Bless packed into one item), not sockets. And "items above +4" only applies to items below ITEM_WING (Trade.cpp:788); excellent options count for every item.
| ## When an item is marked | ||
|
|
||
| An offered item is shown in red when it is worse than the remembered copy of | ||
| its kind. Copies are compared by level first; at the same level, by the skill, |
There was a problem hiding this comment.
Required (part of the docs fix, see line 14): CompareItem also compares durability when everything else is equal, so a sword with less durability is marked too. And it compares the excellent options as one number (the bit flags), not by how many there are, so a copy with one high-bit option counts as better than one with two low-bit options. One line each is enough.
| kind: | ||
|
|
||
| - when the partner takes an item out of the trade window; | ||
| - when a trade with the partner is cancelled, all items they offered. |
There was a problem hiding this comment.
Required (part of the docs fix, see line 14): "when a trade with the partner is cancelled, all items they offered" holds only when the server's Cancelled message arrives while the items are still in the window. Escape and walking away empty the window first (see the comment on Trade.cpp:580), so nothing is remembered there. Either fix that or say so here.
|
|
||
| // Holds an offered item against the copy of its type the trade window remembers. The window remembers at most one | ||
| // copy per type (CTrade::BackUpYourInven). | ||
| UI::Trade::OfferedItemCheck CheckAgainstRemembered(std::span<const ITEM> remembered, const ITEM& offered) |
There was a problem hiding this comment.
Non-blocking: nice that this is a free function now, but it has no test yet, and neither has anything this round fixed (the flag split, the request no longer writing the partner's name, the empty-slot guard). A test with a remembered ITEM and a worse, a same, a better and an other-type offer would pin the code mapping, which is what turned the warning off in #1000.
| }; | ||
|
|
||
| // CompareItem's results for (remembered, offered) of one type. | ||
| constexpr int RememberedIsBetter = 1; |
There was a problem hiding this comment.
Non-blocking: the codes are named here, but BackUpYourInven (lines 799, 804, 810) still uses bare 0, -1 and 2 for the same results. Moving the names next to CompareItem (or an enum it returns) would let both places use them.
| { | ||
| namespace | ||
| { | ||
| std::vector<int> TypesOfferedUnchanged(std::span<const OfferedItemCheck> offers) |
There was a problem hiding this comment.
Non-blocking: this allocates a std::vector each time the partner adds or removes an item. Small, but the old code didn't allocate; with at most 32 offers, a fixed std::array<int, MAX_TRADE_INVEN> plus a count, or just checking offers again for a same-type unchanged item, does the same without the heap.
|
|
||
| namespace UI::Trade | ||
| { | ||
| // One item the trade partner offers, held against the copies of its type the trade window remembers |
There was a problem hiding this comment.
Non-blocking: "the copies of its type" still says plural, while line 20 says the window remembers at most one copy. Same at line 21, "a remembered copy" → "the remembered copy".
| // Marks the offered items the trade window warns about, in red, and returns whether any is marked, which makes the | ||
| // confirm button ask first (CTrade::AlertYourTradeInven). An item is marked when it is worse than the remembered copy | ||
| // of its type (the window remembers at most one copy per type), unless the partner also offers an item of that type | ||
| // that is the same as a remembered copy. The two spans have the same length. |
There was a problem hiding this comment.
Non-blocking: "The two spans have the same length" is a contract, but std::min at TradeWorseOffers.cpp:27 silently uses the shorter one, so a caller that gets it wrong leaves marks unset without any sign. An assert(offers.size() == marked.size()) would match the comment, or the comment could say the shorter length is used.
…'s items The warning dialog stayed open when the trade closed, and its OK then ran AlertTrade, which set m_bForgetBackUpOnClose and sent a button packet outside a trade. The next trade with another player kept the old partner's items because the partner check also looked at that flag. The partner check now only compares names, and ProcessClosing closes the warning dialog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
Create cleared only MAX_USERNAME_SIZE + 1 bytes of the wide-character array, and the accepted partner's name was copied without a terminator. Since the trade request no longer writes the name, a ten-character name could run into leftover memory. Clear the whole array and terminate the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
Escape, walking away (UpdateSendMoveInterface) and the close button sent the cancel and could hide the window before the server's Cancelled message arrived. Hiding empties the partner's grid, so nothing was remembered, and Escape and walking away left m_bForgetBackUpOnClose set, so the memory was even cleared. All three now go through CTrade::CancelTrade, which remembers the offers and resets the flag before sending the cancel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
Which items are remembered (all items from the Cape of Lord on, Mutizens#946), jewel bundles instead of sockets, +4 only for weapons and armour, the full CompareItem order with the bit-flag excellent options and durability, every way of cancelling, and the question closing with the window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
- Engine::Items::CompareResult (CompareItemResult.h) names CompareItem's results; BackUpYourInven and the offer check use them instead of 0, -1, 1 and 2. - UI::Trade::CheckOffer turns a CompareItem result into the offer check and has tests for worse, same, better and no remembered copy. - MarkWorseOffers no longer allocates a vector per call, asserts that both spans have the same length, and the header comments say the copy (one per type). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1d697895bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| RememberYourOffers(); | ||
| m_bForgetBackUpOnClose = false; |
There was a problem hiding this comment.
Clear the backup when completion wins a cancellation race
If the player presses Escape or walks away just after confirming, the server can complete the trade before it receives the cancellation. CancelTrade() now remembers the offers and clears m_bForgetBackUpOnClose, but the Completed branch in ProcessToReceiveTradeExit() neither restores that flag nor clears the backup, so the subsequent close preserves items from a successful trade. Reopening a trade with the same partner then falsely marks lower-quality offers as substitutions for items already received. Handle Completed by explicitly discarding the backup regardless of a preceding local cancel attempt.
Useful? React with 👍 / 👎.
Mosch0512
left a comment
There was a problem hiding this comment.
Verdict: changes requested, one item. Thanks, all eleven points from the last round are fixed, and splitting them into separate commits made this round easy to read. CancelTrade covers Escape, walking away and the close-all path; the warning dialog closes with the window; the partner check no longer depends on the flag; the docs list the remembered items and the comparison order; and the result codes have names in CompareItemResult.h. One thing before merge:
- Required:
docs/trade-window.mdsays the comparison catches a lower additional option, butCompareItemtreats a +16 → +4 swap as the same item. Some item fields aren't compared at all. Either fixCompareItemor say so in the docs (inline at lines 43 and 37).
Non-blocking:
- Cancelling just as the trade completes keeps the memory (inline at
Trade.cpp:683; Codex flagged it too). - "Every way of cancelling" in the docs is a bit too wide (inline at line 12).
- The zen-amount dialog still outlives the window, and
GenericDialogConfig::isValidcould close both dialogs (inline atTrade.cpp:574). - The
CompareItemargument order has no test (inline atTrade.cpp:60). - The PR description doesn't mention this round's changes yet:
CancelTrade(Escape and walking away remember the offers), the warning closing with the window, the partner check without the flag, and the newCompareItemResult.h. Worth adding so the squash commit says it.
CI still hasn't run on this PR (it waits for a maintainer's approval). I ran CI's clang-format 21.1.8 check on the changed lines and it passes. I didn't build the branch.
| 2. whether the item has its skill; | ||
| 3. the excellent options, taken as one bit-flag number, not counted: a copy | ||
| with one high-bit option beats a copy with two low-bit options; | ||
| 4. the number of other options, then the additional option and its value; |
There was a problem hiding this comment.
Required: "then the additional option and its value" is only half true. In CompareItem (ZzzInventory.cpp:3068-3075) the remembered copy only counts as better when the offered item has lost the option completely (addOption1 != addOption2 && addOptionV1 != addOptionV2). With the option on both, a lower value doesn't match either branch, so the result stays Same and only the durability decides. Example: B shows a Blade +9+Luck+16, takes it out, and puts in a Blade +9+Luck+4 with the same durability. It isn't marked, the button doesn't ask, and as a Same copy it also clears the marks of other Blades. CompareItem has only the two callers in Trade.cpp, so else if (addOptionV1 > addOptionV2) equal = 1; after the first branch would be a safe fix (with a test). If you'd rather not touch it in this PR, the docs should say that a lower additional option isn't caught, and the comment in CompareItemResult.h too.
|
|
||
| An offered item is shown in red when it is worse than the remembered copy of | ||
| its kind. Copies are compared (`CompareItem`) in this order, and the first | ||
| difference decides: |
There was a problem hiding this comment.
Required (part of the same fix): "the first difference decides" reads as if the list were complete, but CompareItem never reads several ITEM fields: the Jewel of Harmony option (Jewel_Of_Harmony_Option/...OptionLevel), the 380 option (option_380), the sockets (bySocketOption) and, as far as I can see, the ancient set (AncientDiscriminator/AncientBonusOption). Two copies that differ only there count as the same: no mark, and the marks of that kind clear. One line listing what isn't compared is enough.
| { | ||
| // The window may hide right after this, before the server's answer: remember the offers now. | ||
| RememberYourOffers(); | ||
| m_bForgetBackUpOnClose = false; |
There was a problem hiding this comment.
Non-blocking: this sets the flag to false before the server answers. If both players had confirmed and the server completes the trade before it sees the cancel (Escape or walking away right after the last confirm), the Completed case in ProcessToReceiveTradeExit neither clears the memory nor sets the flag again. So the items A just received stay remembered, and the next trade with B can mark a lower copy of one of them. InitYourInvenBackUp() in the Completed case fixes it, whatever happened before.
| kind: | ||
|
|
||
| - when the partner takes an item out of the trade window; | ||
| - when the trade is cancelled, all items they offered. This holds for every |
There was a problem hiding this comment.
Non-blocking: "This holds for every way of cancelling" misses a few closes:
- The close-all path (
WindowSystem.cpp:1203) callsProcessCloseBtn, which does nothing while an item is held, and the window hides anyway. - When the server ends the trade with
InventoryFullorReinforcedItem(Trade.cpp:905-915), the offers aren't remembered, and if the trade button was pressed,ProcessClosingclears the memory. "Your trade has been canceled because your inventory is full" sounds like a cancel to the player.
Either list just the four ways the docs name, or treat those closes like Cancelled.
|
|
||
| if (m_bTradeAlert) | ||
| // An OK on the warning after the window closed would press the trade button of no trade. | ||
| mu::ui::window::g_pGenericConfirmDialog->Cancel(m_TradeAlertDialogId); |
There was a problem hiding this comment.
Non-blocking: this works. GenericDialogConfig already has isValid for exactly this case, though ("expired requests are dismissed without callbacks"): the dialog checks it every frame and before running a callback. A cfg.isValid tied to the open trade would close the warning without the stored id. It would also fix the zen-amount dialog (line 190), which still stays open after the trade closes: its OK sends SendSetTradeMoney for a trade that has ended.
| { | ||
| const auto copy = | ||
| std::ranges::find_if(remembered, [&offered](const ITEM& item) { return item.Type == offered.Type; }); | ||
| const int compareResult = (copy == remembered.end()) ? CompareResult::OtherType : ::CompareItem(*copy, offered); |
There was a problem hiding this comment.
Non-blocking: thanks for the CheckOffer tests. They pin the mapping from result code to flags, but the part that can go wrong is here: the order CompareItem(*copy, offered). Swapped to CompareItem(offered, *copy), better items would be marked and worse ones not, and every test stays green. Moving the lookup into TradeWorseOffers with the compare function passed in would let a test cover it. Fine as a follow-up.
CompareItem counted the remembered copy as better only when the offered copy had lost its additional option entirely; a lower value (+16 to +4) fell through as the same copy, so the trade window neither marked it nor asked, and it even cleared the marks of other copies of that kind. The additional option comparison is now Engine::Items::CompareAdditionalOption with tests. CompareItem's only callers are in Trade.cpp. The docs and CompareItemResult.h also say which fields CompareItem never reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
CancelTrade remembers the offers and resets m_bForgetBackUpOnClose before the server answers. If the server completed the trade before it got the cancel (Escape or walking away right after both confirmed), the Completed exit left the memory in place, and the next trade with that partner could mark a lower copy of an item that had just been traded. Completed now always clears it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
When the server ends the trade because an inventory is full or an item is reinforced, no items change hands, but the offers were not remembered and, if the trade button had been pressed, the memory was cleared on close. These closes now go through RememberOffersOfFailedTrade like Cancelled and CancelTrade. The docs list the ways a trade ends without an exchange, and name the close-all-windows-while-holding-an-item case that remembers nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
Both dialogs now set GenericDialogConfig::isValid to the trade window being open, which the dialog checks every frame and before any callback. The zen amount box no longer sends SendSetTradeMoney for a trade that has ended, and the warning no longer needs its stored dialog id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
The lookup of the remembered copy moves into UI::Trade::CheckAgainstRemembered, which takes the compare function; Trade.cpp passes ::CompareItem straight in. Tests with a level-only stand-in check that a lower offered copy counts as worse and a higher one does not, so swapping the arguments fails them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc78fLXzwS6CLdro3RAb
|
Thanks for the third round! Pushed six commits (8a7bba1..d0de953): Required
Also done
Built on Linux, trade tests pass (16 cases), clang-format clean, merges cleanly with main. |
Mosch0512
left a comment
There was a problem hiding this comment.
Verdict: changes requested, one item. Thanks, every code point from the last round is fixed, again in clean separate commits. CompareItem now counts a +16 to +4 swap as worse. A completed trade clears the memory even after a late cancel. Inventory-full and reinforced-item stops remember the offers. Both dialogs close with the window through isValid. The lookup is testable, and the tests fail if the arguments are swapped. One thing before merge:
- Required: the docs say a copy with a lower Jewel of Life option is worse, but
CompareItemonly reads the damage, magic, curse, blocking and defense kinds. The HP recovery option (Wings of Elf, the 2nd/3rd wings and capes with that variant, rings and pendants) and the max mana / max AG options of the Ring of Magic and the Pendant of Ability still compare as the same (inline atdocs/trade-window.md:47).
Non-blocking:
- The tests cover
CompareAdditionalOptionbut not howCompareItemcalls it (inline atZzzInventory.cpp:3070). - The new docs line about closing all windows describes closing the inventory, and the trade stays open there (inline at
docs/trade-window.md:15). That wording came from my last review, sorry. RememberYourOffershas one caller left (inline atTrade.cpp:680).- The PR description still describes only the first round. Since this PR now also changes
CompareItemin Engine code, it's worth listing what rounds 2-4 changed so the squash commit says it.
CI still hasn't run on this PR (it waits for a maintainer's approval). I ran CI's clang-format 21.1.8 check on the changed lines and it passes, and the branch merges cleanly with current main. I didn't build the branch.
| 3. the excellent options, taken as one bit-flag number, not counted: a copy | ||
| with one high-bit option beats a copy with two low-bit options; | ||
| 4. the number of other options, then the additional option (the one a Jewel | ||
| of Life raises): a copy without it, or with a lower value, is worse, so a |
There was a problem hiding this comment.
Required: "a copy without it, or with a lower value, is worse" holds only for some items. The switch in CompareItem (ZzzInventory.cpp:3045-3064) collects AT_IMPROVE_DAMAGE, AT_IMPROVE_MAGIC, AT_IMPROVE_CURSE, AT_IMPROVE_BLOCKING and AT_IMPROVE_DEFENSE. But ZzzInfomation.cpp (lines 552-726) gives other items a different Jewel of Life option:
AT_LIFE_REGENERATION(HP recovery) on Wings of Elf, rings and pendants, and on the 2nd/3rd wings and capes in their HP recovery variant;AT_IMPROVE_MAX_MANAon the Ring of Magic;AT_IMPROVE_MAX_AGon the Pendant of Ability.
For those items both sides stay at "no option", CompareAdditionalOption(false, 0, false, 0) returns Same, and only the durability decides. Example: B shows Wings of Elf +9 with +4% HP recovery, takes them out, and puts in Wings of Elf +9 with +1%. They aren't marked, the button doesn't ask, and as a Same copy they also clear the marks of other wings of that kind. (A copy that loses the option completely is still caught, by the option count.)
Two ways out:
- Add the three kinds to both switches. Compare the value only when both copies have the same kind, since HP recovery runs 1-4 and damage 4-16.
- Or say in the docs (and in the comment in
AdditionalOptionComparison.h) that these options aren't compared.
| equal = 1; | ||
| } | ||
| // The original counted a lower value (+16 to +4) as the same copy. | ||
| equal = Engine::Items::CompareAdditionalOption(addOption1 != 0, addOptionV1, addOption2 != 0, |
There was a problem hiding this comment.
Non-blocking: the new tests pin CompareAdditionalOption itself, but not this call. If its arguments were swapped (addOption2 first) or a case dropped out of the switch above, the +16 to +4 swap would go unmarked again and every test would stay green. tests/data already builds real ITEMs with option slots (see test_item_option_slots.cpp). A CompareItem test there with a +16 and a +4 copy (and an HP recovery pair once the point above is settled) would cover it, and would sit better than an Engine test in the UI trade target.
| - when the trade ends without items changing hands, all items they offered: | ||
| you press the close button or Escape, you walk away, the partner cancels, | ||
| or the server stops the trade because an inventory is full or an item is | ||
| reinforced. Closing all windows while you hold an item hides the trade |
There was a problem hiding this comment.
Non-blocking: my last review called this "the close-all path", which was wrong, sorry. It's closing the inventory (its close button, Escape in the inventory, or the inventory key): Hide(INTERFACE_INVENTORY) at WindowSystem.cpp:1201-1205. There the trade window is hidden with ShowInterface(..., false), so ProcessClosing doesn't run: the trade stays open on the server and B's items stay in the hidden grid. If B then cancels, the Cancelled reply remembers them after all, so "remembers nothing" only holds until the trade ends. Something like "Closing the inventory while you hold an item hides the trade window but leaves the trade open; the memory then follows how that trade ends" would match.
| SocketClient->ToGameServer()->SendTradeCancel(); | ||
| } | ||
|
|
||
| void CTrade::RememberOffersOfFailedTrade() |
There was a problem hiding this comment.
Non-blocking: RememberYourOffers is now called only from here. Folding its loop into RememberOffersOfFailedTrade leaves one entry point, so a later caller can't take the loop without the flag reset, which is what made ProcessClosing throw the offers away before CancelTrade.
|
Thanks for the follow-up review. I pushed b8dd12a and 83da676.
All 18 focused test cases passed in a standalone build, along with the pre-push static checks and changed-line formatting. The full client build was not completed locally. |
Resolves the conflict in tests/data/test_item_option_slots.cpp: main's new tests and the trade CompareItem tests were both appended at the end of the file; both are kept.
|
@Mosch0512 all points from your 18 Nov review are in b8dd12a and 83da676 (details in my comment above), and the branch still merges cleanly with current main. Ready for another look when you have time. CI is waiting on a maintainer approval to run. Generated by Claude Code |
Mosch0512
left a comment
There was a problem hiding this comment.
Verdict: changes requested, one item, then this looks good to merge. Thanks, all of the last round is fixed. The comparison now finds the HP recovery, max mana and max AG options and compares values only within one option kind. CompareItem has tests with real items. The docs describe closing the inventory correctly, and the backup loop lives in one helper.
I merged current main into your branch to fix the conflict (7e8518d). The only conflict was the end of tests/data/test_item_option_slots.cpp, where both sides had added tests; both are kept, main's first. Please pull before you push again. Current main sets the Jewel of Life option from Data/Items/Options/Option.json, but each option maps to the same AT_* kinds, so your comparison works the same there.
- Required: a copy with a different option kind counts as
Same, so it clears the marks of its kind (inline atZzzInventory.cpp:3016).
Non-blocking:
- The PR description still describes only the first round. Since the PR now also changes
CompareItemin Engine code, the cancel paths and the dialogs, please list that so the squash commit says it.
CI still hasn't run on this PR (it waits for a maintainer's approval). I ran CI's clang-format 21.1.8 check on the changed lines and it passes. I didn't build the branch.
|
|
||
| // Different options use different scales, so only compare values within the same kind. | ||
| if (firstHasOption && secondHasOption && first.Special[firstSlot] != second.Special[secondSlot]) | ||
| return Engine::Items::CompareResult::Same; |
There was a problem hiding this comment.
Required: two copies with different option kinds aren't the same item, but Same makes them count as it, and Same does more than leave the offered copy unmarked: it clears the marks of every offered item of that kind. Example:
- B shows Wings of Spirits with damage +16. A sees them, so they're remembered.
- B takes them out and puts in Wings of Spirits with damage +4: worse, so it's marked.
- B also puts in Wings of Spirits with HP recovery +1%. Against the remembered damage copy, the kinds differ, so the result is
Same. - A
Samecopy clears the marks of all Wings of Spirits: the +4 wings lose their mark and the trade button doesn't ask, though the +16 wings never came back.
A different option kind should count as a change the warning catches. For example: return FirstIsBetter here, so the offered copy is marked and BackUpYourInven keeps the remembered one. Or add a result of its own that CheckOffer marks and that never clears marks. Either way, please update the docs (line 51, "If the option kinds differ, durability decides") and the test at tests/data/test_item_option_slots.cpp:1342, which expects Same now. While you're there: that test gives Wings of Elf (ITEM_WING) a damage option, which they can't have. ITEM_WINGS_OF_SPIRITS has both versions, so it would show the real case.
… same CompareItem returned Same when the two copies carry different additional option kinds (for example Wings of Spirits with damage and with HP recovery), so such a copy cleared the trade warning of its whole kind. It now returns the new CompareResult::OtherOptionKind: the trade window marks the offered copy, it never clears marks, and BackUpYourInven keeps the remembered copy. The test uses Wings of Spirits, which have both option kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xNc76KW8LiBPtBWqbmEGU
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
CI failed in "Run tests" on all three platforms, and the cause is on main, not in this PR. The only failing test is I ran the editor ON builds on my fork to check:
All trade tests pass. CI should go green here once main is fixed and the checks are re-run. |
Summary
The trade window warns when the partner swaps an item for a worse copy of it (#1000). This PR fixes that warning:
The list of unchanged item kinds had room for 10 entries while the partner can offer up to 32 items, so a full window overflowed it. The marking now lives in
UI::Trade::MarkWorseOfferswith no fixed-size list.One unchanged item cleared the warning for the whole window. Now it clears only the marks of its own kind; a worse item of another kind stays red and the confirm button still asks.
A trade request from a third player no longer overwrites the last partner's name, so declining it keeps the remembered items.
The warning dialog no longer opens with nothing marked after you pressed the trade button once (one flag stood both for the warning and for forgetting the remembered items on close; now there are two).
A remove packet for a slot the partner's grid shows empty is ignored instead of crashing.
Cancelling with Escape, walking away, or using the trade close button saves eligible offers before the window clears. Server cancellation, inventory-full and reinforced-item exits also preserve offers. A completed trade clears them, even if a cancellation was already sent.
An accepted trade with a different partner always clears the saved offers. The warning and zen entry dialogs expire when the trade window closes.
CompareItemuses named results and detects lower Jewel of Life bonuses, including HP recovery, max mana, and max AG. Bonus values are compared within the same option kind.The rule is described in
docs/trade-window.md. Tests:tests/ui/test_trade_worse_offers.cppandtests/data/test_item_option_slots.cpp.Fixes #1000