Skip to content

Commit 6e484c3

Browse files
authored
Merge pull request #82562 from sparr/wait_followers
Add wait duration for followers to catch up
2 parents dc8af21 + e029608 commit 6e484c3

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

data/json/player_activities.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,15 @@
707707
"based_on": "speed",
708708
"can_resume": false
709709
},
710+
{
711+
"id": "ACT_WAIT_FOLLOWERS",
712+
"type": "activity_type",
713+
"activity_level": "NO_EXERCISE",
714+
"verb": "waiting for followers to catch up",
715+
"rooted": true,
716+
"based_on": "time",
717+
"can_resume": false
718+
},
710719
{
711720
"id": "ACT_WAIT_NPC",
712721
"type": "activity_type",

src/activity_actor.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ static const activity_id ACT_UNLOAD( "ACT_UNLOAD" );
179179
static const activity_id ACT_UNLOAD_LOOT( "ACT_UNLOAD_LOOT" );
180180
static const activity_id ACT_VEHICLE_FOLD( "ACT_VEHICLE_FOLD" );
181181
static const activity_id ACT_VEHICLE_UNFOLD( "ACT_VEHICLE_UNFOLD" );
182+
static const activity_id ACT_WAIT_FOLLOWERS( "ACT_WAIT_FOLLOWERS" );
182183
static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" );
183184
static const activity_id ACT_WASH( "ACT_WASH" );
184185
static const activity_id ACT_WEAR( "ACT_WEAR" );
@@ -9246,6 +9247,48 @@ std::unique_ptr<activity_actor> wait_stamina_activity_actor::deserialize( JsonVa
92469247
return wait_stamina_activity_actor().clone();
92479248
}
92489249

9250+
void wait_followers_activity_actor::start( player_activity &act, Character & )
9251+
{
9252+
act.moves_total = calendar::INDEFINITELY_LONG;
9253+
act.moves_left = calendar::INDEFINITELY_LONG;
9254+
}
9255+
9256+
std::vector<npc *> wait_followers_activity_actor::get_absent_followers( Character &you )
9257+
{
9258+
return g->get_npcs_if( [&you]( const npc & n ) -> bool {
9259+
const npc_attitude att = n.get_attitude();
9260+
return ( att == NPCATT_FOLLOW || att == NPCATT_ACTIVITY ) && rl_dist( n.pos_bub(), you.pos_bub() ) > n.follow_distance();
9261+
} );
9262+
}
9263+
9264+
9265+
void wait_followers_activity_actor::do_turn( player_activity &act, Character &you )
9266+
{
9267+
if( get_absent_followers( you ).empty() ) {
9268+
finish( act, you );
9269+
}
9270+
}
9271+
9272+
void wait_followers_activity_actor::finish( player_activity &act, Character &you )
9273+
{
9274+
if( !get_absent_followers( you ).empty() ) {
9275+
you.add_msg_if_player( _( "You are bored of waiting, so you stop." ) );
9276+
} else {
9277+
you.add_msg_if_player( _( "All present and accounted for." ) );
9278+
}
9279+
act.set_to_null();
9280+
}
9281+
9282+
void wait_followers_activity_actor::serialize( JsonOut &jsout ) const
9283+
{
9284+
jsout.write_null();
9285+
}
9286+
9287+
std::unique_ptr<activity_actor> wait_followers_activity_actor::deserialize( JsonValue & )
9288+
{
9289+
return wait_stamina_activity_actor().clone();
9290+
}
9291+
92499292
namespace activity_actors
92509293
{
92519294

@@ -9319,6 +9362,7 @@ deserialize_functions = {
93199362
{ ACT_UNLOAD_LOOT, &unload_loot_activity_actor::deserialize },
93209363
{ ACT_VEHICLE_FOLD, &vehicle_folding_activity_actor::deserialize },
93219364
{ ACT_VEHICLE_UNFOLD, &vehicle_unfolding_activity_actor::deserialize },
9365+
{ ACT_WAIT_FOLLOWERS, &wait_followers_activity_actor::deserialize },
93229366
{ ACT_WAIT_STAMINA, &wait_stamina_activity_actor::deserialize },
93239367
{ ACT_WASH, &wash_activity_actor::deserialize },
93249368
{ ACT_WEAR, &wear_activity_actor::deserialize },

src/activity_actor_definitions.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,4 +2570,29 @@ class wait_stamina_activity_actor : public activity_actor
25702570
int initial_stamina = -1;
25712571
};
25722572

2573+
class wait_followers_activity_actor : public activity_actor
2574+
{
2575+
public:
2576+
// Wait until stamina is at the maximum.
2577+
wait_followers_activity_actor() = default;
2578+
2579+
void start( player_activity &act, Character &who ) override;
2580+
void do_turn( player_activity &act, Character &you ) override;
2581+
void finish( player_activity &act, Character &you ) override;
2582+
2583+
static std::vector<npc *> get_absent_followers( Character &you );
2584+
2585+
const activity_id &get_type() const override {
2586+
static const activity_id ACT_WAIT_FOLLOWERS( "ACT_WAIT_FOLLOWERS" );
2587+
return ACT_WAIT_FOLLOWERS;
2588+
}
2589+
2590+
std::unique_ptr<activity_actor> clone() const override {
2591+
return std::make_unique<wait_followers_activity_actor>( *this );
2592+
}
2593+
2594+
void serialize( JsonOut &jsout ) const override;
2595+
static std::unique_ptr<activity_actor> deserialize( JsonValue &jsin );
2596+
};
2597+
25732598
#endif // CATA_SRC_ACTIVITY_ACTOR_DEFINITIONS_H

src/character.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static const activity_id ACT_TREE_COMMUNION( "ACT_TREE_COMMUNION" );
152152
static const activity_id ACT_TRY_SLEEP( "ACT_TRY_SLEEP" );
153153
static const activity_id ACT_VIBE( "ACT_VIBE" );
154154
static const activity_id ACT_WAIT( "ACT_WAIT" );
155+
static const activity_id ACT_WAIT_FOLLOWERS( "ACT_WAIT_FOLLOWERS" );
155156
static const activity_id ACT_WAIT_NPC( "ACT_WAIT_NPC" );
156157
static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" );
157158

@@ -9306,6 +9307,7 @@ bool Character::can_use_floor_warmth() const
93069307
{
93079308
return in_sleep_state() ||
93089309
has_activity( ACT_WAIT ) ||
9310+
has_activity( ACT_WAIT_FOLLOWERS ) ||
93099311
has_activity( ACT_WAIT_NPC ) ||
93109312
has_activity( ACT_WAIT_STAMINA ) ||
93119313
has_activity( ACT_AUTODRIVE ) ||

src/handle_action.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static const activity_id ACT_SPELLCASTING( "ACT_SPELLCASTING" );
123123
static const activity_id ACT_VEHICLE_DECONSTRUCTION( "ACT_VEHICLE_DECONSTRUCTION" );
124124
static const activity_id ACT_VEHICLE_REPAIR( "ACT_VEHICLE_REPAIR" );
125125
static const activity_id ACT_WAIT( "ACT_WAIT" );
126+
static const activity_id ACT_WAIT_FOLLOWERS( "ACT_WAIT_FOLLOWERS" );
126127
static const activity_id ACT_WAIT_STAMINA( "ACT_WAIT_STAMINA" );
127128
static const activity_id ACT_WAIT_WEATHER( "ACT_WAIT_WEATHER" );
128129

@@ -1236,6 +1237,10 @@ static void wait()
12361237
as_m.addentry( 14, true, 'w', _( "Wait until you catch your breath" ) );
12371238
durations.emplace( 14, 15_minutes ); // to hide it from showing
12381239
}
1240+
if( !wait_followers_activity_actor::get_absent_followers( player_character ).empty() ) {
1241+
as_m.addentry( 15, true, 'f', _( "Wait for followers to catch up" ) );
1242+
durations.emplace( 15, 15_minutes ); // to hide it from showing(?)
1243+
}
12391244
add_menu_item( 1, '1', !has_watch ? _( "Wait 20 heartbeats" ) : "", 20_seconds );
12401245
add_menu_item( 2, '2', !has_watch ? _( "Wait 60 heartbeats" ) : "", 1_minutes );
12411246
add_menu_item( 3, '3', !has_watch ? _( "Wait 300 heartbeats" ) : "", 5_minutes );
@@ -1310,12 +1315,16 @@ static void wait()
13101315
actType = ACT_WAIT_WEATHER;
13111316
} else if( as_m.ret == 14 ) {
13121317
actType = ACT_WAIT_STAMINA;
1318+
} else if( as_m.ret == 15 ) {
1319+
actType = ACT_WAIT_FOLLOWERS;
13131320
} else {
13141321
actType = ACT_WAIT;
13151322
}
13161323

13171324
if( actType == ACT_WAIT_STAMINA ) {
13181325
player_character.assign_activity( wait_stamina_activity_actor() );
1326+
} else if( actType == ACT_WAIT_FOLLOWERS ) {
1327+
player_character.assign_activity( wait_followers_activity_actor() );
13191328
} else {
13201329
player_activity new_act( actType, 100 * to_turns<int>( time_to_wait ), 0 );
13211330
player_character.assign_activity( new_act );

0 commit comments

Comments
 (0)