Skip to content

Commit

Permalink
Fix spawned planes being unable to land back onto their spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
ZivDero committed Oct 22, 2024
1 parent 9d9ea35 commit ce12b49
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
4 changes: 0 additions & 4 deletions docs/New-Features-and-Enhancements.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ HunterSeeker= ; UnitType, the unit that is this side's Hunter-Seeker.

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

```{warning}
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.
```

In `RULES.INI`:
```ini
[SOMETECHNO] ; TechnoType
Expand Down
54 changes: 54 additions & 0 deletions src/extensions/aircraft/aircraftext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static class AircraftClassExt final : public AircraftClass
public:
bool _Unlimbo(Coordinate& coord, DirType dir);
bool _Enter_Idle_Mode(bool initial, bool a2);
bool _Cell_Seems_Ok(Cell& cell, bool strict) const;
};


Expand Down Expand Up @@ -287,6 +288,58 @@ bool AircraftClassExt::_Enter_Idle_Mode(bool initial, bool a2)
}


/**
* Checks to see if a cell is good to enter.
*
* @author: 06/19/1995 JLB - Created.
* ZivDero - Adjustments for Tiberian Sun.
*/
bool AircraftClassExt::_Cell_Seems_Ok(Cell& cell, bool strict) const
{
/**
* If the cell is outisde the playable area, then it is not a valid cell to enter.
*/
if (!Map.In_Local_Radar(cell)) {
return false;
}

/**
* Spawners and spawned objects can co-exist in cells.
*/
if (Extension::Fetch<AircraftTypeClassExtension>(Class)->IsSpawned) {
const TechnoClass* techno = Map[cell].Cell_Techno();
if (techno) {
if (Extension::Fetch<TechnoClassExtension>(techno)->SpawnManager
|| Extension::Fetch<TechnoTypeClassExtension>(techno->Techno_Type_Class())->IsSpawned) {
return true;
}
}
}

/**
* If we're a carryall, we can enter a potential totable unit's cell.
*/
bool can_tote = false;
if (Class->IsCarryall && Target_Legal(NavCom) && NavCom->What_Am_I() == RTTI_UNIT)
can_tote = true;

/**
* Make sure that no other aircraft are heading to the selected location. If they
* are, then don't consider the location as valid.
*/
TARGET astarget = &Map[cell];
for (int index = 0; index < Foots.Count(); index++) {
const FootClass* foot = Foots[index];
if (foot && (!can_tote || foot != NavCom) && (strict || foot != this) && !foot->IsInLimbo) {
if (foot->IsDown && (Coord_Cell(foot->Coord) == cell || foot->NavCom == astarget)) {
return false;
}
}
}

return true;
}


/**
* #issue-996
Expand Down Expand Up @@ -586,4 +639,5 @@ void AircraftClassExtension_Hooks()

Patch_Jump(0x00408940, &AircraftClassExt::_Unlimbo);
Patch_Jump(0x0040B310, &AircraftClassExt::_Enter_Idle_Mode);
Patch_Jump(0x0040D260, &AircraftClassExt::_Cell_Seems_Ok);
}

0 comments on commit ce12b49

Please sign in to comment.