Mercurial > molko
changeset 254:6367b976112d
rpg: merge battle state switchers to remove number of files
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 03 Dec 2020 13:49:54 +0100 |
parents | c4da052c0def |
children | d987a5fc4a3e |
files | libmlk-rpg/CMakeLists.txt libmlk-rpg/rpg/battle-entity-state-attacking.c libmlk-rpg/rpg/battle-entity-state-attacking.h libmlk-rpg/rpg/battle-entity-state-blinking.c libmlk-rpg/rpg/battle-entity-state-blinking.h libmlk-rpg/rpg/battle-entity-state-moving.c libmlk-rpg/rpg/battle-entity-state-moving.h libmlk-rpg/rpg/battle-entity-state-normal.c libmlk-rpg/rpg/battle-entity-state-normal.h libmlk-rpg/rpg/battle-entity-state.h libmlk-rpg/rpg/battle-entity.c libmlk-rpg/rpg/battle-state-ai.c libmlk-rpg/rpg/battle-state-ai.h libmlk-rpg/rpg/battle-state-attacking.c libmlk-rpg/rpg/battle-state-attacking.h libmlk-rpg/rpg/battle-state-check.c libmlk-rpg/rpg/battle-state-check.h libmlk-rpg/rpg/battle-state-closing.c libmlk-rpg/rpg/battle-state-closing.h libmlk-rpg/rpg/battle-state-lost.c libmlk-rpg/rpg/battle-state-lost.h libmlk-rpg/rpg/battle-state-menu.c libmlk-rpg/rpg/battle-state-menu.h libmlk-rpg/rpg/battle-state-opening.c libmlk-rpg/rpg/battle-state-opening.h libmlk-rpg/rpg/battle-state-selection.c libmlk-rpg/rpg/battle-state-selection.h libmlk-rpg/rpg/battle-state-sub.c libmlk-rpg/rpg/battle-state-sub.h libmlk-rpg/rpg/battle-state-victory.c libmlk-rpg/rpg/battle-state-victory.h libmlk-rpg/rpg/battle-state.h libmlk-rpg/rpg/battle.c |
diffstat | 33 files changed, 57 insertions(+), 805 deletions(-) [+] |
line wrap: on
line diff
--- a/libmlk-rpg/CMakeLists.txt Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/CMakeLists.txt Thu Dec 03 13:49:54 2020 +0100 @@ -29,37 +29,23 @@ ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state.c ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-attacking.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-attacking.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-blinking.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-blinking.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-moving.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-moving.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-normal.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-entity-state-normal.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-indicator.c ${libmlk-rpg_SOURCE_DIR}/rpg/battle-indicator.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state.c ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-ai.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-ai.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-attacking.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-attacking.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-check.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-check.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-closing.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-closing.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-menu.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-menu.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-lost.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-lost.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-opening.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-opening.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-selection.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-selection.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-sub.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-sub.h ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-victory.c - ${libmlk-rpg_SOURCE_DIR}/rpg/battle-state-victory.h ${libmlk-rpg_SOURCE_DIR}/rpg/character.c ${libmlk-rpg_SOURCE_DIR}/rpg/character.h ${libmlk-rpg_SOURCE_DIR}/rpg/equipment.c
--- a/libmlk-rpg/rpg/battle-entity-state-attacking.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-attacking.c Thu Dec 03 13:49:54 2020 +0100 @@ -26,7 +26,6 @@ #include <core/sprite.h> #include "battle-entity.h" -#include "battle-entity-state-attacking.h" #include "battle-entity-state.h" struct data {
--- a/libmlk-rpg/rpg/battle-entity-state-attacking.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * battle-entity-state-attacking.h -- the entity is attacking - * - * 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_RPG_BATTLE_ENTITY_STATE_ATTACKING_H -#define MOLKO_RPG_BATTLE_ENTITY_STATE_ATTACKING_H - -/** - * \file battle-entity-state-attacking.h - * \brief The entity is attacking. - */ - -struct battle_entity; -struct sprite; - -/** - * Change battle entity state to attacking. - * - * This will animate the entity with the given sprite which should contain an - * animation with the player and its weapon. - * - * \pre battle_entity_ok(et) - * \pre sprite_ok(which) - * \param et the entity - * \param which the sprite to use as animation - * \post et->state->data is set to custom data - * \post et->state->draw is set - * \post et->state->update is set - * \post et->state->finish is set - */ -void -battle_entity_state_attacking(struct battle_entity *et, struct sprite *which); - -#endif /* !MOLKO_RPG_BATTLE_ENTITY_STATE_ATTACKING_H */
--- a/libmlk-rpg/rpg/battle-entity-state-blinking.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-blinking.c Thu Dec 03 13:49:54 2020 +0100 @@ -25,7 +25,6 @@ #include <core/texture.h> #include "battle-entity.h" -#include "battle-entity-state-blinking.h" #include "battle-entity-state.h" #include "character.h"
--- a/libmlk-rpg/rpg/battle-entity-state-blinking.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * battle-entity-state-blinking.h -- the entity is blinking - * - * 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_RPG_BATTLE_ENTITY_STATE_BLINKING_H -#define MOLKO_RPG_BATTLE_ENTITY_STATE_BLINKING_H - -/** - * \file battle-entity-state-blinking.h - * \brief The entity is blinking. - */ - -struct battle_entity; - -/** - * Start blinking the entity. - * - * This state will blink two times the entity by reducing the alpha from it at - * two intervals. It is designed mostly for enemies since they don't have - * walking sprites. - * - * \pre battle_entity_ok(et) - * \param et the entity to change - * \post et->state->data is set to custom data - * \post et->state->update is set - * \post et->state->finish is set - */ -void -battle_entity_state_blinking(struct battle_entity *et); - -#endif /* !MOLKO_RPG_BATTLE_ENTITY_STATE_BLINKING_H */
--- a/libmlk-rpg/rpg/battle-entity-state-moving.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-moving.c Thu Dec 03 13:49:54 2020 +0100 @@ -25,7 +25,6 @@ #include "battle-entity.h" #include "battle-entity-state.h" -#include "battle-entity-state-moving.h" #include "character.h" #include "walksprite.h"
--- a/libmlk-rpg/rpg/battle-entity-state-moving.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * battle-entity-state-moving.h -- the entity is moving - * - * 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_RPG_BATTLE_ENTITY_STATE_MOVING_H -#define MOLKO_RPG_BATTLE_ENTITY_STATE_MOVING_H - -/** - * \file battle-entity-state-moving.h - * \brief The entity is moving. - */ - -struct battle_entity; - -/** - * Starts moving the entity at the given destination. - * - * This will move the entity to the destination using a walking sprite. - * - * \pre battle_entity_ok(et) - * \param et the entity to move - * \param destx the destination in x - * \param desty the destination in y - * \post et->state->data is set to custom data - * \post et->state->update is set - * \post et->state->finish is set - */ -void -battle_entity_state_moving(struct battle_entity *et, int destx, int desty); - -#endif /* !MOLKO_RPG_BATTLE_ENTITY_STATE_MOVING_H */
--- a/libmlk-rpg/rpg/battle-entity-state-normal.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-normal.c Thu Dec 03 13:49:54 2020 +0100 @@ -18,9 +18,8 @@ #include <assert.h> -#include "battle-entity-state-normal.h" +#include "battle-entity.h" #include "battle-entity-state.h" -#include "battle-entity.h" void battle_entity_state_normal(struct battle_entity *et)
--- a/libmlk-rpg/rpg/battle-entity-state-normal.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * battle-entity-state-normal.h -- the entity is normal - * - * 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_RPG_BATTLE_ENTITY_STATE_NORMAL_H -#define MOLKO_RPG_BATTLE_ENTITY_STATE_NORMAL_H - -/** - * \file battle-entity-state-normal.h - * \brief The entity is normal. - */ - -struct battle_entity; - -/** - * Set normal state. - * - * The normal state does nothing except rendering the entity at its current - * position. - * - * \pre battle_entity_ok(et) - * \param et the entity to set - */ -void -battle_entity_state_normal(struct battle_entity *et); - -#endif /* !MOLKO_RPG_BATTLE_ENTITY_STATE_NORMAL_H */
--- a/libmlk-rpg/rpg/battle-entity-state.h Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state.h Thu Dec 03 13:49:54 2020 +0100 @@ -19,106 +19,38 @@ #ifndef MOLKO_RPG_BATTLE_ENTITY_STATE_H #define MOLKO_RPG_BATTLE_ENTITY_STATE_H -/** - * \file battle-entity-state.h - * \brief Abstract battle entity state. - * - * To animate and update battle entities this structure help splitting the logic - * into differents parts. - * - * In contrast to battle states, battle entity states should not switch - * themselves into an other one because battle states may need to wait until the - * entity state has finished to continue their own work. - * - * \note Do not call pointer functions directly but use the functions from this - * file since they may do additional work. - */ - #include <stdbool.h> struct battle_entity; - -/** - * \brief Abstract battle entity state. - */ -struct battle_entity_state { - /** - * (+&?) Optional state data. - */ - void *data; +struct sprite; - /** - * (+?) Update the entity. - * - * This function should understand a value of 0 as ticks to just request - * the state's status. - * - * \pre st != NULL - * \pre et != NULL - * \param st this state - * \param et the entity owner - * \param ticks elapsed milliseconds since last frame - * \return True if complete. - */ +struct battle_entity_state { + void *data; bool (*update)(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks); - - /** - * (+?) Draw the entity. - * - * If this function is NULL, the default behavior is to draw the entity - * sprite at its current position. - * - * \pre st != NULL - * \pre et != NULL - * \param st this state - * \param et the entity owner - */ void (*draw)(const struct battle_entity_state *st, const struct battle_entity *et); - - /** - * (+?) Clear resources. - * - * \pre st != NULL - * \pre et != NULL - * \param st this state - * \param et the entity owner - */ void (*finish)(struct battle_entity_state *st, struct battle_entity *et); }; -/** - * Shortcut for st->update (if not NULL). - * - * \pre st != NULL - * \pre et != NULL - * \param st this state - * \param et the entity owner - * \param ticks elapsed milliseconds since last frame - * \return True if complete. - */ bool battle_entity_state_update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks); -/** - * Call st->draw or default implementation if NULL. - * - * \pre st != NULL - * \pre et != NULL - * \param st this state - * \param et the entity owner - */ void battle_entity_state_draw(const struct battle_entity_state *st, const struct battle_entity *et); -/** - * Shortcut for st->finish (if not NULL). - * - * \pre st != NULL - * \pre et != NULL - * \param st this state - * \param et the entity owner - */ void battle_entity_state_finish(struct battle_entity_state *st, struct battle_entity *et); +/* Defined in their own files. */ +void +battle_entity_state_normal(struct battle_entity *et); + +void +battle_entity_state_moving(struct battle_entity *et, int destx, int desty); + +void +battle_entity_state_blinking(struct battle_entity *et); + +void +battle_entity_state_attacking(struct battle_entity *et, struct sprite *which); + #endif /* !MOLKO_RPG_BATTLE_ENTITY_STATE_H */
--- a/libmlk-rpg/rpg/battle-entity.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-entity.c Thu Dec 03 13:49:54 2020 +0100 @@ -26,7 +26,6 @@ #include "battle.h" #include "battle-entity.h" #include "battle-entity-state.h" -#include "battle-entity-state-normal.h" #include "character.h" static void
--- a/libmlk-rpg/rpg/battle-state-ai.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-ai.c Thu Dec 03 13:49:54 2020 +0100 @@ -20,8 +20,6 @@ #include "battle.h" #include "battle-state.h" -#include "battle-state-ai.h" -#include "battle-state-check.h" #include "character.h" static bool
--- a/libmlk-rpg/rpg/battle-state-ai.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * battle-state-ai.h -- battle state (enemy is playing) - * - * 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_RPG_BATTLE_STATE_AI_H -#define MOLKO_RPG_BATTLE_STATE_AI_H - -/** - * \file battle-state-ai.h - * \brief Battle state (enemy is playing). - */ - -struct battle; - -/** - * Switch to battle state AI. - * - * \pre bt != NULL - * \param bt the battle to change state - * \post bt->state->update is set - */ -void -battle_state_ai(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_AI_H */
--- a/libmlk-rpg/rpg/battle-state-attacking.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-attacking.c Thu Dec 03 13:49:54 2020 +0100 @@ -23,14 +23,9 @@ #include <core/panic.h> #include <core/sprite.h> -#include "battle-state-check.h" -#include "battle-entity-state-attacking.h" -#include "battle-entity-state-blinking.h" -#include "battle-entity-state-moving.h" -#include "battle-entity-state-normal.h" -#include "battle-state-attacking.h" #include "battle.h" #include "battle-state.h" +#include "battle-entity-state.h" #include "character.h" enum substate {
--- a/libmlk-rpg/rpg/battle-state-attacking.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * battle-state-attacking.h -- battle state (entity is moving for attacking) - * - * 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_RPG_BATTLE_STATE_ATTACKING_H -#define MOLKO_RPG_BATTLE_STATE_ATTACKING_H - -/** - * \file battle-state-attacking.h - * \brief Battle state (entity is moving for attacking). - * - * This state will move the entity source to the target if it is a member of - * team or will blink the enemy. Then it computes damage and change state to - * check. - */ - -struct battle; -struct character; - -/** - * Switch to battle state attacking. - * - * \pre battle_ok(bt) - * \pre character_ok(source) - * \pre character_ok(target) - * \param bt the battle to change state - * \param source the entity attacking - * \param target the target to damage - * \post bt->state->data is set to a custom data type - * \post bt->state->update is set - * \post bt->state->finish is set - */ -void -battle_state_attacking(struct battle *bt, struct character *source, struct character *target); - -#endif /* !MOLKO_RPG_BATTLE_STATE_CHECK_H */
--- a/libmlk-rpg/rpg/battle-state-check.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-check.c Thu Dec 03 13:49:54 2020 +0100 @@ -27,9 +27,6 @@ #include "battle.h" #include "battle-state.h" -#include "battle-state-check.h" -#include "battle-state-lost.h" -#include "battle-state-victory.h" #include "character.h" struct fadeout {
--- a/libmlk-rpg/rpg/battle-state-check.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * battle-state-check.h -- battle state (check status) - * - * 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_RPG_BATTLE_STATE_CHECK_H -#define MOLKO_RPG_BATTLE_STATE_CHECK_H - -/** - * \file battle-state-check.h - * \brief Battle state (check status). - */ - -struct battle; - -/** - * Switch to battle state check. - * - * \pre bt != NULL - * \param bt the battle to change state - * \post bt->state->update is set - */ -void -battle_state_check(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_CHECK_H */
--- a/libmlk-rpg/rpg/battle-state-closing.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-closing.c Thu Dec 03 13:49:54 2020 +0100 @@ -27,7 +27,6 @@ #include <core/window.h> #include "battle.h" -#include "battle-state-closing.h" struct closing { struct battle_state self;
--- a/libmlk-rpg/rpg/battle-state-closing.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * battle-state-closing.h -- battle state (closing) - * - * 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_RPG_BATTLE_STATE_CLOSING_H -#define MOLKO_RPG_BATTLE_STATE_CLOSING_H - -/** - * \file battle-state-closing.h - * \brief Battle state (closing). - */ - -struct battle; - -/** - * Switch to battle state closing. - * - * \pre bt != NULL - * \param bt the battle to change state - */ -void -battle_state_closing(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_CLOSING_H */
--- a/libmlk-rpg/rpg/battle-state-lost.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-lost.c Thu Dec 03 13:49:54 2020 +0100 @@ -27,8 +27,6 @@ #include "battle.h" #include "battle-state.h" -#include "battle-state-closing.h" -#include "battle-state-victory.h" #include "rpg_p.h" struct lost {
--- a/libmlk-rpg/rpg/battle-state-lost.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * battle-state-lost.h -- battle state (lost) - * - * 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_RPG_BATTLE_STATE_LOST_H -#define MOLKO_RPG_BATTLE_STATE_LOST_H - -/** - * \file battle-state-lost.h - * \brief Battle state (lost) - */ - -struct battle; - -/** - * Switch to battle state lost. - * - * \pre bt != NULL - * \param bt the battle to change state - */ -void -battle_state_lost(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_LOST_H */
--- a/libmlk-rpg/rpg/battle-state-menu.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-menu.c Thu Dec 03 13:49:54 2020 +0100 @@ -21,9 +21,6 @@ #include "battle.h" #include "battle-bar.h" -#include "battle-state-menu.h" -#include "battle-state-selection.h" -#include "battle-state-sub.h" #include "battle-state.h" #include "character.h" #include "spell.h"
--- a/libmlk-rpg/rpg/battle-state-menu.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * battle-state-menu.h -- battle state (menu) - * - * 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_RPG_BATTLE_STATE_MENU_H -#define MOLKO_RPG_BATTLE_STATE_MENU_H - -/** - * \file battle-state-menu.h - * \brief Battle state (menu). - */ - -struct battle; - -/** - * Switch to battle state menu. - * - * \pre bt != NULL - * \param bt the battle to change state - * \post bt->state->handle is set - */ -void -battle_state_menu(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_MENU_H */
--- a/libmlk-rpg/rpg/battle-state-opening.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-opening.c Thu Dec 03 13:49:54 2020 +0100 @@ -27,9 +27,6 @@ #include "battle.h" #include "battle-state.h" -#include "battle-state-check.h" -#include "battle-state-opening.h" -#include "battle-state-menu.h" #define DELAY (1000U)
--- a/libmlk-rpg/rpg/battle-state-opening.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * battle-state-opening.h -- battle state (opening) - * - * 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_RPG_BATTLE_STATE_OPENING_H -#define MOLKO_RPG_BATTLE_STATE_OPENING_H - -/** - * \file battle-state-opening.h - * \brief Battle state (opening). - */ - -struct battle; - -/** - * Switch to battle state opening. - * - * \pre bt != NULL - * \param bt the battle to change state - * \post bt->state->data is not NULL - * \post bt->state->update is set - * \post bt->state->draw is set - * \post bt->state->finish is set - */ -void -battle_state_opening(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_OPENING_H */
--- a/libmlk-rpg/rpg/battle-state-selection.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-selection.c Thu Dec 03 13:49:54 2020 +0100 @@ -30,10 +30,6 @@ #include "battle.h" #include "battle-bar.h" #include "battle-state.h" -#include "battle-state-check.h" -#include "battle-state-menu.h" -#include "battle-state-selection.h" -#include "battle-state-sub.h" #include "character.h" #include "spell.h"
--- a/libmlk-rpg/rpg/battle-state-selection.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * battle-state-selection.h -- battle state (selection) - * - * 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_RPG_BATTLE_STATE_SELECTION_H -#define MOLKO_RPG_BATTLE_STATE_SELECTION_H - -/** - * \file battle-state-selection.h - * \brief Battle state (selection). - */ - -#include "selection.h" - -struct battle; - -/** - * Switch to battle state selection. - * - * \pre bt != NULL - * \param bt the battle to change state - * \param type the kind of selection allowed - * \param selection the current selection - * \post bt->state->data is not NULL - * \post bt->state->handle is set - * \post bt->state->draw is set - * \post bt->state->finish is set - */ -void -battle_state_selection(struct battle *bt, - enum selection type, - unsigned int selection); - -#endif /* !MOLKO_RPG_BATTLE_STATE_SELECTION_H */
--- a/libmlk-rpg/rpg/battle-state-sub.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-sub.c Thu Dec 03 13:49:54 2020 +0100 @@ -28,9 +28,6 @@ #include "battle.h" #include "battle-bar.h" #include "battle-state.h" -#include "battle-state-menu.h" -#include "battle-state-sub.h" -#include "battle-state-selection.h" #include "character.h" #include "spell.h"
--- a/libmlk-rpg/rpg/battle-state-sub.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * battle-state-sub.h -- battle state (sub) - * - * 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_RPG_BATTLE_STATE_SUB_H -#define MOLKO_RPG_BATTLE_STATE_SUB_H - -/** - * \file battle-state-sub.h - * \brief Battle state (sub). - */ - -struct battle; - -/** - * Switch to battle state sub. - * - * \pre bt != NULL - * \param bt the battle to change state - * \post bt->state->handle is set - * \post bt->state->draw is set - */ -void -battle_state_sub(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_SUB_H */
--- a/libmlk-rpg/rpg/battle-state-victory.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state-victory.c Thu Dec 03 13:49:54 2020 +0100 @@ -27,8 +27,6 @@ #include "battle.h" #include "battle-state.h" -#include "battle-state-closing.h" -#include "battle-state-victory.h" #include "rpg_p.h" struct victory {
--- a/libmlk-rpg/rpg/battle-state-victory.h Thu Dec 03 09:06:52 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * battle-state-victory.h -- battle state (victory) - * - * 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_RPG_BATTLE_STATE_VICTORY_H -#define MOLKO_RPG_BATTLE_STATE_VICTORY_H - -/** - * \file battle-state-victory.h - * \brief Battle state (victory). - */ - -struct battle; - -/** - * Switch to battle state victory. - * - * \pre bt != NULL - * \param bt the battle to change state - */ -void -battle_state_victory(struct battle *bt); - -#endif /* !MOLKO_RPG_BATTLE_STATE_VICTORY_H */
--- a/libmlk-rpg/rpg/battle-state.h Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle-state.h Thu Dec 03 13:49:54 2020 +0100 @@ -33,105 +33,67 @@ #include <stdbool.h> +#include "selection.h" + struct battle; +struct character; union event; -/** - * \brief Battle abstract state. - */ struct battle_state { - /** - * (+&?) Optional data for the state. - */ void *data; - - /** - * (+?) Handle an event. - * - * \pre bt != NULL - * \pre ev != NULL - * \param bt the current battle - * \param ev the event - */ void (*handle)(struct battle_state *st, struct battle *bt, const union event *ev); - - /** - * (+?) Update the battle state. - * - * \pre bt != NULL - * \param bt the current battle - * \param ticks the number of milliseconds since last frame - * \return True if the battle is considered complete. - */ bool (*update)(struct battle_state *st, struct battle *bt, unsigned int ticks); - - /** - * (+?) Draw the battle state. - * - * Note, the battle itself already draw the background and game - * entities. - * - * \pre bt != NULL - * \param bt the current battle - */ void (*draw)(const struct battle_state *st, const struct battle *bt); - - /** - * (+?) Close internal resources if necessary. - * - * \pre bt != NULL - * \param bt the current battle - */ void (*finish)(struct battle_state *st, struct battle *bt); }; -/** - * Shortcut for st->handle (if not NULL). - * - * \pre st != NULL - * \pre bt != NULL - * \pre ev != NULL - * \param st this state - * \param bt the current battle - * \param ev the input event - */ void battle_state_handle(struct battle_state *st, struct battle *bt, const union event *ev); -/** - * Shortcut for st->update (if not NULL). - * - * \pre st != NULL - * \pre bt != NULL - * \param st this state - * \param bt the current battle - * \param ticks the number of milliseconds since last frame - * \return The result of st->update if not NULL or false otherwise. - */ bool battle_state_update(struct battle_state *st, struct battle *bt, unsigned int ticks); -/** - * Shortcut for st->draw (if not NULL). - * - * \pre st != NULL - * \pre bt != NULL - * \param st this state - * \param bt the current battle - */ void battle_state_draw(const struct battle_state *st, const struct battle *bt); -/** - * Shortcut for st->finish (if not NULL). - * - * \pre st != NULL - * \pre bt != NULL - * \param st this state - * \param bt the current battle - */ void battle_state_finish(struct battle_state *st, struct battle *bt); +/* States switchers, defined in their own files. */ +void +battle_state_ai(struct battle *bt); + +void +battle_state_attacking(struct battle *bt, struct character *source, struct character *target); + +void +battle_state_check(struct battle *bt); + +void +battle_state_check(struct battle *bt); + +void +battle_state_closing(struct battle *bt); + +void +battle_state_lost(struct battle *bt); + +void +battle_state_menu(struct battle *bt); + +void +battle_state_opening(struct battle *bt); + +void +battle_state_selection(struct battle *bt, + enum selection type, + unsigned int selection); + +void +battle_state_sub(struct battle *bt); + +void +battle_state_victory(struct battle *bt); + #endif /* !MOLKO_RPG_BATTLE_STATE_H */
--- a/libmlk-rpg/rpg/battle.c Thu Dec 03 09:06:52 2020 +0100 +++ b/libmlk-rpg/rpg/battle.c Thu Dec 03 13:49:54 2020 +0100 @@ -39,11 +39,6 @@ #include "battle.h" #include "battle-indicator.h" #include "battle-state.h" -#include "battle-state-attacking.h" -#include "battle-state-check.h" -#include "battle-state-opening.h" -#include "battle-state-menu.h" -#include "battle-state-ai.h" #include "character.h" #include "spell.h"