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

Underground temperature and food rot calculation overhaul. #24073

Merged
merged 3 commits into from
Jun 24, 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
2 changes: 1 addition & 1 deletion lua/class_definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ classes = {
{ name = "get_levx", rval = "int", args = { } },
{ name = "get_levy", rval = "int", args = { } },
{ name = "get_levz", rval = "int", args = { } },
{ name = "get_temperature", rval = "int", args = { } },
{ name = "get_temperature", rval = "int", args = { "tripoint" } },
{ name = "handle_liquid", rval = "bool", args = { "item" } },
{ name = "increase_kill_count", rval = nil, args = { "mtype_id" } },
{ name = "inv_for_all", rval = "int", args = { "string" } },
Expand Down
4 changes: 2 additions & 2 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ bool player::activate_bionic( int b, bool eff_only )
double windpower = 100.0f * get_local_windpower( weatherPoint.windpower + vehwindspeed,
cur_om_ter, g->is_sheltered( g->u.pos() ) );
add_msg_if_player( m_info, _( "Temperature: %s." ),
print_temperature( g->get_temperature() ).c_str() );
print_temperature( g->get_temperature( g->u.pos() ) ).c_str() );
add_msg_if_player( m_info, _( "Relative Humidity: %s." ),
print_humidity(
get_local_humidity( weatherPoint.humidity, g->weather,
Expand All @@ -505,7 +505,7 @@ bool player::activate_bionic( int b, bool eff_only )
add_msg_if_player( m_info, _( "Feels Like: %s." ),
print_temperature(
get_local_windchill( weatherPoint.temperature, weatherPoint.humidity,
windpower ) + g->get_temperature() ).c_str() );
windpower ) + g->get_temperature( g->u.pos() ) ).c_str() );
} else if( bio.id == "bio_remote" ) {
int choice = menu( true, _( "Perform which function:" ), _( "Nothing" ),
_( "Control vehicle" ), _( "RC radio" ), NULL );
Expand Down
12 changes: 9 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,9 +1747,15 @@ void game::update_weather()
}
}

int game::get_temperature()
int game::get_temperature( const tripoint &location )
{
return temperature + m.temperature( u.pos() );

if ( location.z < 0 ) {
// underground temperature = average New England temperature = 43F/6C rounded to int
return 43 + m.temperature( location );
}
// if not underground use weather determined temperature
return temperature + m.temperature( location );
}

int game::assign_mission_id()
Expand Down Expand Up @@ -4657,7 +4663,7 @@ void game::draw_sidebar()
}

if( u.has_item_with_flag( "THERMOMETER" ) || u.has_bionic( bionic_id( "bio_meteorologist" ) ) ) {
wprintz( w_location, c_white, " %s", print_temperature( get_temperature() ).c_str());
wprintz( w_location, c_white, " %s", print_temperature( get_temperature( u.pos() ) ).c_str());
}

//moon phase display
Expand Down
3 changes: 2 additions & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ class game
int get_user_action_counter() const;

signed char temperature; // The air temperature
int get_temperature(); // Returns outdoor or indoor temperature of current location
// Returns outdoor or indoor temperature of given location
int get_temperature( const tripoint &location );
weather_type weather; // Weather pattern--SEE weather.h
bool lightning_active;
pimpl<w_point> weather_precise; // Cached weather data
Expand Down
6 changes: 3 additions & 3 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7436,10 +7436,10 @@ int iuse::weather_tool( player *p, item *it, bool, const tripoint & )
if( it->has_flag( "THERMOMETER" ) ) {
if( it->typeId() == "thermometer" ) {
p->add_msg_if_player( m_neutral, _( "The %1$s reads %2$s." ), it->tname().c_str(),
print_temperature( g->get_temperature() ).c_str() );
print_temperature( g->get_temperature( g->u.pos() ) ).c_str() );
} else {
p->add_msg_if_player( m_neutral, _( "Temperature: %s." ),
print_temperature( g->get_temperature() ).c_str() );
print_temperature( g->get_temperature( g->u.pos() ) ).c_str() );
}
}
if( it->has_flag( "HYGROMETER" ) ) {
Expand Down Expand Up @@ -7483,7 +7483,7 @@ int iuse::weather_tool( player *p, item *it, bool, const tripoint & )
m_neutral, _( "Feels Like: %s." ),
print_temperature(
get_local_windchill( weatherPoint.temperature, weatherPoint.humidity, windpower ) +
g->get_temperature() ).c_str() );
g->get_temperature( g->u.pos() ) ).c_str() );
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mission_companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ void talk_function::field_build_2( npc &p )

void talk_function::field_plant( npc &p, std::string place )
{
if (g->get_temperature() < 50) {
if (g->get_temperature( g->u.pos() ) < 50) {
popup(_("It is too cold to plant anything now."));
return;
}
Expand Down
18 changes: 9 additions & 9 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ void player::update_bodytemp()
}
// NOTE : visit weather.h for some details on the numbers used
// Converts temperature to Celsius/10
int Ctemperature = int( 100 * temp_to_celsius( g->get_temperature() ) );
int Ctemperature = int( 100 * temp_to_celsius( g->get_temperature( g->u.pos() ) ) );
w_point const weather = *g->weather_precise;
int vehwindspeed = 0;
if( const optional_vpart_position vp = g->m.veh_at( pos() ) ) {
Expand Down Expand Up @@ -1086,7 +1086,7 @@ void player::update_bodytemp()

bp_windpower = int( ( float )bp_windpower * ( 1 - get_wind_resistance( bp ) / 100.0 ) );
// Calculate windchill
int windchill = get_local_windchill( g->get_temperature(),
int windchill = get_local_windchill( g->get_temperature( g->u.pos() ),
get_local_humidity( weather.humidity, g->weather,
sheltered ),
bp_windpower );
Expand Down Expand Up @@ -1348,7 +1348,7 @@ void player::update_bodytemp()
int wetness_percentage = 100 * body_wetness[bp] / drench_capacity[bp]; // 0 - 100
// Warmth gives a slight buff to temperature resistance
// Wetness gives a heavy nerf to temperature resistance
int Ftemperature = int( g->get_temperature() +
int Ftemperature = int( g->get_temperature( g->u.pos() ) +
warmth( bp ) * 0.2 - 20 * wetness_percentage / 100 );
// Windchill reduced by your armor
int FBwindPower = int( total_windpower * ( 1 - get_wind_resistance( bp ) / 100.0 ) );
Expand Down Expand Up @@ -1758,12 +1758,12 @@ void player::recalc_speed_bonus()
if( has_trait( trait_SUNLIGHT_DEPENDENT ) && !g->is_in_sunlight( pos() ) ) {
mod_speed_bonus( -( g->light_level( posz() ) >= 12 ? 5 : 10 ) );
}
if( has_trait( trait_COLDBLOOD4 ) || ( has_trait( trait_COLDBLOOD3 ) && g->get_temperature() < 65 ) ) {
mod_speed_bonus( ( g->get_temperature() - 65 ) / 2 );
} else if( has_trait( trait_COLDBLOOD2 ) && g->get_temperature() < 65 ) {
mod_speed_bonus( ( g->get_temperature() - 65 ) / 3 );
} else if( has_trait( trait_COLDBLOOD ) && g->get_temperature() < 65 ) {
mod_speed_bonus( ( g->get_temperature() - 65 ) / 5 );
if( has_trait( trait_COLDBLOOD4 ) || ( has_trait( trait_COLDBLOOD3 ) && g->get_temperature( pos() ) < 65 ) ) {
mod_speed_bonus( ( g->get_temperature( pos() ) - 65 ) / 2 );
} else if( has_trait( trait_COLDBLOOD2 ) && g->get_temperature( pos() ) < 65 ) {
mod_speed_bonus( ( g->get_temperature( pos() ) - 65 ) / 3 );
} else if( has_trait( trait_COLDBLOOD ) && g->get_temperature( pos() ) < 65 ) {
mod_speed_bonus( ( g->get_temperature( pos() ) - 65 ) / 5 );
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/player_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,21 +610,21 @@ Strength - 4; Dexterity - 4; Intelligence - 4; Perception - 4" ) );
( pen < 10 ? " " : "" ), pen );
line++;
}
if( has_trait( trait_id( "COLDBLOOD4" ) ) && g->get_temperature() > 65 ) {
pen = ( g->get_temperature() - 65 ) / 2;
if( has_trait( trait_id( "COLDBLOOD4" ) ) && g->get_temperature( g->u.pos() ) > 65 ) {
pen = ( g->get_temperature( g->u.pos() ) - 65 ) / 2;
mvwprintz( w_speed, line, 1, c_green, _( "Cold-Blooded +%s%d%%" ),
( pen < 10 ? " " : "" ), pen );
line++;
}
if( ( has_trait( trait_id( "COLDBLOOD" ) ) || has_trait( trait_id( "COLDBLOOD2" ) ) ||
has_trait( trait_id( "COLDBLOOD3" ) ) || has_trait( trait_id( "COLDBLOOD4" ) ) ) &&
g->get_temperature() < 65 ) {
g->get_temperature( g->u.pos() ) < 65 ) {
if( has_trait( trait_id( "COLDBLOOD3" ) ) || has_trait( trait_id( "COLDBLOOD4" ) ) ) {
pen = ( 65 - g->get_temperature() ) / 2;
pen = ( 65 - g->get_temperature( g->u.pos() ) ) / 2;
} else if( has_trait( trait_id( "COLDBLOOD2" ) ) ) {
pen = ( 65 - g->get_temperature() ) / 3;
pen = ( 65 - g->get_temperature( g->u.pos() ) ) / 3;
} else {
pen = ( 65 - g->get_temperature() ) / 5;
pen = ( 65 - g->get_temperature( g->u.pos() ) ) / 5;
}
mvwprintz( w_speed, line, 1, c_red, _( "Cold-Blooded -%s%d%%" ),
( pen < 10 ? " " : "" ), pen );
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ double vehicle::engine_cold_factor( const int e ) const
{
if( !is_engine_type( e, fuel_type_diesel ) ) { return 0.0; }

int eff_temp = g->get_temperature();
int eff_temp = g->get_temperature( g->u.pos() );
if( !parts[ engines[ e ] ].faults().count( fault_glowplug ) ) {
eff_temp = std::min( eff_temp, 20 );
}
Expand Down
20 changes: 10 additions & 10 deletions src/weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ int get_hourly_rotpoints_at_temp( int temp );

time_duration get_rot_since( const time_point &start, const time_point &end, const tripoint &location )
{
// Ensure food doesn't rot in ice labs, where the
// temperature is much less than the weather specifies.
tripoint const omt_pos = ms_to_omt_copy( location );
oter_id const & oter = overmap_buffer.ter( omt_pos );
// TODO: extract this into a property of the overmap terrain
if (is_ot_type("ice_lab", oter)) {
return 0;
}
// TODO: maybe have different rotting speed when underground?

time_duration ret = 0;
// if underground it ignores weather, using strait underground temperature instead
if ( location.z < 0 ) {
for( time_point i = start; i < end; i += 1_hours ) {
ret += std::min( 1_hours, end - i ) / 1_hours * get_hourly_rotpoints_at_temp( g->get_temperature( location ) ) * 1_turns;
}
return ret;
}
// if on- or above-ground it uses progressive weather-determined temperatures at location
const auto &wgen = g->get_cur_weather_gen();
for( time_point i = start; i < end; i += 1_hours ) {
w_point w = wgen.get_weather( location, i, g->get_seed() );
Expand Down Expand Up @@ -728,7 +728,7 @@ int get_local_windpower(double windpower, const oter_id &omter, bool sheltered)
}

bool warm_enough_to_plant() {
return g->get_temperature() >= 50; // semi-appropriate temperature for most plants
return g->get_temperature( g-> u.pos() ) >= 50; // semi-appropriate temperature for most plants
}

///@}