Attached Files |
fraction_success_patch.txt [^] (11,973 bytes) 2012-01-06 04:43 [Show Content] [Hide Content]diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index 614471c..88ffd5f 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -2834,10 +2834,10 @@ int choose_ability_menu(const std::vector<talent>& talents)
abil_menu.set_highlighter(NULL);
abil_menu.set_title(
new MenuEntry(" Ability - do what? "
- "Cost Success"));
+ "Cost Failure"));
abil_menu.set_title(
new MenuEntry(" Ability - describe what? "
- "Cost Success"), false);
+ "Cost Failure"), false);
abil_menu.set_flags(MF_SINGLESELECT | MF_ANYPRINTABLE
| MF_ALWAYS_SHOW_MORE);
@@ -2933,12 +2933,15 @@ int choose_ability_menu(const std::vector<talent>& talents)
static std::string _describe_talent(const talent& tal)
{
ASSERT(tal.which != ABIL_NON_ABILITY);
+
+ char* failure = failure_rate_to_string(tal.fail);
std::ostringstream desc;
desc << std::left
<< chop_string(ability_name(tal.which), 32)
<< chop_string(make_cost_description(tal.which), 27)
- << chop_string(failure_rate_to_string(tal.fail), 10);
+ << chop_string(failure, 10);
+ free(failure);
return desc.str();
}
diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc
index c105868..195fa32 100644
--- a/crawl-ref/source/chardump.cc
+++ b/crawl-ref/source/chardump.cc
@@ -961,7 +961,7 @@ static void _sdump_spells(dump_params &par)
text += "You " + verb + " the following spells:\n\n";
- text += " Your Spells Type Power Success Level Hunger" "\n";
+ text += " Your Spells Type Power Failure Level Hunger" "\n";
for (int j = 0; j < 52; j++)
{
@@ -997,7 +997,9 @@ static void _sdump_spells(dump_params &par)
spell_line = chop_string(spell_line, 54);
- spell_line += failure_rate_to_string(spell_fail(spell));
+ char* failure = failure_rate_to_string(spell_fail(spell));
+ spell_line += failure;
+ free(failure);
spell_line = chop_string(spell_line, 66);
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 9f4a22f..084e189 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -2921,12 +2921,14 @@ static void _append_spell_stats(const spell_type spell,
else
{
const std::string schools = spell_schools_string(spell);
+ char* failure = failure_rate_to_string(spell_fail(spell));
snprintf(info, INFO_SIZE,
"\nLevel: %d School%s: %s (%s)",
spell_difficulty(spell),
schools.find("/") != std::string::npos ? "s" : "",
schools.c_str(),
- failure_rate_to_string(spell_fail(spell)));
+ failure);
+ free(failure);
}
description += info;
description += "\n\nPower : ";
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index 9a2088b..5a1b657 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -946,7 +946,7 @@ static spell_type _choose_mem_spell(spell_list &spells,
{
MenuEntry* me =
new MenuEntry(" Spells Type "
- " Success Level",
+ " Failure Level",
MEL_ITEM);
me->colour = BLUE;
spell_menu.add_entry(me);
@@ -954,12 +954,12 @@ static spell_type _choose_mem_spell(spell_list &spells,
#else
spell_menu.set_title(
new MenuEntry(" Spells (Memorisation) Type "
- " Success Level",
+ " Failure Level",
MEL_TITLE));
spell_menu.set_title(
new MenuEntry(" Spells (Description) Type "
- " Success Level",
+ " Failure Level",
MEL_TITLE), false);
#endif
@@ -1040,8 +1040,10 @@ static spell_type _choose_mem_spell(spell_list &spells,
if (so_far < 60)
desc << std::string(60 - so_far, ' ');
- desc << chop_string(failure_rate_to_string(spell_fail(spell)), 12)
+ char* failure = failure_rate_to_string(spell_fail(spell));
+ desc << chop_string(failure, 12)
<< spell_difficulty(spell);
+ free(failure);
desc << "</" << colour_to_str(colour) << ">";
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index 0698a2a..b9cd351 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -109,9 +109,11 @@ static std::string _spell_base_description(spell_type spell, bool viewing)
desc << std::string(60 - so_far, ' ');
// spell fail rate, level
- desc << chop_string(failure_rate_to_string(spell_fail(spell)), 12)
+ char* failure = failure_rate_to_string(spell_fail(spell));
+ desc << chop_string(failure, 12)
<< spell_difficulty(spell);
desc << "</" << colour_to_str(highlight) <<">";
+ free(failure);
return desc.str();
}
@@ -164,7 +166,7 @@ int list_spells(bool toggle_with_I, bool viewing, bool allow_preselect,
ToggleableMenuEntry* me =
new ToggleableMenuEntry(
" Your Spells Type "
- " Success Level",
+ " Failure Level",
" Your Spells Power "
"Range Hunger Level",
MEL_ITEM);
@@ -175,7 +177,7 @@ int list_spells(bool toggle_with_I, bool viewing, bool allow_preselect,
spell_menu.set_title(
new ToggleableMenuEntry(
" Your Spells Type "
- " Success Level",
+ " Failure Level",
" Your Spells Power "
"Range Hunger Level",
MEL_TITLE));
@@ -1685,18 +1687,95 @@ static spret_type _do_cast(spell_type spell, int powc,
return (SPRET_SUCCESS);
}
-const char* failure_rate_to_string(int fail)
+/*
+ _tetrahedral_number: returns the nth tetrahedral number.
+ Called only by get_true_fail_rate.
+*/
+static int _tetrahedral_number(int n)
{
- return (fail == 100) ? "Useless" : // 0% success chance
- (fail > 77) ? "Terrible" : // 0-5%
- (fail > 59) ? "Very Poor" : // 5-30%
- (fail > 50) ? "Poor" : // 30-50%
- (fail > 40) ? "Fair" : // 50-70%
- (fail > 35) ? "Good" : // 70-80%
- (fail > 28) ? "Very Good" : // 80-90%
- (fail > 22) ? "Great" : // 90-95%
- (fail > 0) ? "Excellent" // 95-100%
- : "Perfect"; // 100%
+ return n * (n+1) * (n+2) / 6;
+}
+
+/*
+ get_true_fail_rate: Takes the raw failure to-beat number
+ and converts it to actual failure rate percentage for display.
+ Should probably use more constants, though I doubt the spell
+ success algorithms will really change *that* much.
+ Called only by failure_rate_to_string.
+*/
+double get_true_fail_rate(int raw_fail)
+{
+ //Three d100 rolls. Need average to be less than raw_fail.
+ //Fun with tetrahedral numbers!
+
+ int target = raw_fail * 3;
+
+ if(target <= 100)
+ {
+ return (double) _tetrahedral_number(target)/1030301;
+ }
+ if(target < 200)
+ {
+ //PIE: the negative term takes the maximum of 100 into
+ //consideration. Note that only one term can exceed 100 in this case,
+ //which is why this works.
+ return (double) (_tetrahedral_number(target) - 3*_tetrahedral_number(target-100))/1030301;
+ }
+ //Target is between 201 and 300 inclusive. Note that finding the number of ways
+ //you can go below, say, 207 is equivalent to finding the number of ways you
+ //can go >= 208... which is equal to the number of ways to go below
+ //300 - 207 = 93.
+ return (double) (1030301 - _tetrahedral_number(300 - target))/1030301;
+
+}
+
+//Converts the raw failure to-beat number into a more intuitive string.
+//Note that this char[] is allocated on the heap, so anything calling
+//this function will also need ot call free()!
+char* failure_rate_to_string(int fail)
+{
+ char *buffer = (char *)malloc(9);
+ if(fail == 100)
+ {
+ sprintf(buffer, "Always");
+ return buffer;
+ }
+ else if(fail > 65)
+ {
+ sprintf(buffer, "High");
+ return buffer;
+ }
+ else if(fail > 62)
+ {
+ sprintf(buffer, "4/5");
+ return buffer;
+ }
+ else if(fail > 57)
+ {
+ sprintf(buffer, "3/4");
+ return buffer;
+ }
+ else if(fail > 50)
+ {
+ sprintf(buffer, "2/3");
+ return buffer;
+ }
+ else if(fail == 0)
+ {
+ sprintf(buffer, "Never");
+ return buffer;
+ }
+
+ int fail_denominator = (int) (1/get_true_fail_rate(fail));
+
+ if(fail_denominator > 1000)
+ {
+ sprintf(buffer, "< 1/1000");
+ return buffer;
+ }
+
+ sprintf(buffer, "1/%d", fail_denominator);
+ return buffer;
}
const char* spell_hunger_string(spell_type spell, bool rod)
diff --git a/crawl-ref/source/spl-cast.h b/crawl-ref/source/spl-cast.h
index ea0663b..2ef1471 100644
--- a/crawl-ref/source/spl-cast.h
+++ b/crawl-ref/source/spl-cast.h
@@ -73,7 +73,7 @@ void do_cast_spell_cmd(bool force);
spret_type your_spells(spell_type spell, int powc = 0, bool allow_fail = true,
bool check_range = true);
-const char* failure_rate_to_string(int fail);
+char* failure_rate_to_string(int fail);
std::string spell_power_string(spell_type spell, bool rod = false);
std::string spell_range_string(spell_type spell, bool rod = false);
diff --git a/crawl-ref/source/tilereg-mem.cc b/crawl-ref/source/tilereg-mem.cc
index 31e92a4..8840b8d 100644
--- a/crawl-ref/source/tilereg-mem.cc
+++ b/crawl-ref/source/tilereg-mem.cc
@@ -40,12 +40,14 @@ void MemoriseRegion::draw_tag()
return;
const spell_type spell = (spell_type) idx;
+ char* failure = failure_rate_to_string(spell_fail(spell));
std::string desc = make_stringf("%s (%s) %d/%d spell slot%s",
spell_title(spell),
- failure_rate_to_string(spell_fail(spell)),
+ failure,
spell_levels_required(spell),
player_spell_levels(),
spell_levels_required(spell) > 1 ? "s" : "");
+ free(failure);
draw_desc(desc.c_str());
}
diff --git a/crawl-ref/source/tilereg-spl.cc b/crawl-ref/source/tilereg-spl.cc
index 81cc43a..1acf90d 100644
--- a/crawl-ref/source/tilereg-spl.cc
+++ b/crawl-ref/source/tilereg-spl.cc
@@ -43,10 +43,12 @@ void SpellRegion::draw_tag()
return;
const spell_type spell = (spell_type) idx;
+ char* failure = failure_rate_to_string(spell_fail(spell));
std::string desc = make_stringf("%d MP %s (%s)",
spell_difficulty(spell),
spell_title(spell),
- failure_rate_to_string(spell_fail(spell)));
+ failure);
+ free(failure);
draw_desc(desc.c_str());
}
fail_2.png [^] (81,146 bytes) 2012-01-11 05:35
fail_1.png [^] (21,740 bytes) 2012-01-11 05:35
|