36 Commits

Author SHA1 Message Date
RenechCDDA da2aaffffd Add quick setup option to clear map 2026-06-22 15:07:51 -04:00
Alex Mooney b821358c28 Place player so npc_light_and_fine_detail_vision_mod can pass 2026-02-18 21:02:03 -08: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
Holli 3dbab0f9ed Recontextualize atomic powered tools (#83244)
* Remove atomic stuff

* lint

* lint2

* fix tests (hopefully)

* fix tests more

* fix tests

* fix tests

* fix afs
2025-10-10 23:29:16 -05: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
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
Anton Simakov 58210e4986 Merge branch 'master' into map_scale_constants 2024-12-24 09:32:05 +01:00
GuardianDll 98fe6e6856 Merge branch 'master' of https://github.com/CleverRaven/Cataclysm-DDA into map_scale_constants 2024-12-21 22:17:23 +01:00
RenechCDDA 43c2abf54a Fix some tests that relied on previous ordering, maybe 2024-12-21 02:22:39 -05:00
Procyonae eed3ee5f73 Remove ledge trap hack (#78254)
* Rip out tr_ledge hack

* Make non Character creatures fall again

* Typify and rename ledge -> try_fall

* Add tr_ledge obsoletion

* Remove t_hole

* Fix climbing down triggering falling first resulting in you burying yourself

* Update map.cpp

* Fix being grapple pulled off a roof sending you into the ground

* Fix spawned NPCs not falling until they move

* Fix spawned monsters not falling until they move

Not the most ideal looking spot for this but its the only place all the calls I could find filter down to

* Fix a test expecting spawned NPCs to float

* Another test that expects floating to be fine

* Appease our clang overlords

* More appeasement

* Did you know stashing changes for one branch on another by accident and forgetting about them is not great?

* More fixes

* Appease our clang overlords

* Fix some since typified stuff
2024-12-18 20:01:23 -06:00
PatrikLundell c380147ab2 typified creature.h and monster.h (#78565)
* typified creature.h and monster.h

* Update src/monmove.cpp

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

* Update src/monster.h

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-12-16 22:16:00 -06:00
PatrikLundell fbf71a0f66 typified game.h and .cpp 2024-12-07 15:55:25 +01:00
Clarence "Sparr" Risher 8b27b967ae Replace point constants with static class members 2024-11-26 10:14:26 -05:00
Anton Simakov 7126340eab Merge branch 'master' into map_scale_constants 2024-09-10 09:41:05 +02:00
PatrikLundell ec028a90be typified lightmap 2024-05-07 16:05:53 +02:00
eso fd5cee2182 use MAX_VIEW_DISTANCE in place of hardcoded values. unmagic air opacity 2024-04-25 00:03:14 -07:00
PatrikLundell f78bf49442 Fix companions ceasing activities when PC enter Z level (#72883)
* Fix companions ceasing activities when PC enter Z level

* fix night light test
2024-04-09 18:12:27 -04:00
Qrox c52a49e3f8 Work around NPC aborting activity due to unbuilt light map
Light map is only built on the player character's z level even with 3D FOV on, and building the light map on all NPCs' levels might be too expensive, so simply let NPCs finish their business when not on the player character's z-level for now, like what was done for non-3D-FOV mode.
2024-01-29 13:37:26 +08:00
Qrox 46202a92a6 Remove FOV_3D option and default to 3d FOV 2024-01-28 11:06:56 +08:00
Brambor 1c4a43815a docs fix grammar, finish sentence, reword 2023-10-15 17:33:03 +02: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
andrei 0e78201e6c character: fix fine detail vision (#67295) 2023-07-30 19:53:43 +03: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
Anton Simakov af4a7b3d35 Fog and mist weather (#64954)
* initial commit

* no message

* improve calculations, currently uses test values

* oops

* no message

* no message

* fixing the wrong values, remove debug message

* tests: override weather in tests that need clear vision

* Andrei's fix of vision test

* vision_junction_reciprocity fix

* weather realism test fix

---------

Co-authored-by: andrei <a12l+git@runbox.com>
2023-04-21 16:24:02 -03:00
Hirmuolio 8bfa7ec839 Minor light level refactor (#59062)
* float double

* character

* monster

* incident

* astyle

* round npc vision

* unround npc vision
2022-08-17 12:54:02 +02:00
andrei 262de91aa7 Partially revert #56231 (#57235)
This reverts commit 52d991bb44.
2022-05-04 10:45:44 -07:00
Mylie 52d991bb44 Monster cameras, vision optimizations, and an implementation through Slime (#56231)
* Added monster support and Slime Ocularium

Currently the Ocularium cannot be created, this is intentional - Slimewave is still useful through slime minions from Omnicellular

* Large camera and rendering changes

Makes cameras independent from player vision radius limits, dirties vision cache while cameras are active, and adds better vision falloff to cameras.
In addition, removes recalculation of seen_cache during long activities except on refresh frames - an optimization that arose from camera needs.

* Updates tests, bugfixes player half-seeing monsters

Player was able to detect a monster existed, especially on the compass, but not see their location, when the mosnter was outside of sight_max range (usually 9999, but sometimes much smaller for certain mutations and effects)

* Vision lightcasting now checks sightmax first

Also upped MYOPIC vision radius, preventing an adverse effect of excessive blindness - and somehow making a much nicer vision effect for short-sighted characters.

Mirrors were giving inaccurate vision ranges - also I nerfed mirrors because its now possible to nerf mirrors.

Co-authored-by: bombasticSlacks <dillon.matchett@gmail.com>
Co-authored-by: Kevin Granade <kevin.granade@gmail.com>
2022-03-26 19:35:26 -07: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
Hirmuolio 6631d5e0f2 Adjust sun and moon light levels (#50068)
* Adjusted light levels
* sun rises at -1 degree
* various fixes to -1° sunrise
* reduce moonlight by 33%
* fix moon tests
2021-07-31 18:41:30 -07:00
John Bytheway a17ccb1888 Sunlight angle (#48090)
* Make turn_zero constexpr

* Add features to rl_vec3d

* Construct from rl_vec2d and z-coord
* Extract xy as rl_vec2d
* In-place scaling

* StringMaker support for rl_vec2d

* Add StringMaker specialization for time_point

* Add atan2( rl_vec2d ) overload

* Add units::asin returning units::angle

* Add sunlight angle calculation and tests

This is an initial implementation of sunlight_angle, which should work
OK for the first few days, but will break down before the end of the
first year.

One test plots the path of the sun through the sky at each solstice and
an equinox.  This is intended as a simple smell test that's easy for a
human to see when something has gone wrong with the sun angle algorithm.

* Add analemma unit test

* Tweak sunlight calculation away from reality

Because the game years don't match real-world years, we need to make
some adjustments to the sunlight angle calculations to allow for that.

* Use logical origin of sidereal time

We had an origin of 177, but 180 makes logical sense, so switch to that
as it's easier to understand.

* Derive sidereal time from angle_per_day

Removing one magic constant.

* mean_long, mean_anomaly in terms of angle_per_day

Remove more arbitrary constants from the calculation, and document those
which remain.

* Use game year length, not real-world one

This removes one more arbitrary constant and means that the sunlight
angle calculations ought to work for other season lengths.

* Unit test for handling season length

* Base sunrise and sunset on astronomical maths

This is the first change that allows the sun angle calculations to
actually influence the game.

We switch the sunrise and sunset times to match the sun positions as
calculated by the astronomical equations surrounding the location of the
sun.

This requires changing a few other places in the code, and updating a
lot of tests.

Heavinly inspired by Hirmuolio's work in #47570, but reimplemented
rather than cherry-picked.

Co-authored-by: Hirmuolio <hirmuolio@gmail.com>

* Support eternal season for new Sun calculations

When eternal season is set, always have the Sun behave as it does on
whatever day the game starts.

* Update some comments in sun_test.cpp

* Appease clang 3.8

* Improve comments and variable names

Based on Github review.

Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>

* Fix clang-tidy issues

* Assume solar time rather than timezone

Previously the sunlight angle code required you to pass a timezone.
Now, instead, it assumes the timezone is local solar time (determined by
the longitude).  This makes some of the calculations simpler and the API
less confusing.

It does mean that the test cases have drifted a little further from the
'true' Boston sunrise and sunset times, but they're still fairly close.

Co-authored-by: Hirmuolio <hirmuolio@gmail.com>
Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
2021-07-18 07:57:39 -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
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
Eric Pierce 6ce107c4df Add tests for Ursine Vision and other sight stuff
Add tests covering the Ursine Vision and impaired-while-blindfolded
fixes, as well as for several related aspects of Character sight
functions, including:

- sight_impaired: true if mutations/effects/clothing impair sight
- recalc_sight_limits: compute max_sight adjusted for such effects
- unimpaired_range: return max_sight, or 60 at most
- sight_range: atmosphere-attenuated vision range, max_sight at most
- fine_detail_vision_mod: crafting time multiplier based on light
2020-09-12 09:42:39 -06:00