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

Fix vehicle heater consuming too much energy #66504

Merged
merged 1 commit into from
Jun 29, 2023
Merged
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
48 changes: 20 additions & 28 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5313,6 +5313,26 @@ void vehicle::idle( bool on_map )
update_time( calendar::turn );
}

map &here = get_map();
// Parts emitting fields
const std::pair<int, double> exhaust_and_muffle = get_exhaust_part();
for( const int emitter_idx : emitters ) {
const vehicle_part &pt = parts[emitter_idx];
if( pt.is_unavailable() || !pt.enabled ) {
continue;
}
for( const emit_id &e : pt.info().emissions ) {
here.emit_field( global_part_pos3( pt ), e );
}
for( const emit_id &e : pt.info().exhaust ) {
if( exhaust_and_muffle.first == -1 ) {
here.emit_field( global_part_pos3( pt ), e );
} else {
here.emit_field( exhaust_dest( exhaust_and_muffle.first ), e );
}
}
}

if( has_part( "STEREO", true ) ) {
play_music();
}
Expand Down Expand Up @@ -7458,34 +7478,6 @@ void vehicle::update_time( const time_point &update_to )
}

map &here = get_map();
// Parts emitting fields
const std::pair<int, double> exhaust_and_muffle = get_exhaust_part();
for( const int emitter_idx : emitters ) {
const vehicle_part &pt = parts[emitter_idx];
if( pt.is_unavailable() || !pt.enabled ) {
continue;
}
for( const emit_id &e : pt.info().emissions ) {
here.emit_field( global_part_pos3( pt ), e );
}
for( const emit_id &e : pt.info().exhaust ) {
if( exhaust_and_muffle.first == -1 ) {
here.emit_field( global_part_pos3( pt ), e );
} else {
here.emit_field( exhaust_dest( exhaust_and_muffle.first ), e );
}
}
// reduce interval of parts with VPFLAG_ENABLED_DRAINS_EPOWER, otherwise their epower
// get charged twice - once by power_parts in vehicle::idle and once here
const time_duration interval = pt.info().has_flag( VPFLAG_ENABLED_DRAINS_EPOWER )
? update_to - last_update - 1_seconds
: update_to - last_update;
if( interval < 0_seconds ) {
debugmsg( "emitter simulating negative time interval, something is fishy / buggy" );
break;
}
discharge_battery( power_to_energy_bat( -pt.info().epower, interval ) );
}

if( sm_pos.z < 0 ) {
last_update = update_to;
Expand Down