From 3a4a750dde8e1b6ca3a8d030d5ac3cd90ac8d6e7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 10 Aug 2014 20:51:23 -0400 Subject: load job from chardump --- crawl-ref/source/wiz-you.cc | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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(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 &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; } } -- cgit v1.2.3-54-g00ecf