Commit Graph
572 Commits
Author SHA1 Message Date
Vladimir Olteanu 4d6ff58c22 Reduce reliance on bool done for control flow (part 1 of x) (#4720) 2022-06-17 13:13:39 +02:00
Gleb Mazovetskiy 1fc8ecb6f6 Add fmt::runtime annotations for C++20 support
`fmt` requires non-contexpr format string arguments to be wrapped in
`fmt::runtime` in C++20.
2022-06-14 12:46:36 +01:00
Gleb Mazovetskiy 779ccaca17 Overhaul translation fetching
1. Do not modify the map after loading. Instead, return string views
   (guaranteed to be null-terminated) from look up functions and return
   the key directly if not found.
2. Use an `unorded_map` instead of `map` where available (C++20).
   Saves a bit of RAM (~50 KiB) and improves lookup performance.
2022-06-14 12:46:36 +01:00
Anders Jenbo 1203514383 Clean up use of currlevel 2022-06-07 21:35:01 +02:00
Gleb Mazovetskiy e76d5fc494 UseScroll: use HasInventoryOrBeltItem 2022-06-06 08:15:40 +01:00
Gleb Mazovetskiy 628406a44c Refactor inventory/belt item presence and removal
Introduces new functions to check for presence of and remove player items.
These functions do not rely on or expose item indices.

They're implemented as free functions instead of Player methods due to
complicated include dependencies between `player.h`, `inv.h`, and
`inv_iterators.h`. We should probably look into cleaning this up at some
point.
2022-06-05 13:30:26 +02:00
qndel 354e329644 Players[MyPlayerId] -> MyPlayer 2022-05-31 05:35:52 +02:00
obligaron bc15bdf3a9 Remove PANEL_ defines and replace them with GetMainPanel() 2022-05-29 20:20:44 +02:00
Stephen C. Wills 99ab06776c Apply clang-format to inv.cpp (#4581) 2022-05-16 08:22:13 +10:00
Nick Tholin 5fd93408f8 Move identical belt items down belt as they are used. 2022-05-15 21:34:04 +02:00
ephphatha af3187a15e Provide sound cue when gold is auto-placed into the open inventory 2022-05-15 14:49:06 +02:00
ephphatha 0cfd0e194a Refactor TryDropItem to reduce use of globals
The way TryInvPut and DropItemBeforeTrig interacted was fragile, don't think this would've worked as expected at the best of times. Looks like it was added as part of controller support so guessing this isn't vanilla behaviour anyway.
2022-04-25 06:38:27 +02:00
ephphatha 4d7c08d5b4 Deduplicate code for setting stat requirements/flag 2022-04-21 05:44:38 +02:00
ephphatha 64a2c41b2c Set clang-tidy config for MethodCase option
Previously this was falling back to FunctionCase, leading to inconsistent casing of class methods throughout the codebase. Applied to Item as an example.
2022-04-20 13:50:57 +02:00
ephphatha 7a3722d63b Add helper for clearing an item and using it's old value
Used when moving from one persistent variable to another where we want the source variable to be marked empty. Defining as a function instead of move constructor/assignment operator as we only really need to mark the source for xvalues. Detecting that in the constructor/assignment would be needlessly complicated.
2022-04-20 13:35:55 +02:00
Andrew James 72cfdc31ea Clear held item when putting in an empty belt slot (#4490) 2022-04-19 07:00:33 +01:00
ephphatha ad7ad46ce9 Explicitly clear HoldItem when putting an item into the Inventory/Stash
Previously this also relied on NewCursor modifying MyPlayer->HoldItem when setting the cursor to a non-item cursor to avoid item duplication, seems more appropriate to make this explicit in the caller.
2022-04-18 19:25:55 +02:00
ephphatha 7e7798fd2b Add function to mark an item as empty 2022-04-18 19:25:55 +02:00
ephphatha 28b6eaf7de Only use HoldItem in InvGetItem if necessary
When auto-placing gold in the inventory there's no need to trample HoldItem.
2022-04-18 17:41:01 +02:00
ephphatha 026b428c7d Add NewCursor(Item&) for setting the cursor based on a held item
The case for empty items should never be hit in the current code, but I've got a related PR that'll make use of that so adding it now.
2022-04-18 16:59:34 +02:00
Anders Jenbo dc706e8ed5 Use HoldItem for determining if an item is held
This cleans up a bit of code and solves a few edge cases where an item
could be lost, the game be unresponsive, or miss fire an event during
lag cause of the cursor not reflecting the currently held item.
2022-04-18 11:27:07 +02:00
ephphatha 5b83f2a7c4 Remove SetICursor and unused globals 2022-04-16 05:54:03 +02:00
ephphatha aab970dcde Use GetIventorySize(Item) instead of SetICursor in inv.cpp
Also use mod for testing if item dimensions are even. Lets assume the release build can optimise this into a bitmask, probably wont need to do this anyway after a refactor.
2022-04-15 09:43:15 +02:00
Gleb Mazovetskiy a66ca44695 Zero-based frame indexing
Index frames starting at 0 instead of 1.
2022-04-14 04:39:26 +01:00
Anders Jenbo c5a3d138e0 Avoid using HeldItem in CheckInvSwap 2022-04-14 01:20:06 +02:00
staphen 33b27f630f Clean up logic for 1-handed weapons in CheckInvPaste() 2022-04-14 01:19:14 +02:00
staphen d16c2f0086 Avoid recreating items in PutItem locally 2022-04-10 23:37:33 +02:00
staphen cf41911417 Use appropriate spell ID when quick casting from scroll or staff 2022-04-10 17:32:16 +02:00
qndel a6ebc506a0 refresh stats when sending an item to stash by ctrl + click 2022-03-31 14:50:10 +02:00
staphen 33338115f6 Don't use HoldItem in CMD_PUTITEM handler 2022-03-31 11:43:58 +02:00
staphen 6a30cd3950 Add gamepad support for stash 2022-03-30 23:12:09 +02:00
staphen 82f53c53b0 Fix shift-click equipment swapping network messages 2022-03-27 18:26:43 +02:00
staphen 822a0cd22a Fix auto-equip network messages 2022-03-27 18:26:43 +02:00
Anders Jenbo e2fef44c9f Close gold withdraw when closing stash 2022-03-27 18:08:02 +02:00
ephphatha 4bbc2e56a0 Restore position of dropped note when recombining fragments 2022-03-27 03:40:44 +02:00
Anders Jenbo 1ba817ca53 Unify gold handling (withdraw any amount from stash) 2022-03-22 21:38:51 +01:00
Anders Jenbo 6d28810dc7 Change infostr from char[128] to std::string 2022-03-20 14:23:30 +01:00
Andrew James 4ff83431d2 Remove the use of HoldItem in AutoGetItem (#4178) 2022-03-19 14:32:54 +01:00
obligaron 92993ad039 Ctrl+click stash item swap: if there is no room left, don't drop the item on the ground 2022-03-19 14:30:44 +01:00
obligaron b495cabeb5 Allow to swap items with ctrl+click between inventory and stash 2022-03-19 08:29:04 +01:00
obligaron 05658de4e9 Make GetInventorySize public 2022-03-19 08:29:04 +01:00
Anders Jenbo be57d62684 Use UTF8 aware string copying 2022-03-19 06:03:19 +01:00
Anders Jenbo 718c46e7fe Remove use of tempstr 2022-03-19 06:03:19 +01:00
obligaron 2617332a41 Allow only one gold input panel to be open 2022-03-19 02:11:02 +01:00
Anders Jenbo a48f89007d Implement stash 2022-03-18 06:01:53 +01:00
ephphatha ca1ec8548f Move GoldAutoPlaceInInventorySlot to anonymous namespace 2022-03-06 06:33:11 +01:00
ephphatha f5da32a21c Don't assume holdItem when auto-placing gold 2022-03-06 06:33:11 +01:00
Andrew James f64d17bfa9 Initial clean up of code related to creating items (#2943)
* Move declaration of dItems to items.cpp

This array is never used in dungeon generation, it's closely related to Items so should be kept together. Ideally managing dItems can become responsibility of a container for Items, which will handle adding/removing items from the list and keeping the positions in sync.

* Rename SetPlrHandItem to match purpose/use

* Give more descriptive name to GetPlrHandSeed

This function sets a new seed on a given item struct, not just the held item.

* Don't use HoldItem as a temporary for the players initial inventory

* Take Item by reference in RespawnItem

* Don't use holdItem as a temporary when dropping gold on death

* Update DeadItem to take item by reference, and refer to it consistently

Move code which invalidates the source of dropped items to the caller

Most call sites use a temporary item instance or remove the item from the container, so there's no real point invalidating the item after it's been copied to the drop list.

Update DeadItem to take position instead of player references
2022-03-06 14:53:29 +11:00
Gleb Mazovetskiy 7fede6c4cb Clean up owned/unowned CelSprite ambiguity
Makes `CelSprite` unowned and adds a new `OwnedCelSprite` class for
owned sprites.

This clarifies ownership and makes the code cleaner in a number of
places.

Additionally, because the `CelSprite` class is now tiny (1 less
pointer), we can pass it by-value instead of by-reference, removing a
pointer indirection in the rendering functions.
2022-03-06 04:49:13 +01:00
qndel be0845f41d barb 2h cleanup 2022-03-04 19:45:20 +01:00