#ifndef MAP_H #define MAP_H #include "tile.h" #define TILE_REPLACE 1 #define TILE_APPEND 2 struct Map { short width; short height; struct Tile **matrix; }; /*** allocateMapTiles allocateMapTiles dynamically allocates a new multi-dimensional array of Tiles to the given rows and width arguments. Always call freeMap to its parent Map object if unaccessable. ***/ int allocateMapTiles(struct Tile ***memory, unsigned int rows, unsigned int cols); /*** allocateMap allocateMap sets the passed Map's width and height properties, then calls allocateMapTiles to its matrix property. ***/ int allocateMap(struct Map **map, unsigned int width, unsigned int height); /*** freeMap freeMap walks through the map, freeing Tiles, their data, and finally itself. If a Map is ever to be completely unaccessable, always call this, otherwise memory will be leaked. ***/ void freeMap(struct Map **map); /**** drawing operations ****/ /*** drawPath This function "walks" a path from from_x,from_y to to_x,to_y, populating each step with either a new tile or replacing the old one with a tile of tid and id. Note that Tile data is freed and the new tile's default properties are memcpy'd to a new malloc'd space. ***/ void drawPath(struct Map** map, unsigned int operation, unsigned int tid, short id, unsigned int from_x, unsigned int from_y, unsigned int to_x, unsigned int to_y); /*** drawLine This function simply draws a line from_x,from_y to to_x,to_y, populating each step with either a new tile or replacing the old one with a tile of tid and id. Note that Tile data is freed and the new tile's default properties are memcpy'd to a new malloc'd space. ***/ void drawLine(struct Map** map, unsigned int operation, unsigned int tid, short id, unsigned int from_x, unsigned int from_y, unsigned int to_x, unsigned int to_y); /*** floodMap floodMap does as is expected - it floods a given map with the given tid and id, memcpy-ing the new tile's default data. Can replace or append the tile. ***/ void floodMap(struct Map** map, unsigned int operation, unsigned int tid, short id); /*** replaceTile replaceTile changes a Tile's tid and id to the passed arguments, frees the old Tile's data, and thereafter mallocs and memcpys the default properties for the "new" tile. ***/ void replaceTile(struct Tile *tile, unsigned int tid, short id); /*** replaceTile appendTile calls newTile, sets its tid and id accordingly, then mallocs and memcpy's that tile's default attributes. It then modifies the passed Tile's next pointer to point to the new Tile and the new Tile's prev pointer to the passed Tile. ***/ void appendTile(struct Tile *tile, unsigned int tid, short id); /* find operations */ struct Tile *findTile(int start_x, int start_y, int width, int height, int tid); struct Tile *getTopTile(struct Map *target_map, int x, int y); struct Tile *getTile(struct Map *target_map, int x, int y); #endif