Resync bomp using Network Area Timer

This commit is contained in:
MysterD 2021-08-03 18:52:48 -07:00
parent a520b25c26
commit a84e7a73fe
10 changed files with 2849 additions and 104 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.28.29333:TargetPlatformVersion=10.0.18362.0:
Debug|Win32|X:\Projects\sm64ex-coop\build-windows-visual-studio\|

View file

@ -232,6 +232,7 @@
/* Bomp (Small) */ /* Bomp (Small) */
#define /*0x100*/ oSmallBompInitX OBJECT_FIELD_F32(0x1E) #define /*0x100*/ oSmallBompInitX OBJECT_FIELD_F32(0x1E)
#define /*?????*/ oBompTimer OBJECT_FIELD_U32(0x1F)
/* Boo */ /* Boo */
#define /*0x088*/ oBooDeathStatus OBJECT_FIELD_S32(0x00) #define /*0x088*/ oBooDeathStatus OBJECT_FIELD_S32(0x00)

View file

@ -109,6 +109,18 @@ s32 random_sign(void) {
} }
} }
u16 position_based_random_u16(void) {
u16 value = (u16)(gCurrentObject->oPosX * 2659);
value ^= (u16)(gCurrentObject->oPosY * 1901);
value ^= (u16)(gCurrentObject->oPosZ * 3331);
return value;
}
f32 position_based_random_float_position(void) {
f32 rnd = position_based_random_u16();
return rnd / (double)0x10000;
}
// Update an object's graphical position and rotation to match its real position and rotation. // Update an object's graphical position and rotation to match its real position and rotation.
void obj_update_gfx_pos_and_angle(struct Object *obj) { void obj_update_gfx_pos_and_angle(struct Object *obj) {
obj->header.gfx.pos[0] = obj->oPosX; obj->header.gfx.pos[0] = obj->oPosX;

View file

@ -22,6 +22,8 @@
u16 random_u16(void); u16 random_u16(void);
float random_float(void); float random_float(void);
s32 random_sign(void); s32 random_sign(void);
u16 position_based_random_u16(void);
f32 position_based_random_float_position(void);
void stub_behavior_script_2(void); void stub_behavior_script_2(void);

View file

@ -1,134 +1,144 @@
// bomp.c.inc // bomp.c.inc
void bhv_small_bomp_init(void) { void bhv_small_bomp_init(void) {
o->oBompTimer = 0;
o->oFaceAngleYaw -= 0x4000; o->oFaceAngleYaw -= 0x4000;
o->oSmallBompInitX = o->oPosX; o->oSmallBompInitX = o->oPosX;
o->oTimer = random_float() * 100.0f; o->oTimer = position_based_random_float_position() * 100.0f;
if (!network_sync_object_initialized(o)) {
network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
network_init_object_field(o, &o->oAction);
network_init_object_field(o, &o->oForwardVel);
network_init_object_field(o, &o->oMoveAngleYaw);
network_init_object_field(o, &o->oPosX);
network_init_object_field(o, &o->oTimer);
}
} }
void bhv_small_bomp_loop(void) { void bhv_small_bomp_loop(void) {
switch (o->oAction) { u32 loopLength = 168;
case BOMP_ACT_WAIT: if ((gNetworkAreaTimer - o->oBompTimer) >= loopLength) {
if (o->oTimer >= 101) { u32 catchup = (gNetworkAreaTimer - o->oBompTimer) / loopLength;
o->oAction = BOMP_ACT_POKE_OUT; catchup *= loopLength;
o->oForwardVel = 30.0f; o->oBompTimer += catchup;
} }
break;
case BOMP_ACT_POKE_OUT: while (o->oBompTimer < gNetworkAreaTimer) {
if (o->oPosX > 3450.0f) { switch (o->oAction) {
o->oPosX = 3450.0f; case BOMP_ACT_WAIT:
o->oForwardVel = 0; if (o->oTimer >= 101) {
} o->oAction = BOMP_ACT_POKE_OUT;
o->oForwardVel = 30.0f;
}
break;
if (o->oTimer == 15.0) { case BOMP_ACT_POKE_OUT:
o->oAction = BOMP_ACT_EXTEND; if (o->oPosX > 3450.0f) {
o->oForwardVel = 40.0f; o->oPosX = 3450.0f;
cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2); o->oForwardVel = 0;
} }
break;
case BOMP_ACT_EXTEND: if (o->oTimer == 15.0) {
if (o->oPosX > 3830.0f) { o->oAction = BOMP_ACT_EXTEND;
o->oPosX = 3830.0f; o->oForwardVel = 40.0f;
o->oForwardVel = 0; cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
} }
break;
if (o->oTimer >= 60) { case BOMP_ACT_EXTEND:
if (o->oTimer == 60) { cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2); } if (o->oPosX > 3830.0f) {
if (!network_owns_object(o)) { break; } o->oPosX = 3830.0f;
o->oAction = BOMP_ACT_RETRACT; o->oForwardVel = 0;
o->oForwardVel = 10.0f; }
o->oMoveAngleYaw -= 0x8000;
network_send_object(o);
}
break;
case BOMP_ACT_RETRACT: if (o->oTimer == 60) {
if (o->oPosX < 3330.0f) { o->oAction = BOMP_ACT_RETRACT;
o->oPosX = 3330.0f; o->oForwardVel = 10.0f;
o->oForwardVel = 0; o->oMoveAngleYaw -= 0x8000;
} cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
}
break;
if (o->oTimer == 90) { case BOMP_ACT_RETRACT:
o->oAction = BOMP_ACT_POKE_OUT; if (o->oPosX < 3330.0f) {
o->oForwardVel = 25.0f; o->oPosX = 3330.0f;
o->oMoveAngleYaw -= 0x8000; o->oForwardVel = 0;
} }
break;
if (o->oTimer == 90) {
o->oAction = BOMP_ACT_POKE_OUT;
o->oForwardVel = 25.0f;
o->oMoveAngleYaw -= 0x8000;
}
break;
}
o->oBompTimer++;
if (o->oBompTimer < gNetworkAreaTimer) {
cur_obj_fake_update();
}
} }
} }
void bhv_large_bomp_init(void) { void bhv_large_bomp_init(void) {
o->oBompTimer = 0;
o->oMoveAngleYaw += 0x4000; o->oMoveAngleYaw += 0x4000;
o->oTimer = random_float() * 100.0f; o->oTimer = position_based_random_float_position() * 100.0f;
if (!network_sync_object_initialized(o)) {
network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
network_init_object_field(o, &o->oAction);
network_init_object_field(o, &o->oForwardVel);
network_init_object_field(o, &o->oMoveAngleYaw);
network_init_object_field(o, &o->oPosX);
network_init_object_field(o, &o->oTimer);
}
} }
void bhv_large_bomp_loop(void) { void bhv_large_bomp_loop(void) {
switch (o->oAction) { u32 loopLength = 168;
case BOMP_ACT_WAIT: if ((gNetworkAreaTimer - o->oBompTimer) >= loopLength) {
if (o->oTimer >= 101) { u32 catchup = (gNetworkAreaTimer - o->oBompTimer) / loopLength;
o->oAction = BOMP_ACT_POKE_OUT; catchup *= loopLength;
o->oForwardVel = 30.0f; o->oBompTimer += catchup;
} }
break;
case BOMP_ACT_POKE_OUT: while (o->oBompTimer < gNetworkAreaTimer) {
if (o->oPosX > 3450.0f) { switch (o->oAction) {
o->oPosX = 3450.0f; case BOMP_ACT_WAIT:
o->oForwardVel = 0; if (o->oTimer >= 101) {
} o->oAction = BOMP_ACT_POKE_OUT;
o->oForwardVel = 30.0f;
}
break;
if (o->oTimer == 15.0) { case BOMP_ACT_POKE_OUT:
o->oAction = BOMP_ACT_EXTEND; if (o->oPosX > 3450.0f) {
o->oForwardVel = 10.0f; o->oPosX = 3450.0f;
cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2); o->oForwardVel = 0;
} }
break;
case BOMP_ACT_EXTEND: if (o->oTimer == 15.0) {
if (o->oPosX > 3830.0f) { o->oAction = BOMP_ACT_EXTEND;
o->oPosX = 3830.0f; o->oForwardVel = 10.0f;
o->oForwardVel = 0; cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
} }
break;
if (o->oTimer >= 60) { case BOMP_ACT_EXTEND:
if (o->oTimer == 60) { cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2); } if (o->oPosX > 3830.0f) {
if (!network_owns_object(o)) { break; } o->oPosX = 3830.0f;
o->oAction = BOMP_ACT_RETRACT; o->oForwardVel = 0;
o->oForwardVel = 10.0f; }
o->oMoveAngleYaw -= 0x8000;
network_send_object(o);
}
break;
case BOMP_ACT_RETRACT: if (o->oTimer == 60) {
if (o->oPosX < 3330.0f) { o->oAction = BOMP_ACT_RETRACT;
o->oPosX = 3330.0f; o->oForwardVel = 10.0f;
o->oForwardVel = 0; o->oMoveAngleYaw -= 0x8000;
} cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
}
break;
if (o->oTimer == 90) { case BOMP_ACT_RETRACT:
o->oAction = BOMP_ACT_POKE_OUT; if (o->oPosX < 3330.0f) {
o->oForwardVel = 25.0f; o->oPosX = 3330.0f;
o->oMoveAngleYaw -= 0x8000; o->oForwardVel = 0;
} }
break;
if (o->oTimer == 90) {
o->oAction = BOMP_ACT_POKE_OUT;
o->oForwardVel = 25.0f;
o->oMoveAngleYaw -= 0x8000;
}
break;
}
o->oBompTimer++;
if (o->oBompTimer < gNetworkAreaTimer) {
cur_obj_fake_update();
}
} }
} }