Skip to content

Commit e1513f6

Browse files
authored
Merge pull request #83112 from RenechCDDA/I_fucking_LOVE_stardew_valley
Better feedback on planting failures + plants need sunlight
2 parents d0be893 + b1935ba commit e1513f6

File tree

8 files changed

+60
-26
lines changed

8 files changed

+60
-26
lines changed

src/activity_item_handling.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,8 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
13251325
for( const zone_data &zone : zones ) {
13261326
const plot_options &options = dynamic_cast<const plot_options &>( zone.get_options() );
13271327
const itype_id seed = options.get_seed();
1328+
ret_val<void>can_plant = !seed.is_empty() ?
1329+
warm_enough_to_plant( src_loc, seed ) : ret_val<void>::make_success();
13281330

13291331
if( here.has_flag_furn( ter_furn_flag::TFLAG_GROWTH_OVERGROWN, src_loc ) ) {
13301332
return activity_reason_info::ok( do_activity_reason::NEEDS_CLEARING );
@@ -1362,7 +1364,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
13621364
// If its a farm zone with no specified seed, and we've checked for tilling and harvesting.
13631365
// then it means no further work can be done here
13641366
} else if( !seed.is_empty() &&
1365-
warm_enough_to_plant( src_loc, seed ) &&
1367+
can_plant.success() &&
13661368
here.has_flag_ter_or_furn( seed->seed->required_terrain_flag, src_loc ) ) {
13671369
if( here.has_items( src_loc ) ) {
13681370
return activity_reason_info::fail( do_activity_reason::BLOCKING_TILE );
@@ -1378,6 +1380,10 @@ static activity_reason_info can_do_activity_there( const activity_id &act, Chara
13781380
}
13791381

13801382
} else {
1383+
// Extra, specific messaging returned from warm_enough_to_plant()
1384+
if( !can_plant.success() ) {
1385+
you.add_msg_if_player( can_plant.c_str() );
1386+
}
13811387
// can't plant, till or harvest
13821388
return activity_reason_info::fail( do_activity_reason::ALREADY_DONE );
13831389
}

src/faction_camp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,10 +1216,12 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p
12161216
&plots]() {
12171217
return farm_description( dir, plots, farm_ops::plant );
12181218
} ) );
1219+
const tripoint_abs_omt target_omt = omt_pos + dir;
1220+
const tripoint_bub_ms target_pnt = get_map().get_bub( project_to<coords::ms>( target_omt ) );
12191221
// FIXME/HACK: Always checks buckwheat seeds!
12201222
mission_key.add_start( miss_id,
12211223
name_display_of( miss_id ), entry,
1222-
plots > 0 && warm_enough_to_plant( omt_pos + dir, itype_seed_buckwheat ) );
1224+
plots > 0 && warm_enough_to_plant( target_pnt, itype_seed_buckwheat ).success() );
12231225
}
12241226
if( !npc_list.empty() ) {
12251227
entry = action_of( miss_id.id );

src/iexamine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,8 +2799,9 @@ void iexamine::dirtmound( Character &you, const tripoint_bub_ms &examp )
27992799
}
28002800
const itype_id &seed_id = std::get<0>( seed_entries[seed_index] );
28012801

2802-
if( !warm_enough_to_plant( you.pos_bub(), seed_id ) ) {
2803-
you.add_msg_if_player( m_info, _( "It is too cold to plant that now." ) );
2802+
ret_val<void>can_plant = warm_enough_to_plant( you.pos_bub(), seed_id );
2803+
if( !can_plant.success() ) {
2804+
you.add_msg_if_player( m_info, can_plant.c_str() );
28042805
return;
28052806
}
28062807

src/mission_companion.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "overmap.h"
6161
#include "overmapbuffer.h"
6262
#include "point.h"
63+
#include "ret_val.h"
6364
#include "rng.h"
6465
#include "skill.h"
6566
#include "string_formatter.h"
@@ -1577,8 +1578,9 @@ void talk_function::field_plant( npc &p, const std::string &place )
15771578
}
15781579

15791580
const itype_id &seed_id = seed_types[seed_index];
1580-
if( !warm_enough_to_plant( player_character.pos_bub(), seed_id ) ) {
1581-
popup( _( "It is too cold to plant that now." ) );
1581+
ret_val<void>can_plant = warm_enough_to_plant( player_character.pos_bub(), seed_id );
1582+
if( !can_plant.success() ) {
1583+
popup( can_plant.c_str() );
15821584
return;
15831585
}
15841586
if( item::count_by_charges( seed_id ) ) {

src/vehicle.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6039,11 +6039,14 @@ void vehicle::idle( map &here, bool on_map )
60396039
}
60406040

60416041
// FIXME/HACK: Always checks buckwheat seeds!
6042-
if( !warm_enough_to_plant( player_character.pos_bub( here ), itype_seed_buckwheat ) ) {
6042+
// Returned string intentionally discarded!
6043+
ret_val<void>can_plant = warm_enough_to_plant( player_character.pos_bub(), itype_seed_buckwheat );
6044+
if( !can_plant.success() ) {
60436045
for( int i : planters ) {
60446046
vehicle_part &vp = parts[ i ];
60456047
if( vp.enabled ) {
6046-
add_msg_if_player_sees( pos_bub( here ), _( "The %s's planter turns off due to low temperature." ),
6048+
add_msg_if_player_sees( pos_bub( here ),
6049+
_( "The %s's planter turns off due to unsuitable planting conditions." ),
60476050
name );
60486051
vp.enabled = false;
60496052
}

src/vehicle_part.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,11 @@ bool vehicle::can_enable( map &here, const vehicle_part &pt, bool alert ) const
728728
}
729729

730730
// FIXME/HACK: Always checks buckwheat seeds!
731-
if( pt.info().has_flag( "PLANTER" ) &&
732-
!warm_enough_to_plant( get_player_character().pos_bub(), itype_seed_buckwheat ) ) {
731+
ret_val<void>can_plant = warm_enough_to_plant( get_player_character().pos_bub(),
732+
itype_seed_buckwheat );
733+
if( pt.info().has_flag( "PLANTER" ) && !can_plant.success() ) {
733734
if( alert ) {
734-
add_msg( m_bad, _( "It is too cold to plant most things now." ) );
735+
add_msg( m_bad, can_plant.c_str() );
735736
}
736737
return false;
737738
}

src/weather.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -897,27 +897,47 @@ static units::temperature highest_temp_on_day( time_point &base_date, const trip
897897
return highest_temp;
898898
}
899899

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 )
901901
{
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;
905917
}
906918

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 )
908920
{
909921
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+
911930
const std::vector<std::pair<flag_id, time_duration>> &growth_stages = it->seed->get_growth_stages();
912931
// we will iterate a copy of the weather into the future to see if they'll be plantable then as well.
913932
const weather_generator weather_gen = get_weather().get_cur_weather_gen();
914933
// initialize the first...
915934
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 );
917936
for( const auto &pair : growth_stages ) {
918937
// TODO: Replace epoch checks with data from a farmer's almanac
919938
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 );
921941
}
922942
for( const std::pair<const time_point, units::temperature> &pair : planting_times ) {
923943
// 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 )
929949
add_msg_debug( debugmode::DF_MAP, "Planting failure! %s needs temperature of %s but found only %s",
930950
it->nname( 1 ), print_temperature( it->seed->get_growth_temp(), 2 ),
931951
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!" ) );
934954
}
935955
}
936-
return okay_to_plant;
956+
return ret_val<void>::make_success();
937957
}
938958

939959
weather_manager::weather_manager()

src/weather.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "color.h"
1111
#include "coordinates.h"
1212
#include "pimpl.h"
13+
#include "ret_val.h"
1314
#include "type_id.h"
1415
#include "units.h"
1516
#include "weather_gen.h"
@@ -167,11 +168,9 @@ nc_color get_wind_color( double );
167168

168169
/**
169170
* Is it warm enough to plant seeds? Will it be warm enough during the type's grow periods?
170-
*
171-
* The first overload is simply a forwarding helper.
171+
* Also includes check for whether the tile is exposed to sunlight.
172172
*/
173-
bool warm_enough_to_plant( const tripoint_bub_ms &pos, const itype_id &it );
174-
bool warm_enough_to_plant( const tripoint_abs_omt &pos, const itype_id &it );
173+
ret_val<void> warm_enough_to_plant( const tripoint_bub_ms &pos, const itype_id &it );
175174

176175
bool is_wind_blocker( const tripoint_bub_ms &location );
177176

0 commit comments

Comments
 (0)