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

Increase precision of craft progress to better support long/slow crafts #29633

Merged
merged 3 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,7 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
}

// item_counter represents the percent progress relative to the base batch time
// stored precise to 2 decimal places ( e.g. 67.32 percent would be stored as 6732 )
// stored precise to 5 decimal places ( e.g. 67.32 percent would be stored as 6732000 )

// Base moves for batch size with no speed modifier or assistants
// Must ensure >= 1 so we don't divide by 0;
Expand All @@ -2683,13 +2683,14 @@ void activity_handlers::craft_do_turn( player_activity *act, player *p )
// Delta progress in moves adjusted for current crafting speed
const double delta_progress = p->get_moves() * base_total_moves / cur_total_moves;
// Current progress in moves
const double current_progress = craft->item_counter * base_total_moves / 10000.0 + delta_progress;
const double current_progress = craft->item_counter * base_total_moves / 10000000.0 +
delta_progress;
// Current progress as a percent of base_total_moves to 2 decimal places
craft->item_counter = current_progress / base_total_moves * 10000.0;
craft->item_counter = round( current_progress / base_total_moves * 10000000.0 );
p->set_moves( 0 );

// if item_counter has reached 100% or more
if( craft->item_counter >= 10000 ) {
if( craft->item_counter >= 10000000 ) {
p->cancel_activity();
item craft_copy = p->i_rem( craft );
p->complete_craft( craft_copy );
Expand Down
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ std::string item::info( std::vector<iteminfo> &info, const iteminfo_query *parts
} else {
if( is_craft() ) {
const std::string desc = _( "This is an in progress %s. It is %d percent complete." );
const int percent_progress = item_counter / 100;
const int percent_progress = item_counter / 100000;
info.push_back( iteminfo( "DESCRIPTION", string_format( desc,
making->result_name(),
percent_progress ) ) );
Expand Down Expand Up @@ -2989,7 +2989,7 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t
if( charges > 1 ) {
ret << " (" << charges << ")";
}
const int percent_progress = item_counter / 100;
const int percent_progress = item_counter / 100000;
ret << " (" << percent_progress << "%)";
maintext = ret.str();
} else if( contents.size() == 1 ) {
Expand Down