comparison librpg/rpg/battle.h @ 230:86b71e1f9dd5

rpg: add movements in battle
author David Demelier <markand@malikania.fr>
date Mon, 23 Nov 2020 17:05:07 +0100
parents e71039d820a7
children
comparison
equal deleted inserted replaced
229:e71039d820a7 230:86b71e1f9dd5
23 23
24 #include <core/action.h> 24 #include <core/action.h>
25 #include <core/drawable.h> 25 #include <core/drawable.h>
26 26
27 #include <ui/frame.h> 27 #include <ui/frame.h>
28 #include <ui/label.h>
29 #include <ui/gridmenu.h> 28 #include <ui/gridmenu.h>
30 29
31 #include "battle-bar.h" 30 #include "battle-bar.h"
31 #include "battle-entity.h"
32 #include "battle-state.h" 32 #include "battle-state.h"
33 #include "selection.h" 33 #include "selection.h"
34 #include "spell.h" 34 #include "spell.h"
35 35
36 union event; 36 union event;
49 for (size_t i = 0; i < BATTLE_TEAM_MAX && ((iter) = &(bt)->team[i]); ++i) 49 for (size_t i = 0; i < BATTLE_TEAM_MAX && ((iter) = &(bt)->team[i]); ++i)
50 #define BATTLE_ENEMY_FOREACH(bt, iter) \ 50 #define BATTLE_ENEMY_FOREACH(bt, iter) \
51 for (size_t i = 0; i < BATTLE_ENEMY_MAX && ((iter) = &(bt)->enemies[i]); ++i) 51 for (size_t i = 0; i < BATTLE_ENEMY_MAX && ((iter) = &(bt)->enemies[i]); ++i)
52 52
53 #define BATTLE_THEME(bt) ((bt)->theme ? (bt)->theme : theme_default()) 53 #define BATTLE_THEME(bt) ((bt)->theme ? (bt)->theme : theme_default())
54
55 /**
56 * \brief In battle entity.
57 */
58 struct battle_entity {
59 struct character *ch; /*!< (+&?) Character to use. */
60 int x; /*!< (+) Position on screen. */
61 int y; /*!< (+) Position on screen. */
62 struct label name; /*!< (*) Where its name label is located. */
63 };
64 54
65 /** 55 /**
66 * \brief Generic battle status. 56 * \brief Generic battle status.
67 */ 57 */
68 enum battle_status { 58 enum battle_status {
171 */ 161 */
172 void 162 void
173 battle_start(struct battle *bt); 163 battle_start(struct battle *bt);
174 164
175 /** 165 /**
176 * Select next member in team. 166 * Select next member in battle.
177 * 167 *
178 * \pre bt != NULL 168 * \pre bt != NULL
179 * \param bt the battle object 169 * \param bt the battle object
180 */ 170 */
181 void 171 void
182 battle_next(struct battle *bt); 172 battle_next(struct battle *bt);
173
174 struct battle_entity *
175 battle_find(struct battle *bt, const struct character *ch);
183 176
184 /** 177 /**
185 * Change battle state. 178 * Change battle state.
186 * 179 *
187 * \pre bt != NULL 180 * \pre bt != NULL
202 */ 195 */
203 void 196 void
204 battle_order(struct battle *bt); 197 battle_order(struct battle *bt);
205 198
206 /** 199 /**
207 * Default function to calculate damage calculation from the source to the 200 * All in one function to animate and compute damage.
208 * given target and then add an amount indicator as a drawable. 201 *
202 * Use this function from the character AI or when a character from the team
203 * should attack an enemy.
204 *
205 * This will do the following in order:
206 *
207 * 1. Change battle state to "attacking"
208 * 2. Change battle entity state to "moving" or "blinking" if source is member of
209 * team or enemies respectively.
210 * 3. Wait until animations complete.
211 * 4. Compute and produce damage.
212 * 5. Change battle state to "check"
209 * 213 *
210 * \pre bt != NULL 214 * \pre bt != NULL
211 * \pre source != NULL 215 * \pre source != NULL
212 * \pre target != NULL 216 * \pre target != NULL
213 * \param bt the battle object 217 * \param bt the battle object
214 * \param source the entity attacking 218 * \param source the entity attacking
215 * \param target the target entity 219 * \param target the target entity
216 */ 220 */
217 void 221 void
218 battle_attack(struct battle *bt, struct character *source, struct character *target); 222 battle_attack(struct battle *bt,
223 struct character *source,
224 struct character *target);
219 225
220 /** 226 /**
221 * Default function to cast a spell. 227 * Default function to cast a spell.
222 * 228 *
223 * Prefer to use this function to cast a spell because it performs some checks 229 * Prefer to use this function to cast a spell because it performs some checks