forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character_oracle.cpp
117 lines (105 loc) · 3.15 KB
/
character_oracle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <array>
#include <list>
#include <memory>
#include <string>
#include "behavior.h"
#include "bodypart.h"
#include "character.h"
#include "character_oracle.h"
#include "inventory.h"
#include "item.h"
#include "itype.h"
#include "player.h"
#include "ret_val.h"
#include "value_ptr.h"
#include "weather.h"
static const std::string flag_FIRESTARTER( "FIRESTARTER" );
namespace behavior
{
// To avoid a local minima when the character has access to warmth in a shelter but gets cold
// when they go outside, this method needs to only alert when travel time to known shelter
// approaches time to freeze.
status_t character_oracle_t::needs_warmth_badly() const
{
const player *p = dynamic_cast<const player *>( subject );
// Use player::temp_conv to predict whether the Character is "in trouble".
for( const body_part bp : all_body_parts ) {
if( p->temp_conv[ bp ] <= BODYTEMP_VERY_COLD ) {
return running;
}
}
return success;
}
status_t character_oracle_t::needs_water_badly() const
{
// Check thirst threshold.
if( subject->get_thirst() > thirst_levels::parched ) {
return running;
}
return success;
}
status_t character_oracle_t::needs_food_badly() const
{
// Check hunger threshold.
if( subject->get_kcal_percent() < 0.5f ) {
return running;
}
return success;
}
status_t character_oracle_t::can_wear_warmer_clothes() const
{
const player *p = dynamic_cast<const player *>( subject );
// Check inventory for wearable warmer clothes, greedily.
// Don't consider swapping clothes yet, just evaluate adding clothes.
for( const auto &i : subject->inv.const_slice() ) {
const item &candidate = i->front();
if( candidate.get_warmth() > 0 || p->can_wear( candidate ).success() ) {
return running;
}
}
return failure;
}
status_t character_oracle_t::can_make_fire() const
{
// Check inventory for firemaking tools and fuel
bool tool = false;
bool fuel = false;
for( const auto &i : subject->inv.const_slice() ) {
const item &candidate = i->front();
if( candidate.has_flag( flag_FIRESTARTER ) ) {
tool = true;
if( fuel ) {
return running;
}
} else if( candidate.flammable() ) {
fuel = true;
if( tool ) {
return running;
}
}
}
return success;
}
status_t character_oracle_t::can_take_shelter() const
{
// See if we know about some shelter
// Don't know how yet.
return failure;
}
status_t character_oracle_t::has_water() const
{
// Check if we know about water somewhere
bool found_water = subject->inv.has_item_with( []( const item & cand ) {
return cand.is_food() && cand.get_comestible()->quench > 0;
} );
return found_water ? running : failure;
}
status_t character_oracle_t::has_food() const
{
// Check if we know about food somewhere
bool found_food = subject->inv.has_item_with( []( const item & cand ) {
return cand.is_food() && cand.get_comestible()->has_calories();
} );
return found_food ? running : failure;
}
} // namespace behavior