144 lines
3.0 KiB
C

/**
* Copyright (c) 2024 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "tile.h"
#include "rpg/entity/entity.h"
#include "rpg/world/trigger.h"
#include "maplist.h"
#define MAP_WIDTH_MAX 512
#define MAP_HEIGHT_MAX 512
#define MAP_LAYERS_MAX 1
#define MAP_ENTITIES_MAX 64
#define MAP_TRIGGERS_MAX 32
typedef struct _map_t {
tile_t tiles[MAP_WIDTH_MAX * MAP_HEIGHT_MAX * MAP_LAYERS_MAX];
uint16_t width;
uint16_t height;
uint8_t layers;
maplist_t list;
entity_t entities[MAP_ENTITIES_MAX];
uint8_t entityCount;
trigger_t triggers[MAP_TRIGGERS_MAX];
uint8_t triggerCount;
} map_t;
extern map_t MAP_MAIN;
/**
* Initializes a map.
*
* @param map Map to initialize.
* @param width Width of the map.
* @param height Height of the map.
* @param layers Number of layers in the map.
*/
void mapInit(
map_t *map,
const maplist_t list,
const uint16_t width,
const uint16_t height,
const uint8_t layers
);
/**
* Updates the map and all entities on it.
*
* @param map Map to update.
*/
void mapUpdate(map_t *map);
/**
* Adds an entity to the map.
*
* @param map Map to add the entity to.
* @param entity Entity to add to the map.
*/
entity_t * mapEntityAdd(map_t *map);
/**
* Gets the entity at the specified position.
*
* @param map Map to get the entity from.
* @param x X position of the entity.
* @param y Y position of the entity.
* @return Entity at the specified position, or NULL if no entity is there.
*/
entity_t * mapEntityGetByPosition(
map_t *map,
const uint16_t x,
const uint16_t y
);
/**
* Gets the entity of the specified type.
*
* @param map Map to get the entity from.
* @param type Type of entity to get.
* @return Entity of the specified type, or NULL if no entity is found.
*/
entity_t * mapEntityGetByType(
map_t *map,
const entitytype_t type
);
/**
* Gets the tile at the specified position.
*
* @param map Map to get the tile from.
* @param x X position of the tile.
* @param y Y position of the tile.
* @param layer Layer of the tile.
* @return Tile at the specified position.
*/
tile_t mapTileGetByPosition(
const map_t *map,
const uint16_t x,
const uint16_t y,
const uint8_t layer
);
/**
* Quickly set an entire layer of tiles at once.
*
* @param map Map to set the tiles on.
* @param ids Array of tiles to set.
* @param layer Layer to set the tiles on.
*/
void mapTilesSet(
map_t *map,
const tile_t tiles[],
const uint8_t layer
);
/**
* Adds a trigger to the map.
*
* @param map Map to add the trigger to.
* @return Trigger added to the map.
*/
trigger_t * mapTriggerAdd(map_t *map);
/**
* Gets the trigger at the specified position.
*
* @param map Map to get the trigger from.
* @param x X position of the trigger.
* @param y Y position of the trigger.
* @return Trigger at the specified position, or NULL if no trigger is there.
*/
trigger_t * mapTriggerGetByPosition(
map_t *map,
const uint16_t x,
const uint16_t y
);