Crossfire Server, Trunk  R20513
Functions
gods.c File Reference

All this functions handle gods: give presents, punish, and so on. More...

#include "global.h"
#include <stdlib.h>
#include <string.h>
#include "living.h"
#include "object.h"
#include "sounds.h"
#include "spells.h"
#include "sproto.h"
Include dependency graph for gods.c:

Go to the source code of this file.

Functions

int become_follower (object *op, const object *new_god)
 This function is called whenever a player has switched to a new god. More...
 
const char * determine_god (object *op)
 Determines if op worships a god. More...
 
archetypedetermine_holy_arch (const object *god, const char *type)
 Determines the archetype for holy servant and god avatar. More...
 
const objectfind_god (const char *name)
 Returns pointer to specified god's object through pntr_to_god_obj(). More...
 
static int follower_has_similar_item (object *op, object *item)
 Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively). More...
 
static int follower_level_to_enchantments (int level, int difficulty)
 Converts a level and difficulty to a magic/enchantment value for eg weapons. More...
 
static void follower_remove_given_items (object *pl, object *op, const object *god)
 Removes from a player's inventory all items bestowed by a particular god. More...
 
static const char * get_god_for_race (const char *race)
 Returns a string that is the name of the god that should be natively worshipped by a creature of who has race *race if we can't find a god that is appropriate, we return NULL. More...
 
static int god_enchants_weapon (object *op, const object *god, object *tr, object *skill)
 God wants to enchant weapon. More...
 
static int god_examines_item (const object *god, object *item)
 God checks item the player is using. More...
 
static int god_examines_priest (object *op, const object *god)
 Checks and maybe punishes someone praying. More...
 
static int god_gives_present (object *op, const object *god, treasure *tr)
 God gives an item to the player. More...
 
static void god_intervention (object *op, const object *god, object *skill, object *altar)
 Every once in a while the god will intervene to help the worshiper. More...
 
static int god_removes_curse (object *op, int remove_damnation)
 God helps player by removing curse and/or damnation. More...
 
static int improve_weapon_magic (object *op, object *tr, object *weapon, object *skill)
 Utility function for improving the magic on a weapon. More...
 
static int lookup_god_by_name (const char *name)
 Returns the id of specified god. More...
 
void pray_at_altar (object *pl, object *altar, object *skill)
 Player prays at altar. More...
 
static void remove_special_prayers (object *op, const object *god)
 Removes special prayers given by a god. More...
 
static int same_string (const char *s1, const char *s2)
 Compares 2 strings. More...
 
static void stop_using_item (object *op, int type, int number)
 Unapplies up to number worth of items of type type, ignoring curse status. More...
 
int tailor_god_spell (object *spellop, object *caster)
 Changes the attributes of cone, smite, and ball spells as needed by the code. More...
 
static void update_priest_flag (const object *god, object *exp_ob, uint32_t flag)
 If the god does/doesnt have this flag, we give/remove it from the experience object if it doesnt/does already exist. More...
 
static int worship_forbids_use (object *op, object *exp_obj, uint32_t flag, const char *string)
 Forbids or let player use something item type. More...
 

Detailed Description

All this functions handle gods: give presents, punish, and so on.

Oct 3, 1995 - Code laid down for initial gods, priest alignment, and monster race initialization. b.t.

Sept 1996 - moved code over to object -oriented gods -b.t.

Definition in file gods.c.

Function Documentation

int become_follower ( object op,
const object new_god 
)

This function is called whenever a player has switched to a new god.

It handles basically all the stat changes that happen to the player, including the removal of godgiven items (from the former cult). Handles race restrictions on god, and will punish player if needed.

Parameters
opplayer switching cults.
new_godnew god to worship.
Returns
1 if successfully converted, 0 if the god doesn't like the race, or something else.
Todo:

isn't there duplication with remove_special_prayers() for spell removing?

split the check to make this function only actually become follower

Definition at line 466 of file gods.c.

References add_string(), ARMOUR, ATNR_COLD, ATNR_ELECTRICITY, ATNR_FIRE, ATNR_POISON, BOOK, BOOTS, cast_magic_storm(), change_abil(), CLEAR_FLAG, archt::clone, obj::contr, create_archetype(), determine_god(), draw_ext_info_format(), find_god(), FLAG_APPLIED, FLAG_BLIND, FLAG_MAKE_INVIS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STARTEQUIP, FLAG_STEALTH, FLAG_UNDEAD, FLAG_USE_ARMOUR, FLAG_USE_SHIELD, FLAG_USE_WEAPON, FLAG_XRAYS, follower_remove_given_items(), liv::food, FOR_INV_FINISH, FOR_INV_PREPARE, FORCE, free_string(), get_archetype_by_type_subtype(), give_skill_by_name(), GLOVES, god_gives_present(), liv::grace, HELMET, liv::hp, obj::invisible, treasurestruct::item, treasureliststruct::items, obj::last_eat, obj::last_grace, obj::last_heal, obj::last_sp, obj::level, link_player_skills(), LOOSE_MANA, liv::luck, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, obj::name, NDI_NAVY, NDI_UNIQUE, treasurestruct::next, NROFATTACKS, object_find_by_type_subtype(), object_free_drop_inventory(), object_present_in_ob_by_name(), object_remove(), obj::path_attuned, obj::path_denied, obj::path_repelled, player_unready_range_ob(), PREFER_LOW, QUERY_FLAG, obj::race, random_roll(), obj::randomitems, obj::resist, SET_FLAG, SHIELD, SK_PRAYING, SKILL, obj::slaying, liv::sp, SPELL, SPELLBOOK, obj::stats, stop_using_item(), obj::title, obj::type, update_priest_flag(), WEAPON, and worship_forbids_use().

Referenced by command_setgod(), and pray_at_altar().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* determine_god ( object op)

Determines if op worships a god.

Returns the godname if they do or "none" if they have no god. In the case of an NPC, if they have no god, we try and guess who they should worship based on their race. If that fails we give them a random one.

Parameters
opobject to get name of.
Returns
god name, "none" if nothing suitable.

Definition at line 106 of file gods.c.

References add_string(), first_god, FLAG_ALIVE, get_god_for_race(), glnk::id, lookup_god_by_name(), glnk::name, glnk::next, object_find_by_type_subtype(), PLAYER, QUERY_FLAG, obj::race, rndm(), SK_PRAYING, SKILL, SPELL, SPELL_EFFECT, obj::title, and obj::type.

Referenced by become_follower(), cast_bless(), cast_consecrate(), cast_curse(), cast_detection(), cast_smite_spell(), cast_spell(), cfapi_object_get_property(), hit_player(), hit_with_one_attacktype(), kill_player_not_permadeath(), mood_change(), perceive_self(), pets_summon_golem(), pets_summon_object(), pray_at_altar(), prayer_failure(), show_skills(), and tailor_god_spell().

Here is the call graph for this function:

Here is the caller graph for this function:

archetype* determine_holy_arch ( const object god,
const char *  type 
)

Determines the archetype for holy servant and god avatar.

Possible monsters are stored as invisible books in god's inventory, one having the right name is selected randomly.

Parameters
godgod for which we want something.
typewhat the summon type is. Must be a shared string.
Returns
random archetype matching the type, NULL if none found.

Definition at line 735 of file gods.c.

References BOOK, archt::clone, obj::invisible, treasurestruct::item, treasureliststruct::items, llevError, LOG(), obj::name, treasurestruct::next, obj::other_arch, obj::randomitems, rndm(), and obj::type.

Referenced by CREMainWindow::onReportSummon(), and pets_summon_golem().

Here is the call graph for this function:

Here is the caller graph for this function:

const object* find_god ( const char *  name)

Returns pointer to specified god's object through pntr_to_god_obj().

Note
returned object shouldn't be modified.
Parameters
namegod's name.
Returns
pointer to god's object, NULL if doesn't match any god.

Definition at line 80 of file gods.c.

References first_god, glnk::name, glnk::next, and pntr_to_god_obj().

Referenced by become_follower(), cast_bless(), cast_consecrate(), cast_curse(), cast_detection(), cast_smite_spell(), command_setgod(), hit_player(), hit_with_one_attacktype(), mood_change(), perceive_self(), pets_summon_golem(), pets_summon_object(), pray_at_altar(), and tailor_god_spell().

Here is the call graph for this function:

Here is the caller graph for this function:

static int follower_has_similar_item ( object op,
object item 
)
static

Checks for any occurrence of the given 'item' in the inventory of 'op' (recursively).

Parameters
opobject to check.
itemobject to check for.
Returns
1 if found, else 0.

Definition at line 226 of file gods.c.

References FOR_INV_FINISH, FOR_INV_PREPARE, obj::msg, obj::name, same_string(), obj::slaying, obj::title, and obj::type.

Referenced by god_gives_present().

Here is the call graph for this function:

Here is the caller graph for this function:

static int follower_level_to_enchantments ( int  level,
int  difficulty 
)
static

Converts a level and difficulty to a magic/enchantment value for eg weapons.

Parameters
levellevel
difficultydifficulty. Must be 1 or more.
Returns
number of enchantments for level and difficulty.

Definition at line 816 of file gods.c.

References llevError, and LOG().

Referenced by improve_weapon_magic().

Here is the call graph for this function:

Here is the caller graph for this function:

static void follower_remove_given_items ( object pl,
object op,
const object god 
)
static

Removes from a player's inventory all items bestowed by a particular god.

Intended mainly for use in punishing characters for switching gods.

Parameters
plthe player object
opthe object to be searched for items
godthe god whose objects to remove

Definition at line 190 of file gods.c.

References draw_ext_info_format(), FOR_INV_FINISH, FOR_INV_PREPARE, HUGE_BUF, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, obj::name, NDI_UNIQUE, object_free_drop_inventory(), object_get_value(), object_remove(), and query_short_name().

Referenced by become_follower().

Here is the call graph for this function:

Here is the caller graph for this function:

static const char * get_god_for_race ( const char *  race)
static

Returns a string that is the name of the god that should be natively worshipped by a creature of who has race *race if we can't find a god that is appropriate, we return NULL.

Parameters
racerace we're getting the god of.
Returns
NULL if no matching race, else god's name.

Definition at line 1301 of file gods.c.

References glnk::arch, archt::clone, first_god, glnk::name, glnk::next, obj::race, and strcasecmp().

Referenced by determine_god().

Here is the call graph for this function:

Here is the caller graph for this function:

static int god_enchants_weapon ( object op,
const object god,
object tr,
object skill 
)
static

God wants to enchant weapon.

Affected weapon is the applied one (weapon or bow). It's checked to make sure it isn't a weapon for another god. If all is all right, update weapon with attacktype, slaying and such.

Parameters
opplayer
godgod enchanting weapon.
trtreasure list item for enchanting weapon, contains the enchantment level.
skillpraying skill of op.
Returns
0 if weapon wasn't changed, 1 if changed.

Definition at line 880 of file gods.c.

References add_string(), AT_PHYSICAL, obj::attacktype, BOW, draw_ext_info(), draw_ext_info_format(), esrv_update_item(), liv::exp, find_skill_by_number(), FMT64, god_examines_item(), improve_weapon_magic(), obj::item_power, llevError, LOG(), MAX_BUF, MAX_WEAPON_ITEM_POWER, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, MSG_TYPE_ITEM_INFO, obj::name, NDI_UNIQUE, object_find_by_type_applied(), object_get_value(), object_set_value(), Settings::personalized_blessings, PLAYER, settings, SK_PRAYING, obj::slaying, snprintf, obj::stats, obj::title, TRUE, obj::type, UPD_NAME, and WEAPON.

Referenced by god_intervention().

Here is the call graph for this function:

Here is the caller graph for this function:

static int god_examines_item ( const object god,
object item 
)
static

God checks item the player is using.

If you are using the item of an enemy god, it can be bad...-b.t.

Parameters
godgod checking.
itemitem to check.
Return values
-1item is bad.
0item is neutral.
1item is good.

Definition at line 1261 of file gods.c.

References draw_ext_info_format(), obj::env, MAX_BUF, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, obj::name, NDI_NAVY, NDI_UNIQUE, query_name(), snprintf, and obj::title.

Referenced by god_enchants_weapon(), and god_examines_priest().

Here is the call graph for this function:

Here is the caller graph for this function:

static int god_examines_priest ( object op,
const object god 
)
static

Checks and maybe punishes someone praying.

All applied items are examined, if player is using more items of other gods, s/he loses experience in praying or general experience if no praying.

Parameters
opplayer the god examines.
godgod examining the player.
Returns
negative value is god is not pleased, else positive value, the higher the better.

Definition at line 1214 of file gods.c.

References cast_magic_storm(), change_exp(), create_archetype(), draw_ext_info_format(), liv::exp, FLAG_APPLIED, FOR_INV_FINISH, FOR_INV_PREPARE, god_examines_item(), obj::level, LOOSE_MANA, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, obj::name, NDI_NAVY, NDI_UNIQUE, object_find_by_type_subtype(), PREFER_LOW, QUERY_FLAG, random_roll(), SK_PRAYING, SK_SUBTRACT_SKILL_EXP, SKILL, obj::skill, and obj::stats.

Referenced by god_intervention().

Here is the call graph for this function:

Here is the caller graph for this function:

static int god_gives_present ( object op,
const object god,
treasure tr 
)
static

God gives an item to the player.

Inform player of the present.

Parameters
opwho is getting the treasure.
godgod giving the present.
trobject to give. Should be a single object on list.
Returns
0 if nothing was given, 1 else.

Mark what god gave it, so it can be taken vengefully later!

Definition at line 252 of file gods.c.

References arch_to_object(), archt::clone, draw_ext_info_format(), fix_generated_item(), follower_has_similar_item(), GT_ONLY_GOOD, HUGE_BUF, obj::inv, treasurestruct::item, MSG_TYPE_ITEM, MSG_TYPE_ITEM_ADD, obj::name, NDI_UNIQUE, object_free2(), object_insert_in_ob(), object_set_value(), query_short_name(), ROD, TRUE, obj::type, and WAND.

Referenced by become_follower(), and god_intervention().

Here is the call graph for this function:

Here is the caller graph for this function:

static void god_intervention ( object op,
const object god,
object skill,
object altar 
)
static

Every once in a while the god will intervene to help the worshiper.

Later, this fctn can be used to supply quests, etc for the priest. -b.t. called from pray_at_altar() currently.

Parameters
opplayer praying.
godgod player is praying to.
skillplayer's praying skill.
altarwhere the player is praying.

Definition at line 986 of file gods.c.

References obj::anim_suffix, apply_anim_suffix(), ARCH_DEPLETION, arch_present_in_ob(), BOOK, cast_change_ability(), cast_heal(), treasurestruct::chance, check_spell_known(), archt::clone, create_archetype(), create_archetype_by_object_name(), create_treasure(), do_learn_spell(), draw_ext_info(), draw_ext_info_format(), find_archetype(), find_treasurelist(), fix_object(), get_attr_value(), god_enchants_weapon(), god_examines_priest(), god_gives_present(), god_removes_curse(), liv::grace, GT_ONLY_GOOD, GT_STARTEQUIP, GT_UPDATE_INV, HOLY_POSSESSION, liv::hp, obj::invisible, treasurestruct::item, treasureliststruct::items, obj::level, llevError, LOG(), liv::maxgrace, liv::maxhp, liv::maxsp, obj::msg, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END, MSG_TYPE_ITEM, MSG_TYPE_ITEM_ADD, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, treasurestruct::name, obj::name, NDI_UNIQUE, NDI_WHITE, treasurestruct::next, NUM_STATS, object_free_drop_inventory(), object_remove(), PREFER_HIGH, random_roll(), obj::randomitems, restore_msg, obj::slaying, liv::sp, SPELL, obj::stats, and obj::type.

Referenced by pray_at_altar().

Here is the call graph for this function:

Here is the caller graph for this function:

static int god_removes_curse ( object op,
int  remove_damnation 
)
static

God helps player by removing curse and/or damnation.

Parameters
opplayer to help.
remove_damnationif set, also removes damned items.
Returns
1 if at least one item was uncursed, 0 else.

Definition at line 783 of file gods.c.

References CLEAR_FLAG, draw_ext_info(), esrv_update_item(), FLAG_CURSED, FLAG_DAMNED, FLAG_KNOWN_CURSED, FOR_INV_FINISH, FOR_INV_PREPARE, MSG_TYPE_SKILL, MSG_TYPE_SKILL_PRAY, NDI_UNIQUE, PLAYER, QUERY_FLAG, obj::type, and UPD_FLAGS.

Referenced by god_intervention().

Here is the call graph for this function:

Here is the caller graph for this function:

static int improve_weapon_magic ( object op,
object tr,
object weapon,
object skill 
)
static

Utility function for improving the magic on a weapon.

Affected weapon is the applied one (weapon or bow). This utility function improves the weapon magic on a weapon being enchanted by a god. This was necessary because the same block of the code was being called from two places in the god_enchants_weapon(...) function.

Parameters
opplayer
trtreasure list item for enchanting weapon, contains the enchantment level.
weaponweapon being modified
skillpraying skill of op.
Returns
0 if weapon wasn't changed, 1 if changed.

Definition at line 847 of file gods.c.

References draw_ext_info(), esrv_update_item(), follower_level_to_enchantments(), obj::item_power, obj::level, obj::magic, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE, NDI_UNIQUE, PLAYER, obj::type, and UPD_NAME.

Referenced by god_enchants_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

static int lookup_god_by_name ( const char *  name)
static

Returns the id of specified god.

Parameters
namegod to search for.
Returns
identifier of god, -1 if not found.
Todo:
couldn't == be used for comparison, if name is a shared string?

Definition at line 54 of file gods.c.

References first_god, glnk::id, MIN, glnk::name, and glnk::next.

Referenced by determine_god().

Here is the caller graph for this function:

void pray_at_altar ( object pl,
object altar,
object skill 
)

Player prays at altar.

Checks for god changing, divine intervention, and so on.

Parameters
plplayer praying.
altaraltar player's praying on. Doesn't need to be consecrated.
skillpraying skill.

Definition at line 296 of file gods.c.

References absdir(), become_follower(), cast_magic_storm(), change_exp(), archt::clone, create_archetype(), determine_god(), draw_ext_info(), draw_ext_info_format(), EVENT_APPLY, execute_event(), liv::exp, obj::facing, find_god(), god_intervention(), liv::grace, obj::level, LOOSE_MANA, liv::luck, MAX, liv::maxgrace, move_player(), MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, obj::name, archt::name, NDI_NAVY, NDI_UNIQUE, obj::other_arch, PREFER_LOW, random_roll(), random_roll64(), remove_special_prayers(), SCRIPT_FIX_ALL, SK_SUBTRACT_SKILL_EXP, obj::skill, obj::stats, and liv::Wis.

Referenced by pray().

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_special_prayers ( object op,
const object god 
)
static

Removes special prayers given by a god.

After this function, op shouldn't know any prayer granted by god. Prayers will be given when player prays on god's altar, so not handled now.

Parameters
opplayer to remove prayers from.
godgod we're removing the prayers.

Definition at line 402 of file gods.c.

References archt::clone, obj::contr, draw_ext_info_format(), FLAG_STARTEQUIP, FOR_INV_FINISH, FOR_INV_PREPARE, treasurestruct::item, treasureliststruct::items, llevError, LOG(), MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, obj::name, NDI_NAVY, NDI_UNIQUE, treasurestruct::next, object_free_drop_inventory(), object_remove(), player_unready_range_ob(), QUERY_FLAG, obj::randomitems, SPELL, and obj::type.

Referenced by pray_at_altar().

Here is the call graph for this function:

Here is the caller graph for this function:

static int same_string ( const char *  s1,
const char *  s2 
)
static

Compares 2 strings.

Parameters
s1
s2strings to compare.
Returns
1 if s1 and s2 are the same - either both NULL, or strcmp( ) == 0.

Definition at line 168 of file gods.c.

Referenced by follower_has_similar_item().

Here is the caller graph for this function:

static void stop_using_item ( object op,
int  type,
int  number 
)
static

Unapplies up to number worth of items of type type, ignoring curse status.

This is used when the player gets forbidden to use eg weapons.

Parameters
opplayer we're considering.
typeitem type to remove.
numbermaximum number of items to unapply. Must be positive.

Definition at line 680 of file gods.c.

References AP_IGNORE_CURSE, AP_UNAPPLY, apply_special(), FLAG_APPLIED, FOR_INV_FINISH, FOR_INV_PREPARE, and QUERY_FLAG.

Referenced by become_follower().

Here is the call graph for this function:

Here is the caller graph for this function:

int tailor_god_spell ( object spellop,
object caster 
)

Changes the attributes of cone, smite, and ball spells as needed by the code.

Parameters
spellopspell object to change.
casterwhat is casting spellop (player, spell, ...).
Returns
0 if there was no race to assign to the slaying field of the spell, but the spell attacktype contains AT_HOLYWORD, 1 else.

Definition at line 1328 of file gods.c.

References add_string(), AT_GODPOWER, AT_HOLYWORD, obj::attacktype, determine_god(), draw_ext_info(), find_god(), FREE_AND_COPY, free_string(), llevError, LOG(), MAX_BUF, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, obj::name, obj::name_pl, NDI_UNIQUE, object_free_drop_inventory(), object_get_owner(), obj::race, obj::slaying, snprintf, SPELL, SPELL_EFFECT, obj::title, and obj::type.

Referenced by cast_cone(), cast_smite_spell(), explode_bullet(), fire_arch_from_position(), and fire_swarm().

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_priest_flag ( const object god,
object exp_ob,
uint32_t  flag 
)
static

If the god does/doesnt have this flag, we give/remove it from the experience object if it doesnt/does already exist.

Parameters
godgod object.
exp_obplayer's praying skill object.
flagflag to consider.

Definition at line 703 of file gods.c.

References CLEAR_FLAG, QUERY_FLAG, and SET_FLAG.

Referenced by become_follower(), and worship_forbids_use().

Here is the caller graph for this function:

static int worship_forbids_use ( object op,
object exp_obj,
uint32_t  flag,
const char *  string 
)
static

Forbids or let player use something item type.

Parameters
opplayer.
exp_objpraying skill.
flagFLAG_xxx to check against.
stringwhat flag corresponds to ("weapons", "shield", ...).
Returns
1 if player was changed, 0 if no change.

Definition at line 650 of file gods.c.

References obj::arch, archt::clone, draw_ext_info_format(), MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOD, NDI_UNIQUE, QUERY_FLAG, and update_priest_flag().

Referenced by become_follower().

Here is the call graph for this function:

Here is the caller graph for this function: