瀏覽代碼

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

SBird1337 6 年之前
父節點
當前提交
fe536694bf
共有 4 個文件被更改,包括 52 次插入9 次删除
  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 查看文件

@@ -106,12 +106,12 @@ $(STRINGDIR)/%.s: $(STRINGDIR)/%.txt
106 106
 	@echo -e "\e[93mGenerating strings $<\e[0m"
107 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 110
 	@echo -e "\e[32mCompiling $<\e[0m"		
111 111
 	$(shell mkdir -p $(dir $@))		
112 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 115
 	@echo -e "\e[32mAssembling $<\e[0m"		
116 116
 	$(shell mkdir -p $(dir $@))		
117 117
 	$(PREPROC) $< $(CHARMAP) > $*.i		

+ 4
- 0
patches/overworlds/trainer.asm 查看文件

@@ -3,4 +3,8 @@ ldr r1, =trainer_check_flag_on_spot+1
3 3
 bx r1
4 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 查看文件

@@ -148,6 +148,23 @@ trainerbattle 0x8 \doublegymbattle_id 0x0 \doublegymbattle_before \doublegymbatt
148 148
 trainerbattle 0x9 \winlosebattle_id 0x3 \winlosebattle_win \winlosebattle_lose
149 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 168
 .macro msgbox msgbox_textpointer:req msgbox_callstd:req
152 169
 loadpointer 0x0 \msgbox_textpointer
153 170
 callstd \msgbox_callstd

+ 29
- 7
src/specials/trainer_battle.c 查看文件

@@ -31,12 +31,8 @@
31 31
 /* === INCLUDE === */
32 32
 
33 33
 #include <agb_debug.h>
34
-#include <callback.h>
35 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 37
 /* === ENGINE EXTERNS === */
42 38
 extern void battle_init();
@@ -101,7 +97,7 @@ u32 load_word(void *ptr) {
101 97
  * @return flag +1 for medium, flag +2 for hard
102 98
  */
103 99
 u16 tb_modify_flag_id(u16 flag) {
104
-    u16 difficulty = var_get(0x5052);
100
+    u16 difficulty = var_load(0x5052);
105 101
     u16 new_flag = flag;
106 102
     switch (difficulty) {
107 103
     case 0:
@@ -186,7 +182,7 @@ void *tb_configure_by_script(void *ptr_script) {
186 182
         trainerbattle_message_intro = NULL;
187 183
 
188 184
         trainerbattle_message_defeat = tb_modify_text((char *)load_word(ptr_script), 0);
189
-        ptr_script+= 4;
185
+        ptr_script += 4;
190 186
 
191 187
         trainerbattle_message_2 = NULL;
192 188
         trainerbattle_message_need_2_poke = NULL;
@@ -280,6 +276,11 @@ void *tb_configure_by_script(void *ptr_script) {
280 276
         battle_80801F0_something();
281 277
 
282 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 284
     default:
284 285
         trainerbattle_battle_type = load_byte(ptr_script);
285 286
         ptr_script++;
@@ -307,3 +308,24 @@ void *tb_configure_by_script(void *ptr_script) {
307 308
     // assert(0);
308 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
+}