|
@@ -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
|
+}
|