summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions.c68
-rw-r--r--actions.h11
-rw-r--r--constantes.h2
-rw-r--r--entry.h5
-rw-r--r--ia.c10
-rw-r--r--jouer.c8
-rw-r--r--target.h16
7 files changed, 93 insertions, 27 deletions
diff --git a/actions.c b/actions.c
index 5559bd1..e356a83 100644
--- a/actions.c
+++ b/actions.c
@@ -4,6 +4,7 @@
#include "constantes.h"
+#include "target.h"
#include "character.h"
static int compute_damages(const struct character_t *src, const struct character_t *dest,
@@ -64,40 +65,71 @@ static int compute_cure(const struct character_t *src, const struct character_t
return rand() % (max - min + 1) + min;
}
-void attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, void *data)
+static
+void __attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest)
{
int damages;
- (void) data;
-
damages = compute_damages(src, dest, DAMAGES_PHYSICAL, ELEMENT_NONE);
damage_target_hp(surfaces, positions, dest, damages);
}
-void cast_element(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, void *data)
+void attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data)
+{
+ (void) data;
+
+ __attack(surfaces, positions, src, dest->chr);
+}
+
+void cast_element(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data)
{
int damages;
enum element_t elem = *((enum element_t *)data);
/* TODO remove the MP */
- damages = compute_damages(src, dest, DAMAGES_MAGICAL, elem);
- damage_target_hp(surfaces, positions, dest, damages);
+ if (dest->is_chr) {
+ damages = compute_damages(src, dest->chr, DAMAGES_MAGICAL, elem);
+ damage_target_hp(surfaces, positions, dest->chr, damages);
+ } else {
+ for (int i = 0; i < dest->team->chr_cnt; ++i) {
+ struct character_t *target = &dest->team->chrs[i];
+
+ if (!target->alive)
+ continue;
+
+ damages = compute_damages(src, target, DAMAGES_MAGICAL, elem);
+ damage_target_hp(surfaces, positions, target, damages / 3);
+ }
+ }
}
-void cast_cure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, void *data)
+void cast_cure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data)
{
int cure;
(void) data;
- cure = compute_cure(src, dest);
- cure_target_hp(surfaces, positions, dest, cure);
+ if (dest->is_chr) {
+ cure = compute_cure(src, dest->chr);
+ cure_target_hp(surfaces, positions, dest->chr, cure);
+ } else {
+ for (int i = 0; i < dest->team->chr_cnt; ++i) {
+ struct character_t *target = &dest->team->chrs[i];
+
+ if (!target->alive)
+ continue;
+
+ cure = compute_cure(src, target);
+ cure_target_hp(surfaces, positions, target, cure / 3);
+ }
+ }
}
-void use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, void *data)
+
+static
+void __use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, int type)
{
- int type = *((int *)data);
int cure;
switch (type) {
@@ -116,9 +148,14 @@ void use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t *sr
cure_target_hp(surfaces, positions, dest, cure);
}
-void use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, void *data)
+void use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data)
+{
+ __use_potion(surfaces, positions, src, dest->chr, *((int *)data));
+}
+
+static
+void __use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, int type)
{
- int type = *((int *)data);
int cure;
switch (type) {
@@ -136,3 +173,8 @@ void use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *src
cure_target_mp(surfaces, positions, dest, cure);
}
+
+void use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data)
+{
+ __use_ether(surfaces, positions, src, dest->chr, *((int *)data));
+}
diff --git a/actions.h b/actions.h
index 425b5a9..b7a4f09 100644
--- a/actions.h
+++ b/actions.h
@@ -3,11 +3,12 @@
#include "structures.h"
#include "players.h"
+#include "target.h"
-void attack(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data);
-void cast_element(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data);
-void cast_cure(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data);
-void use_potion(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data);
-void use_ether(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data);
+void attack(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data);
+void cast_element(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data);
+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);
#endif /* ACTIONS_H */
diff --git a/constantes.h b/constantes.h
index e68946b..dc647ba 100644
--- a/constantes.h
+++ b/constantes.h
@@ -73,7 +73,7 @@ enum action_state_t {
ACTION_COUNT,
};
-enum target_t {
+enum target_type_t {
TARGET_SINGLE_ALLY = 0x1,
TARGET_SINGLE_ENEMY = TARGET_SINGLE_ALLY << 0x1,
diff --git a/entry.h b/entry.h
index 7258569..db81e47 100644
--- a/entry.h
+++ b/entry.h
@@ -3,6 +3,7 @@
#include "structures.h"
#include "players.h"
+#include "target.h"
struct entry_t {
/* displayed name */
@@ -14,9 +15,9 @@ struct entry_t {
struct {
void *data;
- void (*f)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *data);
+ void (*f)(SURFACES *, POSITIONS *, struct character_t *, struct target_t *, void *data);
- enum target_t target;
+ enum target_type_t target;
} action;
};
};
diff --git a/ia.c b/ia.c
index 0844339..3b5d3f4 100644
--- a/ia.c
+++ b/ia.c
@@ -39,16 +39,18 @@ void ai_play_turn(struct action_params_t *params)
/* XXX complete brainless articial intelligence */
struct team_t *target_team;
- struct character_t *target;
+ struct target_t target;
+
+ target.is_chr = true;
target_team = (params->src->team == params->t1) ? params->t2 : params->t1;
- target = ai_find_random_target(target_team);
+ target.chr = ai_find_random_target(target_team);
- if (target == NULL) {
+ if (target.chr == NULL) {
/* do nothing, everyone is dead */
return;
}
- attack(params->surfaces, params->positions, params->src, target, NULL);
+ attack(params->surfaces, params->positions, params->src, &target, NULL);
}
diff --git a/jouer.c b/jouer.c
index 95ee0f4..4aac874 100644
--- a/jouer.c
+++ b/jouer.c
@@ -110,12 +110,13 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc
static
enum action_state_t select_target(struct action_params_t *params, void *data,
- void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *))
+ void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct target_t *, void *))
{
SURFACES *surfaces = params->surfaces;
POSITIONS *positions = params->positions;
/* select our own character because he exists no matter what */
struct team_t *target_team = params->src->team;
+ struct target_t target;
int selection = target_team->chr_cur;
int new_selection;
SDL_Event event;
@@ -172,9 +173,12 @@ enum action_state_t select_target(struct action_params_t *params, void *data,
break;
case SDLK_RETURN:
case SDLK_f:
+ target.is_chr = true;
+ target.chr = &target_team->chrs[selection];
+
update_selected_target(surfaces, positions, NULL);
- (*cb)(surfaces, positions, params->src, &target_team->chrs[selection], data);
+ (*cb)(surfaces, positions, params->src, &target, data);
return ACTION_PERFORMED;
default:
diff --git a/target.h b/target.h
new file mode 100644
index 0000000..941b1f6
--- /dev/null
+++ b/target.h
@@ -0,0 +1,16 @@
+#ifndef TARGET_H
+#define TARGET_H
+
+#include <stdbool.h>
+#include "players.h"
+
+struct target_t {
+ bool is_chr;
+
+ union {
+ struct team_t *team;
+ struct character_t *chr;
+ };
+};
+
+#endif /* TARGET_H */