Przeglądaj źródła

fix trainer loops, migrate some methods to pokeagb

SBird1337 7 lat temu
rodzic
commit
bc3c891610

+ 3
- 0
.gitmodules Wyświetl plik

@@ -4,3 +4,6 @@
4 4
 [submodule "battle_engine"]
5 5
 	path = battle_engine
6 6
 	url = https://github.com/EternalCode/battle_engine
7
+[submodule "g3headers"]
8
+	path = g3headers
9
+	url = https://github.com/SBird1337/g3headers

+ 1
- 1
.vscode/c_cpp_properties.json Wyświetl plik

@@ -35,7 +35,7 @@
35 35
                     "/usr/include",
36 36
                     "/usr/local/include",
37 37
                     "src/include",
38
-                    "${workspaceRoot}"
38
+                    "$(workspaceRoot}/g3headers/include"
39 39
                 ],
40 40
                 "limitSymbolsToIncludedHeaders": true,
41 41
                 "databaseFilename": ""

+ 1
- 1
bpre.sym Wyświetl plik

@@ -92,7 +92,7 @@ objc_exec = 0x08006B5D;
92 92
 obj_sync = 0x08006BA9;
93 93
 
94 94
 flag_clear = 0x0806E6A8|1;
95
-flag_set = 0x0806E680|1;
95
+/*flag_set = 0x0806E680|1;*/
96 96
 
97 97
 divide = 0x081E4018;
98 98
 

+ 1
- 0
g3headers

@@ -0,0 +1 @@
1
+Subproject commit 055ac19e4f3768b154554e097d3e8e9b46c8935b

+ 1
- 0
main.asm Wyświetl plik

@@ -43,6 +43,7 @@
43 43
 .include "patches/pokemon_data/pokemon_evolution.asm"
44 44
 
45 45
 .include "patches/overworlds/pkm_wild.asm"
46
+.include "patches/overworlds/trainer.asm"
46 47
 //.include "patches/dns/core.asm"
47 48
 
48 49
 .include "patches/overworlds/overworld.asm"

+ 2
- 2
makefile Wyświetl plik

@@ -12,7 +12,7 @@ STRAGB	:= string2agb
12 12
 
13 13
 export PATH := $(realpath ../tools):$(PATH)
14 14
 
15
-PAGB_MAIN := battle_engine/deps/pokeagb
15
+PAGB_MAIN := g3headers
16 16
 PAGB_INCLUDE := $(PAGB_MAIN)/build/include/
17 17
 PAGB_LINK := $(PAGB_MAIN)/build/linker/BPRE.ld
18 18
 
@@ -85,7 +85,7 @@ rom: main.asm $(MAIN_OBJ)
85 85
 	
86 86
 $(MAIN_OBJ): $(ALL_OBJ) $(ICONS_AR) $(SPRITES) $(MUSIC_AR) $(SMPL_AR) $(VOICE_AR) $(LIST_AR) $(CRY_AR) $(STRING_OBJ)#$(B_ENGINE)
87 87
 	$(MAKE) -f assets.makefile
88
-	$(LD) $(LDFLAGS) -T linker.ld -T bpre.sym --whole-archive -r -o $@ --start-group $^ --end-group
88
+	$(LD) $(LDFLAGS) -T $(PAGB_LINK) -T linker.ld -T bpre.sym --whole-archive -r -o $@ --start-group $^ --end-group
89 89
 
90 90
 .PHONY: $(B_ENGINE)
91 91
 $(B_ENGINE):

+ 5
- 0
patches/hooks.asm Wyświetl plik

@@ -100,6 +100,11 @@ _call_via_r1 equ 0x081E3BAC
100 100
 	bx r0
101 101
 	lsl r0, #0
102 102
 	.pool
103
+
104
+.org 0x0806E680
105
+    ldr r1, =flag_set|1
106
+    bx r1
107
+    .pool
103 108
 //end of flag routine
104 109
 
105 110
 //var routine

+ 1
- 1
patches/overworlds/trainer.asm Wyświetl plik

@@ -1,5 +1,5 @@
1 1
 .org 0x08081B84 
2
-ldr r1, =trainer_run_code+1
2
+ldr r1, =trainer_check_flag_on_spot+1
3 3
 bx r1
4 4
 .pool
5 5
 

+ 39
- 7
src/savefile/flag_manipulation.c Wyświetl plik

@@ -26,16 +26,11 @@
26 26
  * @date 25 may 2017
27 27
  * @brief functions for preserving flags and reusing difficulty
28 28
  */
29
+#include <pokeagb/pokeagb.h>
29 30
 
30 31
 #define TRAINER_FLAG_SPACE_START 0x1000
31 32
 
32
-#include <types.h>
33
-#include <agb_debug.h>
34
-#include <stdbool.h>
35
-#include <game_engine.h>
36
-#include <battle_structs.h>
37
-#include <config.h>
38
-
33
+extern u16 tb_modify_flag_id(u16 flag_id);
39 34
 u16 trainerflag_fix_difficulty(u16 flag_id);
40 35
 
41 36
 u16 load_hword(void* ptr)
@@ -46,6 +41,11 @@ u16 load_hword(void* ptr)
46 41
     return result | result2;
47 42
 }
48 43
 
44
+u8 load_byte(void* ptr)
45
+{
46
+    return (u8) (*((u8*)ptr));
47
+}
48
+
49 49
 u16 trainerflag_fix_difficulty(u16 flag_id)
50 50
 {
51 51
     u16 new_flag = ((flag_id - TRAINER_FLAG_SPACE_START + 1) / 3) + TRAINER_FLAG_SPACE_START;
@@ -53,6 +53,31 @@ u16 trainerflag_fix_difficulty(u16 flag_id)
53 53
     return new_flag;
54 54
 }
55 55
 
56
+bool trainer_check_flag_on_spot(u8 npc_id)
57
+{
58
+    void* script = npc_get_script_by_npc_id(npc_id);
59
+    /* probably inject some script execution here */
60
+
61
+    u16 flag = tb_modify_flag_id(load_hword(script+2));
62
+    /* check for line of sight */
63
+
64
+    u8 hit_result = npc_trainer_and_raycast_hit(&npc_states[npc_id]);
65
+
66
+    if(hit_result == 0)
67
+        return false;
68
+
69
+    if(flag_check(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START)))
70
+        return false;
71
+
72
+    if((load_byte(script + 1) == 4) && (player_cant_double_battle() > 0))
73
+        return false;
74
+    
75
+    spot_trainer_8080334(npc_id, script);
76
+    spot_trainer_8081E68(&npc_states[npc_id], hit_result -1);
77
+    return true;
78
+
79
+}
80
+
56 81
 u8 trainerflag_read_fix(void* script_location)
57 82
 {
58 83
     script_location+=2;
@@ -83,3 +108,10 @@ void trainerflag_clear_fix(u16 flag)
83 108
 {
84 109
     flag_clear(trainerflag_fix_difficulty(flag + TRAINER_FLAG_SPACE_START));
85 110
 }
111
+
112
+void flag_set(u16 flag)
113
+{
114
+    u8* addr = flag_byte_access(flag);
115
+    if(addr != NULL)
116
+        *addr |= 1 << (flag & 7);
117
+}