view librpg/rpg/item.h @ 210:70e6ed74940d

rpg: attempt of collide detection in map
author David Demelier <markand@malikania.fr>
date Sat, 14 Nov 2020 16:59:11 +0100
parents ce789473567e
children
line wrap: on
line source

/*
 * item.h -- inventory items
 *
 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef MOLKO_ITEM_H
#define MOLKO_ITEM_H

/**
 * \file item.h
 * \brief Inventory items.
 */

#include <stdbool.h>

struct character;
struct texture;

/**
 * \brief Inventory items.
 */
struct item {
	const char *name;               /*!< (+) Name of item. */
	const char *summary;            /*!< (+) Summary description. */
	struct texture *icon;           /*!< (+&) Icon to show. */

	/**
	 * (+) Execute the action for this character.
	 *
	 * \param item this item
	 * \param ch the character owner
	 */
	void (*exec)(struct item *item, struct character *ch);

	/**
	 * (+?) Tells if the item can be used in this context.
	 *
	 * \param item this item
	 * \param ch the character owner
	 */
	bool (*allowed)(const struct item *item, const struct character *ch);
};

/**
 * Shortcut for item->exec (if not NULL).
 *
 * \pre item != NULL
 * \pre ch != NULL
 * \param item the item to use
 * \param ch the character owner
 */
void
item_exec(struct item *item, struct character *ch);

/**
 * Shortcut for item->allowed (if not NULL).
 *
 * \pre item != NULL
 * \pre ch != NULL
 * \param item the item to use
 * \param ch the character owner
 * \return The return value of item->allowed or true if NULL.
 */
bool
item_allowed(const struct item *item, struct character *ch);

#endif /* !MOLKO_ITEM_H */