From 65364d2e2f40807fdd03ade25917f728adc0ef77 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 11 Jan 2015 02:02:07 +0100 Subject: coding rules: stop at 78 cols Signed-off-by: Olivier Gayot --- actions.c | 60 ++++++++++-------- actions.h | 24 +++++--- blits.c | 93 ++++++++++++++++++---------- blits.h | 12 ++-- character.c | 52 +++++++++------- character.h | 9 ++- constantes.h | 24 ++++---- entry.h | 7 ++- ia.c | 2 +- jouer.c | 80 ++++++++++++++---------- map.c | 23 ++++--- menuchoixpersos.c | 42 ++++++++----- menuprincipal.c | 3 +- players.h | 6 +- priv_entries.h | 28 ++++----- prototypes.h | 6 +- rpg.c | 181 +++++++++++++++++++++++------------------------------- target.h | 2 +- 18 files changed, 354 insertions(+), 300 deletions(-) diff --git a/actions.c b/actions.c index 5ab45b4..f5a06f1 100644 --- a/actions.c +++ b/actions.c @@ -7,7 +7,7 @@ #include "target.h" #include "character.h" -static int compute_damages(const struct character_t *src, const struct character_t *dest, +static int compute_damages(const struct chr_t *src, const struct chr_t *dest, enum damages_type_t type, enum element_t element) { int avg; @@ -15,7 +15,7 @@ static int compute_damages(const struct character_t *src, const struct character int max; /* we optimize if the target is invulnerable */ - if (element != ELEMENT_NONE && dest->affinities[element] == AFFINITY_INVULNERABILITY) + if (element != ELEM_NONE && dest->affinities[element] == AFFIN_INVULN) return 0; if (type == DAMAGES_PHYSICAL) { @@ -27,18 +27,18 @@ static int compute_damages(const struct character_t *src, const struct character if (avg <= 0) return 0; - if (element != ELEMENT_NONE) { + if (element != ELEM_NONE) { switch (dest->affinities[element]) { - case AFFINITY_SENSITIVE: + case AFFIN_SENSITIVE: avg *= 2; break; - case AFFINITY_RESISTANCE: + case AFFIN_RESISTANCE: avg /= 2; break; - case AFFINITY_ABSORPTION: + case AFFIN_ABSORPTION: avg = -avg; break; - case AFFINITY_NONE: + case AFFIN_NONE: break; default: abort(); @@ -55,7 +55,7 @@ static int compute_damages(const struct character_t *src, const struct character return rand() % (max - min + 1) + min; } -static int compute_cure(const struct character_t *src, const struct character_t *dest) +static int compute_cure(const struct chr_t *src, const struct chr_t *dest) { int avg, max, min; @@ -69,23 +69,25 @@ static int compute_cure(const struct character_t *src, const struct character_t return rand() % (max - min + 1) + min; } -static -void __attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest) +static void __attack(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct chr_t *dest) { int damages; - damages = compute_damages(src, dest, DAMAGES_PHYSICAL, ELEMENT_NONE); + damages = compute_damages(src, dest, DAMAGES_PHYSICAL, ELEM_NONE); damage_target_hp(surfaces, positions, dest, damages); } -void attack(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void attack(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { (void) data; __attack(surfaces, positions, src, dest->chr); } -void defend(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void defend(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { (void) data; (void) dest; @@ -95,7 +97,8 @@ void defend(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, s src->defensive = true; } -void cast_element(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void cast_element(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { int damages; enum element_t elem = *((enum element_t *)data); @@ -107,7 +110,7 @@ void cast_element(SURFACES *surfaces, POSITIONS *positions, struct character_t * 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]; + struct chr_t *target = &dest->team->chrs[i]; if (!target->alive) continue; @@ -118,7 +121,8 @@ void cast_element(SURFACES *surfaces, POSITIONS *positions, struct character_t * } } -void cast_cure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void cast_cure(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { int cure; @@ -129,7 +133,7 @@ void cast_cure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src 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]; + struct chr_t *target = &dest->team->chrs[i]; if (!target->alive) continue; @@ -141,8 +145,8 @@ void cast_cure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src } -static -void __use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct character_t *dest, int type) +static void __use_potion(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct chr_t *dest, int type) { int cure; @@ -162,13 +166,14 @@ void __use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t * cure_target_hp(surfaces, positions, dest, cure); } -void use_potion(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void use_potion(SURFACES *surfaces, POSITIONS *positions, + struct chr_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) +static void __use_ether(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct chr_t *dest, int type) { int cure; @@ -188,14 +193,16 @@ void __use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *s cure_target_mp(surfaces, positions, dest, cure); } -void use_ether(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void use_ether(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { __use_ether(surfaces, positions, src, dest->chr, *((int *)data)); } -void cyanure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void cyanure(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { - struct character_t *target = dest->chr; + struct chr_t *target = dest->chr; (void) data; (void) src; @@ -204,7 +211,8 @@ void cyanure(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, target->poisoned = true; } -void esuna(SURFACES *surfaces, POSITIONS *positions, struct character_t *src, struct target_t *dest, void *data) +void esuna(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *src, struct target_t *dest, void *data) { (void) surfaces; (void) positions; diff --git a/actions.h b/actions.h index e51edc7..89e7f7e 100644 --- a/actions.h +++ b/actions.h @@ -5,20 +5,28 @@ #include "players.h" #include "target.h" -void attack(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); +void attack(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); /* black magic */ -void cast_element(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); -void cyanure(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); +void cast_element(SURFACES *, POSITIONS *, struct chr_t *src, + struct target_t *dst, void *data); +void cyanure(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); /* white magic */ -void cast_cure(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); -void esuna(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); +void cast_cure(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); +void esuna(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); /* use */ -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 use_potion(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); +void use_ether(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); -void defend(SURFACES *, POSITIONS *, struct character_t *src, struct target_t *dst, void *data); +void defend(SURFACES *, POSITIONS *, struct chr_t *src, struct target_t *, + void *data); #endif /* ACTIONS_H */ diff --git a/blits.c b/blits.c index 40e20f4..51ce1e7 100644 --- a/blits.c +++ b/blits.c @@ -11,7 +11,7 @@ #include "rpg.h" -static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr) +static void blit_chr_infos(SURFACES *surfaces, struct chr_t *chr) { SDL_Color fg={132,215,107,0},bg={100,0,0,0}; char string[256]; @@ -41,7 +41,7 @@ static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr) SDL_FreeSurface(surf_mp); } -void blit_character(SURFACES *surfaces, struct character_t *chr) +void blit_character(SURFACES *surfaces, struct chr_t *chr) { SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos); @@ -63,28 +63,37 @@ void blit_team(SURFACES *surfaces, struct team_t *team) } } -static void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr) +static void +blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, + const struct chr_t *chr) { static const enum affinity_t affinities[] = { - AFFINITY_SENSITIVE, - AFFINITY_RESISTANCE, - AFFINITY_INVULNERABILITY, - AFFINITY_ABSORPTION, + AFFIN_SENSITIVE, + AFFIN_RESISTANCE, + AFFIN_INVULN, + AFFIN_ABSORPTION, }; for (int i = 0; i < countof(affinities); ++i) { - for (enum element_t elmt = 0; elmt < ELEMENT_COUNT; ++elmt) { + for (enum element_t elmt = 0; elmt < ELEM_COUNT; ++elmt) { + SDL_Surface *surf; + SDL_Rect *rect; + if (chr->affinities[elmt] == affinities[i]) { - SDL_BlitSurface(surfaces->Pactive, NULL, surfaces->screen, &positions->activedesactive[i * ELEMENT_COUNT + elmt]); + surf = surfaces->Pactive; } else { - SDL_BlitSurface(surfaces->Pdesactive, NULL, surfaces->screen, &positions->activedesactive[i * ELEMENT_COUNT + elmt]); + surf = surfaces->Pdesactive; } + + rect = &positions->activedesactive[i * ELEM_COUNT + elmt]; + + SDL_BlitSurface(surf, NULL, surfaces->screen, rect); } } } -static -void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) +static void Fblitterpvcible(SURFACES *surfaces, POSITIONS *positions, + const struct chr_t *chr) { SDL_Color couleur = {132,215,107,0}; char chaine[50]; @@ -97,8 +106,8 @@ void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct char SDL_FreeSurface(surf); } -static -void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) +static void Fblitterpmcible(SURFACES *surfaces, POSITIONS *positions, + const struct chr_t *chr) { SDL_Color couleur = {132,215,107,0}; char chaine[50]; @@ -111,18 +120,21 @@ void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct char SDL_FreeSurface(surf); } -static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) +static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, + struct target_t *target) { SDL_Color color = {0x8a, 0x00, 0x00, 0x00}; SDL_Surface *surf_name; - SDL_Rect pos_name;; + SDL_Rect pos_name; + const char *name; /* display the information frame */ - SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->screen, &positions->cadrecible); + SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->screen, + &positions->cadrecible); if (target->is_chr) { /* display the name of the character */ - surf_name = TTF_RenderText_Blended(rpg_g.font, target->chr->name, color); + name = target->chr->name; /* display the affinities of the character */ blit_character_affinities(surfaces, positions, target->chr); @@ -131,10 +143,13 @@ static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struc Fblitterpvcible (surfaces,positions, target->chr); Fblitterpmcible (surfaces,positions, target->chr); } else { - surf_name = TTF_RenderText_Blended(rpg_g.font, target->team->name, color); + name = target->team->name; } - pos_name.x = positions->cadrecible.x + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; + surf_name = TTF_RenderText_Blended(rpg_g.font, name, color); + + pos_name.x = positions->cadrecible.x + + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; pos_name.y = positions->cadrecible.y + 10; SDL_BlitSurface(surf_name, NULL, surfaces->Pecran, &pos_name); @@ -142,14 +157,17 @@ static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struc SDL_FreeSurface(surf_name); } -void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) +void update_selected_target(SURFACES *surfaces, POSITIONS *positions, + struct target_t *target) { /* clear cursor */ - SDL_BlitSurface(surfaces->Pfondjeu, &positions->last_cursor, surfaces->Pecran, &positions->last_cursor); + SDL_BlitSurface(surfaces->background, &positions->last_cursor, + surfaces->screen, &positions->last_cursor); if (target == NULL) { /* clear the target informations frame */ - SDL_BlitSurface(surfaces->background, &positions->cadrecible, surfaces->screen, &positions->cadrecible); + SDL_BlitSurface(surfaces->background, &positions->cadrecible, + surfaces->screen, &positions->cadrecible); } else { /* display the new cursor */ if (target->is_chr) { @@ -159,11 +177,12 @@ void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct tar positions->last_cursor.w = target->chr->curs->w; positions->last_cursor.h = target->chr->curs->h; - SDL_BlitSurface(target->chr->curs, NULL, surfaces->Pecran, &target->chr->pos_curs); + SDL_BlitSurface(target->chr->curs, NULL, surfaces->screen, + &target->chr->pos_curs); } else { for (int i = 0; i < target->team->chr_cnt; ++i) { - struct character_t *chr = &target->team->chrs[i]; + struct chr_t *chr = &target->team->chrs[i]; positions->last_cursor.x = chr->pos_curs.x; positions->last_cursor.y = chr->pos_curs.y; @@ -171,7 +190,8 @@ void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct tar positions->last_cursor.w = chr->curs->w; positions->last_cursor.h = chr->curs->h; - SDL_BlitSurface(chr->curs, NULL, surfaces->Pecran, &chr->pos_curs); + SDL_BlitSurface(chr->curs, NULL, surfaces->screen, + &chr->pos_curs); } } @@ -179,19 +199,22 @@ void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct tar } } -void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected) +void update_list_entries(SURFACES *surfaces, POSITIONS *positions, + const struct entry_t *entries, int cnt, int selected) { SDL_Color color = {0, 0, 0, 0}; SDL_Surface *surf; int off; if (selected == -1) { - SDL_BlitSurface(surfaces->Pfondjeu, &positions->cadreactions, surfaces->Pecran, &positions->cadreactions); + SDL_BlitSurface(surfaces->background, &positions->cadreactions, + surfaces->screen, &positions->cadreactions); SDL_Flip(surfaces->Pecran); return; } - SDL_BlitSurface(surfaces->Pcadreactions, NULL, surfaces->Pecran, &positions->cadreactions); + SDL_BlitSurface(surfaces->Pcadreactions, NULL, surfaces->screen, + &positions->cadreactions); off = selected / 3 * 3; /* display at most three actions */ @@ -200,13 +223,15 @@ void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct char buffer[256]; if (off + i >= cnt) { - SDL_BlitSurface(surfaces->Pactiondesactivee, NULL, surfaces->Pecran, &positions->actionselectionnee[i]); + SDL_BlitSurface(surfaces->Pactiondesactivee, NULL, + surfaces->screen, &positions->actionselectionnee[i]); continue; } /* if the current entry is the selected one */ if (selected == off + i) { - SDL_BlitSurface(surfaces->Pactionselectionnee, NULL, surfaces->Pecran, &positions->actionselectionnee[i]); + SDL_BlitSurface(surfaces->Pactionselectionnee, NULL, + surfaces->screen, &positions->actionselectionnee[i]); } if (entries[off + i].children_cnt) { @@ -218,7 +243,8 @@ void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct surf = TTF_RenderText_Blended(rpg_g.font, string, color); - SDL_BlitSurface(surf, NULL, surfaces->Pecran, &positions->nomactions[i]); + SDL_BlitSurface(surf, NULL, surfaces->screen, + &positions->nomactions[i]); SDL_FreeSurface(surf); } @@ -226,7 +252,8 @@ void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct SDL_Flip(surfaces->Pecran); } -void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color) +void display_incr(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *target, unsigned int incr, SDL_Color color) { char string[256]; SDL_Surface *surf; diff --git a/blits.h b/blits.h index 371231e..82d03fe 100644 --- a/blits.h +++ b/blits.h @@ -5,12 +5,14 @@ #include "players.h" #include "entry.h" -void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color); +void display_incr(SURFACES *, POSITIONS *, struct chr_t *target, + unsigned int incr, SDL_Color color); -void blit_team(SURFACES *surfaces, struct team_t *team); +void blit_team(SURFACES *, struct team_t *team); -void blit_character(SURFACES *surfaces, struct character_t *chr); -void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct target_t *target); -void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected); +void blit_character(SURFACES *, struct chr_t *chr); +void update_selected_target(SURFACES *, POSITIONS *, struct target_t *target); +void update_list_entries(SURFACES *, POSITIONS *, + const struct entry_t *entries, int cnt, int selected); #endif /* BLITS_H */ diff --git a/character.c b/character.c index 4a3a260..2b4be4e 100644 --- a/character.c +++ b/character.c @@ -2,57 +2,65 @@ #include "players.h" #include "blits.h" -static void incr_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) +static void +incr_hp(SURFACES *surfaces, POSITIONS *positions, struct chr_t *chr, int incr) { SDL_Color color; - target->hp += incr; + chr->hp += incr; - if (target->hp <= 0) { - target->hp = 0; - target->alive = false; - } else if (target->hp > target->max_hp) { - target->hp = target->max_hp; + if (chr->hp <= 0) { + chr->hp = 0; + chr->alive = false; + } else if (chr->hp > chr->max_hp) { + chr->hp = chr->max_hp; } - color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; + if (incr < 0) { + color = (SDL_Color){0xe0, 0x00, 0x00, 0x00}; + } else { + color = (SDL_Color){0x00, 0xe0, 0x00, 0x00}; + } - display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); + display_incr(surfaces, positions, chr, (incr >= 0) ? incr : -incr, color); } -static void incr_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) +static void +incr_mp(SURFACES *surfaces, POSITIONS *positions, struct chr_t *chr, int incr) { SDL_Color color; - target->hp += incr; + chr->hp += incr; - if (target->mp <= 0) { - target->mp = 0; - } else if (target->mp > target->max_mp) { - target->mp = target->max_mp; + if (chr->mp <= 0) { + chr->mp = 0; + } else if (chr->mp > chr->max_mp) { + chr->mp = chr->max_mp; } - color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; - - display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); + display_incr(surfaces, positions, chr, (incr >= 0) ? incr : -incr, color); } -void damage_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) +void damage_target_hp(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *target, int damages) { incr_hp(surfaces, positions, target, -damages); } -void cure_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) +void cure_target_hp(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *target, int cure) { incr_hp(surfaces, positions, target, cure); } -void damage_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) +void damage_target_mp(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *target, int damages) { incr_mp(surfaces, positions, target, -damages); } -void cure_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) +void cure_target_mp(SURFACES *surfaces, POSITIONS *positions, + struct chr_t *target, int cure) { incr_mp(surfaces, positions, target, cure); } diff --git a/character.h b/character.h index 3fba9c7..04b43f1 100644 --- a/character.h +++ b/character.h @@ -3,10 +3,9 @@ #include "players.h" -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); - -void damage_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages); -void cure_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure); +void damage_target_hp(SURFACES *, POSITIONS *, struct chr_t *, int damages); +void cure_target_hp(SURFACES *, POSITIONS *, struct chr_t *, int cure); +void damage_target_mp(SURFACES *, POSITIONS *, struct chr_t *, int damages); +void cure_target_mp(SURFACES *, POSITIONS *, struct chr_t *target, int cure); #endif /* CHARACTER_H */ diff --git a/constantes.h b/constantes.h index eb530f9..b6238b5 100644 --- a/constantes.h +++ b/constantes.h @@ -29,24 +29,24 @@ enum character_class_t { #define MORT 0 enum element_t { - ELEMENT_FIRE, - ELEMENT_ICE, - ELEMENT_WATER, - ELEMENT_THUNDER, + ELEM_FIRE, + ELEM_ICE, + ELEM_WATER, + ELEM_THUNDER, - ELEMENT_COUNT, + ELEM_COUNT, - ELEMENT_NONE = ELEMENT_COUNT, + ELEM_NONE = ELEM_COUNT, }; enum affinity_t { - AFFINITY_ABSORPTION, - AFFINITY_INVULNERABILITY, - AFFINITY_RESISTANCE, - AFFINITY_NONE, - AFFINITY_SENSITIVE, + AFFIN_ABSORPTION, + AFFIN_INVULN, + AFFIN_RESISTANCE, + AFFIN_NONE, + AFFIN_SENSITIVE, - AFFINITY_COUNT, + AFFIN_COUNT, }; #define POTION 0 diff --git a/entry.h b/entry.h index daa1e5d..aa66d95 100644 --- a/entry.h +++ b/entry.h @@ -5,9 +5,12 @@ #include "players.h" #include "target.h" +typedef void (*action_f)(SURFACES *, POSITIONS *, struct chr_t *src, + struct target_t *, void *data); + struct action_t { void *data; - void (*f)(SURFACES *, POSITIONS *, struct character_t *, struct target_t *, void *data); + action_f f; enum target_type_t target; }; @@ -31,7 +34,7 @@ struct action_params_t { struct team_t *t1; struct team_t *t2; - struct character_t *src; + struct chr_t *src; }; #endif /* ENTRY_H */ diff --git a/ia.c b/ia.c index 3b5d3f4..22bd863 100644 --- a/ia.c +++ b/ia.c @@ -8,7 +8,7 @@ #include "actions.h" -static struct character_t *ai_find_random_target(const struct team_t *team) +static struct chr_t *ai_find_random_target(const struct team_t *team) { int alive = 0; int target_idx; diff --git a/jouer.c b/jouer.c index 22d123c..2d4a30f 100644 --- a/jouer.c +++ b/jouer.c @@ -11,29 +11,29 @@ static inline void highlight_current_character(struct team_t *team) { - struct character_t *chr = &team->chrs[team->chr_cur]; + struct chr_t *chr = &team->chrs[team->chr_cur]; chr->surf = chr->red_surf; } static inline void unhighlight_prev_character(struct team_t *team) { - struct character_t *chr = &team->chrs[team->chr_cur]; + struct chr_t *chr = &team->chrs[team->chr_cur]; chr->surf = chr->def_surf; } -static struct character_t *find_next_team_member(const struct character_t *current) +static struct chr_t *find_next_team_member(const struct chr_t *current) { for (int i = current->idx + 1; i < current->team->chr_cnt; ++i) { - struct character_t *chr = ¤t->team->chrs[i]; + struct chr_t *chr = ¤t->team->chrs[i]; if (chr->alive) return chr; } for (int i = 0; i <= current->idx; ++i) { - struct character_t *chr = ¤t->team->chrs[i]; + struct chr_t *chr = ¤t->team->chrs[i]; if (chr->alive) return chr; @@ -42,17 +42,17 @@ static struct character_t *find_next_team_member(const struct character_t *curre return NULL; } -static struct character_t *find_prev_team_member(const struct character_t *current) +static struct chr_t *find_prev_team_member(const struct chr_t *current) { for (int i = current->idx - 1; i >= 0; --i) { - struct character_t *chr = ¤t->team->chrs[i]; + struct chr_t *chr = ¤t->team->chrs[i]; if (chr->alive) return chr; } for (int i = current->team->chr_cnt - 1; i >= current->idx; ++i) { - struct character_t *chr = ¤t->team->chrs[i]; + struct chr_t *chr = ¤t->team->chrs[i]; if (chr->alive) return chr; @@ -61,7 +61,7 @@ static struct character_t *find_prev_team_member(const struct character_t *curre return NULL; } -static struct character_t *get_first_alive_character(const struct team_t *team) +static struct chr_t *get_first_alive_character(const struct team_t *team) { for (int i = 0; i < team->chr_cnt; ++i) { if (team->chrs[i].alive) @@ -72,10 +72,11 @@ static struct character_t *get_first_alive_character(const struct team_t *team) } /* function called after an action has been performed */ -static void update_current_character(struct team_t *t1, struct team_t *t2, struct team_t **playing) +static void update_current_character(struct team_t *t1, struct team_t *t2, + struct team_t **playing) { struct team_t *current; - struct character_t *next; + struct chr_t *next; unhighlight_prev_character(*playing); @@ -119,8 +120,8 @@ static void update_current_character(struct team_t *t1, struct team_t *t2, struc } /* TODO the code of this function should be split in different functions */ -static -struct target_t select_default_target(const struct action_params_t *params, + static struct target_t +select_default_target(const struct action_params_t *params, enum target_type_t type) { struct team_t *enemy_team; @@ -159,14 +160,14 @@ struct target_t select_default_target(const struct action_params_t *params, abort(); } -static -enum action_state_t select_target(struct action_params_t *params, const struct action_t *action) +static enum action_state_t +select_target(struct action_params_t *params, const struct action_t *action) { SURFACES *surfaces = params->surfaces; POSITIONS *positions = params->positions; /* select our own character because he exists no matter what */ struct target_t target = select_default_target(params, action->target); - struct character_t *new_selection; + struct chr_t *new_selection; struct team_t *team; SDL_Event event; @@ -288,7 +289,8 @@ enum action_state_t select_target(struct action_params_t *params, const struct a case SDLK_f: update_selected_target(surfaces, positions, NULL); - (*action->f)(surfaces, positions, params->src, &target, action->data); + (*action->f)(surfaces, positions, params->src, &target, + action->data); return ACTION_PERFORMED; default: @@ -297,14 +299,15 @@ enum action_state_t select_target(struct action_params_t *params, const struct a } } -static -enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, struct action_params_t *params) +static enum action_state_t dig_entry(const struct entry_t *entries, + int cnt_entries, struct action_params_t *params) { SDL_Event event; const struct entry_t *target; int selection = 0; - update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection); + update_list_entries(params->surfaces, params->positions, entries, + cnt_entries, selection); while (SDL_PollEvent(&event)); for (;;) { @@ -320,12 +323,14 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st case SDLK_k: case SDLK_UP: selection = (selection > 0) ? selection - 1 : cnt_entries - 1; - update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection); + update_list_entries(params->surfaces, params->positions, + entries, cnt_entries, selection); break; case SDLK_j: case SDLK_DOWN: selection = (selection < cnt_entries - 1) ? selection + 1 : 0; - update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection); + update_list_entries(params->surfaces, params->positions, + entries, cnt_entries, selection); break; case SDLK_f: case SDLK_RETURN: @@ -333,25 +338,31 @@ enum action_state_t dig_entry(const struct entry_t *entries, int cnt_entries, st if (!target->children_cnt) { enum action_state_t state; - update_list_entries(params->surfaces, params->positions, entries, cnt_entries, -1); + update_list_entries(params->surfaces, params->positions, + entries, cnt_entries, -1); state = select_target(params, &target->action); if (state == ACTION_PERFORMED) return ACTION_PERFORMED; - } else { - if (dig_entry(target->children, target->children_cnt, params) == ACTION_PERFORMED) + } else { + if (dig_entry(target->children, target->children_cnt, + params) == ACTION_PERFORMED) + { return ACTION_PERFORMED; + } } - update_list_entries(params->surfaces, params->positions, entries, cnt_entries, selection); + update_list_entries(params->surfaces, params->positions, + entries, cnt_entries, selection); default: break; } } } -static enum action_state_t character_play_turn(struct action_params_t *params) +static enum action_state_t +character_play_turn(struct action_params_t *params) { params->src->defensive = false; @@ -366,10 +377,12 @@ static enum action_state_t character_play_turn(struct action_params_t *params) static void hook_post_action(struct action_params_t *params) { - struct character_t *chr = params->src; + struct chr_t *chr = params->src; if (chr->alive && chr->poisoned) { - damage_target_hp(params->surfaces, params->positions, chr, chr->max_hp / 4); + int damages = chr->max_hp / 4; + + damage_target_hp(params->surfaces, params->positions, chr, damages); SDL_Flip(params->surfaces->screen); @@ -377,7 +390,8 @@ static void hook_post_action(struct action_params_t *params) } } -int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct team_t *t2) +int Fjouer(SURFACES *surfaces, POSITIONS *positions, + struct team_t *t1, struct team_t *t2) { struct team_t *playing_team; unsigned int continuer=1; @@ -419,7 +433,8 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct SDL_Delay(1000); - SDL_BlitSurface(surfaces->background, &positions->degats, surfaces->screen, &positions->degats); + SDL_BlitSurface(surfaces->background, &positions->degats, + surfaces->screen, &positions->degats); SDL_Flip(surfaces->Pecran); @@ -433,7 +448,7 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct break; } - // on vérifie à présent si on a gagné ou si on a perdu ! + /* TODO rewrite */ gagne=1; perdu=1; for (i = 0; i < t2->chr_cnt; i++) { @@ -445,7 +460,6 @@ int Fjouer (SURFACES *surfaces, POSITIONS *positions, struct team_t *t1, struct perdu=0; } - // la y'a des trucs a mettre pour si on gagne ou on perd parce que sa fait assez pitié :p if(perdu) { SDL_Delay(2000); diff --git a/map.c b/map.c index 15aa3f7..84ddefe 100644 --- a/map.c +++ b/map.c @@ -6,7 +6,8 @@ #include "structures.h" #include "prototypes.h" -void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *t1, struct team_t *t2) +void Fmap (SURFACES*surfaces, POSITIONS* positions, + struct team_t *t1, struct team_t *t2) { #if 0 int map[15][11]; @@ -120,17 +121,21 @@ void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]) switch (map[i][j]) { case SOL: - SDL_BlitSurface(surfaces->Pmap_sol, NULL, surfaces->screen, &positions->map_item[i][j]); - break; + SDL_BlitSurface(surfaces->Pmap_sol, NULL, + surfaces->screen, &positions->map_item[i][j]); + break; case MUR: - SDL_BlitSurface(surfaces->Pmap_mur, NULL, surfaces->screen, &positions->map_item[i][j]); - break; + SDL_BlitSurface(surfaces->Pmap_mur, NULL, + surfaces->screen, &positions->map_item[i][j]); + break; case COFFRE: - SDL_BlitSurface(surfaces->Pmap_coffre, NULL, surfaces->screen, &positions->map_item[i][j]); - break; + SDL_BlitSurface(surfaces->Pmap_coffre, NULL, + surfaces->screen, &positions->map_item[i][j]); + break; case GUS: - SDL_BlitSurface(surfaces->Pmap_perso, NULL, surfaces->screen, &positions->map_item[i][j]); - break; + SDL_BlitSurface(surfaces->Pmap_perso, NULL, + surfaces->screen, &positions->map_item[i][j]); + break; } } } diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 9c02389..eb452c9 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -14,7 +14,7 @@ static void init_team_players(struct team_t *team, bool left, const enum character_class_t *classes, SURFACES *surfaces) { for (int i = 0; i < team->chr_cnt; i++) { - struct character_t *chr = &team->chrs[i]; + struct chr_t *chr = &team->chrs[i]; chr->name = "Player"; chr->team = team; @@ -59,10 +59,11 @@ static void init_team_players(struct team_t *team, bool left, chr->spirit = base_stats_g[chr->class_].spirit; for (int j = 0; j < countof(chr->affinities); ++j) { - chr->affinities[j] = rand() % AFFINITY_COUNT; + chr->affinities[j] = rand() % AFFIN_COUNT; } - chr->pos.y = (rpg_g.screen->h / ((team->chr_cnt + 1) * 2)) * (2 * (i + 1)) - chr->surf->h / 2; + chr->pos.y = (rpg_g.screen->h / ((team->chr_cnt + 1) * 2)) * + (2 * (i + 1)) - chr->surf->h / 2; if (left) { chr->curs = surfaces->Pcurseurallies; @@ -87,7 +88,7 @@ static void init_team(struct team_t *team, int chr_cnt) team->chr_cnt = chr_cnt; team->chr_cur = rand() % team->chr_cnt; - team->chrs = malloc(sizeof(struct character_t) * team->chr_cnt); + team->chrs = malloc(sizeof(struct chr_t) * team->chr_cnt); } static @@ -134,8 +135,8 @@ static void generate_enemy_types(const struct team_t *ally_team, } } -static -struct team_t *new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team) +static struct team_t +*new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team) { struct team_t *team = malloc(sizeof(struct team_t)); enum character_class_t *classes; @@ -156,7 +157,7 @@ struct team_t *new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team return team; } -static void Fchangersurlignage2(int Vchoix, SURFACES *surfaces, +static void update_menu(int Vchoix, SURFACES *surfaces, SDL_Surface *text, POSITIONS *positions) { SDL_Surface *surf; @@ -174,9 +175,12 @@ static void Fchangersurlignage2(int Vchoix, SURFACES *surfaces, /* this surface fills the whole screen */ SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); - SDL_BlitSurface(surfaces->Ppretre, NULL, surfaces->screen, &positions->menupretre); - SDL_BlitSurface(surfaces->Ppaladin, NULL, surfaces->screen, &positions->menupaladin); - SDL_BlitSurface(surfaces->Pvoleur, NULL, surfaces->screen, &positions->menuvoleur); + SDL_BlitSurface(surfaces->Ppretre, NULL, surfaces->screen, + &positions->menupretre); + SDL_BlitSurface(surfaces->Ppaladin, NULL, surfaces->screen, + &positions->menupaladin); + SDL_BlitSurface(surfaces->Pvoleur, NULL, surfaces->screen, + &positions->menuvoleur); SDL_BlitSurface(text, NULL, surfaces->screen, &positions->textemenu); @@ -221,16 +225,22 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); - /* display the string associated with the current character number (aka Please choose ...) */ + /* + * display the string associated with the current character number + * (aka Please choose ...) + */ surf = TTF_RenderText_Blended(rpg_g.font, strings[Vnbperso], vert); positions->textemenu.x = surfaces->screen->w / 2 - surf->w / 2; SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->textemenu); - SDL_BlitSurface(surfaces->Ppretre, NULL, surfaces->screen, &positions->menupretre); - SDL_BlitSurface(surfaces->Ppaladin, NULL, surfaces->screen, &positions->menupaladin); - SDL_BlitSurface(surfaces->Pvoleur, NULL, surfaces->screen, &positions->menuvoleur); + SDL_BlitSurface(surfaces->Ppretre, NULL, surfaces->screen, + &positions->menupretre); + SDL_BlitSurface(surfaces->Ppaladin, NULL, surfaces->screen, + &positions->menupaladin); + SDL_BlitSurface(surfaces->Pvoleur, NULL, surfaces->screen, + &positions->menuvoleur); SDL_Flip (surfaces->Pecran); continuer = true; @@ -249,7 +259,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } else { Vchoix = CLASS_THIEF; } - Fchangersurlignage2(Vchoix, surfaces, surf, positions); + update_menu(Vchoix, surfaces, surf, positions); break; case SDLK_RIGHT: @@ -259,7 +269,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } else { Vchoix = CLASS_PALADIN; } - Fchangersurlignage2(Vchoix, surfaces, surf, positions); + update_menu(Vchoix, surfaces, surf, positions); break; case SDLK_RETURN: case SDLK_f: diff --git a/menuprincipal.c b/menuprincipal.c index 76dff2f..a3c4f7c 100644 --- a/menuprincipal.c +++ b/menuprincipal.c @@ -69,7 +69,8 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) Vmode = 0; if (continuer) { - SDL_BlitSurface(surfaces->Pmenujouer, NULL, surfaces->screen, NULL); + SDL_BlitSurface(surfaces->Pmenujouer, NULL, + surfaces->screen, NULL); SDL_Flip (surfaces->Pecran); } break; diff --git a/players.h b/players.h index 0da996d..d22e1fe 100644 --- a/players.h +++ b/players.h @@ -7,7 +7,7 @@ #include "constantes.h" #include "structures.h" -struct character_t { +struct chr_t { struct team_t *team; int idx; @@ -49,7 +49,7 @@ struct character_t { int spirit; /* one for each element */ - enum affinity_t affinities[ELEMENT_COUNT]; + enum affinity_t affinities[ELEM_COUNT]; }; struct team_t { @@ -59,7 +59,7 @@ struct team_t { char *name; - struct character_t *chrs; + struct chr_t *chrs; struct objects_t objects; }; diff --git a/priv_entries.h b/priv_entries.h index db76406..b26f968 100644 --- a/priv_entries.h +++ b/priv_entries.h @@ -40,7 +40,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_FIRE }, + .data = (enum element_t []) { ELEM_FIRE }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -48,7 +48,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_FIRE }, + .data = (enum element_t []) { ELEM_FIRE }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -56,7 +56,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_FIRE }, + .data = (enum element_t []) { ELEM_FIRE }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -64,7 +64,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_ICE }, + .data = (enum element_t []) { ELEM_ICE }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -72,7 +72,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_ICE }, + .data = (enum element_t []) { ELEM_ICE }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -80,7 +80,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_ICE }, + .data = (enum element_t []) { ELEM_ICE }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -88,7 +88,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_THUNDER }, + .data = (enum element_t []) { ELEM_THUNDER }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -96,7 +96,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_THUNDER }, + .data = (enum element_t []) { ELEM_THUNDER }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -104,7 +104,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_THUNDER }, + .data = (enum element_t []) { ELEM_THUNDER }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -112,7 +112,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_WATER }, + .data = (enum element_t []) { ELEM_WATER }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -120,7 +120,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_WATER }, + .data = (enum element_t []) { ELEM_WATER }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -128,7 +128,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_WATER }, + .data = (enum element_t []) { ELEM_WATER }, .target = TARGET_SINGLE | TARGET_TEAM, }, }, { @@ -136,7 +136,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_NONE }, + .data = (enum element_t []) { ELEM_NONE }, .target = TARGET_SINGLE, }, }, { @@ -144,7 +144,7 @@ struct entry_t black_magic_entries[] = { .children_cnt = 0, .action = { .f = cast_element, - .data = (enum element_t []) { ELEMENT_NONE }, + .data = (enum element_t []) { ELEM_NONE }, .target = TARGET_TEAM, }, }, { diff --git a/prototypes.h b/prototypes.h index 0b34b26..1feb053 100644 --- a/prototypes.h +++ b/prototypes.h @@ -8,12 +8,10 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions); int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions); void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions); -int Fjouer(SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy); +int Fjouer(SURFACES *, POSITIONS *, struct team_t *, struct team_t *); -Uint32 obtenirPixel(SDL_Surface *surface, int x, int y); -void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel); void Fgetmap (int map[][11]); -void Fmap (SURFACES*surfaces, POSITIONS* positions, struct team_t *ally, struct team_t *enemy); +void Fmap (SURFACES *, POSITIONS *, struct team_t *, struct team_t *); void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions); void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]); void Fdechargersurfaces_map(SURFACES*surfaces); diff --git a/rpg.c b/rpg.c index b725995..aee39ba 100644 --- a/rpg.c +++ b/rpg.c @@ -12,7 +12,68 @@ struct rpg_t rpg_g; -static void colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint32 incr) +static Uint32 get_pixel(SDL_Surface *surface, int x, int y) +{ + int Bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * Bpp; + + switch (Bpp) + { + case 1: + return *p; + + case 2: + return *(Uint16 *)p; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + return p[0] << 16 | p[1] << 8 | p[2]; + } else { + return p[0] | p[1] << 8 | p[2] << 16; + } + case 4: + return *(Uint32 *)p; + + default: + return 0; + } +} + +static void set_pixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int Bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * Bpp; + + switch (Bpp) + { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + } +} + +static void +colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint32 incr) { int buffer = 0; Uint8 r, g, b; @@ -24,7 +85,7 @@ static void colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint for (int y = 0; y < surf->h; ++y) { for (int x = 0; x < surf->w; ++x) { - Uint32 pixel = obtenirPixel(surf, x, y); + Uint32 pixel = get_pixel(surf, x, y); SDL_GetRGB(pixel, fmt, &r, &g, &b); @@ -47,7 +108,7 @@ static void colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint b = buffer; pixel = SDL_MapRGB(fmt, r, g, b); - definirPixel(surf, x, y, pixel); + set_pixel(surf, x, y, pixel); } } @@ -57,7 +118,7 @@ static void colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint static void colorize_every_red_surface(SURFACES *surfaces) { - const SDL_PixelFormat *fmt = surfaces->Pecran->format; + const SDL_PixelFormat *fmt = surfaces->screen->format; Uint32 red = SDL_MapRGB(fmt, 30, 0, 0); colorize_surface(surfaces->red_paladin, fmt, red); @@ -107,7 +168,8 @@ static int rpg_load_images(SURFACES *surfaces) static int rpg_initialize_sprites(void) { #define set_color_key(surf_, r_, g_, b_) \ - SDL_SetColorKey((surf_), SDL_SRCCOLORKEY, SDL_MapRGB(rpg_g.surfaces.screen->format, (r_), (g_), (b_))) + SDL_SetColorKey((surf_), SDL_SRCCOLORKEY, \ + SDL_MapRGB(rpg_g.surfaces.screen->format, (r_), (g_), (b_))) #define load_sprite(surf_) \ tmp = SDL_DisplayFormat((surf_)); \ @@ -157,7 +219,8 @@ static int rpg_initialize_sprites(void) load_sprite(rpg_g.surfaces.background); rpg_g.surfaces.Pfondjeu = rpg_g.surfaces.background; - rpg_g.surfaces.red_warrior_gobelin = SDL_DisplayFormat(rpg_g.surfaces.Pgobelin); + rpg_g.surfaces.red_warrior_gobelin = + SDL_DisplayFormat(rpg_g.surfaces.Pgobelin); if (rpg_g.surfaces.red_warrior_gobelin == NULL) return -1; @@ -176,7 +239,8 @@ static int rpg_initialize_sprites(void) return 0; } -static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surfaces) +static void +Finitialiserpositions(POSITIONS *positions, const SURFACES *surfaces) { int y = 0, z = 0; @@ -219,7 +283,9 @@ static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surface } } - /* TODO this is pretty uggly .. and we can have multiple cursors as well */ + /* + * TODO this is pretty uggly .. and we can have multiple cursors as well + */ positions->last_cursor = (SDL_Rect){0, 0, 0, 0}; } @@ -251,7 +317,8 @@ static int rpg_init(int width, int height) return -1; } - rpg_g.screen = SDL_SetVideoMode(width, height, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); + rpg_g.screen = SDL_SetVideoMode(width, height, 0, + SDL_HWSURFACE | SDL_DOUBLEBUF); if (rpg_g.screen == NULL) { fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError()); @@ -343,99 +410,3 @@ int main (int argc, char *argv[]) return 0; } - - -/* ********************************************************************* */ -/*obtenirPixel : permet de récupérer la couleur d'un pixel -Paramètres d'entrée/sortie : -SDL_Surface *surface : la surface sur laquelle on va récupérer la couleur d'un pixel -int x : la coordonnée en x du pixel à récupérer -int y : la coordonnée en y du pixel à récupérer - -Uint32 resultat : la fonction renvoie le pixel aux coordonnées (x,y) dans la surface -*/ -Uint32 obtenirPixel(SDL_Surface *surface, int x, int y) -{ - /*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel. - En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur - de l'image : 8, 16, 24 ou 32 bits.*/ - int nbOctetsParPixel = surface->format->BytesPerPixel; - /* Ici p est l'adresse du pixel que l'on veut connaitre */ - /*surface->pixels contient l'adresse du premier pixel de l'image*/ - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel; - - /*Gestion différente suivant le nombre d'octets par pixel de l'image*/ - switch(nbOctetsParPixel) - { - case 1: - return *p; - - case 2: - return *(Uint16 *)p; - - case 3: - /*Suivant l'architecture de la machine*/ - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - return p[0] << 16 | p[1] << 8 | p[2]; - else - return p[0] | p[1] << 8 | p[2] << 16; - - case 4: - return *(Uint32 *)p; - - /*Ne devrait pas arriver, mais évite les erreurs*/ - default: - return 0; - } -} - -/* ********************************************************************* */ -/*definirPixel : permet de modifier la couleur d'un pixel -Paramètres d'entrée/sortie : -SDL_Surface *surface : la surface sur laquelle on va modifier la couleur d'un pixel -int x : la coordonnée en x du pixel à modifier -int y : la coordonnée en y du pixel à modifier -Uint32 pixel : le pixel à insérer -*/ -void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) -{ - /*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel. - En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur - de l'image : 8, 16, 24 ou 32 bits.*/ - int nbOctetsParPixel = surface->format->BytesPerPixel; - /*Ici p est l'adresse du pixel que l'on veut modifier*/ - /*surface->pixels contient l'adresse du premier pixel de l'image*/ - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel; - - /*Gestion différente suivant le nombre d'octets par pixel de l'image*/ - switch(nbOctetsParPixel) - { - case 1: - *p = pixel; - break; - - case 2: - *(Uint16 *)p = pixel; - break; - - case 3: - /*Suivant l'architecture de la machine*/ - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } - else - { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - } - break; - - case 4: - *(Uint32 *)p = pixel; - break; - } -} diff --git a/target.h b/target.h index 941b1f6..32e9c49 100644 --- a/target.h +++ b/target.h @@ -9,7 +9,7 @@ struct target_t { union { struct team_t *team; - struct character_t *chr; + struct chr_t *chr; }; }; -- cgit v1.2.3