DayZ 1.24
Loading...
Searching...
No Matches
RemotelyActivatedItemBehaviour Class Reference
Collaboration diagram for RemotelyActivatedItemBehaviour:
[legend]

Protected Member Functions

void RemotelyActivatedItemBehaviour (notnull EntityAI pParent)
 
void ~RemotelyActivatedItemBehaviour ()
 
void SetTrigger ()
 
void OnVariableSynchronized ()
 
void OnStoreSave (ParamsWriteContext ctx)
 
bool OnStoreLoad (ParamsReadContext ctx, int version)
 
void OnAfterLoad ()
 
void SetPersistentPairID (int id)
 
void Pair ()
 
void Pair (notnull EntityAI device)
 
void Unpair ()
 
EntityAI GetPairDevice ()
 
bool IsPaired ()
 
void SetPairDeviceNetIds (notnull EntityAI device)
 
int GetPairDeviceNetIdLow ()
 
int GetPairDeviceNetIdHigh ()
 

Static Protected Member Functions

static int GeneratePersistentID ()
 

Protected Attributes

EntityAI m_Parent
 
bool m_IsTrigger
 
EntityAI m_PairDevice
 
int m_PairDeviceNetIdLow
 
int m_PairDeviceNetIdHigh
 
int m_PersistentPairID = int.MIN
 

Static Protected Attributes

static ref map< int, EntityAIm_RemoteReceivers = new map<int, EntityAI>()
 

Detailed Description

Definition at line 1 of file RemotelyActivatedItemBehaviour.c.

Constructor & Destructor Documentation

◆ RemotelyActivatedItemBehaviour()

void RemotelyActivatedItemBehaviour::RemotelyActivatedItemBehaviour ( notnull EntityAI pParent)
inlineprotected

◆ ~RemotelyActivatedItemBehaviour()

void RemotelyActivatedItemBehaviour::~RemotelyActivatedItemBehaviour ( )
inlineprotected

Definition at line 20 of file RemotelyActivatedItemBehaviour.c.

References m_Parent, and Unpair().

Member Function Documentation

◆ GeneratePersistentID()

static int RemotelyActivatedItemBehaviour::GeneratePersistentID ( )
inlinestaticprotected

Definition at line 81 of file RemotelyActivatedItemBehaviour.c.

82 {
83 int randomID = Math.RandomInt(0, int.MAX);
84 if (m_RemoteReceivers.Contains(randomID))
85 {
86 //it's very unlikely to have a collision here, but lets handle it anyway
87 return GeneratePersistentID();
88 }
89 else
90 return randomID;
91 }
const int MAX
Definition EnConvert.c:27
Definition EnMath.c:7
static ref map< int, EntityAI > m_RemoteReceivers
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].

References GeneratePersistentID(), m_RemoteReceivers, MAX, and Math::RandomInt().

Referenced by GeneratePersistentID(), and InventoryItem::PairWithDevice().

◆ GetPairDevice()

EntityAI RemotelyActivatedItemBehaviour::GetPairDevice ( )
inlineprotected

Definition at line 141 of file RemotelyActivatedItemBehaviour.c.

References m_PairDevice.

◆ GetPairDeviceNetIdHigh()

int RemotelyActivatedItemBehaviour::GetPairDeviceNetIdHigh ( )
inlineprotected

Definition at line 161 of file RemotelyActivatedItemBehaviour.c.

162 {
164 }

References m_PairDeviceNetIdHigh.

Referenced by Pair().

◆ GetPairDeviceNetIdLow()

int RemotelyActivatedItemBehaviour::GetPairDeviceNetIdLow ( )
inlineprotected

Definition at line 156 of file RemotelyActivatedItemBehaviour.c.

157 {
159 }

References m_PairDeviceNetIdLow.

Referenced by Pair().

◆ IsPaired()

bool RemotelyActivatedItemBehaviour::IsPaired ( )
inlineprotected

Definition at line 146 of file RemotelyActivatedItemBehaviour.c.

147 {
148 return m_PairDevice != null;
149 }

References m_PairDevice.

◆ OnAfterLoad()

void RemotelyActivatedItemBehaviour::OnAfterLoad ( )
inlineprotected

Definition at line 63 of file RemotelyActivatedItemBehaviour.c.

64 {
66 {
68 if (receiver)
69 {
70 //if both the receiver and trigger are somewhere in the world outside of the player inventory, there is no guarantee
71 //that the pairing is going to be succesful during the 'OnStoreLoad' event as that requires the receiver to already be loaded when the trigger is being loaded
72 //therefore, it's necessary to also perform pairing in this event, which happens at the end of the storage loading process
73 //do note that this event is not called when the entity is being loaded as part of the player inventory, therefore, we need to pair both in 'OnStoreLoad' and here to handle both situations
74 //(when the trigger is in the player's inventory, it always loads correctly after the receiver, which is always in the world)
76 }
77 }
78 }
const int MIN
Definition EnConvert.c:28

References m_IsTrigger, m_PairDevice, m_PersistentPairID, m_RemoteReceivers, MIN, and Pair().

◆ OnStoreLoad()

bool RemotelyActivatedItemBehaviour::OnStoreLoad ( ParamsReadContext ctx,
int version )
inlineprotected

Definition at line 41 of file RemotelyActivatedItemBehaviour.c.

42 {
43 if (!ctx.Read(m_PersistentPairID))
44 return false;
45
46 if (m_PersistentPairID == int.MIN)//default value, no point in going further
47 return true;
48
49 if (m_IsTrigger)//trigger
50 {
52 if (receiver)
54 }
55 else // remotely controlled device
56 {
57 m_RemoteReceivers.Insert(m_PersistentPairID, m_Parent);//receivers will register themselves upon being loaded from the storage
58 }
59
60 return true;
61 }

References m_IsTrigger, m_Parent, m_PersistentPairID, m_RemoteReceivers, MIN, and Pair().

◆ OnStoreSave()

void RemotelyActivatedItemBehaviour::OnStoreSave ( ParamsWriteContext ctx)
inlineprotected

Definition at line 36 of file RemotelyActivatedItemBehaviour.c.

37 {
39 }

References m_PersistentPairID.

◆ OnVariableSynchronized()

void RemotelyActivatedItemBehaviour::OnVariableSynchronized ( )
inlineprotected

Definition at line 31 of file RemotelyActivatedItemBehaviour.c.

32 {
33 Pair();
34 }

References Pair().

◆ Pair() [1/2]

void RemotelyActivatedItemBehaviour::Pair ( )
inlineprotected

◆ Pair() [2/2]

void RemotelyActivatedItemBehaviour::Pair ( notnull EntityAI device)
inlineprotected

Definition at line 108 of file RemotelyActivatedItemBehaviour.c.

109 {
112
113 if (device != m_Parent && (!m_Parent.GetPairDevice() || m_Parent.GetPairDevice() != m_PairDevice))
114 m_PairDevice.PairRemote(m_Parent);
115
116 m_PairDevice.SetSynchDirty();
117 m_Parent.SetSynchDirty();
118 }
void SetPairDeviceNetIds(notnull EntityAI device)

References m_PairDevice, m_Parent, and SetPairDeviceNetIds().

◆ SetPairDeviceNetIds()

void RemotelyActivatedItemBehaviour::SetPairDeviceNetIds ( notnull EntityAI device)
inlineprotected

Definition at line 151 of file RemotelyActivatedItemBehaviour.c.

152 {
154 }

References m_PairDeviceNetIdHigh, and m_PairDeviceNetIdLow.

Referenced by Pair().

◆ SetPersistentPairID()

void RemotelyActivatedItemBehaviour::SetPersistentPairID ( int id)
inlineprotected

Definition at line 93 of file RemotelyActivatedItemBehaviour.c.

94 {
96
97 if (!m_IsTrigger)
98 m_RemoteReceivers.Insert(id, m_Parent);
99 }

References m_IsTrigger, m_Parent, m_PersistentPairID, and m_RemoteReceivers.

◆ SetTrigger()

void RemotelyActivatedItemBehaviour::SetTrigger ( )
inlineprotected

Definition at line 26 of file RemotelyActivatedItemBehaviour.c.

27 {
28 m_IsTrigger = true;
29 }

References m_IsTrigger.

◆ Unpair()

void RemotelyActivatedItemBehaviour::Unpair ( )
inlineprotected

Definition at line 120 of file RemotelyActivatedItemBehaviour.c.

121 {
124
125 if (m_PairDevice)
126 {
127 m_PairDevice.SetSynchDirty();
129 }
130
131 if (m_PersistentPairID != int.MIN)
132 {
135 }
136
137 m_PersistentPairID = int.MIN;
138 m_Parent.SetSynchDirty();
139 }

References m_PairDevice, m_PairDeviceNetIdHigh, m_PairDeviceNetIdLow, m_Parent, m_PersistentPairID, m_RemoteReceivers, and MIN.

Referenced by ~RemotelyActivatedItemBehaviour().

Member Data Documentation

◆ m_IsTrigger

bool RemotelyActivatedItemBehaviour::m_IsTrigger
protected

◆ m_PairDevice

EntityAI RemotelyActivatedItemBehaviour::m_PairDevice
protected

Definition at line 5 of file RemotelyActivatedItemBehaviour.c.

Referenced by GetPairDevice(), IsPaired(), OnAfterLoad(), Pair(), and Unpair().

◆ m_PairDeviceNetIdHigh

int RemotelyActivatedItemBehaviour::m_PairDeviceNetIdHigh
protected

◆ m_PairDeviceNetIdLow

int RemotelyActivatedItemBehaviour::m_PairDeviceNetIdLow
protected

◆ m_Parent

EntityAI RemotelyActivatedItemBehaviour::m_Parent
protected

◆ m_PersistentPairID

int RemotelyActivatedItemBehaviour::m_PersistentPairID = int.MIN
protected

◆ m_RemoteReceivers

ref map<int, EntityAI> RemotelyActivatedItemBehaviour::m_RemoteReceivers = new map<int, EntityAI>()
staticprotected

The documentation for this class was generated from the following file: