Crossfire Server, Trunk  R20513
Macros | Functions
weapon_improver.c File Reference

The implementation of the Weapon Improver class of objects. More...

#include "global.h"
#include <string.h>
#include "ob_methods.h"
#include "ob_types.h"
#include "sounds.h"
#include "sproto.h"
Include dependency graph for weapon_improver.c:

Go to the source code of this file.

Macros

#define IMPROVE_CHA   9
 Increase charisma bonus. More...
 
#define IMPROVE_CON   7
 Increase constitution bonus. More...
 
#define IMPROVE_DAMAGE   2
 Increase damage. More...
 
#define IMPROVE_DEX   6
 Increase dexterity bonus. More...
 
#define IMPROVE_ENCHANT   4
 Increase magic. More...
 
#define IMPROVE_INT   10
 Increase intelligence bonus. More...
 
#define IMPROVE_POW   11
 Increase power bonus. More...
 
#define IMPROVE_PREPARE   1
 Prepare the weapon. More...
 
#define IMPROVE_STR   5
 Increase strength bonus. More...
 
#define IMPROVE_WEIGHT   3
 Decrease weight. More...
 
#define IMPROVE_WIS   8
 Increase wisdom bonus. More...
 

Functions

static int check_item (object *op, const char *item)
 Counts suitable items with specified archetype name. More...
 
static int check_sacrifice (object *op, const object *improver)
 Returns how many items of type improver->slaying there are under op. More...
 
static void eat_item (object *op, const char *item, uint32_t nrof)
 This removes 'nrof' items with specified archetype. More...
 
static int improve_weapon (object *op, object *improver, object *weapon)
 Does the dirty job for 'improve weapon' scroll, prepare or add something. More...
 
static int improve_weapon_stat (object *op, object *improver, object *weapon, signed char *stat, int sacrifice_count, const char *statname)
 Actually improves the weapon, and tells user. More...
 
void init_type_weapon_improver (void)
 Initializer for the WEAPON_IMPROVER object type. More...
 
static int prepare_weapon (object *op, object *improver, object *weapon)
 This does the prepare weapon scroll. More...
 
static method_ret weapon_improver_type_apply (ob_methods *context, object *op, object *applier, int aflags)
 Attempts to apply weapon_improver. More...
 

Detailed Description

The implementation of the Weapon Improver class of objects.

Definition in file weapon_improver.c.

Macro Definition Documentation

#define IMPROVE_CHA   9

Increase charisma bonus.

Definition at line 227 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_CON   7

Increase constitution bonus.

Definition at line 225 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_DAMAGE   2

Increase damage.

Definition at line 220 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_DEX   6

Increase dexterity bonus.

Definition at line 224 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_ENCHANT   4

Increase magic.

Definition at line 222 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_INT   10

Increase intelligence bonus.

Definition at line 228 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_POW   11

Increase power bonus.

Definition at line 229 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_PREPARE   1

Prepare the weapon.

Definition at line 219 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_STR   5

Increase strength bonus.

Definition at line 223 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_WEIGHT   3

Decrease weight.

Definition at line 221 of file weapon_improver.c.

Referenced by improve_weapon().

#define IMPROVE_WIS   8

Increase wisdom bonus.

Definition at line 226 of file weapon_improver.c.

Referenced by improve_weapon().

Function Documentation

static int check_item ( object op,
const char *  item 
)
static

Counts suitable items with specified archetype name.

Will not consider unpaid/cursed items.

Parameters
opobject just before the bottom of the pile, others will be checked through object->below.
itemwhat archetype to check for.
Returns
count of matching items.
Todo:
couldn't item be a shared string, and == be used instead of strcmp? The op = op->below is weird - what is it's NULL?

Definition at line 93 of file weapon_improver.c.

References FLAG_CURSED, FLAG_DAMNED, FLAG_UNPAID, FOR_BELOW_FINISH, FOR_BELOW_PREPARE, and QUERY_FLAG.

Referenced by check_sacrifice().

Here is the caller graph for this function:

static int check_sacrifice ( object op,
const object improver 
)
static

Returns how many items of type improver->slaying there are under op.

Will display a message if none found, and 1 if improver->slaying is NULL.

Parameters
opitem just below the bottom of the pile.
improversacrifice object.
Returns
count of matching items.
Todo:
weird logic? use shared string directly, improver isn't really useful.

Definition at line 165 of file weapon_improver.c.

References check_item(), draw_ext_info_format(), MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, NDI_UNIQUE, and obj::slaying.

Referenced by improve_weapon(), and prepare_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

static void eat_item ( object op,
const char *  item,
uint32_t  nrof 
)
static

This removes 'nrof' items with specified archetype.

op is typically the player, which is only really used to determine what space to look at. Modified to only eat 'nrof' of objects.

Parameters
opitem at the bottom to check.
itemarchetype to look for.
nrofcount to remove.
Todo:
couldn't item be a shared string, and use == instead of strcmp? also, the remove logic is wrong - op->nrof will be 0 after decreat_ob_nr in the 2nd case.

Definition at line 130 of file weapon_improver.c.

References obj::arch, obj::below, archt::name, obj::nrof, and object_decrease_nrof().

Referenced by improve_weapon(), and prepare_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

static int improve_weapon ( object op,
object improver,
object weapon 
)
static

Does the dirty job for 'improve weapon' scroll, prepare or add something.

This is the new improve weapon code.

Checks if weapon was prepared, if enough potions on the floor, ...

We are hiding extra information about the weapon in the level and last_eat numbers for an object. Hopefully this won't break anything ?? level == max improve last_eat == current improve

Parameters
opplayer improving.
improverthe scroll that was read.
weaponwepaon to improve.
Returns
1 if weapon was improved, 0 if not enough sacrifice, weapon not prepared, ...

Definition at line 332 of file weapon_improver.c.

References AP_UNAPPLY, apply_check_weapon_power(), apply_special(), liv::Cha, check_sacrifice(), liv::Con, obj::contr, liv::dam, liv::Dex, draw_ext_info(), draw_ext_info_format(), eat_item(), esrv_update_item(), FLAG_APPLIED, IMPROVE_CHA, IMPROVE_CON, IMPROVE_DAMAGE, IMPROVE_DEX, IMPROVE_ENCHANT, IMPROVE_INT, IMPROVE_POW, IMPROVE_PREPARE, IMPROVE_STR, improve_weapon_stat(), IMPROVE_WEIGHT, IMPROVE_WIS, liv::Int, pl::item_power, obj::item_power, Settings::item_power_factor, obj::last_eat, obj::level, llevError, LOG(), obj::magic, MAX_WEAPON_ITEM_POWER, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, MSG_TYPE_APPLY_SUCCESS, NDI_UNIQUE, object_decrease_nrof_by_one, PLAYER, liv::Pow, prepare_weapon(), QUERY_FLAG, settings, obj::slaying, liv::sp, obj::stats, liv::Str, obj::type, UPD_WEIGHT, obj::weight, and liv::Wis.

Referenced by weapon_improver_type_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

static int improve_weapon_stat ( object op,
object improver,
object weapon,
signed char *  stat,
int  sacrifice_count,
const char *  statname 
)
static

Actually improves the weapon, and tells user.

Won't test anything.

Parameters
opplayer improving.
improverscroll used to improve.
weaponimproved weapon.
statwhat statistic to improve.
sacrifice_counthow much to improve stat by.
statnamename of stat to display to player.
Returns
1.

Definition at line 200 of file weapon_improver.c.

References draw_ext_info(), draw_ext_info_format(), fix_object(), obj::last_eat, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, NDI_UNIQUE, and object_decrease_nrof_by_one.

Referenced by improve_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

void init_type_weapon_improver ( void  )

Initializer for the WEAPON_IMPROVER object type.

Definition at line 38 of file weapon_improver.c.

References register_apply(), WEAPON_IMPROVER, and weapon_improver_type_apply().

Referenced by register_all_ob_types().

Here is the call graph for this function:

Here is the caller graph for this function:

static int prepare_weapon ( object op,
object improver,
object weapon 
)
static

This does the prepare weapon scroll.

Checks for sacrifice, and so on. Will inform the player of failures or success.

Parameters
opplayer using the scroll.
improverimprovement scroll.
weaponweapon to improve.
Returns
1 if weapon was prepared, 0 else.

Definition at line 245 of file weapon_improver.c.

References check_sacrifice(), draw_ext_info(), draw_ext_info_format(), eat_item(), esrv_update_item(), FREE_AND_COPY, isqrt(), MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, MSG_TYPE_APPLY_SUCCESS, NDI_UNIQUE, NROFATTACKS, object_decrease_nrof_by_one, object_insert_in_ob(), object_split(), snprintf, UPD_NAME, UPD_NROF, and WEAPON.

Referenced by improve_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

static method_ret weapon_improver_type_apply ( ob_methods context,
object op,
object applier,
int  aflags 
)
static

Attempts to apply weapon_improver.

Parameters
contextThe method context
opThe weapon_improver to apply
applierThe object attempting to apply the weapon_improver. Ignored unless a player
aflagsSpecial flags (always apply/unapply)
Returns
The return value is METHOD_OK unless it fails to apply.

Definition at line 51 of file weapon_improver.c.

References BOW, draw_ext_info(), esrv_update_item(), find_marked_object(), FLAG_WIZCAST, get_map_flags(), improve_weapon(), obj::map, METHOD_ERROR, METHOD_OK, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, MSG_TYPE_APPLY_SUCCESS, NDI_UNIQUE, P_NO_MAGIC, PLAYER, QUERY_FLAG, obj::type, UPD_FLAGS, UPD_NAME, UPD_NROF, WEAPON, obj::x, and obj::y.

Referenced by init_type_weapon_improver().

Here is the call graph for this function:

Here is the caller graph for this function: