Crossfire Client, Branches  R11627
mapdata.c File Reference
#include <assert.h>
#include <stdlib.h>
#include "client.h"
#include "external.h"
#include "mapdata.h"
+ Include dependency graph for mapdata.c:

Go to the source code of this file.

Data Structures

struct  BigCell
 

Macros

#define CLEAR_CELLS(x, y, len_y)
 
#define CURRENT_MAX_VIEW   33
 
#define FOG_BORDER_MIN   128
 
#define FOG_MAP_SIZE   512
 
#define MAX_FACE_SIZE   16
 

Functions

static void expand_clear_bigface (int x, int y, int w, int h, int layer, int set_need_update)
 
static void expand_clear_bigface_from_layer (int x, int y, int layer, int set_need_update)
 
static void expand_clear_face (int x, int y, int w, int h, int layer)
 
static void expand_clear_face_from_layer (int x, int y, int layer)
 
static void expand_need_update (int x, int y, int w, int h)
 
static void expand_need_update_from_layer (int x, int y, int layer)
 
static void expand_set_bigface (int x, int y, int layer, sint16 face, int clear)
 
static void expand_set_face (int x, int y, int layer, sint16 face, int clear)
 
void mapdata_animation (void)
 
sint16 mapdata_bigface (int x, int y, int layer, int *ww, int *hh)
 
sint16 mapdata_bigface_head (int x, int y, int layer, int *ww, int *hh)
 
void mapdata_clear_old (int x, int y)
 
void mapdata_clear_space (int x, int y)
 
sint16 mapdata_face (int x, int y, int layer)
 
static void mapdata_get_image_size (int face, uint8 *w, uint8 *h)
 
void mapdata_init (void)
 
int mapdata_is_inside (int x, int y)
 
void mapdata_newmap (void)
 
void mapdata_reset (void)
 
void mapdata_scroll (int dx, int dy)
 
void mapdata_set_anim_layer (int x, int y, uint16 anim, uint8 anim_speed, int layer)
 
void mapdata_set_check_space (int x, int y)
 
void mapdata_set_darkness (int x, int y, int darkness)
 
void mapdata_set_face_layer (int x, int y, sint16 face, int layer)
 
void mapdata_set_size (int viewx, int viewy)
 
void mapdata_set_smooth (int x, int y, int smooth, int layer)
 
static void mark_resmooth (int x, int y, int layer)
 
static void recenter_virtual_map_view (int diff_x, int diff_y)
 
static void set_darkness (int x, int y, int darkness)
 

Variables

static struct BigCell bigfaces [MAX_VIEW][MAX_VIEW][MAXLAYERS]
 
static struct BigCellbigfaces_head
 
static int height
 
struct Map the_map
 
static int width
 

Macro Definition Documentation

#define CLEAR_CELLS (   x,
  y,
  len_y 
)
Value:
do { \
int clear_cells_i, j; \
memset(&the_map.cells[(x)][(y)], 0, sizeof(the_map.cells[(x)][(y)])*(len_y)); \
for (clear_cells_i = 0; clear_cells_i < (len_y); clear_cells_i++) \
{ \
for (j=0; j < MAXLAYERS; j++) { \
the_map.cells[(x)][(y)+clear_cells_i].heads[j].size_x = 1; \
the_map.cells[(x)][(y)+clear_cells_i].heads[j].size_y = 1; \
} \
} \
} while(0)
sint8 size_x
Definition: mapdata.h:46
struct Map the_map
Definition: mapdata.c:121
struct MapCell ** cells
Definition: mapdata.h:95
#define MAXLAYERS
Definition: mapdata.h:32
struct MapCellLayer heads[MAXLAYERS]
Definition: mapdata.h:77
sint8 size_y
Definition: mapdata.h:47

Clear cells the_map.cells[x][y..y+len_y-1].

Definition at line 35 of file mapdata.c.

Referenced by mapdata_init(), mapdata_newmap(), and recenter_virtual_map_view().

#define CURRENT_MAX_VIEW   33

Definition at line 70 of file mapdata.c.

Referenced by mapdata_animation().

#define FOG_BORDER_MIN   128

After shifting the virtual map: new minimum distance of the view area to the new virtual map border.

Definition at line 58 of file mapdata.c.

Referenced by recenter_virtual_map_view().

#define MAX_FACE_SIZE   16

Maximum size of a big face image in tiles. Larger faces will be clipped top/left.

Definition at line 63 of file mapdata.c.

Referenced by expand_clear_bigface(), expand_clear_face(), expand_need_update(), expand_set_bigface(), expand_set_face(), mapdata_bigface(), mapdata_get_image_size(), and recenter_virtual_map_view().

Function Documentation

static void expand_clear_bigface ( int  x,
int  y,
int  w,
int  h,
int  layer,
int  set_need_update 
)
static

Clear a face from bigfaces[].

x, y, and layer are the coordinates and layer of the head relative to pl_pos.

w and h give the width and height of the face to clear.

If set_need_update is set, all affected tiles are marked as "need_update".

Definition at line 306 of file mapdata.c.

References bigfaces, Map::cells, MapCellLayer::face, FOG_MAP_SIZE, BigCell::head, height, MAX_FACE_SIZE, MAX_VIEW, MAXLAYERS, MapCell::need_update, pl_pos, MapCellLayer::size_x, MapCellLayer::size_y, BigCell::tail, the_map, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by expand_clear_bigface_from_layer().

+ Here is the caller graph for this function:

static void expand_clear_bigface_from_layer ( int  x,
int  y,
int  layer,
int  set_need_update 
)
static

Clear a face from bigfaces[].

x, y, and layer are the coordinates and layer of the head relative to pl_pos.

If set_need_update is set, all affected tiles are marked as "need_update".

Definition at line 360 of file mapdata.c.

References bigfaces, expand_clear_bigface(), MapCellLayer::face, BigCell::head, MAX_VIEW, MAXLAYERS, BigCell::next, BigCell::prev, MapCellLayer::size_x, and MapCellLayer::size_y.

Referenced by expand_set_bigface(), mapdata_newmap(), and mapdata_scroll().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void expand_clear_face ( int  x,
int  y,
int  w,
int  h,
int  layer 
)
static

Clear a face from the_map.cells[].

x, y, and layer are the coordinates of the head and layer relative to pl_pos.

w and h give the width and height of the face to clear.

Definition at line 175 of file mapdata.c.

References MapCellLayer::animation, MapCellLayer::animation_left, MapCellLayer::animation_phase, MapCellLayer::animation_speed, Map::cells, MapCellLayer::face, FOG_MAP_SIZE, MapCell::heads, mark_resmooth(), MAX_FACE_SIZE, MAXLAYERS, MapCell::need_resmooth, MapCell::need_update, MapCellLayer::size_x, MapCellLayer::size_y, MapCell::tails, and the_map.

Referenced by expand_clear_face_from_layer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void expand_clear_face_from_layer ( int  x,
int  y,
int  layer 
)
static

Clear a face from the_map.cells[].

x, y, and layer are the coordinates of the head and layer relative to pl_pos.

Definition at line 230 of file mapdata.c.

References Map::cells, expand_clear_face(), FOG_MAP_SIZE, MapCell::heads, MAXLAYERS, MapCellLayer::size_x, MapCellLayer::size_y, and the_map.

Referenced by expand_set_face(), mapdata_animation(), mapdata_bigface(), mapdata_clear_old(), mapdata_set_anim_layer(), and mapdata_set_face_layer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void expand_need_update ( int  x,
int  y,
int  w,
int  h 
)
static

Mark a face as "need_update".

x and y are the coordinates of the head relative to pl_pos.

w and h is the size of the face.

Definition at line 468 of file mapdata.c.

References Map::cells, FOG_MAP_SIZE, MAX_FACE_SIZE, MapCell::need_update, and the_map.

Referenced by expand_need_update_from_layer().

+ Here is the caller graph for this function:

static void expand_need_update_from_layer ( int  x,
int  y,
int  layer 
)
static

Mark a face as "need_update".

x, y, and layer are the coordinates and layer of the head relative to pl_pos.

Definition at line 496 of file mapdata.c.

References Map::cells, expand_need_update(), MapCellLayer::face, FOG_MAP_SIZE, MapCell::heads, MAXLAYERS, MapCellLayer::size_x, MapCellLayer::size_y, and the_map.

Referenced by mapdata_clear_space(), and mapdata_set_check_space().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void expand_set_bigface ( int  x,
int  y,
int  layer,
sint16  face,
int  clear 
)
static

Update a face into bigfaces[].

x, y, and layer are the coordinates and layer of the head relative to pl_pos.

face is the new face to set.

Definition at line 404 of file mapdata.c.

References bigfaces, bigfaces_head, Map::cells, expand_clear_bigface_from_layer(), MapCellLayer::face, FOG_MAP_SIZE, BigCell::head, height, mapdata_get_image_size(), MAX_FACE_SIZE, MAX_VIEW, MAXLAYERS, MapCell::need_update, BigCell::next, pl_pos, BigCell::prev, MapCellLayer::size_x, MapCellLayer::size_y, BigCell::tail, the_map, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by mapdata_animation(), mapdata_clear_space(), mapdata_set_anim_layer(), and mapdata_set_face_layer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void expand_set_face ( int  x,
int  y,
int  layer,
sint16  face,
int  clear 
)
static

Update a face into the_map.cells[].

x, y, and layer are the coordinates and layer of the head relative to pl_pos.

face is the new face to set. if clear is set, clear this face. If not set, don't clear. the reason clear may not be set is because this is an animation update - animations must all be the same size, so when we set the data for the space, we will just overwrite the old data. Problem with clearing is that clobbers the animation data.

Definition at line 256 of file mapdata.c.

References Map::cells, expand_clear_face_from_layer(), MapCellLayer::face, FOG_MAP_SIZE, MapCell::heads, mapdata_get_image_size(), mark_resmooth(), MAX_FACE_SIZE, MAXLAYERS, MapCell::need_update, MapCellLayer::size_x, MapCellLayer::size_y, MapCell::tails, and the_map.

Referenced by mapdata_animation(), mapdata_set_anim_layer(), and mapdata_set_face_layer().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

sint16 mapdata_bigface ( int  x,
int  y,
int  layer,
int *  ww,
int *  hh 
)

Returns the face to display at a given location. This function returns the "tail" information, i.e. big faces expanded by the client.

*ww and *hh return the offset of the current tile relative to the head; 0 <= *ww < (width of face), 0 <= *hh < (height of face).

When drawing the map view, this function must be used instead than a direct access to the_map.cells[]. This is because the_map.cells[] eventually still contains obsolete (fog of war) big face information; this function detects and clears such faces.

Definition at line 966 of file mapdata.c.

References bigfaces, Map::cells, MapCell::cleared, expand_clear_face_from_layer(), MapCellLayer::face, BigCell::head, MapCell::heads, height, BigCell::layer, MAX_FACE_SIZE, MAXLAYERS, pl_pos, MapCellLayer::size_x, MapCellLayer::size_y, BigCell::tail, MapCell::tails, the_map, width, BigCell::x, PlayerPosition::x, BigCell::y, and PlayerPosition::y.

Referenced by display_mapcell().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

sint16 mapdata_bigface_head ( int  x,
int  y,
int  layer,
int *  ww,
int *  hh 
)
void mapdata_clear_old ( int  x,
int  y 
)

Definition at line 744 of file mapdata.c.

References Map::cells, MapCell::cleared, MapCell::darkness, expand_clear_face_from_layer(), FOG_MAP_SIZE, MapCell::have_darkness, height, MAX_VIEW, MAXLAYERS, pl_pos, the_map, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by Map2Cmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_clear_space ( int  x,
int  y 
)

Definition at line 596 of file mapdata.c.

References Map::cells, MapCell::cleared, expand_need_update_from_layer(), expand_set_bigface(), MapCellLayer::face, FOG_MAP_SIZE, MapCell::heads, height, MAX_VIEW, MAXLAYERS, MapCell::need_update, pl_pos, the_map, TRUE, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by Map2Cmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

sint16 mapdata_face ( int  x,
int  y,
int  layer 
)

Returns the face to display at a given location. This function returns the "head" information, i.e. the face information sent by the server.

Definition at line 955 of file mapdata.c.

References Map::cells, MapCellLayer::face, MapCell::heads, height, MAXLAYERS, pl_pos, the_map, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by display_mapcell().

+ Here is the caller graph for this function:

static void mapdata_get_image_size ( int  face,
uint8 w,
uint8 h 
)
static

Return the size of a face in tiles. The returned size is at between 1 and MAX_FACE_SIZE (inclusive).

Definition at line 1252 of file mapdata.c.

References get_map_image_size(), and MAX_FACE_SIZE.

Referenced by expand_set_bigface(), and expand_set_face().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_init ( void  )

Initializes the module. Allocates memory for the_map. This functions must be called before any other function is used.

Definition at line 514 of file mapdata.c.

References bigfaces, Map::cells, CLEAR_CELLS, MapCellLayer::face, FOG_MAP_SIZE, BigCell::head, height, BigCell::layer, LOG(), LOG_ERROR, MAX_VIEW, MAXLAYERS, BigCell::next, pl_pos, BigCell::prev, MapCellLayer::size_x, MapCellLayer::size_y, BigCell::tail, the_map, width, BigCell::x, Map::x, PlayerPosition::x, BigCell::y, Map::y, and PlayerPosition::y.

Referenced by init_windows(), mapdata_reset(), mapdata_set_size(), and parse_args().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mapdata_is_inside ( int  x,
int  y 
)

Checks whether the given coordinates are within the current display size (as set by mapdata_set_size).

Definition at line 587 of file mapdata.c.

References height.

void mapdata_newmap ( void  )

Clears the map view. Must be called whenever a newmap command was received from the server.

Definition at line 935 of file mapdata.c.

References Map::cells, CLEAR_CELLS, display_map_newmap(), expand_clear_bigface_from_layer(), FOG_MAP_SIZE, BigCell::layer, MapCell::need_update, the_map, BigCell::x, and BigCell::y.

Referenced by NewmapCmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_reset ( void  )

Resets all stored information.

Definition at line 572 of file mapdata.c.

References mapdata_init().

Referenced by main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_scroll ( int  dx,
int  dy 
)

Scrolls the map view. Must be called whenever a map_scroll command was received from the server.

Definition at line 859 of file mapdata.c.

References Map::cells, MapCell::cleared, CONFIG_MAPSCROLL, display_mapscroll(), expand_clear_bigface_from_layer(), BigCell::head, height, BigCell::layer, MapCell::need_update, BigCell::next, pl_pos, recenter_virtual_map_view(), MapCellLayer::size_x, MapCellLayer::size_y, the_map, want_config, width, BigCell::x, PlayerPosition::x, BigCell::y, and PlayerPosition::y.

Referenced by Map2Cmd(), and map_scrollCmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_set_check_space ( int  x,
int  y 
)

Definition at line 638 of file mapdata.c.

References Map::cells, MapCell::cleared, expand_need_update_from_layer(), MapCellLayer::face, FOG_MAP_SIZE, MapCell::have_darkness, MapCell::heads, height, MAX_VIEW, MAXLAYERS, MapCell::need_update, pl_pos, MapCell::tails, the_map, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by Map2Cmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_set_darkness ( int  x,
int  y,
int  darkness 
)

Definition at line 688 of file mapdata.c.

References FOG_MAP_SIZE, height, MAX_VIEW, pl_pos, set_darkness(), width, PlayerPosition::x, and PlayerPosition::y.

Referenced by Map2Cmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_set_face_layer ( int  x,
int  y,
sint16  face,
int  layer 
)

Definition at line 770 of file mapdata.c.

References Map::cells, MapCell::cleared, expand_clear_face_from_layer(), expand_set_bigface(), expand_set_face(), FOG_MAP_SIZE, height, MAX_VIEW, MapCell::need_update, pl_pos, the_map, TRUE, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by Map2Cmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_set_size ( int  viewx,
int  viewy 
)

Sets the current display size. Must be called whenever a new display size was negotiated with the server.

Definition at line 577 of file mapdata.c.

References FOG_MAP_SIZE, height, mapdata_init(), pl_pos, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by negotiate_connection(), on_drawingarea_map_configure_event(), and SetupCmd().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mapdata_set_smooth ( int  x,
int  y,
int  smooth,
int  layer 
)

Definition at line 711 of file mapdata.c.

References Map::cells, FOG_MAP_SIZE, MAX_VIEW, MapCell::need_resmooth, pl_pos, MapCell::smooth, the_map, Map::x, PlayerPosition::x, Map::y, and PlayerPosition::y.

Referenced by Map2Cmd().

+ Here is the caller graph for this function:

static void mark_resmooth ( int  x,
int  y,
int  layer 
)
static

Definition at line 156 of file mapdata.c.

References Map::cells, FOG_MAP_SIZE, MapCell::need_resmooth, MapCell::smooth, and the_map.

Referenced by expand_clear_face(), and expand_set_face().

+ Here is the caller graph for this function:

static void recenter_virtual_map_view ( int  diff_x,
int  diff_y 
)
static

Check if current map position is out of bounds if shifted by (dx, dy). If so, shift the virtual map so that the map view is within bounds again.

Assures that [pl_pos.x-MAX_FACE_SIZE..pl_pos.x+MAX_VIEW+1] is within the bounds of the virtual map area. This covers the area a map1a command may affect plus a one tile border.

Definition at line 1084 of file mapdata.c.

References Map::cells, CLEAR_CELLS, FOG_BORDER_MIN, FOG_MAP_SIZE, height, MAX_FACE_SIZE, MAX_VIEW, pl_pos, the_map, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by mapdata_scroll().

+ Here is the caller graph for this function:

static void set_darkness ( int  x,
int  y,
int  darkness 
)
static

Update darkness information. This function is called whenever a map1a command from the server was received.

x and y are absolute coordinates into the_map.cells[].

darkness is the new darkness value.

Definition at line 132 of file mapdata.c.

References Map::cells, CFG_DM_SDL, CFG_LT_PIXEL, CFG_LT_PIXEL_BEST, CONFIG_DISPLAYMODE, CONFIG_LIGHTING, MapCell::darkness, MapCell::have_darkness, height, MapCell::need_update, the_map, use_config, width, Map::x, and Map::y.

Referenced by mapdata_set_darkness().

+ Here is the caller graph for this function:

Variable Documentation

struct BigCell bigfaces[MAX_VIEW][MAX_VIEW][MAXLAYERS]
static

The variable bigfaces[] contains information about big faces (faces with a width or height >1). The viewable area bigfaces[0..width-1][0..height-1] is unused.

Definition at line 118 of file mapdata.c.

Referenced by expand_clear_bigface(), expand_clear_bigface_from_layer(), expand_set_bigface(), mapdata_animation(), mapdata_bigface(), mapdata_bigface_head(), and mapdata_init().

struct BigCell* bigfaces_head
static

Contains the head of a list of all currently active big faces outside the view area. All entries are part of bigfaces[].

Definition at line 111 of file mapdata.c.

Referenced by expand_set_bigface().