Skip to content

Commit 1c9a584

Browse files
authored
Fix water temperature from vehicle faucets (#55092)
* fuels_left() works with item * use get_item_thermal_energy() * use current phase * ammo_required() is more generic * combine different tanks for turrets * split fuel_items_left() from fuels_left() * correct unit in comment * specify unit here too
1 parent f365508 commit 1c9a584

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

src/item.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ class item : public visitable
990990
/** Sets the item to new temperature and energy based new specific energy (J/g) and resets last_temp_check*/
991991
void set_item_specific_energy( float specific_energy );
992992

993+
/**
994+
* Get the thermal energy of the item in Joules.
995+
*/
996+
float get_item_thermal_energy() const;
997+
993998
/** reset the last_temp_check used when crafting new items and the like */
994999
void reset_temp_check();
9951000

@@ -2658,11 +2663,6 @@ class item : public visitable
26582663
*/
26592664
void calc_temp( int temp, float insulation, const time_duration &time_delta );
26602665

2661-
/**
2662-
* Get the thermal energy of the item in Joules.
2663-
*/
2664-
float get_item_thermal_energy() const;
2665-
26662666
/** Calculates item specific energy (J/g) from temperature (K)*/
26672667
float get_specific_energy_from_temperature( float new_temperature );
26682668

src/vehicle.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,15 +3333,13 @@ int vehicle::fuel_capacity( const itype_id &ftype ) const
33333333

33343334
float vehicle::fuel_specific_energy( const itype_id &ftype ) const
33353335
{
3336-
float total_energy = 0.0f;
3337-
float total_mass = 0.0f;
3336+
float total_energy = 0.0f; // J
3337+
float total_mass = 0.0f; // g
33383338
for( const vehicle_part &vp : parts ) {
33393339
if( vp.is_tank() && vp.ammo_current() == ftype &&
3340-
vp.base.legacy_front().made_of( phase_id::LIQUID ) ) {
3341-
float energy = vp.base.legacy_front().specific_energy;
3342-
float mass = to_gram( vp.base.legacy_front().weight() );
3343-
total_energy += energy * mass;
3344-
total_mass += mass;
3340+
vp.base.only_item().made_of( phase_id::LIQUID ) ) {
3341+
total_energy += vp.base.only_item().get_item_thermal_energy();
3342+
total_mass += to_gram( vp.base.only_item().weight() );
33453343
}
33463344
}
33473345
return total_energy / total_mass;
@@ -6766,6 +6764,17 @@ std::map<itype_id, int> vehicle::fuels_left() const
67666764
return result;
67676765
}
67686766

6767+
std::list<item *> vehicle::fuel_items_left()
6768+
{
6769+
std::list<item *> result;
6770+
for( vehicle_part &p : parts ) {
6771+
if( p.is_fuel_store() && !p.ammo_current().is_null() && !p.base.is_container_empty() ) {
6772+
result.push_back( &p.base.only_item() );
6773+
}
6774+
}
6775+
return result;
6776+
}
6777+
67696778
bool vehicle::is_foldable() const
67706779
{
67716780
for( const vpart_reference &vp : get_all_parts() ) {

src/vehicle.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,11 @@ class vehicle
11861186
*/
11871187
std::map<itype_id, int> fuels_left() const;
11881188

1189+
/**
1190+
* All the individual fuel items that are in all the tanks in the vehicle.
1191+
*/
1192+
std::list<item *> fuel_items_left();
1193+
11891194
// Checks how much certain fuel left in tanks.
11901195
int fuel_left( const itype_id &ftype, bool recurse = false,
11911196
const std::function<bool( const vehicle_part & )> &filter = return_true<const vehicle_part &> )
@@ -1199,7 +1204,7 @@ class vehicle
11991204
// Returns total vehicle fuel capacity for the given fuel type
12001205
int fuel_capacity( const itype_id &ftype ) const;
12011206

1202-
// Returns the total specific energy of this fuel type. Frozen is ignored.
1207+
// Returns the total specific energy (J/g) of this fuel type. Frozen is ignored.
12031208
float fuel_specific_energy( const itype_id &ftype ) const;
12041209

12051210
// drains a fuel type (e.g. for the kitchen unit)

src/vehicle_use.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,10 +2085,9 @@ void vpart_position::form_inventory( inventory &inv )
20852085

20862086
// HACK: water_faucet pseudo tool gives access to liquids in tanks
20872087
if( vp_faucet && inv.provide_pseudo_item( itype_water_faucet, 0 ) ) {
2088-
for( const std::pair<const itype_id, int> &it : vehicle().fuels_left() ) {
2089-
item fuel( it.first, calendar::turn_zero );
2090-
if( fuel.made_of( phase_id::LIQUID ) ) {
2091-
fuel.charges = it.second;
2088+
for( const item *it : vehicle().fuel_items_left() ) {
2089+
if( it->made_of( phase_id::LIQUID ) ) {
2090+
item fuel( *it );
20922091
inv.add_item( fuel );
20932092
}
20942093
}

0 commit comments

Comments
 (0)