MCPcopy Create free account
hub / github.com/Phobos-developers/Phobos / TransferMindControlOnDeploy

Function TransferMindControlOnDeploy

src/Ext/Unit/Hooks.DeploysInto.cpp:8–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <Ext/WarheadType/Body.h>
7
8static void TransferMindControlOnDeploy(TechnoClass* pTechnoFrom, TechnoClass* pTechnoTo)
9{
10 auto pAnimType = pTechnoFrom->MindControlRingAnim ?
11 pTechnoFrom->MindControlRingAnim->Type : TechnoExt::ExtMap.Find(pTechnoFrom)->MindControlRingAnimType;
12
13 if (auto Controller = pTechnoFrom->MindControlledBy)
14 {
15 if (auto Manager = Controller->CaptureManager)
16 {
17 CaptureManagerExt::FreeUnit(Manager, pTechnoFrom, true);
18
19 if (CaptureManagerExt::CaptureUnit(Manager, pTechnoTo, false, pAnimType, true))
20 {
21 if (auto pBld = abstract_cast<BuildingClass*, true>(pTechnoTo))
22 {
23 // Capturing the building after unlimbo before buildup has finished or even started appears to throw certain things off,
24 // Hopefully this is enough to fix most of it like anims playing prematurely etc.
25 pBld->ActuallyPlacedOnMap = false;
26 pBld->DestroyNthAnim(BuildingAnimSlot::All);
27
28 pBld->BeginMode(BStateType::Construction);
29 pBld->QueueMission(Mission::Construction, false);
30 }
31 }
32 else
33 {
34 int nSound = pTechnoTo->GetTechnoType()->MindClearedSound;
35 if (nSound == -1)
36 nSound = RulesClass::Instance->MindClearedSound;
37
38 if (nSound != -1)
39 VocClass::PlayIndexAtPos(nSound, pTechnoTo->Location);
40 }
41 }
42 }
43 else if (auto MCHouse = pTechnoFrom->MindControlledByHouse)
44 {
45 pTechnoTo->MindControlledByHouse = MCHouse;
46 pTechnoFrom->MindControlledByHouse = nullptr;
47 }
48 else if (pTechnoFrom->MindControlledByAUnit) // Perma MC
49 {
50 pTechnoTo->MindControlledByAUnit = true;
51
52 auto const pBuilding = abstract_cast<BuildingClass*, true>(pTechnoTo);
53 CoordStruct location = pTechnoTo->GetCoords();
54
55 location.Z += pBuilding
56 ? pBuilding->Type->Height * Unsorted::LevelHeight
57 : pTechnoTo->GetTechnoType()->MindControlRingOffset;
58
59 auto const pAnim = pAnimType
60 ? GameCreate<AnimClass>(pAnimType, location, 0, 1)
61 : nullptr;
62
63 if (pAnim)
64 {
65 if (pBuilding)

Callers 1

Calls 2

GetTechnoTypeMethod · 0.80
FindMethod · 0.45

Tested by

no test coverage detected