Skip to content

Commit

Permalink
Use dedicated function of trap class instead of checking translated n…
Browse files Browse the repository at this point in the history
…ame for emptiness
  • Loading branch information
ZhilkinSerg committed Jun 12, 2019
1 parent 17e5458 commit 23cd5ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
18 changes: 12 additions & 6 deletions data/json/traps.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "temple_toggle"
"action": "temple_toggle",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -410,7 +411,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "glow"
"action": "glow",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -421,7 +423,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "hum"
"action": "hum",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -432,7 +435,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "shadow"
"action": "shadow",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -443,7 +447,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "drain"
"action": "drain",
"always_invisible": true
},
{
"type": "trap",
Expand All @@ -454,7 +459,8 @@
"visibility": 99,
"avoidance": 99,
"difficulty": 99,
"action": "snake"
"action": "snake",
"always_invisible": true
},
{
"type": "trap",
Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2932,8 +2932,8 @@ void player::search_surroundings()
if( !sees( tp ) ) {
continue;
}
if( tr.name().empty() || tr.can_see( tp, *this ) ) {
// Already seen, or has no name -> can never be seen
if( tr.is_always_invisible() || tr.can_see( tp, *this ) ) {
// Already seen, or can never be seen
continue;
}
// Chance to detect traps we haven't yet seen.
Expand Down
4 changes: 2 additions & 2 deletions src/trap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ void trap::load( JsonObject &jo, const std::string & )
act = trap_function_from_string( jo.get_string( "action" ) );

optional( jo, was_loaded, "benign", benign, false );
optional( jo, was_loaded, "always_invisible", always_invisible, false );
optional( jo, was_loaded, "funnel_radius", funnel_radius_mm, 0 );
assign( jo, "trigger_weight", trigger_weight );
optional( jo, was_loaded, "drops", components );
}

std::string trap::name() const
{
// trap names can be empty, those are special always invisible traps. See player::search_surroundings
return name_.empty() ? name_ : _( name_ );
return _( name_ );
}

void trap::reset()
Expand Down
7 changes: 7 additions & 0 deletions src/trap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct trap {
int avoidance; // 0 to ??, affects avoidance
int difficulty; // 0 to ??, difficulty of assembly & disassembly
bool benign = false;
bool always_invisible = false;
trap_function act;
std::string name_;
/**
Expand All @@ -86,6 +87,12 @@ struct trap {
std::vector<itype_id> components; // For disassembly?
public:
std::string name() const;
/**
* There are special always invisible traps. See player::search_surroundings
*/
bool is_always_invisible() const {
return always_invisible;
}
/**
* How easy it is to spot the trap. Smaller values means it's easier to spot.
*/
Expand Down

0 comments on commit 23cd5ce

Please sign in to comment.