Browse Source

add spot scripts, remove script/language.h dependency, take care

SBird1337 6 years ago
parent
commit
fe536694bf
4 changed files with 52 additions and 9 deletions
  1. 2
    2
      makefile
  2. 4
    0
      patches/overworlds/trainer.asm
  3. 17
    0
      src/include/script/language.h
  4. 29
    7
      src/specials/trainer_battle.c

+ 2
- 2
makefile View File

106
 	@echo -e "\e[93mGenerating strings $<\e[0m"
106
 	@echo -e "\e[93mGenerating strings $<\e[0m"
107
 	$(STRAGB) -o $@ -i $< -t string/table.tbl -e 0xFF
107
 	$(STRAGB) -o $@ -i $< -t string/table.tbl -e 0xFF
108
 
108
 
109
-$(BLDPATH)/%.o: %.c $(ASSETS) $(PAGB_INCLUDE)/pokeagb/pokeagb.h src/include/script/language.h	
109
+$(BLDPATH)/%.o: %.c $(ASSETS) $(PAGB_INCLUDE)/pokeagb/pokeagb.h
110
 	@echo -e "\e[32mCompiling $<\e[0m"		
110
 	@echo -e "\e[32mCompiling $<\e[0m"		
111
 	$(shell mkdir -p $(dir $@))		
111
 	$(shell mkdir -p $(dir $@))		
112
 	$(CC) $(CFLAGS) -c $< -o $@		
112
 	$(CC) $(CFLAGS) -c $< -o $@		
113
 		
113
 		
114
-$(BLDPATH)/%.o: %.s $(PAGB_INCLUDE)/pokeagb/pokeagb.h src/include/script/language.h	
114
+$(BLDPATH)/%.o: %.s $(PAGB_INCLUDE)/pokeagb/pokeagb.h
115
 	@echo -e "\e[32mAssembling $<\e[0m"		
115
 	@echo -e "\e[32mAssembling $<\e[0m"		
116
 	$(shell mkdir -p $(dir $@))		
116
 	$(shell mkdir -p $(dir $@))		
117
 	$(PREPROC) $< $(CHARMAP) > $*.i		
117
 	$(PREPROC) $< $(CHARMAP) > $*.i		

+ 4
- 0
patches/overworlds/trainer.asm View File

3
 bx r1
3
 bx r1
4
 .pool
4
 .pool
5
 
5
 
6
+.org 0x08080334
7
+ldr r2, =tb_on_spot+1
8
+bx r2
9
+.pool
6
 
10
 

+ 17
- 0
src/include/script/language.h View File

148
 trainerbattle 0x9 \winlosebattle_id 0x3 \winlosebattle_win \winlosebattle_lose
148
 trainerbattle 0x9 \winlosebattle_id 0x3 \winlosebattle_win \winlosebattle_lose
149
 .endm
149
 .endm
150
 
150
 
151
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
152
+@@@                                                                                               @@@
153
+@@@   special version of the trainerbattle command to be caught by the custom handler             @@@
154
+@@@   if the player is spotted and spotscript_flag is set, spotscript_ptr_true is executed        @@@
155
+@@@   if the player is spotted and spotscript_flag is not set, spotscript_ptr_false is executed   @@@
156
+@@@   if the player talks to an npc who has this as its first command, it is ignored              @@@
157
+@@@   THIS COMMAND WORKS IF AND ONLY IF THE TRAINER BIT IS SET ON THE NPC TEMPLATE                @@@
158
+@@@                                                                                               @@@
159
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
160
+.macro spotscript spotscript_flag:req spotscript_ptr_true:req spotscript_ptr_false:req
161
+.byte 0x5C, 0xFF
162
+.hword \spotscript_flag
163
+.hword 0xFFFF
164
+.word \spotscript_ptr_true
165
+.word \spotscript_ptr_false
166
+.endm
167
+
151
 .macro msgbox msgbox_textpointer:req msgbox_callstd:req
168
 .macro msgbox msgbox_textpointer:req msgbox_callstd:req
152
 loadpointer 0x0 \msgbox_textpointer
169
 loadpointer 0x0 \msgbox_textpointer
153
 callstd \msgbox_callstd
170
 callstd \msgbox_callstd

+ 29
- 7
src/specials/trainer_battle.c View File

31
 /* === INCLUDE === */
31
 /* === INCLUDE === */
32
 
32
 
33
 #include <agb_debug.h>
33
 #include <agb_debug.h>
34
-#include <callback.h>
35
 #include <config/core.h>
34
 #include <config/core.h>
36
-#include <debug.h>
37
-#include <game_engine.h>
38
-#include <types.h>
39
-
35
+#include <pokeagb/pokeagb.h>
40
 
36
 
41
 /* === ENGINE EXTERNS === */
37
 /* === ENGINE EXTERNS === */
42
 extern void battle_init();
38
 extern void battle_init();
101
  * @return flag +1 for medium, flag +2 for hard
97
  * @return flag +1 for medium, flag +2 for hard
102
  */
98
  */
103
 u16 tb_modify_flag_id(u16 flag) {
99
 u16 tb_modify_flag_id(u16 flag) {
104
-    u16 difficulty = var_get(0x5052);
100
+    u16 difficulty = var_load(0x5052);
105
     u16 new_flag = flag;
101
     u16 new_flag = flag;
106
     switch (difficulty) {
102
     switch (difficulty) {
107
     case 0:
103
     case 0:
186
         trainerbattle_message_intro = NULL;
182
         trainerbattle_message_intro = NULL;
187
 
183
 
188
         trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 0);
184
         trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 0);
189
-        ptr_script+= 4;
185
+        ptr_script += 4;
190
 
186
 
191
         trainerbattle_message_2 = NULL;
187
         trainerbattle_message_2 = NULL;
192
         trainerbattle_message_need_2_poke = NULL;
188
         trainerbattle_message_need_2_poke = NULL;
280
         battle_80801F0_something();
276
         battle_80801F0_something();
281
 
277
 
282
         return (void *)(0x081A4EC1); /* some script to execute */
278
         return (void *)(0x081A4EC1); /* some script to execute */
279
+
280
+    case 0xFF:
281
+        /* this is a registered on-spot script */
282
+        /* since this is a trainerbattle configuration we will skip the TB command. */
283
+        return ptr_script + 13;
283
     default:
284
     default:
284
         trainerbattle_battle_type = load_byte(ptr_script);
285
         trainerbattle_battle_type = load_byte(ptr_script);
285
         ptr_script++;
286
         ptr_script++;
307
     // assert(0);
308
     // assert(0);
308
     // return NULL;
309
     // return NULL;
309
 }
310
 }
311
+
312
+void tb_on_spot(u8 npc_id, void *ptr_script) {
313
+    scripting_npc = npc_id;
314
+    var_800F = npc_states[npc_id].local_id;
315
+    u8 tb_battle_type = load_byte(ptr_script + 1);
316
+
317
+    if (tb_battle_type != 0xFF) {
318
+        tb_configure_by_script(ptr_script + 1);
319
+        script_env_init_script((void *)0x081A4EB4);
320
+        script_env_enable();
321
+    } else {
322
+        u16 flag = load_hword(ptr_script + 2);
323
+        void *scr_true = (void *)load_word(ptr_script + 6);
324
+        void *scr_false = (void *)load_word(ptr_script + 10);
325
+        if (flag_check(flag))
326
+            script_env_init_script(scr_true);
327
+        else
328
+            script_env_init_script(scr_false);
329
+        script_env_enable();
330
+    }
331
+}