Browse Source

level up evolution

SBird1337 7 years ago
parent
commit
8a01e252f3
3 changed files with 90 additions and 1 deletions
  1. 2
    0
      bpre.sym
  2. 4
    0
      data/raw_defines.s
  3. 84
    1
      src/evolution/evolution_methods.c

+ 2
- 0
bpre.sym View File

@@ -162,6 +162,8 @@ party_opponent = 0x0202402C;
162 162
 pokemon_get_attribute = 0x0803FBE8|1;
163 163
 pokemon_set_attribute = 0x0804037C|1;
164 164
 
165
+pokemon_evolution_table = 08259754;
166
+
165 167
 
166 168
 battle_status3_bits_pbs = 0x02023DFC;
167 169
 

+ 4
- 0
data/raw_defines.s View File

@@ -6,6 +6,10 @@
6 6
 objects:
7 7
     .word 0x0202063C
8 8
 
9
+.global evolutions
10
+evolutions:
11
+    .word 0x08259754
12
+
9 13
 .global ts_pals
10 14
 ts_pals:
11 15
     .incbin "sots-private/assets/misc/title/pal.bin"

+ 84
- 1
src/evolution/evolution_methods.c View File

@@ -39,6 +39,66 @@ enum evo_source
39 39
     STONE_REQUEST
40 40
 };
41 41
 
42
+struct evo_information
43
+{
44
+    u16 method;
45
+    u16 argument;
46
+    u16 evolve_to;
47
+    u8 arg1;
48
+    u8 arg2;
49
+};
50
+
51
+struct evo_result
52
+{
53
+    u8 can_evolve;
54
+    u8 consume_item;
55
+    u8 evolve_to;
56
+};
57
+
58
+#define EVO_NULL {0,0,0,0,0}
59
+#define EVO_LEVEL_UP 4
60
+#define MAX_EVOLUTIONS 3
61
+
62
+struct evo_information evolutions[][MAX_EVOLUTIONS] = {
63
+    {EVO_NULL,EVO_NULL,EVO_NULL},
64
+    {{EVO_LEVEL_UP,16,2,0,0},EVO_NULL,EVO_NULL},
65
+    {{EVO_LEVEL_UP,32,3,0,0},EVO_NULL,EVO_NULL},
66
+};
67
+
68
+struct evo_call_arguments
69
+{
70
+    u16 item;
71
+    u16 level;
72
+    enum evo_source source;
73
+    u16 stoneId;
74
+    struct pokemon* poke;
75
+    struct evo_information evolution;
76
+};
77
+
78
+typedef struct evo_result (*evolution_callback)(struct evo_call_arguments);
79
+
80
+struct evo_result evolve_by_level(struct evo_call_arguments arguments)
81
+{
82
+    if(arguments.source != LEVEL_UP)
83
+    {
84
+        return (struct evo_result){false, false, 0};
85
+    }
86
+    if(arguments.evolution.argument <= arguments.level)
87
+    {
88
+        return (struct evo_result){true, false, arguments.evolution.evolve_to};
89
+    }
90
+    return (struct evo_result){false, false, 0};
91
+}
92
+
93
+static evolution_callback evolution_methods[] =
94
+{
95
+    NULL,
96
+    NULL, //TODO: Happiness
97
+    NULL, //TODO: Happiness DAY
98
+    NULL, //TODO: Happiness NIGHT
99
+    evolve_by_level
100
+};
101
+
42 102
 u16 evolution_try_evolve(struct pokemon* pokemon, enum evo_source source, u16 stoneId)
43 103
 {
44 104
     u16 held_item = pokemon_get_attribute(pokemon, ATTR_HELD_ITEM, NULL);
@@ -47,6 +107,29 @@ u16 evolution_try_evolve(struct pokemon* pokemon, enum evo_source source, u16 st
47 107
     //TODO PID
48 108
     dprintf("Species %d tried to evolve.\n", species);
49 109
     dprintf("Cause: %d\n", source);
50
-    dprintf("Held Item: %d; Level: %d\nBlocking evolution for debug.", held_item, level);
110
+    struct evo_information* current_evolution_structure = evolutions[species];
111
+    struct evo_result result;
112
+    for(int i = 0; i < MAX_EVOLUTIONS; ++i)
113
+    {
114
+        if(current_evolution_structure[i].method != 0)
115
+        {
116
+            dprintf("found valid evolution with method %d for species %d", current_evolution_structure[i].method, species);
117
+            struct evo_call_arguments args = {held_item, level, source, stoneId, pokemon, current_evolution_structure[i]};
118
+            result = evolution_methods[current_evolution_structure[i].method](args);
119
+            if(result.can_evolve)
120
+                break;
121
+        }
122
+    }
123
+    if(result.can_evolve)
124
+    {
125
+        if(result.consume_item)
126
+        {
127
+            //TODO: Consume
128
+        }
129
+        return result.evolve_to;
130
+    }
131
+    else
132
+        return 0;
133
+    /*evolve everything to mewtu for jiggs & giggles*/
51 134
     return 150;
52 135
 }