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

Temperature phases (HOT/COLD/FROZEN) tweaks & fixes [SPLIT] #25166

Merged
merged 6 commits into from Aug 27, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/consumption.cpp
Expand Up @@ -337,8 +337,7 @@ ret_val<edible_rating> player::can_eat( const item &food ) const
}
}
}
if( food.item_tags.count( "FROZEN" ) && !food.has_flag( "EDIBLE_FROZEN" ) &&
food.item_counter >= 100 ) {
if( food.item_tags.count( "FROZEN" ) && !food.has_flag( "EDIBLE_FROZEN" ) ) {
if( edible ) {
return ret_val<edible_rating>::make_failure(
_( "It's frozen solid. You must defrost it before you can eat it." ) );
Expand Down
4 changes: 2 additions & 2 deletions src/game_constants.h
Expand Up @@ -68,10 +68,10 @@
#define PLUTONIUM_CHARGES 500

/** Temperature inside an active fridge in Fahrenheit */
#define FRIDGE_TEMPERATURE 37 // 5 Celsius
#define FRIDGE_TEMPERATURE 37 // ~ 2.7 Celsius

/** Temperature inside an active freezer in Fahrenheit */
#define FREEZER_TEMPERATURE 27 // -5 Celsius
#define FREEZER_TEMPERATURE 23 // -5 Celsius

/** Temperature in which water freezes in Fahrenheit */
#define FREEZING_TEMPERATURE 32 // 0 Celsius
Expand Down
25 changes: 11 additions & 14 deletions src/item.cpp
Expand Up @@ -5778,22 +5778,19 @@ bool item::process_food( player * /*carrier*/, const tripoint &pos )
if( item_tags.count( "FROZEN" ) > 0 && item_counter > 500 && type->comestible->parasites > 0 ) {
item_tags.insert( "NO_PARASITES" );
}
/* cache g->get_temperature( item location ). It is used a minimum of 3 times, no reason to recalculate. */
const auto item_local_temp = g->get_temperature( pos );
unsigned int diff_freeze = abs( item_local_temp - FREEZING_TEMPERATURE );
diff_freeze = diff_freeze < 1 ? 1 : diff_freeze;
diff_freeze = diff_freeze > 10 ? 10 : diff_freeze;

unsigned int diff_cold = abs( item_local_temp - FRIDGE_TEMPERATURE );
diff_cold = diff_cold < 1 ? 1 : diff_cold;
diff_cold = diff_cold > 10 ? 10 : diff_cold;
// environment temperature applies COLD/FROZEN flags to food
if( item_local_temp <= FRIDGE_TEMPERATURE ) {
g->m.apply_in_fridge( *this, item_local_temp );

// minimum is 0 - takes into account that process() takes --1 counter per turn regardless
const auto temp = g->get_temperature( pos );
unsigned int diff_freeze = temp_difference_ratio( temp, FREEZING_TEMPERATURE ) - 1; //effective 1-4
unsigned int diff_cold = temp_difference_ratio( temp, FRIDGE_TEMPERATURE ) - 1;

// environment temperature applies COLD/FROZEN
if( temp <= FRIDGE_TEMPERATURE ) {
g->m.apply_in_fridge( *this, temp );
} else if ( item_tags.count( "FROZEN" ) > 0 && item_counter > diff_freeze ) {
item_counter -= diff_freeze;
item_counter -= diff_freeze; // thaw
} else if( item_tags.count( "COLD" ) > 0 && item_counter > diff_cold ) {
item_counter -= diff_cold;
item_counter -= diff_cold; // get warm
}
return false;
}
Expand Down
31 changes: 20 additions & 11 deletions src/map.cpp
Expand Up @@ -4251,17 +4251,26 @@ void map::update_lum( item_location &loc, bool add )
}
}

unsigned int temp_difference_ratio( int temp_one, int temp_two )
{
// ratio is between 1-4 and changes every 10F (~5.5C)
unsigned int ratio = abs( temp_one - temp_two ) / 10;
ratio = clamp( ratio, static_cast<unsigned int>(1), static_cast<unsigned int>(4) );
return ratio;
}

// Check if it's in a fridge/freezer and is food, set the fridge/freezer
// date to current time, and also check contents.
void map::apply_in_fridge( item &it, int temp )
void map::apply_in_fridge( item &it, int temp, bool vehicle )
{
unsigned int diff_freeze = abs(temp - FREEZING_TEMPERATURE);
diff_freeze = std::max( static_cast<unsigned int>(1), diff_freeze );
diff_freeze = std::min( static_cast<unsigned int>(5), diff_freeze );

unsigned int diff_cold = abs(temp - FRIDGE_TEMPERATURE);
diff_freeze = std::max( static_cast<unsigned int>(1), diff_cold );
diff_freeze = std::min( static_cast<unsigned int>(5), diff_cold );
unsigned int diff_freeze = temp_difference_ratio( temp, FREEZING_TEMPERATURE ) + 1; //effective 1-4
unsigned int diff_cold = temp_difference_ratio( temp, FRIDGE_TEMPERATURE ) + 1;

// this counters environmental effects trying to heat-up at the same ratio
if( vehicle ) {
diff_freeze *= 2;
diff_cold *= 2;
}

if( it.is_food() ) {
if( temp <= FREEZING_TEMPERATURE ) {
Expand Down Expand Up @@ -4308,7 +4317,7 @@ void map::apply_in_fridge( item &it, int temp )
}
if( it.is_container() ) {
for( auto &elem : it.contents ) {
apply_in_fridge( elem, temp );
apply_in_fridge( elem, temp, vehicle );
}
}
}
Expand Down Expand Up @@ -4345,14 +4354,14 @@ static void process_vehicle_items( vehicle &cur_veh, int part )
const bool fridge_here = cur_veh.part_flag( part, VPFLAG_FRIDGE ) && cur_veh.has_part( "FRIDGE", true );
if( fridge_here ) {
for( auto &n : cur_veh.get_items( part ) ) {
g->m.apply_in_fridge( n, FRIDGE_TEMPERATURE);
g->m.apply_in_fridge( n, FRIDGE_TEMPERATURE, true );
}
}

const bool freezer_here = cur_veh.part_flag( part, VPFLAG_FREEZER ) && cur_veh.has_part( "FREEZER", true );
if( freezer_here ) {
for( auto &n : cur_veh.get_items( part ) ) {
g->m.apply_in_fridge( n, FREEZER_TEMPERATURE );
g->m.apply_in_fridge( n, FREEZER_TEMPERATURE, true );
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/map.h
Expand Up @@ -907,7 +907,7 @@ class map
* @param it Item processed.
* @param temperature Temperature affecting item.
*/
void apply_in_fridge( item &it, int temperature );
void apply_in_fridge( item &it, int temperature, bool vehicle = false );

/**
* @name Consume items on the map
Expand Down Expand Up @@ -1578,6 +1578,12 @@ class map
bool need_draw_lower_floor( const tripoint &p );
};

/**
* Gives ratio for temperature differential of two temperatures
* Used in determining speed of temperature change of items
*/
unsigned int temp_difference_ratio( int temp_one, int temp_two );

std::vector<point> closest_points_first( int radius, point p );
std::vector<point> closest_points_first( int radius, int x, int y );
// Does not build "piles" - does the same as above functions, except in tripoints
Expand Down
1 change: 1 addition & 0 deletions src/vehicle_use.cpp
Expand Up @@ -219,6 +219,7 @@ void vehicle::set_electronics_menu_options( std::vector<uimenu_entry> &options,
add_toggle( _( "stereo" ), keybind( "TOGGLE_STEREO" ), "STEREO" );
add_toggle( _( "chimes" ), keybind( "TOGGLE_CHIMES" ), "CHIMES" );
add_toggle( _( "fridge" ), keybind( "TOGGLE_FRIDGE" ), "FRIDGE" );
add_toggle( _( "freezer" ), keybind( "TOGGLE_FEEZER" ), "FREEZER" );
add_toggle( _( "recharger" ), keybind( "TOGGLE_RECHARGER" ), "RECHARGE" );
add_toggle( _( "plow" ), keybind( "TOGGLE_PLOW" ), "PLOW" );
add_toggle( _( "reaper" ), keybind( "TOGGLE_REAPER" ), "REAPER" );
Expand Down