diff options
author | Nicholas Feinberg <pleasingfung@gmail.com> | 2014-06-29 15:18:20 -0700 |
---|---|---|
committer | Nicholas Feinberg <pleasingfung@gmail.com> | 2014-06-29 15:18:20 -0700 |
commit | 687e18844208294d4576c7f7a3d428a780cdfd0b (patch) | |
tree | f751f3f387301a9ca74e6ecfa8de3879887f6407 /crawl-ref/source/godabil.cc | |
parent | 4683f236fdd13dc5d67d6bbb98a8e3afce4e7ed9 (diff) | |
download | crawl-ref-687e18844208294d4576c7f7a3d428a780cdfd0b.tar.gz crawl-ref-687e18844208294d4576c7f7a3d428a780cdfd0b.zip |
Tweak beogh gifting code.
Diffstat (limited to 'crawl-ref/source/godabil.cc')
-rw-r--r-- | crawl-ref/source/godabil.cc | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/crawl-ref/source/godabil.cc b/crawl-ref/source/godabil.cc index 7a1b071ec3..7c9beefb39 100644 --- a/crawl-ref/source/godabil.cc +++ b/crawl-ref/source/godabil.cc @@ -1501,7 +1501,7 @@ bool beogh_water_walk() * @param mon the orc in question. * @returns whether you have given the monster a Beogh gift before now. */ -static bool _given_gift(monster* mon) +static bool _given_gift(const monster* mon) { return mon->props.exists(BEOGH_WPN_GIFT_KEY) || mon->props.exists(BEOGH_ARM_GIFT_KEY) @@ -1509,45 +1509,43 @@ static bool _given_gift(monster* mon) } /** - * Allow the player to give an item to a named orcish ally that hasn't - * been given a gift before + * Checks whether the target square holds a valid target for beogh item-gifts. * - * @returns whether an item was given. + * @param pos The position to check for orcs in. + * @param quiet Whether to print messages if the target is invalid. + * @return Whether the player can give an item to an orc in the target + * square. */ -bool beogh_gift_item() +static bool _can_gift_to(const coord_def &pos, bool quiet) { - bolt beam; - dist spd; - - spd.isValid = spell_direction(spd, beam, DIR_TARGET, - TARG_FRIEND, LOS_RADIUS); - - if (!spd.isValid) - return false; - - if (spd.target == you.pos()) + if (pos == you.pos()) { - mpr("You can't give yourself an item!"); - return false; + // I think this should never happen? + if (!quiet) + mpr("You can't give yourself an item!"); + return false; } - monster* mons = monster_at(spd.target); + const monster* mons = monster_at(pos); if (!mons || !mons->visible_to(&you)) { - canned_msg(MSG_NOTHING_THERE); + if (!quiet) + canned_msg(MSG_NOTHING_THERE); return false; } if (!is_orcish_follower(mons)) { - mpr("That's not an orcish ally!"); + if (!quiet) + mpr("That's not an orcish ally!"); return false; } if (!mons->is_named()) { - mpr("That orc has not proved itself worthy of your gift."); + if (!quiet) + mpr("That orc has not proved itself worthy of your gift."); return false; } @@ -1555,10 +1553,43 @@ bool beogh_gift_item() if (_given_gift(mons)) { - mprf("%s has already been given a gift.", monsname); + if (!quiet) + mprf("%s has already been given a gift.", monsname); return false; } + return true; +} + +// used for the targeter. +static bool _can_gift_to(const coord_def &pos) +{ + return _can_gift_to(pos, true); +} + +/** + * Allow the player to give an item to a named orcish ally that hasn't + * been given a gift before + * + * @returns whether an item was given. + */ +bool beogh_gift_item() +{ + bolt beam; + dist spd; + + targetter_smite tgt(&you, LOS_RADIUS, 0, 0, false, &_can_gift_to); + spd.isValid = spell_direction(spd, beam, DIR_TARGET, TARG_FRIEND, + LOS_RADIUS, false, true, false, NULL, + "Gift an item:", true, &tgt); + + if (!spd.isValid || !_can_gift_to(spd.target, false)) + return false; + + monster* mons = monster_at(spd.target); + ASSERT(mons); + const char* monsname = mons->name(DESC_THE, false).c_str(); + int item_slot = prompt_invent_item("Give which item?", MT_INVLIST, OSEL_ANY, true); |