Mercurial > molko
changeset 175:ce789473567e
rpg: disable inventory for now and add item.c
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 22 Oct 2020 15:27:57 +0200 |
parents | 6992085d47fd |
children | 408e4823e378 |
files | librpg/CMakeLists.txt librpg/rpg/inventory.c librpg/rpg/inventory.h librpg/rpg/item.c librpg/rpg/item.h tests/test-inventory.c |
diffstat | 6 files changed, 86 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/librpg/CMakeLists.txt Thu Oct 22 15:16:43 2020 +0200 +++ b/librpg/CMakeLists.txt Thu Oct 22 15:27:57 2020 +0200 @@ -22,6 +22,7 @@ SOURCES ${librpg_SOURCE_DIR}/rpg/inventory.c ${librpg_SOURCE_DIR}/rpg/inventory.h + ${librpg_SOURCE_DIR}/rpg/item.c ${librpg_SOURCE_DIR}/rpg/item.h ${librpg_SOURCE_DIR}/rpg/map.c ${librpg_SOURCE_DIR}/rpg/map.h
--- a/librpg/rpg/inventory.c Thu Oct 22 15:16:43 2020 +0200 +++ b/librpg/rpg/inventory.c Thu Oct 22 15:27:57 2020 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if 0 + #include <assert.h> #include <stddef.h> #include <stdlib.h> @@ -208,3 +210,5 @@ memset(iv, 0, sizeof (*iv)); } + +#endif
--- a/librpg/rpg/inventory.h Thu Oct 22 15:16:43 2020 +0200 +++ b/librpg/rpg/inventory.h Thu Oct 22 15:27:57 2020 +0200 @@ -19,6 +19,8 @@ #ifndef MOLKO_INVENTORY_H #define MOLKO_INVENTORY_H +#if 0 + /** * \file inventory.h * \brief Inventory of items. @@ -89,4 +91,6 @@ void inventory_clear(struct inventory *iv); +#endif + #endif /* !MOLKO_INVENTORY_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/librpg/rpg/item.c Thu Oct 22 15:27:57 2020 +0200 @@ -0,0 +1,39 @@ +/* + * item.c -- 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. + */ + +#include <assert.h> + +#include "item.h" + +void +item_exec(struct item *item, struct character *ch) +{ + assert(item); + assert(ch); + + return item->exec(item, ch); +} + +bool +item_allowed(const struct item *item, struct character *ch) +{ + assert(item); + assert(ch); + + return item->allowed ? item->allowed(item, ch) : true; +}
--- a/librpg/rpg/item.h Thu Oct 22 15:16:43 2020 +0200 +++ b/librpg/rpg/item.h Thu Oct 22 15:27:57 2020 +0200 @@ -26,11 +26,6 @@ #include <stdbool.h> -/** - * \brief Maximum count of an item into a stack. - */ -#define ITEM_STACK_MAX 64 - struct character; struct texture; @@ -41,17 +36,45 @@ const char *name; /*!< (+) Name of item. */ const char *summary; /*!< (+) Summary description. */ struct texture *icon; /*!< (+&) Icon to show. */ - unsigned int stackable; /*!< (+) Stack count allowed. */ /** * (+) Execute the action for this character. + * + * \param item this item + * \param ch the character owner */ - void (*exec)(const struct item *, struct character *); + 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 *, const struct character *); + 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 */
--- a/tests/test-inventory.c Thu Oct 22 15:16:43 2020 +0200 +++ b/tests/test-inventory.c Thu Oct 22 15:27:57 2020 +0200 @@ -19,6 +19,8 @@ #define GREATEST_USE_ABBREVS 0 #include <greatest.h> +#if 0 + #include <rpg/item.h> #include <rpg/inventory.h> @@ -249,11 +251,16 @@ GREATEST_MAIN_DEFS(); +#endif + int main(int argc, char **argv) { +#if 0 GREATEST_MAIN_BEGIN(); GREATEST_RUN_SUITE(push); GREATEST_RUN_SUITE(sort); GREATEST_MAIN_END(); +#endif + return 0; }