Add obj_behaviors to the Lua API

This commit is contained in:
MysterD 2022-02-22 22:39:45 -08:00
parent e499f51767
commit 816df2117f
5 changed files with 2955 additions and 45 deletions

View File

@ -37,6 +37,8 @@ in_files = [
"include/behavior_table.h",
"src/pc/lua/smlua_obj_utils.h",
"src/game/object_helpers.c",
"src/game/obj_behaviors.c",
"src/game/obj_behaviors_2.c",
]
override_allowed_functions = {
@ -65,6 +67,8 @@ override_disallowed_functions = {
"src/pc/network/network_utils.h": [ "network_get_player_text_color[^_]" ],
"src/pc/network/network_player.h": [ "_init", "_connected[^_]", "_shutdown", "_disconnected", "_update" ],
"src/game/object_helpers.c": [ "spawn_obj" ],
"src/game/obj_behaviors.c": [ "debug_" ],
"src/game/obj_behaviors_2.c": [ "wiggler_jumped_on_attack_handler", "huge_goomba_weakly_attacked" ],
}
###########################################################

File diff suppressed because it is too large Load Diff

View File

@ -80,7 +80,7 @@ f32 sObjSavedPosZ;
void wiggler_jumped_on_attack_handler(void);
void huge_goomba_weakly_attacked(void);
static s32 obj_is_rendering_enabled(void) {
s32 obj_is_rendering_enabled(void) {
if (o->header.gfx.node.flags & GRAPH_RENDER_ACTIVE) {
return TRUE;
} else {
@ -88,7 +88,7 @@ static s32 obj_is_rendering_enabled(void) {
}
}
static s16 obj_get_pitch_from_vel(void) {
s16 obj_get_pitch_from_vel(void) {
return -atan2s(o->oForwardVel, o->oVelY);
}
@ -110,12 +110,12 @@ static s32 obj_update_race_proposition_dialog(struct MarioState* m, s16 dialogID
return dialogResponse;
}
static void obj_set_dist_from_home(f32 distFromHome) {
void obj_set_dist_from_home(f32 distFromHome) {
o->oPosX = o->oHomeX + distFromHome * coss(o->oMoveAngleYaw);
o->oPosZ = o->oHomeZ + distFromHome * sins(o->oMoveAngleYaw);
}
static s32 obj_is_near_to_and_facing_mario(struct MarioState* m, f32 maxDist, s16 maxAngleDiff) {
s32 obj_is_near_to_and_facing_mario(struct MarioState* m, f32 maxDist, s16 maxAngleDiff) {
struct Object* player = m->marioObj;
int distanceToPlayer = dist_between_objects(o, player);
int angleToPlayer = obj_angle_to_object(o, player);
@ -150,7 +150,7 @@ static BAD_RETURN(u32) obj_perform_position_op(s32 op) {
}
}
static void platform_on_track_update_pos_or_spawn_ball(s32 ballIndex, f32 x, f32 y, f32 z) {
void platform_on_track_update_pos_or_spawn_ball(s32 ballIndex, f32 x, f32 y, f32 z) {
struct Object *trackBall;
struct Waypoint *initialPrevWaypoint;
struct Waypoint *nextWaypoint;
@ -246,7 +246,7 @@ static void platform_on_track_update_pos_or_spawn_ball(s32 ballIndex, f32 x, f32
}
}
static void cur_obj_spin_all_dimensions(f32 arg0, f32 arg1) {
void cur_obj_spin_all_dimensions(f32 arg0, f32 arg1) {
f32 val24;
f32 val20;
f32 val1C;
@ -301,18 +301,18 @@ static void cur_obj_spin_all_dimensions(f32 arg0, f32 arg1) {
}
}
static void obj_rotate_yaw_and_bounce_off_walls(s16 targetYaw, s16 turnAmount) {
void obj_rotate_yaw_and_bounce_off_walls(s16 targetYaw, s16 turnAmount) {
if (o->oMoveFlags & OBJ_MOVE_HIT_WALL) {
targetYaw = cur_obj_reflect_move_angle_off_wall();
}
cur_obj_rotate_yaw_toward(targetYaw, turnAmount);
}
static s16 obj_get_pitch_to_home(f32 latDistToHome) {
s16 obj_get_pitch_to_home(f32 latDistToHome) {
return atan2s(latDistToHome, o->oPosY - o->oHomeY);
}
static void obj_compute_vel_from_move_pitch(f32 speed) {
void obj_compute_vel_from_move_pitch(f32 speed) {
o->oForwardVel = speed * coss(o->oMoveAnglePitch);
o->oVelY = speed * -sins(o->oMoveAnglePitch);
}
@ -341,22 +341,22 @@ static s32 clamp_f32(f32 *value, f32 minimum, f32 maximum) {
return TRUE;
}
static void cur_obj_init_anim_extend(s32 arg0) {
void cur_obj_init_anim_extend(s32 arg0) {
cur_obj_init_animation_with_sound(arg0);
cur_obj_extend_animation_if_at_end();
}
static s32 cur_obj_init_anim_and_check_if_end(s32 arg0) {
s32 cur_obj_init_anim_and_check_if_end(s32 arg0) {
cur_obj_init_animation_with_sound(arg0);
return cur_obj_check_if_near_animation_end();
}
static s32 cur_obj_init_anim_check_frame(s32 arg0, s32 arg1) {
s32 cur_obj_init_anim_check_frame(s32 arg0, s32 arg1) {
cur_obj_init_animation_with_sound(arg0);
return cur_obj_check_anim_frame(arg1);
}
static s32 cur_obj_set_anim_if_at_end(s32 arg0) {
s32 cur_obj_set_anim_if_at_end(s32 arg0) {
if (cur_obj_check_if_at_animation_end()) {
cur_obj_init_animation_with_sound(arg0);
return TRUE;
@ -364,7 +364,7 @@ static s32 cur_obj_set_anim_if_at_end(s32 arg0) {
return FALSE;
}
static s32 cur_obj_play_sound_at_anim_range(s8 arg0, s8 arg1, u32 sound) {
s32 cur_obj_play_sound_at_anim_range(s8 arg0, s8 arg1, u32 sound) {
s32 val04;
if ((val04 = o->header.gfx.animInfo.animAccel / 0x10000) <= 0) {
@ -379,7 +379,7 @@ static s32 cur_obj_play_sound_at_anim_range(s8 arg0, s8 arg1, u32 sound) {
return FALSE;
}
static s16 obj_turn_pitch_toward_mario(struct MarioState* m, f32 targetOffsetY, s16 turnAmount) {
s16 obj_turn_pitch_toward_mario(struct MarioState* m, f32 targetOffsetY, s16 turnAmount) {
s16 targetPitch;
o->oPosY -= targetOffsetY;
@ -389,7 +389,7 @@ static s16 obj_turn_pitch_toward_mario(struct MarioState* m, f32 targetOffsetY,
return targetPitch;
}
static s32 approach_f32_ptr(f32 *px, f32 target, f32 delta) {
s32 approach_f32_ptr(f32 *px, f32 target, f32 delta) {
if (*px > target) {
delta = -delta;
}
@ -403,15 +403,15 @@ static s32 approach_f32_ptr(f32 *px, f32 target, f32 delta) {
return FALSE;
}
static s32 obj_forward_vel_approach(f32 target, f32 delta) {
s32 obj_forward_vel_approach(f32 target, f32 delta) {
return approach_f32_ptr(&o->oForwardVel, target, delta);
}
static s32 obj_y_vel_approach(f32 target, f32 delta) {
s32 obj_y_vel_approach(f32 target, f32 delta) {
return approach_f32_ptr(&o->oVelY, target, delta);
}
static s32 obj_move_pitch_approach(s16 target, s16 delta) {
s32 obj_move_pitch_approach(s16 target, s16 delta) {
o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, target, delta);
if ((s16) o->oMoveAnglePitch == target) {
@ -421,7 +421,7 @@ static s32 obj_move_pitch_approach(s16 target, s16 delta) {
return FALSE;
}
static s32 obj_face_pitch_approach(s16 targetPitch, s16 deltaPitch) {
s32 obj_face_pitch_approach(s16 targetPitch, s16 deltaPitch) {
o->oFaceAnglePitch = approach_s16_symmetric(o->oFaceAnglePitch, targetPitch, deltaPitch);
if ((s16) o->oFaceAnglePitch == targetPitch) {
@ -431,7 +431,7 @@ static s32 obj_face_pitch_approach(s16 targetPitch, s16 deltaPitch) {
return FALSE;
}
static s32 obj_face_yaw_approach(s16 targetYaw, s16 deltaYaw) {
s32 obj_face_yaw_approach(s16 targetYaw, s16 deltaYaw) {
o->oFaceAngleYaw = approach_s16_symmetric(o->oFaceAngleYaw, targetYaw, deltaYaw);
if ((s16) o->oFaceAngleYaw == targetYaw) {
@ -441,7 +441,7 @@ static s32 obj_face_yaw_approach(s16 targetYaw, s16 deltaYaw) {
return FALSE;
}
static s32 obj_face_roll_approach(s16 targetRoll, s16 deltaRoll) {
s32 obj_face_roll_approach(s16 targetRoll, s16 deltaRoll) {
o->oFaceAngleRoll = approach_s16_symmetric(o->oFaceAngleRoll, targetRoll, deltaRoll);
if ((s16) o->oFaceAngleRoll == targetRoll) {
@ -451,7 +451,7 @@ static s32 obj_face_roll_approach(s16 targetRoll, s16 deltaRoll) {
return FALSE;
}
static s32 obj_smooth_turn(s16 *angleVel, s32 *angle, s16 targetAngle, f32 targetSpeedProportion,
s32 obj_smooth_turn(s16 *angleVel, s32 *angle, s16 targetAngle, f32 targetSpeedProportion,
s16 accel, s16 minSpeed, s16 maxSpeed) {
s16 currentSpeed;
s16 currentAngle = (s16)(*angle);
@ -466,21 +466,21 @@ static s32 obj_smooth_turn(s16 *angleVel, s32 *angle, s16 targetAngle, f32 targe
return (s16)(*angle) == targetAngle;
}
static void obj_roll_to_match_yaw_turn(s16 targetYaw, s16 maxRoll, s16 rollSpeed) {
void obj_roll_to_match_yaw_turn(s16 targetYaw, s16 maxRoll, s16 rollSpeed) {
s16 targetRoll = o->oMoveAngleYaw - targetYaw;
clamp_s16(&targetRoll, -maxRoll, maxRoll);
obj_face_roll_approach(targetRoll, rollSpeed);
}
static s16 random_linear_offset(s16 base, s16 range) {
s16 random_linear_offset(s16 base, s16 range) {
return base + (s16)(range * random_float());
}
static s16 random_mod_offset(s16 base, s16 step, s16 mod) {
s16 random_mod_offset(s16 base, s16 step, s16 mod) {
return base + step * (random_u16() % mod);
}
static s16 obj_random_fixed_turn(s16 delta) {
s16 obj_random_fixed_turn(s16 delta) {
return o->oMoveAngleYaw + (s16) random_sign() * delta;
}
@ -491,7 +491,7 @@ static s16 obj_random_fixed_turn(s16 delta) {
* shootFireScale during this time, return 1.
* Return -1 once it's reached endScale.
*/
static s32 obj_grow_then_shrink(f32 *scaleVel, f32 shootFireScale, f32 endScale) {
s32 obj_grow_then_shrink(f32 *scaleVel, f32 shootFireScale, f32 endScale) {
if (o->oTimer < 2) {
o->header.gfx.scale[0] += *scaleVel;
@ -510,7 +510,7 @@ static s32 obj_grow_then_shrink(f32 *scaleVel, f32 shootFireScale, f32 endScale)
return 0;
}
static s32 oscillate_toward(s32 *value, f32 *vel, s32 target, f32 velCloseToZero, f32 accel,
s32 oscillate_toward(s32 *value, f32 *vel, s32 target, f32 velCloseToZero, f32 accel,
f32 slowdown) {
if (value == NULL || vel == NULL) { return FALSE; }
s32 startValue = *value;
@ -536,7 +536,7 @@ static s32 oscillate_toward(s32 *value, f32 *vel, s32 target, f32 velCloseToZero
return FALSE;
}
static void obj_update_blinking(s32 *blinkTimer, s16 baseCycleLength, s16 cycleLengthRange,
void obj_update_blinking(s32 *blinkTimer, s16 baseCycleLength, s16 cycleLengthRange,
s16 blinkLength) {
if (*blinkTimer != 0) {
*blinkTimer -= 1;
@ -551,7 +551,7 @@ static void obj_update_blinking(s32 *blinkTimer, s16 baseCycleLength, s16 cycleL
}
}
static s32 obj_resolve_object_collisions(s32 *targetYaw) {
s32 obj_resolve_object_collisions(s32 *targetYaw) {
struct Object *otherObject;
f32 dx;
f32 dz;
@ -597,7 +597,7 @@ static s32 obj_resolve_object_collisions(s32 *targetYaw) {
return FALSE;
}
static s32 obj_bounce_off_walls_edges_objects(s32 *targetYaw) {
s32 obj_bounce_off_walls_edges_objects(s32 *targetYaw) {
if (o->oMoveFlags & OBJ_MOVE_HIT_WALL) {
*targetYaw = cur_obj_reflect_move_angle_off_wall();
} else if (o->oMoveFlags & OBJ_MOVE_HIT_EDGE) {
@ -609,7 +609,7 @@ static s32 obj_bounce_off_walls_edges_objects(s32 *targetYaw) {
return TRUE;
}
static s32 obj_resolve_collisions_and_turn(s16 targetYaw, s16 turnSpeed) {
s32 obj_resolve_collisions_and_turn(s16 targetYaw, s16 turnSpeed) {
obj_resolve_object_collisions(NULL);
if (cur_obj_rotate_yaw_toward(targetYaw, turnSpeed)) {
@ -619,7 +619,7 @@ static s32 obj_resolve_collisions_and_turn(s16 targetYaw, s16 turnSpeed) {
}
}
static void obj_die_if_health_non_positive(void) {
void obj_die_if_health_non_positive(void) {
if (o->oHealth <= 0) {
if (o->oDeathSound == 0) {
spawn_mist_particles_with_sound(SOUND_OBJ_DEFAULT_DEATH);
@ -646,12 +646,12 @@ static void obj_die_if_health_non_positive(void) {
}
}
static void obj_unused_die(void) {
void obj_unused_die(void) {
o->oHealth = 0;
obj_die_if_health_non_positive();
}
static void obj_set_knockback_action(s32 attackType) {
void obj_set_knockback_action(s32 attackType) {
switch (attackType) {
case ATTACK_KICK_OR_TRIP:
case ATTACK_FAST_ATTACK:
@ -673,12 +673,12 @@ static void obj_set_knockback_action(s32 attackType) {
o->oMoveAngleYaw = obj_angle_to_object(player, o);
}
static void obj_set_squished_action(void) {
void obj_set_squished_action(void) {
cur_obj_play_sound_2(SOUND_OBJ_STOMPED);
o->oAction = OBJ_ACT_SQUISHED;
}
static s32 obj_die_if_above_lava_and_health_non_positive(void) {
s32 obj_die_if_above_lava_and_health_non_positive(void) {
if (o->oMoveFlags & OBJ_MOVE_UNDERWATER_ON_GROUND) {
if (o->oGravity + o->oBuoyancy > 0.0f
|| find_water_level(o->oPosX, o->oPosZ) - o->oPosY < 150.0f) {
@ -699,7 +699,7 @@ static s32 obj_die_if_above_lava_and_health_non_positive(void) {
return TRUE;
}
static s32 obj_handle_attacks(struct ObjectHitbox *hitbox, s32 attackedMarioAction,
s32 obj_handle_attacks(struct ObjectHitbox *hitbox, s32 attackedMarioAction,
u8 *attackHandlers) {
s32 attackType;
@ -764,7 +764,7 @@ static s32 obj_handle_attacks(struct ObjectHitbox *hitbox, s32 attackedMarioActi
return 0;
}
static void obj_act_knockback(UNUSED f32 baseScale) {
void obj_act_knockback(UNUSED f32 baseScale) {
cur_obj_update_floor_and_walls();
if (o->header.gfx.animInfo.curAnim != NULL) {
@ -781,7 +781,7 @@ static void obj_act_knockback(UNUSED f32 baseScale) {
cur_obj_move_standard(-78);
}
static void obj_act_squished(f32 baseScale) {
void obj_act_squished(f32 baseScale) {
f32 targetScaleY = baseScale * 0.3f;
cur_obj_update_floor_and_walls();
@ -802,7 +802,7 @@ static void obj_act_squished(f32 baseScale) {
cur_obj_move_standard(-78);
}
static s32 obj_update_standard_actions(f32 scale) {
s32 obj_update_standard_actions(f32 scale) {
if (o->oAction < 100) {
return TRUE;
} else {
@ -823,7 +823,7 @@ static s32 obj_update_standard_actions(f32 scale) {
}
}
static s32 obj_check_attacks(struct ObjectHitbox *hitbox, s32 attackedMarioAction) {
s32 obj_check_attacks(struct ObjectHitbox *hitbox, s32 attackedMarioAction) {
s32 attackType;
obj_set_hitbox(o, hitbox);
@ -849,7 +849,7 @@ static s32 obj_check_attacks(struct ObjectHitbox *hitbox, s32 attackedMarioActio
return 0;
}
static s32 obj_move_for_one_second(s32 endAction) {
s32 obj_move_for_one_second(s32 endAction) {
cur_obj_update_floor_and_walls();
cur_obj_extend_animation_if_at_end();
@ -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, int* distanceToPlayer, int* angleToPlayer) {
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;

File diff suppressed because it is too large Load Diff

View File

@ -34,10 +34,15 @@ struct Object* spawn_object_sync(enum BehaviorId behaviorId, enum ModelExtendedI
}
obj->parentObj = obj;
obj->oPosX = x;
obj->oPosY = y;
obj->oPosZ = z;
obj->oHomeX = x;
obj->oHomeY = y;
obj->oHomeZ = z;
struct SyncObject* so = &gSyncObjects[obj->oSyncID];
so->extendedModelId = modelId;
so->o = obj;