Skip to content

Commit

Permalink
Jsonize autodoc couch (#36200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman authored and kevingranade committed Jan 2, 2020
1 parent 1b3b2db commit a85a02a
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 29 deletions.
4 changes: 2 additions & 2 deletions data/json/furniture_and_terrain/furniture-medical.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"move_cost_mod": -1,
"coverage": 35,
"required_str": -1,
"flags": [ "TRANSPARENT" ],
"flags": [ "TRANSPARENT", "AUTODOC" ],
"examine_action": "autodoc",
"deconstruct": {
"items": [
Expand Down Expand Up @@ -66,7 +66,7 @@
{ "item": "cable", "charges": [ 1, 2 ], "prob": 50 }
]
},
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "ORGANIC", "BLOCKSDOOR", "MOUNTABLE" ],
"flags": [ "TRANSPARENT", "FLAMMABLE_ASH", "ORGANIC", "BLOCKSDOOR", "MOUNTABLE", "AUTODOC_COUCH" ],
"bash": {
"str_min": 10,
"str_max": 40,
Expand Down
3 changes: 3 additions & 0 deletions doc/JSON_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ List of known flags, used in both `terrain.json` and `furniture.json`.
### Examine Actions
- ```aggie_plant``` Harvest plants.
- ```autodoc``` Brings the autodoc consoles menu. Needs the ```AUTODOC``` flag to function properly and an adjacent furniture with the ```AUTODOC_COUCH``` flag.
- ```autoclave_empty``` Start the autoclave cycle if it contains filthy CBM, and the player has enough water.
- ```autoclave_full``` Check on the progress of the cycle, and collect sterile CBM once cycle is completed.
- ```bars``` Take advantage of AMORPHOUS and slip through the bars.
Expand Down Expand Up @@ -640,6 +641,8 @@ List of known flags, used in both `terrain.json` and `furniture.json`.
### Furniture Only
- ```AUTODOC``` This furniture can be an autodoc console, it also needs the ```autodoc``` examine action.
- ```AUTODOC_COUCH``` This furniture can be a couch for a furniture with the ```autodoc``` examine action.
- ```BLOCKSDOOR``` This will boost map terrain's resistance to bashing if `str_*_blocked` is set (see `map_bash_info`)
Expand Down
17 changes: 10 additions & 7 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ static const efftype_id effect_controlled( "controlled" );

static const trait_id trait_ILLITERATE( "ILLITERATE" );

static const std::string flag_AUTODOC( "AUTODOC" );
static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );

using namespace activity_handlers;

const std::map< activity_id, std::function<void( player_activity *, player * )> >
Expand Down Expand Up @@ -3153,10 +3156,10 @@ void activity_handlers::operation_do_turn( player_activity *act, player *p )
time_duration time_left = time_duration::from_turns( act->moves_left / 100 ) ;

if( autodoc && g->m.inbounds( p->pos() ) ) {
const std::list<tripoint> autodocs = g->m.find_furnitures_in_radius( p->pos(), 1,
furn_str_id( "f_autodoc" ) );
const std::list<tripoint> autodocs = g->m.find_furnitures_with_flag_in_radius( p->pos(), 1,
flag_AUTODOC );

if( g->m.furn( p->pos() ) != furn_str_id( "f_autodoc_couch" ) || autodocs.empty() ) {
if( !g->m.has_flag_furn( flag_AUTODOC_COUCH, p->pos() ) || autodocs.empty() ) {
p->remove_effect( effect_under_op );
act->set_to_null();

Expand Down Expand Up @@ -3294,17 +3297,17 @@ void activity_handlers::operation_finish( player_activity *act, player *p )
if( act->values[1] > 0 ) {
add_msg( m_good,
_( "The Autodoc returns to its resting position after successfully performing the operation." ) );
const std::list<tripoint> autodocs = g->m.find_furnitures_in_radius( p->pos(), 1,
furn_str_id( "f_autodoc" ) );
const std::list<tripoint> autodocs = g->m.find_furnitures_with_flag_in_radius( p->pos(), 1,
flag_AUTODOC );
sounds::sound( autodocs.front(), 10, sounds::sound_t::music,
_( "a short upbeat jingle: \"Operation successful\"" ), true,
"Autodoc",
"success" );
} else {
add_msg( m_bad,
_( "The Autodoc jerks back to its resting position after failing the operation." ) );
const std::list<tripoint> autodocs = g->m.find_furnitures_in_radius( p->pos(), 1,
furn_str_id( "f_autodoc" ) );
const std::list<tripoint> autodocs = g->m.find_furnitures_with_flag_in_radius( p->pos(), 1,
flag_AUTODOC );
sounds::sound( autodocs.front(), 10, sounds::sound_t::music,
_( "a sad beeping noise: \"Operation failed\"" ), true,
"Autodoc",
Expand Down
8 changes: 4 additions & 4 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ static const trait_id trait_THRESH_MARLOSS( "THRESH_MARLOSS" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );
static const trap_str_id tr_unfinished_construction( "tr_unfinished_construction" );

static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );

static void pick_plant( player &p, const tripoint &examp, const std::string &itemType,
ter_id new_ter,
bool seeds = false );
Expand Down Expand Up @@ -4285,8 +4287,7 @@ static player &player_on_couch( player &p, const tripoint &autodoc_loc, player &
bool &adjacent_couch, tripoint &couch_pos )
{
for( const auto &couch_loc : g->m.points_in_radius( autodoc_loc, 1 ) ) {
const furn_str_id couch( "f_autodoc_couch" );
if( g->m.furn( couch_loc ) == couch ) {
if( g->m.has_flag_furn( flag_AUTODOC_COUCH, couch_loc ) ) {
adjacent_couch = true;
couch_pos = couch_loc;
if( p.pos() == couch_loc ) {
Expand All @@ -4306,8 +4307,7 @@ static Character &operator_present( Character &p, const tripoint &autodoc_loc,
Character &null_patient )
{
for( const auto &loc : g->m.points_in_radius( autodoc_loc, 1 ) ) {
const furn_str_id couch( "f_autodoc_couch" );
if( g->m.furn( loc ) != couch ) {
if( !g->m.has_flag_furn( flag_AUTODOC_COUCH, loc ) ) {
if( p.pos() == loc ) {
return p;
}
Expand Down
6 changes: 3 additions & 3 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8180,13 +8180,13 @@ std::list<item_location> map::get_active_items_in_radius( const tripoint &center
return result;
}

std::list<tripoint> map::find_furnitures_in_radius( const tripoint &center, size_t radius,
furn_id target,
std::list<tripoint> map::find_furnitures_with_flag_in_radius( const tripoint &center, size_t radius,
const std::string &flag,
size_t radiusz )
{
std::list<tripoint> furn_locs;
for( const auto &furn_loc : points_in_radius( center, radius, radiusz ) ) {
if( furn( furn_loc ) == target ) {
if( has_flag_furn( flag, furn_loc ) ) {
furn_locs.push_back( furn_loc );
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1807,9 +1807,9 @@ class map
std::list<item_location> get_active_items_in_radius( const tripoint &center, int radius,
special_item_type type ) const;

/**returns positions of furnitures matching target in the specified radius*/
std::list<tripoint> find_furnitures_in_radius( const tripoint &center, size_t radius,
furn_id target,
/**returns positions of furnitures with matching flag in the specified radius*/
std::list<tripoint> find_furnitures_with_flag_in_radius( const tripoint &center, size_t radius,
const std::string &flag,
size_t radiusz = 0 );
/**returns creatures in specified radius*/
std::list<Creature *> get_creatures_in_radius( const tripoint &center, size_t radius,
Expand Down
4 changes: 1 addition & 3 deletions src/mapdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,7 @@ furn_id f_null,
f_brazier,
f_firering,
f_tourist_table,
f_camp_chair,
f_autodoc_couch;
f_camp_chair;

void set_furn_ids()
{
Expand Down Expand Up @@ -1065,7 +1064,6 @@ void set_furn_ids()
f_wind_mill_active = furn_id( "f_wind_mill_active" );
f_robotic_arm = furn_id( "f_robotic_arm" );
f_brazier = furn_id( "f_brazier" );
f_autodoc_couch = furn_id( "f_autodoc_couch" );
f_firering = furn_id( "f_firering" );
f_tourist_table = furn_id( "f_tourist_table" );
f_camp_chair = furn_id( "f_camp_chair" );
Expand Down
3 changes: 1 addition & 2 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,7 @@ extern furn_id f_null,
f_brazier,
f_firering,
f_tourist_table,
f_camp_chair,
f_autodoc_couch;
f_camp_chair;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// These are on their way OUT and only used in certain switch statements until they are rewritten.
Expand Down
6 changes: 4 additions & 2 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ static const trait_id trait_TAIL_CATTLE( "TAIL_CATTLE" );
static const trait_id trait_THRESH_MARLOSS( "THRESH_MARLOSS" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );

static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );

// shared utility functions
static bool within_visual_range( monster *z, int max_range )
{
Expand Down Expand Up @@ -2951,8 +2953,8 @@ bool mattack::nurse_operate( monster *z )

z->friendly = 0;
z->anger = 100;
std::list<tripoint> couch_pos = g->m.find_furnitures_in_radius( z->pos(), 10,
furn_id( "f_autodoc_couch" ) ) ;
std::list<tripoint> couch_pos = g->m.find_furnitures_with_flag_in_radius( z->pos(), 10,
flag_AUTODOC_COUCH ) ;

if( couch_pos.empty() ) {
add_msg( m_info, _( "The %s looks for something but doesn't seem to find it." ), z->name() );
Expand Down
8 changes: 5 additions & 3 deletions src/monmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static const efftype_id effect_harnessed( "harnessed" );

static const species_id ZOMBIE( "ZOMBIE" );

static const std::string flag_AUTODOC_COUCH( "AUTODOC_COUCH" );

bool monster::wander()
{
return ( goal == pos() );
Expand Down Expand Up @@ -486,8 +488,8 @@ void monster::plan()
bool found_path_to_couch = false;
tripoint tmp( pos() + point( 12, 12 ) );
tripoint couch_loc;
for( const auto &couch_pos : g->m.find_furnitures_in_radius( pos(), 10,
furn_id( "f_autodoc_couch" ) ) ) {
for( const auto &couch_pos : g->m.find_furnitures_with_flag_in_radius( pos(), 10,
flag_AUTODOC_COUCH ) ) {
if( g->m.clear_path( pos(), couch_pos, 10, 0, 100 ) ) {
if( rl_dist( pos(), couch_pos ) < rl_dist( pos(), tmp ) ) {
tmp = couch_pos;
Expand Down Expand Up @@ -971,7 +973,7 @@ void monster::nursebot_operate( player *dragged_foe )
return;
}

if( rl_dist( pos(), goal ) == 1 && g->m.furn( goal ) == furn_id( "f_autodoc_couch" ) &&
if( rl_dist( pos(), goal ) == 1 && !g->m.has_flag_furn( flag_AUTODOC_COUCH, goal ) &&
!has_effect( effect_operating ) ) {
if( dragged_foe->has_effect( effect_grabbed ) && !has_effect( effect_countdown ) &&
( g->critter_at( goal ) == nullptr || g->critter_at( goal ) == dragged_foe ) ) {
Expand Down

0 comments on commit a85a02a

Please sign in to comment.