Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Ext/Techno/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@

if (AresFunctions::ConvertTypeTo)
{
const int oldHealth = pThis->Health;

Check warning on line 328 in src/Ext/Techno/Body.cpp

View workflow job for this annotation

GitHub Actions / build

'oldHealth': local variable is initialized but not referenced [D:\a\Phobos\Phobos\Phobos.vcxproj]

if (AresFunctions::ConvertTypeTo(pThis, pToType))
{
// Fixed an issue where morphing could result in -1 health.
const double ratio = static_cast<double>(pToType->Strength) / pType->Strength;
pThis->Health = static_cast<int>(oldHealth * ratio + 0.5);

auto const pTypeExt = TechnoExt::ExtMap.Find(pThis);
pTypeExt->UpdateTypeData(pToType);
pTypeExt->UpdateTypeData_Foot();
Expand Down Expand Up @@ -833,7 +829,7 @@
const bool isLander = pType->DeployToLand && (isJumpjet || isHover);
disallowedLandTypes = isLander ? (LandTypeFlags)(LandTypeFlags::Water | LandTypeFlags::Beach) : LandTypeFlags::None;
}

if (IsLandTypeInFlags(disallowedLandTypes, pThis->GetCell()->LandType))
return false;

Expand Down
40 changes: 40 additions & 0 deletions src/Misc/Hooks.BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,7 @@
GET(AbstractType, rtti, EAX);

if (CanBeSold(pTechno, rtti))
pTechno->Sell(-1);

Check warning on line 3000 in src/Misc/Hooks.BugFixes.cpp

View workflow job for this annotation

GitHub Actions / build

'argument': conversion from 'int' to 'DWORD', signed/unsigned mismatch [D:\a\Phobos\Phobos\Phobos.vcxproj]

return SkipGameCode;
}
Expand Down Expand Up @@ -3089,3 +3089,43 @@
R->AL(garrisonable && (isFullMap || pThis->MegaMissionIsAttackMove())); // Attack move is allowed because it can switch to Mission::Attack
return 0;
}

#pragma region SetHealthPercentageFix

DEFINE_HOOK(0x5F5C80, ObjectClass_SetHealthPercentage_Round, 0xA)
{
enum { SkipGameCode = 0x5F5CBA };

GET(ObjectClass* const, pThis, ECX);
GET_STACK(const double, percentage, STACK_OFFSET(0x0, 0x4));

pThis->Health = (percentage <= 0.0) ? 0 : Math::max(1, Game::F2I(pThis->GetType()->Strength * percentage + 0.5));

return SkipGameCode;
}

DEFINE_HOOK(0x44A010, BuildingClass_Mission_Selling_SetUnitHealthPercentage, 0xA)
{
enum { SkipGameCode = 0x44A03C };

GET(UnitClass* const, pUnit, EBX);
GET_STACK(const double, percentage, STACK_OFFSET(0xD0, -0xAC));

pUnit->SetHealthPercentage(percentage);
pUnit->EstimatedHealth = pUnit->Health;
return SkipGameCode;
}

DEFINE_HOOK(0x73992B, UnitClass_TryToDeploy_SetBuildingHealthPercentage, 0x7)
{
enum { SkipGameCode = 0x739956 };

GET(const UnitClass* const, pThis, EBP);
GET(BuildingClass* const, pBuilding, EBX);

pBuilding->SetHealthPercentage(pThis->GetHealthPercentage());
pBuilding->EstimatedHealth = pBuilding->Health;
return SkipGameCode;
}

#pragma endregion