Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-Authored-By: Anton Burmistrov <11132525+Night-Pryanik@users.noreply.github.com>
  • Loading branch information
Maleclypse and Night-Pryanik committed Jun 4, 2023
1 parent 5325c6e commit 4529f65
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,8 @@ class npc : public Character

// Where we last saw the player
std::optional<tripoint_abs_ms> last_player_seen_pos;
// Player orders a friendly NPC to move to this position
std::optional<tripoint_abs_ms> goto_to_this_pos;
int last_seen_player_turn = 0; // Timeout to forgetting
tripoint wanted_item_pos; // The square containing an item we want
// These are the coordinates that a guard will return to inside of their goal tripoint
Expand Down
17 changes: 17 additions & 0 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ enum npc_action : int {
npc_flee, npc_melee, npc_shoot,
npc_look_for_player, npc_heal_player, npc_follow_player, npc_follow_embarked,
npc_talk_to_player, npc_mug_player,
npc_goto_to_this_pos,
npc_goto_destination,
npc_avoid_friendly_fire,
npc_escape_explosion,
Expand Down Expand Up @@ -926,6 +927,10 @@ void npc::move()
}
}

if( action == npc_undecided && is_walking_with() && goto_to_this_pos ) {
action = npc_goto_to_this_pos;
}

// check if in vehicle before doing any other follow activities
if( action == npc_undecided && is_walking_with() && player_character.in_vehicle &&
!in_vehicle ) {
Expand Down Expand Up @@ -1376,6 +1381,16 @@ void npc::execute_action( npc_action action )
mug_player( player_character );
break;

case npc_goto_to_this_pos: {
update_path( get_map().getlocal( *goto_to_this_pos ) );
move_to_next();

if( get_location() == *goto_to_this_pos ) {
goto_to_this_pos = std::nullopt;
}
break;
}

case npc_goto_destination:
go_to_omt_destination();
break;
Expand Down Expand Up @@ -4294,6 +4309,8 @@ std::string npc_action_name( npc_action action )
return "Do nothing";
case npc_do_attack:
return "Attack";
case npc_goto_to_this_pos:
return "Go to position";
case num_npc_actions:
return "Unnamed action";
}
Expand Down
34 changes: 34 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <vector>

#include "achievement.h"
#include "action.h"
#include "activity_type.h"
#include "auto_pickup.h"
#include "avatar.h"
Expand Down Expand Up @@ -311,6 +312,7 @@ enum npc_chat_menu {
NPC_CHAT_START_SEMINAR,
NPC_CHAT_SENTENCE,
NPC_CHAT_GUARD,
NPC_CHAT_MOVE_TO_POS,
NPC_CHAT_FOLLOW,
NPC_CHAT_AWAKE,
NPC_CHAT_MOUNT,
Expand Down Expand Up @@ -781,6 +783,9 @@ void game::chat()
string_format( _( "Tell %s to guard" ), followers.front()->get_name() ) :
_( "Tell someone to guard…" )
);
nmenu.addentry( NPC_CHAT_MOVE_TO_POS, true, 'G',
follower_count == 1 ? string_format( _( "Tell %s to move to location" ),
followers.front()->get_name() ) : _( "Tell someone to move to location…" ) );
nmenu.addentry( NPC_CHAT_AWAKE, true, 'w', _( "Tell everyone on your team to wake up" ) );
nmenu.addentry( NPC_CHAT_MOUNT, true, 'M', _( "Tell everyone on your team to mount up" ) );
nmenu.addentry( NPC_CHAT_DISMOUNT, true, 'm', _( "Tell everyone on your team to dismount" ) );
Expand Down Expand Up @@ -885,6 +890,35 @@ void game::chat()
}
break;
}
case NPC_CHAT_MOVE_TO_POS: {
const int npcselect = npc_select_menu( followers, _( "Who should move?" ) );
if( npcselect < 0 ) {
return;
}

map &here = get_map();
std::optional<tripoint> p = look_around();

if( !p ) {
return;
}

if( here.impassable( tripoint( *p ) ) ) {
add_msg( m_info, _( "This destination can't be reached." ) );
return;
}

if( npcselect == follower_count ) {
for( npc *them : followers ) {
them->goto_to_this_pos = here.getglobal( *p );
}
yell_msg = _( "Everyone move there!" );
} else {
followers[npcselect]->goto_to_this_pos = here.getglobal( *p );
yell_msg = string_format( _( "Move there, %s!" ), followers[npcselect]->get_name() );
}
break;
}
case NPC_CHAT_FOLLOW: {
const int npcselect = npc_select_menu( guards, _( "Who should follow you?" ) );
if( npcselect < 0 ) {
Expand Down

0 comments on commit 4529f65

Please sign in to comment.