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

savegame: migrate addiction variants #56915

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/addiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,35 @@ void add_type::check_add_types()
}
}
}

std::string add_type_legacy_conv( std::string const &v )
{
if( v == "CAFFEINE" ) {
return "caffeine";
} else if( v == "ALCOHOL" ) {
return "alcohol";
} else if( v == "SLEEP" ) {
return "sleeping pill";
} else if( v == "PKILLER" ) {
return "opiate";
} else if( v == "SPEED" ) {
return "amphetamine";
} else if( v == "CIG" ) {
return "nicotine";
} else if( v == "COKE" ) {
return "cocaine";
} else if( v == "CRACK" ) {
return "crack";
} else if( v == "MUTAGEN" ) {
return "mutagen";
} else if( v == "DIAZEPAM" ) {
return "diazepam";
} else if( v == "MARLOSS_R" ) {
return "marloss_r";
} else if( v == "MARLOSS_B" ) {
return "marloss_b";
} else if( v == "MARLOSS_Y" ) {
return "marloss_y";
}
return {};
}
2 changes: 2 additions & 0 deletions src/addiction.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class addiction
bool run_effect( Character &u );
};

std::string add_type_legacy_conv( std::string const &v );

// Minimum intensity before effects are seen
constexpr int MIN_ADDICTION_LEVEL = 3;
constexpr int MAX_ADDICTION_LEVEL = 20;
Expand Down
13 changes: 11 additions & 2 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "activity_actor.h"
#include "activity_actor_definitions.h"
#include "activity_type.h"
#include "addiction.h"
#include "assign.h"
#include "auto_pickup.h"
#include "avatar.h"
Expand Down Expand Up @@ -4401,8 +4402,16 @@ void cata_variant::deserialize( JsonIn &jsin )
*this = cata_variant::make<cata_variant_type::bool_>( jsin.get_bool() );
} else {
jsin.start_array();
if( !( jsin.read( type_ ) && jsin.read( value_ ) ) ) {
jsin.error( "Failed to read cata_variant" );
int const rewind = jsin.tell();
// FIXME: add_type migration - remove after 0.G
if( jsin.get_string() == "add_type" ) {
type_ = cata_variant_type::addiction_id;
value_ = add_type_legacy_conv( jsin.get_string() );
} else {
jsin.seek( rewind );
if( !( jsin.read( type_ ) && jsin.read( value_ ) ) ) {
jsin.error( "Failed to read cata_variant" );
}
}
jsin.end_array();
}
Expand Down