From cbef37bd5bfb938a2303ee3887520c08be85d8e8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 26 Mar 2013 17:10:10 +0100 Subject: Switch almost everything over to C++ --- src/melee2.cc | 7561 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 7561 insertions(+) create mode 100644 src/melee2.cc (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc new file mode 100644 index 00000000..0a139f89 --- /dev/null +++ b/src/melee2.cc @@ -0,0 +1,7561 @@ +/* File: melee2.c */ + +/* Purpose: Monster spells and movement */ + +/* +* Copyright (c) 1989 James E. Wilson, Robert A. Koeneke +* +* This software may be copied and distributed for educational, research, and +* not for profit purposes provided that this copyright and statement are +* included in all such copies. +*/ + +/* +* This file has several additions to it by Keldon Jones (keldon@umr.edu) +* to improve the general quality of the AI (version 0.1.1). +*/ + +#include "angband.h" + +#include "messages.h" +#include "quark.h" +#include "hooks.h" + +#define SPEAK_CHANCE 8 +#define GRINDNOISE 20 + +#define FOLLOW_DISTANCE 6 + +/* + * Based on mon_take_hit... all monster attacks on + * other monsters should use + */ +bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) +{ + monster_type *m_ptr = &m_list[m_idx], *s_ptr = &m_list[s_idx]; + + monster_race *r_ptr = race_inf(m_ptr); + + s32b div, new_exp, new_exp_frac; + + /* Redraw (later) if needed */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + + /* Some mosnters are immune to death */ + if (r_ptr->flags7 & RF7_NO_DEATH) return FALSE; + + /* Wake it up */ + m_ptr->csleep = 0; + + /* Hurt it */ + m_ptr->hp -= dam; + + /* It is dead now... or is it? */ + if (m_ptr->hp < 0) + { + if (((r_ptr->flags1 & RF1_UNIQUE) && (m_ptr->status <= MSTATUS_NEUTRAL_P)) || + (m_ptr->mflag & MFLAG_QUEST)) + { + m_ptr->hp = 1; + } + else + { + char m_name[80]; + s32b dive = s_ptr->level; + + if (!dive) dive = 1; + + /* Extract monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Make a sound */ + if ((r_ptr->flags3 & RF3_DEMON) || + (r_ptr->flags3 & RF3_UNDEAD) || + (r_ptr->flags2 & RF2_STUPID) || + (r_ptr->flags3 & RF3_NONLIVING) || + (strchr("Evg", r_ptr->d_char))) + { + sound(SOUND_N_KILL); + } + else + { + sound(SOUND_KILL); + } + + /* Death by Missile/Spell attack */ + if (note) + { + cmonster_msg(TERM_L_RED, "%^s%s", m_name, note); + } + /* Death by Physical attack -- living monster */ + else if (!m_ptr->ml) + { + /* Do nothing */ + } + /* Death by Physical attack -- non-living monster */ + else if ((r_ptr->flags3 & (RF3_DEMON)) || + (r_ptr->flags3 & (RF3_UNDEAD)) || + (r_ptr->flags2 & (RF2_STUPID)) || + (r_ptr->flags3 & (RF3_NONLIVING)) || + (strchr("Evg", r_ptr->d_char))) + { + cmonster_msg(TERM_L_RED, "%^s is destroyed.", m_name); + } + else + { + cmonster_msg(TERM_L_RED, "%^s is killed.", m_name); + } + + dive = r_ptr->mexp * m_ptr->level / dive; + if (!dive) dive = 1; + + /* Monster gains some xp */ + monster_gain_exp(s_idx, dive, FALSE); + + /* Monster lore skill allows gaining xp from pets */ + if (get_skill(SKILL_LORE) && (s_ptr->status >= MSTATUS_PET)) + { + /* Maximum player level */ + div = p_ptr->max_plv; + + /* Give some experience for the kill */ + new_exp = ((long)r_ptr->mexp * m_ptr->level) / div; + + /* Handle fractional experience */ + new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div) + * 0x10000L / div) + p_ptr->exp_frac; + + /* Keep track of experience */ + if (new_exp_frac >= 0x10000L) + { + new_exp++; + p_ptr->exp_frac = new_exp_frac - 0x10000; + } + else + { + p_ptr->exp_frac = new_exp_frac; + } + + /* + * Factor the xp by the skill level + * Note that a score of 50 in the skill makes the gain be 120% of the exp + */ + new_exp = new_exp * get_skill_scale(SKILL_LORE, 120) / 100; + + /* Gain experience */ + gain_exp(new_exp); + } + + /* When an Unique dies, it stays dead */ + if (r_ptr->flags1 & (RF1_UNIQUE)) + { + r_ptr->max_num = 0; + } + + /* Generate treasure */ + monster_death(m_idx); + + /* Delete the monster */ + delete_monster_idx(m_idx); + + /* Not afraid */ + (*fear) = FALSE; + + /* Monster is dead */ + return (TRUE); + } + + } + + /* Apply fear */ + mon_handle_fear(m_ptr, dam, fear); + + /* Not dead yet */ + return (FALSE); +} + + +void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) +{ + monster_race *r_ptr = NULL; + + assert(m_ptr != NULL); + + r_ptr = race_inf(m_ptr); + + /* Mega-Hack -- Pain cancels fear */ + if (m_ptr->monfear && (dam > 0)) + { + int tmp = randint(dam); + + /* Cure a little fear */ + if (tmp < m_ptr->monfear) + { + /* Reduce fear */ + m_ptr->monfear -= tmp; + } + + /* Cure all the fear */ + else + { + /* Cure fear */ + m_ptr->monfear = 0; + + /* No more fear */ + (*fear) = FALSE; + } + } + + /* Sometimes a monster gets scared by damage */ + if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR))) + { + int percentage; + + /* Percentage of fully healthy */ + percentage = (100L * m_ptr->hp) / m_ptr->maxhp; + + /* + * Run (sometimes) if at 10% or less of max hit points, + * or (usually) when hit for half its current hit points + */ + if (((percentage <= 10) && (rand_int(10) < percentage)) || + ((dam >= m_ptr->hp) && (rand_int(100) < 80))) + { + /* Hack -- note fear */ + (*fear) = TRUE; + + /* XXX XXX XXX Hack -- Add some timed fear */ + m_ptr->monfear = (randint(10) + + (((dam >= m_ptr->hp) && (percentage > 7)) ? + 20 : ((11 - percentage) * 5))); + } + } +} + + +/* +* And now for Intelligent monster attacks (including spells). +* +* Original idea and code by "DRS" (David Reeves Sward). +* Major modifications by "BEN" (Ben Harrison). +* +* Give monsters more intelligent attack/spell selection based on +* observations of previous attacks on the player, and/or by allowing +* the monster to "cheat" and know the player status. +* +* Maintain an idea of the player status, and use that information +* to occasionally eliminate "ineffective" spell attacks. We could +* also eliminate ineffective normal attacks, but there is no reason +* for the monster to do this, since he gains no benefit. +* Note that MINDLESS monsters are not allowed to use this code. +* And non-INTELLIGENT monsters only use it partially effectively. +* +* Actually learn what the player resists, and use that information +* to remove attacks or spells before using them. This will require +* much less space, if I am not mistaken. Thus, each monster gets a +* set of 32 bit flags, "smart", build from the various "SM_*" flags. +* +* This has the added advantage that attacks and spells are related. +* The "smart_learn" option means that the monster "learns" the flags +* that should be set, and "smart_cheat" means that he "knows" them. +* So "smart_cheat" means that the "smart" field is always up to date, +* while "smart_learn" means that the "smart" field is slowly learned. +* Both of them have the same effect on the "choose spell" routine. +*/ + + + +/* +* Internal probability routine +*/ +static bool_ int_outof(monster_race *r_ptr, int prob) +{ + /* Non-Smart monsters are half as "smart" */ + if (!(r_ptr->flags2 & (RF2_SMART))) prob = prob / 2; + + /* Roll the dice */ + return (rand_int(100) < prob); +} + + + +/* + * Remove the "bad" spells from a spell list + */ +static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) +{ + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + + u32b f4 = (*f4p); + u32b f5 = (*f5p); + u32b f6 = (*f6p); + + u32b smart = 0L; + + + /* Too stupid to know anything */ + if (r_ptr->flags2 & (RF2_STUPID)) return; + + + /* Must be cheating or learning */ + if (!smart_cheat && !smart_learn) return; + + + /* Update acquired knowledge */ + if (smart_learn) + { + /* Hack -- Occasionally forget player status */ + if (m_ptr->smart && (rand_int(100) < 1)) m_ptr->smart = 0L; + + /* Use the memorized flags */ + smart = m_ptr->smart; + } + + + /* Cheat if requested */ + if (smart_cheat) + { + /* Know basic info */ + if (p_ptr->resist_acid) smart |= (SM_RES_ACID); + if (p_ptr->oppose_acid) smart |= (SM_OPP_ACID); + if (p_ptr->immune_acid) smart |= (SM_IMM_ACID); + if (p_ptr->resist_elec) smart |= (SM_RES_ELEC); + if (p_ptr->oppose_elec) smart |= (SM_OPP_ELEC); + if (p_ptr->immune_elec) smart |= (SM_IMM_ELEC); + if (p_ptr->resist_fire) smart |= (SM_RES_FIRE); + if (p_ptr->oppose_fire) smart |= (SM_OPP_FIRE); + if (p_ptr->immune_fire) smart |= (SM_IMM_FIRE); + if (p_ptr->resist_cold) smart |= (SM_RES_COLD); + if (p_ptr->oppose_cold) smart |= (SM_OPP_COLD); + if (p_ptr->immune_cold) smart |= (SM_IMM_COLD); + + /* Know poison info */ + if (p_ptr->resist_pois) smart |= (SM_RES_POIS); + if (p_ptr->oppose_pois) smart |= (SM_OPP_POIS); + + /* Know special resistances */ + if (p_ptr->resist_neth) smart |= (SM_RES_NETH); + if (p_ptr->resist_lite) smart |= (SM_RES_LITE); + if (p_ptr->resist_dark) smart |= (SM_RES_DARK); + if (p_ptr->resist_fear) smart |= (SM_RES_FEAR); + if (p_ptr->resist_conf) smart |= (SM_RES_CONF); + if (p_ptr->resist_chaos) smart |= (SM_RES_CHAOS); + if (p_ptr->resist_disen) smart |= (SM_RES_DISEN); + if (p_ptr->resist_blind) smart |= (SM_RES_BLIND); + if (p_ptr->resist_nexus) smart |= (SM_RES_NEXUS); + if (p_ptr->resist_sound) smart |= (SM_RES_SOUND); + if (p_ptr->resist_shard) smart |= (SM_RES_SHARD); + if (p_ptr->reflect) smart |= (SM_IMM_REFLECT); + + /* Know bizarre "resistances" */ + if (p_ptr->free_act) smart |= (SM_IMM_FREE); + if (!p_ptr->msp) smart |= (SM_IMM_MANA); + } + + + /* Nothing known */ + if (!smart) return; + + + if (smart & (SM_IMM_ACID)) + { + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_ACID); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_ACID); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ACID); + } + else if ((smart & (SM_OPP_ACID)) && (smart & (SM_RES_ACID))) + { + if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ACID); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ACID); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ACID); + } + else if ((smart & (SM_OPP_ACID)) || (smart & (SM_RES_ACID))) + { + if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ACID); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ACID); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ACID); + } + + + if (smart & (SM_IMM_ELEC)) + { + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_ELEC); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_ELEC); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ELEC); + } + else if ((smart & (SM_OPP_ELEC)) && (smart & (SM_RES_ELEC))) + { + if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ELEC); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ELEC); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ELEC); + } + else if ((smart & (SM_OPP_ELEC)) || (smart & (SM_RES_ELEC))) + { + if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ELEC); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ELEC); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ELEC); + } + + + if (smart & (SM_IMM_FIRE)) + { + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_FIRE); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_FIRE); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_FIRE); + } + else if ((smart & (SM_OPP_FIRE)) && (smart & (SM_RES_FIRE))) + { + if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_FIRE); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_FIRE); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_FIRE); + } + else if ((smart & (SM_OPP_FIRE)) || (smart & (SM_RES_FIRE))) + { + if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_FIRE); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_FIRE); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_FIRE); + } + + + if (smart & (SM_IMM_COLD)) + { + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_COLD); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_COLD); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_COLD); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ICEE); + } + else if ((smart & (SM_OPP_COLD)) && (smart & (SM_RES_COLD))) + { + if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_COLD); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_COLD); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_COLD); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ICEE); + } + else if ((smart & (SM_OPP_COLD)) || (smart & (SM_RES_COLD))) + { + if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_COLD); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_COLD); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_COLD); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ICEE); + } + + + if ((smart & (SM_OPP_POIS)) && (smart & (SM_RES_POIS))) + { + if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_POIS); + if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_POIS); + if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BA_NUKE); + if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BR_NUKE); + } + else if ((smart & (SM_OPP_POIS)) || (smart & (SM_RES_POIS))) + { + if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_POIS); + if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_POIS); + } + + + if (smart & (SM_RES_NETH)) + { + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NETH); + if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_NETH); + if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BO_NETH); + } + + if (smart & (SM_RES_LITE)) + { + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_LITE); + } + + if (smart & (SM_RES_DARK)) + { + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_DARK); + if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_DARK); + } + + if (smart & (SM_RES_FEAR)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_SCARE); + } + + if (smart & (SM_RES_CONF)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_CONF); + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF); + } + + if (smart & (SM_RES_CHAOS)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_CONF); + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF); + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CHAO); + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BA_CHAO); + } + + if (smart & (SM_RES_DISEN)) + { + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_DISE); + } + + if (smart & (SM_RES_BLIND)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BLIND); + } + + if (smart & (SM_RES_NEXUS)) + { + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NEXU); + if (int_outof(r_ptr, 50)) f6 &= ~(RF6_TELE_LEVEL); + } + + if (smart & (SM_RES_SOUND)) + { + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_SOUN); + } + + if (smart & (SM_RES_SHARD)) + { + if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_SHAR); + if (int_outof(r_ptr, 20)) f4 &= ~(RF4_ROCKET); + } + + if (smart & (SM_IMM_REFLECT)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_COLD); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_FIRE); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ACID); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ELEC); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_POIS); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_NETH); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_WATE); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_MANA); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_PLAS); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ICEE); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_MISSILE); + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_1); + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_2); + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_3); + if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_4); + } + + if (smart & (SM_IMM_FREE)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_HOLD); + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_SLOW); + } + + if (smart & (SM_IMM_MANA)) + { + if (int_outof(r_ptr, 100)) f5 &= ~(RF5_DRAIN_MANA); + } + + /* XXX XXX XXX No spells left? */ + /* if (!f4 && !f5 && !f6) ... */ + + (*f4p) = f4; + (*f5p) = f5; + (*f6p) = f6; +} + + +/* + * Determine if there is a space near the player in which + * a summoned creature can appear + */ +static bool_ summon_possible(int y1, int x1) +{ + int y, x; + + /* Start at the player's location, and check 2 grids in each dir */ + for (y = y1 - 2; y <= y1 + 2; y++) + { + for (x = x1 - 2; x <= x1 + 2; x++) + { + /* Ignore illegal locations */ + if (!in_bounds(y, x)) continue; + + /* Only check a circular area */ + if (distance(y1, x1, y, x) > 2) continue; + + /* Hack: no summon on glyph of warding */ + if (cave[y][x].feat == FEAT_GLYPH) continue; + if (cave[y][x].feat == FEAT_MINOR_GLYPH) continue; + + /* Nor on the between */ + if (cave[y][x].feat == FEAT_BETWEEN) return (FALSE); + + /* ...nor on the Pattern */ + if ((cave[y][x].feat >= FEAT_PATTERN_START) + && (cave[y][x].feat <= FEAT_PATTERN_XTRA2)) continue; + + /* Require empty floor grid in line of sight */ + if (cave_empty_bold(y, x) && los(y1, x1, y, x)) return (TRUE); + } + } + + return FALSE; +} + + + +/* + * Determine if a bolt spell will hit the player. + * + * This is exactly like "projectable", but it will return FALSE if a monster + * is in the way. + */ +static bool_ clean_shot(int y1, int x1, int y2, int x2) +{ + int dist, y, x; + + /* Start at the initial location */ + y = y1, x = x1; + + /* See "project()" and "projectable()" */ + for (dist = 0; dist <= MAX_RANGE; dist++) + { + /* Never pass through walls */ + if (dist && (!cave_sight_bold(y, x) || !cave_floor_bold(y, x))) break; + + /* Never pass through monsters */ + if (dist && cave[y][x].m_idx > 0) + { + if (is_friend(&m_list[cave[y][x].m_idx]) < 0) break; + } + + /* Check for arrival at "final target" */ + if ((x == x2) && (y == y2)) return (TRUE); + + /* Calculate the new location */ + mmove2(&y, &x, y1, x1, y2, x2); + } + + /* Assume obstruction */ + return (FALSE); +} + + +/* + * Cast a bolt at the player + * Stop if we hit a monster + * Affect monsters and the player + */ +static void bolt(int m_idx, int typ, int dam_hp) +{ + int flg = PROJECT_STOP | PROJECT_KILL; + + /* Target the player with a bolt attack */ + (void)project(m_idx, 0, p_ptr->py, p_ptr->px, dam_hp, typ, flg); +} + + +/* + * Return TRUE if a spell is good for hurting the player (directly). + */ +static bool_ spell_attack(byte spell) +{ + /* All RF4 spells hurt (except for shriek, multiply, summon animal) */ + if (spell >= 96 + 3 && spell <= 96 + 31) return (TRUE); + + /* Various "ball" spells */ + if (spell >= 128 && spell <= 128 + 8) return (TRUE); + + /* "Cause wounds" and "bolt" spells */ + if (spell >= 128 + 12 && spell <= 128 + 26) return (TRUE); + + /* Hand of Doom */ + if (spell == 160 + 1) return (TRUE); + + /* Doesn't hurt */ + return (FALSE); +} + + +/* + * Return TRUE if a spell is good for escaping. + */ +static bool_ spell_escape(byte spell) +{ + /* Blink or Teleport */ + if (spell == 160 + 4 || spell == 160 + 5) return (TRUE); + + /* Teleport the player away */ + if (spell == 160 + 7 || spell == 160 + 8) return (TRUE); + + /* Isn't good for escaping */ + return (FALSE); +} + +/* + * Return TRUE if a spell is good for annoying the player. + */ +static bool_ spell_annoy(byte spell) +{ + /* Shriek */ + if (spell == 96 + 0) return (TRUE); + + /* Brain smash, et al (added curses) */ + if (spell >= 128 + 9 && spell <= 128 + 14) return (TRUE); + + /* Scare, confuse, blind, slow, paralyze */ + if (spell >= 128 + 27 && spell <= 128 + 31) return (TRUE); + + /* Teleport to */ + if (spell == 160 + 6) return (TRUE); + + /* Darkness, make traps, cause amnesia */ + if (spell >= 160 + 9 && spell <= 160 + 11) return (TRUE); + + /* Doesn't annoy */ + return (FALSE); +} + +/* + * Return TRUE if a spell summons help. + */ +static bool_ spell_summon(byte spell) +{ + /* RF4_S_ANIMAL, RF6_S_ANIMALS */ + if (spell == 96 + 2 || spell == 160 + 3) return (TRUE); + /* All other summon spells */ + if (spell >= 160 + 13 && spell <= 160 + 31) return (TRUE); + + /* Doesn't summon */ + return (FALSE); +} + + +/* + * Return TRUE if a spell is good in a tactical situation. + */ +static bool_ spell_tactic(byte spell) +{ + /* Blink */ + if (spell == 160 + 4) return (TRUE); + + /* Not good */ + return (FALSE); +} + + +/* + * Return TRUE if a spell hastes. + */ +static bool_ spell_haste(byte spell) +{ + /* Haste self */ + if (spell == 160 + 0) return (TRUE); + + /* Not a haste spell */ + return (FALSE); +} + + +/* + * Return TRUE if a spell is good for healing. + */ +static bool_ spell_heal(byte spell) +{ + /* Heal */ + if (spell == 160 + 2) return (TRUE); + + /* No healing */ + return (FALSE); +} + + +/* + * Have a monster choose a spell from a list of "useful" spells. + * + * Note that this list does NOT include spells that will just hit + * other monsters, and the list is restricted when the monster is + * "desperate". Should that be the job of this function instead? + * + * Stupid monsters will just pick a spell randomly. Smart monsters + * will choose more "intelligently". + * + * Use the helper functions above to put spells into categories. + * + * This function may well be an efficiency bottleneck. + */ +static int choose_attack_spell(int m_idx, byte spells[], byte num) +{ + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + + byte escape[96], escape_num = 0; + byte attack[96], attack_num = 0; + byte summon[96], summon_num = 0; + byte tactic[96], tactic_num = 0; + byte annoy[96], annoy_num = 0; + byte haste[96], haste_num = 0; + byte heal[96], heal_num = 0; + + int i; + + /* Stupid monsters choose randomly */ + if (r_ptr->flags2 & (RF2_STUPID)) + { + /* Pick at random */ + return (spells[rand_int(num)]); + } + + /* Categorize spells */ + for (i = 0; i < num; i++) + { + /* Escape spell? */ + if (spell_escape(spells[i])) escape[escape_num++] = spells[i]; + + /* Attack spell? */ + if (spell_attack(spells[i])) attack[attack_num++] = spells[i]; + + /* Summon spell? */ + if (spell_summon(spells[i])) summon[summon_num++] = spells[i]; + + /* Tactical spell? */ + if (spell_tactic(spells[i])) tactic[tactic_num++] = spells[i]; + + /* Annoyance spell? */ + if (spell_annoy(spells[i])) annoy[annoy_num++] = spells[i]; + + /* Haste spell? */ + if (spell_haste(spells[i])) haste[haste_num++] = spells[i]; + + /* Heal spell? */ + if (spell_heal(spells[i])) heal[heal_num++] = spells[i]; + } + + /*** Try to pick an appropriate spell type ***/ + + /* Hurt badly or afraid, attempt to flee */ + if ((m_ptr->hp < m_ptr->maxhp / 3) || m_ptr->monfear) + { + /* Choose escape spell if possible */ + if (escape_num) return (escape[rand_int(escape_num)]); + } + + /* Still hurt badly, couldn't flee, attempt to heal */ + if (m_ptr->hp < m_ptr->maxhp / 3) + { + /* Choose heal spell if possible */ + if (heal_num) return (heal[rand_int(heal_num)]); + } + + /* Player is close and we have attack spells, blink away */ + if ((distance(p_ptr->py, p_ptr->px, m_ptr->fy, m_ptr->fx) < 4) && attack_num && (rand_int(100) < 75)) + { + /* Choose tactical spell */ + if (tactic_num) return (tactic[rand_int(tactic_num)]); + } + + /* We're hurt (not badly), try to heal */ + if ((m_ptr->hp < m_ptr->maxhp * 3 / 4) && (rand_int(100) < 75)) + { + /* Choose heal spell if possible */ + if (heal_num) return (heal[rand_int(heal_num)]); + } + + /* Summon if possible (sometimes) */ + if (summon_num && (rand_int(100) < 50)) + { + /* Choose summon spell */ + return (summon[rand_int(summon_num)]); + } + + /* Attack spell (most of the time) */ + if (attack_num && (rand_int(100) < 85)) + { + /* Choose attack spell */ + return (attack[rand_int(attack_num)]); + } + + /* Try another tactical spell (sometimes) */ + if (tactic_num && (rand_int(100) < 50)) + { + /* Choose tactic spell */ + return (tactic[rand_int(tactic_num)]); + } + + /* Haste self if we aren't already somewhat hasted (rarely) */ + if (haste_num && (rand_int(100) < (20 + m_ptr->speed - m_ptr->mspeed))) + { + /* Choose haste spell */ + return (haste[rand_int(haste_num)]); + } + + /* Annoy player (most of the time) */ + if (annoy_num && (rand_int(100) < 85)) + { + /* Choose annoyance spell */ + return (annoy[rand_int(annoy_num)]); + } + + /* Choose no spell */ + return (0); +} + + +/* + * Cast a breath (or ball) attack at the player + * Pass over any monsters that may be in the way + * Affect grids, objects, monsters, and the player + */ +static void breath(int m_idx, int typ, int dam_hp, int rad) +{ + int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL; + + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + + /* Determine the radius of the blast */ + if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2; + + /* Target the player with a ball attack */ + (void)project(m_idx, rad, p_ptr->py, p_ptr->px, dam_hp, typ, flg); +} + + +/* + * Monster casts a breath (or ball) attack at another monster. + * Pass over any monsters that may be in the way + * Affect grids, objects, monsters, and the player + */ +static void monst_breath_monst(int m_idx, int y, int x, int typ, int dam_hp, int rad) +{ + int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL; + + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + + /* Determine the radius of the blast */ + if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2; + + (void)project(m_idx, rad, y, x, dam_hp, typ, flg); +} + + +/* + * Monster casts a bolt at another monster + * Stop if we hit a monster + * Affect monsters and the player + */ +static void monst_bolt_monst(int m_idx, int y, int x, int typ, int dam_hp) +{ + int flg = PROJECT_STOP | PROJECT_KILL; + + (void)project(m_idx, 0, y, x, dam_hp, typ, flg); +} + + +void monster_msg(cptr fmt, ...) +{ + va_list vp; + + char buf[1024]; + + /* Begin the Varargs Stuff */ + va_start(vp, fmt); + + /* Format the args, save the length */ + (void)vstrnfmt(buf, 1024, fmt, vp); + + /* End the Varargs Stuff */ + va_end(vp); + + /* Display */ + if (disturb_other) + msg_print(buf); + else + { + message_add(buf, TERM_WHITE); + p_ptr->window |= PW_MESSAGE; + } +} + +void cmonster_msg(char a, cptr fmt, ...) +{ + va_list vp; + + char buf[1024]; + + /* Begin the Varargs Stuff */ + va_start(vp, fmt); + + /* Format the args, save the length */ + (void)vstrnfmt(buf, 1024, fmt, vp); + + /* End the Varargs Stuff */ + va_end(vp); + + /* Display */ + if (disturb_other) + cmsg_print(a, buf); + else + { + message_add(buf, a); + p_ptr->window |= PW_MESSAGE; + } +} + + +/* + * Monster tries to 'cast a spell' (or breath, etc) + * at another monster. + */ +int monst_spell_monst_spell = -1; +static bool_ monst_spell_monst(int m_idx) +{ + int y = 0, x = 0; + int i = 1, k, t_idx; + int chance, thrown_spell, count = 0; + byte spell[96], num = 0; + char m_name[80], t_name[80]; + char m_poss[80]; + char ddesc[80]; + int rlev; /* monster level */ + monster_type *m_ptr = &m_list[m_idx]; /* Attacker */ + monster_race *r_ptr = race_inf(m_ptr); + monster_type *t_ptr; /* Putative target */ + monster_race *tr_ptr; + u32b f4, f5, f6; /* racial spell flags */ + bool_ direct = TRUE; + bool_ wake_up = FALSE; + + /* Extract the blind-ness */ + bool_ blind = (p_ptr->blind ? TRUE : FALSE); + + /* Extract the "see-able-ness" */ + bool_ seen = (!blind && m_ptr->ml); + + bool_ see_m; + bool_ see_t; + bool_ see_either; + bool_ see_both; + + bool_ friendly = FALSE; + + if (is_friend(m_ptr) > 0) friendly = TRUE; + + /* Cannot cast spells when confused */ + if (m_ptr->confused) return (FALSE); + + /* Hack -- Extract the spell probability */ + chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2; + + /* Not allowed to cast spells */ + if ((!chance) && (monst_spell_monst_spell == -1)) return (FALSE); + + if ((rand_int(100) >= chance) && (monst_spell_monst_spell == -1)) return (FALSE); + + /* Target location */ + if (m_ptr->target > -1) + { + if (m_ptr->target > 0) + { + i = m_ptr->target; + } + else return FALSE; + } + else return FALSE; + + + { + t_idx = i; + t_ptr = &m_list[t_idx]; + tr_ptr = race_inf(t_ptr); + + /* Hack -- no fighting >100 squares from player */ + if (t_ptr->cdis > MAX_RANGE) return FALSE; + + /* Monster must be projectable */ + if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) return FALSE; + + /* OK -- we-ve got a target */ + y = t_ptr->fy; + x = t_ptr->fx; + + /* Extract the monster level */ + rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); + + /* Extract the racial spell flags */ + f4 = r_ptr->flags4; + f5 = r_ptr->flags5; + f6 = r_ptr->flags6; + + /* Hack -- allow "desperate" spells */ + if ((r_ptr->flags2 & (RF2_SMART)) && + (m_ptr->hp < m_ptr->maxhp / 10) && + (rand_int(100) < 50)) + { + /* Require intelligent spells */ + f4 &= (RF4_INT_MASK); + f5 &= (RF5_INT_MASK); + f6 &= (RF6_INT_MASK); + + /* No spells left */ + if ((!f4 && !f5 && !f6) && (monst_spell_monst_spell == -1)) return (FALSE); + } + + /* Extract the "inate" spells */ + for (k = 0; k < 32; k++) + { + if (f4 & (1L << k)) spell[num++] = k + 32 * 3; + } + + /* Extract the "normal" spells */ + for (k = 0; k < 32; k++) + { + if (f5 & (1L << k)) spell[num++] = k + 32 * 4; + } + + /* Extract the "bizarre" spells */ + for (k = 0; k < 32; k++) + { + if (f6 & (1L << k)) spell[num++] = k + 32 * 5; + } + + /* No spells left */ + if (!num) return (FALSE); + + /* Stop if player is dead or gone */ + if (!alive || death) return (FALSE); + + /* Handle "leaving" */ + if (p_ptr->leaving) return (FALSE); + + /* Get the monster name (or "it") */ + monster_desc(m_name, m_ptr, 0x00); + + /* Get the monster possessive ("his"/"her"/"its") */ + monster_desc(m_poss, m_ptr, 0x22); + + /* Get the target's name (or "it") */ + monster_desc(t_name, t_ptr, 0x00); + + /* Hack -- Get the "died from" name */ + monster_desc(ddesc, m_ptr, 0x88); + + /* Choose a spell to cast */ + thrown_spell = spell[rand_int(num)]; + + /* Force a spell ? */ + if (monst_spell_monst_spell > -1) + { + thrown_spell = monst_spell_monst_spell; + monst_spell_monst_spell = -1; + } + + see_m = seen; + see_t = (!blind && t_ptr->ml); + see_either = (see_m || see_t); + see_both = (see_m && see_t); + + switch (thrown_spell) + { + /* RF4_SHRIEK */ + case 96 + 0: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (!see_m) monster_msg("You hear a shriek."); + else monster_msg("%^s shrieks at %s.", m_name, t_name); + wake_up = TRUE; + break; + } + + /* RF4_MULTIPLY */ + case 96 + 1: + { + break; + } + + /* RF4_S_ANIMAL */ + case 96 + 2: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons an animal!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_ANIMAL); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF4_ROCKET */ + case 96 + 3: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear an explosion!"); + else if (blind) monster_msg("%^s shoots something.", m_name); + else monster_msg("%^s fires a rocket at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_ROCKET, + ((m_ptr->hp / 4) > 800 ? 800 : (m_ptr->hp / 4)), 2); + break; + } + + /* RF4_ARROW_1 */ + case 96 + 4: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear a strange noise."); + else if (blind) monster_msg("%^s makes a strange noise.", m_name); + else monster_msg("%^s fires an arrow at %s.", m_name, t_name); + sound(SOUND_SHOOT); + monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(1, 6)); + break; + } + + /* RF4_ARROW_2 */ + case 96 + 5: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear a strange noise."); + else if (blind) monster_msg("%^s makes a strange noise.", m_name); + else monster_msg("%^s fires an arrow at %s.", m_name, t_name); + sound(SOUND_SHOOT); + monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(3, 6)); + break; + } + + /* RF4_ARROW_3 */ + case 96 + 6: + { + if (disturb_other) disturb(1); + + if (!see_either) monster_msg("You hear a strange noise."); + else if (blind) monster_msg("%^s makes a strange noise.", m_name); + else monster_msg("%^s fires a missile at %s.", m_name, t_name); + sound(SOUND_SHOOT); + monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(5, 6)); + break; + } + + /* RF4_ARROW_4 */ + case 96 + 7: + { + if (!see_either) monster_msg("You hear a strange noise."); + else if (disturb_other) disturb(1); + if (blind) monster_msg("%^s makes a strange noise.", m_name); + else monster_msg("%^s fires a missile at %s.", m_name, t_name); + sound(SOUND_SHOOT); + monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(7, 6)); + break; + } + + /* RF4_BR_ACID */ + case 96 + 8: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes acid at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_ACID, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_ELEC */ + case 96 + 9: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes lightning at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_ELEC, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_FIRE */ + case 96 + 10: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes fire at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_FIRE, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_COLD */ + case 96 + 11: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes frost at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_COLD, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_POIS */ + case 96 + 12: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes gas at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_POIS, + ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_NETH */ + case 96 + 13: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes nether at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_NETHER, + ((m_ptr->hp / 6) > 550 ? 550 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_LITE */ + case 96 + 14: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes light at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_LITE, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_DARK */ + case 96 + 15: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes darkness at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_DARK, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_CONF */ + case 96 + 16: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes confusion at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_CONFUSION, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_SOUN */ + case 96 + 17: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes sound at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_SOUND, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_CHAO */ + case 96 + 18: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes chaos at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_CHAOS, + ((m_ptr->hp / 6) > 600 ? 600 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_DISE */ + case 96 + 19: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes disenchantment at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_DISENCHANT, + ((m_ptr->hp / 6) > 500 ? 500 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_NEXU */ + case 96 + 20: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes nexus at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_NEXUS, + ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_TIME */ + case 96 + 21: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes time at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_TIME, + ((m_ptr->hp / 3) > 150 ? 150 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_INER */ + case 96 + 22: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes inertia at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_INERTIA, + ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_GRAV */ + case 96 + 23: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes gravity at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_GRAVITY, + ((m_ptr->hp / 3) > 200 ? 200 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_SHAR */ + case 96 + 24: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes shards at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_SHARDS, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_PLAS */ + case 96 + 25: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes plasma at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_PLASMA, + ((m_ptr->hp / 6) > 150 ? 150 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_WALL */ + case 96 + 26: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes force at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_FORCE, + ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_MANA */ + case 96 + 27: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes magical energy at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_MANA, + ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BA_NUKE */ + case 96 + 28: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear someone mumble."); + else if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a ball of radiation at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_NUKE, + (rlev + damroll(10, 6)), 2); + break; + } + + /* RF4_BR_NUKE */ + case 96 + 29: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes toxic waste at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_NUKE, + ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BA_CHAO */ + case 96 + 30: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear someone mumble frighteningly."); + else if (blind) monster_msg("%^s mumbles frighteningly.", m_name); + else monster_msg("%^s invokes a raw Chaos upon %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_CHAOS, + (rlev * 2) + damroll(10, 10), 4); + break; + } + + /* RF4_BR_DISI -> Breathe Disintegration */ + case 96 + 31: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg("You hear breathing noise."); + else if (blind) monster_msg("%^s breathes.", m_name); + else monster_msg("%^s breathes disintegration at %s.", m_name, t_name); + sound(SOUND_BREATH); + monst_breath_monst(m_idx, y, x, GF_DISINTEGRATE, + ((m_ptr->hp / 3) > 300 ? 300 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF5_BA_ACID */ + case 128 + 0: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts an acid ball at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_ACID, randint(rlev * 3) + 15, 2); + break; + } + + /* RF5_BA_ELEC */ + case 128 + 1: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a lightning ball at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_ELEC, randint(rlev * 3 / 2) + 8, 2); + break; + } + + /* RF5_BA_FIRE */ + case 128 + 2: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a fire ball at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_FIRE, randint(rlev * 7 / 2) + 10, 2); + break; + } + + /* RF5_BA_COLD */ + case 128 + 3: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a frost ball at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_COLD, randint(rlev * 3 / 2) + 10, 2); + break; + } + + /* RF5_BA_POIS */ + case 128 + 4: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a stinking cloud at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_POIS, damroll(12, 2), 2); + break; + } + + /* RF5_BA_NETH */ + case 128 + 5: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a nether ball at %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_NETHER, (50 + damroll(10, 10) + rlev), 2); + break; + } + + /* RF5_BA_WATE */ + case 128 + 6: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble."); + else + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s gestures fluidly at %s.", m_name, t_name); + monster_msg("%^s is engulfed in a whirlpool.", t_name); + monst_breath_monst(m_idx, y, x, GF_WATER, randint(rlev * 5 / 2) + 50, 4); + break; + } + + /* RF5_BA_MANA */ + case 128 + 7: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble powerfully."); + else + if (blind) monster_msg("%^s mumbles powerfully.", m_name); + else monster_msg("%^s invokes a mana storm upon %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_MANA, (rlev * 5) + damroll(10, 10), 4); + break; + } + + /* RF5_BA_DARK */ + case 128 + 8: + { + if (disturb_other) disturb(1); + if (!see_either) monster_msg ("You hear someone mumble powerfully."); + else + if (blind) monster_msg("%^s mumbles powerfully.", m_name); + else monster_msg("%^s invokes a darkness storm upon %s.", m_name, t_name); + monst_breath_monst(m_idx, y, x, GF_DARK, (rlev * 5) + damroll(10, 10), 4); + break; + } + + /* RF5_DRAIN_MANA */ + case 128 + 9: + { + /* Attack power */ + int r1 = (randint(rlev) / 2) + 1; + + if (see_m) + { + /* Basic message */ + monster_msg("%^s draws psychic energy from %s.", m_name, t_name); + } + + /* Heal the monster */ + if (m_ptr->hp < m_ptr->maxhp) + { + if (!(tr_ptr->flags4 || tr_ptr->flags5 || tr_ptr->flags6)) + { + if (see_both) + monster_msg("%^s is unaffected!", t_name); + } + else + { + /* Heal */ + m_ptr->hp += (6 * r1); + if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp; + + /* Redraw (later) if needed */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + + /* Special message */ + if (seen) + { + monster_msg("%^s appears healthier.", m_name); + } + } + } + + wake_up = TRUE; + break; + } + + /* RF5_MIND_BLAST */ + case 128 + 10: + { + if (!direct) break; + + if (disturb_other) disturb(1); + + if (!seen) + { + /* */ + } + else + { + monster_msg("%^s gazes intently at %s.", m_name, t_name); + } + + /* Attempt a saving throw */ + if ((tr_ptr->flags1 & (RF1_UNIQUE)) || + (tr_ptr->flags3 & (RF3_NO_CONF)) || + (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) + { + /* Memorize a flag */ + if (tr_ptr->flags3 & (RF3_NO_CONF)) + { + if (seen) tr_ptr->r_flags3 |= (RF3_NO_CONF); + } + + /* No obvious effect */ + if (see_t) + { + monster_msg("%^s is unaffected!", t_name); + } + } + else + { + bool_ fear; + monster_msg("%^s is blasted by psionic energy.", t_name); + t_ptr->confused += rand_int(4) + 4; + + mon_take_hit_mon(m_idx, t_idx, damroll(8, 8), &fear, " collapses, a mindless husk."); + } + + wake_up = TRUE; + break; + } + + /* RF5_BRAIN_SMASH */ + case 128 + 11: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (!seen) + { + /* */ + } + else + { + monster_msg("%^s gazes intently at %s.", m_name, t_name); + } + + /* Attempt a saving throw */ + if ((tr_ptr->flags1 & (RF1_UNIQUE)) || + (tr_ptr->flags3 & (RF3_NO_CONF)) || + (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) + { + /* Memorize a flag */ + if (tr_ptr->flags3 & (RF3_NO_CONF)) + { + if (seen) tr_ptr->r_flags3 |= (RF3_NO_CONF); + } + /* No obvious effect */ + if (see_t) + { + monster_msg("%^s is unaffected!", t_name); + } + } + else + { + bool_ fear; + if (see_t) + { + monster_msg("%^s is blasted by psionic energy.", t_name); + } + t_ptr->confused += rand_int(4) + 4; + t_ptr->mspeed -= rand_int(4) + 4; + t_ptr->stunned += rand_int(4) + 4; + mon_take_hit_mon(m_idx, t_idx, damroll(12, 15), &fear, " collapses, a mindless husk."); + } + wake_up = TRUE; + break; + } + + /* RF5_CAUSE_1 */ + case 128 + 12: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s points at %s and curses.", m_name, t_name); + if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + + if (see_t) monster_msg("%^s resists!", t_name); + } + else + { + bool_ fear; + mon_take_hit_mon(m_idx, t_idx, damroll(3, 8), &fear, " is destroyed."); + } + wake_up = TRUE; + break; + } + + /* RF5_CAUSE_2 */ + case 128 + 13: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s points at %s and curses horribly.", m_name, t_name); + if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s resists!", t_name); + } + else + { + bool_ fear; + mon_take_hit_mon(m_idx, t_idx, damroll(8, 8), &fear, " is destroyed."); + } + wake_up = TRUE; + break; + } + + /* RF5_CAUSE_3 */ + case 128 + 14: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s points at %s, incanting terribly!", m_name, t_name); + if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s resists!", t_name); + } + else + { + bool_ fear; + mon_take_hit_mon(m_idx, t_idx, damroll(10, 15), &fear, " is destroyed."); + } + wake_up = TRUE; + break; + } + + /* RF5_CAUSE_4 */ + case 128 + 15: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s points at %s, screaming the word 'DIE!'", m_name, t_name); + if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s resists!", t_name); + } + else + { + bool_ fear; + mon_take_hit_mon(m_idx, t_idx, damroll(15, 15), &fear, " is destroyed."); + } + wake_up = TRUE; + break; + } + + /* RF5_BO_ACID */ + case 128 + 16: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts an acid bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_ACID, + damroll(7, 8) + (rlev / 3)); + break; + } + + /* RF5_BO_ELEC */ + case 128 + 17: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a lightning bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_ELEC, + damroll(4, 8) + (rlev / 3)); + break; + } + + /* RF5_BO_FIRE */ + case 128 + 18: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a fire bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_FIRE, + damroll(9, 8) + (rlev / 3)); + break; + } + + /* RF5_BO_COLD */ + case 128 + 19: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a frost bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_COLD, + damroll(6, 8) + (rlev / 3)); + break; + } + + /* RF5_BO_POIS */ + case 128 + 20: + { + /* XXX XXX XXX */ + break; + } + + /* RF5_BO_NETH */ + case 128 + 21: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a nether bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_NETHER, + 30 + damroll(5, 5) + (rlev * 3) / 2); + break; + } + + /* RF5_BO_WATE */ + case 128 + 22: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a water bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_WATER, + damroll(10, 10) + (rlev)); + break; + } + + /* RF5_BO_MANA */ + case 128 + 23: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a mana bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_MANA, + randint(rlev * 7 / 2) + 50); + break; + } + + /* RF5_BO_PLAS */ + case 128 + 24: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a plasma bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_PLASMA, + 10 + damroll(8, 7) + (rlev)); + break; + } + + /* RF5_BO_ICEE */ + case 128 + 25: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts an ice bolt at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_ICE, + damroll(6, 6) + (rlev)); + break; + } + + /* RF5_MISSILE */ + case 128 + 26: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a magic missile at %s.", m_name, t_name); + monst_bolt_monst(m_idx, y, x, GF_MISSILE, + damroll(2, 6) + (rlev / 3)); + break; + } + + /* RF5_SCARE */ + case 128 + 27: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles, and you hear scary noises.", m_name); + else monster_msg("%^s casts a fearful illusion at %s.", m_name, t_name); + if (tr_ptr->flags3 & RF3_NO_FEAR) + { + if (see_t) monster_msg("%^s refuses to be frightened.", t_name); + } + else if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s refuses to be frightened.", t_name); + } + else + { + if (!(t_ptr->monfear) && see_t) monster_msg("%^s flees in terror!", t_name); + t_ptr->monfear += rand_int(4) + 4; + } + wake_up = TRUE; + break; + } + + /* RF5_BLIND */ + case 128 + 28: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s casts a spell, burning %s%s eyes.", m_name, t_name, + (!strcmp(t_name, "it") ? "s" : "'s")); + if (tr_ptr->flags3 & RF3_NO_CONF) /* Simulate blindness with confusion */ + { + if (see_t) monster_msg("%^s is unaffected.", t_name); + } + else if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s is unaffected.", t_name); + } + else + { + if (see_t) monster_msg("%^s is blinded!", t_name); + t_ptr->confused += 12 + (byte)rand_int(4); + } + wake_up = TRUE; + break; + + } + + /* RF5_CONF */ + case 128 + 29: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles, and you hear puzzling noises.", m_name); + else monster_msg("%^s creates a mesmerising illusion in front of %s.", m_name, t_name); + if (tr_ptr->flags3 & RF3_NO_CONF) + { + if (see_t) monster_msg("%^s disbelieves the feeble spell.", t_name); + } + else if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s disbelieves the feeble spell.", t_name); + } + else + { + if (see_t) monster_msg("%^s seems confused.", t_name); + t_ptr->confused += 12 + (byte)rand_int(4); + } + wake_up = TRUE; + break; + } + + /* RF5_SLOW */ + case 128 + 30: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (!blind && see_either) monster_msg("%^s drains power from %s%s muscles.", m_name, t_name, + (!strcmp(t_name, "it") ? "s" : "'s")); + if (tr_ptr->flags1 & RF1_UNIQUE) + { + if (see_t) monster_msg("%^s is unaffected.", t_name); + } + else if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s is unaffected.", t_name); + } + else + { + t_ptr->mspeed -= 10; + if (see_t) monster_msg("%^s starts moving slower.", t_name); + } + wake_up = TRUE; + break; + } + + /* RF5_HOLD */ + case 128 + 31: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (!blind && see_m) monster_msg("%^s stares intently at %s.", m_name, t_name); + if ((tr_ptr->flags1 & RF1_UNIQUE) || + (tr_ptr->flags3 & RF3_NO_STUN)) + { + if (see_t) monster_msg("%^s is unaffected.", t_name); + } + else if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) + { + if (see_t) monster_msg("%^s is unaffected.", t_name); + } + else + { + t_ptr->stunned += randint(4) + 4; + if (see_t) monster_msg("%^s is paralyzed!", t_name); + } + wake_up = TRUE; + break; + } + + + /* RF6_HASTE */ + case 160 + 0: + { + if (disturb_other) disturb(1); + if (blind || !see_m) + { + monster_msg("%^s mumbles.", m_name); + } + else + { + monster_msg("%^s concentrates on %s body.", m_name, m_poss); + } + + /* Allow quick speed increases to base+10 */ + if (m_ptr->mspeed < m_ptr->speed + 10) + { + if (see_m) monster_msg("%^s starts moving faster.", m_name); + m_ptr->mspeed += 10; + } + + /* Allow small speed increases to base+20 */ + else if (m_ptr->mspeed < m_ptr->speed + 20) + { + if (see_m) monster_msg("%^s starts moving faster.", m_name); + m_ptr->mspeed += 2; + } + + break; + } + + /* RF6_HAND_DOOM */ + case 160 + 1: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (!see_m) monster_msg("You hear someone invoke the Hand of Doom!"); + else if (!blind) monster_msg("%^s invokes the Hand of Doom on %s.", m_name, t_name); + else + monster_msg ("You hear someone invoke the Hand of Doom!"); + if (tr_ptr->flags1 & RF1_UNIQUE) + { + if (!blind && see_t) monster_msg("^%s is unaffected!", t_name); + } + else + { + if (((m_ptr->level) + randint(20)) > + ((t_ptr->level) + 10 + randint(20))) + { + t_ptr->hp = t_ptr->hp + - (((s32b) ((65 + randint(25)) * (t_ptr->hp))) / 100); + if (t_ptr->hp < 1) t_ptr->hp = 1; + } + else + { + if (see_t) monster_msg("%^s resists!", t_name); + } + } + + wake_up = TRUE; + break; + } + + /* RF6_HEAL */ + case 160 + 2: + { + if (disturb_other) disturb(1); + + /* Message */ + if (blind || !see_m) + { + monster_msg("%^s mumbles.", m_name); + } + else + { + monster_msg("%^s concentrates on %s wounds.", m_name, m_poss); + } + + /* Heal some */ + m_ptr->hp += (rlev * 6); + + /* Fully healed */ + if (m_ptr->hp >= m_ptr->maxhp) + { + /* Fully healed */ + m_ptr->hp = m_ptr->maxhp; + + /* Message */ + if (seen) + { + monster_msg("%^s looks completely healed!", m_name); + } + else + { + monster_msg("%^s sounds completely healed!", m_name); + } + } + + /* Partially healed */ + else + { + /* Message */ + if (seen) + { + monster_msg("%^s looks healthier.", m_name); + } + else + { + monster_msg("%^s sounds healthier.", m_name); + } + } + + /* Redraw (later) if needed */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + + /* Cancel fear */ + if (m_ptr->monfear) + { + /* Cancel fear */ + m_ptr->monfear = 0; + + /* Message */ + if (see_m) monster_msg("%^s recovers %s courage.", m_name, m_poss); + } + + break; + } + + /* RF6_S_ANIMALS */ + case 160 + 3: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons some animals!", m_name); + for (k = 0; k < 4; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_ANIMAL); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_BLINK */ + case 160 + 4: + { + if (disturb_other) disturb(1); + if (see_m) monster_msg("%^s blinks away.", m_name); + teleport_away(m_idx, 10); + break; + } + + /* RF6_TPORT */ + case 160 + 5: + { + if (dungeon_flags2 & DF2_NO_TELEPORT) break; /* No teleport on special levels */ + else + { + if (disturb_other) disturb(1); + if (see_m) monster_msg("%^s teleports away.", m_name); + teleport_away(m_idx, MAX_SIGHT * 2 + 5); + break; + } + } + + /* RF6_TELE_TO */ + case 160 + 6: + { + /* Not implemented */ + break; + } + + /* RF6_TELE_AWAY */ + case 160 + 7: + { + if (dungeon_flags2 & DF2_NO_TELEPORT) break; + + if (!direct) break; + else + { + bool_ resists_tele = FALSE; + if (disturb_other) disturb(1); + monster_msg("%^s teleports %s away.", m_name, t_name); + + + if (tr_ptr->flags3 & (RF3_RES_TELE)) + { + if (tr_ptr->flags1 & (RF1_UNIQUE)) + { + if (see_t) + { + tr_ptr->r_flags3 |= RF3_RES_TELE; + monster_msg("%^s is unaffected!", t_name); + } + resists_tele = TRUE; + } + else if (t_ptr->level > randint(100)) + { + if (see_t) + { + tr_ptr->r_flags3 |= RF3_RES_TELE; + monster_msg("%^s resists!", t_name); + } + resists_tele = TRUE; + } + } + + if (!resists_tele) + { + teleport_away(t_idx, MAX_SIGHT * 2 + 5); + } + } + + break; + } + + /* RF6_TELE_LEVEL */ + case 160 + 8: + { + /* Not implemented */ + break; + } + + /* RF6_DARKNESS */ + case 160 + 9: + { + if (!direct) break; + if (disturb_other) disturb(1); + if (blind) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s gestures in shadow.", m_name); + if (seen) + monster_msg("%^s is surrounded by darkness.", t_name); + (void)project(m_idx, 3, y, x, 0, GF_DARK_WEAK, PROJECT_GRID | PROJECT_KILL); + /* Lite up the room */ + unlite_room(y, x); + break; + } + + /* RF6_TRAPS */ + case 160 + 10: + { + /* Not implemented */ + break; + } + + /* RF6_FORGET */ + case 160 + 11: + { + /* Not implemented */ + break; + } + + /* RF6_ANIM_DEAD */ + case 160 + 12: + { + break; + } + + /* RF6_S_BUG */ + case 160 + 13: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically codes some software bugs.", m_name); + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_BUG, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_BUG); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_S_RNG */ + case 160 + 14: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically codes some RNGs.", m_name); + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_RNG, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_RNG); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + + /* RF6_S_THUNDERLORD */ + case 160 + 15: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons a Thunderlord!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_THUNDERLORD); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF6_SUMMON_KIN */ + case 160 + 16: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons %s %s.", + m_name, m_poss, + ((r_ptr->flags1) & RF1_UNIQUE ? + "minions" : "kin")); + summon_kin_type = r_ptr->d_char; /* Big hack */ + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_KIN, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_KIN); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + + + break; + } + + /* RF6_S_HI_DEMON */ + case 160 + 17: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons greater demons!", m_name); + if (blind && count) monster_msg("You hear heavy steps nearby."); + if (friendly) + summon_specific_friendly(y, x, rlev, SUMMON_HI_DEMON, TRUE); + else + summon_cyber(); + break; + } + + /* RF6_S_MONSTER */ + case 160 + 18: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons help!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE); + else + count += summon_specific(y, x, rlev, 0); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF6_S_MONSTERS */ + case 160 + 19: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons monsters!", m_name); + for (k = 0; k < 8; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE); + else + count += summon_specific(y, x, rlev, 0); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_S_ANT */ + case 160 + 20: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons ants.", m_name); + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_ANT, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_ANT); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_S_SPIDER */ + case 160 + 21: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons spiders.", m_name); + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_SPIDER); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_S_HOUND */ + case 160 + 22: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons hounds.", m_name); + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_HOUND, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_HOUND); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_S_HYDRA */ + case 160 + 23: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons hydras.", m_name); + for (k = 0; k < 6; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_HYDRA); + } + if (blind && count) monster_msg("You hear many things appear nearby."); + break; + } + + /* RF6_S_ANGEL */ + case 160 + 24: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons an angel!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_ANGEL); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF6_S_DEMON */ + case 160 + 25: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons a demon!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_DEMON, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_DEMON); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF6_S_UNDEAD */ + case 160 + 26: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons an undead adversary!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_UNDEAD); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF6_S_DRAGON */ + case 160 + 27: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons a dragon!", m_name); + for (k = 0; k < 1; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_DRAGON); + } + if (blind && count) monster_msg("You hear something appear nearby."); + break; + } + + /* RF6_S_HI_UNDEAD */ + case 160 + 28: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons greater undead!", m_name); + for (k = 0; k < 8; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + } + if (blind && count) + { + monster_msg("You hear many creepy things appear nearby."); + } + break; + } + + /* RF6_S_HI_DRAGON */ + case 160 + 29: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons ancient dragons!", m_name); + for (k = 0; k < 8; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_HI_DRAGON); + } + if (blind && count) + { + monster_msg("You hear many powerful things appear nearby."); + } + break; + } + + /* RF6_S_WRAITH */ + case 160 + 30: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons a wraith!", m_name); + + + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, SUMMON_WRAITH); + } + + if (blind && count) + { + monster_msg("You hear immortal beings appear nearby."); + } + break; + } + + /* RF6_S_UNIQUE */ + case 160 + 31: + { + if (disturb_other) disturb(1); + if (blind || !see_m) monster_msg("%^s mumbles.", m_name); + else monster_msg("%^s magically summons special opponents!", m_name); + for (k = 0; k < 8; k++) + { + if (!friendly) + count += summon_specific(y, x, rlev, SUMMON_UNIQUE); + } + for (k = 0; k < 8; k++) + { + if (friendly) + count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); + else + count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + } + if (blind && count) + { + monster_msg("You hear many powerful things appear nearby."); + } + break; + } + } + + if (wake_up) + { + t_ptr->csleep = 0; + } + + + /* Remember what the monster did, if we saw it */ + if (seen) + { + /* Inate spell */ + if (thrown_spell < 32*4) + { + r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3)); + if (r_ptr->r_cast_inate < MAX_UCHAR) r_ptr->r_cast_inate++; + } + + /* Bolt or Ball */ + else if (thrown_spell < 32*5) + { + r_ptr->r_flags5 |= (1L << (thrown_spell - 32 * 4)); + if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; + } + + /* Special spell */ + else if (thrown_spell < 32*6) + { + r_ptr->r_flags6 |= (1L << (thrown_spell - 32 * 5)); + if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; + } + } + + /* Always take note of monsters that kill you --- + * even accidentally */ + if (death && (r_ptr->r_deaths < MAX_SHORT)) + { + r_ptr->r_deaths++; + } + + /* A spell was cast */ + return (TRUE); + } + + /* No enemy found */ + return (FALSE); +} + + +void curse_equipment(int chance, int heavy_chance) +{ + bool_ changed = FALSE; + u32b o1, o2, o3, o4, esp, o5; + object_type * o_ptr = + &p_ptr->inventory[rand_range(INVEN_WIELD, INVEN_TOTAL - 1)]; + + if (randint(100) > chance) return; + + if (!(o_ptr->k_idx)) return; + + object_flags(o_ptr, &o1, &o2, &o3, &o4, &o5, &esp); + + + /* Extra, biased saving throw for blessed items */ + if ((o3 & (TR3_BLESSED)) && (randint(888) > chance)) + { + char o_name[256]; + object_desc(o_name, o_ptr, FALSE, 0); + msg_format("Your %s resist%s cursing!", o_name, + ((o_ptr->number > 1) ? "" : "s")); + /* Hmmm -- can we wear multiple items? If not, this is unnecessary */ + return; + } + + if ((randint(100) <= heavy_chance) && + (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name)) + { + if (!(o3 & TR3_HEAVY_CURSE)) + changed = TRUE; + o_ptr->art_flags3 |= TR3_HEAVY_CURSE; + o_ptr->art_flags3 |= TR3_CURSED; + o_ptr->ident |= IDENT_CURSED; + } + else + { + if (!(o_ptr->ident & (IDENT_CURSED))) + changed = TRUE; + o_ptr->art_flags3 |= TR3_CURSED; + o_ptr->ident |= IDENT_CURSED; + } + + if (changed) + { + msg_print("There is a malignant black aura surrounding you..."); + if (o_ptr->note) + { + if (streq(quark_str(o_ptr->note), "uncursed")) + { + o_ptr->note = 0; + } + } + } +} + + +void curse_equipment_dg(int chance, int heavy_chance) +{ + bool_ changed = FALSE; + u32b o1, o2, o3, o4, esp, o5; + object_type * o_ptr = + &p_ptr->inventory[rand_range(INVEN_WIELD, INVEN_TOTAL - 1)]; + + if (randint(100) > chance) return; + + if (!(o_ptr->k_idx)) return; + + object_flags(o_ptr, &o1, &o2, &o3, &o4, &o5, &esp); + + + /* Extra, biased saving throw for blessed items */ + if ((o3 & (TR3_BLESSED)) && (randint(888) > chance)) + { + char o_name[256]; + object_desc(o_name, o_ptr, FALSE, 0); + msg_format("Your %s resist%s cursing!", o_name, + ((o_ptr->number > 1) ? "" : "s")); + /* Hmmm -- can we wear multiple items? If not, this is unnecessary */ + /* DG -- Yes we can, in the quiver */ + return; + } + + if ((randint(100) <= heavy_chance) && + (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name)) + { + if (!(o3 & TR3_HEAVY_CURSE)) + changed = TRUE; + o_ptr->art_flags3 |= TR3_HEAVY_CURSE; + o_ptr->art_flags3 |= TR3_CURSED; + o_ptr->art_flags4 |= TR4_DG_CURSE; + o_ptr->ident |= IDENT_CURSED; + } + else + { + if (!(o_ptr->ident & (IDENT_CURSED))) + changed = TRUE; + o_ptr->art_flags3 |= TR3_CURSED; + o_ptr->art_flags4 |= TR4_DG_CURSE; + o_ptr->ident |= IDENT_CURSED; + } + + if (changed) + { + msg_print("There is a malignant black aura surrounding you..."); + if (o_ptr->note) + { + if (streq(quark_str(o_ptr->note), "uncursed")) + { + o_ptr->note = 0; + } + } + } +} + + +/* + * Creatures can cast spells, shoot missiles, and breathe. + * + * Returns "TRUE" if a spell (or whatever) was (successfully) cast. + * + * XXX XXX XXX This function could use some work, but remember to + * keep it as optimized as possible, while retaining generic code. + * + * Verify the various "blind-ness" checks in the code. + * + * XXX XXX XXX Note that several effects should really not be "seen" + * if the player is blind. See also "effects.c" for other "mistakes". + * + * Perhaps monsters should breathe at locations *near* the player, + * since this would allow them to inflict "partial" damage. + * + * Perhaps smart monsters should decline to use "bolt" spells if + * there is a monster in the way, unless they wish to kill it. + * + * Note that, to allow the use of the "track_target" option at some + * later time, certain non-optimal things are done in the code below, + * including explicit checks against the "direct" variable, which is + * currently always true by the time it is checked, but which should + * really be set according to an explicit "projectable()" test, and + * the use of generic "x,y" locations instead of the player location, + * with those values being initialized with the player location. + * + * It will not be possible to "correctly" handle the case in which a + * monster attempts to attack a location which is thought to contain + * the player, but which in fact is nowhere near the player, since this + * might induce all sorts of messages about the attack itself, and about + * the effects of the attack, which the player might or might not be in + * a position to observe. Thus, for simplicity, it is probably best to + * only allow "faulty" attacks by a monster if one of the important grids + * (probably the initial or final grid) is in fact in view of the player. + * It may be necessary to actually prevent spell attacks except when the + * monster actually has line of sight to the player. Note that a monster + * could be left in a bizarre situation after the player ducked behind a + * pillar and then teleported away, for example. + * + * Note that certain spell attacks do not use the "project()" function + * but "simulate" it via the "direct" variable, which is always at least + * as restrictive as the "project()" function. This is necessary to + * prevent "blindness" attacks and such from bending around walls, etc, + * and to allow the use of the "track_target" option in the future. + * + * Note that this function attempts to optimize the use of spells for the + * cases in which the monster has no spells, or has spells but cannot use + * them, or has spells but they will have no "useful" effect. Note that + * this function has been an efficiency bottleneck in the past. + * + * Note the special "MFLAG_NICE" flag, which prevents a monster from using + * any spell attacks until the player has had a single chance to move. + */ +bool_ make_attack_spell(int m_idx) +{ + int k, chance, thrown_spell, rlev, failrate; + byte spell[96], num = 0; + u32b f4, f5, f6; + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + char m_name[80]; + bool_ no_inate = FALSE; + int x, y; + + /* Summon count */ + int count = 0; + + /* Extract the blind-ness */ + bool_ blind = (p_ptr->blind ? TRUE : FALSE); + + /* Extract the "see-able-ness" */ + bool_ seen = (!blind && m_ptr->ml); + + /* Assume "normal" target */ + bool_ normal = TRUE; + + /* Assume "projectable" */ + bool_ direct = TRUE; + + /* Target location */ + if (m_ptr->target > -1) + { + if (!m_ptr->target) + { + y = p_ptr->py; + x = p_ptr->px; + } + else + { + return (FALSE); + } + } + else return FALSE; + + /* Cannot cast spells when confused */ + if (m_ptr->confused) return (FALSE); + + /* Cannot cast spells when nice */ + if (m_ptr->mflag & (MFLAG_NICE)) return (FALSE); + if (is_friend(m_ptr) >= 0) return (FALSE); + + /* Cannot attack the player if mortal and player fated to never die by the ... */ + if ((r_ptr->flags7 & RF7_MORTAL) && (p_ptr->no_mortal)) return (FALSE); + + /* Hack -- Extract the spell probability */ + chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2; + + /* Not allowed to cast spells */ + if (!chance) return (FALSE); + + /* Only do spells occasionally */ + if (rand_int(100) >= chance) return (FALSE); + + /* Sometimes forbid inate attacks (breaths) */ + if (rand_int(100) >= (chance * 2)) no_inate = TRUE; + + /* XXX XXX XXX Handle "track_target" option (?) */ + + + /* Hack -- require projectable player */ + if (normal) + { + /* Check range */ + if (m_ptr->cdis > MAX_RANGE) return (FALSE); + + /* Check path */ + if (!projectable(m_ptr->fy, m_ptr->fx, y, x)) return (FALSE); + } + + /* Extract the monster level */ + rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); + + /* Extract the racial spell flags */ + f4 = r_ptr->flags4; + f5 = r_ptr->flags5; + f6 = r_ptr->flags6; + + /* Forbid inate attacks sometimes */ + if (no_inate) f4 = 0L; + + /* Hack -- allow "desperate" spells */ + if ((r_ptr->flags2 & (RF2_SMART)) && + (m_ptr->hp < m_ptr->maxhp / 10) && + (rand_int(100) < 50)) + { + /* Require intelligent spells */ + f4 &= (RF4_INT_MASK); + f5 &= (RF5_INT_MASK); + f6 &= (RF6_INT_MASK); + + /* No spells left */ + if (!f4 && !f5 && !f6) return (FALSE); + } + + /* Remove the "ineffective" spells */ + remove_bad_spells(m_idx, &f4, &f5, &f6); + + /* No spells left */ + if (!f4 && !f5 && !f6) return (FALSE); + + /* Check for a clean bolt shot */ + if ((f4&(RF4_BOLT_MASK) || f5 & (RF5_BOLT_MASK) || + f6&(RF6_BOLT_MASK)) && + !(r_ptr->flags2 & (RF2_STUPID)) && + !clean_shot(m_ptr->fy, m_ptr->fx, y, x)) + { + /* Remove spells that will only hurt friends */ + f4 &= ~(RF4_BOLT_MASK); + f5 &= ~(RF5_BOLT_MASK); + f6 &= ~(RF6_BOLT_MASK); + } + + /* Check for a possible summon */ + if ((f4 & (RF4_SUMMON_MASK) || f5 & (RF5_SUMMON_MASK) || + f6 & (RF6_SUMMON_MASK)) && + !(r_ptr->flags2 & (RF2_STUPID)) && + !(summon_possible(y, x))) + { + /* Remove summoning spells */ + f4 &= ~(RF4_SUMMON_MASK); + f5 &= ~(RF5_SUMMON_MASK); + f6 &= ~(RF6_SUMMON_MASK); + } + + /* No spells left */ + if (!f4 && !f5 && !f6) return (FALSE); + + /* Extract the "inate" spells */ + for (k = 0; k < 32; k++) + { + if (f4 & (1L << k)) spell[num++] = k + 32 * 3; + } + + /* Extract the "normal" spells */ + for (k = 0; k < 32; k++) + { + if (f5 & (1L << k)) spell[num++] = k + 32 * 4; + } + + /* Extract the "bizarre" spells */ + for (k = 0; k < 32; k++) + { + if (f6 & (1L << k)) spell[num++] = k + 32 * 5; + } + + /* No spells left */ + if (!num) return (FALSE); + + /* Stop if player is dead or gone */ + if (!alive || death) return (FALSE); + + /* Stop if player is leaving */ + if (p_ptr->leaving) return (FALSE); + + /* Get the monster name (or "it") */ + monster_desc(m_name, m_ptr, 0x00); + + /* Choose a spell to cast */ + thrown_spell = choose_attack_spell(m_idx, spell, num); + + /* Abort if no spell was chosen */ + if (!thrown_spell) return (FALSE); + + /* Calculate spell failure rate */ + failrate = 25 - (rlev + 3) / 4; + + /* Hack -- Stupid monsters will never fail (for jellies and such) */ + if (r_ptr->flags2 & (RF2_STUPID)) failrate = 0; + + /* Check for spell failure (inate attacks never fail) */ + if ((thrown_spell >= 128) && (rand_int(100) < failrate)) + { + /* Message */ + msg_format("%^s tries to cast a spell, but fails.", m_name); + + return (TRUE); + } + + /* Can the player disrupt its puny attempts? */ + if ((p_ptr->antimagic_dis >= m_ptr->cdis) && (magik(p_ptr->antimagic)) && (thrown_spell >= 128)) + { + char m_poss[80]; + + /* Get monster's possessive noun form ("the Illusionist's") */ + monster_desc(m_poss, m_ptr, 0x06); + + msg_format("Your anti-magic field disrupts %s spell.", m_poss); + } + else + { + char m_poss[80]; + char ddesc[80]; + + /* Get the monster possessive ("his"/"her"/"its") */ + monster_desc(m_poss, m_ptr, 0x22); + + /* Hack -- Get the "died from" name */ + monster_desc(ddesc, m_ptr, 0x88); + + /* Cast the spell. */ + switch (thrown_spell) + { + /* RF4_SHRIEK */ + case 96 + 0: + { + if (!direct) break; + disturb(1); + msg_format("%^s makes a high pitched shriek.", m_name); + aggravate_monsters(m_idx); + break; + } + + /* RF4_MULTIPLY */ + case 96 + 1: + { + break; + } + + /* RF4_S_ANIMAL */ + case 96 + 2: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons an animal!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, SUMMON_ANIMAL); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF4_ROCKET */ + case 96 + 3: + { + disturb(1); + if (blind) msg_format("%^s shoots something.", m_name); + else msg_format("%^s fires a rocket.", m_name); + breath(m_idx, GF_ROCKET, + ((m_ptr->hp / 4) > 800 ? 800 : (m_ptr->hp / 4)), 2); + update_smart_learn(m_idx, DRS_SHARD); + break; + } + + /* RF4_ARROW_1 */ + case 96 + 4: + { + disturb(1); + if (blind) msg_format("%^s makes a strange noise.", m_name); + else msg_format("%^s fires an arrow.", m_name); + bolt(m_idx, GF_ARROW, damroll(1, 6)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF4_ARROW_2 */ + case 96 + 5: + { + disturb(1); + if (blind) msg_format("%^s makes a strange noise.", m_name); + else msg_format("%^s fires an arrow!", m_name); + bolt(m_idx, GF_ARROW, damroll(3, 6)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF4_ARROW_3 */ + case 96 + 6: + { + disturb(1); + if (blind) msg_format("%^s makes a strange noise.", m_name); + else msg_format("%^s fires a missile.", m_name); + bolt(m_idx, GF_ARROW, damroll(5, 6)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF4_ARROW_4 */ + case 96 + 7: + { + disturb(1); + if (blind) msg_format("%^s makes a strange noise.", m_name); + else msg_format("%^s fires a missile!", m_name); + bolt(m_idx, GF_ARROW, damroll(7, 6)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF4_BR_ACID */ + case 96 + 8: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes acid.", m_name); + breath(m_idx, GF_ACID, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_ACID); + break; + } + + /* RF4_BR_ELEC */ + case 96 + 9: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes lightning.", m_name); + breath(m_idx, GF_ELEC, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_ELEC); + break; + } + + /* RF4_BR_FIRE */ + case 96 + 10: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes fire.", m_name); + breath(m_idx, GF_FIRE, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_FIRE); + break; + } + + /* RF4_BR_COLD */ + case 96 + 11: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes frost.", m_name); + breath(m_idx, GF_COLD, + ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_COLD); + break; + } + + /* RF4_BR_POIS */ + case 96 + 12: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes gas.", m_name); + breath(m_idx, GF_POIS, + ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_POIS); + break; + } + + + /* RF4_BR_NETH */ + case 96 + 13: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes nether.", m_name); + breath(m_idx, GF_NETHER, + ((m_ptr->hp / 6) > 550 ? 550 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_NETH); + break; + } + + /* RF4_BR_LITE */ + case 96 + 14: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes light.", m_name); + breath(m_idx, GF_LITE, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_LITE); + break; + } + + /* RF4_BR_DARK */ + case 96 + 15: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes darkness.", m_name); + breath(m_idx, GF_DARK, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_DARK); + break; + } + + /* RF4_BR_CONF */ + case 96 + 16: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes confusion.", m_name); + breath(m_idx, GF_CONFUSION, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_CONF); + break; + } + + /* RF4_BR_SOUN */ + case 96 + 17: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes sound.", m_name); + breath(m_idx, GF_SOUND, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_SOUND); + break; + } + + /* RF4_BR_CHAO */ + case 96 + 18: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes chaos.", m_name); + breath(m_idx, GF_CHAOS, + ((m_ptr->hp / 6) > 600 ? 600 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_CHAOS); + break; + } + + /* RF4_BR_DISE */ + case 96 + 19: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes disenchantment.", m_name); + breath(m_idx, GF_DISENCHANT, + ((m_ptr->hp / 6) > 500 ? 500 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_DISEN); + break; + } + + /* RF4_BR_NEXU */ + case 96 + 20: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes nexus.", m_name); + breath(m_idx, GF_NEXUS, + ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_NEXUS); + break; + } + + /* RF4_BR_TIME */ + case 96 + 21: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes time.", m_name); + breath(m_idx, GF_TIME, + ((m_ptr->hp / 3) > 150 ? 150 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_INER */ + case 96 + 22: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes inertia.", m_name); + breath(m_idx, GF_INERTIA, + ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_GRAV */ + case 96 + 23: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes gravity.", m_name); + breath(m_idx, GF_GRAVITY, + ((m_ptr->hp / 3) > 200 ? 200 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BR_SHAR */ + case 96 + 24: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes shards.", m_name); + breath(m_idx, GF_SHARDS, + ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + update_smart_learn(m_idx, DRS_SHARD); + break; + } + + /* RF4_BR_PLAS */ + case 96 + 25: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes plasma.", m_name); + breath(m_idx, GF_PLASMA, + ((m_ptr->hp / 6) > 150 ? 150 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_WALL */ + case 96 + 26: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes force.", m_name); + breath(m_idx, GF_FORCE, + ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + break; + } + + /* RF4_BR_MANA */ + case 96 + 27: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes magical energy.", m_name); + breath(m_idx, GF_MANA, + ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + break; + } + + /* RF4_BA_NUKE */ + case 96 + 28: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a ball of radiation.", m_name); + breath(m_idx, GF_NUKE, (rlev + damroll(10, 6)), 2); + update_smart_learn(m_idx, DRS_POIS); + break; + } + + /* RF4_BR_NUKE */ + case 96 + 29: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes toxic waste.", m_name); + breath(m_idx, GF_NUKE, + ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); + update_smart_learn(m_idx, DRS_POIS); + break; + } + + /* RF4_BA_CHAO */ + case 96 + 30: + { + disturb(1); + if (blind) msg_format("%^s mumbles frighteningly.", m_name); + else msg_format("%^s invokes a raw chaos.", m_name); + breath(m_idx, GF_CHAOS, (rlev * 2) + damroll(10, 10), 4); + update_smart_learn(m_idx, DRS_CHAOS); + break; + } + + /* RF4_BR_DISI -> Disintegration breath! */ + case 96 + 31: + { + disturb(1); + if (blind) msg_format("%^s breathes.", m_name); + else msg_format("%^s breathes disintegration.", m_name); + breath(m_idx, GF_DISINTEGRATE, + ((m_ptr->hp / 3) > 300 ? 300 : (m_ptr->hp / 3)), 0); + break; + } + + + + /* RF5_BA_ACID */ + case 128 + 0: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts an acid ball.", m_name); + breath(m_idx, GF_ACID, + randint(rlev * 3) + 15, 2); + update_smart_learn(m_idx, DRS_ACID); + break; + } + + /* RF5_BA_ELEC */ + case 128 + 1: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a lightning ball.", m_name); + breath(m_idx, GF_ELEC, + randint(rlev * 3 / 2) + 8, 2); + update_smart_learn(m_idx, DRS_ELEC); + break; + } + + /* RF5_BA_FIRE */ + case 128 + 2: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a fire ball.", m_name); + breath(m_idx, GF_FIRE, + randint(rlev * 7 / 2) + 10, 2); + update_smart_learn(m_idx, DRS_FIRE); + break; + } + + /* RF5_BA_COLD */ + case 128 + 3: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a frost ball.", m_name); + breath(m_idx, GF_COLD, + randint(rlev * 3 / 2) + 10, 2); + update_smart_learn(m_idx, DRS_COLD); + break; + } + + /* RF5_BA_POIS */ + case 128 + 4: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a stinking cloud.", m_name); + breath(m_idx, GF_POIS, + damroll(12, 2), 2); + update_smart_learn(m_idx, DRS_POIS); + break; + } + + /* RF5_BA_NETH */ + case 128 + 5: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a nether ball.", m_name); + breath(m_idx, GF_NETHER, + (50 + damroll(10, 10) + rlev), 2); + update_smart_learn(m_idx, DRS_NETH); + break; + } + + /* RF5_BA_WATE */ + case 128 + 6: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s gestures fluidly.", m_name); + msg_print("You are engulfed in a whirlpool."); + breath(m_idx, GF_WATER, + randint(rlev * 5 / 2) + 50, 4); + break; + } + + /* RF5_BA_MANA */ + case 128 + 7: + { + disturb(1); + if (blind) msg_format("%^s mumbles powerfully.", m_name); + else msg_format("%^s invokes a mana storm.", m_name); + breath(m_idx, GF_MANA, + (rlev * 5) + damroll(10, 10), 4); + break; + } + + /* RF5_BA_DARK */ + case 128 + 8: + { + disturb(1); + if (blind) msg_format("%^s mumbles powerfully.", m_name); + else msg_format("%^s invokes a darkness storm.", m_name); + breath(m_idx, GF_DARK, + (rlev * 5) + damroll(10, 10), 4); + update_smart_learn(m_idx, DRS_DARK); + break; + } + + /* RF5_DRAIN_MANA */ + case 128 + 9: + { + if (!direct) break; + if (p_ptr->csp) + { + int r1; + + /* Disturb if legal */ + disturb(1); + + /* Basic message */ + msg_format("%^s draws psychic energy from you!", m_name); + + /* Attack power */ + r1 = (randint(rlev) / 2) + 1; + + /* Full drain */ + if (r1 >= p_ptr->csp) + { + r1 = p_ptr->csp; + p_ptr->csp = 0; + p_ptr->csp_frac = 0; + } + + /* Partial drain */ + else + { + p_ptr->csp -= r1; + } + + /* Redraw mana */ + p_ptr->redraw |= (PR_MANA); + + /* Window stuff */ + p_ptr->window |= (PW_PLAYER); + + /* Heal the monster */ + if (m_ptr->hp < m_ptr->maxhp) + { + /* Heal */ + m_ptr->hp += (6 * r1); + if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp; + + /* Redraw (later) if needed */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + + /* Special message */ + if (seen) + { + msg_format("%^s appears healthier.", m_name); + } + } + } + update_smart_learn(m_idx, DRS_MANA); + break; + } + + /* RF5_MIND_BLAST */ + case 128 + 10: + { + if (!direct) break; + disturb(1); + if (!seen) + { + msg_print("You feel something focusing on your mind."); + } + else + { + msg_format("%^s gazes deep into your eyes.", m_name); + } + + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + msg_print("Your mind is blasted by psionic energy."); + + if (!p_ptr->resist_conf) + { + (void)set_confused(p_ptr->confused + rand_int(4) + 4); + } + + if ((!p_ptr->resist_chaos) && (randint(3) == 1)) + { + (void) set_image(p_ptr->image + rand_int(250) + 150); + } + + take_sanity_hit(damroll(8, 8), ddesc); + } + break; + } + + /* RF5_BRAIN_SMASH */ + case 128 + 11: + { + if (!direct) break; + disturb(1); + if (!seen) + { + msg_print("You feel something focusing on your mind."); + } + else + { + msg_format("%^s looks deep into your eyes.", m_name); + } + + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + msg_print("Your mind is blasted by psionic energy."); + take_sanity_hit(damroll(12, 15), ddesc); + if (!p_ptr->resist_blind) + { + (void)set_blind(p_ptr->blind + 8 + rand_int(8)); + } + if (!p_ptr->resist_conf) + { + (void)set_confused(p_ptr->confused + rand_int(4) + 4); + } + if (!p_ptr->free_act) + { + (void)set_paralyzed(rand_int(4) + 4); + } + (void)set_slow(p_ptr->slow + rand_int(4) + 4); + + while (rand_int(100) > p_ptr->skill_sav) + (void)do_dec_stat(A_INT, STAT_DEC_NORMAL); + while (rand_int(100) > p_ptr->skill_sav) + (void)do_dec_stat(A_WIS, STAT_DEC_NORMAL); + + if (!p_ptr->resist_chaos) + { + (void) set_image(p_ptr->image + rand_int(250) + 150); + } + } + break; + } + + /* RF5_CAUSE_1 */ + case 128 + 12: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s points at you and curses.", m_name); + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + curse_equipment(33, 0); + take_hit(damroll(3, 8), ddesc); + } + break; + } + + /* RF5_CAUSE_2 */ + case 128 + 13: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s points at you and curses horribly.", m_name); + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + curse_equipment(50, 5); + take_hit(damroll(8, 8), ddesc); + } + break; + } + + /* RF5_CAUSE_3 */ + case 128 + 14: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles loudly.", m_name); + else msg_format("%^s points at you, incanting terribly!", m_name); + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + curse_equipment(80, 15); + take_hit(damroll(10, 15), ddesc); + } + break; + } + + /* RF5_CAUSE_4 */ + case 128 + 15: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s screams the word 'DIE!'", m_name); + else msg_format("%^s points at you, screaming the word DIE!", m_name); + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + take_hit(damroll(15, 15), ddesc); + (void)set_cut(p_ptr->cut + damroll(10, 10)); + } + break; + } + + /* RF5_BO_ACID */ + case 128 + 16: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a acid bolt.", m_name); + bolt(m_idx, GF_ACID, damroll(7, 8) + (rlev / 3)); + update_smart_learn(m_idx, DRS_ACID); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_ELEC */ + case 128 + 17: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a lightning bolt.", m_name); + bolt(m_idx, GF_ELEC, damroll(4, 8) + (rlev / 3)); + update_smart_learn(m_idx, DRS_ELEC); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_FIRE */ + case 128 + 18: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a fire bolt.", m_name); + bolt(m_idx, GF_FIRE, damroll(9, 8) + (rlev / 3)); + update_smart_learn(m_idx, DRS_FIRE); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_COLD */ + case 128 + 19: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a frost bolt.", m_name); + bolt(m_idx, GF_COLD, damroll(6, 8) + (rlev / 3)); + update_smart_learn(m_idx, DRS_COLD); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_POIS */ + case 128 + 20: + { + /* XXX XXX XXX */ + break; + } + + /* RF5_BO_NETH */ + case 128 + 21: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a nether bolt.", m_name); + bolt(m_idx, GF_NETHER, 30 + damroll(5, 5) + (rlev * 3) / 2); + update_smart_learn(m_idx, DRS_NETH); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_WATE */ + case 128 + 22: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a water bolt.", m_name); + bolt(m_idx, GF_WATER, damroll(10, 10) + (rlev)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_MANA */ + case 128 + 23: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a mana bolt.", m_name); + bolt(m_idx, GF_MANA, randint(rlev * 7 / 2) + 50); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_PLAS */ + case 128 + 24: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a plasma bolt.", m_name); + bolt(m_idx, GF_PLASMA, 10 + damroll(8, 7) + (rlev)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_BO_ICEE */ + case 128 + 25: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts an ice bolt.", m_name); + bolt(m_idx, GF_ICE, damroll(6, 6) + (rlev)); + update_smart_learn(m_idx, DRS_COLD); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_MISSILE */ + case 128 + 26: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a magic missile.", m_name); + bolt(m_idx, GF_MISSILE, damroll(2, 6) + (rlev / 3)); + update_smart_learn(m_idx, DRS_REFLECT); + break; + } + + /* RF5_SCARE */ + case 128 + 27: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles, and you hear scary noises.", m_name); + else msg_format("%^s casts a fearful illusion.", m_name); + if (p_ptr->resist_fear) + { + msg_print("You refuse to be frightened."); + } + else if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You refuse to be frightened."); + } + else + { + (void)set_afraid(p_ptr->afraid + rand_int(4) + 4); + } + update_smart_learn(m_idx, DRS_FEAR); + break; + } + + /* RF5_BLIND */ + case 128 + 28: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s casts a spell, burning your eyes!", m_name); + if (p_ptr->resist_blind) + { + msg_print("You are unaffected!"); + } + else if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + (void)set_blind(12 + rand_int(4)); + } + update_smart_learn(m_idx, DRS_BLIND); + break; + } + + /* RF5_CONF */ + case 128 + 29: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles, and you hear puzzling noises.", m_name); + else msg_format("%^s creates a mesmerizing illusion.", m_name); + if (p_ptr->resist_conf) + { + msg_print("You disbelieve the feeble spell."); + } + else if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You disbelieve the feeble spell."); + } + else + { + (void)set_confused(p_ptr->confused + rand_int(4) + 4); + } + update_smart_learn(m_idx, DRS_CONF); + break; + } + + /* RF5_SLOW */ + case 128 + 30: + { + if (!direct) break; + disturb(1); + msg_format("%^s drains power from your muscles!", m_name); + if (p_ptr->free_act) + { + msg_print("You are unaffected!"); + } + else if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + (void)set_slow(p_ptr->slow + rand_int(4) + 4); + } + update_smart_learn(m_idx, DRS_FREE); + break; + } + + /* RF5_HOLD */ + case 128 + 31: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s stares deep into your eyes!", m_name); + if (p_ptr->free_act) + { + msg_print("You are unaffected!"); + } + else if (rand_int(100) < p_ptr->skill_sav) + { + msg_format("You resist the effects!"); + } + else + { + (void)set_paralyzed(rand_int(4) + 4); + } + update_smart_learn(m_idx, DRS_FREE); + break; + } + + + + /* RF6_HASTE */ + case 160 + 0: + { + disturb(1); + if (blind) + { + msg_format("%^s mumbles.", m_name); + } + else + { + msg_format("%^s concentrates on %s body.", m_name, m_poss); + } + + /* Allow quick speed increases to base+10 */ + if (m_ptr->mspeed < m_ptr->speed + 10) + { + msg_format("%^s starts moving faster.", m_name); + m_ptr->mspeed += 10; + } + + /* Allow small speed increases to base+20 */ + else if (m_ptr->mspeed < m_ptr->speed + 20) + { + msg_format("%^s starts moving faster.", m_name); + m_ptr->mspeed += 2; + } + + break; + } + + /* RF6_HAND_DOOM */ + case 160 + 1: + { + disturb(1); + msg_format("%^s invokes the Hand of Doom!", m_name); + if (rand_int(100) < p_ptr->skill_sav) + { + msg_format("You resist the effects!"); + } + else + { + int dummy = (((s32b) ((65 + randint(25)) * (p_ptr->chp))) / 100); + msg_print("Your feel your life fade away!"); + take_hit(dummy, m_name); + curse_equipment(100, 20); + + if (p_ptr->chp < 1) p_ptr->chp = 1; + } + break; + } + + /* RF6_HEAL */ + case 160 + 2: + { + disturb(1); + + /* Message */ + if (blind) + { + msg_format("%^s mumbles.", m_name); + } + else + { + msg_format("%^s concentrates on %s wounds.", m_name, m_poss); + } + + /* Heal some */ + m_ptr->hp += (rlev * 6); + + /* Fully healed */ + if (m_ptr->hp >= m_ptr->maxhp) + { + /* Fully healed */ + m_ptr->hp = m_ptr->maxhp; + + /* Message */ + if (seen) + { + msg_format("%^s looks completely healed!", m_name); + } + else + { + msg_format("%^s sounds completely healed!", m_name); + } + } + + /* Partially healed */ + else + { + /* Message */ + if (seen) + { + msg_format("%^s looks healthier.", m_name); + } + else + { + msg_format("%^s sounds healthier.", m_name); + } + } + + /* Redraw (later) if needed */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + + /* Cancel fear */ + if (m_ptr->monfear) + { + /* Cancel fear */ + m_ptr->monfear = 0; + + /* Message */ + msg_format("%^s recovers %s courage.", m_name, m_poss); + } + break; + } + + /* RF6_S_ANIMALS */ + case 160 + 3: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons some animals!", m_name); + for (k = 0; k < 4; k++) + { + count += summon_specific(y, x, rlev, SUMMON_ANIMAL); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_BLINK */ + case 160 + 4: + { + disturb(1); + msg_format("%^s blinks away.", m_name); + teleport_away(m_idx, 10); + break; + } + + /* RF6_TPORT */ + case 160 + 5: + { + disturb(1); + msg_format("%^s teleports away.", m_name); + teleport_away(m_idx, MAX_SIGHT * 2 + 5); + break; + } + + /* RF6_TELE_TO */ + case 160 + 6: + { + if (!direct) break; + disturb(1); + msg_format("%^s commands you to return.", m_name); + teleport_player_to(m_ptr->fy, m_ptr->fx); + break; + } + + /* RF6_TELE_AWAY */ + case 160 + 7: + { + if (!direct) break; + disturb(1); + msg_format("%^s teleports you away.", m_name); + teleport_player(100); + break; + } + + /* RF6_TELE_LEVEL */ + case 160 + 8: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles strangely.", m_name); + else msg_format("%^s gestures at your feet.", m_name); + if (p_ptr->resist_nexus) + { + msg_print("You are unaffected!"); + } + else if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else + { + teleport_player_level(); + } + update_smart_learn(m_idx, DRS_NEXUS); + break; + } + + /* RF6_DARKNESS */ + case 160 + 9: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s gestures in shadow.", m_name); + (void)unlite_area(0, 3); + break; + } + + /* RF6_TRAPS */ + case 160 + 10: + { + if (!direct) break; + disturb(1); + if (blind) msg_format("%^s mumbles, and then cackles evilly.", m_name); + else msg_format("%^s casts a spell and cackles evilly.", m_name); + (void)trap_creation(); + break; + } + + /* RF6_FORGET */ + case 160 + 11: + { + if (!direct) break; + disturb(1); + msg_format("%^s tries to blank your mind.", m_name); + + if (rand_int(100) < p_ptr->skill_sav) + { + msg_print("You resist the effects!"); + } + else if (lose_all_info()) + { + msg_print("Your memories fade away."); + } + break; + } + + /* RF6_ANIM_DEAD */ + case 160 + 12: + break; + + /* RF6_S_BUG */ + case 160 + 13: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically codes some software bugs.", m_name); + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_BUG); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_RNG */ + case 160 + 14: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically codes some RNGs.", m_name); + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_RNG); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_THUNDERLORD */ + case 160 + 15: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons a Thunderlord!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, SUMMON_THUNDERLORD); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_SUMMON_KIN */ + case 160 + 16: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons %s %s.", + m_name, m_poss, + ((r_ptr->flags1) & RF1_UNIQUE ? + "minions" : "kin")); + summon_kin_type = r_ptr->d_char; /* Big hack */ + + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_KIN); + } + if (blind && count) msg_print("You hear many things appear nearby."); + + break; + } + + /* RF6_S_HI_DEMON */ + case 160 + 17: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons greater demons!", m_name); + if (blind && count) msg_print("You hear heavy steps nearby."); + summon_cyber(); + break; + } + + /* RF6_S_MONSTER */ + case 160 + 18: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons help!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, 0); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_S_MONSTERS */ + case 160 + 19: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons monsters!", m_name); + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, 0); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_ANT */ + case 160 + 20: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons ants.", m_name); + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_ANT); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_SPIDER */ + case 160 + 21: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons spiders.", m_name); + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_SPIDER); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_HOUND */ + case 160 + 22: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons hounds.", m_name); + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_HOUND); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_HYDRA */ + case 160 + 23: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons hydras.", m_name); + for (k = 0; k < 6; k++) + { + count += summon_specific(y, x, rlev, SUMMON_HYDRA); + } + if (blind && count) msg_print("You hear many things appear nearby."); + break; + } + + /* RF6_S_ANGEL */ + case 160 + 24: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons an angel!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, SUMMON_ANGEL); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_S_DEMON */ + case 160 + 25: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons a demon!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, SUMMON_DEMON); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_S_UNDEAD */ + case 160 + 26: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons an undead adversary!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, SUMMON_UNDEAD); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_S_DRAGON */ + case 160 + 27: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons a dragon!", m_name); + for (k = 0; k < 1; k++) + { + count += summon_specific(y, x, rlev, SUMMON_DRAGON); + } + if (blind && count) msg_print("You hear something appear nearby."); + break; + } + + /* RF6_S_HI_UNDEAD */ + case 160 + 28: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons greater undead!", m_name); + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + } + if (blind && count) + { + msg_print("You hear many creepy things appear nearby."); + } + break; + } + + /* RF6_S_HI_DRAGON */ + case 160 + 29: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons ancient dragons!", m_name); + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, SUMMON_HI_DRAGON); + } + if (blind && count) + { + msg_print("You hear many powerful things appear nearby."); + } + break; + } + + /* RF6_S_WRAITH */ + case 160 + 30: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons Wraith!", m_name); + + + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, SUMMON_WRAITH); + } + + if (blind && count) + { + msg_print("You hear immortal beings appear nearby."); + } + break; + } + + /* RF6_S_UNIQUE */ + case 160 + 31: + { + disturb(1); + if (blind) msg_format("%^s mumbles.", m_name); + else msg_format("%^s magically summons special opponents!", m_name); + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, SUMMON_UNIQUE); + } + for (k = 0; k < 8; k++) + { + count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + } + if (blind && count) + { + msg_print("You hear many powerful things appear nearby."); + } + break; + } + } + } + + /* Remember what the monster did to us */ + if (seen) + { + /* Inate spell */ + if (thrown_spell < 32*4) + { + r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3)); + if (r_ptr->r_cast_inate < MAX_UCHAR) r_ptr->r_cast_inate++; + } + + /* Bolt or Ball */ + else if (thrown_spell < 32*5) + { + r_ptr->r_flags5 |= (1L << (thrown_spell - 32 * 4)); + if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; + } + + /* Special spell */ + else if (thrown_spell < 32*6) + { + r_ptr->r_flags6 |= (1L << (thrown_spell - 32 * 5)); + if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; + } + } + + + /* Always take note of monsters that kill you */ + if (death && (r_ptr->r_deaths < MAX_SHORT)) + { + r_ptr->r_deaths++; + } + + /* A spell was cast */ + return (TRUE); +} + + +/* + * Returns whether a given monster will try to run from the player. + * + * Monsters will attempt to avoid very powerful players. See below. + * + * Because this function is called so often, little details are important + * for efficiency. Like not using "mod" or "div" when possible. And + * attempting to check the conditions in an optimal order. Note that + * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result. + * + * Note that this function is responsible for about one to five percent + * of the processor use in normal conditions... + */ +static int mon_will_run(int m_idx) +{ + monster_type *m_ptr = &m_list[m_idx]; + u16b p_lev, m_lev; + u16b p_chp, p_mhp; + u16b m_chp, m_mhp; + u32b p_val, m_val; + + /* Keep monsters from running too far away */ + if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE); + + /* Friends don't run away */ + if (is_friend(m_ptr) >= 0) return (FALSE); + + /* All "afraid" monsters will run away */ + if (m_ptr->monfear) return (TRUE); + + /* Nearby monsters will not become terrified */ + if (m_ptr->cdis <= 5) return (FALSE); + + /* Examine player power (level) */ + p_lev = p_ptr->lev; + + /* Examine monster power (level plus morale) */ + m_lev = m_ptr->level + (m_idx & 0x08) + 25; + + /* Optimize extreme cases below */ + if (m_lev > p_lev + 4) return (FALSE); + if (m_lev + 4 <= p_lev) return (TRUE); + + /* Examine player health */ + p_chp = p_ptr->chp; + p_mhp = p_ptr->mhp; + + /* Examine monster health */ + m_chp = m_ptr->hp; + m_mhp = m_ptr->maxhp; + + /* Prepare to optimize the calculation */ + p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */ + m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */ + + /* Strong players scare strong monsters */ + if (p_val * m_mhp > m_val * p_mhp) return (TRUE); + + /* Assume no terror */ + return (FALSE); +} + + + + +/* +* Choose the "best" direction for "flowing" +* +* Note that ghosts and rock-eaters are never allowed to "flow", +* since they should move directly towards the player. +* +* Prefer "non-diagonal" directions, but twiddle them a little +* to angle slightly towards the player's actual location. +* +* Allow very perceptive monsters to track old "spoor" left by +* previous locations occupied by the player. This will tend +* to have monsters end up either near the player or on a grid +* recently occupied by the player (and left via "teleport"). +* +* Note that if "smell" is turned on, all monsters get vicious. +* +* Also note that teleporting away from a location will cause +* the monsters who were chasing you to converge on that location +* as long as you are still near enough to "annoy" them without +* being close enough to chase directly. I have no idea what will +* happen if you combine "smell" with low "aaf" values. +*/ + +/* +* Provide a location to flee to, but give the player a wide berth. +* +* A monster may wish to flee to a location that is behind the player, +* but instead of heading directly for it, the monster should "swerve" +* around the player so that he has a smaller chance of getting hit. +*/ +static bool_ get_fear_moves_aux(int m_idx, int *yp, int *xp) +{ + int y, x, y1, x1, fy, fx, gy = 0, gx = 0; + int when = 0, score = -1; + int i; + + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + + /* Monster flowing disabled */ + if (!flow_by_sound) return (FALSE); + + /* Monster location */ + fy = m_ptr->fy; + fx = m_ptr->fx; + + /* Desired destination */ + y1 = fy - (*yp); + x1 = fx - (*xp); + + /* The player is not currently near the monster grid */ + if (cave[fy][fx].when < cave[p_ptr->py][p_ptr->px].when) + { + /* No reason to attempt flowing */ + return (FALSE); + } + + /* Monster is too far away to use flow information */ + if (cave[fy][fx].cost > MONSTER_FLOW_DEPTH) return (FALSE); + if (cave[fy][fx].cost > r_ptr->aaf) return (FALSE); + + /* Check nearby grids, diagonals first */ + for (i = 7; i >= 0; i--) + { + int dis, s; + + /* Get the location */ + y = fy + ddy_ddd[i]; + x = fx + ddx_ddd[i]; + + /* Ignore illegal locations */ + if (cave[y][x].when == 0) continue; + + /* Ignore ancient locations */ + if (cave[y][x].when < when) continue; + + /* Calculate distance of this grid from our destination */ + dis = distance(y, x, y1, x1); + + /* Score this grid */ + s = 5000 / (dis + 3) - 500 / (cave[y][x].cost + 1); + + /* No negative scores */ + if (s < 0) s = 0; + + /* Ignore lower scores */ + if (s < score) continue; + + /* Save the score and time */ + when = cave[y][x].when; + score = s; + + /* Save the location */ + gy = y; + gx = x; + } + + /* No legal move (?) */ + if (!when) return (FALSE); + + /* Find deltas */ + (*yp) = fy - gy; + (*xp) = fx - gx; + + /* Success */ + return (TRUE); +} + + +/* +* Choose a "safe" location near a monster for it to run toward. +* +* A location is "safe" if it can be reached quickly and the player +* is not able to fire into it (it isn't a "clean shot"). So, this will +* cause monsters to "duck" behind walls. Hopefully, monsters will also +* try to run towards corridor openings if they are in a room. +* +* This function may take lots of CPU time if lots of monsters are +* fleeing. +* +* Return TRUE if a safe location is available. +*/ +static bool_ find_safety(int m_idx, int *yp, int *xp) +{ + monster_type *m_ptr = &m_list[m_idx]; + + int fy = m_ptr->fy; + int fx = m_ptr->fx; + + int y, x, d, dis; + int gy = 0, gx = 0, gdis = 0; + + /* Start with adjacent locations, spread further */ + for (d = 1; d < 10; d++) + { + /* Check nearby locations */ + for (y = fy - d; y <= fy + d; y++) + { + for (x = fx - d; x <= fx + d; x++) + { + /* Skip illegal locations */ + if (!in_bounds(y, x)) continue; + + /* Skip locations in a wall */ + if (!cave_floor_bold(y, x)) continue; + + /* Check distance */ + if (distance(y, x, fy, fx) != d) continue; + + /* Check for "availability" (if monsters can flow) */ + if (flow_by_sound) + { + /* Ignore grids very far from the player */ + if (cave[y][x].when < cave[p_ptr->py][p_ptr->px].when) continue; + + /* Ignore too-distant grids */ + if (cave[y][x].cost > cave[fy][fx].cost + 2 * d) continue; + } + + /* Check for absence of shot */ + if (!projectable(y, x, p_ptr->py, p_ptr->px)) + { + /* Calculate distance from player */ + dis = distance(y, x, p_ptr->py, p_ptr->px); + + /* Remember if further than previous */ + if (dis > gdis) + { + gy = y; + gx = x; + gdis = dis; + } + } + } + } + + /* Check for success */ + if (gdis > 0) + { + /* Good location */ + (*yp) = fy - gy; + (*xp) = fx - gx; + + /* Found safe place */ + return (TRUE); + } + } + + /* No safe place */ + return (FALSE); +} + + +/* + * Choose a good hiding place near a monster for it to run toward. + * + * Pack monsters will use this to "ambush" the player and lure him out + * of corridors into open space so they can swarm him. + * + * Return TRUE if a good location is available. + */ +static bool_ find_hiding(int m_idx, int *yp, int *xp) +{ + monster_type *m_ptr = &m_list[m_idx]; + + int fy = m_ptr->fy; + int fx = m_ptr->fx; + + int y, x, d, dis; + int gy = 0, gx = 0, gdis = 999, min; + + /* Closest distance to get */ + min = distance(p_ptr->py, p_ptr->px, fy, fx) * 3 / 4 + 2; + + /* Start with adjacent locations, spread further */ + for (d = 1; d < 10; d++) + { + /* Check nearby locations */ + for (y = fy - d; y <= fy + d; y++) + { + for (x = fx - d; x <= fx + d; x++) + { + /* Skip illegal locations */ + if (!in_bounds(y, x)) continue; + + /* Skip locations in a wall */ + if (!cave_floor_bold(y, x)) continue; + + /* Check distance */ + if (distance(y, x, fy, fx) != d) continue; + + /* Check for hidden, available grid */ + if (!player_can_see_bold(y, x) && clean_shot(fy, fx, y, x)) + { + /* Calculate distance from player */ + dis = distance(y, x, p_ptr->py, p_ptr->px); + + /* Remember if closer than previous */ + if (dis < gdis && dis >= min) + { + gy = y; + gx = x; + gdis = dis; + } + } + } + } + + /* Check for success */ + if (gdis < 999) + { + /* Good location */ + (*yp) = fy - gy; + (*xp) = fx - gx; + + /* Found good place */ + return (TRUE); + } + } + + /* No good place */ + return (FALSE); +} + + +/* Find an appropriate corpse */ +void find_corpse(monster_type *m_ptr, int *y, int *x) +{ + int k, last = -1; + + for (k = 0; k < max_o_idx; k++) + { + object_type *o_ptr = &o_list[k]; + monster_race *rt_ptr, *rt2_ptr; + + if (!o_ptr->k_idx) continue; + + if (o_ptr->tval != TV_CORPSE) continue; + if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_SKELETON)) continue; + + rt_ptr = &r_info[o_ptr->pval2]; + + /* Cannot incarnate into a higher level monster */ + if (rt_ptr->level > m_ptr->level) continue; + + /* Must be in LOS */ + if (!los(m_ptr->fy, m_ptr->fx, o_ptr->iy, o_ptr->ix)) continue; + + if (last != -1) + { + rt2_ptr = &r_info[o_list[last].pval2]; + if (rt_ptr->level > rt2_ptr->level) last = k; + else continue; + } + else + { + last = k; + } + } + + /* Must be ok now */ + if (last != -1) + { + *y = o_list[last].iy; + *x = o_list[last].ix; + } +} + +/* + * Choose target + */ +static void get_target_monster(int m_idx) +{ + monster_type *m_ptr = &m_list[m_idx]; + int i, t = -1, d = 9999; + + /* Process the monsters (backwards) */ + for (i = m_max - 1; i >= 1; i--) + { + /* Access the monster */ + monster_type *t_ptr = &m_list[i]; + /* hack should call the function for ego monsters ... but no_target i not meant to be added by ego and it speeds up the code */ + monster_race *rt_ptr = &r_info[t_ptr->r_idx]; + int dd; + + /* Ignore "dead" monsters */ + if (!t_ptr->r_idx) continue; + + if (m_idx == i) continue; + + /* Cannot be targeted */ + if (rt_ptr->flags7 & RF7_NO_TARGET) continue; + + if (is_enemy(m_ptr, t_ptr) && (los(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx) && + ((dd = distance(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) < d))) + { + t = i; + d = dd; + } + } + /* Hack */ + if ((is_friend(m_ptr) < 0) && los(m_ptr->fy, m_ptr->fx, p_ptr->py, p_ptr->px) && (distance(m_ptr->fy, m_ptr->fx, p_ptr->py, p_ptr->px) < d)) t = 0; + + m_ptr->target = t; +} + +/* + * Choose "logical" directions for monster movement + */ +static bool_ get_moves(int m_idx, int *mm) +{ + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + + int y, ay, x, ax; + + int move_val = 0; + + int y2 = p_ptr->py; + int x2 = p_ptr->px; + bool_ done = FALSE; + + /* Oups get nearer */ + if ((is_friend(m_ptr) > 0) && (m_ptr->cdis > p_ptr->pet_follow_distance)) + { + y2 = p_ptr->py; + x2 = p_ptr->px; + } + /* Use the target */ + else if (!m_ptr->target) + { + y2 = p_ptr->py; + x2 = p_ptr->px; + } + else if (m_ptr->target > 0) + { + y2 = m_list[m_ptr->target].fy; + x2 = m_list[m_ptr->target].fx; + } + + /* Hack doppleganger confuses monsters(even pets) */ + if (doppleganger) + { + if (magik(70)) + { + y2 = m_list[doppleganger].fy; + x2 = m_list[doppleganger].fx; + } + } + + /* A possessor is not interrested in the player, it only wants a corpse */ + if (r_ptr->flags7 & RF7_POSSESSOR) + { + find_corpse(m_ptr, &y2, &x2); + } + + /* Let quests redefine AI */ + if (r_ptr->flags7 & RF7_AI_SPECIAL) + { + if (process_hooks_ret(HOOK_MONSTER_AI, "dd", "(d)", m_idx)) + { + y2 = process_hooks_return[0].num; + x2 = process_hooks_return[1].num; + } + } + + if (m_idx == p_ptr->control) + { + if ((r_ptr->flags7 & RF7_AI_PLAYER) || magik(85)) + { + if (distance(p_ptr->py, p_ptr->px, m_ptr->fy, m_ptr->fx) < 50) + { + y2 = m_ptr->fy + ddy[p_ptr->control_dir]; + x2 = m_ptr->fx + ddx[p_ptr->control_dir]; + } + } + } + + /* Extract the "pseudo-direction" */ + y = m_ptr->fy - y2; + x = m_ptr->fx - x2; + + /* Tease the player */ + if (r_ptr->flags7 & RF7_AI_ANNOY) + { + if (distance(m_ptr->fy, m_ptr->fx, y2, x2) < 4) + { + y = -y; + x = -x; + } + } + + /* Death orbs .. */ + if (r_ptr->flags2 & RF2_DEATH_ORB) + { + if (!los(m_ptr->fy, m_ptr->fx, y2, x2)) + { + return (FALSE); + } + } + + if (is_friend(m_ptr) < 0) + { + int tx = x2, ty = y2; + + /* + * Animal packs try to get the player out of corridors + * (...unless they can move through walls -- TY) + */ + if ((r_ptr->flags1 & RF1_FRIENDS) && + (r_ptr->flags3 & RF3_ANIMAL) && + !((r_ptr->flags2 & (RF2_PASS_WALL)) || + (r_ptr->flags2 & (RF2_KILL_WALL)))) + { + int i, room = 0; + + /* Count room grids next to player */ + for (i = 0; i < 8; i++) + { + /* Check grid */ + if (cave[ty + ddy_ddd[i]][tx + ddx_ddd[i]].info & (CAVE_ROOM)) + { + /* One more room grid */ + room++; + } + } + + /* Not in a room and strong player */ + if ((room < 8) && (p_ptr->chp > ((p_ptr->mhp * 3) / 4))) + { + /* Find hiding place */ + if (find_hiding(m_idx, &y, &x)) done = TRUE; + } + } + + /* Monster groups try to surround the player */ + if (!done && (r_ptr->flags1 & RF1_FRIENDS)) + { + int i; + + /* Find an empty square near the target to fill */ + for (i = 0; i < 8; i++) + { + /* Pick squares near target (semi-randomly) */ + y2 = ty + ddy_ddd[(m_idx + i) & 7]; + x2 = tx + ddx_ddd[(m_idx + i) & 7]; + + /* Already there? */ + if ((m_ptr->fy == y2) && (m_ptr->fx == x2)) + { + /* Attack the target */ + y2 = ty; + x2 = tx; + + break; + } + + /* Ignore filled grids */ + if (!cave_empty_bold(y2, x2)) continue; + + /* Try to fill this hole */ + break; + } + + /* Extract the new "pseudo-direction" */ + y = m_ptr->fy - y2; + x = m_ptr->fx - x2; + + /* Done */ + done = TRUE; + } + } + + /* Apply fear if possible and necessary */ + if (is_friend(m_ptr) > 0) + { + if (mon_will_run(m_idx)) + { + /* XXX XXX Not very "smart" */ + y = ( -y), x = ( -x); + } + } + else + { + if (!done && mon_will_run(m_idx)) + { + /* Try to find safe place */ + if (!find_safety(m_idx, &y, &x)) + { + /* This is not a very "smart" method XXX XXX */ + y = ( -y); + x = ( -x); + } + else + { + /* Attempt to avoid the player */ + if (flow_by_sound) + { + /* Adjust movement */ + (void)get_fear_moves_aux(m_idx, &y, &x); + } + } + } + } + + + /* Check for no move */ + if (!x && !y) return (FALSE); + + /* Extract the "absolute distances" */ + ax = ABS(x); + ay = ABS(y); + + /* Do something weird */ + if (y < 0) move_val += 8; + if (x > 0) move_val += 4; + + /* Prevent the diamond maneuvre */ + if (ay > (ax << 1)) + { + move_val++; + move_val++; + } + else if (ax > (ay << 1)) + { + move_val++; + } + + /* Extract some directions */ + switch (move_val) + { + case 0: + mm[0] = 9; + if (ay > ax) + { + mm[1] = 8; + mm[2] = 6; + mm[3] = 7; + mm[4] = 3; + } + else + { + mm[1] = 6; + mm[2] = 8; + mm[3] = 3; + mm[4] = 7; + } + break; + case 1: + case 9: + mm[0] = 6; + if (y < 0) + { + mm[1] = 3; + mm[2] = 9; + mm[3] = 2; + mm[4] = 8; + } + else + { + mm[1] = 9; + mm[2] = 3; + mm[3] = 8; + mm[4] = 2; + } + break; + case 2: + case 6: + mm[0] = 8; + if (x < 0) + { + mm[1] = 9; + mm[2] = 7; + mm[3] = 6; + mm[4] = 4; + } + else + { + mm[1] = 7; + mm[2] = 9; + mm[3] = 4; + mm[4] = 6; + } + break; + case 4: + mm[0] = 7; + if (ay > ax) + { + mm[1] = 8; + mm[2] = 4; + mm[3] = 9; + mm[4] = 1; + } + else + { + mm[1] = 4; + mm[2] = 8; + mm[3] = 1; + mm[4] = 9; + } + break; + case 5: + case 13: + mm[0] = 4; + if (y < 0) + { + mm[1] = 1; + mm[2] = 7; + mm[3] = 2; + mm[4] = 8; + } + else + { + mm[1] = 7; + mm[2] = 1; + mm[3] = 8; + mm[4] = 2; + } + break; + case 8: + mm[0] = 3; + if (ay > ax) + { + mm[1] = 2; + mm[2] = 6; + mm[3] = 1; + mm[4] = 9; + } + else + { + mm[1] = 6; + mm[2] = 2; + mm[3] = 9; + mm[4] = 1; + } + break; + case 10: + case 14: + mm[0] = 2; + if (x < 0) + { + mm[1] = 3; + mm[2] = 1; + mm[3] = 6; + mm[4] = 4; + } + else + { + mm[1] = 1; + mm[2] = 3; + mm[3] = 4; + mm[4] = 6; + } + break; + case 12: + mm[0] = 1; + if (ay > ax) + { + mm[1] = 2; + mm[2] = 4; + mm[3] = 3; + mm[4] = 7; + } + else + { + mm[1] = 4; + mm[2] = 2; + mm[3] = 7; + mm[4] = 3; + } + break; + } + + + + /* Wants to move... */ + return (TRUE); +} + + +int check_hit2(int power, int level, int ac) +{ + int i, k; + + /* Percentile dice */ + k = rand_int(100); + + /* Hack -- Always miss or hit */ + if (k < 10) return (k < 5); + + /* Calculate the "attack quality" */ + i = (power + (level * 3)); + + /* Power and Level compete against Armor */ + if ((i > 0) && (randint(i) > ((ac * 3) / 4))) return (TRUE); + + /* Assume miss */ + return (FALSE); +} + + +/* Monster attacks monster */ +static bool_ monst_attack_monst(int m_idx, int t_idx) +{ + monster_type *m_ptr = &m_list[m_idx], *t_ptr = &m_list[t_idx]; + monster_race *r_ptr = race_inf(m_ptr); + monster_race *tr_ptr = race_inf(t_ptr); + int ap_cnt; + int ac, rlev, pt; + char m_name[80], t_name[80]; + char ddesc[80], temp[80]; + bool_ blinked = FALSE, touched = FALSE; + bool_ explode = FALSE; + bool_ fear = FALSE; + byte y_saver = t_ptr->fy; + byte x_saver = t_ptr->fx; + + + /* Not allowed to attack */ + if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE; + if (tr_ptr->flags7 & RF7_IM_MELEE) return FALSE; + + /* Total armor */ + ac = t_ptr->ac; + + /* Extract the effective monster level */ + rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); + + /* Get the monster name (or "it") */ + monster_desc(m_name, m_ptr, 0); + + /* Get the monster name (or "it") */ + monster_desc(t_name, t_ptr, 0); + + /* Get the "died from" information (i.e. "a kobold") */ + monster_desc(ddesc, m_ptr, 0x88); + + /* Assume no blink */ + blinked = FALSE; + + if (!(m_ptr->ml || t_ptr->ml)) + { + monster_msg("You hear noise."); + } + + /* Scan through all four blows */ + for (ap_cnt = 0; ap_cnt < 4; ap_cnt++) + { + bool_ visible = FALSE; + bool_ obvious = FALSE; + + int power = 0; + int damage = 0; + + cptr act = NULL; + + /* Extract the attack infomation */ + int effect = m_ptr->blow[ap_cnt].effect; + int method = m_ptr->blow[ap_cnt].method; + int d_dice = m_ptr->blow[ap_cnt].d_dice; + int d_side = m_ptr->blow[ap_cnt].d_side; + + if (t_ptr == m_ptr) /* Paranoia */ + { + if (wizard) + monster_msg("Monster attacking self?"); + break; + } + + /* Stop attacking if the target dies! */ + if (t_ptr->fx != x_saver || t_ptr->fy != y_saver) + break; + + /* Hack -- no more attacks */ + if (!method) break; + + if (blinked) /* Stop! */ + { + /* break; */ + } + + /* Extract visibility (before blink) */ + if (m_ptr->ml) visible = TRUE; + + /* Extract the attack "power" */ + power = get_attack_power(effect); + + + /* Monster hits*/ + if (!effect || check_hit2(power, rlev, ac)) + { + /* Always disturbing */ + if (disturb_other) disturb(1); + + /* Describe the attack method */ + switch (method) + { + case RBM_HIT: + { + act = "hits %s."; + touched = TRUE; + break; + } + + case RBM_TOUCH: + { + act = "touches %s."; + touched = TRUE; + break; + } + + case RBM_PUNCH: + { + act = "punches %s."; + touched = TRUE; + break; + } + + case RBM_KICK: + { + act = "kicks %s."; + touched = TRUE; + break; + } + + case RBM_CLAW: + { + act = "claws %s."; + touched = TRUE; + break; + } + + case RBM_BITE: + { + act = "bites %s."; + touched = TRUE; + break; + } + + case RBM_STING: + { + act = "stings %s."; + touched = TRUE; + break; + } + + case RBM_XXX1: + { + act = "XXX1's %s."; + break; + } + + case RBM_BUTT: + { + act = "butts %s."; + touched = TRUE; + break; + } + + case RBM_CRUSH: + { + act = "crushes %s."; + touched = TRUE; + break; + } + + case RBM_ENGULF: + { + act = "engulfs %s."; + touched = TRUE; + break; + } + + case RBM_CHARGE: + { + act = "charges %s."; + touched = TRUE; + break; + } + + case RBM_CRAWL: + { + act = "crawls on %s."; + touched = TRUE; + break; + } + + case RBM_DROOL: + { + act = "drools on %s."; + touched = FALSE; + break; + } + + case RBM_SPIT: + { + act = "spits on %s."; + touched = FALSE; + break; + } + + case RBM_EXPLODE: + { + act = "explodes."; + explode = TRUE; + touched = FALSE; + break; + } + + case RBM_GAZE: + { + act = "gazes at %s."; + touched = FALSE; + break; + } + + case RBM_WAIL: + { + act = "wails at %s."; + touched = FALSE; + break; + } + + case RBM_SPORE: + { + act = "releases spores at %s."; + touched = FALSE; + break; + } + + case RBM_XXX4: + { + act = "projects XXX4's at %s."; + touched = FALSE; + break; + } + + case RBM_BEG: + { + act = "begs %s for money."; + touched = FALSE; + t_ptr->csleep = 0; + break; + } + + case RBM_INSULT: + { + act = "insults %s."; + touched = FALSE; + t_ptr->csleep = 0; + break; + } + + case RBM_MOAN: + { + act = "moans at %s."; + touched = FALSE; + t_ptr->csleep = 0; + break; + } + + case RBM_SHOW: + { + act = "sings to %s."; + touched = FALSE; + t_ptr->csleep = 0; + break; + } + } + + /* Message */ + if (act) + { + strfmt(temp, act, t_name); + if (m_ptr->ml || t_ptr->ml) + monster_msg("%^s %s", m_name, temp); + + } + + /* Hack -- assume all attacks are obvious */ + obvious = TRUE; + + /* Roll out the damage */ + damage = damroll(d_dice, d_side); + + /* Hack need more punch against monsters */ + damage *= 3; + + pt = GF_MISSILE; + + /* Apply appropriate damage */ + switch (effect) + { + case 0: + { + damage = 0; + pt = 0; + break; + } + + case RBE_HURT: + case RBE_SANITY: + { + damage -= (damage * ((ac < 150) ? ac : 150) / 250); + break; + } + + case RBE_POISON: + case RBE_DISEASE: + { + pt = GF_POIS; + break; + } + + case RBE_UN_BONUS: + case RBE_UN_POWER: + case RBE_ABOMINATION: + { + pt = GF_DISENCHANT; + break; + } + + case RBE_EAT_FOOD: + case RBE_EAT_LITE: + { + pt = damage = 0; + break; + } + + case RBE_EAT_ITEM: + case RBE_EAT_GOLD: + { + pt = damage = 0; + if (randint(2) == 1) blinked = TRUE; + break; + } + + case RBE_ACID: + { + pt = GF_ACID; + break; + } + + case RBE_ELEC: + { + pt = GF_ELEC; + break; + } + + case RBE_FIRE: + { + pt = GF_FIRE; + break; + } + + case RBE_COLD: + { + pt = GF_COLD; + break; + } + + case RBE_BLIND: + { + break; + } + + case RBE_HALLU: + case RBE_CONFUSE: + { + pt = GF_CONFUSION; + break; + } + + case RBE_TERRIFY: + { + pt = GF_TURN_ALL; + break; + } + + case RBE_PARALYZE: + { + pt = GF_OLD_SLEEP; /* sort of close... */ + break; + } + + case RBE_LOSE_STR: + case RBE_LOSE_INT: + case RBE_LOSE_WIS: + case RBE_LOSE_DEX: + case RBE_LOSE_CON: + case RBE_LOSE_CHR: + case RBE_LOSE_ALL: + case RBE_PARASITE: + { + break; + } + case RBE_SHATTER: + { + if (damage > 23) + { + /* Prevent destruction of quest levels and town */ + if (!is_quest(dun_level) && dun_level) + earthquake(m_ptr->fy, m_ptr->fx, 8); + } + break; + } + case RBE_EXP_10: + case RBE_EXP_20: + case RBE_EXP_40: + case RBE_EXP_80: + { + pt = GF_NETHER; + break; + } + case RBE_TIME: + { + pt = GF_TIME; + break; + } + default: + { + pt = 0; + break; + } + } + + if (pt) + { + /* Do damage if not exploding */ + if (!explode) + { + project(m_idx, 0, t_ptr->fy, t_ptr->fx, + (pt == GF_OLD_SLEEP ? m_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP); + } + + if (touched) + { + /* Aura fire */ + if ((tr_ptr->flags2 & RF2_AURA_FIRE) && + !(r_ptr->flags3 & RF3_IM_FIRE)) + { + if (m_ptr->ml || t_ptr->ml) + { + blinked = FALSE; + monster_msg("%^s is suddenly very hot!", m_name); + if (t_ptr->ml) + tr_ptr->r_flags2 |= RF2_AURA_FIRE; + } + project(t_idx, 0, m_ptr->fy, m_ptr->fx, + damroll (1 + ((t_ptr->level) / 26), + 1 + ((t_ptr->level) / 17)), + GF_FIRE, PROJECT_KILL | PROJECT_STOP); + } + + /* Aura elec */ + if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) && !(r_ptr->flags3 & (RF3_IM_ELEC))) + { + if (m_ptr->ml || t_ptr->ml) + { + blinked = FALSE; + monster_msg("%^s gets zapped!", m_name); + if (t_ptr->ml) + tr_ptr->r_flags2 |= RF2_AURA_ELEC; + } + project(t_idx, 0, m_ptr->fy, m_ptr->fx, + damroll (1 + ((t_ptr->level) / 26), + 1 + ((t_ptr->level) / 17)), + GF_ELEC, PROJECT_KILL | PROJECT_STOP); + } + + } + } + } + + /* Monster missed player */ + else + { + /* Analyze failed attacks */ + switch (method) + { + case RBM_HIT: + case RBM_TOUCH: + case RBM_PUNCH: + case RBM_KICK: + case RBM_CLAW: + case RBM_BITE: + case RBM_STING: + case RBM_XXX1: + case RBM_BUTT: + case RBM_CRUSH: + case RBM_ENGULF: + case RBM_CHARGE: + { + /* Visible monsters */ + if (m_ptr->ml) + { + /* Disturbing */ + disturb(1); + + /* Message */ + monster_msg("%^s misses %s.", m_name, t_name); + } + + break; + } + } + } + + + /* Analyze "visible" monsters only */ + if (visible) + { + /* Count "obvious" attacks (and ones that cause damage) */ + if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10)) + { + /* Count attacks of this type */ + if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR) + { + r_ptr->r_blows[ap_cnt]++; + } + } + } + } + + if (explode) + { + sound(SOUND_EXPLODE); + mon_take_hit_mon(m_idx, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds."); + + blinked = FALSE; + } + + + /* Blink away */ + if (blinked) + { + if (m_ptr->ml) + { + monster_msg("The thief flees laughing!"); + } + else + { + monster_msg("You hear laughter!"); + } + + teleport_away(m_idx, MAX_SIGHT * 2 + 5); + } + + return TRUE; +} + + +/* + * Hack -- local "player stealth" value (see below) + */ +static u32b noise = 0L; + +/* Determine whether the player is invisible to a monster */ +static bool_ player_invis(monster_type * m_ptr) +{ + s16b inv, mlv; + monster_race *r_ptr = race_inf(m_ptr); + + inv = p_ptr->invis; + + mlv = (s16b) m_ptr->level; + + if (r_ptr->flags3 & RF3_NO_SLEEP) + mlv += 10; + if (r_ptr->flags3 & RF3_DRAGON) + mlv += 20; + if (r_ptr->flags3 & RF3_UNDEAD) + mlv += 15; + if (r_ptr->flags3 & RF3_DEMON) + mlv += 15; + if (r_ptr->flags3 & RF3_ANIMAL) + mlv += 15; + if (r_ptr->flags3 & RF3_ORC) + mlv -= 15; + if (r_ptr->flags3 & RF3_TROLL) + mlv -= 10; + if (r_ptr->flags2 & RF2_STUPID) + mlv /= 2; + if (r_ptr->flags2 & RF2_SMART) + mlv = (mlv * 5) / 4; + if (m_ptr->mflag & MFLAG_QUEST) + inv = 0; + if (r_ptr->flags2 & RF2_INVISIBLE) + inv = 0; + if (m_ptr->mflag & MFLAG_CONTROL) + inv = 0; + if (mlv < 1) + mlv = 1; + return (inv >= randint(mlv*2)); +} + +/* + * Process a monster + * + * The monster is known to be within 100 grids of the player + * + * In several cases, we directly update the monster lore + * + * Note that a monster is only allowed to "reproduce" if there + * are a limited number of "reproducing" monsters on the current + * level. This should prevent the level from being "swamped" by + * reproducing monsters. It also allows a large mass of mice to + * prevent a louse from multiplying, but this is a small price to + * pay for a simple multiplication method. + * + * XXX Monster fear is slightly odd, in particular, monsters will + * fixate on opening a door even if they cannot open it. Actually, + * the same thing happens to normal monsters when they hit a door + * + * XXX XXX XXX In addition, monsters which *cannot* open or bash + * down a door will still stand there trying to open it... + * + * XXX Technically, need to check for monster in the way + * combined with that monster being in a wall (or door?) + * + * A "direction" of "5" means "pick a random direction". + */ +static void process_monster(int m_idx, bool_ is_frien) +{ + monster_type *m_ptr = &m_list[m_idx]; + monster_race *r_ptr = race_inf(m_ptr); + cave_type *c_ptr = &cave[m_ptr->fy][m_ptr->fx]; + + int i, d, oy, ox, ny, nx; + + int mm[8]; + + monster_type *y_ptr; + + bool_ do_turn; + bool_ do_move; + bool_ do_view; + + bool_ did_open_door; + bool_ did_bash_door; + bool_ did_take_item; + bool_ did_kill_item; + bool_ did_move_body; + bool_ did_kill_body; + bool_ did_pass_wall; + bool_ did_kill_wall; + bool_ gets_angry = FALSE; + bool_ inv; + bool_ xxx = FALSE; + + inv = player_invis(m_ptr); + + if (r_ptr->flags9 & RF9_DOPPLEGANGER) doppleganger = m_idx; + + /* Handle "bleeding" */ + if (m_ptr->bleeding) + { + int d = 1 + (m_ptr->maxhp / 50); + if (d > m_ptr->bleeding) d = m_ptr->bleeding; + + /* Exit if the monster dies */ + if (mon_take_hit(m_idx, d, &xxx, " bleeds to death.")) return; + + /* Hack -- Recover from bleeding */ + if (m_ptr->bleeding > d) + { + /* Recover somewhat */ + m_ptr->bleeding -= d; + } + + /* Fully recover */ + else + { + /* Recover fully */ + m_ptr->bleeding = 0; + + /* Message if visible */ + if (m_ptr->ml) + { + char m_name[80]; + + /* Get the monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Dump a message */ + msg_format("%^s is no longer bleeding.", m_name); + + /* Hack -- Update the health bar */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + } + } + } + + /* Handle "poisoned" */ + if (m_ptr->poisoned) + { + int d = (m_ptr->poisoned) / 10; + if (d < 1) d = 1; + + /* Exit if the monster dies */ + if (mon_take_hit(m_idx, d, &xxx, " dies of poison.")) return; + + /* Hack -- Recover from bleeding */ + if (m_ptr->poisoned > d) + { + /* Recover somewhat */ + m_ptr->poisoned -= d; + } + + /* Fully recover */ + else + { + /* Recover fully */ + m_ptr->poisoned = 0; + + /* Message if visible */ + if (m_ptr->ml) + { + char m_name[80]; + + /* Get the monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Dump a message */ + msg_format("%^s is no longer poisoned.", m_name); + + /* Hack -- Update the health bar */ + if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + } + } + } + + /* Handle "sleep" */ + if (m_ptr->csleep) + { + u32b notice = 0; + + /* Hack -- handle non-aggravation */ + if (!p_ptr->aggravate) notice = rand_int(1024); + + /* Hack -- See if monster "notices" player */ + if ((notice * notice * notice) <= noise) + { + /* Hack -- amount of "waking" */ + int d = 1; + + /* Wake up faster near the player */ + if (m_ptr->cdis < 50) d = (100 / m_ptr->cdis); + + /* Hack -- handle aggravation */ + if (p_ptr->aggravate) d = m_ptr->csleep; + + /* Still asleep */ + if (m_ptr->csleep > d) + { + /* Monster wakes up "a little bit" */ + m_ptr->csleep -= d; + + /* Notice the "not waking up" */ + if (m_ptr->ml) + { + /* Hack -- Count the ignores */ + if (r_ptr->r_ignore < MAX_UCHAR) + { + r_ptr->r_ignore++; + } + } + } + + /* Just woke up */ + else + { + /* Reset sleep counter */ + m_ptr->csleep = 0; + + /* Notice the "waking up" */ + if (m_ptr->ml) + { + char m_name[80]; + + /* Acquire the monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Dump a message */ + msg_format("%^s wakes up.", m_name); + + /* Hack -- Count the wakings */ + if (r_ptr->r_wake < MAX_UCHAR) + { + r_ptr->r_wake++; + } + } + } + } + + /* Still sleeping */ + if (m_ptr->csleep) return; + } + + + /* Handle "stun" */ + if (m_ptr->stunned) + { + int d = 1; + + /* Make a "saving throw" against stun */ + if (rand_int(5000) <= m_ptr->level * m_ptr->level) + { + /* Recover fully */ + d = m_ptr->stunned; + } + + /* Hack -- Recover from stun */ + if (m_ptr->stunned > d) + { + /* Recover somewhat */ + m_ptr->stunned -= d; + } + + /* Fully recover */ + else + { + /* Recover fully */ + m_ptr->stunned = 0; + + /* Message if visible */ + if (m_ptr->ml) + { + char m_name[80]; + + /* Acquire the monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Dump a message */ + msg_format("%^s is no longer stunned.", m_name); + } + } + + /* Still stunned */ + if (m_ptr->stunned) return; + } + + + /* Handle confusion */ + if (m_ptr->confused) + { + /* Amount of "boldness" */ + int d = randint(m_ptr->level / 10 + 1); + + /* Still confused */ + if (m_ptr->confused > d) + { + /* Reduce the confusion */ + m_ptr->confused -= d; + } + + /* Recovered */ + else + { + /* No longer confused */ + m_ptr->confused = 0; + + /* Message if visible */ + if (m_ptr->ml) + { + char m_name[80]; + + /* Acquire the monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Dump a message */ + msg_format("%^s is no longer confused.", m_name); + } + } + } + + /* No one wants to be your friend if you're aggravating */ + if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && (p_ptr->aggravate) && !(r_ptr->flags7 & RF7_PET)) + gets_angry = TRUE; + + /* Paranoia... no friendly uniques outside wizard mode -- TY */ + if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && !(wizard) && + (r_ptr->flags1 & (RF1_UNIQUE)) && !(r_ptr->flags7 & RF7_PET)) + gets_angry = TRUE; + + if (gets_angry) + { + char m_name[80]; + monster_desc(m_name, m_ptr, 0); + switch (is_friend(m_ptr)) + { + case 1: + msg_format("%^s suddenly becomes hostile!", m_name); + change_side(m_ptr); + break; + } + } + + /* Handle "fear" */ + if (m_ptr->monfear) + { + /* Amount of "boldness" */ + int d = randint(m_ptr->level / 10 + 1); + + /* Still afraid */ + if (m_ptr->monfear > d) + { + /* Reduce the fear */ + m_ptr->monfear -= d; + } + + /* Recover from fear, take note if seen */ + else + { + /* No longer afraid */ + m_ptr->monfear = 0; + + /* Visual note */ + if (m_ptr->ml) + { + char m_name[80]; + char m_poss[80]; + + /* Acquire the monster name/poss */ + monster_desc(m_name, m_ptr, 0); + monster_desc(m_poss, m_ptr, 0x22); + + /* Dump a message */ + msg_format("%^s recovers %s courage.", m_name, m_poss); + } + } + } + + /* Get the origin */ + oy = m_ptr->fy; + ox = m_ptr->fx; + + /* Attempt to "multiply" if able and allowed */ + if ((r_ptr->flags4 & (RF4_MULTIPLY)) && (num_repro < MAX_REPRO)) + { + if (ai_multiply(m_idx)) return; + } + + if (speak_unique) + { + if (randint(SPEAK_CHANCE) == 1) + { + if (player_has_los_bold(oy, ox) && (r_ptr->flags2 & RF2_CAN_SPEAK)) + { + char m_name[80]; + char monmessage[80]; + + /* Acquire the monster name/poss */ + if (m_ptr->ml) + monster_desc(m_name, m_ptr, 0); + else + strcpy(m_name, "It"); + + /* xtra_line function by Matt Graham--allow uniques to */ + /* say "unique" things based on their monster index. */ + /* Try for the unique's lines in "monspeak.txt" first. */ + /* 0 is SUCCESS, of course.... */ + + if (!process_hooks(HOOK_MON_SPEAK, "(d,s)", m_idx, m_name)) + { + if (get_xtra_line("monspeak.txt", m_ptr, monmessage) != 0) + { + /* Get a message from old defaults if new don't work */ + + if (is_friend(m_ptr) > 0) + get_rnd_line("speakpet.txt", monmessage); + else if (m_ptr->monfear) + get_rnd_line("monfear.txt", monmessage); + else + get_rnd_line("bravado.txt", monmessage); + } + msg_format("%^s %s", m_name, monmessage); + } + } + } + } + + /* Need a new target ? */ + if ((m_ptr->target == -1) || magik(10)) get_target_monster(m_idx); + + + /* Attempt to cast a spell */ + if (make_attack_spell(m_idx)) return; + + /* + * Attempt to cast a spell at an enemy other than the player + * (may slow the game a smidgeon, but I haven't noticed.) + */ + hack_message_pain_may_silent = TRUE; + if (monst_spell_monst(m_idx)) + { + hack_message_pain_may_silent = FALSE; + return; + } + hack_message_pain_may_silent = FALSE; + + + /* Hack -- Assume no movement */ + mm[0] = mm[1] = mm[2] = mm[3] = 0; + mm[4] = mm[5] = mm[6] = mm[7] = 0; + + /* Confused -- 100% random */ + if (m_ptr->confused || (inv == TRUE && m_ptr->target == 0)) + { + /* Try four "random" directions */ + mm[0] = mm[1] = mm[2] = mm[3] = 5; + } + + /* 75% random movement */ + else if ((r_ptr->flags1 & (RF1_RAND_50)) && + (r_ptr->flags1 & (RF1_RAND_25)) && + (rand_int(100) < 75)) + { + /* Memorize flags */ + if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50); + if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25); + + /* Try four "random" directions */ + mm[0] = mm[1] = mm[2] = mm[3] = 5; + } + + /* 50% random movement */ + else if ((r_ptr->flags1 & (RF1_RAND_50)) && + (rand_int(100) < 50)) + { + /* Memorize flags */ + if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50); + + /* Try four "random" directions */ + mm[0] = mm[1] = mm[2] = mm[3] = 5; + } + + /* 25% random movement */ + else if ((r_ptr->flags1 & (RF1_RAND_25)) && + (rand_int(100) < 25)) + { + /* Memorize flags */ + if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25); + + /* Try four "random" directions */ + mm[0] = mm[1] = mm[2] = mm[3] = 5; + } + + /* Normal movement */ + else + { + /* Logical moves, may do nothing */ + if (!get_moves(m_idx, mm)) return; + } + + /* Paranoia -- quest code could delete it */ + if (!c_ptr->m_idx) return; + + /* Assume nothing */ + do_turn = FALSE; + do_move = FALSE; + do_view = FALSE; + + /* Assume nothing */ + did_open_door = FALSE; + did_bash_door = FALSE; + did_take_item = FALSE; + did_kill_item = FALSE; + did_move_body = FALSE; + did_kill_body = FALSE; + did_pass_wall = FALSE; + did_kill_wall = FALSE; + + + /* Take a zero-terminated array of "directions" */ + for (i = 0; mm[i]; i++) + { + /* Get the direction */ + d = mm[i]; + + /* Hack -- allow "randomized" motion */ + if (d == 5) d = ddd[rand_int(8)]; + + /* Get the destination */ + ny = oy + ddy[d]; + nx = ox + ddx[d]; + + /* Access that cave grid */ + c_ptr = &cave[ny][nx]; + + /* Access that cave grid's contents */ + y_ptr = &m_list[c_ptr->m_idx]; + + + /* Floor is open? */ + if (cave_floor_bold(ny, nx)) + { + /* Go ahead and move */ + do_move = TRUE; + } + + /* Floor is trapped? */ + else if (c_ptr->feat == FEAT_MON_TRAP) + { + /* Go ahead and move */ + do_move = TRUE; + } + + /* Hack -- check for Glyph of Warding */ + if ((c_ptr->feat == FEAT_GLYPH) && + !(r_ptr->flags1 & RF1_NEVER_BLOW)) + { + /* Assume no move allowed */ + do_move = FALSE; + + /* Break the ward */ + if (randint(BREAK_GLYPH) < m_ptr->level) + { + /* Describe observable breakage */ + if (c_ptr->info & CAVE_MARK) + { + msg_print("The rune of protection is broken!"); + } + + /* Forget the rune */ + c_ptr->info &= ~(CAVE_MARK); + + /* Break the rune */ + place_floor_convert_glass(ny, nx); + + /* Allow movement */ + do_move = TRUE; + } + } + + /* Hack -- trees are obstacle */ + else if ((cave[ny][nx].feat == FEAT_TREES) && (r_ptr->flags9 & RF9_KILL_TREES)) + { + do_move = TRUE; + + /* Forget the tree */ + c_ptr->info &= ~(CAVE_MARK); + + /* Notice */ + cave_set_feat(ny, nx, FEAT_GRASS); + } + + /* Hack -- player 'in' wall */ + else if ((ny == p_ptr->py) && (nx == p_ptr->px)) + { + do_move = TRUE; + } + + else if (c_ptr->m_idx) + { + /* Possibly a monster to attack */ + do_move = TRUE; + } + + /* Permanent wall */ + else if (f_info[c_ptr->feat].flags1 & FF1_PERMANENT) + { + /* Nothing */ + } + + + /* Some monsters can fly */ + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_LEVITATE) && (r_ptr->flags7 & (RF7_CAN_FLY))) + { + /* Pass through walls/doors/rubble */ + do_move = TRUE; + } + + /* Some monsters can fly */ + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_FLY) && (r_ptr->flags7 & (RF7_CAN_FLY))) + { + /* Pass through trees/... */ + do_move = TRUE; + } + + /* Monster moves through walls (and doors) */ + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & (RF2_PASS_WALL))) + { + /* Pass through walls/doors/rubble */ + do_move = TRUE; + + /* Monster went through a wall */ + did_pass_wall = TRUE; + } + + /* Monster destroys walls (and doors) */ + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & (RF2_KILL_WALL))) + { + /* Eat through walls/doors/rubble */ + do_move = TRUE; + + /* Monster destroyed a wall */ + did_kill_wall = TRUE; + + if (randint(GRINDNOISE) == 1) + { + msg_print("There is a grinding sound."); + } + + /* Forget the wall */ + c_ptr->info &= ~(CAVE_MARK); + + /* Notice */ + cave_set_feat(ny, nx, FEAT_FLOOR); + + /* Note changes to viewable region */ + if (player_has_los_bold(ny, nx)) do_view = TRUE; + } + + /* Monster moves through walls (and doors) */ + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & (RF2_PASS_WALL))) + { + /* Pass through walls/doors/rubble */ + do_move = TRUE; + + /* Monster went through a wall */ + did_pass_wall = TRUE; + } + + /* Monster moves through webs */ + else if ((f_info[c_ptr->feat].flags1 & FF1_WEB) && + (r_ptr->flags7 & RF7_SPIDER)) + { + /* Pass through webs */ + do_move = TRUE; + } + + /* Handle doors and secret doors */ + else if (((c_ptr->feat >= FEAT_DOOR_HEAD) && + (c_ptr->feat <= FEAT_DOOR_TAIL)) || + (c_ptr->feat == FEAT_SECRET)) + { + bool_ may_bash = TRUE; + + /* Take a turn */ + do_turn = TRUE; + + if ((r_ptr->flags2 & (RF2_OPEN_DOOR)) && + ((is_friend(m_ptr) <= 0) || p_ptr->pet_open_doors)) + { + /* Closed doors and secret doors */ + if ((c_ptr->feat == FEAT_DOOR_HEAD) || + (c_ptr->feat == FEAT_SECRET)) + { + /* The door is open */ + did_open_door = TRUE; + + /* Do not bash the door */ + may_bash = FALSE; + } + + /* Locked doors (not jammed) */ + else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08) + { + int k; + + /* Door power */ + k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07); + + /* Try to unlock it XXX XXX XXX */ + if (rand_int(m_ptr->hp / 10) > k) + { + /* Unlock the door */ + cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00); + + /* Do not bash the door */ + may_bash = FALSE; + } + } + } + + /* Stuck doors -- attempt to bash them down if allowed */ + if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && + ((is_friend(m_ptr) <= 0) || p_ptr->pet_open_doors)) + { + int k; + + /* Door power */ + k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07); + + /* Attempt to Bash XXX XXX XXX */ + if (rand_int(m_ptr->hp / 10) > k) + { + /* Message */ + msg_print("You hear a door burst open!"); + + /* Disturb (sometimes) */ + if (disturb_minor) disturb(0); + + /* The door was bashed open */ + did_bash_door = TRUE; + + /* Hack -- fall into doorway */ + do_move = TRUE; + } + } + + + /* Deal with doors in the way */ + if (did_open_door || did_bash_door) + { + /* It's no longer hidden */ + cave[ny][nx].mimic = 0; + + /* Break down the door */ + if (did_bash_door && (rand_int(100) < 50)) + { + cave_set_feat(ny, nx, FEAT_BROKEN); + } + + /* Open the door */ + else + { + cave_set_feat(ny, nx, FEAT_OPEN); + } + + /* Handle viewable doors */ + if (player_has_los_bold(ny, nx)) do_view = TRUE; + } + } + else if (do_move && (c_ptr->feat == FEAT_MINOR_GLYPH) + && !(r_ptr->flags1 & RF1_NEVER_BLOW)) + { + /* Assume no move allowed */ + do_move = FALSE; + + /* Break the ward */ + if (randint(BREAK_MINOR_GLYPH) < m_ptr->level) + { + /* Describe observable breakage */ + if (c_ptr->info & CAVE_MARK) + { + if (ny == p_ptr->py && nx == p_ptr->px) + { + msg_print("The rune explodes!"); + fire_ball(GF_MANA, 0, + 2 * ((p_ptr->lev / 2) + damroll(7, 7)), 2); + } + else + msg_print("An explosive rune was disarmed."); + } + + /* Forget the rune */ + c_ptr->info &= ~(CAVE_MARK); + + /* Break the rune */ + place_floor_convert_glass(ny, nx); + + /* Allow movement */ + do_move = TRUE; + } + } + + /* Hack -- the Between teleport the monsters too */ + else if (cave[ny][nx].feat == FEAT_BETWEEN) + { + nx = cave[ny][nx].special & 255; + ny = cave[ny][nx].special >> 8; + get_pos_player(10, &ny, &nx); + + /* Access that cave grid */ + c_ptr = &cave[ny][nx]; + + /* Access that cave grid's contents */ + y_ptr = &m_list[c_ptr->m_idx]; + + if (!(r_ptr->flags3 & RF3_IM_COLD)) + { + if ((m_ptr->hp - distance(ny, nx, oy, ox)*2) <= 0) + { + ny = oy + ddy[d]; + nx = ox + ddx[d]; + do_move = FALSE; + } + else + { + m_ptr->hp -= distance(ny, nx, oy, ox) * 2; + do_move = TRUE; + } + } + else + { + do_move = TRUE; + } + } + + /* Execute the inscription -- MEGA HACK -- */ + if ((c_ptr->inscription) && (c_ptr->inscription != INSCRIP_CHASM)) + { + if (inscription_info[c_ptr->inscription].when & INSCRIP_EXEC_MONST_WALK) + { + bool_ t; + t = execute_inscription(c_ptr->inscription, ny, nx); + if (!t && do_move) + { + /* Hack -- attack the player even if on the inscription */ + if ((ny == p_ptr->py) && (nx == p_ptr->px)) + do_move = TRUE; + else + do_move = FALSE; + } + } + } + + /* Some monsters never attack */ + if (do_move && (ny == p_ptr->py) && (nx == p_ptr->px) && + (r_ptr->flags1 & RF1_NEVER_BLOW)) + { + /* Do not move */ + do_move = FALSE; + } + + /* The player is in the way. Attack him. */ + if (do_move && (ny == p_ptr->py) && (nx == p_ptr->px)) + { + /* Do the attack */ + (void)make_attack_normal(m_idx, 1); + + /* Do not move */ + do_move = FALSE; + + /* Took a turn */ + do_turn = TRUE; + } + + if ((cave[ny][nx].feat >= FEAT_PATTERN_START) && + (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2) && + do_turn == FALSE) + { + do_move = FALSE; + } + + + /* A monster is in the way */ + if (do_move && c_ptr->m_idx) + { + monster_race *z_ptr = race_inf(y_ptr); + monster_type *m2_ptr = &m_list[c_ptr->m_idx]; + + /* Assume no movement */ + do_move = FALSE; + + /* Kill weaker monsters */ + if ((r_ptr->flags2 & RF2_KILL_BODY) && + (r_ptr->mexp > z_ptr->mexp) && (cave_floor_bold(ny, nx)) && + /* Friends don't kill friends... */ + !((is_friend(m_ptr) > 0) && (is_friend(m2_ptr) > 0)) && + /* Uniques aren't faceless monsters in a crowd */ + !(z_ptr->flags1 & RF1_UNIQUE) && + /* Don't wreck quests */ + !(m2_ptr->mflag & (MFLAG_QUEST | MFLAG_QUEST2)) && + /* Don't punish summoners for relying on their friends */ + (is_friend(m2_ptr) <= 0)) + { + /* Allow movement */ + do_move = TRUE; + + /* Monster ate another monster */ + did_kill_body = TRUE; + + /* XXX XXX XXX Message */ + + /* Kill the monster */ + delete_monster(ny, nx); + + /* Hack -- get the empty monster */ + y_ptr = &m_list[c_ptr->m_idx]; + } + + /* Attack 'enemies' */ + else if (is_enemy(m_ptr, m2_ptr) || m_ptr->confused) + { + do_move = FALSE; + /* attack */ + if (m2_ptr->r_idx && (m2_ptr->hp >= 0)) + { + hack_message_pain_may_silent = TRUE; + if (monst_attack_monst(m_idx, c_ptr->m_idx)) + { + hack_message_pain_may_silent = FALSE; + return; + } + hack_message_pain_may_silent = FALSE; + } + } + + /* Push past weaker monsters (unless leaving a wall) */ + else if ((r_ptr->flags2 & RF2_MOVE_BODY) && + (r_ptr->mexp > z_ptr->mexp) && cave_floor_bold(ny, nx) && + (cave_floor_bold(m_ptr->fy, m_ptr->fx))) + { + /* Allow movement */ + do_move = TRUE; + + /* Monster pushed past another monster */ + did_move_body = TRUE; + + /* XXX XXX XXX Message */ + } + } + + /* + * Check if monster can cross terrain + * This is checked after the normal attacks + * to allow monsters to attack an enemy, + * even if it can't enter the terrain. + */ + if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr)) + { + /* Assume no move allowed */ + do_move = FALSE; + } + + /* Some monsters never move */ + if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE)) + { + /* Hack -- memorize lack of attacks */ + /* if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE); */ + + /* Do not move */ + do_move = FALSE; + } + + + + /* Creature has been allowed move */ + if (do_move) + { + s16b this_o_idx, next_o_idx = 0; + + /* Take a turn */ + do_turn = TRUE; + + /* Hack -- Update the old location */ + cave[oy][ox].m_idx = c_ptr->m_idx; + + /* Mega-Hack -- move the old monster, if any */ + if (c_ptr->m_idx) + { + /* Move the old monster */ + y_ptr->fy = oy; + y_ptr->fx = ox; + + /* Update the old monster */ + update_mon(c_ptr->m_idx, TRUE); + + /* Wake up the moved monster */ + m_list[c_ptr->m_idx].csleep = 0; + + /* + * Update monster light -- I'm too lazy to check flags + * here, and those ego monster_race functions aren't + * re-entrant XXX XXX XXX + */ + p_ptr->update |= (PU_MON_LITE); + } + + /* Hack -- Update the new location */ + c_ptr->m_idx = m_idx; + + /* Move the monster */ + m_ptr->fy = ny; + m_ptr->fx = nx; + + /* Update the monster */ + update_mon(m_idx, TRUE); + + /* Redraw the old grid */ + lite_spot(oy, ox); + + /* Redraw the new grid */ + lite_spot(ny, nx); + + /* Execute the inscription -- MEGA HACK -- */ + if (c_ptr->inscription == INSCRIP_CHASM) + { + if (inscription_info[c_ptr->inscription].when & INSCRIP_EXEC_MONST_WALK) + { + execute_inscription(c_ptr->inscription, ny, nx); + } + } + + /* Possible disturb */ + if (m_ptr->ml && (disturb_move || + ((m_ptr->mflag & (MFLAG_VIEW)) && + disturb_near))) + { + /* Disturb */ + if ((is_friend(m_ptr) < 0) || disturb_pets) + disturb(0); + } + + /* Check for monster trap */ + if (c_ptr->feat == FEAT_MON_TRAP) + { + if (mon_hit_trap(m_idx)) return; + } + else + { + /* Scan all objects in the grid */ + for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) + { + object_type * o_ptr; + + /* Acquire object */ + o_ptr = &o_list[this_o_idx]; + + /* Acquire next object */ + next_o_idx = o_ptr->next_o_idx; + + /* Skip gold */ + if (o_ptr->tval == TV_GOLD) continue; + + /* Incarnate ? */ + if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags7 & RF7_POSSESSOR) && + ((o_ptr->sval == SV_CORPSE_CORPSE) || (o_ptr->sval == SV_CORPSE_SKELETON))) + { + if (ai_possessor(m_idx, this_o_idx)) return; + } + + /* Take or Kill objects on the floor */ + /* rr9: Pets will no longer pick up/destroy items */ + if ((((r_ptr->flags2 & (RF2_TAKE_ITEM)) && + ((is_friend(m_ptr) <= 0) || p_ptr->pet_pickup_items)) || + (r_ptr->flags2 & (RF2_KILL_ITEM))) && + (is_friend(m_ptr) <= 0)) + { + u32b f1, f2, f3, f4, f5, esp; + + u32b flg3 = 0L; + + char m_name[80]; + char o_name[80]; + + /* Extract some flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + /* Acquire the object name */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Acquire the monster name */ + monster_desc(m_name, m_ptr, 0x04); + + /* React to objects that hurt the monster */ + if (f5 & (TR5_KILL_DEMON)) flg3 |= (RF3_DEMON); + if (f5 & (TR5_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD); + if (f1 & (TR1_SLAY_DRAGON)) flg3 |= (RF3_DRAGON); + if (f1 & (TR1_SLAY_TROLL)) flg3 |= (RF3_TROLL); + if (f1 & (TR1_SLAY_GIANT)) flg3 |= (RF3_GIANT); + if (f1 & (TR1_SLAY_ORC)) flg3 |= (RF3_ORC); + if (f1 & (TR1_SLAY_DEMON)) flg3 |= (RF3_DEMON); + if (f1 & (TR1_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD); + if (f1 & (TR1_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL); + if (f1 & (TR1_SLAY_EVIL)) flg3 |= (RF3_EVIL); + + /* The object cannot be picked up by the monster */ + if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || + (o_ptr->art_name)) + { + /* Only give a message for "take_item" */ + if (r_ptr->flags2 & (RF2_TAKE_ITEM)) + { + /* Take note */ + did_take_item = TRUE; + + /* Describe observable situations */ + if (m_ptr->ml && player_has_los_bold(ny, nx)) + { + /* Dump a message */ + msg_format("%^s tries to pick up %s, but fails.", + m_name, o_name); + } + } + } + + /* Pick up the item */ + else if (r_ptr->flags2 & (RF2_TAKE_ITEM)) + { + /* Take note */ + did_take_item = TRUE; + + /* Describe observable situations */ + if (player_has_los_bold(ny, nx)) + { + /* Dump a message */ + msg_format("%^s picks up %s.", m_name, o_name); + } + + /* Option */ + if (testing_carry) + { + /* Excise the object */ + excise_object_idx(this_o_idx); + + /* Forget mark */ + o_ptr->marked = FALSE; + + /* Forget location */ + o_ptr->iy = o_ptr->ix = 0; + + /* Memorize monster */ + o_ptr->held_m_idx = m_idx; + + /* Build a stack */ + o_ptr->next_o_idx = m_ptr->hold_o_idx; + + /* Carry object */ + m_ptr->hold_o_idx = this_o_idx; + } + + /* Nope */ + else + { + /* Delete the object */ + delete_object_idx(this_o_idx); + } + } + + /* Destroy the item */ + else + { + /* Take note */ + did_kill_item = TRUE; + + /* Describe observable situations */ + if (player_has_los_bold(ny, nx)) + { + /* Dump a message */ + msg_format("%^s crushes %s.", m_name, o_name); + } + + /* Delete the object */ + delete_object_idx(this_o_idx); + } + } + } + } + + /* Update monster light */ + if (r_ptr->flags9 & RF9_HAS_LITE) p_ptr->update |= (PU_MON_LITE); + } + + /* Stop when done */ + if (do_turn) break; + } + + + /* If we haven't done anything, try casting a spell again */ + if (!do_turn && !do_move && !m_ptr->monfear && + (is_friend(m_ptr) < 0)) + { + /* Cast spell */ + if (make_attack_spell(m_idx)) return; + } + + + /* Notice changes in view */ + if (do_view) + { + /* Update some things */ + p_ptr->update |= (PU_VIEW | PU_FLOW | PU_MONSTERS | PU_MON_LITE); + } + + + /* Learn things from observable monster */ + if (m_ptr->ml) + { + /* Monster opened a door */ + if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR); + + /* Monster bashed a door */ + if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR); + + /* Monster tried to pick something up */ + if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM); + + /* Monster tried to crush something */ + if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM); + + /* Monster pushed past another monster */ + if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY); + + /* Monster ate another monster */ + if (did_kill_body) r_ptr->r_flags2 |= (RF2_KILL_BODY); + + /* Monster passed through a wall */ + if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL); + + /* Monster destroyed a wall */ + if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL); + } + + + /* Hack -- get "bold" if out of options */ + if (!do_turn && !do_move && m_ptr->monfear) + { + /* No longer afraid */ + m_ptr->monfear = 0; + + /* Message if seen */ + if (m_ptr->ml) + { + char m_name[80]; + + /* Acquire the monster name */ + monster_desc(m_name, m_ptr, 0); + + /* Dump a message */ + msg_format("%^s turns to fight!", m_name); + } + + /* XXX XXX XXX Actually do something now (?) */ + } +} + + +void summon_maint(int m_idx) +{ + + monster_type *m_ptr = &m_list[m_idx]; + + /* Can you pay? */ + if ((s32b)(p_ptr->maintain_sum / 10000) > p_ptr->csp) + { + char m_name[80]; + + monster_desc(m_name, m_ptr, 0); + + msg_format("You lose control of %s.", m_name); + + /* Well, then, I guess I'm dead. */ + delete_monster_idx(m_idx); + } + else + { + s32b cl, ml, floor, cost; + + cl = get_skill_scale(SKILL_SUMMON, 100); + ml = m_ptr->level * 10000; + + /* Floor = 19 * ml / 990 + 8 / 199 + This gives a floor of 0.1 at level 1 and a floor of 2 at level 100 + + Since ml is multiplied by 10000 already, we multiply the 8/199 too + */ + floor = ml * 19 / 990 + 80000 / 199; + cost = (ml / cl - 10000) / 4; + if(cost < floor) + cost = floor; + + /* Well, then I'll take my wages from you. */ + p_ptr->maintain_sum += cost; + } + return; +} + + +/* + * Process all the "live" monsters, once per game turn. + * + * During each game turn, we scan through the list of all the "live" monsters, + * (backwards, so we can excise any "freshly dead" monsters), energizing each + * monster, and allowing fully energized monsters to move, attack, pass, etc. + * + * Note that monsters can never move in the monster array (except when the + * "compact_monsters()" function is called by "dungeon()" or "save_player()"). + * + * This function is responsible for at least half of the processor time + * on a normal system with a "normal" amount of monsters and a player doing + * normal things. + * + * When the player is resting, virtually 90% of the processor time is spent + * in this function, and its children, "process_monster()" and "make_move()". + * + * Most of the rest of the time is spent in "update_view()" and "lite_spot()", + * especially when the player is running. + * + * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh" + * monsters while they are still being "born". A monster is "fresh" only + * during the turn in which it is created, and we use the "hack_m_idx" to + * determine if the monster is yet to be processed during the current turn. + * + * Note the special "MFLAG_NICE" flag, which allows the player to get one + * move before any "nasty" monsters get to use their spell attacks. + * + * Note that when the "knowledge" about the currently tracked monster + * changes (flags, attacks, spells), we induce a redraw of the monster + * recall window. + */ +void process_monsters(void) +{ + int i, e; + int fx, fy; + + bool_ test; + bool_ is_frien = FALSE; + + monster_type *m_ptr; + monster_race *r_ptr; + + int old_monster_race_idx; + + u32b old_r_flags1 = 0L; + u32b old_r_flags2 = 0L; + u32b old_r_flags3 = 0L; + u32b old_r_flags4 = 0L; + u32b old_r_flags5 = 0L; + u32b old_r_flags6 = 0L; + + byte old_r_blows0 = 0; + byte old_r_blows1 = 0; + byte old_r_blows2 = 0; + byte old_r_blows3 = 0; + + byte old_r_cast_inate = 0; + byte old_r_cast_spell = 0; + + /* Check the doppleganger */ + if (doppleganger && !(r_info[m_list[doppleganger].r_idx].flags9 & RF9_DOPPLEGANGER)) + doppleganger = 0; + + /* Memorize old race */ + old_monster_race_idx = monster_race_idx; + + /* Acquire knowledge */ + if (monster_race_idx) + { + /* Acquire current monster */ + r_ptr = &r_info[monster_race_idx]; + + /* Memorize flags */ + old_r_flags1 = r_ptr->r_flags1; + old_r_flags2 = r_ptr->r_flags2; + old_r_flags3 = r_ptr->r_flags3; + old_r_flags4 = r_ptr->r_flags4; + old_r_flags5 = r_ptr->r_flags5; + old_r_flags6 = r_ptr->r_flags6; + + /* Memorize blows */ + old_r_blows0 = r_ptr->r_blows[0]; + old_r_blows1 = r_ptr->r_blows[1]; + old_r_blows2 = r_ptr->r_blows[2]; + old_r_blows3 = r_ptr->r_blows[3]; + + /* Memorize castings */ + old_r_cast_inate = r_ptr->r_cast_inate; + old_r_cast_spell = r_ptr->r_cast_spell; + } + + + /* Hack -- calculate the "player noise" */ + noise = (1L << (30 - p_ptr->skill_stl)); + + + /* Process the monsters (backwards) */ + for (i = m_max - 1; i >= 1; i--) + { + /* Access the monster */ + m_ptr = &m_list[i]; + + /* Handle "leaving" */ + if (p_ptr->leaving) break; + + /* Ignore "dead" monsters */ + if (!m_ptr->r_idx) continue; + + /* Calculate "upkeep" for friendly monsters */ + if (m_ptr->status == MSTATUS_PET) + { + total_friends++; + total_friend_levels += m_ptr->level; + } + + + /* Handle "fresh" monsters */ + if (m_ptr->mflag & (MFLAG_BORN)) + { + /* No longer "fresh" */ + m_ptr->mflag &= ~(MFLAG_BORN); + + /* Skip */ + continue; + } + + + /* Obtain the energy boost */ + e = extract_energy[m_ptr->mspeed]; + + /* Give this monster some energy */ + m_ptr->energy += e; + + + /* Not enough energy to move */ + if (m_ptr->energy < 100) continue; + + /* Use up "some" energy */ + m_ptr->energy -= 100; + + + /* Hack -- Require proximity */ + if (m_ptr->cdis >= 100) continue; + + + /* Access the race */ + r_ptr = race_inf(m_ptr); + + /* Access the location */ + fx = m_ptr->fx; + fy = m_ptr->fy; + + + /* Assume no move */ + test = FALSE; + + /* Control monster aint affected by distance */ + if (p_ptr->control == i) + { + test = TRUE; + } + + /* No free upkeep on partial summons just because they're out + * of line of sight. */ + else if (m_ptr->mflag & MFLAG_PARTIAL) test = TRUE; + + /* Handle "sensing radius" */ + else if (m_ptr->cdis <= r_ptr->aaf) + { + /* We can "sense" the player */ + test = TRUE; + } + + /* Handle "sight" and "aggravation" */ + else if ((m_ptr->cdis <= MAX_SIGHT) && + (player_has_los_bold(fy, fx) || + p_ptr->aggravate)) + { + /* We can "see" or "feel" the player */ + test = TRUE; + } + + /* Hack -- Monsters can "smell" the player from far away */ + /* Note that most monsters have "aaf" of "20" or so */ + else if (flow_by_sound && + (cave[p_ptr->py][p_ptr->px].when == cave[fy][fx].when) && + (cave[fy][fx].cost < MONSTER_FLOW_DEPTH) && + (cave[fy][fx].cost < r_ptr->aaf)) + { + /* We can "smell" the player */ + test = TRUE; + } + + /* Running away wont save them ! */ + if (m_ptr->poisoned || m_ptr->bleeding) test = TRUE; + + /* Do nothing */ + if (!test) continue; + + /* Save global index */ + hack_m_idx = i; + + if (is_friend(m_ptr) > 0) is_frien = TRUE; + + /* Process the monster */ + process_monster(i, is_frien); + + /* Hack -- notice death or departure */ + if (!alive || death) break; + + /* If it's still alive and friendly, charge upkeep. */ + if (m_ptr->mflag & MFLAG_PARTIAL) summon_maint(i); + + /* Notice leaving */ + if (p_ptr->leaving) break; + } + + /* Reset global index */ + hack_m_idx = 0; + + + /* Tracking a monster race (the same one we were before) */ + if (monster_race_idx && (monster_race_idx == old_monster_race_idx)) + { + /* Acquire monster race */ + r_ptr = &r_info[monster_race_idx]; + + /* Check for knowledge change */ + if ((old_r_flags1 != r_ptr->r_flags1) || + (old_r_flags2 != r_ptr->r_flags2) || + (old_r_flags3 != r_ptr->r_flags3) || + (old_r_flags4 != r_ptr->r_flags4) || + (old_r_flags5 != r_ptr->r_flags5) || + (old_r_flags6 != r_ptr->r_flags6) || + (old_r_blows0 != r_ptr->r_blows[0]) || + (old_r_blows1 != r_ptr->r_blows[1]) || + (old_r_blows2 != r_ptr->r_blows[2]) || + (old_r_blows3 != r_ptr->r_blows[3]) || + (old_r_cast_inate != r_ptr->r_cast_inate) || + (old_r_cast_spell != r_ptr->r_cast_spell)) + { + /* Window stuff */ + p_ptr->window |= (PW_MONSTER); + } + } +} -- cgit v1.2.3 From 62bcb16ba7fdda8f87d5b698546c4b3ba4b721cd Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Jun 2014 09:40:26 +0200 Subject: Remove a usage of vstrnfmt() --- src/melee2.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 0a139f89..5b3251ef 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -962,12 +962,20 @@ void monster_msg(cptr fmt, ...) /* End the Varargs Stuff */ va_end(vp); + /* Print */ + monster_msg_simple(buf); +} + +void monster_msg_simple(cptr s) +{ /* Display */ if (disturb_other) - msg_print(buf); + { + msg_print(s); + } else { - message_add(buf, TERM_WHITE); + message_add(s, TERM_WHITE); p_ptr->window |= PW_MESSAGE; } } -- cgit v1.2.3 From ca71ccff098e4eec97480d2a08773a06629cc66e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 26 Jun 2014 06:50:06 +0200 Subject: Simplify PR_* redraw code and remove direct references to Term members --- src/melee2.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 5b3251ef..a7975638 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -39,7 +39,7 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) s32b div, new_exp, new_exp_frac; /* Redraw (later) if needed */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); /* Some mosnters are immune to death */ if (r_ptr->flags7 & RF7_NO_DEATH) return FALSE; @@ -1702,7 +1702,7 @@ static bool_ monst_spell_monst(int m_idx) if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp; /* Redraw (later) if needed */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); /* Special message */ if (seen) @@ -2241,7 +2241,7 @@ static bool_ monst_spell_monst(int m_idx) } /* Redraw (later) if needed */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); /* Cancel fear */ if (m_ptr->monfear) @@ -3665,7 +3665,7 @@ bool_ make_attack_spell(int m_idx) } /* Redraw mana */ - p_ptr->redraw |= (PR_MANA); + p_ptr->redraw |= (PR_FRAME); /* Window stuff */ p_ptr->window |= (PW_PLAYER); @@ -3678,7 +3678,7 @@ bool_ make_attack_spell(int m_idx) if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp; /* Redraw (later) if needed */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); /* Special message */ if (seen) @@ -4193,7 +4193,7 @@ bool_ make_attack_spell(int m_idx) } /* Redraw (later) if needed */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); /* Cancel fear */ if (m_ptr->monfear) @@ -6146,7 +6146,7 @@ static void process_monster(int m_idx, bool_ is_frien) msg_format("%^s is no longer bleeding.", m_name); /* Hack -- Update the health bar */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); } } } @@ -6185,7 +6185,7 @@ static void process_monster(int m_idx, bool_ is_frien) msg_format("%^s is no longer poisoned.", m_name); /* Hack -- Update the health bar */ - if (health_who == m_idx) p_ptr->redraw |= (PR_HEALTH); + if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); } } } -- cgit v1.2.3 From 76d1d3f63fef965ba0a2d5ccea3408ad36e9ce4c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 18 Dec 2014 00:00:35 +0100 Subject: Remove all uses of sglib --- src/melee2.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index a7975638..f35e1e80 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -21,6 +21,8 @@ #include "quark.h" #include "hooks.h" +#include + #define SPEAK_CHANCE 8 #define GRINDNOISE 20 -- cgit v1.2.3 From 9a10050acb1c6398eedfe9c20611ac31f17802d5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 18 Dec 2014 20:38:17 +0100 Subject: Update HOOK_MON_SPEAK to new-style hook --- src/melee2.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index f35e1e80..d4f2e9ff 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6423,7 +6423,8 @@ static void process_monster(int m_idx, bool_ is_frien) /* Try for the unique's lines in "monspeak.txt" first. */ /* 0 is SUCCESS, of course.... */ - if (!process_hooks(HOOK_MON_SPEAK, "(d,s)", m_idx, m_name)) + struct hook_mon_speak_in in = { m_idx, m_name }; + if (!process_hooks_new(HOOK_MON_SPEAK, &in, NULL)) { if (get_xtra_line("monspeak.txt", m_ptr, monmessage) != 0) { -- cgit v1.2.3 From c1a907e0bf6acc94e77f5af50cd8099977a9ab30 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 21 Dec 2014 14:38:46 +0100 Subject: Update HOOK_MONSTER_AI to new-style hook --- src/melee2.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index d4f2e9ff..f3dc1301 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -5119,10 +5119,12 @@ static bool_ get_moves(int m_idx, int *mm) /* Let quests redefine AI */ if (r_ptr->flags7 & RF7_AI_SPECIAL) { - if (process_hooks_ret(HOOK_MONSTER_AI, "dd", "(d)", m_idx)) + struct hook_monster_ai_in in = { m_idx, &m_list[m_idx] }; + struct hook_monster_ai_out out = { 0, 0 }; + if (process_hooks_new(HOOK_MONSTER_AI, &in, &out)) { - y2 = process_hooks_return[0].num; - x2 = process_hooks_return[1].num; + y2 = out.y; + x2 = out.x; } } -- cgit v1.2.3 From c67bb95861c02f01988205c0879c72c53fc3c92e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Remove speak_unique option --- src/melee2.cc | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index f3dc1301..8479f68b 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6405,42 +6405,39 @@ static void process_monster(int m_idx, bool_ is_frien) if (ai_multiply(m_idx)) return; } - if (speak_unique) + if (randint(SPEAK_CHANCE) == 1) { - if (randint(SPEAK_CHANCE) == 1) + if (player_has_los_bold(oy, ox) && (r_ptr->flags2 & RF2_CAN_SPEAK)) { - if (player_has_los_bold(oy, ox) && (r_ptr->flags2 & RF2_CAN_SPEAK)) - { - char m_name[80]; - char monmessage[80]; + char m_name[80]; + char monmessage[80]; - /* Acquire the monster name/poss */ - if (m_ptr->ml) - monster_desc(m_name, m_ptr, 0); - else - strcpy(m_name, "It"); + /* Acquire the monster name/poss */ + if (m_ptr->ml) + monster_desc(m_name, m_ptr, 0); + else + strcpy(m_name, "It"); - /* xtra_line function by Matt Graham--allow uniques to */ - /* say "unique" things based on their monster index. */ - /* Try for the unique's lines in "monspeak.txt" first. */ - /* 0 is SUCCESS, of course.... */ + /* xtra_line function by Matt Graham--allow uniques to */ + /* say "unique" things based on their monster index. */ + /* Try for the unique's lines in "monspeak.txt" first. */ + /* 0 is SUCCESS, of course.... */ - struct hook_mon_speak_in in = { m_idx, m_name }; - if (!process_hooks_new(HOOK_MON_SPEAK, &in, NULL)) + struct hook_mon_speak_in in = { m_idx, m_name }; + if (!process_hooks_new(HOOK_MON_SPEAK, &in, NULL)) + { + if (get_xtra_line("monspeak.txt", m_ptr, monmessage) != 0) { - if (get_xtra_line("monspeak.txt", m_ptr, monmessage) != 0) - { - /* Get a message from old defaults if new don't work */ + /* Get a message from old defaults if new don't work */ - if (is_friend(m_ptr) > 0) - get_rnd_line("speakpet.txt", monmessage); - else if (m_ptr->monfear) - get_rnd_line("monfear.txt", monmessage); - else - get_rnd_line("bravado.txt", monmessage); - } - msg_format("%^s %s", m_name, monmessage); + if (is_friend(m_ptr) > 0) + get_rnd_line("speakpet.txt", monmessage); + else if (m_ptr->monfear) + get_rnd_line("monfear.txt", monmessage); + else + get_rnd_line("bravado.txt", monmessage); } + msg_format("%^s %s", m_name, monmessage); } } } -- cgit v1.2.3 From 505f310399c9d113874250b697692112ca48411c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove effectively unused variables --- src/melee2.cc | 39 --------------------------------------- 1 file changed, 39 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 8479f68b..de16d2f8 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2916,14 +2916,6 @@ void curse_equipment_dg(int chance, int heavy_chance) * Perhaps smart monsters should decline to use "bolt" spells if * there is a monster in the way, unless they wish to kill it. * - * Note that, to allow the use of the "track_target" option at some - * later time, certain non-optimal things are done in the code below, - * including explicit checks against the "direct" variable, which is - * currently always true by the time it is checked, but which should - * really be set according to an explicit "projectable()" test, and - * the use of generic "x,y" locations instead of the player location, - * with those values being initialized with the player location. - * * It will not be possible to "correctly" handle the case in which a * monster attempts to attack a location which is thought to contain * the player, but which in fact is nowhere near the player, since this @@ -2937,12 +2929,6 @@ void curse_equipment_dg(int chance, int heavy_chance) * could be left in a bizarre situation after the player ducked behind a * pillar and then teleported away, for example. * - * Note that certain spell attacks do not use the "project()" function - * but "simulate" it via the "direct" variable, which is always at least - * as restrictive as the "project()" function. This is necessary to - * prevent "blindness" attacks and such from bending around walls, etc, - * and to allow the use of the "track_target" option in the future. - * * Note that this function attempts to optimize the use of spells for the * cases in which the monster has no spells, or has spells but cannot use * them, or has spells but they will have no "useful" effect. Note that @@ -2974,9 +2960,6 @@ bool_ make_attack_spell(int m_idx) /* Assume "normal" target */ bool_ normal = TRUE; - /* Assume "projectable" */ - bool_ direct = TRUE; - /* Target location */ if (m_ptr->target > -1) { @@ -3014,9 +2997,6 @@ bool_ make_attack_spell(int m_idx) /* Sometimes forbid inate attacks (breaths) */ if (rand_int(100) >= (chance * 2)) no_inate = TRUE; - /* XXX XXX XXX Handle "track_target" option (?) */ - - /* Hack -- require projectable player */ if (normal) { @@ -3163,7 +3143,6 @@ bool_ make_attack_spell(int m_idx) /* RF4_SHRIEK */ case 96 + 0: { - if (!direct) break; disturb(1); msg_format("%^s makes a high pitched shriek.", m_name); aggravate_monsters(m_idx); @@ -3638,7 +3617,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_DRAIN_MANA */ case 128 + 9: { - if (!direct) break; if (p_ptr->csp) { int r1; @@ -3696,7 +3674,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_MIND_BLAST */ case 128 + 10: { - if (!direct) break; disturb(1); if (!seen) { @@ -3733,7 +3710,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_BRAIN_SMASH */ case 128 + 11: { - if (!direct) break; disturb(1); if (!seen) { @@ -3782,7 +3758,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_CAUSE_1 */ case 128 + 12: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s points at you and curses.", m_name); @@ -3801,7 +3776,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_CAUSE_2 */ case 128 + 13: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s points at you and curses horribly.", m_name); @@ -3820,7 +3794,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_CAUSE_3 */ case 128 + 14: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles loudly.", m_name); else msg_format("%^s points at you, incanting terribly!", m_name); @@ -3839,7 +3812,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_CAUSE_4 */ case 128 + 15: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s screams the word 'DIE!'", m_name); else msg_format("%^s points at you, screaming the word DIE!", m_name); @@ -3981,7 +3953,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_SCARE */ case 128 + 27: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles, and you hear scary noises.", m_name); else msg_format("%^s casts a fearful illusion.", m_name); @@ -4004,7 +3975,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_BLIND */ case 128 + 28: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a spell, burning your eyes!", m_name); @@ -4027,7 +3997,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_CONF */ case 128 + 29: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles, and you hear puzzling noises.", m_name); else msg_format("%^s creates a mesmerizing illusion.", m_name); @@ -4050,7 +4019,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_SLOW */ case 128 + 30: { - if (!direct) break; disturb(1); msg_format("%^s drains power from your muscles!", m_name); if (p_ptr->free_act) @@ -4072,7 +4040,6 @@ bool_ make_attack_spell(int m_idx) /* RF5_HOLD */ case 128 + 31: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s stares deep into your eyes!", m_name); @@ -4244,7 +4211,6 @@ bool_ make_attack_spell(int m_idx) /* RF6_TELE_TO */ case 160 + 6: { - if (!direct) break; disturb(1); msg_format("%^s commands you to return.", m_name); teleport_player_to(m_ptr->fy, m_ptr->fx); @@ -4254,7 +4220,6 @@ bool_ make_attack_spell(int m_idx) /* RF6_TELE_AWAY */ case 160 + 7: { - if (!direct) break; disturb(1); msg_format("%^s teleports you away.", m_name); teleport_player(100); @@ -4264,7 +4229,6 @@ bool_ make_attack_spell(int m_idx) /* RF6_TELE_LEVEL */ case 160 + 8: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles strangely.", m_name); else msg_format("%^s gestures at your feet.", m_name); @@ -4287,7 +4251,6 @@ bool_ make_attack_spell(int m_idx) /* RF6_DARKNESS */ case 160 + 9: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s gestures in shadow.", m_name); @@ -4298,7 +4261,6 @@ bool_ make_attack_spell(int m_idx) /* RF6_TRAPS */ case 160 + 10: { - if (!direct) break; disturb(1); if (blind) msg_format("%^s mumbles, and then cackles evilly.", m_name); else msg_format("%^s casts a spell and cackles evilly.", m_name); @@ -4309,7 +4271,6 @@ bool_ make_attack_spell(int m_idx) /* RF6_FORGET */ case 160 + 11: { - if (!direct) break; disturb(1); msg_format("%^s tries to blank your mind.", m_name); -- cgit v1.2.3 From dc4b789acb2e6737dd6ed5721b3efbde1a2be14f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move skills.cc function declarations to skills.hpp --- src/melee2.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index de16d2f8..ff3a9150 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -17,9 +17,10 @@ #include "angband.h" +#include "hooks.h" #include "messages.h" #include "quark.h" -#include "hooks.h" +#include "skills.hpp" #include -- cgit v1.2.3 From 5ef53fee463b7f93b8b890ed8e6ff0db778bd596 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move xtra2.cc functions to separate header Remove some functions and make others static while we're at it. --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index ff3a9150..744e99fe 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -21,6 +21,7 @@ #include "messages.h" #include "quark.h" #include "skills.hpp" +#include "xtra2.hpp" #include -- cgit v1.2.3 From 55a098461106d1ca4a72e30eaa572470433b6f5f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Make make_attack_spell() static --- src/melee2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 744e99fe..7032e511 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2939,7 +2939,7 @@ void curse_equipment_dg(int chance, int heavy_chance) * Note the special "MFLAG_NICE" flag, which prevents a monster from using * any spell attacks until the player has had a single chance to move. */ -bool_ make_attack_spell(int m_idx) +static bool_ make_attack_spell(int m_idx) { int k, chance, thrown_spell, rlev, failrate; byte spell[96], num = 0; -- cgit v1.2.3 From b0eb19b7a0750759d429c78845888e88de517352 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Remove smart_cheat option Behave as if always FALSE. --- src/melee2.cc | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 7032e511..6832eb39 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -261,10 +261,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) * * This has the added advantage that attacks and spells are related. * The "smart_learn" option means that the monster "learns" the flags -* that should be set, and "smart_cheat" means that he "knows" them. -* So "smart_cheat" means that the "smart" field is always up to date, -* while "smart_learn" means that the "smart" field is slowly learned. -* Both of them have the same effect on the "choose spell" routine. +* that should be set. */ @@ -303,7 +300,7 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) /* Must be cheating or learning */ - if (!smart_cheat && !smart_learn) return; + if (!smart_learn) return; /* Update acquired knowledge */ @@ -317,47 +314,6 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) } - /* Cheat if requested */ - if (smart_cheat) - { - /* Know basic info */ - if (p_ptr->resist_acid) smart |= (SM_RES_ACID); - if (p_ptr->oppose_acid) smart |= (SM_OPP_ACID); - if (p_ptr->immune_acid) smart |= (SM_IMM_ACID); - if (p_ptr->resist_elec) smart |= (SM_RES_ELEC); - if (p_ptr->oppose_elec) smart |= (SM_OPP_ELEC); - if (p_ptr->immune_elec) smart |= (SM_IMM_ELEC); - if (p_ptr->resist_fire) smart |= (SM_RES_FIRE); - if (p_ptr->oppose_fire) smart |= (SM_OPP_FIRE); - if (p_ptr->immune_fire) smart |= (SM_IMM_FIRE); - if (p_ptr->resist_cold) smart |= (SM_RES_COLD); - if (p_ptr->oppose_cold) smart |= (SM_OPP_COLD); - if (p_ptr->immune_cold) smart |= (SM_IMM_COLD); - - /* Know poison info */ - if (p_ptr->resist_pois) smart |= (SM_RES_POIS); - if (p_ptr->oppose_pois) smart |= (SM_OPP_POIS); - - /* Know special resistances */ - if (p_ptr->resist_neth) smart |= (SM_RES_NETH); - if (p_ptr->resist_lite) smart |= (SM_RES_LITE); - if (p_ptr->resist_dark) smart |= (SM_RES_DARK); - if (p_ptr->resist_fear) smart |= (SM_RES_FEAR); - if (p_ptr->resist_conf) smart |= (SM_RES_CONF); - if (p_ptr->resist_chaos) smart |= (SM_RES_CHAOS); - if (p_ptr->resist_disen) smart |= (SM_RES_DISEN); - if (p_ptr->resist_blind) smart |= (SM_RES_BLIND); - if (p_ptr->resist_nexus) smart |= (SM_RES_NEXUS); - if (p_ptr->resist_sound) smart |= (SM_RES_SOUND); - if (p_ptr->resist_shard) smart |= (SM_RES_SHARD); - if (p_ptr->reflect) smart |= (SM_IMM_REFLECT); - - /* Know bizarre "resistances" */ - if (p_ptr->free_act) smart |= (SM_IMM_FREE); - if (!p_ptr->msp) smart |= (SM_IMM_MANA); - } - - /* Nothing known */ if (!smart) return; -- cgit v1.2.3 From fe6ebd4af16244a02e16eb095181c0d8d5c56858 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cave.cc function declarations to separate header --- src/melee2.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 6832eb39..bf294b9e 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -1,14 +1,10 @@ -/* File: melee2.c */ - -/* Purpose: Monster spells and movement */ - /* -* Copyright (c) 1989 James E. Wilson, Robert A. Koeneke -* -* This software may be copied and distributed for educational, research, and -* not for profit purposes provided that this copyright and statement are -* included in all such copies. -*/ + * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke + * + * This software may be copied and distributed for educational, research, and + * not for profit purposes provided that this copyright and statement are + * included in all such copies. + */ /* * This file has several additions to it by Keldon Jones (keldon@umr.edu) @@ -17,6 +13,7 @@ #include "angband.h" +#include "cave.hpp" #include "hooks.h" #include "messages.h" #include "quark.h" -- cgit v1.2.3 From 205a2dab56c8661413f2927737794fdd57437075 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd1.cc function declarations to separate header file Also remove unused step_effects() function while we're at it --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index bf294b9e..11bc5de0 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -14,6 +14,7 @@ #include "angband.h" #include "cave.hpp" +#include "cmd1.hpp" #include "hooks.h" #include "messages.h" #include "quark.h" -- cgit v1.2.3 From f19edf28cf16a0776f54753d953901b91f54e278 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split traps.cc function declarations to separate file --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 11bc5de0..8d24878a 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -19,6 +19,7 @@ #include "messages.h" #include "quark.h" #include "skills.hpp" +#include "traps.hpp" #include "xtra2.hpp" #include -- cgit v1.2.3 From 901657b0c61ab16cceaef875d3ecd0b9f2bbbc5b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split spells1.cc declarations to separate header file Make a couple of the functions static while we're at it --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 8d24878a..5a3f2301 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -19,6 +19,7 @@ #include "messages.h" #include "quark.h" #include "skills.hpp" +#include "spells1.hpp" #include "traps.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From 22d802ecbdbee5b06d32d1643af01744689c8b87 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split spells2.cc function declarations to separate header file --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 5a3f2301..860c7f94 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -20,6 +20,7 @@ #include "quark.h" #include "skills.hpp" #include "spells1.hpp" +#include "spells2.hpp" #include "traps.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From 37ac44add61e4547507770017dcb85b53c20acb5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split util.cc function declarations into separate header files We need one .h file and one .hpp since some of the functions are being called from plain C code. --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 860c7f94..acff1f87 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -22,6 +22,7 @@ #include "spells1.hpp" #include "spells2.hpp" #include "traps.hpp" +#include "util.hpp" #include "xtra2.hpp" #include -- cgit v1.2.3 From d379c47aaec011921c1d09140ee1098a7053b5b6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster2.cc declarations into separate header --- src/melee2.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index acff1f87..6cb1420d 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -17,6 +17,7 @@ #include "cmd1.hpp" #include "hooks.h" #include "messages.h" +#include "monster2.hpp" #include "quark.h" #include "skills.hpp" #include "spells1.hpp" @@ -32,6 +33,8 @@ #define FOLLOW_DISTANCE 6 +static void cmonster_msg(char a, cptr fmt, ...); + /* * Based on mon_take_hit... all monster attacks on * other monsters should use @@ -909,7 +912,7 @@ static void monst_bolt_monst(int m_idx, int y, int x, int typ, int dam_hp) } -void monster_msg(cptr fmt, ...) +static void monster_msg(cptr fmt, ...) { va_list vp; -- cgit v1.2.3 From d2b23810e3349e7cb12d8c51d2a630c6a31d7cd0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster3.cc declarations to separate header file --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 6cb1420d..bc0bfb0a 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -18,6 +18,7 @@ #include "hooks.h" #include "messages.h" #include "monster2.hpp" +#include "monster3.hpp" #include "quark.h" #include "skills.hpp" #include "spells1.hpp" -- cgit v1.2.3 From 7bdfa1a20c8921e53baecdd12b48870417f8b426 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split files.cc declarations into separate header files --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index bc0bfb0a..9ac7ff4c 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -15,6 +15,7 @@ #include "cave.hpp" #include "cmd1.hpp" +#include "files.hpp" #include "hooks.h" #include "messages.h" #include "monster2.hpp" -- cgit v1.2.3 From cfc0a04155eda35a4fe80ef72fd2b0f9eb10856b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split object*.cc declarations into separate header files --- src/melee2.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 9ac7ff4c..dd349f39 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -20,6 +20,8 @@ #include "messages.h" #include "monster2.hpp" #include "monster3.hpp" +#include "object1.hpp" +#include "object2.hpp" #include "quark.h" #include "skills.hpp" #include "spells1.hpp" -- cgit v1.2.3 From 3b5446d7c303099094f84a32df29d2d9dc2049d0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Move melee*.cc declaration to separate header files --- src/melee2.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index dd349f39..638b7151 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -11,12 +11,14 @@ * to improve the general quality of the AI (version 0.1.1). */ -#include "angband.h" +#include "melee2.hpp" +#include "angband.h" #include "cave.hpp" #include "cmd1.hpp" #include "files.hpp" #include "hooks.h" +#include "melee1.hpp" #include "messages.h" #include "monster2.hpp" #include "monster3.hpp" -- cgit v1.2.3 From 72ceb4f2aba3b86be43ba9a7cb5c576b79920543 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split option variables into separate header and source file Remove unused testing_stack testing_carry options while we're at it. --- src/melee2.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 638b7151..58aa68cb 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -24,6 +24,7 @@ #include "monster3.hpp" #include "object1.hpp" #include "object2.hpp" +#include "options.hpp" #include "quark.h" #include "skills.hpp" #include "spells1.hpp" @@ -7083,8 +7084,7 @@ static void process_monster(int m_idx, bool_ is_frien) msg_format("%^s picks up %s.", m_name, o_name); } - /* Option */ - if (testing_carry) + /* Put into inventory of monster */ { /* Excise the object */ excise_object_idx(this_o_idx); @@ -7104,13 +7104,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Carry object */ m_ptr->hold_o_idx = this_o_idx; } - - /* Nope */ - else - { - /* Delete the object */ - delete_object_idx(this_o_idx); - } } /* Destroy the item */ -- cgit v1.2.3 From f93c700dc8320da438ad46b59b2541e29d9b6d68 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split tables.cc declarations into separate header files --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 58aa68cb..e1c8eaf1 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -29,6 +29,7 @@ #include "skills.hpp" #include "spells1.hpp" #include "spells2.hpp" +#include "tables.hpp" #include "traps.hpp" #include "util.hpp" #include "xtra2.hpp" -- cgit v1.2.3 From 6f612c6e6cf9b20c00fd2f515d3694d2b7f7f444 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split variables.cc declarations to separate header files - Can now remove externs.h. Yay! - Put a stray option variable into its rightful place in options.hpp --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index e1c8eaf1..fdd31846 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -32,6 +32,7 @@ #include "tables.hpp" #include "traps.hpp" #include "util.hpp" +#include "variable.hpp" #include "xtra2.hpp" #include -- cgit v1.2.3 From c17c9486a22ce9f2160b2d2ad559d9a19e453f83 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 15:22:02 +0100 Subject: Rename miscellaneous .h headers to .hpp --- src/melee2.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index fdd31846..09c47340 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -17,15 +17,15 @@ #include "cave.hpp" #include "cmd1.hpp" #include "files.hpp" -#include "hooks.h" +#include "hooks.hpp" #include "melee1.hpp" -#include "messages.h" +#include "messages.hpp" #include "monster2.hpp" #include "monster3.hpp" #include "object1.hpp" #include "object2.hpp" #include "options.hpp" -#include "quark.h" +#include "quark.hpp" #include "skills.hpp" #include "spells1.hpp" #include "spells2.hpp" -- cgit v1.2.3 From c8a270e51dc22f39ed048ab1cc609e6e456df58f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Split types.h into separate header for each type --- src/melee2.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 09c47340..da37f760 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -13,22 +13,30 @@ #include "melee2.hpp" -#include "angband.h" #include "cave.hpp" +#include "cave_type.hpp" #include "cmd1.hpp" +#include "feature_type.hpp" #include "files.hpp" +#include "hook_mon_speak_in.hpp" +#include "hook_monster_ai_in.hpp" +#include "hook_monster_ai_out.hpp" #include "hooks.hpp" #include "melee1.hpp" #include "messages.hpp" #include "monster2.hpp" #include "monster3.hpp" +#include "monster_race.hpp" +#include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" #include "options.hpp" +#include "player_type.hpp" #include "quark.hpp" #include "skills.hpp" #include "spells1.hpp" #include "spells2.hpp" +#include "stats.hpp" #include "tables.hpp" #include "traps.hpp" #include "util.hpp" -- cgit v1.2.3 From c6196b25d119a10e79deedef26a73e0d5a021b0e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 12 Jun 2015 06:27:05 +0200 Subject: Refactor cave_type and monster_type to use non-intrusive lists We use vectors of object indexes instead of embedding the list within object_type itself. --- src/melee2.cc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index da37f760..8e5f09cd 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6934,8 +6934,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Creature has been allowed move */ if (do_move) { - s16b this_o_idx, next_o_idx = 0; - /* Take a turn */ do_turn = TRUE; @@ -7005,16 +7003,14 @@ static void process_monster(int m_idx, bool_ is_frien) } else { + /* Copy list of objects; we need a copy because we're mutating the list. */ + auto const object_idxs(c_ptr->o_idxs); + /* Scan all objects in the grid */ - for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) + for (auto const this_o_idx: object_idxs) { - object_type * o_ptr; - /* Acquire object */ - o_ptr = &o_list[this_o_idx]; - - /* Acquire next object */ - next_o_idx = o_ptr->next_o_idx; + object_type * o_ptr = &o_list[this_o_idx]; /* Skip gold */ if (o_ptr->tval == TV_GOLD) continue; @@ -7108,11 +7104,8 @@ static void process_monster(int m_idx, bool_ is_frien) /* Memorize monster */ o_ptr->held_m_idx = m_idx; - /* Build a stack */ - o_ptr->next_o_idx = m_ptr->hold_o_idx; - /* Carry object */ - m_ptr->hold_o_idx = this_o_idx; + m_ptr->hold_o_idxs.push_back(this_o_idx); } } -- cgit v1.2.3 From baa22bb096d08b6304b0dada144fec128ac69974 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 21 Aug 2015 21:06:13 +0200 Subject: Remove unused IM_MELEE flag --- src/melee2.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 8e5f09cd..e62b72bb 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -5423,7 +5423,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) /* Not allowed to attack */ if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE; - if (tr_ptr->flags7 & RF7_IM_MELEE) return FALSE; /* Total armor */ ac = t_ptr->ac; -- cgit v1.2.3 From 3928bcfc90c4dcdeaa91aade191d4b4c7ae7d0ef Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 21 Aug 2015 19:10:14 +0200 Subject: Use magik() instead of explicitly using rand_int() --- src/melee2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index e62b72bb..05d91f3c 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -329,7 +329,7 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) if (smart_learn) { /* Hack -- Occasionally forget player status */ - if (m_ptr->smart && (rand_int(100) < 1)) m_ptr->smart = 0L; + if (m_ptr->smart && magik(1)) m_ptr->smart = 0L; /* Use the memorized flags */ smart = m_ptr->smart; -- cgit v1.2.3 From 00be445e9127922933dae91a3d68660a57f53c5b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Refactor race_info_idx() to avoid "invisible" static pointers --- src/melee2.cc | 254 +++++++++++++++++++++++++++------------------------------- 1 file changed, 116 insertions(+), 138 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 05d91f3c..8478addd 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -60,14 +60,11 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) { monster_type *m_ptr = &m_list[m_idx], *s_ptr = &m_list[s_idx]; - monster_race *r_ptr = race_inf(m_ptr); - - s32b div, new_exp, new_exp_frac; - /* Redraw (later) if needed */ if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); - /* Some mosnters are immune to death */ + /* Some monsters are immune to death */ + auto const r_ptr = m_ptr->race(); if (r_ptr->flags7 & RF7_NO_DEATH) return FALSE; /* Wake it up */ @@ -142,13 +139,13 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) if (get_skill(SKILL_LORE) && (s_ptr->status >= MSTATUS_PET)) { /* Maximum player level */ - div = p_ptr->max_plv; + s32b div = p_ptr->max_plv; /* Give some experience for the kill */ - new_exp = ((long)r_ptr->mexp * m_ptr->level) / div; + s32b new_exp = ((long)r_ptr->mexp * m_ptr->level) / div; /* Handle fractional experience */ - new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div) + s32b new_exp_frac = ((((long)r_ptr->mexp * m_ptr->level) % div) * 0x10000L / div) + p_ptr->exp_frac; /* Keep track of experience */ @@ -203,12 +200,8 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) { - monster_race *r_ptr = NULL; - assert(m_ptr != NULL); - r_ptr = race_inf(m_ptr); - /* Mega-Hack -- Pain cancels fear */ if (m_ptr->monfear && (dam > 0)) { @@ -233,6 +226,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) } /* Sometimes a monster gets scared by damage */ + auto const r_ptr = m_ptr->race(); if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR))) { int percentage; @@ -291,7 +285,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) /* * Internal probability routine */ -static bool_ int_outof(monster_race *r_ptr, int prob) +static bool_ int_outof(std::shared_ptr r_ptr, int prob) { /* Non-Smart monsters are half as "smart" */ if (!(r_ptr->flags2 & (RF2_SMART))) prob = prob / 2; @@ -308,7 +302,6 @@ static bool_ int_outof(monster_race *r_ptr, int prob) static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) { monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); u32b f4 = (*f4p); u32b f5 = (*f5p); @@ -317,7 +310,8 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) u32b smart = 0L; - /* Too stupid to know anything */ + /* Too stupid to know anything? */ + auto const r_ptr = m_ptr->race(); if (r_ptr->flags2 & (RF2_STUPID)) return; @@ -763,7 +757,6 @@ static bool_ spell_heal(byte spell) static int choose_attack_spell(int m_idx, byte spells[], byte num) { monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); byte escape[96], escape_num = 0; byte attack[96], attack_num = 0; @@ -773,9 +766,8 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num) byte haste[96], haste_num = 0; byte heal[96], heal_num = 0; - int i; - /* Stupid monsters choose randomly */ + auto const r_ptr = m_ptr->race(); if (r_ptr->flags2 & (RF2_STUPID)) { /* Pick at random */ @@ -783,7 +775,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num) } /* Categorize spells */ - for (i = 0; i < num; i++) + for (int i = 0; i < num; i++) { /* Escape spell? */ if (spell_escape(spells[i])) escape[escape_num++] = spells[i]; @@ -887,7 +879,7 @@ static void breath(int m_idx, int typ, int dam_hp, int rad) int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL; monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); + auto const r_ptr = m_ptr->race(); /* Determine the radius of the blast */ if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2; @@ -907,7 +899,7 @@ static void monst_breath_monst(int m_idx, int y, int x, int typ, int dam_hp, int int flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL; monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); + auto const r_ptr = m_ptr->race(); /* Determine the radius of the blast */ if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2; @@ -996,17 +988,13 @@ int monst_spell_monst_spell = -1; static bool_ monst_spell_monst(int m_idx) { int y = 0, x = 0; - int i = 1, k, t_idx; - int chance, thrown_spell, count = 0; + int i = 1; + int thrown_spell; byte spell[96], num = 0; char m_name[80], t_name[80]; char m_poss[80]; char ddesc[80]; - int rlev; /* monster level */ monster_type *m_ptr = &m_list[m_idx]; /* Attacker */ - monster_race *r_ptr = race_inf(m_ptr); - monster_type *t_ptr; /* Putative target */ - monster_race *tr_ptr; u32b f4, f5, f6; /* racial spell flags */ bool_ direct = TRUE; bool_ wake_up = FALSE; @@ -1030,7 +1018,8 @@ static bool_ monst_spell_monst(int m_idx) if (m_ptr->confused) return (FALSE); /* Hack -- Extract the spell probability */ - chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2; + const auto r_ptr = m_ptr->race(); + const int chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2; /* Not allowed to cast spells */ if ((!chance) && (monst_spell_monst_spell == -1)) return (FALSE); @@ -1050,9 +1039,10 @@ static bool_ monst_spell_monst(int m_idx) { - t_idx = i; - t_ptr = &m_list[t_idx]; - tr_ptr = race_inf(t_ptr); + int t_idx = i; + + monster_type *t_ptr = &m_list[t_idx]; + auto const tr_ptr = t_ptr->race(); /* Hack -- no fighting >100 squares from player */ if (t_ptr->cdis > MAX_RANGE) return FALSE; @@ -1065,7 +1055,7 @@ static bool_ monst_spell_monst(int m_idx) x = t_ptr->fx; /* Extract the monster level */ - rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); + const int rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); /* Extract the racial spell flags */ f4 = r_ptr->flags4; @@ -1087,19 +1077,19 @@ static bool_ monst_spell_monst(int m_idx) } /* Extract the "inate" spells */ - for (k = 0; k < 32; k++) + for (int k = 0; k < 32; k++) { if (f4 & (1L << k)) spell[num++] = k + 32 * 3; } /* Extract the "normal" spells */ - for (k = 0; k < 32; k++) + for (int k = 0; k < 32; k++) { if (f5 & (1L << k)) spell[num++] = k + 32 * 4; } /* Extract the "bizarre" spells */ - for (k = 0; k < 32; k++) + for (int k = 0; k < 32; k++) { if (f6 & (1L << k)) spell[num++] = k + 32 * 5; } @@ -1140,6 +1130,7 @@ static bool_ monst_spell_monst(int m_idx) see_either = (see_m || see_t); see_both = (see_m && see_t); + int count = 0; switch (thrown_spell) { /* RF4_SHRIEK */ @@ -1165,7 +1156,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons an animal!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); @@ -2244,7 +2235,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons some animals!", m_name); - for (k = 0; k < 4; k++) + for (int k = 0; k < 4; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); @@ -2376,7 +2367,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically codes some software bugs.", m_name); - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_BUG, TRUE); @@ -2393,7 +2384,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically codes some RNGs.", m_name); - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_RNG, TRUE); @@ -2411,7 +2402,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons a Thunderlord!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, TRUE); @@ -2432,7 +2423,7 @@ static bool_ monst_spell_monst(int m_idx) ((r_ptr->flags1) & RF1_UNIQUE ? "minions" : "kin")); summon_kin_type = r_ptr->d_char; /* Big hack */ - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_KIN, TRUE); @@ -2465,7 +2456,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons help!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE); @@ -2482,7 +2473,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons monsters!", m_name); - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE); @@ -2499,7 +2490,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons ants.", m_name); - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_ANT, TRUE); @@ -2516,7 +2507,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons spiders.", m_name); - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, TRUE); @@ -2533,7 +2524,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons hounds.", m_name); - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_HOUND, TRUE); @@ -2550,7 +2541,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons hydras.", m_name); - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, TRUE); @@ -2567,7 +2558,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons an angel!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, TRUE); @@ -2584,7 +2575,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons a demon!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_DEMON, TRUE); @@ -2601,7 +2592,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons an undead adversary!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, TRUE); @@ -2618,7 +2609,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons a dragon!", m_name); - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, TRUE); @@ -2635,7 +2626,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons greater undead!", m_name); - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); @@ -2655,7 +2646,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons ancient dragons!", m_name); - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, TRUE); @@ -2677,7 +2668,7 @@ static bool_ monst_spell_monst(int m_idx) else monster_msg("%^s magically summons a wraith!", m_name); - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { count += summon_specific(y, x, rlev, SUMMON_WRAITH); } @@ -2695,12 +2686,12 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons special opponents!", m_name); - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { if (!friendly) count += summon_specific(y, x, rlev, SUMMON_UNIQUE); } - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { if (friendly) count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); @@ -2922,8 +2913,6 @@ static bool_ make_attack_spell(int m_idx) int k, chance, thrown_spell, rlev, failrate; byte spell[96], num = 0; u32b f4, f5, f6; - monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); char m_name[80]; bool_ no_inate = FALSE; int x, y; @@ -2934,6 +2923,9 @@ static bool_ make_attack_spell(int m_idx) /* Extract the blind-ness */ bool_ blind = (p_ptr->blind ? TRUE : FALSE); + /* Get a pointer to the monster */ + monster_type *m_ptr = &m_list[m_idx]; + /* Extract the "see-able-ness" */ bool_ seen = (!blind && m_ptr->ml); @@ -2963,6 +2955,7 @@ static bool_ make_attack_spell(int m_idx) if (is_friend(m_ptr) >= 0) return (FALSE); /* Cannot attack the player if mortal and player fated to never die by the ... */ + auto const r_ptr = m_ptr->race(); if ((r_ptr->flags7 & RF7_MORTAL) && (p_ptr->no_mortal)) return (FALSE); /* Hack -- Extract the spell probability */ @@ -4693,23 +4686,17 @@ static int mon_will_run(int m_idx) */ static bool_ get_fear_moves_aux(int m_idx, int *yp, int *xp) { - int y, x, y1, x1, fy, fx, gy = 0, gx = 0; - int when = 0, score = -1; - int i; - - monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); - /* Monster flowing disabled */ if (!flow_by_sound) return (FALSE); /* Monster location */ - fy = m_ptr->fy; - fx = m_ptr->fx; + monster_type *m_ptr = &m_list[m_idx]; + const int fy = m_ptr->fy;; + const int fx = m_ptr->fx; /* Desired destination */ - y1 = fy - (*yp); - x1 = fx - (*xp); + int y1 = fy - (*yp); + int x1 = fx - (*xp); /* The player is not currently near the monster grid */ if (cave[fy][fx].when < cave[p_ptr->py][p_ptr->px].when) @@ -4719,17 +4706,24 @@ static bool_ get_fear_moves_aux(int m_idx, int *yp, int *xp) } /* Monster is too far away to use flow information */ + auto const r_ptr = m_ptr->race(); if (cave[fy][fx].cost > MONSTER_FLOW_DEPTH) return (FALSE); if (cave[fy][fx].cost > r_ptr->aaf) return (FALSE); + /* Loop state */ + int when = 0; + int gy = 0; + int gx = 0; + int score = -1; + /* Check nearby grids, diagonals first */ - for (i = 7; i >= 0; i--) + for (int i = 7; i >= 0; i--) { int dis, s; /* Get the location */ - y = fy + ddy_ddd[i]; - x = fx + ddx_ddd[i]; + const int y = fy + ddy_ddd[i]; + const int x = fx + ddx_ddd[i]; /* Ignore illegal locations */ if (cave[y][x].when == 0) continue; @@ -5013,9 +5007,6 @@ static void get_target_monster(int m_idx) static bool_ get_moves(int m_idx, int *mm) { monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); - - int y, ay, x, ax; int move_val = 0; @@ -5051,6 +5042,9 @@ static bool_ get_moves(int m_idx, int *mm) } } + /* Get the race */ + const auto r_ptr = m_ptr->race(); + /* A possessor is not interrested in the player, it only wants a corpse */ if (r_ptr->flags7 & RF7_POSSESSOR) { @@ -5082,8 +5076,8 @@ static bool_ get_moves(int m_idx, int *mm) } /* Extract the "pseudo-direction" */ - y = m_ptr->fy - y2; - x = m_ptr->fx - x2; + int y = m_ptr->fy - y2; + int x = m_ptr->fx - x2; /* Tease the player */ if (r_ptr->flags7 & RF7_AI_ANNOY) @@ -5213,8 +5207,8 @@ static bool_ get_moves(int m_idx, int *mm) if (!x && !y) return (FALSE); /* Extract the "absolute distances" */ - ax = ABS(x); - ay = ABS(y); + int ay = ABS(y); + int ax = ABS(x); /* Do something weird */ if (y < 0) move_val += 8; @@ -5407,36 +5401,39 @@ int check_hit2(int power, int level, int ac) /* Monster attacks monster */ static bool_ monst_attack_monst(int m_idx, int t_idx) { - monster_type *m_ptr = &m_list[m_idx], *t_ptr = &m_list[t_idx]; - monster_race *r_ptr = race_inf(m_ptr); - monster_race *tr_ptr = race_inf(t_ptr); - int ap_cnt; - int ac, rlev, pt; - char m_name[80], t_name[80]; - char ddesc[80], temp[80]; - bool_ blinked = FALSE, touched = FALSE; + char temp[80]; + bool_ blinked = FALSE; + bool_ touched = FALSE; bool_ explode = FALSE; bool_ fear = FALSE; + monster_type *t_ptr = &m_list[t_idx]; byte y_saver = t_ptr->fy; byte x_saver = t_ptr->fx; + /* Get the racial information on the two monsters */ + monster_type *m_ptr = &m_list[m_idx]; + const auto r_ptr = m_ptr->race(); + const auto tr_ptr = t_ptr->race(); /* Not allowed to attack */ if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE; /* Total armor */ - ac = t_ptr->ac; + const int ac = t_ptr->ac; /* Extract the effective monster level */ - rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); + const int rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); /* Get the monster name (or "it") */ + char m_name[80]; monster_desc(m_name, m_ptr, 0); /* Get the monster name (or "it") */ + char t_name[80]; monster_desc(t_name, t_ptr, 0); /* Get the "died from" information (i.e. "a kobold") */ + char ddesc[80]; monster_desc(ddesc, m_ptr, 0x88); /* Assume no blink */ @@ -5448,7 +5445,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) } /* Scan through all four blows */ - for (ap_cnt = 0; ap_cnt < 4; ap_cnt++) + for (int ap_cnt = 0; ap_cnt < 4; ap_cnt++) { bool_ visible = FALSE; bool_ obvious = FALSE; @@ -5690,7 +5687,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) /* Hack need more punch against monsters */ damage *= 3; - pt = GF_MISSILE; + int pt = GF_MISSILE; /* Apply appropriate damage */ switch (effect) @@ -5962,12 +5959,9 @@ static u32b noise = 0L; /* Determine whether the player is invisible to a monster */ static bool_ player_invis(monster_type * m_ptr) { - s16b inv, mlv; - monster_race *r_ptr = race_inf(m_ptr); - - inv = p_ptr->invis; - - mlv = (s16b) m_ptr->level; + const auto r_ptr = m_ptr->race(); + s16b inv = p_ptr->invis; + s16b mlv = m_ptr->level; if (r_ptr->flags3 & RF3_NO_SLEEP) mlv += 10; @@ -6026,34 +6020,14 @@ static bool_ player_invis(monster_type * m_ptr) */ static void process_monster(int m_idx, bool_ is_frien) { - monster_type *m_ptr = &m_list[m_idx]; - monster_race *r_ptr = race_inf(m_ptr); - cave_type *c_ptr = &cave[m_ptr->fy][m_ptr->fx]; - int i, d, oy, ox, ny, nx; int mm[8]; - monster_type *y_ptr; - - bool_ do_turn; - bool_ do_move; - bool_ do_view; - - bool_ did_open_door; - bool_ did_bash_door; - bool_ did_take_item; - bool_ did_kill_item; - bool_ did_move_body; - bool_ did_kill_body; - bool_ did_pass_wall; - bool_ did_kill_wall; - bool_ gets_angry = FALSE; - bool_ inv; - bool_ xxx = FALSE; - - inv = player_invis(m_ptr); + monster_type *m_ptr = &m_list[m_idx]; + const bool_ inv = player_invis(m_ptr); + auto const r_ptr = m_ptr->race(); if (r_ptr->flags9 & RF9_DOPPLEGANGER) doppleganger = m_idx; /* Handle "bleeding" */ @@ -6063,6 +6037,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (d > m_ptr->bleeding) d = m_ptr->bleeding; /* Exit if the monster dies */ + bool_ xxx = FALSE; if (mon_take_hit(m_idx, d, &xxx, " bleeds to death.")) return; /* Hack -- Recover from bleeding */ @@ -6102,6 +6077,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (d < 1) d = 1; /* Exit if the monster dies */ + bool_ xxx = FALSE; if (mon_take_hit(m_idx, d, &xxx, " dies of poison.")) return; /* Hack -- Recover from bleeding */ @@ -6278,6 +6254,9 @@ static void process_monster(int m_idx, bool_ is_frien) } } + /* Do the monster get angry? */ + bool_ gets_angry = FALSE; + /* No one wants to be your friend if you're aggravating */ if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && (p_ptr->aggravate) && !(r_ptr->flags7 & RF7_PET)) gets_angry = TRUE; @@ -6456,23 +6435,23 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Paranoia -- quest code could delete it */ + cave_type *c_ptr = &cave[m_ptr->fy][m_ptr->fx]; if (!c_ptr->m_idx) return; /* Assume nothing */ - do_turn = FALSE; - do_move = FALSE; - do_view = FALSE; + bool_ do_turn = FALSE; + bool_ do_move = FALSE; + bool_ do_view = FALSE; /* Assume nothing */ - did_open_door = FALSE; - did_bash_door = FALSE; - did_take_item = FALSE; - did_kill_item = FALSE; - did_move_body = FALSE; - did_kill_body = FALSE; - did_pass_wall = FALSE; - did_kill_wall = FALSE; - + bool_ did_open_door = FALSE; + bool_ did_bash_door = FALSE; + bool_ did_take_item = FALSE; + bool_ did_kill_item = FALSE; + bool_ did_move_body = FALSE; + bool_ did_kill_body = FALSE; + bool_ did_pass_wall = FALSE; + bool_ did_kill_wall = FALSE; /* Take a zero-terminated array of "directions" */ for (i = 0; mm[i]; i++) @@ -6491,7 +6470,7 @@ static void process_monster(int m_idx, bool_ is_frien) c_ptr = &cave[ny][nx]; /* Access that cave grid's contents */ - y_ptr = &m_list[c_ptr->m_idx]; + monster_type *y_ptr = &m_list[c_ptr->m_idx]; /* Floor is open? */ @@ -6841,7 +6820,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* A monster is in the way */ if (do_move && c_ptr->m_idx) { - monster_race *z_ptr = race_inf(y_ptr); + auto z_ptr = y_ptr->race(); monster_type *m2_ptr = &m_list[c_ptr->m_idx]; /* Assume no movement */ @@ -7288,7 +7267,6 @@ void process_monsters(void) bool_ is_frien = FALSE; monster_type *m_ptr; - monster_race *r_ptr; int old_monster_race_idx; @@ -7318,7 +7296,7 @@ void process_monsters(void) if (monster_race_idx) { /* Acquire current monster */ - r_ptr = &r_info[monster_race_idx]; + monster_race *r_ptr = &r_info[monster_race_idx]; /* Memorize flags */ old_r_flags1 = r_ptr->r_flags1; @@ -7394,7 +7372,7 @@ void process_monsters(void) /* Access the race */ - r_ptr = race_inf(m_ptr); + auto const r_ptr = m_ptr->race(); /* Access the location */ fx = m_ptr->fx; @@ -7473,7 +7451,7 @@ void process_monsters(void) if (monster_race_idx && (monster_race_idx == old_monster_race_idx)) { /* Acquire monster race */ - r_ptr = &r_info[monster_race_idx]; + monster_race *r_ptr = &r_info[monster_race_idx]; /* Check for knowledge change */ if ((old_r_flags1 != r_ptr->r_flags1) || -- cgit v1.2.3 From 97bcf1bc612d9920390c885b8dcea0b0cda6f246 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Migrate z-rand.c to C++ - Include explicitly instead of via angband.h - Change to regular functions instead of macros. --- src/melee2.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 8478addd..ce2f11a2 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -42,6 +42,7 @@ #include "util.hpp" #include "variable.hpp" #include "xtra2.hpp" +#include "z-rand.hpp" #include -- cgit v1.2.3 From 5ce1ccafa65c5cfbcd0f4431f51abfa1d700a885 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove strfmt() --- src/melee2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index ce2f11a2..b3aa5c61 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -5673,7 +5673,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) /* Message */ if (act) { - strfmt(temp, act, t_name); + strnfmt(temp, sizeof(temp), act, t_name); if (m_ptr->ml || t_ptr->ml) monster_msg("%^s %s", m_name, temp); -- cgit v1.2.3 From 443761e4649390291d5e06bb9dba2540ac5e9fd9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 27 Mar 2016 15:46:59 +0200 Subject: Fix occasional overflow when monster speaks --- src/melee2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index b3aa5c61..5a643132 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6330,7 +6330,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (player_has_los_bold(oy, ox) && (r_ptr->flags2 & RF2_CAN_SPEAK)) { char m_name[80]; - char monmessage[80]; + char monmessage[1024]; /* Acquire the monster name/poss */ if (m_ptr->ml) -- cgit v1.2.3 From 899041ce6b7cbc33e8cb3124aaa54b518c4a4b72 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 Mar 2016 20:32:55 +0200 Subject: Convert dungeon_info_type to use new flag_set --- src/melee2.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 5a643132..e4f0802a 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -16,6 +16,7 @@ #include "cave.hpp" #include "cave_type.hpp" #include "cmd1.hpp" +#include "dungeon_flag.hpp" #include "feature_type.hpp" #include "files.hpp" #include "hook_mon_speak_in.hpp" @@ -2259,7 +2260,7 @@ static bool_ monst_spell_monst(int m_idx) /* RF6_TPORT */ case 160 + 5: { - if (dungeon_flags2 & DF2_NO_TELEPORT) break; /* No teleport on special levels */ + if (dungeon_flags & DF_NO_TELEPORT) break; /* No teleport on special levels */ else { if (disturb_other) disturb(1); @@ -2279,7 +2280,7 @@ static bool_ monst_spell_monst(int m_idx) /* RF6_TELE_AWAY */ case 160 + 7: { - if (dungeon_flags2 & DF2_NO_TELEPORT) break; + if (dungeon_flags & DF_NO_TELEPORT) break; if (!direct) break; else -- cgit v1.2.3 From 7137a17f77fd3b6c3bbcefa2d621b3a11f161679 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Remove monster memory Instead of having monster memory, the player automatically knows everything about all monsters from the start. --- src/melee2.cc | 268 ---------------------------------------------------------- 1 file changed, 268 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index e4f0802a..080208f1 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -1712,12 +1712,6 @@ static bool_ monst_spell_monst(int m_idx) (tr_ptr->flags3 & (RF3_NO_CONF)) || (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) { - /* Memorize a flag */ - if (tr_ptr->flags3 & (RF3_NO_CONF)) - { - if (seen) tr_ptr->r_flags3 |= (RF3_NO_CONF); - } - /* No obvious effect */ if (see_t) { @@ -1756,11 +1750,6 @@ static bool_ monst_spell_monst(int m_idx) (tr_ptr->flags3 & (RF3_NO_CONF)) || (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) { - /* Memorize a flag */ - if (tr_ptr->flags3 & (RF3_NO_CONF)) - { - if (seen) tr_ptr->r_flags3 |= (RF3_NO_CONF); - } /* No obvious effect */ if (see_t) { @@ -2296,7 +2285,6 @@ static bool_ monst_spell_monst(int m_idx) { if (see_t) { - tr_ptr->r_flags3 |= RF3_RES_TELE; monster_msg("%^s is unaffected!", t_name); } resists_tele = TRUE; @@ -2305,7 +2293,6 @@ static bool_ monst_spell_monst(int m_idx) { if (see_t) { - tr_ptr->r_flags3 |= RF3_RES_TELE; monster_msg("%^s resists!", t_name); } resists_tele = TRUE; @@ -2713,39 +2700,6 @@ static bool_ monst_spell_monst(int m_idx) t_ptr->csleep = 0; } - - /* Remember what the monster did, if we saw it */ - if (seen) - { - /* Inate spell */ - if (thrown_spell < 32*4) - { - r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3)); - if (r_ptr->r_cast_inate < MAX_UCHAR) r_ptr->r_cast_inate++; - } - - /* Bolt or Ball */ - else if (thrown_spell < 32*5) - { - r_ptr->r_flags5 |= (1L << (thrown_spell - 32 * 4)); - if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; - } - - /* Special spell */ - else if (thrown_spell < 32*6) - { - r_ptr->r_flags6 |= (1L << (thrown_spell - 32 * 5)); - if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; - } - } - - /* Always take note of monsters that kill you --- - * even accidentally */ - if (death && (r_ptr->r_deaths < MAX_SHORT)) - { - r_ptr->r_deaths++; - } - /* A spell was cast */ return (TRUE); } @@ -4554,38 +4508,6 @@ static bool_ make_attack_spell(int m_idx) } } - /* Remember what the monster did to us */ - if (seen) - { - /* Inate spell */ - if (thrown_spell < 32*4) - { - r_ptr->r_flags4 |= (1L << (thrown_spell - 32 * 3)); - if (r_ptr->r_cast_inate < MAX_UCHAR) r_ptr->r_cast_inate++; - } - - /* Bolt or Ball */ - else if (thrown_spell < 32*5) - { - r_ptr->r_flags5 |= (1L << (thrown_spell - 32 * 4)); - if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; - } - - /* Special spell */ - else if (thrown_spell < 32*6) - { - r_ptr->r_flags6 |= (1L << (thrown_spell - 32 * 5)); - if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++; - } - } - - - /* Always take note of monsters that kill you */ - if (death && (r_ptr->r_deaths < MAX_SHORT)) - { - r_ptr->r_deaths++; - } - /* A spell was cast */ return (TRUE); } @@ -5449,9 +5371,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) /* Scan through all four blows */ for (int ap_cnt = 0; ap_cnt < 4; ap_cnt++) { - bool_ visible = FALSE; - bool_ obvious = FALSE; - int power = 0; int damage = 0; @@ -5482,9 +5401,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) /* break; */ } - /* Extract visibility (before blink) */ - if (m_ptr->ml) visible = TRUE; - /* Extract the attack "power" */ power = get_attack_power(effect); @@ -5680,9 +5596,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) } - /* Hack -- assume all attacks are obvious */ - obvious = TRUE; - /* Roll out the damage */ damage = damroll(d_dice, d_side); @@ -5846,8 +5759,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) { blinked = FALSE; monster_msg("%^s is suddenly very hot!", m_name); - if (t_ptr->ml) - tr_ptr->r_flags2 |= RF2_AURA_FIRE; } project(t_idx, 0, m_ptr->fy, m_ptr->fx, damroll (1 + ((t_ptr->level) / 26), @@ -5862,8 +5773,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) { blinked = FALSE; monster_msg("%^s gets zapped!", m_name); - if (t_ptr->ml) - tr_ptr->r_flags2 |= RF2_AURA_ELEC; } project(t_idx, 0, m_ptr->fy, m_ptr->fx, damroll (1 + ((t_ptr->level) / 26), @@ -5908,21 +5817,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) } } } - - - /* Analyze "visible" monsters only */ - if (visible) - { - /* Count "obvious" attacks (and ones that cause damage) */ - if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10)) - { - /* Count attacks of this type */ - if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR) - { - r_ptr->r_blows[ap_cnt]++; - } - } - } } if (explode) @@ -6137,18 +6031,7 @@ static void process_monster(int m_idx, bool_ is_frien) { /* Monster wakes up "a little bit" */ m_ptr->csleep -= d; - - /* Notice the "not waking up" */ - if (m_ptr->ml) - { - /* Hack -- Count the ignores */ - if (r_ptr->r_ignore < MAX_UCHAR) - { - r_ptr->r_ignore++; - } - } } - /* Just woke up */ else { @@ -6165,12 +6048,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Dump a message */ msg_format("%^s wakes up.", m_name); - - /* Hack -- Count the wakings */ - if (r_ptr->r_wake < MAX_UCHAR) - { - r_ptr->r_wake++; - } } } } @@ -6399,10 +6276,6 @@ static void process_monster(int m_idx, bool_ is_frien) (r_ptr->flags1 & (RF1_RAND_25)) && (rand_int(100) < 75)) { - /* Memorize flags */ - if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50); - if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25); - /* Try four "random" directions */ mm[0] = mm[1] = mm[2] = mm[3] = 5; } @@ -6411,9 +6284,6 @@ static void process_monster(int m_idx, bool_ is_frien) else if ((r_ptr->flags1 & (RF1_RAND_50)) && (rand_int(100) < 50)) { - /* Memorize flags */ - if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50); - /* Try four "random" directions */ mm[0] = mm[1] = mm[2] = mm[3] = 5; } @@ -6422,9 +6292,6 @@ static void process_monster(int m_idx, bool_ is_frien) else if ((r_ptr->flags1 & (RF1_RAND_25)) && (rand_int(100) < 25)) { - /* Memorize flags */ - if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25); - /* Try four "random" directions */ mm[0] = mm[1] = mm[2] = mm[3] = 5; } @@ -6448,12 +6315,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Assume nothing */ bool_ did_open_door = FALSE; bool_ did_bash_door = FALSE; - bool_ did_take_item = FALSE; - bool_ did_kill_item = FALSE; - bool_ did_move_body = FALSE; - bool_ did_kill_body = FALSE; - bool_ did_pass_wall = FALSE; - bool_ did_kill_wall = FALSE; /* Take a zero-terminated array of "directions" */ for (i = 0; mm[i]; i++) @@ -6566,9 +6427,6 @@ static void process_monster(int m_idx, bool_ is_frien) { /* Pass through walls/doors/rubble */ do_move = TRUE; - - /* Monster went through a wall */ - did_pass_wall = TRUE; } /* Monster destroys walls (and doors) */ @@ -6577,9 +6435,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Eat through walls/doors/rubble */ do_move = TRUE; - /* Monster destroyed a wall */ - did_kill_wall = TRUE; - if (randint(GRINDNOISE) == 1) { msg_print("There is a grinding sound."); @@ -6600,9 +6455,6 @@ static void process_monster(int m_idx, bool_ is_frien) { /* Pass through walls/doors/rubble */ do_move = TRUE; - - /* Monster went through a wall */ - did_pass_wall = TRUE; } /* Monster moves through webs */ @@ -6843,11 +6695,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Allow movement */ do_move = TRUE; - /* Monster ate another monster */ - did_kill_body = TRUE; - - /* XXX XXX XXX Message */ - /* Kill the monster */ delete_monster(ny, nx); @@ -6879,11 +6726,6 @@ static void process_monster(int m_idx, bool_ is_frien) { /* Allow movement */ do_move = TRUE; - - /* Monster pushed past another monster */ - did_move_body = TRUE; - - /* XXX XXX XXX Message */ } } @@ -7044,9 +6886,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Only give a message for "take_item" */ if (r_ptr->flags2 & (RF2_TAKE_ITEM)) { - /* Take note */ - did_take_item = TRUE; - /* Describe observable situations */ if (m_ptr->ml && player_has_los_bold(ny, nx)) { @@ -7060,9 +6899,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Pick up the item */ else if (r_ptr->flags2 & (RF2_TAKE_ITEM)) { - /* Take note */ - did_take_item = TRUE; - /* Describe observable situations */ if (player_has_los_bold(ny, nx)) { @@ -7092,9 +6928,6 @@ static void process_monster(int m_idx, bool_ is_frien) /* Destroy the item */ else { - /* Take note */ - did_kill_item = TRUE; - /* Describe observable situations */ if (player_has_los_bold(ny, nx)) { @@ -7135,35 +6968,6 @@ static void process_monster(int m_idx, bool_ is_frien) } - /* Learn things from observable monster */ - if (m_ptr->ml) - { - /* Monster opened a door */ - if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR); - - /* Monster bashed a door */ - if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR); - - /* Monster tried to pick something up */ - if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM); - - /* Monster tried to crush something */ - if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM); - - /* Monster pushed past another monster */ - if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY); - - /* Monster ate another monster */ - if (did_kill_body) r_ptr->r_flags2 |= (RF2_KILL_BODY); - - /* Monster passed through a wall */ - if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL); - - /* Monster destroyed a wall */ - if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL); - } - - /* Hack -- get "bold" if out of options */ if (!do_turn && !do_move && m_ptr->monfear) { @@ -7270,56 +7074,10 @@ void process_monsters(void) monster_type *m_ptr; - int old_monster_race_idx; - - u32b old_r_flags1 = 0L; - u32b old_r_flags2 = 0L; - u32b old_r_flags3 = 0L; - u32b old_r_flags4 = 0L; - u32b old_r_flags5 = 0L; - u32b old_r_flags6 = 0L; - - byte old_r_blows0 = 0; - byte old_r_blows1 = 0; - byte old_r_blows2 = 0; - byte old_r_blows3 = 0; - - byte old_r_cast_inate = 0; - byte old_r_cast_spell = 0; - /* Check the doppleganger */ if (doppleganger && !(r_info[m_list[doppleganger].r_idx].flags9 & RF9_DOPPLEGANGER)) doppleganger = 0; - /* Memorize old race */ - old_monster_race_idx = monster_race_idx; - - /* Acquire knowledge */ - if (monster_race_idx) - { - /* Acquire current monster */ - monster_race *r_ptr = &r_info[monster_race_idx]; - - /* Memorize flags */ - old_r_flags1 = r_ptr->r_flags1; - old_r_flags2 = r_ptr->r_flags2; - old_r_flags3 = r_ptr->r_flags3; - old_r_flags4 = r_ptr->r_flags4; - old_r_flags5 = r_ptr->r_flags5; - old_r_flags6 = r_ptr->r_flags6; - - /* Memorize blows */ - old_r_blows0 = r_ptr->r_blows[0]; - old_r_blows1 = r_ptr->r_blows[1]; - old_r_blows2 = r_ptr->r_blows[2]; - old_r_blows3 = r_ptr->r_blows[3]; - - /* Memorize castings */ - old_r_cast_inate = r_ptr->r_cast_inate; - old_r_cast_spell = r_ptr->r_cast_spell; - } - - /* Hack -- calculate the "player noise" */ noise = (1L << (30 - p_ptr->skill_stl)); @@ -7447,30 +7205,4 @@ void process_monsters(void) /* Reset global index */ hack_m_idx = 0; - - - /* Tracking a monster race (the same one we were before) */ - if (monster_race_idx && (monster_race_idx == old_monster_race_idx)) - { - /* Acquire monster race */ - monster_race *r_ptr = &r_info[monster_race_idx]; - - /* Check for knowledge change */ - if ((old_r_flags1 != r_ptr->r_flags1) || - (old_r_flags2 != r_ptr->r_flags2) || - (old_r_flags3 != r_ptr->r_flags3) || - (old_r_flags4 != r_ptr->r_flags4) || - (old_r_flags5 != r_ptr->r_flags5) || - (old_r_flags6 != r_ptr->r_flags6) || - (old_r_blows0 != r_ptr->r_blows[0]) || - (old_r_blows1 != r_ptr->r_blows[1]) || - (old_r_blows2 != r_ptr->r_blows[2]) || - (old_r_blows3 != r_ptr->r_blows[3]) || - (old_r_cast_inate != r_ptr->r_cast_inate) || - (old_r_cast_spell != r_ptr->r_cast_spell)) - { - /* Window stuff */ - p_ptr->window |= (PW_MONSTER); - } - } } -- cgit v1.2.3 From 0cb03efd7c438ee8fc5d9444e0c8e60a8eeb7f16 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Remove redundant parens from RFn_* in expressions --- src/melee2.cc | 286 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 143 insertions(+), 143 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 080208f1..522b2f47 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -118,10 +118,10 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) /* Do nothing */ } /* Death by Physical attack -- non-living monster */ - else if ((r_ptr->flags3 & (RF3_DEMON)) || - (r_ptr->flags3 & (RF3_UNDEAD)) || - (r_ptr->flags2 & (RF2_STUPID)) || - (r_ptr->flags3 & (RF3_NONLIVING)) || + else if ((r_ptr->flags3 & RF3_DEMON) || + (r_ptr->flags3 & RF3_UNDEAD) || + (r_ptr->flags2 & RF2_STUPID) || + (r_ptr->flags3 & RF3_NONLIVING) || (strchr("Evg", r_ptr->d_char))) { cmonster_msg(TERM_L_RED, "%^s is destroyed.", m_name); @@ -172,7 +172,7 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) } /* When an Unique dies, it stays dead */ - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags1 & RF1_UNIQUE) { r_ptr->max_num = 0; } @@ -229,7 +229,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) /* Sometimes a monster gets scared by damage */ auto const r_ptr = m_ptr->race(); - if (!m_ptr->monfear && !(r_ptr->flags3 & (RF3_NO_FEAR))) + if (!m_ptr->monfear && !(r_ptr->flags3 & RF3_NO_FEAR)) { int percentage; @@ -290,7 +290,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) static bool_ int_outof(std::shared_ptr r_ptr, int prob) { /* Non-Smart monsters are half as "smart" */ - if (!(r_ptr->flags2 & (RF2_SMART))) prob = prob / 2; + if (!(r_ptr->flags2 & RF2_SMART)) prob = prob / 2; /* Roll the dice */ return (rand_int(100) < prob); @@ -314,7 +314,7 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) /* Too stupid to know anything? */ auto const r_ptr = m_ptr->race(); - if (r_ptr->flags2 & (RF2_STUPID)) return; + if (r_ptr->flags2 & RF2_STUPID) return; /* Must be cheating or learning */ @@ -338,178 +338,178 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) if (smart & (SM_IMM_ACID)) { - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_ACID); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_ACID); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ACID); + if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_ACID; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_ACID; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ACID; } else if ((smart & (SM_OPP_ACID)) && (smart & (SM_RES_ACID))) { - if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ACID); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ACID); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ACID); + if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_ACID; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_ACID; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_ACID; } else if ((smart & (SM_OPP_ACID)) || (smart & (SM_RES_ACID))) { - if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ACID); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ACID); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ACID); + if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_ACID; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_ACID; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_ACID; } if (smart & (SM_IMM_ELEC)) { - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_ELEC); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_ELEC); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ELEC); + if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_ELEC; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_ELEC; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ELEC; } else if ((smart & (SM_OPP_ELEC)) && (smart & (SM_RES_ELEC))) { - if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_ELEC); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_ELEC); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ELEC); + if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_ELEC; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_ELEC; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_ELEC; } else if ((smart & (SM_OPP_ELEC)) || (smart & (SM_RES_ELEC))) { - if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_ELEC); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_ELEC); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ELEC); + if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_ELEC; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_ELEC; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_ELEC; } if (smart & (SM_IMM_FIRE)) { - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_FIRE); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_FIRE); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_FIRE); + if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_FIRE; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_FIRE; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_FIRE; } else if ((smart & (SM_OPP_FIRE)) && (smart & (SM_RES_FIRE))) { - if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_FIRE); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_FIRE); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_FIRE); + if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_FIRE; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_FIRE; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_FIRE; } else if ((smart & (SM_OPP_FIRE)) || (smart & (SM_RES_FIRE))) { - if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_FIRE); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_FIRE); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_FIRE); + if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_FIRE; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_FIRE; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_FIRE; } if (smart & (SM_IMM_COLD)) { - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_COLD); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BA_COLD); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_COLD); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ICEE); + if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_COLD; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_COLD; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_COLD; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ICEE; } else if ((smart & (SM_OPP_COLD)) && (smart & (SM_RES_COLD))) { - if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_COLD); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_COLD); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_COLD); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BO_ICEE); + if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_COLD; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_COLD; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_COLD; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_ICEE; } else if ((smart & (SM_OPP_COLD)) || (smart & (SM_RES_COLD))) { - if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_COLD); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_COLD); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_COLD); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BO_ICEE); + if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_COLD; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_COLD; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_COLD; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_ICEE; } if ((smart & (SM_OPP_POIS)) && (smart & (SM_RES_POIS))) { - if (int_outof(r_ptr, 80)) f4 &= ~(RF4_BR_POIS); - if (int_outof(r_ptr, 80)) f5 &= ~(RF5_BA_POIS); - if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BA_NUKE); - if (int_outof(r_ptr, 40)) f4 &= ~(RF4_BR_NUKE); + if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_POIS; + if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_POIS; + if (int_outof(r_ptr, 40)) f4 &= ~RF4_BA_NUKE; + if (int_outof(r_ptr, 40)) f4 &= ~RF4_BR_NUKE; } else if ((smart & (SM_OPP_POIS)) || (smart & (SM_RES_POIS))) { - if (int_outof(r_ptr, 30)) f4 &= ~(RF4_BR_POIS); - if (int_outof(r_ptr, 30)) f5 &= ~(RF5_BA_POIS); + if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_POIS; + if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_POIS; } if (smart & (SM_RES_NETH)) { - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NETH); - if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_NETH); - if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BO_NETH); + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_NETH; + if (int_outof(r_ptr, 50)) f5 &= ~RF5_BA_NETH; + if (int_outof(r_ptr, 50)) f5 &= ~RF5_BO_NETH; } if (smart & (SM_RES_LITE)) { - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_LITE); + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_LITE; } if (smart & (SM_RES_DARK)) { - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_DARK); - if (int_outof(r_ptr, 50)) f5 &= ~(RF5_BA_DARK); + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_DARK; + if (int_outof(r_ptr, 50)) f5 &= ~RF5_BA_DARK; } if (smart & (SM_RES_FEAR)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_SCARE); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_SCARE; } if (smart & (SM_RES_CONF)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_CONF); - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_CONF; + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_CONF; } if (smart & (SM_RES_CHAOS)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_CONF); - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CONF); - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_CHAO); - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BA_CHAO); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_CONF; + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_CONF; + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_CHAO; + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BA_CHAO; } if (smart & (SM_RES_DISEN)) { - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_BR_DISE); + if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_DISE; } if (smart & (SM_RES_BLIND)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BLIND); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BLIND; } if (smart & (SM_RES_NEXUS)) { - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_NEXU); - if (int_outof(r_ptr, 50)) f6 &= ~(RF6_TELE_LEVEL); + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_NEXU; + if (int_outof(r_ptr, 50)) f6 &= ~RF6_TELE_LEVEL; } if (smart & (SM_RES_SOUND)) { - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_SOUN); + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_SOUN; } if (smart & (SM_RES_SHARD)) { - if (int_outof(r_ptr, 50)) f4 &= ~(RF4_BR_SHAR); - if (int_outof(r_ptr, 20)) f4 &= ~(RF4_ROCKET); + if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_SHAR; + if (int_outof(r_ptr, 20)) f4 &= ~RF4_ROCKET; } if (smart & (SM_IMM_REFLECT)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_COLD); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_FIRE); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ACID); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ELEC); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_POIS); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_NETH); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_WATE); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_MANA); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_PLAS); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_BO_ICEE); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_MISSILE); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_COLD; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_FIRE; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ACID; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ELEC; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_POIS; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_NETH; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_WATE; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_MANA; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_PLAS; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ICEE; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_MISSILE; if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_1); if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_2); if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_3); @@ -518,13 +518,13 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) if (smart & (SM_IMM_FREE)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_HOLD); - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_SLOW); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_HOLD; + if (int_outof(r_ptr, 100)) f5 &= ~RF5_SLOW; } if (smart & (SM_IMM_MANA)) { - if (int_outof(r_ptr, 100)) f5 &= ~(RF5_DRAIN_MANA); + if (int_outof(r_ptr, 100)) f5 &= ~RF5_DRAIN_MANA; } /* XXX XXX XXX No spells left? */ @@ -770,7 +770,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num) /* Stupid monsters choose randomly */ auto const r_ptr = m_ptr->race(); - if (r_ptr->flags2 & (RF2_STUPID)) + if (r_ptr->flags2 & RF2_STUPID) { /* Pick at random */ return (spells[rand_int(num)]); @@ -884,7 +884,7 @@ static void breath(int m_idx, int typ, int dam_hp, int rad) auto const r_ptr = m_ptr->race(); /* Determine the radius of the blast */ - if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2; + if (rad < 1) rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2; /* Target the player with a ball attack */ (void)project(m_idx, rad, p_ptr->py, p_ptr->px, dam_hp, typ, flg); @@ -904,7 +904,7 @@ static void monst_breath_monst(int m_idx, int y, int x, int typ, int dam_hp, int auto const r_ptr = m_ptr->race(); /* Determine the radius of the blast */ - if (rad < 1) rad = (r_ptr->flags2 & (RF2_POWERFUL)) ? 3 : 2; + if (rad < 1) rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2; (void)project(m_idx, rad, y, x, dam_hp, typ, flg); } @@ -1065,14 +1065,14 @@ static bool_ monst_spell_monst(int m_idx) f6 = r_ptr->flags6; /* Hack -- allow "desperate" spells */ - if ((r_ptr->flags2 & (RF2_SMART)) && + if ((r_ptr->flags2 & RF2_SMART) && (m_ptr->hp < m_ptr->maxhp / 10) && (rand_int(100) < 50)) { /* Require intelligent spells */ - f4 &= (RF4_INT_MASK); - f5 &= (RF5_INT_MASK); - f6 &= (RF6_INT_MASK); + f4 &= RF4_INT_MASK; + f5 &= RF5_INT_MASK; + f6 &= RF6_INT_MASK; /* No spells left */ if ((!f4 && !f5 && !f6) && (monst_spell_monst_spell == -1)) return (FALSE); @@ -1708,8 +1708,8 @@ static bool_ monst_spell_monst(int m_idx) } /* Attempt a saving throw */ - if ((tr_ptr->flags1 & (RF1_UNIQUE)) || - (tr_ptr->flags3 & (RF3_NO_CONF)) || + if ((tr_ptr->flags1 & RF1_UNIQUE) || + (tr_ptr->flags3 & RF3_NO_CONF) || (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) { /* No obvious effect */ @@ -1746,8 +1746,8 @@ static bool_ monst_spell_monst(int m_idx) } /* Attempt a saving throw */ - if ((tr_ptr->flags1 & (RF1_UNIQUE)) || - (tr_ptr->flags3 & (RF3_NO_CONF)) || + if ((tr_ptr->flags1 & RF1_UNIQUE) || + (tr_ptr->flags3 & RF3_NO_CONF) || (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) { /* No obvious effect */ @@ -2279,9 +2279,9 @@ static bool_ monst_spell_monst(int m_idx) monster_msg("%^s teleports %s away.", m_name, t_name); - if (tr_ptr->flags3 & (RF3_RES_TELE)) + if (tr_ptr->flags3 & RF3_RES_TELE) { - if (tr_ptr->flags1 & (RF1_UNIQUE)) + if (tr_ptr->flags1 & RF1_UNIQUE) { if (see_t) { @@ -2948,14 +2948,14 @@ static bool_ make_attack_spell(int m_idx) if (no_inate) f4 = 0L; /* Hack -- allow "desperate" spells */ - if ((r_ptr->flags2 & (RF2_SMART)) && + if ((r_ptr->flags2 & RF2_SMART) && (m_ptr->hp < m_ptr->maxhp / 10) && (rand_int(100) < 50)) { /* Require intelligent spells */ - f4 &= (RF4_INT_MASK); - f5 &= (RF5_INT_MASK); - f6 &= (RF6_INT_MASK); + f4 &= RF4_INT_MASK; + f5 &= RF5_INT_MASK; + f6 &= RF6_INT_MASK; /* No spells left */ if (!f4 && !f5 && !f6) return (FALSE); @@ -2968,27 +2968,27 @@ static bool_ make_attack_spell(int m_idx) if (!f4 && !f5 && !f6) return (FALSE); /* Check for a clean bolt shot */ - if ((f4&(RF4_BOLT_MASK) || f5 & (RF5_BOLT_MASK) || - f6&(RF6_BOLT_MASK)) && - !(r_ptr->flags2 & (RF2_STUPID)) && + if ((f4&RF4_BOLT_MASK || f5 & RF5_BOLT_MASK || + f6&RF6_BOLT_MASK) && + !(r_ptr->flags2 & RF2_STUPID) && !clean_shot(m_ptr->fy, m_ptr->fx, y, x)) { /* Remove spells that will only hurt friends */ - f4 &= ~(RF4_BOLT_MASK); - f5 &= ~(RF5_BOLT_MASK); - f6 &= ~(RF6_BOLT_MASK); + f4 &= ~RF4_BOLT_MASK; + f5 &= ~RF5_BOLT_MASK; + f6 &= ~RF6_BOLT_MASK; } /* Check for a possible summon */ - if ((f4 & (RF4_SUMMON_MASK) || f5 & (RF5_SUMMON_MASK) || - f6 & (RF6_SUMMON_MASK)) && - !(r_ptr->flags2 & (RF2_STUPID)) && + if ((f4 & RF4_SUMMON_MASK || f5 & RF5_SUMMON_MASK || + f6 & RF6_SUMMON_MASK) && + !(r_ptr->flags2 & RF2_STUPID) && !(summon_possible(y, x))) { /* Remove summoning spells */ - f4 &= ~(RF4_SUMMON_MASK); - f5 &= ~(RF5_SUMMON_MASK); - f6 &= ~(RF6_SUMMON_MASK); + f4 &= ~RF4_SUMMON_MASK; + f5 &= ~RF5_SUMMON_MASK; + f6 &= ~RF6_SUMMON_MASK; } /* No spells left */ @@ -3034,7 +3034,7 @@ static bool_ make_attack_spell(int m_idx) failrate = 25 - (rlev + 3) / 4; /* Hack -- Stupid monsters will never fail (for jellies and such) */ - if (r_ptr->flags2 & (RF2_STUPID)) failrate = 0; + if (r_ptr->flags2 & RF2_STUPID) failrate = 0; /* Check for spell failure (inate attacks never fail) */ if ((thrown_spell >= 128) && (rand_int(100) < failrate)) @@ -5032,8 +5032,8 @@ static bool_ get_moves(int m_idx, int *mm) */ if ((r_ptr->flags1 & RF1_FRIENDS) && (r_ptr->flags3 & RF3_ANIMAL) && - !((r_ptr->flags2 & (RF2_PASS_WALL)) || - (r_ptr->flags2 & (RF2_KILL_WALL)))) + !((r_ptr->flags2 & RF2_PASS_WALL) || + (r_ptr->flags2 & RF2_KILL_WALL))) { int i, room = 0; @@ -5767,7 +5767,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) } /* Aura elec */ - if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) && !(r_ptr->flags3 & (RF3_IM_ELEC))) + if ((tr_ptr->flags2 & RF2_AURA_ELEC) && !(r_ptr->flags3 & RF3_IM_ELEC)) { if (m_ptr->ml || t_ptr->ml) { @@ -6142,7 +6142,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Paranoia... no friendly uniques outside wizard mode -- TY */ if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && !(wizard) && - (r_ptr->flags1 & (RF1_UNIQUE)) && !(r_ptr->flags7 & RF7_PET)) + (r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_PET)) gets_angry = TRUE; if (gets_angry) @@ -6198,7 +6198,7 @@ static void process_monster(int m_idx, bool_ is_frien) ox = m_ptr->fx; /* Attempt to "multiply" if able and allowed */ - if ((r_ptr->flags4 & (RF4_MULTIPLY)) && (num_repro < MAX_REPRO)) + if ((r_ptr->flags4 & RF4_MULTIPLY) && (num_repro < MAX_REPRO)) { if (ai_multiply(m_idx)) return; } @@ -6409,28 +6409,28 @@ static void process_monster(int m_idx, bool_ is_frien) /* Some monsters can fly */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_LEVITATE) && (r_ptr->flags7 & (RF7_CAN_FLY))) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_LEVITATE) && (r_ptr->flags7 & RF7_CAN_FLY)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Some monsters can fly */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_FLY) && (r_ptr->flags7 & (RF7_CAN_FLY))) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_FLY) && (r_ptr->flags7 & RF7_CAN_FLY)) { /* Pass through trees/... */ do_move = TRUE; } /* Monster moves through walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & (RF2_PASS_WALL))) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & RF2_PASS_WALL)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Monster destroys walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & (RF2_KILL_WALL))) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & RF2_KILL_WALL)) { /* Eat through walls/doors/rubble */ do_move = TRUE; @@ -6451,7 +6451,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Monster moves through walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & (RF2_PASS_WALL))) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & RF2_PASS_WALL)) { /* Pass through walls/doors/rubble */ do_move = TRUE; @@ -6475,7 +6475,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Take a turn */ do_turn = TRUE; - if ((r_ptr->flags2 & (RF2_OPEN_DOOR)) && + if ((r_ptr->flags2 & RF2_OPEN_DOOR) && ((is_friend(m_ptr) <= 0) || p_ptr->pet_open_doors)) { /* Closed doors and secret doors */ @@ -6745,7 +6745,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE)) { /* Hack -- memorize lack of attacks */ - /* if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE); */ + /* if (m_ptr->ml) r_ptr->r_flags1 |= RF1_NEVER_MOVE; */ /* Do not move */ do_move = FALSE; @@ -6846,9 +6846,9 @@ static void process_monster(int m_idx, bool_ is_frien) /* Take or Kill objects on the floor */ /* rr9: Pets will no longer pick up/destroy items */ - if ((((r_ptr->flags2 & (RF2_TAKE_ITEM)) && + if ((((r_ptr->flags2 & RF2_TAKE_ITEM) && ((is_friend(m_ptr) <= 0) || p_ptr->pet_pickup_items)) || - (r_ptr->flags2 & (RF2_KILL_ITEM))) && + (r_ptr->flags2 & RF2_KILL_ITEM)) && (is_friend(m_ptr) <= 0)) { u32b f1, f2, f3, f4, f5, esp; @@ -6868,23 +6868,23 @@ static void process_monster(int m_idx, bool_ is_frien) monster_desc(m_name, m_ptr, 0x04); /* React to objects that hurt the monster */ - if (f5 & (TR5_KILL_DEMON)) flg3 |= (RF3_DEMON); - if (f5 & (TR5_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD); - if (f1 & (TR1_SLAY_DRAGON)) flg3 |= (RF3_DRAGON); - if (f1 & (TR1_SLAY_TROLL)) flg3 |= (RF3_TROLL); - if (f1 & (TR1_SLAY_GIANT)) flg3 |= (RF3_GIANT); - if (f1 & (TR1_SLAY_ORC)) flg3 |= (RF3_ORC); - if (f1 & (TR1_SLAY_DEMON)) flg3 |= (RF3_DEMON); - if (f1 & (TR1_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD); - if (f1 & (TR1_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL); - if (f1 & (TR1_SLAY_EVIL)) flg3 |= (RF3_EVIL); + if (f5 & (TR5_KILL_DEMON)) flg3 |= RF3_DEMON; + if (f5 & (TR5_KILL_UNDEAD)) flg3 |= RF3_UNDEAD; + if (f1 & (TR1_SLAY_DRAGON)) flg3 |= RF3_DRAGON; + if (f1 & (TR1_SLAY_TROLL)) flg3 |= RF3_TROLL; + if (f1 & (TR1_SLAY_GIANT)) flg3 |= RF3_GIANT; + if (f1 & (TR1_SLAY_ORC)) flg3 |= RF3_ORC; + if (f1 & (TR1_SLAY_DEMON)) flg3 |= RF3_DEMON; + if (f1 & (TR1_SLAY_UNDEAD)) flg3 |= RF3_UNDEAD; + if (f1 & (TR1_SLAY_ANIMAL)) flg3 |= RF3_ANIMAL; + if (f1 & (TR1_SLAY_EVIL)) flg3 |= RF3_EVIL; /* The object cannot be picked up by the monster */ if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || (o_ptr->art_name)) { /* Only give a message for "take_item" */ - if (r_ptr->flags2 & (RF2_TAKE_ITEM)) + if (r_ptr->flags2 & RF2_TAKE_ITEM) { /* Describe observable situations */ if (m_ptr->ml && player_has_los_bold(ny, nx)) @@ -6897,7 +6897,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Pick up the item */ - else if (r_ptr->flags2 & (RF2_TAKE_ITEM)) + else if (r_ptr->flags2 & RF2_TAKE_ITEM) { /* Describe observable situations */ if (player_has_los_bold(ny, nx)) -- cgit v1.2.3 From fa5083020d4cc4d6d7471b461c430d40ed36c02e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Remove ANIM_DEAD monster spell It doesn't seem like it was ever implemented fully in the first place, i.e. it was only available to Possessors and Symbiants, not monsters. --- src/melee2.cc | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 522b2f47..83827dcf 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2344,12 +2344,6 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_ANIM_DEAD */ - case 160 + 12: - { - break; - } - /* RF6_S_BUG */ case 160 + 13: { @@ -4214,10 +4208,6 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_ANIM_DEAD */ - case 160 + 12: - break; - /* RF6_S_BUG */ case 160 + 13: { -- cgit v1.2.3 From 59b5314b6b7880cfda73f34aed03a700fd523017 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Rework RF{4,5,6}_* monster spell flags to flag_set<> --- src/melee2.cc | 1135 ++++++++++++++++++++++----------------------------------- 1 file changed, 440 insertions(+), 695 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 83827dcf..3e03c8f6 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -28,6 +28,8 @@ #include "monster2.hpp" #include "monster3.hpp" #include "monster_race.hpp" +#include "monster_spell.hpp" +#include "monster_spell_flag.hpp" #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" @@ -301,16 +303,13 @@ static bool_ int_outof(std::shared_ptr r_ptr, int prob) /* * Remove the "bad" spells from a spell list */ -static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) +static void remove_bad_spells(int m_idx, monster_spell_flag_set *spells_p) { monster_type *m_ptr = &m_list[m_idx]; - - u32b f4 = (*f4p); - u32b f5 = (*f5p); - u32b f6 = (*f6p); - u32b smart = 0L; + // Shorthand + auto spells(*spells_p); /* Too stupid to know anything? */ auto const r_ptr = m_ptr->race(); @@ -338,201 +337,199 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p) if (smart & (SM_IMM_ACID)) { - if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_ACID; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_ACID; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ACID; + if (int_outof(r_ptr, 100)) spells &= ~SF_BR_ACID; + if (int_outof(r_ptr, 100)) spells &= ~SF_BA_ACID; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_ACID; } else if ((smart & (SM_OPP_ACID)) && (smart & (SM_RES_ACID))) { - if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_ACID; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_ACID; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_ACID; + if (int_outof(r_ptr, 80)) spells &= ~SF_BR_ACID; + if (int_outof(r_ptr, 80)) spells &= ~SF_BA_ACID; + if (int_outof(r_ptr, 80)) spells &= ~SF_BO_ACID; } else if ((smart & (SM_OPP_ACID)) || (smart & (SM_RES_ACID))) { - if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_ACID; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_ACID; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_ACID; + if (int_outof(r_ptr, 30)) spells &= ~SF_BR_ACID; + if (int_outof(r_ptr, 30)) spells &= ~SF_BA_ACID; + if (int_outof(r_ptr, 30)) spells &= ~SF_BO_ACID; } if (smart & (SM_IMM_ELEC)) { - if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_ELEC; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_ELEC; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ELEC; + if (int_outof(r_ptr, 100)) spells &= ~SF_BR_ELEC; + if (int_outof(r_ptr, 100)) spells &= ~SF_BA_ELEC; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_ELEC; } else if ((smart & (SM_OPP_ELEC)) && (smart & (SM_RES_ELEC))) { - if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_ELEC; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_ELEC; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_ELEC; + if (int_outof(r_ptr, 80)) spells &= ~SF_BR_ELEC; + if (int_outof(r_ptr, 80)) spells &= ~SF_BA_ELEC; + if (int_outof(r_ptr, 80)) spells &= ~SF_BO_ELEC; } else if ((smart & (SM_OPP_ELEC)) || (smart & (SM_RES_ELEC))) { - if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_ELEC; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_ELEC; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_ELEC; + if (int_outof(r_ptr, 30)) spells &= ~SF_BR_ELEC; + if (int_outof(r_ptr, 30)) spells &= ~SF_BA_ELEC; + if (int_outof(r_ptr, 30)) spells &= ~SF_BO_ELEC; } if (smart & (SM_IMM_FIRE)) { - if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_FIRE; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_FIRE; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_FIRE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BR_FIRE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BA_FIRE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_FIRE; } else if ((smart & (SM_OPP_FIRE)) && (smart & (SM_RES_FIRE))) { - if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_FIRE; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_FIRE; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_FIRE; + if (int_outof(r_ptr, 80)) spells &= ~SF_BR_FIRE; + if (int_outof(r_ptr, 80)) spells &= ~SF_BA_FIRE; + if (int_outof(r_ptr, 80)) spells &= ~SF_BO_FIRE; } else if ((smart & (SM_OPP_FIRE)) || (smart & (SM_RES_FIRE))) { - if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_FIRE; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_FIRE; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_FIRE; + if (int_outof(r_ptr, 30)) spells &= ~SF_BR_FIRE; + if (int_outof(r_ptr, 30)) spells &= ~SF_BA_FIRE; + if (int_outof(r_ptr, 30)) spells &= ~SF_BO_FIRE; } if (smart & (SM_IMM_COLD)) { - if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_COLD; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BA_COLD; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_COLD; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ICEE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BR_COLD; + if (int_outof(r_ptr, 100)) spells &= ~SF_BA_COLD; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_COLD; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_ICEE; } else if ((smart & (SM_OPP_COLD)) && (smart & (SM_RES_COLD))) { - if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_COLD; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_COLD; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_COLD; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BO_ICEE; + if (int_outof(r_ptr, 80)) spells &= ~SF_BR_COLD; + if (int_outof(r_ptr, 80)) spells &= ~SF_BA_COLD; + if (int_outof(r_ptr, 80)) spells &= ~SF_BO_COLD; + if (int_outof(r_ptr, 80)) spells &= ~SF_BO_ICEE; } else if ((smart & (SM_OPP_COLD)) || (smart & (SM_RES_COLD))) { - if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_COLD; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_COLD; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_COLD; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BO_ICEE; + if (int_outof(r_ptr, 30)) spells &= ~SF_BR_COLD; + if (int_outof(r_ptr, 30)) spells &= ~SF_BA_COLD; + if (int_outof(r_ptr, 30)) spells &= ~SF_BO_COLD; + if (int_outof(r_ptr, 30)) spells &= ~SF_BO_ICEE; } if ((smart & (SM_OPP_POIS)) && (smart & (SM_RES_POIS))) { - if (int_outof(r_ptr, 80)) f4 &= ~RF4_BR_POIS; - if (int_outof(r_ptr, 80)) f5 &= ~RF5_BA_POIS; - if (int_outof(r_ptr, 40)) f4 &= ~RF4_BA_NUKE; - if (int_outof(r_ptr, 40)) f4 &= ~RF4_BR_NUKE; + if (int_outof(r_ptr, 80)) spells &= ~SF_BR_POIS; + if (int_outof(r_ptr, 80)) spells &= ~SF_BA_POIS; + if (int_outof(r_ptr, 40)) spells &= ~SF_BA_NUKE; + if (int_outof(r_ptr, 40)) spells &= ~SF_BR_NUKE; } else if ((smart & (SM_OPP_POIS)) || (smart & (SM_RES_POIS))) { - if (int_outof(r_ptr, 30)) f4 &= ~RF4_BR_POIS; - if (int_outof(r_ptr, 30)) f5 &= ~RF5_BA_POIS; + if (int_outof(r_ptr, 30)) spells &= ~SF_BR_POIS; + if (int_outof(r_ptr, 30)) spells &= ~SF_BA_POIS; } if (smart & (SM_RES_NETH)) { - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_NETH; - if (int_outof(r_ptr, 50)) f5 &= ~RF5_BA_NETH; - if (int_outof(r_ptr, 50)) f5 &= ~RF5_BO_NETH; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_NETH; + if (int_outof(r_ptr, 50)) spells &= ~SF_BA_NETH; + if (int_outof(r_ptr, 50)) spells &= ~SF_BO_NETH; } if (smart & (SM_RES_LITE)) { - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_LITE; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_LITE; } if (smart & (SM_RES_DARK)) { - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_DARK; - if (int_outof(r_ptr, 50)) f5 &= ~RF5_BA_DARK; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_DARK; + if (int_outof(r_ptr, 50)) spells &= ~SF_BA_DARK; } if (smart & (SM_RES_FEAR)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_SCARE; + if (int_outof(r_ptr, 100)) spells &= ~SF_SCARE; } if (smart & (SM_RES_CONF)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_CONF; - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_CONF; + if (int_outof(r_ptr, 100)) spells &= ~SF_CONF; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_CONF; } if (smart & (SM_RES_CHAOS)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_CONF; - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_CONF; - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_CHAO; - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BA_CHAO; + if (int_outof(r_ptr, 100)) spells &= ~SF_CONF; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_CONF; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_CHAO; + if (int_outof(r_ptr, 50)) spells &= ~SF_BA_CHAO; } if (smart & (SM_RES_DISEN)) { - if (int_outof(r_ptr, 100)) f4 &= ~RF4_BR_DISE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BR_DISE; } if (smart & (SM_RES_BLIND)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BLIND; + if (int_outof(r_ptr, 100)) spells &= ~SF_BLIND; } if (smart & (SM_RES_NEXUS)) { - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_NEXU; - if (int_outof(r_ptr, 50)) f6 &= ~RF6_TELE_LEVEL; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_NEXU; + if (int_outof(r_ptr, 50)) spells &= ~SF_TELE_LEVEL; } if (smart & (SM_RES_SOUND)) { - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_SOUN; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_SOUN; } if (smart & (SM_RES_SHARD)) { - if (int_outof(r_ptr, 50)) f4 &= ~RF4_BR_SHAR; - if (int_outof(r_ptr, 20)) f4 &= ~RF4_ROCKET; + if (int_outof(r_ptr, 50)) spells &= ~SF_BR_SHAR; + if (int_outof(r_ptr, 20)) spells &= ~SF_ROCKET; } if (smart & (SM_IMM_REFLECT)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_COLD; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_FIRE; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ACID; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ELEC; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_POIS; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_NETH; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_WATE; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_MANA; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_PLAS; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_BO_ICEE; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_MISSILE; - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_1); - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_2); - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_3); - if (int_outof(r_ptr, 100)) f4 &= ~(RF4_ARROW_4); + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_COLD; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_FIRE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_ACID; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_ELEC; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_POIS; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_NETH; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_WATE; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_MANA; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_PLAS; + if (int_outof(r_ptr, 100)) spells &= ~SF_BO_ICEE; + if (int_outof(r_ptr, 100)) spells &= ~SF_MISSILE; + if (int_outof(r_ptr, 100)) spells &= ~(SF_ARROW_1); + if (int_outof(r_ptr, 100)) spells &= ~(SF_ARROW_2); + if (int_outof(r_ptr, 100)) spells &= ~(SF_ARROW_3); + if (int_outof(r_ptr, 100)) spells &= ~(SF_ARROW_4); } if (smart & (SM_IMM_FREE)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_HOLD; - if (int_outof(r_ptr, 100)) f5 &= ~RF5_SLOW; + if (int_outof(r_ptr, 100)) spells &= ~SF_HOLD; + if (int_outof(r_ptr, 100)) spells &= ~SF_SLOW; } if (smart & (SM_IMM_MANA)) { - if (int_outof(r_ptr, 100)) f5 &= ~RF5_DRAIN_MANA; + if (int_outof(r_ptr, 100)) spells &= ~SF_DRAIN_MANA; } /* XXX XXX XXX No spells left? */ /* if (!f4 && !f5 && !f6) ... */ - (*f4p) = f4; - (*f5p) = f5; - (*f6p) = f6; + *spells_p = spells; } @@ -628,117 +625,70 @@ static void bolt(int m_idx, int typ, int dam_hp) /* - * Return TRUE if a spell is good for hurting the player (directly). - */ -static bool_ spell_attack(byte spell) -{ - /* All RF4 spells hurt (except for shriek, multiply, summon animal) */ - if (spell >= 96 + 3 && spell <= 96 + 31) return (TRUE); - - /* Various "ball" spells */ - if (spell >= 128 && spell <= 128 + 8) return (TRUE); - - /* "Cause wounds" and "bolt" spells */ - if (spell >= 128 + 12 && spell <= 128 + 26) return (TRUE); - - /* Hand of Doom */ - if (spell == 160 + 1) return (TRUE); - - /* Doesn't hurt */ - return (FALSE); -} - - -/* - * Return TRUE if a spell is good for escaping. - */ -static bool_ spell_escape(byte spell) -{ - /* Blink or Teleport */ - if (spell == 160 + 4 || spell == 160 + 5) return (TRUE); - - /* Teleport the player away */ - if (spell == 160 + 7 || spell == 160 + 8) return (TRUE); - - /* Isn't good for escaping */ - return (FALSE); -} - -/* - * Return TRUE if a spell is good for annoying the player. - */ -static bool_ spell_annoy(byte spell) -{ - /* Shriek */ - if (spell == 96 + 0) return (TRUE); - - /* Brain smash, et al (added curses) */ - if (spell >= 128 + 9 && spell <= 128 + 14) return (TRUE); - - /* Scare, confuse, blind, slow, paralyze */ - if (spell >= 128 + 27 && spell <= 128 + 31) return (TRUE); - - /* Teleport to */ - if (spell == 160 + 6) return (TRUE); - - /* Darkness, make traps, cause amnesia */ - if (spell >= 160 + 9 && spell <= 160 + 11) return (TRUE); - - /* Doesn't annoy */ - return (FALSE); -} - -/* - * Return TRUE if a spell summons help. + * Calculate the mask for "bolt" spells */ -static bool_ spell_summon(byte spell) +static monster_spell_flag_set compute_bolt_mask() { - /* RF4_S_ANIMAL, RF6_S_ANIMALS */ - if (spell == 96 + 2 || spell == 160 + 3) return (TRUE); - /* All other summon spells */ - if (spell >= 160 + 13 && spell <= 160 + 31) return (TRUE); - - /* Doesn't summon */ - return (FALSE); + monster_spell_flag_set flags; + for (auto const &monster_spell: monster_spells()) + { + if (monster_spell->is_bolt) + { + flags |= monster_spell->flag_set; + } + } + return flags; } /* - * Return TRUE if a spell is good in a tactical situation. + * Calculate mask for summoning spells */ -static bool_ spell_tactic(byte spell) +static monster_spell_flag_set compute_summoning_mask() { - /* Blink */ - if (spell == 160 + 4) return (TRUE); - - /* Not good */ - return (FALSE); + monster_spell_flag_set flags; + for (auto const &monster_spell: monster_spells()) + { + if (monster_spell->is_summon) + { + flags |= monster_spell->flag_set; + } + } + return flags; } /* - * Return TRUE if a spell hastes. + * Calculate mask for spells requiring SMART flag */ -static bool_ spell_haste(byte spell) +static monster_spell_flag_set compute_smart_mask() { - /* Haste self */ - if (spell == 160 + 0) return (TRUE); - - /* Not a haste spell */ - return (FALSE); + monster_spell_flag_set flags; + for (auto const &monster_spell: monster_spells()) + { + if (monster_spell->is_smart) + { + flags |= monster_spell->flag_set; + } + } + return flags; } /* - * Return TRUE if a spell is good for healing. + * Calculate mask for spells requiring SMART flag */ -static bool_ spell_heal(byte spell) +static monster_spell_flag_set compute_innate_mask() { - /* Heal */ - if (spell == 160 + 2) return (TRUE); - - /* No healing */ - return (FALSE); + monster_spell_flag_set flags; + for (auto const &monster_spell: monster_spells()) + { + if (monster_spell->is_innate) + { + flags |= monster_spell->flag_set; + } + } + return flags; } @@ -756,49 +706,71 @@ static bool_ spell_heal(byte spell) * * This function may well be an efficiency bottleneck. */ -static int choose_attack_spell(int m_idx, byte spells[], byte num) +static monster_spell const *choose_attack_spell(int m_idx, std::vector const &spells) { monster_type *m_ptr = &m_list[m_idx]; - byte escape[96], escape_num = 0; - byte attack[96], attack_num = 0; - byte summon[96], summon_num = 0; - byte tactic[96], tactic_num = 0; - byte annoy[96], annoy_num = 0; - byte haste[96], haste_num = 0; - byte heal[96], heal_num = 0; - /* Stupid monsters choose randomly */ auto const r_ptr = m_ptr->race(); if (r_ptr->flags2 & RF2_STUPID) { /* Pick at random */ - return (spells[rand_int(num)]); + return spells[rand_int(spells.size())]; } + /* Spells by category */ + std::vector escape; escape.reserve(spells.size()); + std::vector attack; attack.reserve(spells.size()); + std::vector summon; summon.reserve(spells.size()); + std::vector tactic; tactic.reserve(spells.size()); + std::vector annoy ; annoy.reserve(spells.size()); + std::vector haste ; haste.reserve(spells.size()); + std::vector heal ; heal.reserve(spells.size()); + /* Categorize spells */ - for (int i = 0; i < num; i++) + for (std::size_t i = 0; i < spells.size(); i++) { /* Escape spell? */ - if (spell_escape(spells[i])) escape[escape_num++] = spells[i]; + if (spells[i]->is_escape) + { + escape.push_back(spells[i]); + } /* Attack spell? */ - if (spell_attack(spells[i])) attack[attack_num++] = spells[i]; + if (spells[i]->is_damage) + { + attack.push_back(spells[i]); + } /* Summon spell? */ - if (spell_summon(spells[i])) summon[summon_num++] = spells[i]; + if (spells[i]->is_summon) + { + summon.push_back(spells[i]); + } /* Tactical spell? */ - if (spell_tactic(spells[i])) tactic[tactic_num++] = spells[i]; + if (spells[i]->is_tactic) + { + tactic.push_back(spells[i]); + } /* Annoyance spell? */ - if (spell_annoy(spells[i])) annoy[annoy_num++] = spells[i]; + if (spells[i]->is_annoy) + { + annoy.push_back(spells[i]); + } /* Haste spell? */ - if (spell_haste(spells[i])) haste[haste_num++] = spells[i]; + if (spells[i]->is_haste) + { + haste.push_back(spells[i]); + } /* Heal spell? */ - if (spell_heal(spells[i])) heal[heal_num++] = spells[i]; + if (spells[i]->is_heal) + { + heal.push_back(spells[i]); + } } /*** Try to pick an appropriate spell type ***/ @@ -806,68 +778,59 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num) /* Hurt badly or afraid, attempt to flee */ if ((m_ptr->hp < m_ptr->maxhp / 3) || m_ptr->monfear) { - /* Choose escape spell if possible */ - if (escape_num) return (escape[rand_int(escape_num)]); + if (!escape.empty()) return escape[rand_int(escape.size())]; } /* Still hurt badly, couldn't flee, attempt to heal */ if (m_ptr->hp < m_ptr->maxhp / 3) { - /* Choose heal spell if possible */ - if (heal_num) return (heal[rand_int(heal_num)]); + if (!heal.empty()) return heal[rand_int(heal.size())]; } /* Player is close and we have attack spells, blink away */ - if ((distance(p_ptr->py, p_ptr->px, m_ptr->fy, m_ptr->fx) < 4) && attack_num && (rand_int(100) < 75)) + if ((distance(p_ptr->py, p_ptr->px, m_ptr->fy, m_ptr->fx) < 4) && !attack.empty() && (rand_int(100) < 75)) { - /* Choose tactical spell */ - if (tactic_num) return (tactic[rand_int(tactic_num)]); + if (!tactic.empty()) return tactic[rand_int(tactic.size())]; } /* We're hurt (not badly), try to heal */ if ((m_ptr->hp < m_ptr->maxhp * 3 / 4) && (rand_int(100) < 75)) { - /* Choose heal spell if possible */ - if (heal_num) return (heal[rand_int(heal_num)]); + if (!heal.empty()) return heal[rand_int(heal.size())]; } /* Summon if possible (sometimes) */ - if (summon_num && (rand_int(100) < 50)) + if (!summon.empty() && (rand_int(100) < 50)) { - /* Choose summon spell */ - return (summon[rand_int(summon_num)]); + return summon[rand_int(summon.size())]; } /* Attack spell (most of the time) */ - if (attack_num && (rand_int(100) < 85)) + if (!attack.empty() && (rand_int(100) < 85)) { - /* Choose attack spell */ - return (attack[rand_int(attack_num)]); + return attack[rand_int(attack.size())]; } /* Try another tactical spell (sometimes) */ - if (tactic_num && (rand_int(100) < 50)) + if (!tactic.empty() && (rand_int(100) < 50)) { - /* Choose tactic spell */ - return (tactic[rand_int(tactic_num)]); + return tactic[rand_int(tactic.size())]; } /* Haste self if we aren't already somewhat hasted (rarely) */ - if (haste_num && (rand_int(100) < (20 + m_ptr->speed - m_ptr->mspeed))) + if (!haste.empty() && (rand_int(100) < (20 + m_ptr->speed - m_ptr->mspeed))) { - /* Choose haste spell */ - return (haste[rand_int(haste_num)]); + return haste[rand_int(haste.size())]; } /* Annoy player (most of the time) */ - if (annoy_num && (rand_int(100) < 85)) + if (!annoy.empty() && (rand_int(100) < 85)) { - /* Choose annoyance spell */ - return (annoy[rand_int(annoy_num)]); + return annoy[rand_int(annoy.size())]; } /* Choose no spell */ - return (0); + return nullptr; } @@ -981,6 +944,24 @@ void cmonster_msg(char a, cptr fmt, ...) } } +/** + * Extract list of spell indexes from a flag set. + */ +static std::vector extract_spells(monster_spell_flag_set const &spell_flag_set) +{ + auto result = std::vector(); + result.reserve(spell_flag_set.nbits); + + for (std::size_t k = 0; k < monster_spell_flag_set::nbits; k++) + { + if (spell_flag_set.bit(k)) + { + result.push_back(monster_spells()[k]); + } + } + + return result; +} /* * Monster tries to 'cast a spell' (or breath, etc) @@ -989,15 +970,14 @@ void cmonster_msg(char a, cptr fmt, ...) int monst_spell_monst_spell = -1; static bool_ monst_spell_monst(int m_idx) { + static const monster_spell_flag_set SF_INT_MASK = compute_smart_mask(); + int y = 0, x = 0; int i = 1; - int thrown_spell; - byte spell[96], num = 0; char m_name[80], t_name[80]; char m_poss[80]; char ddesc[80]; monster_type *m_ptr = &m_list[m_idx]; /* Attacker */ - u32b f4, f5, f6; /* racial spell flags */ bool_ direct = TRUE; bool_ wake_up = FALSE; @@ -1059,10 +1039,8 @@ static bool_ monst_spell_monst(int m_idx) /* Extract the monster level */ const int rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); - /* Extract the racial spell flags */ - f4 = r_ptr->flags4; - f5 = r_ptr->flags5; - f6 = r_ptr->flags6; + /* Which spells are allowed? */ + monster_spell_flag_set allowed_spells = r_ptr->spells; /* Hack -- allow "desperate" spells */ if ((r_ptr->flags2 & RF2_SMART) && @@ -1070,34 +1048,17 @@ static bool_ monst_spell_monst(int m_idx) (rand_int(100) < 50)) { /* Require intelligent spells */ - f4 &= RF4_INT_MASK; - f5 &= RF5_INT_MASK; - f6 &= RF6_INT_MASK; - - /* No spells left */ - if ((!f4 && !f5 && !f6) && (monst_spell_monst_spell == -1)) return (FALSE); - } + allowed_spells &= SF_INT_MASK; - /* Extract the "inate" spells */ - for (int k = 0; k < 32; k++) - { - if (f4 & (1L << k)) spell[num++] = k + 32 * 3; - } - - /* Extract the "normal" spells */ - for (int k = 0; k < 32; k++) - { - if (f5 & (1L << k)) spell[num++] = k + 32 * 4; + /* No spells left? */ + if ((!allowed_spells) && (monst_spell_monst_spell == -1)) return (FALSE); } - /* Extract the "bizarre" spells */ - for (int k = 0; k < 32; k++) - { - if (f6 & (1L << k)) spell[num++] = k + 32 * 5; - } + /* Extract spells */ + auto spell = extract_spells(allowed_spells); - /* No spells left */ - if (!num) return (FALSE); + /* No spells left? */ + if (spell.empty()) return (FALSE); /* Stop if player is dead or gone */ if (!alive || death) return (FALSE); @@ -1118,12 +1079,12 @@ static bool_ monst_spell_monst(int m_idx) monster_desc(ddesc, m_ptr, 0x88); /* Choose a spell to cast */ - thrown_spell = spell[rand_int(num)]; + auto thrown_spell = spell[rand_int(spell.size())]; /* Force a spell ? */ if (monst_spell_monst_spell > -1) { - thrown_spell = monst_spell_monst_spell; + thrown_spell = spell[monst_spell_monst_spell]; monst_spell_monst_spell = -1; } @@ -1133,10 +1094,9 @@ static bool_ monst_spell_monst(int m_idx) see_both = (see_m && see_t); int count = 0; - switch (thrown_spell) + switch (thrown_spell->spell_idx) { - /* RF4_SHRIEK */ - case 96 + 0: + case SF_SHRIEK_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1146,14 +1106,12 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_MULTIPLY */ - case 96 + 1: + case SF_MULTIPLY_IDX: { break; } - /* RF4_S_ANIMAL */ - case 96 + 2: + case SF_S_ANIMAL_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1169,8 +1127,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_ROCKET */ - case 96 + 3: + case SF_ROCKET_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear an explosion!"); @@ -1181,8 +1138,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_ARROW_1 */ - case 96 + 4: + case SF_ARROW_1_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear a strange noise."); @@ -1193,8 +1149,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_ARROW_2 */ - case 96 + 5: + case SF_ARROW_2_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear a strange noise."); @@ -1205,8 +1160,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_ARROW_3 */ - case 96 + 6: + case SF_ARROW_3_IDX: { if (disturb_other) disturb(1); @@ -1218,8 +1172,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_ARROW_4 */ - case 96 + 7: + case SF_ARROW_4_IDX: { if (!see_either) monster_msg("You hear a strange noise."); else if (disturb_other) disturb(1); @@ -1230,8 +1183,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_ACID */ - case 96 + 8: + case SF_BR_ACID_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1243,8 +1195,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_ELEC */ - case 96 + 9: + case SF_BR_ELEC_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1256,8 +1207,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_FIRE */ - case 96 + 10: + case SF_BR_FIRE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1269,8 +1219,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_COLD */ - case 96 + 11: + case SF_BR_COLD_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1282,8 +1231,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_POIS */ - case 96 + 12: + case SF_BR_POIS_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1295,8 +1243,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_NETH */ - case 96 + 13: + case SF_BR_NETH_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1308,8 +1255,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_LITE */ - case 96 + 14: + case SF_BR_LITE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1321,8 +1267,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_DARK */ - case 96 + 15: + case SF_BR_DARK_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1334,8 +1279,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_CONF */ - case 96 + 16: + case SF_BR_CONF_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1347,8 +1291,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_SOUN */ - case 96 + 17: + case SF_BR_SOUN_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1360,8 +1303,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_CHAO */ - case 96 + 18: + case SF_BR_CHAO_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1373,8 +1315,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_DISE */ - case 96 + 19: + case SF_BR_DISE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1386,8 +1327,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_NEXU */ - case 96 + 20: + case SF_BR_NEXU_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1399,8 +1339,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_TIME */ - case 96 + 21: + case SF_BR_TIME_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1412,8 +1351,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_INER */ - case 96 + 22: + case SF_BR_INER_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1425,8 +1363,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_GRAV */ - case 96 + 23: + case SF_BR_GRAV_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1438,8 +1375,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_SHAR */ - case 96 + 24: + case SF_BR_SHAR_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1451,8 +1387,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_PLAS */ - case 96 + 25: + case SF_BR_PLAS_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1464,8 +1399,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_WALL */ - case 96 + 26: + case SF_BR_WALL_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1477,8 +1411,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_MANA */ - case 96 + 27: + case SF_BR_MANA_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1490,8 +1423,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BA_NUKE */ - case 96 + 28: + case SF_BA_NUKE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear someone mumble."); @@ -1503,8 +1435,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_NUKE */ - case 96 + 29: + case SF_BR_NUKE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1516,8 +1447,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BA_CHAO */ - case 96 + 30: + case SF_BA_CHAO_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear someone mumble frighteningly."); @@ -1529,8 +1459,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF4_BR_DISI -> Breathe Disintegration */ - case 96 + 31: + case SF_BR_DISI_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear breathing noise."); @@ -1542,8 +1471,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_ACID */ - case 128 + 0: + case SF_BA_ACID_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1553,8 +1481,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_ELEC */ - case 128 + 1: + case SF_BA_ELEC_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1565,8 +1492,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_FIRE */ - case 128 + 2: + case SF_BA_FIRE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1577,8 +1503,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_COLD */ - case 128 + 3: + case SF_BA_COLD_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1589,8 +1514,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_POIS */ - case 128 + 4: + case SF_BA_POIS_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1601,8 +1525,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_NETH */ - case 128 + 5: + case SF_BA_NETH_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1613,8 +1536,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_WATE */ - case 128 + 6: + case SF_BA_WATE_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble."); @@ -1626,8 +1548,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_MANA */ - case 128 + 7: + case SF_BA_MANA_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble powerfully."); @@ -1638,8 +1559,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BA_DARK */ - case 128 + 8: + case SF_BA_DARK_IDX: { if (disturb_other) disturb(1); if (!see_either) monster_msg ("You hear someone mumble powerfully."); @@ -1650,8 +1570,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_DRAIN_MANA */ - case 128 + 9: + case SF_DRAIN_MANA_IDX: { /* Attack power */ int r1 = (randint(rlev) / 2) + 1; @@ -1665,7 +1584,7 @@ static bool_ monst_spell_monst(int m_idx) /* Heal the monster */ if (m_ptr->hp < m_ptr->maxhp) { - if (!(tr_ptr->flags4 || tr_ptr->flags5 || tr_ptr->flags6)) + if (!tr_ptr->spells) { if (see_both) monster_msg("%^s is unaffected!", t_name); @@ -1691,8 +1610,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_MIND_BLAST */ - case 128 + 10: + case SF_MIND_BLAST_IDX: { if (!direct) break; @@ -1731,8 +1649,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BRAIN_SMASH */ - case 128 + 11: + case SF_BRAIN_SMASH_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1772,8 +1689,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_CAUSE_1 */ - case 128 + 12: + case SF_CAUSE_1_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1793,8 +1709,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_CAUSE_2 */ - case 128 + 13: + case SF_CAUSE_2_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1813,8 +1728,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_CAUSE_3 */ - case 128 + 14: + case SF_CAUSE_3_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1833,8 +1747,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_CAUSE_4 */ - case 128 + 15: + case SF_CAUSE_4_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1853,8 +1766,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_ACID */ - case 128 + 16: + case SF_BO_ACID_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1864,8 +1776,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_ELEC */ - case 128 + 17: + case SF_BO_ELEC_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1875,8 +1786,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_FIRE */ - case 128 + 18: + case SF_BO_FIRE_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1886,8 +1796,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_COLD */ - case 128 + 19: + case SF_BO_COLD_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1897,15 +1806,13 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_POIS */ - case 128 + 20: + case SF_BO_POIS_IDX: { /* XXX XXX XXX */ break; } - /* RF5_BO_NETH */ - case 128 + 21: + case SF_BO_NETH_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1915,8 +1822,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_WATE */ - case 128 + 22: + case SF_BO_WATE_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1926,8 +1832,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_MANA */ - case 128 + 23: + case SF_BO_MANA_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1937,8 +1842,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_PLAS */ - case 128 + 24: + case SF_BO_PLAS_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1948,8 +1852,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BO_ICEE */ - case 128 + 25: + case SF_BO_ICEE_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1959,8 +1862,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_MISSILE */ - case 128 + 26: + case SF_MISSILE_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -1970,8 +1872,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_SCARE */ - case 128 + 27: + case SF_SCARE_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -1994,8 +1895,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_BLIND */ - case 128 + 28: + case SF_BLIND_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -2020,8 +1920,7 @@ static bool_ monst_spell_monst(int m_idx) } - /* RF5_CONF */ - case 128 + 29: + case SF_CONF_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -2044,8 +1943,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_SLOW */ - case 128 + 30: + case SF_SLOW_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -2068,8 +1966,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF5_HOLD */ - case 128 + 31: + case SF_HOLD_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -2092,9 +1989,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - - /* RF6_HASTE */ - case 160 + 0: + case SF_HASTE_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) @@ -2123,8 +2018,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_HAND_DOOM */ - case 160 + 1: + case SF_HAND_DOOM_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -2155,8 +2049,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_HEAL */ - case 160 + 2: + case SF_HEAL_IDX: { if (disturb_other) disturb(1); @@ -2220,8 +2113,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_ANIMALS */ - case 160 + 3: + case SF_S_ANIMALS_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2237,8 +2129,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_BLINK */ - case 160 + 4: + case SF_BLINK_IDX: { if (disturb_other) disturb(1); if (see_m) monster_msg("%^s blinks away.", m_name); @@ -2246,8 +2137,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_TPORT */ - case 160 + 5: + case SF_TPORT_IDX: { if (dungeon_flags & DF_NO_TELEPORT) break; /* No teleport on special levels */ else @@ -2259,15 +2149,13 @@ static bool_ monst_spell_monst(int m_idx) } } - /* RF6_TELE_TO */ - case 160 + 6: + case SF_TELE_TO_IDX: { /* Not implemented */ break; } - /* RF6_TELE_AWAY */ - case 160 + 7: + case SF_TELE_AWAY_IDX: { if (dungeon_flags & DF_NO_TELEPORT) break; @@ -2308,15 +2196,13 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_TELE_LEVEL */ - case 160 + 8: + case SF_TELE_LEVEL_IDX: { /* Not implemented */ break; } - /* RF6_DARKNESS */ - case 160 + 9: + case SF_DARKNESS_IDX: { if (!direct) break; if (disturb_other) disturb(1); @@ -2330,22 +2216,19 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_TRAPS */ - case 160 + 10: + case SF_TRAPS_IDX: { /* Not implemented */ break; } - /* RF6_FORGET */ - case 160 + 11: + case SF_FORGET_IDX: { /* Not implemented */ break; } - /* RF6_S_BUG */ - case 160 + 13: + case SF_S_BUG_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2361,8 +2244,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_RNG */ - case 160 + 14: + case SF_S_RNG_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2378,9 +2260,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - - /* RF6_S_THUNDERLORD */ - case 160 + 15: + case SF_S_THUNDERLORD_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2396,8 +2276,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_SUMMON_KIN */ - case 160 + 16: + case SF_S_KIN_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2419,8 +2298,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_HI_DEMON */ - case 160 + 17: + case SF_S_HI_DEMON_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2433,8 +2311,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_MONSTER */ - case 160 + 18: + case SF_S_MONSTER_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2450,8 +2327,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_MONSTERS */ - case 160 + 19: + case SF_S_MONSTERS_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2467,8 +2343,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_ANT */ - case 160 + 20: + case SF_S_ANT_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2484,8 +2359,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_SPIDER */ - case 160 + 21: + case SF_S_SPIDER_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2501,8 +2375,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_HOUND */ - case 160 + 22: + case SF_S_HOUND_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2518,8 +2391,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_HYDRA */ - case 160 + 23: + case SF_S_HYDRA_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2535,8 +2407,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_ANGEL */ - case 160 + 24: + case SF_S_ANGEL_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2552,8 +2423,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_DEMON */ - case 160 + 25: + case SF_S_DEMON_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2569,8 +2439,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_UNDEAD */ - case 160 + 26: + case SF_S_UNDEAD_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2586,8 +2455,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_DRAGON */ - case 160 + 27: + case SF_S_DRAGON_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2603,8 +2471,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_HI_UNDEAD */ - case 160 + 28: + case SF_S_HI_UNDEAD_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2623,8 +2490,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_HI_DRAGON */ - case 160 + 29: + case SF_S_HI_DRAGON_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2643,8 +2509,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_WRAITH */ - case 160 + 30: + case SF_S_WRAITH_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2663,8 +2528,7 @@ static bool_ monst_spell_monst(int m_idx) break; } - /* RF6_S_UNIQUE */ - case 160 + 31: + case SF_S_UNIQUE_IDX: { if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); @@ -2860,9 +2724,12 @@ void curse_equipment_dg(int chance, int heavy_chance) */ static bool_ make_attack_spell(int m_idx) { - int k, chance, thrown_spell, rlev, failrate; - byte spell[96], num = 0; - u32b f4, f5, f6; + static const auto SF_BOLT_MASK = compute_bolt_mask(); + static const auto SF_SUMMON_MASK = compute_summoning_mask(); + static const auto SF_INT_MASK = compute_smart_mask(); + static const auto SF_INNATE_MASK = compute_innate_mask(); + + int k, chance, rlev, failrate; char m_name[80]; bool_ no_inate = FALSE; int x, y; @@ -2934,12 +2801,13 @@ static bool_ make_attack_spell(int m_idx) rlev = ((m_ptr->level >= 1) ? m_ptr->level : 1); /* Extract the racial spell flags */ - f4 = r_ptr->flags4; - f5 = r_ptr->flags5; - f6 = r_ptr->flags6; + monster_spell_flag_set allowed_spells = r_ptr->spells; /* Forbid inate attacks sometimes */ - if (no_inate) f4 = 0L; + if (no_inate) + { + allowed_spells &= ~SF_INNATE_MASK; + } /* Hack -- allow "desperate" spells */ if ((r_ptr->flags2 & RF2_SMART) && @@ -2947,67 +2815,44 @@ static bool_ make_attack_spell(int m_idx) (rand_int(100) < 50)) { /* Require intelligent spells */ - f4 &= RF4_INT_MASK; - f5 &= RF5_INT_MASK; - f6 &= RF6_INT_MASK; + allowed_spells &= SF_INT_MASK; - /* No spells left */ - if (!f4 && !f5 && !f6) return (FALSE); + /* No spells left? */ + if (!allowed_spells) return (FALSE); } /* Remove the "ineffective" spells */ - remove_bad_spells(m_idx, &f4, &f5, &f6); + remove_bad_spells(m_idx, &allowed_spells); /* No spells left */ - if (!f4 && !f5 && !f6) return (FALSE); + if (!allowed_spells) return (FALSE); /* Check for a clean bolt shot */ - if ((f4&RF4_BOLT_MASK || f5 & RF5_BOLT_MASK || - f6&RF6_BOLT_MASK) && + if ((allowed_spells & SF_BOLT_MASK) && !(r_ptr->flags2 & RF2_STUPID) && !clean_shot(m_ptr->fy, m_ptr->fx, y, x)) { /* Remove spells that will only hurt friends */ - f4 &= ~RF4_BOLT_MASK; - f5 &= ~RF5_BOLT_MASK; - f6 &= ~RF6_BOLT_MASK; + allowed_spells &= ~SF_BOLT_MASK; } /* Check for a possible summon */ - if ((f4 & RF4_SUMMON_MASK || f5 & RF5_SUMMON_MASK || - f6 & RF6_SUMMON_MASK) && + if ((allowed_spells & SF_SUMMON_MASK) && !(r_ptr->flags2 & RF2_STUPID) && !(summon_possible(y, x))) { /* Remove summoning spells */ - f4 &= ~RF4_SUMMON_MASK; - f5 &= ~RF5_SUMMON_MASK; - f6 &= ~RF6_SUMMON_MASK; + allowed_spells &= ~SF_SUMMON_MASK; } /* No spells left */ - if (!f4 && !f5 && !f6) return (FALSE); + if (!allowed_spells) return (FALSE); /* Extract the "inate" spells */ - for (k = 0; k < 32; k++) - { - if (f4 & (1L << k)) spell[num++] = k + 32 * 3; - } - - /* Extract the "normal" spells */ - for (k = 0; k < 32; k++) - { - if (f5 & (1L << k)) spell[num++] = k + 32 * 4; - } - - /* Extract the "bizarre" spells */ - for (k = 0; k < 32; k++) - { - if (f6 & (1L << k)) spell[num++] = k + 32 * 5; - } + auto spell = extract_spells(allowed_spells); /* No spells left */ - if (!num) return (FALSE); + if (spell.empty()) return (FALSE); /* Stop if player is dead or gone */ if (!alive || death) return (FALSE); @@ -3019,7 +2864,7 @@ static bool_ make_attack_spell(int m_idx) monster_desc(m_name, m_ptr, 0x00); /* Choose a spell to cast */ - thrown_spell = choose_attack_spell(m_idx, spell, num); + auto thrown_spell = choose_attack_spell(m_idx, spell); /* Abort if no spell was chosen */ if (!thrown_spell) return (FALSE); @@ -3031,7 +2876,7 @@ static bool_ make_attack_spell(int m_idx) if (r_ptr->flags2 & RF2_STUPID) failrate = 0; /* Check for spell failure (inate attacks never fail) */ - if ((thrown_spell >= 128) && (rand_int(100) < failrate)) + if ((!thrown_spell->is_innate) && (rand_int(100) < failrate)) { /* Message */ msg_format("%^s tries to cast a spell, but fails.", m_name); @@ -3040,7 +2885,7 @@ static bool_ make_attack_spell(int m_idx) } /* Can the player disrupt its puny attempts? */ - if ((p_ptr->antimagic_dis >= m_ptr->cdis) && (magik(p_ptr->antimagic)) && (thrown_spell >= 128)) + if ((p_ptr->antimagic_dis >= m_ptr->cdis) && magik(p_ptr->antimagic) && thrown_spell->is_magic) { char m_poss[80]; @@ -3061,10 +2906,9 @@ static bool_ make_attack_spell(int m_idx) monster_desc(ddesc, m_ptr, 0x88); /* Cast the spell. */ - switch (thrown_spell) + switch (thrown_spell->spell_idx) { - /* RF4_SHRIEK */ - case 96 + 0: + case SF_SHRIEK_IDX: { disturb(1); msg_format("%^s makes a high pitched shriek.", m_name); @@ -3072,14 +2916,12 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_MULTIPLY */ - case 96 + 1: + case SF_MULTIPLY_IDX: { break; } - /* RF4_S_ANIMAL */ - case 96 + 2: + case SF_S_ANIMAL_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3092,8 +2934,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_ROCKET */ - case 96 + 3: + case SF_ROCKET_IDX: { disturb(1); if (blind) msg_format("%^s shoots something.", m_name); @@ -3104,8 +2945,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_ARROW_1 */ - case 96 + 4: + case SF_ARROW_1_IDX: { disturb(1); if (blind) msg_format("%^s makes a strange noise.", m_name); @@ -3115,8 +2955,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_ARROW_2 */ - case 96 + 5: + case SF_ARROW_2_IDX: { disturb(1); if (blind) msg_format("%^s makes a strange noise.", m_name); @@ -3126,8 +2965,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_ARROW_3 */ - case 96 + 6: + case SF_ARROW_3_IDX: { disturb(1); if (blind) msg_format("%^s makes a strange noise.", m_name); @@ -3137,8 +2975,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_ARROW_4 */ - case 96 + 7: + case SF_ARROW_4_IDX: { disturb(1); if (blind) msg_format("%^s makes a strange noise.", m_name); @@ -3148,8 +2985,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_ACID */ - case 96 + 8: + case SF_BR_ACID_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3160,8 +2996,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_ELEC */ - case 96 + 9: + case SF_BR_ELEC_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3172,8 +3007,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_FIRE */ - case 96 + 10: + case SF_BR_FIRE_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3184,8 +3018,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_COLD */ - case 96 + 11: + case SF_BR_COLD_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3196,8 +3029,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_POIS */ - case 96 + 12: + case SF_BR_POIS_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3208,9 +3040,7 @@ static bool_ make_attack_spell(int m_idx) break; } - - /* RF4_BR_NETH */ - case 96 + 13: + case SF_BR_NETH_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3221,8 +3051,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_LITE */ - case 96 + 14: + case SF_BR_LITE_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3233,8 +3062,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_DARK */ - case 96 + 15: + case SF_BR_DARK_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3245,8 +3073,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_CONF */ - case 96 + 16: + case SF_BR_CONF_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3257,8 +3084,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_SOUN */ - case 96 + 17: + case SF_BR_SOUN_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3269,8 +3095,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_CHAO */ - case 96 + 18: + case SF_BR_CHAO_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3281,8 +3106,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_DISE */ - case 96 + 19: + case SF_BR_DISE_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3293,8 +3117,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_NEXU */ - case 96 + 20: + case SF_BR_NEXU_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3305,8 +3128,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_TIME */ - case 96 + 21: + case SF_BR_TIME_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3316,8 +3138,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_INER */ - case 96 + 22: + case SF_BR_INER_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3327,8 +3148,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_GRAV */ - case 96 + 23: + case SF_BR_GRAV_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3338,8 +3158,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_SHAR */ - case 96 + 24: + case SF_BR_SHAR_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3350,8 +3169,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_PLAS */ - case 96 + 25: + case SF_BR_PLAS_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3361,8 +3179,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_WALL */ - case 96 + 26: + case SF_BR_WALL_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3372,8 +3189,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_MANA */ - case 96 + 27: + case SF_BR_MANA_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3383,8 +3199,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BA_NUKE */ - case 96 + 28: + case SF_BA_NUKE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3394,8 +3209,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_NUKE */ - case 96 + 29: + case SF_BR_NUKE_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3406,8 +3220,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BA_CHAO */ - case 96 + 30: + case SF_BA_CHAO_IDX: { disturb(1); if (blind) msg_format("%^s mumbles frighteningly.", m_name); @@ -3417,8 +3230,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF4_BR_DISI -> Disintegration breath! */ - case 96 + 31: + case SF_BR_DISI_IDX: { disturb(1); if (blind) msg_format("%^s breathes.", m_name); @@ -3428,10 +3240,7 @@ static bool_ make_attack_spell(int m_idx) break; } - - - /* RF5_BA_ACID */ - case 128 + 0: + case SF_BA_ACID_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3442,8 +3251,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_ELEC */ - case 128 + 1: + case SF_BA_ELEC_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3454,8 +3262,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_FIRE */ - case 128 + 2: + case SF_BA_FIRE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3466,8 +3273,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_COLD */ - case 128 + 3: + case SF_BA_COLD_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3478,8 +3284,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_POIS */ - case 128 + 4: + case SF_BA_POIS_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3490,8 +3295,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_NETH */ - case 128 + 5: + case SF_BA_NETH_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3502,8 +3306,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_WATE */ - case 128 + 6: + case SF_BA_WATE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3514,8 +3317,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_MANA */ - case 128 + 7: + case SF_BA_MANA_IDX: { disturb(1); if (blind) msg_format("%^s mumbles powerfully.", m_name); @@ -3525,8 +3327,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BA_DARK */ - case 128 + 8: + case SF_BA_DARK_IDX: { disturb(1); if (blind) msg_format("%^s mumbles powerfully.", m_name); @@ -3537,8 +3338,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_DRAIN_MANA */ - case 128 + 9: + case SF_DRAIN_MANA_IDX: { if (p_ptr->csp) { @@ -3594,8 +3394,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_MIND_BLAST */ - case 128 + 10: + case SF_MIND_BLAST_IDX: { disturb(1); if (!seen) @@ -3630,8 +3429,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BRAIN_SMASH */ - case 128 + 11: + case SF_BRAIN_SMASH_IDX: { disturb(1); if (!seen) @@ -3678,8 +3476,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_CAUSE_1 */ - case 128 + 12: + case SF_CAUSE_1_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3696,8 +3493,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_CAUSE_2 */ - case 128 + 13: + case SF_CAUSE_2_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3714,8 +3510,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_CAUSE_3 */ - case 128 + 14: + case SF_CAUSE_3_IDX: { disturb(1); if (blind) msg_format("%^s mumbles loudly.", m_name); @@ -3732,8 +3527,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_CAUSE_4 */ - case 128 + 15: + case SF_CAUSE_4_IDX: { disturb(1); if (blind) msg_format("%^s screams the word 'DIE!'", m_name); @@ -3750,8 +3544,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_ACID */ - case 128 + 16: + case SF_BO_ACID_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3762,8 +3555,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_ELEC */ - case 128 + 17: + case SF_BO_ELEC_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3774,8 +3566,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_FIRE */ - case 128 + 18: + case SF_BO_FIRE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3786,8 +3577,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_COLD */ - case 128 + 19: + case SF_BO_COLD_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3798,15 +3588,13 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_POIS */ - case 128 + 20: + case SF_BO_POIS_IDX: { /* XXX XXX XXX */ break; } - /* RF5_BO_NETH */ - case 128 + 21: + case SF_BO_NETH_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3817,8 +3605,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_WATE */ - case 128 + 22: + case SF_BO_WATE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3828,8 +3615,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_MANA */ - case 128 + 23: + case SF_BO_MANA_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3839,8 +3625,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_PLAS */ - case 128 + 24: + case SF_BO_PLAS_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3850,8 +3635,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BO_ICEE */ - case 128 + 25: + case SF_BO_ICEE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3862,8 +3646,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_MISSILE */ - case 128 + 26: + case SF_MISSILE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3873,8 +3656,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_SCARE */ - case 128 + 27: + case SF_SCARE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles, and you hear scary noises.", m_name); @@ -3895,8 +3677,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_BLIND */ - case 128 + 28: + case SF_BLIND_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3917,8 +3698,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_CONF */ - case 128 + 29: + case SF_CONF_IDX: { disturb(1); if (blind) msg_format("%^s mumbles, and you hear puzzling noises.", m_name); @@ -3939,8 +3719,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_SLOW */ - case 128 + 30: + case SF_SLOW_IDX: { disturb(1); msg_format("%^s drains power from your muscles!", m_name); @@ -3960,8 +3739,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF5_HOLD */ - case 128 + 31: + case SF_HOLD_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -3982,10 +3760,7 @@ static bool_ make_attack_spell(int m_idx) break; } - - - /* RF6_HASTE */ - case 160 + 0: + case SF_HASTE_IDX: { disturb(1); if (blind) @@ -4014,8 +3789,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_HAND_DOOM */ - case 160 + 1: + case SF_HAND_DOOM_IDX: { disturb(1); msg_format("%^s invokes the Hand of Doom!", m_name); @@ -4035,8 +3809,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_HEAL */ - case 160 + 2: + case SF_HEAL_IDX: { disturb(1); @@ -4099,8 +3872,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_ANIMALS */ - case 160 + 3: + case SF_S_ANIMALS_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4113,8 +3885,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_BLINK */ - case 160 + 4: + case SF_BLINK_IDX: { disturb(1); msg_format("%^s blinks away.", m_name); @@ -4122,8 +3893,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_TPORT */ - case 160 + 5: + case SF_TPORT_IDX: { disturb(1); msg_format("%^s teleports away.", m_name); @@ -4131,8 +3901,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_TELE_TO */ - case 160 + 6: + case SF_TELE_TO_IDX: { disturb(1); msg_format("%^s commands you to return.", m_name); @@ -4140,8 +3909,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_TELE_AWAY */ - case 160 + 7: + case SF_TELE_AWAY_IDX: { disturb(1); msg_format("%^s teleports you away.", m_name); @@ -4149,8 +3917,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_TELE_LEVEL */ - case 160 + 8: + case SF_TELE_LEVEL_IDX: { disturb(1); if (blind) msg_format("%^s mumbles strangely.", m_name); @@ -4171,8 +3938,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_DARKNESS */ - case 160 + 9: + case SF_DARKNESS_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4181,8 +3947,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_TRAPS */ - case 160 + 10: + case SF_TRAPS_IDX: { disturb(1); if (blind) msg_format("%^s mumbles, and then cackles evilly.", m_name); @@ -4191,8 +3956,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_FORGET */ - case 160 + 11: + case SF_FORGET_IDX: { disturb(1); msg_format("%^s tries to blank your mind.", m_name); @@ -4208,8 +3972,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_BUG */ - case 160 + 13: + case SF_S_BUG_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4222,8 +3985,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_RNG */ - case 160 + 14: + case SF_S_RNG_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4236,8 +3998,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_THUNDERLORD */ - case 160 + 15: + case SF_S_THUNDERLORD_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4250,8 +4011,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_SUMMON_KIN */ - case 160 + 16: + case SF_S_KIN_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4270,8 +4030,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_HI_DEMON */ - case 160 + 17: + case SF_S_HI_DEMON_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4281,8 +4040,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_MONSTER */ - case 160 + 18: + case SF_S_MONSTER_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4295,8 +4053,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_MONSTERS */ - case 160 + 19: + case SF_S_MONSTERS_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4309,8 +4066,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_ANT */ - case 160 + 20: + case SF_S_ANT_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4323,8 +4079,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_SPIDER */ - case 160 + 21: + case SF_S_SPIDER_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4337,8 +4092,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_HOUND */ - case 160 + 22: + case SF_S_HOUND_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4351,8 +4105,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_HYDRA */ - case 160 + 23: + case SF_S_HYDRA_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4365,8 +4118,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_ANGEL */ - case 160 + 24: + case SF_S_ANGEL_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4379,8 +4131,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_DEMON */ - case 160 + 25: + case SF_S_DEMON_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4393,8 +4144,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_UNDEAD */ - case 160 + 26: + case SF_S_UNDEAD_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4407,8 +4157,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_DRAGON */ - case 160 + 27: + case SF_S_DRAGON_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4421,8 +4170,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_HI_UNDEAD */ - case 160 + 28: + case SF_S_HI_UNDEAD_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4438,8 +4186,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_HI_DRAGON */ - case 160 + 29: + case SF_S_HI_DRAGON_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4455,8 +4202,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_WRAITH */ - case 160 + 30: + case SF_S_WRAITH_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -4475,8 +4221,7 @@ static bool_ make_attack_spell(int m_idx) break; } - /* RF6_S_UNIQUE */ - case 160 + 31: + case SF_S_UNIQUE_IDX: { disturb(1); if (blind) msg_format("%^s mumbles.", m_name); @@ -6188,7 +5933,7 @@ static void process_monster(int m_idx, bool_ is_frien) ox = m_ptr->fx; /* Attempt to "multiply" if able and allowed */ - if ((r_ptr->flags4 & RF4_MULTIPLY) && (num_repro < MAX_REPRO)) + if ((r_ptr->spells & SF_MULTIPLY) && (num_repro < MAX_REPRO)) { if (ai_multiply(m_idx)) return; } -- cgit v1.2.3 From 68e2a10b2d76cb3a2f5aa6818b4b184b6a02ef14 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Rework RF{1,2,3,7,8,9}_* monster flags to use flag_set<> --- src/melee2.cc | 219 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 108 insertions(+), 111 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 3e03c8f6..9d09fb67 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -28,6 +28,7 @@ #include "monster2.hpp" #include "monster3.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_spell.hpp" #include "monster_spell_flag.hpp" #include "monster_type.hpp" @@ -69,7 +70,7 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) /* Some monsters are immune to death */ auto const r_ptr = m_ptr->race(); - if (r_ptr->flags7 & RF7_NO_DEATH) return FALSE; + if (r_ptr->flags & RF_NO_DEATH) return FALSE; /* Wake it up */ m_ptr->csleep = 0; @@ -80,7 +81,7 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) /* It is dead now... or is it? */ if (m_ptr->hp < 0) { - if (((r_ptr->flags1 & RF1_UNIQUE) && (m_ptr->status <= MSTATUS_NEUTRAL_P)) || + if (((r_ptr->flags & RF_UNIQUE) && (m_ptr->status <= MSTATUS_NEUTRAL_P)) || (m_ptr->mflag & MFLAG_QUEST)) { m_ptr->hp = 1; @@ -96,10 +97,10 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) monster_desc(m_name, m_ptr, 0); /* Make a sound */ - if ((r_ptr->flags3 & RF3_DEMON) || - (r_ptr->flags3 & RF3_UNDEAD) || - (r_ptr->flags2 & RF2_STUPID) || - (r_ptr->flags3 & RF3_NONLIVING) || + if ((r_ptr->flags & RF_DEMON) || + (r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_STUPID) || + (r_ptr->flags & RF_NONLIVING) || (strchr("Evg", r_ptr->d_char))) { sound(SOUND_N_KILL); @@ -120,10 +121,10 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) /* Do nothing */ } /* Death by Physical attack -- non-living monster */ - else if ((r_ptr->flags3 & RF3_DEMON) || - (r_ptr->flags3 & RF3_UNDEAD) || - (r_ptr->flags2 & RF2_STUPID) || - (r_ptr->flags3 & RF3_NONLIVING) || + else if ((r_ptr->flags & RF_DEMON) || + (r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_STUPID) || + (r_ptr->flags & RF_NONLIVING) || (strchr("Evg", r_ptr->d_char))) { cmonster_msg(TERM_L_RED, "%^s is destroyed.", m_name); @@ -174,7 +175,7 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) } /* When an Unique dies, it stays dead */ - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { r_ptr->max_num = 0; } @@ -231,7 +232,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) /* Sometimes a monster gets scared by damage */ auto const r_ptr = m_ptr->race(); - if (!m_ptr->monfear && !(r_ptr->flags3 & RF3_NO_FEAR)) + if (!m_ptr->monfear && !(r_ptr->flags & RF_NO_FEAR)) { int percentage; @@ -292,7 +293,7 @@ void mon_handle_fear(monster_type *m_ptr, int dam, bool_ *fear) static bool_ int_outof(std::shared_ptr r_ptr, int prob) { /* Non-Smart monsters are half as "smart" */ - if (!(r_ptr->flags2 & RF2_SMART)) prob = prob / 2; + if (!(r_ptr->flags & RF_SMART)) prob = prob / 2; /* Roll the dice */ return (rand_int(100) < prob); @@ -313,7 +314,7 @@ static void remove_bad_spells(int m_idx, monster_spell_flag_set *spells_p) /* Too stupid to know anything? */ auto const r_ptr = m_ptr->race(); - if (r_ptr->flags2 & RF2_STUPID) return; + if (r_ptr->flags & RF_STUPID) return; /* Must be cheating or learning */ @@ -712,7 +713,7 @@ static monster_spell const *choose_attack_spell(int m_idx, std::vectorrace(); - if (r_ptr->flags2 & RF2_STUPID) + if (r_ptr->flags & RF_STUPID) { /* Pick at random */ return spells[rand_int(spells.size())]; @@ -847,7 +848,7 @@ static void breath(int m_idx, int typ, int dam_hp, int rad) auto const r_ptr = m_ptr->race(); /* Determine the radius of the blast */ - if (rad < 1) rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2; + if (rad < 1) rad = (r_ptr->flags & RF_POWERFUL) ? 3 : 2; /* Target the player with a ball attack */ (void)project(m_idx, rad, p_ptr->py, p_ptr->px, dam_hp, typ, flg); @@ -867,7 +868,7 @@ static void monst_breath_monst(int m_idx, int y, int x, int typ, int dam_hp, int auto const r_ptr = m_ptr->race(); /* Determine the radius of the blast */ - if (rad < 1) rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2; + if (rad < 1) rad = (r_ptr->flags & RF_POWERFUL) ? 3 : 2; (void)project(m_idx, rad, y, x, dam_hp, typ, flg); } @@ -1043,7 +1044,7 @@ static bool_ monst_spell_monst(int m_idx) monster_spell_flag_set allowed_spells = r_ptr->spells; /* Hack -- allow "desperate" spells */ - if ((r_ptr->flags2 & RF2_SMART) && + if ((r_ptr->flags & RF_SMART) && (m_ptr->hp < m_ptr->maxhp / 10) && (rand_int(100) < 50)) { @@ -1626,8 +1627,8 @@ static bool_ monst_spell_monst(int m_idx) } /* Attempt a saving throw */ - if ((tr_ptr->flags1 & RF1_UNIQUE) || - (tr_ptr->flags3 & RF3_NO_CONF) || + if ((tr_ptr->flags & RF_UNIQUE) || + (tr_ptr->flags & RF_NO_CONF) || (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) { /* No obvious effect */ @@ -1663,8 +1664,8 @@ static bool_ monst_spell_monst(int m_idx) } /* Attempt a saving throw */ - if ((tr_ptr->flags1 & RF1_UNIQUE) || - (tr_ptr->flags3 & RF3_NO_CONF) || + if ((tr_ptr->flags & RF_UNIQUE) || + (tr_ptr->flags & RF_NO_CONF) || (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10)) { /* No obvious effect */ @@ -1878,7 +1879,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles, and you hear scary noises.", m_name); else monster_msg("%^s casts a fearful illusion at %s.", m_name, t_name); - if (tr_ptr->flags3 & RF3_NO_FEAR) + if (tr_ptr->flags & RF_NO_FEAR) { if (see_t) monster_msg("%^s refuses to be frightened.", t_name); } @@ -1902,7 +1903,7 @@ static bool_ monst_spell_monst(int m_idx) if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a spell, burning %s%s eyes.", m_name, t_name, (!strcmp(t_name, "it") ? "s" : "'s")); - if (tr_ptr->flags3 & RF3_NO_CONF) /* Simulate blindness with confusion */ + if (tr_ptr->flags & RF_NO_CONF) /* Simulate blindness with confusion */ { if (see_t) monster_msg("%^s is unaffected.", t_name); } @@ -1926,7 +1927,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (blind || !see_m) monster_msg("%^s mumbles, and you hear puzzling noises.", m_name); else monster_msg("%^s creates a mesmerising illusion in front of %s.", m_name, t_name); - if (tr_ptr->flags3 & RF3_NO_CONF) + if (tr_ptr->flags & RF_NO_CONF) { if (see_t) monster_msg("%^s disbelieves the feeble spell.", t_name); } @@ -1949,7 +1950,7 @@ static bool_ monst_spell_monst(int m_idx) if (disturb_other) disturb(1); if (!blind && see_either) monster_msg("%^s drains power from %s%s muscles.", m_name, t_name, (!strcmp(t_name, "it") ? "s" : "'s")); - if (tr_ptr->flags1 & RF1_UNIQUE) + if (tr_ptr->flags & RF_UNIQUE) { if (see_t) monster_msg("%^s is unaffected.", t_name); } @@ -1971,8 +1972,8 @@ static bool_ monst_spell_monst(int m_idx) if (!direct) break; if (disturb_other) disturb(1); if (!blind && see_m) monster_msg("%^s stares intently at %s.", m_name, t_name); - if ((tr_ptr->flags1 & RF1_UNIQUE) || - (tr_ptr->flags3 & RF3_NO_STUN)) + if ((tr_ptr->flags & RF_UNIQUE) || + (tr_ptr->flags & RF_NO_STUN)) { if (see_t) monster_msg("%^s is unaffected.", t_name); } @@ -2026,7 +2027,7 @@ static bool_ monst_spell_monst(int m_idx) else if (!blind) monster_msg("%^s invokes the Hand of Doom on %s.", m_name, t_name); else monster_msg ("You hear someone invoke the Hand of Doom!"); - if (tr_ptr->flags1 & RF1_UNIQUE) + if (tr_ptr->flags & RF_UNIQUE) { if (!blind && see_t) monster_msg("^%s is unaffected!", t_name); } @@ -2167,9 +2168,9 @@ static bool_ monst_spell_monst(int m_idx) monster_msg("%^s teleports %s away.", m_name, t_name); - if (tr_ptr->flags3 & RF3_RES_TELE) + if (tr_ptr->flags & RF_RES_TELE) { - if (tr_ptr->flags1 & RF1_UNIQUE) + if (tr_ptr->flags & RF_UNIQUE) { if (see_t) { @@ -2282,7 +2283,7 @@ static bool_ monst_spell_monst(int m_idx) if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s magically summons %s %s.", m_name, m_poss, - ((r_ptr->flags1) & RF1_UNIQUE ? + ((r_ptr->flags) & RF_UNIQUE ? "minions" : "kin")); summon_kin_type = r_ptr->d_char; /* Big hack */ for (int k = 0; k < 6; k++) @@ -2773,7 +2774,7 @@ static bool_ make_attack_spell(int m_idx) /* Cannot attack the player if mortal and player fated to never die by the ... */ auto const r_ptr = m_ptr->race(); - if ((r_ptr->flags7 & RF7_MORTAL) && (p_ptr->no_mortal)) return (FALSE); + if ((r_ptr->flags & RF_MORTAL) && (p_ptr->no_mortal)) return (FALSE); /* Hack -- Extract the spell probability */ chance = (r_ptr->freq_inate + r_ptr->freq_spell) / 2; @@ -2810,7 +2811,7 @@ static bool_ make_attack_spell(int m_idx) } /* Hack -- allow "desperate" spells */ - if ((r_ptr->flags2 & RF2_SMART) && + if ((r_ptr->flags & RF_SMART) && (m_ptr->hp < m_ptr->maxhp / 10) && (rand_int(100) < 50)) { @@ -2829,7 +2830,7 @@ static bool_ make_attack_spell(int m_idx) /* Check for a clean bolt shot */ if ((allowed_spells & SF_BOLT_MASK) && - !(r_ptr->flags2 & RF2_STUPID) && + !(r_ptr->flags & RF_STUPID) && !clean_shot(m_ptr->fy, m_ptr->fx, y, x)) { /* Remove spells that will only hurt friends */ @@ -2838,7 +2839,7 @@ static bool_ make_attack_spell(int m_idx) /* Check for a possible summon */ if ((allowed_spells & SF_SUMMON_MASK) && - !(r_ptr->flags2 & RF2_STUPID) && + !(r_ptr->flags & RF_STUPID) && !(summon_possible(y, x))) { /* Remove summoning spells */ @@ -2873,7 +2874,7 @@ static bool_ make_attack_spell(int m_idx) failrate = 25 - (rlev + 3) / 4; /* Hack -- Stupid monsters will never fail (for jellies and such) */ - if (r_ptr->flags2 & RF2_STUPID) failrate = 0; + if (r_ptr->flags & RF_STUPID) failrate = 0; /* Check for spell failure (inate attacks never fail) */ if ((!thrown_spell->is_innate) && (rand_int(100) < failrate)) @@ -4017,7 +4018,7 @@ static bool_ make_attack_spell(int m_idx) if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s magically summons %s %s.", m_name, m_poss, - ((r_ptr->flags1) & RF1_UNIQUE ? + ((r_ptr->flags) & RF_UNIQUE ? "minions" : "kin")); summon_kin_type = r_ptr->d_char; /* Big hack */ @@ -4645,7 +4646,7 @@ static void get_target_monster(int m_idx) if (m_idx == i) continue; /* Cannot be targeted */ - if (rt_ptr->flags7 & RF7_NO_TARGET) continue; + if (rt_ptr->flags & RF_NO_TARGET) continue; if (is_enemy(m_ptr, t_ptr) && (los(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx) && ((dd = distance(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) < d))) @@ -4705,13 +4706,13 @@ static bool_ get_moves(int m_idx, int *mm) const auto r_ptr = m_ptr->race(); /* A possessor is not interrested in the player, it only wants a corpse */ - if (r_ptr->flags7 & RF7_POSSESSOR) + if (r_ptr->flags & RF_POSSESSOR) { find_corpse(m_ptr, &y2, &x2); } /* Let quests redefine AI */ - if (r_ptr->flags7 & RF7_AI_SPECIAL) + if (r_ptr->flags & RF_AI_SPECIAL) { struct hook_monster_ai_in in = { m_idx, &m_list[m_idx] }; struct hook_monster_ai_out out = { 0, 0 }; @@ -4724,7 +4725,7 @@ static bool_ get_moves(int m_idx, int *mm) if (m_idx == p_ptr->control) { - if ((r_ptr->flags7 & RF7_AI_PLAYER) || magik(85)) + if ((r_ptr->flags & RF_AI_PLAYER) || magik(85)) { if (distance(p_ptr->py, p_ptr->px, m_ptr->fy, m_ptr->fx) < 50) { @@ -4739,7 +4740,7 @@ static bool_ get_moves(int m_idx, int *mm) int x = m_ptr->fx - x2; /* Tease the player */ - if (r_ptr->flags7 & RF7_AI_ANNOY) + if (r_ptr->flags & RF_AI_ANNOY) { if (distance(m_ptr->fy, m_ptr->fx, y2, x2) < 4) { @@ -4749,7 +4750,7 @@ static bool_ get_moves(int m_idx, int *mm) } /* Death orbs .. */ - if (r_ptr->flags2 & RF2_DEATH_ORB) + if (r_ptr->flags & RF_DEATH_ORB) { if (!los(m_ptr->fy, m_ptr->fx, y2, x2)) { @@ -4765,10 +4766,10 @@ static bool_ get_moves(int m_idx, int *mm) * Animal packs try to get the player out of corridors * (...unless they can move through walls -- TY) */ - if ((r_ptr->flags1 & RF1_FRIENDS) && - (r_ptr->flags3 & RF3_ANIMAL) && - !((r_ptr->flags2 & RF2_PASS_WALL) || - (r_ptr->flags2 & RF2_KILL_WALL))) + if ((r_ptr->flags & RF_FRIENDS) && + (r_ptr->flags & RF_ANIMAL) && + !((r_ptr->flags & RF_PASS_WALL) || + (r_ptr->flags & RF_KILL_WALL))) { int i, room = 0; @@ -4792,7 +4793,7 @@ static bool_ get_moves(int m_idx, int *mm) } /* Monster groups try to surround the player */ - if (!done && (r_ptr->flags1 & RF1_FRIENDS)) + if (!done && (r_ptr->flags & RF_FRIENDS)) { int i; @@ -5075,7 +5076,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) const auto tr_ptr = t_ptr->race(); /* Not allowed to attack */ - if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE; + if (r_ptr->flags & RF_NEVER_BLOW) return FALSE; /* Total armor */ const int ac = t_ptr->ac; @@ -5487,8 +5488,8 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) if (touched) { /* Aura fire */ - if ((tr_ptr->flags2 & RF2_AURA_FIRE) && - !(r_ptr->flags3 & RF3_IM_FIRE)) + if ((tr_ptr->flags & RF_AURA_FIRE) && + !(r_ptr->flags & RF_IM_FIRE)) { if (m_ptr->ml || t_ptr->ml) { @@ -5502,7 +5503,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) } /* Aura elec */ - if ((tr_ptr->flags2 & RF2_AURA_ELEC) && !(r_ptr->flags3 & RF3_IM_ELEC)) + if ((tr_ptr->flags & RF_AURA_ELEC) && !(r_ptr->flags & RF_IM_ELEC)) { if (m_ptr->ml || t_ptr->ml) { @@ -5594,27 +5595,27 @@ static bool_ player_invis(monster_type * m_ptr) s16b inv = p_ptr->invis; s16b mlv = m_ptr->level; - if (r_ptr->flags3 & RF3_NO_SLEEP) + if (r_ptr->flags & RF_NO_SLEEP) mlv += 10; - if (r_ptr->flags3 & RF3_DRAGON) + if (r_ptr->flags & RF_DRAGON) mlv += 20; - if (r_ptr->flags3 & RF3_UNDEAD) + if (r_ptr->flags & RF_UNDEAD) mlv += 15; - if (r_ptr->flags3 & RF3_DEMON) + if (r_ptr->flags & RF_DEMON) mlv += 15; - if (r_ptr->flags3 & RF3_ANIMAL) + if (r_ptr->flags & RF_ANIMAL) mlv += 15; - if (r_ptr->flags3 & RF3_ORC) + if (r_ptr->flags & RF_ORC) mlv -= 15; - if (r_ptr->flags3 & RF3_TROLL) + if (r_ptr->flags & RF_TROLL) mlv -= 10; - if (r_ptr->flags2 & RF2_STUPID) + if (r_ptr->flags & RF_STUPID) mlv /= 2; - if (r_ptr->flags2 & RF2_SMART) + if (r_ptr->flags & RF_SMART) mlv = (mlv * 5) / 4; if (m_ptr->mflag & MFLAG_QUEST) inv = 0; - if (r_ptr->flags2 & RF2_INVISIBLE) + if (r_ptr->flags & RF_INVISIBLE) inv = 0; if (m_ptr->mflag & MFLAG_CONTROL) inv = 0; @@ -5659,7 +5660,7 @@ static void process_monster(int m_idx, bool_ is_frien) const bool_ inv = player_invis(m_ptr); auto const r_ptr = m_ptr->race(); - if (r_ptr->flags9 & RF9_DOPPLEGANGER) doppleganger = m_idx; + if (r_ptr->flags & RF_DOPPLEGANGER) doppleganger = m_idx; /* Handle "bleeding" */ if (m_ptr->bleeding) @@ -5872,12 +5873,12 @@ static void process_monster(int m_idx, bool_ is_frien) bool_ gets_angry = FALSE; /* No one wants to be your friend if you're aggravating */ - if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && (p_ptr->aggravate) && !(r_ptr->flags7 & RF7_PET)) + if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && (p_ptr->aggravate) && !(r_ptr->flags & RF_PET)) gets_angry = TRUE; /* Paranoia... no friendly uniques outside wizard mode -- TY */ if ((m_ptr->status > MSTATUS_NEUTRAL) && (m_ptr->status < MSTATUS_COMPANION) && !(wizard) && - (r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_PET)) + (r_ptr->flags & RF_UNIQUE) && !(r_ptr->flags & RF_PET)) gets_angry = TRUE; if (gets_angry) @@ -5940,7 +5941,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (randint(SPEAK_CHANCE) == 1) { - if (player_has_los_bold(oy, ox) && (r_ptr->flags2 & RF2_CAN_SPEAK)) + if (player_has_los_bold(oy, ox) && (r_ptr->flags & RF_CAN_SPEAK)) { char m_name[80]; char monmessage[1024]; @@ -6007,8 +6008,8 @@ static void process_monster(int m_idx, bool_ is_frien) } /* 75% random movement */ - else if ((r_ptr->flags1 & (RF1_RAND_50)) && - (r_ptr->flags1 & (RF1_RAND_25)) && + else if ((r_ptr->flags & RF_RAND_50) && + (r_ptr->flags & RF_RAND_25) && (rand_int(100) < 75)) { /* Try four "random" directions */ @@ -6016,7 +6017,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* 50% random movement */ - else if ((r_ptr->flags1 & (RF1_RAND_50)) && + else if ((r_ptr->flags & RF_RAND_50) && (rand_int(100) < 50)) { /* Try four "random" directions */ @@ -6024,7 +6025,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* 25% random movement */ - else if ((r_ptr->flags1 & (RF1_RAND_25)) && + else if ((r_ptr->flags & RF_RAND_25) && (rand_int(100) < 25)) { /* Try four "random" directions */ @@ -6087,7 +6088,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Hack -- check for Glyph of Warding */ if ((c_ptr->feat == FEAT_GLYPH) && - !(r_ptr->flags1 & RF1_NEVER_BLOW)) + !(r_ptr->flags & RF_NEVER_BLOW)) { /* Assume no move allowed */ do_move = FALSE; @@ -6113,7 +6114,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Hack -- trees are obstacle */ - else if ((cave[ny][nx].feat == FEAT_TREES) && (r_ptr->flags9 & RF9_KILL_TREES)) + else if ((cave[ny][nx].feat == FEAT_TREES) && (r_ptr->flags & RF_KILL_TREES)) { do_move = TRUE; @@ -6144,28 +6145,28 @@ static void process_monster(int m_idx, bool_ is_frien) /* Some monsters can fly */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_LEVITATE) && (r_ptr->flags7 & RF7_CAN_FLY)) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_LEVITATE) && (r_ptr->flags & RF_CAN_FLY)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Some monsters can fly */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_FLY) && (r_ptr->flags7 & RF7_CAN_FLY)) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_FLY) && (r_ptr->flags & RF_CAN_FLY)) { /* Pass through trees/... */ do_move = TRUE; } /* Monster moves through walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & RF2_PASS_WALL)) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags & RF_PASS_WALL)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Monster destroys walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & RF2_KILL_WALL)) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags & RF_KILL_WALL)) { /* Eat through walls/doors/rubble */ do_move = TRUE; @@ -6186,7 +6187,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Monster moves through walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags2 & RF2_PASS_WALL)) + else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags & RF_PASS_WALL)) { /* Pass through walls/doors/rubble */ do_move = TRUE; @@ -6194,7 +6195,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Monster moves through webs */ else if ((f_info[c_ptr->feat].flags1 & FF1_WEB) && - (r_ptr->flags7 & RF7_SPIDER)) + (r_ptr->flags & RF_SPIDER)) { /* Pass through webs */ do_move = TRUE; @@ -6210,7 +6211,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Take a turn */ do_turn = TRUE; - if ((r_ptr->flags2 & RF2_OPEN_DOOR) && + if ((r_ptr->flags & RF_OPEN_DOOR) && ((is_friend(m_ptr) <= 0) || p_ptr->pet_open_doors)) { /* Closed doors and secret doors */ @@ -6245,7 +6246,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Stuck doors -- attempt to bash them down if allowed */ - if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && + if (may_bash && (r_ptr->flags & RF_BASH_DOOR) && ((is_friend(m_ptr) <= 0) || p_ptr->pet_open_doors)) { int k; @@ -6294,7 +6295,7 @@ static void process_monster(int m_idx, bool_ is_frien) } } else if (do_move && (c_ptr->feat == FEAT_MINOR_GLYPH) - && !(r_ptr->flags1 & RF1_NEVER_BLOW)) + && !(r_ptr->flags & RF_NEVER_BLOW)) { /* Assume no move allowed */ do_move = FALSE; @@ -6339,7 +6340,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Access that cave grid's contents */ y_ptr = &m_list[c_ptr->m_idx]; - if (!(r_ptr->flags3 & RF3_IM_COLD)) + if (!(r_ptr->flags & RF_IM_COLD)) { if ((m_ptr->hp - distance(ny, nx, oy, ox)*2) <= 0) { @@ -6379,7 +6380,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Some monsters never attack */ if (do_move && (ny == p_ptr->py) && (nx == p_ptr->px) && - (r_ptr->flags1 & RF1_NEVER_BLOW)) + (r_ptr->flags & RF_NEVER_BLOW)) { /* Do not move */ do_move = FALSE; @@ -6416,12 +6417,12 @@ static void process_monster(int m_idx, bool_ is_frien) do_move = FALSE; /* Kill weaker monsters */ - if ((r_ptr->flags2 & RF2_KILL_BODY) && + if ((r_ptr->flags & RF_KILL_BODY) && (r_ptr->mexp > z_ptr->mexp) && (cave_floor_bold(ny, nx)) && /* Friends don't kill friends... */ !((is_friend(m_ptr) > 0) && (is_friend(m2_ptr) > 0)) && /* Uniques aren't faceless monsters in a crowd */ - !(z_ptr->flags1 & RF1_UNIQUE) && + !(z_ptr->flags & RF_UNIQUE) && /* Don't wreck quests */ !(m2_ptr->mflag & (MFLAG_QUEST | MFLAG_QUEST2)) && /* Don't punish summoners for relying on their friends */ @@ -6455,7 +6456,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Push past weaker monsters (unless leaving a wall) */ - else if ((r_ptr->flags2 & RF2_MOVE_BODY) && + else if ((r_ptr->flags & RF_MOVE_BODY) && (r_ptr->mexp > z_ptr->mexp) && cave_floor_bold(ny, nx) && (cave_floor_bold(m_ptr->fy, m_ptr->fx))) { @@ -6477,11 +6478,8 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Some monsters never move */ - if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE)) + if (do_move && (r_ptr->flags & RF_NEVER_MOVE)) { - /* Hack -- memorize lack of attacks */ - /* if (m_ptr->ml) r_ptr->r_flags1 |= RF1_NEVER_MOVE; */ - /* Do not move */ do_move = FALSE; } @@ -6573,7 +6571,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (o_ptr->tval == TV_GOLD) continue; /* Incarnate ? */ - if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags7 & RF7_POSSESSOR) && + if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags & RF_POSSESSOR) && ((o_ptr->sval == SV_CORPSE_CORPSE) || (o_ptr->sval == SV_CORPSE_SKELETON))) { if (ai_possessor(m_idx, this_o_idx)) return; @@ -6581,15 +6579,13 @@ static void process_monster(int m_idx, bool_ is_frien) /* Take or Kill objects on the floor */ /* rr9: Pets will no longer pick up/destroy items */ - if ((((r_ptr->flags2 & RF2_TAKE_ITEM) && + if ((((r_ptr->flags & RF_TAKE_ITEM) && ((is_friend(m_ptr) <= 0) || p_ptr->pet_pickup_items)) || - (r_ptr->flags2 & RF2_KILL_ITEM)) && + (r_ptr->flags & RF_KILL_ITEM)) && (is_friend(m_ptr) <= 0)) { u32b f1, f2, f3, f4, f5, esp; - u32b flg3 = 0L; - char m_name[80]; char o_name[80]; @@ -6603,23 +6599,24 @@ static void process_monster(int m_idx, bool_ is_frien) monster_desc(m_name, m_ptr, 0x04); /* React to objects that hurt the monster */ - if (f5 & (TR5_KILL_DEMON)) flg3 |= RF3_DEMON; - if (f5 & (TR5_KILL_UNDEAD)) flg3 |= RF3_UNDEAD; - if (f1 & (TR1_SLAY_DRAGON)) flg3 |= RF3_DRAGON; - if (f1 & (TR1_SLAY_TROLL)) flg3 |= RF3_TROLL; - if (f1 & (TR1_SLAY_GIANT)) flg3 |= RF3_GIANT; - if (f1 & (TR1_SLAY_ORC)) flg3 |= RF3_ORC; - if (f1 & (TR1_SLAY_DEMON)) flg3 |= RF3_DEMON; - if (f1 & (TR1_SLAY_UNDEAD)) flg3 |= RF3_UNDEAD; - if (f1 & (TR1_SLAY_ANIMAL)) flg3 |= RF3_ANIMAL; - if (f1 & (TR1_SLAY_EVIL)) flg3 |= RF3_EVIL; + monster_race_flag_set flg; + if (f5 & (TR5_KILL_DEMON)) flg |= RF_DEMON; + if (f5 & (TR5_KILL_UNDEAD)) flg |= RF_UNDEAD; + if (f1 & (TR1_SLAY_DRAGON)) flg |= RF_DRAGON; + if (f1 & (TR1_SLAY_TROLL)) flg |= RF_TROLL; + if (f1 & (TR1_SLAY_GIANT)) flg |= RF_GIANT; + if (f1 & (TR1_SLAY_ORC)) flg |= RF_ORC; + if (f1 & (TR1_SLAY_DEMON)) flg |= RF_DEMON; + if (f1 & (TR1_SLAY_UNDEAD)) flg |= RF_UNDEAD; + if (f1 & (TR1_SLAY_ANIMAL)) flg |= RF_ANIMAL; + if (f1 & (TR1_SLAY_EVIL)) flg |= RF_EVIL; /* The object cannot be picked up by the monster */ - if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || + if (artifact_p(o_ptr) || (r_ptr->flags & flg) || (o_ptr->art_name)) { /* Only give a message for "take_item" */ - if (r_ptr->flags2 & RF2_TAKE_ITEM) + if (r_ptr->flags & RF_TAKE_ITEM) { /* Describe observable situations */ if (m_ptr->ml && player_has_los_bold(ny, nx)) @@ -6632,7 +6629,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Pick up the item */ - else if (r_ptr->flags2 & RF2_TAKE_ITEM) + else if (r_ptr->flags & RF_TAKE_ITEM) { /* Describe observable situations */ if (player_has_los_bold(ny, nx)) @@ -6678,7 +6675,7 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Update monster light */ - if (r_ptr->flags9 & RF9_HAS_LITE) p_ptr->update |= (PU_MON_LITE); + if (r_ptr->flags & RF_HAS_LITE) p_ptr->update |= (PU_MON_LITE); } /* Stop when done */ @@ -6810,7 +6807,7 @@ void process_monsters(void) monster_type *m_ptr; /* Check the doppleganger */ - if (doppleganger && !(r_info[m_list[doppleganger].r_idx].flags9 & RF9_DOPPLEGANGER)) + if (doppleganger && !(r_info[m_list[doppleganger].r_idx].flags & RF_DOPPLEGANGER)) doppleganger = 0; /* Hack -- calculate the "player noise" */ -- cgit v1.2.3 From 073ad3584fbf781ce10bef61ad4ff38850282f47 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 13:37:02 +0200 Subject: Rework TR{1,2,3,4,5}_* flags to flag_set<> --- src/melee2.cc | 62 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 9d09fb67..f52c7061 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -34,6 +34,7 @@ #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "options.hpp" #include "player_type.hpp" #include "quark.hpp" @@ -2571,7 +2572,6 @@ static bool_ monst_spell_monst(int m_idx) void curse_equipment(int chance, int heavy_chance) { bool_ changed = FALSE; - u32b o1, o2, o3, o4, esp, o5; object_type * o_ptr = &p_ptr->inventory[rand_range(INVEN_WIELD, INVEN_TOTAL - 1)]; @@ -2579,11 +2579,11 @@ void curse_equipment(int chance, int heavy_chance) if (!(o_ptr->k_idx)) return; - object_flags(o_ptr, &o1, &o2, &o3, &o4, &o5, &esp); + auto const flags = object_flags(o_ptr); /* Extra, biased saving throw for blessed items */ - if ((o3 & (TR3_BLESSED)) && (randint(888) > chance)) + if ((flags & TR_BLESSED) && (randint(888) > chance)) { char o_name[256]; object_desc(o_name, o_ptr, FALSE, 0); @@ -2596,17 +2596,17 @@ void curse_equipment(int chance, int heavy_chance) if ((randint(100) <= heavy_chance) && (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name)) { - if (!(o3 & TR3_HEAVY_CURSE)) + if (!(flags & TR_HEAVY_CURSE)) changed = TRUE; - o_ptr->art_flags3 |= TR3_HEAVY_CURSE; - o_ptr->art_flags3 |= TR3_CURSED; + o_ptr->art_flags |= TR_HEAVY_CURSE; + o_ptr->art_flags |= TR_CURSED; o_ptr->ident |= IDENT_CURSED; } else { - if (!(o_ptr->ident & (IDENT_CURSED))) + if (!(o_ptr->ident & IDENT_CURSED)) changed = TRUE; - o_ptr->art_flags3 |= TR3_CURSED; + o_ptr->art_flags |= TR_CURSED; o_ptr->ident |= IDENT_CURSED; } @@ -2627,7 +2627,7 @@ void curse_equipment(int chance, int heavy_chance) void curse_equipment_dg(int chance, int heavy_chance) { bool_ changed = FALSE; - u32b o1, o2, o3, o4, esp, o5; + object_type * o_ptr = &p_ptr->inventory[rand_range(INVEN_WIELD, INVEN_TOTAL - 1)]; @@ -2635,37 +2635,35 @@ void curse_equipment_dg(int chance, int heavy_chance) if (!(o_ptr->k_idx)) return; - object_flags(o_ptr, &o1, &o2, &o3, &o4, &o5, &esp); + auto const flags = object_flags(o_ptr); /* Extra, biased saving throw for blessed items */ - if ((o3 & (TR3_BLESSED)) && (randint(888) > chance)) + if ((flags & TR_BLESSED) && (randint(888) > chance)) { char o_name[256]; object_desc(o_name, o_ptr, FALSE, 0); msg_format("Your %s resist%s cursing!", o_name, ((o_ptr->number > 1) ? "" : "s")); - /* Hmmm -- can we wear multiple items? If not, this is unnecessary */ - /* DG -- Yes we can, in the quiver */ return; } if ((randint(100) <= heavy_chance) && (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name)) { - if (!(o3 & TR3_HEAVY_CURSE)) + if (!(flags & TR_HEAVY_CURSE)) changed = TRUE; - o_ptr->art_flags3 |= TR3_HEAVY_CURSE; - o_ptr->art_flags3 |= TR3_CURSED; - o_ptr->art_flags4 |= TR4_DG_CURSE; + o_ptr->art_flags |= TR_HEAVY_CURSE; + o_ptr->art_flags |= TR_CURSED; + o_ptr->art_flags |= TR_DG_CURSE; o_ptr->ident |= IDENT_CURSED; } else { - if (!(o_ptr->ident & (IDENT_CURSED))) + if (!(o_ptr->ident & IDENT_CURSED)) changed = TRUE; - o_ptr->art_flags3 |= TR3_CURSED; - o_ptr->art_flags4 |= TR4_DG_CURSE; + o_ptr->art_flags |= TR_CURSED; + o_ptr->art_flags |= TR_DG_CURSE; o_ptr->ident |= IDENT_CURSED; } @@ -6584,13 +6582,11 @@ static void process_monster(int m_idx, bool_ is_frien) (r_ptr->flags & RF_KILL_ITEM)) && (is_friend(m_ptr) <= 0)) { - u32b f1, f2, f3, f4, f5, esp; - char m_name[80]; char o_name[80]; /* Extract some flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Acquire the object name */ object_desc(o_name, o_ptr, TRUE, 3); @@ -6600,16 +6596,16 @@ static void process_monster(int m_idx, bool_ is_frien) /* React to objects that hurt the monster */ monster_race_flag_set flg; - if (f5 & (TR5_KILL_DEMON)) flg |= RF_DEMON; - if (f5 & (TR5_KILL_UNDEAD)) flg |= RF_UNDEAD; - if (f1 & (TR1_SLAY_DRAGON)) flg |= RF_DRAGON; - if (f1 & (TR1_SLAY_TROLL)) flg |= RF_TROLL; - if (f1 & (TR1_SLAY_GIANT)) flg |= RF_GIANT; - if (f1 & (TR1_SLAY_ORC)) flg |= RF_ORC; - if (f1 & (TR1_SLAY_DEMON)) flg |= RF_DEMON; - if (f1 & (TR1_SLAY_UNDEAD)) flg |= RF_UNDEAD; - if (f1 & (TR1_SLAY_ANIMAL)) flg |= RF_ANIMAL; - if (f1 & (TR1_SLAY_EVIL)) flg |= RF_EVIL; + if (flags & TR_KILL_DEMON) flg |= RF_DEMON; + if (flags & TR_KILL_UNDEAD) flg |= RF_UNDEAD; + if (flags & TR_SLAY_DRAGON) flg |= RF_DRAGON; + if (flags & TR_SLAY_TROLL) flg |= RF_TROLL; + if (flags & TR_SLAY_GIANT) flg |= RF_GIANT; + if (flags & TR_SLAY_ORC) flg |= RF_ORC; + if (flags & TR_SLAY_DEMON) flg |= RF_DEMON; + if (flags & TR_SLAY_UNDEAD) flg |= RF_UNDEAD; + if (flags & TR_SLAY_ANIMAL) flg |= RF_ANIMAL; + if (flags & TR_SLAY_EVIL) flg |= RF_EVIL; /* The object cannot be picked up by the monster */ if (artifact_p(o_ptr) || (r_ptr->flags & flg) || -- cgit v1.2.3 From 3966bfb2f6836d13c1a93bfab1e9fa61ec4fff35 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 21:17:20 +0200 Subject: Rework FF1_* flags to flags_set<> --- src/melee2.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index f52c7061..a0f43492 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -17,6 +17,7 @@ #include "cave_type.hpp" #include "cmd1.hpp" #include "dungeon_flag.hpp" +#include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" #include "hook_mon_speak_in.hpp" @@ -6136,35 +6137,35 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Permanent wall */ - else if (f_info[c_ptr->feat].flags1 & FF1_PERMANENT) + else if (f_info[c_ptr->feat].flags & FF_PERMANENT) { /* Nothing */ } /* Some monsters can fly */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_LEVITATE) && (r_ptr->flags & RF_CAN_FLY)) + else if ((f_info[c_ptr->feat].flags & FF_CAN_LEVITATE) && (r_ptr->flags & RF_CAN_FLY)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Some monsters can fly */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_FLY) && (r_ptr->flags & RF_CAN_FLY)) + else if ((f_info[c_ptr->feat].flags & FF_CAN_FLY) && (r_ptr->flags & RF_CAN_FLY)) { /* Pass through trees/... */ do_move = TRUE; } /* Monster moves through walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags & RF_PASS_WALL)) + else if ((f_info[c_ptr->feat].flags & FF_CAN_PASS) && (r_ptr->flags & RF_PASS_WALL)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Monster destroys walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags & RF_KILL_WALL)) + else if ((f_info[c_ptr->feat].flags & FF_CAN_PASS) && (r_ptr->flags & RF_KILL_WALL)) { /* Eat through walls/doors/rubble */ do_move = TRUE; @@ -6185,14 +6186,14 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Monster moves through walls (and doors) */ - else if ((f_info[c_ptr->feat].flags1 & FF1_CAN_PASS) && (r_ptr->flags & RF_PASS_WALL)) + else if ((f_info[c_ptr->feat].flags & FF_CAN_PASS) && (r_ptr->flags & RF_PASS_WALL)) { /* Pass through walls/doors/rubble */ do_move = TRUE; } /* Monster moves through webs */ - else if ((f_info[c_ptr->feat].flags1 & FF1_WEB) && + else if ((f_info[c_ptr->feat].flags & FF_WEB) && (r_ptr->flags & RF_SPIDER)) { /* Pass through webs */ -- cgit v1.2.3 From 5e42771bae33ca475447dc34610addad8efdb74f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove unused variable in make_attack_spell() --- src/melee2.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index a0f43492..6d025511 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2746,9 +2746,6 @@ static bool_ make_attack_spell(int m_idx) /* Extract the "see-able-ness" */ bool_ seen = (!blind && m_ptr->ml); - /* Assume "normal" target */ - bool_ normal = TRUE; - /* Target location */ if (m_ptr->target > -1) { @@ -2787,8 +2784,7 @@ static bool_ make_attack_spell(int m_idx) /* Sometimes forbid inate attacks (breaths) */ if (rand_int(100) >= (chance * 2)) no_inate = TRUE; - /* Hack -- require projectable player */ - if (normal) + /* Require projectable player */ { /* Check range */ if (m_ptr->cdis > MAX_RANGE) return (FALSE); -- cgit v1.2.3 From ceb4551cfb0e3fd1bdf8bdb868e6758634486ecb Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove effectively dead sound() code --- src/melee2.cc | 43 ------------------------------------------- 1 file changed, 43 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 6d025511..1cebfb0b 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -98,20 +98,6 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) /* Extract monster name */ monster_desc(m_name, m_ptr, 0); - /* Make a sound */ - if ((r_ptr->flags & RF_DEMON) || - (r_ptr->flags & RF_UNDEAD) || - (r_ptr->flags & RF_STUPID) || - (r_ptr->flags & RF_NONLIVING) || - (strchr("Evg", r_ptr->d_char))) - { - sound(SOUND_N_KILL); - } - else - { - sound(SOUND_KILL); - } - /* Death by Missile/Spell attack */ if (note) { @@ -1147,7 +1133,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear a strange noise."); else if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires an arrow at %s.", m_name, t_name); - sound(SOUND_SHOOT); monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(1, 6)); break; } @@ -1158,7 +1143,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear a strange noise."); else if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires an arrow at %s.", m_name, t_name); - sound(SOUND_SHOOT); monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(3, 6)); break; } @@ -1170,7 +1154,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear a strange noise."); else if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires a missile at %s.", m_name, t_name); - sound(SOUND_SHOOT); monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(5, 6)); break; } @@ -1181,7 +1164,6 @@ static bool_ monst_spell_monst(int m_idx) else if (disturb_other) disturb(1); if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires a missile at %s.", m_name, t_name); - sound(SOUND_SHOOT); monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(7, 6)); break; } @@ -1192,7 +1174,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes acid at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_ACID, ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); break; @@ -1204,7 +1185,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes lightning at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_ELEC, ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); break; @@ -1216,7 +1196,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes fire at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_FIRE, ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); break; @@ -1228,7 +1207,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes frost at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_COLD, ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); break; @@ -1240,7 +1218,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes gas at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_POIS, ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); break; @@ -1252,7 +1229,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes nether at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_NETHER, ((m_ptr->hp / 6) > 550 ? 550 : (m_ptr->hp / 6)), 0); break; @@ -1264,7 +1240,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes light at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_LITE, ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); break; @@ -1276,7 +1251,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes darkness at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_DARK, ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); break; @@ -1288,7 +1262,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes confusion at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_CONFUSION, ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); break; @@ -1300,7 +1273,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes sound at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_SOUND, ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); break; @@ -1312,7 +1284,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes chaos at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_CHAOS, ((m_ptr->hp / 6) > 600 ? 600 : (m_ptr->hp / 6)), 0); break; @@ -1324,7 +1295,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes disenchantment at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_DISENCHANT, ((m_ptr->hp / 6) > 500 ? 500 : (m_ptr->hp / 6)), 0); break; @@ -1336,7 +1306,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes nexus at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_NEXUS, ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); break; @@ -1348,7 +1317,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes time at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_TIME, ((m_ptr->hp / 3) > 150 ? 150 : (m_ptr->hp / 3)), 0); break; @@ -1360,7 +1328,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes inertia at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_INERTIA, ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); break; @@ -1372,7 +1339,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes gravity at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_GRAVITY, ((m_ptr->hp / 3) > 200 ? 200 : (m_ptr->hp / 3)), 0); break; @@ -1384,7 +1350,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes shards at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_SHARDS, ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); break; @@ -1396,7 +1361,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes plasma at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_PLASMA, ((m_ptr->hp / 6) > 150 ? 150 : (m_ptr->hp / 6)), 0); break; @@ -1408,7 +1372,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes force at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_FORCE, ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); break; @@ -1420,7 +1383,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes magical energy at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_MANA, ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); break; @@ -1432,7 +1394,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a ball of radiation at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_NUKE, (rlev + damroll(10, 6)), 2); break; @@ -1444,7 +1405,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes toxic waste at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_NUKE, ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); break; @@ -1456,7 +1416,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear someone mumble frighteningly."); else if (blind) monster_msg("%^s mumbles frighteningly.", m_name); else monster_msg("%^s invokes a raw Chaos upon %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_CHAOS, (rlev * 2) + damroll(10, 10), 4); break; @@ -1468,7 +1427,6 @@ static bool_ monst_spell_monst(int m_idx) if (!see_either) monster_msg("You hear breathing noise."); else if (blind) monster_msg("%^s breathes.", m_name); else monster_msg("%^s breathes disintegration at %s.", m_name, t_name); - sound(SOUND_BREATH); monst_breath_monst(m_idx, y, x, GF_DISINTEGRATE, ((m_ptr->hp / 3) > 300 ? 300 : (m_ptr->hp / 3)), 0); break; @@ -5552,7 +5510,6 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) if (explode) { - sound(SOUND_EXPLODE); mon_take_hit_mon(m_idx, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds."); blinked = FALSE; -- cgit v1.2.3 From 993cc3d53b2f2ca85a1b035b185d7515d2da2a16 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove lots of boilerplate for monster breaths --- src/melee2.cc | 347 +++++++++++++++------------------------------------------- 1 file changed, 89 insertions(+), 258 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 1cebfb0b..c43b2aae 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -1082,6 +1082,31 @@ static bool_ monst_spell_monst(int m_idx) see_either = (see_m || see_t); see_both = (see_m && see_t); + /* Do a breath */ + auto do_breath = [&](char const *element, int gf, s32b max, int divisor) -> void { + // Interrupt + if (disturb_other) + { + disturb(1); + } + // Message + if (!see_either) + { + monster_msg("You hear breathing noise."); + } + else if (blind) + { + monster_msg("%^s breathes.", m_name); + } + else + { + monster_msg("%^s breathes %s at %s.", m_name, element, t_name); + } + // Breathe + monst_breath_monst(m_idx, y, x, gf, std::min(max, m_ptr->hp / divisor), 0); + }; + + /* Spell effect */ int count = 0; switch (thrown_spell->spell_idx) { @@ -1170,227 +1195,127 @@ static bool_ monst_spell_monst(int m_idx) case SF_BR_ACID_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes acid at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_ACID, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + do_breath("acid", GF_ACID, 1600, 3); break; } case SF_BR_ELEC_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes lightning at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_ELEC, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + do_breath("lightning", GF_ELEC, 1600, 3); break; } case SF_BR_FIRE_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes fire at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_FIRE, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + do_breath("fire", GF_FIRE, 1600, 3); break; } case SF_BR_COLD_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes frost at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_COLD, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); + do_breath("frost", GF_COLD, 1600, 3); break; } case SF_BR_POIS_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes gas at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_POIS, - ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); + do_breath("gas", GF_POIS, 800, 3); break; } case SF_BR_NETH_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes nether at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_NETHER, - ((m_ptr->hp / 6) > 550 ? 550 : (m_ptr->hp / 6)), 0); + do_breath("nether", GF_NETHER, 550, 6); break; } case SF_BR_LITE_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes light at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_LITE, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + do_breath("light", GF_LITE, 400, 6); break; } case SF_BR_DARK_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes darkness at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_DARK, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + do_breath("darkness", GF_DARK, 400, 6); break; } case SF_BR_CONF_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes confusion at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_CONFUSION, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + do_breath("confusion", GF_CONFUSION, 400, 6); break; } case SF_BR_SOUN_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes sound at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_SOUND, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + do_breath("sound", GF_SOUND, 400, 6); break; } case SF_BR_CHAO_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes chaos at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_CHAOS, - ((m_ptr->hp / 6) > 600 ? 600 : (m_ptr->hp / 6)), 0); + do_breath("chaos", GF_CHAOS, 600, 6); break; } case SF_BR_DISE_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes disenchantment at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_DISENCHANT, - ((m_ptr->hp / 6) > 500 ? 500 : (m_ptr->hp / 6)), 0); + do_breath("disenchantment", GF_DISENCHANT, 500, 6); break; } case SF_BR_NEXU_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes nexus at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_NEXUS, - ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + do_breath("nexus", GF_NEXUS, 250, 3); break; } case SF_BR_TIME_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes time at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_TIME, - ((m_ptr->hp / 3) > 150 ? 150 : (m_ptr->hp / 3)), 0); + do_breath("time", GF_TIME, 150, 3); break; } case SF_BR_INER_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes inertia at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_INERTIA, - ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + do_breath("inertia", GF_INERTIA, 200, 6); break; } case SF_BR_GRAV_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes gravity at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_GRAVITY, - ((m_ptr->hp / 3) > 200 ? 200 : (m_ptr->hp / 3)), 0); + do_breath("gravity", GF_GRAVITY, 200, 3); break; } case SF_BR_SHAR_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes shards at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_SHARDS, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); + do_breath("shards", GF_SHARDS, 400, 6); break; } case SF_BR_PLAS_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes plasma at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_PLASMA, - ((m_ptr->hp / 6) > 150 ? 150 : (m_ptr->hp / 6)), 0); + do_breath("plasma", GF_PLASMA, 150, 6); break; } case SF_BR_WALL_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes force at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_FORCE, - ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + do_breath("force", GF_FORCE, 200, 6); break; } case SF_BR_MANA_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes magical energy at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_MANA, - ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + do_breath("magical energy", GF_MANA, 250, 3); break; } case SF_BA_NUKE_IDX: { - if (disturb_other) disturb(1); + if (disturb_other) disturb(1); if (!see_either) monster_msg("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a ball of radiation at %s.", m_name, t_name); @@ -1401,12 +1326,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BR_NUKE_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes toxic waste at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_NUKE, - ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); + do_breath("toxic waste", GF_NUKE, 800, 3); break; } @@ -1423,12 +1343,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BR_DISI_IDX: { - if (disturb_other) disturb(1); - if (!see_either) monster_msg("You hear breathing noise."); - else if (blind) monster_msg("%^s breathes.", m_name); - else monster_msg("%^s breathes disintegration at %s.", m_name, t_name); - monst_breath_monst(m_idx, y, x, GF_DISINTEGRATE, - ((m_ptr->hp / 3) > 300 ? 300 : (m_ptr->hp / 3)), 0); + do_breath("disintegration", GF_DISINTEGRATE, 300, 3); break; } @@ -2859,6 +2774,25 @@ static bool_ make_attack_spell(int m_idx) /* Hack -- Get the "died from" name */ monster_desc(ddesc, m_ptr, 0x88); + /* Do a breath */ + auto do_breath = [&](char const *element, int gf, s32b max, int divisor, int smart_learn) -> void { + // Interrupt + disturb(1); + // Message + if (blind) + { + msg_format("%^s breathes.", m_name); + } + else + { + msg_format("%^s breathes %s.", m_name, element); + } + // Breathe + breath(m_idx, gf, std::min(m_ptr->hp / divisor, max), 0); + // Update "smart" monster knowledge + update_smart_learn(m_idx, smart_learn); + }; + /* Cast the spell. */ switch (thrown_spell->spell_idx) { @@ -2941,215 +2875,121 @@ static bool_ make_attack_spell(int m_idx) case SF_BR_ACID_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes acid.", m_name); - breath(m_idx, GF_ACID, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_ACID); + do_breath("acid", GF_ACID, 1600, 3, DRS_ACID); break; } case SF_BR_ELEC_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes lightning.", m_name); - breath(m_idx, GF_ELEC, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_ELEC); + do_breath("lightning", GF_ELEC, 1600, 3, DRS_ELEC); break; } case SF_BR_FIRE_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes fire.", m_name); - breath(m_idx, GF_FIRE, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_FIRE); + do_breath("fire", GF_FIRE, 1600, 3, DRS_FIRE); break; } case SF_BR_COLD_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes frost.", m_name); - breath(m_idx, GF_COLD, - ((m_ptr->hp / 3) > 1600 ? 1600 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_COLD); + do_breath("frost", GF_COLD, 1600, 3, DRS_COLD); break; } case SF_BR_POIS_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes gas.", m_name); - breath(m_idx, GF_POIS, - ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_POIS); + do_breath("gas", GF_POIS, 800, 3, DRS_POIS); break; } case SF_BR_NETH_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes nether.", m_name); - breath(m_idx, GF_NETHER, - ((m_ptr->hp / 6) > 550 ? 550 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_NETH); + do_breath("nether", GF_NETHER, 550, 6, DRS_NETH); break; } case SF_BR_LITE_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes light.", m_name); - breath(m_idx, GF_LITE, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_LITE); + do_breath("light", GF_LITE, 400, 6, DRS_LITE); break; } case SF_BR_DARK_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes darkness.", m_name); - breath(m_idx, GF_DARK, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_DARK); + do_breath("darkness", GF_DARK, 400, 6, DRS_DARK); break; } case SF_BR_CONF_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes confusion.", m_name); - breath(m_idx, GF_CONFUSION, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_CONF); + do_breath("confusion", GF_CONFUSION, 400, 6, DRS_CONF); break; } case SF_BR_SOUN_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes sound.", m_name); - breath(m_idx, GF_SOUND, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_SOUND); + do_breath("sound", GF_SOUND, 400, 6, DRS_SOUND); break; } case SF_BR_CHAO_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes chaos.", m_name); - breath(m_idx, GF_CHAOS, - ((m_ptr->hp / 6) > 600 ? 600 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_CHAOS); + do_breath("chaos", GF_CHAOS, 600, 6, DRS_CHAOS); break; } case SF_BR_DISE_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes disenchantment.", m_name); - breath(m_idx, GF_DISENCHANT, - ((m_ptr->hp / 6) > 500 ? 500 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_DISEN); + do_breath("disenchantment", GF_DISENCHANT, 500, 6, DRS_DISEN); break; } case SF_BR_NEXU_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes nexus.", m_name); - breath(m_idx, GF_NEXUS, - ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_NEXUS); + do_breath("nexus", GF_NEXUS, 250, 3, DRS_NEXUS); break; } case SF_BR_TIME_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes time.", m_name); - breath(m_idx, GF_TIME, - ((m_ptr->hp / 3) > 150 ? 150 : (m_ptr->hp / 3)), 0); + do_breath("time", GF_TIME, 150, 3, DRS_NONE); break; } case SF_BR_INER_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes inertia.", m_name); - breath(m_idx, GF_INERTIA, - ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + do_breath("inertia", GF_INERTIA, 200, 6, DRS_NONE); break; } case SF_BR_GRAV_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes gravity.", m_name); - breath(m_idx, GF_GRAVITY, - ((m_ptr->hp / 3) > 200 ? 200 : (m_ptr->hp / 3)), 0); + do_breath("gravity", GF_GRAVITY, 200, 3, DRS_NONE); break; } case SF_BR_SHAR_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes shards.", m_name); - breath(m_idx, GF_SHARDS, - ((m_ptr->hp / 6) > 400 ? 400 : (m_ptr->hp / 6)), 0); - update_smart_learn(m_idx, DRS_SHARD); + do_breath("shards", GF_SHARDS, 400, 6, DRS_SHARD); break; } case SF_BR_PLAS_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes plasma.", m_name); - breath(m_idx, GF_PLASMA, - ((m_ptr->hp / 6) > 150 ? 150 : (m_ptr->hp / 6)), 0); + do_breath("plasma", GF_PLASMA, 150, 6, DRS_NONE); break; } case SF_BR_WALL_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes force.", m_name); - breath(m_idx, GF_FORCE, - ((m_ptr->hp / 6) > 200 ? 200 : (m_ptr->hp / 6)), 0); + do_breath("force", GF_FORCE, 200, 6, DRS_NONE); break; } case SF_BR_MANA_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes magical energy.", m_name); - breath(m_idx, GF_MANA, - ((m_ptr->hp / 3) > 250 ? 250 : (m_ptr->hp / 3)), 0); + do_breath("magical energy", GF_MANA, 250, 3, DRS_NONE); break; } @@ -3165,12 +3005,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BR_NUKE_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes toxic waste.", m_name); - breath(m_idx, GF_NUKE, - ((m_ptr->hp / 3) > 800 ? 800 : (m_ptr->hp / 3)), 0); - update_smart_learn(m_idx, DRS_POIS); + do_breath("toxic waste", GF_NUKE, 800, 3, DRS_POIS); break; } @@ -3186,11 +3021,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BR_DISI_IDX: { - disturb(1); - if (blind) msg_format("%^s breathes.", m_name); - else msg_format("%^s breathes disintegration.", m_name); - breath(m_idx, GF_DISINTEGRATE, - ((m_ptr->hp / 3) > 300 ? 300 : (m_ptr->hp / 3)), 0); + do_breath("disintegration", GF_DISINTEGRATE, 300, 3, DRS_NONE); break; } -- cgit v1.2.3 From 0d6002ae3c1f2b4fc043bf5ff8cad1e918af7c80 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove lots of boilerplate for monster summoning --- src/melee2.cc | 728 ++++++++++++++++++++++------------------------------------ 1 file changed, 276 insertions(+), 452 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index c43b2aae..419282c6 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -1106,9 +1106,76 @@ static bool_ monst_spell_monst(int m_idx) monst_breath_monst(m_idx, y, x, gf, std::min(max, m_ptr->hp / divisor), 0); }; + /* Messages for summoning */ + struct summon_messages { + char const *singular; + char const *plural; + }; + + /* Default message for summoning when player is blinded */ + auto blind_msg_default = summon_messages { + "You hear something appear nearby.", + "You hear many things appear nearby." + }; + + /* Do a summoning spell */ + auto do_summon = [&](char const *action, int n, int friendly_type, int hostile_type, summon_messages const &blind_msg) -> void { + // Interrupt + if (disturb_other) + { + disturb(1); + } + // Message + if (blind || !see_m) + { + monster_msg("%^s mumbles.", m_name); + } + else + { + monster_msg("%^s magically %s", m_name, action); + } + // Do the actual summoning + int count = 0; + for (int k = 0; k < n; k++) + { + if (friendly) + { + count += summon_specific_friendly(y, x, rlev, friendly_type, TRUE); + } + else if (!friendly) + { + count += summon_specific(y, x, rlev, hostile_type); + } + } + // Message for blinded characters + if (blind) + { + if (count == 1) + { + monster_msg(blind_msg.singular); + } + else if (count > 1) + { + monster_msg(blind_msg.plural); + } + } + }; + + /* There's no summoning friendly uniques or Nazgul */ + auto spell_idx = thrown_spell->spell_idx; + + if (friendly) + { + if ((thrown_spell->spell_idx == SF_S_UNIQUE_IDX) && + (thrown_spell->spell_idx == SF_S_WRAITH_IDX)) + { + // Summon high undead instead + spell_idx = SF_S_HI_UNDEAD_IDX; + } + } + /* Spell effect */ - int count = 0; - switch (thrown_spell->spell_idx) + switch (spell_idx) { case SF_SHRIEK_IDX: { @@ -1125,22 +1192,6 @@ static bool_ monst_spell_monst(int m_idx) break; } - case SF_S_ANIMAL_IDX: - { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons an animal!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_ANIMAL); - } - if (blind && count) monster_msg("You hear something appear nearby."); - break; - } - case SF_ROCKET_IDX: { if (disturb_other) disturb(1); @@ -1989,22 +2040,6 @@ static bool_ monst_spell_monst(int m_idx) break; } - case SF_S_ANIMALS_IDX: - { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons some animals!", m_name); - for (int k = 0; k < 4; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_ANIMAL); - } - if (blind && count) monster_msg("You hear many things appear nearby."); - break; - } - case SF_BLINK_IDX: { if (disturb_other) disturb(1); @@ -2104,326 +2139,189 @@ static bool_ monst_spell_monst(int m_idx) break; } + case SF_S_ANIMAL_IDX: + { + do_summon("summons an animal!", 1, SUMMON_ANIMAL, SUMMON_ANIMAL, blind_msg_default); + break; + } + + case SF_S_ANIMALS_IDX: + { + do_summon("summons some animals!", 4, SUMMON_ANIMAL, SUMMON_ANIMAL, blind_msg_default); + break; + } + case SF_S_BUG_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically codes some software bugs.", m_name); - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_BUG, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_BUG); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("codes some software bugs.", 6, SUMMON_BUG, SUMMON_BUG, blind_msg_default); break; } case SF_S_RNG_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically codes some RNGs.", m_name); - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_RNG, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_RNG); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("codes some RNGs.", 6, SUMMON_RNG, SUMMON_RNG, blind_msg_default); break; } case SF_S_THUNDERLORD_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons a Thunderlord!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_THUNDERLORD); - } - if (blind && count) monster_msg("You hear something appear nearby."); + do_summon("summons a Thunderlord!", 1, SUMMON_THUNDERLORD, SUMMON_THUNDERLORD, blind_msg_default); break; } case SF_S_KIN_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons %s %s.", - m_name, m_poss, - ((r_ptr->flags) & RF_UNIQUE ? - "minions" : "kin")); - summon_kin_type = r_ptr->d_char; /* Big hack */ - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_KIN, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_KIN); - } - if (blind && count) monster_msg("You hear many things appear nearby."); - - + // Describe the summons + char action[256]; + sprintf(action, + "summons %s %s.", + m_poss, + (r_ptr->flags & RF_UNIQUE ? "minions" : "kin")); + // Force the right type of "kin" + summon_kin_type = r_ptr->d_char; + // Summon + do_summon(action, 6, SUMMON_KIN, SUMMON_KIN, blind_msg_default); break; } case SF_S_HI_DEMON_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons greater demons!", m_name); - if (blind && count) monster_msg("You hear heavy steps nearby."); - if (friendly) - summon_specific_friendly(y, x, rlev, SUMMON_HI_DEMON, TRUE); - else - summon_cyber(); + do_summon("summons greater demons!", 8, SUMMON_HI_DEMON, SUMMON_HI_DEMON, blind_msg_default); break; - } + } case SF_S_MONSTER_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons help!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE); - else - count += summon_specific(y, x, rlev, 0); - } - if (blind && count) monster_msg("You hear something appear nearby."); + do_summon("summons help!", 1, SUMMON_NO_UNIQUES, 0, blind_msg_default); break; } case SF_S_MONSTERS_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons monsters!", m_name); - for (int k = 0; k < 8; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_NO_UNIQUES, TRUE); - else - count += summon_specific(y, x, rlev, 0); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("summons monsters!", 8, SUMMON_NO_UNIQUES, 0, blind_msg_default); break; } case SF_S_ANT_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons ants.", m_name); - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_ANT, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_ANT); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("summons ants.", 6, SUMMON_ANT, SUMMON_ANT, blind_msg_default); break; } case SF_S_SPIDER_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons spiders.", m_name); - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_SPIDER); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("summons spiders.", 6, SUMMON_SPIDER, SUMMON_SPIDER, blind_msg_default); break; } case SF_S_HOUND_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons hounds.", m_name); - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_HOUND, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_HOUND); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("summons hounds.", 6, SUMMON_HOUND, SUMMON_HOUND, blind_msg_default); break; } case SF_S_HYDRA_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons hydras.", m_name); - for (int k = 0; k < 6; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_HYDRA); - } - if (blind && count) monster_msg("You hear many things appear nearby."); + do_summon("summons hydras.", 6, SUMMON_HYDRA, SUMMON_HYDRA, blind_msg_default); break; } case SF_S_ANGEL_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons an angel!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_ANGEL); - } - if (blind && count) monster_msg("You hear something appear nearby."); + do_summon("summons an angel!", 1, SUMMON_ANGEL, SUMMON_ANGEL, blind_msg_default); break; } case SF_S_DEMON_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons a demon!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_DEMON, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_DEMON); - } - if (blind && count) monster_msg("You hear something appear nearby."); + do_summon("summons a demon!", 1, SUMMON_DEMON, SUMMON_DEMON, blind_msg_default); break; } case SF_S_UNDEAD_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons an undead adversary!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_UNDEAD); - } - if (blind && count) monster_msg("You hear something appear nearby."); + do_summon("summons an undead adversary!", 1, SUMMON_UNDEAD, SUMMON_UNDEAD, blind_msg_default); break; } case SF_S_DRAGON_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons a dragon!", m_name); - for (int k = 0; k < 1; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_DRAGON); - } - if (blind && count) monster_msg("You hear something appear nearby."); + do_summon("summons a dragon!", 1, SUMMON_DRAGON, SUMMON_DRAGON, blind_msg_default); break; } case SF_S_HI_UNDEAD_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons greater undead!", m_name); - for (int k = 0; k < 8; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); - } - if (blind && count) - { - monster_msg("You hear many creepy things appear nearby."); - } + summon_messages blind_msg { + "You hear a creepy thing appear nearby.", + "You hear many creepy things appear nearby." + }; + do_summon("summons greater undead!", 8, SUMMON_HI_UNDEAD_NO_UNIQUES, SUMMON_HI_UNDEAD, blind_msg); break; } case SF_S_HI_DRAGON_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons ancient dragons!", m_name); - for (int k = 0; k < 8; k++) - { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_HI_DRAGON); - } - if (blind && count) - { - monster_msg("You hear many powerful things appear nearby."); - } + summon_messages blind_msg { + "You hear many a powerful thing appear nearby.", + "You hear many powerful things appear nearby." + }; + do_summon("summons ancient dragons!", 8, SUMMON_HI_DRAGON_NO_UNIQUES, SUMMON_HI_DRAGON, blind_msg); break; } case SF_S_WRAITH_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons a wraith!", m_name); - - - for (int k = 0; k < 8; k++) - { - count += summon_specific(y, x, rlev, SUMMON_WRAITH); - } - - if (blind && count) - { - monster_msg("You hear immortal beings appear nearby."); - } + // No summoning Nazgul; see the remapping code above the switch. + assert(!friendly); + // Summon + summon_messages blind_msg { + "You hear an immortal being appear nearby.", + "You hear immortal beings appear nearby." + }; + do_summon("summons a wraith!", 8, 0 /* not used */, SUMMON_WRAITH, blind_msg); break; } case SF_S_UNIQUE_IDX: { - if (disturb_other) disturb(1); - if (blind || !see_m) monster_msg("%^s mumbles.", m_name); - else monster_msg("%^s magically summons special opponents!", m_name); + // No summoning uniques; see the remapping code above the switch. + assert(!friendly); + // Interrupt + if (disturb_other) + { + disturb(1); + } + // Message + if (blind || !see_m) + { + monster_msg("%^s mumbles.", m_name); + } + else + { + monster_msg("%^s magically summons special opponents!", m_name); + } + // Summon + int count = 0; for (int k = 0; k < 8; k++) { - if (!friendly) - count += summon_specific(y, x, rlev, SUMMON_UNIQUE); + count += summon_specific(y, x, rlev, SUMMON_UNIQUE); } for (int k = 0; k < 8; k++) { - if (friendly) - count += summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); - else - count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); } - if (blind && count) + // Message + if (blind) { - monster_msg("You hear many powerful things appear nearby."); + if (count == 1) + { + monster_msg("You hear a powerful thing appear nearby."); + } + else if (count > 1) + { + monster_msg("You hear many powerful things appear nearby."); + } } break; } @@ -2602,14 +2500,11 @@ static bool_ make_attack_spell(int m_idx) static const auto SF_INT_MASK = compute_smart_mask(); static const auto SF_INNATE_MASK = compute_innate_mask(); - int k, chance, rlev, failrate; + int chance, rlev, failrate; char m_name[80]; bool_ no_inate = FALSE; int x, y; - /* Summon count */ - int count = 0; - /* Extract the blind-ness */ bool_ blind = (p_ptr->blind ? TRUE : FALSE); @@ -2793,6 +2688,51 @@ static bool_ make_attack_spell(int m_idx) update_smart_learn(m_idx, smart_learn); }; + /* Messages for summoning */ + struct summon_messages { + char const *singular; + char const *plural; + }; + + /* Default message for summoning when player is blinded */ + summon_messages blind_msg_default { + "You hear something appear nearby.", + "You hear many things appear nearby." + }; + + /* Do a summoning spell */ + auto do_summon = [&](char const *action, int n, int type, summon_messages const &blind_msg) -> void { + // Interrupt + disturb(1); + // Message + if (blind) + { + msg_format("%^s mumbles.", m_name); + } + else + { + msg_format("%^s magically %s", m_name, action); + } + // Do the actual summoning + int count = 0; + for (int k = 0; k < n; k++) + { + count += summon_specific(y, x, rlev, type); + } + // Message for blinded characters + if (blind) + { + if (count == 1) + { + msg_print(blind_msg.singular); + } + else if (count > 1) + { + msg_print(blind_msg.plural); + } + } + }; + /* Cast the spell. */ switch (thrown_spell->spell_idx) { @@ -2809,19 +2749,6 @@ static bool_ make_attack_spell(int m_idx) break; } - case SF_S_ANIMAL_IDX: - { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons an animal!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, SUMMON_ANIMAL); - } - if (blind && count) msg_print("You hear something appear nearby."); - break; - } - case SF_ROCKET_IDX: { disturb(1); @@ -3657,19 +3584,6 @@ static bool_ make_attack_spell(int m_idx) break; } - case SF_S_ANIMALS_IDX: - { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons some animals!", m_name); - for (k = 0; k < 4; k++) - { - count += summon_specific(y, x, rlev, SUMMON_ANIMAL); - } - if (blind && count) msg_print("You hear something appear nearby."); - break; - } - case SF_BLINK_IDX: { disturb(1); @@ -3757,271 +3671,181 @@ static bool_ make_attack_spell(int m_idx) break; } + case SF_S_ANIMAL_IDX: + { + do_summon("summons an animal!", 1, SUMMON_ANIMAL, blind_msg_default); + break; + } + + case SF_S_ANIMALS_IDX: + { + do_summon("summons some animals!", 4, SUMMON_ANIMAL, blind_msg_default); + break; + } + case SF_S_BUG_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically codes some software bugs.", m_name); - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_BUG); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("codes some software bugs.", 6, SUMMON_BUG, blind_msg_default); break; } case SF_S_RNG_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically codes some RNGs.", m_name); - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_RNG); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("codes some RNGs.", 6, SUMMON_RNG, blind_msg_default); break; } case SF_S_THUNDERLORD_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons a Thunderlord!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, SUMMON_THUNDERLORD); - } - if (blind && count) msg_print("You hear something appear nearby."); + do_summon("summons a Thunderlord!", 1, SUMMON_THUNDERLORD, blind_msg_default); break; } case SF_S_KIN_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons %s %s.", - m_name, m_poss, - ((r_ptr->flags) & RF_UNIQUE ? - "minions" : "kin")); - summon_kin_type = r_ptr->d_char; /* Big hack */ - - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_KIN); - } - if (blind && count) msg_print("You hear many things appear nearby."); - + // Describe the summons + char action[256]; + sprintf(action, + "summons %s %s.", + m_poss, + (r_ptr->flags & RF_UNIQUE) ? "minions" : "kin"); + // Force the correct type of "kin" + summon_kin_type = r_ptr->d_char; + // Summon + do_summon(action, 6, SUMMON_KIN, blind_msg_default); break; } case SF_S_HI_DEMON_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons greater demons!", m_name); - if (blind && count) msg_print("You hear heavy steps nearby."); - summon_cyber(); + do_summon("summons greater demons!", 8, SUMMON_HI_DEMON, blind_msg_default); break; } case SF_S_MONSTER_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons help!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, 0); - } - if (blind && count) msg_print("You hear something appear nearby."); + do_summon("summons help!", 1, 0, blind_msg_default); break; } case SF_S_MONSTERS_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons monsters!", m_name); - for (k = 0; k < 8; k++) - { - count += summon_specific(y, x, rlev, 0); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("summons monsters!", 8, 0, blind_msg_default); break; } case SF_S_ANT_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons ants.", m_name); - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_ANT); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("summons ants.", 6, SUMMON_ANT, blind_msg_default); break; } case SF_S_SPIDER_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons spiders.", m_name); - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_SPIDER); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("summons spiders.", 6, SUMMON_SPIDER, blind_msg_default); break; } case SF_S_HOUND_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons hounds.", m_name); - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_HOUND); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("summons hounds.", 6, SUMMON_HOUND, blind_msg_default); break; } case SF_S_HYDRA_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons hydras.", m_name); - for (k = 0; k < 6; k++) - { - count += summon_specific(y, x, rlev, SUMMON_HYDRA); - } - if (blind && count) msg_print("You hear many things appear nearby."); + do_summon("summons hydras.", 6, SUMMON_HYDRA, blind_msg_default); break; } case SF_S_ANGEL_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons an angel!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, SUMMON_ANGEL); - } - if (blind && count) msg_print("You hear something appear nearby."); + do_summon("summons an angel!", 1, SUMMON_ANGEL, blind_msg_default); break; } case SF_S_DEMON_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons a demon!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, SUMMON_DEMON); - } - if (blind && count) msg_print("You hear something appear nearby."); + do_summon("summons a demon!", 1, SUMMON_DEMON, blind_msg_default); break; } case SF_S_UNDEAD_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons an undead adversary!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, SUMMON_UNDEAD); - } - if (blind && count) msg_print("You hear something appear nearby."); + do_summon("summons an undead adversary!", 1, SUMMON_UNDEAD, blind_msg_default); break; } case SF_S_DRAGON_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons a dragon!", m_name); - for (k = 0; k < 1; k++) - { - count += summon_specific(y, x, rlev, SUMMON_DRAGON); - } - if (blind && count) msg_print("You hear something appear nearby."); + do_summon("summons a dragon!", 1, SUMMON_DRAGON, blind_msg_default); break; } case SF_S_HI_UNDEAD_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons greater undead!", m_name); - for (k = 0; k < 8; k++) - { - count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); - } - if (blind && count) - { - msg_print("You hear many creepy things appear nearby."); - } + summon_messages blind_msg { + "You hear a creepy thing appear nearby.", + "You hear many creepy things appear nearby." + }; + do_summon("summons greater undead!", 8, SUMMON_HI_UNDEAD, blind_msg); break; } case SF_S_HI_DRAGON_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons ancient dragons!", m_name); - for (k = 0; k < 8; k++) - { - count += summon_specific(y, x, rlev, SUMMON_HI_DRAGON); - } - if (blind && count) - { - msg_print("You hear many powerful things appear nearby."); - } + summon_messages blind_msg { + "You hear a powerful thing appear nearby.", + "You hear many powerful things appear nearby." + }; + do_summon("summons ancient dragons!", 8, SUMMON_HI_DRAGON, blind_msg); break; } case SF_S_WRAITH_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons Wraith!", m_name); - - - for (k = 0; k < 8; k++) - { - count += summon_specific(y, x, rlev, SUMMON_WRAITH); - } - - if (blind && count) - { - msg_print("You hear immortal beings appear nearby."); - } + summon_messages blind_msg { + "You hear an immortal being appear nearby.", + "You hear immortal beings appear nearby." + }; + do_summon("summons Wraiths!", 8, SUMMON_WRAITH, blind_msg); break; } case SF_S_UNIQUE_IDX: { - disturb(1); - if (blind) msg_format("%^s mumbles.", m_name); - else msg_format("%^s magically summons special opponents!", m_name); - for (k = 0; k < 8; k++) + // Interrupt + disturb(1); + // Message + if (blind) + { + msg_format("%^s mumbles.", m_name); + } + else + { + msg_format("%^s magically summons special opponents!", m_name); + } + // Summon + int count = 0; + for (int k = 0; k < 8; k++) { count += summon_specific(y, x, rlev, SUMMON_UNIQUE); } - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); } - if (blind && count) + // Message + if (blind) { - msg_print("You hear many powerful things appear nearby."); + if (count == 1) + { + msg_print("You hear a powerful thing appear nearby."); + } + else if (count > 1) + { + msg_print("You hear many powerful things appear nearby."); + } } break; } -- cgit v1.2.3 From d191da218fc81d989d0ebdcfd66a4e0b00405121 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Clean up conditional in monst_spell_monst() --- src/melee2.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 419282c6..59f85803 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -962,7 +962,6 @@ static bool_ monst_spell_monst(int m_idx) static const monster_spell_flag_set SF_INT_MASK = compute_smart_mask(); int y = 0, x = 0; - int i = 1; char m_name[80], t_name[80]; char m_poss[80]; char ddesc[80]; @@ -997,20 +996,14 @@ static bool_ monst_spell_monst(int m_idx) if ((rand_int(100) >= chance) && (monst_spell_monst_spell == -1)) return (FALSE); - /* Target location */ - if (m_ptr->target > -1) + /* Make sure monster actually has a target */ + if (m_ptr->target <= 0) { - if (m_ptr->target > 0) - { - i = m_ptr->target; - } - else return FALSE; + return FALSE; } - else return FALSE; - { - int t_idx = i; + int t_idx = m_ptr->target; monster_type *t_ptr = &m_list[t_idx]; auto const tr_ptr = t_ptr->race(); -- cgit v1.2.3 From 03c402d63f5bef5d880c81bf7253a1274aaacf01 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Clean up conditional in make_attack_spell() --- src/melee2.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 59f85803..a31ca1f7 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2496,7 +2496,6 @@ static bool_ make_attack_spell(int m_idx) int chance, rlev, failrate; char m_name[80]; bool_ no_inate = FALSE; - int x, y; /* Extract the blind-ness */ bool_ blind = (p_ptr->blind ? TRUE : FALSE); @@ -2508,19 +2507,12 @@ static bool_ make_attack_spell(int m_idx) bool_ seen = (!blind && m_ptr->ml); /* Target location */ - if (m_ptr->target > -1) + if (m_ptr->target != 0) { - if (!m_ptr->target) - { - y = p_ptr->py; - x = p_ptr->px; - } - else - { - return (FALSE); - } + return FALSE; } - else return FALSE; + int y = p_ptr->py; + int x = p_ptr->px; /* Cannot cast spells when confused */ if (m_ptr->confused) return (FALSE); -- cgit v1.2.3 From bef0f98085526b80b316580bb5a07fcd8b1af2c5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Make summons appear around summoner instead of player --- src/melee2.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index a31ca1f7..c246343b 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -1127,17 +1127,18 @@ static bool_ monst_spell_monst(int m_idx) { monster_msg("%^s magically %s", m_name, action); } + // Do the actual summoning int count = 0; for (int k = 0; k < n; k++) { if (friendly) { - count += summon_specific_friendly(y, x, rlev, friendly_type, TRUE); + count += summon_specific_friendly(m_ptr->fy, m_ptr->fx, rlev, friendly_type, TRUE); } else if (!friendly) { - count += summon_specific(y, x, rlev, hostile_type); + count += summon_specific(m_ptr->fy, m_ptr->fx, rlev, hostile_type); } } // Message for blinded characters @@ -2298,11 +2299,11 @@ static bool_ monst_spell_monst(int m_idx) int count = 0; for (int k = 0; k < 8; k++) { - count += summon_specific(y, x, rlev, SUMMON_UNIQUE); + count += summon_specific(m_ptr->fy, m_ptr->fx, rlev, SUMMON_UNIQUE); } for (int k = 0; k < 8; k++) { - count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + count += summon_specific(m_ptr->fy, m_ptr->fx, rlev, SUMMON_HI_UNDEAD); } // Message if (blind) @@ -2702,7 +2703,7 @@ static bool_ make_attack_spell(int m_idx) int count = 0; for (int k = 0; k < n; k++) { - count += summon_specific(y, x, rlev, type); + count += summon_specific(m_ptr->fy, m_ptr->fx, rlev, type); } // Message for blinded characters if (blind) @@ -3814,11 +3815,11 @@ static bool_ make_attack_spell(int m_idx) int count = 0; for (int k = 0; k < 8; k++) { - count += summon_specific(y, x, rlev, SUMMON_UNIQUE); + count += summon_specific(m_ptr->fy, m_ptr->fx, rlev, SUMMON_UNIQUE); } for (int k = 0; k < 8; k++) { - count += summon_specific(y, x, rlev, SUMMON_HI_UNDEAD); + count += summon_specific(m_ptr->fy, m_ptr->fx, rlev, SUMMON_HI_UNDEAD); } // Message if (blind) -- cgit v1.2.3 From 55729f1d5e1c656fa909e9c18275107d206aedea Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Factor out 'disturb_other' option handling --- src/melee2.cc | 108 +++++++++++++++++++++++++++------------------------------- 1 file changed, 50 insertions(+), 58 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index c246343b..91dfcaf2 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -1078,10 +1078,7 @@ static bool_ monst_spell_monst(int m_idx) /* Do a breath */ auto do_breath = [&](char const *element, int gf, s32b max, int divisor) -> void { // Interrupt - if (disturb_other) - { - disturb(1); - } + disturb_on_other(); // Message if (!see_either) { @@ -1114,10 +1111,8 @@ static bool_ monst_spell_monst(int m_idx) /* Do a summoning spell */ auto do_summon = [&](char const *action, int n, int friendly_type, int hostile_type, summon_messages const &blind_msg) -> void { // Interrupt - if (disturb_other) - { - disturb(1); - } + disturb_on_other(); + // Message if (blind || !see_m) { @@ -1174,7 +1169,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_SHRIEK_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_m) monster_msg("You hear a shriek."); else monster_msg("%^s shrieks at %s.", m_name, t_name); wake_up = TRUE; @@ -1188,7 +1183,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_ROCKET_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg("You hear an explosion!"); else if (blind) monster_msg("%^s shoots something.", m_name); else monster_msg("%^s fires a rocket at %s.", m_name, t_name); @@ -1199,7 +1194,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_ARROW_1_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg("You hear a strange noise."); else if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires an arrow at %s.", m_name, t_name); @@ -1209,7 +1204,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_ARROW_2_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg("You hear a strange noise."); else if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires an arrow at %s.", m_name, t_name); @@ -1219,7 +1214,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_ARROW_3_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg("You hear a strange noise."); else if (blind) monster_msg("%^s makes a strange noise.", m_name); @@ -1231,7 +1226,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_ARROW_4_IDX: { if (!see_either) monster_msg("You hear a strange noise."); - else if (disturb_other) disturb(1); + else disturb_on_other(); if (blind) monster_msg("%^s makes a strange noise.", m_name); else monster_msg("%^s fires a missile at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_ARROW, damroll(7, 6)); @@ -1360,7 +1355,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_NUKE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a ball of radiation at %s.", m_name, t_name); @@ -1377,7 +1372,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_CHAO_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg("You hear someone mumble frighteningly."); else if (blind) monster_msg("%^s mumbles frighteningly.", m_name); else monster_msg("%^s invokes a raw Chaos upon %s.", m_name, t_name); @@ -1394,7 +1389,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_ACID_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts an acid ball at %s.", m_name, t_name); @@ -1404,7 +1399,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_ELEC_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); @@ -1415,7 +1410,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_FIRE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); @@ -1426,7 +1421,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_COLD_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); @@ -1437,7 +1432,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_POIS_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); @@ -1448,7 +1443,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_NETH_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); @@ -1459,7 +1454,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_WATE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble."); else if (blind) monster_msg("%^s mumbles.", m_name); @@ -1471,7 +1466,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_MANA_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble powerfully."); else if (blind) monster_msg("%^s mumbles powerfully.", m_name); @@ -1482,7 +1477,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BA_DARK_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_either) monster_msg ("You hear someone mumble powerfully."); else if (blind) monster_msg("%^s mumbles powerfully.", m_name); @@ -1535,7 +1530,7 @@ static bool_ monst_spell_monst(int m_idx) { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (!seen) { @@ -1573,7 +1568,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BRAIN_SMASH_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (!seen) { /* */ @@ -1613,7 +1608,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_CAUSE_1_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s points at %s and curses.", m_name, t_name); if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) @@ -1633,7 +1628,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_CAUSE_2_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s points at %s and curses horribly.", m_name, t_name); if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) @@ -1652,7 +1647,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_CAUSE_3_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s points at %s, incanting terribly!", m_name, t_name); if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) @@ -1671,7 +1666,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_CAUSE_4_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s points at %s, screaming the word 'DIE!'", m_name, t_name); if (t_ptr->level > randint((rlev - 10) < 1 ? 1 : (rlev - 10)) + 10) @@ -1689,7 +1684,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_ACID_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts an acid bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_ACID, @@ -1699,7 +1694,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_ELEC_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a lightning bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_ELEC, @@ -1709,7 +1704,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_FIRE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a fire bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_FIRE, @@ -1719,7 +1714,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_COLD_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a frost bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_COLD, @@ -1735,7 +1730,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_NETH_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a nether bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_NETHER, @@ -1745,7 +1740,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_WATE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a water bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_WATER, @@ -1755,7 +1750,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_MANA_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a mana bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_MANA, @@ -1765,7 +1760,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_PLAS_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a plasma bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_PLASMA, @@ -1775,7 +1770,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BO_ICEE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts an ice bolt at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_ICE, @@ -1785,7 +1780,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_MISSILE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a magic missile at %s.", m_name, t_name); monst_bolt_monst(m_idx, y, x, GF_MISSILE, @@ -1796,7 +1791,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_SCARE_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles, and you hear scary noises.", m_name); else monster_msg("%^s casts a fearful illusion at %s.", m_name, t_name); if (tr_ptr->flags & RF_NO_FEAR) @@ -1819,7 +1814,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BLIND_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s casts a spell, burning %s%s eyes.", m_name, t_name, (!strcmp(t_name, "it") ? "s" : "'s")); @@ -1844,7 +1839,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_CONF_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) monster_msg("%^s mumbles, and you hear puzzling noises.", m_name); else monster_msg("%^s creates a mesmerising illusion in front of %s.", m_name, t_name); if (tr_ptr->flags & RF_NO_CONF) @@ -1867,7 +1862,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_SLOW_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (!blind && see_either) monster_msg("%^s drains power from %s%s muscles.", m_name, t_name, (!strcmp(t_name, "it") ? "s" : "'s")); if (tr_ptr->flags & RF_UNIQUE) @@ -1890,7 +1885,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_HOLD_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (!blind && see_m) monster_msg("%^s stares intently at %s.", m_name, t_name); if ((tr_ptr->flags & RF_UNIQUE) || (tr_ptr->flags & RF_NO_STUN)) @@ -1912,7 +1907,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_HASTE_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (blind || !see_m) { monster_msg("%^s mumbles.", m_name); @@ -1942,7 +1937,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_HAND_DOOM_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (!see_m) monster_msg("You hear someone invoke the Hand of Doom!"); else if (!blind) monster_msg("%^s invokes the Hand of Doom on %s.", m_name, t_name); else @@ -1972,7 +1967,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_HEAL_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); /* Message */ if (blind || !see_m) @@ -2036,7 +2031,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_BLINK_IDX: { - if (disturb_other) disturb(1); + disturb_on_other(); if (see_m) monster_msg("%^s blinks away.", m_name); teleport_away(m_idx, 10); break; @@ -2047,7 +2042,7 @@ static bool_ monst_spell_monst(int m_idx) if (dungeon_flags & DF_NO_TELEPORT) break; /* No teleport on special levels */ else { - if (disturb_other) disturb(1); + disturb_on_other(); if (see_m) monster_msg("%^s teleports away.", m_name); teleport_away(m_idx, MAX_SIGHT * 2 + 5); break; @@ -2068,7 +2063,7 @@ static bool_ monst_spell_monst(int m_idx) else { bool_ resists_tele = FALSE; - if (disturb_other) disturb(1); + disturb_on_other(); monster_msg("%^s teleports %s away.", m_name, t_name); @@ -2110,7 +2105,7 @@ static bool_ monst_spell_monst(int m_idx) case SF_DARKNESS_IDX: { if (!direct) break; - if (disturb_other) disturb(1); + disturb_on_other(); if (blind) monster_msg("%^s mumbles.", m_name); else monster_msg("%^s gestures in shadow.", m_name); if (seen) @@ -2282,10 +2277,7 @@ static bool_ monst_spell_monst(int m_idx) // No summoning uniques; see the remapping code above the switch. assert(!friendly); // Interrupt - if (disturb_other) - { - disturb(1); - } + disturb_on_other(); // Message if (blind || !see_m) { @@ -4739,7 +4731,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) if (!effect || check_hit2(power, rlev, ac)) { /* Always disturbing */ - if (disturb_other) disturb(1); + disturb_on_other(); /* Describe the attack method */ switch (method) -- cgit v1.2.3 From f035201f330a3b1f50a2041ea9ad3f854f7d4e00 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Move all options to a struct instead of using globals --- src/melee2.cc | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 91dfcaf2..49742a59 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -302,23 +302,22 @@ static void remove_bad_spells(int m_idx, monster_spell_flag_set *spells_p) /* Too stupid to know anything? */ auto const r_ptr = m_ptr->race(); - if (r_ptr->flags & RF_STUPID) return; - + if (r_ptr->flags & RF_STUPID) + { + return; + } /* Must be cheating or learning */ - if (!smart_learn) return; - - - /* Update acquired knowledge */ - if (smart_learn) + if (!options->smart_learn) { - /* Hack -- Occasionally forget player status */ - if (m_ptr->smart && magik(1)) m_ptr->smart = 0L; - - /* Use the memorized flags */ - smart = m_ptr->smart; + return; } + /* Hack -- Occasionally forget player status */ + if (m_ptr->smart && magik(1)) m_ptr->smart = 0L; + + /* Use the memorized flags */ + smart = m_ptr->smart; /* Nothing known */ if (!smart) return; @@ -897,7 +896,7 @@ static void monster_msg(cptr fmt, ...) void monster_msg_simple(cptr s) { /* Display */ - if (disturb_other) + if (options->disturb_other) { msg_print(s); } @@ -924,7 +923,7 @@ void cmonster_msg(char a, cptr fmt, ...) va_end(vp); /* Display */ - if (disturb_other) + if (options->disturb_other) cmsg_print(a, buf); else { @@ -3933,7 +3932,10 @@ static int mon_will_run(int m_idx) static bool_ get_fear_moves_aux(int m_idx, int *yp, int *xp) { /* Monster flowing disabled */ - if (!flow_by_sound) return (FALSE); + if (!options->flow_by_sound) + { + return (FALSE); + } /* Monster location */ monster_type *m_ptr = &m_list[m_idx]; @@ -4051,7 +4053,7 @@ static bool_ find_safety(int m_idx, int *yp, int *xp) if (distance(y, x, fy, fx) != d) continue; /* Check for "availability" (if monsters can flow) */ - if (flow_by_sound) + if (options->flow_by_sound) { /* Ignore grids very far from the player */ if (cave[y][x].when < cave[p_ptr->py][p_ptr->px].when) continue; @@ -4439,7 +4441,7 @@ static bool_ get_moves(int m_idx, int *mm) else { /* Attempt to avoid the player */ - if (flow_by_sound) + if (options->flow_by_sound) { /* Adjust movement */ (void)get_fear_moves_aux(m_idx, &y, &x); @@ -5846,7 +5848,10 @@ static void process_monster(int m_idx, bool_ is_frien) msg_print("You hear a door burst open!"); /* Disturb (sometimes) */ - if (disturb_minor) disturb(0); + if (options->disturb_minor) + { + disturb(0); + } /* The door was bashed open */ did_bash_door = TRUE; @@ -6127,12 +6132,12 @@ static void process_monster(int m_idx, bool_ is_frien) } /* Possible disturb */ - if (m_ptr->ml && (disturb_move || + if (m_ptr->ml && (options->disturb_move || ((m_ptr->mflag & (MFLAG_VIEW)) && - disturb_near))) + options->disturb_near))) { /* Disturb */ - if ((is_friend(m_ptr) < 0) || disturb_pets) + if ((is_friend(m_ptr) < 0) || options->disturb_pets) disturb(0); } @@ -6485,7 +6490,7 @@ void process_monsters(void) /* Hack -- Monsters can "smell" the player from far away */ /* Note that most monsters have "aaf" of "20" or so */ - else if (flow_by_sound && + else if (options->flow_by_sound && (cave[p_ptr->py][p_ptr->px].when == cave[fy][fx].when) && (cave[fy][fx].cost < MONSTER_FLOW_DEPTH) && (cave[fy][fx].cost < r_ptr->aaf)) -- cgit v1.2.3 From 39eb6a171792b3bd34e0afdafa72a1a2b7d9fd78 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Add explicit braces in a few places --- src/melee2.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 49742a59..d519dd8a 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -924,7 +924,9 @@ void cmonster_msg(char a, cptr fmt, ...) /* Display */ if (options->disturb_other) + { cmsg_print(a, buf); + } else { message_add(buf, a); @@ -2038,7 +2040,10 @@ static bool_ monst_spell_monst(int m_idx) case SF_TPORT_IDX: { - if (dungeon_flags & DF_NO_TELEPORT) break; /* No teleport on special levels */ + if (dungeon_flags & DF_NO_TELEPORT) + { + break; /* No teleport on special levels */ + } else { disturb_on_other(); @@ -2056,9 +2061,15 @@ static bool_ monst_spell_monst(int m_idx) case SF_TELE_AWAY_IDX: { - if (dungeon_flags & DF_NO_TELEPORT) break; + if (dungeon_flags & DF_NO_TELEPORT) + { + break; + } - if (!direct) break; + if (!direct) + { + break; + } else { bool_ resists_tele = FALSE; -- cgit v1.2.3 From b15461dbcedf27f28a843f700ce0473d57364230 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove redundant checks "around" artifact_p() Turns out artifact_p() already performs the necessary checks. --- src/melee2.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index d519dd8a..130b74ee 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6211,8 +6211,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (flags & TR_SLAY_EVIL) flg |= RF_EVIL; /* The object cannot be picked up by the monster */ - if (artifact_p(o_ptr) || (r_ptr->flags & flg) || - (o_ptr->art_name)) + if (artifact_p(o_ptr) || (r_ptr->flags & flg)) { /* Only give a message for "take_item" */ if (r_ptr->flags & RF_TAKE_ITEM) -- cgit v1.2.3 From 013e27d39ee8ee513208d2855c7e3f6252f0c0bf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Refactor object_type 'inscription' field to std::string We don't really need quarks for this since we're not nearly as memory-constrained these days. --- src/melee2.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 130b74ee..562bca57 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2381,12 +2381,9 @@ void curse_equipment(int chance, int heavy_chance) if (changed) { msg_print("There is a malignant black aura surrounding you..."); - if (o_ptr->note) + if (o_ptr->inscription == "uncursed") { - if (streq(quark_str(o_ptr->note), "uncursed")) - { - o_ptr->note = 0; - } + o_ptr->inscription.clear(); } } } @@ -2438,12 +2435,9 @@ void curse_equipment_dg(int chance, int heavy_chance) if (changed) { msg_print("There is a malignant black aura surrounding you..."); - if (o_ptr->note) + if (o_ptr->inscription == "uncursed") { - if (streq(quark_str(o_ptr->note), "uncursed")) - { - o_ptr->note = 0; - } + o_ptr->inscription.clear(); } } } -- cgit v1.2.3 From 8bbf783ead4517465445272f9144cf06bdac9be7 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Refactor object_type 'artifact name' field to std::string We don't really need quarks for this since we're not nearly as memory-constrained these days. --- src/melee2.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 562bca57..41756550 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2362,7 +2362,7 @@ void curse_equipment(int chance, int heavy_chance) } if ((randint(100) <= heavy_chance) && - (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name)) + (o_ptr->name1 || o_ptr->name2 || (!o_ptr->artifact_name.empty()))) { if (!(flags & TR_HEAVY_CURSE)) changed = TRUE; @@ -2414,7 +2414,7 @@ void curse_equipment_dg(int chance, int heavy_chance) } if ((randint(100) <= heavy_chance) && - (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name)) + (o_ptr->name1 || o_ptr->name2 || (!o_ptr->artifact_name.empty()))) { if (!(flags & TR_HEAVY_CURSE)) changed = TRUE; -- cgit v1.2.3 From 288c3d3f725eabfee06507966a0ba63bf587c3da Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove quark.{cc,hpp} --- src/melee2.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 41756550..773cdad1 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -38,7 +38,6 @@ #include "object_flag.hpp" #include "options.hpp" #include "player_type.hpp" -#include "quark.hpp" #include "skills.hpp" #include "spells1.hpp" #include "spells2.hpp" -- cgit v1.2.3 From 0c2f30b56c221a826ba64f0ec864c29d0f717644 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move r_info into GameEditData --- src/melee2.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 773cdad1..d1fc3767 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -20,6 +20,7 @@ #include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "hook_mon_speak_in.hpp" #include "hook_monster_ai_in.hpp" #include "hook_monster_ai_out.hpp" @@ -4175,19 +4176,20 @@ static bool_ find_hiding(int m_idx, int *yp, int *xp) /* Find an appropriate corpse */ void find_corpse(monster_type *m_ptr, int *y, int *x) { + auto const &r_info = game->edit_data.r_info; + int k, last = -1; for (k = 0; k < max_o_idx; k++) { object_type *o_ptr = &o_list[k]; - monster_race *rt_ptr, *rt2_ptr; if (!o_ptr->k_idx) continue; if (o_ptr->tval != TV_CORPSE) continue; if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_SKELETON)) continue; - rt_ptr = &r_info[o_ptr->pval2]; + auto rt_ptr = &r_info[o_ptr->pval2]; /* Cannot incarnate into a higher level monster */ if (rt_ptr->level > m_ptr->level) continue; @@ -4197,9 +4199,16 @@ void find_corpse(monster_type *m_ptr, int *y, int *x) if (last != -1) { - rt2_ptr = &r_info[o_list[last].pval2]; - if (rt_ptr->level > rt2_ptr->level) last = k; - else continue; + auto rt2_ptr = &r_info[o_list[last].pval2]; + + if (rt_ptr->level > rt2_ptr->level) + { + last = k; + } + else + { + continue; + } } else { @@ -4220,6 +4229,8 @@ void find_corpse(monster_type *m_ptr, int *y, int *x) */ static void get_target_monster(int m_idx) { + auto const &r_info = game->edit_data.r_info; + monster_type *m_ptr = &m_list[m_idx]; int i, t = -1, d = 9999; @@ -4229,7 +4240,7 @@ static void get_target_monster(int m_idx) /* Access the monster */ monster_type *t_ptr = &m_list[i]; /* hack should call the function for ego monsters ... but no_target i not meant to be added by ego and it speeds up the code */ - monster_race *rt_ptr = &r_info[t_ptr->r_idx]; + auto rt_ptr = &r_info[t_ptr->r_idx]; int dd; /* Ignore "dead" monsters */ @@ -6389,6 +6400,8 @@ void summon_maint(int m_idx) */ void process_monsters(void) { + auto const &r_info = game->edit_data.r_info; + int i, e; int fx, fy; -- cgit v1.2.3 From b9fca0267b1d6a32d57e1fb4387f52c19d1c3fa6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move f_info into GameEditData --- src/melee2.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index d1fc3767..415fd478 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -5254,6 +5254,8 @@ static bool_ player_invis(monster_type * m_ptr) */ static void process_monster(int m_idx, bool_ is_frien) { + auto const &f_info = game->edit_data.f_info; + int i, d, oy, ox, ny, nx; int mm[8]; -- cgit v1.2.3 From cbafbc638c2e1d5bb40ee6bc419007062e9615e4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:09 +0200 Subject: Remove traps Credit goes mostly to "miramor" who did most of the actual work. I just did a few minor tweaks and fixes + rebased onto master. --- src/melee2.cc | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 415fd478..df9ee6d3 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -44,7 +44,6 @@ #include "spells2.hpp" #include "stats.hpp" #include "tables.hpp" -#include "traps.hpp" #include "util.hpp" #include "variable.hpp" #include "xtra2.hpp" @@ -2126,12 +2125,6 @@ static bool_ monst_spell_monst(int m_idx) break; } - case SF_TRAPS_IDX: - { - /* Not implemented */ - break; - } - case SF_FORGET_IDX: { /* Not implemented */ @@ -3628,15 +3621,6 @@ static bool_ make_attack_spell(int m_idx) break; } - case SF_TRAPS_IDX: - { - disturb(1); - if (blind) msg_format("%^s mumbles, and then cackles evilly.", m_name); - else msg_format("%^s casts a spell and cackles evilly.", m_name); - (void)trap_creation(); - break; - } - case SF_FORGET_IDX: { disturb(1); @@ -5683,13 +5667,6 @@ static void process_monster(int m_idx, bool_ is_frien) do_move = TRUE; } - /* Floor is trapped? */ - else if (c_ptr->feat == FEAT_MON_TRAP) - { - /* Go ahead and move */ - do_move = TRUE; - } - /* Hack -- check for Glyph of Warding */ if ((c_ptr->feat == FEAT_GLYPH) && !(r_ptr->flags & RF_NEVER_BLOW)) @@ -6158,12 +6135,7 @@ static void process_monster(int m_idx, bool_ is_frien) disturb(0); } - /* Check for monster trap */ - if (c_ptr->feat == FEAT_MON_TRAP) - { - if (mon_hit_trap(m_idx)) return; - } - else + { /* Copy list of objects; we need a copy because we're mutating the list. */ auto const object_idxs(c_ptr->o_idxs); -- cgit v1.2.3 From b3d136333c1b516123cc83e3dc96d4bd79dd52ca Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 20:01:12 +0200 Subject: Fix indentation --- src/melee2.cc | 174 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 86 insertions(+), 88 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index df9ee6d3..691021a5 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -6136,116 +6136,114 @@ static void process_monster(int m_idx, bool_ is_frien) } + /* Copy list of objects; we need a copy because we're mutating the list. */ + auto const object_idxs(c_ptr->o_idxs); + + /* Scan all objects in the grid */ + for (auto const this_o_idx: object_idxs) { - /* Copy list of objects; we need a copy because we're mutating the list. */ - auto const object_idxs(c_ptr->o_idxs); + /* Acquire object */ + object_type * o_ptr = &o_list[this_o_idx]; + + /* Skip gold */ + if (o_ptr->tval == TV_GOLD) continue; + + /* Incarnate ? */ + if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags & RF_POSSESSOR) && + ((o_ptr->sval == SV_CORPSE_CORPSE) || (o_ptr->sval == SV_CORPSE_SKELETON))) + { + if (ai_possessor(m_idx, this_o_idx)) return; + } - /* Scan all objects in the grid */ - for (auto const this_o_idx: object_idxs) + /* Take or Kill objects on the floor */ + /* rr9: Pets will no longer pick up/destroy items */ + if ((((r_ptr->flags & RF_TAKE_ITEM) && + ((is_friend(m_ptr) <= 0) || p_ptr->pet_pickup_items)) || + (r_ptr->flags & RF_KILL_ITEM)) && + (is_friend(m_ptr) <= 0)) { - /* Acquire object */ - object_type * o_ptr = &o_list[this_o_idx]; + char m_name[80]; + char o_name[80]; - /* Skip gold */ - if (o_ptr->tval == TV_GOLD) continue; + /* Extract some flags */ + auto const flags = object_flags(o_ptr); - /* Incarnate ? */ - if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags & RF_POSSESSOR) && - ((o_ptr->sval == SV_CORPSE_CORPSE) || (o_ptr->sval == SV_CORPSE_SKELETON))) - { - if (ai_possessor(m_idx, this_o_idx)) return; - } + /* Acquire the object name */ + object_desc(o_name, o_ptr, TRUE, 3); - /* Take or Kill objects on the floor */ - /* rr9: Pets will no longer pick up/destroy items */ - if ((((r_ptr->flags & RF_TAKE_ITEM) && - ((is_friend(m_ptr) <= 0) || p_ptr->pet_pickup_items)) || - (r_ptr->flags & RF_KILL_ITEM)) && - (is_friend(m_ptr) <= 0)) + /* Acquire the monster name */ + monster_desc(m_name, m_ptr, 0x04); + + /* React to objects that hurt the monster */ + monster_race_flag_set flg; + if (flags & TR_KILL_DEMON) flg |= RF_DEMON; + if (flags & TR_KILL_UNDEAD) flg |= RF_UNDEAD; + if (flags & TR_SLAY_DRAGON) flg |= RF_DRAGON; + if (flags & TR_SLAY_TROLL) flg |= RF_TROLL; + if (flags & TR_SLAY_GIANT) flg |= RF_GIANT; + if (flags & TR_SLAY_ORC) flg |= RF_ORC; + if (flags & TR_SLAY_DEMON) flg |= RF_DEMON; + if (flags & TR_SLAY_UNDEAD) flg |= RF_UNDEAD; + if (flags & TR_SLAY_ANIMAL) flg |= RF_ANIMAL; + if (flags & TR_SLAY_EVIL) flg |= RF_EVIL; + + /* The object cannot be picked up by the monster */ + if (artifact_p(o_ptr) || (r_ptr->flags & flg)) { - char m_name[80]; - char o_name[80]; - - /* Extract some flags */ - auto const flags = object_flags(o_ptr); - - /* Acquire the object name */ - object_desc(o_name, o_ptr, TRUE, 3); - - /* Acquire the monster name */ - monster_desc(m_name, m_ptr, 0x04); - - /* React to objects that hurt the monster */ - monster_race_flag_set flg; - if (flags & TR_KILL_DEMON) flg |= RF_DEMON; - if (flags & TR_KILL_UNDEAD) flg |= RF_UNDEAD; - if (flags & TR_SLAY_DRAGON) flg |= RF_DRAGON; - if (flags & TR_SLAY_TROLL) flg |= RF_TROLL; - if (flags & TR_SLAY_GIANT) flg |= RF_GIANT; - if (flags & TR_SLAY_ORC) flg |= RF_ORC; - if (flags & TR_SLAY_DEMON) flg |= RF_DEMON; - if (flags & TR_SLAY_UNDEAD) flg |= RF_UNDEAD; - if (flags & TR_SLAY_ANIMAL) flg |= RF_ANIMAL; - if (flags & TR_SLAY_EVIL) flg |= RF_EVIL; - - /* The object cannot be picked up by the monster */ - if (artifact_p(o_ptr) || (r_ptr->flags & flg)) + /* Only give a message for "take_item" */ + if (r_ptr->flags & RF_TAKE_ITEM) { - /* Only give a message for "take_item" */ - if (r_ptr->flags & RF_TAKE_ITEM) + /* Describe observable situations */ + if (m_ptr->ml && player_has_los_bold(ny, nx)) { - /* Describe observable situations */ - if (m_ptr->ml && player_has_los_bold(ny, nx)) - { - /* Dump a message */ - msg_format("%^s tries to pick up %s, but fails.", - m_name, o_name); - } + /* Dump a message */ + msg_format("%^s tries to pick up %s, but fails.", + m_name, o_name); } } + } - /* Pick up the item */ - else if (r_ptr->flags & RF_TAKE_ITEM) + /* Pick up the item */ + else if (r_ptr->flags & RF_TAKE_ITEM) + { + /* Describe observable situations */ + if (player_has_los_bold(ny, nx)) { - /* Describe observable situations */ - if (player_has_los_bold(ny, nx)) - { - /* Dump a message */ - msg_format("%^s picks up %s.", m_name, o_name); - } + /* Dump a message */ + msg_format("%^s picks up %s.", m_name, o_name); + } - /* Put into inventory of monster */ - { - /* Excise the object */ - excise_object_idx(this_o_idx); + /* Put into inventory of monster */ + { + /* Excise the object */ + excise_object_idx(this_o_idx); - /* Forget mark */ - o_ptr->marked = FALSE; + /* Forget mark */ + o_ptr->marked = FALSE; - /* Forget location */ - o_ptr->iy = o_ptr->ix = 0; + /* Forget location */ + o_ptr->iy = o_ptr->ix = 0; - /* Memorize monster */ - o_ptr->held_m_idx = m_idx; + /* Memorize monster */ + o_ptr->held_m_idx = m_idx; - /* Carry object */ - m_ptr->hold_o_idxs.push_back(this_o_idx); - } + /* Carry object */ + m_ptr->hold_o_idxs.push_back(this_o_idx); } + } - /* Destroy the item */ - else + /* Destroy the item */ + else + { + /* Describe observable situations */ + if (player_has_los_bold(ny, nx)) { - /* Describe observable situations */ - if (player_has_los_bold(ny, nx)) - { - /* Dump a message */ - msg_format("%^s crushes %s.", m_name, o_name); - } - - /* Delete the object */ - delete_object_idx(this_o_idx); + /* Dump a message */ + msg_format("%^s crushes %s.", m_name, o_name); } + + /* Delete the object */ + delete_object_idx(this_o_idx); } } } -- cgit v1.2.3 From 71a820e7298a670c13bd68cb3e6f2274a4dc3ba9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 8 Oct 2016 11:38:29 +0200 Subject: Remove unused parameter from disturb() --- src/melee2.cc | 110 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 55 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 691021a5..0988d2af 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -2647,7 +2647,7 @@ static bool_ make_attack_spell(int m_idx) /* Do a breath */ auto do_breath = [&](char const *element, int gf, s32b max, int divisor, int smart_learn) -> void { // Interrupt - disturb(1); + disturb(); // Message if (blind) { @@ -2678,7 +2678,7 @@ static bool_ make_attack_spell(int m_idx) /* Do a summoning spell */ auto do_summon = [&](char const *action, int n, int type, summon_messages const &blind_msg) -> void { // Interrupt - disturb(1); + disturb(); // Message if (blind) { @@ -2713,7 +2713,7 @@ static bool_ make_attack_spell(int m_idx) { case SF_SHRIEK_IDX: { - disturb(1); + disturb(); msg_format("%^s makes a high pitched shriek.", m_name); aggravate_monsters(m_idx); break; @@ -2726,7 +2726,7 @@ static bool_ make_attack_spell(int m_idx) case SF_ROCKET_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s shoots something.", m_name); else msg_format("%^s fires a rocket.", m_name); breath(m_idx, GF_ROCKET, @@ -2737,7 +2737,7 @@ static bool_ make_attack_spell(int m_idx) case SF_ARROW_1_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s makes a strange noise.", m_name); else msg_format("%^s fires an arrow.", m_name); bolt(m_idx, GF_ARROW, damroll(1, 6)); @@ -2747,7 +2747,7 @@ static bool_ make_attack_spell(int m_idx) case SF_ARROW_2_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s makes a strange noise.", m_name); else msg_format("%^s fires an arrow!", m_name); bolt(m_idx, GF_ARROW, damroll(3, 6)); @@ -2757,7 +2757,7 @@ static bool_ make_attack_spell(int m_idx) case SF_ARROW_3_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s makes a strange noise.", m_name); else msg_format("%^s fires a missile.", m_name); bolt(m_idx, GF_ARROW, damroll(5, 6)); @@ -2767,7 +2767,7 @@ static bool_ make_attack_spell(int m_idx) case SF_ARROW_4_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s makes a strange noise.", m_name); else msg_format("%^s fires a missile!", m_name); bolt(m_idx, GF_ARROW, damroll(7, 6)); @@ -2897,7 +2897,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_NUKE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a ball of radiation.", m_name); breath(m_idx, GF_NUKE, (rlev + damroll(10, 6)), 2); @@ -2913,7 +2913,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_CHAO_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles frighteningly.", m_name); else msg_format("%^s invokes a raw chaos.", m_name); breath(m_idx, GF_CHAOS, (rlev * 2) + damroll(10, 10), 4); @@ -2929,7 +2929,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_ACID_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts an acid ball.", m_name); breath(m_idx, GF_ACID, @@ -2940,7 +2940,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_ELEC_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a lightning ball.", m_name); breath(m_idx, GF_ELEC, @@ -2951,7 +2951,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_FIRE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a fire ball.", m_name); breath(m_idx, GF_FIRE, @@ -2962,7 +2962,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_COLD_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a frost ball.", m_name); breath(m_idx, GF_COLD, @@ -2973,7 +2973,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_POIS_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a stinking cloud.", m_name); breath(m_idx, GF_POIS, @@ -2984,7 +2984,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_NETH_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a nether ball.", m_name); breath(m_idx, GF_NETHER, @@ -2995,7 +2995,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_WATE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s gestures fluidly.", m_name); msg_print("You are engulfed in a whirlpool."); @@ -3006,7 +3006,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_MANA_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles powerfully.", m_name); else msg_format("%^s invokes a mana storm.", m_name); breath(m_idx, GF_MANA, @@ -3016,7 +3016,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BA_DARK_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles powerfully.", m_name); else msg_format("%^s invokes a darkness storm.", m_name); breath(m_idx, GF_DARK, @@ -3032,7 +3032,7 @@ static bool_ make_attack_spell(int m_idx) int r1; /* Disturb if legal */ - disturb(1); + disturb(); /* Basic message */ msg_format("%^s draws psychic energy from you!", m_name); @@ -3083,7 +3083,7 @@ static bool_ make_attack_spell(int m_idx) case SF_MIND_BLAST_IDX: { - disturb(1); + disturb(); if (!seen) { msg_print("You feel something focusing on your mind."); @@ -3118,7 +3118,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BRAIN_SMASH_IDX: { - disturb(1); + disturb(); if (!seen) { msg_print("You feel something focusing on your mind."); @@ -3165,7 +3165,7 @@ static bool_ make_attack_spell(int m_idx) case SF_CAUSE_1_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s points at you and curses.", m_name); if (rand_int(100) < p_ptr->skill_sav) @@ -3182,7 +3182,7 @@ static bool_ make_attack_spell(int m_idx) case SF_CAUSE_2_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s points at you and curses horribly.", m_name); if (rand_int(100) < p_ptr->skill_sav) @@ -3199,7 +3199,7 @@ static bool_ make_attack_spell(int m_idx) case SF_CAUSE_3_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles loudly.", m_name); else msg_format("%^s points at you, incanting terribly!", m_name); if (rand_int(100) < p_ptr->skill_sav) @@ -3216,7 +3216,7 @@ static bool_ make_attack_spell(int m_idx) case SF_CAUSE_4_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s screams the word 'DIE!'", m_name); else msg_format("%^s points at you, screaming the word DIE!", m_name); if (rand_int(100) < p_ptr->skill_sav) @@ -3233,7 +3233,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_ACID_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a acid bolt.", m_name); bolt(m_idx, GF_ACID, damroll(7, 8) + (rlev / 3)); @@ -3244,7 +3244,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_ELEC_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a lightning bolt.", m_name); bolt(m_idx, GF_ELEC, damroll(4, 8) + (rlev / 3)); @@ -3255,7 +3255,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_FIRE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a fire bolt.", m_name); bolt(m_idx, GF_FIRE, damroll(9, 8) + (rlev / 3)); @@ -3266,7 +3266,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_COLD_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a frost bolt.", m_name); bolt(m_idx, GF_COLD, damroll(6, 8) + (rlev / 3)); @@ -3283,7 +3283,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_NETH_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a nether bolt.", m_name); bolt(m_idx, GF_NETHER, 30 + damroll(5, 5) + (rlev * 3) / 2); @@ -3294,7 +3294,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_WATE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a water bolt.", m_name); bolt(m_idx, GF_WATER, damroll(10, 10) + (rlev)); @@ -3304,7 +3304,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_MANA_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a mana bolt.", m_name); bolt(m_idx, GF_MANA, randint(rlev * 7 / 2) + 50); @@ -3314,7 +3314,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_PLAS_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a plasma bolt.", m_name); bolt(m_idx, GF_PLASMA, 10 + damroll(8, 7) + (rlev)); @@ -3324,7 +3324,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BO_ICEE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts an ice bolt.", m_name); bolt(m_idx, GF_ICE, damroll(6, 6) + (rlev)); @@ -3335,7 +3335,7 @@ static bool_ make_attack_spell(int m_idx) case SF_MISSILE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a magic missile.", m_name); bolt(m_idx, GF_MISSILE, damroll(2, 6) + (rlev / 3)); @@ -3345,7 +3345,7 @@ static bool_ make_attack_spell(int m_idx) case SF_SCARE_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles, and you hear scary noises.", m_name); else msg_format("%^s casts a fearful illusion.", m_name); if (p_ptr->resist_fear) @@ -3366,7 +3366,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BLIND_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s casts a spell, burning your eyes!", m_name); if (p_ptr->resist_blind) @@ -3387,7 +3387,7 @@ static bool_ make_attack_spell(int m_idx) case SF_CONF_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles, and you hear puzzling noises.", m_name); else msg_format("%^s creates a mesmerizing illusion.", m_name); if (p_ptr->resist_conf) @@ -3408,7 +3408,7 @@ static bool_ make_attack_spell(int m_idx) case SF_SLOW_IDX: { - disturb(1); + disturb(); msg_format("%^s drains power from your muscles!", m_name); if (p_ptr->free_act) { @@ -3428,7 +3428,7 @@ static bool_ make_attack_spell(int m_idx) case SF_HOLD_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s stares deep into your eyes!", m_name); if (p_ptr->free_act) @@ -3449,7 +3449,7 @@ static bool_ make_attack_spell(int m_idx) case SF_HASTE_IDX: { - disturb(1); + disturb(); if (blind) { msg_format("%^s mumbles.", m_name); @@ -3478,7 +3478,7 @@ static bool_ make_attack_spell(int m_idx) case SF_HAND_DOOM_IDX: { - disturb(1); + disturb(); msg_format("%^s invokes the Hand of Doom!", m_name); if (rand_int(100) < p_ptr->skill_sav) { @@ -3498,7 +3498,7 @@ static bool_ make_attack_spell(int m_idx) case SF_HEAL_IDX: { - disturb(1); + disturb(); /* Message */ if (blind) @@ -3561,7 +3561,7 @@ static bool_ make_attack_spell(int m_idx) case SF_BLINK_IDX: { - disturb(1); + disturb(); msg_format("%^s blinks away.", m_name); teleport_away(m_idx, 10); break; @@ -3569,7 +3569,7 @@ static bool_ make_attack_spell(int m_idx) case SF_TPORT_IDX: { - disturb(1); + disturb(); msg_format("%^s teleports away.", m_name); teleport_away(m_idx, MAX_SIGHT * 2 + 5); break; @@ -3577,7 +3577,7 @@ static bool_ make_attack_spell(int m_idx) case SF_TELE_TO_IDX: { - disturb(1); + disturb(); msg_format("%^s commands you to return.", m_name); teleport_player_to(m_ptr->fy, m_ptr->fx); break; @@ -3585,7 +3585,7 @@ static bool_ make_attack_spell(int m_idx) case SF_TELE_AWAY_IDX: { - disturb(1); + disturb(); msg_format("%^s teleports you away.", m_name); teleport_player(100); break; @@ -3593,7 +3593,7 @@ static bool_ make_attack_spell(int m_idx) case SF_TELE_LEVEL_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles strangely.", m_name); else msg_format("%^s gestures at your feet.", m_name); if (p_ptr->resist_nexus) @@ -3614,7 +3614,7 @@ static bool_ make_attack_spell(int m_idx) case SF_DARKNESS_IDX: { - disturb(1); + disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s gestures in shadow.", m_name); (void)unlite_area(0, 3); @@ -3623,7 +3623,7 @@ static bool_ make_attack_spell(int m_idx) case SF_FORGET_IDX: { - disturb(1); + disturb(); msg_format("%^s tries to blank your mind.", m_name); if (rand_int(100) < p_ptr->skill_sav) @@ -3781,7 +3781,7 @@ static bool_ make_attack_spell(int m_idx) case SF_S_UNIQUE_IDX: { // Interrupt - disturb(1); + disturb(); // Message if (blind) { @@ -5130,7 +5130,7 @@ static bool_ monst_attack_monst(int m_idx, int t_idx) if (m_ptr->ml) { /* Disturbing */ - disturb(1); + disturb(); /* Message */ monster_msg("%^s misses %s.", m_name, t_name); @@ -5844,7 +5844,7 @@ static void process_monster(int m_idx, bool_ is_frien) /* Disturb (sometimes) */ if (options->disturb_minor) { - disturb(0); + disturb(); } /* The door was bashed open */ @@ -6132,7 +6132,7 @@ static void process_monster(int m_idx, bool_ is_frien) { /* Disturb */ if ((is_friend(m_ptr) < 0) || options->disturb_pets) - disturb(0); + disturb(); } -- cgit v1.2.3 From 128b467fcc9a36fc1f8d1794f8c66ae1a9d08274 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 16 Oct 2016 12:28:53 +0200 Subject: Fix monster spell selection caused by 'missing' TRAPS spell --- src/melee2.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 0988d2af..fbc793bd 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -941,11 +941,11 @@ static std::vector extract_spells(monster_spell_flag_set auto result = std::vector(); result.reserve(spell_flag_set.nbits); - for (std::size_t k = 0; k < monster_spell_flag_set::nbits; k++) + for (auto const &monster_spell: monster_spells()) { - if (spell_flag_set.bit(k)) + if (bool(spell_flag_set & monster_spell->flag_set)) { - result.push_back(monster_spells()[k]); + result.push_back(monster_spell); } } -- cgit v1.2.3 From 6a35e3de332df186eab39c3b67506882409a3ca2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Remove redundant (void) parameters and return value casts --- src/melee2.cc | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index fbc793bd..3ab3cc1c 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -607,7 +607,7 @@ static void bolt(int m_idx, int typ, int dam_hp) int flg = PROJECT_STOP | PROJECT_KILL; /* Target the player with a bolt attack */ - (void)project(m_idx, 0, p_ptr->py, p_ptr->px, dam_hp, typ, flg); + project(m_idx, 0, p_ptr->py, p_ptr->px, dam_hp, typ, flg); } @@ -837,7 +837,7 @@ static void breath(int m_idx, int typ, int dam_hp, int rad) if (rad < 1) rad = (r_ptr->flags & RF_POWERFUL) ? 3 : 2; /* Target the player with a ball attack */ - (void)project(m_idx, rad, p_ptr->py, p_ptr->px, dam_hp, typ, flg); + project(m_idx, rad, p_ptr->py, p_ptr->px, dam_hp, typ, flg); } @@ -856,7 +856,7 @@ static void monst_breath_monst(int m_idx, int y, int x, int typ, int dam_hp, int /* Determine the radius of the blast */ if (rad < 1) rad = (r_ptr->flags & RF_POWERFUL) ? 3 : 2; - (void)project(m_idx, rad, y, x, dam_hp, typ, flg); + project(m_idx, rad, y, x, dam_hp, typ, flg); } @@ -869,7 +869,7 @@ static void monst_bolt_monst(int m_idx, int y, int x, int typ, int dam_hp) { int flg = PROJECT_STOP | PROJECT_KILL; - (void)project(m_idx, 0, y, x, dam_hp, typ, flg); + project(m_idx, 0, y, x, dam_hp, typ, flg); } @@ -883,7 +883,7 @@ static void monster_msg(cptr fmt, ...) va_start(vp, fmt); /* Format the args, save the length */ - (void)vstrnfmt(buf, 1024, fmt, vp); + vstrnfmt(buf, 1024, fmt, vp); /* End the Varargs Stuff */ va_end(vp); @@ -916,7 +916,7 @@ void cmonster_msg(char a, cptr fmt, ...) va_start(vp, fmt); /* Format the args, save the length */ - (void)vstrnfmt(buf, 1024, fmt, vp); + vstrnfmt(buf, 1024, fmt, vp); /* End the Varargs Stuff */ va_end(vp); @@ -2119,7 +2119,7 @@ static bool_ monst_spell_monst(int m_idx) else monster_msg("%^s gestures in shadow.", m_name); if (seen) monster_msg("%^s is surrounded by darkness.", t_name); - (void)project(m_idx, 3, y, x, 0, GF_DARK_WEAK, PROJECT_GRID | PROJECT_KILL); + project(m_idx, 3, y, x, 0, GF_DARK_WEAK, PROJECT_GRID | PROJECT_KILL); /* Lite up the room */ unlite_room(y, x); break; @@ -3103,12 +3103,12 @@ static bool_ make_attack_spell(int m_idx) if (!p_ptr->resist_conf) { - (void)set_confused(p_ptr->confused + rand_int(4) + 4); + set_confused(p_ptr->confused + rand_int(4) + 4); } if ((!p_ptr->resist_chaos) && (randint(3) == 1)) { - (void) set_image(p_ptr->image + rand_int(250) + 150); + set_image(p_ptr->image + rand_int(250) + 150); } take_sanity_hit(damroll(8, 8), ddesc); @@ -3138,26 +3138,26 @@ static bool_ make_attack_spell(int m_idx) take_sanity_hit(damroll(12, 15), ddesc); if (!p_ptr->resist_blind) { - (void)set_blind(p_ptr->blind + 8 + rand_int(8)); + set_blind(p_ptr->blind + 8 + rand_int(8)); } if (!p_ptr->resist_conf) { - (void)set_confused(p_ptr->confused + rand_int(4) + 4); + set_confused(p_ptr->confused + rand_int(4) + 4); } if (!p_ptr->free_act) { - (void)set_paralyzed(rand_int(4) + 4); + set_paralyzed(rand_int(4) + 4); } - (void)set_slow(p_ptr->slow + rand_int(4) + 4); + set_slow(p_ptr->slow + rand_int(4) + 4); while (rand_int(100) > p_ptr->skill_sav) - (void)do_dec_stat(A_INT, STAT_DEC_NORMAL); + do_dec_stat(A_INT, STAT_DEC_NORMAL); while (rand_int(100) > p_ptr->skill_sav) - (void)do_dec_stat(A_WIS, STAT_DEC_NORMAL); + do_dec_stat(A_WIS, STAT_DEC_NORMAL); if (!p_ptr->resist_chaos) { - (void) set_image(p_ptr->image + rand_int(250) + 150); + set_image(p_ptr->image + rand_int(250) + 150); } } break; @@ -3226,7 +3226,7 @@ static bool_ make_attack_spell(int m_idx) else { take_hit(damroll(15, 15), ddesc); - (void)set_cut(p_ptr->cut + damroll(10, 10)); + set_cut(p_ptr->cut + damroll(10, 10)); } break; } @@ -3358,7 +3358,7 @@ static bool_ make_attack_spell(int m_idx) } else { - (void)set_afraid(p_ptr->afraid + rand_int(4) + 4); + set_afraid(p_ptr->afraid + rand_int(4) + 4); } update_smart_learn(m_idx, DRS_FEAR); break; @@ -3379,7 +3379,7 @@ static bool_ make_attack_spell(int m_idx) } else { - (void)set_blind(12 + rand_int(4)); + set_blind(12 + rand_int(4)); } update_smart_learn(m_idx, DRS_BLIND); break; @@ -3400,7 +3400,7 @@ static bool_ make_attack_spell(int m_idx) } else { - (void)set_confused(p_ptr->confused + rand_int(4) + 4); + set_confused(p_ptr->confused + rand_int(4) + 4); } update_smart_learn(m_idx, DRS_CONF); break; @@ -3420,7 +3420,7 @@ static bool_ make_attack_spell(int m_idx) } else { - (void)set_slow(p_ptr->slow + rand_int(4) + 4); + set_slow(p_ptr->slow + rand_int(4) + 4); } update_smart_learn(m_idx, DRS_FREE); break; @@ -3441,7 +3441,7 @@ static bool_ make_attack_spell(int m_idx) } else { - (void)set_paralyzed(rand_int(4) + 4); + set_paralyzed(rand_int(4) + 4); } update_smart_learn(m_idx, DRS_FREE); break; @@ -3617,7 +3617,7 @@ static bool_ make_attack_spell(int m_idx) disturb(); if (blind) msg_format("%^s mumbles.", m_name); else msg_format("%^s gestures in shadow.", m_name); - (void)unlite_area(0, 3); + unlite_area(0, 3); break; } @@ -4443,7 +4443,7 @@ static bool_ get_moves(int m_idx, int *mm) if (options->flow_by_sound) { /* Adjust movement */ - (void)get_fear_moves_aux(m_idx, &y, &x); + get_fear_moves_aux(m_idx, &y, &x); } } } @@ -5974,7 +5974,7 @@ static void process_monster(int m_idx, bool_ is_frien) if (do_move && (ny == p_ptr->py) && (nx == p_ptr->px)) { /* Do the attack */ - (void)make_attack_normal(m_idx, 1); + make_attack_normal(m_idx, 1); /* Do not move */ do_move = FALSE; @@ -6370,7 +6370,7 @@ void summon_maint(int m_idx) * changes (flags, attacks, spells), we induce a redraw of the monster * recall window. */ -void process_monsters(void) +void process_monsters() { auto const &r_info = game->edit_data.r_info; -- cgit v1.2.3 From 554ff9a63d5d9bc64f668a00b6baa9b91dc41306 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 13 Jun 2017 18:24:42 +0200 Subject: Move "messages" to Game struct --- src/melee2.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 3ab3cc1c..10807b44 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -894,6 +894,8 @@ static void monster_msg(cptr fmt, ...) void monster_msg_simple(cptr s) { + auto &messages = game->messages; + /* Display */ if (options->disturb_other) { @@ -901,7 +903,7 @@ void monster_msg_simple(cptr s) } else { - message_add(s, TERM_WHITE); + messages.add(s, TERM_WHITE); p_ptr->window |= PW_MESSAGE; } } @@ -910,6 +912,7 @@ void cmonster_msg(char a, cptr fmt, ...) { va_list vp; + auto &messages = game->messages; char buf[1024]; /* Begin the Varargs Stuff */ @@ -928,7 +931,7 @@ void cmonster_msg(char a, cptr fmt, ...) } else { - message_add(buf, a); + messages.add(buf, a); p_ptr->window |= PW_MESSAGE; } } -- cgit v1.2.3 From 6f14a3a6846868dc07e60ba1350ffe0cea5ad4ae Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 13 Jun 2017 18:24:42 +0200 Subject: Clean up cmonster_msg() --- src/melee2.cc | 66 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 37 deletions(-) (limited to 'src/melee2.cc') diff --git a/src/melee2.cc b/src/melee2.cc index 10807b44..d769355a 100644 --- a/src/melee2.cc +++ b/src/melee2.cc @@ -56,7 +56,6 @@ #define FOLLOW_DISTANCE 6 -static void cmonster_msg(char a, cptr fmt, ...); /* * Based on mon_take_hit... all monster attacks on @@ -66,6 +65,28 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) { monster_type *m_ptr = &m_list[m_idx], *s_ptr = &m_list[s_idx]; + /* Output */ + auto cmonster_msg = [m_ptr](std::string const &suffix) { + auto &messages = game->messages; + // Build monster name + char m_name[80]; + monster_desc(m_name, m_ptr, 0); + capitalize(m_name); + // Add suffix + auto msg = std::string(m_name); + msg += suffix; + // Display + if (options->disturb_other) + { + cmsg_print(TERM_L_RED, msg); + } + else + { + messages.add(msg, TERM_L_RED); + p_ptr->window |= PW_MESSAGE; + } + }; + /* Redraw (later) if needed */ if (health_who == m_idx) p_ptr->redraw |= (PR_FRAME); @@ -89,18 +110,17 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) } else { - char m_name[80]; s32b dive = s_ptr->level; - if (!dive) dive = 1; - - /* Extract monster name */ - monster_desc(m_name, m_ptr, 0); + if (!dive) + { + dive = 1; + } /* Death by Missile/Spell attack */ if (note) { - cmonster_msg(TERM_L_RED, "%^s%s", m_name, note); + cmonster_msg(note); } /* Death by Physical attack -- living monster */ else if (!m_ptr->ml) @@ -114,11 +134,11 @@ bool_ mon_take_hit_mon(int s_idx, int m_idx, int dam, bool_ *fear, cptr note) (r_ptr->flags & RF_NONLIVING) || (strchr("Evg", r_ptr->d_char))) { - cmonster_msg(TERM_L_RED, "%^s is destroyed.", m_name); + cmonster_msg(" is destroyed."); } else { - cmonster_msg(TERM_L_RED, "%^s is killed.", m_name); + cmonster_msg(" is killed."); } dive = r_ptr->mexp * m_ptr->level / dive; @@ -908,34 +928,6 @@ void monster_msg_simple(cptr s) } } -void cmonster_msg(char a, cptr fmt, ...) -{ - va_list vp; - - auto &messages = game->messages; - char buf[1024]; - - /* Begin the Varargs Stuff */ - va_start(vp, fmt); - - /* Format the args, save the length */ - vstrnfmt(buf, 1024, fmt, vp); - - /* End the Varargs Stuff */ - va_end(vp); - - /* Display */ - if (options->disturb_other) - { - cmsg_print(a, buf); - } - else - { - messages.add(buf, a); - p_ptr->window |= PW_MESSAGE; - } -} - /** * Extract list of spell indexes from a flag set. */ -- cgit v1.2.3