Skip to content

Commit

Permalink
Fix tech dialog text when we have more bulbs than needed
Browse files Browse the repository at this point in the history
The price of a tech can change due to tech leak. In this case it isn't
researched immediately and the player may see 123/100 bulbs. Account for
this when calculating how many turns are left to discover the tech.
  • Loading branch information
lmoureaux authored and jwrober committed Jul 23, 2023
1 parent f19d6a7 commit f39a1f4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions client/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,14 @@ int get_bulbs_per_turn(int *pours, bool *pteam, int *ptheirs)
*/
int turns_to_research_done(const struct research *presearch, int per_turn)
{
if (per_turn > 0) {
return ceil(static_cast<double>(presearch->client.researching_cost
- presearch->bulbs_researched)
/ per_turn);
// Can be negative if the tech cost went down due to tech leak.
int missing =
presearch->client.researching_cost - presearch->bulbs_researched;
if (missing <= per_turn) {
// Tech will be researched at TC.
return 1;
} else if (per_turn > 0) {
return std::ceil(static_cast<double>(missing) / per_turn);
} else {
return -1;
}
Expand Down

0 comments on commit f39a1f4

Please sign in to comment.