diff --git a/src/game/area.c b/src/game/area.c index eb3c92bed..ef5375d87 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -172,6 +172,21 @@ struct ObjectWarpNode *area_get_warp_node(u8 id) { return node; } +struct ObjectWarpNode *area_get_any_warp_node(void) { + if (!gCurrentArea || !gCurrentArea->warpNodes) { return NULL; } + + struct ObjectWarpNode *node = NULL; + struct ObjectWarpNode *pick = NULL; + + for (node = gCurrentArea->warpNodes; node != NULL; node = node->next) { + if (node->node.destLevel != gCurrLevelNum) { continue; } + if (!pick) { pick = node; continue; } + if (node->node.destArea < pick->node.destArea) { pick = node; } + } + + return pick; +} + struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o) { if (o == NULL) { return NULL; } diff --git a/src/game/area.h b/src/game/area.h index 1b855a8e8..f1a607ca7 100644 --- a/src/game/area.h +++ b/src/game/area.h @@ -157,6 +157,7 @@ void override_viewport_and_clip(Vp *a, Vp *b, u8 c, u8 d, u8 e); void print_intro_text(void); u32 get_mario_spawn_type(struct Object *o); struct ObjectWarpNode *area_get_warp_node(u8 id); +struct ObjectWarpNode *area_get_any_warp_node(void); struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *o); void clear_areas(void); void clear_area_graph_nodes(void); diff --git a/src/game/level_update.c b/src/game/level_update.c index c9ef14596..fed7b1378 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -405,7 +405,9 @@ void init_mario_after_warp(void) { struct ObjectWarpNode *spawnNode = area_get_warp_node(sWarpDest.nodeId); if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_warp_node(0xFA); } if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_warp_node(0x00); } + if (spawnNode == NULL || spawnNode->object == NULL) { spawnNode = area_get_any_warp_node(); } if (spawnNode == NULL || spawnNode->object == NULL) { return; } + u32 marioSpawnType = get_mario_spawn_type(spawnNode->object); if (gMarioState && gMarioState->action != ACT_UNINITIALIZED) { diff --git a/src/game/paintings.c b/src/game/paintings.c index eb6a187bd..5a32782d2 100644 --- a/src/game/paintings.c +++ b/src/game/paintings.c @@ -1782,7 +1782,7 @@ Gfx *geo_painting_draw(s32 callContext, struct GraphNode *node, UNUSED void *con * Update the painting system's local copy of Mario's current floor and position. */ Gfx *geo_painting_update(s32 callContext, UNUSED struct GraphNode *node, UNUSED Mat4 c) { - struct Surface *surface; + struct Surface *surface = NULL; // Reset the update counter if (callContext != GEO_CONTEXT_RENDER) { @@ -1793,13 +1793,15 @@ Gfx *geo_painting_update(s32 callContext, UNUSED struct GraphNode *node, UNUSED gPaintingUpdateCounter = gAreaUpdateCounter; // Store Mario's floor and position - find_floor(gMarioObject->oPosX, gMarioObject->oPosY, gMarioObject->oPosZ, &surface); - if (surface != NULL) { - gPaintingMarioFloorType = surface->type; + if (gMarioObject) { + find_floor(gMarioObject->oPosX, gMarioObject->oPosY, gMarioObject->oPosZ, &surface); + if (surface != NULL) { + gPaintingMarioFloorType = surface->type; + } + gPaintingMarioXPos = gMarioObject->oPosX; + gPaintingMarioYPos = gMarioObject->oPosY; + gPaintingMarioZPos = gMarioObject->oPosZ; } - gPaintingMarioXPos = gMarioObject->oPosX; - gPaintingMarioYPos = gMarioObject->oPosY; - gPaintingMarioZPos = gMarioObject->oPosZ; } return NULL; }