Crossfire Client, Trunk  R20996
mapdata.c File Reference
#include "client.h"
#include <assert.h>
#include <stdbool.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 CURRENT_MAX_VIEW   33
 
#define FOG_BORDER_MIN   128
 
#define FOG_MAP_SIZE   512
 
#define MAX_FACE_SIZE   16
 

Functions

static void clear_cells (int x, int y, int len_y)
 
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, gint16 face, int clear)
 
static void expand_set_face (int x, int y, int layer, gint16 face, int clear)
 
static void mapdata_alloc (struct Map *const map, const int width, const int height)
 
void mapdata_animation (void)
 
gint16 mapdata_bigface (int x, int y, int layer, int *ww, int *hh)
 
gint16 mapdata_bigface_head (int x, int y, int layer, int *ww, int *hh)
 
bool mapdata_can_smooth (int x, int y, int layer)
 
struct MapCellmapdata_cell (int x, int y)
 
void mapdata_clear_old (int x, int y)
 
void mapdata_clear_space (int x, int y)
 
bool mapdata_contains (int x, int y)
 
gint16 mapdata_face (int x, int y, int layer)
 
gint16 mapdata_face_info (int mx, int my, int layer, int *dx, int *dy)
 
void mapdata_free (void)
 
static void mapdata_get_image_size (int face, guint8 *w, guint8 *h)
 
static bool mapdata_has_tile (int x, int y, int layer)
 
static void mapdata_init (void)
 
int mapdata_is_inside (int x, int y)
 
void mapdata_newmap (void)
 
void mapdata_scroll (int dx, int dy)
 
void mapdata_set_anim_layer (int x, int y, guint16 anim, guint8 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, gint16 face, int layer)
 
void mapdata_set_size (int viewx, int viewy)
 
void mapdata_set_smooth (int x, int y, guint8 smooth, int layer)
 
void mapdata_size (int *x, int *y)
 
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
 
static struct Map the_map
 
static int width
 

Detailed Description

Map processing functions.

Definition in file mapdata.c.

Macro Definition Documentation

◆ CURRENT_MAX_VIEW

#define CURRENT_MAX_VIEW   33

Definition at line 48 of file mapdata.c.

Referenced by mapdata_animation().

◆ FOG_BORDER_MIN

#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 36 of file mapdata.c.

Referenced by recenter_virtual_map_view().

◆ FOG_MAP_SIZE

#define FOG_MAP_SIZE   512

Size of virtual map.

Definition at line 30 of file mapdata.c.

Referenced by mapdata_init().

◆ MAX_FACE_SIZE

#define MAX_FACE_SIZE   16

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

Definition at line 41 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

◆ clear_cells()

static void clear_cells ( int  x,
int  y,
int  len_y 
)
static

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

Definition at line 101 of file mapdata.c.

References MapCell::heads, mapdata_cell(), MAXLAYERS, MapCellLayer::size_x, and MapCellLayer::size_y.

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

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

◆ expand_clear_bigface()

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 343 of file mapdata.c.

References bigfaces, MapCellLayer::face, MapCellTailLayer::face, BigCell::head, Map::height, height, BigCell::layer, mapdata_cell(), MAX_FACE_SIZE, MAX_VIEW, MAXLAYERS, MapCell::need_update, pl_pos, MapCellLayer::size_x, MapCellTailLayer::size_x, MapCellLayer::size_y, MapCellTailLayer::size_y, BigCell::tail, the_map, Map::width, width, BigCell::x, PlayerPosition::x, BigCell::y, and PlayerPosition::y.

Referenced by expand_clear_bigface_from_layer().

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

◆ expand_clear_bigface_from_layer()

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 397 of file mapdata.c.

References bigfaces, expand_clear_bigface(), MapCellLayer::face, BigCell::head, BigCell::layer, MAX_VIEW, MAXLAYERS, BigCell::next, BigCell::prev, MapCellLayer::size_x, MapCellLayer::size_y, BigCell::x, and BigCell::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:

◆ expand_clear_face()

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 210 of file mapdata.c.

References MapCellLayer::animation, MapCellLayer::animation_left, MapCellLayer::animation_phase, MapCellLayer::animation_speed, MapCellLayer::face, MapCellTailLayer::face, MapCell::heads, Map::height, BigCell::layer, mapdata_cell(), mark_resmooth(), MAX_FACE_SIZE, MAXLAYERS, MapCell::need_resmooth, MapCell::need_update, MapCellLayer::size_x, MapCellTailLayer::size_x, MapCellLayer::size_y, MapCellTailLayer::size_y, BigCell::tail, MapCell::tails, the_map, and Map::width.

Referenced by expand_clear_face_from_layer().

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

◆ expand_clear_face_from_layer()

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 265 of file mapdata.c.

References expand_clear_face(), MapCell::heads, Map::height, BigCell::layer, mapdata_cell(), MAXLAYERS, MapCellLayer::size_x, MapCellLayer::size_y, the_map, and Map::width.

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:

◆ expand_need_update()

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 508 of file mapdata.c.

References Map::height, mapdata_cell(), MAX_FACE_SIZE, MapCell::need_update, the_map, and Map::width.

Referenced by expand_need_update_from_layer().

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

◆ expand_need_update_from_layer()

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 536 of file mapdata.c.

References expand_need_update(), MapCellLayer::face, BigCell::head, MapCell::heads, Map::height, BigCell::layer, mapdata_cell(), MAXLAYERS, MapCellLayer::size_x, MapCellLayer::size_y, the_map, and Map::width.

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:

◆ expand_set_bigface()

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

◆ expand_set_face()

static void expand_set_face ( int  x,
int  y,
int  layer,
gint16  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 292 of file mapdata.c.

References expand_clear_face_from_layer(), MapCellLayer::face, MapCellTailLayer::face, MapCell::heads, Map::height, BigCell::layer, mapdata_cell(), mapdata_get_image_size(), mark_resmooth(), MAX_FACE_SIZE, MAXLAYERS, MapCell::need_update, MapCellLayer::size_x, MapCellTailLayer::size_x, MapCellLayer::size_y, MapCellTailLayer::size_y, BigCell::tail, MapCell::tails, the_map, and Map::width.

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:

◆ mapdata_alloc()

static void mapdata_alloc ( struct Map *const  map,
const int  width,
const int  height 
)
static

Allocate and set up pointers for a map, with cells represented as a C-style multi-dimensional array.

Definition at line 557 of file mapdata.c.

References Map::_cells, Map::height, height, Map::width, and width.

Referenced by mapdata_init().

+ Here is the caller graph for this function:

◆ mapdata_animation()

◆ mapdata_bigface()

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

Return the face number of a multi-square pixmap at the given map tile.

Parameters
xX-coordinate of tile on-screen
yY-coordinate of tile on-screen
layer
ww
hh
Returns
Pixmap face number, or zero if the tile does not exist

Definition at line 1059 of file mapdata.c.

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

+ Here is the call graph for this function:

◆ mapdata_bigface_head()

gint16 mapdata_bigface_head ( int  x,
int  y,
int  layer,
int *  ww,
int *  hh 
)

Definition at line 1140 of file mapdata.c.

References bigfaces, MapCellLayer::face, BigCell::head, BigCell::layer, mapdata_has_tile(), MapCellLayer::size_x, MapCellLayer::size_y, BigCell::x, and BigCell::y.

+ Here is the call graph for this function:

◆ mapdata_can_smooth()

bool mapdata_can_smooth ( int  x,
int  y,
int  layer 
)

Definition at line 131 of file mapdata.c.

References MapCell::heads, BigCell::layer, mapdata_cell(), and MapCell::smooth.

Referenced by drawsmooth().

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

◆ mapdata_cell()

◆ mapdata_clear_old()

void mapdata_clear_old ( int  x,
int  y 
)

Definition at line 793 of file mapdata.c.

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

Referenced by Map2Cmd().

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

◆ mapdata_clear_space()

void mapdata_clear_space ( int  x,
int  y 
)

Definition at line 639 of file mapdata.c.

References MapCell::cleared, expand_need_update_from_layer(), expand_set_bigface(), MapCell::heads, Map::height, height, mapdata_cell(), MAX_VIEW, MAXLAYERS, MapCell::need_update, pl_pos, the_map, Map::width, width, BigCell::x, PlayerPosition::x, BigCell::y, and PlayerPosition::y.

Referenced by Map2Cmd().

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

◆ mapdata_contains()

bool mapdata_contains ( int  x,
int  y 
)

Determine whether the map data contains the given cell.

Definition at line 123 of file mapdata.c.

References Map::height, the_map, and Map::width.

Referenced by drawsmooth(), ExtSmooth(), and send_map().

+ Here is the caller graph for this function:

◆ mapdata_face()

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

Return the face number of a single-square pixmap at the given map tile.

Parameters
xX-coordinate of tile on-screen
yY-coordinate of tile on-screen
layer
Returns
Pixmap face number, or zero if the tile does not exist

Definition at line 1025 of file mapdata.c.

References MapCellLayer::face, MapCell::heads, BigCell::layer, mapdata_cell(), mapdata_has_tile(), pl_pos, PlayerPosition::x, and PlayerPosition::y.

+ Here is the call graph for this function:

◆ mapdata_face_info()

gint16 mapdata_face_info ( int  mx,
int  my,
int  layer,
int *  dx,
int *  dy 
)

Return the face number of the pixmap in the given map cell and set the offset pointers to indicate where to correctly draw the face. Offsets are zero for single-tile maps and negative for multi-tile maps. This provides a consistent way to draw tiles no matter single or multi part.

Parameters
mxVirtual map x-coordinate
myVirtual map y-coordinate
layerMap layer number
dxPointer to store x-offset
dyPointer to store y-offset
Returns
Pixmap face number, zero if the tile does not exist

Definition at line 1033 of file mapdata.c.

References MapCellLayer::face, MapCellTailLayer::face, BigCell::head, MapCell::heads, height, BigCell::layer, mapdata_cell(), MapCellLayer::size_x, MapCellTailLayer::size_x, MapCellLayer::size_y, MapCellTailLayer::size_y, BigCell::tail, MapCell::tails, and width.

Referenced by map_draw_layer().

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

◆ mapdata_free()

void mapdata_free ( void  )

Deallocate map data. Do not call functions other than mapdata_set_size() after calling mapdata_free().

Definition at line 612 of file mapdata.c.

References Map::_cells, and the_map.

Referenced by mapdata_set_size(), and reset_vars_common().

+ Here is the caller graph for this function:

◆ mapdata_get_image_size()

static void mapdata_get_image_size ( int  face,
guint8 *  w,
guint8 *  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 1326 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:

◆ mapdata_has_tile()

static bool mapdata_has_tile ( int  x,
int  y,
int  layer 
)
static

Check if the given map tile is a valid slot in the map array.

Definition at line 1008 of file mapdata.c.

References height, MAXLAYERS, and width.

Referenced by mapdata_bigface(), mapdata_bigface_head(), and mapdata_face().

+ Here is the caller graph for this function:

◆ mapdata_init()

◆ mapdata_is_inside()

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 630 of file mapdata.c.

References height.

◆ mapdata_newmap()

void mapdata_newmap ( void  )

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

Definition at line 987 of file mapdata.c.

References clear_cells(), expand_clear_bigface_from_layer(), Map::height, BigCell::layer, mapdata_cell(), MapCell::need_update, the_map, Map::width, BigCell::x, and BigCell::y.

Referenced by NewmapCmd().

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

◆ mapdata_scroll()

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 914 of file mapdata.c.

References MapCell::cleared, CONFIG_MAPSCROLL, display_mapscroll(), expand_clear_bigface_from_layer(), BigCell::head, height, BigCell::layer, mapdata_cell(), MapCell::need_update, BigCell::next, pl_pos, recenter_virtual_map_view(), MapCellLayer::size_x, MapCellLayer::size_y, 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:

◆ mapdata_set_anim_layer()

◆ mapdata_set_check_space()

void mapdata_set_check_space ( int  x,
int  y 
)

◆ mapdata_set_darkness()

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

Definition at line 736 of file mapdata.c.

References Map::height, height, MAX_VIEW, pl_pos, set_darkness(), the_map, Map::width, width, BigCell::x, PlayerPosition::x, BigCell::y, and PlayerPosition::y.

Referenced by Map2Cmd().

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

◆ mapdata_set_face_layer()

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

Definition at line 821 of file mapdata.c.

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

Referenced by Map2Cmd().

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

◆ mapdata_set_size()

void mapdata_set_size ( int  viewx,
int  viewy 
)

Initializes the module. Allocates memory for the_map. This functions must be called before any other function is used, and whenever a new display size was negotiated with the server.

Definition at line 619 of file mapdata.c.

References Map::height, height, mapdata_free(), mapdata_init(), pl_pos, the_map, Map::width, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by client_mapsize(), and SetupCmd().

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

◆ mapdata_set_smooth()

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

Definition at line 759 of file mapdata.c.

References Map::height, BigCell::layer, mapdata_cell(), MAX_VIEW, MapCell::need_resmooth, pl_pos, MapCell::smooth, the_map, Map::width, BigCell::x, PlayerPosition::x, BigCell::y, and PlayerPosition::y.

Referenced by Map2Cmd().

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

◆ mapdata_size()

void mapdata_size ( int *  x,
int *  y 
)

Determine the size of the internal fog-of-war map.

Definition at line 139 of file mapdata.c.

References Map::height, the_map, and Map::width.

Referenced by script_process_cmd().

+ Here is the caller graph for this function:

◆ mark_resmooth()

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

Definition at line 189 of file mapdata.c.

References Map::height, mapdata_cell(), MapCell::need_resmooth, MapCell::smooth, the_map, and Map::width.

Referenced by expand_clear_face(), and expand_set_face().

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

◆ recenter_virtual_map_view()

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 1169 of file mapdata.c.

References clear_cells(), FOG_BORDER_MIN, Map::height, height, mapdata_cell(), MAX_FACE_SIZE, MAX_VIEW, pl_pos, the_map, Map::width, width, PlayerPosition::x, and PlayerPosition::y.

Referenced by mapdata_scroll().

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

◆ set_darkness()

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 157 of file mapdata.c.

References CFG_DM_SDL, CFG_LT_PIXEL, CFG_LT_PIXEL_BEST, CONFIG_DISPLAYMODE, CONFIG_LIGHTING, MapCell::darkness, MapCell::have_darkness, height, mapdata_cell(), MapCell::need_update, use_config, and width.

Referenced by mapdata_set_darkness().

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

Variable Documentation

◆ bigfaces

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 94 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().

◆ bigfaces_head

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 87 of file mapdata.c.

Referenced by expand_set_bigface().

◆ height

◆ the_map

◆ width