@@ -897,27 +897,47 @@ static units::temperature highest_temp_on_day( time_point &base_date, const trip
897
897
return highest_temp;
898
898
}
899
899
900
- bool warm_enough_to_plant ( const tripoint_bub_ms &pos, const itype_id &it )
900
+ static bool has_sunlight_access ( const tripoint_bub_ms &pos )
901
901
{
902
- const tripoint_abs_ms abs = get_map ().get_abs ( pos );
903
- const tripoint_abs_omt target_omt = project_to<coords::omt>( abs );
904
- return warm_enough_to_plant ( target_omt, it );
902
+ tripoint_bub_ms checked_pnt = pos;
903
+ const map &here = get_map ();
904
+ while ( checked_pnt.z () < OVERMAP_HEIGHT ) {
905
+ const tripoint_bub_ms pnt_above = {checked_pnt.xy (), checked_pnt.z () + 1 };
906
+ const bool should_check_above = pnt_above.z () < OVERMAP_HEIGHT;
907
+ // If checking above would take us outside of game bounds, just assume that it's all open air up there.
908
+ const bool transparent_roof = should_check_above ?
909
+ here.is_outside ( pnt_above ) && here.has_flag_ter ( " TRANSPARENT" , pnt_above ) :
910
+ true ;
911
+ if ( !here.is_outside ( checked_pnt ) || !transparent_roof ) {
912
+ return false ;
913
+ }
914
+ checked_pnt = pnt_above;
915
+ }
916
+ return true ;
905
917
}
906
918
907
- bool warm_enough_to_plant ( const tripoint_abs_omt &pos, const itype_id &it )
919
+ ret_val< void > warm_enough_to_plant ( const tripoint_bub_ms &pos, const itype_id &it )
908
920
{
909
921
std::map<time_point, units::temperature> planting_times;
910
- bool okay_to_plant = true ;
922
+
923
+ if ( !has_sunlight_access ( pos ) ) {
924
+ return ret_val<void >::make_failure ( _ ( " Plants need sunlight to grow! You can't plant there." ) );
925
+ }
926
+
927
+ const tripoint_abs_ms abs = get_map ().get_abs ( pos );
928
+ const tripoint_abs_omt checked_omt = project_to<coords::omt>( abs );
929
+
911
930
const std::vector<std::pair<flag_id, time_duration>> &growth_stages = it->seed ->get_growth_stages ();
912
931
// we will iterate a copy of the weather into the future to see if they'll be plantable then as well.
913
932
const weather_generator weather_gen = get_weather ().get_cur_weather_gen ();
914
933
// initialize the first...
915
934
time_point check_date = calendar::turn;
916
- planting_times[check_date] = highest_temp_on_day ( check_date, pos , weather_gen );
935
+ planting_times[check_date] = highest_temp_on_day ( check_date, checked_omt , weather_gen );
917
936
for ( const auto &pair : growth_stages ) {
918
937
// TODO: Replace epoch checks with data from a farmer's almanac
919
938
check_date = check_date + pair.second ;
920
- planting_times[check_date] = highest_temp_on_day ( check_date, pos, weather_gen );
939
+ // The [] operator in std::map inserts an entry if it doesn't already exist.
940
+ planting_times[check_date] = highest_temp_on_day ( check_date, checked_omt, weather_gen );
921
941
}
922
942
for ( const std::pair<const time_point, units::temperature> &pair : planting_times ) {
923
943
// This absolutely needs to be a time point.
@@ -929,11 +949,11 @@ bool warm_enough_to_plant( const tripoint_abs_omt &pos, const itype_id &it )
929
949
add_msg_debug ( debugmode::DF_MAP, " Planting failure! %s needs temperature of %s but found only %s" ,
930
950
it->nname ( 1 ), print_temperature ( it->seed ->get_growth_temp (), 2 ),
931
951
print_temperature ( pair.second , 2 ) );
932
- okay_to_plant = false ;
933
- break ;
952
+ return ret_val< void >:: make_failure (
953
+ _ ( " If you plant now, the cold will kill this plant before it can be harvested! " ) ) ;
934
954
}
935
955
}
936
- return okay_to_plant ;
956
+ return ret_val< void >:: make_success () ;
937
957
}
938
958
939
959
weather_manager::weather_manager ()
0 commit comments