Mercurial > molko
comparison libmlk-rpg/rpg/battle.h @ 243:71b3b7036de7
misc: lot of cleanups,
- prefix libraries with libmlk,
- move assets from source directories closes #2520,
- prefix header guards closes #2519
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Nov 2020 22:37:30 +0100 |
parents | librpg/rpg/battle.h@86b71e1f9dd5 |
children | 3991779aaba9 |
comparison
equal
deleted
inserted
replaced
242:4c24604efcab | 243:71b3b7036de7 |
---|---|
1 /* | |
2 * battle.h -- battles | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef MOLKO_RPG_BATTLE_H | |
20 #define MOLKO_RPG_BATTLE_H | |
21 | |
22 #include <stdbool.h> | |
23 | |
24 #include <core/action.h> | |
25 #include <core/drawable.h> | |
26 | |
27 #include <ui/frame.h> | |
28 #include <ui/gridmenu.h> | |
29 | |
30 #include "battle-bar.h" | |
31 #include "battle-entity.h" | |
32 #include "battle-state.h" | |
33 #include "selection.h" | |
34 #include "spell.h" | |
35 | |
36 union event; | |
37 | |
38 struct character; | |
39 struct music; | |
40 struct spell; | |
41 struct theme; | |
42 | |
43 #define BATTLE_TEAM_MAX (4) /*!< Maximum team members. */ | |
44 #define BATTLE_ENEMY_MAX (8) /*!< Maximum enemies. */ | |
45 #define BATTLE_ENTITY_MAX \ | |
46 (BATTLE_TEAM_MAX + BATTLE_ENEMY_MAX) | |
47 | |
48 #define BATTLE_TEAM_FOREACH(bt, iter) \ | |
49 for (size_t i = 0; i < BATTLE_TEAM_MAX && ((iter) = &(bt)->team[i]); ++i) | |
50 #define BATTLE_ENEMY_FOREACH(bt, iter) \ | |
51 for (size_t i = 0; i < BATTLE_ENEMY_MAX && ((iter) = &(bt)->enemies[i]); ++i) | |
52 | |
53 #define BATTLE_THEME(bt) ((bt)->theme ? (bt)->theme : theme_default()) | |
54 | |
55 /** | |
56 * \brief Generic battle status. | |
57 */ | |
58 enum battle_status { | |
59 BATTLE_STATUS_NONE, /*!< Battle is not even started. */ | |
60 BATTLE_STATUS_RUNNING, /*!< Battle is running. */ | |
61 BATTLE_STATUS_WON, /*!< Battle has been won. */ | |
62 BATTLE_STATUS_LOST, /*!< Battle has been lost. */ | |
63 }; | |
64 | |
65 /** | |
66 * \brief Battle structure. | |
67 */ | |
68 struct battle { | |
69 /** | |
70 * (+&?) Battle state. | |
71 */ | |
72 struct battle_state *state; | |
73 | |
74 /** | |
75 * (-) Battle status. | |
76 * | |
77 * This information is provided as final result once the battle has | |
78 * completed, modifying by the user won't change the battle routines. | |
79 */ | |
80 enum battle_status status; | |
81 | |
82 /** | |
83 * (+) Member of team. | |
84 */ | |
85 struct battle_entity team[BATTLE_TEAM_MAX]; | |
86 | |
87 /** | |
88 * (+) Ennemies to fight. | |
89 */ | |
90 struct battle_entity enemies[BATTLE_ENEMY_MAX]; | |
91 | |
92 /** | |
93 * (+&?) Order of playing. | |
94 */ | |
95 struct battle_entity *order[BATTLE_ENTITY_MAX]; | |
96 | |
97 /** | |
98 * (-&?) Current entity playing. | |
99 */ | |
100 struct battle_entity *order_cur; | |
101 | |
102 /** | |
103 * (-) Current entity playing index. | |
104 */ | |
105 size_t order_curindex; | |
106 | |
107 /** | |
108 * (+&?) An optional background. | |
109 */ | |
110 struct texture *background; | |
111 | |
112 /** | |
113 * (+&?) A music to play. | |
114 * | |
115 * Music to play in the battle: | |
116 * | |
117 * - [0]: while the battle is running, | |
118 * - [1]: in case of victory, | |
119 * - [2]: in case of lost. | |
120 */ | |
121 struct music *music[3]; | |
122 | |
123 /** | |
124 * (+&?) Theme to use. | |
125 */ | |
126 struct theme *theme; | |
127 | |
128 /** | |
129 * (+) Stack of animations. | |
130 * | |
131 * The drawing animations are ran in parallel. | |
132 */ | |
133 struct drawable_stack effects; | |
134 | |
135 /** | |
136 * (+) Stack of actions. | |
137 * | |
138 * The array [0] contains actions that must complete to continue the | |
139 * battle, it can be used to write some messages while blocking the | |
140 * battle. | |
141 * | |
142 * The array [1] is a set of actions that run in "parallel" and don't | |
143 * prevent the battle from continuing. | |
144 */ | |
145 struct action_stack actions[2]; | |
146 | |
147 /** | |
148 * (-) Bottom bar. | |
149 */ | |
150 struct battle_bar bar; | |
151 }; | |
152 | |
153 /** | |
154 * Call this function before using the battle but after calling \a battle_init. | |
155 * | |
156 * If the team entities are positioned to 0, 0 they will be placed | |
157 * automatically. | |
158 * | |
159 * \pre bt != NULL | |
160 * \param bt the battle object | |
161 */ | |
162 void | |
163 battle_start(struct battle *bt); | |
164 | |
165 /** | |
166 * Select next member in battle. | |
167 * | |
168 * \pre bt != NULL | |
169 * \param bt the battle object | |
170 */ | |
171 void | |
172 battle_next(struct battle *bt); | |
173 | |
174 struct battle_entity * | |
175 battle_find(struct battle *bt, const struct character *ch); | |
176 | |
177 /** | |
178 * Change battle state. | |
179 * | |
180 * \pre bt != NULL | |
181 * \pre st != NULL | |
182 * \param bt the battle object | |
183 * \param st the state (referenced) | |
184 * \warning This will immediately close the current state and call finish field | |
185 * function if defined. | |
186 */ | |
187 void | |
188 battle_switch(struct battle *bt, struct battle_state *st); | |
189 | |
190 /** | |
191 * Compute battle ordering. | |
192 * | |
193 * \pre bt != NULL | |
194 * \param bt the battle object | |
195 */ | |
196 void | |
197 battle_order(struct battle *bt); | |
198 | |
199 /** | |
200 * All in one function to animate and compute damage. | |
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" | |
213 * | |
214 * \pre bt != NULL | |
215 * \pre source != NULL | |
216 * \pre target != NULL | |
217 * \param bt the battle object | |
218 * \param source the entity attacking | |
219 * \param target the target entity | |
220 */ | |
221 void | |
222 battle_attack(struct battle *bt, | |
223 struct character *source, | |
224 struct character *target); | |
225 | |
226 /** | |
227 * Default function to cast a spell. | |
228 * | |
229 * Prefer to use this function to cast a spell because it performs some checks | |
230 * and hooks before casting the spell. | |
231 * | |
232 * \pre bt != NULL | |
233 * \pre source != NULL | |
234 * \pre spell != NULL | |
235 * \param bt the current battle | |
236 * \param source the entity casting a spell | |
237 * \param spell the spell used | |
238 * \param selection the selection | |
239 */ | |
240 void | |
241 battle_cast(struct battle *bt, | |
242 struct character *source, | |
243 const struct spell *spell, | |
244 unsigned int selection); | |
245 | |
246 /** | |
247 * Spawn an indicator drawable to show damage. | |
248 * | |
249 * The drawable will draw the amount near the entity and fade away after | |
250 * several seconds. | |
251 * | |
252 * \pre bt != NULL | |
253 * \pre target != NULL | |
254 * \param bt the battle object | |
255 * \param target the target entity | |
256 * \param amount the amount of damage | |
257 */ | |
258 void | |
259 battle_indicator_hp(struct battle *bt, const struct character *target, unsigned int amount); | |
260 | |
261 /** | |
262 * Handle an event. | |
263 * | |
264 * \pre bt != NULL | |
265 * \pre ev != NULL | |
266 * \param bt the battle object | |
267 * \param ev the event | |
268 */ | |
269 void | |
270 battle_handle(struct battle *bt, const union event *ev); | |
271 | |
272 /** | |
273 * Update the battle. | |
274 * | |
275 * \pre bt != NULL | |
276 * \param bt the battle object | |
277 * \param ticks the number of milliseconds since last frame | |
278 */ | |
279 bool | |
280 battle_update(struct battle *bt, unsigned int ticks); | |
281 | |
282 /** | |
283 * Draw the battle. | |
284 * | |
285 * \pre bt != NULL | |
286 * \param bt the battle object | |
287 */ | |
288 void | |
289 battle_draw(struct battle *bt); | |
290 | |
291 /** | |
292 * Finish and dispose resources if necessary. | |
293 * | |
294 * \pre bt != NULL | |
295 * \param bt the battle object | |
296 */ | |
297 void | |
298 battle_finish(struct battle *bt); | |
299 | |
300 #endif /* MOLKO_RPG_BATTLE_H */ |