comparison libmlk-rpg/rpg/battle-state-menu.c @ 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-state-menu.c@86b71e1f9dd5
children 6367b976112d
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * battle-state-menu.h -- battle state (menu)
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 #include <assert.h>
20 #include <stdbool.h>
21
22 #include "battle.h"
23 #include "battle-bar.h"
24 #include "battle-state-menu.h"
25 #include "battle-state-selection.h"
26 #include "battle-state-sub.h"
27 #include "battle-state.h"
28 #include "character.h"
29 #include "spell.h"
30
31 static void
32 open_spells(struct battle *bt)
33 {
34 battle_bar_open_spells(&bt->bar, bt, bt->order_cur->ch);
35 battle_state_sub(bt);
36 }
37
38 static void
39 open_attack(struct battle *bt)
40 {
41 unsigned int selection = 0;
42
43 /* Find first enemy to attack. */
44 for (size_t i = 0; i < BATTLE_ENEMY_MAX; ++i) {
45 if (character_ok(bt->enemies[i].ch)) {
46 selection = i;
47 break;
48 }
49 }
50
51 battle_state_selection(bt, SELECTION_ENEMY_ONE, selection);
52 }
53
54 static void
55 handle(struct battle_state *st, struct battle *bt, const union event *ev)
56 {
57 (void)st;
58
59 if (battle_bar_handle(&bt->bar, bt, ev)) {
60 switch (bt->bar.menu) {
61 case BATTLE_BAR_MENU_ATTACK:
62 open_attack(bt);
63 break;
64 case BATTLE_BAR_MENU_MAGIC:
65 open_spells(bt);
66 break;
67 case BATTLE_BAR_MENU_OBJECTS:
68 break;
69 case BATTLE_BAR_MENU_SPECIAL:
70 break;
71 default:
72 break;
73 }
74 }
75 }
76
77 void
78 battle_state_menu(struct battle *bt)
79 {
80 assert(bt);
81
82 static struct battle_state self = {
83 .handle = handle,
84 };
85
86 battle_switch(bt, &self);
87 }