summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions.c295
-rw-r--r--blits.c137
-rw-r--r--entry.h2
-rw-r--r--jouer.c124
-rw-r--r--magies.c139
-rw-r--r--priv_entries.h40
-rw-r--r--prototypes.h15
7 files changed, 201 insertions, 551 deletions
diff --git a/actions.c b/actions.c
index dcbfc10..bd1ce2e 100644
--- a/actions.c
+++ b/actions.c
@@ -5,6 +5,64 @@
#include <stdio.h>
#include <stdlib.h>
+static int compute_damages(const struct character_t *src, const struct character_t *dest,
+ enum damages_type_t type, enum element_t element)
+{
+ int avg;
+ int min;
+ int max;
+
+ /* we optimize if the target is invulnerable */
+ if (element != ELEMENT_NONE && dest->affinities[element] == AFFINITY_INVULNERABILITY)
+ return 0;
+
+ if (type == DAMAGES_PHYSICAL) {
+ avg = src->strength * 60 - dest->defense * 50;
+ } else if (type == DAMAGES_MAGICAL) {
+ avg = src->magic * 60 - dest->spirit * 50;
+ }
+
+ if (avg <= 0)
+ return 0;
+
+ if (element != ELEMENT_NONE) {
+ switch (dest->affinities[element]) {
+ case AFFINITY_SENSITIVE:
+ avg *= 2;
+ break;
+ case AFFINITY_RESISTANCE:
+ avg /= 2;
+ break;
+ case AFFINITY_ABSORPTION:
+ avg = -avg;
+ break;
+ case AFFINITY_NONE:
+ break;
+ default:
+ abort();
+ }
+ }
+
+ min = avg - avg / 4;
+ max = avg + avg / 4;
+
+ return rand() % (max - min + 1) + min;
+}
+
+static int compute_cure(const struct character_t *src, const struct character_t *dest)
+{
+ int avg, max, min;
+
+ /* TODO maybe we should use the dest to compute the cure ? */
+ (void) dest;
+
+ avg = src->magic * 20;
+ min = avg - avg / 4;
+ max = avg + avg / 4;
+
+ return rand() % (max - min + 1) + min;
+}
+
void attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, void *data)
{
int damages;
@@ -77,240 +135,3 @@ void use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *src
cure_target_mp(surfaces, positions, dest, cure);
}
-
-enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data)
-{
- int degats;
- struct character_t *target;
- int clan=ENNEMI;
- int selection = 0;
- SDL_Event event;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
-
- (void) data;
-
- while(!enemy->chrs[selection].alive)
- selection++;
-
- update_selected_target(surfaces, positions, &enemy->chrs[selection]);
-
- for (;;) {
- SDL_Flip (surfaces->Pecran);
- SDL_WaitEvent (&event);
- switch (event.type)
- {
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- update_selected_target(surfaces, positions, NULL);
- SDL_Flip(surfaces->Pecran);
- return ACTION_CANCELED;
- SELECTION_CIBLE();
- case SDLK_RETURN:
- case SDLK_f:
- if (clan == ENNEMI) {
- target = &enemy->chrs[selection];
- } else {
- target = &ally->chrs[selection];
- }
-
- degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_PHYSICAL, ELEMENT_NONE);
-
- update_selected_target(surfaces, positions, NULL);
-
- damage_target_hp(surfaces, positions, target, degats);
- SDL_Flip(surfaces->Pecran);
-
- SDL_Delay(1000);
-
- SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
-
- SDL_Flip(surfaces->Pecran);
-
- return ACTION_PERFORMED;
- default:
- break;
- }
- break;
-
- }
- }
-}
-
-int compute_damages(const struct character_t *src, const struct character_t *dest,
- enum damages_type_t type, enum element_t element)
-{
- int avg;
- int min;
- int max;
-
- /* we optimize if the target is invulnerable */
- if (element != ELEMENT_NONE && dest->affinities[element] == AFFINITY_INVULNERABILITY)
- return 0;
-
- if (type == DAMAGES_PHYSICAL) {
- avg = src->strength * 60 - dest->defense * 50;
- } else if (type == DAMAGES_MAGICAL) {
- avg = src->magic * 60 - dest->spirit * 50;
- }
-
- if (avg <= 0)
- return 0;
-
- if (element != ELEMENT_NONE) {
- switch (dest->affinities[element]) {
- case AFFINITY_SENSITIVE:
- avg *= 2;
- break;
- case AFFINITY_RESISTANCE:
- avg /= 2;
- break;
- case AFFINITY_ABSORPTION:
- avg = -avg;
- break;
- case AFFINITY_NONE:
- break;
- default:
- abort();
- }
- }
-
- min = avg - avg / 4;
- max = avg + avg / 4;
-
- return rand() % (max - min + 1) + min;
-}
-
-enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data)
-{
- struct character_t *target;
- SDL_Event event;
- int selection=0;
- int soins=0;
- int clan=ALLIE;
-
- int type = *((int *)data);
-
- if (type == POTION && ally->objects.potions <= 0)
- return ACTION_ERROR;
- else if(type == POTIONPLUS && ally->objects.potionsplus <= 0)
- return ACTION_ERROR;
-
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
- while (!ally->chrs[selection].alive)
- selection++;
- update_selected_target(surfaces,positions, &ally->chrs[selection]);
- SDL_Flip(surfaces->Pecran);
-
- for (;;) {
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- update_selected_target(surfaces, positions, NULL);
- SDL_Flip(surfaces->Pecran);
- return ACTION_CANCELED;
- SELECTION_CIBLE();
- case SDLK_RETURN:
- case SDLK_f:
- if (clan == ENNEMI) {
- target = &enemy->chrs[selection];
- } else {
- target = &ally->chrs[selection];
- }
-
- update_selected_target(surfaces, positions, NULL);
-
- if (type == POTION) {
- soins = 1000;
- ally->objects.potions--;
- } else if (type == POTIONPLUS) {
- soins = 4000;
- ally->objects.potionsplus--;
- }
-
- cure_target_hp(surfaces, positions, target, soins);
-
- SDL_Flip(surfaces->Pecran);
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
-
- return ACTION_PERFORMED;
- default:
- break;
- }
- break;
- }
- }
-}
-
-enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data)
-{
- struct character_t *target;
- SDL_Event event;
- int selection=0;
- int soins=0;
- int clan=ALLIE;
-
- int type = *((int *)data);
-
- if (type == ETHER && ally->objects.ethers <= 0)
- return ACTION_ERROR;
- else if (type == ETHERPLUS && ally->objects.ethersplus <= 0)
- return ACTION_ERROR;
-
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
- while (!ally->chrs[selection].alive)
- selection++;
- update_selected_target(surfaces,positions, &ally->chrs[selection]);
- SDL_Flip(surfaces->Pecran);
-
- for (;;) {
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- update_selected_target(surfaces, positions, NULL);
- SDL_Flip(surfaces->Pecran);
- return ACTION_CANCELED;
- SELECTION_CIBLE();
- case SDLK_RETURN:
- case SDLK_f:
- if (clan == ENNEMI) {
- target = &enemy->chrs[selection];
- } else {
- target = &ally->chrs[selection];
- }
-
- if (type == ETHER) {
- soins = 10;
- ally->objects.ethers--;
- } else if (type == ETHERPLUS) {
- soins = 40;
- ally->objects.ethersplus--;
- }
-
- cure_target_mp(surfaces, positions, target, soins);
-
- SDL_Flip(surfaces->Pecran);
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
-
- return ACTION_PERFORMED;
- default:
- break;
- }
- break;
- }
- }
-}
diff --git a/blits.c b/blits.c
index 2eb49d4..0bb6b61 100644
--- a/blits.c
+++ b/blits.c
@@ -115,43 +115,6 @@ void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct cha
}
}
-void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions, struct character_t *chr)
-{
- SDL_Color couleur={120,0,0,0};
- TTF_Font *police=NULL;
- const char *string;
-
- if (surfaces->Pnomcible!=NULL)
- {
- SDL_FreeSurface (surfaces->Pnomcible);
- surfaces->Pnomcible=NULL;
- }
- police=TTF_OpenFont("times.ttf",20);
-
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
-
- SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible);
-
- positions->Vpositioncurseurallies.x = chr->pos.x + 20 + chr->surf->w;
- positions->Vpositioncurseurallies.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pcurseurallies->h / 2;
-
- SDL_BlitSurface(surfaces->Pcurseurallies, NULL, surfaces->Pecran, &positions->Vpositioncurseurallies);
-
- string = (chr->name) ? chr->name : "NO NAME";
-
- surfaces->Pnomcible = TTF_RenderText_Blended (police, string, couleur);
-
- positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surfaces->Pnomcible->w / 2;
- positions->Vpositionnomcible.y = positions->Vpositioncadrecible.y + 10;
- blit_character_affinities(surfaces, positions, chr);
-
- Fblitterpvcible (surfaces,positions, chr);
- Fblitterpmcible (surfaces,positions, chr);
- SDL_BlitSurface (surfaces->Pnomcible,NULL,surfaces->Pecran,&positions->Vpositionnomcible);
- SDL_Flip (surfaces->Pecran);
- TTF_CloseFont(police);
-}
-
void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected)
{
SDL_Color color = {0, 0, 0, 0};
@@ -192,106 +155,6 @@ void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct
SDL_Flip(surfaces->Pecran);
}
-void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type)
-{
- int i;
- TTF_Font *police=NULL;
- SDL_Color couleur={0,0,0,0};
- char chaine[3][50];
- police=TTF_OpenFont ("TIMESBI.TTF",20);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
- SDL_BlitSurface (surfaces->Pcadreactions,NULL,surfaces->Pecran,&positions->Vpositioncadreactions);
- for(i=0;i<nbactions;i++)
- {
- if (selection==i)
- SDL_BlitSurface (surfaces->Pactionselectionnee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[selection-page*3]);
- }
- for(i=0;i<3;i++)
- {
- if(surfaces->Pnomactions[i]!=NULL)
- {
- SDL_FreeSurface(surfaces->Pnomactions[i]);
- surfaces->Pnomactions[i]=NULL;
- }
- }
- if(type==ACTIONS)
- {
- if(page==0)
- {
- ECRIRE("ATTAQUE",0);
- ECRIRE("MAGIE BLANCHE",1);
- ECRIRE("MAGIE NOIRE",2);
- }
- else if(page==1)
- {
- ECRIRE("TECHNIQUES",0);
- ECRIRE("OBJETS",1);
- }
- }
- else if(type==MAGIE_BLANCHE)
- {
- if (page==0)
- {
- ECRIRE("SOIN",0);
- }
- }
- else if(type==MAGIE_NOIRE)
- {
- if(page==0)
- {
- ECRIRE("FEU",0);
- ECRIRE("GLACE",1);
- ECRIRE("EAU",2);
- }
- else if(page==1)
- {
- ECRIRE("TONNERRE",0);
- ECRIRE("CHOC",1);
- }
- }
- else if(type==OBJETS)
- {
- if(page==0)
- {
- ECRIRE("POTION",0);
- ECRIRE("ETHER",1);
- ECRIRE("POTION +",2);
-#if 0
- sprintf(chaine[0],"%d", ally->objects.potions);
- surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur);
- sprintf(chaine[1],"%d", ally->objects.ethers);
- surfaces->Pquantite[1]=TTF_RenderText_Blended(police,chaine[1],couleur);
- sprintf(chaine[2],"%d", ally->objects.potionsplus);
- surfaces->Pquantite[2]=TTF_RenderText_Blended(police,chaine[2],couleur);
- SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]);
- SDL_BlitSurface(surfaces->Pquantite[1],NULL,surfaces->Pecran,&positions->Vpositionquantite[1]);
- SDL_BlitSurface(surfaces->Pquantite[2],NULL,surfaces->Pecran,&positions->Vpositionquantite[2]);
-#endif
- }
- else if(page==1)
- {
- ECRIRE("ETHER +",0);
-#if 0
- sprintf(chaine[0],"%d", ally->objects.ethersplus);
- surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur);
- SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]);
-#endif
- }
- }
- if (page==nbactions/3)
- {
- if(3*(page+1)-nbactions==1)
- SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]);
- if(3*(page+1)-nbactions==2)
- {
- SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]);
- SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[1]);
- }
- }
- SDL_Flip(surfaces->Pecran);
- TTF_CloseFont (police);
-}
-
static void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color)
{
TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30);
diff --git a/entry.h b/entry.h
index 00b58e9..066cf4a 100644
--- a/entry.h
+++ b/entry.h
@@ -14,7 +14,7 @@ struct entry_t {
struct {
void *data;
- enum action_state_t (*f)(SURFACES *, POSITIONS *, struct team_t *, struct team_t *, void *data);
+ void (*f)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *data);
};
};
};
diff --git a/jouer.c b/jouer.c
index 70795a8..7175191 100644
--- a/jouer.c
+++ b/jouer.c
@@ -21,17 +21,17 @@ static inline void unhighlight_prev_character(struct team_t *team)
chr->surf = chr->def_surf;
}
-static int find_next_ally(const struct team_t *ally)
+static int find_next_team_member(const struct team_t *team, int current)
{
- for (int i = ally->chr_cur + 1; i < ally->chr_cnt; ++i) {
- const struct character_t *chr = &ally->chrs[i];
+ for (int i = current + 1; i < team->chr_cnt; ++i) {
+ const struct character_t *chr = &team->chrs[i];
if (chr->alive)
return i;
}
- for (int i = 0; i <= ally->chr_cur; ++i) {
- const struct character_t *chr = &ally->chrs[i];
+ for (int i = 0; i <= current; ++i) {
+ const struct character_t *chr = &team->chrs[i];
if (chr->alive)
return i;
@@ -40,6 +40,35 @@ static int find_next_ally(const struct team_t *ally)
return -1;
}
+static int find_prev_team_member(const struct team_t *team, int current)
+{
+ for (int i = current - 1; i >= 0; --i) {
+ const struct character_t *chr = &team->chrs[i];
+
+ if (chr->alive)
+ return i;
+ }
+
+ for (int i = team->chr_cnt - 1; i >= current; ++i) {
+ const struct character_t *chr = &team->chrs[i];
+
+ if (chr->alive)
+ return i;
+ }
+
+ return -1;
+}
+
+static int get_alive_character(const struct team_t *team)
+{
+ for (int i = 0; i < team->chr_cnt; ++i) {
+ if (team->chrs[i].alive)
+ return i;
+ }
+
+ return -1;
+}
+
/* function called after an action has been performed */
static void update_current_character(struct team_t *ally, bool *ally_turn)
{
@@ -48,7 +77,7 @@ static void update_current_character(struct team_t *ally, bool *ally_turn)
unhighlight_prev_character(ally);
- next = find_next_ally(ally);
+ next = find_next_team_member(ally, ally->chr_cur);
/* if there is no next ally or they are dead */
if (next <= ally->chr_cur) {
@@ -63,6 +92,87 @@ static void update_current_character(struct team_t *ally, bool *ally_turn)
}
}
+static
+enum action_state_t select_target(SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2,
+ void *data, void (*cb)(SURFACES *, POSITIONS *, struct character_t *, struct character_t *, void *))
+{
+ SDL_Event event;
+ /* select our own character because he exists no matter what */
+ struct team_t *target_team = t1;
+ int selection = target_team->chr_cur;
+ int new_selection;
+
+ update_selected_target(surfaces, positions, &t1->chrs[selection]);
+ SDL_Flip(surfaces->Pecran);
+
+ for (;;) {
+ SDL_WaitEvent(&event);
+
+ if (event.type != SDL_KEYDOWN)
+ continue;
+
+ switch (event.key.keysym.sym) {
+ case SDLK_ESCAPE:
+ case SDLK_a:
+ update_selected_target(surfaces, positions, NULL);
+ SDL_Flip(surfaces->Pecran);
+ return ACTION_CANCELED;
+ case SDLK_UP:
+ case SDLK_k:
+ new_selection = find_prev_team_member(target_team, selection);
+
+ if (new_selection == selection)
+ continue;
+
+ selection = new_selection;
+ update_selected_target(surfaces, positions, &target_team->chrs[selection]);
+ SDL_Flip(surfaces->Pecran);
+ break;
+ case SDLK_DOWN:
+ case SDLK_j:
+ new_selection = find_next_team_member(target_team, selection);
+
+ if (new_selection == selection)
+ continue;
+
+ selection = new_selection;
+ update_selected_target(surfaces, positions, &target_team->chrs[selection]);
+ SDL_Flip(surfaces->Pecran);
+ break;
+ case SDLK_LEFT:
+ case SDLK_h:
+ case SDLK_RIGHT:
+ case SDLK_l:
+ new_selection = get_alive_character((target_team == t1) ? t2 : t1);
+ if (new_selection < 0)
+ continue;
+
+ selection = new_selection;
+ target_team = (target_team == t1) ? t2 : t1;
+ update_selected_target(surfaces, positions, &target_team->chrs[selection]);
+ SDL_Flip(surfaces->Pecran);
+ break;
+ case SDLK_RETURN:
+ case SDLK_f:
+ update_selected_target(surfaces, positions, NULL);
+
+ (*cb)(surfaces, positions, &t1->chrs[t1->chr_cur], &target_team->chrs[selection], data);
+
+ SDL_Flip(surfaces->Pecran);
+
+ SDL_Delay(1000);
+
+ SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
+
+ SDL_Flip(surfaces->Pecran);
+
+ return ACTION_PERFORMED;
+ default:
+ break;
+ }
+ }
+}
+
enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, struct action_params_t *params)
{
SDL_Event event;
@@ -95,7 +205,7 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st
case SDLK_RETURN:
target = &entries[selection];
if (!target->children_cnt) {
- enum action_state_t state = target->f(params->surfaces, params->positions, params->t1, params->t2, target->data);
+ enum action_state_t state = select_target(params->surfaces, params->positions, params->t1, params->t2, target->data, target->f);
if (state == ACTION_PERFORMED)
return ACTION_PERFORMED;
diff --git a/magies.c b/magies.c
deleted file mode 100644
index 94183e7..0000000
--- a/magies.c
+++ /dev/null
@@ -1,139 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <SDL/SDL.h>
-#include "structures.h"
-#include "constantes.h"
-#include "prototypes.h"
-
-enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data)
-{
- struct character_t *target;
- int degats;
- int selection = 0;
- int clan=ENNEMI;
- SDL_Event event;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
-
- enum element_t element = *((enum element_t *)data);
-
- while (!enemy->chrs[selection].alive)
- selection++;
- update_selected_target(surfaces,positions, &enemy->chrs[selection]);
- SDL_Flip(surfaces->Pecran);
-
- for (;;) {
- SDL_WaitEvent (&event);
- switch (event.type)
- {
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- update_selected_target(surfaces, positions, NULL);
- SDL_Flip(surfaces->Pecran);
- return ACTION_CANCELED;
- SELECTION_CIBLE()
- case SDLK_RETURN:
- case SDLK_f:
- if (clan == ENNEMI) {
- target = &enemy->chrs[selection];
- } else {
- target = &ally->chrs[selection];
- }
-
- degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_MAGICAL, element);
-
- update_selected_target(surfaces, positions, NULL);
-
- damage_target_hp(surfaces, positions, target, degats);
- SDL_Flip(surfaces->Pecran);
-
- SDL_Delay(1000);
-
- SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
-
- SDL_Flip(surfaces->Pecran);
-
- return ACTION_PERFORMED;
- default:
- break;
- }
- break;
- }
- }
-}
-
-enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data)
-{
- struct character_t *target;
- SDL_Event event;
- int soins;
- int clan=ALLIE;
- int selection=0;
-
- (void) data;
-
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
- while(!ally->chrs[selection].alive)
- selection++;
- update_selected_target(surfaces,positions, &ally->chrs[selection]);
- SDL_Flip(surfaces->Pecran);
-
- for (;;) {
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- update_selected_target(surfaces, positions, NULL);
- SDL_Flip (surfaces->Pecran);
- return ACTION_CANCELED;
- SELECTION_CIBLE()
- case SDLK_RETURN:
- case SDLK_f:
- if (clan == ENNEMI) {
- target = &enemy->chrs[selection];
- } else {
- target = &ally->chrs[selection];
- }
-
- soins = compute_cure(&ally->chrs[ally->chr_cur], target);
-
- update_selected_target(surfaces, positions, NULL);
-
- cure_target_hp(surfaces, positions, target, soins);
- SDL_Flip(surfaces->Pecran);
-
- SDL_Delay(1000);
-
- SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
-
-
- SDL_Flip (surfaces->Pecran);
-
- return ACTION_PERFORMED;
- default:
- break;
- }
- break;
- }
- }
-}
-
-int compute_cure(const struct character_t *src, const struct character_t *dest)
-{
- int avg, max, min;
-
- /* TODO maybe we should use the dest to compute the cure ? */
- (void) dest;
-
- avg = src->magic * 20;
- min = avg - avg / 4;
- max = avg + avg / 4;
-
- return rand() % (max - min + 1) + min;
-}
diff --git a/priv_entries.h b/priv_entries.h
index c2fa5c6..a0fe66e 100644
--- a/priv_entries.h
+++ b/priv_entries.h
@@ -10,12 +10,12 @@ struct entry_t white_magic_entries[] = {
{
.name = "Cure",
.children_cnt = 0,
- .f = Fattaquer,
+ .f = cast_cure,
.data = NULL,
}, {
.name = "Cure +",
.children_cnt = 0,
- .f = Fattaquer,
+ .f = cast_cure,
.data = NULL,
},
};
@@ -24,67 +24,67 @@ struct entry_t black_magic_entries[] = {
{
.name = "Fire",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_FIRE },
}, {
.name = "Fire +",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_FIRE },
}, {
.name = "Fire x",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_FIRE },
}, {
.name = "Ice -",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_ICE },
}, {
.name = "Ice +",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_ICE },
}, {
.name = "Ice x",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_ICE },
}, {
.name = "Thunder",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_THUNDER },
}, {
.name = "Thunder +",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_THUNDER },
}, {
.name = "Thunder x",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_THUNDER },
}, {
.name = "Water",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_WATER },
}, {
.name = "Water + ",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_WATER },
}, {
.name = "Water x",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_WATER },
}, {
.name = "Choc",
.children_cnt = 0,
- .f = Fmagieelement,
+ .f = cast_element,
.data = (enum element_t []) { ELEMENT_NONE },
},
};
@@ -93,22 +93,22 @@ struct entry_t object_entries[] = {
{
.name = "Potion",
.children_cnt = 0,
- .f = Fpotion,
+ .f = use_potion,
.data = (int []) { POTION },
}, {
.name = "Potion +",
.children_cnt = 0,
- .f = Fpotion,
+ .f = use_potion,
.data = (int []) { POTIONPLUS },
}, {
.name = "Ether",
.children_cnt = 0,
- .f = Fether,
+ .f = use_ether,
.data = (int []) { ETHER },
}, {
.name = "Ether + ",
.children_cnt = 0,
- .f = Fether,
+ .f = use_ether,
.data = (int []) { ETHERPLUS },
},
};
@@ -117,7 +117,7 @@ struct entry_t action_entries_g[] = {
{
.name = "Attack",
.children_cnt = 0,
- .f = Fattaquer,
+ .f = attack,
.data = NULL,
}, {
.name = "White Magic",
diff --git a/prototypes.h b/prototypes.h
index 2b69a76..ffa1c94 100644
--- a/prototypes.h
+++ b/prototypes.h
@@ -20,14 +20,11 @@ void Fdechargerimages (SURFACES *surfaces);
void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces);
/* actions */
-enum action_state_t Fattaquer (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data);
-enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data);
-enum action_state_t Fmagiesoin (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data);
-enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data);
-enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, void *data);
-
-int compute_damages(const struct character_t *src, const struct character_t *target, enum damages_type_t, enum element_t);
-int compute_cure(const struct character_t *src, const struct character_t *target);
+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 damage_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages);
void cure_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure);
@@ -36,10 +33,8 @@ void damage_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *targe
void cure_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure);
void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *);
-void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection);
void blit_character_affinities(SURFACES *, POSITIONS *, const struct character_t *);
void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected);
-void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type);
void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *);
void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *);
void Fremplirobjets(OBJET *objets);