Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix place npc iuse #42647

Merged
merged 2 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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