Skip to content

Commit

Permalink
Deprecate mutation and bionic functions from player to character (#44008
Browse files Browse the repository at this point in the history
)
  • Loading branch information
KorGgenT authored Sep 7, 2020
1 parent b607788 commit 93431eb
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 101 deletions.
6 changes: 3 additions & 3 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool is_layer_visible( const std::map<tripoint, explosion_tile> &layer )
}

//! Get p relative to u's current position and view
tripoint relative_view_pos( const player &u, const tripoint &p ) noexcept
tripoint relative_view_pos( const avatar &u, const tripoint &p ) noexcept
{
return p - u.view_offset + tripoint( POSX - u.posx(), POSY - u.posy(), -u.posz() );
}
Expand Down Expand Up @@ -514,7 +514,7 @@ namespace
{
// short visual animation (player, monster, ...) (hit, dodge, ...)
// cTile is a UTF-8 strings, and must be a single cell wide!
void hit_animation( const player &u, const tripoint &center, nc_color cColor,
void hit_animation( const avatar &u, const tripoint &center, nc_color cColor,
const std::string &cTile )
{
const tripoint init_pos = relative_view_pos( u, center );
Expand All @@ -537,7 +537,7 @@ void hit_animation( const player &u, const tripoint &center, nc_color cColor,
}
}

void draw_hit_mon_curses( const tripoint &center, const monster &m, const player &u,
void draw_hit_mon_curses( const tripoint &center, const monster &m, const avatar &u,
const bool dead )
{
hit_animation( u, center, red_background( m.type->color ), dead ? "%" : m.symbol() );
Expand Down
4 changes: 4 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class avatar : public player
int free_upgrade_points() const;
// how much "kill xp" you have
int kill_xp() const;
void power_bionics() override;
void power_mutations() override;
/** Returns the bionic with the given invlet, or NULL if no bionic has that invlet */
bionic *bionic_by_invlet( int ch );

faction *get_faction() const override;
// Set in npc::talk_to_you for use in further NPC interactions
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ void Character::add_bionic( const bionic_id &b )
return;
}

my_bionics->push_back( bionic( b, get_free_invlet( *this->as_player() ) ) );
my_bionics->push_back( bionic( b, get_free_invlet( *this ) ) );
if( b == bio_tools || b == bio_ears ) {
activate_bionic( my_bionics->size() - 1 );
}
Expand Down
3 changes: 2 additions & 1 deletion src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "units_fwd.h"
#include "value_ptr.h"

class avatar;
class Character;
class JsonIn;
class JsonObject;
Expand Down Expand Up @@ -214,7 +215,7 @@ std::vector<bodypart_id> get_occupied_bodyparts( const bionic_id &bid );

void reset_bionics();

char get_free_invlet( player &p );
char get_free_invlet( Character &p );
std::string list_occupied_bps( const bionic_id &bio_id, const std::string &intro,
bool each_bp_on_new_line = true );

Expand Down
15 changes: 10 additions & 5 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <cstddef>
#include <memory>

#include "avatar.h"
#include "bionics.h"
#include "bodypart.h"
#include "cata_utility.h"
Expand Down Expand Up @@ -159,7 +160,7 @@ std::string enum_to_string<bionic_ui_sort_mode>( bionic_ui_sort_mode mode )
}
} // namespace io

bionic *player::bionic_by_invlet( const int ch )
bionic *avatar::bionic_by_invlet( const int ch )
{
// space is a special case for unassigned
if( ch == ' ' ) {
Expand All @@ -174,17 +175,21 @@ bionic *player::bionic_by_invlet( const int ch )
return nullptr;
}

char get_free_invlet( player &p )
char get_free_invlet( Character &p )
{
if( p.is_npc() ) {
// npcs don't need an invlet
return ' ';
}
for( const char &inv_char : bionic_chars ) {
if( p.bionic_by_invlet( inv_char ) == nullptr ) {
if( p.as_avatar()->bionic_by_invlet( inv_char ) == nullptr ) {
return inv_char;
}
}
return ' ';
}

static void draw_bionics_titlebar( const catacurses::window &window, player *p,
static void draw_bionics_titlebar( const catacurses::window &window, avatar *p,
bionic_menu_mode mode )
{
input_context ctxt( "BIONICS", keyboard_mode::keychar );
Expand Down Expand Up @@ -534,7 +539,7 @@ static nc_color get_bionic_text_color( const bionic &bio, const bool isHighlight
return type;
}

void player::power_bionics()
void avatar::power_bionics()
{
sorted_bionics passive = filtered_bionics( *my_bionics, TAB_PASSIVE );
sorted_bionics active = filtered_bionics( *my_bionics, TAB_ACTIVE );
Expand Down
20 changes: 20 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,22 @@ class Character : public Creature, public visitable<Character>
trait_id random_bad_trait();

// In mutation.cpp
/** Returns true if the player has a conflicting trait to the entered trait
* Uses has_opposite_trait(), has_lower_trait(), and has_higher_trait() to determine conflicts.
*/
bool has_conflicting_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which upgrades into the entered trait */
bool has_lower_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which is an upgrade of the entered trait */
bool has_higher_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait that shares a type with the entered trait */
bool has_same_type_trait( const trait_id &flag ) const;
/** Returns true if the entered trait may be purified away
* Defaults to true
*/
bool purifiable( const trait_id &flag ) const;
/** Returns a dream's description selected randomly from the player's highest mutation category */
std::string get_category_dream( const mutation_category_id &cat, int strength ) const;
/** Returns true if the player has the entered trait */
bool has_trait( const trait_id &b ) const override;
/** Returns true if the player has the entered starting trait */
Expand All @@ -893,6 +909,10 @@ class Character : public Creature, public visitable<Character>
void switch_mutations( const trait_id &switched, const trait_id &target, bool start_powered );

bool can_power_mutation( const trait_id &mut );
/** Generates and handles the UI for player interaction with installed bionics */
virtual void power_bionics() {};
// TODO: Implement NPCs activating mutations
virtual void power_mutations() {};

/**Trigger reflex activation if the mutation has one*/
void mutation_reflex_trigger( const trait_id &mut );
Expand Down
61 changes: 61 additions & 0 deletions src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,67 @@ bool Character::mutate_towards( const trait_id &mut )
return true;
}

bool Character::has_conflicting_trait( const trait_id &flag ) const
{
return ( has_opposite_trait( flag ) || has_lower_trait( flag ) || has_higher_trait( flag ) ||
has_same_type_trait( flag ) );
}

bool Character::has_lower_trait( const trait_id &flag ) const
{
for( const trait_id &i : flag->prereqs ) {
if( has_trait( i ) || has_lower_trait( i ) ) {
return true;
}
}
return false;
}

bool Character::has_higher_trait( const trait_id &flag ) const
{
for( const auto &i : flag->replacements ) {
if( has_trait( i ) || has_higher_trait( i ) ) {
return true;
}
}
return false;
}

bool Character::has_same_type_trait( const trait_id &flag ) const
{
for( auto &i : get_mutations_in_types( flag->types ) ) {
if( has_trait( i ) && flag != i ) {
return true;
}
}
return false;
}

bool Character::purifiable( const trait_id &flag ) const
{
return flag->purifiable;
}

/// Returns a randomly selected dream
std::string Character::get_category_dream( const mutation_category_id &cat,
int strength ) const
{
std::vector<dream> valid_dreams;
//Pull the list of dreams
for( auto &i : dreams ) {
//Pick only the ones matching our desired category and strength
if( ( i.category == cat ) && ( i.strength == strength ) ) {
// Put the valid ones into our list
valid_dreams.push_back( i );
}
}
if( valid_dreams.empty() ) {
return "";
}
const dream &selected_dream = random_entry( valid_dreams );
return random_entry( selected_dream.messages() );
}

void Character::remove_mutation( const trait_id &mut, bool silent )
{
const auto &mdata = mut.obj();
Expand Down
8 changes: 2 additions & 6 deletions src/mutation_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <memory>
#include <unordered_map>

#include "avatar.h"
#include "color.h"
#include "enums.h"
#include "input.h"
Expand Down Expand Up @@ -67,13 +68,8 @@ static void show_mutations_titlebar( const catacurses::window &window,
wnoutrefresh( window );
}

void player::power_mutations()
void avatar::power_mutations()
{
if( !is_player() ) {
// TODO: Implement NPCs activating mutations
return;
}

std::vector<trait_id> passive;
std::vector<trait_id> active;
for( std::pair<const trait_id, trait_data> &mut : my_mutations ) {
Expand Down
61 changes: 0 additions & 61 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,67 +566,6 @@ time_duration player::estimate_effect_dur( const skill_id &relevant_skill,
return estimate;
}

bool player::has_conflicting_trait( const trait_id &flag ) const
{
return ( has_opposite_trait( flag ) || has_lower_trait( flag ) || has_higher_trait( flag ) ||
has_same_type_trait( flag ) );
}

bool player::has_lower_trait( const trait_id &flag ) const
{
for( const trait_id &i : flag->prereqs ) {
if( has_trait( i ) || has_lower_trait( i ) ) {
return true;
}
}
return false;
}

bool player::has_higher_trait( const trait_id &flag ) const
{
for( const auto &i : flag->replacements ) {
if( has_trait( i ) || has_higher_trait( i ) ) {
return true;
}
}
return false;
}

bool player::has_same_type_trait( const trait_id &flag ) const
{
for( auto &i : get_mutations_in_types( flag->types ) ) {
if( has_trait( i ) && flag != i ) {
return true;
}
}
return false;
}

bool player::purifiable( const trait_id &flag ) const
{
return flag->purifiable;
}

/// Returns a randomly selected dream
std::string player::get_category_dream( const mutation_category_id &cat,
int strength ) const
{
std::vector<dream> valid_dreams;
//Pull the list of dreams
for( auto &i : dreams ) {
//Pick only the ones matching our desired category and strength
if( ( i.category == cat ) && ( i.strength == strength ) ) {
// Put the valid ones into our list
valid_dreams.push_back( i );
}
}
if( valid_dreams.empty() ) {
return "";
}
const dream &selected_dream = random_entry( valid_dreams );
return random_entry( selected_dream.messages() );
}

std::list<item *> player::get_radio_items()
{
std::list<item *> rc_items;
Expand Down
24 changes: 0 additions & 24 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,6 @@ class player : public Character
/** Calculates the various speed bonuses we will get from mutations, etc. */
void recalc_speed_bonus();

/** Returns true if the player has a conflicting trait to the entered trait
* Uses has_opposite_trait(), has_lower_trait(), and has_higher_trait() to determine conflicts.
*/
bool has_conflicting_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which upgrades into the entered trait */
bool has_lower_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait which is an upgrade of the entered trait */
bool has_higher_trait( const trait_id &flag ) const;
/** Returns true if the player has a trait that shares a type with the entered trait */
bool has_same_type_trait( const trait_id &flag ) const;
/** Returns true if the entered trait may be purified away
* Defaults to true
*/
bool purifiable( const trait_id &flag ) const;
/** Returns a dream's description selected randomly from the player's highest mutation category */
std::string get_category_dream( const mutation_category_id &cat, int strength ) const;

/** Generates and handles the UI for player interaction with installed bionics */
void power_bionics();
void power_mutations();

/** Returns the bionic with the given invlet, or NULL if no bionic has that invlet */
bionic *bionic_by_invlet( int ch );

/** Called when a player triggers a trap, returns true if they don't set it off */
bool avoid_trap( const tripoint &pos, const trap &tr ) const override;

Expand Down

0 comments on commit 93431eb

Please sign in to comment.