Crossfire Server, Trunk
converter.cpp File Reference
#include "global.h"
#include <string.h>
#include <stdlib.h>
#include "ob_methods.h"
#include "ob_types.h"
#include "shop.h"
#include "sounds.h"
#include "sproto.h"
+ Include dependency graph for converter.cpp:

Go to the source code of this file.

Macros

#define CONV_FROM(xyz)   xyz->slaying
 
#define CONV_FROM_MATCH(xyz, _match)   (CONV_FROM(xyz) == (_match) || ((strchr(CONV_FROM(xyz),'*')) && wildcard_match(CONV_FROM(xyz),(_match))))
 
#define CONV_LIMIT(xyz)   ((xyz->stats.wc > 0) ? ((unsigned long)xyz->stats.wc) : INT32_MAX)
 
#define CONV_NEED(xyz)   (unsigned long)xyz->stats.food
 
#define CONV_NR(xyz)   (unsigned char)xyz->stats.sp
 
#define CONV_TO(xyz)   xyz->other_arch
 

Functions

static int convert_item (object *item, object *converter)
 
static method_ret converter_type_apply (object *converter, object *applier, int aflags)
 
static method_ret converter_type_move_on (object *trap, object *victim, object *originator)
 
static objectdo_item_conversion (object *converter, object *item, int weight_rem, int *status)
 
void init_type_converter (void)
 
static int wildcard_match (const char *string, const char *candidate)
 

Detailed Description

The implementation of the Converter class of objects.

Definition in file converter.cpp.

Macro Definition Documentation

◆ CONV_FROM

#define CONV_FROM (   xyz)    xyz->slaying

Definition at line 34 of file converter.cpp.

◆ CONV_FROM_MATCH

#define CONV_FROM_MATCH (   xyz,
  _match 
)    (CONV_FROM(xyz) == (_match) || ((strchr(CONV_FROM(xyz),'*')) && wildcard_match(CONV_FROM(xyz),(_match))))

Definition at line 39 of file converter.cpp.

◆ CONV_LIMIT

#define CONV_LIMIT (   xyz)    ((xyz->stats.wc > 0) ? ((unsigned long)xyz->stats.wc) : INT32_MAX)

Definition at line 37 of file converter.cpp.

◆ CONV_NEED

#define CONV_NEED (   xyz)    (unsigned long)xyz->stats.food

Definition at line 38 of file converter.cpp.

◆ CONV_NR

#define CONV_NR (   xyz)    (unsigned char)xyz->stats.sp

Definition at line 36 of file converter.cpp.

◆ CONV_TO

#define CONV_TO (   xyz)    xyz->other_arch

Definition at line 35 of file converter.cpp.

Function Documentation

◆ convert_item()

static int convert_item ( object item,
object converter 
)
static

Transforms an item into another item.

Parameters
itemThe object that triggered the converter - if it isn't of a type accepted by the converter, nothing will happen
converterThe object that is doing the conversion
Return values
-1If something went wrong when attempting the conversion
0If the item was not converted
1If the item got converted

Definition at line 220 of file converter.cpp.

References do_item_conversion(), object::map, object_insert_in_map_at(), takeitem::status, object::x, and object::y.

Referenced by converter_type_move_on().

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

◆ converter_type_apply()

static method_ret converter_type_apply ( object converter,
object applier,
int  aflags 
)
static

Apply the converter object.

Looks for the desired type of the converter in top-level inventory and active containers, and performs the conversion until inventory is full or until conversion is exhausted.

Parameters
converterThe converter we applied
applierThe player applying the converter.
aflagsThe apply flags (currently unused)
Returns
METHOD_OK

Definition at line 265 of file converter.cpp.

References object::carrying, CONV_FROM, do_item_conversion(), fix_object(), FLAG_UNPAID, get_weight_limit(), object::map, METHOD_OK, object_find_by_arch_name(), object_insert_in_map_at(), object_insert_in_ob(), PLAYER, QUERY_FLAG, object::stats, takeitem::status, living::Str, object::type, nlohmann::detail::void(), object::weight, object::x, and object::y.

Referenced by init_type_converter().

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

◆ converter_type_move_on()

static method_ret converter_type_move_on ( object trap,
object victim,
object originator 
)
static

Move on this Converter object.

Parameters
trapThe Converter we're moving on
victimThe object moving over this one
originatorThe object that caused the move_on event
Returns
METHOD_OK

Definition at line 235 of file converter.cpp.

References common_post_ob_move_on(), common_pre_ob_move_on(), convert_item(), create_archetype(), draw_ext_info_format(), object::map, MAX_BUF, METHOD_ERROR, METHOD_OK, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, give::name, NDI_UNIQUE, object_insert_in_map_at(), give::op, query_name(), sword_of_souls::victim, object::x, and object::y.

Referenced by init_type_converter().

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

◆ do_item_conversion()

static object* do_item_conversion ( object converter,
object item,
int  weight_rem,
int *  status 
)
static

Do the actual item conversion. Determine the number of sources item to remove and the number of result items to produce.

Parameters
converterThe converter being used
itemThe discovered source item object.
weight_remThe amount of weight we can add to the total. Used when doing direct-in-player-inventory conversions. Can be set to -1 if there is no weight limit, such as when using move_on.
statusThe conversion status. 1 if successful, 0 if no conversion nor error, -1 if error. Caller cannot pass NULL here.
Returns
A pointer to the produced object, which needs to be appropriately insert into map or inventory. Returns NULL if an error or no conversion happened.

Definition at line 96 of file converter.cpp.

References Settings::allow_broken_converters, CLEAR_FLAG, archetype::clone, CONV_FROM, CONV_FROM_MATCH, CONV_LIMIT, CONV_NEED, CONV_NR, diamondslots::cost, create_archetype(), FALSE, fix_generated_item(), FLAG_IS_A_TEMPLATE, FLAG_UNPAID, FOR_BELOW_FINISH, FOR_BELOW_PREPARE, GT_MINIMAL, if(), object::inv, say::item, llevError, LOG(), object::map, MIN, MONEY, object::name, guildjoin::ob, object_create_arch(), object_create_clone(), object_decrease_nrof(), object_free_drop_inventory(), object_remove(), object_unset_flag_inv(), object::other_arch, mapstruct::path, PLAYER, QUERY_FLAG, rndm(), SET_FLAG, settings, shop_contains(), takeitem::status, object::weight, object::x, and object::y.

Referenced by convert_item(), and converter_type_apply().

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

◆ init_type_converter()

void init_type_converter ( void  )

Initializer for the CONVERTER object type.

Definition at line 80 of file converter.cpp.

References CONVERTER, converter_type_apply(), converter_type_move_on(), register_apply(), and register_move_on().

Referenced by register_all_ob_types().

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

◆ wildcard_match()

static int wildcard_match ( const char *  string,
const char *  candidate 
)
static

Wildcard match where 'string' contains a '*' at the start, end, or both

Definition at line 46 of file converter.cpp.

References FALSE, m, make_face_from_files::str, and TRUE.