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

Remove include of "bionics.h" from "character.h". #22528

Merged
merged 2 commits into from
Dec 2, 2017
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
34 changes: 17 additions & 17 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void force_comedown( effect &eff )
// share functions....
bool player::activate_bionic( int b, bool eff_only )
{
bionic &bio = my_bionics[b];
bionic &bio = ( *my_bionics )[b];

// Preserve the fake weapon used to initiate bionic gun firing
static item bio_gun( weapon );
Expand Down Expand Up @@ -191,14 +191,14 @@ bool player::activate_bionic( int b, bool eff_only )
weapon = item( bionics[bio.id].fake_item );
weapon.invlet = '#';
} else if( bio.id == "bio_ears" && has_active_bionic( bionic_id( "bio_earplugs" ) ) ) {
for( auto &i : my_bionics ) {
for( auto &i : *my_bionics ) {
if( i.id == "bio_earplugs" ) {
i.powered = false;
add_msg( m_info, _( "Your %s automatically turn off." ), bionics[i.id].name.c_str() );
}
}
} else if( bio.id == "bio_earplugs" && has_active_bionic( bionic_id( "bio_ears" ) ) ) {
for( auto &i : my_bionics ) {
for( auto &i : *my_bionics ) {
if( i.id == "bio_ears" ) {
i.powered = false;
add_msg( m_info, _( "Your %s automatically turns off." ), bionics[i.id].name.c_str() );
Expand Down Expand Up @@ -554,7 +554,7 @@ bool player::activate_bionic( int b, bool eff_only )

bool player::deactivate_bionic( int b, bool eff_only )
{
bionic &bio = my_bionics[b];
bionic &bio = ( *my_bionics )[b];

// Just do the effect, no stat changing or messages
if( !eff_only ) {
Expand Down Expand Up @@ -659,7 +659,7 @@ bool attempt_recharge( player &p, bionic &bio, int &amount, int factor = 1, int

void player::process_bionic( int b )
{
bionic &bio = my_bionics[b];
bionic &bio = ( *my_bionics )[b];
// Only powered bionics should be processed
if( !bio.powered ) {
return;
Expand Down Expand Up @@ -895,8 +895,8 @@ bool player::uninstall_bionic( bionic_id const &b_id, int skill_level )

// Surgery is imminent, retract claws or blade if active
if( skill_level == -1 ) {
for( size_t i = 0; i < my_bionics.size(); i++ ) {
const auto &bio = my_bionics[ i ];
for( size_t i = 0; i < my_bionics->size(); i++ ) {
const auto &bio = ( *my_bionics )[ i ];
if( bio.powered && bio.info().weapon_bionic ) {
deactivate_bionic( i );
}
Expand Down Expand Up @@ -1243,7 +1243,7 @@ std::string list_occupied_bps( const bionic_id &bio_id, const std::string &intro
int player::get_used_bionics_slots( const body_part bp ) const
{
int used_slots = 0;
for( auto &bio : my_bionics ) {
for( auto &bio : *my_bionics ) {
auto search = bionics[bio.id].occupied_bodyparts.find( bp );
if( search != bionics[bio.id].occupied_bodyparts.end() ) {
used_slots += search->second;
Expand Down Expand Up @@ -1326,9 +1326,9 @@ void player::add_bionic( bionic_id const &b )
return;
}

my_bionics.push_back( bionic( b, get_free_invlet( *this ) ) );
my_bionics->push_back( bionic( b, get_free_invlet( *this ) ) );
if( b == "bio_tools" || b == "bio_ears" ) {
activate_bionic( my_bionics.size() - 1 );
activate_bionic( my_bionics->size() - 1 );
}

for( const auto &inc_bid : bionics[b].included_bionics ) {
Expand All @@ -1340,8 +1340,8 @@ void player::add_bionic( bionic_id const &b )

void player::remove_bionic( bionic_id const &b )
{
std::vector<bionic> new_my_bionics;
for( auto &i : my_bionics ) {
bionic_collection new_my_bionics;
for( auto &i : *my_bionics ) {
if( b == i.id ) {
continue;
}
Expand All @@ -1353,21 +1353,21 @@ void player::remove_bionic( bionic_id const &b )

new_my_bionics.push_back( bionic( i.id, i.invlet ) );
}
my_bionics = new_my_bionics;
*my_bionics = new_my_bionics;
recalc_sight_limits();
}

int player::num_bionics() const
{
return my_bionics.size();
return my_bionics->size();
}

std::pair<int, int> player::amount_of_storage_bionics() const
{
int lvl = max_power_level;

// exclude amount of power capacity obtained via non-power-storage CBMs
for( auto it : my_bionics ) {
for( auto it : *my_bionics ) {
lvl -= bionics[it.id].capacity;
}

Expand Down Expand Up @@ -1397,7 +1397,7 @@ std::pair<int, int> player::amount_of_storage_bionics() const

bionic &player::bionic_at_index( int i )
{
return my_bionics[i];
return ( *my_bionics )[i];
}


Expand All @@ -1408,7 +1408,7 @@ bool player::remove_random_bionic()
const int numb = num_bionics();
if( numb ) {
int rem = rng( 0, num_bionics() - 1 );
const auto bionic = my_bionics[rem];
const auto bionic = ( *my_bionics )[rem];
remove_bionic( bionic.id );
add_msg( m_bad, _( "Your %s fails, and is destroyed!" ), bionics[ bionic.id ].name.c_str() );
recalc_sight_limits();
Expand Down
6 changes: 6 additions & 0 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ struct bionic : public JsonSerializer, public JsonDeserializer {
void deserialize( JsonIn &jsin ) override;
};

// A simpler wrapper to allow forward declarations of it. std::vector can not
// be forward declared without a *definition* of bionic, but this wrapper can.
class bionic_collection : public std::vector<bionic>
{
};

void check_bionics();
void reset_bionics();
void load_bionic( JsonObject &jsobj ); // load a bionic from JSON
Expand Down
16 changes: 8 additions & 8 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum bionic_menu_mode {

bionic *player::bionic_by_invlet( const long ch )
{
for( auto &elem : my_bionics ) {
for( auto &elem : *my_bionics ) {
if( elem.invlet == ch ) {
return &elem;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ nc_color get_bionic_text_color( bionic const &bio, bool const isHighlightedBioni
return type;
}

std::vector< bionic *>filtered_bionics( std::vector<bionic> &all_bionics, bionic_tab_mode mode )
std::vector< bionic *>filtered_bionics( bionic_collection &all_bionics, bionic_tab_mode mode )
{
std::vector< bionic *>filtered_entries;
for( auto &elem : all_bionics ) {
Expand All @@ -289,8 +289,8 @@ std::vector< bionic *>filtered_bionics( std::vector<bionic> &all_bionics, bionic

void player::power_bionics()
{
std::vector <bionic *> passive = filtered_bionics( my_bionics, TAB_PASSIVE );
std::vector <bionic *> active = filtered_bionics( my_bionics, TAB_ACTIVE );
std::vector <bionic *> passive = filtered_bionics( *my_bionics, TAB_PASSIVE );
std::vector <bionic *> active = filtered_bionics( *my_bionics, TAB_ACTIVE );
bionic *bio_last = NULL;
bionic_tab_mode tab_mode = TAB_ACTIVE;

Expand All @@ -310,7 +310,7 @@ void player::power_bionics()
const int HEIGHT = std::min( TERMY,
std::max( FULL_SCREEN_HEIGHT,
TITLE_HEIGHT + TITLE_TAB_HEIGHT +
( int )my_bionics.size() + 2 ) );
( int )my_bionics->size() + 2 ) );
const int WIDTH = FULL_SCREEN_WIDTH + ( TERMX - FULL_SCREEN_WIDTH ) / 2;
const int START_X = ( TERMX - WIDTH ) / 2;
const int START_Y = ( TERMY - HEIGHT ) / 2;
Expand Down Expand Up @@ -368,8 +368,8 @@ void player::power_bionics()

for( ;; ) {
if( recalc ) {
passive = filtered_bionics( my_bionics, TAB_PASSIVE );
active = filtered_bionics( my_bionics, TAB_ACTIVE );
passive = filtered_bionics( *my_bionics, TAB_PASSIVE );
active = filtered_bionics( *my_bionics, TAB_ACTIVE );

if( active.empty() && !passive.empty() ) {
tab_mode = TAB_PASSIVE;
Expand Down Expand Up @@ -590,7 +590,7 @@ void player::power_bionics()
}
if( menu_mode == ACTIVATING ) {
if( bio_data.activated ) {
int b = tmp - &my_bionics[0];
int b = tmp - &( *my_bionics )[0];
if( tmp->powered ) {
deactivate_bionic( b );
} else {
Expand Down
7 changes: 5 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "character.h"
#include "game.h"
#include "map.h"
#include "bionics.h"
#include "map_selector.h"
#include "vehicle_selector.h"
#include "debug.h"
Expand Down Expand Up @@ -132,6 +133,8 @@ Character::Character() : Creature(), visitable<Character>()
path_settings = pathfinding_settings{ 0, 1000, 1000, 0, true, false, true };
}

Character::~Character() = default;

field_id Character::bloodType() const
{
if (has_trait( trait_ACIDBLOOD ))
Expand Down Expand Up @@ -614,7 +617,7 @@ float Character::get_vision_threshold( float light_level ) const {

bool Character::has_bionic(const bionic_id &b) const
{
for (auto &i : my_bionics) {
for (auto &i : *my_bionics) {
if (i.id == b) {
return true;
}
Expand All @@ -624,7 +627,7 @@ bool Character::has_bionic(const bionic_id &b) const

bool Character::has_active_bionic(const bionic_id &b) const
{
for (auto &i : my_bionics) {
for (auto &i : *my_bionics) {
if (i.id == b) {
return (i.powered);
}
Expand Down
9 changes: 6 additions & 3 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "visitable.h"
#include "creature.h"
#include "inventory.h"
#include "bionics.h"
#include "copyable_unique_ptr.h"
#include "skill.h"
#include "map_selector.h"
#include "pathfinding.h"
Expand All @@ -20,6 +20,9 @@ class field_entry;
class vehicle;
struct resistances;
struct mutation_branch;
class bionic_collection;
struct bionic_data;
using bionic_id = string_id<bionic_data>;

enum vision_modes {
DEBUG_NIGHTVISION,
Expand Down Expand Up @@ -71,7 +74,7 @@ struct aim_type {
class Character : public Creature, public visitable<Character>
{
public:
~Character() override { };
~Character() override;

field_id bloodType() const override;
field_id gibType() const override;
Expand Down Expand Up @@ -602,7 +605,7 @@ class Character : public Creature, public visitable<Character>
item weapon;
item ret_null; // Null item, sometimes returns by weapon() etc

std::vector<bionic> my_bionics;
copyable_unique_ptr<bionic_collection> my_bionics;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here is the problem I think, the vector was default contructed, but the unique_ptr is constructed empty, it just needs a new default constructed bionic_collection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good, added my_bionics.reset( new bionic_collection() ); to the end of the Character constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry. I forgot that. Somehow I assumed the wrapper would create the pointer automatically. May need to add something like this.


protected:
void on_stat_change( const std::string &, int ) override {};
Expand Down
3 changes: 2 additions & 1 deletion src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "game.h"
#include "game_inventory.h"
#include "input.h"
#include "bionics.h"
#include "inventory.h"
#include "itype.h"
#include "json.h"
Expand Down Expand Up @@ -285,7 +286,7 @@ const inventory &player::crafting_inventory()
cached_crafting_inventory += inv;
cached_crafting_inventory += weapon;
cached_crafting_inventory += worn;
for( const auto &bio : my_bionics ) {
for( const auto &bio : *my_bionics ) {
const auto &bio_data = bio.info();
if( ( !bio_data.activated || bio.powered ) &&
!bio_data.fake_item.empty() ) {
Expand Down
1 change: 1 addition & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "veh_type.h"
#include "options.h"
#include "auto_pickup.h"
#include "bionics.h"
#include "gamemode.h"
#include "mapbuffer.h"
#include "map_item_stack.h"
Expand Down
1 change: 0 additions & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "addiction.h"
#include "artifact.h"
#include "bionics.h"
#include "catacharset.h"
#include "construction.h"
#include "crafting.h"
Expand Down
1 change: 0 additions & 1 deletion src/melee.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "player.h"
#include "bionics.h"
#include "debug.h"
#include "game.h"
#include "game_inventory.h"
Expand Down
3 changes: 2 additions & 1 deletion src/mission_companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "dialogue.h"
#include "rng.h"
#include "line.h"
#include "bionics.h"
#include "debug.h"
#include "catacharset.h"
#include "messages.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ void talk_function::bionic_install(npc &p)

void talk_function::bionic_remove(npc &p)
{
std::vector <bionic> all_bio = g->u.my_bionics;
bionic_collection all_bio = *g->u.my_bionics;
if (all_bio.size() == 0){
popup(_("You don't have any bionics installed..."));
return;
Expand Down
1 change: 1 addition & 0 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "start_location.h"
#include "input.h"
#include "output.h"
#include "bionics.h"
#include "rng.h"
#include "game.h"
#include "name.h"
Expand Down
12 changes: 6 additions & 6 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,8 @@ void player::memorial( std::ostream &memorial_file, std::string epitaph )
//Bionics
memorial_file << _( "Bionics:" ) << eol;
int total_bionics = 0;
for( size_t i = 0; i < my_bionics.size(); ++i ) {
memorial_file << indent << ( i + 1 ) << ": " << my_bionics[i].id->name << eol;
for( size_t i = 0; i < my_bionics->size(); ++i ) {
memorial_file << indent << ( i + 1 ) << ": " << (*my_bionics)[i].id->name << eol;
total_bionics++;
}
if( total_bionics == 0 ) {
Expand Down Expand Up @@ -5390,8 +5390,8 @@ void player::suffer()
}
}

for (size_t i = 0; i < my_bionics.size(); i++) {
if (my_bionics[i].powered) {
for (size_t i = 0; i < my_bionics->size(); i++) {
if ((*my_bionics)[i].powered) {
process_bionic(i);
}
}
Expand Down Expand Up @@ -6755,7 +6755,7 @@ int player::invlet_to_position( const long linvlet ) const
}

bool player::can_interface_armor() const {
bool okay = std::any_of( my_bionics.begin(), my_bionics.end(),
bool okay = std::any_of( my_bionics->begin(), my_bionics->end(),
[]( const bionic &b ) { return b.powered && b.info().armor_interface; } );
return okay;
}
Expand Down Expand Up @@ -11371,7 +11371,7 @@ void player::place_corpse()
for( auto itm : tmp ) {
g->m.add_item_or_charges( pos(), *itm );
}
for( auto & bio : my_bionics ) {
for( auto & bio : *my_bionics ) {
if( item::type_is_defined( bio.id.str() ) ) {
body.put_in( item( bio.id.str(), calendar::turn ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
static const std::string DEFAULT_HOTKEYS("1234567890abcdefghijklmnopqrstuvwxyz");

enum action_id : int;

struct bionic;
class dispersion_sources;
class monster;
class game;
Expand Down
1 change: 0 additions & 1 deletion src/profession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "debug.h"
#include "json.h"
#include "player.h"
#include "bionics.h"
#include "text_snippets.h"
#include "rng.h"
#include "translations.h"
Expand Down
Loading