Crossfire Server, Trunk  R21670
spellbook.c File Reference
#include <global.h>
#include <ob_methods.h>
#include <ob_types.h>
#include <sounds.h>
#include <sproto.h>
#include <stdlib.h>
#include <string.h>
#include "living.h"
+ Include dependency graph for spellbook.c:

Go to the source code of this file.


void init_type_spellbook (void)
static method_ret spellbook_type_apply (ob_methods *context, object *book, object *applier, int aflags)
static void spellbook_type_describe (const ob_methods *context, const object *book, const object *observer, const int use_media_tags, char *buf, const size_t size)
void stringbuffer_append_ordinal (StringBuffer *sb, const int n)
static void stringbuffer_append_spelldesc (StringBuffer *sb, const object *spell)


static const char *const numbers_10 []
static const char *const ordinals []
static const char *const ordinals_10 []

Detailed Description

Implimentation of spellbooks.

Definition in file spellbook.c.

Function Documentation

◆ init_type_spellbook()

void init_type_spellbook ( void  )

Initializer for the SPELLBOOK object type.

Definition at line 46 of file spellbook.c.

References register_apply(), register_describe(), SPELLBOOK, spellbook_type_apply(), and spellbook_type_describe().

Referenced by register_all_ob_types().

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

◆ spellbook_type_apply()

static method_ret spellbook_type_apply ( ob_methods context,
object book,
object applier,
int  aflags 

Applies a spellbook. Checks whether player has knowledge of required skill, doesn't already know the spell, stuff like that. Random learning failure too.

contextmethod context.
bookSpellbook to apply.
applierobject attempting to apply the spellbook. Should be a player.
aflagsspecial flags (always apply/unapply).
METHOD_OK always.

handle failure differently for praying/magic.

split into multiple functions

Definition at line 205 of file spellbook.c.

References calc_skill_exp(), change_exp(), check_spell_known(), obj::contr, die_roll(), do_forget_spell(), do_learn_spell(), draw_ext_info(), draw_ext_info_format(), obj::env, esrv_update_item(), find_skill_by_name(), FLAG_BLESSED, FLAG_BLIND, FLAG_CONFUSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IDENTIFIED, FLAG_STARTEQUIP, FLAG_WIZ, get_learn_spell(), get_readable_message_type(), liv::grace, identify(), liv::Int, obj::inv, obj::level, llevError, LOG(), MAX, MAX_BUF, readable_message_type::message_subtype, readable_message_type::message_type, METHOD_OK, obj::msg, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, MSG_TYPE_APPLY_FAILURE, MSG_TYPE_APPLY_SUCCESS, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, obj::name, NDI_BLUE, NDI_NAVY, NDI_UNIQUE, object_decrease_nrof_by_one, play_sound_player_only(), PLAYER, PREFER_LOW, QUERY_FLAG, query_name(), query_short_name(), random_roll(), rndm(), scroll_failure(), settings, obj::skill, pl::socket, SOUND_TYPE_SPELL, liv::sp, Settings::spell_failure_effects, obj::stats, stringbuffer_append_spelldesc(), stringbuffer_append_string(), stringbuffer_finish(), stringbuffer_new(), stringbuffer_trim_whitespace(), TRUE, obj::type, UPD_FLAGS, UPD_NAME, socket_struct::update_look, and liv::Wis.

Referenced by init_type_spellbook().

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

◆ spellbook_type_describe()

static void spellbook_type_describe ( const ob_methods context,
const object book,
const object observer,
const int  use_media_tags,
char *  buf,
size_t  size 

Describe a spellbook.

If identified, displays the level and description of the spell inside it.

contextmethod context.
bookSpellbook to describe
observerPlayer examining the spellbook
use_media_tagsTrue if we should use mediatags in the output
bufOutput buffer to append description to
sizeTotal output buffer size

Definition at line 150 of file spellbook.c.

References common_ob_describe(), obj::inv, is_identified(), query_name(), safe_strcat(), snprintf, stringbuffer_append_spelldesc(), stringbuffer_append_string(), stringbuffer_finish(), and stringbuffer_new().

Referenced by init_type_spellbook().

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

◆ stringbuffer_append_ordinal()

void stringbuffer_append_ordinal ( StringBuffer sb,
const int  n 

Turns a cardinal number (e.g. 7) into an ordinal number (e.g. "seventh") and appends it to a caller-supplied StringBuffer. Works only on numbers 0 <= n < 100; outside that range just returns the cardinal number as a string.

sbStringBuffer to append the result to.
nNumber to ordinalize.

Definition at line 82 of file spellbook.c.

References ordinals, ordinals_10, stringbuffer_append_printf(), and stringbuffer_append_string().

Referenced by stringbuffer_append_spelldesc().

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

◆ stringbuffer_append_spelldesc()

static void stringbuffer_append_spelldesc ( StringBuffer sb,
const object spell 

Append a terse description of the spell's name, level, discipline, and paths to a stringbuffer. What comes out is something like: "medium fireball (a third level pyromancy) (paths: Fire)" this is used in both spellbook_type_describe() to generate the one-line description for a spellbook, and in spellbook_type_apply to summarize what the spellbook contains if you don't ID it until you start reading it.

sbThe StringBuffer to append to
spellThe spell to describe

Definition at line 108 of file spellbook.c.

References describe_spellpath_attenuation(), liv::grace, obj::level, obj::path_attuned, obj::skill, obj::stats, stringbuffer_append_ordinal(), and stringbuffer_append_string().

Referenced by spellbook_type_apply(), and spellbook_type_describe().

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

Variable Documentation

◆ numbers_10

const char* const numbers_10[]
Initial value:
= {
"zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
"eighty", "ninety"


Definition at line 52 of file spellbook.c.

◆ ordinals

const char* const ordinals[]
Initial value:
= {
"zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
"eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth",
"fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth",
"nineteenth", "twentieth"

Levels as a full name and not a number.

Definition at line 58 of file spellbook.c.

Referenced by stringbuffer_append_ordinal().

◆ ordinals_10

const char* const ordinals_10[]
Initial value:
= {
"zeroth", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth",
"seventieth", "eightieth", "ninetieth"

Tens for levels

Definition at line 66 of file spellbook.c.

Referenced by stringbuffer_append_ordinal().