Crossfire Server, Trunk
spell_util.cpp File Reference
#include "global.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "living.h"
#include "object.h"
#include "sounds.h"
#include "spells.h"
#include "sproto.h"
#include "assets.h"
#include "AssetsManager.h"
+ Include dependency graph for spell_util.cpp:

Go to the source code of this file.

Functions

static int can_be_transmuted_to_flower (object *op)
 
int cast_create_obj (object *op, object *new_op, int dir)
 
int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
 
int caster_level (const object *caster, const object *spell)
 
void check_spell_expiry (object *spell)
 
objectcheck_spell_known (object *op, const char *name)
 
void drain_rod_charge (object *rod)
 
void drain_wand_charge (object *wand)
 
void dump_spells (void)
 
objectfind_random_spell_in_ob (object *ob, const char *skill)
 
objectfind_target_for_friendly_spell (object *op, int dir)
 
int fire_arch_from_position (object *op, object *caster, int16_t x, int16_t y, int dir, object *spell)
 
static void handle_spell_confusion (object *op)
 
objectlookup_spell_by_name (object *op, const char *spname)
 
int min_casting_level (const object *caster, const object *spell)
 
int ok_to_put_more (mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop)
 
static void prayer_failure (object *op, int failure, int power)
 
static int put_a_monster (object *op, const char *monstername)
 
int reflwall (mapstruct *m, int x, int y, object *sp_op)
 
void regenerate_rod (object *rod)
 
void rod_adjust (object *rod)
 
void set_spell_skill (object *op, object *caster, object *spob, object *dest)
 
void shuffle_attack (object *op)
 
int SP_level_dam_adjust (const object *caster, const object *spob)
 
int SP_level_duration_adjust (const object *caster, const object *spob)
 
int SP_level_range_adjust (const object *caster, const object *spob)
 
int16_t SP_level_spellpoint_cost (object *caster, object *spell, int flags)
 
int SP_level_wc_adjust (const object *caster, const object *spob)
 
static int spell_consume_items (object *op, const object *spell_ob)
 
void spell_effect (object *spob, int x, int y, mapstruct *map, object *originator)
 
void spell_failure (object *op, int failure, int power, object *skill)
 
int spell_find_dir (mapstruct *m, int x, int y, object *exclude)
 
void store_spell_expiry (object *spell)
 
int summon_hostile_monsters (object *op, int n, const char *monstername)
 
static void swap_random_stats (object *op)
 
static void transmute_item_to_flower (object *op)
 

Detailed Description

Spell-related helper functions.

Definition in file spell_util.cpp.

Function Documentation

◆ can_be_transmuted_to_flower()

static int can_be_transmuted_to_flower ( object op)
static

Determines if an item can be transmuted after a cast failure.

Parameters
opitem to check.
Returns
1 if op can be transmuted, 0 else.
Note
can_be_tansmuted() has been renamed to can_be_transmuted_to_flower()

Definition at line 1161 of file spell_util.cpp.

References give::op, POTION, ROD, SCROLL, WAND, and WEAPON.

Referenced by transmute_item_to_flower().

+ Here is the caller graph for this function:

◆ cast_create_obj()

int cast_create_obj ( object op,
object new_op,
int  dir 
)

Creates object new_op in direction dir or if that is blocked, beneath the player (op). This is really just a simple wrapper function .

Parameters
opwho is casting.
new_opobject to insert.
dirdirection to insert into. Can be 0 to insert below.
Returns
direction that the object was actually placed in.

Definition at line 494 of file spell_util.cpp.

References draw_ext_info(), freearr_x, freearr_y, get_map_flags(), GET_MAP_MOVE_BLOCK, INS_BELOW_ORIGINATOR, m, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, NDI_UNIQUE, OB_TYPE_MOVE_BLOCK, object_insert_in_map_at(), give::op, and P_OUT_OF_MAP.

Referenced by cast_create_food(), cast_create_missile(), cast_create_town_portal(), and cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cast_spell()

int cast_spell ( object op,
object caster,
int  dir,
object spell_ob,
char *  stringarg 
)

Main dispatch when someone casts a spell.

Will decrease mana/gr points, check for skill, confusion and such.

Note that this function is really a dispatch routine that calls other functions - it just blindly returns what ever value those functions return. So if your writing a new function that is called from this, it should also return 1 on success, 0 on failure.

if it is a player casting the spell (op->type == PLAYER, op == caster), this function will decrease the mana/grace appropriately. For other objects, the caller should do what it considers appropriate.

Parameters
opcreature that is owner of the object that is casting the spell - eg, the player or monster.
casteractual object (wand, potion) casting the spell. can be same as op.
dirdirection to cast in. Note in some cases, if the spell is self only, dir really doesn't make a difference.
spell_obspell object that is being cast. From that, we can determine what to do. *
stringargany options that are being used. It can be NULL. Almost certainly, only players will set it. It is basically used as optional parameters to a spell (eg, item to create, information for marking runes, etc.
Returns
1 on successful cast, or 0 on error. These values should really be swapped, so that 0 is successful, and non zero is failure, with a code of what it failed.
Todo:
return a failure value?

Definition at line 1424 of file spell_util.cpp.

References alchemy(), object::anim_suffix, animate_weapon(), apply_anim_suffix(), object::arch, ARCH_SPELL_BLOCKED, ARCH_SPELL_BUNGLE, cast_bless(), cast_cause_disease(), cast_change_ability(), cast_change_map_lightlevel(), cast_cone(), cast_consecrate(), cast_create_food(), cast_create_missile(), cast_create_obj(), cast_create_town_portal(), cast_curse(), cast_destruction(), cast_detection(), cast_earth_to_dust(), cast_heal(), cast_identify(), cast_invisible(), cast_item_curse_or_bless(), cast_light(), cast_polymorph(), cast_raise_dead_spell(), cast_smite_spell(), cast_transfer(), cast_wonder(), cast_word_of_recall(), caster_level(), Settings::casting_time, object::casting_time, change_skill(), create_archetype(), create_aura(), create_bomb(), determine_god(), dimension_door(), dispel_rune(), draw_ext_info(), draw_ext_info_format(), draw_magic_map(), FABS, find_random_spell_in_ob(), find_skill_by_name(), fire_arch_from_position(), fire_bolt(), fire_swarm(), FIREWALL, FLAG_ALIVE, FLAG_CONFUSED, FLAG_MONSTER, FLAG_WIZ, FLAG_WIZCAST, freearr_x, freearr_y, get_cleric_chance(), get_map_flags(), living::grace, handle_spell_confusion(), make_face_from_files::int, object::level, llevError, LOG(), magic_wall(), MAX, MAX_BUF, min_casting_level(), mood_change(), MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, MSG_TYPE_SKILL_MISSING, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, MSG_TYPE_SPELL_FAILURE, MSG_TYPE_SPELL_INFO, give::name, object::name, NDI_UNIQUE, object_get_owner(), give::op, P_NO_CLERIC, P_NO_MAGIC, object::path_attuned, object::path_denied, object::path_repelled, PATH_TIME_MULT, perceive_self(), pets_summon_golem(), pets_summon_object(), play_sound_map(), play_sound_player_only(), PLAYER, POTION, prayer_failure(), PREFER_HIGH, PREFER_LOW, probe(), QUERY_FLAG, query_name(), random_roll(), range_golem, range_magic, range_misc, range_none, recharge(), remove_curse(), rndm(), ROD, RUNE, SCROLL, settings, object::skill, SOUND_TYPE_SPELL, living::sp, SP_ALCHEMY, SP_ANIMATE_WEAPON, SP_AURA, SP_BLESS, SP_BOLT, SP_BOMB, SP_BULLET, SP_CAUSE_DISEASE, SP_CHANGE_ABILITY, SP_CHANGE_MANA, SP_CHANGE_MAP_LIGHT, SP_CHARGING, SP_CONE, SP_CONSECRATE, SP_CREATE_FOOD, SP_CREATE_MISSILE, SP_CURSE, SP_DESTRUCTION, SP_DETECTION, SP_DIMENSION_DOOR, SP_DISPEL_RUNE, SP_EARTH_TO_DUST, SP_ELEM_SHIELD, SP_FAERY_FIRE, SP_HEALING, SP_IDENTIFY, SP_INVISIBLE, SP_ITEM_CURSE_BLESS, SP_level_spellpoint_cost(), SP_LIGHT, SP_MAGIC_MAPPING, SP_MAGIC_MISSILE, SP_MAGIC_WALL, SP_MAKE_MARK, SP_MOOD_CHANGE, SP_MOVING_BALL, SP_PERCEIVE_SELF, SP_POLYMORPH, SP_PROBE, SP_RAISE_DEAD, SP_REMOVE_CURSE, SP_RUNE, SP_SMITE, SP_SUMMON_GOLEM, SP_SUMMON_MONSTER, SP_SWARM, SP_TOWN_PORTAL, SP_WONDER, SP_WORD_OF_RECALL, SPELL, spell_consume_items(), spell_effect(), spell_failure(), Settings::spell_failure_effects, SPELL_GRACE, SPELL_MANA, object::stats, strdup_local, object::subtype, TRUE, object::type, WAND, write_mark(), and write_rune().

Referenced by altar_type_move_on(), cast_dust(), cast_wonder(), cfapi_object_cast(), command_cast_spell(), fire(), fire_misc_object(), monster_cast_spell(), monster_use_range(), move_aura(), move_firewall(), potion_type_apply(), scroll_type_apply(), spring_trap(), and START_TEST().

+ Here is the caller graph for this function:

◆ caster_level()

int caster_level ( const object caster,
const object spell 
)

This function returns the effective level the spell is being cast at. Note that I changed the repelled/attuned bonus to 2 from 5. This is because the new code compares casting_level against min_caster_level, so the difference is effectively 4

Parameters
casterperson casting the spell.
spellspell object.
Returns
adjusted level.

Definition at line 194 of file spell_util.cpp.

References find_applied_skill_by_name(), object::level, level, object::path_attuned, object::path_repelled, PLAYER, object::skill, and object::type.

Referenced by animate_weapon(), cast_cause_disease(), cast_cone(), cast_consecrate(), cast_create_town_portal(), cast_detection(), cast_polymorph(), cast_raise_dead_spell(), cast_smite_spell(), cast_spell(), cast_transfer(), charge_mana_effect(), create_aura(), fire_arch_from_position(), fire_swarm(), magic_wall(), mood_change(), pets_summon_golem(), pets_summon_object(), remove_curse(), SP_level_dam_adjust(), SP_level_duration_adjust(), SP_level_range_adjust(), SP_level_spellpoint_cost(), SP_level_wc_adjust(), and write_rune().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_spell_expiry()

void check_spell_expiry ( object spell)

Checks if player should be warned of soon expiring spell.

Should be called at each move of the spell. Will use key stored by store_spell_expiry(). If the spell effect/force isn't in a player's inventory, won't do anything.

Parameters
spellforce or spell whose effects will expire.

Definition at line 2006 of file spell_util.cpp.

References draw_ext_info_format(), object::duration, object::env, IS_PLAYER(), castle_read::key, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN, object::name, NDI_NAVY, NDI_UNIQUE, and object_get_value().

Referenced by move_aura(), and remove_force().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_spell_known()

object* check_spell_known ( object op,
const char *  name 
)

Checks to see if player knows the spell. If the name is the same as an existing spell, we presume they know it.

Parameters
opobject we're looking into.
namespell name. Doesn't need to be a shared string.
Returns
1 if op knows the spell, 0 if it don't.

Definition at line 394 of file spell_util.cpp.

References give::name, object_find_by_type_and_name(), give::op, and SPELL.

Referenced by cfapi_object_check_spell(), command_learn_spell_or_prayer(), do_forget_spell(), do_learn_spell(), dragon_ability_gain(), god_intervention(), and spellbook_type_apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drain_rod_charge()

void drain_rod_charge ( object rod)

Drain charges from a rod.

Parameters
rodrod to drain.

Definition at line 776 of file spell_util.cpp.

References living::hp, object::inv, SP_level_spellpoint_cost(), SPELL_HIGHEST, and object::stats.

Referenced by fire_misc_object(), and monster_use_range().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drain_wand_charge()

void drain_wand_charge ( object wand)

Drains a charge from a wand. Handles animation fix, and player update if required.

Parameters
wandwand to drain. Must be of type WAND.

Definition at line 786 of file spell_util.cpp.

References object::arch, CLEAR_FLAG, archetype::clone, esrv_update_item(), object::face, FLAG_ANIMATE, living::food, object_get_player_container(), object_update_speed(), object::speed, object::stats, Ice::tmp, object::type, UPD_ANIM, and WAND.

Referenced by fire_misc_object(), and monster_use_range().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dump_spells()

void dump_spells ( void  )

Dumps all the spells - now also dumps skill associated with the spell. not sure what this would be used for, as the data seems pretty minimal, but easy enough to keep around.

Definition at line 108 of file spell_util.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), getManager(), and SPELL.

Referenced by init_beforeplay().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_random_spell_in_ob()

object* find_random_spell_in_ob ( object ob,
const char *  skill 
)

This returns a random spell from 'ob'. If skill is set, then the spell must be of this skill, it can be NULL in which case all matching spells are used.

Parameters
obobject to find spells in.
skillskill the spell should match, NULL if can match any spell.
Returns
random spell, or NULL if none found.
Todo:
change skill to sstring.

Definition at line 48 of file spell_util.cpp.

References FOR_INV_FINISH, FOR_INV_PREPARE, guildjoin::ob, RANDOM, SPELL, and Ice::tmp.

Referenced by cast_spell(), and write_scroll().

+ Here is the caller graph for this function:

◆ find_target_for_friendly_spell()

object* find_target_for_friendly_spell ( object op,
int  dir 
)

This function is commonly used to find a friendly target for spells such as heal or protection or armour

Parameters
opwhat is looking for the target (which can be a player).
dirdirection we are looking in.
Returns
object found, or NULL if no good object.

Definition at line 813 of file spell_util.cpp.

References FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, get_map_flags(), GET_MAP_OB, commongive::inv, m, object_get_owner(), give::op, P_OUT_OF_MAP, PLAYER, QUERY_FLAG, RUNE, Ice::tmp, TRANSPORT, diamondslots::x, and diamondslots::y.

Referenced by cast_bless(), cast_change_ability(), and cast_heal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fire_arch_from_position()

int fire_arch_from_position ( object op,
object caster,
int16_t  x,
int16_t  y,
int  dir,
object spell 
)

Fires an archetype.

Note
it uses op->map for the map for these coordinates, which is probably a really bad idea.
Parameters
opperson firing the object.
casterobject casting the spell.
x
ywhere to fire the spell.
dirdirection to fire in.
spellspell that is being fired. It uses other_arch for the archetype to fire.
Returns
0 on failure, 1 on success.
Todo:
check the note?

Definition at line 629 of file spell_util.cpp.

References absdir(), add_refcount(), arch_to_object(), AT_GODPOWER, AT_HOLYWORD, object::attacktype, caster_level(), check_bullet(), living::dam, DIRX, DIRY, draw_ext_info(), object::duration, FLAG_REFLECTING, living::food, get_map_flags(), GET_MAP_MOVE_BLOCK, llevError, LOG(), m, MSG_TYPE_SPELL, MSG_TYPE_SPELL_ERROR, object::name, NDI_UNIQUE, ob_process(), OB_TYPE_MOVE_BLOCK, object_copy_owner(), object_free_drop_inventory(), object_get_owner(), object_insert_in_map_at(), object_set_owner(), object_update_turn_face(), give::op, object::other_arch, P_OUT_OF_MAP, PLAYER, QUERY_FLAG, RANDOM, object::range, set_spell_skill(), object::slaying, SP_BULLET, SP_level_dam_adjust(), SP_level_duration_adjust(), SP_level_range_adjust(), SP_MAGIC_MISSILE, SP_MOVING_BALL, SPELL, object::stats, object::subtype, tailor_god_spell(), Ice::tmp, object::type, diamondslots::x, and diamondslots::y.

Referenced by alchemy_failure_effect(), cast_spell(), and move_swarm_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handle_spell_confusion()

static void handle_spell_confusion ( object op)
static

This does a random effect for op, which tried to cast a spell in a confused state.

Note that random spell casting is handled in cast_spell itself.

Used for spell casting when confused.

Parameters
opplayer for which to produce a random effect.

Definition at line 1289 of file spell_util.cpp.

References give::op, RANDOM, swap_random_stats(), and transmute_item_to_flower().

Referenced by cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookup_spell_by_name()

object* lookup_spell_by_name ( object op,
const char *  spname 
)

Look at object 'op' and see if they know the spell spname. This is pretty close to check_spell_known above, but it uses a looser matching mechanism.

Parameters
opobject we're searching the inventory.
spnamepartial spell name.
Returns
matching spell object, or NULL. If we match multiple spells but don't get an exact match, we also return NULL.

Definition at line 410 of file spell_util.cpp.

References FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), give::op, and SPELL.

Referenced by command_cast_spell(), and command_forget_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ min_casting_level()

int min_casting_level ( const object caster,
const object spell 
)

This function takes a caster and spell and presents the effective level the caster needs to be to cast the spell. Basically, it just adjusts the spell->level with attuned/repelled spellpaths.

Parameters
casterperson casting the spell.
spellspell object.
Returns
adjusted level.

Definition at line 164 of file spell_util.cpp.

References object::level, MAX, object::path_attuned, object::path_denied, and object::path_repelled.

Referenced by cast_spell(), SP_level_dam_adjust(), SP_level_duration_adjust(), SP_level_range_adjust(), and SP_level_wc_adjust().

+ Here is the caller graph for this function:

◆ ok_to_put_more()

int ok_to_put_more ( mapstruct m,
int16_t  x,
int16_t  y,
object op,
uint32_t  immune_stop 
)

Returns true if it is ok to put spell op on the space/may provided.

Parameters
m
x
ycoordinates to test.
opspell to test for.
immune_stopbasically the attacktype of the spell (why passed as a different value, not sure of). If immune_stop has the AT_MAGIC bit set, and there is a counterwall on the space, the object doesn't get placed. if immune_stop does not have AT_MAGIC, then counterwalls do not effect the spell.
Returns
1 if we can add op, 0 else.

Definition at line 530 of file spell_util.cpp.

References ARROW, AT_COUNTERSPELL, AT_MAGIC, BOW, FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, get_map_flags(), GET_MAP_MOVE_BLOCK, GOLEM, m, OB_SPELL_TAG_MATCH, OB_TYPE_MOVE_BLOCK, give::op, P_OUT_OF_MAP, PLAYER, QUERY_FLAG, Statistics::spell_suppressions, SPELL_TAG_SIZE, statistics, Ice::tmp, WEAPON, diamondslots::x, and diamondslots::y.

Referenced by explosion(), and move_cone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prayer_failure()

static void prayer_failure ( object op,
int  failure,
int  power 
)
static

Called when a player fails at casting a prayer.

Parameters
opplayer.
failurebasically how much grace they had.
powerhow much grace the spell would normally take to cast.

Definition at line 1052 of file spell_util.cpp.

References cast_cone(), cast_magic_storm(), confuse_living(), create_archetype(), determine_god(), draw_ext_info(), draw_ext_info_format(), GOD_POWER, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, NDI_UNIQUE, object_free_drop_inventory(), give::op, paralyze_living(), SPELL_WONDER, and Ice::tmp.

Referenced by cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ put_a_monster()

static int put_a_monster ( object op,
const char *  monstername 
)
static

Puts a monster named monstername near by op. This creates the treasures for the monsters, and also deals with multipart monsters properly.

Parameters
opvictim.
monsternamemonster's archetype name.
Returns
1 if a monster was put, 0 else (no free space around the spot or invalid monster name).
Todo:
there is a multipart-aware archetype conversion function, use it.

Definition at line 939 of file spell_util.cpp.

References arch_to_object(), archetype::clone, create_archetype(), create_treasure(), freearr_x, freearr_y, GT_INVISIBLE, object::more, archetype::more, object_find_first_free_spot(), object_insert_in_map_at(), give::op, object::randomitems, Ice::tmp, try_find_archetype(), object::x, and object::y.

Referenced by summon_hostile_monsters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reflwall()

int reflwall ( mapstruct m,
int  x,
int  y,
object sp_op 
)

Decides weither the (spell-)object sp_op will be reflected from the given mapsquare. Returns 1 if true.

(Note that for living creatures there is a small chance that reflect_spell fails.)

Caller should be sure it passes us valid map coordinates eg, updated for tiled maps.

Parameters
m
x
yposition of the object to test.
sp_opspell object to test.
Returns
1 if reflected, 0 else.

Definition at line 470 of file spell_util.cpp.

References FLAG_ALIVE, FLAG_REFL_SPELL, FOR_MAP_FINISH, FOR_MAP_PREPARE, object::level, m, give::op, OUT_OF_REAL_MAP, QUERY_FLAG, rndm(), diamondslots::x, and diamondslots::y.

Referenced by move_bolt(), and move_bullet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regenerate_rod()

void regenerate_rod ( object rod)

Regenerates a rod's charges.

Parameters
rodrod to regenerate.

Definition at line 761 of file spell_util.cpp.

References living::hp, living::maxhp, and object::stats.

Referenced by legacy_ob_process().

+ Here is the caller graph for this function:

◆ rod_adjust()

void rod_adjust ( object rod)

Adjusts rod attributes. This function must be called after a new rod has been created.

Parameters
rodthe rod to update

Definition at line 2037 of file spell_util.cpp.

References living::hp, object::inv, object::level, MAX, living::maxhp, SP_level_spellpoint_cost(), SPELL_HIGHEST, object::stats, and object::value.

+ Here is the call graph for this function:

◆ set_spell_skill()

void set_spell_skill ( object op,
object caster,
object spob,
object dest 
)

Utility function to assign the correct skill when casting.

Relatively simple function that gets used a lot. Basically, it sets up the skill pointer for the spell being cast. If op is really casting the spell, then the skill is whatever skill the spell requires. if instead caster (rod, horn, wand, etc) is casting the skill, then they get exp for the skill that you need to use for that object (use magic device).

Parameters
opobject casting the spell.
casterobject used to cast the spell (rod, wand, ...).
spobspell object.
destobject to set the skill for.

Definition at line 94 of file spell_util.cpp.

References add_refcount(), convert::dest, FREE_AND_CLEAR_STR, give::op, and object::skill.

Referenced by animate_weapon(), cast_cause_disease(), cast_cone(), cast_smite_spell(), create_aura(), create_bomb(), fire_arch_from_position(), fire_bolt(), fire_swarm(), magic_wall(), mood_change(), pets_summon_golem(), pets_summon_object(), and write_rune().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shuffle_attack()

void shuffle_attack ( object op)

This routine shuffles the attack of op to one of the ones in the list. It does this at random. It also chooses a face appropriate to the attack that is being committed by that square at the moment.

It's being used by color spray and create pool of chaos.

Note
This could really be a better implementation - the faces and attacktypes above are hardcoded, which is never good. The faces refer to faces in the animation sequence. Not sure how to do better - but not having it hardcoded would be nice.
Parameters
opobject to change.

Definition at line 1033 of file spell_util.cpp.

References AT_MAGIC, ATTACKS, Chaos_Attacks::attacktype, give::op, rndm(), and SET_ANIMATION.

Referenced by hit_map().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SP_level_dam_adjust()

int SP_level_dam_adjust ( const object caster,
const object spob 
)

Returns adjusted damage based on the caster.

Parameters
casterwho is casting.
spobspell we are adjusting.
Returns
adjusted damage.

Definition at line 287 of file spell_util.cpp.

References caster_level(), object::dam_modifier, and min_casting_level().

Referenced by alchemy(), animate_weapon(), append_spell(), cast_cause_disease(), cast_change_ability(), cast_cone(), cast_create_missile(), cast_destruction(), cast_identify(), cast_light(), cast_smite_spell(), cast_transfer(), create_aura(), create_bomb(), esrv_update_spells(), fire_arch_from_position(), fire_bolt(), magic_wall(), pets_summon_golem(), pets_summon_object(), and recharge().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SP_level_duration_adjust()

int SP_level_duration_adjust ( const object caster,
const object spob 
)

Adjust the duration of the spell based on level. This is basically the same as SP_level_dam_adjust() above, but instead looks at the level_modifier value.

Parameters
casterwho is casting.
spobspell we are adjusting.
Returns
adjusted duration.

Definition at line 312 of file spell_util.cpp.

References caster_level(), object::duration_modifier, and min_casting_level().

Referenced by alchemy(), animate_weapon(), cast_bless(), cast_cause_disease(), cast_change_ability(), cast_cone(), cast_create_food(), cast_create_missile(), cast_curse(), cast_destruction(), cast_invisible(), cast_light(), cast_word_of_recall(), create_aura(), create_bomb(), fire_arch_from_position(), fire_bolt(), fire_swarm(), magic_wall(), and pets_summon_golem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SP_level_range_adjust()

int SP_level_range_adjust ( const object caster,
const object spob 
)

Adjust the range of the spell based on level. This is basically the same as SP_level_dam_adjust() above, but instead looks at the level_modifier value.

Parameters
casterwho is casting.
spobspell we are adjusting.
Returns
adjusted range.

Definition at line 338 of file spell_util.cpp.

References caster_level(), min_casting_level(), and object::range_modifier.

Referenced by animate_weapon(), cast_cause_disease(), cast_cone(), cast_destruction(), cast_detection(), cast_earth_to_dust(), cast_light(), cast_polymorph(), cast_smite_spell(), create_aura(), create_bomb(), dimension_door(), fire_arch_from_position(), fire_bolt(), magic_wall(), mood_change(), pets_summon_golem(), and probe().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SP_level_spellpoint_cost()

int16_t SP_level_spellpoint_cost ( object caster,
object spell,
int  flags 
)

Scales the spellpoint cost of a spell by it's increased effectiveness. Some of the lower level spells become incredibly vicious at high levels. Very cheap mass destruction. This function is intended to keep the sp cost related to the effectiveness.

Note that it is now possible for a spell to cost both grace and mana. In that case, we return which ever value is higher.

Parameters
casterwhat is casting the spell.
spellspell object.
flagsone of Spell/grace points.
Returns
sp/mana points cost.

Definition at line 236 of file spell_util.cpp.

References caster_level(), flags, living::grace, make_face_from_files::int, object::level, llevError, LOG(), MAX, living::maxgrace, living::maxsp, PATH_SP_MULT, settings, living::sp, SPELL_GRACE, SPELL_HIGHEST, SPELL_MANA, Settings::spellpoint_level_depend, object::stats, and TRUE.

Referenced by append_spell(), cast_spell(), drain_rod_charge(), esrv_update_spells(), examine_rod_charge_level(), fire_misc_object(), monster_cast_spell(), rod_adjust(), show_matching_spells(), write_rune(), and write_scroll().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SP_level_wc_adjust()

int SP_level_wc_adjust ( const object caster,
const object spob 
)

Returns adjusted wc based on the caster and the spell.

Parameters
casterwho is casting.
spobspell we are adjusting.
Returns
adjusted wc (positive is best).

Definition at line 362 of file spell_util.cpp.

References caster_level(), min_casting_level(), object_get_value(), and sstring.

Referenced by pets_summon_golem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spell_consume_items()

static int spell_consume_items ( object op,
const object spell_ob 
)
static

Check if the player attempting to cast a spell has the required items, and eat those. Will warn of insufficient resources if failure. Only eats if all items are found, else don't do anything.

Parameters
opwho is casting.
spell_obspell being cast.
Returns
0 if some items were missing, and warn player, 1 if all if ok.

Definition at line 1308 of file spell_util.cpp.

References bigchest::check, disinfect::count, draw_ext_info_format(), FOR_INV_FINISH, FOR_INV_PREPARE, is_valid_types_gen::found, MAX_BUF, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, NDI_UNIQUE, object_decrease_nrof(), object_get_value(), give::op, PLAYER, split_string(), sstring, and strdup_local.

Referenced by cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spell_effect()

void spell_effect ( object spob,
int  x,
int  y,
mapstruct map,
object originator 
)

Inserts into map a spell effect based on other_arch.

Parameters
spobspell object to insert object from.
x
y
mapcoordinates to put the effect at.
originatorwhat causes the effect to be inserted. Can be NULL.

Definition at line 144 of file spell_util.cpp.

References arch_to_object(), disinfect::map, object_insert_in_map_at(), object::other_arch, diamondslots::x, and diamondslots::y.

Referenced by cast_identify(), and cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spell_failure()

void spell_failure ( object op,
int  failure,
int  power,
object skill 
)

Handles the various effects for differing degrees of failure badness.

Parameters
opplayer that failed.
failurerandom value of how badly you failed.
powerhow many spellpoints you'd normally need for the spell.
skillskill needed to cast the spell.

Definition at line 1103 of file spell_util.cpp.

References AT_INTERNAL, cast_cone(), confuse_living(), create_archetype(), draw_ext_info(), FALSE, get_map_flags(), hit_player(), isqrt(), object::level, LOOSE_MANA, MSG_TYPE_SPELL, MSG_TYPE_SPELL_FAILURE, NDI_UNIQUE, object_free_drop_inventory(), object_insert_in_map_at(), give::op, P_NO_MAGIC, paralyze_living(), settings, Settings::spell_failure_effects, SPELL_WONDER, and Ice::tmp.

Referenced by cast_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spell_find_dir()

int spell_find_dir ( mapstruct m,
int  x,
int  y,
object exclude 
)

Search what direction a spell should go in, first the center square then some close squares in the given map at the given coordinates for live objects.

It will not consider the object given as exclude (= caster) among possible live objects. If the caster is a player, the spell will go after monsters/generators only. If not, the spell will hunt players only.

Exception is player on a battleground, who will be targeted unless excluded.

Parameters
m
x
ywhere to search from.
excludewhat object to avoid. Can be NULL, in which case all bets are off.
Returns
direction toward the first/closest live object if it finds any, otherwise -1.

Definition at line 887 of file spell_util.cpp.

References can_see_monsterP(), FLAG_GENERATOR, FLAG_MONSTER, freearr_x, freearr_y, freedir, get_map_flags(), GET_MAP_OB, get_search_arr(), HEAD, m, op_on_battleground(), P_BLOCKSVIEW, P_OUT_OF_MAP, PLAYER, QUERY_FLAG, SIZEOFFREE, Ice::tmp, object::type, diamondslots::x, and diamondslots::y.

Referenced by move_ball_spell(), and move_missile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store_spell_expiry()

void store_spell_expiry ( object spell)

Stores in the spell when to warn player of expiration.

Parameters
spellspell we're considering.

Definition at line 1981 of file spell_util.cpp.

References object::duration, and object_set_value().

Referenced by cast_bless(), cast_change_ability(), create_aura(), and potion_type_apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ summon_hostile_monsters()

int summon_hostile_monsters ( object op,
int  n,
const char *  monstername 
)

Summons hostile monsters and places them in nearby squares.

Note
this is not used by any spells (summon evil monsters use to call this, but best I can tell, that spell/ability was never used. This is however used by various failures on the players part (alchemy, reincarnation, etc)
Parameters
opthe summoner.
nnumber of monsters.
monsternamename of the monster to summon, should be a valid archetype.
Returns
number of monsters actually put on the map.

Definition at line 1005 of file spell_util.cpp.

References give::op, and put_a_monster().

Referenced by alchemy_failure_effect(), and cast_raise_dead_spell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap_random_stats()

static void swap_random_stats ( object op)
static

Randomly swaps 2 stats of op.

Swapping is merely a FORCE inserted into op's inventory.

Used for spell casting when confused.

Parameters
opplayer who is the victim.

Definition at line 1254 of file spell_util.cpp.

References change_abil(), create_archetype(), draw_ext_info_format(), fix_object(), FLAG_APPLIED, dragon_attune::force, FORCE_NAME, get_attr_value(), MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_SPELL, NDI_UNIQUE, NUM_STATS, object_insert_in_ob(), object_update_speed(), give::op, RANDOM, rndm(), set_attr_value(), and SET_FLAG.

Referenced by handle_spell_confusion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ transmute_item_to_flower()

static void transmute_item_to_flower ( object op)
static

This transforms one random item of op to a flower.

Only some items are considered, mostly magical ones.

Transformed item is put in a force in a flower, weights are adjusted.

See remove_force() in server/time.c to see object removal.

Parameters
opplayer who is the victim.

Definition at line 1183 of file spell_util.cpp.

References AP_IGNORE_CURSE, AP_NOPRINT, AP_UNAPPLY, apply_manual(), can_be_transmuted_to_flower(), disinfect::count, create_archetype(), draw_ext_info_format(), esrv_del_item(), esrv_send_item(), FLAG_APPLIED, FLAG_STARTEQUIP, FOR_INV_FINISH, FOR_INV_PREPARE, dragon_attune::force, FORCE_NAME, FORCE_TRANSFORMED_ITEM, HUGE_BUF, say::item, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, give::name, NDI_UNIQUE, object_insert_in_ob(), object_remove(), object_update_speed(), give::op, QUERY_FLAG, query_short_name(), rndm(), SET_FLAG, and object::weight.

Referenced by handle_spell_confusion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: