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

Allow spawning npc via iuse action #36358

Merged
merged 3 commits into from
Dec 27, 2019

Conversation

ZhilkinSerg
Copy link
Contributor

@ZhilkinSerg ZhilkinSerg commented Dec 22, 2019

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:

    "use_action": {
      "type": "place_npc",
      "npc_class_id": "true_foodperson",
      "summon_msg": "You summon a food hero!",
      "place_randomly": true,
      "moves": 50
    },

@ZhilkinSerg ZhilkinSerg added NPC / Factions NPCs, AI, Speech, Factions, Ownership [JSON] Changes (can be) made in JSON [C++] Changes (can be) made in C++. Previously named `Code` Items / Item Actions / Item Qualities Items and how they work and interact [Markdown] Markdown issues and PRs labels Dec 22, 2019
@Fris0uman
Copy link
Contributor

The Foodsignal is lit!

@yowshi
Copy link
Contributor

yowshi commented Dec 22, 2019

this would be so awesome to have.

@BevapDin
Copy link
Contributor

This needs an item that actually invokes it. Currently it's just dead code.

@yowshi
Copy link
Contributor

yowshi commented Dec 22, 2019

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.

if( place_randomly ) {
const tripoint_range target_range = points_in_radius( p.pos(), 1 );
target_pos = random_point( target_range, []( const tripoint & ) {
return true;
Copy link
Contributor

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() ) ) {
Copy link
Contributor

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?

Copy link
Contributor Author

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 Show resolved Hide resolved
} else {
const std::string query = _( "Place npc where?" );
target_pos = choose_adjacent( query );
if( !target_pos ) {
Copy link
Contributor

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.

src/iuse_actor.cpp Outdated Show resolved Hide resolved
src/iuse_actor.h Outdated Show resolved Hide resolved
@kevingranade kevingranade merged commit ba506fb into CleverRaven:master Dec 27, 2019
@ZhilkinSerg ZhilkinSerg deleted the iuse-summon-npc branch December 27, 2019 09:24
@ZhilkinSerg ZhilkinSerg mentioned this pull request Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Items / Item Actions / Item Qualities Items and how they work and interact [JSON] Changes (can be) made in JSON [Markdown] Markdown issues and PRs NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants