Skip to content

Commit

Permalink
Research view: improve the tech goal text
Browse files Browse the repository at this point in the history
The research view has a text with the number of bulbs and turns needed
to achieve the current tech goal. This text had issues in multiple
situations:

* When no goal was set, it was showing "(0 steps - 0 bulbs - never)";
* It was never taking tech leak into account.

Solve these issues by considering the current research as the implicit
goal if none is set, and taking the actual cost of the current research
into account. The label still does not take tech leak into account for
the following techs, even if the player knows that the cost will be
lower (e.g. through diplomacy).
  • Loading branch information
lmoureaux committed Jul 22, 2023
1 parent 8c4c918 commit a5398bd
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions client/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,35 +917,49 @@ const QString get_science_target_text()
const QString get_science_goal_text(Tech_type_id goal)
{
const struct research *research = research_get(client_player());
int steps = research_goal_unknown_techs(research, goal);
int bulbs_needed = research_goal_bulbs_required(research, goal);
int turns;
int perturn = get_bulbs_per_turn(nullptr, nullptr, nullptr);
QString str, buf1, buf2, buf3;

if (!research) {
return QStringLiteral("-");
}

if (!valid_advance_by_number(goal)) {
// No goal - act as if it were the current research
goal = research->researching;
}

int steps = research_goal_unknown_techs(research, goal);
int bulbs_needed = research_goal_bulbs_required(research, goal);
int perturn = get_bulbs_per_turn(nullptr, nullptr, nullptr);

if (research_goal_tech_req(research, goal, research->researching)
|| research->researching == goal) {
bulbs_needed -= research->bulbs_researched;
// Adjust for the actual cost of the current tech (e.g. due to tech leak)
bulbs_needed -=
research_goal_bulbs_required(research, research->researching);
bulbs_needed += research->client.researching_cost;
}

int turns = -1;
if (bulbs_needed < perturn) {
turns = 1;
} else if (perturn > 0) {
turns = (bulbs_needed + perturn - 1) / perturn;
}

QString buf1, buf2, buf3;
buf1 =
QString(PL_("%1 step", "%1 steps", steps)).arg(QString::number(steps));
buf2 = QString(PL_("%1 bulb", "%1 bulbs", bulbs_needed))
.arg(QString::number(bulbs_needed));
if (perturn > 0) {
turns = (bulbs_needed + perturn - 1) / perturn;

if (turns >= 0) {
buf3 = QString(PL_("%1 turn", "%1 turns", turns))
.arg(QString::number(turns));
} else {
buf3 = QString(_("never"));
}
str += QStringLiteral("(%1 - %2 - %3)").arg(buf1, buf2, buf3);

return str.trimmed();
return QStringLiteral("(%1 - %2 - %3)").arg(buf1, buf2, buf3);
}

/**
Expand Down

0 comments on commit a5398bd

Please sign in to comment.