- -30_C negates an absolute temperature and gives -303.15 K, far below minus thirty Celsius
- use units::from_celsius( -30 ) in the behavior tree score test and four preemption sections
- fire goes only in a hearth: fireplace, stove, brazier, fire ring or clay oven
- fuel is the NPC's own burnable firewood, or firewood or tinder in the hearth it may use
- a hearth that is a firewood pile, busy, off-limits, unburnable or full is skipped
- sleep search stays inside the reach and skips spots the NPC may not use
- the npc_sleep action asks the same permission as the behavior tree
- an NPC that sleeps past an obligation says so
- a failed sleep search pauses sleep a minute unless something changes
- replace should_follow_close with can_follow_player_now and desired_follow_radius
- gate on_shift, displaced_from_post, duty_urgency on is_walking_with
- drop guard_post early-return from npc_is_following
- pause under hold_position and guarding-idle when address_needs undecided
- update tests for new follower-vs-duty arbitration
- Add npc_within_camp() helper using basecamp::point_within_camp()
- Replace base-OMT checks in all six camp BT predicates/scores
- Fall back to base-OMT match when camp object is gone
- Align return_to_camp_duties() with expansion-aware check
- Add expansion-tile regression tests for free_time and camp_work
- Guard BT oracle predicates (needs_food/water_badly, urgency) on needs_food()
- Guard address_needs() food/water handling on needs_food()
- Make npc_noop consume moves when caller didn't
- Add NO_NPC_FOOD sections to behavior_test and npc loop test
assign_camp() and assign_guard() both set NPC_MISSION_GUARD_ALLY, so
the BT treats camp workers as guards. This causes oscillation between
hold_position and worker_downtime after returning from camp activities.
New NPC_MISSION_CAMP_RESIDENT for camp workers. CAMP_RESIDENT never
has guard_pos, so duty predicates naturally fail. Three new BT goals:
camp_work (job scanning), return_to_camp (overmap travel home), and
free_time (worker_downtime between jobs).
Camp residents can be temporarily ordered to guard (switches to
GUARD_ALLY, keeps assigned_camp). stop_guard preserves assigned_camp
so the player can send them back via "Go back to your camp" in
follower dialogue. New return_to_camp_duties talk effect for the
reverse transition.
On-load migration converts legacy GUARD_ALLY + assigned_camp NPCs,
including previous_mission for those saved mid-activity.
Remove the mission gate so the BT runs every turn for all NPCs, not
just guards and shopkeepers. Duty predicates now key off persistent
guard_pos only, ignoring temp sound-investigation anchors.
New BT goals under npc_priorities (utility scoring):
- npc_follow: fires for followers with follow_close, urgency 0.3-0.6
based on distance. NPCATT_LEAD excluded so leaders keep their own
pause/goto/keep-up behavior.
- goto_ordered_position: player-directed goto, urgency 0.65. Beats
follow but loses to life-threatening needs.
Idle dispatch: guard_pos holds post, temp anchor returns to origin,
no anchor falls through to the cascade.
npc_decision tree: fallback(combat, investigate, utility(needs, duty)).
Evaluates each NPC turn alongside the legacy cascade, logs symmetric
category comparison under DF_NPC_NEEDS. No behavior changes.
Needs and duty compete via utility scoring with child scores bubbling
up (no parent score override). Predicates mirror live cascade gates
for sound investigation and guard displacement.
Extend shelter search from radius 1 to 6 with LOS and creature checks.
Oracle delegates to the same helper so BT matches action scope.
Add vehicle cargo to find_nearby_food/warm_clothing, respecting locked
cargo and cargo-locking features.
Floor rate_food() quench penalty so calorie-positive food survives.
Drop the thirst-dominant hard filter -- rate_food scoring handles it.
Add harvest scavenging as last-resort food fallback in both extreme
and normal hunger paths. Adjacent harvestable terrain triggers examine,
distant terrain uses move_to_and_verify.
Sleepiness: new needs_sleep_badly predicate (fires at DEAD_TIRED/383)
and sleepiness_urgency score (0-1 against MASSIVE_SLEEPINESS/1000).
The can_sleep feasibility gate fires at EXHAUSTED (575) -- between
DEAD_TIRED and EXHAUSTED the need exists but the NPC pushes through.
Meth effect and positive stim also block sleep, matching the
deterministic checks from Character::can_sleep().
Shelter: can_take_shelter is now an action predicate. Returns running
when the NPC is outdoors with an adjacent passable INDOORS tile.
Returns failure when already indoors (action not applicable), when no
indoor tiles are nearby, or when the indoor tile is impassable.
Fix can_make_fire: was returning success instead of failure when no
fire supplies existed. process_predicates breaks on non-running results,
so success propagated through the fallback as warmth handled, hiding
the shelter check.
The npc_needs root node now uses the utility strategy instead of
sequential_until_done. Competing survival needs are prioritized by
urgency score rather than fixed tree order.
Score predicates on the three branch nodes:
- npc_homeostasis: npc_warmth_urgency
- npc_thirst: npc_thirst_urgency
- npc_hunger: npc_hunger_urgency
No gameplay change -- the behavior tree only drives the debug
diagnostic. But the diagnostic now shows dynamic priority shifts
(e.g., near-starvation beats moderate thirst).
Three new float-returning methods on character_oracle_t return 0-1
urgency values for use with the behavior tree utility strategy:
- thirst_urgency: thirst / 1200 (dehydration death threshold)
- hunger_urgency: 1 - stored_kcal / healthy_kcal (starvation proximity)
- warmth_urgency: coldest bodypart distance from BODYTEMP_NORM toward
BODYTEMP_FREEZING
Registered in score_predicate_map via make_score_function helper so
npc_behavior.json can reference them by name.
New strategy type that evaluates all children and selects the running
one with the highest score. This is the foundational piece for
kevingranade's NPC needs architecture (#28681) where competing survival
needs are prioritized by urgency (e.g. time_to_die estimates).
- behavior_return gains a score field (default 0.0, no impact on
existing strategies)
- node_t gains set_score_function() for attaching numeric scoring to
both leaf and branch nodes
- Score propagation works on branch nodes: a branch evaluates its
children via its own strategy, then attaches its score to the result.
This lets a utility parent pick between scored subtrees.
- JSON loading: nodes can specify "score" field referencing a named
score predicate from score_predicate_map. Unknown IDs are fatal
(matching strategy/predicate error handling).
- score_predicate_map starts empty, populated by future PRs adding
time_to_die oracle methods
- "utility" registered in strategy_map for JSON use
Add DF_NPC_NEEDS debug filter that evaluates the npc_behavior.json
behavior tree each NPC turn and logs the goal. Purely diagnostic,
no behavior change. Toggle it in the debug menu to see what the BT
would recommend for each NPC (idle, eat_food, drink_water, etc.).
Fix stale comments claiming NPCs can't starve -- they can and do
when needs_food() returns true. Mark the old enum npc_need system
and decide_needs() as legacy with pointers to the behavior tree
replacement path.
Add test coverage for thirst+hunger BT precedence and an integration
test verifying the diagnostic fires (and doesn't fire) based on the
debug filter.
* 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>
* 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
These are mostly automated changes. My automation tries to be
conservative, but I did have to do manual fixup of a few things.
I plan to PR the clang-tidy check that automates these changes later,
but I think more changes may be needed before that.
Some of the manual changes:
- Added svto<T> where T is an integer type, which parses integers in
string_views. This is our first use of the low-level C++17 int
conversion functions.
- Added a shortcut to lcmatch for empty queries, to allow for
refactoring overmapbuffer searches.
- Fixed an apparent bug in overmapbuffer::get_notes and get_extras,
where it was inverting the match result. As far as I can tell, these
functions aren't actually used anywhere, so I guess this bug wasn't
breaking anything.
- Allow use of string_view in JSON serialization. Previously these were
misidentified as sequences and appeared as a list of integers rather
than a string.
* Check that reviving items are corpses, not 1 specific corpse type
* Persist installed CBM info across revives
* Astyle
* Remove unused itype_corpse variable
* On first death, spawn CBMs into CORPSE pocket.
* Don't spawn non-cbm dissection items on death
* Revert "Don't spawn non-cbm dissection items on death"
This reverts commit 394309dc61.
* Dissect action now pulls from CORPSE pocket instead of generating from corpse's dissect entries.
* Comment cleanup
* Astyle
* Remove unused success variable
* Update failing tests. CORPSE pocket does not drop contents, but corpse's CONTAINER pocket does.
* Preserve drop type until dissection
Co-authored-by: psuedolet <psuedolet@gmail.com>
Previously behaviour_test was using extern declarations that linked to
values inside src/behaviour.cpp for its default behaviours. But that's
an unclear connection that's somewhat confusing. It might as well just
have its own static declarations of the same things.
There are three clang-tidy checks which are looking for use of reserved
identifiers. Enable all of them and fix or suppress the associated
warnings.
The reserved identifiers we had fall into three categories:
- Names containing "__"
- Names starting with "_" followed by a capital letter.
- Names starting with "_" in the global namespace.
Most of those could be automatically fixed by clang-tidy.
One was also affected by the cata-static-string_id-constants check,
which needed to be updated so they wouldn't conflict.
Two cases were erroneous and needed suppression.
The _ macro we use for translation is a reserved identifier, but we're
going to use it anyway. So that is also suppressed.
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.
* 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
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.
* 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++
* clear achievement tracker
* Guard against rounding errors with Approx()
* Add requirements to wield test.
* Manually set margins for comparison
* Just accept minor variation in results
* Verify that behavioral needs are needed
* Fix oracle checks
* Clear temperature cache in behavior test