97 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
kuutekitty cfe6af8c73 remove and migrate obsolete ammo (#88400)
* migrate reloadd, matchead, and bp ammo to the base bullet

* rename

* fix typos

* remove mentiosn of 223, 338

* do 303, 300, 10mm, and others

* 32, 357

* 38, 380

* everything else

* fix tests

* fix nr 2

* start fixing tests and item demographics

* remove all mentions, hopefully

* fix gg_ammo_migration ?
2026-08-28 17:57:09 -05:00
dumb-kevin 1cad28fd43 Avoid unnecessary copies in drop and debug menu helpers
- bind item_location by const ref in zone drop debug log loop in activity_actor.cpp
- bind mission_type::get_all() result by const ref in mission-add debug menu
- bind selected dialogue topic by const ref in talk-topic debug menu
- NOLINT outfit_component copy near who.takeoff; takeoff can invalidate worn_item before force_insert_item runs
2026-05-09 10:02:28 +04:00
dumb-kevin e4bb943d3b Fix CI skip-detection job refs, Makefile parallel safety, and test tag syntax
- matrix.yml SKIP condition referenced non-existent job names
  (skip-duplicates, skip-duplicates-mods); corrected to match declared
  jobs (skip-duplicates-code, skip-duplicates-data). Same fix for the
  commented emscripten block.
- tests/Makefile batch runs now use --user-dir with a unique PID-based
  path so parallel shard execution doesn't collide on filesystem state.
- Normalized comma-separated TEST_CASE tags to space-separated across
  9 test files (25 declarations). Comma syntax is deprecated in Catch2
  v2 and removed in v3. Also fixed a missing space between adjacent
  tags in throwing_test.cpp.
2026-02-24 21:24:24 +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
Gabriel Sibley 4f75c4aa59 Fix usages in tests 2025-11-23 21:36:05 -04:00
marilynias 1271c8b08a Refactor and consolidate wield (#79719)
* refactor wield

* refactor wield

* rename wield_new, replace tests

* return early

* fix test and .h var name

* add unwield from game.wield
add_msg_if_player

* remove references to u.

* small fixes

* missing ;

* fix unwield

* fix test

* remove_old for compatibility

* wrong paranthesis

* correct wield_new

* use more wield_new, remove some reminder comments

* fix craft

* fix wielding from reloading

* remove commented out code

* rename weapon -> wielded

* IWYU

* fix wrong move cost
use correct wield for 'one of the bottles is wielded' test

* remove debug msg

* fix tests / clang-tidy

* I hate those tests

* fex 2/3 tests

* please let this be the last test

* clang-tidy

* apply some reviews, remove reminder comments

* re-work; overload item_location from item,

* fix missing item replacement

* fix using item after removing

* revert unecessary changes

* fix missed revert

* move steal check to avatar overload

* this time for real

* extend wield( item_location loc)

* fix

* forgot to do the actual wielding

* fix moves test, apply clang-tidy

* correct obtain cost, doc

* clang-tidy, cleaner conditional

* ordering

* move to std::optional instead of default

* fix optional

* fix 2

---------

Co-authored-by: marilynias <marilynias57+github@gmail.com>
2025-03-01 22:46:14 +01: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
PatrikLundell f9900fccc2 Merge pull request #79670 from PatrikLundell/mapify
mapify: split ammo remaining into link and non link
2025-02-16 14:49:56 -06:00
PatrikLundell 7bfa56fa99 Merge branch 'master' into mapify 2025-02-13 08:46:56 +01:00
moxian c44d65a8ae Run IWYU again to pick up the changes 2025-02-11 13:02:19 -08:00
PatrikLundell 0ac675121c mapified a little item prompting a lot of vehicle 2025-02-11 15:10:00 +01: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
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
Clarence "Sparr" Risher 8b27b967ae Replace point constants with static class members 2024-11-26 10:14:26 -05: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
mqrause 25bfa40b43 use automatic ammo selection and reload activity in integral magazine speedloader reloading test 2024-08-19 09:42:19 +02:00
Anton Simakov 381e661f12 replace modular m4 carabin item with respective itemgroup (#75298)
* replace modular m4 carabin item with respective itemgroup

* fix incorrect syntax in vehicle spawn

* fix wrongdoing of find and replace

* make test version of m4 carbine with reveiver to handle test

* fix debug item version having lack of name

* fix even more tests

* more test fixes

* add modular_m4_carbine to dps tests

* sort itypes in reload_magazine_test
2024-08-01 01:15:33 -05:00
Holli 29456b1fec Remove survivor launchers (#75172) 2024-07-23 10:18:19 -05: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
osuphobia 46926a4a3a Not to try to reload a gun without default ammo type defined (#73714)
* Should not reload a gun without ammo defined.

* Update src/item_location.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-05-12 19:07:23 -04:00
Anton Simakov 7b1fec4ed5 Further receiver cleanups (#70473)
* further receiver cleanups

* lint

* fixing tests that use obsoleted guns in tests

* more fixing
2023-12-27 15:12:07 -06:00
mqrause bd211963e6 move item_pocket::pocket_type to it's own header 2023-11-27 13:22:35 +01: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
Zhilkin Serg e44f38af40 Remove excessive empty lines 2022-12-06 10:42:15 +03: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
Hirmuolio aaacceb23c Handle item temperature as float (#58172) 2022-06-24 07:30:16 -07:00
mqrause d688521e7b Character::i_add returns an item_location (#58191)
Co-authored-by: mqrause <martin@qrause.de>
2022-06-18 21:27:30 -04:00
KorGgenT 99a62861eb Create wrapper for worn items called outfit 2022-02-27 23:44:51 -05:00
Hirmuolio 94f0268f53 Allow reloading guns with mixed ammo (#54028) 2022-01-14 19:55:01 -08:00
Hirmuolio 5c469add50 Reloading weapons reloads guns and magazines only (#53426)
* skip non-gun/magazines

* use reload_wielded in tests
2021-12-16 22:26:00 -08:00
Hirmuolio 0f3ea21bba Reloadability check refactoring (#53102)
* use item instead of item_id
* watertight containers are reloadable
* mods are reloadable, same_contents checks contents of contents
* add large number of new tests
2021-12-12 18:03:27 -08: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
mqrause e1a3575a09 private contents member and remove most item_contents.h includes 2021-07-23 00:23:22 +02:00
mqrause 9bf95457cd remove uses of item_contents::remaining_container_capacity in reloading_test.cpp and item_contents::remove_item_if in item_contents_test.cpp 2021-07-22 23:01:41 +02:00
mqrause 33905d9879 wrappers for item_contents::handle_liquid_or_spill and item_contents::total_contained_volume in item 2021-07-22 15:44:11 +02:00
mqrause dbd0913999 wrappers for item_contents::first_ammo and item_contents::get_item_with in item 2021-07-22 15:43:38 +02:00
mqrause 1da011a713 wrappers for item_contents::spill_open_pockets and item_contents::empty in item 2021-07-08 12:28:06 +02: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
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
John Bytheway b285a13080 Make time_point( int ) constructor explicit
Resolves a TODO on that constructor, and one more TODO elsewhere due to
the resulting refactoring.

time_point was implicitly convertible from int.  This led to unclear
code.  In particular, the item constructor took a time_point and a
quantity, and these two ints appeared adjacent with no obvious way to
see what they meant at call sites.

Make the constructor explicit, so the conversion is no longer implicit.
Update the rest of the code accordingly.

In most cases switched from 0 to calendar::turn_zero, which is
equivalent.  In a couple of places, used start_of_cataclysm instead,
when it seemed more appropriate (such as birthday of toilet water).
It's possible there are more cases which should have been something
other than turn_zero.
2020-11-10 11:21:02 -08:00
Aivean c32a629ceb replace all item flag constants with static string_ids
remove adapter has_flag (and related) methods that took string argument
change all remaining method signatures where item flags were passed as strings
2020-10-18 19:56:40 -07:00
RoyBerube 3370bf3b76 reference misuse 2020-10-02 13:32:20 -06:00
RoyBerube 61118f7fae Unit tests for liquid reload 2020-10-02 12:53:32 -06:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00