Skip to content

Commit 0177dc4

Browse files
committed
Allow customizing aircraft landing/docking direction
1 parent 4f6eac9 commit 0177dc4

File tree

11 files changed

+131
-2
lines changed

11 files changed

+131
-2
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ This page lists all the individual contributions to the project by their author.
221221
- Fire particle rotation coordinate adjust toggle
222222
- `AmbientDamage` warhead & main target ignore customization
223223
- Projectile return weapon
224+
- Aircraft landing / docking direction
224225
- **Morton (MortonPL)**:
225226
- `XDrawOffset` for animations
226227
- Shield passthrough & absorption

docs/Fixed-or-Improved-Logics.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
145145
- Fixed `AmbientDamage` when used with `IsRailgun=yes` being cut off by elevation changes.
146146
- Fixed railgun and fire particles being cut off by elevation changes.
147147
- Fixed teleport units' (for example CLEG) frozen-still timer being cleared after load game.
148+
- 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.
148149

149150
## Fixes / interactions with other extensions
150151

@@ -165,6 +166,17 @@ SpawnDistanceFromTarget= ; floating point value, distance in cells
165166
SpawnHeight= ; integer, height in leptons
166167
```
167168

169+
### Landing direction
170+
171+
- 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.
172+
- Negative values are allowed as a special case for `AirportBound=false` aircraft which makes them land facing their current direction.
173+
174+
In `rulesmd.ini`:
175+
```ini
176+
[SOMEAIRCRAFT] ; AircraftType
177+
LandingDir= ; Direction type (integers from 0-255). Accepts negative values as a special case.
178+
```
179+
168180
## Animations
169181

170182
### Animation weapon and damage settings
@@ -239,6 +251,16 @@ HideIfNoOre.Threshold=0 ; integer, minimal ore growth stage
239251

240252
## Buildings
241253

254+
### Aircraft docking direction
255+
256+
- 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`.
257+
258+
In `rulesmd.ini`:
259+
```ini
260+
[SOMEBUILDING] ; BuildingType
261+
AircraftDockingDir= ; Direction type (integers from 0-255)
262+
```
263+
242264
### Airstrike target eligibility
243265

244266
- 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`.

docs/New-or-Enhanced-Logics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ CreateUnit= ; VehicleType
266266
CreateUnit.Owner=Victim ; Owner house kind, Invoker/Killer/Victim/Civilian/Special/Neutral/Random
267267
CreateUnit.RemapAnim=false ; boolean
268268
CreateUnit.Mission=Guard ; MissionType
269-
CreateUnit.Facing=0 ; integer, facings in range of 0-255
269+
CreateUnit.Facing=0 ; Direction type (integers from 0-255)
270270
CreateUnit.RandomFacing=true ; boolean
271271
CreateUnit.InheritFacings=false ; boolean
272272
CreateUnit.InheritTurretFacings=false ; boolean

docs/Whats-New.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ New:
357357
- `AmbientDamage` warhead & main target ignore customization (by Starkku)
358358
- Flashing Technos on selecting (by Fryone)
359359
- Projectile return weapon (by Starkku)
360+
- Allow customizing aircraft landing direction per aircraft or per dock (by Starkku)
360361
361362
Vanilla fixes:
362363
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)
@@ -410,6 +411,7 @@ Vanilla fixes:
410411
- Fixed `AmbientDamage` when used with `IsRailgun=yes` being cut off by elevation changes (by Starkku)
411412
- Fixed railgun and fire particles being cut off by elevation changes (by Starkku)
412413
- Fixed teleport units' frozen-still timer being reset after load game (by Trsdy)
414+
- 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)
413415
414416
Phobos fixes:
415417
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)

src/Ext/Aircraft/Body.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include "Body.h"
2+
3+
#include <BuildingClass.h>
4+
5+
#include <Ext/BuildingType/Body.h>
26
#include <Ext/TechnoType/Body.h>
37
#include <Ext/WeaponType/Body.h>
48

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

5155
return result;
5256
}
57+
58+
DirType AircraftExt::GetLandingDir(AircraftClass* pThis, BuildingClass* pDock)
59+
{
60+
auto const poseDir = static_cast<DirType>(RulesClass::Instance->PoseDir);
61+
62+
if (!pThis)
63+
return poseDir;
64+
65+
bool isAirportBound = true;
66+
67+
if (pDock || pThis->HasAnyLink())
68+
{
69+
auto pBuilding = pDock;
70+
71+
if (!pDock)
72+
pBuilding = abstract_cast<BuildingClass*>(pThis->GetNthLink(0));
73+
74+
if (pBuilding)
75+
{
76+
auto const pBuildingTypeExt = BuildingTypeExt::ExtMap.Find(pBuilding->Type);
77+
78+
if (pBuildingTypeExt->AircraftDockingDir.isset())
79+
return pBuildingTypeExt->AircraftDockingDir.Get();
80+
}
81+
}
82+
else if (!pThis->Type->AirportBound)
83+
{
84+
isAirportBound = false;
85+
}
86+
87+
int landingDir = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType())->LandingDir.Get((int)poseDir);
88+
89+
if (isAirportBound)
90+
return static_cast<DirType>(Math::clamp(landingDir, 0, 255));
91+
else if (landingDir < 0)
92+
return pThis->PrimaryFacing.Current().GetDir();
93+
94+
return poseDir;
95+
}
96+

src/Ext/Aircraft/Body.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ class AircraftExt
88
public:
99
static void FireBurst(AircraftClass* pThis, AbstractClass* pTarget, int shotNumber);
1010
static bool PlaceReinforcementAircraft(AircraftClass* pThis, CellStruct edgeCell);
11+
static DirType GetLandingDir(AircraftClass* pThis, BuildingClass* pDock = nullptr);
1112
};
1213

src/Ext/Aircraft/Hooks.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include <AircraftClass.h>
2-
#include <Utilities/Macro.h>
2+
#include <FlyLocomotionClass.h>
3+
4+
35
#include <Ext/Aircraft/Body.h>
46
#include <Ext/Anim/Body.h>
57
#include <Ext/WeaponType/Body.h>
8+
#include <Utilities/Macro.h>
69

710
DEFINE_HOOK(0x417FF1, AircraftClass_Mission_Attack_StrafeShots, 0x6)
811
{
@@ -107,3 +110,49 @@ DEFINE_HOOK(0x414C0B, AircraftClass_ChronoSparkleDelay, 0x5)
107110
R->ECX(RulesExt::Global()->ChronoSparkleDisplayDelay);
108111
return 0x414C10;
109112
}
113+
114+
115+
#pragma region LandingDir
116+
117+
DEFINE_HOOK(0x4CF31C, FlyLocomotionClass_FlightUpdate_LandingDir, 0x9)
118+
{
119+
enum { SkipGameCode = 0x4CF351 };
120+
121+
GET(FootClass**, pLinkedToPtr, ESI);
122+
REF_STACK(unsigned int, dir, STACK_OFFSET(0x48, 0x8));
123+
124+
auto const pLinkedTo = *pLinkedToPtr;
125+
dir = 0;
126+
127+
if (pLinkedTo->CurrentMission == Mission::Enter || pLinkedTo->GetMapCoords() == CellClass::Coord2Cell(pLinkedTo->Locomotor->Destination()))
128+
{
129+
if (auto const pAircraft = abstract_cast<AircraftClass*>(pLinkedTo))
130+
dir = DirStruct(AircraftExt::GetLandingDir(pAircraft)).Raw;
131+
}
132+
133+
return SkipGameCode;
134+
}
135+
136+
DEFINE_HOOK(0x446F6C, BuildingClass_GrandOpening_PoseDir, 0x9)
137+
{
138+
GET(BuildingClass*, pThis, EBP);
139+
GET(AircraftClass*, pAircraft, ESI);
140+
141+
R->EAX(AircraftExt::GetLandingDir(pAircraft, pThis));
142+
143+
return 0;
144+
}
145+
146+
DEFINE_HOOK_AGAIN(0x443FEF, BuildingClass_ExitObject_PoseDir, 0xA)
147+
DEFINE_HOOK(0x443FC7, BuildingClass_ExitObject_PoseDir, 0x8)
148+
{
149+
GET(BuildingClass*, pThis, ESI);
150+
GET(AircraftClass*, pAircraft, EBP);
151+
152+
R->EAX(AircraftExt::GetLandingDir(pAircraft, pThis));
153+
154+
return 0;
155+
}
156+
157+
#pragma endregion
158+

src/Ext/BuildingType/Body.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
147147
this->ConsideredVehicle.Read(exINI, pSection, "ConsideredVehicle");
148148
this->SellBuildupLength.Read(exINI, pSection, "SellBuildupLength");
149149

150+
this->AircraftDockingDir.Read(exINI, pSection, "AircraftDockingDir");
151+
150152
// Ares tag
151153
this->SpyEffect_Custom.Read(exINI, pSection, "SpyEffect.Custom");
152154
if (SuperWeaponTypeClass::Array->Count > 0)
@@ -234,6 +236,7 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm)
234236
.Process(this->ConsideredVehicle)
235237
.Process(this->ZShapePointMove_OnBuildup)
236238
.Process(this->SellBuildupLength)
239+
.Process(this->AircraftDockingDir)
237240
;
238241
}
239242

src/Ext/BuildingType/Body.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class BuildingTypeExt
6161
Valueable<bool> ZShapePointMove_OnBuildup;
6262
Valueable<int> SellBuildupLength;
6363

64+
Nullable<DirType> AircraftDockingDir;
65+
6466
ExtData(BuildingTypeClass* OwnerObject) : Extension<BuildingTypeClass>(OwnerObject)
6567
, PowersUp_Owner { AffectedHouse::Owner }
6668
, PowersUp_Buildings {}
@@ -96,6 +98,7 @@ class BuildingTypeExt
9698
, ConsideredVehicle {}
9799
, ZShapePointMove_OnBuildup { false }
98100
, SellBuildupLength { 23 }
101+
, AircraftDockingDir {}
99102
{ }
100103

101104
// Ares 0.A functions

src/Ext/TechnoType/Body.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
272272

273273
this->SpawnDistanceFromTarget.Read(exINI, pSection, "SpawnDistanceFromTarget");
274274
this->SpawnHeight.Read(exINI, pSection, "SpawnHeight");
275+
this->LandingDir.Read(exINI, pSection, "LandingDir");
275276

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

570571
.Process(this->SpawnDistanceFromTarget)
571572
.Process(this->SpawnHeight)
573+
.Process(this->LandingDir)
572574
;
573575
}
574576
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)

0 commit comments

Comments
 (0)