summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authordolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-05-25 17:33:38 +0000
committerdolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573>2008-05-25 17:33:38 +0000
commit63e4083df060b3cdd0ce18d04949dd7831cc10d4 (patch)
tree67311940576728ec6be2d310256d1727b9a77d5a /crawl-ref/source
parent0eceb6ff8b8501d07c94e2e5d46aca19121b205e (diff)
downloadcrawl-ref-63e4083df060b3cdd0ce18d04949dd7831cc10d4.tar.gz
crawl-ref-63e4083df060b3cdd0ce18d04949dd7831cc10d4.zip
Consolidate the attack warning prompts for both melee and beams, and use
the prompts properly with Burn/Freeze, Smite, and Airstrike. Also, move the now-single function for this into misc.cc, since I can't think of a better location right now. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5235 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/beam.cc54
-rw-r--r--crawl-ref/source/fight.cc44
-rw-r--r--crawl-ref/source/misc.cc73
-rw-r--r--crawl-ref/source/misc.h4
-rw-r--r--crawl-ref/source/spells2.cc52
-rw-r--r--crawl-ref/source/spells3.cc97
6 files changed, 141 insertions, 183 deletions
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index 9fc6b6350a..e61a9ba80b 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -4175,56 +4175,6 @@ static bool _beam_is_harmless(bolt &beam, monsters *mon)
}
}
-static bool _stop_unchivalric_attack(monsters *mon, bool target)
-{
- const bool inSanctuary = (is_sanctuary(you.x_pos, you.y_pos)
- || is_sanctuary(mon->x, mon->y));
- const bool wontAttack = mons_wont_attack(mon);
- const bool isFriendly = mons_friendly(mon);
- const bool isNeutral = mons_neutral(mon);
- const bool isUnchivalric = is_unchivalric_attack(&you, mon, mon);
- const bool isHoly = mons_is_holy(mon);
-
- if (isFriendly)
- {
- // listed in the form: "your rat", "Blork"
- snprintf(info, INFO_SIZE, "Really fire %s %s%s?",
- (target) ? "at"
- : "through",
- mon->name(DESC_NOCAP_THE).c_str(),
- (inSanctuary) ? ", despite your sanctuary"
- : "");
-
- if (!yesno(info, true, 'n'))
- return (true);
- }
- else if (inSanctuary || wontAttack
- || is_good_god(you.religion) && (isNeutral || isHoly)
- || you.religion == GOD_SHINING_ONE && isUnchivalric)
- {
- // "Really fire through the helpless neutral holy Daeva?"
- // was: "Really fire through this helpless neutral holy creature?"
- snprintf(info, INFO_SIZE, "Really fire %s the %s%s%s%s%s?",
- (target) ? "at"
- : "through",
- (isUnchivalric) ? "helpless "
- : "",
- (isFriendly) ? "friendly " :
- (wontAttack) ? "non-hostile " :
- (isNeutral) ? "neutral "
- : "",
- (isHoly) ? "holy "
- : "",
- mon->name(DESC_PLAIN).c_str(),
- (inSanctuary) ? ", despite your sanctuary"
- : "");
-
- if (!yesno(info, true, 'n'))
- return (true);
- }
- return (false);
-}
-
// return amount of range used up by affectation of this monster
static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
{
@@ -4296,7 +4246,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
const bool target = (beam.target_x == mon->x
&& beam.target_y == mon->y);
- if (_stop_unchivalric_attack(mon, target))
+ if (stop_attack_prompt(mon, true, target))
{
beam.fr_count = 1;
return (BEAM_STOP);
@@ -4475,7 +4425,7 @@ static int _affect_monster(bolt &beam, monsters *mon, item_def *item)
const bool target = (beam.target_x == mon->x
&& beam.target_y == mon->y);
- if (_stop_unchivalric_attack(mon, target))
+ if (stop_attack_prompt(mon, true, target))
{
beam.fr_count = 1;
return (BEAM_STOP);
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index 5b326ddc20..f890bac0ef 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -606,49 +606,7 @@ bool melee_attack::attack()
conduct.enabled = false;
if (attacker->atype() == ACT_PLAYER)
- {
- const bool inSanctuary = (is_sanctuary(you.x_pos, you.y_pos)
- || is_sanctuary(def->x, def->y));
- const bool wontAttack = mons_wont_attack(def);
- const bool isFriendly = mons_friendly(def);
- const bool isNeutral = mons_neutral(def);
- const bool isUnchivalric = is_unchivalric_attack(&you, def, def);
- const bool isHoly = mons_is_holy(def);
-
- if (inSanctuary || wontAttack
- || (is_good_god(you.religion) && (isNeutral || isHoly))
- || (you.religion == GOD_SHINING_ONE && isUnchivalric))
- {
- snprintf(info, INFO_SIZE, "Really attack the %s%s%s%s%s?",
- (isUnchivalric) ? "helpless "
- : "",
- (isFriendly) ? "friendly " :
- (wontAttack) ? "non-hostile " :
- (isNeutral) ? "neutral "
- : "",
- (isHoly) ? "holy "
- : "",
- def->name(DESC_PLAIN).c_str(),
- (inSanctuary) ? ", despite your sanctuary"
- : "");
-
- if (you.confused() || yesno(info, false, 'n'))
- {
- if (isFriendly)
- conduct.set(DID_ATTACK_FRIEND, 5, true, def);
- else if (isNeutral)
- conduct.set(DID_ATTACK_NEUTRAL, 5, true, def);
-
- if (isUnchivalric)
- conduct.set(DID_UNCHIVALRIC_ATTACK, 4, true, def);
-
- if (isHoly)
- conduct.set(DID_ATTACK_HOLY, def->hit_dice, true, def);
- }
- else
- cancel_attack = true;
- }
- }
+ cancel_attack = stop_attack_prompt(def, false, false, &conduct);
// Trying to stay general beyond this point is a recipe for insanity.
// Maybe when Stone Soup hits 1.0... :-)
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index f96865f093..1a3e99d9ed 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -49,6 +49,7 @@
#include "dgnevent.h"
#include "directn.h"
#include "dungeon.h"
+#include "fight.h"
#include "files.h"
#include "food.h"
#include "format.h"
@@ -2997,3 +2998,75 @@ std::string your_hand(bool plural)
return result;
}
+
+bool stop_attack_prompt(const monsters *mon, bool beam_attack,
+ bool beam_target, god_conduct_trigger *conduct)
+{
+ bool retval = false;
+ bool prompt = false;
+
+ const bool inSanctuary = (is_sanctuary(you.x_pos, you.y_pos)
+ || is_sanctuary(mon->x, mon->y));
+ const bool wontAttack = mons_wont_attack(mon);
+ const bool isFriendly = mons_friendly(mon);
+ const bool isNeutral = mons_neutral(mon);
+ const bool isUnchivalric = is_unchivalric_attack(&you, mon, mon);
+ const bool isHoly = mons_is_holy(mon);
+
+ if (isFriendly)
+ {
+ // listed in the form: "your rat", "Blork"
+ snprintf(info, INFO_SIZE, "Really %s %s%s?",
+ (beam_attack) ? (beam_target) ? "fire at"
+ : "fire through"
+ : "attack",
+ mon->name(DESC_NOCAP_THE).c_str(),
+ (inSanctuary) ? ", despite your sanctuary"
+ : "");
+ prompt = true;
+ }
+ else if (inSanctuary || wontAttack
+ || (is_good_god(you.religion) && (isNeutral || isHoly))
+ || (you.religion == GOD_SHINING_ONE && isUnchivalric))
+ {
+ // "Really fire through the helpless neutral holy Daeva?"
+ // was: "Really fire through this helpless neutral holy creature?"
+ snprintf(info, INFO_SIZE, "Really %s the %s%s%s%s%s?",
+ (beam_attack) ? (beam_target) ? "fire at"
+ : "fire through"
+ : "attack",
+ (isUnchivalric) ? "helpless "
+ : "",
+ (isFriendly) ? "friendly " :
+ (wontAttack) ? "non-hostile " :
+ (isNeutral) ? "neutral "
+ : "",
+ (isHoly) ? "holy "
+ : "",
+ mon->name(DESC_PLAIN).c_str(),
+ (inSanctuary) ? ", despite your sanctuary"
+ : "");
+ prompt = true;
+ }
+
+ if (you.confused() || (prompt && yesno(info, false, 'n')))
+ {
+ if (conduct)
+ {
+ if (isFriendly)
+ conduct->set(DID_ATTACK_FRIEND, 5, true, mon);
+ else if (isNeutral)
+ conduct->set(DID_ATTACK_NEUTRAL, 5, true, mon);
+
+ if (isUnchivalric)
+ conduct->set(DID_UNCHIVALRIC_ATTACK, 4, true, mon);
+
+ if (isHoly)
+ conduct->set(DID_ATTACK_HOLY, mon->hit_dice, true, mon);
+ }
+ }
+ else
+ retval = true;
+
+ return retval;
+}
diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h
index 21df0331f5..13d8fd6864 100644
--- a/crawl-ref/source/misc.h
+++ b/crawl-ref/source/misc.h
@@ -14,6 +14,7 @@
#define MISC_H
#include "externs.h"
+#include "religion.h"
struct bolt;
struct dist;
@@ -145,4 +146,7 @@ void reveal_secret_door(int x, int y);
std::string your_hand(bool plural);
+bool stop_attack_prompt(const monsters *mon, bool beam_attack,
+ bool beam_target, god_conduct_trigger *conduct = NULL);
+
#endif
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index c261b9d04b..2f322535d9 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -35,7 +35,6 @@
#include "directn.h"
#include "dungeon.h"
#include "effects.h"
-#include "fight.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
@@ -1190,42 +1189,35 @@ char burn_freeze(int pow, beam_type flavour)
monsters *monster = &menv[mgr];
- mprf("You %s %s.",
- (flavour == BEAM_FIRE) ? "burn" :
- (flavour == BEAM_COLD) ? "freeze" :
- (flavour == BEAM_MISSILE) ? "crush" :
- (flavour == BEAM_ELECTRICITY) ? "zap"
- : "______",
- monster->name(DESC_NOCAP_THE).c_str());
-
- int hurted = roll_dice( 1, 3 + pow / 3 );
-
- bolt beam;
-
- beam.flavour = flavour;
+ god_conduct_trigger conduct;
+ conduct.enabled = false;
- if (flavour != BEAM_MISSILE)
- hurted = mons_adjust_flavoured(monster, beam, hurted);
+ bool success = !stop_attack_prompt(monster, false, false, &conduct);
- if (hurted)
+ if (success)
{
- god_conduct_trigger conduct;
- conduct.enabled = false;
+ mprf("You %s %s.",
+ (flavour == BEAM_FIRE) ? "burn" :
+ (flavour == BEAM_COLD) ? "freeze" :
+ (flavour == BEAM_MISSILE) ? "crush" :
+ (flavour == BEAM_ELECTRICITY) ? "zap"
+ : "______",
+ monster->name(DESC_NOCAP_THE).c_str());
- if (mons_friendly(monster))
- conduct.set(DID_ATTACK_FRIEND, 5, true, monster);
- else if (mons_neutral(monster))
- conduct.set(DID_ATTACK_NEUTRAL, 5, true, monster);
+ behaviour_event(monster, ME_ANNOY, MHITYOU);
+ }
- if (is_unchivalric_attack(&you, monster, monster))
- conduct.set(DID_UNCHIVALRIC_ATTACK, 4, true, monster);
+ conduct.enabled = true;
- if (mons_is_holy(monster))
- conduct.set(DID_ATTACK_HOLY, monster->hit_dice);
+ if (success)
+ {
+ bolt beam;
+ beam.flavour = flavour;
- behaviour_event(monster, ME_ANNOY, MHITYOU);
+ int hurted = roll_dice(1, 3 + pow / 3);
- conduct.enabled = true;
+ if (flavour != BEAM_MISSILE)
+ hurted = mons_adjust_flavoured(monster, beam, hurted);
hurt_monster(monster, hurted);
@@ -1237,7 +1229,7 @@ char burn_freeze(int pow, beam_type flavour)
if (flavour == BEAM_COLD)
{
- if (mons_class_flag( monster->type, M_COLD_BLOOD )
+ if (mons_class_flag(monster->type, M_COLD_BLOOD)
&& coinflip())
{
monster->add_ench(ENCH_SLOW);
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index aa9063d5e7..dd11b43503 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -31,7 +31,6 @@
#include "debug.h"
#include "delay.h"
#include "effects.h" // holy word
-#include "fight.h"
#include "food.h"
#include "itemname.h"
#include "itemprop.h"
@@ -200,45 +199,38 @@ int cast_smiting(int power, dist &beam)
{
bool success = false;
- if (mgrd[beam.tx][beam.ty] == NON_MONSTER
- || beam.isMe)
- {
+ if (mgrd[beam.tx][beam.ty] == NON_MONSTER || beam.isMe)
canned_msg(MSG_SPELL_FIZZLES);
- }
else
{
monsters *monster = &menv[mgrd[beam.tx][beam.ty]];
- mprf("You smite %s!", monster->name(DESC_NOCAP_THE).c_str());
-
god_conduct_trigger conduct;
conduct.enabled = false;
- if (mons_friendly(monster))
- conduct.set(DID_ATTACK_FRIEND, 5, true, monster);
- else if (mons_neutral(monster))
- conduct.set(DID_ATTACK_NEUTRAL, 5, true, monster);
+ success = !stop_attack_prompt(monster, false, false, &conduct);
- if (is_unchivalric_attack(&you, monster, monster))
- conduct.set(DID_UNCHIVALRIC_ATTACK, 4, true, monster);
-
- if (mons_is_holy(monster))
- conduct.set(DID_ATTACK_HOLY, monster->hit_dice, true, monster);
+ if (success)
+ {
+ mprf("You smite %s!", monster->name(DESC_NOCAP_THE).c_str());
- behaviour_event(monster, ME_ANNOY, MHITYOU);
+ behaviour_event(monster, ME_ANNOY, MHITYOU);
+ }
conduct.enabled = true;
- // Maxes out at around 40 damage at 27 Invocations, which is plenty
- // in my book (the old max damage was around 70, which seems excessive)
- hurt_monster(monster, 7 + (random2(power) * 33 / 191));
-
- if (monster->hit_points < 1)
- monster_die(monster, KILL_YOU, 0);
- else
- print_wounds(monster);
+ if (success)
+ {
+ // Maxes out at around 40 damage at 27 Invocations, which is
+ // plenty in my book (the old max damage was around 70,
+ // which seems excessive).
+ hurt_monster(monster, 7 + (random2(power) * 33 / 191));
- success = true;
+ if (monster->hit_points < 1)
+ monster_die(monster, KILL_YOU, 0);
+ else
+ print_wounds(monster);
+ }
}
return (success);
@@ -248,51 +240,42 @@ int airstrike(int power, dist &beam)
{
bool success = false;
- if (mgrd[beam.tx][beam.ty] == NON_MONSTER
- || beam.isMe)
- {
+ if (mgrd[beam.tx][beam.ty] == NON_MONSTER || beam.isMe)
canned_msg(MSG_SPELL_FIZZLES);
- }
else
{
monsters *monster = &menv[mgrd[beam.tx][beam.ty]];
- mprf("The air twists around and strikes %s!",
- monster->name(DESC_NOCAP_THE).c_str());
+ god_conduct_trigger conduct;
+ conduct.enabled = false;
- int hurted = 8 + random2( random2(4) + (random2(power) / 6)
- + (random2(power) / 7) );
+ success = !stop_attack_prompt(monster, false, false, &conduct);
- if ( mons_flies(monster) )
+ if (success)
{
- hurted *= 3;
- hurted /= 2;
- }
+ mprf("The air twists around and strikes %s!",
+ monster->name(DESC_NOCAP_THE).c_str());
- hurted -= random2(1 + monster->ac);
+ behaviour_event(monster, ME_ANNOY, MHITYOU);
+ }
- if (hurted < 0)
- hurted = 0;
+ conduct.enabled = true;
- if (hurted)
+ if (success)
{
- god_conduct_trigger conduct;
- conduct.enabled = false;
-
- if (mons_friendly(monster))
- conduct.set(DID_ATTACK_FRIEND, 5, true, monster);
- else if (mons_neutral(monster))
- conduct.set(DID_ATTACK_NEUTRAL, 5, true, monster);
+ int hurted = 8 + random2(random2(4) + (random2(power) / 6)
+ + (random2(power) / 7));
- if (is_unchivalric_attack(&you, monster, monster))
- conduct.set(DID_UNCHIVALRIC_ATTACK, 5, true, monster);
-
- if (mons_is_holy(monster))
- conduct.set(DID_ATTACK_HOLY, monster->hit_dice, true, monster);
+ if (mons_flies(monster))
+ {
+ hurted *= 3;
+ hurted /= 2;
+ }
- behaviour_event(monster, ME_ANNOY, MHITYOU);
+ hurted -= random2(1 + monster->ac);
- conduct.enabled = true;
+ if (hurted < 0)
+ hurted = 0;
hurt_monster(monster, hurted);
@@ -301,8 +284,6 @@ int airstrike(int power, dist &beam)
else
print_wounds(monster);
}
-
- success = true;
}
return (success);