check_and_recover_morale() was replacing the entire morale object when
it found a permanent-point inconsistency, wiping all temporary morale
(food, music, social, etc.). Players would go from +48 to +2.
Two fixes:
1. Add sync_permanent() that replaces only permanent morale points and
non-point state (prozac, pain, radiation, mutations, body parts),
preserving temporary morale. Use it instead of full replacement.
2. After morale->load() in save loading, activate mutations in morale's
internal tracking. Without this, has_mutation() returns false for all
traits, so update_constrained_penalty() and update_masochist_bonus()
compute wrong values when triggered by item equips or stat changes.
Add clear_map() to reset terrain, items, fields, and lighting state
before the visibility-at-midnight check. Without it, stale light
sources from previous tests can illuminate the player position,
making ambient_light_at() exceed natural_light_level_cache and
giving the NPC full sight range at midnight.
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.
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.
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.
A first step towards IWYU support. Doing the sorting first because it
makes reviewing any additions or removals of headers much simpler.
The IWYU order is:
- Associated headers
- Misc system headers
- C++ STL headers
- Other project headers
The biggest change is moving system headers before project headers (they
are usually afterwards in Cata at the moment.
The associated header for a cpp file is the header file which declares
the functions defined in that cpp file. Normally that's the one which
shares the same name (up to extension), and if so IWYU figures it out
automatically.
However, in this project there are many corner cases, so we need to use
IWYU pragma: associated to tell it which header (or, in some cases,
which headers) is the associated header. We are unusual in having
multiple associated headers for some files, which might lead to
discovering some interesting IWYU bugs later, but in theory it is
supported.