Skip to content

Commit

Permalink
Fix case where skill is greater than level max (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
stridera authored Jan 25, 2024
1 parent 82a107a commit 9911ed7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
1 change: 0 additions & 1 deletion include/act.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ long xp_percentage(CharData *ch);
const char *exp_message(CharData *ch);
const char *exp_bar(CharData *ch, int length, int gradations, int sub_gradations, bool color);
const char *cooldown_bar(CharData *ch, int cooldown, int length, int gradations, bool color);
const char *proficiency_message(int proficiency);
const char *hp_regen_message(int regen);
const char *focus_message(int focus);

Expand Down
29 changes: 3 additions & 26 deletions src/act.informative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3474,29 +3474,6 @@ ACMD(do_score) {
show_active_spells(ch, tch);
}

const char *proficiency_message(int proficiency) {
if (proficiency == 0)
return "(not learned)";
else if (proficiency <= 100)
return "(awful)";
else if (proficiency <= 200)
return "(bad)";
else if (proficiency <= 400)
return "(poor)";
else if (proficiency <= 550)
return "(average)";
else if (proficiency <= 700)
return "(fair)";
else if (proficiency <= 800)
return "(good)";
else if (proficiency <= 850)
return "(very good)";
else if (proficiency <= 999)
return "(superb)";
else
return "(mastered)";
}

#define MAX_CIRCLE 14
#define MAX_SPELLS_PER_CIRCLE 30

Expand Down Expand Up @@ -3574,7 +3551,6 @@ ACMD(do_spells) {
return;
}


/* Collect and count the spells known by the victim. */

memset(&circle_spells, 0, sizeof(circle_spells));
Expand All @@ -3583,7 +3559,8 @@ ACMD(do_spells) {
i = skill_sort_info[k];
if (!IS_SPELL(i))
continue;
if (skills[i].min_level[GET_CLASS(tch)] < LVL_IMMORT && GET_SKILL(tch, i) > 0 && skills[i].min_level[GET_CLASS(tch)] <= skills[i].min_race_level[GET_RACE(tch)]) {
if (skills[i].min_level[GET_CLASS(tch)] < LVL_IMMORT && GET_SKILL(tch, i) > 0 &&
skills[i].min_level[GET_CLASS(tch)] <= skills[i].min_race_level[GET_RACE(tch)]) {
circle = (skills[i].min_level[GET_CLASS(tch)] - 1) / 8;
for (j = 0; circle_spells[circle][j] && j < MAX_SPELLS_PER_CIRCLE && circle < max_vis_circle; ++j)
;
Expand Down Expand Up @@ -3813,7 +3790,7 @@ ACMD(do_skills) {
continue;

/* Show exact skill numbers of mobs when switched. */
result += fmt::format("{:<22} {:<15} ", skills[i].name, proficiency_message(GET_ISKILL(tch, i)));
result += fmt::format("{:<22} ", skills[i].name);
if (POSSESSED(tch) && GET_LEVEL(POSSESSOR(tch)) >= LVL_IMMORT) {
result += fmt::format("[{:4d}]", GET_ISKILL(tch, i));
} else {
Expand Down
18 changes: 8 additions & 10 deletions src/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,26 @@ bool matches_start(std::string_view lhs, std::string_view rhs) {
// return !std::ranges::search(haystack_low, needle_low).empty();
// }

std::string progress_bar(int current, int wall, int max) {
std::string progress_bar(int current, int level_max, int max) {
double percentage = static_cast<double>(current) / max * 100;
double level_percentage = static_cast<double>(current) / wall * 100;

if (level_percentage < percentage || max < wall)
return "";
double level_percentage = static_cast<double>(current) / level_max * 100;
level_percentage = std::clamp(level_percentage, 0.0, 100.0);

// Define progress bar lengths
const int bar_length = 40;
const int bar_length = 50;

if (current >= max) {
return fmt::format("[{:#^{}}]", " MASTERED ", bar_length);
}

// Calculate filled portion for each bar
int fill = static_cast<int>(percentage / 100 * bar_length);
int wall_position = static_cast<int>(level_percentage / 100 * bar_length);
int level_fill = static_cast<int>(level_percentage / 100 * bar_length);

// Create progress bars
std::string progress_bar = "[" + std::string(fill, '#') + std::string(wall_position - fill, '=');
if (bar_length - wall_position > 0)
progress_bar += std::string(bar_length - wall_position, '-');
std::string progress_bar = "[" + std::string(fill, '#') + std::string(level_fill - fill, '=');
if (bar_length - level_fill > 0)
progress_bar += std::string(bar_length - level_fill, '-');
progress_bar += "]";

return progress_bar;
Expand Down

0 comments on commit 9911ed7

Please sign in to comment.