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
 

Macros

#define MAX_STRETCH   8
 
#define MAX_STRETCH_DIAG   12
 

Typedefs

typedef struct map_render_data map_render_data_t
 

Functions

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)
 

Variables

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.

Author
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 
)
static

Align tile stretch based on X/Y.

Parameters
xX position.
yY position.
wMax width.
hMax height.
sub_layerSub-layer.

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 
)
static

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

Checks for X/Y overflows.

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

Definition at line 451 of file map.c.

void clear_map ( bool  hard)

Clear the map.

Parameters
hardHard reset

Definition at line 154 of file map.c.

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

Definition at line 99 of file map.c.

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

Scroll the map.

Parameters
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 
)
static

Draw a single object on the map.

Parameters
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 
)
static

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

Parameters
xX position.
yY position.
Returns
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.

Parameters
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.

Parameters
typeAnimation type, one of Animation types.
mapxMap X.
mapyMap Y.
sub_layerSub-layer.
valueValue to display.
Returns
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.

Parameters
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.

Returns
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.

Parameters
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.

Parameters
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.

Parameters
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.

Returns
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.

Parameters
[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.

Returns
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.

Parameters
xX of the cell.
yY of the cell.
sub_layerSub-layer.
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.

Parameters
xX of the cell.
yY of the cell.
layerLayer we're doing this for.
faceFace to set.
quick_posIs this a multi-arch?
obj_flagsFlags.
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 
)
static

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

Parameters
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 
)
static

Determine if an object being rendered should be culled.

Parameters
surfaceSurface that rendering is being done for.
dataRendering data.
Returns
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 
)
static

Determine if a specified tile should be rendered.

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

Parameters
surfaceSurface rendering is being done on.
dataMap rendering data.
Returns
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 
)
static

Compare distances between two targets on the map.

Parameters
aFirst target.
bSecond target.
Returns
Comparison result.

Definition at line 1981 of file map.c.

void map_target_handle ( uint8_t  is_friend)

Target something on the map.

Parameters
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.

Parameters
in_buildingNew in_building state.

Definition at line 337 of file map.c.

void map_update_size ( int  w,
int  h 
)

Update map size.

Parameters
wNew width.
hNew height.

Definition at line 190 of file map.c.

void maps_anims_remove ( map_anim_t anim)

Remove a map animation.

Parameters
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 
)
static

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

Parameters
widgetMap widget.
menuitemMenu item.
eventEvent.

Definition at line 2229 of file map.c.

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

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

Parameters
widgetMap widget.
menuitemMenu item.
eventEvent.

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.

Parameters
mxMouse X.
myMouse Y.
[out]txWill contain tile X, unless function returns false.
[out]tyWill contain tile Y, unless function returns false.
Returns
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 
)
static

Calculates whether the specified coordinates are behind a wall.

Parameters
dxStart X.
dyStart Y.
sxEnd X.
syEnd Y.
Returns
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 
)
static

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

Parameters
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 
)
static

Send a command to target an NPC.

Parameters
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.

Parameters
nameNew map name.

Definition at line 271 of file map.c.

void update_map_path ( const char *  map_path)

Update map's path.

Parameters
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.

Parameters
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.

Parameters
region_nameNew region name.

Definition at line 299 of file map.c.

void update_map_weather ( const char *  weather)

Update map's weather.

Parameters
weatherNew weather.

Definition at line 281 of file map.c.

static void widget_background ( widgetdata widget,
int  draw 
)
static

Definition at line 2449 of file map.c.

static void widget_deinit ( widgetdata widget)
static

Definition at line 2457 of file map.c.

static void widget_draw ( widgetdata widget)
static

Definition at line 2244 of file map.c.

static int widget_event ( widgetdata widget,
SDL_Event *  event 
)
static

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
static

Map cells.

Definition at line 43 of file map.c.

const char* clioptions_option_tiles_debug_desc
static
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
static

Map animation queue.

Definition at line 59 of file map.c.

int map_height
static

Map's height.

Definition at line 51 of file map.c.

bool map_show_mouse = false
static

If true, show the mouse map square indicator.

Definition at line 78 of file map.c.

int map_width
static

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
static

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

Definition at line 74 of file map.c.

int right_click_ticks = -1
static

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
static

If true, will print tile coordinates.

Definition at line 88 of file map.c.

SDL_Surface* zoomed = NULL
static

Zoomed map.

Definition at line 55 of file map.c.