Skip to content

Commit

Permalink
Merge pull request #33262 from jbytheway/enum_conversions
Browse files Browse the repository at this point in the history
Overhaul enum conversions
  • Loading branch information
kevingranade authored Aug 22, 2019
2 parents d27eb66 + 49ce85a commit 16fb9ca
Show file tree
Hide file tree
Showing 32 changed files with 708 additions and 564 deletions.
2 changes: 2 additions & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,8 @@ void activity_handlers::forage_finish( player_activity *act, player *p )
loc = "forage_winter";
next_ter = ter_str_id( "t_underbrush_harvested_winter" );
break;
default:
debugmsg( "Invalid season" );
}

g->m.ter_set( act->placement, next_ter );
Expand Down
237 changes: 126 additions & 111 deletions src/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,129 +1427,144 @@ void it_artifact_armor::serialize( JsonOut &json ) const

namespace io
{
#define PAIR(x) { #x, x }
static const std::unordered_map<std::string, art_effect_passive> art_effect_passive_values = { {
//PAIR( AEP_NULL ), // not really used
PAIR( AEP_STR_UP ),
PAIR( AEP_DEX_UP ),
PAIR( AEP_PER_UP ),
PAIR( AEP_INT_UP ),
PAIR( AEP_ALL_UP ),
PAIR( AEP_SPEED_UP ),
PAIR( AEP_PBLUE ),
PAIR( AEP_SNAKES ),
PAIR( AEP_INVISIBLE ),
PAIR( AEP_CLAIRVOYANCE ),
PAIR( AEP_CLAIRVOYANCE_PLUS ),
PAIR( AEP_SUPER_CLAIRVOYANCE ),
PAIR( AEP_STEALTH ),
PAIR( AEP_EXTINGUISH ),
PAIR( AEP_GLOW ),
PAIR( AEP_PSYSHIELD ),
PAIR( AEP_RESIST_ELECTRICITY ),
PAIR( AEP_CARRY_MORE ),
PAIR( AEP_SAP_LIFE ),
PAIR( AEP_FUN ),
//PAIR( AEP_SPLIT, // not really used
PAIR( AEP_HUNGER ),
PAIR( AEP_THIRST ),
PAIR( AEP_SMOKE ),
PAIR( AEP_EVIL ),
PAIR( AEP_SCHIZO ),
PAIR( AEP_RADIOACTIVE ),
PAIR( AEP_MUTAGENIC ),
PAIR( AEP_ATTENTION ),
PAIR( AEP_STR_DOWN ),
PAIR( AEP_DEX_DOWN ),
PAIR( AEP_PER_DOWN ),
PAIR( AEP_INT_DOWN ),
PAIR( AEP_ALL_DOWN ),
PAIR( AEP_SPEED_DOWN ),
PAIR( AEP_FORCE_TELEPORT ),
PAIR( AEP_MOVEMENT_NOISE ),
PAIR( AEP_BAD_WEATHER ),
PAIR( AEP_SICK ),
}
};
static const std::unordered_map<std::string, art_effect_active> art_effect_active_values = { {
//PAIR( AEA_NULL ), // not really used
PAIR( AEA_STORM ),
PAIR( AEA_FIREBALL ),
PAIR( AEA_ADRENALINE ),
PAIR( AEA_MAP ),
PAIR( AEA_BLOOD ),
PAIR( AEA_FATIGUE ),
PAIR( AEA_ACIDBALL ),
PAIR( AEA_PULSE ),
PAIR( AEA_HEAL ),
PAIR( AEA_CONFUSED ),
PAIR( AEA_ENTRANCE ),
PAIR( AEA_BUGS ),
PAIR( AEA_TELEPORT ),
PAIR( AEA_LIGHT ),
PAIR( AEA_GROWTH ),
PAIR( AEA_HURTALL ),
PAIR( AEA_FUN ),
//PAIR( AEA_SPLIT ), // not really used
PAIR( AEA_RADIATION ),
PAIR( AEA_PAIN ),
PAIR( AEA_MUTATE ),
PAIR( AEA_PARALYZE ),
PAIR( AEA_FIRESTORM ),
PAIR( AEA_ATTENTION ),
PAIR( AEA_TELEGLOW ),
PAIR( AEA_NOISE ),
PAIR( AEA_SCREAM ),
PAIR( AEA_DIM ),
PAIR( AEA_FLASH ),
PAIR( AEA_VOMIT ),
PAIR( AEA_SHADOWS ),
PAIR( AEA_STAMINA_EMPTY ),
}
};
static const std::unordered_map<std::string, art_charge> art_charge_values = { {
PAIR( ARTC_NULL ),
PAIR( ARTC_TIME ),
PAIR( ARTC_SOLAR ),
PAIR( ARTC_PAIN ),
PAIR( ARTC_HP ),
PAIR( ARTC_FATIGUE ),
PAIR( ARTC_PORTAL ),
}
};
static const std::unordered_map<std::string, art_charge_req> art_charge_req_values = { {
PAIR( ACR_NULL ),
PAIR( ACR_EQUIP ),
PAIR( ACR_SKIN ),
PAIR( ACR_SLEEP ),
PAIR( ACR_RAD ),
PAIR( ACR_WET ),
PAIR( ACR_SKY ),
}
};
#undef PAIR

#define PAIR(x) case x: return #x;
template<>
art_effect_passive string_to_enum<art_effect_passive>( const std::string &data )
std::string enum_to_string<art_effect_passive>( art_effect_passive data )
{
return string_to_enum_look_up( art_effect_passive_values, data );
switch( data ) {
// *INDENT-OFF*
PAIR( AEP_NULL )
PAIR( AEP_STR_UP )
PAIR( AEP_DEX_UP )
PAIR( AEP_PER_UP )
PAIR( AEP_INT_UP )
PAIR( AEP_ALL_UP )
PAIR( AEP_SPEED_UP )
PAIR( AEP_PBLUE )
PAIR( AEP_SNAKES )
PAIR( AEP_INVISIBLE )
PAIR( AEP_CLAIRVOYANCE )
PAIR( AEP_CLAIRVOYANCE_PLUS )
PAIR( AEP_SUPER_CLAIRVOYANCE )
PAIR( AEP_STEALTH )
PAIR( AEP_EXTINGUISH )
PAIR( AEP_GLOW )
PAIR( AEP_PSYSHIELD )
PAIR( AEP_RESIST_ELECTRICITY )
PAIR( AEP_CARRY_MORE )
PAIR( AEP_SAP_LIFE )
PAIR( AEP_FUN )
PAIR( AEP_SPLIT )
PAIR( AEP_HUNGER )
PAIR( AEP_THIRST )
PAIR( AEP_SMOKE )
PAIR( AEP_EVIL )
PAIR( AEP_SCHIZO )
PAIR( AEP_RADIOACTIVE )
PAIR( AEP_MUTAGENIC )
PAIR( AEP_ATTENTION )
PAIR( AEP_STR_DOWN )
PAIR( AEP_DEX_DOWN )
PAIR( AEP_PER_DOWN )
PAIR( AEP_INT_DOWN )
PAIR( AEP_ALL_DOWN )
PAIR( AEP_SPEED_DOWN )
PAIR( AEP_FORCE_TELEPORT )
PAIR( AEP_MOVEMENT_NOISE )
PAIR( AEP_BAD_WEATHER )
PAIR( AEP_SICK )
// *INDENT-ON*
case NUM_AEPS:
break;
}
debugmsg( "Invalid AEP" );
abort();
}

template<>
art_effect_active string_to_enum<art_effect_active>( const std::string &data )
std::string enum_to_string<art_effect_active>( art_effect_active data )
{
return string_to_enum_look_up( art_effect_active_values, data );
switch( data ) {
// *INDENT-OFF*
PAIR( AEA_NULL )
PAIR( AEA_STORM )
PAIR( AEA_FIREBALL )
PAIR( AEA_ADRENALINE )
PAIR( AEA_MAP )
PAIR( AEA_BLOOD )
PAIR( AEA_FATIGUE )
PAIR( AEA_ACIDBALL )
PAIR( AEA_PULSE )
PAIR( AEA_HEAL )
PAIR( AEA_CONFUSED )
PAIR( AEA_ENTRANCE )
PAIR( AEA_BUGS )
PAIR( AEA_TELEPORT )
PAIR( AEA_LIGHT )
PAIR( AEA_GROWTH )
PAIR( AEA_HURTALL )
PAIR( AEA_FUN )
PAIR( AEA_SPLIT )
PAIR( AEA_RADIATION )
PAIR( AEA_PAIN )
PAIR( AEA_MUTATE )
PAIR( AEA_PARALYZE )
PAIR( AEA_FIRESTORM )
PAIR( AEA_ATTENTION )
PAIR( AEA_TELEGLOW )
PAIR( AEA_NOISE )
PAIR( AEA_SCREAM )
PAIR( AEA_DIM )
PAIR( AEA_FLASH )
PAIR( AEA_VOMIT )
PAIR( AEA_SHADOWS )
PAIR( AEA_STAMINA_EMPTY )
// *INDENT-ON*
case NUM_AEAS:
break;
}
debugmsg( "Invalid AEA" );
abort();
}

template<>
art_charge string_to_enum<art_charge>( const std::string &data )
std::string enum_to_string<art_charge>( art_charge data )
{
return string_to_enum_look_up( art_charge_values, data );
switch( data ) {
// *INDENT-OFF*
PAIR( ARTC_NULL )
PAIR( ARTC_TIME )
PAIR( ARTC_SOLAR )
PAIR( ARTC_PAIN )
PAIR( ARTC_HP )
PAIR( ARTC_FATIGUE )
PAIR( ARTC_PORTAL )
// *INDENT-ON*
case NUM_ARTCS:
break;
}
debugmsg( "Invalid ARTC" );
abort();
}

template<>
art_charge_req string_to_enum<art_charge_req>( const std::string &data )
std::string enum_to_string<art_charge_req>( art_charge_req data )
{
return string_to_enum_look_up( art_charge_req_values, data );
switch( data ) {
// *INDENT-OFF*
PAIR( ACR_NULL )
PAIR( ACR_EQUIP )
PAIR( ACR_SKIN )
PAIR( ACR_SLEEP )
PAIR( ACR_RAD )
PAIR( ACR_WET )
PAIR( ACR_SKY )
// *INDENT-ON*
case NUM_ACRS:
break;
}
debugmsg( "Invalid ACR" );
abort();
}
#undef PAIR

} // namespace io
16 changes: 16 additions & 0 deletions src/artifact.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class JsonObject;
class JsonOut;
class item;
template<typename T> struct enum_traits;

enum art_effect_active : int {
AEA_NULL = 0,
Expand Down Expand Up @@ -52,6 +53,11 @@ enum art_effect_active : int {
NUM_AEAS
};

template<>
struct enum_traits<art_effect_active> {
static constexpr art_effect_active last = art_effect_active::NUM_AEAS;
};

enum art_charge : int {
ARTC_NULL, // Never recharges!
ARTC_TIME, // Very slowly recharges with time
Expand All @@ -63,6 +69,11 @@ enum art_charge : int {
NUM_ARTCS
};

template<>
struct enum_traits<art_charge> {
static constexpr art_charge last = art_charge::NUM_ARTCS;
};

enum art_charge_req : int {
ACR_NULL = 0, //No extra requirement
ACR_EQUIP, //Must be worn/wielded as appropriate
Expand All @@ -74,6 +85,11 @@ enum art_charge_req : int {
NUM_ACRS
};

template<>
struct enum_traits<art_charge_req> {
static constexpr art_charge_req last = art_charge_req::NUM_ACRS;
};

/* CLASSES */

class it_artifact_tool : public itype
Expand Down
24 changes: 15 additions & 9 deletions src/bodypart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ side opposite_side( side s )
return side::RIGHT;
case side::RIGHT:
return side::LEFT;
case side::num_sides:
debugmsg( "invalid side %d", static_cast<int>( s ) );
break;
}

return s;
Expand All @@ -29,17 +32,20 @@ side opposite_side( side s )
namespace io
{

static const std::map<std::string, side> side_map = {{
{ "left", side::LEFT },
{ "right", side::RIGHT },
{ "both", side::BOTH }
}
};

template<>
side string_to_enum<side>( const std::string &data )
std::string enum_to_string<side>( side data )
{
return string_to_enum_look_up( side_map, data );
switch( data ) {
// *INDENT-OFF*
case side::LEFT: return "left";
case side::RIGHT: return "right";
case side::BOTH: return "both";
// *INDENT-ON*
case side::num_sides:
break;
}
debugmsg( "Invalid side" );
abort();
}

} // namespace io
Expand Down
8 changes: 7 additions & 1 deletion src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ struct enum_traits<body_part> {
enum class side : int {
BOTH,
LEFT,
RIGHT
RIGHT,
num_sides
};

template<>
struct enum_traits<side> {
static constexpr auto last = side::num_sides;
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <limits>
#include <algorithm>

#include "debug.h"
#include "options.h"
#include "rng.h"
#include "string_formatter.h"
Expand Down Expand Up @@ -154,6 +155,8 @@ double current_daylight_level( const time_point &p )
case WINTER:
modifier = ( 1. - deviation ) + ( percent * deviation );
break;
default:
debugmsg( "Invalid season" );
}

return modifier * default_daylight_level();
Expand Down
Loading

0 comments on commit 16fb9ca

Please sign in to comment.