+1








f3e61a31aa
* buffers: refresh 15 and revert to base decomp * behavior script * color helper functions * extended bounds * egeo_layout * fixed model ids * camera conf improved * message panel ucode small * graph node * level script * mathutil updates * mathutil updates (allow unused funcs) * behaviors a - beta_fish * Add librtc and fix some data declarations * Move GRUCODE define to proper location in makefile * Refresh 15 * extra * Make ROM name smaller and change messages printed on build a bit * Fix console (lol) * Update UNF to latest master * Make ucode load from .o's (and also fix Super3D) * Fix crash with rumble + custom mario model * graph node and mathutil * removed behaviors * Ldtob documentation * _Putfld labeling * area * behavior actions * camera * debug updates * bubbles * envfx snow * farcall helpers * game init * geo misc * hud * only check if VC on render init * ingame menu * revert goddard to base decomp * insn disasm * interaction documentation * level geo * level update defines * macro special objects formatting changes * main.h documentation * map parser documentation & formatting * airborne documentation * mario actions automatic documentation * mario actions cutscene documentation * mario actions moving documentation and options * mario actions object documentation and options * mario stationary documentation * mario submerged documentation * mario misc documentation * mario step: ledge grab fixes and documentation * mario documentation * memory.h documentation * moving textures * object behaviors * object collision * fix flamethrower bug * object helpers * object list processor documentation * paintings * platform displacement * print / printf * puppycam absf * puppyprint updates and formatting changes * rendering graph node performance optimizations * rumble opt and doc * hqvm back to ultrasm64 * save file documentation and unlock defines * s2d engine * reset various files to ultrasm64 * file select * intro geo documentation * screen transition documentation * segment2.h * shadow overhaul * skybox refactor * sound init: clean up define usage + documentation * spawn object optimizations and documentation * spawn sound cleanup * sram to ultrasm64 * star select cleanup * title screen cleanup * dialogs / text * rename stomp smoke * stomp smoke -> small water splash * updated README * compilation flags * optimized file positions + support function/data sections * surface collision performance improvements * surface load optimizations * camera conf documentation * Allow easier command for opening puppyprint debug * Rearranged framebuffers & fixed puppyprint console printing * Fix shadow scaling and shifting * Fix SILHOUETTE, OBJECTS_REJ, and ucode loading, also clean up render phase system a bit. * Fixed build with BETTER_HANGING off * Clean up OBJECTS_REJ ifdefs * Fix duplicate comment & graph render layers/flags bitmask * Fixed build with BETTER_HANGING off * Fix Fast64 importing by reverting sSegmentTable change * Readded missing functions that caused build errors with Mario head enabled * Fixed clang compilation issues * Add INTER mode for geo_update_layer_transparency * Fix build warnings * bugfix: miscalculation in obj_turn_toward_object * Some puppytech fixes * Further Puppycamera fixes * Fix BUGFIX_DIALOG_TIME_STOP Fixes #136 * Fix sliding platform bparams * Add LEGACY_SHADOW_IDS define for Fast64 compatibility * Apply suggested changes * Better find_in_bounds_yaw_wdw_bob_thi ifdef * Fix build warnings for unused functions * Fixed stale reference bug from obj_mark_for_deletion change * Fixed incorrect digit for 100s #145 * Change groundpound-fix define and functionality to just disable bonking * Fixed puppyroll #134 * Adjust height value for terrain angle to kick in * fixed hi score flashing * Remove menudata backup (#131) Not considered important enough to keep * Fix fread() build warning * Add COURSE_NUM_TO_INDEX to save_file_get_star_flags check in bhv_unagi_init * Fix approach_s16 return value * Use boolean defines for oCapDoScaleVertically * Make the door lock a part of the key door model to eliminate z-fighting, also reduce z fighting on numbered doors with AUTO_LOD enabled. * Move flames to LAYER_TRANSPARENT_INTER * Resolved some compiler warnings and added FALL_THROUGH define (#168) * Address some more compiler warnings with different define toggles * Remove unnecessary fallthrough attribute * fixed geo_process_billboard floating point exception * Allow water to face any direction * Initialize focOffset so that BBH doesn't crash * Removed superfluous RDP commands when switching microcodes which would override scissor * Set OBJ_FLAG_DONT_CALC_COLL_DIST on bhvUkikiCage * Fix rumble build * Fixed UNLOCK_FPS strobing * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update src/game/object_helpers.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Fix LEGACY_SHADOW_IDS id conflict * Use the vanilla default value for rotating fire bars if bparam2 is 0 * START_LEVEL safeguard * Fix some drawing distance issues caused by AUTO_COLLISION_DISTANCE * Fix rumble build * Fixed spline poll code using the wrong values for keyframes * Update readme with better credits Better credits for individual contributors * add arthur * added falco and moose * add fazana * le funny typo * added S2DEX engine to credits * silhouette + axo + ratio * remove specific callouts + add auto col distance * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Update data/behavior_data.c Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com> * Revert formatting changes to match vanilla decomp * Re-implement Y buffer for find_ceil * Re-implement POWER_STARS_HEAL for normal Power Stars * Start level comment & exit course comment/collapse * utilize reonucam technique for FAST_VERTICAL_CAMERA_MOVEMENT * Fix "MAX_REFERENCED_WALLS" typo * Allow stop_and_set_height_to_floor to work at any height if Mario is teleporting (#213) * Revert stop_and_set_height_to_floor to vanilla Fixes #208 * Fixed sAudioEnabled so that it disables audio CPU processing as well * Fixed puppyprint debug RDP us calculations * Renamed sAudioEnabled to gAudioEnabled * Replaced mtxf_to_mtx_asm with an equivalent implementation that supports WORLD_SCALE * Moved extended bounds and world scale configuration to a new config_world.h file * Default all objects to non-rej (#227) Fixes #221 (Default all objects to non-rej) * Fix #221 * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled (#211) * Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled * Change vtl decrement in visual_surface_display from 6 to 3 Fixes #207 * Make area in SL igloo wider to prevent a softlock (#233) Fixes #210 * Fix coin formation coins being deleted if they spawn in the middle of a floor, also fix TTM slide coin position (#232) Fixes #201 * Make UNLOCK_ALL apply to more things * Fix wrong ifdef/ifndef in bhv_invisible_objects_under_bridge_init * Change chain chomp load/unload distances depending on number of segments (#237) Fixes #192 * added WATER_PLUNGE_UPWARP define * Add reonucam patch (#239) * added reonucam patch Fixes #218 * Fix how shadows handle water/transparency/height (#228) * Fix how shadows handle water/transparency/height * Change shadow check for flying carpets from a level specific check to a oPlatformOnTrackType check Fixes #179 * added reonucam credit * delete unnecesary patches * Apply suggested changes * murdered more patches * UNLOCK_ALL unlocks the cap boxes * UNLOCK_ALL unlocks cap boxes (slightly more epic edition) * revert ceil buffer * Renamed HD_INTRO_TEXTURES define, separated intro floombas * prevent double definition of floombas * actually prevent floomba redefinition * Develop/refactor default defines (#242) * Changed default config options * Added build dir to includePaths for pngs * disable NO_SLEEP by default * Disable puppyprint by default Sorry fazana 😔 * fix typos * add comment about BETTER_REVERB console perf * disable blue coin switch retry by default * Update config_audio.h Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> * revert air step line to vanilla to fix bitfs scaling platform issue (#247) Fixes #200 * Fix stuttering on thin slopes (#248) * Fix stuttering on thin slopes * Revert vec3f_find_ceil calls to vanilla * Rename vec3f_find_ceil to find_mario_ceil * Update src/engine/surface_collision.h Fixes #249 * Swap static and dynamic surface checks back to vanilla order (#253) * Swap static and dynamic surface checks back to vanilla order * re-enable DISABLE_ALL config Fixes #251 #252 * Fixed save and quitting while in widescreen (#257) * Fixed save and quitting while in widescreen * use define for the level * all my homies hate ifdefs * skip wall offsets < 0 (#255) Fixes #255 * #264: Document non-stop stars' issues (#267) * #264: Document non-stop stars' issues * Update include/config/config_game.h * nonstop vanilla comment * derive margin_radius from radius after capping at 200 (#266) Fixes #259 * Config cleanup/refactor (#269) * Moved puppyprint define to graphics / rearranged some debug defines for ease of access * Moved compatibility safeguards to config_safeguards.h * spacing and comment formatting * #272 Move GFX_POOL_SIZE to config_graphics.h * disable EASIER_DIALOG_TRIGGER by default * prevent redefining warnings * small ifdef typo * changed ifndef to undefs Fixes #262 Fixes #272 * Improved movement config documentation related to turning around (#271) Fixes #270 * rename CUSTOM_DEBUG, add comments (#275) * Update README.md (#277) * v2.0.0 Co-authored-by: CrashOveride95 <crashoveride953@gmail.com> Co-authored-by: Arceveti <73617174+Arceveti@users.noreply.github.com> Co-authored-by: n64 <n64> Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <mrwiseguyromhacking@gmail.com> Co-authored-by: aglab2 <aglab3@gmail.com> Co-authored-by: gheskett <gheskett@gmail.com> Co-authored-by: Reonu <danileon95@gmail.com> Co-authored-by: Axollyon <20480418+Axollyon@users.noreply.github.com> Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
783 lines
24 KiB
C
783 lines
24 KiB
C
#include <PR/ultratypes.h>
|
|
|
|
#include "sm64.h"
|
|
#include "area.h"
|
|
#include "audio/external.h"
|
|
#include "behavior_actions.h"
|
|
#include "behavior_data.h"
|
|
#include "camera.h"
|
|
#include "course_table.h"
|
|
#include "dialog_ids.h"
|
|
#include "engine/behavior_script.h"
|
|
#include "engine/math_util.h"
|
|
#include "engine/surface_collision.h"
|
|
#include "envfx_bubbles.h"
|
|
#include "game_init.h"
|
|
#include "ingame_menu.h"
|
|
#include "interaction.h"
|
|
#include "level_misc_macros.h"
|
|
#include "level_table.h"
|
|
#include "level_update.h"
|
|
#include "levels/bob/header.h"
|
|
#include "levels/ttm/header.h"
|
|
#include "mario.h"
|
|
#include "mario_actions_cutscene.h"
|
|
#include "mario_misc.h"
|
|
#include "memory.h"
|
|
#include "obj_behaviors.h"
|
|
#include "object_helpers.h"
|
|
#include "object_list_processor.h"
|
|
#include "rendering_graph_node.h"
|
|
#include "save_file.h"
|
|
#include "spawn_object.h"
|
|
#include "spawn_sound.h"
|
|
#include "rumble_init.h"
|
|
#include "puppylights.h"
|
|
|
|
/**
|
|
* @file obj_behaviors.c
|
|
* This file contains a portion of the obj behaviors and many helper functions for those
|
|
* specific behaviors. Few functions besides the bhv_ functions are used elsewhere in the repo.
|
|
*/
|
|
|
|
/**
|
|
* Current object floor as defined in object_step.
|
|
*/
|
|
static struct Surface *sObjFloor;
|
|
|
|
/**
|
|
* Set to false when an object close to the floor should not be oriented in reference
|
|
* to it. Happens with boulder, falling pillar, and the rolling snowman body.
|
|
*/
|
|
static s8 sOrientObjWithFloor = TRUE;
|
|
|
|
/**
|
|
* Keeps track of Mario's previous non-zero room.
|
|
* Helps keep track of room when Mario is over an object.
|
|
*/
|
|
s16 sPrevCheckMarioRoom = 0;
|
|
|
|
/**
|
|
* Tracks whether or not Yoshi has walked/jumped off the roof.
|
|
*/
|
|
s8 sYoshiDead = FALSE;
|
|
|
|
extern void *ccm_seg7_trajectory_snowman;
|
|
extern void *inside_castle_seg7_trajectory_mips;
|
|
|
|
/**
|
|
* Resets yoshi as spawned/despawned upon new file select.
|
|
* Possibly a function with stubbed code.
|
|
*/
|
|
void set_yoshi_as_not_dead(void) {
|
|
sYoshiDead = FALSE;
|
|
}
|
|
|
|
/**
|
|
* An unused geo function. Bears strong similarity to geo_bits_bowser_coloring, and relates something
|
|
* of the opacity of an object to something else. Perhaps like, giving a parent object the same
|
|
* opacity?
|
|
*/
|
|
Gfx UNUSED *geo_obj_transparency_something(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx) {
|
|
Gfx *gfxHead = NULL;
|
|
Gfx *gfx;
|
|
|
|
if (callContext == GEO_CONTEXT_RENDER) {
|
|
struct Object *heldObject = (struct Object *) gCurGraphNodeObject;
|
|
struct Object *obj = (struct Object *) node;
|
|
|
|
|
|
if (gCurGraphNodeHeldObject != NULL) {
|
|
heldObject = gCurGraphNodeHeldObject->objNode;
|
|
}
|
|
|
|
gfxHead = alloc_display_list(3 * sizeof(Gfx));
|
|
gfx = gfxHead;
|
|
SET_GRAPH_NODE_LAYER(obj->header.gfx.node.flags, LAYER_TRANSPARENT);
|
|
|
|
gDPSetEnvColor(gfx++, 255, 255, 255, heldObject->oOpacity);
|
|
|
|
gSPEndDisplayList(gfx);
|
|
}
|
|
|
|
return gfxHead;
|
|
}
|
|
|
|
/**
|
|
* Backwards compatibility, used to be a duplicate function
|
|
*/
|
|
#define absf_2 absf
|
|
|
|
/**
|
|
* Turns an object away from floors/walls that it runs into.
|
|
*/
|
|
void turn_obj_away_from_surface(f32 velX, f32 velZ, f32 nX, UNUSED f32 nY, f32 nZ, f32 *objYawX,
|
|
f32 *objYawZ) {
|
|
*objYawX = (nZ * nZ - nX * nX) * velX / (nX * nX + nZ * nZ)
|
|
- 2 * velZ * (nX * nZ) / (nX * nX + nZ * nZ);
|
|
|
|
*objYawZ = (nX * nX - nZ * nZ) * velZ / (nX * nX + nZ * nZ)
|
|
- 2 * velX * (nX * nZ) / (nX * nX + nZ * nZ);
|
|
}
|
|
|
|
/**
|
|
* Finds any wall collisions, applies them, and turns away from the surface.
|
|
*/
|
|
s8 obj_find_wall(f32 objNewX, f32 objY, f32 objNewZ, f32 objVelX, f32 objVelZ) {
|
|
struct WallCollisionData hitbox;
|
|
f32 wall_nX, wall_nY, wall_nZ, objVelXCopy, objVelZCopy, objYawX, objYawZ;
|
|
|
|
hitbox.x = objNewX;
|
|
hitbox.y = objY;
|
|
hitbox.z = objNewZ;
|
|
hitbox.offsetY = o->hitboxHeight / 2;
|
|
hitbox.radius = o->hitboxRadius;
|
|
|
|
if (find_wall_collisions(&hitbox) != 0) {
|
|
o->oPosX = hitbox.x;
|
|
o->oPosY = hitbox.y;
|
|
o->oPosZ = hitbox.z;
|
|
|
|
wall_nX = hitbox.walls[0]->normal.x;
|
|
wall_nY = hitbox.walls[0]->normal.y;
|
|
wall_nZ = hitbox.walls[0]->normal.z;
|
|
|
|
objVelXCopy = objVelX;
|
|
objVelZCopy = objVelZ;
|
|
|
|
// Turns away from the first wall only.
|
|
turn_obj_away_from_surface(objVelXCopy, objVelZCopy, wall_nX, wall_nY, wall_nZ, &objYawX, &objYawZ);
|
|
|
|
o->oMoveAngleYaw = atan2s(objYawZ, objYawX);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* Turns an object away from steep floors, similarly to walls.
|
|
*/
|
|
s8 turn_obj_away_from_steep_floor(struct Surface *objFloor, f32 floorY, f32 objVelX, f32 objVelZ) {
|
|
f32 floor_nX, floor_nY, floor_nZ, objVelXCopy, objVelZCopy, objYawX, objYawZ;
|
|
|
|
if (objFloor == NULL) {
|
|
o->oMoveAngleYaw += 0x8000;
|
|
return FALSE;
|
|
}
|
|
|
|
floor_nX = objFloor->normal.x;
|
|
floor_nY = objFloor->normal.y;
|
|
floor_nZ = objFloor->normal.z;
|
|
|
|
// If the floor is steep and we are below it (i.e. walking into it), turn away from the floor.
|
|
if (floor_nY < 0.5f && floorY > o->oPosY) {
|
|
objVelXCopy = objVelX;
|
|
objVelZCopy = objVelZ;
|
|
turn_obj_away_from_surface(objVelXCopy, objVelZCopy, floor_nX, floor_nY, floor_nZ, &objYawX, &objYawZ);
|
|
o->oMoveAngleYaw = atan2s(objYawZ, objYawX);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* Orients an object with the given normals, typically the surface under the object.
|
|
*/
|
|
void obj_orient_graph(struct Object *obj, f32 normalX, f32 normalY, f32 normalZ) {
|
|
Vec3f objVisualPosition, surfaceNormals;
|
|
|
|
Mat4 *throwMatrix;
|
|
|
|
// Passes on orienting certain objects that shouldn't be oriented, like boulders.
|
|
if (!sOrientObjWithFloor) {
|
|
return;
|
|
}
|
|
|
|
// Passes on orienting billboard objects, i.e. coins, trees, etc.
|
|
if (obj->header.gfx.node.flags & GRAPH_RENDER_BILLBOARD) {
|
|
return;
|
|
}
|
|
|
|
throwMatrix = alloc_display_list(sizeof(*throwMatrix));
|
|
// If out of memory, fail to try orienting the object.
|
|
if (throwMatrix == NULL) {
|
|
return;
|
|
}
|
|
|
|
vec3f_copy_y_off(objVisualPosition, &obj->oPosVec, obj->oGraphYOffset);
|
|
vec3f_set(surfaceNormals, normalX, normalY, normalZ);
|
|
|
|
mtxf_align_terrain_normal(*throwMatrix, surfaceNormals, objVisualPosition, obj->oFaceAngleYaw);
|
|
obj->header.gfx.throwMatrix = throwMatrix;
|
|
}
|
|
|
|
/**
|
|
* Determines an object's forward speed multiplier.
|
|
*/
|
|
void calc_obj_friction(f32 *objFriction, f32 floor_nY) {
|
|
if (floor_nY < 0.2f && o->oFriction < 0.9999f) {
|
|
*objFriction = 0;
|
|
} else {
|
|
*objFriction = o->oFriction;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Updates an objects speed for gravity and updates Y position.
|
|
*/
|
|
void calc_new_obj_vel_and_pos_y(struct Surface *objFloor, f32 objFloorY, f32 objVelX, f32 objVelZ) {
|
|
f32 floor_nX = objFloor->normal.x;
|
|
f32 floor_nY = objFloor->normal.y;
|
|
f32 floor_nZ = objFloor->normal.z;
|
|
f32 objFriction;
|
|
|
|
// Caps vertical speed with a "terminal velocity".
|
|
o->oVelY -= o->oGravity;
|
|
if (o->oVelY > 75.0) {
|
|
o->oVelY = 75.0;
|
|
}
|
|
if (o->oVelY < -75.0) {
|
|
o->oVelY = -75.0;
|
|
}
|
|
|
|
o->oPosY += o->oVelY;
|
|
|
|
// Snap the object up to the floor.
|
|
if (o->oPosY < objFloorY) {
|
|
o->oPosY = objFloorY;
|
|
|
|
// Bounces an object if the ground is hit fast enough.
|
|
if (o->oVelY < -17.5f) {
|
|
o->oVelY = -(o->oVelY / 2);
|
|
} else {
|
|
o->oVelY = 0;
|
|
}
|
|
}
|
|
|
|
//! (Obj Position Crash) If you got an object with height past 2^31, the game would crash.
|
|
if ((s32) o->oPosY >= (s32) objFloorY && (s32) o->oPosY < (s32) objFloorY + 37) {
|
|
obj_orient_graph(o, floor_nX, floor_nY, floor_nZ);
|
|
|
|
// Adds horizontal component of gravity for horizontal speed.
|
|
f32 nxz = sqr(floor_nX) + sqr(floor_nZ);
|
|
f32 vel = ((nxz) / (nxz + sqr(floor_nY))) * o->oGravity * 2;
|
|
objVelX += floor_nX * vel;
|
|
objVelZ += floor_nZ * vel;
|
|
|
|
if (objVelX < NEAR_ZERO && objVelX > -NEAR_ZERO) objVelX = 0;
|
|
if (objVelZ < NEAR_ZERO && objVelZ > -NEAR_ZERO) objVelZ = 0;
|
|
|
|
if (objVelX != 0 || objVelZ != 0) {
|
|
o->oMoveAngleYaw = atan2s(objVelZ, objVelX);
|
|
}
|
|
|
|
calc_obj_friction(&objFriction, floor_nY);
|
|
o->oForwardVel = sqrtf(sqr(objVelX) + sqr(objVelZ)) * objFriction;
|
|
}
|
|
}
|
|
|
|
void calc_new_obj_vel_and_pos_y_underwater(struct Surface *objFloor, f32 floorY, f32 objVelX, f32 objVelZ, f32 waterY) {
|
|
f32 floor_nX = objFloor->normal.x;
|
|
f32 floor_nY = objFloor->normal.y;
|
|
f32 floor_nZ = objFloor->normal.z;
|
|
|
|
f32 netYAccel = (1.0f - o->oBuoyancy) * (-1.0f * o->oGravity);
|
|
o->oVelY -= netYAccel;
|
|
|
|
// Caps vertical speed with a "terminal velocity".
|
|
if (o->oVelY > 75.0f) {
|
|
o->oVelY = 75.0f;
|
|
}
|
|
if (o->oVelY < -75.0f) {
|
|
o->oVelY = -75.0f;
|
|
}
|
|
|
|
o->oPosY += o->oVelY;
|
|
|
|
// Snap the object up to the floor.
|
|
if (o->oPosY < floorY) {
|
|
o->oPosY = floorY;
|
|
|
|
// Bounces an object if the ground is hit fast enough.
|
|
if (o->oVelY < -17.5f) {
|
|
o->oVelY = -(o->oVelY / 2);
|
|
} else {
|
|
o->oVelY = 0;
|
|
}
|
|
}
|
|
|
|
// If moving fast near the surface of the water, flip vertical speed? To emulate skipping?
|
|
if (o->oForwardVel > 12.5f && (waterY + 30.0f) > o->oPosY && (waterY - 30.0f) < o->oPosY) {
|
|
o->oVelY = -o->oVelY;
|
|
}
|
|
|
|
if ((s32) o->oPosY >= (s32) floorY && (s32) o->oPosY < (s32) floorY + 37) {
|
|
obj_orient_graph(o, floor_nX, floor_nY, floor_nZ);
|
|
|
|
// Adds horizontal component of gravity for horizontal speed.
|
|
f32 nxz = sqr(floor_nX) + sqr(floor_nZ);
|
|
f32 velm = (nxz / (nxz + sqr(floor_nY))) * netYAccel * 2;
|
|
objVelX += floor_nX * velm;
|
|
objVelZ += floor_nZ * velm;
|
|
}
|
|
|
|
if (objVelX < NEAR_ZERO && objVelX > -NEAR_ZERO) objVelX = 0;
|
|
if (objVelZ < NEAR_ZERO && objVelZ > -NEAR_ZERO) objVelZ = 0;
|
|
|
|
if (o->oVelY < NEAR_ZERO && o->oVelY > -NEAR_ZERO) {
|
|
o->oVelY = 0;
|
|
}
|
|
|
|
if (objVelX != 0 || objVelZ != 0) {
|
|
o->oMoveAngleYaw = atan2s(objVelZ, objVelX);
|
|
}
|
|
|
|
// Decreases both vertical velocity and forward velocity. Likely so that skips above
|
|
// don't loop infinitely.
|
|
o->oForwardVel = sqrtf(sqr(objVelX) + sqr(objVelZ)) * 0.8f;
|
|
o->oVelY *= 0.8f;
|
|
}
|
|
|
|
/**
|
|
* Updates an objects position from oForwardVel and oMoveAngleYaw.
|
|
*/
|
|
void obj_update_pos_vel_xz(void) {
|
|
o->oPosX += o->oForwardVel * sins(o->oMoveAngleYaw);
|
|
o->oPosZ += o->oForwardVel * coss(o->oMoveAngleYaw);
|
|
}
|
|
|
|
/**
|
|
* Generates splashes if at surface of water, entering water, or bubbles
|
|
* if underwater.
|
|
*/
|
|
void obj_splash(s32 waterY, s32 objY) {
|
|
u32 globalTimer = gGlobalTimer;
|
|
|
|
// Spawns waves if near surface of water and plays a noise if entering.
|
|
if ((f32)(waterY + 30) > o->oPosY && o->oPosY > (f32)(waterY - 30)) {
|
|
spawn_object(o, MODEL_IDLE_WATER_WAVE, bhvObjectWaterWave);
|
|
|
|
if (o->oVelY < -20.0f) {
|
|
cur_obj_play_sound_2(SOUND_OBJ_DIVING_INTO_WATER);
|
|
}
|
|
}
|
|
|
|
// Spawns bubbles if underwater.
|
|
if ((objY + 50) < waterY && !(globalTimer & 31)) {
|
|
spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvObjectBubble);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generic object move function. Handles walls, water, floors, and gravity.
|
|
* Returns flags for certain interactions.
|
|
*/
|
|
s16 object_step(void) {
|
|
f32 objX = o->oPosX;
|
|
f32 objY = o->oPosY;
|
|
f32 objZ = o->oPosZ;
|
|
|
|
f32 floorY;
|
|
f32 waterY = FLOOR_LOWER_LIMIT_MISC;
|
|
|
|
f32 objVelX = o->oForwardVel * sins(o->oMoveAngleYaw);
|
|
f32 objVelZ = o->oForwardVel * coss(o->oMoveAngleYaw);
|
|
|
|
s16 collisionFlags = 0;
|
|
|
|
// Find any wall collisions, receive the push, and set the flag.
|
|
if (obj_find_wall(objX + objVelX, objY, objZ + objVelZ, objVelX, objVelZ) == 0) {
|
|
collisionFlags += OBJ_COL_FLAG_HIT_WALL;
|
|
}
|
|
|
|
floorY = find_floor(objX + objVelX, objY, objZ + objVelZ, &sObjFloor);
|
|
|
|
o->oFloor = sObjFloor;
|
|
o->oFloorHeight = floorY;
|
|
|
|
if (turn_obj_away_from_steep_floor(sObjFloor, floorY, objVelX, objVelZ) == 1) {
|
|
waterY = find_water_level(objX + objVelX, objZ + objVelZ);
|
|
if (waterY > objY) {
|
|
calc_new_obj_vel_and_pos_y_underwater(sObjFloor, floorY, objVelX, objVelZ, waterY);
|
|
collisionFlags += OBJ_COL_FLAG_UNDERWATER;
|
|
} else {
|
|
calc_new_obj_vel_and_pos_y(sObjFloor, floorY, objVelX, objVelZ);
|
|
}
|
|
} else {
|
|
// Treat any awkward floors similar to a wall.
|
|
collisionFlags +=
|
|
((collisionFlags & OBJ_COL_FLAG_HIT_WALL) ^ OBJ_COL_FLAG_HIT_WALL);
|
|
}
|
|
|
|
obj_update_pos_vel_xz();
|
|
if ((s32) o->oPosY == (s32) floorY) {
|
|
collisionFlags += OBJ_COL_FLAG_GROUNDED;
|
|
}
|
|
|
|
if ((s32) o->oVelY == 0) {
|
|
collisionFlags += OBJ_COL_FLAG_NO_Y_VEL;
|
|
}
|
|
|
|
// Generate a splash if in water.
|
|
obj_splash((s32) waterY, (s32) o->oPosY);
|
|
return collisionFlags;
|
|
}
|
|
|
|
/**
|
|
* Takes an object step but does not orient with the object's floor.
|
|
* Used for boulders, falling pillars, and the rolling snowman body.
|
|
*/
|
|
s16 object_step_without_floor_orient(void) {
|
|
sOrientObjWithFloor = FALSE;
|
|
s16 collisionFlags = object_step();
|
|
sOrientObjWithFloor = TRUE;
|
|
|
|
return collisionFlags;
|
|
}
|
|
|
|
/**
|
|
* Uses an object's forward velocity and yaw to move its X, Y, and Z positions.
|
|
* This does accept an object as an argument, though it is always called with `o`.
|
|
*/
|
|
void obj_move_xyz_using_fvel_and_yaw(struct Object *obj) {
|
|
obj->oVelX = obj->oForwardVel * sins(obj->oMoveAngleYaw);
|
|
obj->oVelZ = obj->oForwardVel * coss(obj->oMoveAngleYaw);
|
|
|
|
vec3f_add(&obj->oPosVec, &obj->oVelVec);
|
|
}
|
|
|
|
/**
|
|
* Checks if a point is within distance from Mario's graphical position. Test is exclusive.
|
|
*/
|
|
s32 is_point_within_radius_of_mario(f32 x, f32 y, f32 z, s32 dist) {
|
|
f32 dx = x - gMarioObject->header.gfx.pos[0];
|
|
f32 dy = y - gMarioObject->header.gfx.pos[1];
|
|
f32 dz = z - gMarioObject->header.gfx.pos[2];
|
|
|
|
return sqr(dx) + sqr(dy) + sqr(dz) < (f32)sqr(dist);
|
|
}
|
|
|
|
/**
|
|
* Checks whether a point is within distance of a given point. Test is exclusive.
|
|
*/
|
|
s32 is_point_close_to_object(struct Object *obj, f32 x, f32 y, f32 z, s32 dist) {
|
|
f32 dx = x - obj->oPosX;
|
|
f32 dy = y - obj->oPosY;
|
|
f32 dz = z - obj->oPosZ;
|
|
|
|
return sqr(dx) + sqr(dy) + sqr(dz) < (f32)sqr(dist);
|
|
}
|
|
|
|
/**
|
|
* Sets an object as visible if within a certain distance of Mario's graphical position.
|
|
*/
|
|
void set_object_visibility(struct Object *obj, s32 dist) {
|
|
COND_BIT(
|
|
!is_point_within_radius_of_mario(obj->oPosX, obj->oPosY, obj->oPosZ, dist),
|
|
obj->header.gfx.node.flags,
|
|
GRAPH_RENDER_INVISIBLE
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Turns an object towards home if Mario is not near to it.
|
|
*/
|
|
s32 obj_return_home_if_safe(struct Object *obj, f32 homeX, f32 y, f32 homeZ, s32 dist) {
|
|
f32 homeDistX = homeX - obj->oPosX;
|
|
f32 homeDistZ = homeZ - obj->oPosZ;
|
|
s16 angleTowardsHome = atan2s(homeDistZ, homeDistX);
|
|
|
|
if (is_point_within_radius_of_mario(homeX, y, homeZ, dist)) {
|
|
return TRUE;
|
|
} else {
|
|
obj->oMoveAngleYaw = approach_s16_symmetric(obj->oMoveAngleYaw, angleTowardsHome, 320);
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Randomly displaces an objects home if RNG says to, and turns the object towards its home.
|
|
*/
|
|
void obj_return_and_displace_home(struct Object *obj, f32 homeX, UNUSED f32 homeY, f32 homeZ, s32 baseDisp) {
|
|
s16 angleToNewHome;
|
|
f32 homeDistX, homeDistZ;
|
|
|
|
if ((s32)(random_float() * 50.0f) == 0) {
|
|
obj->oHomeX = (f32)(baseDisp * 2) * random_float() - (f32) baseDisp + homeX;
|
|
obj->oHomeZ = (f32)(baseDisp * 2) * random_float() - (f32) baseDisp + homeZ;
|
|
}
|
|
|
|
homeDistX = obj->oHomeX - obj->oPosX;
|
|
homeDistZ = obj->oHomeZ - obj->oPosZ;
|
|
angleToNewHome = atan2s(homeDistZ, homeDistX);
|
|
obj->oMoveAngleYaw = approach_s16_symmetric(obj->oMoveAngleYaw, angleToNewHome, 320);
|
|
}
|
|
|
|
/**
|
|
* A series of checks using sin and cos to see if a given angle is facing in the same direction
|
|
* of a given angle, within a certain range.
|
|
*/
|
|
s32 obj_check_if_facing_toward_angle(u32 base, u32 goal, s16 range) {
|
|
s16 dAngle = (u16) goal - (u16) base;
|
|
|
|
if (((f32) sins(-range) < (f32) sins(dAngle)) && ((f32) sins(dAngle) < (f32) sins(range))
|
|
&& (coss(dAngle) > 0)) {
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Finds any wall collisions and returns what the displacement vector would be.
|
|
*/
|
|
s32 obj_find_wall_displacement(Vec3f dist, f32 x, f32 y, f32 z, f32 radius) {
|
|
struct WallCollisionData hitbox;
|
|
hitbox.x = x;
|
|
hitbox.y = y;
|
|
hitbox.z = z;
|
|
hitbox.offsetY = 10.0f;
|
|
hitbox.radius = radius;
|
|
|
|
if (find_wall_collisions(&hitbox) != 0) {
|
|
dist[0] = hitbox.x - x;
|
|
dist[1] = hitbox.y - y;
|
|
dist[2] = hitbox.z - z;
|
|
return TRUE;
|
|
} else {
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Spawns a number of coins at the location of an object
|
|
* with a random forward velocity, y velocity, and direction.
|
|
*/
|
|
void obj_spawn_yellow_coins(struct Object *obj, s8 nCoins) {
|
|
struct Object *coin;
|
|
s8 count;
|
|
|
|
for (count = 0; count < nCoins; count++) {
|
|
coin = spawn_object(obj, MODEL_YELLOW_COIN, bhvMovingYellowCoin);
|
|
coin->oForwardVel = random_float() * 20;
|
|
coin->oVelY = random_float() * 40 + 20;
|
|
coin->oMoveAngleYaw = random_u16();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Controls whether certain objects should flicker/when to despawn.
|
|
*/
|
|
s32 obj_flicker_and_disappear(struct Object *obj, s16 lifeSpan) {
|
|
if (obj->oTimer < lifeSpan) {
|
|
return FALSE;
|
|
}
|
|
|
|
if (obj->oTimer < lifeSpan + 40) {
|
|
COND_BIT((obj->oTimer & 0x1), obj->header.gfx.node.flags, GRAPH_RENDER_INVISIBLE);
|
|
} else {
|
|
obj->activeFlags = ACTIVE_FLAG_DEACTIVATED;
|
|
return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Checks if a given room is Mario's current room, even if on an object.
|
|
*/
|
|
s32 current_mario_room_check(RoomData room) {
|
|
s32 result;
|
|
|
|
// Since object surfaces have room 0, this tests if the surface is an
|
|
// object first and uses the last room if so.
|
|
if (gMarioCurrentRoom == 0) {
|
|
return room == sPrevCheckMarioRoom;
|
|
} else {
|
|
result = room == gMarioCurrentRoom;
|
|
|
|
sPrevCheckMarioRoom = gMarioCurrentRoom;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Triggers dialog when Mario is facing an object and controls it while in the dialog.
|
|
*/
|
|
s32 trigger_obj_dialog_when_facing(s32 *inDialog, s16 dialogID, f32 dist, s32 actionArg) {
|
|
if ((is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, (s32) dist)
|
|
&& obj_check_if_facing_toward_angle(o->oFaceAngleYaw, gMarioObject->header.gfx.angle[1] + 0x8000, 0x1000)
|
|
&& obj_check_if_facing_toward_angle(o->oMoveAngleYaw, o->oAngleToMario, 0x1000))
|
|
|| (*inDialog == TRUE)) {
|
|
*inDialog = TRUE;
|
|
|
|
if (set_mario_npc_dialog(actionArg) == MARIO_DIALOG_STATUS_SPEAK) { // If Mario is speaking.
|
|
s16 dialogResponse = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogID);
|
|
if (dialogResponse != DIALOG_RESPONSE_NONE) {
|
|
set_mario_npc_dialog(MARIO_DIALOG_STOP);
|
|
*inDialog = FALSE;
|
|
return dialogResponse;
|
|
}
|
|
return DIALOG_RESPONSE_NONE;
|
|
}
|
|
}
|
|
|
|
return DIALOG_RESPONSE_NONE;
|
|
}
|
|
|
|
/**
|
|
*Checks if a floor is one that should cause an object to "die".
|
|
*/
|
|
void obj_check_floor_death(s16 collisionFlags, struct Surface *floor) {
|
|
if (floor == NULL) {
|
|
return;
|
|
}
|
|
|
|
if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == OBJ_COL_FLAG_GROUNDED) {
|
|
switch (floor->type) {
|
|
case SURFACE_BURNING:
|
|
o->oAction = OBJ_ACT_LAVA_DEATH;
|
|
break;
|
|
case SURFACE_VERTICAL_WIND:
|
|
case SURFACE_DEATH_PLANE:
|
|
o->oAction = OBJ_ACT_DEATH_PLANE_DEATH;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Controls an object dying in lava by creating smoke, sinking the object, playing
|
|
* audio, and eventually despawning it. Returns TRUE when the obj is dead.
|
|
*/
|
|
s32 obj_lava_death(void) {
|
|
struct Object *deathSmoke;
|
|
|
|
if (o->oTimer > 30) {
|
|
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
|
|
return TRUE;
|
|
} else {
|
|
// Sinking effect
|
|
o->oPosY -= 10.0f;
|
|
}
|
|
|
|
if ((o->oTimer % 8) == 0) {
|
|
cur_obj_play_sound_2(SOUND_OBJ_BULLY_EXPLODE_LAVA);
|
|
deathSmoke = spawn_object(o, MODEL_SMOKE, bhvBobombBullyDeathSmoke);
|
|
deathSmoke->oPosX += random_float() * 20.0f;
|
|
deathSmoke->oPosY += random_float() * 20.0f;
|
|
deathSmoke->oPosZ += random_float() * 20.0f;
|
|
deathSmoke->oForwardVel = random_float() * 10.0f;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/**
|
|
* Spawns an orange number object relatively, such as those that count up for secrets.
|
|
*/
|
|
void spawn_orange_number(s8 behParam, s16 relX, s16 relY, s16 relZ) {
|
|
#ifdef DIALOG_INDICATOR
|
|
if (behParam > ORANGE_NUMBER_F) return;
|
|
#else
|
|
if (behParam > ORANGE_NUMBER_9) return;
|
|
#endif
|
|
|
|
struct Object *orangeNumber = spawn_object_relative(behParam, relX, relY, relZ, o, MODEL_NUMBER, bhvOrangeNumber);
|
|
orangeNumber->oPosY += 25.0f;
|
|
}
|
|
|
|
/**
|
|
* Unused variables for debug_sequence_tracker.
|
|
*/
|
|
s8 sDebugSequenceTracker = 0;
|
|
s8 sDebugTimer = 0;
|
|
|
|
/**
|
|
* Unused presumably debug function that tracks for a sequence of inputs.
|
|
*/
|
|
UNUSED s32 debug_sequence_tracker(s16 debugInputSequence[]) {
|
|
// If end of sequence reached, return true.
|
|
if (debugInputSequence[sDebugSequenceTracker] == 0) {
|
|
sDebugSequenceTracker = 0;
|
|
return TRUE;
|
|
}
|
|
|
|
// If the third controller button pressed is next in sequence, reset timer and progress to next value.
|
|
if (debugInputSequence[sDebugSequenceTracker] & gPlayer3Controller->buttonPressed) {
|
|
sDebugSequenceTracker++;
|
|
sDebugTimer = 0;
|
|
// If wrong input or timer reaches 10, reset sequence progress.
|
|
} else if (sDebugTimer == 10 || gPlayer3Controller->buttonPressed != 0) {
|
|
sDebugSequenceTracker = 0;
|
|
sDebugTimer = 0;
|
|
return FALSE;
|
|
}
|
|
sDebugTimer++;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
#include "behaviors/moving_coin.inc.c"
|
|
#include "behaviors/seaweed.inc.c"
|
|
#include "behaviors/bobomb.inc.c"
|
|
#include "behaviors/cannon_door.inc.c"
|
|
#include "behaviors/whirlpool.inc.c"
|
|
#include "behaviors/amp.inc.c"
|
|
#include "behaviors/butterfly.inc.c"
|
|
#include "behaviors/hoot.inc.c"
|
|
#include "behaviors/beta_holdable_object.inc.c"
|
|
#include "behaviors/bubble.inc.c"
|
|
#include "behaviors/water_wave.inc.c"
|
|
#include "behaviors/explosion.inc.c"
|
|
#include "behaviors/respawner.inc.c"
|
|
#include "behaviors/bully.inc.c"
|
|
#include "behaviors/water_ring.inc.c"
|
|
#include "behaviors/bowser_bomb.inc.c"
|
|
#include "behaviors/celebration_star.inc.c"
|
|
#include "behaviors/drawbridge.inc.c"
|
|
#include "behaviors/bomp.inc.c"
|
|
#include "behaviors/sliding_platform.inc.c"
|
|
#include "behaviors/moneybag.inc.c"
|
|
#include "behaviors/bowling_ball.inc.c"
|
|
#include "behaviors/cruiser.inc.c"
|
|
#include "behaviors/spindel.inc.c"
|
|
#include "behaviors/pyramid_wall.inc.c"
|
|
#include "behaviors/pyramid_elevator.inc.c"
|
|
#include "behaviors/pyramid_top.inc.c"
|
|
#include "behaviors/sound_waterfall.inc.c"
|
|
#include "behaviors/sound_volcano.inc.c"
|
|
#include "behaviors/castle_flag.inc.c"
|
|
#include "behaviors/sound_birds.inc.c"
|
|
#include "behaviors/sound_ambient.inc.c"
|
|
#include "behaviors/sound_sand.inc.c"
|
|
#include "behaviors/castle_cannon_grate.inc.c"
|
|
#include "behaviors/snowman.inc.c"
|
|
#include "behaviors/boulder.inc.c"
|
|
#include "behaviors/cap.inc.c"
|
|
#include "behaviors/koopa_shell.inc.c"
|
|
#include "behaviors/spawn_star.inc.c"
|
|
#include "behaviors/red_coin.inc.c"
|
|
#include "behaviors/hidden_star.inc.c"
|
|
#include "behaviors/rolling_log.inc.c"
|
|
#include "behaviors/mushroom_1up.inc.c"
|
|
#include "behaviors/controllable_platform.inc.c"
|
|
#include "behaviors/breakable_box_small.inc.c"
|
|
#include "behaviors/snow_mound.inc.c"
|
|
#include "behaviors/floating_platform.inc.c"
|
|
#include "behaviors/arrow_lift.inc.c"
|
|
#include "behaviors/orange_number.inc.c"
|
|
#include "behaviors/manta_ray.inc.c"
|
|
#include "behaviors/falling_pillar.inc.c"
|
|
#include "behaviors/floating_box.inc.c"
|
|
#include "behaviors/decorative_pendulum.inc.c"
|
|
#include "behaviors/treasure_chest.inc.c"
|
|
#include "behaviors/mips.inc.c"
|
|
#include "behaviors/yoshi.inc.c"
|