summaryrefslogtreecommitdiff
path: root/actions.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-08 06:02:31 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-08 06:02:31 +0100
commit9a98118c3d9a062b33134e8354620be43ecf3786 (patch)
treeee04aa9b65a401a720e387439b8180578ee8cbfe /actions.c
parentc1e13470835e18ac0077bf77ce8f77db07144bcf (diff)
improve code and fix numerous bugs
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'actions.c')
-rw-r--r--actions.c461
1 files changed, 193 insertions, 268 deletions
diff --git a/actions.c b/actions.c
index b70758a..09fd3af 100644
--- a/actions.c
+++ b/actions.c
@@ -9,18 +9,15 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te
{
int degats;
struct character_t *target;
- enum action_state_t ret = ACTION_CANCELED;
- unsigned int continuer = 1;
int clan=ENNEMI;
int selection = 0;
SDL_Event event;
- int delay=1;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
while(!enemy->chrs[selection].alive)
selection++;
- Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);
- while (continuer)
- {
+ update_selected_target(surfaces, positions, &enemy->chrs[selection]);
+
+ for (;;) {
SDL_Flip (surfaces->Pecran);
SDL_WaitEvent (&event);
switch (event.type)
@@ -30,50 +27,39 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te
{
case SDLK_ESCAPE:
case SDLK_a:
- delay=0;
- continuer = 0;
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- SDL_Flip (surfaces->Pecran);
- break;
- SELECTION_CIBLE()
+ update_selected_target(surfaces, positions, NULL);
+ SDL_Flip(surfaces->Pecran);
+ return ACTION_CANCELED;
+ SELECTION_CIBLE();
case SDLK_RETURN:
case SDLK_f:
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
+ if (clan == ENNEMI) {
+ target = &enemy->chrs[selection];
+ } else {
+ target = &ally->chrs[selection];
+ }
- 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);
- 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_Flip(surfaces->Pecran);
+ SDL_Delay(1000);
- ret = ACTION_PERFORMED;
- continuer=0;
- break;
+ SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats);
+
+ SDL_Flip(surfaces->Pecran);
+
+ return ACTION_PERFORMED;
default:
- break;
+ break;
}
break;
}
}
- if (delay)
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
-
- return ret;
}
int compute_damages(const struct character_t *src, const struct character_t *dest,
@@ -93,6 +79,9 @@ int compute_damages(const struct character_t *src, const struct character_t *des
avg = src->magic * 60 - dest->spirit * 50;
}
+ if (avg <= 0)
+ return 0;
+
if (element != ELEMENT_NONE) {
switch (dest->affinities[element]) {
case AFFINITY_SENSITIVE:
@@ -117,33 +106,6 @@ int compute_damages(const struct character_t *src, const struct character_t *des
return rand() % (max - min + 1) + min;
}
-int Fcalculerdegats(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection,int camp,int type)
-{
- unsigned int degats;
- int max;
- int taux;
-
- if(type==TYPE_ATTAQUE)
- {
- if(camp==ENNEMI)
- degats=ally->chrs[ally->chr_cur].strength*60-ennemis[selection].defense*50;
- else
- degats=ally->chrs[ally->chr_cur].strength*60-ally->chrs[selection].defense*50;
- }
- else
- {
- if(camp==ENNEMI)
- degats=ally->chrs[ally->chr_cur].magic*60-ennemis[selection].defensemagique*50;
- else
- degats=ally->chrs[ally->chr_cur].magic*60-ally->chrs[selection].spirit*50;
- }
- taux=degats/4;
- max=degats+taux;
- *min=degats-taux;
-
- return max;
-}
-
enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
SDL_Event event;
@@ -160,44 +122,44 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi
switch (event.type)
{
case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_a:
- case SDLK_ESCAPE:
- continuer=0;
- break;
- case SDLK_k:
- case SDLK_UP:
- if(selection!=0)
- selection--;
- else
- selection=nbactions-1;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL);
- break;
- case SDLK_j:
- case SDLK_DOWN:
- if (selection!=nbactions-1)
- selection++;
- else
- selection=0;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL);
- break;
- case SDLK_f:
- case SDLK_RETURN:
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
- ret = Fmagieelement(surfaces,positions, ally, enemy, selection);
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_a:
+ case SDLK_ESCAPE:
+ continuer=0;
+ break;
+ case SDLK_k:
+ case SDLK_UP:
+ if(selection!=0)
+ selection--;
+ else
+ selection=nbactions-1;
+ page=selection/3;
+ Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL);
+ break;
+ case SDLK_j:
+ case SDLK_DOWN:
+ if (selection!=nbactions-1)
+ selection++;
+ else
+ selection=0;
+ page=selection/3;
+ Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL);
+ break;
+ case SDLK_f:
+ case SDLK_RETURN:
+ SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
+ SDL_Flip(surfaces->Pecran);
+ ret = Fmagieelement(surfaces,positions, ally, enemy, selection);
- if (ret == ACTION_PERFORMED) {
- continuer = 0;
- }
+ if (ret == ACTION_PERFORMED) {
+ continuer = 0;
+ }
- break;
- default:
- break;
- }
+ break;
+ default:
+ break;
+ }
}
}
@@ -220,44 +182,44 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi
switch (event.type)
{
case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- continuer=0;
- break;
- case SDLK_UP:
- case SDLK_k:
- if (selection!=0)
- selection--;
- else
- selection=nbactions-1;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL);
- break;
- case SDLK_DOWN:
- case SDLK_j:
- if(selection!=nbactions-1)
- selection++;
- else
- selection=0;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL);
- break;
- case SDLK_f:
- case SDLK_RETURN:
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
- if(selection==SOIN)
- ret = Fmagiesoin(surfaces,positions, ally, enemy);
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ case SDLK_a:
+ continuer=0;
+ break;
+ case SDLK_UP:
+ case SDLK_k:
+ if (selection!=0)
+ selection--;
+ else
+ selection=nbactions-1;
+ page=selection/3;
+ Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL);
+ break;
+ case SDLK_DOWN:
+ case SDLK_j:
+ if(selection!=nbactions-1)
+ selection++;
+ else
+ selection=0;
+ page=selection/3;
+ Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL);
+ break;
+ case SDLK_f:
+ case SDLK_RETURN:
+ SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
+ SDL_Flip(surfaces->Pecran);
+ if(selection==SOIN)
+ ret = Fmagiesoin(surfaces,positions, ally, enemy);
- if (ret == ACTION_PERFORMED) {
- continuer = 0;
- }
- break;
- default:
- break;
- }
+ if (ret == ACTION_PERFORMED) {
+ continuer = 0;
+ }
+ break;
+ default:
+ break;
+ }
}
}
@@ -280,58 +242,58 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,
switch (event.type)
{
case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- case SDLK_a:
- continuer=0;
- break;
- case SDLK_UP:
- case SDLK_k:
- if(selection!=0)
- selection--;
- else
- selection=nbactions-1;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects);
- break;
- case SDLK_DOWN:
- case SDLK_j:
- if (selection!=nbactions-1)
- selection++;
- else
- selection=0;
- page=selection/3;
- Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects);
- break;
- case SDLK_RETURN:
- case SDLK_f:
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
- if(page==0)
+ switch (event.key.keysym.sym)
{
- if(selection==POTION)
- ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection);
- else if(selection==ETHER)
- ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection);
- else if(selection==POTIONPLUS)
- ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection);
+ case SDLK_ESCAPE:
+ case SDLK_a:
+ continuer=0;
+ break;
+ case SDLK_UP:
+ case SDLK_k:
+ if(selection!=0)
+ selection--;
+ else
+ selection=nbactions-1;
+ page=selection/3;
+ Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects);
+ break;
+ case SDLK_DOWN:
+ case SDLK_j:
+ if (selection!=nbactions-1)
+ selection++;
+ else
+ selection=0;
+ page=selection/3;
+ Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects);
+ break;
+ case SDLK_RETURN:
+ case SDLK_f:
+ SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
+ SDL_Flip(surfaces->Pecran);
+ if(page==0)
+ {
+ if(selection==POTION)
+ ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection);
+ else if(selection==ETHER)
+ ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection);
+ else if(selection==POTIONPLUS)
+ ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection);
- }
- else if(page==1)
- {
- if(selection==ETHERPLUS)
- ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection);
- }
+ }
+ else if(page==1)
+ {
+ if(selection==ETHERPLUS)
+ ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection);
+ }
- if (ret == ACTION_PERFORMED) {
- continuer = 0;
- }
+ if (ret == ACTION_PERFORMED) {
+ continuer = 0;
+ }
- break;
- default:
- break;
- }
+ break;
+ default:
+ break;
+ }
}
}
@@ -341,11 +303,8 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,
enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type)
{
struct character_t *target;
- enum action_state_t ret = ACTION_CANCELED;
- int continuer=1;
SDL_Event event;
int selection=0;
- int delay=1;
int soins=0;
int clan=ALLIE;
@@ -357,9 +316,10 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
while (!ally->chrs[selection].alive)
selection++;
- Fchangercurseurpersos (surfaces,positions,selection);
- while(continuer)
- {
+ update_selected_target(surfaces,positions, &ally->chrs[selection]);
+ SDL_Flip(surfaces->Pecran);
+
+ for (;;) {
SDL_WaitEvent(&event);
switch(event.type)
{
@@ -368,66 +328,47 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team
{
case SDLK_ESCAPE:
case SDLK_a:
- delay=0;
- continuer = 0;
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- SDL_Flip (surfaces->Pecran);
- break;
+ update_selected_target(surfaces, positions, NULL);
+ SDL_Flip(surfaces->Pecran);
+ return ACTION_CANCELED;
SELECTION_CIBLE();
case SDLK_RETURN:
case SDLK_f:
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
-
if (clan == ENNEMI) {
target = &enemy->chrs[selection];
} else {
target = &ally->chrs[selection];
}
- if (type == POTION)
+ update_selected_target(surfaces, positions, NULL);
+
+ if (type == POTION) {
soins = 1000;
- else if (type == POTIONPLUS)
+ objets->potions--;
+ } else if (type == POTIONPLUS) {
soins = 4000;
+ objets->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);
- continuer = 0;
- ret = ACTION_PERFORMED;
-
- if (type == POTION)
- objets->potions--;
- else if (type == POTIONPLUS)
- objets->potionsplus--;
- break;
+ return ACTION_PERFORMED;
default:
break;
}
break;
}
}
- if (delay)
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
-
- return ret;
}
enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type)
{
struct character_t *target;
- enum action_state_t ret = ACTION_CANCELED;
- int continuer=1;
SDL_Event event;
- int delay=1;
int selection=0;
int soins=0;
int clan=ALLIE;
@@ -440,9 +381,10 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
while (!ally->chrs[selection].alive)
selection++;
- Fchangercurseurpersos (surfaces,positions,selection);
- while(continuer)
- {
+ update_selected_target(surfaces,positions, &ally->chrs[selection]);
+ SDL_Flip(surfaces->Pecran);
+
+ for (;;) {
SDL_WaitEvent(&event);
switch(event.type)
{
@@ -451,54 +393,37 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_
{
case SDLK_ESCAPE:
case SDLK_a:
- delay=0;
- continuer = 0;
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- SDL_Flip (surfaces->Pecran);
- break;
- SELECTION_CIBLE()
+ update_selected_target(surfaces, positions, NULL);
+ SDL_Flip(surfaces->Pecran);
+ return ACTION_CANCELED;
+ SELECTION_CIBLE();
case SDLK_RETURN:
case SDLK_f:
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
-
- if (clan == ENNEMI) {
- target = &enemy->chrs[selection];
- } else {
- target = &ally->chrs[selection];
- }
-
- if (type == ETHER)
- soins = 10;
- else if (type == ETHERPLUS)
- soins = 40;
-
- cure_target_mp(surfaces, positions, target, soins);
-
- SDL_Flip (surfaces->Pecran);
-
- continuer=0;
- ret = ACTION_PERFORMED;
- if(type==ETHER)
- objets->ethers--;
- else if(type==ETHERPLUS)
- objets->ethersplus--;
- break;
+ if (clan == ENNEMI) {
+ target = &enemy->chrs[selection];
+ } else {
+ target = &ally->chrs[selection];
+ }
+
+ if (type == ETHER) {
+ soins = 10;
+ objets->ethers--;
+ } else if (type == ETHERPLUS) {
+ soins = 40;
+ objets->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;
}
break;
}
}
- if (delay)
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
-
- return ret;
}