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

[Vanilla Fix] Fix unit get stuck in factory #1347

Open
wants to merge 30 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ff494bc
Core
CrimRecya Aug 10, 2024
ff9257b
Co-Author
CrimRecya Aug 10, 2024
b734ec6
Fix
CrimRecya Aug 10, 2024
115b33c
Delete useless
CrimRecya Aug 10, 2024
e3e7cb3
Fix
CrimRecya Aug 11, 2024
c0a95ba
Check WeaponsFactory
CrimRecya Aug 11, 2024
f148995
CellHeight
CrimRecya Aug 12, 2024
230d037
Merge branch 'develop' into develop-kickout
CrimRecya Aug 12, 2024
cf7663a
Fix
CrimRecya Aug 13, 2024
4961925
Merge branch 'develop' into develop-kickout
CrimRecya Aug 13, 2024
8a77a94
Fix
CrimRecya Aug 13, 2024
fff3d9a
Fix
CrimRecya Aug 13, 2024
204fb75
Fix
CrimRecya Aug 13, 2024
af52bf9
Fix
CrimRecya Aug 13, 2024
d0d498c
Fix
CrimRecya Aug 13, 2024
a613113
Fix
CrimRecya Aug 13, 2024
ef91253
Fix
CrimRecya Aug 13, 2024
e64c545
Fix
CrimRecya Aug 13, 2024
cad8168
Fix
CrimRecya Aug 14, 2024
010a347
Add conditions
CrimRecya Aug 24, 2024
000095b
Fix a bug that units kicked out from the factory building inside will…
CrimRecya Aug 24, 2024
58306a2
Merge branch 'develop' into develop-kickout
CrimRecya Aug 24, 2024
6796f90
Fix an issue that caused a delay in kicking out
CrimRecya Aug 25, 2024
c02645d
Merge branch 'develop' into develop-kickout
CrimRecya Sep 15, 2024
09cc06a
Merge branch 'develop' into develop-kickout
CrimRecya Sep 18, 2024
ddbaac7
Update Fixed-or-Improved-Logics.md
CrimRecya Sep 18, 2024
dc70fd8
Merge branch 'develop' into develop-kickout
CrimRecya Oct 14, 2024
2d2e4ad
Fix hover types stuck
CrimRecya Oct 20, 2024
483185b
Merge branch 'develop' into develop-kickout
CrimRecya Nov 7, 2024
236ada4
Const auto
CrimRecya Nov 7, 2024
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
3 changes: 3 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ This page lists all the individual contributions to the project by their author.
- Allow to change the speed of gas particles
- **CrimRecya**
- Fix `LimboKill` not working reliably
- Units will not always stuck in the factory
- **TaranDahl**
- Units are now unable to kick out from a factory that is in construction process
- **Ollerus**
- Build limit group enhancement
- Customizable rocker amplitude
Expand Down
1 change: 1 addition & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- OverlayTypes now read and use `ZAdjust` if specified in their `artmd.ini` entry.
- Setting `[AudioVisual]` -> `ColorAddUse8BitRGB` to true makes game treat values from `[ColorAdd]` as 8-bit RGB (0-255) instead of RGB565 (0-31 for red & blue, 0-63 for green). This works for `LaserTargetColor`, `IronCurtainColor`, `BerserkColor` and `ForceShieldColor`.
- Weapons with `AA=true` Projectile can now correctly fire at air units when both firer and target are over a bridge.
- Units are now unable to kick out from a factory that is in construction process, and will not always stuck in the factory.
- Fixed disguised units not using the correct palette if target has custom palette.
- Building upgrades now consistently use building's `PowerUpN` animation settings corresponding to the upgrade's `PowersUpToLevel` where possible.
- Subterranean units are no longer allowed to perform deploy functions like firing weapons or `IsSimpleDeployer` while burrowed or burrowing, they will instead emerge first like they do for transport unloading.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ Vanilla fixes:
- Units with `Sensors=true` will no longer reveal ally buildings (by Starkku)
- Air units are now reliably included by target scan with large range and Warhead detonation by large `CellSpread` (by Starkku)
- Weapons with `AA=true` Projectile can now correctly fire at air units when both firer and target are over a bridge (by Starkku)
- 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)
- Fixed disguised units not using the correct palette if target has custom palette (by NetsuNegi)
- Building upgrades now consistently use building's `PowerUpN` animation settings corresponding to the upgrade's `PowersUpToLevel` where possible (by Starkku)
- Subterranean units are no longer allowed to perform deploy functions like firing weapons or `IsSimpleDeployer` while burrowed or burrowing, they will instead emerge first like they do for transport unloading (by Starkku)
Expand Down
52 changes: 52 additions & 0 deletions src/Ext/Building/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,58 @@ bool BuildingExt::ExtData::HandleInfiltrate(HouseClass* pInfiltratorHouse, int m
return true;
}

void BuildingExt::KickOutStuckUnits(BuildingClass* pThis)
{
if (const auto pTechno = pThis->GetNthLink())
{
if (const auto pUnit = abstract_cast<UnitClass*>(pTechno))
{
if (!pUnit->unknown_bool_418 && pUnit->GetCurrentSpeed() <= 0)
{
if (const auto pTeam = pUnit->Team)
pTeam->LiberateMember(pUnit);

pThis->SendCommand(RadioCommand::NotifyUnlink, pUnit);
pUnit->QueueMission(Mission::Guard, false);
return; // one after another
}
}
}

auto buffer = CoordStruct::Empty;
auto pCell = MapClass::Instance->GetCellAt(*pThis->GetExitCoords(&buffer, 0));
int i = 0;

while (true)
{
for (auto pObject = pCell->FirstObject; pObject; pObject = pObject->NextObject)
{
if (const auto pUnit = abstract_cast<UnitClass*>(pObject))
{
if (pThis->Owner != pUnit->Owner || pUnit->unknown_bool_418)
continue;

const auto height = pUnit->GetHeight();

if (height < 0 || height > Unsorted::CellHeight)
continue;

if (const auto pTeam = pUnit->Team)
pTeam->LiberateMember(pUnit);

pThis->SendCommand(RadioCommand::RequestLink, pUnit);
pThis->QueueMission(Mission::Unload, false);
return; // one after another
}
}

if (++i >= 2)
return; // no stuck

pCell = pCell->GetNeighbourCell(FacingType::East);
}
}

// Get all cells covered by the building, optionally including those covered by OccupyHeight.
const std::vector<CellStruct> BuildingExt::GetFoundationCells(BuildingClass* const pThis, CellStruct const baseCoords, bool includeOccupyHeight)
{
Expand Down
1 change: 1 addition & 0 deletions src/Ext/Building/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ class BuildingExt
static bool CanGrindTechno(BuildingClass* pBuilding, TechnoClass* pTechno);
static bool DoGrindingExtras(BuildingClass* pBuilding, TechnoClass* pTechno, int refund);
static bool CanUndeployOnSell(BuildingClass* pThis);
static void KickOutStuckUnits(BuildingClass* pThis);
static const std::vector<CellStruct> GetFoundationCells(BuildingClass* pThis, CellStruct baseCoords, bool includeOccupyHeight = false);
};
33 changes: 33 additions & 0 deletions src/Ext/Building/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,39 @@ DEFINE_HOOK(0x44D455, BuildingClass_Mission_Missile_EMPulseBulletWeapon, 0x8)

#pragma endregion

// Kick out stuck units when the factory building is not busy
DEFINE_HOOK(0x450248, BuildingClass_UpdateFactory_KickOutStuckUnits, 0x6)
{
GET(BuildingClass*, pThis, ESI);

if (!(Unsorted::CurrentFrame % 15))
{
const auto pType = pThis->Type;

if (pType->Factory == AbstractType::UnitType && pType->WeaponsFactory && !pType->Naval && pThis->QueuedMission != Mission::Unload)
{
const auto mission = pThis->CurrentMission;

if (mission == Mission::Guard || (mission == Mission::Unload && pThis->MissionStatus == 1))
BuildingExt::KickOutStuckUnits(pThis);
}
}

return 0;
}

// Should not kick out units if the factory building is in construction process
DEFINE_HOOK(0x4444A0, BuildingClass_KickOutUnit_NoKickOutInConstruction, 0xA)
{
enum { ThisIsOK = 0x444565, ThisIsNotOK = 0x4444B3};

GET(BuildingClass* const, pThis, ESI);

const auto mission = pThis->GetCurrentMission();

return (mission == Mission::Unload || mission == Mission::Construction) ? ThisIsNotOK : ThisIsOK;
}

// Ares didn't have something like 0x7397E4 in its UnitDelivery code
DEFINE_HOOK(0x44FBBF, CreateBuildingFromINIFile_AfterCTOR_BeforeUnlimbo, 0x8)
{
Expand Down
Loading