From 30842cc79c0a3e3566e9da61f2499fa1342c6d52 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 10 Jan 2015 00:14:19 +0100 Subject: added "Defend" action physical and magical damages are divided by 2 when a character is on defensive state. Signed-off-by: Olivier Gayot --- actions.c | 14 ++++++++++++++ actions.h | 1 + jouer.c | 2 ++ menuchoixpersos.c | 2 ++ players.h | 2 ++ priv_entries.h | 8 ++++++++ 6 files changed, 29 insertions(+) diff --git a/actions.c b/actions.c index e356a83..ac5cc03 100644 --- a/actions.c +++ b/actions.c @@ -45,6 +45,10 @@ static int compute_damages(const struct character_t *src, const struct character } } + if (dest->defensive) { + avg /= 2; + } + min = avg - avg / 4; max = avg + avg / 4; @@ -81,6 +85,16 @@ void attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, s __attack(surfaces, positions, src, dest->chr); } +void defend(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +{ + (void) data; + (void) dest; + (void) surfaces; + (void) positions; + + src->defensive = true; +} + void cast_element(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) { int damages; diff --git a/actions.h b/actions.h index b7a4f09..7510f38 100644 --- a/actions.h +++ b/actions.h @@ -10,5 +10,6 @@ void cast_element(SURFACES *, POSITIONS *, struct character_t *src, struct targe void cast_cure(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); void use_potion(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); void use_ether(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); +void defend(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); #endif /* ACTIONS_H */ diff --git a/jouer.c b/jouer.c index 6d230f9..a5f20ad 100644 --- a/jouer.c +++ b/jouer.c @@ -290,6 +290,8 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st static enum action_state_t character_play_turn(struct action_params_t *params) { + params->src->defensive = false; + if (!params->src->team->cpu) { return dig_entry(action_entries_g, countof(action_entries_g), params); } diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 3eb77a9..f83fb16 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -21,6 +21,8 @@ static void init_team_players(struct team_t *team, bool left, chr->class_ = classes[i]; chr->alive = true; + chr->defensive = false; + switch (chr->class_) { case CLASS_PALADIN: chr->def_surf = surfaces->Ppaladin; diff --git a/players.h b/players.h index 062bde5..5d535bf 100644 --- a/players.h +++ b/players.h @@ -36,6 +36,8 @@ struct character_t { bool alive; + bool defensive; + int hp; int max_hp; int mp; diff --git a/priv_entries.h b/priv_entries.h index f553a2b..f7697a6 100644 --- a/priv_entries.h +++ b/priv_entries.h @@ -199,6 +199,14 @@ struct entry_t action_entries_g[] = { .name = "Use", .children = object_entries, .children_cnt = countof(object_entries), + }, { + .name = "Defend", + .children_cnt = 0, + .action = { + .f = defend, + .data = NULL, + .target = TARGET_SELF, + }, }, }; -- cgit v1.2.3