Atrinik Server  4.0
Functions | Variables
spell_util.c File Reference
#include <global.h>
#include <spellist.h>
#include <toolkit/string.h>
#include <plugin.h>
#include <arch.h>
#include <player.h>
#include <object.h>
#include <object_methods.h>

Go to the source code of this file.

Functions

void init_spells (void)
 
int insert_spell_effect (const char *archname, mapstruct *m, int x, int y)
 
spell_structfind_spell (int spelltype)
 
int cast_spell (object *op, object *caster, int dir, int type, int ability, int item, const char *stringarg)
 
int cast_create_obj (object *op, object *new_op, int dir)
 
int fire_bolt (object *op, object *caster, int dir, int type)
 
int fire_arch_from_position (object *op, object *caster, int16_t x, int16_t y, int dir, struct archetype *at, int type, object *target)
 
int cast_cone (object *op, object *caster, int dir, int strength, int spell_type, struct archetype *spell_arch)
 
void cone_drop (object *op)
 
void explode_object (object *op)
 
void check_fired_arch (object *op)
 
int find_target_for_spell (object *op, object **target, uint32_t flags)
 
int SP_level_dam_adjust (object *caster, int spell_type, bool exact)
 
int SP_level_strength_adjust (object *caster, int spell_type)
 
int SP_level_spellpoint_cost (object *caster, int spell_type, int caster_level)
 
void fire_swarm (object *op, object *caster, int dir, struct archetype *swarm_type, int spell_type, int n, int magic)
 
void spell_failure_raw_mana (object *caster, int level)
 
void spell_failure (object *caster, int level)
 
int spell_get_random (int level, int flags)
 

Variables

struct archetypespellarch [NROFREALSPELLS]
 
static double spell_dam_bonus [MAX_STAT+1]
 

Detailed Description

Spell related helper functions.

Definition in file spell_util.c.

Function Documentation

int cast_cone ( object op,
object caster,
int  dir,
int  strength,
int  spell_type,
struct archetype spell_arch 
)

Casts a cone spell.

Parameters
opPerson firing the object.
casterObject casting the spell.
dirDirection to fire in.
strengthStrength of the spell.
spell_typeID of the spell.
spell_archSpell's arch.
Return values
0Couldn't cast.
1Successful cast.

Definition at line 687 of file spell_util.c.

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).

Parameters
opWho is casting.
new_opObject to insert.
dirDirection to insert into. Can be 0.
Returns
Direction that the object was actually placed in.

Definition at line 501 of file spell_util.c.

int cast_spell ( object op,
object caster,
int  dir,
int  type,
int  ability,
int  item,
const char *  stringarg 
)

Cast a spell.

Parameters
opThe creature that is owner of the object that is casting the spell.
casterThe actual object (wand, potion) casting the spell. Can be same as op.
dirDirection to cast in.
typeSpell ID.
abilityIf true, the spell is the innate ability of a monster (ie, don't check for blocks_magic(), and don't add AT_MAGIC to attacktype).
itemThe type of object that is casting the spell.
stringargAny options that are being used.
Returns
0 on failure, non-zero on success and is used by caller to drain mana.

Definition at line 192 of file spell_util.c.

void check_fired_arch ( object op)

If we are here, the arch (spell) we check was able to move to this place. wall() has failed, including reflection checking.

Look for a target.

Parameters
opThe spell object.

Definition at line 843 of file spell_util.c.

void cone_drop ( object op)

Drops an object based on what is in the cone's "other_arch".

Parameters
opThe object.

Definition at line 777 of file spell_util.c.

void explode_object ( object op)

Causes an object to explode, eg, a firebullet, poison cloud ball, etc.

Parameters
opThe object to explode.

Definition at line 799 of file spell_util.c.

spell_struct* find_spell ( int  spelltype)

Find a spell in the spells array.

Parameters
spelltypeID of the spell to find.
Returns
The spell from the spells array, NULL if not found.

Definition at line 160 of file spell_util.c.

int find_target_for_spell ( object op,
object **  target,
uint32_t  flags 
)

Detect target for casting a spell.

Parameters
opCaster.
[out]targetWill contain target for the spell we're casting.
flagsSpell flags.
Returns
1 if the object can cast the spell on the target, 0 otherwise.

Definition at line 896 of file spell_util.c.

int fire_arch_from_position ( object op,
object caster,
int16_t  x,
int16_t  y,
int  dir,
struct archetype at,
int  type,
object target 
)

Fires an archetype.

Parameters
opPerson firing the object.
casterObject casting the spell.
xX position where to fire the spell.
yY position where to fire the spell.
dirDirection to fire in.
atThe archetype to fire.
typeSpell ID.
Returns
0 on failure, 1 on success.

Definition at line 615 of file spell_util.c.

int fire_bolt ( object op,
object caster,
int  dir,
int  type 
)

Cast a bolt-like spell.

Parameters
opWho is casting the spell.
casterWhat object is casting the spell (rod, ...).
dirFiring direction.
typeSpell ID.
Return values
0No bolt could be fired.
1Bolt was fired (but may have been destroyed already).

Definition at line 545 of file spell_util.c.

void fire_swarm ( object op,
object caster,
int  dir,
struct archetype swarm_type,
int  spell_type,
int  n,
int  magic 
)

The following routine creates a swarm of objects. It actually sets up a specific swarm object, which then fires off all the parts of the swarm.

Parameters
opWho is casting.
casterWhat object is casting.
dirCast direction.
swarm_typeArchetype of the swarm.
spell_typeID of the spell.
nThe number to be fired.
magicMagic.

Definition at line 1109 of file spell_util.c.

void init_spells ( void  )

Initialize spells.

Definition at line 61 of file spell_util.c.

int insert_spell_effect ( const char *  archname,
mapstruct m,
int  x,
int  y 
)

Inserts a spell effect on map.

Parameters
archnameSpell effect arch.
mMap.
xX position on map.
yY position on map.
Returns
1 on failure, 0 otherwise.

Definition at line 118 of file spell_util.c.

int SP_level_dam_adjust ( object caster,
int  spell_type,
bool  exact 
)

Returns adjusted damage based on the caster.

Parameters
casterWho is casting.
spell_typeSpell ID we're adjusting.
exactReturn exact damage, unadjusted by random percentage.
Returns
Adjusted damage.

Definition at line 992 of file spell_util.c.

int SP_level_spellpoint_cost ( object caster,
int  spell_type,
int  caster_level 
)

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.

Parameters
casterWhat is casting the spell.
spell_typeSpell ID.
caster_levelLevel of caster. If -1, will use SK_level() to determine caster's level. Will also avoid affecting the cost with paths.
Returns
Spell points cost.

Definition at line 1072 of file spell_util.c.

int SP_level_strength_adjust ( object caster,
int  spell_type 
)

Adjust the strength of the spell based on level.

Parameters
casterWho is casting.
spell_typeSpell ID we're adjusting.
Returns
Adjusted strength.

Definition at line 1039 of file spell_util.c.

void spell_failure ( object caster,
int  level 
)

Punish player for failure in casting a spell.

Parameters
casterThe caster.
levelLevel of the spell.

Definition at line 1178 of file spell_util.c.

void spell_failure_raw_mana ( object caster,
int  level 
)

Punish player for failure in casting a spell by summoning a blast of uncontrollable raw mana.

Parameters
casterThe caster.
levelLevel of the spell.

Definition at line 1140 of file spell_util.c.

int spell_get_random ( int  level,
int  flags 
)

Get a random spell from the spell list.

Parameters
levelMinimum level of the spell.
flagsSpell flags to check for.
Returns
SP_NO_SPELL if no valid spell matches, ID of the spell otherwise.

Definition at line 1230 of file spell_util.c.

Variable Documentation

double spell_dam_bonus[MAX_STAT+1]
static
Initial value:
= {
-2.5,
-2.0, -1.75, -1.5, -1.25, -1.0,
-0.5, -0.5, -0.5, -0.25, -0.25,
0.0, 0.0, 0.0, 0.0, 0.0,
0.15, 0.25, 0.4, 0.5, 0.65,
0.75, 0.85, 0.95, 1.10, 1.30,
1.45, 1.55, 1.65, 1.80, 2.0,
}

Bonus to spell damage. Based on power.

Definition at line 48 of file spell_util.c.

struct archetype* spellarch[NROFREALSPELLS]

Array of pointers to archetypes used by the spells for quick access.

Definition at line 43 of file spell_util.c.