Skip to content

Commit

Permalink
dialogue conditions: make is_safe work for tiles without monster groups
Browse files Browse the repository at this point in the history
The dialogue condition is_safe checks whether the overmap terrain
tile is_safe(), and that in turn checks if there are any unsafe
monster groups on the tile.  If a tile has no monster groups (and many
don't), the tile is safe.  This results is some weirdness when an
avatar and an NPC are in hand-to-hand combat with zombies and the NPC
is perfectly willing to train the avatar in lockpicking.

Add a new "is_safe()" function to talker, talker_npc, and npc, and
have the npc version return false if the NPC's ai_cache.total_danger
is greater than 0, and then return the union of the tile's is_safe()
and the talker's is_safe().  That seems to resolve the issue.
  • Loading branch information
mlangsdorf committed Oct 17, 2020
1 parent 5f38296 commit e57e97e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ template<class T>
void conditional_t<T>::set_at_safe_space()
{
condition = []( const T & d ) {
return overmap_buffer.is_safe( d.beta->global_omt_location() );
return overmap_buffer.is_safe( d.beta->global_omt_location() ) && d.beta->is_safe();
};
}

Expand Down
1 change: 1 addition & 0 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ class npc : public player
float evaluate_enemy( const Creature &target ) const;

void assess_danger();
bool is_safe() const;
// Functions which choose an action for a particular goal
npc_action method_of_fleeing();
npc_action method_of_attack();
Expand Down
5 changes: 5 additions & 0 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ void npc::assess_danger()
ai_cache.danger_assessment = assessment;
}

bool npc::is_safe() const
{
return ai_cache.total_danger <= 0;
}

float npc::character_danger( const Character &uc ) const
{
// TODO: Remove this when possible
Expand Down
3 changes: 3 additions & 0 deletions src/talker.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,8 @@ class talker
virtual void add_opinion( int /*trust*/, int /*fear*/, int /*value*/, int /*anger*/,
int /*debt*/ ) {}
virtual void set_first_topic( const std::string & ) {}
virtual bool is_safe() const {
return true;
}
};
#endif // CATA_SRC_TALKER_H
5 changes: 5 additions & 0 deletions src/talker_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,3 +888,8 @@ void talker_npc::set_first_topic( const std::string &chat_topic )
{
me_npc->chatbin.first_topic = chat_topic;
}

bool talker_npc::is_safe() const
{
return me_npc->is_safe();
}
1 change: 1 addition & 0 deletions src/talker_npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class talker_npc : public talker_character
void add_opinion( int trust, int fear, int value, int anger, int debt ) override;
bool enslave_mind() override;
void set_first_topic( const std::string &chat_topic ) override;
bool is_safe() const override;

protected:
npc *me_npc;
Expand Down

0 comments on commit e57e97e

Please sign in to comment.