89 Commits

Author SHA1 Message Date
Curtis Merrill 258b80d42b change visitable to item_location, remove item inheritance from visitable, and add item_location inheritance from visitable.
Co-Authored-By: dobbry-vechur <259678433+dobbry-vechur@users.noreply.github.com>
2026-09-30 21:34:09 -04:00
Curtis Merrill 63be141baf remove inventory class and reimplement invlets under avatar
stash starting inv that doesn't fit

fix save load order

initialize string hint in android build to none

reuse free assigned invlet and move it

Update npc.cpp

Update character_inventory.cpp

Update src/avatar.cpp

Update src/npc.cpp

Update src/avatar.cpp

Co-Authored-By: dobbry-vechur <dumbkevin@proton.me>
2026-09-21 16:15:22 -04:00
dumb-kevin 05ab42807e tests/: wrap TU-local test fixture types in anon namespaces
- addiction_test: wrap addict_effect_totals
- battery_density_test: wrap battery_chemistry_family
- comestible_test: wrap all_stats
- encumbrance_test: wrap add_trait
- invlet_test: fuse inventory_location + invlet_state + test_action enums
- throwing_test: fuse throw_test_data + throw_test_pstats, move operator<< inside anon-ns
- vehicle_test: wrap vehicle_preset, damage_preset, folded_item_damage_preset, fuse rack_activation + rack_preset
- vision_test: wrap vision_test_case
- water_movement_test: fuse 6 swimmer/swim structs into one block
- weakpoint_test: wrap weakpoint_test_data, weakpoint_expectation, weakpoint_report
2026-05-12 10:53:28 +04:00
Andrew Krieger 0215b26cce Rewrite all tests to clear map without touching character map memory, for performance. 2026-02-08 23:05:55 -08:00
PatrikLundell 586cf5f1ce Mapify: character etc. sees + sundry others (#79699)
* Mapify: character etc. sees + sundry others

* demanded changes

* Corrected correction
2025-02-18 09:29:22 -06:00
moxian c44d65a8ae Run IWYU again to pick up the changes 2025-02-11 13:02:19 -08:00
moxian 2ee44002fd Mechanically IWYU the tests
python3 ~/github/include-what-you-use/iwyu_tool.py -j5 -p build $( find
src/ tests/ -maxdepth 1 -name '*.cpp' | grep -v -f
tools/iwyu/bad_files.txt )  --  -Xiwyu --comment_style=long -Xiwyu -
-max_line_length=1000 -Xiwyu --cxx17ns -Xiwyu
--mapping_file=../tools/iwyu/cata.imp   | tee out/iwyu/f-a-01.txt >
/dev/null

followed by

cat out/iwyu/f-a-02.txt | python3
~/github/include-what-you-use/fix_includes.py --reorder --nosafe_headers

followed by manual fixups of <stddef.h> -> <cstddef> and similar.

tests/generic_factory_test.cpp gets mangled very badly (IWYU bug) so
it's excluded from the list.

Code size:
includes:
$ cat obj/tiles/*.inc | wc
 288068  576136 17898260
$ cat tests/obj/tiles/*.inc | wc
 167044  334088 10465766

post-processed source (clang -E):
./make_preproc.sh src/
68567896 177775140 2134075721
./make_preproc.sh tests/
39341957 102891720 1243323710
2025-02-10 00:46:57 -08:00
PatrikLundell 537d9d12a1 Standardized get/set pos operations for talker/creature class hierarchy (#79206)
* Standardized get/set pos operations for talker/creature class hierarchy

* sort out merge failure
2025-01-20 08:20:58 +01:00
Procyonae 982df19d0f Change /tests remaining uses of raw string item initialisation to use itype_id s
"remaining uses" being somewhat of an understatement -_-
2025-01-10 15:31:15 +00:00
PatrikLundell 26eb173d36 typified character.h + npc.h (#78623)
* typified character.h + npc.h

* demanded collateral change

* demanded collateral change
2024-12-18 20:03:41 -06:00
PatrikLundell 5648f805dc typified a bit of map.cpp + dependents 2024-10-12 13:12:23 +02:00
PatrikLundell 456a199f5c typified a bit of map.cpp and dependents 2024-10-08 16:23:15 +02:00
PatrikLundell ab062c5e8b typified a bit of map.h/cpp + some dependents (#75125)
* typified a bit of map.h/cpp + some dependents

* Macro crasher found by one compiler!

* demanded changes

* stupid wokaround for demanded changes

* Sort out conflict mess
2024-09-10 09:42:54 -05:00
PatrikLundell c120294d1f allow map_cursor to be made from abs pos (#75449) 2024-08-04 20:00:32 -04:00
PatrikLundell 4ba6a9f7a8 Typified parts of map.h/map.cpp + usages 2024-07-18 00:23:02 +02:00
PatrikLundell 4c6b91838c Removed one getlocal (#73940)
Co-authored-by: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com>
2024-05-25 16:18:25 -05:00
PatrikLundell 1542a3ac1b typified activity_actor 2024-05-15 17:01:50 +02:00
RenechCDDA b0882ee2eb Update tests for protected moves variable 2024-03-09 16:33:12 -05:00
Kamayana 6a46c5a421 Cache results of item search functions (#67835)
* Cache results of `has_item_with_flag` and `all_items_with_flag`

Adds new functions `add_to_flagged_item_cache` and `remove_from_flagged_item_cache`, as well as new overloads in `visitable` to accomplish this

* Replace some `items_with` with `all_items_with_flag`

* Add special handling for the unique LIGHT flag

* Handle flagged item cache in `item::convert`

* Add note to flag_LIGHT that it's not a real flag

* Open the cache up to expansion beyond just `flag_id`s

* Rename "cache" to "caches"

* Add function `all_items_with` for inventory searches. Replaces `all_items_with_flag`.

There are three overloads for this function. One searches for an item flag, as `all_items_with_flag` did. One searches for all items that pass a specified boolean function. The last one does both. All three add the results to the cache.

* Fix cache handling for item contents

* Embed cache clearing into more item removal functions

Replaces `Character.worn.clear()` with `Character.clear_worn()`. `Character` is now a friend of `outfit` to accomplish this

* Use inv search cache for seeds

* Use inv search cache for cash cards

* Use inv search cache for npc food

* Update some implementations of `all_items_with`

* Use inv search cache for relic processing

* Change cache names to use the function name for simplicity

* Use `all_items_with` for relics in `recalculate_enchantment_cache`

* Include `set` in iexamine

* Use `on_item_acquire` in `convert`

* Handle `i_add` with charged items directly in the function itself

This lets us always assume that calls to the `try_add` overload with copies should, in fact, be doing so

* Adjust `try_add` copies to add all added items to the cache

It used to only add the first item. There's a CPU impact of this change when spawning huge amounts of items, but it's very slight

* Use `has_item_with_flag` instead of `all_items_with` in `link_up_actor`

* Use `all_items_with` for bionic cable functions

* Make `get_cable_vehicle` const

* Make `all_items_with` key use a const reference

* Add `clear_inv` for clearing Character's inventory and cache

* astyle invlet test

* Revert "Add `clear_inv` for clearing Character's inventory and cache"

This reverts commit 944d768dd1.

* Make cache use vectors of items instead of sets

* Deduplicate code in `all_items_with` overloads

Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>

* Fix iteration in `remove_from_inv_search_caches`

Temporary measure while I rethink how the cache works. Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>

* Greatly rework the item search cache and all its functions

The cache now uses safe references rather than direct item pointers. `all_items_with` replaced with `do_on_items_with`, a function that iterates through the cache, applying a given function to the items and removing invalid item pointers as it goes. There's also an overload that gives the function a boolean `abort` parameter that, if ever set to true, exits the loop immediately and returns true. Also adds `get_items_with` for creating a vector of all the cached item pointers.

* Remove `remove_from_inv_search_caches`

Also reverts changes that were made earlier to accomodate manual cache removal

* Replace `has_item_with_flag` with `has_any_item_with`

I went with a unique function name rather than overloading `read_only_visitable::has_item_with` since visitable can't use the caches, so they're worth differentiating

* Consolidate `do_to_items_with_until` and `has_any_item_with`

They basically did the same thing

* Leftover debug line

* Add `do_and_check_func` to `get_items_with`. Adds const versions

* Rename `get_items_with` to `all_items_with`

* Make `has_any_item_with` use const item references.

The const_cast added to radiocontrol is temporary

* Fix returns

* Fix radio control handling

Specifically, fixes the game letting you activate an RC with a bomb in your inventory (it doesn't activate but it also doesn't warn you). Adds a const version of the item pocket chain's `get_item_with`s to accomplish this

* Add additional overload to inv search functions that looks for an item type id

* Only cache flags of the item's type, not the item specifically.

We should only use const flags for caches, not ones that can be set/unset

* Add `can_link_up` for optimizing cable finding

* Implement inv search cache functions

* Temporary fix for item tests

I need to think about how to handle non-type flags

* Change all the item search function names to specifically mention the cache

I grew to dislike the "almost but not quite the same as visitable" names I've been using. These names are clearer

* Make separate const versions of `cache_visit_items_with`

It's better design to do this; `inv_search_caches` being mutable was causing ambiguity

* Bring back `has_item_with_flag`

Now that `cache_visit_items_with` only accepts item type flags, the original functionality to check for non-type flags like WET has been lost. This brings that back.

* Unused lambda captures

* Reference the references

---------

Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>
2023-09-04 23:47:42 -05:00
Alexey 07356b65a5 Normalize TEST_CASE names (#66241)
* Convert integer parsing test to use normal TEST_CASEs

* Rename test name too similar to another

* Test to enforce normalized test names

* Normalize TEST_CASE names (scripted)
2023-06-17 13:57:19 -03:00
Alexey 568aa76de8 Unwrap activity_actors into their own assign_activity overload 2023-04-23 03:58:10 +03:00
mqrause fe5350e30f item components as map (#62498)
Co-authored-by: mqrause <martin@qrause.de>
2023-03-09 21:58:17 -05:00
mqrause 979718d90a change return type of Character::get_wielded_item to item_location (#58666)
Co-authored-by: mqrause <martin@qrause.de>
2022-07-09 02:03:09 -04:00
BevapDin f90f042ec4 Remove empty statements as they are meaningless. 2022-06-26 12:41:32 +02:00
David Seguin 766c26a663 Autopickup settings: preserve autopickup state between items 2022-03-17 16:58:04 -04:00
KorGgenT 99a62861eb Create wrapper for worn items called outfit 2022-02-27 23:44:51 -05:00
John Bytheway e95a4fc9b8 Promote string_id constants to global statics
Our string_id constants were a mixture of temporaries, locals, and
globals.  Pull them all out as globals, for consistency and efficiency.
The efficiency comes from the fact that each string_id instance caches
its respective int_id, and sharing one instance means that value need
not be recomputed.
2021-11-19 19:10:09 -05:00
Fris0uman aa69568ddc Make get_wielded_item() return a ref instead of a pointer (#51614) 2021-09-14 14:02:34 -07:00
Fris0uman da590d88ef Make weapon private (#50286)
* Make `weapon` private

* Update tests

* Rebase

* Appley suggestions

* Fix weapon dorping

* fix weapon saving

* Rename to get_wielded_item

* rename to set_wielded_item

* fixes

* Post rebase fixes

* fixes

* fix weapon saving

* fixes

* more rebase and fixes

* Apply suggestions

* post rebase fixes
2021-09-12 08:47:47 -07:00
Eric 51520f6245 Move more player to character (#50971)
* player to character

* Update npc_talk_test.cpp
2021-08-23 00:58:51 -07:00
Eric 9ea592c80c Remove player class from gameinventory (#50481) 2021-08-08 12:34:44 +03:00
topherclay 9389485934 player::takeoff rewrite to use item_location (#46989) 2021-07-04 19:12:28 -07:00
John Bytheway 8cc6378fc5 clang-tidy modernize-use-emplace (#48661)
* Port code to emplace_back

This is clang-tidy making automated changes to convert push_back into
emplace_back whenever the argument to push_back is either a constructor
call for the type in question of an expression of a type implicitly
convertible to the type in question.

This should eliminate one move-construction of the inserted object for
each call.

* Enable clang-tidy modernize-use-emplace
2021-07-03 07:42:06 -07:00
John Bytheway ebd549b300 Fix StringMaker ODR violations in tests
Catch2 provides a customization point for converting our types to
strings by specializing the StringMaker template.

We have some specializations in stringmaker.h, but this feature was only
working intermittently.  I finally figured out that was due to an ODR
violation.  The test files that didn't include stringmaker.h were
compiling a different specialization than the ones that did.

Re-jig the test includes so that any file including catch.hpp also
includes stringmaker.h, thereby ensuring that the custom
specializations are used everywhere and there is no ODR violation.

I achieved this by adding a new cata_catch.h header and making all
existing headers include catch.hpp via the new header.
2021-07-03 07:42:06 -07:00
John Bytheway a8f17b497e Enable clang-tidy readability-isolate-declaration (#48629)
* Enable clang-tidy readability-isolate-declaration

Enable this clang-tidy check and apply the changes it suggests.

Perform some minor refactoring on the result to move some declarations
to first use.

* Refactor some point code

These changes were suggested by clang-tidy as a result of the earlier
tweaks to isolate declarations.
2021-07-03 07:42:06 -07:00
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00
Aivean dcc7997329 extract read-only part of visitable interface
make visitable a real interface
2020-12-24 16:09:29 -08:00
Kevin Granade 14016d5ca8 extract activity_actor subclasses to a seperate header to reduce inclusion overhead and fanout (#45967) 2020-12-11 20:05:05 -08:00
RoyBerube 0c44caf2a6 dupe_fix 2020-11-07 21:04:53 -07:00
Eric Pierce 493cdf4acd Obsolete DEBUG_STORAGE mutation and remove effects
The "Debug Strong Back" mutation has been non-functional since switching
to nested containers, and is not needed for any in-game feature or test.

This commit removes all code related to the mutation, and obsoletes the
mutation JSON data.
2020-09-26 18:12:28 -06:00
ZhilkinSerg a94ce8df12 Use static cast instead of C-style functional cast 2020-09-04 10:13:36 +03:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00
anothersimulacrum 8eaa61fd8f Remove inventory.h from character.h
Convert it to a pimpl<T> to help speed up build times.
2020-08-03 23:25:28 +00:00
Kevin Granade 6d1841ac67 Precompiled Catch2 header (#42453)
* Hoist catch.hpp include to the top of files

* Precompile the catch header in tests
2020-07-29 01:28:26 +03:00
Kevin Granade 438774d386 Global getters (#41347)
* Make Character::stat into a standalone enum class

Enables forward declaration

* Remove player centric overload and unecessary include

* Remove player.h dependency from trap.cpp

* Add singleton-like accessors for avatar, map, weather and event_bus

* use accessors to remove includes of game.h
2020-06-16 16:48:45 +03:00
John Bytheway 4591cf4b37 Automated fixes for string_id constants
Fix various names and static/const-ness.
2020-05-28 06:36:18 -04:00
John Bytheway b83fc88b9e Convert itype_id to string_id<itype>
itype_id is (presumably) one of the oldest type ids in the game.  In
particular, it predates string_id, and was simply a typedef of
std::string.

This is bad for type safety.

Make it be a string_id specialization instead, and update the rest of
the code accordingly.
2020-05-19 21:07:40 -04:00
KorGgenT b95da6db91 turn off other invlet test 2020-05-02 16:05:20 -04:00
KorGgenT 6b4544ef05 turn off invlet tests 2020-05-02 16:05:19 -04:00
KorGgenT d34ddf6772 turn off some tests for a future pr 2020-05-02 16:05:14 -04:00