Skip to content

Commit

Permalink
Make add_type a class enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed Apr 13, 2020
1 parent 95d889b commit 339ac5c
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 135 deletions.
203 changes: 102 additions & 101 deletions src/addiction.cpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/addiction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

#include <string>

#include "pldata.h"
#include "type_id.h"

class addiction;
class Character;

enum add_type : int;

// Minimum intensity before effects are seen
constexpr int MIN_ADDICTION_LEVEL = 3;
constexpr int MAX_ADDICTION_LEVEL = 20;
Expand Down
2 changes: 0 additions & 2 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

class faction;

enum character_type : int;

class JsonIn;
class JsonObject;
class JsonOut;
Expand Down
2 changes: 1 addition & 1 deletion src/cata_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "debug.h"
#include "enum_conversions.h"
#include "hash_utils.h"
#include "pldata.h"
#include "type_id.h"

class JsonIn;
class JsonOut;
template <typename E> struct enum_traits;

enum add_type : int;
enum body_part : int;
enum class mutagen_technique : int;
enum hp_part : int;
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9490,7 +9490,7 @@ int Character::heartrate_bpm() const
heartbeat += average_heartbeat * stim_modifer;
if( get_effect_dur( effect_cig ) > 0_turns ) {
//Nicotine-induced tachycardia
if( get_effect_dur( effect_cig ) > 10_minutes * ( addiction_level( ADD_CIG ) + 1 ) ) {
if( get_effect_dur( effect_cig ) > 10_minutes * ( addiction_level( add_type::CIG ) + 1 ) ) {
heartbeat += average_heartbeat * 0.4;
} else {
heartbeat += average_heartbeat * 0.1;
Expand Down
4 changes: 2 additions & 2 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ void Character::modify_stimulation( const islot_comestible &comest )
}
}
if( has_trait( trait_STIMBOOST ) && ( current_stim > 30 ) &&
( ( comest.add == ADD_CAFFEINE ) || ( comest.add == ADD_SPEED ) || ( comest.add == ADD_COKE ) ||
( comest.add == ADD_CRACK ) ) ) {
( ( comest.add == add_type::CAFFEINE ) || ( comest.add == add_type::SPEED ) ||
( comest.add == add_type::COKE ) || ( comest.add == add_type::CRACK ) ) ) {
int hallu_duration = ( current_stim - comest.stim < 30 ) ? current_stim - 30 : comest.stim;
add_effect( effect_visuals, hallu_duration * 30_minutes );
std::vector<std::string> stimboost_msg{ _( "The shadows are getting ever closer." ),
Expand Down
2 changes: 1 addition & 1 deletion src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ void iexamine::flower_poppy( player &p, const tripoint &examp )
p.add_effect( effect_pkill2, 7_minutes );
// Please drink poppy nectar responsibly.
if( one_in( 20 ) ) {
p.add_addiction( ADD_PKILLER, 1 );
p.add_addiction( add_type::PKILLER, 1 );
}
}
if( !query_yn( _( "Pick %s?" ), g->m.furnname( examp ) ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct islot_comestible {
int addict = 0;

/** effects of addiction */
add_type add = ADD_NULL;
add_type add = add_type::NONE;

/** stimulant effect */
int stim = 0;
Expand Down
14 changes: 8 additions & 6 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ int iuse::smoking( player *p, item *it, bool, const tripoint & )
weed_msg( *p );
}
}
if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level( ADD_CIG ) + 1 ) ) {
if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level(
add_type::CIG ) + 1 ) ) {
p->add_msg_if_player( m_bad, _( "Ugh, too much smoke… you feel nasty." ) );
}

Expand All @@ -561,7 +562,8 @@ int iuse::ecig( player *p, item *it, bool, const tripoint & )
p->mod_thirst( 1 );
p->mod_hunger( -1 );
p->add_effect( effect_cig, 10_minutes );
if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level( ADD_CIG ) + 1 ) ) {
if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level(
add_type::CIG ) + 1 ) ) {
p->add_msg_if_player( m_bad, _( "Ugh, too much nicotine… you feel nasty." ) );
}
return it->type->charges_to_use();
Expand Down Expand Up @@ -1239,7 +1241,7 @@ static void spawn_spores( const player &p )
static void marloss_common( player &p, item &it, const trait_id &current_color )
{
static const std::map<trait_id, add_type> mycus_colors = {{
{ trait_MARLOSS_BLUE, ADD_MARLOSS_B }, { trait_MARLOSS_YELLOW, ADD_MARLOSS_Y }, { trait_MARLOSS, ADD_MARLOSS_R }
{ trait_MARLOSS_BLUE, add_type::MARLOSS_B }, { trait_MARLOSS_YELLOW, add_type::MARLOSS_Y }, { trait_MARLOSS, add_type::MARLOSS_R }
}
};

Expand Down Expand Up @@ -1484,9 +1486,9 @@ int iuse::mycus( player *p, item *it, bool t, const tripoint &pos )
for( const tripoint &nearby_pos : g->m.points_in_radius( p->pos(), 3 ) ) {
fe.marlossify( nearby_pos );
}
p->rem_addiction( ADD_MARLOSS_R );
p->rem_addiction( ADD_MARLOSS_B );
p->rem_addiction( ADD_MARLOSS_Y );
p->rem_addiction( add_type::MARLOSS_R );
p->rem_addiction( add_type::MARLOSS_B );
p->rem_addiction( add_type::MARLOSS_Y );
} else if( p->has_trait( trait_THRESH_MYCUS ) &&
!p->has_trait( trait_M_DEPENDENT ) ) { // OK, now set the hook.
if( !one_in( 3 ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ void player::process_one_effect( effect &it, bool is_new )
// Handle painkillers
val = get_effect( "PKILL", reduced );
if( val != 0 ) {
mod = it.get_addict_mod( "PKILL", addiction_level( ADD_PKILLER ) );
mod = it.get_addict_mod( "PKILL", addiction_level( add_type::PKILLER ) );
if( is_new || it.activated( calendar::turn, "PKILL", val, reduced, mod ) ) {
mod_painkiller( bound_mod_to_vals( get_painkiller(), val, it.get_max_val( "PKILL", reduced ), 0 ) );
}
Expand Down Expand Up @@ -4317,7 +4317,7 @@ int player::sleep_spot( const tripoint &p ) const
int sleepy = static_cast<int>( comfort_info.level );
bool watersleep = has_trait( trait_WATERSLEEP );

if( has_addiction( ADD_SLEEP ) ) {
if( has_addiction( add_type::SLEEP ) ) {
sleepy -= 4;
}
if( has_trait( trait_INSOMNIA ) ) {
Expand Down
16 changes: 8 additions & 8 deletions src/pldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ enum class character_type : int {
FULL_RANDOM,
};

enum add_type : int {
ADD_NULL,
ADD_CAFFEINE, ADD_ALCOHOL, ADD_SLEEP, ADD_PKILLER, ADD_SPEED, ADD_CIG,
ADD_COKE, ADD_CRACK, ADD_MUTAGEN, ADD_DIAZEPAM, ADD_MARLOSS_R, ADD_MARLOSS_B,
ADD_MARLOSS_Y,
enum class add_type : int {
NONE,
CAFFEINE, ALCOHOL, SLEEP, PKILLER, SPEED, CIG,
COKE, CRACK, MUTAGEN, DIAZEPAM,
MARLOSS_R, MARLOSS_B, MARLOSS_Y,
NUM_ADD_TYPES // last
};

template<>
struct enum_traits<add_type> {
static constexpr add_type last = NUM_ADD_TYPES;
static constexpr add_type last = add_type::NUM_ADD_TYPES;
};

enum hp_part : int {
Expand All @@ -49,8 +49,8 @@ struct enum_traits<hp_part> {
class addiction
{
public:
add_type type = ADD_NULL;
int intensity = 0;
add_type type = add_type::NONE;
int intensity = 0;
time_duration sated = 1_hours;

addiction() = default;
Expand Down
2 changes: 0 additions & 2 deletions src/profession.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class JsonObject;
class avatar;
class player;

enum add_type : int;

class profession
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include <string>
#include <vector>

#include "pldata.h"
#include "string_id.h"
#include "translations.h"
#include "type_id.h"

class JsonObject;
class profession;

enum add_type : int;
template<typename T>
class generic_factory;

Expand Down
6 changes: 3 additions & 3 deletions src/suffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1570,13 +1570,13 @@ void Character::mend( int rate_multiplier )
if( has_effect( effect_cig ) ) {
healing_factor *= 0.5;
} else {
healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( ADD_CIG ) );
healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( add_type::CIG ) );
}

if( has_effect( effect_drunk ) ) {
healing_factor *= 0.5;
} else {
healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( ADD_ALCOHOL ) );
healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( add_type::ALCOHOL ) );
}

if( get_rad() > 0 && !has_trait( trait_RADIOGENIC ) ) {
Expand Down Expand Up @@ -1836,7 +1836,7 @@ void Character::apply_wetness_morale( int temperature )

void Character::add_addiction( add_type type, int strength )
{
if( type == ADD_NULL ) {
if( type == add_type::NONE ) {
return;
}
time_duration timer = 2_hours;
Expand Down
4 changes: 2 additions & 2 deletions tests/memorial_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TEST_CASE( "memorials" )
m, b, "The fuel tank of the vehicle_name exploded!", "vehicle_name" );

check_memorial<event_type::gains_addiction>(
m, b, "Became addicted to alcohol.", ch, ADD_ALCOHOL );
m, b, "Became addicted to alcohol.", ch, add_type::ALCOHOL );

check_memorial<event_type::gains_mutation>(
m, b, "Gained the mutation 'Carnivore'.", ch, mut );
Expand All @@ -198,7 +198,7 @@ TEST_CASE( "memorials" )
m, b, "Learned Aikido.", ch, matype_id( "style_aikido" ) );

check_memorial<event_type::loses_addiction>(
m, b, "Overcame addiction to alcohol.", ch, ADD_ALCOHOL );
m, b, "Overcame addiction to alcohol.", ch, add_type::ALCOHOL );

check_memorial<event_type::npc_becomes_hostile>(
m, b, "npc_name became hostile.", ch2, "npc_name" );
Expand Down

0 comments on commit 339ac5c

Please sign in to comment.