|
| 1 | +#include "swim.h" |
| 2 | + |
| 3 | +RespawnByScene respawnsByScene[] = { |
| 4 | + { 0x1D9, { { -1455, -20, 1384 }, 28761 }}, // Hyrule Field to Zora River (in water) |
| 5 | + { 0x311, { { 5852, -20, 3725 }, -20025 }}, // Zora River to Hyrule Field (in water) |
| 6 | + { 0x4DA, { { 1978, -36, -855 }, -16384 }}, // Zora River to Lost Woods |
| 7 | + { 0x1DD, { { 4082, 860, -1018 }, -32768 }}, // Lost Woods to Zora River |
| 8 | + { 0x219, { { -3276, -1033, 2908 }, 11228 }}, // Gerudo Valley to Lake Hylia |
| 9 | + { 0x3D4, { { -2361, 0, 610 }, 32768 }}, // Ice Cavern to Zora Fountain |
| 10 | + { 0x21D, { { -955, -1306, 6768 }, -32768 }}, // Water Temple to Lake Hylia |
| 11 | + { 0x328, { { -109, 11, -9 }, -29131 }}, // Lake Hylia to Zora Domain |
| 12 | + { 0x560, { { -912, -1326, 3391 }, 0 }}, // Zora Domain to Lake Hylia |
| 13 | + { 0x10E, { { -1500, 150, 1600 }, 32768}}, // Sapphire cutscene to Zora Fountain |
| 14 | +}; |
| 15 | + |
| 16 | +void set_new_respawn() { |
| 17 | + |
| 18 | + uint8_t newRespawnTrue = 0; |
| 19 | + int32_t currentEntranceIndex = z64_game.entrance_index; |
| 20 | + for (uint8_t i = 0; i < 10; i++) { |
| 21 | + // Ensure we always respawn at a safe location. |
| 22 | + if (currentEntranceIndex == respawnsByScene[i].scene_index) { |
| 23 | + z64_Play_SetupRespawnPoint(&z64_game, 0x01, 0xDFF); |
| 24 | + z64_file.respawn[RESPAWN_MODE_RETURN].pos = respawnsByScene[i].respawnInfo.pos; |
| 25 | + z64_file.respawn[RESPAWN_MODE_RETURN].yaw = respawnsByScene[i].respawnInfo.yaw; |
| 26 | + z64_file.respawn_flag = 2; |
| 27 | + z64_game.scene_load_flag = 0x14; |
| 28 | + newRespawnTrue = 1; |
| 29 | + break; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + // Special case for Water Temple river area, so that player respawns at the start of the room. |
| 34 | + if (z64_game.scene_index == 5 && z64_game.room_index == 21) { |
| 35 | + z64_Play_SetupRespawnPoint(&z64_game, 0x01, 0xDFF); |
| 36 | + z64_xyzf_t riverPos = {-3063, 380, -4066}; |
| 37 | + z64_file.respawn[RESPAWN_MODE_RETURN].pos = riverPos; |
| 38 | + z64_file.respawn[RESPAWN_MODE_RETURN].yaw = 9010; |
| 39 | + z64_file.respawn_flag = 2; |
| 40 | + z64_game.scene_load_flag = 0x14; |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + if (newRespawnTrue == 0) { |
| 45 | + z64_game.entrance_index = z64_file.entrance_index; |
| 46 | + z64_game.fadeout_transition = 0x02; |
| 47 | + z64_file.respawn_flag = -2; |
| 48 | + z64_game.scene_load_flag = 0x14; |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +void manage_swim() { |
| 53 | + |
| 54 | + // We found the first scale. |
| 55 | + if (extended_savectx.extended_scale[0] > 0) { |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + // Iron boots are equipped. |
| 60 | + if (z64_file.equip_boots == 2) { |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + // Always allow to swim out of water temple to avoid softlocks. |
| 65 | + if (z64_game.scene_index == 5 && z64_link.common.pos_world.z > 700.0) { |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + if (z64_link.state_flags_1 & 0x08000000) { // Swimming state flag. |
| 70 | + set_new_respawn(); |
| 71 | + } |
| 72 | +} |
0 commit comments