From 5e6eb4fbcc454947ab1a80a083d5d0fb222d889e Mon Sep 17 00:00:00 2001 From: coco875 Date: Fri, 20 Dec 2024 04:23:37 +0100 Subject: [PATCH] document waypoint and more --- .../code_80005FD0/func_8000929C.s | 2 +- .../code_80005FD0/func_80009B60.s | 36 +- .../code_80005FD0/func_80017054.s | 20 +- .../code_80005FD0/kart_ai_use_item_strategy.s | 4 +- include/course.h | 6 +- include/defines.h | 1 + include/waypoints.h | 26 +- src/camera.c | 2 +- src/code_80005FD0.c | 639 +++++++++--------- src/code_80005FD0.h | 30 +- src/code_8003DC40.c | 1 + src/effects.c | 14 +- src/math_util_2.h | 2 + src/racing/race_logic.c | 4 +- src/spawn_players.c | 8 +- 15 files changed, 414 insertions(+), 381 deletions(-) diff --git a/asm/non_matchings/code_80005FD0/func_8000929C.s b/asm/non_matchings/code_80005FD0/func_8000929C.s index f31cb788f..c809a5d98 100644 --- a/asm/non_matchings/code_80005FD0/func_8000929C.s +++ b/asm/non_matchings/code_80005FD0/func_8000929C.s @@ -328,7 +328,7 @@ glabel func_8000929C /* 00A340 80009740 304C1000 */ andi $t4, $v0, 0x1000 /* 00A344 80009744 1580001E */ bnez $t4, .L800097C0 /* 00A348 80009748 01402825 */ move $a1, $t2 -/* 00A34C 8000974C 0C001974 */ jal func_800065D0 +/* 00A34C 8000974C 0C001974 */ jal detect_player_wrong_direction /* 00A350 80009750 AFA40050 */ sw $a0, 0x50($sp) /* 00A354 80009754 3C0D800E */ lui $t5, %hi(gModeSelection) /* 00A358 80009758 8DADC53C */ lw $t5, %lo(gModeSelection)($t5) diff --git a/asm/non_matchings/code_80005FD0/func_80009B60.s b/asm/non_matchings/code_80005FD0/func_80009B60.s index 87bb29360..9ac0fdb76 100644 --- a/asm/non_matchings/code_80005FD0/func_80009B60.s +++ b/asm/non_matchings/code_80005FD0/func_80009B60.s @@ -349,10 +349,10 @@ glabel func_80009B60 /* 00AC08 8000A008 8FB90038 */ lw $t9, 0x38($sp) /* 00AC0C 8000A00C AFAE0024 */ sw $t6, 0x24($sp) /* 00AC10 8000A010 00027880 */ sll $t7, $v0, 2 -/* 00AC14 8000A014 3C0D8016 */ lui $t5, %hi(D_80164550) # 0x8016 +/* 00AC14 8000A014 3C0D8016 */ lui $t5, %hi(gTrackWaypoints) # 0x8016 /* 00AC18 8000A018 95D80000 */ lhu $t8, ($t6) /* 00AC1C 8000A01C 01AF6821 */ addu $t5, $t5, $t7 -/* 00AC20 8000A020 8DAD4550 */ lw $t5, %lo(D_80164550)($t5) # 0x4550($t5) +/* 00AC20 8000A020 8DAD4550 */ lw $t5, %lo(gTrackWaypoints)($t5) # 0x4550($t5) /* 00AC24 8000A024 032A3021 */ addu $a2, $t9, $t2 /* 00AC28 8000A028 0018C8C0 */ sll $t9, $t8, 3 /* 00AC2C 8000A02C 01B95021 */ addu $t2, $t5, $t9 @@ -569,8 +569,8 @@ glabel func_80009B60 /* 00AF48 8000A348 0C00350E */ jal func_8000D438 /* 00AF4C 8000A34C 8FA400D0 */ lw $a0, 0xd0($sp) /* 00AF50 8000A350 8FA60040 */ lw $a2, 0x40($sp) -/* 00AF54 8000A354 3C078016 */ lui $a3, %hi(D_80162FA0) # $a3, 0x8016 -/* 00AF58 8000A358 24E72FA0 */ addiu $a3, %lo(D_80162FA0) # addiu $a3, $a3, 0x2fa0 +/* 00AF54 8000A354 3C078016 */ lui $a3, %hi(gOffsetPosition) # $a3, 0x8016 +/* 00AF58 8000A358 24E72FA0 */ addiu $a3, %lo(gOffsetPosition) # addiu $a3, $a3, 0x2fa0 /* 00AF5C 8000A35C 8CC200BC */ lw $v0, 0xbc($a2) /* 00AF60 8000A360 C4E80000 */ lwc1 $f8, ($a3) /* 00AF64 8000A364 C4EA0008 */ lwc1 $f10, 8($a3) @@ -593,7 +593,7 @@ glabel func_80009B60 /* 00AFA8 8000A3A8 3C0B8016 */ lui $t3, %hi(D_801630E0) # 0x8016 /* 00AFAC 8000A3AC 3C0C8016 */ lui $t4, %hi(D_80164430) # $t4, 0x8016 /* 00AFB0 8000A3B0 3C198016 */ lui $t9, %hi(D_80163448) # 0x8016 -/* 00AFB4 8000A3B4 3C0F8016 */ lui $t7, %hi(D_80164590) # 0x8016 +/* 00AFB4 8000A3B4 3C0F8016 */ lui $t7, %hi(gWaypointExpectedRotation) # 0x8016 /* 00AFB8 8000A3B8 46062200 */ add.s $f8, $f4, $f6 /* 00AFBC 8000A3BC 4608903C */ c.lt.s $f18, $f8 /* 00AFC0 8000A3C0 00000000 */ nop @@ -608,10 +608,10 @@ glabel func_80009B60 /* 00AFE4 8000A3E4 AFA8003C */ sw $t0, 0x3c($sp) /* 00AFE8 8000A3E8 8FAB0034 */ lw $t3, 0x34($sp) /* 00AFEC 8000A3EC 3C0E8016 */ lui $t6, %hi(D_80162FF8) # 0x8016 -/* 00AFF0 8000A3F0 3C078016 */ lui $a3, %hi(D_80162FA0) # $a3, 0x8016 +/* 00AFF0 8000A3F0 3C078016 */ lui $a3, %hi(gOffsetPosition) # $a3, 0x8016 /* 00AFF4 8000A3F4 01CB7021 */ addu $t6, $t6, $t3 /* 00AFF8 8000A3F8 85CE2FF8 */ lh $t6, %lo(D_80162FF8)($t6) # 0x2ff8($t6) -/* 00AFFC 8000A3FC 24E72FA0 */ addiu $a3, %lo(D_80162FA0) # addiu $a3, $a3, 0x2fa0 +/* 00AFFC 8000A3FC 24E72FA0 */ addiu $a3, %lo(gOffsetPosition) # addiu $a3, $a3, 0x2fa0 /* 00B000 8000A400 8FA8003C */ lw $t0, 0x3c($sp) /* 00B004 8000A404 19C0001F */ blez $t6, .L8000A484 /* 00B008 8000A408 3C048016 */ lui $a0, %hi(D_801630E0) # $a0, 0x8016 @@ -644,8 +644,8 @@ glabel func_80009B60 /* 00B06C 8000A46C 84C6344A */ lh $a2, %lo(D_80163448 + 2)($a2) /* 00B070 8000A470 0C002EF6 */ jal func_8000BBD8 /* 00B074 8000A474 AFA8003C */ sw $t0, 0x3c($sp) -/* 00B078 8000A478 3C078016 */ lui $a3, %hi(D_80162FA0) # $a3, 0x8016 -/* 00B07C 8000A47C 24E72FA0 */ addiu $a3, %lo(D_80162FA0) # addiu $a3, $a3, 0x2fa0 +/* 00B078 8000A478 3C078016 */ lui $a3, %hi(gOffsetPosition) # $a3, 0x8016 +/* 00B07C 8000A47C 24E72FA0 */ addiu $a3, %lo(gOffsetPosition) # addiu $a3, $a3, 0x2fa0 /* 00B080 8000A480 8FA8003C */ lw $t0, 0x3c($sp) .L8000A484: /* 00B084 8000A484 8FA60040 */ lw $a2, 0x40($sp) @@ -667,7 +667,7 @@ glabel func_80009B60 /* 00B0BC 8000A4BC 01CC001A */ div $zero, $t6, $t4 /* 00B0C0 8000A4C0 00196880 */ sll $t5, $t9, 2 /* 00B0C4 8000A4C4 01ED7821 */ addu $t7, $t7, $t5 -/* 00B0C8 8000A4C8 8DEF4590 */ lw $t7, %lo(D_80164590)($t7) # 0x4590($t7) +/* 00B0C8 8000A4C8 8DEF4590 */ lw $t7, %lo(gWaypointExpectedRotation)($t7) # 0x4590($t7) /* 00B0CC 8000A4CC 0000C010 */ mfhi $t8 /* 00B0D0 8000A4D0 00185040 */ sll $t2, $t8, 1 /* 00B0D4 8000A4D4 15800002 */ bnez $t4, .L8000A4E0 @@ -1092,8 +1092,8 @@ glabel func_80009B60 /* 00B6CC 8000AACC 24010003 */ li $at, 3 /* 00B6D0 8000AAD0 004A1021 */ addu $v0, $v0, $t2 /* 00B6D4 8000AAD4 84423410 */ lh $v0, %lo(D_80163410)($v0) # 0x3410($v0) -/* 00B6D8 8000AAD8 3C078016 */ lui $a3, %hi(D_80162FA0) # $a3, 0x8016 -/* 00B6DC 8000AADC 24E72FA0 */ addiu $a3, %lo(D_80162FA0) # addiu $a3, $a3, 0x2fa0 +/* 00B6D8 8000AAD8 3C078016 */ lui $a3, %hi(gOffsetPosition) # $a3, 0x8016 +/* 00B6DC 8000AADC 24E72FA0 */ addiu $a3, %lo(gOffsetPosition) # addiu $a3, $a3, 0x2fa0 /* 00B6E0 8000AAE0 10410005 */ beq $v0, $at, .L8000AAF8 /* 00B6E4 8000AAE4 24010004 */ li $at, 4 /* 00B6E8 8000AAE8 1041000C */ beq $v0, $at, .L8000AB1C @@ -1117,16 +1117,16 @@ glabel func_80009B60 /* 00B728 8000AB28 030CC021 */ addu $t8, $t8, $t4 /* 00B72C 8000AB2C 971845C8 */ lhu $t8, %lo(gWaypointCountByPathIndex)($t8) # 0x45c8($t8) /* 00B730 8000AB30 25EB000A */ addiu $t3, $t7, 0xa -/* 00B734 8000AB34 3C0A8016 */ lui $t2, %hi(D_80164550) # 0x8016 +/* 00B734 8000AB34 3C0A8016 */ lui $t2, %hi(gTrackWaypoints) # 0x8016 /* 00B738 8000AB38 0178001A */ div $zero, $t3, $t8 /* 00B73C 8000AB3C 01495021 */ addu $t2, $t2, $t1 -/* 00B740 8000AB40 8D4A4550 */ lw $t2, %lo(D_80164550)($t2) # 0x4550($t2) +/* 00B740 8000AB40 8D4A4550 */ lw $t2, %lo(gTrackWaypoints)($t2) # 0x4550($t2) /* 00B744 8000AB44 0000C810 */ mfhi $t9 /* 00B748 8000AB48 001970C0 */ sll $t6, $t9, 3 /* 00B74C 8000AB4C 01CA1021 */ addu $v0, $t6, $t2 /* 00B750 8000AB50 844D0000 */ lh $t5, ($v0) -/* 00B754 8000AB54 3C078016 */ lui $a3, %hi(D_80162FA0) # $a3, 0x8016 -/* 00B758 8000AB58 24E72FA0 */ addiu $a3, %lo(D_80162FA0) # addiu $a3, $a3, 0x2fa0 +/* 00B754 8000AB54 3C078016 */ lui $a3, %hi(gOffsetPosition) # $a3, 0x8016 +/* 00B758 8000AB58 24E72FA0 */ addiu $a3, %lo(gOffsetPosition) # addiu $a3, $a3, 0x2fa0 /* 00B75C 8000AB5C 448D9000 */ mtc1 $t5, $f18 /* 00B760 8000AB60 17000002 */ bnez $t8, .L8000AB6C /* 00B764 8000AB64 00000000 */ nop @@ -1148,9 +1148,9 @@ glabel func_80009B60 /* 00B79C 8000AB9C E4F00008 */ swc1 $f16, 8($a3) .L8000ABA0: /* 00B7A0 8000ABA0 3C0C8016 */ lui $t4, %hi(D_80163178) # $t4, 0x8016 -/* 00B7A4 8000ABA4 3C078016 */ lui $a3, %hi(D_80162FA0) # 0x8016 +/* 00B7A4 8000ABA4 3C078016 */ lui $a3, %hi(gOffsetPosition) # 0x8016 /* 00B7A8 8000ABA8 258C3178 */ addiu $t4, %lo(D_80163178) # addiu $t4, $t4, 0x3178 -/* 00B7AC 8000ABAC 24E52FA0 */ addiu $a1, $a3, %lo(D_80162FA0) # 0x2fa0 +/* 00B7AC 8000ABAC 24E52FA0 */ addiu $a1, $a3, %lo(gOffsetPosition) # 0x2fa0 /* 00B7B0 8000ABB0 012C1021 */ addu $v0, $t1, $t4 /* 00B7B4 8000ABB4 C4460000 */ lwc1 $f6, ($v0) /* 00B7B8 8000ABB8 C4A40000 */ lwc1 $f4, ($a1) diff --git a/asm/non_matchings/code_80005FD0/func_80017054.s b/asm/non_matchings/code_80005FD0/func_80017054.s index de71136a5..87decc72f 100644 --- a/asm/non_matchings/code_80005FD0/func_80017054.s +++ b/asm/non_matchings/code_80005FD0/func_80017054.s @@ -136,8 +136,8 @@ glabel func_80017054 /* 017E24 80017224 3044FFFF */ andi $a0, $v0, 0xffff /* 017E28 80017228 0C002EF6 */ jal func_8000BBD8 /* 017E2C 8001722C AFA6003C */ sw $a2, 0x3c($sp) -/* 017E30 80017230 3C038016 */ lui $v1, %hi(D_80162FA0) # $v1, 0x8016 -/* 017E34 80017234 24632FA0 */ addiu $v1, %lo(D_80162FA0) # addiu $v1, $v1, 0x2fa0 +/* 017E30 80017230 3C038016 */ lui $v1, %hi(gOffsetPosition) # $v1, 0x8016 +/* 017E34 80017234 24632FA0 */ addiu $v1, %lo(gOffsetPosition) # addiu $v1, $v1, 0x2fa0 /* 017E38 80017238 C4660000 */ lwc1 $f6, ($v1) /* 017E3C 8001723C 3C013FE0 */ li $at, 0x3FE00000 # 1.750000 /* 017E40 80017240 44810800 */ mtc1 $at, $f1 @@ -156,8 +156,8 @@ glabel func_80017054 /* 017E74 80017274 E7A40084 */ swc1 $f4, 0x84($sp) /* 017E78 80017278 0C002EF6 */ jal func_8000BBD8 /* 017E7C 8001727C 8F050000 */ lw $a1, ($t8) -/* 017E80 80017280 3C038016 */ lui $v1, %hi(D_80162FA0) # $v1, 0x8016 -/* 017E84 80017284 24632FA0 */ addiu $v1, %lo(D_80162FA0) # addiu $v1, $v1, 0x2fa0 +/* 017E80 80017280 3C038016 */ lui $v1, %hi(gOffsetPosition) # $v1, 0x8016 +/* 017E84 80017284 24632FA0 */ addiu $v1, %lo(gOffsetPosition) # addiu $v1, $v1, 0x2fa0 /* 017E88 80017288 C46A0000 */ lwc1 $f10, ($v1) /* 017E8C 8001728C C7A6008C */ lwc1 $f6, 0x8c($sp) /* 017E90 80017290 3C013FE0 */ li $at, 0x3FE00000 # 1.750000 @@ -201,9 +201,9 @@ glabel func_80017054 /* 017F20 80017320 8FAC005C */ lw $t4, 0x5c($sp) /* 017F24 80017324 000D7403 */ sra $t6, $t5, 0x10 /* 017F28 80017328 01C01025 */ move $v0, $t6 -/* 017F2C 8001732C 3C0E8016 */ lui $t6, %hi(D_80164550) # $t6, 0x8016 +/* 017F2C 8001732C 3C0E8016 */ lui $t6, %hi(gTrackWaypoints) # $t6, 0x8016 /* 017F30 80017330 00004810 */ mfhi $t1 -/* 017F34 80017334 25CE4550 */ addiu $t6, %lo(D_80164550) # addiu $t6, $t6, 0x4550 +/* 017F34 80017334 25CE4550 */ addiu $t6, %lo(gTrackWaypoints) # addiu $t6, $t6, 0x4550 /* 017F38 80017338 000C6880 */ sll $t5, $t4, 2 /* 017F3C 8001733C 0009C400 */ sll $t8, $t1, 0x10 /* 017F40 80017340 01AE5021 */ addu $t2, $t5, $t6 @@ -272,8 +272,8 @@ glabel func_80017054 /* 018024 80017424 A7AF006C */ sh $t7, 0x6c($sp) /* 018028 80017428 0C002EF6 */ jal func_8000BBD8 /* 01802C 8001742C A7A2006E */ sh $v0, 0x6e($sp) -/* 018030 80017430 3C038016 */ lui $v1, %hi(D_80162FA0) # $v1, 0x8016 -/* 018034 80017434 24632FA0 */ addiu $v1, %lo(D_80162FA0) # addiu $v1, $v1, 0x2fa0 +/* 018030 80017430 3C038016 */ lui $v1, %hi(gOffsetPosition) # $v1, 0x8016 +/* 018034 80017434 24632FA0 */ addiu $v1, %lo(gOffsetPosition) # addiu $v1, $v1, 0x2fa0 /* 018038 80017438 C4660000 */ lwc1 $f6, ($v1) /* 01803C 8001743C 3C013FE0 */ li $at, 0x3FE00000 # 1.750000 /* 018040 80017440 44810800 */ mtc1 $at, $f1 @@ -292,8 +292,8 @@ glabel func_80017054 /* 018074 80017474 E7AE0098 */ swc1 $f14, 0x98($sp) /* 018078 80017478 0C002EF6 */ jal func_8000BBD8 /* 01807C 8001747C E7B00090 */ swc1 $f16, 0x90($sp) -/* 018080 80017480 3C038016 */ lui $v1, %hi(D_80162FA0) # $v1, 0x8016 -/* 018084 80017484 24632FA0 */ addiu $v1, %lo(D_80162FA0) # addiu $v1, $v1, 0x2fa0 +/* 018080 80017480 3C038016 */ lui $v1, %hi(gOffsetPosition) # $v1, 0x8016 +/* 018084 80017484 24632FA0 */ addiu $v1, %lo(gOffsetPosition) # addiu $v1, $v1, 0x2fa0 /* 018088 80017488 C4640000 */ lwc1 $f4, ($v1) /* 01808C 8001748C 3C013FE0 */ li $at, 0x3FE00000 # 1.750000 /* 018090 80017490 44810800 */ mtc1 $at, $f1 diff --git a/asm/non_matchings/code_80005FD0/kart_ai_use_item_strategy.s b/asm/non_matchings/code_80005FD0/kart_ai_use_item_strategy.s index 6e1f08c5a..f23ae42fe 100644 --- a/asm/non_matchings/code_80005FD0/kart_ai_use_item_strategy.s +++ b/asm/non_matchings/code_80005FD0/kart_ai_use_item_strategy.s @@ -398,11 +398,11 @@ glabel L8001B0EC /* 01BD9C 8001B19C 01EB7821 */ addu $t7, $t7, $t3 /* 01BDA0 8001B1A0 95EF45C8 */ lhu $t7, %lo(gWaypointCountByPathIndex)($t7) # 0x45c8($t7) /* 01BDA4 8001B1A4 952D0000 */ lhu $t5, ($t1) -/* 01BDA8 8001B1A8 3C0B8016 */ lui $t3, %hi(D_80164550) # 0x8016 +/* 01BDA8 8001B1A8 3C0B8016 */ lui $t3, %hi(gTrackWaypoints) # 0x8016 /* 01BDAC 8001B1AC 018F001A */ div $zero, $t4, $t7 /* 01BDB0 8001B1B0 000DC880 */ sll $t9, $t5, 2 /* 01BDB4 8001B1B4 01795821 */ addu $t3, $t3, $t9 -/* 01BDB8 8001B1B8 8D6B4550 */ lw $t3, %lo(D_80164550)($t3) # 0x4550($t3) +/* 01BDB8 8001B1B8 8D6B4550 */ lw $t3, %lo(gTrackWaypoints)($t3) # 0x4550($t3) /* 01BDBC 8001B1BC 00007010 */ mfhi $t6 /* 01BDC0 8001B1C0 000EC0C0 */ sll $t8, $t6, 3 /* 01BDC4 8001B1C4 030B1021 */ addu $v0, $t8, $t3 diff --git a/include/course.h b/include/course.h index ff99e5933..e3fec600d 100644 --- a/include/course.h +++ b/include/course.h @@ -18,9 +18,9 @@ typedef struct { } TrackSections; struct _struct_gCoursePathSizes_0x10 { - /* 0x00 */ u16 unk0; - /* 0x02 */ u16 unk2; - /* 0x04 */ u16 unk4; + /* 0x00 */ u16 numWaypoint; + /* 0x02 */ u16 numInnerWaypoint; + /* 0x04 */ u16 numOuterWaypoint; /* 0x06 */ u16 unk6; /* 0x08 */ u16 unk8; /* 0x0A */ char padA[6]; diff --git a/include/defines.h b/include/defines.h index ec8bb4f43..949c19749 100644 --- a/include/defines.h +++ b/include/defines.h @@ -325,6 +325,7 @@ enum DIRECTION { NORTH, EAST, SOUTH, WEST }; #define STAR_EFFECT 0x200 // being a star #define BOOST_EFFECT 0x2000 // being boosted by trigger a mushroom #define BOOST_RAMP_ASPHALT_EFFECT 0x100000 // being boosted by a boost pad +#define REVERSE_EFFECT 0x400000 // being in reverse of the course #define HIT_BY_ITEM_EFFECT 0x2000000 // being hit by an item #define HIT_EFFECT 0x4000000 // hitting an object #define LIGHTNING_EFFECT 0x40000000 // being hit by lightning diff --git a/include/waypoints.h b/include/waypoints.h index 2583e8a11..ad5acf5d8 100644 --- a/include/waypoints.h +++ b/include/waypoints.h @@ -12,46 +12,46 @@ typedef struct { /** * These are per-path arrays that contain some information relating to waypoints - * The arrays in D_80164550 contain X/Y/Z and track segment information - * The arrays in D_80164560 and D_80164570 track some other X/Y/Z, but the track segment is always 0 (so, + * The arrays in gTrackWaypoints contain X/Y/Z and track segment information + * The arrays in gTrackInnerPath and gTrackOuterPath track some other X/Y/Z, but the track segment is always 0 (so, *untracked/unused) Its unclear how these arrays relate to each other **/ -extern TrackWaypoint* D_80164550[]; -extern TrackWaypoint* D_80164560[]; -extern TrackWaypoint* D_80164570[]; +extern TrackWaypoint* gTrackWaypoints[]; +extern TrackWaypoint* gTrackInnerPath[]; +extern TrackWaypoint* gTrackOuterPath[]; /** - * Don't know what exactly these are, but like D_80164550, D_80164560, and D_80164570 + * Don't know what exactly these are, but like gTrackWaypoints, gTrackInnerPath, and gTrackOuterPath * they track something about the waypoints on a per-path basis **/ // Waypoint types? extern s16* D_80164580[]; // Based on func_80010DBC this may be angles between waypoints -// D_80164590[i] = atan2(waypoint_i, waypoint_i+1)? -extern s16* D_80164590[]; +// gWaypointExpectedRotation[i] = atan2(waypoint_i, waypoint_i+1)? +extern s16* gWaypointExpectedRotation[]; // No idea. Adjacency list? extern s16* D_801645A0[]; /** * Certain parts of the waypoint logic will copy some path/player specific data to a temporary variable. - * For example: D_80164490 is always a value from D_80164550. Depending on which path + * For example: D_80164490 is always a value from gTrackWaypoints. Depending on which path * a given player is on, the specific value may change **/ // Shadows values from gNearestWaypointByPlayerId extern s16 sSomeNearestWaypoint; // Shadows values from gPathIndexByPlayerId extern s32 D_80163448; -// Shadows values from D_80164560 +// Shadows values from gTrackInnerPath extern TrackWaypoint* D_801631D0; -// Shadows values from D_80164570 +// Shadows values from gTrackOuterPath extern TrackWaypoint* D_801631D4; // Shadows values from D_80164580 extern s16* D_801631D8; -// Shadows values from D_80164590 +// Shadows values from gWaypointExpectedRotation extern s16* D_801631DC; // Shadowd values from gWaypointCountByPathIndex extern u16 D_80164430; -// Shadows values from D_80164550 +// Shadows values from gTrackWaypoints extern TrackWaypoint* D_80164490; // Shadows values from D_801645A0 extern s16* D_801645E0; diff --git a/src/camera.c b/src/camera.c index 8cc8b8e45..98992f7d0 100644 --- a/src/camera.c +++ b/src/camera.c @@ -223,7 +223,7 @@ void func_8001CA78(UNUSED Player* player, Camera* camera, Vec3f arg2, f32* arg3, UNUSED s32 pad; TrackWaypoint* temp_s2; - temp_s2 = &D_80164550[0][gWaypointCountByPathIndex[0] - 10]; + temp_s2 = &gTrackWaypoints[0][gWaypointCountByPathIndex[0] - 10]; sp68[0] = camera->unk_30[0]; sp68[1] = camera->unk_30[1]; sp68[2] = camera->unk_30[2]; diff --git a/src/code_80005FD0.c b/src/code_80005FD0.c index 2c76be345..750a401b4 100644 --- a/src/code_80005FD0.c +++ b/src/code_80005FD0.c @@ -30,6 +30,7 @@ #include "spawn_players.h" #include "sounds.h" #include "data/path_spawn_metadata.h" +#include "math_util_2.h" s32 unk_code_80005FD0_pad[24]; Collision D_80162E70; @@ -47,7 +48,7 @@ s16 D_80162F50[30]; // padding, seemingly? s32 D_80162F90[4]; -Vec3f D_80162FA0; +Vec3f gOffsetPosition; Vec3f D_80162FB0; Vec3f D_80162FC0; s16 gTrainSmokeTimer; @@ -88,8 +89,8 @@ f32 D_8016320C; f32 D_80163210[10]; s32 D_80163238; u16 D_80163240[12]; -u16 D_80163258[12]; -u16 D_80163270[12]; +u16 gWrongDirectionCounter[12]; +u16 gIsPlayerWrongDirection[12]; s32 D_80163288[10]; KartAIBehaviour* sCurrentKartAIBehaviour; u16 gCurrentKartAIBehaviourId[12]; @@ -102,7 +103,7 @@ u16 D_80163344[2]; u16 D_80163348[2]; u16 D_8016334C[2]; u16 gSpeedKartAIBehaviour[12]; -s32 D_80163368[4]; +s32 gSizeWaypointPath[4]; s32 D_80163378; s32 D_8016337C; s16 D_80163380[12]; @@ -170,11 +171,11 @@ f32 gCourseCompletionPercentByPlayerId[10]; // D_801644D0 s16 D_801644F8[12]; f32 D_80164510[10]; s16 D_80164538[12]; -TrackWaypoint* D_80164550[4]; -TrackWaypoint* D_80164560[4]; -TrackWaypoint* D_80164570[4]; +TrackWaypoint* gTrackWaypoints[4]; +TrackWaypoint* gTrackInnerPath[4]; +TrackWaypoint* gTrackOuterPath[4]; s16* D_80164580[4]; -s16* D_80164590[4]; +s16* gWaypointExpectedRotation[4]; s16* D_801645A0[4]; u16 gPathIndexByPlayerId[12]; // D_801645B0 u16 gWaypointCountByPathIndex[4]; // D_801645C8 @@ -561,22 +562,25 @@ s16 get_angle_between_waypoints(Vec3f arg0, Vec3f arg1) { return phi_v1; } -s32 func_80006018(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32 arg7) { - f32 temp_f0; +bool is_collide_with_vehicle(f32 vehicleX, f32 vehicleY, f32 vehicleVelocityX, f32 vehicleVelocityZ, f32 distanceX, + f32 distanceY, f32 playerX, f32 playerZ) { + f32 velocity; f32 temp_f18; - temp_f0 = sqrtf((arg2 * arg2) + (arg3 * arg3)); - if (temp_f0 < 0.01f) { - return 0; + velocity = sqrtf((vehicleVelocityX * vehicleVelocityX) + (vehicleVelocityZ * vehicleVelocityZ)); + if (velocity < 0.01f) { + return false; } - temp_f18 = ((arg2 / temp_f0) * (arg6 - arg0)) + ((arg3 / temp_f0) * (arg7 - arg1)); - if ((-arg4 < temp_f18) && (temp_f18 < arg4)) { - temp_f18 = ((arg3 / temp_f0) * (arg6 - arg0)) + (-(arg2 / temp_f0) * (arg7 - arg1)); - if ((-arg5 < temp_f18) && (temp_f18 < arg5)) { - return 1; + temp_f18 = + ((vehicleVelocityX / velocity) * (playerX - vehicleX)) + ((vehicleVelocityZ / velocity) * (playerZ - vehicleY)); + if ((-distanceX < temp_f18) && (temp_f18 < distanceX)) { + temp_f18 = ((vehicleVelocityZ / velocity) * (playerX - vehicleX)) + + (-(vehicleVelocityX / velocity) * (playerZ - vehicleY)); + if ((-distanceY < temp_f18) && (temp_f18 < distanceY)) { + return true; } } - return 0; + return false; } void adjust_position_by_angle(Vec3f newPos, Vec3f oldPos, s16 orientationY) { @@ -664,36 +668,38 @@ s32 set_vehicle_render_distance_flags(Vec3f vehiclePos, f32 renderDistance, s32 return flag; } -void func_800065D0(s32 playerId, Player* player) { - s16 temp_t2; - s16 var_t1; - s16 temp_t3; - s16 a; - u32 b; +void detect_player_wrong_direction(s32 playerId, Player* player) { + s16 playerAngle; + s16 rotationDifference; + s16 waypointAngle; + s16 pathIndex; + u32 waypoint; - a = (s16) gPathIndexByPlayerId[playerId]; - b = gNearestWaypointByPlayerId[playerId]; + pathIndex = (s16) gPathIndexByPlayerId[playerId]; + waypoint = gNearestWaypointByPlayerId[playerId]; - temp_t2 = (s16) ((s16) player->rotation[1] / 182); - temp_t3 = (s16) ((s16) D_80164590[a][b] / 182); + playerAngle = (s16) ((s16) player->rotation[1] / DEGREES_CONVERSION_FACTOR); + waypointAngle = (s16) ((s16) gWaypointExpectedRotation[pathIndex][waypoint] / DEGREES_CONVERSION_FACTOR); - var_t1 = temp_t2 - temp_t3; + rotationDifference = playerAngle - waypointAngle; - if (var_t1 < 0) { - var_t1 = -var_t1; + if (rotationDifference < 0) { + rotationDifference = -rotationDifference; } - if ((D_80164450[playerId] < D_80163288[playerId]) && (var_t1 >= 136) && (var_t1 < 225)) { - D_80163258[playerId]++; - if ((D_80163258[playerId]) >= 5) { - D_80163270[playerId] = 1; - D_80163258[playerId] = 5; - gPlayers[playerId].effects |= 0x400000; + if ((D_80164450[playerId] < D_80163288[playerId]) && (rotationDifference >= SEVERE_WRONG_DIRECTION_MIN) && + (rotationDifference < SEVERE_WRONG_DIRECTION_MAX)) { + gWrongDirectionCounter[playerId]++; + if ((gWrongDirectionCounter[playerId]) >= WRONG_DIRECTION_FRAMES_LIMIT) { + gIsPlayerWrongDirection[playerId] = 1; + gWrongDirectionCounter[playerId] = WRONG_DIRECTION_FRAMES_LIMIT; + gPlayers[playerId].effects |= REVERSE_EFFECT; } - } else if ((var_t1 < 45) || (var_t1 >= 316)) { - D_80163270[playerId] = 0; - D_80163258[playerId] = 0; - gPlayers[playerId].effects &= 0xFFBFFFFF; + } else if ((rotationDifference < SEVERE_CORRECT_DIRECTION_MIN) || + (rotationDifference >= SEVERE_CORRECT_DIRECTION_MAX)) { + gIsPlayerWrongDirection[playerId] = 0; + gWrongDirectionCounter[playerId] = 0; + gPlayers[playerId].effects &= ~REVERSE_EFFECT; } D_80163288[playerId] = D_80164450[playerId]; } @@ -789,15 +795,15 @@ void set_places(void) { } } -void func_800070F4(void) { +void update_places(void) { f32 temp_f0; UNUSED s32 pad; - s32 sp50[8]; + s32 playerIds[8]; s32 temp_a0; s32 temp_t2_2; - s32 var_a1_2; - s32 var_a3; - s32 var_a2; + s32 compareIndex; + s32 i; + s32 numRacers; switch (gModeSelection) { case BATTLE: @@ -805,43 +811,43 @@ void func_800070F4(void) { return; // HEY! returns, not breaks case GRAND_PRIX: case TIME_TRIALS: - var_a2 = 8; + numRacers = 8; break; case VERSUS: - var_a2 = gPlayerCount; + numRacers = gPlayerCount; break; } - for (var_a3 = 0; var_a3 < var_a2; var_a3++) { - temp_a0 = gGPCurrentRacePlayerIdByRank[var_a3]; - sp50[var_a3] = temp_a0; - gCourseCompletionPercentByRank[var_a3] = -gTimePlayerLastTouchedFinishLine[temp_a0]; + for (i = 0; i < numRacers; i++) { + temp_a0 = gGPCurrentRacePlayerIdByRank[i]; + playerIds[i] = temp_a0; + gCourseCompletionPercentByRank[i] = -gTimePlayerLastTouchedFinishLine[temp_a0]; } - for (var_a3 = 0; var_a3 < (var_a2 - 1); var_a3++) { - for (var_a1_2 = var_a3 + 1; var_a1_2 < var_a2; var_a1_2++) { - if (gCourseCompletionPercentByRank[var_a3] < gCourseCompletionPercentByRank[var_a1_2]) { - temp_t2_2 = sp50[var_a3]; - sp50[var_a3] = sp50[var_a1_2]; - sp50[var_a1_2] = temp_t2_2; - temp_f0 = gCourseCompletionPercentByRank[var_a3]; - gCourseCompletionPercentByRank[var_a3] = gCourseCompletionPercentByRank[var_a1_2]; - gCourseCompletionPercentByRank[var_a1_2] = temp_f0; + for (i = 0; i < (numRacers - 1); i++) { + for (compareIndex = i + 1; compareIndex < numRacers; compareIndex++) { + if (gCourseCompletionPercentByRank[i] < gCourseCompletionPercentByRank[compareIndex]) { + temp_t2_2 = playerIds[i]; + playerIds[i] = playerIds[compareIndex]; + playerIds[compareIndex] = temp_t2_2; + temp_f0 = gCourseCompletionPercentByRank[i]; + gCourseCompletionPercentByRank[i] = gCourseCompletionPercentByRank[compareIndex]; + gCourseCompletionPercentByRank[compareIndex] = temp_f0; } } } - for (var_a3 = 0; var_a3 < NUM_PLAYERS; var_a3++) { - D_801643E0[var_a3] = gGPCurrentRaceRankByPlayerId[var_a3]; + for (i = 0; i < NUM_PLAYERS; i++) { + D_801643E0[i] = gGPCurrentRaceRankByPlayerId[i]; } - for (var_a3 = 0; var_a3 < var_a2; var_a3++) { - gGPCurrentRaceRankByPlayerId[sp50[var_a3]] = var_a3; - gGPCurrentRacePlayerIdByRank[var_a3] = sp50[var_a3]; + for (i = 0; i < numRacers; i++) { + gGPCurrentRaceRankByPlayerId[playerIds[i]] = i; + gGPCurrentRacePlayerIdByRank[i] = playerIds[i]; } } -void func_800074D4(void) { +void set_places_end_course_with_time(void) { f32 temp_a0; s32 temp; s32 sp68[8]; @@ -856,7 +862,7 @@ void func_800074D4(void) { } for (j = 0, i = 0; i < this_loops_upper_bound_is_brough_to_you_by_the_number; i++) { - if (gPlayers[i].type & 0x800) { + if (gPlayers[i].type & PLAYER_CINEMATIC_MODE) { sp68[j] = i; gCourseCompletionPercentByRank[j] = -gTimePlayerLastTouchedFinishLine[i]; j++; @@ -865,7 +871,7 @@ void func_800074D4(void) { temp_t1 = j; for (i = 0; i < this_loops_upper_bound_is_brough_to_you_by_the_number; i++) { - if (!(gPlayers[i].type & 0x800)) { + if (!(gPlayers[i].type & PLAYER_CINEMATIC_MODE)) { sp68[j] = i; gCourseCompletionPercentByRank[j] = gCourseCompletionPercentByPlayerId[i]; j++; @@ -908,15 +914,15 @@ void func_800074D4(void) { } } -s32 func_80007BF8(u16 arg0, u16 arg1, u16 arg2, u16 arg3, u16 arg4) { +s32 func_80007BF8(u16 waypoint, u16 arg1, u16 arg2, u16 arg3, u16 arg4) { s32 var_v1; var_v1 = 0; if ((arg1 >= arg2) && (arg1 < (arg4 - arg3))) { - if ((arg0 >= (arg1 - arg2)) && ((arg1 + arg3) >= arg0)) { + if ((waypoint >= (arg1 - arg2)) && ((arg1 + arg3) >= waypoint)) { var_v1 = 1; } - } else if ((((arg1 + arg3) % arg4) < arg0) && ((((arg1 + arg4) - arg2) % arg4) >= arg0)) { + } else if ((((arg1 + arg3) % arg4) < waypoint) && ((((arg1 + arg4) - arg2) % arg4) >= waypoint)) { var_v1 = -1; } else { var_v1 = 2; @@ -1293,11 +1299,11 @@ GLOBAL_ASM("asm/non_matchings/code_80005FD0/func_800088D8.s") #endif void func_80008DC0(s32 pathIndex) { - D_80164490 = D_80164550[pathIndex]; - D_801631D0 = D_80164560[pathIndex]; - D_801631D4 = D_80164570[pathIndex]; + D_80164490 = gTrackWaypoints[pathIndex]; + D_801631D0 = gTrackInnerPath[pathIndex]; + D_801631D4 = gTrackOuterPath[pathIndex]; D_801631D8 = D_80164580[pathIndex]; - D_801631DC = D_80164590[pathIndex]; + D_801631DC = gWaypointExpectedRotation[pathIndex]; D_801645E0 = D_801645A0[pathIndex]; D_80164430 = gWaypointCountByPathIndex[pathIndex]; } @@ -1411,9 +1417,9 @@ f32 func_80009258(UNUSED s32 playerId, f32 arg1, f32 arg2) { #ifdef NON_MATCHING // Weird stack issue, can't figure out how to get rid of it void func_8000929C(s32 playerId, Player* player) { - f32 tempPos0; - f32 tempPos1; - f32 tempPos2; + f32 playerX; + f32 playerY; + f32 playerZ; s32 var_v0; s32 var_v1; f32 someTemp0; @@ -1421,13 +1427,13 @@ void func_8000929C(s32 playerId, Player* player) { s16 var_t0; UNUSED s32 stackPadding1; - tempPos0 = player->pos[0]; - tempPos1 = player->pos[1]; - tempPos2 = player->pos[2]; + playerX = player->pos[0]; + playerY = player->pos[1]; + playerZ = player->pos[2]; D_801630E2 = 0; D_80163240[playerId] = 0; sSomeNearestWaypoint = - func_8000CD24(tempPos0, tempPos1, tempPos2, gNearestWaypointByPlayerId[playerId], player, playerId, D_80163448); + func_8000CD24(playerX, playerY, playerZ, gNearestWaypointByPlayerId[playerId], player, playerId, D_80163448); D_801630E0 = sSomeNearestWaypoint; if (gNearestWaypointByPlayerId[playerId] != sSomeNearestWaypoint) { gNearestWaypointByPlayerId[playerId] = sSomeNearestWaypoint; @@ -1448,19 +1454,19 @@ void func_8000929C(s32 playerId, Player* player) { D_801634EC = 1; } if (gIsMirrorMode != 0) { - if (tempPos0 < 300.0f) { + if (playerX < 300.0f) { var_v1 = 1; var_t0 = 1; - } else if ((tempPos0 < 1300.0f) && (gLapCountByPlayerId[playerId] < 2) && ((D_801634EC == 1))) { + } else if ((playerX < 1300.0f) && (gLapCountByPlayerId[playerId] < 2) && ((D_801634EC == 1))) { var_v1 = 1; var_t0 = 1; } } else { - if (tempPos0 > -300.0f) { + if (playerX > -300.0f) { var_v1 = 1; var_t0 = 1; } else { - if ((tempPos0 > -1300.0f) && (gLapCountByPlayerId[playerId] < 2) && (D_801634EC == 1)) { + if ((playerX > -1300.0f) && (gLapCountByPlayerId[playerId] < 2) && (D_801634EC == 1)) { var_v1 = 1; var_t0 = 1; } @@ -1471,7 +1477,7 @@ void func_8000929C(s32 playerId, Player* player) { var_t0 = 1; } someTemp0 = D_80163450[playerId]; - if ((var_v1 != 0) && (tempPos2 <= D_8016344C)) { + if ((var_v1 != 0) && (playerZ <= D_8016344C)) { if (D_8016344C < someTemp0) { gLapCountByPlayerId[playerId]++; if ((gModeSelection == 0) && (gLapCountByPlayerId[playerId] == 5)) { @@ -1486,16 +1492,16 @@ void func_8000929C(s32 playerId, Player* player) { reset_kart_ai_behaviour(playerId); D_801642D8[playerId].unk_06 = 0; if ((D_8016348C == 0) && !(player->type & 0x800)) { - gTimePlayerLastTouchedFinishLine[playerId] = func_80009258(playerId, someTemp0, tempPos2); + gTimePlayerLastTouchedFinishLine[playerId] = func_80009258(playerId, someTemp0, playerZ); } } } - if ((var_t0 != 0) && (someTemp0 <= D_8016344C) && (D_8016344C < tempPos2)) { + if ((var_t0 != 0) && (someTemp0 <= D_8016344C) && (D_8016344C < playerZ)) { gLapCountByPlayerId[playerId]--; func_80008F38(playerId); } } - D_80163450[playerId] = tempPos2; + D_80163450[playerId] = playerZ; if ((gCurrentCourseId == COURSE_YOSHI_VALLEY) && (D_801630E2 == 1)) { func_80009000(playerId); if (((player->type & 0x4000) == 0) || (player->type & 0x1000)) { @@ -1503,7 +1509,7 @@ void func_8000929C(s32 playerId, Player* player) { } } if ((player->type & 0x4000) && !(player->type & 0x1000)) { - func_800065D0(playerId, player); + detect_player_wrong_direction(playerId, player); if ((gModeSelection == 0) && (gPlayerCount == 2) && (playerId == 0)) { if (D_80164408[0] < D_80164408[1]) { D_80163478 = 0; @@ -1737,7 +1743,7 @@ void func_80009B60(s32 playerId) { D_801634F8[playerId].unkC = 0.0f; } // gNearestWaypointByPlayerId[playerId] might need to be saved to a temp - D_80164510[playerId] = D_80164550[D_80163448][gNearestWaypointByPlayerId[playerId]].posY + 4.3f; + D_80164510[playerId] = gTrackWaypoints[D_80163448][gNearestWaypointByPlayerId[playerId]].posY + 4.3f; if ((D_801631F8[playerId] == 1) && (D_801631E0[playerId] == 0)) { func_8002E4C4(player); } @@ -1781,8 +1787,8 @@ void func_80009B60(s32 playerId) { check_ai_crossing_distance(playerId); func_8000D3B8(playerId); func_8000D438(playerId, D_801630E0); - temp_f0 = D_80162FA0[0] - player->pos[0]; - temp_f2 = D_80162FA0[2] - player->pos[2]; + temp_f0 = gOffsetPosition[0] - player->pos[0]; + temp_f2 = gOffsetPosition[2] - player->pos[2]; if (!(player->effects & 0x80) && !(player->effects & 0x40) && !(player->effects & 0x800)) { if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2)) > 6400.0f) { if (D_80163448 == 0) { @@ -1793,9 +1799,9 @@ void func_80009B60(s32 playerId) { func_8000BBD8(stackPadding1A, D_80163090[playerId], D_80163448); } } - player->rotation[1] = -get_angle_between_two_vectors(player->pos, D_80162FA0); + player->rotation[1] = -get_angle_between_two_vectors(player->pos, gOffsetPosition); } else { - player->rotation[1] = D_80164590[D_80163448][(D_801630E0 + 4) % D_80164430]; + player->rotation[1] = gWaypointExpectedRotation[D_80163448][(D_801630E0 + 4) % D_80164430]; } } func_8003680C(player, 0); @@ -1898,28 +1904,29 @@ void func_80009B60(s32 playerId) { if (gCurrentCourseId == COURSE_AWARD_CEREMONY) { switch (D_80163410[playerId]) { /* switch 3; irregular */ case 3: /* switch 3 */ - D_80162FA0[0] = D_80163418[playerId]; - D_80162FA0[2] = D_80163438[playerId]; + gOffsetPosition[0] = D_80163418[playerId]; + gOffsetPosition[2] = D_80163438[playerId]; break; case 4: /* switch 3 */ - waypoint = &D_80164550[playerId][(gNearestWaypointByPlayerId[playerId] + 0xA) % - gWaypointCountByPathIndex[playerId]]; - D_80162FA0[0] = waypoint->posX; - D_80162FA0[2] = waypoint->posZ; + waypoint = &gTrackWaypoints[playerId][(gNearestWaypointByPlayerId[playerId] + 0xA) % + gWaypointCountByPathIndex[playerId]]; + gOffsetPosition[0] = waypoint->posX; + gOffsetPosition[2] = waypoint->posZ; break; } } - D_80162FA0[0] = (D_80163178[playerId] + D_80162FA0[0]) * 0.5f; - D_80162FA0[2] = (D_801631A0[playerId] + D_80162FA0[2]) * 0.5f; - D_80163178[playerId] = D_80162FA0[0]; - D_801631A0[playerId] = D_80162FA0[2]; + gOffsetPosition[0] = (D_80163178[playerId] + gOffsetPosition[0]) * 0.5f; + gOffsetPosition[2] = (D_801631A0[playerId] + gOffsetPosition[2]) * 0.5f; + D_80163178[playerId] = gOffsetPosition[0]; + D_801631A0[playerId] = gOffsetPosition[2]; temp_f2 = athing * 182.0f; temp_f6 = -athing * 182.0f; // MISMATCH2 // This fixes part of the register allocation problems, makes fixing others // harder though. Needs more investigation - // var_a2 = (-get_angle_between_two_vectors(player->pos, D_80162FA0)) - (var_a1 = player->rotation[1]); - stackPadding19 = -get_angle_between_two_vectors(player->pos, D_80162FA0) - player->rotation[1]; + // var_a2 = (-get_angle_between_two_vectors(player->pos, gOffsetPosition)) - (var_a1 = + // player->rotation[1]); + stackPadding19 = -get_angle_between_two_vectors(player->pos, gOffsetPosition) - player->rotation[1]; var_a1 = stackPadding19; var_a2 = var_a1; if ((s16) temp_f2 < var_a1) { @@ -2146,8 +2153,8 @@ f32 func_8000B874(f32 posX, f32 posZ, u16 waypointIndex, s32 pathIndex) { TrackWaypoint* thing1; TrackWaypoint* thing2; - thing1 = &D_80164560[pathIndex][waypointIndex]; - thing2 = &D_80164570[pathIndex][waypointIndex]; + thing1 = &gTrackInnerPath[pathIndex][waypointIndex]; + thing2 = &gTrackOuterPath[pathIndex][waypointIndex]; x1 = thing1->posX; z1 = thing1->posZ; @@ -2173,7 +2180,7 @@ void func_8000B95C(s32 playerId, u16 waypointIndex, s32 pathIndex) { } } -void func_8000BA14(u16 waypointIndex, f32 arg1, f32 arg2, s16 pathIndex) { +void calculate_track_offset_position(u16 waypointIndex, f32 lerpFactor, f32 offsetDistance, s16 pathIndex) { UNUSED s32 pad[4]; f32 waypointOneX; f32 waypointOneZ; @@ -2182,31 +2189,36 @@ void func_8000BA14(u16 waypointIndex, f32 arg1, f32 arg2, s16 pathIndex) { UNUSED s32 pad2; f32 xdiff; f32 zdiff; - f32 distance; + f32 segmentLength; UNUSED f32 temp_f12; UNUSED f32 temp_f2_2; UNUSED TrackWaypoint* path; TrackWaypoint* waypointTwo; TrackWaypoint* waypointOne; - waypointOne = &D_80164550[pathIndex][waypointIndex]; + waypointOne = &gTrackWaypoints[pathIndex][waypointIndex]; waypointOneX = waypointOne->posX; waypointOneZ = waypointOne->posZ; - waypointTwo = &D_80164550[pathIndex][(waypointIndex + 1) % D_80164430]; + waypointTwo = &gTrackWaypoints[pathIndex][(waypointIndex + 1) % D_80164430]; waypointTwoX = waypointTwo->posX; waypointTwoZ = waypointTwo->posZ; + + // Calculate vector between waypoints zdiff = waypointTwoZ - waypointOneZ; xdiff = waypointTwoX - waypointOneX; if (xdiff && xdiff) {} - distance = sqrtf((xdiff * xdiff) + (zdiff * zdiff)); - if (distance < 0.01f) { - D_80162FA0[0] = waypointTwoX; - D_80162FA0[2] = waypointTwoZ; + + segmentLength = sqrtf((xdiff * xdiff) + (zdiff * zdiff)); + if (segmentLength < 0.01f) { + gOffsetPosition[0] = waypointTwoX; + gOffsetPosition[2] = waypointTwoZ; } else { - D_80162FA0[0] = ((0.5f - (arg1 * 0.5f)) * (((arg2 * zdiff) / distance) + waypointOneX)) + - ((1.0f - (0.5f - (arg1 * 0.5f))) * (((arg2 * -zdiff) / distance) + waypointOneX)); - D_80162FA0[2] = ((0.5f - (arg1 * 0.5f)) * (((arg2 * -xdiff) / distance) + waypointOneZ)) + - ((1.0f - (0.5f - (arg1 * 0.5f))) * (((arg2 * xdiff) / distance) + waypointOneZ)); + gOffsetPosition[0] = + ((0.5f - (lerpFactor * 0.5f)) * (((offsetDistance * zdiff) / segmentLength) + waypointOneX)) + + ((1.0f - (0.5f - (lerpFactor * 0.5f))) * (((offsetDistance * -zdiff) / segmentLength) + waypointOneX)); + gOffsetPosition[2] = + ((0.5f - (lerpFactor * 0.5f)) * (((offsetDistance * -xdiff) / segmentLength) + waypointOneZ)) + + ((1.0f - (0.5f - (lerpFactor * 0.5f))) * (((offsetDistance * xdiff) / segmentLength) + waypointOneZ)); } } @@ -2224,8 +2236,8 @@ void func_8000BBD8(u16 waypointIndex, f32 arg1, s16 pathIndex) { f32 temp_f0; f32 temp_f12; - path1 = &D_80164560[pathIndex][waypointIndex]; - path2 = &D_80164570[pathIndex][waypointIndex]; + path1 = &gTrackInnerPath[pathIndex][waypointIndex]; + path2 = &gTrackOuterPath[pathIndex][waypointIndex]; x1 = (f32) path1->posX; z1 = (f32) path1->posZ; @@ -2236,8 +2248,8 @@ void func_8000BBD8(u16 waypointIndex, f32 arg1, s16 pathIndex) { waypointIndex += 1; waypointIndex = waypointIndex % gWaypointCountByPathIndex[pathIndex]; - path1 = &D_80164560[pathIndex][waypointIndex]; - path2 = &D_80164570[pathIndex][waypointIndex]; + path1 = &gTrackInnerPath[pathIndex][waypointIndex]; + path2 = &gTrackOuterPath[pathIndex][waypointIndex]; x3 = (f32) path1->posX; z3 = (f32) path1->posZ; @@ -2247,8 +2259,8 @@ void func_8000BBD8(u16 waypointIndex, f32 arg1, s16 pathIndex) { temp_f0 = 0.5f - (arg1 / 2.0f); temp_f12 = 1.0f - temp_f0; - D_80162FA0[0] = ((temp_f0 * (x1 + x3)) / 2.0f) + ((temp_f12 * (x2 + x4)) / 2.0f); - D_80162FA0[2] = ((temp_f0 * (z1 + z3)) / 2.0f) + ((temp_f12 * (z2 + z4)) / 2.0f); + gOffsetPosition[0] = ((temp_f0 * (x1 + x3)) / 2.0f) + ((temp_f12 * (x2 + x4)) / 2.0f); + gOffsetPosition[2] = ((temp_f0 * (z1 + z3)) / 2.0f) + ((temp_f12 * (z2 + z4)) / 2.0f); } s16 func_8000BD94(f32 posX, f32 posY, f32 posZ, s32 pathIndex) { @@ -2263,7 +2275,7 @@ s16 func_8000BD94(f32 posX, f32 posY, f32 posZ, s32 pathIndex) { TrackWaypoint* pathWaypoints; TrackWaypoint* considerWaypoint; - pathWaypoints = D_80164550[pathIndex]; + pathWaypoints = gTrackWaypoints[pathIndex]; pathWaypointCount = gWaypointCountByPathIndex[pathIndex]; considerWaypoint = &pathWaypoints[0]; x_dist = (f32) considerWaypoint->posX - posX; @@ -2307,7 +2319,7 @@ s16 find_closest_waypoint_track_section(f32 posX, f32 posY, f32 posZ, u16 trackS nearestWaypointIndex = 0; var_t1 = 0; var_a1 = 0; - pathWaypoints = D_80164550[temp_t0]; + pathWaypoints = gTrackWaypoints[temp_t0]; pathWaypointCount = gWaypointCountByPathIndex[temp_t0]; considerWaypoint = &pathWaypoints[0]; for (considerWaypointIndex = 0; considerWaypointIndex < pathWaypointCount; @@ -2327,8 +2339,8 @@ s16 find_closest_waypoint_track_section(f32 posX, f32 posY, f32 posZ, u16 trackS } if (var_t1 == 0) { for (considerPathIndex = 0; considerPathIndex < 4; considerPathIndex++) { - if ((considerPathIndex != temp_t0) && (D_80163368[considerPathIndex] >= 2)) { - pathWaypoints = D_80164550[considerPathIndex]; + if ((considerPathIndex != temp_t0) && (gSizeWaypointPath[considerPathIndex] >= 2)) { + pathWaypoints = gTrackWaypoints[considerPathIndex]; considerWaypoint = &pathWaypoints[0]; pathWaypointCount = gWaypointCountByPathIndex[considerPathIndex]; for (considerWaypointIndex = 0; considerWaypointIndex < pathWaypointCount; @@ -2350,7 +2362,7 @@ s16 find_closest_waypoint_track_section(f32 posX, f32 posY, f32 posZ, u16 trackS } } if (var_a1 == 0) { - pathWaypoints = D_80164550[0]; + pathWaypoints = gTrackWaypoints[0]; pathWaypointCount = gWaypointCountByPathIndex[0]; considerWaypoint = &pathWaypoints[0]; x_dist = (f32) considerWaypoint->posX - posX; @@ -2400,10 +2412,10 @@ s16 func_8000C884(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex nearestWaypointIndex = -1; minimumDistance = 250000.0f; pathWaypointCount = gWaypointCountByPathIndex[pathIndex]; - pathWaypoints = D_80164550[pathIndex]; + pathWaypoints = gTrackWaypoints[pathIndex]; for (searchIndex = waypointIndex - 3; searchIndex < waypointIndex + 7; searchIndex++) { // Its possible for searchIndex to be less than 0 or greater than the number of waypoints in a given path - // This is done to ensure we access D_80164550 at a valid index + // This is done to ensure we access gTrackWaypoints at a valid index considerIndex = (searchIndex + pathWaypointCount) % pathWaypointCount; considerWaypoint = &pathWaypoints[considerIndex]; if (considerWaypoint->trackSectionId == trackSectionId) { @@ -2443,10 +2455,10 @@ s16 find_closest_waypoint_with_previous_waypoint(f32 posX, f32 posY, f32 posZ, s nearestWaypointIndex = -1; minimumDistance = 160000.0f; pathWaypointCount = gWaypointCountByPathIndex[pathIndex]; - pathWaypoints = D_80164550[pathIndex]; + pathWaypoints = gTrackWaypoints[pathIndex]; for (searchIndex = waypointIndex - 3; searchIndex < waypointIndex + 7; searchIndex++) { // Its possible for searchIndex to be less than 0 or greater than the number of waypoints in a given path - // This is done to ensure we access D_80164550 at a valid index + // This is done to ensure we access gTrackWaypoints at a valid index considerIndex = (searchIndex + pathWaypointCount) % pathWaypointCount; considerWaypoint = &pathWaypoints[considerIndex]; x_dist = considerWaypoint->posX - posX; @@ -2527,7 +2539,7 @@ s16 func_8000CD24(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, Player* playe } else { if (D_801631E0[playerId] == 1) { if (player->unk_0CA & 1) { - temp_v1 = &D_80164550[pathIndex][waypointIndex]; + temp_v1 = &gTrackWaypoints[pathIndex][waypointIndex]; player->pos[0] = (f32) temp_v1->posX; player->pos[1] = (f32) temp_v1->posY; player->pos[2] = (f32) temp_v1->posZ; @@ -2545,7 +2557,7 @@ s16 func_8000CD24(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, Player* playe if (newWaypoint == -1) { newWaypoint = find_closest_waypoint_track_section(posX, posY, posZ, D_80163318[playerId], &pathIndex); - temp_v1 = &D_80164550[pathIndex][newWaypoint]; + temp_v1 = &gTrackWaypoints[pathIndex][newWaypoint]; player->pos[0] = (f32) temp_v1->posX; player->pos[1] = (f32) temp_v1->posY; player->pos[2] = (f32) temp_v1->posZ; @@ -2554,7 +2566,7 @@ s16 func_8000CD24(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, Player* playe newWaypoint = find_closest_waypoint_with_previous_waypoint(posX, posY, posZ, waypointIndex, pathIndex); if (newWaypoint == -1) { newWaypoint = func_8000BD94(posX, posY, posZ, pathIndex); - temp_v1 = &D_80164550[pathIndex][newWaypoint]; + temp_v1 = &gTrackWaypoints[pathIndex][newWaypoint]; posX = (f32) temp_v1->posX; posY = (f32) temp_v1->posY; posZ = (f32) temp_v1->posZ; @@ -2718,13 +2730,13 @@ void func_8000D438(s32 arg0, u16 arg1) { } arg1 = (D_80163380[arg0] + arg1) % D_80164430; func_8000BBD8(arg1, sp2C, D_80163448); - sp48 = D_80162FA0[0]; - sp44 = D_80162FA0[2]; + sp48 = gOffsetPosition[0]; + sp44 = gOffsetPosition[2]; func_8000BBD8(((arg1 + 1) % D_80164430) & 0xFFFF, sp2C, D_80163448); - stackPadding5 = D_80162FA0[0]; - D_80162FA0[0] = (sp48 + stackPadding5) * 0.5f; - stackPadding4 = D_80162FA0[2]; - D_80162FA0[2] = (sp44 + stackPadding4) * 0.5f; + stackPadding5 = gOffsetPosition[0]; + gOffsetPosition[0] = (sp48 + stackPadding5) * 0.5f; + stackPadding4 = gOffsetPosition[2]; + gOffsetPosition[2] = (sp44 + stackPadding4) * 0.5f; } s16 func_8000D6D0(Vec3f position, s16* waypointIndex, f32 speed, f32 arg3, s16 pathIndex, s16 arg5) { @@ -2753,7 +2765,7 @@ s16 func_8000D6D0(Vec3f position, s16* waypointIndex, f32 speed, f32 arg3, s16 p Vec3f oldPos; TrackWaypoint* path; - path = D_80164550[pathIndex]; + path = gTrackWaypoints[pathIndex]; oldPos[0] = position[0]; oldPos[1] = position[1]; oldPos[2] = position[2]; @@ -2766,11 +2778,11 @@ s16 func_8000D6D0(Vec3f position, s16* waypointIndex, f32 speed, f32 arg3, s16 p waypoint1 = temp_v1 % gWaypointCountByPathIndex[pathIndex]; waypoint2 = (temp_v1 + 1) % gWaypointCountByPathIndex[pathIndex]; func_8000BBD8(waypoint1, arg3, pathIndex); - pad3 = D_80162FA0[0]; - pad4 = D_80162FA0[2]; + pad3 = gOffsetPosition[0]; + pad4 = gOffsetPosition[2]; func_8000BBD8(waypoint2, arg3, pathIndex); - temp1 = D_80162FA0[0]; - temp2 = D_80162FA0[2]; + temp1 = gOffsetPosition[0]; + temp2 = gOffsetPosition[2]; midY = (path[waypoint1].posY + path[waypoint2].posY) * 0.5f; midX = (pad3 + temp1) * 0.5f; midZ = (pad4 + temp2) * 0.5f; @@ -2832,12 +2844,12 @@ s16 func_8000D940(Vec3f pos, s16* waypointIndex, f32 speed, f32 arg3, s16 pathIn waypoint1 = ((temp_v0 + waypointCount) - 3) % waypointCount; waypoint2 = ((temp_v0 + waypointCount) - 4) % waypointCount; func_8000BBD8(waypoint1, arg3, pathIndex); - pad2 = D_80162FA0[0]; - pad3 = D_80162FA0[2]; + pad2 = gOffsetPosition[0]; + pad3 = gOffsetPosition[2]; func_8000BBD8(waypoint2, arg3, pathIndex); - thing1 = D_80162FA0[0]; - thing2 = D_80162FA0[2]; - midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) * 0.5f; + thing1 = gOffsetPosition[0]; + thing2 = gOffsetPosition[2]; + midY = (gTrackWaypoints[pathIndex][waypoint1].posY + gTrackWaypoints[pathIndex][waypoint2].posY) * 0.5f; midX = (pad2 + thing1) * 0.5f; midZ = (pad3 + thing2) * 0.5f; xdiff = midX - temp_f20; @@ -2935,13 +2947,13 @@ void set_bomb_kart_spawn_positions(void) { startingYPos = get_surface_height(startingXPos, 2000.0f, startingZPos); break; case COURSE_AWARD_CEREMONY: - temp_v0 = &D_80164550[3][bombKartSpawn->waypointIndex]; + temp_v0 = &gTrackWaypoints[3][bombKartSpawn->waypointIndex]; startingXPos = temp_v0->posX; startingYPos = temp_v0->posY; startingZPos = temp_v0->posZ; break; default: - temp_v0 = &D_80164550[0][bombKartSpawn->waypointIndex]; + temp_v0 = &gTrackWaypoints[0][bombKartSpawn->waypointIndex]; startingXPos = temp_v0->posX; startingYPos = temp_v0->posY; startingZPos = temp_v0->posZ; @@ -3088,7 +3100,7 @@ void func_8000DF8C(s32 bombKartId) { temp_t6 = (var_s1 * 0xFFFF) / 360; sp118 = coss(temp_t6) * 25.0; temp_f0_3 = sins(temp_t6) * 25.0; - temp_v0_2 = &D_80164550[0][spCA]; + temp_v0_2 = &gTrackWaypoints[0][spCA]; var_f22 = temp_v0_2->posX + sp118; var_f20 = bombKart->yPos + 3.5f; var_f24 = temp_v0_2->posZ + temp_f0_3; @@ -3108,7 +3120,7 @@ void func_8000DF8C(s32 bombKartId) { temp_t6 = (var_s1 * 0xFFFF) / 360; sp118 = coss(temp_t6) * 25.0; temp_f0_3 = sins(temp_t6) * 25.0; - temp_v0_2 = &D_80164550[0][spCA]; + temp_v0_2 = &gTrackWaypoints[0][spCA]; var_f22 = temp_v0_2->posX + sp118; var_f20 = bombKart->yPos + 3.5f; var_f24 = temp_v0_2->posZ + temp_f0_3; @@ -3137,11 +3149,11 @@ void func_8000DF8C(s32 bombKartId) { spCA = 0; } if (((s32) spCA) < 0x1A) { - temp_v0_2 = &D_80164550[3][(spCA + 1) % gWaypointCountByPathIndex[3]]; + temp_v0_2 = &gTrackWaypoints[3][(spCA + 1) % gWaypointCountByPathIndex[3]]; D_80162FB0[0] = temp_v0_2->posX; D_80162FB0[1] = temp_v0_2->posY; D_80162FB0[2] = temp_v0_2->posZ; - temp_v0_4 = &D_80164550[3][(spCA + 2) % gWaypointCountByPathIndex[3]]; + temp_v0_4 = &gTrackWaypoints[3][(spCA + 2) % gWaypointCountByPathIndex[3]]; D_80162FC0[0] = temp_v0_4->posX; D_80162FC0[1] = temp_v0_4->posY; D_80162FC0[2] = temp_v0_4->posZ; @@ -3174,11 +3186,11 @@ void func_8000DF8C(s32 bombKartId) { } break; case 4: - temp_v0_2 = &D_80164550[0][spCA]; + temp_v0_2 = &gTrackWaypoints[0][spCA]; D_80162FB0[0] = temp_v0_2->posX; D_80162FB0[1] = temp_v0_2->posY; D_80162FB0[2] = temp_v0_2->posZ; - temp_v0_4 = &D_80164550[0][(spCA + 1) % gWaypointCountByPathIndex[0]]; + temp_v0_4 = &gTrackWaypoints[0][(spCA + 1) % gWaypointCountByPathIndex[0]]; D_80162FC0[0] = temp_v0_4->posX; D_80162FC0[1] = temp_v0_4->posY; D_80162FC0[2] = temp_v0_4->posZ; @@ -3409,57 +3421,57 @@ void func_8000F124(void) { } // Delete track waypoints -void func_8000F2BC(TrackWaypoint* arg0, size_t size) { +void clear_waypoint(TrackWaypoint* arg0, size_t size) { bzero((void*) arg0, size * sizeof(TrackWaypoint)); } // Appears to allocate memory for each course. -void func_8000F2DC(void) { +void init_course_waypoint(void) { struct _struct_gCoursePathSizes_0x10* ptr = &GET_COURSE_PathSizes; s32 temp; s32 i; - D_80163368[0] = (s32) ptr->unk0; - D_80163368[1] = (s32) ptr->unk2; - D_80163368[2] = (s32) ptr->unk4; - D_80163368[3] = (s32) ptr->unk6; + gSizeWaypointPath[0] = (s32) ptr->numWaypoint; + gSizeWaypointPath[1] = (s32) ptr->numInnerWaypoint; + gSizeWaypointPath[2] = (s32) ptr->numOuterWaypoint; + gSizeWaypointPath[3] = (s32) ptr->unk6; temp = ptr->unk8; gVehicle2DWaypoint = get_next_available_memory_addr(temp * 4); // Podium ceremony appears to allocate 1 * 8 bytes of data. Which would be aligned to 0x10. for (i = 0; i < 4; i++) { - D_80164550[i] = get_next_available_memory_addr(D_80163368[i] * 8); - D_80164560[i] = get_next_available_memory_addr(D_80163368[i] * 8); - D_80164570[i] = get_next_available_memory_addr(D_80163368[i] * 8); - D_80164580[i] = get_next_available_memory_addr(D_80163368[i] * 2); - D_80164590[i] = get_next_available_memory_addr(D_80163368[i] * 2); - D_801645A0[i] = get_next_available_memory_addr(D_80163368[i] * 2); + gTrackWaypoints[i] = get_next_available_memory_addr(gSizeWaypointPath[i] * sizeof(TrackWaypoint)); + gTrackInnerPath[i] = get_next_available_memory_addr(gSizeWaypointPath[i] * sizeof(TrackWaypoint)); + gTrackOuterPath[i] = get_next_available_memory_addr(gSizeWaypointPath[i] * sizeof(TrackWaypoint)); + D_80164580[i] = get_next_available_memory_addr(gSizeWaypointPath[i] * sizeof(s16)); + gWaypointExpectedRotation[i] = get_next_available_memory_addr(gSizeWaypointPath[i] * sizeof(s16)); + D_801645A0[i] = get_next_available_memory_addr(gSizeWaypointPath[i] * sizeof(s16)); } - D_80164490 = D_80164550[0]; - D_801631D0 = D_80164560[0]; - D_801631D4 = D_80164570[0]; + D_80164490 = gTrackWaypoints[0]; + D_801631D0 = gTrackInnerPath[0]; + D_801631D4 = gTrackOuterPath[0]; D_801631D8 = D_80164580[0]; - D_801631DC = D_80164590[0]; + D_801631DC = gWaypointExpectedRotation[0]; D_801645E0 = D_801645A0[0]; // zero allocated memory? //! @warning does not appear to zero all the above allocated variables. for (i = 0; i < 4; i++) { - func_8000F2BC(D_80164550[i], D_80163368[i]); - func_8000F2BC(D_80164560[i], D_80163368[i]); - func_8000F2BC(D_80164570[i], D_80163368[i]); + clear_waypoint(gTrackWaypoints[i], gSizeWaypointPath[i]); + clear_waypoint(gTrackInnerPath[i], gSizeWaypointPath[i]); + clear_waypoint(gTrackOuterPath[i], gSizeWaypointPath[i]); } // Skip several cpu cycles. for (i = 0; i < 4; i++) {} for (i = 0; i < 4; i++) { - if (D_80163368[i] >= 2) { - func_800100F0(i); - func_80010218(i); + if (gSizeWaypointPath[i] >= 2) { + load_track_waypoint(i); + calculate_track_boundaries(i); func_800107C4(i); func_80010DBC(i); func_80010E6C(i); @@ -3531,8 +3543,8 @@ void func_8000F628(void) { gGPCurrentRacePlayerIdByRank[temp_v0_3] = (s16) i; D_80164378[temp_v0_3] = (s16) i; D_80164408[i] = temp_v0_3; - D_80163258[i] = 0; - D_80163270[i] = 0; + gWrongDirectionCounter[i] = 0; + gIsPlayerWrongDirection[i] = 0; D_801631E0[i] = 0; D_801631F8[i] = 0; D_80164450[i] = -20; @@ -3635,7 +3647,7 @@ void func_8000F628(void) { D_80163478 = 0; D_80163378 = 0; D_8016337C = 0; - D_8016344C = (f32) D_80164550[0][0].posZ; // [i][2] + D_8016344C = (f32) gTrackWaypoints[0][0].posZ; // [i][2] D_801634F0 = 0; D_801634F4 = 0; D_80163488 = 0; @@ -3660,7 +3672,7 @@ void func_8000F628(void) { // Processes course path by index. // @arg index from 0 to 3. // Each course can have 1-4 course paths. -void func_800100F0(s32 pathIndex) { +void load_track_waypoint(s32 pathIndex) { TrackWaypoint* ptr; TrackWaypoint* pathDest; @@ -3673,7 +3685,7 @@ void func_800100F0(s32 pathIndex) { // cast required if ((s32) GET_COURSE_AIMaximumSeparation >= 0) { - pathDest = D_80164550[pathIndex]; + pathDest = gTrackWaypoints[pathIndex]; bInvalidPath = 1; if (gCurrentCourseId != COURSE_AWARD_CEREMONY) { var_v0 = process_path_data(pathDest, GET_COURSE_PathTable2(pathIndex)); @@ -3703,7 +3715,7 @@ void func_800100F0(s32 pathIndex) { } } -void func_80010218(s32 pathIndex) { +void calculate_track_boundaries(s32 pathIndex) { f32 waypointWidth; f32 x1; f32 y1; @@ -3725,16 +3737,17 @@ void func_80010218(s32 pathIndex) { if (((s32) GET_COURSE_AIMaximumSeparation) >= 0) { waypointWidth = GET_COURSE_AIMaximumSeparation; - waypoint = &D_80164550[pathIndex][0]; - var_s1 = &D_80164560[pathIndex][0]; - var_s2 = &D_80164570[pathIndex][0]; + waypoint = &gTrackWaypoints[pathIndex][0]; + var_s1 = &gTrackInnerPath[pathIndex][0]; + var_s2 = &gTrackOuterPath[pathIndex][0]; for (waypointIndex = 0; waypointIndex < gWaypointCountByPathIndex[pathIndex]; waypointIndex++, var_s1++, var_s2++) { x1 = waypoint->posX; y1 = waypoint->posY; z1 = waypoint->posZ; waypoint++; - nextWaypoint = &D_80164550[pathIndex][(waypointIndex + 1) % ((s32) gWaypointCountByPathIndex[pathIndex])]; + nextWaypoint = + &gTrackWaypoints[pathIndex][(waypointIndex + 1) % ((s32) gWaypointCountByPathIndex[pathIndex])]; x2 = nextWaypoint->posX; y2 = nextWaypoint->posY; z2 = nextWaypoint->posZ; @@ -3744,9 +3757,15 @@ void func_80010218(s32 pathIndex) { neg_z_dist = z1 - z2; xz_dist = sqrtf((x_dist * x_dist) + (z_dist * z_dist)); temp_f16 = (f32) ((y1 + y2) * 0.5); + + // Calculate inner boundary position + // Uses perpendicular vector (Z, -X) normalized by segment length var_s1->posX = ((waypointWidth * z_dist) / xz_dist) + x1; var_s1->posY = temp_f16; var_s1->posZ = ((waypointWidth * neg_x_dist) / xz_dist) + z1; + + // Calculate outer boundary position + // Uses opposite perpendicular vector (-Z, X) var_s2->posX = ((waypointWidth * neg_z_dist) / xz_dist) + x1; var_s2->posY = temp_f16; var_s2->posZ = ((waypointWidth * x_dist) / xz_dist) + z1; @@ -3778,7 +3797,7 @@ f32 func_80010480(s32 pathIndex, u16 waypointIndex) { return 0.0f; } waypointCount = gWaypointCountByPathIndex[pathIndex]; - pathWaypoints = D_80164550[pathIndex]; + pathWaypoints = gTrackWaypoints[pathIndex]; waypoint1 = &pathWaypoints[waypointIndex]; waypoint2 = &pathWaypoints[(waypointIndex + 1) % waypointCount]; waypoint3 = &pathWaypoints[(waypointIndex + 2) % waypointCount]; @@ -3867,11 +3886,11 @@ s16 func_80010CB0(s32 pathIndex, s32 waypointIndex) { Vec3f sp24; TrackWaypoint* temp_v0; - temp_v0 = &D_80164550[pathIndex][waypointIndex]; + temp_v0 = &gTrackWaypoints[pathIndex][waypointIndex]; sp30[0] = temp_v0->posX; sp30[1] = temp_v0->posY; sp30[2] = temp_v0->posZ; - temp_v0 = &D_80164550[pathIndex][(waypointIndex + 1) % gWaypointCountByPathIndex[pathIndex]]; + temp_v0 = &gTrackWaypoints[pathIndex][(waypointIndex + 1) % gWaypointCountByPathIndex[pathIndex]]; sp24[0] = temp_v0->posX; sp24[1] = temp_v0->posY; sp24[2] = temp_v0->posZ; @@ -3879,13 +3898,13 @@ s16 func_80010CB0(s32 pathIndex, s32 waypointIndex) { return -ret; } -// Populates D_80164590 +// Populates gWaypointExpectedRotation void func_80010DBC(s32 pathIndex) { s32 waypointIndex; u16* angle; if ((s32) GET_COURSE_AIMaximumSeparation >= 0) { - for (angle = (u16*) &D_80164590[pathIndex][0], waypointIndex = 0; + for (angle = (u16*) &gWaypointExpectedRotation[pathIndex][0], waypointIndex = 0; waypointIndex < gWaypointCountByPathIndex[pathIndex]; waypointIndex++, angle++) { *angle = func_80010CB0(pathIndex, waypointIndex); } @@ -4707,14 +4726,15 @@ void func_80012DC0(s32 playerId, Player* player) { z_dist = playerPosZ - trainCar->position[2]; if ((x_dist > -100.0) && (x_dist < 100.0)) { if ((z_dist > -100.0) && (z_dist < 100.0)) { - if (func_80006018(trainCar->position[0], trainCar->position[2], trainCar->velocity[0], - trainCar->velocity[2], 60.0f, 20.0f, playerPosX, playerPosZ) == 1) { + if (is_collide_with_vehicle(trainCar->position[0], trainCar->position[2], trainCar->velocity[0], + trainCar->velocity[2], 60.0f, 20.0f, playerPosX, playerPosZ) == 1) { player->soundEffects |= REVERSE_SOUND_EFFECT; } trainCar = &gTrainList[trainIndex].tender; if (trainCar->isActive == 1) { - if (func_80006018(trainCar->position[0], trainCar->position[2], trainCar->velocity[0], - trainCar->velocity[2], 30.0f, 20.0f, playerPosX, playerPosZ) == 1) { + if (is_collide_with_vehicle(trainCar->position[0], trainCar->position[2], + trainCar->velocity[0], trainCar->velocity[2], 30.0f, 20.0f, + playerPosX, playerPosZ) == 1) { player->soundEffects |= REVERSE_SOUND_EFFECT; } } @@ -4728,8 +4748,9 @@ void func_80012DC0(s32 playerId, Player* player) { if (trainCar->isActive == 1) { if ((x_dist > -100.0) && (x_dist < 100.0)) { if ((z_dist > -100.0) && (z_dist < 100.0)) { - if (func_80006018(trainCar->position[0], trainCar->position[2], trainCar->velocity[0], - trainCar->velocity[2], 30.0f, 20.0f, playerPosX, playerPosZ) == 1) { + if (is_collide_with_vehicle(trainCar->position[0], trainCar->position[2], + trainCar->velocity[0], trainCar->velocity[2], 30.0f, 20.0f, + playerPosX, playerPosZ) == 1) { player->soundEffects |= REVERSE_SOUND_EFFECT; } } @@ -4953,9 +4974,9 @@ void func_80013854(Player* player) { z_diff = playerZ - tempPaddleWheelBoat->position[2]; if ((x_diff > -300.0) && (x_diff < 300.0)) { if ((z_diff > -300.0) && (z_diff < 300.0)) { - if ((func_80006018(tempPaddleWheelBoat->position[0], tempPaddleWheelBoat->position[2], - tempPaddleWheelBoat->velocity[0], tempPaddleWheelBoat->velocity[2], 200.0f, - 60.0f, playerX, playerZ) == 1) && + if ((is_collide_with_vehicle(tempPaddleWheelBoat->position[0], tempPaddleWheelBoat->position[2], + tempPaddleWheelBoat->velocity[0], tempPaddleWheelBoat->velocity[2], + 200.0f, 60.0f, playerX, playerZ) == 1) && (y_diff < 60.0)) { player->soundEffects |= 0x80000; } @@ -5118,28 +5139,28 @@ void func_80013F7C(s32 playerId, Player* player, VehicleStuff* vehicle, f32 arg3 s32 i; - f32 spC4; + f32 playerX; f32 spC0; - f32 spBC; + f32 playerZ; if (((D_801631E0[playerId] != 1) || ((((player->type & PLAYER_HUMAN) != 0)) && !(player->type & PLAYER_KART_AI))) && !(player->effects & 0x01000000)) { - spC4 = player->pos[0]; + playerX = player->pos[0]; spC0 = player->pos[1]; - spBC = player->pos[2]; + playerZ = player->pos[2]; for (i = 0; i < arg5; i++) { - temp_f12 = spC4 - vehicle->position[0]; + temp_f12 = playerX - vehicle->position[0]; temp_f22 = spC0 - vehicle->position[1]; - temp_f14 = spBC - vehicle->position[2]; + temp_f14 = playerZ - vehicle->position[2]; if (((temp_f12) > -100.0) && ((temp_f12) < 100.0)) { if ((temp_f22 > -20.0) && (temp_f22 < 20.0)) { if (((temp_f14) > -100.0) && ((temp_f14) < 100.0)) { - if (func_80006018(vehicle->position[0], vehicle->position[2], vehicle->velocity[0], - vehicle->velocity[2], arg3, arg4, spC4, spBC) == (s32) 1) { + if (is_collide_with_vehicle(vehicle->position[0], vehicle->position[2], vehicle->velocity[0], + vehicle->velocity[2], arg3, arg4, playerX, playerZ) == (s32) 1) { player->soundEffects |= REVERSE_SOUND_EFFECT; } } @@ -5176,10 +5197,11 @@ void func_80013F7C(s32 playerId, Player* player, VehicleStuff* vehicle, f32 arg3 case 0: t1 = func_80007BF8(vehicle->waypointIndex, gNearestWaypointByPlayerId[playerId], 10, 0, path); - if ((D_80163270[playerId] == 0) && (t1 > 0) && (player->unk_094 < vehicle->speed)) { + if ((gIsPlayerWrongDirection[playerId] == 0) && (t1 > 0) && + (player->unk_094 < vehicle->speed)) { var_s1 = 1; } - if ((D_80163270[playerId] == 1) && (t1 > 0)) { + if ((gIsPlayerWrongDirection[playerId] == 1) && (t1 > 0)) { var_s1 = 1; } break; @@ -5188,11 +5210,12 @@ void func_80013F7C(s32 playerId, Player* player, VehicleStuff* vehicle, f32 arg3 path); if (t2 > 0) { if (random_int(2) == 0) { - // temp_v1_2 = D_80163270[playerId]; - if (D_80163270[playerId] == 0) { + // temp_v1_2 = gIsPlayerWrongDirection[playerId]; + if (gIsPlayerWrongDirection[playerId] == 0) { var_s1 = 1; } - if ((D_80163270[playerId] == 1) && (player->unk_094 < vehicle->speed)) { + if ((gIsPlayerWrongDirection[playerId] == 1) && + (player->unk_094 < vehicle->speed)) { var_s1 = 1; } } else { @@ -5317,7 +5340,7 @@ void init_vehicles_box_trucks(void) { if (gModeSelection == TIME_TRIALS) { numTrucks = NUM_TIME_TRIAL_BOX_TRUCKS; } - initialize_toads_turnpike_vehicle(a, b, numTrucks, 0, gBoxTruckList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numTrucks, 0, gBoxTruckList, &gTrackWaypoints[0][0]); } void update_vehicle_box_trucks(void) { @@ -5345,7 +5368,7 @@ void init_vehicles_school_buses(void) { if (gModeSelection == TIME_TRIALS) { numBusses = NUM_TIME_TRIAL_SCHOOL_BUSES; } - initialize_toads_turnpike_vehicle(a, b, numBusses, 75, gSchoolBusList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numBusses, 75, gSchoolBusList, &gTrackWaypoints[0][0]); } void update_vehicle_school_bus(void) { @@ -5373,7 +5396,7 @@ void init_vehicles_trucks(void) { if (gModeSelection == TIME_TRIALS) { numTrucks = NUM_TIME_TRIAL_TANKER_TRUCKS; } - initialize_toads_turnpike_vehicle(a, b, numTrucks, 50, gTankerTruckList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numTrucks, 50, gTankerTruckList, &gTrackWaypoints[0][0]); } void update_vehicle_tanker_trucks(void) { @@ -5401,7 +5424,7 @@ void init_vehicles_cars(void) { if (gModeSelection == TIME_TRIALS) { numCars = NUM_TIME_TRIAL_CARS; } - initialize_toads_turnpike_vehicle(a, b, numCars, 25, gCarList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numCars, 25, gCarList, &gTrackWaypoints[0][0]); } void update_vehicle_cars(void) { @@ -5424,7 +5447,7 @@ void func_80014D30(s32 cameraId, s32 pathIndex) { TrackWaypoint* temp_v0; cameraWaypoint = gNearestWaypointByCameraId[cameraId]; - temp_v0 = &D_80164550[pathIndex][cameraWaypoint]; + temp_v0 = &gTrackWaypoints[pathIndex][cameraWaypoint]; check_bounding_collision(&cameras[cameraId].collision, 10.0f, (f32) temp_v0->posX, (f32) temp_v0->posY + 30.0f, (f32) temp_v0->posZ); } @@ -5643,12 +5666,12 @@ void func_80015544(s32 playerId, f32 arg1, s32 cameraId, s32 pathIndex) { func_8000BBD8(gNearestWaypointByCameraId[cameraId], arg1, pathIndex); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164638[cameraId] = gOffsetPosition[2]; - temp_f2 = (f32) D_80164550[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; + temp_f2 = (f32) gTrackWaypoints[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; - temp_f12 = get_surface_height(D_80162FA0[0], (f32) (temp_f2 + 30.0), D_80162FA0[2]); + temp_f12 = get_surface_height(gOffsetPosition[0], (f32) (temp_f2 + 30.0), gOffsetPosition[2]); if ((temp_f12 < (temp_f2 - 20.0)) || (temp_f12 >= 3000.0)) { D_80164618[cameraId] = (f32) (temp_f2 + 10.0); } else { @@ -5726,9 +5749,9 @@ void func_80015A9C(s32 playerId, f32 arg1, s32 cameraId, s16 pathIndex) { func_8000BBD8(gNearestWaypointByCameraId[cameraId], arg1, pathIndex); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164618[cameraId] = (f32) D_80164550[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164618[cameraId] = (f32) gTrackWaypoints[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; + D_80164638[cameraId] = gOffsetPosition[2]; D_80164648[cameraId] = gPlayers[playerId].unk_094 / 5.0f; if ((f64) D_80164648[cameraId] < 0.0) { @@ -5783,12 +5806,12 @@ void func_80015C94(Camera* camera, UNUSED Player* unusedPlayer, UNUSED s32 arg2, waypoint1 = (gNearestWaypointByCameraId[cameraId] + 1) % gWaypointCountByPathIndex[pathIndex]; waypoint2 = (gNearestWaypointByCameraId[cameraId] + 2) % gWaypointCountByPathIndex[pathIndex]; func_8000BBD8(waypoint1, D_80164688[cameraId], pathIndex); - midX = D_80162FA0[0] * 0.5; - midZ = D_80162FA0[2] * 0.5; + midX = gOffsetPosition[0] * 0.5; + midZ = gOffsetPosition[2] * 0.5; func_8000BBD8(waypoint2, D_80164688[cameraId], pathIndex); - midX += D_80162FA0[0] * 0.5; - midZ += D_80162FA0[2] * 0.5; - midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) / 2.0; + midX += gOffsetPosition[0] * 0.5; + midZ += gOffsetPosition[2] * 0.5; + midY = (gTrackWaypoints[pathIndex][waypoint1].posY + gTrackWaypoints[pathIndex][waypoint2].posY) / 2.0; xdiff = midX - D_801645F8[cameraId]; ydiff = midY - D_80164618[cameraId]; zdiff = midZ - D_80164638[cameraId]; @@ -5835,9 +5858,9 @@ void func_800162CC(s32 playerId, f32 arg1, s32 cameraId, s16 pathIndex) { func_8000BBD8(gNearestWaypointByCameraId[cameraId], arg1, pathIndex); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164618[cameraId] = (f32) D_80164550[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164618[cameraId] = (f32) gTrackWaypoints[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; + D_80164638[cameraId] = gOffsetPosition[2]; D_80164658[cameraId] = gPlayers[playerId].unk_094; D_80164648[cameraId] = gPlayers[playerId].unk_094; @@ -5911,12 +5934,12 @@ void func_80016494(Camera* camera, UNUSED Player* unusedPlayer, UNUSED s32 arg2, waypoint1 = (gNearestWaypointByCameraId[cameraId] + 1) % gWaypointCountByPathIndex[pathIndex]; waypoint2 = (gNearestWaypointByCameraId[cameraId] + 2) % gWaypointCountByPathIndex[pathIndex]; func_8000BBD8(waypoint1, D_80164688[cameraId], pathIndex); - midX = D_80162FA0[0] * 0.5; - midZ = D_80162FA0[2] * 0.5; + midX = gOffsetPosition[0] * 0.5; + midZ = gOffsetPosition[2] * 0.5; func_8000BBD8(waypoint2, D_80164688[cameraId], pathIndex); - midX += D_80162FA0[0] * 0.5; - midZ += D_80162FA0[2] * 0.5; - midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) / 2.0; + midX += gOffsetPosition[0] * 0.5; + midZ += gOffsetPosition[2] * 0.5; + midY = (gTrackWaypoints[pathIndex][waypoint1].posY + gTrackWaypoints[pathIndex][waypoint2].posY) / 2.0; xdiff = midX - D_801645F8[cameraId]; ydiff = midY - D_80164618[cameraId]; zdiff = midZ - D_80164638[cameraId]; @@ -5979,20 +6002,20 @@ void func_80016C3C(UNUSED s32 playerId, UNUSED f32 arg1, s32 cameraId) { temp_s0 = gWaypointCountByPathIndex[D_80163DD8[cameraId]]; gNearestWaypointByCameraId[cameraId] %= temp_s0; func_8000BBD8(gNearestWaypointByCameraId[cameraId], D_80164688[cameraId], 0); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164618[cameraId] = D_80164550[0][gNearestWaypointByCameraId[cameraId]].posY; - path = D_80164550; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164618[cameraId] = gTrackWaypoints[0][gNearestWaypointByCameraId[cameraId]].posY; + path = gTrackWaypoints; + D_80164638[cameraId] = gOffsetPosition[2]; D_80164658[cameraId] = 16.666666f; D_80164648[cameraId] = 0.0f; sp48 = (gNearestWaypointByCameraId[cameraId] + 0xA) % temp_s0; sp44 = (gNearestWaypointByCameraId[cameraId] + 0xB) % temp_s0; func_8000BBD8(sp48, D_80164688[cameraId], 0); - temp_f2 = D_80162FA0[0] * 0.5; - temp_f12 = D_80162FA0[2] * 0.5; + temp_f2 = gOffsetPosition[0] * 0.5; + temp_f12 = gOffsetPosition[2] * 0.5; func_8000BBD8(sp44, D_80164688[cameraId], 0); - temp_f2 += D_80162FA0[0] * 0.5; - temp_f12 += D_80162FA0[2] * 0.5; + temp_f2 += gOffsetPosition[0] * 0.5; + temp_f12 += gOffsetPosition[2] * 0.5; sp48 = (gNearestWaypointByCameraId[cameraId] + 0x5) % temp_s0; sp44 = (gNearestWaypointByCameraId[cameraId] + 0x6) % temp_s0; sp54 = (path[0][sp48].posY + path[0][sp44].posY) * 0.5f; @@ -6059,23 +6082,23 @@ void func_80017054(Camera* camera, UNUSED Player* player, UNUSED s32 index, s32 sp6E = (gNearestWaypointByCameraId[cameraId] + 0xA) % sp58; sp6C = (gNearestWaypointByCameraId[cameraId] + 0xB) % sp58; func_8000BBD8(sp6E, D_80164688[cameraId], pathIndex); - sp8C = D_80162FA0[0] * 0.5; - sp84 = D_80162FA0[2] * 0.5; + sp8C = gOffsetPosition[0] * 0.5; + sp84 = gOffsetPosition[2] * 0.5; func_8000BBD8(sp6C, D_80164688[cameraId], pathIndex); - sp8C += D_80162FA0[0] * 0.5; - sp84 += D_80162FA0[2] * 0.5; + sp8C += gOffsetPosition[0] * 0.5; + sp84 += gOffsetPosition[2] * 0.5; sp6E = (gNearestWaypointByCameraId[cameraId] + 5) % sp58; sp6C = (gNearestWaypointByCameraId[cameraId] + 6) % sp58; - sp88 = (D_80164550[pathIndex][sp6E].posY + D_80164550[pathIndex][sp6C].posY) * 0.5f; + sp88 = (gTrackWaypoints[pathIndex][sp6E].posY + gTrackWaypoints[pathIndex][sp6C].posY) * 0.5f; sp6E = (gNearestWaypointByCameraId[cameraId] + 1) % sp58; sp6C = (gNearestWaypointByCameraId[cameraId] + 2) % sp58; func_8000BBD8(sp6E, D_80164688[cameraId], pathIndex); - sp98 = D_80162FA0[0] * 0.5; - sp90 = D_80162FA0[2] * 0.5; + sp98 = gOffsetPosition[0] * 0.5; + sp90 = gOffsetPosition[2] * 0.5; func_8000BBD8(sp6C, D_80164688[cameraId], pathIndex); - sp98 += D_80162FA0[0] * 0.5; - sp90 += D_80162FA0[2] * 0.5; - sp94 = (D_80164550[pathIndex][sp6E].posY + D_80164550[pathIndex][sp6C].posY) * 0.5f; + sp98 += gOffsetPosition[0] * 0.5; + sp90 += gOffsetPosition[2] * 0.5; + sp94 = (gTrackWaypoints[pathIndex][sp6E].posY + gTrackWaypoints[pathIndex][sp6C].posY) * 0.5f; stackPadding4 = sp98 - D_801645F8[cameraId]; stackPadding5 = sp90 - D_80164618[cameraId]; stackPadding6 = sp94 - D_80164638[cameraId]; @@ -6128,9 +6151,9 @@ void func_80017720(s32 playerId, UNUSED f32 arg1, s32 cameraId, s16 pathIndex) { func_8000BBD8(gNearestWaypointByCameraId[cameraId], D_80163068[playerId], pathIndex); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164618[cameraId] = (f32) D_80164550[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164618[cameraId] = (f32) gTrackWaypoints[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; + D_80164638[cameraId] = gOffsetPosition[2]; D_80164658[cameraId] = gPlayers[playerId].unk_094; D_80164648[cameraId] = gPlayers[playerId].unk_094; @@ -6196,12 +6219,12 @@ void func_800178F4(Camera* camera, UNUSED Player* unusedPlayer, UNUSED s32 arg2, waypoint1 = (gNearestWaypointByCameraId[cameraId] + 1) % waypointCount; waypoint2 = (gNearestWaypointByCameraId[cameraId] + 2) % waypointCount; func_8000BBD8(waypoint1, D_80164688[cameraId], pathIndex); - midX = D_80162FA0[0] * 0.5; - midZ = D_80162FA0[2] * 0.5; + midX = gOffsetPosition[0] * 0.5; + midZ = gOffsetPosition[2] * 0.5; func_8000BBD8(waypoint2, D_80164688[cameraId], pathIndex); - midX += D_80162FA0[0] * 0.5; - midZ += D_80162FA0[2] * 0.5; - midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) / 2.0; + midX += gOffsetPosition[0] * 0.5; + midZ += gOffsetPosition[2] * 0.5; + midY = (gTrackWaypoints[pathIndex][waypoint1].posY + gTrackWaypoints[pathIndex][waypoint2].posY) / 2.0; xdiff = midX - D_801645F8[cameraId]; ydiff = midY - D_80164618[cameraId]; zdiff = midZ - D_80164638[cameraId]; @@ -6243,9 +6266,9 @@ void func_80017F10(s32 playerId, UNUSED f32 arg1, s32 cameraId, s16 pathIndex) { func_8000BBD8(gNearestWaypointByCameraId[cameraId], D_80163068[playerId], pathIndex); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164618[cameraId] = (f32) D_80164550[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164618[cameraId] = (f32) gTrackWaypoints[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; + D_80164638[cameraId] = gOffsetPosition[2]; D_80164658[cameraId] = gPlayers[playerId].unk_094; D_80164648[cameraId] = gPlayers[playerId].unk_094; @@ -6311,12 +6334,12 @@ void func_800180F0(Camera* camera, UNUSED Player* unusedPlayer, UNUSED s32 arg2, waypoint1 = (gNearestWaypointByCameraId[cameraId] + 1) % waypointCount; waypoint2 = (gNearestWaypointByCameraId[cameraId] + 2) % waypointCount; func_8000BBD8(waypoint1, D_80164688[cameraId], pathIndex); - midX = D_80162FA0[0] * 0.5; - midZ = D_80162FA0[2] * 0.5; + midX = gOffsetPosition[0] * 0.5; + midZ = gOffsetPosition[2] * 0.5; func_8000BBD8(waypoint2, D_80164688[cameraId], pathIndex); - midX += D_80162FA0[0] * 0.5; - midZ += D_80162FA0[2] * 0.5; - midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) / 2.0; + midX += gOffsetPosition[0] * 0.5; + midZ += gOffsetPosition[2] * 0.5; + midY = (gTrackWaypoints[pathIndex][waypoint1].posY + gTrackWaypoints[pathIndex][waypoint2].posY) / 2.0; xdiff = midX - D_801645F8[cameraId]; ydiff = midY - D_80164618[cameraId]; zdiff = midZ - D_80164638[cameraId]; @@ -6355,11 +6378,11 @@ void func_80018718(s32 playerId, UNUSED f32 arg1, s32 cameraId, s16 pathIndex) { D_80164688[cameraId] = D_80163068[playerId]; gNearestWaypointByCameraId[cameraId] = ((gNearestWaypointByPlayerId[playerId] + test) - 5) % test; - func_8000BA14(gNearestWaypointByCameraId[cameraId], D_80163068[playerId], 60.0f, pathIndex); + calculate_track_offset_position(gNearestWaypointByCameraId[cameraId], D_80163068[playerId], 60.0f, pathIndex); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164618[cameraId] = (f32) D_80164550[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; - D_80164638[cameraId] = D_80162FA0[2]; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164618[cameraId] = (f32) gTrackWaypoints[pathIndex][gNearestWaypointByCameraId[cameraId]].posY; + D_80164638[cameraId] = gOffsetPosition[2]; D_80164658[cameraId] = gPlayers[playerId].unk_094; D_80164648[cameraId] = gPlayers[playerId].unk_094; @@ -6440,13 +6463,13 @@ void func_800188F4(Camera* camera, UNUSED Player* unusePlayer, UNUSED s32 arg2, } waypoint1 = (gNearestWaypointByCameraId[cameraId] + 1) % waypointCount; waypoint2 = (gNearestWaypointByCameraId[cameraId] + 2) % waypointCount; - func_8000BA14(waypoint1, D_80164688[cameraId], 60.0f, pathIndex); - midX = D_80162FA0[0] * 0.5; - midZ = D_80162FA0[2] * 0.5; - func_8000BA14(waypoint2, D_80164688[cameraId], 60.0f, pathIndex); - midX += D_80162FA0[0] * 0.5; - midZ += D_80162FA0[2] * 0.5; - midY = (D_80164550[pathIndex][waypoint1].posY + D_80164550[pathIndex][waypoint2].posY) / 2.0; + calculate_track_offset_position(waypoint1, D_80164688[cameraId], 60.0f, pathIndex); + midX = gOffsetPosition[0] * 0.5; + midZ = gOffsetPosition[2] * 0.5; + calculate_track_offset_position(waypoint2, D_80164688[cameraId], 60.0f, pathIndex); + midX += gOffsetPosition[0] * 0.5; + midZ += gOffsetPosition[2] * 0.5; + midY = (gTrackWaypoints[pathIndex][waypoint1].posY + gTrackWaypoints[pathIndex][waypoint2].posY) / 2.0; xdiff = midX - D_801645F8[cameraId]; ydiff = midY - D_80164618[cameraId]; zdiff = midZ - D_80164638[cameraId]; @@ -6494,11 +6517,11 @@ void func_80019118(s32 playerId, f32 arg1, s32 cameraId, UNUSED s16 pathIndex) { gNearestWaypointByCameraId[cameraId] = gNearestWaypointByCameraId[cameraId] % test; func_8000BBD8(gNearestWaypointByCameraId[cameraId], arg1, 0); - D_801645F8[cameraId] = D_80162FA0[0]; - D_80164638[cameraId] = D_80162FA0[2]; - temp_f2 = (f32) D_80164550[0][gNearestWaypointByCameraId[cameraId]].posY; + D_801645F8[cameraId] = gOffsetPosition[0]; + D_80164638[cameraId] = gOffsetPosition[2]; + temp_f2 = (f32) gTrackWaypoints[0][gNearestWaypointByCameraId[cameraId]].posY; - temp_f12 = get_surface_height(D_80162FA0[0], (f32) (temp_f2 + 30.0), D_80162FA0[2]); + temp_f12 = get_surface_height(gOffsetPosition[0], (f32) (temp_f2 + 30.0), gOffsetPosition[2]); if ((temp_f12 < (temp_f2 - 20.0)) || (temp_f12 >= 3000.0)) { D_80164618[cameraId] = (f32) (temp_f2 + 10.0); @@ -6547,7 +6570,7 @@ void func_8001933C(Camera* camera, UNUSED Player* playerArg, UNUSED s32 arg2, s3 camera->pos[0] = D_801645F8[cameraId]; camera->pos[1] = D_80164618[cameraId]; camera->pos[2] = D_80164638[cameraId]; - waypoint = &D_80164550[pathIndex][cameraWaypoint]; + waypoint = &gTrackWaypoints[pathIndex][cameraWaypoint]; camera->lookAt[0] = (player->pos[0] * 0.8) + (0.2 * waypoint->posX); camera->lookAt[1] = (player->pos[1] * 0.8) + (0.2 * waypoint->posY); camera->lookAt[2] = (player->pos[2] * 0.8) + (0.2 * waypoint->posZ); @@ -6569,7 +6592,7 @@ void func_8001969C(UNUSED s32 playerId, UNUSED f32 arg1, s32 cameraId, UNUSED s1 gNearestWaypointByCameraId[cameraId] = gWaypointCountByPathIndex[0] - 18; - waypoint = &D_80164550[0][gNearestWaypointByCameraId[cameraId]]; + waypoint = &gTrackWaypoints[0][gNearestWaypointByCameraId[cameraId]]; D_801645F8[cameraId] = waypoint->posX; //! @bug Adding an (f32) cast changes asm, why? @@ -6589,7 +6612,7 @@ void func_80019760(Camera* camera, UNUSED Player* player, UNUSED s32 arg2, s32 c camera->pos[0] = D_801645F8[cameraId]; camera->pos[1] = D_80164618[cameraId]; camera->pos[2] = D_80164638[cameraId]; - temp_v1 = &(*D_80164550)[gNearestWaypointByCameraId[cameraId]]; + temp_v1 = &(*gTrackWaypoints)[gNearestWaypointByCameraId[cameraId]]; camera->lookAt[0] = (f32) temp_v1->posX; camera->lookAt[1] = (f32) temp_v1->posY; camera->lookAt[2] = (f32) temp_v1->posZ; @@ -7239,9 +7262,9 @@ void kart_ai_use_item_strategy(s32 playerId) { temp_s0->unk_00 = 0x0023; temp_s0->unk_04 = 0; temp_s0->unk_06 += 1; - waypoint = &D_80164550[gPathIndexByPlayerId[0]] - [(gNearestWaypointByPlayerId[D_80163478] + 0x1E) % - gWaypointCountByPathIndex[gPathIndexByPlayerId[D_80163478]]]; + waypoint = &gTrackWaypoints[gPathIndexByPlayerId[0]] + [(gNearestWaypointByPlayerId[D_80163478] + 0x1E) % + gWaypointCountByPathIndex[gPathIndexByPlayerId[D_80163478]]]; banana->velocity[0] = (waypoint->posX - player->pos[0]) / 20.0; banana->velocity[1] = ((waypoint->posY - player->pos[1]) / 20.0) + 4.0; banana->velocity[2] = (waypoint->posZ - player->pos[2]) / 20.0; @@ -7636,12 +7659,12 @@ void func_8001BE78(void) { gNearestWaypointByPlayerId[i] = 1; break; } - temp_s0 = &D_80164550[i][gNearestWaypointByPlayerId[i]]; + temp_s0 = &gTrackWaypoints[i][gNearestWaypointByPlayerId[i]]; temp_s1->pos[0] = (f32) temp_s0->posX; temp_s1->pos[1] = get_surface_height((f32) temp_s0->posX, 2000.0f, (f32) temp_s0->posZ) + temp_s1->boundingBoxSize; temp_s1->pos[2] = (f32) temp_s0->posZ; - temp_s1->rotation[1] = (s16) *D_80164590[i]; + temp_s1->rotation[1] = (s16) *gWaypointExpectedRotation[i]; func_8003680C(temp_s1, 0); temp_s1++; D_80163410[i] = 0; @@ -7655,7 +7678,7 @@ void func_8001C05C(void) { D_8016347E = 0; D_80163480 = 0; D_80163484 = 0; - func_8000F2DC(); + init_course_waypoint(); func_80014DE4(0); func_8001BE78(); D_80163418[0] = -3202.475097656f; diff --git a/src/code_80005FD0.h b/src/code_80005FD0.h index 61dff3435..a1a47010a 100644 --- a/src/code_80005FD0.h +++ b/src/code_80005FD0.h @@ -61,14 +61,14 @@ typedef struct { /* Function Prototypes */ s16 get_angle_between_waypoints(Vec3f, Vec3f); -s32 func_80006018(f32, f32, f32, f32, f32, f32, f32, f32); +s32 is_collide_with_vehicle(f32, f32, f32, f32, f32, f32, f32, f32); void adjust_position_by_angle(Vec3f, Vec3f, s16); s32 set_vehicle_render_distance_flags(Vec3f, f32, s32); -void func_800065D0(s32, Player*); +void detect_player_wrong_direction(s32, Player*); void set_places(void); -void func_800070F4(void); -void func_800074D4(void); +void update_places(void); +void set_places_end_course_with_time(void); s32 func_80007BF8(u16, u16, u16, u16, u16); void func_80007D04(s32, Player*); void func_80007FA4(s32, Player*, f32); @@ -93,7 +93,7 @@ s32 func_8000B7E4(s32, u16); s32 func_8000B820(s32); f32 func_8000B874(f32, f32, u16, s32); void func_8000B95C(s32, u16, s32); -void func_8000BA14(u16, f32, f32, s16); +void calculate_track_offset_position(u16, f32, f32, s16); void func_8000BBD8(u16, f32, s16); s16 func_8000BD94(f32, f32, f32, s32); @@ -127,12 +127,12 @@ void generate_player_smoke(void); void func_8000F0E0(void); void func_8000F124(void); -void func_8000F2BC(TrackWaypoint*, size_t); -void func_8000F2DC(void); +void clear_waypoint(TrackWaypoint*, size_t); +void init_course_waypoint(void); void func_8000F628(void); -void func_800100F0(s32); -void func_80010218(s32); +void load_track_waypoint(s32); +void calculate_track_boundaries(s32); f32 func_80010480(s32, u16); void func_800107C4(s32); s16 func_80010CB0(s32, s32); @@ -261,7 +261,7 @@ extern s16 D_80162EB2; // possibly [3] extern KartAIBehaviour* gCoursesKartAIBehaviour[]; extern s16 D_80162F10[]; extern s16 D_80162F50[]; -extern Vec3f D_80162FA0; +extern Vec3f gOffsetPosition; extern Vec3f D_80162FB0; extern Vec3f D_80162FC0; extern s16 gTrainSmokeTimer; @@ -294,8 +294,8 @@ extern f32 D_8016320C; extern f32 D_80163210[]; extern s32 D_80163238; extern u16 D_80163240[]; -extern u16 D_80163258[]; -extern u16 D_80163270[]; +extern u16 gWrongDirectionCounter[]; +extern u16 gIsPlayerWrongDirection[]; extern s32 D_80163288[]; // Exact pointer type unknown extern KartAIBehaviour* sCurrentKartAIBehaviour; @@ -408,6 +408,12 @@ extern s32 D_8016448C; extern u16 D_801637BE; extern u16 D_80163E2A; +#define SEVERE_WRONG_DIRECTION_MIN 136 +#define SEVERE_WRONG_DIRECTION_MAX 225 +#define SEVERE_CORRECT_DIRECTION_MIN 45 +#define SEVERE_CORRECT_DIRECTION_MAX 316 +#define WRONG_DIRECTION_FRAMES_LIMIT 5 + // extern Gfx D_0D0076F8[]; #endif diff --git a/src/code_8003DC40.c b/src/code_8003DC40.c index b97838b71..220a4c7c7 100644 --- a/src/code_8003DC40.c +++ b/src/code_8003DC40.c @@ -61,6 +61,7 @@ UNUSED void func_8003DE4C(Player* player, Vec3f arg1) { arg1[1] = 0.0f; mtxf_translate_vec3f_mat3(arg1, player->orientationMatrix); } + // Stick to ground? void func_8003E048(Player* player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7) { *arg5 += arg1[0] * player->collision.surfaceDistance[2] * 1; diff --git a/src/effects.c b/src/effects.c index eef7a0bb5..fe7564bee 100644 --- a/src/effects.c +++ b/src/effects.c @@ -1701,13 +1701,13 @@ void func_80090178(Player* player, s8 playerId, Vec3f arg2, Vec3f arg3) { switch (gCurrentCourseId) { case COURSE_YOSHI_VALLEY: test = player->nearestWaypointId; - temp_v1 = &D_80164550[gCopyPathIndexByPlayerId[playerId]][test]; + temp_v1 = &gTrackWaypoints[gCopyPathIndexByPlayerId[playerId]][test]; arg2[0] = temp_v1->posX; arg2[1] = temp_v1->posY; arg2[2] = temp_v1->posZ; - temp_v1 = &D_80164550[gCopyPathIndexByPlayerId[playerId]] - [(player->nearestWaypointId + 5) % - (gWaypointCountByPathIndex[gCopyPathIndexByPlayerId[playerId]] + 1)]; + temp_v1 = &gTrackWaypoints[gCopyPathIndexByPlayerId[playerId]] + [(player->nearestWaypointId + 5) % + (gWaypointCountByPathIndex[gCopyPathIndexByPlayerId[playerId]] + 1)]; arg3[0] = temp_v1->posX; arg3[1] = temp_v1->posY; arg3[2] = temp_v1->posZ; @@ -1746,11 +1746,11 @@ void func_80090178(Player* player, s8 playerId, Vec3f arg2, Vec3f arg3) { break; default: test = player->nearestWaypointId; - temp_v1 = &D_80164550[0][test]; + temp_v1 = &gTrackWaypoints[0][test]; arg2[0] = temp_v1->posX; arg2[1] = temp_v1->posY; arg2[2] = temp_v1->posZ; - temp_v1 = &D_80164550[0][(player->nearestWaypointId + 5) % (gWaypointCountByPathIndex[0] + 1)]; + temp_v1 = &gTrackWaypoints[0][(player->nearestWaypointId + 5) % (gWaypointCountByPathIndex[0] + 1)]; arg3[0] = temp_v1->posX; arg3[1] = temp_v1->posY; arg3[2] = temp_v1->posZ; @@ -1921,7 +1921,7 @@ void func_80090970(Player* player, s8 playerId, s8 arg2) { player->pos[0] = player->pos[0] + sins(-player->rotation[1]) * -10.0f; } if (player->unk_0C8 == 0x00FC) { - waypoint = D_80164550[0]; + waypoint = gTrackWaypoints[0]; player->pos[0] = waypoint->posX; player->pos[1] = waypoint->posY; player->pos[2] = waypoint->posZ; diff --git a/src/math_util_2.h b/src/math_util_2.h index 3dc40c696..591c6f210 100644 --- a/src/math_util_2.h +++ b/src/math_util_2.h @@ -79,6 +79,8 @@ void rsp_set_matrix_transformation_inverted_x_y_orientation(Vec3f, Vec3su, f32); void rsp_set_matrix_transl_rot_scale(Vec3f, Vec3f, f32); void rsp_set_matrix_gObjectList(s32); +#define DEGREES_CONVERSION_FACTOR 182 + /* This is where I'd put my static data, if I had any */ extern s8 D_801658FE; diff --git a/src/racing/race_logic.c b/src/racing/race_logic.c index 257cff0ac..cfef19179 100644 --- a/src/racing/race_logic.c +++ b/src/racing/race_logic.c @@ -139,7 +139,7 @@ void func_8028E298(void) { gTimePlayerLastTouchedFinishLine[i] = gCourseTimer + temp_v0; } D_8016348C = 1; - func_800070F4(); + update_places(); } void func_8028E3A0(void) { @@ -625,7 +625,7 @@ void func_8028EF28(void) { } if ((D_802BA048 != 0) && (D_802BA048 != 100)) { D_802BA048 = 100; - func_800074D4(); + set_places_end_course_with_time(); } } diff --git a/src/spawn_players.c b/src/spawn_players.c index 83a16cd19..4efdf0acf 100644 --- a/src/spawn_players.c +++ b/src/spawn_players.c @@ -871,10 +871,10 @@ void func_8003C0F0(void) { case COURSE_RAINBOW_ROAD: case COURSE_WARIO_STADIUM: case COURSE_DK_JUNGLE: - func_8000F2DC(); - sp5E = (f32) D_80164550[0][0].posX; - sp5C = (f32) D_80164550[0][0].posZ; - sp5A = (f32) D_80164550[0][0].posY; + init_course_waypoint(); + sp5E = (f32) gTrackWaypoints[0][0].posX; + sp5C = (f32) gTrackWaypoints[0][0].posZ; + sp5A = (f32) gTrackWaypoints[0][0].posY; if (gCurrentCourseId == COURSE_TOADS_TURNPIKE) { sp5E = 0; }