Synchronized moat draining and cap switch unlocks

This commit is contained in:
MysterD 2021-06-14 19:59:11 -07:00
parent 02fbdca868
commit 6aded174e9
7 changed files with 58 additions and 1 deletions

View file

@ -2371,7 +2371,9 @@ const BehaviorScript bhvInvisibleObjectsUnderBridge[] = {
BEGIN(OBJ_LIST_DEFAULT),
ID(id_bhvInvisibleObjectsUnderBridge),
CALL_NATIVE(bhv_invisible_objects_under_bridge_init),
BREAK(),
BEGIN_LOOP(),
CALL_NATIVE(bhv_invisible_objects_under_bridge_loop),
END_LOOP(),
};
const BehaviorScript bhvWaterLevelPillar[] = {

View file

@ -181,6 +181,7 @@ void bhv_checkerboard_platform_loop(void);
void bhv_bowser_key_unlock_door_loop(void);
void bhv_bowser_key_course_exit_loop(void);
void bhv_invisible_objects_under_bridge_init(void);
void bhv_invisible_objects_under_bridge_loop(void);
void bhv_water_level_pillar_init(void);
void bhv_water_level_pillar_loop(void);
void bhv_ddd_warp_loop(void);

View file

@ -4,5 +4,31 @@ void bhv_invisible_objects_under_bridge_init(void) {
if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) {
gEnvironmentRegions[6] = -800;
gEnvironmentRegions[12] = -800;
o->oAction = 2;
} else {
o->oAction = 0;
}
}
void bhv_invisible_objects_under_bridge_loop(void) {
switch (o->oAction) {
case 0:
// wait for moat drained flag to get set
if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) { o->oAction = 1; }
break;
case 1:
// approach -800
gEnvironmentRegions[6] = (s16)approach_f32_symmetric(gEnvironmentRegions[6], -800, 5.0f);
gEnvironmentRegions[12] = (s16)approach_f32_symmetric(gEnvironmentRegions[12], -800, 5.0f);
if (gEnvironmentRegions[6] <= -795 && gEnvironmentRegions[12] <= -795) {
gEnvironmentRegions[6] = -800;
gEnvironmentRegions[12] = -800;
o->oAction = 2;
}
break;
case 2:
// clean up
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
break;
}
}

View file

@ -605,6 +605,7 @@ s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse)
void save_file_set_flags(u32 flags) {
gSaveBuffer.files[gCurrSaveFileNum - 1][0].flags |= (flags | SAVE_FLAG_FILE_EXISTS);
gSaveFileModified = TRUE;
network_send_save_set_flag(flags);
}
void save_file_clear_flags(u32 flags) {

View file

@ -39,6 +39,7 @@ void packet_process(struct Packet* p) {
case PACKET_KEEP_ALIVE: network_receive_keep_alive(p); break;
case PACKET_LEAVING: network_receive_leaving(p); break;
case PACKET_SAVE_FILE: network_receive_save_file(p); break;
case PACKET_SAVE_SET_FLAG: network_receive_save_set_flag(p); break;
case PACKET_NETWORK_PLAYERS: network_receive_network_players(p); break;
case PACKET_DEATH: network_receive_death(p); break;

View file

@ -31,6 +31,7 @@ enum PacketType {
PACKET_KEEP_ALIVE,
PACKET_LEAVING,
PACKET_SAVE_FILE,
PACKET_SAVE_SET_FLAG,
PACKET_NETWORK_PLAYERS,
PACKET_DEATH,
@ -187,6 +188,10 @@ void network_receive_leaving(struct Packet* p);
void network_send_save_file(s32 fileIndex);
void network_receive_save_file(struct Packet* p);
// packet_save_set_flag.c
void network_send_save_set_flag(u32 flags);
void network_receive_save_set_flag(struct Packet* p);
// packet_network_players.c
void network_send_network_players(void);
void network_receive_network_players(struct Packet* p);

View file

@ -0,0 +1,21 @@
#include <stdio.h>
#include "../network.h"
#include "game/save_file.h"
static bool sIgnoreSendSaveSetFlag = false;
void network_send_save_set_flag(u32 flags) {
// prevent replying to the packet we just received
if (sIgnoreSendSaveSetFlag) { return; }
struct Packet p;
packet_init(&p, PACKET_SAVE_SET_FLAG, true, false);
packet_write(&p, &flags, sizeof(u32));
network_send(&p);
}
void network_receive_save_set_flag(struct Packet* p) {
u32 flags;
packet_read(p, &flags, sizeof(u32));
save_file_set_flags(flags);
}