summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/spl-cast.cc55
-rw-r--r--crawl-ref/source/spl-cast.h8
2 files changed, 46 insertions, 17 deletions
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index e6dfd60263..6d3e80eea5 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -28,6 +28,7 @@
#include "effects.h"
#include "fight.h"
#include "food.h"
+#include "format.h"
#include "it_use2.h"
#include "itemname.h"
#include "itemprop.h"
@@ -170,7 +171,7 @@ static std::string spell_extra_description(spell_type spell)
desc << std::setw(30) << spell_title(spell);
// spell power, hunger level, level
- desc << std::setw(30) << spell_power_string(spell)
+ desc << std::setw(30) << spell_power_string(spell).tostring()
<< std::setw(12) << spell_hunger_string(spell)
<< spell_difficulty(spell);
@@ -3510,24 +3511,46 @@ const char* spell_hunger_string( spell_type spell )
return "Extreme";
}
-const char* spell_power_string( spell_type spell )
+formatted_string spell_power_string(spell_type spell)
+{
+ formatted_string result;
+ result.textcolor(spell_power_colour(spell));
+ const int numbars = spell_power_bars(spell);
+ if ( numbars < 0 )
+ result.cprintf("N/A");
+ else
+ result.cprintf(std::string(numbars, '#'));
+ return result;
+}
+
+int spell_power_colour(spell_type spell)
{
const int powercap = spell_power_cap(spell);
if ( powercap == 0 )
- return "N/A";
+ return DARKGREY;
const int power = calc_spell_power(spell, true);
if ( power >= powercap )
- return "Maximum";
- return
- (power > 100) ? "Enormous" :
- (power > 90) ? "Huge" :
- (power > 80) ? "Massive" :
- (power > 70) ? "Major" :
- (power > 60) ? "Impressive" :
- (power > 50) ? "Reasonable" :
- (power > 40) ? "Moderate" :
- (power > 30) ? "Adequate" :
- (power > 20) ? "Mediocre" :
- (power > 10) ? "Minor"
- : "Negligible";
+ return WHITE;
+ if ( power * 3 < powercap )
+ return RED;
+ if ( power * 3 < powercap * 2 )
+ return YELLOW;
+ return GREEN;
+}
+
+int spell_power_bars( spell_type spell )
+{
+ const int powercap = spell_power_cap(spell);
+ if ( powercap == 0 )
+ return -1;
+ const int power = std::min(calc_spell_power(spell, true), powercap);
+
+ const int breakpoints[] = { 5, 10, 15, 25, 35, 50, 75, 100, 150 };
+ int result = 0;
+ for ( unsigned int i = 0; i < ARRAYSIZE(breakpoints); ++i )
+ {
+ if ( power > breakpoints[i] )
+ ++result;
+ }
+ return result + 1;
}
diff --git a/crawl-ref/source/spl-cast.h b/crawl-ref/source/spl-cast.h
index 488ef1b669..7dad287b23 100644
--- a/crawl-ref/source/spl-cast.h
+++ b/crawl-ref/source/spl-cast.h
@@ -16,6 +16,8 @@
#include "enum.h"
+class formatted_string;
+
char list_spells( void );
int spell_fail( spell_type spell );
int calc_spell_power(spell_type spell, bool apply_intel,
@@ -54,7 +56,11 @@ bool miscast_effect( unsigned int sp_type, int mag_pow, int mag_fail,
int force_effect, const char *cause = NULL );
const char* failure_rate_to_string( int fail );
-const char* spell_power_string( spell_type spell );
+
+int spell_power_colour(spell_type spell);
+int spell_power_bars(spell_type spell);
+formatted_string spell_power_string(spell_type spell);
+
const char* spell_hunger_string( spell_type spell );
#endif