From 1f9c71b49eeef9cd05b542515c06200b4a25f693 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 8 Jan 2015 15:04:26 +0100 Subject: use a generic way to navigate through entries entries are actually any action or subaction that can be performed. Attack, White Magic and so on are root actions. Fire, Ice X are subactions of Black Magic. Signed-off-by: Olivier Gayot --- actions.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'actions.c') diff --git a/actions.c b/actions.c index 096fba9..cb0d8ea 100644 --- a/actions.c +++ b/actions.c @@ -5,7 +5,7 @@ #include #include -enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) +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; @@ -13,6 +13,9 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te 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]); @@ -150,7 +153,7 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi case SDLK_RETURN: SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); - ret = Fmagieelement(surfaces,positions, ally, enemy, selection); + ret = Fmagieelement(surfaces,positions, ally, enemy, (enum element_t []) {selection}); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -211,7 +214,7 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); SDL_Flip(surfaces->Pecran); if(selection==SOIN) - ret = Fmagiesoin(surfaces,positions, ally, enemy); + ret = Fmagiesoin(surfaces,positions, ally, enemy, NULL); if (ret == ACTION_PERFORMED) { continuer = 0; @@ -273,17 +276,17 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, if(page==0) { if(selection==POTION) - ret = Fpotion(surfaces,positions, ally, enemy, selection); + ret = Fpotion(surfaces,positions, ally, enemy, (int []) {selection}); else if(selection==ETHER) - ret = Fether(surfaces,positions, ally, enemy, selection); + ret = Fether(surfaces,positions, ally, enemy, (int []) {selection}); else if(selection==POTIONPLUS) - ret = Fpotion(surfaces,positions, ally, enemy, selection); + ret = Fpotion(surfaces,positions, ally, enemy, (int []) { selection}); } else if(page==1) { if(selection==ETHERPLUS) - ret = Fether(surfaces,positions, ally, enemy, selection); + ret = Fether(surfaces,positions, ally, enemy, (int []) { selection}); } if (ret == ACTION_PERFORMED) { @@ -300,7 +303,7 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, return ret; } -enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, int type) +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; @@ -308,6 +311,8 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team 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) @@ -365,7 +370,7 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team } } -enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, int type) +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; @@ -373,6 +378,8 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_ 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) -- cgit v1.2.3