std::string map_data_common_t::extended_description() const { std::stringstream ss; ss << "<header>" << string_format( _( "That is a %s." ), name().c_str() ) << "</header>" << '\n'; ss << description << std::endl; bool has_any_harvest = std::any_of( harvest_by_season.begin(), harvest_by_season.end(), []( const harvest_id & hv ) { return !hv.obj().empty(); } ); if( has_any_harvest ) { ss << "--" << std::endl; int player_skill = g->u.get_skill_level( skill_survival ); ss << _( "You could harvest the following things from it:" ) << std::endl; // Group them by identical ids to avoid repeating same blocks of data // First, invert the mapping: season->id to id->seasons std::multimap<harvest_id, season_type> identical_harvest; for( size_t season = SPRING; season <= WINTER; season++ ) { const auto &hv = harvest_by_season[ season ]; if( hv.obj().empty() ) { continue; } identical_harvest.insert( std::make_pair( hv, static_cast<season_type>( season ) ) ); } // Now print them in order of seasons // @todo: Highlight current season for( size_t season = SPRING; season <= WINTER; season++ ) { const auto range = identical_harvest.equal_range( harvest_by_season[ season ] ); if( range.first == range.second ) { continue; } // List the seasons first ss << enumerate_as_string( range.first, range.second, []( const std::pair<harvest_id, season_type> &pr ) { if( pr.second == season_of_year( calendar::turn ) ) { return "<good>" + calendar::name_season( pr.second ) + "</good>"; } return "<dark>" + calendar::name_season( pr.second ) + "</dark>"; } ); ss << ":" << std::endl; // List the drops // They actually describe what player can get from it now, so it isn't spoily // @todo: Allow spoily listing of everything ss << range.first->first.obj().describe( player_skill ) << std::endl; // Remove the range from the multimap so that it isn't listed twice identical_harvest.erase( range.first, range.second ); } ss << std::endl; } return replace_colors( ss.str() ); }
std::string to_string( const time_point &p ) { const int year = to_turns<int>( p - calendar::time_of_cataclysm ) / to_turns<int> ( calendar::year_length() ) + 1; const std::string time = to_string_time_of_day( p ); if( calendar::eternal_season() ) { const int day = to_days<int>( time_past_new_year( p ) ); //~ 1 is the year, 2 is the day (of the *year*), 3 is the time of the day in its usual format return string_format( _( "Year %1$d, day %2$d %3$s" ), year, day, time ); } else { const int day = day_of_season<int>( p ); //~ 1 is the year, 2 is the season name, 3 is the day (of the season), 4 is the time of the day in its usual format return string_format( _( "Year %1$d, %2$s, day %3$d %4$s" ), year, calendar::name_season( season_of_year( p ) ), day, time ); } }
void weather_effect::glare( bool snowglare ) { season_type season = season_of_year( calendar::turn ); if( is_player_outside() && g->is_in_sunlight( g->u.pos() ) && !g->u.in_sleep_state() && !g->u.worn_with_flag( "SUN_GLASSES" ) && !g->u.is_blind() && !snowglare && !g->u.has_bionic( bionic_id( "bio_sunglasses" ) ) ) { if( !g->u.has_effect( effect_glare ) ) { if( g->u.has_trait( trait_CEPH_VISION ) ) { g->u.add_env_effect( effect_glare, bp_eyes, 2, 4_turns ); } else { g->u.add_env_effect( effect_glare, bp_eyes, 2, 2_turns ); } } else { if( g->u.has_trait( trait_CEPH_VISION ) ) { g->u.add_env_effect( effect_glare, bp_eyes, 2, 2_turns ); } else { g->u.add_env_effect( effect_glare, bp_eyes, 2, 1_turns ); } } } if( is_player_outside() && !g->u.in_sleep_state() && season == WINTER && !g->u.worn_with_flag( "SUN_GLASSES" ) && !g->u.is_blind() && snowglare && !g->u.has_bionic( bionic_id( "bio_sunglasses" ) ) ) { if( !g->u.has_effect( effect_snow_glare ) ) { if( g->u.has_trait( trait_CEPH_VISION ) ) { g->u.add_env_effect( effect_snow_glare, bp_eyes, 2, 4_turns ); } else { g->u.add_env_effect( effect_snow_glare, bp_eyes, 2, 2_turns ); } } else { if( g->u.has_trait( trait_CEPH_VISION ) ) { g->u.add_env_effect( effect_snow_glare, bp_eyes, 2, 2_turns ); } else { g->u.add_env_effect( effect_snow_glare, bp_eyes, 2, 1_turns ); } } } }
//Quantity is adjusted directly as a side effect of this function MonsterGroupResult MonsterGroupManager::GetResultFromGroup( const mongroup_id &group_name, int *quantity ) { auto &group = GetUpgradedMonsterGroup( group_name ); int spawn_chance = rng( 1, group.freq_total ); //Default 1000 unless specified //Our spawn details specify, by default, a single instance of the default monster MonsterGroupResult spawn_details = MonsterGroupResult( group.defaultMonster, 1 ); bool monster_found = false; // Loop invariant values const time_point sunset = calendar::turn.sunset(); const time_point sunrise = calendar::turn.sunrise(); const season_type season = season_of_year( calendar::turn ); // Step through spawn definitions from the monster group until one is found or for( auto it = group.monsters.begin(); it != group.monsters.end() && !monster_found; ++it ) { // There's a lot of conditions to work through to see if this spawn definition is valid bool valid_entry = true; //Insure that the time is not before the spawn first appears or after it stops appearing valid_entry = valid_entry && ( calendar::time_of_cataclysm + it->starts < calendar::turn ); valid_entry = valid_entry && ( it->lasts_forever() || calendar::time_of_cataclysm + it->ends > calendar::turn ); std::vector<std::pair<time_point, time_point> > valid_times_of_day; bool season_limited = false; bool season_matched = false; //Collect the various spawn conditions, and then insure they are met appropriately for( auto &elem : it->conditions ) { //Collect valid time of day ranges if( elem == "DAY" || elem == "NIGHT" || elem == "DUSK" || elem == "DAWN" ) { if( elem == "DAY" ) { valid_times_of_day.push_back( std::make_pair( sunrise, sunset ) ); } else if( elem == "NIGHT" ) { valid_times_of_day.push_back( std::make_pair( sunset, sunrise ) ); } else if( elem == "DUSK" ) { valid_times_of_day.push_back( std::make_pair( sunset - 1_hours, sunset + 1_hours ) ); } else if( elem == "DAWN" ) { valid_times_of_day.push_back( std::make_pair( sunrise - 1_hours, sunrise + 1_hours ) ); } } //If we have any seasons listed, we know to limit by season, and if any season matches this season, we are good to spawn if( elem == "SUMMER" || elem == "WINTER" || elem == "SPRING" || elem == "AUTUMN" ) { season_limited = true; if( ( season == SUMMER && elem == "SUMMER" ) || ( season == WINTER && elem == "WINTER" ) || ( season == SPRING && elem == "SPRING" ) || ( season == AUTUMN && elem == "AUTUMN" ) ) { season_matched = true; } } } //Make sure the current time of day is within one of the valid time ranges for this spawn bool is_valid_time_of_day = false; if( valid_times_of_day.empty() ) { //Then it can spawn whenever, since no times were defined is_valid_time_of_day = true; } else { //Otherwise, it's valid if it matches any of the times of day for( auto &elem : valid_times_of_day ) { if( calendar::turn > elem.first && calendar::turn < elem.second ) { is_valid_time_of_day = true; } } } if( !is_valid_time_of_day ) { valid_entry = false; } //If we are limited by season, make sure we matched a season if( season_limited && !season_matched ) { valid_entry = false; } //If the entry was valid, check to see if we actually spawn it if( valid_entry ) { //If the monsters frequency is greater than the spawn_chance, select this spawn rule if( it->frequency >= spawn_chance ) { if( it->pack_maximum > 1 ) { spawn_details = MonsterGroupResult( it->name, rng( it->pack_minimum, it->pack_maximum ) ); } else { spawn_details = MonsterGroupResult( it->name, 1 ); } //And if a quantity pointer with remaining value was passed, will modify the external value as a side effect //We will reduce it by the spawn rule's cost multiplier if( quantity ) { *quantity -= std::max( 1, it->cost_multiplier * spawn_details.pack_size ); } monster_found = true; //Otherwise, subtract the frequency from spawn result for the next loop around } else { spawn_chance -= it->frequency; } } } // Force quantity to decrement regardless of whether we found a monster. if( quantity && !monster_found ) { ( *quantity )--; } return spawn_details; }
const harvest_id &map_data_common_t::get_harvest() const { return harvest_by_season[season_of_year( calendar::turn )]; }
nc_color map_data_common_t::color() const { return color_[season_of_year( calendar::turn )]; }
long map_data_common_t::symbol() const { return symbol_[season_of_year( calendar::turn )]; }