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) */
#define /*0x100*/ oSmallBompInitX OBJECT_FIELD_F32(0x1E)
#define /*?????*/ oBompTimer OBJECT_FIELD_U32(0x1F)
/* Boo */
#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.
void obj_update_gfx_pos_and_angle(struct Object *obj) {
obj->header.gfx.pos[0] = obj->oPosX;

View File

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

View File

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