Next: libmsg, Previous: libldr, Up: C API

### 5.26 libmap

#### 5.26.1 Overview

View lcov test coverage results on http://www.gnu.org/software/liquidwar6/coverage/src/lib/map/index.html.

#### 5.26.2 API

— Function: void lw6map_body_builtin_custom (lw6map_body_t * body, int w, int h, int d, int noise_percent, lw6map_rules_t * rules)

> body: the body to initialize

> w: the width

> h: the height

> d: the depth

> noise_percent: the noise level to fill meta layers with

> rules: the map rules

> Sets up a default body structure.

> Return value: none

— Function: void lw6map_body_clear (lw6map_body_t * body)

> body: the structure to clear

> Clears a body structure.

> Return value: none.

— Function: void lw6map_body_fix_checksum (lw6map_body_t * body)

> body: the structure to update

> Updates (calculates) the checksum of a map body structure.

> Return value: none.

— Function: int lw6map_body_check_and_fix_holes (lw6map_body_t * body, lw6map_rules_t * rules)

> body: the structure to update

> rules: the game rules

> This (fundamental) function ensures that all playable areas in a map are connected. If isolated zones are found out, then they are marked as walls and not used any more.

> Return value: none.

— Function: int lw6map_body_coord_from_texture (lw6map_level_t * level, int * body_x, int * body_y, int texture_x, int texture_y)

> level: the level to work on

> body_x: the body (logical) x coord

> body_y: the body (logical) y coord

> texture_x: the texture x coord

> texture_y: the texture y coord

> Gets body (logical) coords from texture position.

> Return value: 1 on success, 0 on failure (out of bounds)

— Function: u_int8_t lw6map_body_get_with_texture_coord (lw6map_level_t * level, int texture_x, int texture_y, int z)

> level: the level to work on

> texture_x: the texture x coord

> texture_y: the texture y coord

> z: the z position (depth related)

> Tells wether a given map position is free or not, but using texture coords.

> Return value: 1 if position is playable, 0 if not (wall)

— Function: void lw6map_color_invert (lw6map_color_couple_t * color)

> color: the color to invert

> Inverts a color couple, that is, replace fg by bg and vice-versa.

> Return value: none.

— Function: int lw6map_color_is_same (lw6map_color_couple_t * color1, lw6map_color_couple_t * color2)

> color1: 1st color to compare

> color2: 2nd color to compare

> Compares two colors.

> Return value: 1 if equal, 0 if not.

— Function: char * lw6map_team_color_index_to_key (int index)

> index: index of the color between 0 & 9

> Transforms a team color index into its readable string form, which can be used in config files for instance.

> Return value: a string, must *not* be freed.

— Function: int lw6map_team_color_key_to_index (char * key)

> key: key of the color, for instance "red"

> The index of the color, between 0 & 9

> Return value: an integer.

— Function: void lw6map_cursor_texture_clear (lw6map_cursor_texture_t * cursor_texture)

> cursor_texture: the cursor texture to clear

> Clears a cursor texture (set it all transparent).

> Return value: none

— Function: void lw6map_cursor_texture_builtin (lw6map_cursor_texture_t * cursor_texture)

> cursor_texture: the cursor texture to clear

> Sets a cursor texture to the builtin defauts, that is a circle that is black on the outside and gets white/transparent in the middle.

> Return value: none

— Function: void lw6map_cursor_texture_layer_set (lw6map_cursor_texture_layer_t * cursor_texture_layer, int x, int y, lw6sys_color_8_t color)

> cursor_texture_layer: the cursor texture_layer to change

> x: x coord

> y: y coord

> color: the color

> Sets a pixel in the cursor texture_layer.

> Return value: none

— Function: lw6sys_color_8_t lw6map_cursor_texture_layer_get (lw6map_cursor_texture_layer_t * cursor_texture_layer, int x, int y)

> cursor_texture_layer: the cursor texture_layer to query

> x: x coord

> y: y coord

> Gets a pixel in the cursor texture_layer.

> Return value: the color

— Function: lw6map_level_t * lw6map_dup (lw6map_level_t * source, lw6sys_progress_t * progress)

> source: the map to copy

> progress: to show advancement

> Performs a deep copy of the map, all elements are newly allocated and source can safely be destroyed after it's been duplicated.

> Return value: a newly allocated map, may be NULL.

— Function: int lw6map_exp_get_highest_team_color_allowed (int exp)

> exp: the player experience

> Gets the highest color available for a given exp.

> Return value: a color id

— Function: int lw6map_exp_get_highest_weapon_allowed (int exp)

> exp: the player experience

> Gets the highest weapon available for a given exp.

> Return value: a weapon id

— Function: char * lw6map_to_hexa (lw6map_level_t * level)

> Converts a map to something that is later readable by `lw6map_from_hexa` to reproduce the exact same map. Just a serializer.

> Return value: a newly allocated pointer, NULL if conversion failed.

— Function: lw6map_level_t * lw6map_from_hexa (char * hexa)

> hexa: an hexadecimal ASCII string, created by `lw6map_to_hexa`

> Constructs a map from an hexadecimal string generated by `lw6map_to_hexa`. Just an un-serializer.

> Return value: a new map, might be NULL if string isn't correct.

— Function: void lw6map_layer_builtin_custom (lw6map_layer_t * layer, int w, int h)

> layer: the layer to init

> w: width

> h: height

> Creates a default layer. This is mostly for testing purposes, the default layer is not empty, it contains a simplified map of the world.

> Return value: none

— Function: void lw6map_layer_clear (lw6map_layer_t * layer)

> layer: the layer to init

> Clears a layer struct. This means freeing the pointer if it's non NULL and setting everything to 0.

> Return value: none

— Function: lw6map_level_t * lw6map_new ()

> Creates a new empty map. This object is perfectly unusable as is, since it has a 0x0 size, and many things set to "NULL". Still, it's used internally and is the canonical way to create the object, it ensures later calls that set up default parameters, for instance, will succeed.

> Return value: a newly allocated pointer.

— Function: lw6map_level_t * lw6map_builtin_defaults ()

> Creates a map, set to defaults. This is usefull mostly for testing. This builtin map has walls, paths, it's playable.

> Return value: a newly allocated map.

— Function: lw6map_level_t * lw6map_builtin_custom (int w, int h, int d, int noise_percent)

> w: the width of the map

> h: the height of the map

> d: the depth (number of layers) of the map

> noise_percent: percentage of noise to use for metalayers

> Creates a map, set to defaults. This is usefull mostly for testing. This one, unlike `lw6map_builtin_defaults` will let you give a width, height and a depth.

> Return value: a newly allocated map.

— Function: void lw6map_free (lw6map_level_t * level)

> Frees a map and releases all its internal ressources.

> Return value: none.

— Function: int lw6map_memory_footprint (lw6map_level_t * level)

> Reports how many bytes the map needs, in memory. Note that this is not contiguous memory, it involves a bunch of pointers, and possibly much more...

— Function: char * lw6map_repr (lw6map_level_t * level)

> Returns a string describing the map. This is a very short description, use it for logs, and to debug stuff. By no means it's a complete exhaustive description. Still, the string returned should be unique.

> Return value: a dynamically allocated string.

— Function: int lw6map_is_same (lw6map_level_t * level_a, lw6map_level_t * level_b)

> level_a: the first level to compare

> level_b: the other level to compare

> Compares two level structs, the idea is to compare the content, not only the pointers and level ids.

> Return value: 1 if they're the same, 0 if not.

— Function: int lw6map_local_info_set_music_dir (lw6map_local_info_t * local_info, char * music_dir)

> local_info: the structure to modify

> music_dir: the new music_dir value

> Sets the music_dir value, in a 'safe' manner, freeing any previous value and performing a string duplication.

> Return value: 1 on success, 0 on failure.

— Function: void lw6map_local_info_clear (lw6map_local_info_t * local_info)

> local_info: the structure to clear

> Clears the local_info structure, before destroying a level for instance.

> Return value: none

— Function: void lw6map_meta_layer_set (lw6map_meta_layer_t * meta_layer, int x, int y, u_int8_t value)

> meta_layer: the meta_layer structure

> x: x coord

> y: y coord

> value: the value to set at this place

> Simple setter for the meta_layer struct.

> Return value: none

— Function: u_int8_t lw6map_meta_layer_get (lw6map_meta_layer_t * meta_layer, int x, int y)

> meta_layer: the meta_layer structure

> x: x coord

> y: y coord

> Simple getter for the meta_layer struct.

> Return value: the value at this place

— Function: void lw6map_meta_layer_clear (lw6map_meta_layer_t * meta_layer)

> meta_layer: the meta_layer to clear

> Clears a meta_layer struct. This means freeing the pointer if it's non NULL and setting everything to 0.

> Return value: none

— Function: int lw6map_meta_layer_builtin_custom (lw6map_meta_layer_t * meta_layer, int w, int h, int analog, int noise_percent, int seed)

> meta_layer: the object to init

> w: width

> h: height

> analog: wether to use analog mode (0-255) or boolean (0-1)

> noise_percent: the quantity of noise to initialise the layer with

> seed: a pseudo-random seed to feed the pseudo-random generator

> Builds a custom metalyer, suitable for tests or demo, letting the choice of its size and the noise to fill it with. If noise is 100 then metalayer is "full". If noise is 0, then meta layer is empty.

> Return value: 1 if OK, 0 on failure.

— Function: void lw6map_param_defaults (lw6map_param_t * param)

> param: the param struct to modify

> Sets a param structure to its default value, note that current structured must be zeroed or correctly initialized.

> Return value: none

— Function: void lw6map_param_clear (lw6map_param_t * param)

> param: the param struct to modify

> Resets a param structure to nothing. Note that current structured must be zeroed or correctly initialized. The idea is just to free member pointers before calling free.

> Return value: none

— Function: void lw6map_param_copy (lw6map_param_t * dst, lw6map_param_t * src)

> dst: the destination param struct

> src: the source param struct

> Copies parameters. Both structures must be zeroed or correctly initialized.

> Return value: none

— Function: int lw6map_param_set (lw6map_param_t * param, char * key, char * value)

> param: the param struct to modify

> key: the name of the parameter to modify

> value: the value of the parameter to modify

> Sets an entry in a param struct. All values must be submitted as strings, internally, the function will call atoi to convert to integers if needed, for instance. It will also dispatch automatically between rules, style and teams.

> Return value: 1 if parameter successfully set, 0 on error.

— Function: char * lw6map_param_get (lw6map_param_t * param, char * key)

> param: the param struct to query

> key: the name of the parameter to get

> Gets an entry from a param struct. All values returned as strings, do not use this in performance bottlenecks, this is just to export values to scripts, for instance.

> Return value: dynamically allocated string, NULL on error, might return a string containing 0 on bad keys.

— Function: int lw6map_param_is_same (lw6map_param_t * param_a, lw6map_param_t * param_b)

> param_a: one struct to compare

> param_b: another struct to compare

> Compares the contents of two param structs.

> Return value: 1 if they contain the same thing, 0 if not

— Function: void lw6map_teams_zero (lw6map_teams_t * teams)

> teams: data to initialize

> Zeros the teams struct, this is not the same as setting to defaults.

> Return value: none.

— Function: void lw6map_teams_defaults (lw6map_teams_t * teams)

> teams: data to initialize

> Set the teams struct to its defaults.

> Return value: none.

— Function: void lw6map_teams_clear (lw6map_teams_t * teams)

> teams: data to initialize

> Clears the teams struct, this is not the same as setting to defaults. This one supposes the struct has been properly initialized, at least zeroed before usage, it might contain pointers which should be freed.

> Return value: none.

— Function: void lw6map_teams_copy (lw6map_teams_t * dst, lw6map_teams_t * src)

> dst: destination

> src: source

> Copies the contents of the teams struct. It's a real duplicate, any string is reallocated.

> Return value: none.

— Function: int lw6map_teams_set (lw6map_teams_t * teams, char * key, char * value)

> teams: the teams to modify

> key: the key to modify

> value: the value to affect to the key, as a string

> Sets one single parameter in a teams structure. Value must always be passed as a string, will be converted to the right type automatically when storing it in the structure.

> Return value: 1 if success, 0 if failed. Note that while 0 really means there's a problem, some affectations can fail and return 1, needs to be worked on.

— Function: char * lw6map_teams_get (lw6map_teams_t * teams, char * key)

> teams: the teams to modify

> key: the key to modify

> Gets one single parameter in a teams structure. Value is converted as a string.

> Return value: dynamically allocated string, NULL on error.

— Function: char * lw6map_teams_get_default (char * key)

> key: the key we want informations about.

> Gets the default value for a given teams key.

> Return value: dynamically allocated string, NULL on error.

— Function: int lw6map_teams_is_same (lw6map_teams_t * teams_a, lw6map_teams_t * teams_b)

> teams_a: one struct to compare

> teams_b: another struct to compare

> Compares the contents of two teams structs.

> Return value: 1 if they contain the same thing, 0 if not

— Function: int lw6map_test (int mode)

> mode: 0 for check only, 1 for full test

> Runs the `map` module test suite.

> Return value: 1 if test is successfull, 0 on error.

— Function: char * lw6map_weapon_index_to_key (int index)

> index: index of the weapon between 0 & 19

> Transforms a team weapon index into its readable string form, which can be used in config files for instance.

> Return value: a string, must *not* be freed.

— Function: int lw6map_weapon_key_to_index (char * key)

> key: key of the weapon, for instance "red"

> The index of the weapon, between 0 & 19

> Return value: an integer.