Crossfire Server, Trunk  R20513
Functions
region.c File Reference

Region management. More...

#include "global.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for region.c:

Go to the source code of this file.

Functions

static void assign_region_parents (void)
 Links child with their parent from the parent_name field. More...
 
objectget_jail_exit (object *op)
 Returns an object which is an exit through which the player represented by op should be sent in order to be imprisoned. More...
 
const char * get_name_of_region_for_map (const mapstruct *m)
 Gets the name of a region for a map. More...
 
regionget_region_by_map (mapstruct *m)
 Gets a region from a map. More...
 
regionget_region_by_name (const char *region_name)
 Gets a region by name. More...
 
regionget_region_from_string (const char *name)
 Tries to find a region that 'name' corresponds to. More...
 
const char * get_region_longname (const region *r)
 Gets the longname of a region. More...
 
const char * get_region_msg (const region *r)
 Gets a message for a region. More...
 
regionget_region_struct (void)
 Allocates and zeros a region struct, this isn't free()'d anywhere, so might be a memory leak, but it shouldn't matter too much since it isn't called that often.... More...
 
int init_regions (void)
 Initialises regions from the regions file. More...
 
static void parse_regions (FILE *fp)
 Reads/parses the region file, and copies into a linked list of region structs. More...
 
int region_is_child_of_region (const region *child, const region *r)
 Checks if a region is a child of another. More...
 

Detailed Description

Region management.

A region is a group of maps. It includes a "parent" region.

Definition in file region.c.

Function Documentation

static void assign_region_parents ( void  )
static

Links child with their parent from the parent_name field.

Definition at line 508 of file region.c.

References first_region, get_region_by_name(), llevDebug, llevError, LOG(), regiondef::name, regiondef::next, regiondef::parent, regiondef::parent_name, and region_count.

Referenced by init_regions().

Here is the call graph for this function:

Here is the caller graph for this function:

object* get_jail_exit ( object op)

Returns an object which is an exit through which the player represented by op should be sent in order to be imprisoned.

If there is no suitable place to which an exit can be constructed, then NULL will be returned. The caller is responsible for freeing the object created by this function.

Parameters
opObject we want to jail. Must be a player.
Returns
exit to jail, or NULL, in which case a message is LOG()ged .

Definition at line 260 of file region.c.

References add_string(), EXIT_PATH, EXIT_X, EXIT_Y, FLAG_DAMNED, get_region_by_map(), regiondef::jailmap, regiondef::jailx, regiondef::jaily, llevDebug, llevError, LOG(), obj::map, regiondef::name, object_new(), regiondef::parent, PLAYER, SET_FLAG, and obj::type.

Referenced by player_arrest().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* get_name_of_region_for_map ( const mapstruct m)

Gets the name of a region for a map.

Since we won't assume all maps have a region set properly, we need an explicit check that it is, this is much nicer here than scattered throughout the map code.

Parameters
mmap
Returns
  • region's name if map has a region
  • if no region is set for the map, returns the first region with the 'fallback' property
  • if no fallback region, LOG()s an info message and returns "unknown".

Definition at line 92 of file region.c.

References regiondef::fallback, first_region, llevInfo, LOG(), regiondef::name, mapdef::name, regiondef::next, and mapdef::region.

Referenced by current_region_info(), get_region_by_map(), get_who_escape_code_value(), and pick_bg_music().

Here is the call graph for this function:

Here is the caller graph for this function:

region* get_region_by_map ( mapstruct m)

Gets a region from a map.

Parameters
mmap we want the region of.
Returns
region.
Todo:
This might need optimising at some point.

Definition at line 74 of file region.c.

References get_name_of_region_for_map(), and get_region_by_name().

Referenced by add_region_link(), cfapi_map_get_map_property(), command_whereabouts(), current_map_info(), enter_random_map(), enter_random_template_map(), get_jail_exit(), get_who_escape_code_value(), list_players(), process_map(), and teardown().

Here is the call graph for this function:

Here is the caller graph for this function:

region* get_region_by_name ( const char *  region_name)

Gets a region by name.

Used by the map parsing code.

Parameters
region_namename of region.
Returns
  • matching region
  • if no match, returns the first region with the 'fallback' property set and LOG()s to debug.
  • if it can't find a matching name and a fallback region it LOG()s an info message and returns NULL.

Definition at line 46 of file region.c.

References regiondef::fallback, first_region, llevDebug, llevInfo, LOG(), regiondef::name, and regiondef::next.

Referenced by assign_region_parents(), current_region_info(), get_region_by_map(), and load_map_header().

Here is the call graph for this function:

Here is the caller graph for this function:

region* get_region_from_string ( const char *  name)

Tries to find a region that 'name' corresponds to.

It looks, in order, for:

  • an exact match to region name (case insensitive)
  • an exact match to longname (case insensitive)
  • a substring that matches to the longname (eg Kingdom)
  • a substring that matches to the region name (eg nav)
  • if it can find none of these it returns the first parentless region (there should be only one of these - the top level one) An empty region name returns the top level region
Parameters
nameregion we're searching.
Returns
matching region.

Definition at line 121 of file region.c.

References first_region, regiondef::longname, regiondef::name, regiondef::next, regiondef::parent, and strcasecmp().

Referenced by command_who().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* get_region_longname ( const region r)

Gets the longname of a region.

The longname of a region is not a required field, any given region may want to not set it and use the parent's one instead.

Parameters
rregion we're searching the longname.
Returns
  • if a longname is set return it.
  • if there is a parent, call the function against that
  • if all fails, return a obviously wrong string if we can't get a longname, this should never happen. We also LOG() a debug message.

Definition at line 217 of file region.c.

References get_region_longname(), llevDebug, LOG(), regiondef::longname, regiondef::name, and regiondef::parent.

Referenced by command_whereabouts(), current_map_info(), current_region_info(), get_region_longname(), get_who_escape_code_value(), CRERegionPanel::setItem(), write_map_page(), write_region_index(), and write_region_page().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* get_region_msg ( const region r)

Gets a message for a region.

Parameters
rregion. Can't be NULL.
Returns
  • region's message if set
  • message of parent else
  • obviously wrong message if no parent, and we LOG() a debug message.

Definition at line 238 of file region.c.

References get_region_msg(), llevDebug, LOG(), regiondef::msg, regiondef::name, and regiondef::parent.

Referenced by current_region_info(), get_region_msg(), CRERegionPanel::setItem(), and write_region_page().

Here is the call graph for this function:

Here is the caller graph for this function:

region* get_region_struct ( void  )

Allocates and zeros a region struct, this isn't free()'d anywhere, so might be a memory leak, but it shouldn't matter too much since it isn't called that often....

Returns
initialised region structure.
Note
will never fail, as a memory allocation error calls fatal().
Todo:
free those pointers someday? :)

Definition at line 325 of file region.c.

References fatal(), and OUT_OF_MEMORY.

Referenced by main(), and parse_regions().

Here is the call graph for this function:

Here is the caller graph for this function:

int init_regions ( void  )

Initialises regions from the regions file.

Returns
  • Returns '0' on success, anything else if failed.

Definition at line 292 of file region.c.

References assign_region_parents(), Settings::datadir, first_region, llevError, LOG(), Settings::mapdir, MAX_BUF, parse_regions(), Settings::regions, settings, and snprintf.

Referenced by init_beforeplay(), init_library(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

static void parse_regions ( FILE *  fp)
static

Reads/parses the region file, and copies into a linked list of region structs.

Parameters
fpopened file to read from.

Definition at line 340 of file region.c.

References fatal(), first_region, get_region_struct(), HUGE_BUF, llevError, LOG(), MAX_BUF, regiondef::next, SEE_LAST_ERROR, and strdup_local.

Referenced by init_regions().

Here is the call graph for this function:

Here is the caller graph for this function:

int region_is_child_of_region ( const region child,
const region r 
)

Checks if a region is a child of another.

Parameters
childregion we want to test.
rpotential parent.
Returns
  • 1 if child has r as parent somewhere.
  • -1 if passed a NULL region
  • 0 else

Definition at line 190 of file region.c.

References regiondef::name, regiondef::parent, and region_is_child_of_region().

Referenced by list_players(), and region_is_child_of_region().

Here is the call graph for this function:

Here is the caller graph for this function: