Skip to content

Commit

Permalink
Show number of variants for starting locations (#39331)
Browse files Browse the repository at this point in the history
* Show number of variants for starting locations
* Fix bug with selection of first starting location entry in Evacuee scenario
  • Loading branch information
ZhilkinSerg authored Apr 8, 2020
1 parent 1271f22 commit 2e5563a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,11 @@ tab_direction set_scenario( avatar &u, points_left &points,

mvwprintz( w_location, point_zero, COL_HEADER, _( "Scenario Location:" ) );
wprintz( w_location, c_light_gray, ( "\n" ) );
wprintz( w_location, c_light_gray, sorted_scens[cur_id]->start_name() );
wprintz( w_location, c_light_gray,
string_format( _( "%s (%d locations, %d variants)" ),
sorted_scens[cur_id]->start_name(),
sorted_scens[cur_id]->start_location_count(),
sorted_scens[cur_id]->start_location_targets_count() ) );

mvwprintz( w_flags, point_zero, COL_HEADER, _( "Scenario Flags:" ) );
wprintz( w_flags, c_light_gray, ( "\n" ) );
Expand Down Expand Up @@ -2215,9 +2219,10 @@ tab_direction set_scenario( avatar &u, points_left &points,
tab_direction set_description( avatar &you, const bool allow_reroll,
points_left &points )
{

static constexpr int RANDOM_START_LOC_ENTRY = INT_MIN;
const std::string RANDOM_START_LOC_TEXT = _( "* Random location *" );
const std::string RANDOM_START_LOC_TEXT_TEMPLATE =
_( "<color_red>* Random location *</color> (<color_white>%d</color> variants)" );
const std::string START_LOC_TEXT_TEMPLATE = _( "%s (<color_white>%d</color> variants)" );

ui_adaptor ui;
catacurses::window w;
Expand Down Expand Up @@ -2266,12 +2271,15 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
uilist select_location;
select_location.text = _( "Select a starting location." );
int offset = 1;
uilist_entry entry_random_start_location( RANDOM_START_LOC_ENTRY, true, -1, RANDOM_START_LOC_TEXT );
entry_random_start_location.text_color = c_red;
const std::string random_start_location_text = string_format( RANDOM_START_LOC_TEXT_TEMPLATE,
g->scen->start_location_targets_count() );
uilist_entry entry_random_start_location( RANDOM_START_LOC_ENTRY, true, -1,
random_start_location_text );
select_location.entries.emplace_back( entry_random_start_location );
for( const auto &loc : start_locations::get_all() ) {
if( g->scen->allowed_start( loc.id ) ) {
uilist_entry entry( loc.id.get_cid().to_i(), true, -1, loc.name() );
uilist_entry entry( loc.id.get_cid().to_i(), true, -1,
string_format( START_LOC_TEXT_TEMPLATE, loc.name(), loc.targets_count() ) );

select_location.entries.emplace_back( entry );

Expand Down Expand Up @@ -2441,7 +2449,10 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
// ::find will return empty location if id was not found. Debug msg will be printed too.
mvwprintz( w_location, point( prompt_offset + utf8_width( _( "Starting location:" ) ) - 9, 0 ),
you.random_start_location ? c_red : c_light_green,
you.random_start_location ? RANDOM_START_LOC_TEXT : you.start_location.obj().name() );
you.random_start_location ? remove_color_tags( random_start_location_text ) :
string_format( remove_color_tags( START_LOC_TEXT_TEMPLATE ),
you.start_location.obj().name(),
you.start_location.obj().targets_count() ) );
wrefresh( w_location );

werase( w_scenario );
Expand Down Expand Up @@ -2515,7 +2526,7 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
select_location.query();
if( select_location.ret == RANDOM_START_LOC_ENTRY ) {
you.random_start_location = true;
} else if( select_location.ret >= 1 ) {
} else if( select_location.ret >= 0 ) {
for( const auto &loc : start_locations::get_all() ) {
if( loc.id.get_cid().to_i() == select_location.ret ) {
you.random_start_location = false;
Expand Down
16 changes: 16 additions & 0 deletions src/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "profession.h"
#include "translations.h"
#include "rng.h"
#include "start_location.h"

namespace
{
Expand Down Expand Up @@ -385,6 +386,21 @@ std::string scenario::start_name() const
return _start_name.translated();
}


int scenario::start_location_count() const
{
return _allowed_locs.size();
}

int scenario::start_location_targets_count() const
{
int cnt = 0;
for( const auto &sloc : _allowed_locs ) {
cnt += sloc.obj().targets_count();
}
return cnt;
}

bool scenario::traitquery( const trait_id &trait ) const
{
return _allowed_traits.count( trait ) != 0 || is_locked_trait( trait ) ||
Expand Down
2 changes: 2 additions & 0 deletions src/scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class scenario
start_location_id start_location() const;
start_location_id random_start_location() const;
std::string start_name() const;
int start_location_count() const;
int start_location_targets_count() const;

const profession *weighted_random_profession() const;
std::vector<string_id<profession>> permitted_professions() const;
Expand Down
5 changes: 5 additions & 0 deletions src/start_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ std::string start_location::name() const
return _name.translated();
}

int start_location::targets_count() const
{
return _omt_types.size();
}

std::pair<std::string, ot_match_type> start_location::random_target() const
{
return random_entry( _omt_types );
Expand Down
1 change: 1 addition & 0 deletions src/start_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class start_location
void check() const;

std::string name() const;
int targets_count() const;
std::pair<std::string, ot_match_type> random_target() const;
const std::set<std::string> &flags() const;

Expand Down

0 comments on commit 2e5563a

Please sign in to comment.