Skip to content

Commit

Permalink
Allow customizing aircraft landing/docking direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku committed Oct 1, 2023
1 parent 3896640 commit 6d51eec
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 2 deletions.
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ This page lists all the individual contributions to the project by their author.
- Reloading ammo in transports
- Straight projectile trajectory additions
- Airstrike & spy plane fixed spawn distance & height
- Aircraft landing / docking direction
- **Morton (MortonPL)**:
- `XDrawOffset` for animations
- Shield passthrough & absorption
Expand Down
22 changes: 22 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Wall overlays are now drawn with the custom palette defined in `Palette` in `artmd.ini` if possible.
- `Secondary` will now be used against walls if `Primary` weapon Warhead has `Wall=false`, `Secondary` has `Wall=true` and the firer does not have `NoSecondaryWeaponFallback` set to true.
- Setting `ReloadInTransport` to true on units with `Ammo` will allow the ammo to be reloaded according to `Reload` or `EmptyReload` timers even while the unit is inside a transport.
- Aircraft docking on buildings now respect `[AudioVisual]`->`PoseDir` as the default setting and do not always land facing north or in case of pre-placed buildings, the building's direction.

## Fixes / interactions with other extensions

Expand All @@ -156,6 +157,17 @@ SpawnDistanceFromTarget= ; floating point value, distance in cells
SpawnHeight= ; integer, height in leptons
```

### Landing direction

- By default aircraft land facing the direction specified by `[AudioVisual]`->`PoseDir`. This can now be customized per AircraftType via `LandingDir`, defaults to `[AudioVisual]`->`PoseDir`. If the building the aircraft is docking to has [aircraft docking direction](#aircraft-docking-direction) set, that setting takes priority over this.
- Negative values are allowed as a special case for `AirportBound=false` aircraft which makes them land facing their current direction.

In `rulesmd.ini`:
```ini
[SOMEAIRCRAFT] ; AircraftType
LandingDir= ; Direction type (integers from 0-255). Accepts negative values as a special case.
```

## Animations

### Animation weapon and damage settings
Expand Down Expand Up @@ -228,6 +240,16 @@ HideIfNoOre.Threshold=0 ; integer, minimal ore growth stage

## Buildings

### Aircraft docking direction

- It is now possible to customize the landing direction for docking aircraft via `AircraftDockingDir` on the dock building. This overrides the aircraft's own [landing direction](#landing-direction) setting and defaults to `[AudioVisual]` -> `PoseDir`.

In `rulesmd.ini`:
```ini
[SOMEBUILDING] ; BuildingType
AircraftDockingDir= ; Direction type (integers from 0-255)
```

### Airstrike target eligibility

- By default whether or not a building can be targeted by airstrikes depends on value of `CanC4`, which also affects other things. This can now be changed independently by setting `AllowAirstrike`. If not set, defaults to value of `CanC4`.
Expand Down
2 changes: 1 addition & 1 deletion docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ CreateUnit= ; VehicleType
CreateUnit.Owner=Victim ; Owner house kind, Invoker/Killer/Victim/Civilian/Special/Neutral/Random
CreateUnit.RemapAnim=false ; boolean
CreateUnit.Mission=Guard ; MissionType
CreateUnit.Facing=0 ; integer, facings in range of 0-255
CreateUnit.Facing=0 ; Direction type (integers from 0-255)
CreateUnit.RandomFacing=true ; boolean
CreateUnit.InheritFacings=false ; boolean
CreateUnit.InheritTurretFacings=false ; boolean
Expand Down
2 changes: 2 additions & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ New:
- Allow toggling `Infantry/UnitsGainSelfHeal` for `MultiplayPassive=true` houses (by Starkku)
- Customizable straight trajectory detonation & snap distance and pass-through option (by Starkku)
- Airstrike & spy plane fixed spawn distance & height (by Starkku)
- Allow customizing aircraft landing direction per aircraft or per dock (by Starkku)
Vanilla fixes:
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)
Expand Down Expand Up @@ -393,6 +394,7 @@ Vanilla fixes:
- `EMPulseCannon=yes` building weapons now respect `Floater` and Phobos-added `Gravity` setting (by Starkku)
- Fixed position and layer of info tip and reveal production cameo on selected building (by Belonit)
- Fixed `TurretOffset` to be supported for SHP vehicles (by TwinkleStar)
- Aircraft docking on buildings now respect `[AudioVisual]`->`PoseDir` as the default setting and do not always land facing north or in case of pre-placed buildings, the building's direction (by Starkku)
Phobos fixes:
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)
Expand Down
44 changes: 44 additions & 0 deletions src/Ext/Aircraft/Body.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "Body.h"

#include <BuildingClass.h>

#include <Ext/BuildingType/Body.h>
#include <Ext/TechnoType/Body.h>
#include <Ext/WeaponType/Body.h>

Expand Down Expand Up @@ -50,3 +54,43 @@ bool AircraftExt::PlaceReinforcementAircraft(AircraftClass* pThis, CellStruct ed

return result;
}

DirType AircraftExt::GetLandingDir(AircraftClass* pThis, BuildingClass* pDock)
{
auto const poseDir = static_cast<DirType>(RulesClass::Instance->PoseDir);

if (!pThis)
return poseDir;

bool isAirportBound = true;

if (pDock || pThis->HasAnyLink())
{
auto pBuilding = pDock;

if (!pDock)
pBuilding = abstract_cast<BuildingClass*>(pThis->GetNthLink(0));

if (pBuilding)
{
auto const pBuildingTypeExt = BuildingTypeExt::ExtMap.Find(pBuilding->Type);

if (pBuildingTypeExt->AircraftDockingDir.isset())
return pBuildingTypeExt->AircraftDockingDir.Get();
}
}
else if (!pThis->Type->AirportBound)
{
isAirportBound = false;
}

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

if (isAirportBound)
return static_cast<DirType>(Math::clamp(landingDir, 0, 255));
else if (landingDir < 0)
return pThis->PrimaryFacing.Current().GetDir();

return poseDir;
}

1 change: 1 addition & 0 deletions src/Ext/Aircraft/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class AircraftExt
public:
static void FireBurst(AircraftClass* pThis, AbstractClass* pTarget, int shotNumber);
static bool PlaceReinforcementAircraft(AircraftClass* pThis, CellStruct edgeCell);
static DirType GetLandingDir(AircraftClass* pThis, BuildingClass* pDock = nullptr);
};

51 changes: 50 additions & 1 deletion src/Ext/Aircraft/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <AircraftClass.h>
#include <Utilities/Macro.h>
#include <FlyLocomotionClass.h>


#include <Ext/Aircraft/Body.h>
#include <Ext/Anim/Body.h>
#include <Ext/WeaponType/Body.h>
#include <Utilities/Macro.h>

DEFINE_HOOK(0x417FF1, AircraftClass_Mission_Attack_StrafeShots, 0x6)
{
Expand Down Expand Up @@ -107,3 +110,49 @@ DEFINE_HOOK(0x414C0B, AircraftClass_ChronoSparkleDelay, 0x5)
R->ECX(RulesExt::Global()->ChronoSparkleDisplayDelay);
return 0x414C10;
}


#pragma region LandingDir

DEFINE_HOOK(0x4CF31C, FlyLocomotionClass_FlightUpdate_LandingDir, 0x9)
{
enum { SkipGameCode = 0x4CF351 };

GET(FootClass**, pLinkedToPtr, ESI);
REF_STACK(unsigned int, dir, STACK_OFFSET(0x48, 0x8));

auto const pLinkedTo = *pLinkedToPtr;
dir = 0;

if (pLinkedTo->CurrentMission == Mission::Enter || pLinkedTo->GetMapCoords() == CellClass::Coord2Cell(pLinkedTo->Locomotor->Destination()))
{
if (auto const pAircraft = abstract_cast<AircraftClass*>(pLinkedTo))
dir = DirStruct(AircraftExt::GetLandingDir(pAircraft)).Raw;
}

return SkipGameCode;
}

DEFINE_HOOK(0x446F6C, BuildingClass_GrandOpening_PoseDir, 0x9)
{
GET(BuildingClass*, pThis, EBP);
GET(AircraftClass*, pAircraft, ESI);

R->EAX(AircraftExt::GetLandingDir(pAircraft, pThis));

return 0;
}

DEFINE_HOOK_AGAIN(0x443FEF, BuildingClass_ExitObject_PoseDir, 0xA)
DEFINE_HOOK(0x443FC7, BuildingClass_ExitObject_PoseDir, 0x8)
{
GET(BuildingClass*, pThis, ESI);
GET(AircraftClass*, pAircraft, EBP);

R->EAX(AircraftExt::GetLandingDir(pAircraft, pThis));

return 0;
}

#pragma endregion

3 changes: 3 additions & 0 deletions src/Ext/BuildingType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->ConsideredVehicle.Read(exINI, pSection, "ConsideredVehicle");
this->SellBuildupLength.Read(exINI, pSection, "SellBuildupLength");

this->AircraftDockingDir.Read(exINI, pSection, "AircraftDockingDir");

// Ares tag
this->SpyEffect_Custom.Read(exINI, pSection, "SpyEffect.Custom");
if (SuperWeaponTypeClass::Array->Count > 0)
Expand Down Expand Up @@ -234,6 +236,7 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm)
.Process(this->ConsideredVehicle)
.Process(this->ZShapePointMove_OnBuildup)
.Process(this->SellBuildupLength)
.Process(this->AircraftDockingDir)
;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Ext/BuildingType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class BuildingTypeExt
Valueable<bool> ZShapePointMove_OnBuildup;
Valueable<int> SellBuildupLength;

Nullable<DirType> AircraftDockingDir;

ExtData(BuildingTypeClass* OwnerObject) : Extension<BuildingTypeClass>(OwnerObject)
, PowersUp_Owner { AffectedHouse::Owner }
, PowersUp_Buildings {}
Expand Down Expand Up @@ -96,6 +98,7 @@ class BuildingTypeExt
, ConsideredVehicle {}
, ZShapePointMove_OnBuildup { false }
, SellBuildupLength { 23 }
, AircraftDockingDir {}
{ }

// Ares 0.A functions
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 @@ -272,6 +272,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)

this->SpawnDistanceFromTarget.Read(exINI, pSection, "SpawnDistanceFromTarget");
this->SpawnHeight.Read(exINI, pSection, "SpawnHeight");
this->LandingDir.Read(exINI, pSection, "LandingDir");

// Ares 0.2
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");
Expand Down Expand Up @@ -569,6 +570,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)

.Process(this->SpawnDistanceFromTarget)
.Process(this->SpawnHeight)
.Process(this->LandingDir)
;
}
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
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 @@ -181,6 +181,7 @@ class TechnoTypeExt

Nullable<Leptons> SpawnDistanceFromTarget;
Nullable<int> SpawnHeight;
Nullable<int> LandingDir;

struct LaserTrailDataEntry
{
Expand Down Expand Up @@ -359,6 +360,7 @@ class TechnoTypeExt

, SpawnDistanceFromTarget {}
, SpawnHeight {}
, LandingDir {}
{ }

virtual ~ExtData() = default;
Expand Down

0 comments on commit 6d51eec

Please sign in to comment.