Skip to content

Commit

Permalink
Attempt to fix a bug where spawned planes flying off the map would cr…
Browse files Browse the repository at this point in the history
…ash the game
  • Loading branch information
ZivDero committed Feb 22, 2025
1 parent 8be8882 commit 7edde80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/new/spawnmanager/spawnmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#include "vinifera_saveload.h"


bool SpawnManagerClass::IsLandingSpawnee = false;


/**
* Retrieves the class identifier (CLSID) of the object.
*
Expand Down Expand Up @@ -193,7 +196,9 @@ SpawnManagerClass::SpawnManagerClass(TechnoClass* owner, const AircraftTypeClass
if (spawnee != nullptr)
{
control->IsSpawnedMissile = RocketTypeClass::From_AircraftType(SpawnType) != nullptr;
IsLandingSpawnee = true;
control->Spawnee->Limbo();
IsLandingSpawnee = false;
Extension::Fetch<AircraftClassExtension>(control->Spawnee)->SpawnOwner = Owner;
control->Status = SpawnControlStatus::Idle;
control->ReloadTimer = 0;
Expand Down Expand Up @@ -535,7 +540,9 @@ void SpawnManagerClass::AI()

if (owner_coord == spawnee_coord && std::abs(spawnee->Coord.Z - Owner->Coord.Z) < 20)
{
IsLandingSpawnee = true;
spawnee->Limbo();
IsLandingSpawnee = false;
control->Status = SpawnControlStatus::Reloading;
control->ReloadTimer = ReloadRate;
}
Expand Down Expand Up @@ -585,7 +592,9 @@ void SpawnManagerClass::AI()
*/
control->Spawnee = static_cast<AircraftClass*>(SpawnType->Create_One_Of(Owner->Owning_House()));
control->IsSpawnedMissile = RocketTypeClass::From_AircraftType(SpawnType) != nullptr;
IsLandingSpawnee = true;
control->Spawnee->Limbo();
IsLandingSpawnee = false;
Extension::Fetch<AircraftClassExtension>(control->Spawnee)->SpawnOwner = Owner;
control->Status = SpawnControlStatus::Idle;
break;
Expand Down Expand Up @@ -872,7 +881,7 @@ void SpawnManagerClass::Detach(TARGET target)
const auto control = SpawnControls[i];
if (control->Spawnee == target)
{
if (control->Spawnee->Strength <= 0 || control->Spawnee->IsKamikaze || control->IsSpawnedMissile)
if (!IsLandingSpawnee || control->Spawnee->IsKamikaze || control->IsSpawnedMissile)
{
control->Spawnee = nullptr;
control->Status = SpawnControlStatus::Dead;
Expand Down
8 changes: 8 additions & 0 deletions src/new/spawnmanager/spawnmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,12 @@ class DECLSPEC_UUID(UUID_SPAWN_MANAGER)
* The current status of the spawn manager.
*/
SpawnManagerStatus Status;

private:
/**
* Is some spawner currently landing a spawnee?
* If so, we shouldn't detach it from the spawner when we are asked to.
*/
static bool IsLandingSpawnee;

};

0 comments on commit 7edde80

Please sign in to comment.