-
Notifications
You must be signed in to change notification settings - Fork 280
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
feat(port): Add book binder with many QoL #2170
Conversation
…ok binder from selection
If it passes clang-tidy checks, this is ready for review |
that's great. one more idea: maybe it could also extract recipies from a book without requiring pen and paper, at the cost of destroying the book |
Would it be worth it though? You would lose the ability to potentially read the book, for you and your followers. |
|
* | ||
* @return true if the recipe was added, false if it is a duplicate | ||
*/ | ||
bool eipc_recipe_add( const recipe_id &recipe_id ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed just like eipc_recipe_remove
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work, eipc_recipe_add is used in iuse.cpp and activity_actor.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both could be extracted into item_functions.h
(declarations) + item_functions.cpp
(definitions), that's a file specifically for new functions that use public members of item class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The binder is working in-game, so functional part is good, this is more code style nitpicks and commentary.
"id": "napkin", | ||
"name": { "str": "napkin" }, | ||
"category": "spare_parts", | ||
"weight": "3 g", | ||
"color": "white", | ||
"comestible_type": "FOOD", | ||
"symbol": "`", | ||
"description": "A piece of paper. Can be used for fires.", | ||
"description": "A napkin. Can be used for fires.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is adding this new item intentional? It looks like a merge conflict.
There are no references to napkin
anywhere, it won't spawn in game world.
|
||
void bookbinder_copy_activity_actor::do_turn( player_activity &, Character &p ) | ||
{ | ||
if( character_funcs::fine_detail_vision_mod( p ) > 4.0f ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function has been added for this, no need for magic numbers anymore
if( character_funcs::fine_detail_vision_mod( p ) > 4.0f ) { | |
if( !character_funcs::can_see_fine_details( p ) ) { |
|
||
player->consume_tools( writing_tools, pages ); | ||
} else { | ||
debugmsg( "Recipe book already has '%s' recipe when it should not.", rec_id.str() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast here is done automatically
debugmsg( "Recipe book already has '%s' recipe when it should not.", rec_id.str() ); | |
debugmsg( "Recipe book already has '%s' recipe when it should not.", rec_id ); |
return 0; | ||
} | ||
|
||
if( character_funcs::fine_detail_vision_mod( *p ) > 4.0f ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if( character_funcs::fine_detail_vision_mod( *p ) > 4.0f ) { | |
if( !character_funcs::can_see_fine_details( *p ) ) { |
std::string current_recipes = it.get_var( "EIPC_RECIPES" ); | ||
if( current_recipes.empty() ) { | ||
return false; | ||
} else if( current_recipes.find( "," + recipe_id.str() + "," ) != std::string::npos ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern
std::string current_recipes = it.get_var( "EIPC_RECIPES" );
. . .
check if current_recipes.find( "," + recipe_id.str() + "," ) != std::string::npos is true
repeats multiple times thorough the PR and should ideally be extracted into a dedicated function (say, bool eipc_recipe_check( const item &it, const recipe_id &recipe_id )
, but that's more of a nit towards original implementation.
p->add_msg_if_player( m_info, _ | ||
( string_format( "You already know some recipes. You remove %d pages from the book binder.", | ||
total_pages_removed ) ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_()
must receive either a string literal or a string specifically marked for translation via translate_marker()
. Passing it a dynamically generated string won't work.
p->add_msg_if_player( m_info, _ | |
( string_format( "You already know some recipes. You remove %d pages from the book binder.", | |
total_pages_removed ) ) ); | |
p->add_msg_if_player( m_info, string_format( _( "You already know some recipes. You remove %d pages from the book binder." ), | |
total_pages_removed ) ); |
|
||
|
||
std::vector<const recipe *> not_learnt_recipes; | ||
std::string old_recipes = binder->get_var( "EIPC_RECIPES" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused store (the variable gets assigned here, but nothing uses the value, and a few lines down it get re-assigned again with new value).
std::string old_recipes = binder->get_var( "EIPC_RECIPES" ); |
} | ||
|
||
// only keep not learnt recipes and those that are not already in the book | ||
old_recipes = binder->get_var( "EIPC_RECIPES" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(unused store part 2)
old_recipes = binder->get_var( "EIPC_RECIPES" ); | |
std::string old_recipes = binder->get_var( "EIPC_RECIPES" ); |
|
||
for( const recipe *rec : not_learnt_recipes ) { | ||
|
||
const int pages = 1 + rec->difficulty / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern should also have been extracted into a function, say
int calc_recipe_binder_usage( const recipe_id& r ) {
return 1 + r->difficulty / 2;
}
std::vector<const recipe *> recipe_subset::get_recipes() | ||
{ | ||
std::vector<const recipe *> ret( recipes.begin(), recipes.end() ); | ||
return ret; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really hate how all functions here straight up allocate vectors on each call.
is this PR still worked on? |
Same here, open it up again, if you are willing to work on it. |
Summary
SUMMARY: Features "Add book binder with many QoL"
Purpose of change
Being able to copy and keep the most interesting recipes on you, even if they were above your level when you copied them.
Also, it was one of the (many) PR to port before
CleverRaven/Cataclysm-DDA#46304
and
CleverRaven/Cataclysm-DDA#49408 (the final boss)
Describe the solution
Port CleverRaven/Cataclysm-DDA#44399
and CleverRaven/Cataclysm-DDA#50367
Changes from the original PR:
when you copy a new recipe, the old recipes that you already know are removed with a message. This means you'll be able to keep the same book binder for the entire game.
the PR added some randomness to the spawn of paper, I didn't port it
you could only copy recipes that match your skill level, I removed the requirement
the pen can be used to write too (it has some charges now)
the copying time has been greatly reduced (it was quite long before, probably aligned with DDA pace)
lots of change to the book binder item
Describe alternatives you've considered
Not porting it, and port the e-book one directly (but way too many changes)
Porting the e-book one in this PR too (too big)
Testing