@@ -204,27 +204,62 @@ DEFINE_HOOK(0x44D455, BuildingClass_Mission_Missile_EMPulseBulletWeapon, 0x8)
204
204
205
205
#pragma region KickOutStuckUnits
206
206
207
- // Kick out stuck units when the factory building is not busy, only factory buildings can enter this hook
208
- DEFINE_HOOK (0x450248 , BuildingClass_UpdateFactory_KickOutStuckUnits, 0x6 )
207
+ DEFINE_HOOK (0x44955D , BuildingClass_WeaponFactoryOutsideBusy_WeaponFactoryCell, 0x6 )
209
208
{
210
- GET (BuildingClass*, pThis, ESI) ;
209
+ enum { NotBusy = 0x44969B } ;
211
210
212
- // This is not a solution to the problem at its root
213
- // Currently the root cause of the problem is not located
214
- // So the idle weapon factory is asked to search every second for any units that are stuck
215
- if (!(Unsorted::CurrentFrame % 15 )) // Check every 15 frames for factories
216
- {
217
- const auto pType = pThis->Type ;
211
+ GET (BuildingClass* const , pThis, ESI);
218
212
219
- if (pType->Factory == AbstractType::UnitType && pType->WeaponsFactory && !pType->Naval && pThis->QueuedMission != Mission::Unload)
220
- {
221
- const auto mission = pThis->CurrentMission ;
213
+ const auto pLink = pThis->GetNthLink ();
214
+
215
+ if (!pLink)
216
+ return NotBusy;
217
+
218
+ const auto pLinkType = pLink->GetTechnoType ();
219
+
220
+ if (pLinkType->JumpJet && pLinkType->BalloonHover )
221
+ return NotBusy;
222
+
223
+ return 0 ;
224
+ }
225
+
226
+ // Attempt to kick the stuck unit out again by setting the destination
227
+ DEFINE_HOOK (0x44E202 , BuildingClass_Mission_Unload_CheckStuck, 0x6 )
228
+ {
229
+ enum { Waiting = 0x44E267 , NextStatus = 0x44E20C };
222
230
223
- if (mission == Mission::Guard && !pThis->InLimbo || mission == Mission::Unload && pThis->MissionStatus == 3 ) // Unloading but stuck
224
- BuildingExt::KickOutStuckUnits (pThis);
231
+ GET (BuildingClass*, pThis, EBP);
232
+
233
+ if (!pThis->IsTether )
234
+ return NextStatus;
235
+
236
+ if (const auto pUnit = abstract_cast<UnitClass*>(pThis->GetNthLink ()))
237
+ {
238
+ // Detecting movement status
239
+ if (pUnit->Locomotor ->Destination () == CoordStruct::Empty)
240
+ {
241
+ // Evacuate the congestion at the entrance
242
+ reinterpret_cast <void (__thiscall*)(BuildingClass*)>(0x449540 )(pThis);
243
+ const auto pType = pThis->Type ;
244
+ const auto cell = pThis->GetMapCoords () + pType->FoundationOutside [10 ];
245
+ const auto door = cell - CellStruct { 1 , 0 };
246
+ const auto pDest = MapClass::Instance.GetCellAt (door);
247
+
248
+ // Hover units may stop one cell behind their destination, should forcing them to advance one more cell
249
+ pUnit->SetDestination ((pUnit->Destination != pDest ? pDest : MapClass::Instance.GetCellAt (cell)), true );
225
250
}
226
251
}
227
252
253
+ return Waiting;
254
+ }
255
+
256
+ // Check for any stuck units inside after successful unload each time. If there is, kick it out
257
+ DEFINE_HOOK (0x44E260 , BuildingClass_Mission_Unload_KickOutStuckUnits, 0x7 )
258
+ {
259
+ GET (BuildingClass*, pThis, EBP);
260
+
261
+ BuildingExt::KickOutStuckUnits (pThis);
262
+
228
263
return 0 ;
229
264
}
230
265
0 commit comments