fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchAdd tech chase event (#317)1da5d99

master
12.1 KiB303 linesraw
1#ifndef MEX_H_COLLISION
2#define MEX_H_COLLISION
3
4#include "structs.h"
5#include "datatypes.h"
6#include "obj.h"
7
8// ECB Flags
9#define ECB_GROUND 0x18000
10#define ECB_CEIL 0x6000
11#define ECB_WALLLEFT 0xfc0
12#define ECB_WALLRIGHT 0x3f
13
14// Line Directions
15#define LINE_GROUND 1
16#define LINE_CEIL 2
17#define LINE_WALLRIGHT 4
18#define LINE_WALLLEFT 8
19
20/*** Enums ***/
21enum LineDirection
22{
23    LINEDIR_GROUND = 1 << 0,
24    LINEDIR_CEIL = 1 << 1,
25    LINEDIR_LEFTWALL = 1 << 2,
26    LINEDIR_RIGHTWALL = 1 << 3,
27};
28
29/*** Structs ***/
30
31struct ECBSize
32{
33    float topY;
34    float botY;
35    Vec2 left;
36    Vec2 right;
37};
38
39struct CollData
40{
41    GOBJ *gobj;                  // 0x0
42    Vec3 topN_Curr;              // 0x4
43    Vec3 topN_CurrCorrect;       // 0x10
44    Vec3 topN_Prev;              // 0x1c
45    Vec3 topN_Proj;              // 0x28
46    int flags1;                  // 0x34
47    int coll_test;               // 0x38, is the ID of the most recent collision test for this object
48    int ignore_line;             // 0x3c, ignores this line ID during collision
49    int ledge_left;              // 0x40, ledge ID in contact with
50    int ledge_right;             // 0x44, ledge ID in contact with
51    int ignore_group;            // 0x48  ignores this line group during collision
52    int check_group;             // 0x4c  checks only this line group during collision
53    float weight;                // 0x50
54    float cliffgrab_width;       // 0x54
55    float cliffgrab_y_offset;    // 0x58
56    float cliffgrab_height;      // 0x5c
57    int x60;                     // 0x60
58    int x64;                     // 0x64
59    int x68;                     // 0x68
60    int x6c;                     // 0x6c
61    int x70;                     // 0x70
62    int x74;                     // 0x74
63    int x78;                     // 0x78
64    int x7c;                     // 0x7c
65    int x80;                     // 0x80
66    Vec2 ecbCurr_top;            // 0x84
67    Vec2 ecbCurr_bot;            // 0x8C
68    Vec2 ecbCurr_right;          // 0x94
69    Vec2 ecbCurr_left;           // 0x9C
70    Vec2 ecbCurrCorrect_top;     // 0xA4
71    Vec2 ecbCurrCorrect_bot;     // 0xAC
72    Vec2 ecbCurrCorrect_right;   // 0xB4
73    Vec2 ecbCurrCorrect_left;    // 0xBC
74    Vec2 ecbPrev_top;            // 0xC4
75    Vec2 ecbPrev_bot;            // 0xCC
76    Vec2 ecbPrev_right;          // 0xD4
77    Vec2 ecbPrev_left;           // 0xDC
78    Vec2 ecbProj_top;            // 0xE4
79    Vec2 ecbProj_bot;            // 0xEC
80    Vec2 ecbProj_right;          // 0xF4
81    Vec2 ecbProj_left;           // 0xFC
82    int is_use_joints;           // 0x104, bool that signals to use the jobjs below for ecb edge positions
83    JOBJ *joint_1;               // 0x108
84    JOBJ *joint_2;               // 0x10c
85    JOBJ *joint_3;               // 0x110
86    JOBJ *joint_4;               // 0x114
87    JOBJ *joint_5;               // 0x118
88    JOBJ *joint_6;               // 0x11c
89    JOBJ *joint_7;               // 0x120
90    int x124;                    // 0x124
91    int x128;                    // 0x128
92    int x12c;                    // 0x12c
93    int flags;                   // 0x130, for fighters 0x10 is ecb lock enabled
94    int envFlags;                // 0x134
95    int envFlags_prev;           // 0x138
96    int x13c;                    // 0x13c
97    Vec2 coll_pos;               // 0x140, only updates for ceiling and ground?
98    int x148;                    // 0x148
99    int ground_index;            // 0x14c, ground
100    u8 ground_info;              // 0x150
101    u8 ground_unk;               // 0x151
102    u8 ground_type;              // 0x152, platform/ledgegrab
103    u8 ground_mat;               // 0x153, grass/ice etc
104    Vec3 ground_slope;           // 0x154
105    int rightwall_index;         // 0x160
106    u8 rightwall_info;           // 0x164
107    u8 rightwall_unk;            // 0x165
108    u8 rightwall_type;           // 0x166, platform/ledgegrab
109    u8 rightwall_mat;            // 0x167, grass/ice etc
110    Vec3 rightwall_slope;        // 0x168
111    int leftwall_index;          // 0x174
112    u8 leftwall_info;            // 0x178
113    u8 leftwall_unk;             // 0x179
114    u8 leftwall_type;            // 0x17A, platform/ledgegrab
115    u8 leftwall_mat;             // 0x17B, grass/ice etc
116    Vec3 leftwall_slope;         // 0x17C
117    int ceil_index;              // 0x188
118    u8 ceil_info;                // 0x18C
119    u8 ceil_unk;                 // 0x18D
120    u8 ceil_type;                // 0x18E, platform/ledgegrab
121    u8 ceil_mat;                 // 0x18F, grass/ice etc
122    Vec3 ceil_slope;             // 0x190
123    union                        // 0x19c,
124    {                            //
125        int ecb_bot_lock_frames; // fighters use this. frames until ecb bottom offset is no longer locked
126    } u;                         //
127};
128
129struct CollGroupDesc // exists in stage file
130{
131    u16 floor_start; // 0x0
132    u16 floor_num;
133    u16 ceil_start; // 0x4
134    u16 ceil_num;
135    u16 rwall_start; // 0x8
136    u16 rwall_num;
137    u16 lwall_start; // 0xC
138    u16 lwall_num;
139    u16 dyn_start; // 0x10
140    u16 dyn_num;
141    Vec2 area_min;  // 0x14
142    Vec2 area_max;  // 0x1C
143    u16 vert_start; // 0x24
144    u16 vert_num;   // 0x26
145};
146
147struct CollGroup // runtime struct
148{
149    CollGroup *next;      // 0x0
150    CollGroupDesc *desc;  // 0x4
151    u16 x8 : 15;          // 0x8, unk
152    u16 is_enabled : 1;   // 0x8, bit 0x01
153    u16 xa;               // unk, padding maybe
154    u16 ray_id;           // 0xC, id of the last raycast
155    u16 xe;               // 0xE, flags
156    Vec2 area_min;        // 0x10
157    Vec2 area_max;        // 0x18
158    JOBJ *jobj;           // 0x20
159    void *cb_floor;       // 0x24
160    void *map_data_floor; // 0x28
161    void *cb_ceil;        // 0x2C
162    void *map_data_ceil;  // 0x30
163};
164
165struct CollLineDesc // exists in stage file
166{
167    s16 vert_prev;          // 0x0
168    s16 vert_next;          // 0x2
169    s16 line_prev;          // 0x4
170    s16 line_next;          // 0x6
171    s16 line_prev_altgroup; // 0x8
172    s16 line_next_altgroup; // 0xA
173    u8 xc;
174    u8 xd_1 : 1;     // 0xD, 0x80
175    u8 xd_2 : 1;     // 0xD, 0x40
176    u8 xd_3 : 1;     // 0xD, 0x20
177    u8 disabled : 1; // 0xD, 0x10
178    u8 is_left : 1;  // 0xD, 0x08
179    u8 is_right : 1; // 0xD, 0x04
180    u8 is_ceil : 1;  // 0xD, 0x02
181    u8 is_floor : 1; // 0xD, 0x01
182    u8 xe_1 : 1;     // 0xE, 0x80
183    u8 xe_2 : 1;     // 0xE, 0x40
184    u8 xe_3 : 1;     // 0xE, 0x20
185    u8 xe_4 : 1;     // 0xE, 0x10
186    u8 xe_5 : 1;     // 0xE, 0x08
187    u8 is_drop : 1;  // 0xE, 0x04
188    u8 is_ledge : 1; // 0xE, 0x02
189    u8 is_unk : 1;   // 0xE, 0x01
190    u8 material;     // 0xF,
191};
192
193struct CollLine // runtime struct
194{
195    CollLineDesc *desc; // 0x0, (previously info)
196    u8 x4;              // 0x4
197    u8 x5_x80 : 1;      // 0x5, 0x80
198    u8 x5_x40 : 1;      // 0x5, 0x40
199    u8 x5_x20 : 1;      // 0x5, 0x20
200    u8 x5_x10 : 1;      // 0x5, 0x10
201    u8 x5_x08 : 1;      // 0x5, 0x08
202    u8 x5_x04 : 1;      // 0x5, 0x04
203    u8 x5_x02 : 1;      // 0x5, 0x02
204    u8 is_enabled : 1;  // 0x5, 0x01
205    u8 x6;              // 0x6
206    u8 x7 : 4;          // 0x7
207    u8 is_rwall : 1;    // 0x7, 0x8
208    u8 is_lwall : 1;    // 0x7, 0x4
209    u8 is_ceil : 1;     // 0x7, 0x2
210    u8 is_floor : 1;    // 0x7, 0x1
211};
212
213struct CollVert
214{
215    Vec2 pos_orig;
216    Vec2 pos_curr;
217    Vec2 pos_prev;
218};
219
220struct CollLineUnk
221{
222    int x0;
223    s16 x4;
224    s16 x6;
225    Vec3 left;  // 0x8
226    Vec3 right; // 0x14
227};
228
229struct CollDataStage
230{
231    Vec2 *verts;           // 0x0, array of vec2's
232    int vert_num;          // 0x4
233    CollLineDesc *lines;   // 0x8, array of line descs
234    int line_num;          // 0xC
235    u16 floor_start;       // 0x10
236    u16 floor_num;         // 0x12
237    u16 ceil_start;        // 0x14
238    u16 ceil_num;          // 0x16
239    u16 rwall_start;       // 0x18
240    u16 rwall_num;         // 0x1a
241    u16 lwall_start;       // 0x1c
242    u16 lwall_num;         // 0x1e
243    u16 dyn_start;         // 0x20
244    u16 dyn_num;           // 0x22
245    CollGroupDesc *groups; // 0x24
246    int group_num;         // 0x28
247};
248
249struct CollLineConnection // runtime struct, is created @ 8005a7cc, static array of these for each line direction @ 80458e88
250{
251    CollLineConnection *next; // 0x0
252    int x4;                   // 0x4
253    Vec3 start_pos;           // 0x8
254    Vec3 end_pos;             // 0x14
255    int x20;                  // 0x20
256    int x24;                  // 0x24
257};
258
259/*** Functions ***/
260void Shield_CreateBubble(GOBJ *ft, ShieldDesc *desc, void *(on_hit)(GOBJ *fighter));
261void Shield_HitShield(GOBJ *ft);
262void GuardReflectInitIDK(GOBJ *ft);
263void GuardOnInitIDK(GOBJ *ft);
264void Animation_GuardAgain(GOBJ *ft);
265void EnvironmentCollision_WaitLanding(GOBJ *ft);
266void Coll_CopyPosToECBs(CollData *coll_data, Vec3 *pos);
267void Coll_ECBCurrToPrev(CollData *coll_data);
268void Coll_InitECB(CollData *coll_data);
269void Coll_SetECBScale(CollData *coll_data, float scale1, float scale2, float scale3, float scale4);
270int Coll_CheckLedge(CollData *coll_data);
271float Coll_GetCurrGroundsFrictionMult(CollData *);
272int ECB_CollGround_PassLedge(CollData *ecb, ECBSize *bones); // returns is touching ground bool
273int ECB_CollGround3(CollData *ecb);
274void ECB_CollAir(CollData *ecb, ECBSize *bones);
275int ECB_CollAir2(CollData *ecb);
276int ECB_CollAir3(CollData *ecb);
277int ECB_CollAirCheckLedge(CollData *ecb);
278int ECB_CollGround(CollData *ecb);
279int ECB_StoreLedgeCheckDirection(CollData *ecb, int ledge_check_dir);
280int GrColl_SearchLedgeLeft(CollData *coll_data, int *return_ledge_index);
281int GrColl_SearchLedgeRight(CollData *coll_data, int *return_ledge_index);
282void GrColl_GetGroundLineEndLeft(int floor_index, Vec3 *pos);                                                                                                                                    // returns the leftmost grounded coordinate of the inputted line index within its group                                                                                                                                 // this functon will crawl along the entire line sequence and find the end of the ledge
283void GrColl_GetGroundLineEndRight(int floor_index, Vec3 *pos);                                                                                                                                   // returns the rightmost grounded coordinate of the inputted line index within its group
284void GrColl_GetGroundLineEndLeft_AllGroups(int floor_index, Vec3 *pos);                                                                                                                          // returns the leftmost grounded coordinate of the inputted line index regardless of the group
285void GrColl_GetGroundLineEndRight_AllGroups(int floor_index, Vec3 *pos);                                                                                                                         // returns the rightmost grounded coordinate of the inputted line index regardless of the group
286int GrColl_RaycastGround(Vec3 *coll_pos, int *line_index, int *line_kind, Vec3 *unk1, int unk2, int unk3, int unk4, void *cb, float fromX, float fromY, float toX, float toY, float unk5); // make unk5
287int GrColl_RaycastUnk(Vec3 *coll_pos, int *line_index, int *line_kind, Vec3 *direction, void *cb, void *unk2, float from_x, float from_y, float to_x, float to_y);                                   // unk = 0, unk2 = -1;
288int GrColl_RaycastAll(Vec3 *coll_pos, int *line_index, int *line_kind, Vec3 *direction, void *cb, void *unk2, float from_x, float from_y, float to_x, float to_y);
289int GrColl_CrawlGround(int line_index, Vec3 *pos, int *return_line, Vec3 *return_pos, int *return_flags, Vec3 *return_slope, float x_offset, float y_offset);                                    // returns bool for if position on line series exists
290int GrColl_GetPosDifference(int line_index, Vec3 *pos, Vec3 *return_pos);
291int GrColl_GetLineInfo(int line_index, Vec3 *r4, void *r5, int *flags, Vec3 *return_slope);
292void GrColl_GetLineSlope(int line_index, Vec3 *return_slope);
293int GrColl_CheckIfLineEnabled(int line_index);
294
295static int *stc_colltest = R13_OFFSET(-0x51F4);
296static CollGroup **stc_firstcollgroup = R13_OFFSET(-0x51DC);
297static CollGroup **stc_collgroup = R13_OFFSET(-0x51E0);
298static CollLine **stc_collline = R13_OFFSET(-0x51E4);
299static CollVert **stc_collvert = R13_OFFSET(-0x51E8);
300static CollDataStage **stc_colldata = R13_OFFSET(-0x51EC);
301static CollLineConnection **stc_first_line_connect = (void *)0x80458e88; // array of 9
302
303#endif