Atrinik Client  4.0
Data Structures | Macros | Typedefs | Functions | Variables
map.c File Reference
#include <global.h>
#include <region_map.h>
#include <toolkit/packet.h>
#include <toolkit/string.h>
#include <toolkit/bresenham.h>
#include <toolkit/clioptions.h>
#include <toolkit/path.h>

Go to the source code of this file.

Data Structures

struct  map_render_data


#define MAX_STRETCH   8
#define MAX_STRETCH_DIAG   12


typedef struct map_render_data map_render_data_t


static int get_top_floor_height (struct MapCell *cell, int sub_layer)
static bool clioptions_option_tiles_debug (const char *arg, char **errmsg)
void load_mapdef_dat (void)
void clear_map (bool hard)
void map_update_size (int w, int h)
void display_mapscroll (int dx, int dy, int old_w, int old_h)
void update_map_name (const char *name)
void update_map_weather (const char *weather)
void update_map_height_diff (uint8_t height_diff)
void update_map_region_name (const char *region_name)
void update_map_region_longname (const char *region_longname)
void update_map_path (const char *map_path)
void map_update_in_building (uint8_t in_building)
int map_get_player_direction (void)
void map_get_real_coords (int *x, int *y)
void init_map_data (int xl, int yl, int px, int py)
static int calc_map_cell_height (int x, int y, int w, int h, int sub_layer, int my_height)
static void align_tile_stretch (int x, int y, int w, int h, int sub_layer)
void adjust_tile_stretch (void)
void map_set_data (int x, int y, int layer, int16_t face, uint8_t quick_pos, uint8_t obj_flags, const char *name, const char *name_color, int16_t height, uint8_t probe, int16_t zoom_x, int16_t zoom_y, int16_t align, uint8_t draw_double, uint8_t alpha, int16_t rotate, uint8_t infravision, uint32_t target_object_count, uint8_t target_is_friend, uint8_t anim_speed, uint8_t anim_facing, uint8_t anim_flags, uint8_t anim_state, uint8_t priority, uint8_t secondpass, const char *glow, uint8_t glow_speed)
void map_clear_cell (int x, int y)
void map_set_darkness (int x, int y, int sub_layer, uint8_t darkness)
static void map_animate_object (struct MapCell *cell, int layer)
void map_animate (void)
static uint16_t map_object_get_face (struct MapCell *cell, int layer)
static void draw_map_object (SDL_Surface *surface, map_render_data_t *data)
static bool obj_is_behind_wall (int dx, int dy, int sx, int sy)
static bool map_should_cull (SDL_Surface *surface, map_render_data_t *data)
static bool map_should_draw (SDL_Surface *surface, map_render_data_t *data)
static void map_setup_render_data (SDL_Surface *surface, map_render_data_t *data, int *x, int *y, int *w, int *h)
void map_draw_map (SDL_Surface *surface)
void map_draw_one (int x, int y, SDL_Surface *surface)
static void send_move_path (int tx, int ty)
static void send_target (int x, int y, uint32_t count)
static int map_target_cmp (const void *a, const void *b)
void map_target_handle (uint8_t is_friend)
bool mouse_to_tile_coords (int mx, int my, int *tx, int *ty)
bool map_mouse_fire (void)
static void menu_map_walk_here (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
static void menu_map_talk_to (widgetdata *widget, widgetdata *menuitem, SDL_Event *event)
static void widget_draw (widgetdata *widget)
static int widget_event (widgetdata *widget, SDL_Event *event)
static void widget_background (widgetdata *widget, int draw)
static void widget_deinit (widgetdata *widget)
void widget_map_init (widgetdata *widget)
struct map_animmap_anims_add (int type, int mapx, int mapy, int sub_layer, int value)
void maps_anims_remove (map_anim_t *anim)
void map_anims_mapscroll (int xoff, int yoff)
void map_anims_clear (void)
void map_anims_play (void)
int map_anims_need_redraw (void)


static struct MapCellcells
static int map_width
static int map_height
static SDL_Surface * zoomed = NULL
static map_anim_tfirst_anim = NULL
_mapdata MapData
_multi_part_obj MultiArchs [16]
static int old_map_mouse_x = -1
static int old_map_mouse_y = -1
static bool map_show_mouse = false
static int right_click_ticks = -1
static bool tiles_debug = false
static const char * clioptions_option_tiles_debug_desc

Detailed Description

Implements map type widgets.

Alex Tokar

Definition in file map.c.

Typedef Documentation

Structure used to pass data between the rendering loops in map_draw_map() and the actual rendering logic in draw_map_object().

Try to keep this structure aligned whenever extending it.

Function Documentation

void adjust_tile_stretch ( void  )

Adjust the tile stretch of a map.

Goes through the whole map and for each coordinate calls align_tile_stretch() in all directions. This is done to fix any inconsistencies, since the map command doesn't send us the whole map all over again, but only new/changes parts.

Definition at line 624 of file map.c.

static void align_tile_stretch ( int  x,
int  y,
int  w,
int  h,
int  sub_layer 

Align tile stretch based on X/Y.

xX position.
yY position.
wMax width.
hMax height.

Definition at line 498 of file map.c.

static int calc_map_cell_height ( int  x,
int  y,
int  w,
int  h,
int  sub_layer,
int  my_height 

Calculate height of X/Y coordinate on the specified cell.

Checks for X/Y overflows.

xX position.
yY position.
wMax width.
hMax height.
The height.

Definition at line 451 of file map.c.

void clear_map ( bool  hard)

Clear the map.

hardHard reset

Definition at line 154 of file map.c.

static bool clioptions_option_tiles_debug ( const char *  arg,
char **  errmsg 

Definition at line 99 of file map.c.

void display_mapscroll ( int  dx,
int  dy,
int  old_w,
int  old_h 

Scroll the map.

dxX offset.
dyY offset.
old_wOld width. 0 if width hasn't changed.
old_hOld height. 0 if height hasn't changed.

Definition at line 220 of file map.c.

static void draw_map_object ( SDL_Surface *  surface,
map_render_data_t data 

Draw a single object on the map.

surfaceSurface to render on.
dataRendering data. May be modified.

Definition at line 979 of file map.c.

static int get_top_floor_height ( struct MapCell cell,
int  sub_layer 

Get the height of the topmost floor on the specified square.

xX position.
yY position.
The height.

Definition at line 830 of file map.c.

void init_map_data ( int  xl,
int  yl,
int  px,
int  py 

Initialize map's data.

xlMap width.
ylMap height.
pxPlayer's X position.
pyPlayer's Y position.

Definition at line 410 of file map.c.

void load_mapdef_dat ( void  )

Loads multi-arch object data offsets.

Definition at line 109 of file map.c.

struct map_anim* map_anims_add ( int  type,
int  mapx,
int  mapy,
int  sub_layer,
int  value 

Add an animation.

typeAnimation type, one of Animation types.
mapxMap X.
mapyMap Y.
valueValue to display.
Created animation.

Definition at line 2501 of file map.c.

void map_anims_clear ( void  )

Clear map animations.

Definition at line 2580 of file map.c.

void map_anims_mapscroll ( int  xoff,
int  yoff 

Adjust the X/Y coordinates of map animations due to a map scroll.

xoffX offset.
YoffY offset.

Definition at line 2568 of file map.c.

int map_anims_need_redraw ( void  )

Check whether the damage animations need redrawing.

1 if the damage animations need redrawing, 0 otherwise.

Definition at line 2671 of file map.c.

void map_anims_play ( void  )

Play map animations.

Definition at line 2591 of file map.c.

void map_clear_cell ( int  x,
int  y 

Clear map's cell.

In reality, this only clears some data on the cell, and sets the FOW flag to mark that the cell is actually FOW.

xX of the cell.
yY of the cell.

Definition at line 786 of file map.c.

void map_draw_map ( SDL_Surface *  surface)

Draw the map.

surfaceSurface to render on.

Definition at line 1520 of file map.c.

void map_draw_one ( int  x,
int  y,
SDL_Surface *  surface 

Draw one sprite on map.

xX position.
yY position.
surfaceWhat to draw.

Definition at line 1871 of file map.c.

int map_get_player_direction ( void  )

Get player's direction.

Player's direction.

Definition at line 370 of file map.c.

void map_get_real_coords ( int *  x,
int *  y 

Get real map X/Y coordinates adjusted for player's position.

[out]xWill contain X coordinate.
[out]yWill contain Y coordinate.

Definition at line 393 of file map.c.

bool map_mouse_fire ( void  )

Handle the mouse firing gesture.

True if the gesture was handled, false otherwise.

Definition at line 2173 of file map.c.

void map_set_darkness ( int  x,
int  y,
int  sub_layer,
uint8_t  darkness 

Set darkness for map's cell.

xX of the cell.
yY of the cell.
darknessDarkness to set.

Definition at line 813 of file map.c.

void map_set_data ( int  x,
int  y,
int  layer,
int16_t  face,
uint8_t  quick_pos,
uint8_t  obj_flags,
const char *  name,
const char *  name_color,
int16_t  height,
uint8_t  probe,
int16_t  zoom_x,
int16_t  zoom_y,
int16_t  align,
uint8_t  draw_double,
uint8_t  alpha,
int16_t  rotate,
uint8_t  infravision,
uint32_t  target_object_count,
uint8_t  target_is_friend,
uint8_t  anim_speed,
uint8_t  anim_facing,
uint8_t  anim_flags,
uint8_t  anim_state,
uint8_t  priority,
uint8_t  secondpass,
const char *  glow,
uint8_t  glow_speed 

Set data for map cell.

If FOW was previously set on this cell, cell data is cleared.

xX of the cell.
yY of the cell.
layerLayer we're doing this for.
faceFace to set.
quick_posIs this a multi-arch?
namePlayer's name.
name_colorPlayer's name color.
heightZ position of the tile.
probeTarget's HP bar.
zoomHow much to zoom the face by.
alignX align.
rotateRotation in degrees.
infravisionWhether to show the object in red.

Definition at line 675 of file map.c.

static void map_setup_render_data ( SDL_Surface *  surface,
map_render_data_t data,
int *  x,
int *  y,
int *  w,
int *  h 

Setup the base information in a map render data structure and calculate X/Y cell indexes and maximum dimensions.

surfaceSurface rendering is being done for.
[out]dataMap rendering data.
[out]xWill contain X index of the cell to render. Can be NULL.
[out]yWill contain Y index of the cell to render. Can be NULL.
[out]wMaximum width. Can be NULL.
[out]hMaximum height. Can be NULL.

Definition at line 1441 of file map.c.

static bool map_should_cull ( SDL_Surface *  surface,
map_render_data_t data 

Determine if an object being rendered should be culled.

surfaceSurface that rendering is being done for.
dataRendering data.
Whether the object should be culled.

Definition at line 1312 of file map.c.

static bool map_should_draw ( SDL_Surface *  surface,
map_render_data_t data 

Determine if a specified tile should be rendered.

Assigns the cell to be rendered in the map render data structure on success.

surfaceSurface rendering is being done on.
dataMap rendering data.
Whether the tile should be rendered.

Definition at line 1383 of file map.c.

static int map_target_cmp ( const void *  a,
const void *  b 

Compare distances between two targets on the map.

aFirst target.
bSecond target.
Comparison result.

Definition at line 1981 of file map.c.

void map_target_handle ( uint8_t  is_friend)

Target something on the map.

is_friend1 if targeting friendlies only.

Definition at line 2009 of file map.c.

void map_update_in_building ( uint8_t  in_building)

Updates the map's in_building state flag.

When entering a building, clears FoW objects from effect layer with non-zero sub-layer.

in_buildingNew in_building state.

Definition at line 337 of file map.c.

void map_update_size ( int  w,
int  h 

Update map size.

wNew width.
hNew height.

Definition at line 190 of file map.c.

void maps_anims_remove ( map_anim_t anim)

Remove a map animation.

animThe animation to remove.

Definition at line 2552 of file map.c.

static void menu_map_talk_to ( widgetdata widget,
widgetdata menuitem,
SDL_Event *  event 

Handle the "Talk To NPC" option in map widget menu.

widgetMap widget.
menuitemMenu item.

Definition at line 2229 of file map.c.

static void menu_map_walk_here ( widgetdata widget,
widgetdata menuitem,
SDL_Event *  event 

Handle the "Walk Here" option in map widget menu.

widgetMap widget.
menuitemMenu item.

Definition at line 2207 of file map.c.

bool mouse_to_tile_coords ( int  mx,
int  my,
int *  tx,
int *  ty 

Transform mouse coordinates to tile coordinates on map.

Both 'tx' and 'ty' can be NULL, which is useful if you only want to check if the mouse is over a valid map tile.

mxMouse X.
myMouse Y.
[out]txWill contain tile X, unless function returns false.
[out]tyWill contain tile Y, unless function returns false.
True on success, false on failure.

Definition at line 2095 of file map.c.

static bool obj_is_behind_wall ( int  dx,
int  dy,
int  sx,
int  sy 

Calculates whether the specified coordinates are behind a wall.

dxStart X.
dyStart Y.
sxEnd X.
syEnd Y.
Whether the coordinates dx and dy are behind a wall or not.

Definition at line 1271 of file map.c.

static void send_move_path ( int  tx,
int  ty 

Send a command to move the player to the specified square.

txSquare X position.
tySquare Y position.

Definition at line 1926 of file map.c.

static void send_target ( int  x,
int  y,
uint32_t  count 

Send a command to target an NPC.

txNPC's X position.
tyNPC's Y position.
countNPC's UID.

Definition at line 1949 of file map.c.

void update_map_height_diff ( uint8_t  height_diff)

Update map's height difference rendering flag.

Definition at line 289 of file map.c.

void update_map_name ( const char *  name)

Update map's name.

nameNew map name.

Definition at line 271 of file map.c.

void update_map_path ( const char *  map_path)

Update map's path.

map_pathNew map path.

Definition at line 324 of file map.c.

void update_map_region_longname ( const char *  region_longname)

Update map's region long name.

region_longnameNew region long name.

Definition at line 314 of file map.c.

void update_map_region_name ( const char *  region_name)

Update map's region name.

region_nameNew region name.

Definition at line 299 of file map.c.

void update_map_weather ( const char *  weather)

Update map's weather.

weatherNew weather.

Definition at line 281 of file map.c.

static void widget_background ( widgetdata widget,
int  draw 

Definition at line 2449 of file map.c.

static void widget_deinit ( widgetdata widget)

Definition at line 2457 of file map.c.

static void widget_draw ( widgetdata widget)

Definition at line 2244 of file map.c.

static int widget_event ( widgetdata widget,
SDL_Event *  event 

Definition at line 2396 of file map.c.

void widget_map_init ( widgetdata widget)

Initialize one map widget.

Definition at line 2471 of file map.c.

Variable Documentation

struct MapCell* cells

Map cells.

Definition at line 43 of file map.c.

const char* clioptions_option_tiles_debug_desc
Initial value:
"Enable map tiles debugging (shows tile coordinates)."

Description of the –tiles_debug command.

Definition at line 95 of file map.c.

map_anim_t* first_anim = NULL

Map animation queue.

Definition at line 59 of file map.c.

int map_height

Map's height.

Definition at line 51 of file map.c.

bool map_show_mouse = false

If true, show the mouse map square indicator.

Definition at line 78 of file map.c.

int map_width

Map's width.

Definition at line 47 of file map.c.

_mapdata MapData

Current shown map: mapname, length, etc

Definition at line 64 of file map.c.

_multi_part_obj MultiArchs[16]

Multi-part object data.

Definition at line 69 of file map.c.

int old_map_mouse_x = -1

Holds coordinates of the last map square the mouse was over.

Definition at line 74 of file map.c.

int right_click_ticks = -1

When the right button was pressed on the map widget. -1 = not pressed.

Definition at line 83 of file map.c.

bool tiles_debug = false

If true, will print tile coordinates.

Definition at line 88 of file map.c.

SDL_Surface* zoomed = NULL

Zoomed map.

Definition at line 55 of file map.c.