summaryrefslogtreecommitdiff
path: root/magies.c
blob: 3740c84cda6ef8d1afa4063cfcc9787f2515c575 (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
#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;
    int degats;
    int selection = 0;
    int clan=ENNEMI;
    SDL_Event event;
    SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
    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)
{
    struct character_t *target;
    SDL_Event event;
    int soins;
    int clan=ALLIE;
    int selection=0;
    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;
}