SBird1337 před 7 roky
rodič
revize
de46c2764f
1 změnil soubory, kde provedl 200 přidání a 211 odebrání
  1. 200
    211
      src/specials/trainer_battle.c

+ 200
- 211
src/specials/trainer_battle.c Zobrazit soubor

@@ -25,17 +25,18 @@
25 25
  * @author Sturmvogel
26 26
  * @date 04 Jan 2014
27 27
  * @brief trainerbattle script command overhaul
28
- * 
28
+ *
29 29
  */
30 30
 
31 31
 /* === INCLUDE === */
32 32
 
33
-#include <types.h>
34
-#include <game_engine.h>
35
-#include <debug.h>
36
-#include <config.h>
37
-#include <callback.h>
38 33
 #include <agb_debug.h>
34
+#include <callback.h>
35
+#include <config.h>
36
+#include <debug.h>
37
+#include <game_engine.h>
38
+#include <types.h>
39
+
39 40
 
40 41
 /* === ENGINE EXTERNS === */
41 42
 extern void battle_init();
@@ -43,16 +44,16 @@ extern void battle_80801F0_something();
43 44
 
44 45
 extern volatile u8 trainerbattle_battle_type;
45 46
 extern volatile u16 trainerbattle_arg2;
46
-extern volatile char* trainerbattle_message_intro;
47
-extern volatile char* trainerbattle_message_defeat;
48
-extern volatile char* trainerbattle_message_2;
49
-extern volatile char* trainerbattle_message_need_2_poke;
50
-extern volatile char* trainerbattle_message_4;
51
-extern volatile void* trainerbattle_next_scr_cmd;
47
+extern volatile char *trainerbattle_message_intro;
48
+extern volatile char *trainerbattle_message_defeat;
49
+extern volatile char *trainerbattle_message_2;
50
+extern volatile char *trainerbattle_message_need_2_poke;
51
+extern volatile char *trainerbattle_message_4;
52
+extern volatile void *trainerbattle_next_scr_cmd;
52 53
 extern volatile u16 trainerbattle_unknown;
53 54
 
54
-char*** trainer_text_array;
55
-char* str_invalid_text_ref;
55
+char ***trainer_text_array;
56
+char *str_invalid_text_ref;
56 57
 
57 58
 /* === PROTOTYPES === */
58 59
 
@@ -63,9 +64,8 @@ char* str_invalid_text_ref;
63 64
  * @param ptr pointer to load byte from
64 65
  * @return byte loaded
65 66
  */
66
-u8 load_byte(void* ptr)
67
-{
68
-    u8* to_load = (u8*)ptr;
67
+u8 load_byte(void *ptr) {
68
+    u8 *to_load = (u8 *)ptr;
69 69
     return (u8)(*to_load);
70 70
 }
71 71
 
@@ -74,11 +74,10 @@ u8 load_byte(void* ptr)
74 74
  * @param ptr pointer to load from
75 75
  * @return half word at pointer
76 76
  */
77
-u16 load_hword(void* ptr)
78
-{
79
-    u8* to_load = (u8*)ptr;
77
+u16 load_hword(void *ptr) {
78
+    u8 *to_load = (u8 *)ptr;
80 79
     u16 result = *to_load;
81
-    u16 result2 = *(to_load+1) << 8;
80
+    u16 result2 = *(to_load + 1) << 8;
82 81
     return result | result2;
83 82
 }
84 83
 
@@ -87,13 +86,12 @@ u16 load_hword(void* ptr)
87 86
  * @param ptr pointer to load from
88 87
  * @return word read at pointer
89 88
  */
90
-u32 load_word(void* ptr)
91
-{
92
-    u8* to_load = (u8*)ptr;
89
+u32 load_word(void *ptr) {
90
+    u8 *to_load = (u8 *)ptr;
93 91
     u32 result = *to_load;
94
-    u32 result2 = *(to_load+1);
95
-    u32 result3 = *(to_load+2);
96
-    u32 result4 = *(to_load+3);
92
+    u32 result2 = *(to_load + 1);
93
+    u32 result3 = *(to_load + 2);
94
+    u32 result4 = *(to_load + 3);
97 95
     return (result) | (result2 << 8) | (result3 << 16) | (result4 << 24);
98 96
 }
99 97
 
@@ -102,20 +100,18 @@ u32 load_word(void* ptr)
102 100
  * @param flag flag to modify
103 101
  * @return flag +1 for medium, flag +2 for hard
104 102
  */
105
-u16 tb_modify_flag_id(u16 flag)
106
-{
103
+u16 tb_modify_flag_id(u16 flag) {
107 104
     u16 difficulty = var_get(0x5052);
108 105
     u16 new_flag = flag;
109
-    switch(difficulty)
110
-    {
111
-        case 0:
112
-            break;
113
-        case 1:
114
-            new_flag = flag + 1;
115
-            break;
116
-        case 2:
117
-            new_flag = flag + 2;
118
-            break;
106
+    switch (difficulty) {
107
+    case 0:
108
+        break;
109
+    case 1:
110
+        new_flag = flag + 1;
111
+        break;
112
+    case 2:
113
+        new_flag = flag + 2;
114
+        break;
119 115
     }
120 116
     dprintf("tb_modify_flag_id;; trainer ID: %d, difficulty: %d, new trainer id: %d\n", flag, difficulty, new_flag);
121 117
     return new_flag;
@@ -125,24 +121,19 @@ u16 tb_modify_flag_id(u16 flag)
125 121
  * @brief modifies null text pointers according to the trainer text table
126 122
  * @param original original pointer, will be modified only if equal to NULL
127 123
  * @param index index of the requested text in the trainer table
128
- * @return 
124
+ * @return
129 125
  */
130
-char* tb_modify_text(char* original, u8 index)
131
-{
132
-    if(original != NULL)
126
+char *tb_modify_text(char *original, u8 index) {
127
+    if (original != NULL)
133 128
         return original;
134
-    u8 flag_index = trainerbattle_flag_id;   /* NOTE: divide by 3 eventually */
135
-    for(int i = 0; i <= flag_index; ++i)
136
-    {
137
-        if(trainer_text_array[i] == (char**)0xDEADBEEF)
138
-        {
129
+    u8 flag_index = trainerbattle_flag_id; /* NOTE: divide by 3 eventually */
130
+    for (int i = 0; i <= flag_index; ++i) {
131
+        if (trainer_text_array[i] == (char **)0xDEADBEEF) {
139 132
             return str_invalid_text_ref;
140 133
         }
141 134
     }
142
-    for(int i = 0; i <= index; ++i)
143
-    {
144
-        if(trainer_text_array[flag_index][i] == (char*)0xDEADBEEF)
145
-        {
135
+    for (int i = 0; i <= index; ++i) {
136
+        if (trainer_text_array[flag_index][i] == (char *)0xDEADBEEF) {
146 137
             return str_invalid_text_ref;
147 138
         }
148 139
     }
@@ -154,167 +145,165 @@ char* tb_modify_text(char* original, u8 index)
154 145
  * @param ptr_script pointer to current executed script
155 146
  * @return new script pointer
156 147
  */
157
-void* tb_configure_by_script(void* ptr_script)
158
-{
148
+void *tb_configure_by_script(void *ptr_script) {
159 149
     battle_init();
160 150
     trainerbattle_battle_type = load_byte(ptr_script);
161
-    switch(trainerbattle_battle_type)
162
-    {
163
-        case 1:
164
-        case 2:
165
-            trainerbattle_battle_type = load_byte(ptr_script);
166
-            ptr_script++;
167
-            
168
-            trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
169
-            ptr_script+=2;
170
-            
171
-            trainerbattle_arg2 = load_hword(ptr_script);
172
-            ptr_script+=2;
173
-            
174
-            trainerbattle_message_intro = tb_modify_text((char*)load_word(ptr_script), 0);
175
-            ptr_script+=4;
176
-            
177
-            trainerbattle_message_defeat = tb_modify_text((char*)load_word(ptr_script), 1);
178
-            ptr_script+=4;
179
-            
180
-            trainerbattle_message_2 = NULL;
181
-            trainerbattle_message_need_2_poke = NULL;
182
-            
183
-            trainerbattle_message_4 = tb_modify_text((char*)load_word(ptr_script), 2);
184
-            ptr_script+=4;
185
-            trainerbattle_next_scr_cmd = ptr_script;
186
-            battle_80801F0_something();
187
-            return (void*) (0x081A4EC1) /* some script to execute */;
188
-        case 3:
189
-            trainerbattle_battle_type = load_byte(ptr_script);
190
-            
191
-            trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
192
-            ptr_script+=2;
193
-            
194
-            trainerbattle_arg2 = load_hword(ptr_script);
195
-            ptr_script+=2;
196
-            
197
-            trainerbattle_message_intro = NULL;
198
-            
199
-            trainerbattle_message_defeat = tb_modify_text((char*)load_word(ptr_script), 0);
200
-            ptr_script++;
201
-            
202
-            trainerbattle_message_2 = NULL;
203
-            trainerbattle_message_need_2_poke = NULL;
204
-            
205
-            trainerbattle_message_4 = NULL;
206
-            
207
-            trainerbattle_next_scr_cmd = ptr_script;
208
-            return (void*) (0x081A4F21); /* some script to execute*/
209
-        case 4:
210
-            trainerbattle_battle_type = load_byte(ptr_script);
211
-            ptr_script++;
212
-            
213
-            trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
214
-            ptr_script+=2;
215
-            
216
-            trainerbattle_arg2 = load_hword(ptr_script);
217
-            ptr_script+=2;
218
-            
219
-            trainerbattle_message_intro = tb_modify_text((char*)load_word(ptr_script), 0);
220
-            ptr_script+=4;
221
-            
222
-            trainerbattle_message_defeat = tb_modify_text((char*)load_word(ptr_script), 1);
223
-            ptr_script+=4;
224
-            
225
-            trainerbattle_message_2 = NULL;
226
-            
227
-            trainerbattle_message_need_2_poke = tb_modify_text((char*)load_word(ptr_script), 2);
228
-            ptr_script+= 4;
229
-            
230
-            trainerbattle_message_4 = NULL;
231
-            ptr_script+= 4;
232
-            trainerbattle_next_scr_cmd = ptr_script;
233
-            battle_80801F0_something();
234
-            return (void*) (0x081A4EE9); /* some script to execute */
235
-            
236
-            //this will merge case 5 with default which might not be as intended
237
-        case 6:
238
-        case 8:
239
-            trainerbattle_battle_type = load_byte(ptr_script);
240
-            ptr_script++;
241
-            
242
-            trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
243
-            ptr_script+=2;
244
-            
245
-            trainerbattle_arg2 = load_hword(ptr_script);
246
-            ptr_script+=2;
247
-            
248
-            trainerbattle_message_intro = tb_modify_text((char*)load_word(ptr_script), 0);
249
-            ptr_script+=4;
250
-            
251
-            trainerbattle_message_defeat = tb_modify_text((char*)load_word(ptr_script), 1);
252
-            ptr_script+=4;
253
-            
254
-            trainerbattle_message_2 = NULL;
255
-            
256
-            trainerbattle_message_need_2_poke = tb_modify_text((char*)load_word(ptr_script), 2);
257
-            ptr_script += 4;
258
-            trainerbattle_message_4 = tb_modify_text((char*)load_word(ptr_script), 3);
259
-            ptr_script += 4;
260
-            trainerbattle_next_scr_cmd = ptr_script;
261
-            battle_80801F0_something();
262
-            return (void*) (0x081A4EE9); /* some script to execute */
263
-            
264
-            //this will merge case 7 with default
265
-        case 9:
266
-            /* WIN / LOSE resume script */
267
-            
268
-            trainerbattle_battle_type = load_byte(ptr_script);
269
-            ptr_script++;
270
-            
271
-            trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
272
-            ptr_script += 2;
273
-            
274
-            trainerbattle_unknown = load_hword(ptr_script);
275
-            ptr_script += 2;
276
-            
277
-            trainerbattle_message_intro = NULL;
278
-            
279
-            trainerbattle_message_defeat = tb_modify_text((char*)load_word(ptr_script), 0);
280
-            ptr_script += 4;
281
-            
282
-            trainerbattle_message_2 = tb_modify_text((char*)load_word(ptr_script), 1);
283
-            ptr_script += 4;
284
-            
285
-            trainerbattle_message_need_2_poke = NULL;
286
-            
287
-            trainerbattle_message_4 = NULL;
288
-            
289
-            trainerbattle_next_scr_cmd = ptr_script;
290
-            
291
-            battle_80801F0_something();
292
-            
293
-            return (void*) (0x081A4EC1); /* some script to execute */
294
-        default:
295
-            trainerbattle_battle_type = load_byte(ptr_script);
296
-            ptr_script++;
297
-            
298
-            trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
299
-            ptr_script+=2;
300
-            
301
-            trainerbattle_arg2 = load_hword(ptr_script);
302
-            ptr_script+=2;
303
-            
304
-            trainerbattle_message_intro = tb_modify_text((char*)load_word(ptr_script), 0);
305
-            ptr_script+=4;
306
-            
307
-            trainerbattle_message_defeat = tb_modify_text((char*)load_word(ptr_script), 1);
308
-            ptr_script+=4;
309
-            
310
-            trainerbattle_message_2 = NULL;
311
-            trainerbattle_message_need_2_poke = NULL;
312
-            trainerbattle_message_4 = NULL;
313
-            trainerbattle_next_scr_cmd = ptr_script;
314
-            battle_80801F0_something();
315
-            return (void*) (0x081A4EC1); /* some script to execute */
151
+    switch (trainerbattle_battle_type) {
152
+    case 1:
153
+    case 2:
154
+        trainerbattle_battle_type = load_byte(ptr_script);
155
+        ptr_script++;
156
+
157
+        trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
158
+        ptr_script += 2;
159
+
160
+        trainerbattle_arg2 = load_hword(ptr_script);
161
+        ptr_script += 2;
162
+
163
+        trainerbattle_message_intro = tb_modify_text((char *)load_word(ptr_script), 0);
164
+        ptr_script += 4;
165
+
166
+        trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 1);
167
+        ptr_script += 4;
168
+
169
+        trainerbattle_message_2 = NULL;
170
+        trainerbattle_message_need_2_poke = NULL;
171
+
172
+        trainerbattle_message_4 = tb_modify_text((char *)load_word(ptr_script), 2);
173
+        ptr_script += 4;
174
+        trainerbattle_next_scr_cmd = ptr_script;
175
+        battle_80801F0_something();
176
+        return (void *)(0x081A4EC1) /* some script to execute */;
177
+    case 3:
178
+        trainerbattle_battle_type = load_byte(ptr_script);
179
+
180
+        trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
181
+        ptr_script += 2;
182
+
183
+        trainerbattle_arg2 = load_hword(ptr_script);
184
+        ptr_script += 2;
185
+
186
+        trainerbattle_message_intro = NULL;
187
+
188
+        trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 0);
189
+        ptr_script++;
190
+
191
+        trainerbattle_message_2 = NULL;
192
+        trainerbattle_message_need_2_poke = NULL;
193
+
194
+        trainerbattle_message_4 = NULL;
195
+
196
+        trainerbattle_next_scr_cmd = ptr_script;
197
+        return (void *)(0x081A4F21); /* some script to execute*/
198
+    case 4:
199
+        trainerbattle_battle_type = load_byte(ptr_script);
200
+        ptr_script++;
201
+
202
+        trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
203
+        ptr_script += 2;
204
+
205
+        trainerbattle_arg2 = load_hword(ptr_script);
206
+        ptr_script += 2;
207
+
208
+        trainerbattle_message_intro = tb_modify_text((char *)load_word(ptr_script), 0);
209
+        ptr_script += 4;
210
+
211
+        trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 1);
212
+        ptr_script += 4;
213
+
214
+        trainerbattle_message_2 = NULL;
215
+
216
+        trainerbattle_message_need_2_poke = tb_modify_text((char *)load_word(ptr_script), 2);
217
+        ptr_script += 4;
218
+
219
+        trainerbattle_message_4 = NULL;
220
+        ptr_script += 4;
221
+        trainerbattle_next_scr_cmd = ptr_script;
222
+        battle_80801F0_something();
223
+        return (void *)(0x081A4EE9); /* some script to execute */
224
+
225
+    // this will merge case 5 with default which might not be as intended
226
+    case 6:
227
+    case 8:
228
+        trainerbattle_battle_type = load_byte(ptr_script);
229
+        ptr_script++;
230
+
231
+        trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
232
+        ptr_script += 2;
233
+
234
+        trainerbattle_arg2 = load_hword(ptr_script);
235
+        ptr_script += 2;
236
+
237
+        trainerbattle_message_intro = tb_modify_text((char *)load_word(ptr_script), 0);
238
+        ptr_script += 4;
239
+
240
+        trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 1);
241
+        ptr_script += 4;
242
+
243
+        trainerbattle_message_2 = NULL;
244
+
245
+        trainerbattle_message_need_2_poke = tb_modify_text((char *)load_word(ptr_script), 2);
246
+        ptr_script += 4;
247
+        trainerbattle_message_4 = tb_modify_text((char *)load_word(ptr_script), 3);
248
+        ptr_script += 4;
249
+        trainerbattle_next_scr_cmd = ptr_script;
250
+        battle_80801F0_something();
251
+        return (void *)(0x081A4EE9); /* some script to execute */
252
+
253
+    // this will merge case 7 with default
254
+    case 9:
255
+        /* WIN / LOSE resume script */
256
+
257
+        trainerbattle_battle_type = load_byte(ptr_script);
258
+        ptr_script++;
259
+
260
+        trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
261
+        ptr_script += 2;
262
+
263
+        trainerbattle_unknown = load_hword(ptr_script);
264
+        ptr_script += 2;
265
+
266
+        trainerbattle_message_intro = NULL;
267
+
268
+        trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 0);
269
+        ptr_script += 4;
270
+
271
+        trainerbattle_message_2 = tb_modify_text((char *)load_word(ptr_script), 1);
272
+        ptr_script += 4;
273
+
274
+        trainerbattle_message_need_2_poke = NULL;
275
+
276
+        trainerbattle_message_4 = NULL;
277
+
278
+        trainerbattle_next_scr_cmd = ptr_script;
279
+
280
+        battle_80801F0_something();
281
+
282
+        return (void *)(0x081A4EC1); /* some script to execute */
283
+    default:
284
+        trainerbattle_battle_type = load_byte(ptr_script);
285
+        ptr_script++;
286
+
287
+        trainerbattle_flag_id = tb_modify_flag_id(load_hword(ptr_script));
288
+        ptr_script += 2;
289
+
290
+        trainerbattle_arg2 = load_hword(ptr_script);
291
+        ptr_script += 2;
292
+
293
+        trainerbattle_message_intro = tb_modify_text((char *)load_word(ptr_script), 0);
294
+        ptr_script += 4;
295
+
296
+        trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 1);
297
+        ptr_script += 4;
298
+
299
+        trainerbattle_message_2 = NULL;
300
+        trainerbattle_message_need_2_poke = NULL;
301
+        trainerbattle_message_4 = NULL;
302
+        trainerbattle_next_scr_cmd = ptr_script;
303
+        battle_80801F0_something();
304
+        return (void *)(0x081A4EC1); /* some script to execute */
316 305
     }
317 306
     /* should never be reached */
318
-    //assert(0);
319
-   // return NULL;
307
+    // assert(0);
308
+    // return NULL;
320 309
 }