comparison libmlk-rpg/mlk/rpg/battle-state-ai.c @ 434:4e78f045e8c0

rpg: cleanup hierarchy
author David Demelier <markand@malikania.fr>
date Sat, 15 Oct 2022 21:24:17 +0200
parents src/libmlk-rpg/rpg/battle-state-ai.c@8f59201dc76b
children 25a56ca53ac2
comparison
equal deleted inserted replaced
433:862b15c3a3ae 434:4e78f045e8c0
1 /*
2 * battle-state-ai.c -- battle state (enemy is playing)
3 *
4 * Copyright (c) 2020-2022 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 <stdlib.h>
21
22 #include <mlk/core/alloc.h>
23
24 #include "battle-state-ai.h"
25 #include "battle-state.h"
26 #include "battle.h"
27 #include "character.h"
28
29 static int
30 update(struct battle_state *st, struct battle *bt, unsigned int ticks)
31 {
32 (void)st;
33 (void)ticks;
34
35 battle_state_ai_update(bt);
36
37 return 0;
38 }
39
40 static void
41 draw(const struct battle_state *st, const struct battle *bt)
42 {
43 (void)st;
44
45 battle_state_ai_draw(bt);
46 }
47
48 static void
49 finish(struct battle_state *st, struct battle *bt)
50 {
51 (void)bt;
52
53 free(st);
54 }
55
56 void
57 battle_state_ai_update(struct battle *bt)
58 {
59 assert(battle_ok(bt));
60
61 struct character *ch = battle_current(bt)->ch;
62
63 /*
64 * Immediately invoke the enemy exec strategy and put the battle state
65 * to check.
66 */
67 character_exec(ch, bt);
68 }
69
70 void
71 battle_state_ai_draw(const struct battle *bt)
72 {
73 assert(battle_ok(bt));
74
75 battle_draw_component(bt, BATTLE_COMPONENT_ALL);
76 }
77
78 void
79 battle_state_ai(struct battle *bt)
80 {
81 assert(bt);
82
83 struct battle_state *self;
84
85 self = alloc_new0(sizeof (*self));
86 self->data = bt;
87 self->update = update;
88 self->draw = draw;
89 self->finish = finish;
90
91 battle_switch(bt, self);
92 }