Skip to content

Commit

Permalink
Follower / Faction camp summary menu and migrate to overmap (CleverRa…
Browse files Browse the repository at this point in the history
…ven#28498)

* added NPC summary window
added ability to chat to NPC from menu
added mission description to NPC list
added camp labels and camp names
moved camps to overmap
get camp info works from overmapbuffer now
made the om_camps accept pointers
added mission description to camp menu
  • Loading branch information
davidpwbrown authored and kevingranade committed Mar 14, 2019
1 parent a868b99 commit 46e2ec7
Show file tree
Hide file tree
Showing 25 changed files with 826 additions and 114 deletions.
83 changes: 69 additions & 14 deletions src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include "string_formatter.h"
#include "translations.h"
#include "enums.h"
#include "game.h"
#include "item_group.h"
#include "map.h"
#include "map_iterator.h"
#include "mapbuffer.h"
#include "mapdata.h"
#include "messages.h"
#include "overmap.h"
#include "overmap_ui.h"
#include "overmapbuffer.h"
Expand All @@ -24,6 +26,7 @@
#include "recipe_groups.h"
#include "requirements.h"
#include "skill.h"
#include "string_input_popup.h"
#include "faction_camp.h"

static const std::string base_dir = "[B]";
Expand Down Expand Up @@ -54,16 +57,15 @@ basecamp::basecamp(): bb_pos( tripoint_zero )
{
}

basecamp::basecamp( const std::string &name_, const tripoint &pos_ ): name( name_ ), pos( pos_ )
basecamp::basecamp( const std::string &name_, const tripoint &omt_pos_ ): name( name_ ),
omt_pos( omt_pos_ )
{
}

basecamp::basecamp( const std::string &name_, const tripoint &bb_pos_, const tripoint &pos_,
std::vector<tripoint> sort_points_,
std::vector<std::string> directions_,
std::map<std::string, expansion_data> expansions_ ):
sort_points( sort_points_ ), directions( directions_ ), name( name_ ),
pos( pos_ ), bb_pos( bb_pos_ ), expansions( expansions_ )
basecamp::basecamp( const std::string &name_, const tripoint &bb_pos_,
std::vector<tripoint> sort_points_, std::vector<std::string> directions_,
std::map<std::string, expansion_data> expansions_ ): sort_points( sort_points_ ),
directions( directions_ ), name( name_ ), bb_pos( bb_pos_ ), expansions( expansions_ )
{
}

Expand Down Expand Up @@ -93,32 +95,63 @@ void basecamp::add_expansion( const std::string &terrain, const tripoint &new_po
return;
}

const std::string dir = talk_function::om_simple_dir( pos, new_pos );
const std::string dir = talk_function::om_simple_dir( omt_pos, new_pos );
expansions[ dir ] = parse_expansion( terrain, new_pos );
directions.push_back( dir );
}

void basecamp::define_camp( npc &p )
{
pos = p.global_omt_location();
query_new_name();
omt_pos = p.global_omt_location();
sort_points = p.companion_mission_points;
// purging the regions guarantees all entries will start with faction_base_
for( std::pair<std::string, tripoint> expansion : talk_function::om_building_region( pos, 1,
for( std::pair<std::string, tripoint> expansion : talk_function::om_building_region( omt_pos, 1,
true ) ) {
add_expansion( expansion.first, expansion.second );
}
const std::string om_cur = overmap_buffer.ter( pos ).id().c_str();
const std::string om_cur = overmap_buffer.ter( omt_pos ).id().c_str();
if( om_cur.find( prefix ) == std::string::npos ) {
expansion_data e;
e.type = "camp";
e.cur_level = 0;
e.pos = pos;
e.pos = omt_pos;
expansions[ base_dir ] = e;
} else {
expansions[ base_dir ] = parse_expansion( om_cur, pos );
expansions[ base_dir ] = parse_expansion( om_cur, omt_pos );
}
}

/// Returns the description for the recipe of the next building @ref bldg
std::string basecamp::om_upgrade_description( const std::string &bldg, bool trunc )
{
const recipe &making = recipe_id( bldg ).obj();
const inventory &total_inv = g->u.crafting_inventory();

std::vector<std::string> component_print_buffer;
const int pane = FULL_SCREEN_WIDTH;
const auto tools = making.requirements().get_folded_tools_list( pane, c_white, total_inv, 1 );
const auto comps = making.requirements().get_folded_components_list( pane, c_white, total_inv, 1 );
component_print_buffer.insert( component_print_buffer.end(), tools.begin(), tools.end() );
component_print_buffer.insert( component_print_buffer.end(), comps.begin(), comps.end() );

std::string comp;
for( auto &elem : component_print_buffer ) {
comp = comp + elem + "\n";
}
time_duration duration = time_duration::from_turns( making.time / 100 );
if( trunc ) {
comp = string_format( _( "Notes:\n%s\n\nSkill used: %s\n%s\n" ),
making.description, making.skill_used.obj().name(), comp );
} else {
comp = string_format( _( "Notes:\n%s\n\nSkill used: %s\n"
"Difficulty: %d\n%s \nRisk: None\nTime: %s\n" ),
making.description, making.skill_used.obj().name(),
making.difficulty, comp, to_string( duration ) );
}
return comp;
}

// upgrade levels
bool basecamp::has_level( const std::string &type, int min_level, const std::string &dir ) const
{
Expand Down Expand Up @@ -204,7 +237,7 @@ void basecamp::reset_camp_workers()
camp_workers.clear();
for( const auto &elem : overmap_buffer.get_companion_mission_npcs() ) {
npc_companion_mission c_mission = elem->get_companion_mission();
if( c_mission.position == pos && c_mission.role_id == "FACTION_CAMP" ) {
if( c_mission.position == omt_pos && c_mission.role_id == "FACTION_CAMP" ) {
camp_workers.push_back( elem );
}
}
Expand All @@ -224,6 +257,28 @@ comp_list basecamp::get_mission_workers( const std::string &mission_id, bool con
return available;
}

void basecamp::query_new_name()
{
std::string camp_name;
string_input_popup popup;
popup.title( string_format( _( "Name this camp" ) ) )
.width( 40 )
.text( "" )
.max_length( 25 )
.query();
if( popup.canceled() || popup.text() == "" ) {
camp_name = "faction_camp";
} else {
camp_name = popup.text();
}
name = camp_name;
}

void basecamp::set_name( const std::string &new_name )
{
name = new_name;
}

// display names
std::string basecamp::expansion_tab( const std::string &dir ) const
{
Expand Down
24 changes: 13 additions & 11 deletions src/basecamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,32 @@ class basecamp
{
public:
basecamp();
basecamp( const std::string &name_, const tripoint &pos_ );
basecamp( const std::string &name_, const tripoint &bb_pos_, const tripoint &pos_,
std::vector<tripoint> sort_points_, std::vector<std::string> directions_,
std::map<std::string, expansion_data> expansions_ );
basecamp( const std::string &name_, const tripoint &omt_pos );
basecamp( const std::string &name_, const tripoint &bb_pos_, std::vector<tripoint> sort_points_,
std::vector<std::string> directions_, std::map<std::string, expansion_data> expansions_ );

inline bool is_valid() const {
return !name.empty() && pos != tripoint_zero;
return !name.empty() && omt_pos != tripoint_zero;
}
inline int board_x() const {
return bb_pos.x;
}
inline int board_y() const {
return bb_pos.y;
}
tripoint camp_pos() const {
return pos;
inline tripoint camp_omt_pos() const {
return omt_pos;
}
inline const std::string &camp_name() const {
return name;
}
std::string board_name() const;
std::vector<tripoint> sort_points;
std::vector<std::string> directions;

std::string name;
//change name of camp
void set_name( const std::string &new_name );
void query_new_name();
void add_expansion( const std::string &terrain, const tripoint &new_pos );
void define_camp( npc &p );

Expand Down Expand Up @@ -120,6 +122,7 @@ class basecamp
const std::vector<item *> &equipment,
const std::string &skill_tested, int skill_level );
void start_upgrade( const std::string &bldg, const std::string &key );
std::string om_upgrade_description( const std::string &bldg, bool trunc );
/// Called when a companion is sent to cut logs
void start_cut_logs();
void start_clearcut();
Expand Down Expand Up @@ -172,9 +175,8 @@ class basecamp
void deserialize( JsonIn &jsin );
void load_data( const std::string &data );
private:
std::string name;
// location of the camp in the overmap
tripoint pos;
// omt pos
tripoint omt_pos;
// location of associated bulletin board
tripoint bb_pos;
std::map<std::string, expansion_data> expansions;
Expand Down
81 changes: 81 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,87 @@ int Character::get_thirst() const
return thirst;
}

std::pair<std::string, nc_color> Character::get_thirst_description() const
{
int thirst = get_thirst();
std::string hydration_string;
nc_color hydration_color = c_white;
if( thirst > 520 ) {
hydration_color = c_light_red;
hydration_string = _( "Parched" );
} else if( thirst > 240 ) {
hydration_color = c_light_red;
hydration_string = _( "Dehydrated" );
} else if( thirst > 80 ) {
hydration_color = c_yellow;
hydration_string = _( "Very thirsty" );
} else if( thirst > 40 ) {
hydration_color = c_yellow;
hydration_string = _( "Thirsty" );
} else if( thirst < -60 ) {
hydration_color = c_green;
hydration_string = _( "Turgid" );
} else if( thirst < -20 ) {
hydration_color = c_green;
hydration_string = _( "Hydrated" );
} else if( thirst < 0 ) {
hydration_color = c_green;
hydration_string = _( "Slaked" );
}
return std::make_pair( hydration_string, hydration_color );
}

std::pair<std::string, nc_color> Character::get_hunger_description() const
{
int hunger = get_hunger();
std::string hunger_string;
nc_color hunger_color = c_white;
if( hunger >= 300 && get_starvation() > 2500 ) {
hunger_color = c_red;
hunger_string = _( "Starving!" );
} else if( hunger >= 300 && get_starvation() > 1100 ) {
hunger_color = c_light_red;
hunger_string = _( "Near starving" );
} else if( hunger > 250 ) {
hunger_color = c_light_red;
hunger_string = _( "Famished" );
} else if( hunger > 100 ) {
hunger_color = c_yellow;
hunger_string = _( "Very hungry" );
} else if( hunger > 40 ) {
hunger_color = c_yellow;
hunger_string = _( "Hungry" );
} else if( hunger < -60 ) {
hunger_color = c_green;
hunger_string = _( "Engorged" );
} else if( hunger < -20 ) {
hunger_color = c_green;
hunger_string = _( "Sated" );
} else if( hunger < 0 ) {
hunger_color = c_green;
hunger_string = _( "Full" );
}
return std::make_pair( hunger_string, hunger_color );
}

std::pair<std::string, nc_color> Character::get_fatigue_description() const
{
int fatigue = get_fatigue();
std::string fatigue_string;
nc_color fatigue_color = c_white;
if( fatigue > EXHAUSTED ) {
fatigue_color = c_red;
fatigue_string = _( "Exhausted" );
} else if( fatigue > DEAD_TIRED ) {
fatigue_color = c_light_red;
fatigue_string = _( "Dead Tired" );
} else if( fatigue > TIRED ) {
fatigue_color = c_yellow;
fatigue_string = _( "Tired" );
}
return std::make_pair( fatigue_string, fatigue_color );
}

void Character::mod_thirst( int nthirst )
{
set_thirst( thirst + nthirst );
Expand Down
3 changes: 3 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class Character : public Creature, public visitable<Character>
virtual int get_hunger() const;
virtual int get_starvation() const;
virtual int get_thirst() const;
virtual std::pair<std::string, nc_color> get_thirst_description() const;
virtual std::pair<std::string, nc_color> get_hunger_description() const;
virtual std::pair<std::string, nc_color> get_fatigue_description() const;
virtual int get_fatigue() const;
virtual int get_sleep_deprivation() const;
virtual int get_stomach_food() const;
Expand Down
Loading

0 comments on commit 46e2ec7

Please sign in to comment.