Skip to content

Commit ce12b49

Browse files
committed
Fix spawned planes being unable to land back onto their spawner
1 parent 9d9ea35 commit ce12b49

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

docs/New-Features-and-Enhancements.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ HunterSeeker= ; UnitType, the unit that is this side's Hunter-Seeker.
239239

240240
- Vinifera ports the spawn manager, responsible for AircraftType missiles and aircraft carries from Red Alert 2.
241241

242-
```{warning}
243-
Aircraft carriers (i. e. spawners that spawn non-rockets) are known to have issues with Tiberian Sun aircraft, and as such may not function properly. This will be fixed in a future version of Vinifera.
244-
```
245-
246242
In `RULES.INI`:
247243
```ini
248244
[SOMETECHNO] ; TechnoType

src/extensions/aircraft/aircraftext_hooks.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static class AircraftClassExt final : public AircraftClass
6565
public:
6666
bool _Unlimbo(Coordinate& coord, DirType dir);
6767
bool _Enter_Idle_Mode(bool initial, bool a2);
68+
bool _Cell_Seems_Ok(Cell& cell, bool strict) const;
6869
};
6970

7071

@@ -287,6 +288,58 @@ bool AircraftClassExt::_Enter_Idle_Mode(bool initial, bool a2)
287288
}
288289

289290

291+
/**
292+
* Checks to see if a cell is good to enter.
293+
*
294+
* @author: 06/19/1995 JLB - Created.
295+
* ZivDero - Adjustments for Tiberian Sun.
296+
*/
297+
bool AircraftClassExt::_Cell_Seems_Ok(Cell& cell, bool strict) const
298+
{
299+
/**
300+
* If the cell is outisde the playable area, then it is not a valid cell to enter.
301+
*/
302+
if (!Map.In_Local_Radar(cell)) {
303+
return false;
304+
}
305+
306+
/**
307+
* Spawners and spawned objects can co-exist in cells.
308+
*/
309+
if (Extension::Fetch<AircraftTypeClassExtension>(Class)->IsSpawned) {
310+
const TechnoClass* techno = Map[cell].Cell_Techno();
311+
if (techno) {
312+
if (Extension::Fetch<TechnoClassExtension>(techno)->SpawnManager
313+
|| Extension::Fetch<TechnoTypeClassExtension>(techno->Techno_Type_Class())->IsSpawned) {
314+
return true;
315+
}
316+
}
317+
}
318+
319+
/**
320+
* If we're a carryall, we can enter a potential totable unit's cell.
321+
*/
322+
bool can_tote = false;
323+
if (Class->IsCarryall && Target_Legal(NavCom) && NavCom->What_Am_I() == RTTI_UNIT)
324+
can_tote = true;
325+
326+
/**
327+
* Make sure that no other aircraft are heading to the selected location. If they
328+
* are, then don't consider the location as valid.
329+
*/
330+
TARGET astarget = &Map[cell];
331+
for (int index = 0; index < Foots.Count(); index++) {
332+
const FootClass* foot = Foots[index];
333+
if (foot && (!can_tote || foot != NavCom) && (strict || foot != this) && !foot->IsInLimbo) {
334+
if (foot->IsDown && (Coord_Cell(foot->Coord) == cell || foot->NavCom == astarget)) {
335+
return false;
336+
}
337+
}
338+
}
339+
340+
return true;
341+
}
342+
290343

291344
/**
292345
* #issue-996
@@ -586,4 +639,5 @@ void AircraftClassExtension_Hooks()
586639

587640
Patch_Jump(0x00408940, &AircraftClassExt::_Unlimbo);
588641
Patch_Jump(0x0040B310, &AircraftClassExt::_Enter_Idle_Mode);
642+
Patch_Jump(0x0040D260, &AircraftClassExt::_Cell_Seems_Ok);
589643
}

0 commit comments

Comments
 (0)