Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memorize memory duration once a turn. #27441

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11602,14 +11602,22 @@ long player::get_memorized_symbol( const tripoint &p ) const

size_t player::max_memorized_tiles() const
{
if( has_active_bionic( bio_memory ) ) {
return SEEX * SEEY * 20000; // 5000 overmap tiles
} else if( has_trait( trait_FORGETFUL ) ) {
return SEEX * SEEY * 200; // 50 overmap tiles
} else if( has_trait( trait_GOODMEMORY ) ) {
return SEEX * SEEY * 800; // 200 overmap tiles
// Only check traits once a turn since this is called a huge number of times.
static time_point current_turn = calendar::before_time_starts;
static size_t current_max = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that it's unnecessary to make these static, and they would more logically be member variables. For example, when you save a game and load a different one, it's still using the state from the previous game. Which could (if you got very unlucky) cause that new game's player to forget a bunch of map memory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh you're right, there is a tiny collision risk.

if( current_turn != calendar::turn ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the idea behind, but I don't get how it would work with current implementation as this conditional expression would always be true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because of the static? It's kind of magical how it works.
static type varname = expression;
Is only evaluated the first time the function is invoked, after that varname has a persistent value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is like: initialize current_turn once with calendar::before_time_starts and current_max with 0 on first call to max_memorized_tiles, skip initialization on subsequent calls, right?

current_turn = calendar::turn;
if( has_active_bionic( bio_memory ) ) {
current_max = SEEX * SEEY * 20000; // 5000 overmap tiles
} else if( has_trait( trait_FORGETFUL ) ) {
current_max = SEEX * SEEY * 200; // 50 overmap tiles
} else if( has_trait( trait_GOODMEMORY ) ) {
current_max = SEEX * SEEY * 800; // 200 overmap tiles
} else {
current_max = SEEX * SEEY * 400; // 100 overmap tiles
}
}
return SEEX * SEEY * 400; // 100 overmap tiles
return current_max;
}

bool player::sees( const tripoint &t, bool ) const
Expand Down