Skip to content

Commit

Permalink
Fix place npc iuse (#42647)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg authored Aug 3, 2020
1 parent 824baec commit 9ffafff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,8 @@ The contents of use_action fields can either be a string indicating a built-in f
"npc_class_id": "true_foodperson", // npc class id, see npcs/classes.json
"summon_msg": "You summon a food hero!", // (optional) message when summoning the npc.
"place_randomly": true, // if true: places npc randomly around the player, if false: let the player decide where to put it (default: false)
"moves": 50 // how many move points the action takes.
"moves": 50, // how many move points the action takes.
"radius": 1 // maximum radius for random npc placement.
},
"use_action" : {
"type" : "delayed_transform", // Like transform, but it will only transform when the item has a certain age
Expand Down
24 changes: 10 additions & 14 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,20 +971,16 @@ void place_npc_iuse::load( const JsonObject &obj )
int place_npc_iuse::use( player &p, item &, bool, const tripoint & ) const
{
map &here = get_map();
cata::optional<tripoint> target_pos;
if( place_randomly ) {
const tripoint_range<tripoint> target_range = points_in_radius( p.pos(), 1 );
target_pos = random_point( target_range, [&here]( const tripoint & t ) {
return !here.passable( t );
} );
} else {
const std::string query = _( "Place npc where?" );
target_pos = choose_adjacent( _( "Place npc where?" ) );
}
if( !target_pos ) {
return 0;
}
if( !here.passable( target_pos.value() ) ) {
const tripoint_range<tripoint> target_range = place_randomly ?
points_in_radius( p.pos(), radius ) :
points_in_radius( choose_adjacent( _( "Place npc where?" ) ).value_or( p.pos() ), 0 );

const cata::optional<tripoint> target_pos =
random_point( target_range, [&here]( const tripoint & t ) {
return here.passable( t ) && here.has_floor_or_support( t ) && !g->critter_at( t );
} );

if( !target_pos.has_value() ) {
p.add_msg_if_player( m_info, _( "There is no square to spawn npc in!" ) );
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/iuse_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ class place_npc_iuse : public iuse_actor
public:
string_id<npc_template> npc_class_id;
bool place_randomly = false;
int radius = 1;
int moves = 100;
std::string summon_msg;

Expand Down

0 comments on commit 9ffafff

Please sign in to comment.