From 839575efe1010ce675365e81137aac83d5c69c62 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 14 Jan 2022 16:33:22 -0800 Subject: [PATCH] Fixed home radius on many enemies, fixed draw distance bug --- Makefile.split | 2 +- developer/network.sh | 8 +++--- src/engine/behavior_script.c | 6 +++- src/game/behaviors/bubba.inc.c | 7 +++-- src/game/behaviors/enemy_lakitu.inc.c | 19 +++++++++---- src/game/behaviors/fly_guy.inc.c | 8 +++++- src/game/behaviors/goomba.inc.c | 4 ++- src/game/behaviors/koopa.inc.c | 28 +++++++++---------- src/game/behaviors/pokey.inc.c | 2 +- src/game/behaviors/skeeter.inc.c | 19 ++++++++----- src/game/behaviors/wiggler.inc.c | 12 ++++++-- src/game/obj_behaviors_2.c | 11 +++++++- src/pc/controller/controller_keyboard_debug.c | 4 +-- 13 files changed, 86 insertions(+), 44 deletions(-) diff --git a/Makefile.split b/Makefile.split index be322eb1..a3cfb975 100644 --- a/Makefile.split +++ b/Makefile.split @@ -80,7 +80,7 @@ CUSTOM_DIRS += waluigi_cap ZCUSTOM_DIRS += waluigi # Actor Files -CUSTOM_FILES := $(foreach dir,$(addprefix $(ACTOR_DIR)/,$(CUSTOM_DIRS)),$(patsubst %.png,%.inc.c,$(wildcard $(dir)/*.png))) +CUSTOM_FILES := $(foreach dir,$(addprefix $(ACTOR_DIR)/,$(CUSTOM_DIRS)),$(patsubst %.png,%.inc.c,$(wildcard $(dir)/*.png))) AMP_CHUCKYA_FILES := $(foreach dir,$(addprefix $(ACTOR_DIR)/,$(AMP_DIRS)),$(patsubst %.png,%.inc.c,$(wildcard $(dir)/*.png))) BOBOMBS_BUBBLE_FILES := $(foreach dir,$(addprefix $(ACTOR_DIR)/,$(KING_BOBOMB_DIRS)),$(patsubst %.png,%.inc.c,$(wildcard $(dir)/*.png))) BOO_BOOKEND_FILES := $(foreach dir,$(addprefix $(ACTOR_DIR)/,$(BOO_DIRS)),$(patsubst %.png,%.inc.c,$(wildcard $(dir)/*.png))) diff --git a/developer/network.sh b/developer/network.sh index b274aefe..0d095ced 100644 --- a/developer/network.sh +++ b/developer/network.sh @@ -18,10 +18,10 @@ fi #exit # no debug, direct -$FILE --server 27015 --configfile sm64config_server.txt & -sleep 7 -$FILE --client 127.0.0.1 27015 --configfile sm64config_client.txt & -exit +#$FILE --server 27015 --configfile sm64config_server.txt & +#sleep 7 +#$FILE --client 127.0.0.1 27015 --configfile sm64config_client.txt & +#exit # debug on server #$FILE --client 127.0.0.1 27015 --configfile sm64config_client.txt & diff --git a/src/engine/behavior_script.c b/src/engine/behavior_script.c index 155b0621..418cf180 100644 --- a/src/engine/behavior_script.c +++ b/src/engine/behavior_script.c @@ -1078,7 +1078,11 @@ cur_obj_update_begin:; if (distanceFromMario > gCurrentObject->oDrawingDistance * draw_distance_scalar()) { // Out of render distance, hide the object. gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE; - gCurrentObject->activeFlags |= ACTIVE_FLAG_FAR_AWAY; + + // the following flag would deactivate behavior code + //gCurrentObject->activeFlags |= ACTIVE_FLAG_FAR_AWAY; + gCurrentObject->activeFlags &= ~ACTIVE_FLAG_FAR_AWAY; + } else if (gCurrentObject->oHeldState == HELD_FREE) { // In render distance (and not being held), show the object. gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE; diff --git a/src/game/behaviors/bubba.inc.c b/src/game/behaviors/bubba.inc.c index fe57ee4b..1df01555 100644 --- a/src/game/behaviors/bubba.inc.c +++ b/src/game/behaviors/bubba.inc.c @@ -20,7 +20,9 @@ void bubba_act_0(void) { f32 sp24; sp24 = cur_obj_lateral_dist_to_home(); - treat_far_home_as_mario(2000.0f); + + treat_far_home_as_mario(2000.0f, &distanceToPlayer, &angleToPlayer); + o->oAnimState = 0; o->oBubbaUnk1AC = obj_get_pitch_to_home(sp24); @@ -59,7 +61,8 @@ void bubba_act_1(void) { s16 val06; s16 val04; - treat_far_home_as_mario(2500.0f); + treat_far_home_as_mario(2500.0f, &distanceToPlayer, &angleToPlayer); + if (distanceToPlayer > 2500.0f) { o->oAction = 0; } else if (o->oBubbaUnk100 != 0) { diff --git a/src/game/behaviors/enemy_lakitu.inc.c b/src/game/behaviors/enemy_lakitu.inc.c index 96525276..120d2efe 100644 --- a/src/game/behaviors/enemy_lakitu.inc.c +++ b/src/game/behaviors/enemy_lakitu.inc.c @@ -44,10 +44,13 @@ static void enemy_lakitu_update_vel_y(f32 offsetY) { } struct Object* player = nearest_player_to_object(o); - if (o->oPosY < player->oPosY + offsetY + margin) { - obj_y_vel_approach(4.0f, 0.4f); - } else { - obj_y_vel_approach(-4.0f, 0.4f); + if (player != NULL) { + if (o->oPosY < player->oPosY + offsetY + margin) { + obj_y_vel_approach(4.0f, 0.4f); + } + else { + obj_y_vel_approach(-4.0f, 0.4f); + } } } @@ -102,6 +105,8 @@ static void enemy_lakitu_sub_act_no_spiny(void) { int distanceToPlayer = dist_between_objects(o, player); int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(2000.0f, &distanceToPlayer, &angleToPlayer); + cur_obj_init_animation_with_sound(1); if (o->oEnemyLakituSpinyCooldown != 0) { @@ -139,6 +144,8 @@ static void enemy_lakitu_sub_act_hold_spiny(void) { int distanceToPlayer = dist_between_objects(o, player); int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(2000.0f, &distanceToPlayer, &angleToPlayer); + cur_obj_init_anim_extend(3); if (o->oEnemyLakituSpinyCooldown != 0) { @@ -172,6 +179,7 @@ static void enemy_lakitu_sub_act_throw_spiny(void) { * Main update function. */ static void enemy_lakitu_act_main(void) { + cur_obj_unhide(); cur_obj_play_sound_1(SOUND_AIR_LAKITU_FLY); cur_obj_update_floor_and_walls(); @@ -214,9 +222,10 @@ void bhv_enemy_lakitu_update(void) { network_init_object_field(o, &o->oEnemyLakituBlinkTimer); network_init_object_field(o, &o->oEnemyLakituSpinyCooldown); network_init_object_field(o, &o->oEnemyLakituFaceForwardCountdown); + network_init_object_field(o, &o->oEnemyLakituNumSpinies); } - treat_far_home_as_mario(2000.0f); + treat_far_home_as_mario(2000.0f, NULL, NULL); switch (o->oAction) { case ENEMY_LAKITU_ACT_UNINITIALIZED: diff --git a/src/game/behaviors/fly_guy.inc.c b/src/game/behaviors/fly_guy.inc.c index 3f7df1a2..f6f645f3 100644 --- a/src/game/behaviors/fly_guy.inc.c +++ b/src/game/behaviors/fly_guy.inc.c @@ -32,6 +32,8 @@ static void fly_guy_act_idle(void) { int distanceToPlayer = dist_between_objects(o, player); int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(2000.0f, &distanceToPlayer, &angleToPlayer); + o->oForwardVel = 0.0f; if (approach_f32_ptr(&o->header.gfx.scale[0], 1.5f, 0.02f)) { // If we are >2000 units from home or Mario is <2000 units from us @@ -65,6 +67,8 @@ static void fly_guy_act_approach_mario(void) { int distanceToPlayer = dist_between_objects(o, player); int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(2000.0f, &distanceToPlayer, &angleToPlayer); + // If we are >2000 units from home or Mario is <2000 units from us if (distanceToPlayer >= 25000.0f || distanceToPlayer < 2000.0f) { obj_forward_vel_approach(10.0f, 0.5f); @@ -146,6 +150,8 @@ static void fly_guy_act_shoot_fire(void) { struct Object* player = marioState->marioObj; int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(2000.0f, NULL, &angleToPlayer); + s32 scaleStatus; o->oForwardVel = 0.0f; @@ -210,7 +216,7 @@ void bhv_fly_guy_update(void) { o->oDeathSound = SOUND_OBJ_KOOPA_FLYGUY_DEATH; cur_obj_scale(o->header.gfx.scale[0]); - treat_far_home_as_mario(2000.0f); + treat_far_home_as_mario(2000.0f, NULL, NULL); cur_obj_update_floor_and_walls(); if (o->oMoveFlags & OBJ_MOVE_HIT_WALL) { diff --git a/src/game/behaviors/goomba.inc.c b/src/game/behaviors/goomba.inc.c index ae552ffa..baaf1773 100644 --- a/src/game/behaviors/goomba.inc.c +++ b/src/game/behaviors/goomba.inc.c @@ -152,7 +152,7 @@ void mark_goomba_as_dead(void) { * chase him. */ static void goomba_act_walk(void) { - treat_far_home_as_mario(1000.0f); + treat_far_home_as_mario(1000.0f, NULL, NULL); obj_forward_vel_approach(o->oGoombaRelativeSpeed * o->oGoombaScale, 0.4f); @@ -174,6 +174,8 @@ static void goomba_act_walk(void) { struct Object* player = nearest_player_to_object(o); int distanceToPlayer = dist_between_objects(o, player); int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(1000.0f, &distanceToPlayer, &angleToPlayer); + // If far from home, walk toward home. if (distanceToPlayer >= 25000.0f) { o->oGoombaTargetYaw = angleToPlayer; diff --git a/src/game/behaviors/koopa.inc.c b/src/game/behaviors/koopa.inc.c index 55a93401..2b5adb75 100644 --- a/src/game/behaviors/koopa.inc.c +++ b/src/game/behaviors/koopa.inc.c @@ -174,9 +174,8 @@ static void koopa_play_footstep_sound(s8 animFrame1, s8 animFrame2) { * running away. */ static s32 koopa_check_run_from_mario(void) { - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; if (distanceToPlayer < 300.0f && abs_angle_diff(angleToPlayer, o->oMoveAngleYaw) < 0x3000) { o->oAction = KOOPA_SHELLED_ACT_RUN_FROM_MARIO; return TRUE; @@ -241,9 +240,8 @@ static void koopa_shelled_act_walk(void) { if (o->oKoopaTurningAwayFromWall) { o->oKoopaTurningAwayFromWall = obj_resolve_collisions_and_turn(o->oKoopaTargetYaw, 0x200); } else { - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; // If far from home, then begin turning toward home if (distanceToPlayer >= 25000.0f) { o->oKoopaTargetYaw = angleToPlayer; @@ -276,9 +274,8 @@ static void koopa_shelled_act_run_from_mario(void) { cur_obj_init_animation_with_sound(1); koopa_play_footstep_sound(0, 11); - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; // If far from home, run toward it if (distanceToPlayer >= 25000.0f) { @@ -420,9 +417,8 @@ static void koopa_shelled_update(void) { * action. */ static void koopa_unshelled_act_run(void) { - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; f32 distToShell = 99999.0f; struct Object *shell; @@ -493,8 +489,7 @@ static void koopa_unshelled_act_dive(void) { if (o->oTimer > 10) { shell = cur_obj_find_nearest_object_with_behavior(bhvKoopaShell, &distToShell); - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); + int distanceToPlayer = o->oDistanceToMario; // If we got the shell and mario didn't, put on the shell //! The shell comes after koopa in processing order, and the shell is @@ -926,7 +921,10 @@ void bhv_koopa_update(void) { o->oKoopaDistanceToMario = distanceToPlayer; o->oKoopaAngleToMario = angleToPlayer; - treat_far_home_as_mario(1000.0f); + + treat_far_home_as_mario(1000.0f, &distanceToPlayer, &angleToPlayer); + o->oDistanceToMario = distanceToPlayer; + o->oAngleToMario = angleToPlayer; switch (o->oKoopaMovementType) { case KOOPA_BP_UNSHELLED: diff --git a/src/game/behaviors/pokey.inc.c b/src/game/behaviors/pokey.inc.c index 2952f47b..dfe91de1 100644 --- a/src/game/behaviors/pokey.inc.c +++ b/src/game/behaviors/pokey.inc.c @@ -220,7 +220,7 @@ static void pokey_act_wander(void) { if (o->oPokeyNumAliveBodyParts == 0) { obj_mark_for_deletion(o); } else { - treat_far_home_as_mario(1000.0f); + treat_far_home_as_mario(1000.0f, &distanceToPlayer, &angleToPlayer); cur_obj_update_floor_and_walls(); if (o->oPokeyHeadWasKilled) { diff --git a/src/game/behaviors/skeeter.inc.c b/src/game/behaviors/skeeter.inc.c index 89126ca4..7aae41dc 100644 --- a/src/game/behaviors/skeeter.inc.c +++ b/src/game/behaviors/skeeter.inc.c @@ -61,9 +61,8 @@ static void skeeter_act_idle(void) { } static void skeeter_act_lunge(void) { - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; if (!(o->oMoveFlags & OBJ_MOVE_AT_WATER_SURFACE)) { o->oAction = SKEETER_ACT_IDLE; @@ -94,9 +93,9 @@ static void skeeter_act_lunge(void) { } static void skeeter_act_walk(void) { - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; + f32 sp24; if (!(o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND)) { @@ -155,7 +154,13 @@ void bhv_skeeter_update(void) { } o->oDeathSound = SOUND_OBJ_SNUFIT_SKEETER_DEATH; - treat_far_home_as_mario(1000.0f); + + struct Object* player = nearest_player_to_object(o); + int distanceToPlayer = dist_between_objects(o, player); + int angleToPlayer = obj_angle_to_object(o, player); + treat_far_home_as_mario(1000.0f, &distanceToPlayer, &angleToPlayer); + o->oDistanceToMario = distanceToPlayer; + o->oAngleToMario = angleToPlayer; cur_obj_update_floor_and_walls(); diff --git a/src/game/behaviors/wiggler.inc.c b/src/game/behaviors/wiggler.inc.c index 52e52286..a6bebcd6 100644 --- a/src/game/behaviors/wiggler.inc.c +++ b/src/game/behaviors/wiggler.inc.c @@ -220,8 +220,8 @@ void wiggler_init_segments(void) { static void wiggler_act_walk(void) { struct MarioState* marioState = nearest_mario_state_to_object(o); struct Object* player = marioState->marioObj; - int distanceToPlayer = dist_between_objects(o, player); - int angleToPlayer = obj_angle_to_object(o, player); + int distanceToPlayer = o->oDistanceToMario; + int angleToPlayer = o->oAngleToMario; s16 yawTurnSpeed; @@ -465,13 +465,19 @@ void bhv_wiggler_update(void) { network_init_object_field(o, &o->oFaceAngleYaw); } + struct Object* player = nearest_player_to_object(o); + int distanceToPlayer = dist_between_objects(o, player); + int angleToPlayer = obj_angle_to_object(o, player); + o->oDistanceToMario = distanceToPlayer; + o->oAngleToMario = angleToPlayer; + if (o->oAction == WIGGLER_ACT_UNINITIALIZED) { wiggler_init_segments(); } else { if (o->oAction == WIGGLER_ACT_FALL_THROUGH_FLOOR) { wiggler_act_fall_through_floor(); } else { - treat_far_home_as_mario(1200.0f); + treat_far_home_as_mario(1200.0f, &distanceToPlayer, &angleToPlayer); // Walking animation and sound cur_obj_init_animation_with_accel_and_sound(0, o->oWigglerWalkAnimSpeed); diff --git a/src/game/obj_behaviors_2.c b/src/game/obj_behaviors_2.c index 4f44f8bc..a6abc326 100644 --- a/src/game/obj_behaviors_2.c +++ b/src/game/obj_behaviors_2.c @@ -880,7 +880,7 @@ static s32 obj_move_for_one_second(s32 endAction) { * attack Mario (e.g. fly guy shooting fire or lunging), especially when combined * with partial updates. */ -static void treat_far_home_as_mario(f32 threshold) { +static void treat_far_home_as_mario(f32 threshold, int* distanceToPlayer, int* angleToPlayer) { f32 dx = o->oHomeX - o->oPosX; f32 dy = o->oHomeY - o->oPosY; f32 dz = o->oHomeZ - o->oPosZ; @@ -889,6 +889,12 @@ static void treat_far_home_as_mario(f32 threshold) { if (distance > threshold) { o->oAngleToMario = atan2s(dz, dx); o->oDistanceToMario = 25000.0f; + if (distanceToPlayer != NULL) { + *distanceToPlayer = o->oDistanceToMario; + } + if (angleToPlayer != NULL) { + *angleToPlayer = o->oAngleToMario; + } } else { struct Object* player = nearest_player_to_object(o); dx = o->oHomeX - player->oPosX; @@ -898,6 +904,9 @@ static void treat_far_home_as_mario(f32 threshold) { if (distance > threshold) { o->oDistanceToMario = 20000.0f; + if (distanceToPlayer != NULL) { + *distanceToPlayer = o->oDistanceToMario; + } } } } diff --git a/src/pc/controller/controller_keyboard_debug.c b/src/pc/controller/controller_keyboard_debug.c index 2d0f7e8d..bb2ebb7b 100644 --- a/src/pc/controller/controller_keyboard_debug.c +++ b/src/pc/controller/controller_keyboard_debug.c @@ -13,8 +13,8 @@ #ifdef DEBUG -static u8 warpToLevel = LEVEL_BOB; -static u8 warpToArea = 29; +static u8 warpToLevel = LEVEL_RR; +static u8 warpToArea = 27; // warpToArea: 26 = basement // warpToArea: 27 = upstairs // warpToArea: 29 = courtyard