From d29f5c7a64c0563181726af6ee32dbf73247769b Mon Sep 17 00:00:00 2001 From: MegaMech Date: Sat, 16 Nov 2024 16:40:39 -0700 Subject: [PATCH] General Cleanup of vehicles --- src/engine/World.cpp | 5 +++ src/engine/courses/KalimariDesert.cpp | 19 ++++----- src/engine/courses/KalimariDesert.h | 6 +++ src/engine/courses/ToadsTurnpike.cpp | 60 ++++++++++----------------- src/engine/courses/ToadsTurnpike.h | 5 +++ src/racing/skybox_and_splitscreen.c | 1 + 6 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/engine/World.cpp b/src/engine/World.cpp index 5bdc9e05a..c87bb332d 100644 --- a/src/engine/World.cpp +++ b/src/engine/World.cpp @@ -46,6 +46,11 @@ static size_t busses; static size_t tankerTrucks; static size_t cars; static size_t boats; + +/** + * Note that you can only remove the tender if there are no carriages + * @arg waypoint initial waypoint to spawn at. + */ void World::AddTrain(ATrain::TenderStatus tender, size_t numCarriages, f32 speed, uint32_t waypoint) { Vehicles.push_back(std::make_unique(trains, tender, numCarriages, speed, waypoint)); trains++; diff --git a/src/engine/courses/KalimariDesert.cpp b/src/engine/courses/KalimariDesert.cpp index b982dad68..cfb7316e5 100644 --- a/src/engine/courses/KalimariDesert.cpp +++ b/src/engine/courses/KalimariDesert.cpp @@ -12,7 +12,6 @@ #include "engine/vehicles/Utils.h" #include "engine/vehicles/Vehicle.h" -#include "engine/vehicles/Train.h" extern "C" { #include "main.h" @@ -202,31 +201,27 @@ void KalimariDesert::MinimapFinishlinePosition() { void KalimariDesert::SpawnVehicles() { generate_train_waypoints(); - s32 numTrains = 2; - s32 numCars = 5; - ATrain::TenderStatus tender = ATrain::TenderStatus::HAS_TENDER; s32 centerWaypoint = 160; // Spawn two trains - for (size_t i = 0; i < numTrains; ++i) { - uint32_t waypoint = CalculateWaypointDistribution(i, numTrains, gVehicle2DWaypointLength, centerWaypoint); - + for (size_t i = 0; i < _numTrains; ++i) { + uint32_t waypoint = CalculateWaypointDistribution(i, _numTrains, gVehicle2DWaypointLength, centerWaypoint); if (CVarGetInteger("gMultiplayerNoFeatureCuts", 0) == false) { // Multiplayer modes have no tender and no carriages if (gActiveScreenMode != SCREEN_MODE_1P) { - tender = ATrain::TenderStatus::NO_TENDER; - numCars = 0; + _tender = ATrain::TenderStatus::NO_TENDER; + _numCarriages = 0; } // 2 player versus mode has a tender and a carriage if ((gModeSelection == VERSUS) && (gPlayerCountSelection1 == 2)) { - tender = ATrain::TenderStatus::HAS_TENDER; - numCars = 1; + _tender = ATrain::TenderStatus::HAS_TENDER; + _numCarriages = 1; } } - gWorldInstance.AddTrain(tender, numCars, 2.5f, waypoint); + gWorldInstance.AddTrain(_tender, _numCarriages, 2.5f, waypoint); } if (gModeSelection == VERSUS) { diff --git a/src/engine/courses/KalimariDesert.h b/src/engine/courses/KalimariDesert.h index 8c2d9a4d8..c25e9ba22 100644 --- a/src/engine/courses/KalimariDesert.h +++ b/src/engine/courses/KalimariDesert.h @@ -2,6 +2,7 @@ #include #include "Course.h" +#include "engine/vehicles/Train.h" extern "C" { #include "assets/kalimari_desert_vertices.h" @@ -38,4 +39,9 @@ public: virtual void SpawnVehicles() override; virtual void Collision() override; virtual void Destroy() override; + +private: + size_t _numTrains = 2; + size_t _numCarriages = 5; + ATrain::TenderStatus _tender = ATrain::TenderStatus::HAS_TENDER; }; diff --git a/src/engine/courses/ToadsTurnpike.cpp b/src/engine/courses/ToadsTurnpike.cpp index e629b76ef..257b6c990 100644 --- a/src/engine/courses/ToadsTurnpike.cpp +++ b/src/engine/courses/ToadsTurnpike.cpp @@ -218,52 +218,38 @@ void ToadsTurnpike::RenderCredits() { void ToadsTurnpike::Collision() {} void ToadsTurnpike::SpawnVehicles() { + uint32_t waypoint; f32 a = ((gCCSelection * 90.0) / 216.0f) + 4.583333333333333; f32 b = ((gCCSelection * 90.0) / 216.0f) + 2.9166666666666665; a /= 2; // Normally vehicle logic is only ran every 2 frames. This slows the vehicles down to match. b /= 2; - uint32_t waypoint; + // Other game modes spawn seven of each vehicle if (gModeSelection == TIME_TRIALS) { - for (size_t i = 0; i < NUM_TIME_TRIAL_BOX_TRUCKS; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_TIME_TRIAL_BOX_TRUCKS, gWaypointCountByPathIndex[0], 0); - gWorldInstance.AddTruck(a, b, &D_80164550[0][0], waypoint); - } + _numTrucks = 8; + _numBuses = 8; + _numTankerTrucks = 8; + _numCars = 8; + } + + for (size_t i = 0; i < _numTrucks; i++) { + waypoint = CalculateWaypointDistribution(i, _numTrucks, gWaypointCountByPathIndex[0], 0); + gWorldInstance.AddTruck(a, b, &D_80164550[0][0], waypoint); + } - for (size_t i = 0; i < NUM_TIME_TRIAL_SCHOOL_BUSES; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_TIME_TRIAL_SCHOOL_BUSES, gWaypointCountByPathIndex[0], 75); - gWorldInstance.AddBus(a, b, &D_80164550[0][0], waypoint); - } + for (size_t i = 0; i < _numBuses; i++) { + waypoint = CalculateWaypointDistribution(i, _numBuses, gWaypointCountByPathIndex[0], 75); + gWorldInstance.AddBus(a, b,&D_80164550[0][0], waypoint); + } - for (size_t i = 0; i < NUM_TIME_TRIAL_TANKER_TRUCKS; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_TIME_TRIAL_TANKER_TRUCKS, gWaypointCountByPathIndex[0], 50); - gWorldInstance.AddTankerTruck(a, b, &D_80164550[0][0], waypoint); - } + for (size_t i = 0; i < _numTankerTrucks; i++) { + waypoint = CalculateWaypointDistribution(i, _numTankerTrucks, gWaypointCountByPathIndex[0], 50); + gWorldInstance.AddTankerTruck(a, b, &D_80164550[0][0], waypoint); + } - for (size_t i = 0; i < NUM_TIME_TRIAL_CARS; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_TIME_TRIAL_CARS, gWaypointCountByPathIndex[0], 25); - gWorldInstance.AddCar(a, b, &D_80164550[0][0], waypoint); - } - } else { // All other modes - for (size_t i = 0; i < NUM_RACE_BOX_TRUCKS; i++) { - uint32_t waypoint = CalculateWaypointDistribution(i, NUM_RACE_BOX_TRUCKS, gWaypointCountByPathIndex[0], 0); - gWorldInstance.AddTruck(a, b, &D_80164550[0][0], waypoint); - } - - for (size_t i = 0; i < NUM_RACE_SCHOOL_BUSES; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_RACE_SCHOOL_BUSES, gWaypointCountByPathIndex[0], 75); - gWorldInstance.AddBus(a, b,&D_80164550[0][0], waypoint); - } - - for (size_t i = 0; i < NUM_RACE_TANKER_TRUCKS; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_RACE_TANKER_TRUCKS, gWaypointCountByPathIndex[0], 50); - gWorldInstance.AddTankerTruck(a, b, &D_80164550[0][0], waypoint); - } - - for (size_t i = 0; i < NUM_RACE_CARS; i++) { - waypoint = CalculateWaypointDistribution(i, NUM_RACE_CARS, gWaypointCountByPathIndex[0], 25); - gWorldInstance.AddCar(a, b, &D_80164550[0][0], waypoint); - } + for (size_t i = 0; i < _numCars; i++) { + waypoint = CalculateWaypointDistribution(i, _numCars, gWaypointCountByPathIndex[0], 25); + gWorldInstance.AddCar(a, b, &D_80164550[0][0], waypoint); } if (gModeSelection == VERSUS) { diff --git a/src/engine/courses/ToadsTurnpike.h b/src/engine/courses/ToadsTurnpike.h index 7a097cce3..bbb2df9c3 100644 --- a/src/engine/courses/ToadsTurnpike.h +++ b/src/engine/courses/ToadsTurnpike.h @@ -39,4 +39,9 @@ public: virtual void Collision() override; virtual void SpawnVehicles() override; virtual void Destroy() override; +private: + size_t _numTrucks = 7; + size_t _numBuses = 7; + size_t _numTankerTrucks = 7; + size_t _numCars = 7; }; diff --git a/src/racing/skybox_and_splitscreen.c b/src/racing/skybox_and_splitscreen.c index a3755987f..a5ab4f3bf 100644 --- a/src/racing/skybox_and_splitscreen.c +++ b/src/racing/skybox_and_splitscreen.c @@ -416,6 +416,7 @@ void func_802A487C(Vtx* arg0, UNUSED struct UnkStruct_800DC5EC* arg1, UNUSED s32 } void func_802A4A0C(Vtx* vtx, struct UnkStruct_800DC5EC* arg1, UNUSED s32 arg2, UNUSED s32 arg3, UNUSED f32* arg4) { + //! @todo Confirm if this crash still happens and fix if so s32 id = arg1 - D_8015F480; arg1->camera = &cameras[id]; // bad fix of bowser castle crash where camera get an invalid value Camera* camera = arg1->camera;