Skip to content

Commit

Permalink
complement missing parts in 87be720
Browse files Browse the repository at this point in the history
fix aircraft shadow's flightlevel getter and rotation condition
  • Loading branch information
chaserli committed May 12, 2024
1 parent 7b244db commit bdd2443
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Ext/Aircraft/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ DirType AircraftExt::GetLandingDir(AircraftClass* pThis, BuildingClass* pDock)
return pLink->PrimaryFacing.Current().GetDir();
}

int landingDir = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType())->LandingDir.Get((int)poseDir);
int landingDir = TechnoTypeExt::ExtMap.Find(pThis->Type)->LandingDir.Get((int)poseDir);

if (!pThis->Type->AirportBound && landingDir < 0)
return pThis->PrimaryFacing.Current().GetDir();
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Aircraft/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ DEFINE_HOOK(0x44402E, BuildingClass_ExitObject_PoseDir2, 0x5)
GET(AircraftClass*, pAircraft, EBP);

auto dir = DirStruct(AircraftExt::GetLandingDir(pAircraft, pThis));
pAircraft->PrimaryFacing.SetCurrent(dir);
// pAircraft->PrimaryFacing.SetCurrent(dir);
pAircraft->SecondaryFacing.SetCurrent(dir);

return 0;
Expand Down
32 changes: 20 additions & 12 deletions src/Ext/TechnoType/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ DEFINE_HOOK(0x73C47A, UnitClass_DrawAsVXL_Shadow, 0x5)
{
const float cHeight = (float)uTypeExt->ShadowSizeCharacteristicHeight.Get(RulesClass::Instance->CruiseHeight);

if (cHeight > 0)
if (cHeight > 0 && height > 208)
{
shadow_matrix.Scale((float)std::max(Pade2_2(baseScale_log * height / cHeight), minScale));
shadow_matrix.Scale((float)std::max(Pade2_2(baseScale_log * (height - 208) / cHeight), minScale));
vxl_index_key.Invalidate();
}
}
Expand Down Expand Up @@ -589,27 +589,29 @@ DEFINE_HOOK(0x4147F9, AircraftClass_Draw_Shadow, 0x6)
if (RulesExt::Global()->HeightShadowScaling)
{
const double minScale = RulesExt::Global()->HeightShadowScaling_MinScale;
const float cHeight = (float)aTypeExt->ShadowSizeCharacteristicHeight.Get(flyLoco->FlightLevel);
const float cHeight = (float)aTypeExt->ShadowSizeCharacteristicHeight.Get(pThis->Type->GetFlightLevel());

if (cHeight > 0)
{
shadow_mtx.Scale((float)std::max(Pade2_2(baseScale_log * height / cHeight), minScale));
key.Invalidate(); // I'm sorry
if (flyLoco->FlightLevel > 0 || height > 0)
key.Invalidate();
}
}
else if (pThis->Type->ConsideredAircraft)
{
shadow_mtx.Scale((float)Pade2_2(baseScale_log));
}

if (pThis->IsCrashing)
{
double arf = pThis->AngleRotatedForwards;
if (flyLoco->CurrentSpeed > pThis->Type->PitchSpeed)
arf += pThis->Type->PitchAngle;
shadow_mtx.ScaleY((float)Math::cos(pThis->AngleRotatedSideways));
shadow_mtx.ScaleX((float)Math::cos(arf));
}
double arf = pThis->AngleRotatedForwards;
if (flyLoco->CurrentSpeed > pThis->Type->PitchSpeed)
arf += pThis->Type->PitchAngle;
double ars = pThis->AngleRotatedSideways;
if (key.Is_Valid_Key() && (std::abs(arf) > 0.005 || std::abs(ars) > 0.005))
key.Invalidate();

shadow_mtx.ScaleY((float)Math::cos(ars));
shadow_mtx.ScaleX((float)Math::cos(arf));
}
else if (height > 0)
{
Expand Down Expand Up @@ -659,6 +661,12 @@ DEFINE_HOOK(0x4147F9, AircraftClass_Draw_Shadow, 0x6)

// Shadow_Point of RocketLoco was forgotten to be set to {0,0}. It was an oversight.
DEFINE_JUMP(VTABLE, 0x7F0B4C, 0x4CF940);
/*
//TO TEST AND EXPLAIN: why resetting height when drawing aircrafts?
DEFINE_JUMP(CALL6, 0x4147D5, 0x5F4300);
DEFINE_JUMP(CALL6, 0x4148AB, 0x5F4300);
DEFINE_JUMP(CALL6, 0x4147F3, 0x5F4300);
*/

DEFINE_HOOK(0x7072A1, suka707280_ChooseTheGoddamnMatrix, 0x7)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Ext/Unit/Hooks.Jumpjet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ Matrix3D* __stdcall TeleportLocomotionClass_Draw_Matrix(ILocomotion* iloco, Matr

if (std::abs(ars) >= 0.005 || std::abs(arf) >= 0.005)
{
if (pIndex)// just forget it bro, no one cares
*(int*)pIndex = -1;
if (pIndex)
pIndex->Invalidate();

double scalex = linked->GetTechnoType()->VoxelScaleX;
double scaley = linked->GetTechnoType()->VoxelScaleY;
Expand Down

0 comments on commit bdd2443

Please sign in to comment.