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

Generalize solarpack code #38770

Merged
merged 1 commit into from
Mar 18, 2020
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
10 changes: 6 additions & 4 deletions data/json/items/tool_armor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@
"encumbrance": 12,
"material_thickness": 3,
"use_action": "SOLARPACK",
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE" ]
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE", "SOLARPACK" ]
},
{
"id": "solarpack_on",
Expand All @@ -2724,7 +2724,8 @@
"encumbrance": 20,
"material_thickness": 1,
"use_action": "SOLARPACK_OFF",
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE" ]
"solar_efficiency": 0.05,
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE", "SOLARPACK_ON" ]
},
{
"id": "q_solarpack",
Expand All @@ -2744,7 +2745,7 @@
"encumbrance": 12,
"material_thickness": 3,
"use_action": "SOLARPACK",
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE" ]
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE", "SOLARPACK" ]
},
{
"id": "q_solarpack_on",
Expand All @@ -2765,7 +2766,8 @@
"encumbrance": 20,
"material_thickness": 1,
"use_action": "SOLARPACK_OFF",
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE" ]
"solar_efficiency": 0.3,
"flags": [ "FRAGILE", "OUTER", "ONLY_ONE", "SOLARPACK_ON" ]
},
{
"id": "helmet_riot",
Expand Down
9 changes: 1 addition & 8 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,7 @@ bool Character::burn_fuel( int b, bool start )
if( !remote_fuel.empty() ) {
fuel_available.emplace_back( remote_fuel );
if( remote_fuel == fuel_type_sun_light ) {
// basic solar panel produces 50W = 1 charge/20_seconds = 180 charges/hour(3600)
if( is_wearing( "solarpack_on" ) ) {
effective_efficiency = 0.05;
}
// quantum solar backpack = solar panel x6
if( is_wearing( "q_solarpack_on" ) ) {
effective_efficiency = 0.3;
}
effective_efficiency = item_worn_with_flag( "SOLARPACK_ON" ).type->solar_efficiency;
}
// TODO: check for available fuel in remote source
} else if( !start ) {
Expand Down
12 changes: 12 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,18 @@ bool Character::worn_with_flag( const std::string &flag, body_part bp ) const
} );
}

item Character::item_worn_with_flag( const std::string &flag, body_part bp ) const
{
item it_with_flag;
for( const item &it : worn ) {
if( it.has_flag( flag ) && ( bp == num_bp || it.covers( bp ) ) ) {
it_with_flag = it;
break;
}
}
return it_with_flag;
}

std::vector<std::string> Character::get_overlay_ids() const
{
std::vector<std::string> rval;
Expand Down
2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,8 @@ class Character : public Creature, public visitable<Character>
bool is_wearing_on_bp( const itype_id &it, body_part bp ) const;
/** Returns true if the player is wearing an item with the given flag. */
bool worn_with_flag( const std::string &flag, body_part bp = num_bp ) const;
/** Returns the first worn item with a given flag. */
item item_worn_with_flag( const std::string &flag, body_part bp = num_bp ) const;

// drawing related stuff
/**
Expand Down
2 changes: 1 addition & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ static void sleep()
// List all active items, bionics or mutations so player can deactivate them
std::vector<std::string> active;
for( auto &it : u.inv_dump() ) {
if( it->has_flag( flag_LITCIG ) ||
if( it->has_flag( flag_LITCIG ) ||
( it->active && ( it->charges > 0 || it->units_remaining( u ) > 0 ) && it->is_tool() ) ) {
active.push_back( it->tname() );
}
Expand Down
3 changes: 1 addition & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8932,8 +8932,7 @@ bool item::process_cable( player *carrier, const tripoint &pos )
}
std::string state = get_var( "state" );
if( state == "solar_pack_link" || state == "solar_pack" ) {
if( !carrier->has_item( *this ) || !( carrier->is_wearing( "solarpack_on" ) ||
carrier->is_wearing( "q_solarpack_on" ) ) ) {
if( !carrier->has_item( *this ) || !carrier->worn_with_flag( "SOLARPACK_ON" ) ) {
carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
reset_cable( carrier );
return false;
Expand Down
1 change: 1 addition & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
assign( jo, "magazine_well", def.magazine_well );
assign( jo, "explode_in_fire", def.explode_in_fire );
assign( jo, "insulation", def.insulation_factor );
assign( jo, "solar_efficiency", def.solar_efficiency );
assign( jo, "ascii_picture", def.ascii_picture );

if( jo.has_member( "thrown_damage" ) ) {
Expand Down
5 changes: 5 additions & 0 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,11 @@ struct itype {
*/
float insulation_factor = 1;

/**
* Efficiency of solar energy conversion for solarpacks.
*/
float solar_efficiency = 0;

std::string get_item_type_string() const {
if( tool ) {
return "TOOL";
Expand Down
18 changes: 5 additions & 13 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4107,19 +4107,15 @@ int iuse::solarpack( player *p, item *it, bool, const tripoint & )
return 0;
}
// no doubled sources of power
if( p->is_wearing( "solarpack_on" ) || p->is_wearing( "q_solarpack_on" ) ) {
if( p->worn_with_flag( "SOLARPACK_ON" ) ) {
p->add_msg_if_player( m_neutral, _( "You cannot use the %1$s with another of it's kind." ),
it->tname() );
return 0;
}
p->add_msg_if_player(
_( "You unfold solar array from the pack. You still need to connect it with a cable." ) );

if( it->typeId() == "solarpack" ) {
it->convert( "solarpack_on" );
} else {
it->convert( "q_solarpack_on" );
}
it->convert( it->typeId() + "_on" );
return 0;
}

Expand All @@ -4131,11 +4127,7 @@ int iuse::solarpack_off( player *p, item *it, bool, const tripoint & )
p->add_msg_if_player( _( "You unplug and fold your portable solar array into the pack." ) );
}

if( it->typeId() == "solarpack_on" ) {
it->convert( "solarpack" );
} else {
it->convert( "q_solarpack" );
}
it->convert( it->typeId().substr( 0, it->typeId().size() - 3 ) ).active = false; // 3 = "_on"
return 0;
}

Expand Down Expand Up @@ -8660,8 +8652,8 @@ int iuse::cable_attach( player *p, item *it, bool, const tripoint & )
{
std::string initial_state = it->get_var( "state", "attach_first" );
const bool has_bio_cable = !p->get_remote_fueled_bionic().is_empty();
const bool has_solar_pack = p->is_wearing( "solarpack" ) || p->is_wearing( "q_solarpack" );
const bool has_solar_pack_on = p->is_wearing( "solarpack_on" ) || p->is_wearing( "q_solarpack_on" );
const bool has_solar_pack = p->worn_with_flag( "SOLARPACK" );
const bool has_solar_pack_on = p->worn_with_flag( "SOLARPACK_ON" );
const bool wearing_solar_pack = has_solar_pack || has_solar_pack_on;
const bool has_ups = p->has_charges( "UPS_off", 1 ) || p->has_charges( "adv_UPS_off", 1 );

Expand Down