@@ -2969,18 +2969,31 @@ std::string enum_to_string<efile_combo>( efile_combo data )
2969
2969
}
2970
2970
} // namespace io
2971
2971
2972
+ bool efile_activity_actor::processed_edevices_remain () const
2973
+ {
2974
+ return target_edevices.empty ();
2975
+ }
2976
+
2977
+ bool efile_activity_actor::processed_efiles_remain () const
2978
+ {
2979
+ return currently_processed_efiles.empty ();
2980
+ }
2981
+
2972
2982
item_location &efile_activity_actor::get_currently_processed_edevice ()
2973
2983
{
2974
- return *next_edevice ;
2984
+ return target_edevices. back () ;
2975
2985
}
2976
2986
2977
2987
item_location &efile_activity_actor::get_currently_processed_efile ()
2978
2988
{
2979
- return *next_efile ;
2989
+ return currently_processed_efiles. back () ;
2980
2990
}
2981
2991
void efile_activity_actor::start ( player_activity &act, Character &who )
2982
2992
{
2983
- // handle combo move
2993
+ if ( combo_type == COMBO_MOVE_ONTO_BROWSE ) {
2994
+ target_edevices_copy = target_edevices;
2995
+ }
2996
+ // handle combo move e-device (browsing may have included used e-device)
2984
2997
if ( action_type == EF_MOVE_ONTO_THIS ) {
2985
2998
auto i = target_edevices.begin ();
2986
2999
while ( i != target_edevices.end () ) {
@@ -3002,15 +3015,15 @@ void efile_activity_actor::start( player_activity &act, Character &who )
3002
3015
}
3003
3016
// only skip if loaded through deserialization
3004
3017
if ( !started_processing ) {
3005
- next_edevice = target_edevices.begin ();
3006
3018
started_processing = true ;
3007
3019
computer_low_skill = who.get_skill_level ( skill_computer ) < 1 ;
3008
3020
}
3009
3021
3010
- if ( next_edevice != target_edevices. end () ) {
3022
+ if ( ! processed_edevices_remain () ) {
3011
3023
const time_duration total_time = total_processing_time ( used_edevice, target_edevices,
3012
3024
selected_efiles, action_type, who, computer_low_skill );
3013
3025
act.moves_total = to_moves<int >( total_time );
3026
+ target_edevices_count = target_edevices.size ();
3014
3027
add_msg_debug ( debugmode::DF_ACT_EBOOK, " total processing moves: %d" ,
3015
3028
act.moves_total );
3016
3029
} else {
@@ -3046,8 +3059,11 @@ void efile_activity_actor::do_turn( player_activity &act, Character &who )
3046
3059
do {
3047
3060
failed_processing_current_edevice ();
3048
3061
} while ( !done_processing );
3049
- } else if ( !*next_edevice || !edevice_reduce_charge ( get_currently_processed_edevice () ) ) {
3050
- failed_processing_current_edevice ();
3062
+ } else {
3063
+ item_location next_edevice = get_currently_processed_edevice ();
3064
+ if ( !next_edevice || !edevice_reduce_charge ( next_edevice ) ) {
3065
+ failed_processing_current_edevice ();
3066
+ }
3051
3067
}
3052
3068
}
3053
3069
}
@@ -3076,7 +3092,7 @@ void efile_activity_actor::do_turn( player_activity &act, Character &who )
3076
3092
}
3077
3093
if ( next_edevice_booted ) { // should not be an "else" because files start processing in same turn
3078
3094
// current file exists check
3079
- if ( !*next_efile ) {
3095
+ if ( !get_currently_processed_efile () ) {
3080
3096
failed_processing_current_efile ( act, who );
3081
3097
} else if ( turns_left_on_current_efile > 0 ) {
3082
3098
turns_left_on_current_efile--;
@@ -3100,14 +3116,13 @@ void efile_activity_actor::start_processing_next_edevice()
3100
3116
currently_processed_efiles = ignore_filter ? selected_efiles :
3101
3117
filter_edevice_efiles ( edevice_filter, selected_efiles );
3102
3118
}
3103
- next_efile = currently_processed_efiles.begin ();
3104
3119
add_msg_debug ( debugmode::DF_ACT_EBOOK, string_format ( " started processing edevice %s" ,
3105
3120
current_edevice->display_name () ) );
3106
3121
}
3107
3122
3108
3123
void efile_activity_actor::start_processing_next_efile ( player_activity &/* act*/ , Character &who )
3109
3124
{
3110
- if ( next_efile != currently_processed_efiles. end () ) {
3125
+ if ( ! processed_efiles_remain () ) {
3111
3126
// separate for easy debugging
3112
3127
item_location ¤t_efile = get_currently_processed_efile ();
3113
3128
item_location ¤t_edevice = get_currently_processed_edevice ();
@@ -3133,8 +3148,8 @@ void efile_activity_actor::completed_processing_current_edevice()
3133
3148
3134
3149
next_edevice_booted = false ;
3135
3150
turns_left_on_current_edevice.reset ();
3136
- next_edevice++ ;
3137
- if ( next_edevice == target_edevices. end () ) {
3151
+ target_edevices. pop_back () ;
3152
+ if ( processed_edevices_remain () ) {
3138
3153
done_processing = true ;
3139
3154
}
3140
3155
}
@@ -3225,7 +3240,7 @@ void efile_activity_actor::completed_processing_current_efile( player_activity &
3225
3240
break ;
3226
3241
}
3227
3242
processed_efiles++;
3228
- next_efile++ ;
3243
+ currently_processed_efiles. pop_back () ;
3229
3244
}
3230
3245
3231
3246
void efile_activity_actor::failed_processing_current_edevice ()
@@ -3234,8 +3249,8 @@ void efile_activity_actor::failed_processing_current_edevice()
3234
3249
3235
3250
turns_left_on_current_edevice.reset ();
3236
3251
next_edevice_booted = false ;
3237
- next_edevice++ ;
3238
- if ( next_edevice == target_edevices. end () ) {
3252
+ target_edevices. pop_back () ;
3253
+ if ( processed_edevices_remain () ) {
3239
3254
done_processing = true ;
3240
3255
}
3241
3256
}
@@ -3251,30 +3266,30 @@ void efile_activity_actor::finish( player_activity &act, Character &who )
3251
3266
{
3252
3267
act.set_to_null ();
3253
3268
std::string action_name = efile_action_name ( action_type, true , true );
3254
- int total_edevices = target_edevices. size () ;
3269
+ int total_edevices = target_edevices_count ;
3255
3270
if ( total_edevices == 0 && processed_edevices == 0 ) {
3256
3271
add_msg_if_player_sees ( who, m_info, _ ( " No devices needed to be processed." ) );
3257
3272
} else if ( processed_edevices == 0 ) {
3258
3273
add_msg_if_player_sees ( who, m_warning, _ ( " You failed to %s %d device(s)." ),
3259
3274
efile_action_name ( action_type, false , true ), total_edevices );
3260
3275
} else {
3261
3276
add_msg_if_player_sees ( who, m_good, _ ( " You successfully %s %d/%d device(s)." ),
3262
- action_name, processed_edevices, target_edevices. size () );
3277
+ action_name, processed_edevices, total_edevices );
3263
3278
}
3264
3279
combo_next_activity ( who );
3265
3280
}
3266
3281
3267
3282
std::vector<item_location> efile_activity_actor::filter_edevice_efiles (
3268
- const item_location &edevice,
3269
- const std::vector<item_location> &filter_files )
3283
+ const item_location &edevice, std::vector<item_location> &filter_files )
3270
3284
{
3271
3285
std::vector<item_location> filtered_efiles;
3272
- if ( !filter_files.empty () ) {
3273
- // filter e-files
3274
- for ( const item_location &i : filter_files ) {
3275
- if ( i.parent_item () == edevice ) {
3276
- filtered_efiles.emplace_back ( i );
3277
- }
3286
+ std::vector<item_location>::iterator it = filter_files.begin ();
3287
+ while ( it != filter_files.end () ) {
3288
+ if ( it->parent_item () == edevice ) {
3289
+ filtered_efiles.emplace_back ( *it );
3290
+ it = filter_files.erase ( it );
3291
+ } else {
3292
+ it++;
3278
3293
}
3279
3294
}
3280
3295
return filtered_efiles;
@@ -3348,18 +3363,17 @@ void efile_activity_actor::combo_next_activity( Character &who )
3348
3363
{
3349
3364
efile_combo new_combo = COMBO_NONE;
3350
3365
efile_action new_action = EF_INVALID;
3366
+ std::vector<item_location> all_updated_files;
3351
3367
3352
- // filter out invalidated e-files removed during prior operation
3353
- std::vector< item_location> valid_efiles;
3354
- for ( const item_location & efile : selected_efiles ) {
3355
- if ( efile ) {
3356
- valid_efiles. emplace_back ( efile );
3368
+ if ( combo_type == COMBO_MOVE_ONTO_BROWSE ) {
3369
+ for ( item_location &edevice : target_edevices_copy ) {
3370
+ for ( item * efile : edevice-> efiles () ) {
3371
+ all_updated_files. emplace_back ( edevice, efile );
3372
+ }
3357
3373
}
3358
- }
3359
3374
3360
- if ( combo_type == COMBO_MOVE_ONTO_BROWSE ) {
3361
3375
units::ememory total_ememory;
3362
- for ( item_location &edevice : target_edevices ) {
3376
+ for ( item_location &edevice : target_edevices_copy ) {
3363
3377
if ( edevice->is_browsed () ) {
3364
3378
for ( item *efile : edevice->efiles () ) {
3365
3379
total_ememory += efile->ememory_size ();
@@ -3373,10 +3387,9 @@ void efile_activity_actor::combo_next_activity( Character &who )
3373
3387
_ ( " File size exceeds available memory; canceling file move." ) );
3374
3388
}
3375
3389
}
3376
-
3377
3390
if ( new_action != EF_INVALID ) {
3378
- const efile_activity_actor new_activity ( used_edevice, target_edevices ,
3379
- valid_efiles , new_action, new_combo );
3391
+ const efile_activity_actor new_activity ( used_edevice, target_edevices_copy ,
3392
+ all_updated_files , new_action, new_combo );
3380
3393
who.assign_activity ( player_activity ( new_activity ) );
3381
3394
}
3382
3395
}
@@ -3405,12 +3418,12 @@ void efile_activity_actor::serialize( JsonOut &jsout ) const
3405
3418
jsout.start_object ();
3406
3419
jsout.member ( " used_edevice" , used_edevice );
3407
3420
jsout.member ( " target_edevices" , target_edevices );
3421
+ jsout.member ( " target_edevices_copy" , target_edevices_copy );
3408
3422
jsout.member ( " action_type" , action_type );
3409
3423
jsout.member ( " combo_type" , combo_type );
3410
3424
jsout.member ( " selected_efiles" , selected_efiles );
3411
3425
jsout.member ( " currently_processed_efiles" , currently_processed_efiles );
3412
- jsout.member ( " next_edevice" , next_edevice - target_edevices.begin () );
3413
- jsout.member ( " next_efile" , next_efile - currently_processed_efiles.begin () );
3426
+ jsout.member ( " target_edevices_count" , target_edevices_count );
3414
3427
jsout.member ( " processed_edevices" , processed_edevices );
3415
3428
jsout.member ( " failed_edevices" , failed_edevices );
3416
3429
jsout.member ( " processed_efiles" , processed_efiles );
@@ -3420,10 +3433,7 @@ void efile_activity_actor::serialize( JsonOut &jsout ) const
3420
3433
jsout.member ( " next_edevice_booted" , next_edevice_booted );
3421
3434
jsout.member ( " computer_low_skill" , computer_low_skill );
3422
3435
jsout.member ( " turns_left_on_current_edevice" , turns_left_on_current_edevice );
3423
- jsout.member ( " processed_edevices" , processed_edevices );
3424
3436
jsout.member ( " turns_left_on_current_efile" , turns_left_on_current_efile );
3425
-
3426
-
3427
3437
jsout.end_object ();
3428
3438
}
3429
3439
@@ -3434,28 +3444,21 @@ std::unique_ptr<activity_actor> efile_activity_actor::deserialize( JsonValue &js
3434
3444
JsonObject data = jsin.get_object ();
3435
3445
data.read ( " used_edevice" , actor.used_edevice );
3436
3446
data.read ( " target_edevices" , actor.target_edevices );
3447
+ data.read ( " target_edevices_copy" , actor.target_edevices_copy );
3437
3448
data.read ( " turns_left_on_current_edevice" , actor.turns_left_on_current_edevice );
3438
3449
data.read ( " action_type" , actor.action_type );
3439
3450
data.read ( " combo_type" , actor.combo_type );
3451
+ data.read ( " target_edevices_count" , actor.target_edevices_count );
3440
3452
data.read ( " processed_edevices" , actor.processed_edevices );
3441
3453
data.read ( " selected_efiles" , actor.selected_efiles );
3442
3454
data.read ( " currently_processed_efiles" , actor.currently_processed_efiles );
3443
- if ( data.has_member ( " next_edevice" ) ) {
3444
- actor.next_edevice = actor.target_edevices .begin () + data.get_int ( " next_edevice" );
3445
- }
3446
- if ( data.has_member ( " next_efile" ) ) {
3447
- actor.next_efile = actor.currently_processed_efiles .begin () + data.get_int ( " next_efile" );
3448
- }
3449
- data.read ( " processed_edevices" , actor.processed_edevices );
3450
3455
data.read ( " failed_edevices" , actor.failed_edevices );
3451
3456
data.read ( " processed_efiles" , actor.processed_efiles );
3452
3457
data.read ( " failed_efiles" , actor.failed_efiles );
3453
3458
data.read ( " started_processing" , actor.started_processing );
3454
3459
data.read ( " done_processing" , actor.done_processing );
3455
3460
data.read ( " next_edevice_booted" , actor.next_edevice_booted );
3456
3461
data.read ( " computer_low_skill" , actor.computer_low_skill );
3457
- data.read ( " turns_left_on_current_edevice" , actor.turns_left_on_current_edevice );
3458
- data.read ( " processed_edevices" , actor.processed_edevices );
3459
3462
data.read ( " turns_left_on_current_efile" , actor.turns_left_on_current_efile );
3460
3463
return actor.clone ();
3461
3464
}
0 commit comments