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

Npc can handle multipe power gen cbm #35601

Merged
merged 4 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion data/json/obsolete.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"name": "Internal Furnace",
"description": "When this bionic is active, you can burn nearly any organic material as fuel (use 'E'), recharging your power level. Some materials will burn better than others.",
"occupied_bodyparts": [ [ "TORSO", 40 ] ],
"flags": [ "BIONIC_POWER_SOURCE", "BIONIC_TOGGLED" ]
"flags": [ "BIONIC_POWER_SOURCE", "BIONIC_TOGGLED", "BIONIC_NPC_USABLE" ]
},
{
"id": "bio_storage",
Expand Down
22 changes: 12 additions & 10 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,19 +1644,17 @@ bool npc::wants_to_recharge_cbm()
const units::energy curr_power = get_power_level();
const float allowed_ratio = static_cast<int>( rules.cbm_recharge ) / 100.0f;
const units::energy max_pow_allowed = get_max_power_level() * allowed_ratio;
const bool &no_fueled_cbm = get_fueled_bionics().empty();

bool no_fueled_cbm = true;
for( const bionic_id bid : get_fueled_bionics() ) {
no_fueled_cbm = false;
if( get_fuel_available( bid ).empty() ) {
return true;
} else if( curr_power < max_pow_allowed && !use_bionic_by_id( bid ) ) {
return true;
if( curr_power < max_pow_allowed ) {
for( const bionic_id bid : get_fueled_bionics() ) {
if( !has_active_bionic( bid ) ) {
return true;
}
}
return no_fueled_cbm;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return no_fueled_cbm;
return get_fueled_bionics().empty();

And get rid of the variable. It's only used here.

And why do NPC want to recharge their bionic power if they don't have any fuelled CBMs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bio_furnace and bio_reactor don't use the fuel system but NPC can use them.

}
if( no_fueled_cbm ) {
return curr_power < max_pow_allowed;
}

return false;
}

Expand Down Expand Up @@ -1694,6 +1692,10 @@ bool npc::recharge_cbm()
}

for( bionic_id &bid : get_fueled_bionics() ) {
if( has_active_bionic( bid ) ) {
continue;
}

if( !get_fuel_available( bid ).empty() ) {
use_bionic_by_id( bid );
return true;
Expand Down