diff libmlk-adventure/adventure/item/potion.c @ 290:9948e288925b

rpg: add support for items in battle
author David Demelier <markand@malikania.fr>
date Fri, 08 Jan 2021 12:56:10 +0100
parents 3991779aaba9
children d01e83210ca2
line wrap: on
line diff
--- a/libmlk-adventure/adventure/item/potion.c	Thu Jan 07 15:52:56 2021 +0100
+++ b/libmlk-adventure/adventure/item/potion.c	Fri Jan 08 12:56:10 2021 +0100
@@ -20,6 +20,7 @@
 
 #include <core/sound.h>
 
+#include <rpg/battle.h>
 #include <rpg/character.h>
 #include <rpg/item.h>
 
@@ -29,14 +30,32 @@
 #include "potion.h"
 
 static void
-exec(const struct item *i, struct character *ch)
+heal(struct character *ch)
+{
+	ch->hp = fmin(ch->hp + 50, ch->hpmax);
+	sound_play(&assets_sounds[ASSETS_SOUND_ITEM_POTION], -1, 0);
+}
+
+static void
+exec_menu(const struct item *item, struct character *ch)
 {
-	sound_play(&assets_sounds[ASSETS_SOUND_ITEM_POTION], -1, 0);
-	ch->hp = fmin(ch->hp + 50, ch->hpmax);
+	(void)item;
+
+	heal(ch);
+}
+
+static void
+exec_battle(const struct item *item, struct battle *bt, struct character *src, struct character *tgt)
+{
+	(void)item;
+
+	heal(tgt);
+	battle_indicator_hp(bt, tgt, 50);
 }
 
 const struct item item_potion = {
 	.name = N_("Potion"),
 	.description = N_("Recover 50 HP."),
-	.exec = exec
+	.exec_menu = exec_menu,
+	.exec_battle = exec_battle
 };