Crossfire Server, Trunk  R20513
Data Structures | Macros | Typedefs | Functions | Variables
bwp.c File Reference
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <global.h>
Include dependency graph for bwp.c:

Go to the source code of this file.

Data Structures

struct  string_array
 

Macros

#define LO_NEWFILE   2
 
#define MAX_SIZE   64
 
#define NA   "n/a"
 

Typedefs

typedef struct string_array String_Array
 

Functions

int apply_auto (object *op)
 Map was just loaded, handle op's initialization. More...
 
void apply_auto_fix (mapstruct *m)
 Go through the entire map (only the first time when an original map is loaded) and performs special actions for certain objects (most initialization of chests and creation of treasures and stuff). More...
 
static char * cat_template (char *source, char *add)
 Concatenates a string, and free concatenated string. More...
 
void clean_tmp_files (void)
 Remove temporary map files. More...
 
static char * do_template (const char *template, const char **vars, const char **values)
 Processes a template. More...
 
void dragon_ability_gain (object *ob, int x, int y)
 When a dragon-player gains a new stage of evolution, he gets some treasure. More...
 
void draw_ext_info (int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *txt)
 Those are dummy functions defined to resolve all symboles. More...
 
void draw_ext_info_format (int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
 Sends message to player(s). More...
 
void emergency_save (int x)
 Save all players. More...
 
void esrv_del_item (player *pl, object *ob)
 Tells the client to delete an item. More...
 
void esrv_send_item (object *ob, object *obx)
 Sends item's info to player. More...
 
void esrv_update_spells (player *pl)
 This looks for any spells the player may have that have changed their stats. More...
 
int execute_event (object *op, int eventcode, object *activator, object *third, const char *message, int fix)
 
int execute_global_event (int eventcode,...)
 
void ext_info_map (int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1)
 Writes to everyone on the specified map. More...
 
objectfind_skill_by_number (object *who, int skillno)
 This returns the skill pointer of the given name (the one that accumulates exp, has the level, etc). More...
 
void free_data (String_Array *array)
 Frees the item's data of specified String_Array. More...
 
static void free_if_used (char *p)
 Frees memory if the pointer was ever given a string. More...
 
const char * join_with_comma (String_Array *array)
 Joins strings with a comma and space. More...
 
int main (int argc, char *argv[])
 
void move_firewall (object *ob)
 Move for FIREWALL. More...
 
void push (String_Array *array, const char *string)
 Add a string to a String_Array struct. More...
 
static int read_template (const char *name, char **buffer)
 Reads a file in memory. More...
 
void set_darkness_map (mapstruct *m)
 Set the darkness level for a map, based on the time of the day. More...
 
void set_map_timeout (void)
 
static int sort_archetypes (const void *a, const void *b)
 Sort archetypes alphabetically. More...
 
static int sortbyname (const void *a, const void *b)
 Sort values alphabetically. More...
 

Variables

const char *const flag_names [NUM_FLAGS+1]
 This is a list of pointers that correspond to the FLAG_. More...
 
char * monster_attack_row
 
char * monster_canuse_row
 
char * monster_entry
 
char * monster_lore_row
 
char * monster_page_foot
 
char * monster_page_head
 
char * monster_protected_row
 
char * monster_special_row
 
char * monster_vulnerable_row
 

Macro Definition Documentation

#define LO_NEWFILE   2

Definition at line 36 of file bwp.c.

#define MAX_SIZE   64

Definition at line 37 of file bwp.c.

#define NA   "n/a"

Definition at line 38 of file bwp.c.

Referenced by main().

Typedef Documentation

typedef struct string_array String_Array

Function Documentation

int apply_auto ( object op)

Map was just loaded, handle op's initialization.

Generates shop floor's item, and treasures.

Parameters
opobject to initialize.
Returns
1 if object was initialized, 0 else.
Note
auto_apply() has been renamed to apply_auto()

Definition at line 704 of file bwp.c.

References CLEAR_FLAG, create_treasure(), mapdef::difficulty, liv::exp, FLAG_AUTO_APPLY, FLAG_CURSED, FLAG_DAMNED, FLAG_UNPAID, generate_treasure(), GT_ENVIRONMENT, HAS_RANDOM_ITEMS, liv::hp, identify(), obj::map, object_free_drop_inventory(), object_insert_in_map_at(), object_remove(), QUERY_FLAG, obj::randomitems, SET_FLAG, SHOP_FLOOR, obj::stats, TREASURE, obj::type, obj::x, and obj::y.

Referenced by apply_auto_fix().

Here is the call graph for this function:

Here is the caller graph for this function:

void apply_auto_fix ( mapstruct m)

Go through the entire map (only the first time when an original map is loaded) and performs special actions for certain objects (most initialization of chests and creation of treasures and stuff).

Calls apply_auto() if appropriate.

Parameters
mmap to fix.
Note
fix_auto_apply() has been renamed to apply_auto_fix()

Go through the entire map (only the first time when an original map is loaded) and performs special actions for certain objects (most initialization of chests and creation of treasures and stuff).

Added as part of glue cleaning. Ryo 2005-07-15

Definition at line 747 of file bwp.c.

References obj::above, apply_auto(), obj::arch, check_trigger(), CONTAINER, create_treasure(), mapdef::difficulty, FLAG_AUTO_APPLY, FLAG_MONSTER, GET_MAP_OB, HAS_RANDOM_ITEMS, liv::hp, MAP_HEIGHT, MAP_WIDTH, monster_check_apply_all(), PLAYER, QUERY_FLAG, obj::randomitems, obj::stats, TREASURE, TRIGGER_BUTTON, TRIGGER_PEDESTAL, and obj::type.

Here is the call graph for this function:

static char* cat_template ( char *  source,
char *  add 
)
static

Concatenates a string, and free concatenated string.

Parameters
sourcestring to append to. Can be NULL.
addstring that is appened. Will be free()d after. Must not be NULL.
Returns
new string that should be free()d by caller.

Definition at line 112 of file bwp.c.

void clean_tmp_files ( void  )

Remove temporary map files.

Todo:
check logic, why is file only removed if map is in memory?

Definition at line 816 of file bwp.c.

static char* do_template ( const char *  template,
const char **  vars,
const char **  values 
)
static

Processes a template.

Variables in the form #VARIABLE# will be substituted for specified values.

Parameters
templatetemplate to process.
varsvariables to replace. Array must be NULL-terminated.
valuesvariables to replace by. Must be the same size as vars, no NULL element allowed.
Returns
filled-in template, that must be free()d be caller. NULL if memory allocation error.
Note
returned string will be a memory block larger than required, for performance reasons.

Definition at line 185 of file bwp.c.

References string_array::count, and strdup().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void dragon_ability_gain ( object ob,
int  x,
int  y 
)

When a dragon-player gains a new stage of evolution, he gets some treasure.

Parameters
whothe dragon player.
atnrthe attack-number of the ability focus.
levelability level.

Definition at line 822 of file bwp.c.

void draw_ext_info ( int  flags,
int  pri,
const object pl,
uint8_t  type,
uint8_t  subtype,
const char *  txt 
)

Those are dummy functions defined to resolve all symboles.

Sends message to player(s).

Added as part of glue cleaning. Ryo 2005-07-15

Definition at line 795 of file bwp.c.

References logfile.

void draw_ext_info_format ( int  flags,
int  pri,
const object pl,
uint8_t  type,
uint8_t  subtype,
const char *  format,
  ... 
)

Sends message to player(s).

This function is the same as draw_ext_info, but takes varargs format. Otherwise, the meaning of all the fields is the same. This is perhaps not the most efficient as we do vsnprintf on both the old and newbuf, but it simplifies the code greatly since we can just call draw_ext_info.

Parameters
flagsVarious flags - mostly color, plus a few specials.
priPriority. It is a little odd - the lower the value, the more important it is. Thus, 0 gets sent no matter what. Otherwise, the value must be less than the listening level that the player has set. Unfortunately, there is no clear guideline on what each level does what.
plCan be passed as NULL - in fact, this will be done if NDI_ALL is set in the flags.
typeThe type MSG_TYPE for the type of message.
subtypeThe type MSG_TYPE for the subtype of message.
formatThe message to send, with optional format specifiers.

Definition at line 799 of file bwp.c.

References logfile.

void emergency_save ( int  x)

Save all players.

Parameters
flagif non zero, it means that we want to try and save everyone, but keep the game running. Thus, we don't want to free any information.

Definition at line 813 of file bwp.c.

void esrv_del_item ( player pl,
object ob 
)

Tells the client to delete an item.

Uses the item command with a -1 location.

Definition at line 832 of file bwp.c.

void esrv_send_item ( object ob,
object obx 
)

Sends item's info to player.

Definition at line 819 of file bwp.c.

void esrv_update_spells ( player pl)

This looks for any spells the player may have that have changed their stats.

It then sends an updspell packet for each spell that has changed in this way.

Definition at line 835 of file bwp.c.

int execute_event ( object op,
int  eventcode,
object activator,
object third,
const char *  message,
int  fix 
)

Definition at line 838 of file bwp.c.

int execute_global_event ( int  eventcode,
  ... 
)

Definition at line 842 of file bwp.c.

void ext_info_map ( int  color,
const mapstruct map,
uint8_t  type,
uint8_t  subtype,
const char *  str1 
)

Writes to everyone on the specified map.

Parameters
colorThe color of the message
mapThe map where the players receiving the message are located
typeThe message type
subtypeThe message subtype
str1The message to be sent

Definition at line 806 of file bwp.c.

References logfile.

object* find_skill_by_number ( object who,
int  skillno 
)

This returns the skill pointer of the given name (the one that accumulates exp, has the level, etc).

It is presumed that the player will be needing to actually use the skill, so a skill tool will be equipped if one if found to benefit from its bonuses.

This code is basically the same as find_skill_by_name() above, but instead of a skill name, we search by matching number.

Parameters
whoplayer applying a skill.
skillnoskill subtype.
Returns
skill object if player can use it, NULL else.

Definition at line 828 of file bwp.c.

void free_data ( String_Array array)

Frees the item's data of specified String_Array.

Will free array->item and its fields.

Parameters
arrayelement we want to clean.

Definition at line 325 of file bwp.c.

References string_array::count, and string_array::item.

Referenced by main().

Here is the caller graph for this function:

static void free_if_used ( char *  p)
static

Frees memory if the pointer was ever given a string.

There's probably a cleaner way to do this, but this frees the memory given to a pointer if the pointer points to a string longer than zero length. It's to get rid of "in free(): warning: junk pointer, too high to make sense" errors.

Parameters
pPointer to free memory from

Definition at line 253 of file bwp.c.

const char* join_with_comma ( String_Array array)

Joins strings with a comma and space.

Takes an array of strings and joins them togther with a comma and a space between each of them.

Parameters
arrayPointer to struct of type String_Array, containing strings to join

Definition at line 344 of file bwp.c.

References string_array::count, string_array::item, and sortbyname().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)
void move_firewall ( object ob)

Move for FIREWALL.

firewalls fire other spells. The direction of the wall is stored in op->direction. walls can have hp, so they can be torn down.

Parameters
opfirewall.

Definition at line 810 of file bwp.c.

void push ( String_Array array,
const char *  string 
)

Add a string to a String_Array struct.

Adds the new string to the struct's 'item' array, and updates the 'count'value.

Parameters
arrayThe array to be appended
stringThe new string to append

Definition at line 310 of file bwp.c.

References string_array::count, string_array::item, and strdup_local.

Referenced by check_trigger(), and main().

Here is the caller graph for this function:

static int read_template ( const char *  name,
char **  buffer 
)
static

Reads a file in memory.

Parameters
namefile path to read.
bufferwhere to store. Can be left uninitialized in case of errors.
Returns
1 if error, 0 else.

Definition at line 131 of file bwp.c.

Referenced by main().

Here is the caller graph for this function:

void set_darkness_map ( mapstruct m)

Set the darkness level for a map, based on the time of the day.

Parameters
mmap to alter.

Definition at line 825 of file bwp.c.

void set_map_timeout ( void  )

Definition at line 696 of file bwp.c.

static int sort_archetypes ( const void *  a,
const void *  b 
)
static

Sort archetypes alphabetically.

Used by qsort to sort archetypes alphabetically without regard to case

Parameters
aFirst value
bSecond value

Definition at line 288 of file bwp.c.

References archt::clone, obj::name, and strcasecmp().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sortbyname ( const void *  a,
const void *  b 
)
static

Sort values alphabetically.

Used by qsort to sort values alphabetically without regard to case

Parameters
aFirst value
bSecond value

Definition at line 271 of file bwp.c.

References strcasecmp().

Referenced by join_with_comma().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* const flag_names[NUM_FLAGS+1]

This is a list of pointers that correspond to the FLAG_.

. values. This is a simple 1:1 mapping - if FLAG_FRIENDLY is 15, then the 15'th element of this array should match that name. If an entry is NULL, that is a flag not to loaded/saved.

Copied from common/loader.c; perhaps should be defined elsewhere?

Definition at line 69 of file bwp.c.

Referenced by main().

char* monster_attack_row

Definition at line 52 of file bwp.c.

Referenced by main().

char* monster_canuse_row

Definition at line 48 of file bwp.c.

Referenced by main().

char* monster_entry

Definition at line 47 of file bwp.c.

Referenced by main().

char* monster_lore_row

Definition at line 53 of file bwp.c.

Referenced by main().

char* monster_page_foot

Definition at line 46 of file bwp.c.

Referenced by main().

char* monster_page_head

Definition at line 45 of file bwp.c.

Referenced by main().

char* monster_protected_row

Definition at line 49 of file bwp.c.

Referenced by main().

char* monster_special_row

Definition at line 51 of file bwp.c.

Referenced by main().

char* monster_vulnerable_row

Definition at line 50 of file bwp.c.

Referenced by main().