diff librpg/rpg/character.c @ 235:fb304a94a05c

rpg: prepare equipment
author David Demelier <markand@malikania.fr>
date Thu, 26 Nov 2020 18:00:45 +0100
parents 86b71e1f9dd5
children
line wrap: on
line diff
--- a/librpg/rpg/character.c	Thu Nov 26 13:33:31 2020 +0100
+++ b/librpg/rpg/character.c	Thu Nov 26 18:00:45 2020 +0100
@@ -21,17 +21,21 @@
 #include <core/sprite.h>
 
 #include "character.h"
+#include "equipment.h"
 
 bool
 character_ok(struct character *ch)
 {
-	return ch && ch->name && ch->type && ch->reset && sprite_ok(ch->sprites[CHARACTER_SPRITE_WALK]);
+	return ch && ch->name && ch->type && ch->reset && sprite_ok(ch->sprites[CHARACTER_SPRITE_NORMAL]);
 }
 
 const char *
 character_status_string(enum character_status status)
 {
-	/* We have to use a switch-case as it is a bitmask. */
+	/*
+	 * We expect the user to only specify one status as character_status
+	 * is a bitmask.
+	 */
 	switch (status) {
 	case CHARACTER_STATUS_POISON:
 		return "poison";
@@ -43,9 +47,14 @@
 void
 character_reset(struct character *ch)
 {
-	assert(ch);
+	assert(character_ok(ch));
 
 	ch->reset(ch);
+
+	/* For all equipments, apply its equip function. */
+	for (int i = 0; i < CHARACTER_EQUIPMENT_NUM; ++i)
+		if (ch->equipments[i])
+			equipment_equip(ch->equipments[i], ch);
 }
 
 void