-
Notifications
You must be signed in to change notification settings - Fork 1
/
Moves.c
182 lines (151 loc) · 5.3 KB
/
Moves.c
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include "Moves.h"
#include <stdlib.h>
#include <string.h>
void useMove(move_t* usedMove, pokemon_t* userPoke, pokemon_t* enemyPoke)
{
if(usedMove->actualPP > 0) //Not accounting for pressure
{
float damage;
pokemon_t* target;
target = checkTarget(usedMove, userPoke, enemyPoke);
if(checkAccuracy(usedMove->accuracy, userPoke->stageAcc, target->stageEva) > 0)
{
if(usedMove->category == PHYSICAL)
{
damage = calcDamage(userPoke->atk, userPoke->stageAtk, target->def, target->stageDef,
usedMove->power, usedMove->type, target->mainType, target->subType, userPoke->status);
target->hp-=damage;
}
else if(usedMove->category == SPECIAL)
{
damage = calcDamage(userPoke->spatk, userPoke->stageSpAtk, target->spdef, target->stageSpDef,
usedMove->power, usedMove->type, target->mainType, target->subType, userPoke->status);
target->hp-=damage;
}
//TODO STATUS MOVES
}
else
printf("\nOH THE ATTACK MISSED\n");
}
}
pokemon_t* checkTarget(move_t* usedMove, pokemon_t* userPoke, pokemon_t* enemyPoke)
{
pokemon_t* target;
if(usedMove->target == ENEMY)
target = enemyPoke;
else if (usedMove->target == SELF)
target = userPoke;
else
fprintf(stderr, "\nNO VALID TARGET\n");
return target;
}
int checkAccuracy(int moveAcc, int userAcc, int targetEva)
{
if(rand()%100 < moveAcc) //TODO use ACC and EVASION
return 1;
return 0;
}
//TODO consider critical
float calcDamage(int atk, int stageAtk, int def, int stageDef, int power,
type_t moveType, type_t defenderType1, type_t defenderType2, statusEffect_t userStatus)
{
int totalDamage = 0;
float modifier;
float finalAtk, finalDef;
modifier = calcDamageModifier(moveType, defenderType1, defenderType2, userStatus);
finalAtk = calcStageMult(atk, stageAtk);
finalDef = calcStageMult(def, stageDef);
//We'll consider level 1 for now
totalDamage = ((((((2*1)/5.0) + 2) * power * finalAtk/finalDef)/50) + 2)*modifier;
return totalDamage;
}
//TODO STAB
float calcDamageModifier(type_t moveType, type_t defenderType1, type_t defenderType2, statusEffect_t userStatus)
{
float modifier = 1.0;
if(userStatus == BURN) //TODO CHECK ABILITIES LIKE GUTS
modifier *= 0.5;
modifier *= calculateAdvantage(moveType, defenderType1, defenderType2);
return modifier;
}
float calcStageMult(int stats, int stage)
{
if (stage == 0)
return 1.0;
else if(stage > 0)
return (2+stage)/2.0;
else
return 2/(stage*(-1)+2.0);
}
void applyBurn(pokemon_t* target, int burnChance)
{
if(target->mainType != FIRE && target->subType != FIRE)
{
if(target->status != PARALYZE && target->status != POISONED && target->status != SLEEP
&& target->status != FROZEN && target->status != TOXIC)
{
if(burnChance >= rand()%100)
{
target->status = BURN;
printf("\nTHE TARGET IS NOW BURNED!\n");
}
}
}
}
move_t* createMove(char* name, type_t type, category_t category, int maxPP, int power, int accuracy, void (*effectFun)(pokemon_t*, int), target_t target)
{
move_t* move;
move = (move_t*) malloc(sizeof(move_t));
strcpy(move->name,name);
move->type = type;
move->category = category;
move->maxPP = maxPP;
move->actualPP = maxPP;
move->power = power;
move->accuracy = accuracy;
move->effectFunction = effectFun;
move->target = target;
return move;
}
/*move_t** readMoveDex(int* nMoves)
{
move_t** moveDex = NULL;
FILE *fp;
fp = fopen (MOVEDEXFILE, "r");
if(fp == NULL)
{
fprintf(stderr, "\MOVEDEX FILE NOT FOUND!\n");
exit(1);
}
else
{
*nMoves = 0;
while(!feof(fp))
{
char auxType[15] = {'\0'};
char auxCategory[15] = {'\0'};
move_t auxPkmn;
*nMoves = (*nMoves) + 1;
moveDex = (move_t**) realloc(moveDex, sizeof(move_t*)*(*nMoves));
if(EOF != fscanf (fp, "%d,%[^,],%[^,],%[^,],%d,%d,%d,%d,%d,%d", &(auxPkmn.dexNumber), auxPkmn.species, auxMainType, auxSubType, &(auxPkmn.hp), &(auxPkmn.atk), &(auxPkmn.def), &(auxPkmn.spatk), &(auxPkmn.spdef), &(auxPkmn.speed)))
{
//addStringTerminator(auxPkmn.species);
auxPkmn.mainType = stringToType(auxMainType);
auxPkmn.subType = stringToType(auxSubType);
//printPokemon(&auxPkmn);
moveDex[*nMoves - 1] = (move_t*) malloc(sizeof(move_t));
moveDex[*nMoves - 1] = createPokemon(auxPkmn.dexNumber, auxPkmn.species, auxPkmn.hp, auxPkmn.atk, auxPkmn.def,
auxPkmn.spatk, auxPkmn.spdef, auxPkmn.speed, auxPkmn.mainType, auxPkmn.subType);
}
else
{
*nMoves = (*nMoves) - 1;
moveDex = (move_t**) realloc(moveDex, sizeof(move_t*)*(*nMoves));
}
if((*nMoves)%200 == 0)
printf("Still loading... Please Wait\n");
}
fclose(fp);
}
return pkdex;
}*/