@@ -36,39 +36,42 @@ DEFINE_HOOK(0x6DD8B0, TActionClass_Execute, 0x6)
3636DEFINE_HOOK (0x6E427D , TActionClass_CreateBuildingAt, 0x9 )
3737{
3838 GET (TActionClass*, pThis, ESI );
39- GET (BuildingTypeClass*, pBldType , ECX );
39+ GET (BuildingTypeClass*, pBuildingType , ECX );
4040 GET (HouseClass*, pHouse, EDI );
4141 REF_STACK (CoordStruct, coord, STACK_OFFSET (0x24 , -0x18 ));
4242
43- const bool bPlayBuildUp = pThis->Param3 == 0 && pBldType ->LoadBuildup ();
44- bool bCreated = false ;
43+ const bool playBuildup = pThis->Param3 == 0 && pBuildingType ->LoadBuildup ();
44+ bool created = false ;
4545
46- if (auto pBld = static_cast <BuildingClass*>(pBldType ->CreateObject (pHouse)))
46+ if (auto pBuilding = static_cast <BuildingClass*>(pBuildingType ->CreateObject (pHouse)))
4747 {
48- if (!pBld->ForceCreate (coord))
48+ // Set before unlimbo cause otherwise it will call BuildingClass::Place.
49+ pBuilding->QueueMission (Mission::Construction, false );
50+ pBuilding->NextMission ();
51+
52+ if (!pBuilding->ForceCreate (coord))
4953 {
50- pBld ->UnInit ();
54+ pBuilding ->UnInit ();
5155 }
5256 else
5357 {
54- if (bPlayBuildUp)
55- {
56- pBld->ForceMission (Mission::Construction);
57- }
58- else
58+ // Reset mission and build state if we're not going to play buildup afterwards.
59+ if (!playBuildup)
5960 {
60- pBld->EnterIdleMode (false , false );
61- pBld->Place (false );
61+ pBuilding->BeginMode (BStateType::Idle);
62+ pBuilding->QueueMission (Mission::Guard, false );
63+ pBuilding->NextMission ();
64+ pBuilding->Place (false ); // Manually call this now.
6265 }
6366
6467 if (SessionClass::IsCampaign () && !pHouse->IsControlledByHuman ())
65- pBld ->ShouldRebuild = pThis->Param4 > 0 ;
68+ pBuilding ->ShouldRebuild = pThis->Param4 > 0 ;
6669
67- bCreated = true ;
70+ created = true ;
6871 }
6972 }
7073
71- R->AL (bCreated );
74+ R->AL (created );
7275 return 0x6E42C1 ;
7376}
7477
0 commit comments