# HG changeset patch # User David Demelier # Date 1603373277 -7200 # Node ID ce789473567e91e57229e8776047b3b6ce7b8fd3 # Parent 6992085d47fdff6b4509b81c0fbeb61aff140abc rpg: disable inventory for now and add item.c diff -r 6992085d47fd -r ce789473567e librpg/CMakeLists.txt --- 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 diff -r 6992085d47fd -r ce789473567e librpg/rpg/inventory.c --- 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 #include #include @@ -208,3 +210,5 @@ memset(iv, 0, sizeof (*iv)); } + +#endif diff -r 6992085d47fd -r ce789473567e librpg/rpg/inventory.h --- 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 */ diff -r 6992085d47fd -r ce789473567e librpg/rpg/item.c --- /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 + * + * 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 + +#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; +} diff -r 6992085d47fd -r ce789473567e librpg/rpg/item.h --- 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 -/** - * \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 */ diff -r 6992085d47fd -r ce789473567e tests/test-inventory.c --- 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 +#if 0 + #include #include @@ -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; }