mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Synchronized Pokey
This commit is contained in:
parent
e0736ccc59
commit
608670e0a9
3 changed files with 39 additions and 9 deletions
|
|
@ -142,6 +142,21 @@ void bhv_pokey_body_part_update(void) {
|
||||||
o->oGraphYOffset = o->header.gfx.scale[1] * 22.0f;
|
o->oGraphYOffset = o->header.gfx.scale[1] * 22.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u32 pokeyCacheAliveBodyPartFlags = 0;
|
||||||
|
static s32 pokeyCacheNumAliveBodyParts = 0;
|
||||||
|
|
||||||
|
static void pokey_on_received_pre(u8 localIndex) {
|
||||||
|
pokeyCacheAliveBodyPartFlags = o->oPokeyAliveBodyPartFlags;
|
||||||
|
pokeyCacheNumAliveBodyParts = o->oPokeyNumAliveBodyParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pokey_on_received_post(u8 localIndex) {
|
||||||
|
if (o->oPokeyNumAliveBodyParts > pokeyCacheNumAliveBodyParts) {
|
||||||
|
o->oPokeyAliveBodyPartFlags = pokeyCacheAliveBodyPartFlags;
|
||||||
|
o->oPokeyNumAliveBodyParts = pokeyCacheNumAliveBodyParts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When mario gets within range, spawn the 5 body parts and enter the wander
|
* When mario gets within range, spawn the 5 body parts and enter the wander
|
||||||
* action.
|
* action.
|
||||||
|
|
@ -175,6 +190,17 @@ static void pokey_act_uninitialized(void) {
|
||||||
#ifndef NODRAWINGDISTANCE
|
#ifndef NODRAWINGDISTANCE
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (!network_sync_object_initialized(o)) {
|
||||||
|
struct SyncObject* so = network_init_object(o, 4000.0f);
|
||||||
|
network_init_object_field(o, &o->oPokeyAliveBodyPartFlags);
|
||||||
|
network_init_object_field(o, &o->oPokeyNumAliveBodyParts);
|
||||||
|
network_init_object_field(o, &o->oPokeyHeadWasKilled);
|
||||||
|
network_init_object_field(o, &o->oPokeyTargetYaw);
|
||||||
|
network_init_object_field(o, &o->oPokeyChangeTargetTimer);
|
||||||
|
network_init_object_field(o, &o->oPokeyTurningAwayFromWall);
|
||||||
|
so->on_received_pre = pokey_on_received_pre;
|
||||||
|
so->on_received_post = pokey_on_received_post;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -184,6 +210,10 @@ static void pokey_act_uninitialized(void) {
|
||||||
* if mario gets too close, then shy away from him.
|
* if mario gets too close, then shy away from him.
|
||||||
*/
|
*/
|
||||||
static void pokey_act_wander(void) {
|
static void pokey_act_wander(void) {
|
||||||
|
struct Object* player = nearest_player_to_object(o);
|
||||||
|
int distanceToPlayer = dist_between_objects(o, player);
|
||||||
|
int angleToPlayer = obj_angle_to_object(o, player);
|
||||||
|
|
||||||
s32 targetAngleOffset;
|
s32 targetAngleOffset;
|
||||||
struct Object *bodyPart;
|
struct Object *bodyPart;
|
||||||
|
|
||||||
|
|
@ -233,15 +263,15 @@ static void pokey_act_wander(void) {
|
||||||
obj_resolve_collisions_and_turn(o->oPokeyTargetYaw, 0x200);
|
obj_resolve_collisions_and_turn(o->oPokeyTargetYaw, 0x200);
|
||||||
} else {
|
} else {
|
||||||
// If far from home, turn back toward home
|
// If far from home, turn back toward home
|
||||||
if (o->oDistanceToMario >= 25000.0f) {
|
if (distanceToPlayer >= 25000.0f) {
|
||||||
o->oPokeyTargetYaw = o->oAngleToMario;
|
o->oPokeyTargetYaw = angleToPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(o->oPokeyTurningAwayFromWall =
|
if (!(o->oPokeyTurningAwayFromWall =
|
||||||
obj_bounce_off_walls_edges_objects(&o->oPokeyTargetYaw))) {
|
obj_bounce_off_walls_edges_objects(&o->oPokeyTargetYaw))) {
|
||||||
if (o->oPokeyChangeTargetTimer != 0) {
|
if (o->oPokeyChangeTargetTimer != 0) {
|
||||||
o->oPokeyChangeTargetTimer -= 1;
|
o->oPokeyChangeTargetTimer -= 1;
|
||||||
} else if (o->oDistanceToMario > 2000.0f) {
|
} else if (distanceToPlayer > 2000.0f) {
|
||||||
o->oPokeyTargetYaw = obj_random_fixed_turn(0x2000);
|
o->oPokeyTargetYaw = obj_random_fixed_turn(0x2000);
|
||||||
o->oPokeyChangeTargetTimer = random_linear_offset(30, 50);
|
o->oPokeyChangeTargetTimer = random_linear_offset(30, 50);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -251,7 +281,7 @@ static void pokey_act_wander(void) {
|
||||||
|
|
||||||
// targetAngleOffset is 0 when distance to mario is >= 1838.4
|
// targetAngleOffset is 0 when distance to mario is >= 1838.4
|
||||||
// and 0x4000 when distance to mario is <= 200
|
// and 0x4000 when distance to mario is <= 200
|
||||||
targetAngleOffset = (s32)(0x4000 - (o->oDistanceToMario - 200.0f) * 10.0f);
|
targetAngleOffset = (s32)(0x4000 - (distanceToPlayer - 200.0f) * 10.0f);
|
||||||
if (targetAngleOffset < 0) {
|
if (targetAngleOffset < 0) {
|
||||||
targetAngleOffset = 0;
|
targetAngleOffset = 0;
|
||||||
} else if (targetAngleOffset > 0x4000) {
|
} else if (targetAngleOffset > 0x4000) {
|
||||||
|
|
@ -260,7 +290,7 @@ static void pokey_act_wander(void) {
|
||||||
|
|
||||||
// If we need to rotate CCW to get to mario, then negate
|
// If we need to rotate CCW to get to mario, then negate
|
||||||
// the target angle offset
|
// the target angle offset
|
||||||
if ((s16)(o->oAngleToMario - o->oMoveAngleYaw) > 0) {
|
if ((s16)(angleToPlayer - o->oMoveAngleYaw) > 0) {
|
||||||
targetAngleOffset = -targetAngleOffset;
|
targetAngleOffset = -targetAngleOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,7 +298,7 @@ static void pokey_act_wander(void) {
|
||||||
// toward him directly. When mario is close,
|
// toward him directly. When mario is close,
|
||||||
// targetAngleOffset is 0x4000, so he turns 90 degrees
|
// targetAngleOffset is 0x4000, so he turns 90 degrees
|
||||||
// away from mario
|
// away from mario
|
||||||
o->oPokeyTargetYaw = o->oAngleToMario + targetAngleOffset;
|
o->oPokeyTargetYaw = angleToPlayer + targetAngleOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
static u8 warpToLevel = LEVEL_LLL;
|
static u8 warpToLevel = LEVEL_SSL;
|
||||||
|
|
||||||
#define SCANCODE_0 0x0B
|
#define SCANCODE_0 0x0B
|
||||||
#define SCANCODE_3 0x04
|
#define SCANCODE_3 0x04
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ void network_receive_object(struct Packet* p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger on-received callback
|
// trigger on-received callback
|
||||||
if (so->on_received_pre != NULL) {
|
if (so->on_received_pre != NULL && so->o != NULL) {
|
||||||
extern struct Object* gCurrentObject;
|
extern struct Object* gCurrentObject;
|
||||||
struct Object* tmp = gCurrentObject;
|
struct Object* tmp = gCurrentObject;
|
||||||
gCurrentObject = so->o;
|
gCurrentObject = so->o;
|
||||||
|
|
@ -394,7 +394,7 @@ void network_receive_object(struct Packet* p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger on-received callback
|
// trigger on-received callback
|
||||||
if (so->on_received_post != NULL) {
|
if (so->on_received_post != NULL && so->o != NULL) {
|
||||||
extern struct Object* gCurrentObject;
|
extern struct Object* gCurrentObject;
|
||||||
struct Object* tmp = gCurrentObject;
|
struct Object* tmp = gCurrentObject;
|
||||||
gCurrentObject = so->o;
|
gCurrentObject = so->o;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue