Skip to content

Commit b6438a2

Browse files
authored
Merge pull request #79522 from ShnitzelX2/e-file-deserialize
Fix E_FILE_STORAGE item location serialization
2 parents bb4bac2 + 3233da5 commit b6438a2

File tree

9 files changed

+114
-67
lines changed

9 files changed

+114
-67
lines changed

src/activity_actor.cpp

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,18 +2969,31 @@ std::string enum_to_string<efile_combo>( efile_combo data )
29692969
}
29702970
} // namespace io
29712971

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+
29722982
item_location &efile_activity_actor::get_currently_processed_edevice()
29732983
{
2974-
return *next_edevice;
2984+
return target_edevices.back();
29752985
}
29762986

29772987
item_location &efile_activity_actor::get_currently_processed_efile()
29782988
{
2979-
return *next_efile;
2989+
return currently_processed_efiles.back();
29802990
}
29812991
void efile_activity_actor::start( player_activity &act, Character &who )
29822992
{
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)
29842997
if( action_type == EF_MOVE_ONTO_THIS ) {
29852998
auto i = target_edevices.begin();
29862999
while( i != target_edevices.end() ) {
@@ -3002,15 +3015,15 @@ void efile_activity_actor::start( player_activity &act, Character &who )
30023015
}
30033016
//only skip if loaded through deserialization
30043017
if( !started_processing ) {
3005-
next_edevice = target_edevices.begin();
30063018
started_processing = true;
30073019
computer_low_skill = who.get_skill_level( skill_computer ) < 1;
30083020
}
30093021

3010-
if( next_edevice != target_edevices.end() ) {
3022+
if( !processed_edevices_remain() ) {
30113023
const time_duration total_time = total_processing_time( used_edevice, target_edevices,
30123024
selected_efiles, action_type, who, computer_low_skill );
30133025
act.moves_total = to_moves<int>( total_time );
3026+
target_edevices_count = target_edevices.size();
30143027
add_msg_debug( debugmode::DF_ACT_EBOOK, "total processing moves: %d",
30153028
act.moves_total );
30163029
} else {
@@ -3046,8 +3059,11 @@ void efile_activity_actor::do_turn( player_activity &act, Character &who )
30463059
do {
30473060
failed_processing_current_edevice();
30483061
} 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+
}
30513067
}
30523068
}
30533069
}
@@ -3076,7 +3092,7 @@ void efile_activity_actor::do_turn( player_activity &act, Character &who )
30763092
}
30773093
if( next_edevice_booted ) { //should not be an "else" because files start processing in same turn
30783094
//current file exists check
3079-
if( !*next_efile ) {
3095+
if( !get_currently_processed_efile() ) {
30803096
failed_processing_current_efile( act, who );
30813097
} else if( turns_left_on_current_efile > 0 ) {
30823098
turns_left_on_current_efile--;
@@ -3100,14 +3116,13 @@ void efile_activity_actor::start_processing_next_edevice()
31003116
currently_processed_efiles = ignore_filter ? selected_efiles :
31013117
filter_edevice_efiles( edevice_filter, selected_efiles );
31023118
}
3103-
next_efile = currently_processed_efiles.begin();
31043119
add_msg_debug( debugmode::DF_ACT_EBOOK, string_format( "started processing edevice %s",
31053120
current_edevice->display_name() ) );
31063121
}
31073122

31083123
void efile_activity_actor::start_processing_next_efile( player_activity &/*act*/, Character &who )
31093124
{
3110-
if( next_efile != currently_processed_efiles.end() ) {
3125+
if( !processed_efiles_remain() ) {
31113126
//separate for easy debugging
31123127
item_location &current_efile = get_currently_processed_efile();
31133128
item_location &current_edevice = get_currently_processed_edevice();
@@ -3133,8 +3148,8 @@ void efile_activity_actor::completed_processing_current_edevice()
31333148

31343149
next_edevice_booted = false;
31353150
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() ) {
31383153
done_processing = true;
31393154
}
31403155
}
@@ -3225,7 +3240,7 @@ void efile_activity_actor::completed_processing_current_efile( player_activity &
32253240
break;
32263241
}
32273242
processed_efiles++;
3228-
next_efile++;
3243+
currently_processed_efiles.pop_back();
32293244
}
32303245

32313246
void efile_activity_actor::failed_processing_current_edevice()
@@ -3234,8 +3249,8 @@ void efile_activity_actor::failed_processing_current_edevice()
32343249

32353250
turns_left_on_current_edevice.reset();
32363251
next_edevice_booted = false;
3237-
next_edevice++;
3238-
if( next_edevice == target_edevices.end() ) {
3252+
target_edevices.pop_back();
3253+
if( processed_edevices_remain() ) {
32393254
done_processing = true;
32403255
}
32413256
}
@@ -3251,30 +3266,30 @@ void efile_activity_actor::finish( player_activity &act, Character &who )
32513266
{
32523267
act.set_to_null();
32533268
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;
32553270
if( total_edevices == 0 && processed_edevices == 0 ) {
32563271
add_msg_if_player_sees( who, m_info, _( "No devices needed to be processed." ) );
32573272
} else if( processed_edevices == 0 ) {
32583273
add_msg_if_player_sees( who, m_warning, _( "You failed to %s %d device(s)." ),
32593274
efile_action_name( action_type, false, true ), total_edevices );
32603275
} else {
32613276
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 );
32633278
}
32643279
combo_next_activity( who );
32653280
}
32663281

32673282
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 )
32703284
{
32713285
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++;
32783293
}
32793294
}
32803295
return filtered_efiles;
@@ -3348,18 +3363,17 @@ void efile_activity_actor::combo_next_activity( Character &who )
33483363
{
33493364
efile_combo new_combo = COMBO_NONE;
33503365
efile_action new_action = EF_INVALID;
3366+
std::vector<item_location> all_updated_files;
33513367

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+
}
33573373
}
3358-
}
33593374

3360-
if( combo_type == COMBO_MOVE_ONTO_BROWSE ) {
33613375
units::ememory total_ememory;
3362-
for( item_location &edevice : target_edevices ) {
3376+
for( item_location &edevice : target_edevices_copy ) {
33633377
if( edevice->is_browsed() ) {
33643378
for( item *efile : edevice->efiles() ) {
33653379
total_ememory += efile->ememory_size();
@@ -3373,10 +3387,9 @@ void efile_activity_actor::combo_next_activity( Character &who )
33733387
_( "File size exceeds available memory; canceling file move." ) );
33743388
}
33753389
}
3376-
33773390
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 );
33803393
who.assign_activity( player_activity( new_activity ) );
33813394
}
33823395
}
@@ -3405,12 +3418,12 @@ void efile_activity_actor::serialize( JsonOut &jsout ) const
34053418
jsout.start_object();
34063419
jsout.member( "used_edevice", used_edevice );
34073420
jsout.member( "target_edevices", target_edevices );
3421+
jsout.member( "target_edevices_copy", target_edevices_copy );
34083422
jsout.member( "action_type", action_type );
34093423
jsout.member( "combo_type", combo_type );
34103424
jsout.member( "selected_efiles", selected_efiles );
34113425
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 );
34143427
jsout.member( "processed_edevices", processed_edevices );
34153428
jsout.member( "failed_edevices", failed_edevices );
34163429
jsout.member( "processed_efiles", processed_efiles );
@@ -3420,10 +3433,7 @@ void efile_activity_actor::serialize( JsonOut &jsout ) const
34203433
jsout.member( "next_edevice_booted", next_edevice_booted );
34213434
jsout.member( "computer_low_skill", computer_low_skill );
34223435
jsout.member( "turns_left_on_current_edevice", turns_left_on_current_edevice );
3423-
jsout.member( "processed_edevices", processed_edevices );
34243436
jsout.member( "turns_left_on_current_efile", turns_left_on_current_efile );
3425-
3426-
34273437
jsout.end_object();
34283438
}
34293439

@@ -3434,28 +3444,21 @@ std::unique_ptr<activity_actor> efile_activity_actor::deserialize( JsonValue &js
34343444
JsonObject data = jsin.get_object();
34353445
data.read( "used_edevice", actor.used_edevice );
34363446
data.read( "target_edevices", actor.target_edevices );
3447+
data.read( "target_edevices_copy", actor.target_edevices_copy );
34373448
data.read( "turns_left_on_current_edevice", actor.turns_left_on_current_edevice );
34383449
data.read( "action_type", actor.action_type );
34393450
data.read( "combo_type", actor.combo_type );
3451+
data.read( "target_edevices_count", actor.target_edevices_count );
34403452
data.read( "processed_edevices", actor.processed_edevices );
34413453
data.read( "selected_efiles", actor.selected_efiles );
34423454
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 );
34503455
data.read( "failed_edevices", actor.failed_edevices );
34513456
data.read( "processed_efiles", actor.processed_efiles );
34523457
data.read( "failed_efiles", actor.failed_efiles );
34533458
data.read( "started_processing", actor.started_processing );
34543459
data.read( "done_processing", actor.done_processing );
34553460
data.read( "next_edevice_booted", actor.next_edevice_booted );
34563461
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 );
34593462
data.read( "turns_left_on_current_efile", actor.turns_left_on_current_efile );
34603463
return actor.clone();
34613464
}

src/activity_actor_definitions.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,11 @@ class efile_activity_actor : public activity_actor
852852
/** Returns the effective electronic transfer rate with `external_transfer_rate` factored in */
853853
static units::ememory current_etransfer_rate( Character &who, const efile_transfer &transfer,
854854
const item_location &efile );
855-
/** Returns all e-files on this device that are in the filter_files list
856-
@param filter_files list of e-files to use, usually selected_files */
855+
/** Returns all e-files on this device that are in the filter_files list,
856+
* and removes matching efiles from filter_files list
857+
* @param filter_files list of e-files to use, usually selected_files */
857858
static std::vector<item_location> filter_edevice_efiles( const item_location &edevice,
858-
const std::vector<item_location> &filter_files );
859+
std::vector<item_location> &filter_files );
859860
/** Returns the most optimal estorage (if needed) for improving transfer speed given the two edevices provided */
860861
static item_location find_external_transfer_estorage( Character &p,
861862
const item_location &efile, const item_location &ed1, const item_location &ed2 );
@@ -872,15 +873,16 @@ class efile_activity_actor : public activity_actor
872873
private:
873874
item_location used_edevice;
874875
std::vector<item_location> target_edevices;
876+
/** Held for combo activity */
877+
std::vector<item_location> target_edevices_copy;
878+
/** e-files that have yet to be processed, across all devices */
875879
std::vector<item_location> selected_efiles;
876880
efile_action action_type = EF_INVALID;
877881
efile_combo combo_type = COMBO_NONE;
878-
/** contents copy of currently processed e-device */
882+
/** e-files currently processed on current e-device */
879883
std::vector<item_location> currently_processed_efiles;
880-
/** iterator pointing to next e-file to process */
881-
std::vector<item_location>::iterator next_efile;
882-
/** iterator pointing to next e-device to process */
883-
std::vector<item_location>::iterator next_edevice;
884+
/** How many e-devices this activity started with. */
885+
int target_edevices_count = 0;
884886
/** How many e-devices this activity has successfully processed so far. */
885887
int processed_edevices = 0;
886888
/** How many e-devices this activity has failed to process so far. */
@@ -913,6 +915,9 @@ class efile_activity_actor : public activity_actor
913915

914916
item_location &get_currently_processed_edevice();
915917
item_location &get_currently_processed_efile();
918+
bool processed_edevices_remain() const;
919+
bool processed_efiles_remain() const;
920+
916921
/** Segway to the next player activity for a combo type */
917922
void combo_next_activity( Character &who );
918923
time_duration charge_time( efile_action action_type );

src/item.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15717,6 +15717,16 @@ std::list<item *> item::all_items_top()
1571715717
return contents.all_items_top();
1571815718
}
1571915719

15720+
std::list<const item *> item::all_items_container_top() const
15721+
{
15722+
return contents.all_items_container_top();
15723+
}
15724+
15725+
std::list<item *> item::all_items_container_top()
15726+
{
15727+
return contents.all_items_container_top();
15728+
}
15729+
1572015730
std::list<const item *> item::all_items_top( pocket_type pk_type ) const
1572115731
{
1572215732
return contents.all_items_top( pk_type );

src/item.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,14 +3033,18 @@ class item : public visitable
30333033
std::list<item> remove_items_with( const std::function<bool( const item & )> &filter,
30343034
int count = INT_MAX ) override;
30353035

3036-
/** returns a list of pointers to all top-level items that are not mods */
3036+
/** returns a list of pointers to all top-level items in standard pockets */
30373037
std::list<const item *> all_items_top() const;
3038-
/** returns a list of pointers to all top-level items that are not mods */
3038+
/** returns a list of pointers to all top-level items in standard pockets */
30393039
std::list<item *> all_items_top();
3040-
/** returns a list of pointers to all top-level items */
3040+
/** returns a list of pointers to all top-level items in container-like pockets */
3041+
std::list<const item *> all_items_container_top() const;
3042+
/** returns a list of pointers to all top-level items in container-like pockets */
3043+
std::list<item *> all_items_container_top();
3044+
/** returns a list of pointers to all top-level items in pk_type pockets only */
30413045
std::list<const item *> all_items_top( pocket_type pk_type ) const;
30423046
/**
3043-
* Return a list of pointers to all top-level items.
3047+
* Return a list of pointers to all top-level items in pk_type pockets only
30443048
* If unloading is true ignore items in pockets flagged not to be unloaded.
30453049
*/
30463050
std::list<item *> all_items_top( pocket_type pk_type, bool unloading = false );

src/item_contents.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,20 @@ std::list<const item *> item_contents::all_items_top() const
17801780
} );
17811781
}
17821782

1783+
std::list<const item *> item_contents::all_items_container_top() const
1784+
{
1785+
return all_items_top( []( const item_pocket & pocket ) {
1786+
return pocket.is_container_like_type();
1787+
} );
1788+
}
1789+
1790+
std::list<item *> item_contents::all_items_container_top()
1791+
{
1792+
return all_items_top( []( const item_pocket & pocket ) {
1793+
return pocket.is_container_like_type();
1794+
} );
1795+
}
1796+
17831797
std::list<item *> item_contents::all_known_contents()
17841798
{
17851799
return all_items_top( []( const item_pocket & pocket ) {

src/item_contents.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ class item_contents
122122
/** returns a list of pointers to all top-level items */
123123
std::list<const item *> all_items_top( pocket_type pk_type ) const;
124124

125-
/** returns a list of pointers to all top-level items that are not mods */
125+
/** returns a list of pointers to all top-level items in standard pockets */
126126
std::list<item *> all_items_top();
127-
/** returns a list of pointers to all top-level items that are not mods */
127+
/** returns a list of pointers to all top-level items in standard pockets */
128128
std::list<const item *> all_items_top() const;
129+
/** returns a list of pointers to all top-level items in container-like pockets */
130+
std::list<item *> all_items_container_top();
131+
/** returns a list of pointers to all top-level items in container-like pockets */
132+
std::list<const item *> all_items_container_top() const;
129133

130134
/** returns a list of pointers to all visible or remembered content items that are not mods */
131135
std::list<item *> all_known_contents();

0 commit comments

Comments
 (0)