diff --git a/src/addiction.cpp b/src/addiction.cpp index 99ff6ee038641..9ee3537f4a386 100644 --- a/src/addiction.cpp +++ b/src/addiction.cpp @@ -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 {}; +} diff --git a/src/addiction.h b/src/addiction.h index 0c0e65f98496b..2dd2eb7ddae4b 100644 --- a/src/addiction.h +++ b/src/addiction.h @@ -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; diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index 080efdb7694c6..22e99a55352de 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -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" @@ -4401,8 +4402,16 @@ void cata_variant::deserialize( JsonIn &jsin ) *this = cata_variant::make( 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(); }