diff options
author | Raphael Langella <raphael.langella@gmail.com> | 2014-01-09 11:25:41 +0100 |
---|---|---|
committer | Raphael Langella <raphael.langella@gmail.com> | 2014-01-10 01:24:48 +0100 |
commit | a735ae8250517f301fbf828a4f4cbc4924df3adb (patch) | |
tree | 4344103852ca3e4b7b37470652111a8a7e6673a0 /crawl-ref/source/wiz-fsim.cc | |
parent | ea225a9039777c11305c36afed526213fa6a0c74 (diff) | |
download | crawl-ref-a735ae8250517f301fbf828a4f4cbc4924df3adb.tar.gz crawl-ref-a735ae8250517f301fbf828a4f4cbc4924df3adb.zip |
Generate the items in fsim_kit if they are not in the player's inventory.
Diffstat (limited to 'crawl-ref/source/wiz-fsim.cc')
-rw-r--r-- | crawl-ref/source/wiz-fsim.cc | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/crawl-ref/source/wiz-fsim.cc b/crawl-ref/source/wiz-fsim.cc index b05d06caa0..d000098cb2 100644 --- a/crawl-ref/source/wiz-fsim.cc +++ b/crawl-ref/source/wiz-fsim.cc @@ -20,6 +20,7 @@ #include "items.h" #include "item_use.h" #include "libutil.h" +#include "makeitem.h" #include "message.h" #include "mon-place.h" #include "mgen_data.h" @@ -158,8 +159,33 @@ static void _write_mon(FILE * o, monster &mon) mon.ev); } -static bool _fsim_kit_equip(const string &kit) +static bool _equip_weapon(const string &weapon, bool &abort) { + for (int i = 0; i < ENDOFPACK; ++i) + { + if (!you.inv[i].defined()) + continue; + + if (you.inv[i].name(DESC_PLAIN).find(weapon) != string::npos) + { + if (i != you.equip[EQ_WEAPON]) + { + wield_weapon(true, i, false); + if (i != you.equip[EQ_WEAPON]) + { + abort = true; + return true; + } + } + return true; + } + } + return false; +} + +static bool _fsim_kit_equip(const string &kit, string &error) +{ + bool abort = false; string::size_type ammo_div = kit.find("/"); string weapon = kit; string missile; @@ -173,21 +199,21 @@ static bool _fsim_kit_equip(const string &kit) if (!weapon.empty()) { - for (int i = 0; i < ENDOFPACK; ++i) + if (!_equip_weapon(weapon, abort)) { - if (!you.inv[i].defined()) - continue; + int item = create_item_named("race:none mundane not_cursed ident:all " + weapon, + you.pos(), &error); + if (item == NON_ITEM) + return false; + if (move_item_to_player(item, 1, true, true) <= 0) + return false; + _equip_weapon(weapon, abort); + } - if (you.inv[i].name(DESC_PLAIN).find(weapon) != string::npos) - { - if (i != you.equip[EQ_WEAPON]) - { - wield_weapon(true, i, false); - if (i != you.equip[EQ_WEAPON]) - return false; - } - break; - } + if (abort) + { + error = "Cannot weild weapon"; + return false; } } else if (you.weapon()) @@ -643,7 +669,8 @@ void wizard_fight_sim(bool double_scale) else for (int i = 0, size = Options.fsim_kit.size(); i < size; ++i) { - if (_fsim_kit_equip(Options.fsim_kit[i])) + string error; + if (_fsim_kit_equip(Options.fsim_kit[i], error)) { _write_weapon(o); fsim_proc(o, mon, defense); @@ -652,6 +679,8 @@ void wizard_fight_sim(bool double_scale) else { mprf("Aborting sim on %s", Options.fsim_kit[i].c_str()); + if (error != "") + mpr(error.c_str()); break; } } |