-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Allow spawning npc via iuse action #36358
Conversation
The Foodsignal is lit! |
this would be so awesome to have. |
This needs an item that actually invokes it. Currently it's just dead code. |
well, he has an example of something which invokes, and it came out of a question of me asking if there was a way to spawn NPC's outside of debug menu. EDIT: Because i have plans for an item which does exactly that. |
src/iuse_actor.cpp
Outdated
if( place_randomly ) { | ||
const tripoint_range target_range = points_in_radius( p.pos(), 1 ); | ||
target_pos = random_point( target_range, []( const tripoint & ) { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check !g->m.passable
. Currently this function may find a point that is actually impassable. Try this out inside solid rock, with only one free spot for the player character to stand on and one other free spot, with a target_range
above 0. It will almost always find a random point that is actually impassable, but there is a suitable spot nearby.
Later this will be reported as "There is no square to spawn npc in!". (It actually wont, as calling value
on an empty cata::optional
will already fail.)
return 0; | ||
} | ||
} | ||
if( !g->m.passable( target_pos.value() ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about tiles that have only air (no floor)? What about tiles that another creature (npc, monster, player) in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it in a follow-up PR.
src/iuse_actor.cpp
Outdated
} else { | ||
const std::string query = _( "Place npc where?" ); | ||
target_pos = choose_adjacent( query ); | ||
if( !target_pos ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be below, outside of the if( place_randomly )
block, so it considers the result of random_point
as well.
Co-Authored-By: BevapDin <tho_ki@gmx.de>
Summary
SUMMARY: Infrastructure "Allow spawning npc via iuse action"
Purpose of change
Allow spawning npc via iuse action (somebody on Discord wanted to use it in a mod).
Describe the solution
Added new iuse action for spawning npc.
Testing
Add following code to any item and activate it in game to spawn npc: