Crossfire Server, Trunk
weapon_improver.c File Reference
#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
 
#define IMPROVE_CON   7
 
#define IMPROVE_DAMAGE   2
 
#define IMPROVE_DEX   6
 
#define IMPROVE_ENCHANT   4
 
#define IMPROVE_INT   10
 
#define IMPROVE_POW   11
 
#define IMPROVE_PREPARE   1
 
#define IMPROVE_STR   5
 
#define IMPROVE_WEIGHT   3
 
#define IMPROVE_WIS   8
 

Functions

static int check_item (object *op, const char *item)
 
static int check_sacrifice (object *op, const object *improver)
 
static void eat_item (object *op, const char *item, uint32_t nrof)
 
static int improve_weapon (object *op, object *improver, object *weapon)
 
static int improve_weapon_stat (object *op, object *improver, object *weapon, signed char *stat, int sacrifice_count, const char *statname)
 
void init_type_weapon_improver (void)
 
static int prepare_weapon (object *op, object *improver, object *weapon)
 
static method_ret weapon_improver_type_apply (object *op, object *applier, int aflags)
 

Detailed Description

The implementation of the Weapon Improver class of objects.

Definition in file weapon_improver.c.

Macro Definition Documentation

◆ IMPROVE_CHA

#define IMPROVE_CHA   9

Increase charisma bonus.

Definition at line 227 of file weapon_improver.c.

◆ IMPROVE_CON

#define IMPROVE_CON   7

Increase constitution bonus.

Definition at line 225 of file weapon_improver.c.

◆ IMPROVE_DAMAGE

#define IMPROVE_DAMAGE   2

Increase damage.

Definition at line 220 of file weapon_improver.c.

◆ IMPROVE_DEX

#define IMPROVE_DEX   6

Increase dexterity bonus.

Definition at line 224 of file weapon_improver.c.

◆ IMPROVE_ENCHANT

#define IMPROVE_ENCHANT   4

Increase magic.

Definition at line 222 of file weapon_improver.c.

◆ IMPROVE_INT

#define IMPROVE_INT   10

Increase intelligence bonus.

Definition at line 228 of file weapon_improver.c.

◆ IMPROVE_POW

#define IMPROVE_POW   11

Increase power bonus.

Definition at line 229 of file weapon_improver.c.

◆ IMPROVE_PREPARE

#define IMPROVE_PREPARE   1

Prepare the weapon.

Definition at line 219 of file weapon_improver.c.

◆ IMPROVE_STR

#define IMPROVE_STR   5

Increase strength bonus.

Definition at line 223 of file weapon_improver.c.

◆ IMPROVE_WEIGHT

#define IMPROVE_WEIGHT   3

Decrease weight.

Definition at line 221 of file weapon_improver.c.

◆ IMPROVE_WIS

#define IMPROVE_WIS   8

Increase wisdom bonus.

Definition at line 226 of file weapon_improver.c.

Function Documentation

◆ check_item()

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 disinfect::count, FLAG_CURSED, FLAG_DAMNED, FLAG_UNPAID, FOR_BELOW_FINISH, FOR_BELOW_PREPARE, give::op, QUERY_FLAG, and Ice::tmp.

Referenced by check_sacrifice().

+ Here is the caller graph for this function:

◆ check_sacrifice()

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(), disinfect::count, draw_ext_info_format(), MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, NDI_UNIQUE, give::op, and obj::slaying.

Referenced by improve_weapon().

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

◆ eat_item()

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 object_decrease_nrof(), and give::op.

Referenced by improve_weapon().

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

◆ improve_weapon()

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, 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, 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, give::op, PLAYER, liv::Pow, prepare_weapon(), QUERY_FLAG, settings, obj::slaying, liv::sp, obj::stats, liv::Str, 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:

◆ improve_weapon_stat()

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, object_decrease_nrof_by_one, give::op, and statname.

Referenced by improve_weapon().

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

◆ init_type_weapon_improver()

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:

◆ prepare_weapon()

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 draw_ext_info(), MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, NDI_UNIQUE, and give::op.

Referenced by improve_weapon().

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

◆ weapon_improver_type_apply()

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

Attempts to apply weapon_improver.

Parameters
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 50 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, give::op, P_NO_MAGIC, PLAYER, QUERY_FLAG, obj::type, UPD_FLAGS, UPD_NAME, UPD_NROF, nlohmann::detail::void(), 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: