comparison src/libmlk-rpg/rpg/battle-state-victory.c @ 320:8f9937403749

misc: improve loading of data
author David Demelier <markand@malikania.fr>
date Fri, 01 Oct 2021 20:30:00 +0200
parents libmlk-rpg/rpg/battle-state-victory.c@d01e83210ca2
children 460c78706989
comparison
equal deleted inserted replaced
319:b843eef4cc35 320:8f9937403749
1 /*
2 * battle-state-victory.c -- battle state (victory)
3 *
4 * Copyright (c) 2020-2021 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
21 #include <core/alloc.h>
22 #include <core/music.h>
23 #include <core/panic.h>
24 #include <core/window.h>
25
26 #include <rpg/message.h>
27
28 #include "battle.h"
29 #include "battle-state.h"
30 #include "rpg_p.h"
31
32 struct victory {
33 struct battle_state self;
34 struct message msg;
35 };
36
37 static void
38 handle(struct battle_state *st, struct battle *bt, const union event *ev)
39 {
40 (void)bt;
41
42 struct victory *vic = st->data;
43
44 message_handle(&vic->msg, ev);
45 }
46
47 static int
48 update(struct battle_state *st, struct battle *bt, unsigned int ticks)
49 {
50 (void)bt;
51
52 struct victory *vic = st->data;
53
54 if (message_update(&vic->msg, ticks))
55 battle_state_closing(bt);
56
57 return 0;
58 }
59
60 static void
61 draw(const struct battle_state *st, const struct battle *bt)
62 {
63 (void)bt;
64
65 const struct victory *vic = st->data;
66
67 message_draw(&vic->msg);
68 }
69
70 void
71 battle_state_victory(struct battle *bt)
72 {
73 assert(bt);
74
75 struct victory *vic;
76
77 if (!(vic = alloc_new0(sizeof (*vic))))
78 panic();
79
80 /* TODO: compute money, xp and drop. */
81 vic->self.data = vic;
82 vic->self.handle = handle;
83 vic->self.update = update;
84 vic->self.draw = draw;
85
86 vic->msg.text[0] = _("Victory!");
87 vic->msg.theme = bt->theme;
88 vic->msg.flags = MESSAGE_FLAGS_AUTOMATIC |
89 MESSAGE_FLAGS_FADEIN |
90 MESSAGE_FLAGS_FADEOUT;
91 vic->msg.timeout = MESSAGE_TIMEOUT_DEFAULT;
92 vic->msg.delay = MESSAGE_DELAY_DEFAULT;
93
94 message_start(&vic->msg);
95 message_query(&vic->msg, NULL, &vic->msg.h);
96
97 vic->msg.w = window.w * 0.6;
98 vic->msg.y = window.h * 0.1;
99 vic->msg.x = (window.w - vic->msg.w) / 2;
100
101 bt->status = BATTLE_STATUS_WON;
102 battle_switch(bt, &vic->self);
103
104 if (bt->music[1])
105 music_play(bt->music[1], MUSIC_NONE, 0);
106 }