Various tuxie synchronization fixes

This commit is contained in:
MysterD 2020-09-01 20:13:46 -07:00
parent c54063fadd
commit af117f4647
3 changed files with 28 additions and 15 deletions

View file

@ -62,7 +62,7 @@ void tuxies_mother_act_1(void) {
dialogID = DIALOG_058; dialogID = DIALOG_058;
else else
dialogID = DIALOG_059; dialogID = DIALOG_059;
if (cur_obj_update_dialog_with_cutscene(marioState, 2, 1, CUTSCENE_DIALOG, dialogID, tuxies_mother_act_1_continue_dialog)) { if (nearest_mario_state_to_object(o) == &gMarioStates[0] && cur_obj_update_dialog_with_cutscene(marioState, 2, 1, CUTSCENE_DIALOG, dialogID, tuxies_mother_act_1_continue_dialog)) {
if (dialogID == DIALOG_058) if (dialogID == DIALOG_058)
o->oSubAction = 1; o->oSubAction = 1;
else else
@ -132,7 +132,7 @@ void tuxies_mother_act_0(void) {
o->oSubAction++; o->oSubAction++;
break; break;
case 1: case 1:
if (cur_obj_update_dialog_with_cutscene(marioState, 2, 1, CUTSCENE_DIALOG, DIALOG_057, tuxies_mother_act_0_continue_dialog)) if (nearest_mario_state_to_object(o) == &gMarioStates[0] && cur_obj_update_dialog_with_cutscene(marioState, 2, 1, CUTSCENE_DIALOG, DIALOG_057, tuxies_mother_act_0_continue_dialog))
o->oSubAction++; o->oSubAction++;
break; break;
case 2: case 2:

View file

@ -2447,16 +2447,14 @@ s32 bit_shift_left(s32 a0) {
} }
s32 cur_obj_mario_far_away(void) { s32 cur_obj_mario_far_away(void) {
f32 dx = o->oHomeX - gMarioObject->oPosX; for (int i = 0; i < MAX_PLAYERS; i++) {
f32 dy = o->oHomeY - gMarioObject->oPosY; f32 dx = o->oHomeX - gMarioObject->oPosX;
f32 dz = o->oHomeZ - gMarioObject->oPosZ; f32 dy = o->oHomeY - gMarioObject->oPosY;
f32 marioDistToHome = sqrtf(dx * dx + dy * dy + dz * dz); f32 dz = o->oHomeZ - gMarioObject->oPosZ;
f32 marioDistToHome = sqrtf(dx * dx + dy * dy + dz * dz);
if (o->oDistanceToMario > 2000.0f && marioDistToHome > 2000.0f) { if (marioDistToHome <= 2000.0f) { return FALSE; }
return TRUE;
} else {
return FALSE;
} }
return (o->oDistanceToMario > 2000.0f);
} }
s32 is_mario_moving_fast_or_in_air(s32 speedThreshold) { s32 is_mario_moving_fast_or_in_air(s32 speedThreshold) {

View file

@ -103,6 +103,20 @@ static void packet_write_object_header(struct Packet* p, struct Object* o) {
packet_write(p, &behaviorId, sizeof(enum BehaviorId)); packet_write(p, &behaviorId, sizeof(enum BehaviorId));
} }
static bool allowable_behavior_change(struct SyncObject* so, struct BehaviorScript* behavior) {
struct Object* o = so->o;
bool allow = false;
// bhvPenguinBaby can be set to bhvSmallPenguin
allow = allow || ((o->behavior == bhvPenguinBaby || o->behavior == bhvSmallPenguin) && (behavior == bhvPenguinBaby || behavior == bhvSmallPenguin));
if (!allow) { return false; }
so->behavior = behavior;
so->o->behavior = behavior;
return true;
}
static struct SyncObject* packet_read_object_header(struct Packet* p) { static struct SyncObject* packet_read_object_header(struct Packet* p) {
// get sync ID, sanity check // get sync ID, sanity check
u32 syncId = 0; u32 syncId = 0;
@ -137,8 +151,8 @@ static struct SyncObject* packet_read_object_header(struct Packet* p) {
// make sure the behaviors match // make sure the behaviors match
enum BehaviorId behaviorId; enum BehaviorId behaviorId;
packet_read(p, &behaviorId, sizeof(enum BehaviorId)); packet_read(p, &behaviorId, sizeof(enum BehaviorId));
so->behavior = get_behavior_from_id(behaviorId); struct BehaviorScript* behavior = get_behavior_from_id(behaviorId);
if (o->behavior != so->behavior) { if (o->behavior != behavior && !allowable_behavior_change(so, behavior)) {
printf("network_receive_object() behavior mismatch!\n"); printf("network_receive_object() behavior mismatch!\n");
network_forget_sync_object(so); network_forget_sync_object(so);
return NULL; return NULL;
@ -268,7 +282,7 @@ void network_send_object(struct Object* o) {
if (!network_sync_object_initialized(o)) { return; } if (!network_sync_object_initialized(o)) { return; }
struct SyncObject* so = &syncObjects[o->oSyncID]; struct SyncObject* so = &syncObjects[o->oSyncID];
if (so == NULL) { return; } if (so == NULL) { return; }
if (o->behavior != so->behavior) { if (o->behavior != so->behavior && !allowable_behavior_change(so, so->behavior)) {
printf("network_send_object() BEHAVIOR MISMATCH!\n"); printf("network_send_object() BEHAVIOR MISMATCH!\n");
network_forget_sync_object(so); network_forget_sync_object(so);
return; return;
@ -288,7 +302,8 @@ void network_send_object_reliability(struct Object* o, bool reliable) {
if (!network_sync_object_initialized(o)) { return; } if (!network_sync_object_initialized(o)) { return; }
struct SyncObject* so = &syncObjects[o->oSyncID]; struct SyncObject* so = &syncObjects[o->oSyncID];
if (so == NULL) { return; } if (so == NULL) { return; }
if (o->behavior != so->behavior) {
if (o->behavior != so->behavior && !allowable_behavior_change(so, so->behavior)) {
printf("network_send_object() BEHAVIOR MISMATCH!\n"); printf("network_send_object() BEHAVIOR MISMATCH!\n");
network_forget_sync_object(so); network_forget_sync_object(so);
return; return;