summaryrefslogtreecommitdiff
path: root/magies.c
blob: 13c98eb3dc227f624d76ecb7f16a595494751fc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#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, enum element_t element)
{
    struct character_t *target;
    enum action_state_t ret = ACTION_CANCELED;
    unsigned int continuer = 1;
    int degats;
    int selection = 0;
    int delay=1;
    int clan=ENNEMI;
    SDL_Event event;
    SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
    while (!enemy->chrs[selection].alive)
        selection++;
    Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);
    while (continuer)
    {
        SDL_Flip (surfaces->Pecran);
        SDL_WaitEvent (&event);
        switch (event.type)
        {
            case SDL_KEYDOWN:
            switch (event.key.keysym.sym)
            {
                case SDLK_ESCAPE:
                case SDLK_a:
                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()
                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];
                    }

                    degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_MAGICAL, element);


                    damage_target_hp(surfaces, positions, target, degats);
                    SDL_Flip(surfaces->Pecran);

                    ret = ACTION_PERFORMED;
                    continuer=0;
                    break;
                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 Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy)
{
    struct character_t *target;
    enum action_state_t ret = ACTION_CANCELED;
    unsigned int continuer=1;
    SDL_Event event;
    int soins;
    int clan=ALLIE;
    int delay=1;
    int selection=0;
    SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
    while(!ally->chrs[selection].alive)
        selection++;
    Fchangercurseurpersos (surfaces,positions,selection);
    while(continuer)
    {
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_KEYDOWN:
            switch(event.key.keysym.sym)
            {
                case SDLK_ESCAPE:
                case SDLK_a:
                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()
                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];
                }

                soins = compute_cure(&ally->chrs[ally->chr_cur], target);

                cure_target_hp(surfaces, positions, target, soins);

                SDL_Flip (surfaces->Pecran);

                ret = ACTION_PERFORMED;
                continuer=0;
                break;
                default:
                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_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;
}