summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-08-10 20:51:23 -0400
committerJesse Luehrs <doy@tozt.net>2014-08-10 21:47:55 -0400
commit3a4a750dde8e1b6ca3a8d030d5ac3cd90ac8d6e7 (patch)
tree02cd8e02d2fe78ac61766c5f539ee1e5a47577f9
parentfb5353a63a8a65241ae7ba2613916135af3ee201 (diff)
downloadcrawl-ref-3a4a750dde8e1b6ca3a8d030d5ac3cd90ac8d6e7.tar.gz
crawl-ref-3a4a750dde8e1b6ca3a8d030d5ac3cd90ac8d6e7.zip
load job from chardump
-rw-r--r--crawl-ref/source/wiz-you.cc37
1 files changed, 36 insertions, 1 deletions
diff --git a/crawl-ref/source/wiz-you.cc b/crawl-ref/source/wiz-you.cc
index 1b49b4e282..d3fb284902 100644
--- a/crawl-ref/source/wiz-you.cc
+++ b/crawl-ref/source/wiz-you.cc
@@ -18,6 +18,7 @@
#include "food.h"
#include "godprayer.h"
#include "godwrath.h"
+#include "jobs.h"
#include "libutil.h"
#include "macro.h"
#include "message.h"
@@ -51,6 +52,34 @@ static void _swap_equip(equipment_type a, equipment_type b)
you.melded.set(b, tmp);
}
+static job_type _find_job(string job)
+{
+ string spec = lowercase_string(job);
+
+ job_type j = JOB_UNKNOWN;
+
+ for (int i = 0; i < NUM_JOBS; ++i)
+ {
+ const job_type ji = static_cast<job_type>(i);
+ const string name = lowercase_string(get_job_name(ji));
+
+ string::size_type pos = name.find(spec);
+ if (pos != string::npos)
+ {
+ if (pos == 0)
+ {
+ // We prefer prefixes over partial matches.
+ j = ji;
+ break;
+ }
+ else
+ j = ji;
+ }
+ }
+
+ return j;
+}
+
static species_type _find_species(string species)
{
string spec = lowercase_string(species);
@@ -231,6 +260,12 @@ static void _wizard_change_species_to(species_type sp)
redraw_screen();
}
+static void _wizard_change_job_to(job_type job)
+{
+ you.char_class = job;
+ you.class_name = get_job_name(job);
+}
+
void wizard_change_species()
{
char specs[80];
@@ -1162,7 +1197,7 @@ static bool _chardump_check_char(const vector<string> &tokens)
string role = tokens[k-1].substr(0, tokens[k-1].length() - 1);
_wizard_change_species_to(_find_species(race));
- // XXX role
+ _wizard_change_job_to(_find_job(role));
return true;
}
}