Browse Source

move trainer stuff to trainer folder, finish first rival battle draft

SBird1337 6 years ago
parent
commit
309bdd4969

+ 1
- 1
g3headers

@@ -1 +1 @@
1
-Subproject commit e16cda91fc0c216e41c8a770b5af23a83aba698a
1
+Subproject commit 3e36531d290bd97e7b1208526e54c8acdfe376d3

src/specials/trainer_battle.c → src/trainer/trainer_battle.c View File


+ 170
- 0
src/trainer/trainer_rival_encounters.c View File

@@ -0,0 +1,170 @@
1
+#include <pokeagb/pokeagb.h>
2
+#include <constants/pkmns.h>
3
+#include "trainer_rival_encounters.h"
4
+
5
+
6
+const struct TrainerPokemonBase rival_first_encounter[21][1] = {
7
+    //Bisasam
8
+    {
9
+        {
10
+            .species = PKMN_GLUMANDA,
11
+            .level = 5
12
+        },
13
+    },
14
+
15
+    //Glumanda
16
+    {
17
+        {
18
+            .species = PKMN_SCHIGGY,
19
+            .level = 5
20
+        },
21
+    },
22
+    //Schiggy
23
+    {
24
+        {
25
+            .species = PKMN_BISASAM,
26
+            .level = 5
27
+        },
28
+    },
29
+    //Endivie
30
+    {
31
+        {
32
+            .species = PKMN_FEURIGEL,
33
+            .level = 5
34
+        },
35
+    },
36
+
37
+    //Feurigel
38
+    {
39
+        {
40
+            .species = PKMN_KARNIMANI,
41
+            .level = 5
42
+        },
43
+    },
44
+    //Karnimani
45
+    {
46
+        {
47
+            .species = PKMN_ENDIVIE,
48
+            .level = 5
49
+        },
50
+    },
51
+    //Geckarbor
52
+    {
53
+        {
54
+            .species = PKMN_FLEMMLI,
55
+            .level = 5
56
+        },
57
+    },
58
+
59
+    //Flemmli
60
+    {
61
+        {
62
+            .species = PKMN_HYDROPI,
63
+            .level = 5
64
+        },
65
+    },
66
+    //Hydropi
67
+    {
68
+        {
69
+            .species = PKMN_GECKARBOR,
70
+            .level = 5
71
+        },
72
+    },
73
+    //Chelast
74
+    {
75
+        {
76
+            .species = PKMN_PANFLAM,
77
+            .level = 5
78
+        },
79
+    },
80
+
81
+    //Panflam
82
+    {
83
+        {
84
+            .species = PKMN_PLINFA,
85
+            .level = 5
86
+        },
87
+    },
88
+    //Plinfa
89
+    {
90
+        {
91
+            .species = PKMN_CHELAST,
92
+            .level = 5
93
+        },
94
+    },
95
+    //Serpifeu
96
+    {
97
+        {
98
+            .species = PKMN_FLOINK,
99
+            .level = 5
100
+        },
101
+    },
102
+
103
+    //Floink
104
+    {
105
+        {
106
+            .species = PKMN_OTTARO,
107
+            .level = 5
108
+        },
109
+    },
110
+    //Ottaro
111
+    {
112
+        {
113
+            .species = PKMN_SERPIFEU,
114
+            .level = 5
115
+        },
116
+    },
117
+    //Igamaro
118
+    {
119
+        {
120
+            .species = PKMN_FYNX,
121
+            .level = 5
122
+        },
123
+    },
124
+
125
+    //Fynx
126
+    {
127
+        {
128
+            .species = PKMN_FROXY,
129
+            .level = 5
130
+        },
131
+    },
132
+    //Froxy
133
+    {
134
+        {
135
+            .species = PKMN_IGAMARO,
136
+            .level = 5
137
+        },
138
+    },
139
+    //Bauz
140
+    {
141
+        {
142
+            .species = PKMN_FLAMIAU,
143
+            .level = 5
144
+        },
145
+    },
146
+
147
+    //Flamiau
148
+    {
149
+        {
150
+            .species = PKMN_ROBBALL,
151
+            .level = 5
152
+        },
153
+    },
154
+    //Robball
155
+    {
156
+        {
157
+            .species = PKMN_BAUZ,
158
+            .level = 5
159
+        },
160
+    },
161
+};
162
+
163
+const struct RivalEncounter rival_encounters[RIVAL_ENCOUNTER_COUNT] = {
164
+    {.partyCount = 1, .partyArray = {&rival_first_encounter[0][0]}, .trainerId = 1}, //male easy
165
+    {.partyCount = 1, .partyArray = {&rival_first_encounter[0][0]}, .trainerId = 2}, //male medium
166
+    {.partyCount = 1, .partyArray = {&rival_first_encounter[0][0]}, .trainerId = 3}, //male hard
167
+    {.partyCount = 1, .partyArray = {&rival_first_encounter[0][0]}, .trainerId = 4}, //female easy
168
+    {.partyCount = 1, .partyArray = {&rival_first_encounter[0][0]}, .trainerId = 5}, //female medium
169
+    {.partyCount = 1, .partyArray = {&rival_first_encounter[0][0]}, .trainerId = 6}, //female hard
170
+};

+ 16
- 0
src/trainer/trainer_rival_encounters.h View File

@@ -0,0 +1,16 @@
1
+#ifndef TRAINER_RIVAL_ENC_H_
2
+#define TRAINER_RIVAL_ENC_H_
3
+
4
+#include <pokeagb/pokeagb.h>
5
+
6
+#define RIVAL_ENCOUNTER_COUNT 6
7
+
8
+struct RivalEncounter {
9
+    u8 partyCount;
10
+    const union TrainerPokemonPtr partyArray;
11
+    u8 trainerId;
12
+};
13
+
14
+const struct RivalEncounter rival_encounters[RIVAL_ENCOUNTER_COUNT];
15
+
16
+#endif

src/overworld/trainerbattle_init.c → src/trainer/trainerbattle_init.c View File

@@ -1,5 +1,6 @@
1 1
 #include <pokeagb/pokeagb.h>
2 2
 #include <agb_debug.h>
3
+#include "trainer_rival_encounters.h"
3 4
 
4 5
 void battle_intro_launch(u8 environment) {
5 6
     TaskCallback introTask;
@@ -16,6 +17,43 @@ void battle_intro_launch(u8 environment) {
16 17
     livingTask->priv[1] = environment;
17 18
 }
18 19
 
20
+union TrainerPokemonPtr battle_trainer_get_rival(u8 chosenStarterValue, u8 encounterNumber, enum TrainerPartyFlag flag) {
21
+    u8 partyCount = rival_encounters[encounterNumber].partyCount;
22
+    u8 structureSize = 0;
23
+    switch(flag)
24
+    {
25
+        case TRAINER_PARTY_NONE:
26
+            structureSize = sizeof(struct TrainerPokemonBase);
27
+            break;
28
+        case TRAINER_PARTY_HELD_ITEM:
29
+            structureSize = sizeof(struct TrainerPokemonItem);
30
+            break;
31
+        case TRAINER_PARTY_MOVESET:
32
+            structureSize = sizeof(struct TrainerPokemonMoves);
33
+            break;
34
+        case TRAINER_PARTY_HELD_ITEM_MOVESET:
35
+            structureSize = sizeof(struct TrainerPokemonItemMoves);
36
+            break;
37
+        default:
38
+            structureSize = sizeof(struct TrainerPokemonBase);
39
+            break;
40
+    }
41
+
42
+    return (union TrainerPokemonPtr)(rival_encounters[encounterNumber].partyArray.undefinedStructure + (chosenStarterValue * partyCount * structureSize));
43
+}
44
+
45
+#define VAR_STARTER 0x5052
46
+
47
+union TrainerPokemonPtr battle_trainer_get_rival_or_null(u8 tid) {
48
+    for(u16 i = 0; i < RIVAL_ENCOUNTER_COUNT; ++i) {
49
+        if(rival_encounters[i].trainerId == tid) {
50
+            return battle_trainer_get_rival(var_load(VAR_STARTER), i, trainer_data[tid].flags);
51
+        }
52
+    }
53
+    union TrainerPokemonPtr nullPokemon = {.undefinedStructure = NULL};
54
+    return nullPokemon;
55
+}
56
+
19 57
 u8 battle_trainer_build_party(struct Pokemon *party, u16 tid) {
20 58
     if(tid == 0x400)
21 59
         return 0;
@@ -35,14 +73,15 @@ u8 battle_trainer_build_party(struct Pokemon *party, u16 tid) {
35 73
             for(u8 j = 0; trainer_data[tid].name[j] != 0xFF; ++j){
36 74
                 nameHash += trainer_data[tid].name[j];
37 75
             }
38
-
39 76
             //has custom items etc
40 77
             switch(trainer_data[tid].flags)
41 78
             {
42 79
                 case TRAINER_PARTY_NONE:
43 80
                 {
44 81
                     //nothing
45
-                    const struct TrainerPokemonBase *pokeData = (const struct TrainerPokemonBase*)(trainer_data[tid].party);
82
+                    const struct TrainerPokemonBase *pokeData = battle_trainer_get_rival_or_null(tid).noItemDefaultMoves;
83
+                    if(pokeData == NULL)
84
+                        pokeData = trainer_data[tid].party.noItemDefaultMoves;
46 85
                     dprintf("making pokemon with species: %d, struct: 0x%x\n", pokeData[i].species, pokeData);
47 86
                     for(u8 j = 0; pokemon_names[pokeData[i].species][j] != 0xFF; ++j) {
48 87
                         nameHash += pokemon_names[pokeData[i].species][j];
@@ -57,14 +96,17 @@ u8 battle_trainer_build_party(struct Pokemon *party, u16 tid) {
57 96
                 }
58 97
                 case TRAINER_PARTY_MOVESET:
59 98
                 {
60
-                    const struct TrainerPokemonMoves *pokeData = (const struct TrainerPokemonMoves*)(trainer_data[tid].party);
61
-                    dprintf("making pokemon with species: %d\n", pokeData[i].base.species);
99
+                    const struct TrainerPokemonMoves *pokeData = battle_trainer_get_rival_or_null(tid).noItemCustomMoves;
100
+                    if(pokeData == NULL)
101
+                        pokeData = trainer_data[tid].party.noItemCustomMoves;
102
+                        
103
+                    dprintf("making pokemon with species: %d\n", pokeData[i].species);
62 104
                     //custom moveset
63
-                    for(u8 j = 0; pokemon_names[pokeData[i].base.species][j] != 0xFF; ++j)
64
-                        nameHash += pokemon_names[pokeData[i].base.species][j];
105
+                    for(u8 j = 0; pokemon_names[pokeData[i].species][j] != 0xFF; ++j)
106
+                        nameHash += pokemon_names[pokeData[i].species][j];
65 107
                     personalityValue += nameHash << 8;
66
-                    u8 iv = pokeData[i].base.iv * 31 / 255;
67
-                    pokemon_make_full(&party[i], pokeData[i].base.species, pokeData[i].base.level, iv, true, personalityValue, 2, 0);
108
+                    u8 iv = pokeData[i].iv * 31 / 255;
109
+                    pokemon_make_full(&party[i], pokeData[i].species, pokeData[i].level, iv, true, personalityValue, 2, 0);
68 110
                     for(u8 j = 0; j < 4; ++j) {
69 111
                         pokemon_setattr(&party[i], REQUEST_MOVE1 + j, (void*)&pokeData[i].moves[j]);
70 112
                         pokemon_setattr(&party[i], REQUEST_PP1 + j, (void*)&pokemon_moves[pokeData[i].moves[j]].pp);
@@ -75,7 +117,10 @@ u8 battle_trainer_build_party(struct Pokemon *party, u16 tid) {
75 117
                 {
76 118
                     //custom item
77 119
                     
78
-                    const struct TrainerPokemonBase *pokeData = (const struct TrainerPokemonBase*)(trainer_data[tid].party);
120
+                    const struct TrainerPokemonItem *pokeData = battle_trainer_get_rival_or_null(tid).itemDefaultMoves;
121
+                    if(pokeData == NULL)
122
+                        pokeData = trainer_data[tid].party.itemDefaultMoves;
123
+
79 124
                     dprintf("making pokemon with species: %d\n", pokeData[i].species);
80 125
                     for(u8 j = 0; pokemon_names[pokeData[i].species][j] != 0xFF; ++j)
81 126
                         nameHash += pokemon_names[pokeData[i].species][j];
@@ -89,15 +134,18 @@ u8 battle_trainer_build_party(struct Pokemon *party, u16 tid) {
89 134
                 case TRAINER_PARTY_HELD_ITEM | TRAINER_PARTY_MOVESET:
90 135
                 {
91 136
                     //custom all the things
92
-                    const struct TrainerPokemonMoves *pokeData = (const struct TrainerPokemonMoves*)(trainer_data[tid].party);
93
-                    dprintf("making pokemon with species: %d\n", pokeData[i].base.species);  
94
-                    for(u8 j = 0; pokemon_names[pokeData[i].base.species][j] != 0xFF; ++j)
95
-                        nameHash += pokemon_names[pokeData[i].base.species][j];
137
+                    const struct TrainerPokemonItemMoves *pokeData = battle_trainer_get_rival_or_null(tid).customItemCustomMoves;
138
+                    if(pokeData == NULL)
139
+                        pokeData = trainer_data[tid].party.customItemCustomMoves;
140
+
141
+                    dprintf("making pokemon with species: %d\n", pokeData[i].species);  
142
+                    for(u8 j = 0; pokemon_names[pokeData[i].species][j] != 0xFF; ++j)
143
+                        nameHash += pokemon_names[pokeData[i].species][j];
96 144
                     personalityValue += nameHash << 8;
97
-                    u8 iv = pokeData[i].base.iv * 31 / 255;
98
-                    pokemon_make_full(&party[i], pokeData[i].base.species, pokeData[i].base.level, iv, true, personalityValue, 2, 0);
145
+                    u8 iv = pokeData[i].iv * 31 / 255;
146
+                    pokemon_make_full(&party[i], pokeData[i].species, pokeData[i].level, iv, true, personalityValue, 2, 0);
99 147
                     
100
-                    pokemon_setattr(&party[i], REQUEST_HELD_ITEM, (void*)&pokeData[i].base.Item);
148
+                    pokemon_setattr(&party[i], REQUEST_HELD_ITEM, (void*)&pokeData[i].Item);
101 149
                     for(u8 j = 0; j < 4; ++j) {
102 150
                         pokemon_setattr(&party[i], REQUEST_MOVE1 + j, (void*)&pokeData[i].moves[j]);
103 151
                         pokemon_setattr(&party[i], REQUEST_PP1 + j, (void*)&pokemon_moves[pokeData[i].moves[j]].pp);