Skip to content

Commit

Permalink
Fix OpenTopped state of passengers not being updated on type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku committed Oct 28, 2023
1 parent 07ec3a9 commit a5b0edd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho

## Fixes / interactions with other extensions

- All forms of type conversion (including Ares') now correctly update `OpenTopped` state of passengers in transport that is converted.
- Fixed an issue introduced by Ares that caused `Grinding=true` building `ActiveAnim` to be incorrectly restored while `SpecialAnim` was playing and the building was sold, erased or destroyed.

## Aircraft
Expand Down
2 changes: 1 addition & 1 deletion docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ Phobos fixes:
- Fixed game crashing on loading save games if the saved game state had active radiation sites (by Starkku)
Fixes / interactions with other extensions:
- All forms of type conversion (including Ares') now correctly update `OpenTopped` state of passengers in transport that is converted (by Starkku)
- Fixed an issue introduced by Ares that caused `Grinding=true` building `ActiveAnim` to be incorrectly restored while `SpecialAnim` was playing and the building was sold, erased or destroyed (by Starkku)
</details>
Expand Down Expand Up @@ -623,7 +624,6 @@ Phobos fixes:
- Fixed techno-extdata update after type conversion (by Trsdy)
- Fixed Phobos Warhead effects (crits, new shield modifiers etc.) considering sinking units valid targets (by Starkku)
- Fixed an issue where `FireOnce=yes` deploy weapons on vehicles would still fire multiple times if deploy command is issued repeatedly or when not idle (by Starkku)
- Fixed techno-extdata update after type conversion (by Trsdy)
- Fixed a game crash when checking BuildLimit if Phobos is running without Ares (by Belonit)
- Corrected the misinterpretation in the definition of `DiskLaser.Radius` (by Trsdy)
Expand Down
42 changes: 36 additions & 6 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,16 @@ void TechnoExt::ExtData::ApplySpawnLimitRange()
}
}

void TechnoExt::ExtData::UpdateTypeData(TechnoTypeClass* currentType)
void TechnoExt::ExtData::UpdateTypeData(TechnoTypeClass* pCurrentType)
{
auto const pThis = this->OwnerObject();
auto const oldType = this->TypeExtData;
auto const pOldTypeExt = this->TypeExtData;
auto const pOldType = this->TypeExtData->OwnerObject();

if (this->LaserTrails.size())
this->LaserTrails.clear();

this->TypeExtData = TechnoTypeExt::ExtMap.Find(currentType);
this->TypeExtData = TechnoTypeExt::ExtMap.Find(pCurrentType);

// Recreate Laser Trails
for (auto const& entry : this->TypeExtData->LaserTrailData)
Expand All @@ -410,21 +411,50 @@ void TechnoExt::ExtData::UpdateTypeData(TechnoTypeClass* currentType)
this->PassengerDeletionTimer.Stop();

// Remove from tracked AutoDeath objects if no longer has AutoDeath
if (oldType->AutoDeath_Behavior.isset() && !this->TypeExtData->AutoDeath_Behavior.isset())
if (pOldTypeExt->AutoDeath_Behavior.isset() && !this->TypeExtData->AutoDeath_Behavior.isset())
{
auto& vec = HouseExt::ExtMap.Find(pThis->Owner)->OwnedAutoDeathObjects;
vec.erase(std::remove(vec.begin(), vec.end(), this), vec.end());
}

auto const rtti = oldType->OwnerObject()->WhatAmI();
auto const rtti = pOldType->WhatAmI();

// Remove from limbo reloaders if no longer applicable
if (rtti != AbstractType::AircraftType && rtti != AbstractType::BuildingType
&& oldType->OwnerObject()->Ammo > 0 && oldType->ReloadInTransport && !this->TypeExtData->ReloadInTransport)
&& pOldType->Ammo > 0 && pOldTypeExt->ReloadInTransport && !this->TypeExtData->ReloadInTransport)
{
auto& vec = HouseExt::ExtMap.Find(pThis->Owner)->OwnedTransportReloaders;
vec.erase(std::remove(vec.begin(), vec.end(), this), vec.end());
}

// Update open topped state of potential passengers if transport's OpenTopped value changes.
bool toOpenTopped = pCurrentType->OpenTopped && !pOldType->OpenTopped;

if ((toOpenTopped || (!pCurrentType->OpenTopped && pOldType->OpenTopped)) && pThis->Passengers.NumPassengers > 0)
{
auto pPassenger = pThis->Passengers.FirstPassenger;

while (pPassenger)
{
if (toOpenTopped)
{
pThis->EnteredOpenTopped(pPassenger);
}
else
{
pThis->ExitedOpenTopped(pPassenger);

// Lose target & destination
pPassenger->Guard();

// OpenTopped adds passengers to logic layer when enabled. Under normal conditions this does not need to be removed since
// OpenTopped state does not change while passengers are still in transport but in case of type conversion that can happen.
MapClass::Logics.get().RemoveObject(pPassenger);
}

pPassenger = abstract_cast<FootClass*>(pPassenger->NextObject);
}
}
}

void TechnoExt::ExtData::UpdateLaserTrails()
Expand Down

0 comments on commit a5b0edd

Please sign in to comment.