From 804e9d01d4c033a44fecf1a01c3c8ab276fa11a0 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 30 Dec 2019 20:09:43 +1000 Subject: [PATCH] Decompile aiSetDrCarollImages --- src/files/setup/setuppam.c | 56 +++++----- src/game/chr/chr.c | 12 +- src/game/chr/chraicommands.c | 158 ++++++--------------------- src/include/commands.h | 11 +- src/include/constants.h | 12 +- src/include/game/chr/chraicommands.h | 2 +- src/include/gvars/gvars.h | 2 +- src/include/types.h | 4 +- src/setup/setup_000000.c | 2 +- 9 files changed, 87 insertions(+), 172 deletions(-) diff --git a/src/files/setup/setuppam.c b/src/files/setup/setuppam.c index 529bc9ad6..5b56d163d 100644 --- a/src/files/setup/setuppam.c +++ b/src/files/setup/setuppam.c @@ -1523,7 +1523,7 @@ u8 func0c01_midcutscene[] = { #define wait_until_with_images(time, loopid, image1, image2) \ beginloop(loopid) \ - set_drcaroll_image(CHR_DRCAROLL, image1, image2) \ + set_drcaroll_images(CHR_DRCAROLL, image1, image2) \ if_controller_button_pressed(/*goto*/ 0x57) \ if_timer_gt(time, /*goto*/ 0x06) \ endloop(loopid) \ @@ -1552,16 +1552,16 @@ u8 func0c01_midcutscene[] = { wait_until(570, 0x69) label(0x6c) - set_drcaroll_image(CHR_DRCAROLL, 0x02, 0x03) + set_drcaroll_images(CHR_DRCAROLL, 0x02, 0x03) yield - set_drcaroll_image(CHR_DRCAROLL, 0x03, 0x02) + set_drcaroll_images(CHR_DRCAROLL, 0x03, 0x02) yield if_controller_button_pressed(/*goto*/ 0x57) if_timer_gt(600, /*goto*/ 0x06) goto_first(0x6c) label(0x06) - set_drcaroll_image(CHR_DRCAROLL, 0x02, 0x02) + set_drcaroll_images(CHR_DRCAROLL, 0x02, 0x02) speak(CHR_BOND, 0x3025, 0x746f, CHANNEL_10, COLOR_09_BLUE) // "Me and my big mouth." wait_until(700, 0x6d) @@ -1575,7 +1575,7 @@ u8 func0c01_midcutscene[] = { label(0x71) yield - set_drcaroll_image(CHR_DRCAROLL, 0x07, 0x07) + set_drcaroll_images(CHR_DRCAROLL, 0x07, 0x07) if_controller_button_pressed(/*goto*/ 0x57) if_timer_gt(742, /*goto*/ 0x06) goto_first(0x71) @@ -1628,7 +1628,7 @@ u8 func0c01_midcutscene[] = { wait_until_with_images(1034, 0x94, 0x08, 0x00) play_sound(0x0176, CHANNEL_2) - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) wait_until_with_images(1036, 0x95, 0x08, 0x08) emit_sparks(CHR_DRCAROLL) @@ -1688,7 +1688,7 @@ u8 func0c01_midcutscene[] = { wait_until_with_images(1500, 0xd4, 0x08, 0x00) speak(CHR_BOND, 0x3027, 0x7471, CHANNEL_10, COLOR_09_BLUE) // "Dr. Caroll? Are you in control again? Can you stop..." - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) wait_until(1534, 0xd6) play_sound(0x04f9, CHANNEL_6) @@ -1721,46 +1721,46 @@ u8 func0c01_midcutscene[] = { wait_until(3156, 0xf6) emit_sparks(CHR_DRCAROLL) - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) wait_until(3266, 0xf7) emit_sparks(CHR_DRCAROLL) - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) wait_until(3556, 0xf8) - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) emit_sparks(CHR_DRCAROLL) wait_until(3606, 0xf9) emit_sparks(CHR_DRCAROLL) - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) wait_until(3985, 0x10) play_sound(0x0424, CHANNEL_1) @@ -1768,13 +1768,13 @@ u8 func0c01_midcutscene[] = { wait_until(4046, 0xfa) emit_sparks(CHR_DRCAROLL) - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x08) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x08) yield - set_drcaroll_image(CHR_DRCAROLL, 0x00, 0x00) + set_drcaroll_images(CHR_DRCAROLL, 0x00, 0x00) wait_until(4106, 0xfb) emit_sparks(CHR_DRCAROLL) @@ -2018,7 +2018,7 @@ u8 func0c02_outro[] = { }; u8 func1002_intro[] = { - set_drcaroll_image(CHR_DRCAROLL, 0x02, 0x02) + set_drcaroll_images(CHR_DRCAROLL, 0x02, 0x02) chr_draw_weapon_in_cutscene(CHR_BOND, WEAPON_FALCON2_SCOPE) set_chr_chrflag(CHR_COOP, CHRCFLAG_HIDDEN) set_chr_chrflag(CHR_ANTI, CHRCFLAG_HIDDEN) diff --git a/src/game/chr/chr.c b/src/game/chr/chr.c index 7fb1b7253..68850f92f 100644 --- a/src/game/chr/chr.c +++ b/src/game/chr/chr.c @@ -22015,9 +22015,9 @@ void func0f03119c(struct chrdata *chr) chr->act_dead.unk03c = 0; chr->sleep = 0; - if (chr->race == RACE_MAIAN) { - chr->onlift_00 = 4; - chr->onlift_04 = 4; + if (chr->race == RACE_DRCAROLL) { + chr->drcarollimage_left = DRCAROLLIMAGE_DEAD; + chr->drcarollimage_right = DRCAROLLIMAGE_DEAD; } } } @@ -32392,7 +32392,7 @@ bool func0f03a578(struct chrdata *chr, s32 thingtype, s32 thingid) { s32 race = chr ? chr->race : RACE_HUMAN; - if (race == RACE_MAIAN || race == RACE_ROBOT) { + if (race == RACE_DRCAROLL || race == RACE_ROBOT) { return false; } @@ -32446,7 +32446,7 @@ bool func0f03a76c(struct chrdata *chr, u32 thingtype, s32 thingid) { s32 race = chr ? chr->race : RACE_HUMAN; - if (race == RACE_MAIAN || race == RACE_ROBOT) { + if (race == RACE_DRCAROLL || race == RACE_ROBOT) { return false; } @@ -37893,7 +37893,7 @@ void chrStopFiring(struct chrdata *chr) { u8 race = chr ? chr->race : RACE_HUMAN; - if (race != RACE_MAIAN && race != RACE_ROBOT && chr->unk2d4 == NULL) { + if (race != RACE_DRCAROLL && race != RACE_ROBOT && chr->unk2d4 == NULL) { chrSetFiring(chr, 0, false); chrSetFiring(chr, 1, false); chrResetAimEndProperties(chr); diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index 67c5d1234..8df7d5edf 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -13913,133 +13913,37 @@ bool aiChrEmitSparks(void) /** * @cmd 01d3 */ -GLOBAL_ASM( -glabel ai01d3 -/* f05f5f0: 27bdffd8 */ addiu $sp,$sp,-40 -/* f05f5f4: afb00018 */ sw $s0,0x18($sp) -/* f05f5f8: 3c10800a */ lui $s0,%hi(g_Vars) -/* f05f5fc: 26109fc0 */ addiu $s0,$s0,%lo(g_Vars) -/* f05f600: 8e0e0434 */ lw $t6,0x434($s0) -/* f05f604: 8e0f0438 */ lw $t7,0x438($s0) -/* f05f608: afbf001c */ sw $ra,0x1c($sp) -/* f05f60c: 8e040424 */ lw $a0,0x424($s0) -/* f05f610: 01cf1021 */ addu $v0,$t6,$t7 -/* f05f614: 90450002 */ lbu $a1,0x2($v0) -/* f05f618: 0fc126d1 */ jal chrFindById -/* f05f61c: afa20024 */ sw $v0,0x24($sp) -/* f05f620: 1040005d */ beqz $v0,.L0f05f798 -/* f05f624: 00401825 */ or $v1,$v0,$zero -/* f05f628: 8fb80024 */ lw $t8,0x24($sp) -/* f05f62c: 24010007 */ addiu $at,$zero,0x7 -/* f05f630: 93040004 */ lbu $a0,0x4($t8) -/* f05f634: 14810016 */ bne $a0,$at,.L0f05f690 -/* f05f638: 00802825 */ or $a1,$a0,$zero -/* f05f63c: 8e19000c */ lw $t9,0xc($s0) -/* f05f640: 24010002 */ addiu $at,$zero,0x2 -/* f05f644: 07210004 */ bgez $t9,.L0f05f658 -/* f05f648: 33280003 */ andi $t0,$t9,0x3 -/* f05f64c: 11000002 */ beqz $t0,.L0f05f658 -/* f05f650: 00000000 */ sll $zero,$zero,0x0 -/* f05f654: 2508fffc */ addiu $t0,$t0,-4 -.L0f05f658: -/* f05f658: 55010022 */ bnel $t0,$at,.L0f05f6e4 -/* f05f65c: 8faa0024 */ lw $t2,0x24($sp) -/* f05f660: 0c004b70 */ jal random -/* f05f664: afa30020 */ sw $v1,0x20($sp) -/* f05f668: 24010006 */ addiu $at,$zero,0x6 -/* f05f66c: 0041001b */ divu $zero,$v0,$at -/* f05f670: 8fa30020 */ lw $v1,0x20($sp) -/* f05f674: 00005010 */ mfhi $t2 -/* f05f678: 000a6100 */ sll $t4,$t2,0x4 -/* f05f67c: 906d0362 */ lbu $t5,0x362($v1) -/* f05f680: 31aeff0f */ andi $t6,$t5,0xff0f -/* f05f684: 018e7825 */ or $t7,$t4,$t6 -/* f05f688: 10000015 */ beqz $zero,.L0f05f6e0 -/* f05f68c: a06f0362 */ sb $t7,0x362($v1) -.L0f05f690: -/* f05f690: 24010008 */ addiu $at,$zero,0x8 -/* f05f694: 54a1000e */ bnel $a1,$at,.L0f05f6d0 -/* f05f698: 90580362 */ lbu $t8,0x362($v0) -/* f05f69c: 0c004b70 */ jal random -/* f05f6a0: afa30020 */ sw $v1,0x20($sp) -/* f05f6a4: 24010006 */ addiu $at,$zero,0x6 -/* f05f6a8: 0041001b */ divu $zero,$v0,$at -/* f05f6ac: 8fa30020 */ lw $v1,0x20($sp) -/* f05f6b0: 0000c810 */ mfhi $t9 -/* f05f6b4: 00194900 */ sll $t1,$t9,0x4 -/* f05f6b8: 906a0362 */ lbu $t2,0x362($v1) -/* f05f6bc: 314bff0f */ andi $t3,$t2,0xff0f -/* f05f6c0: 012b6825 */ or $t5,$t1,$t3 -/* f05f6c4: 10000006 */ beqz $zero,.L0f05f6e0 -/* f05f6c8: a06d0362 */ sb $t5,0x362($v1) -/* f05f6cc: 90580362 */ lbu $t8,0x362($v0) -.L0f05f6d0: -/* f05f6d0: 00047900 */ sll $t7,$a0,0x4 -/* f05f6d4: 3319ff0f */ andi $t9,$t8,0xff0f -/* f05f6d8: 01f94025 */ or $t0,$t7,$t9 -/* f05f6dc: a0480362 */ sb $t0,0x362($v0) -.L0f05f6e0: -/* f05f6e0: 8faa0024 */ lw $t2,0x24($sp) -.L0f05f6e4: -/* f05f6e4: 24010007 */ addiu $at,$zero,0x7 -/* f05f6e8: 91420003 */ lbu $v0,0x3($t2) -/* f05f6ec: 14410016 */ bne $v0,$at,.L0f05f748 -/* f05f6f0: 00402025 */ or $a0,$v0,$zero -/* f05f6f4: 8e09000c */ lw $t1,0xc($s0) -/* f05f6f8: 24010002 */ addiu $at,$zero,0x2 -/* f05f6fc: 05210004 */ bgez $t1,.L0f05f710 -/* f05f700: 312b0003 */ andi $t3,$t1,0x3 -/* f05f704: 11600002 */ beqz $t3,.L0f05f710 -/* f05f708: 00000000 */ sll $zero,$zero,0x0 -/* f05f70c: 256bfffc */ addiu $t3,$t3,-4 -.L0f05f710: -/* f05f710: 55610022 */ bnel $t3,$at,.L0f05f79c -/* f05f714: 8e0a0438 */ lw $t2,0x438($s0) -/* f05f718: 0c004b70 */ jal random -/* f05f71c: afa30020 */ sw $v1,0x20($sp) -/* f05f720: 24010006 */ addiu $at,$zero,0x6 -/* f05f724: 0041001b */ divu $zero,$v0,$at -/* f05f728: 8fa30020 */ lw $v1,0x20($sp) -/* f05f72c: 00006010 */ mfhi $t4 -/* f05f730: 318e000f */ andi $t6,$t4,0xf -/* f05f734: 90780362 */ lbu $t8,0x362($v1) -/* f05f738: 330ffff0 */ andi $t7,$t8,0xfff0 -/* f05f73c: 01cfc825 */ or $t9,$t6,$t7 -/* f05f740: 10000015 */ beqz $zero,.L0f05f798 -/* f05f744: a0790362 */ sb $t9,0x362($v1) -.L0f05f748: -/* f05f748: 24010008 */ addiu $at,$zero,0x8 -/* f05f74c: 5481000e */ bnel $a0,$at,.L0f05f788 -/* f05f750: 906f0362 */ lbu $t7,0x362($v1) -/* f05f754: 0c004b70 */ jal random -/* f05f758: afa30020 */ sw $v1,0x20($sp) -/* f05f75c: 24010006 */ addiu $at,$zero,0x6 -/* f05f760: 0041001b */ divu $zero,$v0,$at -/* f05f764: 8fa30020 */ lw $v1,0x20($sp) -/* f05f768: 00005010 */ mfhi $t2 -/* f05f76c: 3149000f */ andi $t1,$t2,0xf -/* f05f770: 906b0362 */ lbu $t3,0x362($v1) -/* f05f774: 316dfff0 */ andi $t5,$t3,0xfff0 -/* f05f778: 012d6025 */ or $t4,$t1,$t5 -/* f05f77c: 10000006 */ beqz $zero,.L0f05f798 -/* f05f780: a06c0362 */ sb $t4,0x362($v1) -/* f05f784: 906f0362 */ lbu $t7,0x362($v1) -.L0f05f788: -/* f05f788: 304e000f */ andi $t6,$v0,0xf -/* f05f78c: 31f9fff0 */ andi $t9,$t7,0xfff0 -/* f05f790: 01d94025 */ or $t0,$t6,$t9 -/* f05f794: a0680362 */ sb $t0,0x362($v1) -.L0f05f798: -/* f05f798: 8e0a0438 */ lw $t2,0x438($s0) -.L0f05f79c: -/* f05f79c: 8fbf001c */ lw $ra,0x1c($sp) -/* f05f7a0: 00001025 */ or $v0,$zero,$zero -/* f05f7a4: 254b0005 */ addiu $t3,$t2,0x5 -/* f05f7a8: ae0b0438 */ sw $t3,0x438($s0) -/* f05f7ac: 8fb00018 */ lw $s0,0x18($sp) -/* f05f7b0: 03e00008 */ jr $ra -/* f05f7b4: 27bd0028 */ addiu $sp,$sp,0x28 -); +bool aiSetDrCarollImages(void) +{ + u8 *cmd = g_Vars.ailist + g_Vars.aioffset; + struct chrdata *drcaroll = chrFindById(g_Vars.chrdata, cmd[2]); + + if (drcaroll) { + if (cmd[4] == 7) { + if ((g_Vars.unk00000c % 4) == 2) { + drcaroll->drcarollimage_left = random() % 6; + } + } else if (cmd[4] == 8) { + drcaroll->drcarollimage_left = random() % 6; + } else { + drcaroll->drcarollimage_left = cmd[4]; + } + + if (cmd[3] == 7) { + if ((g_Vars.unk00000c % 4) == 2) { + drcaroll->drcarollimage_right = random() % 6; + } + } else if (cmd[3] == 8) { + drcaroll->drcarollimage_right = random() % 6; + } else { + drcaroll->drcarollimage_right = cmd[3]; + } + } + + g_Vars.aioffset += 5; + + return false; +} /** * @cmd 01d4 diff --git a/src/include/commands.h b/src/include/commands.h index f523e668b..765643d65 100644 --- a/src/include/commands.h +++ b/src/include/commands.h @@ -2315,7 +2315,16 @@ mkshort(0x01d2), \ chr, -#define set_drcaroll_image(chr, left, right) \ +/** + * Set the images for Dr Caroll. + * + * The chr argument must be Dr Caroll. The left and right arguments can be: + * + * 0-6 = set directly to that image ID + * 7 = 25% chance of changing the image to a random one in range 0-5 + * 8 = 100% chance of changing the image to a random one in range 0-5 + */ +#define set_drcaroll_images(chr, left, right) \ mkshort(0x01d3), \ chr, \ left, \ diff --git a/src/include/constants.h b/src/include/constants.h index 635eb52e2..7a5bcc47d 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -337,6 +337,8 @@ #define DOORSTATEBIT_CLOSING 4 #define DOORSTATEBIT_OPENING 8 +#define DRCAROLLIMAGE_DEAD 4 + #define EEPROMFLAG_USED_TRANSFERPAK 0x23 #define EEPROMFLAG_CI_TOUR_DONE 0x24 #define EEPROMFLAG_CI_HOLO7_DONE 0x29 @@ -693,11 +695,11 @@ #define PROPTYPE_EYESPY 5 #define PROPTYPE_PLAYER 6 -#define RACE_HUMAN 0 -#define RACE_SKEDAR 1 -#define RACE_MAIAN 2 -#define RACE_ROBOT 3 -#define RACE_4 4 +#define RACE_HUMAN 0 +#define RACE_SKEDAR 1 +#define RACE_DRCAROLL 2 +#define RACE_ROBOT 3 +#define RACE_4 4 #define SPEED_WALK 0 #define SPEED_JOG 1 diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index 6ac6e1a86..24e787004 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -430,7 +430,7 @@ /*0x01d0*/ bool ai01d0(void); /*0x01d1*/ bool aiSetObjPartVisible(void); /*0x01d2*/ bool aiChrEmitSparks(void); -/*0x01d3*/ bool ai01d3(void); +/*0x01d3*/ bool aiSetDrCarollImages(void); /*0x01d4*/ bool ai01d4(void); /*0x01d5*/ bool aiShowCutsceneChrs(void); /*0x01d6*/ bool aiMiscellaneous(void); diff --git a/src/include/gvars/gvars.h b/src/include/gvars/gvars.h index bc144a5c2..c2b226ac4 100644 --- a/src/include/gvars/gvars.h +++ b/src/include/gvars/gvars.h @@ -20,7 +20,7 @@ struct g_vars { /*000000*/ u32 unk000000; /*000004*/ u32 unk000004; /*000008*/ s32 tickcount; - /*00000c*/ u32 unk00000c; + /*00000c*/ s32 unk00000c; /*000010*/ u32 unk000010; /*000014*/ u32 unk000014; /*000018*/ u32 unk000018; diff --git a/src/include/types.h b/src/include/types.h index 5717dfaf2..e5433e196 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -485,8 +485,8 @@ struct chrdata { /*0x35f*/ u8 maxdodgerating; /*0x360*/ u8 unarmeddodgerating; /*0x361*/ u8 lastfootsample; - /*0x362*/ u8 onlift_00 : 4; - /*0x362*/ u8 onlift_04 : 4; + /*0x362*/ u8 drcarollimage_left : 4; + /*0x362*/ u8 drcarollimage_right : 4; /*0x364*/ u32 unk364; }; diff --git a/src/setup/setup_000000.c b/src/setup/setup_000000.c index bb79ef4b5..64db3ad61 100644 --- a/src/setup/setup_000000.c +++ b/src/setup/setup_000000.c @@ -14600,7 +14600,7 @@ bool (*g_CommandPointers[])(void) = { /*0x01d0*/ ai01d0, /*0x01d1*/ aiSetObjPartVisible, /*0x01d2*/ aiChrEmitSparks, - /*0x01d3*/ ai01d3, + /*0x01d3*/ aiSetDrCarollImages, /*0x01d4*/ ai01d4, /*0x01d5*/ aiShowCutsceneChrs, /*0x01d6*/ aiMiscellaneous,