Skip to content

Commit

Permalink
Implement inattentive trait: inability to see if creatures surroundin…
Browse files Browse the repository at this point in the history
…g player sees player (#53597)

* Implement unattentive trait: inability to see if creatures surrounding you see you

* Update data/json/mutations/mutations.json

Co-authored-by: Anton Burmistrov <[email protected]>

* Update src/game.cpp

Co-authored-by: Anton Burmistrov <[email protected]>

* Update src/monster.cpp

Co-authored-by: Anton Burmistrov <[email protected]>

* Update src/monster.cpp

Co-authored-by: Anton Burmistrov <[email protected]>

* Update character.cpp

* per github comments

* Improve UI (MATT_UNKNOWN for creature list; no visibility indicator in tileset); reformat with help of astyle

* Removing "Unknown" category from print cycle

* Also remove hostility status from examination window in list of creatures

* Only sort by attitude if player knows the attitude

* reformat things according to checks

* fixes according to github checks

* Update src/game.cpp

Co-authored-by: Anton Burmistrov <[email protected]>

Co-authored-by: Anton Burmistrov <[email protected]>
Co-authored-by: Maleclypse <[email protected]>
Co-authored-by: David Seguin <[email protected]>
  • Loading branch information
4 people authored Apr 18, 2022
1 parent 1d42081 commit 4743f58
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
10 changes: 10 additions & 0 deletions data/json/mutations/mutations.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@
"category": [ "ELFA" ],
"hearing_modifier": 1.75
},
{
"type": "mutation",
"id": "INATTENTIVE",
"name": { "str": "Inattentive" },
"points": -2,
"starting_trait": true,
"description": "You never paid attention to your surroundings and specifically to people around you. You can't judge intent of critters you see.",
"purifiable": false,
"valid": false
},
{
"type": "mutation",
"id": "OUTDOORSMAN",
Expand Down
3 changes: 2 additions & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
static const efftype_id effect_ridden( "ridden" );

static const itype_id itype_corpse( "corpse" );
static const trait_id trait_INATTENTIVE( "INATTENTIVE" );

static const std::string ITEM_HIGHLIGHT( "highlight_item" );
static const std::string ZOMBIE_REVIVAL_INDICATOR( "zombie_revival_indicator" );
Expand Down Expand Up @@ -3564,7 +3565,7 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3

if( result && !is_player ) {
std::string draw_id = "overlay_" + Creature::attitude_raw_string( attitude );
if( sees_player ) {
if( sees_player && !you.has_trait( trait_INATTENTIVE ) ) {
draw_id += "_sees_player";
}
if( tileset_ptr->find_tile_type( draw_id ) ) {
Expand Down
1 change: 1 addition & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9621,6 +9621,7 @@ Creature::Attitude Character::attitude_to( const Creature &other ) const
case MATT_ATTACK:
return Attitude::HOSTILE;
case MATT_NULL:
case MATT_UNKNOWN:
case NUM_MONSTER_ATTITUDES:
break;
}
Expand Down
40 changes: 27 additions & 13 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ static const string_id<npc_template> npc_template_cyborg_rescued( "cyborg_rescue
static const trait_id trait_BADKNEES( "BADKNEES" );
static const trait_id trait_CENOBITE( "CENOBITE" );
static const trait_id trait_ILLITERATE( "ILLITERATE" );
static const trait_id trait_INATTENTIVE( "INATTENTIVE" );
static const trait_id trait_INFIMMUNE( "INFIMMUNE" );
static const trait_id trait_INFRESIST( "INFRESIST" );
static const trait_id trait_LEG_TENT_BRACE( "LEG_TENT_BRACE" );
Expand Down Expand Up @@ -7416,11 +7417,16 @@ void game::list_items_monsters()
}

std::sort( mons.begin(), mons.end(), [&]( const Creature * lhs, const Creature * rhs ) {
const Creature::Attitude att_lhs = lhs->attitude_to( u );
const Creature::Attitude att_rhs = rhs->attitude_to( u );
if( !u.has_trait( trait_INATTENTIVE ) ) {
const Creature::Attitude att_lhs = lhs->attitude_to( u );
const Creature::Attitude att_rhs = rhs->attitude_to( u );

return att_lhs < att_rhs || ( att_lhs == att_rhs
&& rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
} else { // Sort just by ditance if player has inattentive trait
return ( rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
}

return att_lhs < att_rhs || ( att_lhs == att_rhs
&& rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
} );

// If the current list is empty, switch to the non-empty list
Expand Down Expand Up @@ -8007,12 +8013,14 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list

// first integer is the row the attitude category string is printed in the menu
std::map<int, Creature::Attitude> mSortCategory;

for( int i = 0, last_attitude = -1; i < static_cast<int>( monster_list.size() ); i++ ) {
const Creature::Attitude attitude = monster_list[i]->attitude_to( u );
if( static_cast<int>( attitude ) != last_attitude ) {
mSortCategory[i + mSortCategory.size()] = attitude;
last_attitude = static_cast<int>( attitude );
const bool player_knows = !u.has_trait( trait_INATTENTIVE );
if( player_knows ) {
for( int i = 0, last_attitude = -1; i < static_cast<int>( monster_list.size() ); i++ ) {
const Creature::Attitude attitude = monster_list[i]->attitude_to( u );
if( static_cast<int>( attitude ) != last_attitude ) {
mSortCategory[i + mSortCategory.size()] = attitude;
last_attitude = static_cast<int>( attitude );
}
}
}

Expand Down Expand Up @@ -8062,7 +8070,8 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list

const int endY = std::min<int>( iMaxRows - 1, iMenuSize );
for( int y = 0; y < endY; ++y ) {
if( CatSortIter != mSortCategory.cend() ) {

if( player_knows && CatSortIter != mSortCategory.cend() ) {
const int iCurPos = iStartPos + y;
const int iCatPos = CatSortIter->first;
if( iCurPos == iCatPos ) {
Expand All @@ -8073,11 +8082,12 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
continue;
}
}

// select current monster
Creature *critter = monster_list[iCurMon];
const bool selected = iCurMon == iActive;
++iCurMon;
if( critter->sees( u ) ) {
if( critter->sees( u ) && player_knows ) {
mvwprintz( w_monsters, point( 0, y ), c_yellow, "!" );
}
bool is_npc = false;
Expand Down Expand Up @@ -8134,7 +8144,11 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
sText = npc_attitude_name( p->get_attitude() );
color = p->symbol_color();
}
mvwprintz( w_monsters, point( width - 25, y ), color, sText );
if( !player_knows ) {
sText = _( "Unknown" );
color = c_yellow;
}
mvwprintz( w_monsters, point( width - 19, y ), color, sText );

const int mon_dist = rl_dist( u.pos(), critter->pos() );
const int numd = mon_dist > 999 ? 4 :
Expand Down
20 changes: 17 additions & 3 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static const trait_id trait_ANIMALEMPATH( "ANIMALEMPATH" );
static const trait_id trait_ANIMALEMPATH2( "ANIMALEMPATH2" );
static const trait_id trait_BEE( "BEE" );
static const trait_id trait_FLOWERS( "FLOWERS" );
static const trait_id trait_INATTENTIVE( "INATTENTIVE" );
static const trait_id trait_KILLER( "KILLER" );
static const trait_id trait_MYCUS_FRIEND( "MYCUS_FRIEND" );
static const trait_id trait_PHEROMONE_AMPHIBIAN( "PHEROMONE_AMPHIBIAN" );
Expand Down Expand Up @@ -178,6 +179,7 @@ static const std::map<monster_attitude, std::pair<std::string, color_id>> attitu
{monster_attitude::MATT_FOLLOW, {translate_marker( "Tracking." ), def_c_yellow}},
{monster_attitude::MATT_IGNORE, {translate_marker( "Ignoring." ), def_c_light_gray}},
{monster_attitude::MATT_ATTACK, {translate_marker( "Hostile!" ), def_c_red}},
{monster_attitude::MATT_UNKNOWN, {translate_marker( "Unknown" ), def_c_yellow}}, //Should only be used for UI.
{monster_attitude::MATT_NULL, {translate_marker( "BUG: Behavior unnamed." ), def_h_red}},
};

Expand Down Expand Up @@ -698,15 +700,26 @@ int monster::print_info( const catacurses::window &w, int vStart, int vLines, in
oss << "<color_h_white>" << get_effect_status() << "</color>";
vStart += fold_and_print( w, point( column, vStart ), max_width, c_white, oss.str() );

Character &pc = get_player_character();
bool sees_player = sees( pc );
const bool player_knows = !pc.has_trait( trait_INATTENTIVE );

// Hostility indicator on the second line.
std::pair<std::string, nc_color> att = get_attitude();
mvwprintz( w, point( column, vStart++ ), att.second, att.first );
if( player_knows ) {
mvwprintz( w, point( column, vStart++ ), att.second, att.first );
} else {
mvwprintz( w, point( column, vStart++ ), all_colors.get( attitude_names.at( MATT_UNKNOWN ).second ),
attitude_names.at( MATT_UNKNOWN ).first );
}

// Awareness indicator in the third line.
bool sees_player = sees( get_player_character() );
std::string senses_str = sees_player ? _( "Can see to your current location" ) :
_( "Can't see to your current location" );
vStart += fold_and_print( w, point( column, vStart ), max_width, sees_player ? c_red : c_green,
senses_str = !player_knows ? _( "You have no idea what is it doing" ) :
senses_str;
vStart += fold_and_print( w, point( column, vStart ), max_width, player_knows &&
sees_player ? c_red : c_green,
senses_str );

const std::string speed_desc = speed_description(
Expand Down Expand Up @@ -1196,6 +1209,7 @@ Creature::Attitude monster::attitude_to( const Creature &other ) const
case MATT_ATTACK:
return Attitude::HOSTILE;
case MATT_NULL:
case MATT_UNKNOWN:
case NUM_MONSTER_ATTITUDES:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ enum monster_attitude {
MATT_IGNORE,
MATT_FOLLOW,
MATT_ATTACK,
MATT_UNKNOWN,
NUM_MONSTER_ATTITUDES
};

Expand Down
1 change: 1 addition & 0 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,7 @@ Creature::Attitude npc::attitude_to( const Creature &other ) const
case MATT_ATTACK:
return Attitude::HOSTILE;
case MATT_NULL:
case MATT_UNKNOWN:
case NUM_MONSTER_ATTITUDES:
break;
}
Expand Down

0 comments on commit 4743f58

Please sign in to comment.