Skip to content

Commit 4cbcd6e

Browse files
author
mqrause
committed
infrastructure changes to enable testing
1 parent 29511a3 commit 4cbcd6e

File tree

5 files changed

+46
-25
lines changed

5 files changed

+46
-25
lines changed

src/do_turn.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "creature_tracker.h"
99
#include "event_bus.h"
1010
#include "explosion.h"
11-
#include "field.h"
1211
#include "game.h"
1312
#include "gamemode.h"
1413
#include "help.h"
@@ -35,7 +34,6 @@
3534
#include "wcwidth.h"
3635
#include "worldfactory.h"
3736

38-
static const activity_id ACT_AIM( "ACT_AIM" );
3937
static const activity_id ACT_AUTODRIVE( "ACT_AUTODRIVE" );
4038
static const activity_id ACT_OPERATION( "ACT_OPERATION" );
4139

@@ -729,32 +727,13 @@ bool do_turn()
729727
// If player is performing a task, a monster is dangerously close,
730728
// and monster can reach to the player or it has some sort of a ranged attack,
731729
// warn them regardless of previous safemode warnings
732-
if( u.activity && !u.has_activity( ACT_AIM ) &&
733-
u.activity.moves_left > 0 &&
734-
!u.activity.is_distraction_ignored( distraction_type::hostile_spotted_near ) ) {
735-
Creature *hostile_critter = g->is_hostile_very_close( true );
736-
737-
if( hostile_critter != nullptr ) {
738-
g->cancel_activity_or_ignore_query( distraction_type::hostile_spotted_near,
739-
string_format( _( "The %s is dangerously close!" ),
740-
hostile_critter->get_name() ) );
741-
}
742-
}
743-
744-
if( u.activity && !u.has_activity( ACT_AIM ) && u.activity.moves_left > 0 &&
745-
!u.activity.is_distraction_ignored( distraction_type::dangerous_field ) ) {
746-
for( const std::pair<const field_type_id, field_entry> &field : m.field_at( u.pos() ) ) {
747-
if( u.is_dangerous_field( field.second ) ) {
748-
if( g->cancel_activity_or_ignore_query( distraction_type::dangerous_field,
749-
string_format( _( "You stand in %s!" ),
750-
field.second.name() ) ) ||
751-
u.activity.is_distraction_ignored( distraction_type::dangerous_field ) ) {
752-
break;
753-
}
730+
if( u.activity ) {
731+
for( std::pair<const distraction_type, std::string> &dist : u.activity.get_distractions() ) {
732+
if( g->cancel_activity_or_ignore_query( dist.first, dist.second ) ) {
733+
break;
754734
}
755735
}
756736
}
757-
758737
}
759738
}
760739

src/game.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,6 +3854,18 @@ Creature *game::is_hostile_within( int distance, bool dangerous )
38543854
return nullptr;
38553855
}
38563856

3857+
field_entry *game::is_in_dangerous_field()
3858+
{
3859+
map &here = get_map();
3860+
for( std::pair<const field_type_id, field_entry> &field : here.field_at( u.pos() ) ) {
3861+
if( u.is_dangerous_field( field.second ) ) {
3862+
return &field.second;
3863+
}
3864+
}
3865+
3866+
return nullptr;
3867+
}
3868+
38573869
std::unordered_set<tripoint> game::get_fishable_locations( int distance, const tripoint &fish_pos )
38583870
{
38593871
// We're going to get the contiguous fishable terrain starting at

src/game.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ class game
559559
character_id assign_npc_id();
560560
Creature *is_hostile_nearby();
561561
Creature *is_hostile_very_close( bool dangerous = false );
562+
field_entry *is_in_dangerous_field();
562563
// Handles shifting coordinates transparently when moving between submaps.
563564
// Helper to make calling with a player pointer less verbose.
564565
point update_map( Character &p, bool z_level_changed = false );

src/player_activity.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "calendar.h"
1111
#include "character.h"
1212
#include "construction.h"
13+
#include "field.h"
14+
#include "game.h"
1315
#include "item.h"
1416
#include "itype.h"
1517
#include "map.h"
@@ -464,3 +466,28 @@ void player_activity::inherit_distractions( const player_activity &other )
464466
ignore_distraction( type );
465467
}
466468
}
469+
470+
471+
std::map<distraction_type, std::string> player_activity::get_distractions()
472+
{
473+
std::map < distraction_type, std::string > res;
474+
if( id() != ACT_AIM && moves_left > 0 ) {
475+
if( !is_distraction_ignored( distraction_type::hostile_spotted_near ) ) {
476+
Creature *hostile_critter = g->is_hostile_very_close( true );
477+
if( hostile_critter != nullptr ) {
478+
res.emplace( distraction_type::hostile_spotted_near,
479+
string_format( _( "The %s is dangerously close!" ),
480+
g->is_hostile_very_close( true )->get_name() ) );
481+
}
482+
}
483+
if( !is_distraction_ignored( distraction_type::dangerous_field ) ) {
484+
field_entry *field = g->is_in_dangerous_field();
485+
if( field != nullptr ) {
486+
res.emplace( distraction_type::dangerous_field, string_format( _( "You stand in %s!" ),
487+
g->is_in_dangerous_field()->name() ) );
488+
}
489+
}
490+
}
491+
492+
return res;
493+
}

src/player_activity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ class player_activity
178178
bool do_drop_invalid_inventory() const {
179179
return !actor || actor->do_drop_invalid_inventory();
180180
}
181+
182+
std::map<distraction_type, std::string> get_distractions();
181183
};
182184

183185
#endif // CATA_SRC_PLAYER_ACTIVITY_H

0 commit comments

Comments
 (0)