Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Hooks.Others.cpp #8

Merged
merged 5 commits into from
Feb 13, 2025
Merged
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
2 changes: 2 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ This page lists all the individual contributions to the project by their author.
- Raise alert when technos are taking damage
- Toggle waypoint for building
- Parasite returning bug fix
- Bunkerable checks dehardcode
- Prevent the units with locomotors that cause problems from entering the tank bunker
- New hotkey to select the units within the current screen that are captured by non-permanent mind-controller
- `Spawner.RecycleRange`
- `Spawner.RecycleAnim`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Documentation

- [Official docs](https://phobos.readthedocs.io) (also available in [Chinese](https://phobos.readthedocs.io/zh_CN/latest))

You can switch between versions (displays latest develop nightly version by default) in the bottom left corner, as well as download a PDF version.
You can switch between versions (displays latest develop nightly version by default) in the bottom right corner, as well as download a PDF version.

The documentation is split by a few major categories, each represented with a page on the sidebar. Each page has its contents grouped into multiple subcategories, be it buildings, technotypes, infantries, superweapons or something else.

Expand Down
18 changes: 18 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Aircraft will now behave as expected according to it's `MovementZone` and `SpeedType` when moving onto different surfaces. In particular, this fixes erratic behavior when vanilla aircraft is ordered to move onto water surface and instead the movement order changes to a shore nearby.
- Allowed `AuxBuilding` to count building upgrades.
- Fix the bug that parasite will vanish if it missed its target when its previous cell is occupied.
- Prevent the units with locomotors that cause problems from entering the tank bunker.

## Fixes / interactions with other extensions

Expand Down Expand Up @@ -1250,6 +1251,23 @@ MinimapColor= ; integer - Red,Green,Blue

## Vehicles

### Bunker entering check dehardcode

- In vanilla, vehicles entering tank bunkers are subject to a series of hardcoding restrictions, including having to have turrets, having to have weapons, and not having Hover speed types. Now you can skip these restrictions.
- This needs to be used with `Bunkerable=yes`.
- This flag only skips the static check, that is, the check on the unit type. The dynamic check (cannot be parasitized) remains unchanged.

In `rulesmd.ini`:
```ini
[SOMEVEHICLE] ; VehicleType
BunkerableAnyway=false ; boolean
```

```{warning}
Skipping checks with this feature doesn't mean that vehicles and tank bunkers will interact correctly. Following the simple checks performed by the provider of this feature, bunkerability is mainly determined by Locomotor. The details about locomotors' bunkerability can be found on [ModEnc](https://modenc.renegadeprojects.com/Bunkerable).
```


### Customizing crushing tilt and slowdown

- Vehicles with `Crusher=true` and `OmniCrusher=true` / `MovementZone=CrusherAll` were hardcoded to tilt when crushing vehicles / walls respectively. This now obeys `TiltsWhenCrushes` but can be customized individually for these two scenarios using `TiltsWhenCrusher.Vehicles` and `TiltsWhenCrusher.Overlays`, which both default to `TiltsWhenCrushes`.
Expand Down
2 changes: 2 additions & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ New:
- Raise alert when technos are taking damage (by TaranDahl)
- Enhanced Bombard trajectory (by CrimRecya & Ollerus, based on knowledge of NaotoYuuki)
- Toggle waypoint for building (by TaranDahl)
- Bunkerable checks dehardcode (by TaranDahl)
- Projectile subject to ground check before firing (by CrimRecya)
- New Disperse trajectory (by CrimRecya)
- New Engrave trajectory (by CrimRecya)
Expand Down Expand Up @@ -370,6 +371,7 @@ New:
Vanilla fixes:
- Aircraft will now behave as expected according to it's `MovementZone` and `SpeedType` when moving onto different surfaces. In particular, this fixes erratic behavior when vanilla aircraft is ordered to move onto water surface and instead the movement order changes to a shore nearby (by CrimRecya)
- Fix the bug that parasite will vanish if it missed its target when its previous cell is occupied (by 航味麻酱)
- Prevent the units with locomotors that cause problems from entering the tank bunker (by TaranDahl)
- Units are now unable to kick out from a factory that is in construction process, and will not always stuck in the factory (by CrimRecya & TaranDahl)
- Observer sidebar in skirmish game mode (by CrimRecya)

Expand Down
4 changes: 2 additions & 2 deletions docs/locale/zh_CN/LC_MESSAGES/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ msgstr ""
#: ../../README.md:59
msgid ""
"You can switch between versions (displays latest develop nightly version by "
"default) in the bottom left corner, as well as download a PDF version."
"default) in the bottom right corner, as well as download a PDF version."
msgstr ""
"您可以在左下角切换版本(默认显示最新开发的每夜构建版本),也可以下载 PDF 版"
"您可以在右下角切换版本(默认显示最新开发的每夜构建版本),也可以下载 PDF 版"
"本。"

#: ../../README.md:61
Expand Down
35 changes: 17 additions & 18 deletions src/Ext/Bullet/Trajectories/BombardTrajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void BombardTrajectoryType::Read(CCINIClass* const pINI, const char* pSection)
INI_EX exINI(pINI);

this->Height.Read(exINI, pSection, "Trajectory.Bombard.Height");
this->Height = Math::max(0.0, this->Height);
this->FallPercent.Read(exINI, pSection, "Trajectory.Bombard.FallPercent");
this->FallPercentShift.Read(exINI, pSection, "Trajectory.Bombard.FallPercentShift");
this->FallScatter_Max.Read(exINI, pSection, "Trajectory.Bombard.FallScatter.Max");
Expand Down Expand Up @@ -153,14 +154,12 @@ bool BombardTrajectory::OnAI(BulletClass* pBullet)
if (this->BulletDetonatePreCheck(pBullet))
return true;

// Extra check for trajectory falling
const auto pOwner = pBullet->Owner ? pBullet->Owner->Owner : BulletExt::ExtMap.Find(pBullet)->FirerHouse;
this->BulletVelocityChange(pBullet);

if (this->IsFalling && !this->Type->FreeFallOnTarget && this->BulletDetonateRemainCheck(pBullet, pOwner))
// Extra check for trajectory falling
if (this->IsFalling && !this->Type->FreeFallOnTarget && this->BulletDetonateRemainCheck(pBullet))
return true;

this->BulletVelocityChange(pBullet);

return false;
}

Expand Down Expand Up @@ -208,6 +207,7 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
pBullet->Velocity *= pType->Trajectory_Speed / pBullet->Velocity.Magnitude();

this->CalculateDisperseBurst(pBullet);
this->RemainingDistance += static_cast<int>(middleLocation.DistanceFrom(pBullet->SourceCoords) + pType->Trajectory_Speed);
}
else
{
Expand Down Expand Up @@ -241,8 +241,9 @@ void BombardTrajectory::PrepareForOpenFire(BulletClass* pBullet)
this->RefreshBulletLineTrail(pBullet);

pBullet->SetLocation(middleLocation);
const auto pOwner = pBullet->Owner ? pBullet->Owner->Owner : pExt->FirerHouse;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pBullet->Owner, pOwner, true);
const auto pTechno = pBullet->Owner;
const auto pOwner = pTechno ? pTechno->Owner : pExt->FirerHouse;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pOwner, true);
}
}

Expand Down Expand Up @@ -496,7 +497,7 @@ bool BombardTrajectory::BulletDetonatePreCheck(BulletClass* pBullet)
return false;
}

bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet, HouseClass* pOwner)
bool BombardTrajectory::BulletDetonateRemainCheck(BulletClass* pBullet)
{
const auto pType = this->Type;
this->RemainingDistance -= static_cast<int>(pType->FallSpeed);
Expand All @@ -519,26 +520,23 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)

if (!this->IsFalling)
{
if (pBullet->Location.Z + pBullet->Velocity.Z >= this->Height)
this->RemainingDistance -= static_cast<int>(pType->Trajectory_Speed);

if (this->RemainingDistance < static_cast<int>(pType->Trajectory_Speed))
{
if (this->ToFalling)
{
this->IsFalling = true;
this->RemainingDistance = 1;
const auto pTarget = pBullet->Target;
auto middleLocation = CoordStruct::Empty;

if (!pType->FreeFallOnTarget)
{
middleLocation = CoordStruct
{
static_cast<int>(pBullet->Location.X + pBullet->Velocity.X),
static_cast<int>(pBullet->Location.Y + pBullet->Velocity.Y),
static_cast<int>(pBullet->Location.Z + pBullet->Velocity.Z)
};

if (pType->LeadTimeCalculate && pTarget)
pBullet->TargetCoords += pTarget->GetCoords() - this->InitialTargetCoord + this->CalculateBulletLeadTime(pBullet);

middleLocation = pBullet->Location;
pBullet->Velocity.X = static_cast<double>(pBullet->TargetCoords.X - middleLocation.X);
pBullet->Velocity.Y = static_cast<double>(pBullet->TargetCoords.Y - middleLocation.Y);
pBullet->Velocity.Z = static_cast<double>(pBullet->TargetCoords.Z - middleLocation.Z);
Expand Down Expand Up @@ -569,7 +567,8 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)

pBullet->SetLocation(middleLocation);
const auto pTechno = pBullet->Owner;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pTechno ? pTechno->Owner : pExt->FirerHouse, true);
const auto pOwner = pTechno ? pTechno->Owner : pExt->FirerHouse;
AnimExt::CreateRandomAnim(pType->TurningPointAnims, middleLocation, pTechno, pOwner, true);
}
else
{
Expand All @@ -579,7 +578,7 @@ void BombardTrajectory::BulletVelocityChange(BulletClass* pBullet)
if (pType->LeadTimeCalculate && pTarget)
this->LastTargetCoord = pTarget->GetCoords();

pBullet->Velocity *= std::abs((this->Height - pBullet->Location.Z) / pBullet->Velocity.Z);
pBullet->Velocity *= this->RemainingDistance / pType->Trajectory_Speed;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Bullet/Trajectories/BombardTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class BombardTrajectory final : public PhobosTrajectory
void CalculateDisperseBurst(BulletClass* pBullet);
bool BulletPrepareCheck(BulletClass* pBullet);
bool BulletDetonatePreCheck(BulletClass* pBullet);
bool BulletDetonateRemainCheck(BulletClass* pBullet, HouseClass* pOwner);
bool BulletDetonateRemainCheck(BulletClass* pBullet);
void BulletVelocityChange(BulletClass* pBullet);
void RefreshBulletLineTrail(BulletClass* pBullet);
};
26 changes: 26 additions & 0 deletions src/Ext/Techno/Hooks.Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,4 +681,30 @@ DEFINE_HOOK(0x51D7E0, InfantryClass_DoAction_Water, 0x5)
return Continue;
}

bool __fastcall LocomotorCheckForBunkerable(TechnoTypeClass* pType)
{
auto const loco = pType->Locomotor;

// These locomotors either cause the game to crash or fail to enter the tank bunker properly.
return loco != LocomotionClass::CLSIDs::Hover
&& loco != LocomotionClass::CLSIDs::Mech
&& loco != LocomotionClass::CLSIDs::Fly
&& loco != LocomotionClass::CLSIDs::Droppod
&& loco != LocomotionClass::CLSIDs::Rocket
&& loco != LocomotionClass::CLSIDs::Ship;
}

DEFINE_HOOK(0x70FB73, FootClass_IsBunkerableNow_Dehardcode, 0x6)
{
enum { CanEnter = 0x70FBAF, NoEnter = 0x70FB7D };

GET(TechnoTypeClass*, pType, EAX);
GET(FootClass*, pThis, ESI);

if (!LocomotorCheckForBunkerable(pType) || pThis->ParasiteEatingMe)
return NoEnter;

auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
return pTypeExt->BunkerableAnyway ? CanEnter : 0;
}
#pragma endregion
2 changes: 1 addition & 1 deletion src/Ext/Techno/Hooks.Others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ DEFINE_HOOK(0x4DF410, FootClass_UpdateAttackMove_TargetAcquired, 0x6)

if (auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType))
{
if (pTypeExt->AttackMove_StopWhenTargetAcquired.Get(RulesExt::Global()->AttackMove_StopWhenTargetAcquired.Get(!pType->OpportunityFire)))
if (pThis->IsCloseEnoughToAttack(pThis->Target) && pTypeExt->AttackMove_StopWhenTargetAcquired.Get(RulesExt::Global()->AttackMove_StopWhenTargetAcquired.Get(!pType->OpportunityFire)))
{
if (auto const pJumpjetLoco = locomotion_cast<JumpjetLocomotionClass*>(pThis->Locomotor))
{
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Wake.Read(exINI, pSection, "Wake");
this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple");
this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking");
this->BunkerableAnyway.Read(exINI, pSection, "BunkerableAnyway");

this->AttackMove_Aggressive.Read(exINI, pSection, "AttackMove.Aggressive");
this->AttackMove_UpdateTarget.Read(exINI, pSection, "AttackMove.UpdateTarget");
Expand Down Expand Up @@ -1273,6 +1274,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->AttackMove_Aggressive)
.Process(this->AttackMove_UpdateTarget)

.Process(this->BunkerableAnyway)
.Process(this->KeepTargetOnMove)
.Process(this->KeepTargetOnMove_ExtraDistance)

Expand Down
2 changes: 2 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class TechnoTypeExt
Nullable<bool> AttackMove_Aggressive;
Nullable<bool> AttackMove_UpdateTarget;

Valueable<bool> BunkerableAnyway;
Valueable<bool> KeepTargetOnMove;
Valueable<Leptons> KeepTargetOnMove_ExtraDistance;

Expand Down Expand Up @@ -683,6 +684,7 @@ class TechnoTypeExt
, AttackMove_Aggressive {}
, AttackMove_UpdateTarget {}

, BunkerableAnyway { false }
, KeepTargetOnMove { false }
, KeepTargetOnMove_ExtraDistance { Leptons(0) }

Expand Down