Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
plugintransmissionagents.c
Go to the documentation of this file.
2 {
6 };
7 
8 class PluginTransmissionAgents extends PluginBase
9 {
10  static ref map<int, ref AgentBase> m_AgentList = new map<int, ref AgentBase>;
11  ref map<int, string> m_SimpleAgentList = new map<int, string>;
12  bool m_IsConstructed = false;
13 
14  void PluginTransmissionAgents()
15  {
16  //add new agents here
17  RegisterAgent(new InfluenzaAgent);
18  RegisterAgent(new CholeraAgent);
19  RegisterAgent(new SalmonellaAgent);
20  RegisterAgent(new BrainAgent);
21  RegisterAgent(new FoodPoisonAgent);
22  RegisterAgent(new ChemicalAgent);
23  RegisterAgent(new WoundAgent);
24  RegisterAgent(new NerveAgent);
25  }
26 
27  void RegisterAgent(AgentBase agent)
28  {
29  m_AgentList.Insert(agent.GetAgentType(), agent);
30  }
31 
32  void ConstructSimpleAgentList()
33  {
34  string agent_name;
35  int agent_type;
36 
37  for(int i = 0; i < m_AgentList.Count();i++)
38  {
39  AgentBase agent = m_AgentList.GetElement(i);
40  agent_name = agent.GetName();
41  agent_type = agent.GetAgentType();
42  m_SimpleAgentList.Insert(agent_type, agent_name);
43  }
44  }
45 
46  map<int, ref AgentBase> GetAgentList()
47  {
48  return m_AgentList;
49  }
50  // this is a list which is easy to work with for displaying all agents and interacting with them, it doesn't serve any gameplay purpose
51  map<int, string> GetSimpleAgentList()
52  {
53  if( !m_IsConstructed )
54  {
55  ConstructSimpleAgentList();
56  m_IsConstructed = true;
57  }
58  return m_SimpleAgentList;
59  }
60 
61  static string GetNameByID(int agent_id)
62  {
63  return m_AgentList.Get(agent_id).GetName();
64  }
65 
66  void RemoveAllAgents(EntityAI target)
67  {
68  target.RemoveAllAgents();
69  }
70 
71  static void RemoveAgent(EntityAI target, int agent_id )
72  {
73  target.RemoveAgent( agent_id );
74  }
75 
76 
77 
78  protected float GetAgentTransferabilityIn( int agent_id )
79  {
80  if( !m_AgentList.Get(agent_id) ) return 0;
81  return m_AgentList.Get(agent_id).GetTransferabilityIn();
82  }
83 
84 
85  bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
86  {
87  if( !m_AgentList.Get(agent_id) ) return true;
88  return m_AgentList.Get(agent_id).GrowDuringAntibioticsAttack(player);
89  }
90 
91 
92  float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
93  {
94  if( !m_AgentList.Get(agent_id) ) return true;
95  return m_AgentList.Get(agent_id).GetDieOffSpeedEx(player);
96  }
97 
98  EStatLevels GetAgentPotencyEx(int agent_id, PlayerBase player)
99  {
100  if( !m_AgentList.Get(agent_id) ) return true;
101  return m_AgentList.Get(agent_id).GetPotencyEx(player);
102  }
103 
104  float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
105  {
106  if( !m_AgentList.Get(agent_id) ) return true;
107  return m_AgentList.Get(agent_id).GetInvasibilityEx(player);
108  }
109 
110 
111 
112 
113  float GetAgentAntiboticsResistance( int agent_id )
114  {
115  if( !m_AgentList.Get(agent_id) ) return 0;
116  return m_AgentList.Get(agent_id).GetAntiboticsResistance();
117  }
118 
119 
120  float GetAgentAntiboticsResistanceEx( int agent_id , PlayerBase player)
121  {
122  if( !m_AgentList.Get(agent_id) ) return 0;
123  return m_AgentList.Get(agent_id).GetAntibioticsResistanceEx(player);
124  }
125 
126  protected float GetAgentTransferabilityOut( int agent_id )
127  {
128  if(!m_AgentList.Get(agent_id)) return 0;
129  return m_AgentList.Get(agent_id).GetTransferabilityOut();
130  }
131 
132  protected float GetAgentTransferabilityAirOut( int agent_id )
133  {
134  if(!m_AgentList.Get(agent_id)) return 0;
135  return m_AgentList.Get(agent_id).GetTransferabilityAirOut();
136  }
137  /*
138  float GetAgentChance( int agent_id )
139  {
140  return m_AgentList.Get(agent_id).GetChanceOfInfection();
141  }
142  */
143  float GetAgentInvasibility( int agent_id )
144  {
145  if( !m_AgentList.Get(agent_id) )
146  return 0;
147  return m_AgentList.Get(agent_id).GetInvasibility();
148  }
149 
150 
151  float GetAgentDigestibility( int agent_id )
152  {
153  if( !m_AgentList.Get(agent_id) )
154  return 0;
155  return m_AgentList.Get(agent_id).GetDigestibility();
156  }
157 
158  float GetDieOffSpeed( int agent_id )
159  {
160  if( !m_AgentList.Get(agent_id) )
161  return 0;
162  return m_AgentList.Get(agent_id).GetDieOffSpeed();
163  }
164 
165  EStatLevels GetPotency( int agent_id )
166  {
167  if( !m_AgentList.Get(agent_id) )
168  return 0;
169  return m_AgentList.Get(agent_id).GetPotency();
170  }
171 
172  static int GetAgentMaxCount( int agent_id )
173  {
174  if( !m_AgentList.Get(agent_id) ) return 0;
175  return m_AgentList.Get(agent_id).GetMaxCount();
176  }
177 
178  /*
179  private float GetAgentInitialCount( int agent_id )
180  {
181  return m_AgentList.Get(agent_id).GetInitialCount();
182  }
183  */
184 
185  /*
186  float GetImmunityResistance( int agent_id )
187  {
188  if( !m_AgentList.Get(agent_id) ) return 0;
189  return m_AgentList.Get(agent_id).GetImmunityResistance();
190  }
191  */
192  float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size = 1000, int agents = 0)
193  {
194  //Debug.Log("Transmitting agents for source: " +source.ToString()+", target: " +target.ToString(),"Agents");
195  int sourceAgents = agents;
196  int targetAgents;
197  if(!sourceAgents && source) sourceAgents = source.GetAgents();//do not set sourceAgents again if already set
198  if(target) targetAgents = target.GetAgents();
199  float count = 0;
200 
201  switch (pathway)
202  {
203  case AGT_INV_OUT: //item leaving inventory
204  break;
205 
206  case AGT_INV_IN: //item entering inventory
207  break;
208 
209  case AGT_UACTION_TOUCH: //player touched the item
210  //InjectAgents( source, targetAgents ,GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.GLOVES, player) );
211  break;
212 
213  case AGT_WATER_POND:
214  //target.InsertAgent(eAgents.CHOLERA, dose_size);
215  InjectAgentsWithPlayer( target, eAgents.CHOLERA , 0, 1, InjectTypes.ITEM_TO_PLAYER );
216  break;
217 
218  case AGT_UACTION_CONSUME:
219  //InjectAgentsWithPlayer( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
220  InjectAgentsWithPlayer( source, targetAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM );
221  break;
222 
223  case AGT_UACTION_TO_PLAYER: //user action of a consumption, only from item to player
224  InjectAgentsWithPlayerCount( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
225  break;
226 
227  case AGT_UACTION_TO_ITEM: //to transfer from the player to the consumed item
228  InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM );
229  break;
230 
231  case AGT_TRANSFER_COPY: //transferring liquid
232  InjectAgentsWithoutPlayer( target, sourceAgents );
233  break;
234 
235  case AGT_ITEM_TO_FLESH: //transferring liquid
236  InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER);
237  break;
238 
240  float prot_level_mask_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( target ));
241  float prot_level_mask_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( source ));
242  float prot_level_headgear_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( target ));
243  float prot_level_headgear_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( source ));
244  float prot_level_target = Math.Max(prot_level_mask_target, prot_level_headgear_target);//find the bigger of the 2, TODO: should be improved
245  float prot_level_source = Math.Max(prot_level_mask_source, prot_level_headgear_source);//find the bigger of the 2, TODO: should be improved
246  float prot_level_combined = 1 - (1 - prot_level_target) * (1 - prot_level_source);
247  InjectAgentsWithPlayer( target, sourceAgents , prot_level_combined, 1, InjectTypes.PLAYER_AIR_PLAYER );
248  break;
250  float prot_level_mask_target2 = GetProtectionLevel(DEF_CHEMICAL,InventorySlots.MASK, Man.Cast( target ));
251 
252  count = InjectAgentWithPlayerDose( target, agents , prot_level_mask_target2, dose_size, InjectTypes.PLAYER_AIR_PLAYER );
253  break;
254  }
255  return count;
256  }
257 
258 
259  void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size = 1000)
260  {
261  TransmitAgentsEx(source, target, pathway, dose_size);
262  }
263 
264  protected void InjectAgentsWithoutPlayer(EntityAI target, int agents)
265  {
266  if( target.IsItemBase() )
267  {
268  ItemBase ib_target = ItemBase.Cast( target );
269  ib_target.TransferAgents(agents);
270  }
271  }
272 
274  protected void InjectAgentsWithPlayer(EntityAI target, int agents,float protection, int dose_size, int inject_type)//target,array_of_agents,protection_lvl
275  {
276  if(target && (agents != 0) && target.IsEntityAI() )
277  {
278  int bit_count = Math.GetNumberOfSetBits(agents);
279 
280  for (int i = 0; i < bit_count; i++)
281  {
282  int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i));
283  if( DetermineChanceToTransmit(agent_bit, protection, inject_type))
284  {
285  target.InsertAgent(agent_bit,dose_size);
286  }
287  }
288  }
289  }
290 
292  protected void InjectAgentsWithPlayerCount(EntityAI target, int agents,float protection, int dose_size, int inject_type)//target,array_of_agents,protection_lvl
293  {
294  if(target && (agents != 0) && target.IsEntityAI() )
295  {
296  int bit_count = Math.GetNumberOfSetBits(agents);
297 
298  for (int i = 0; i < bit_count; i++)
299  {
300  int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i));
301  float count = CalculateAgentsToTransmit(agent_bit, protection, dose_size, inject_type);
302  target.InsertAgent(agent_bit,count);
303  }
304  }
305  }
306 
308  protected float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)//target,array_of_agents,protection_lvl
309  {
310  float count = CalculateAgentsToTransmit(agent, protection, dose_size, inject_type);
311  {
312  if(count > 0)
313  {
314  target.InsertAgent(agent, count);
315  return count;
316  }
317  }
318  return 0;
319  }
320 
321  // !performance hog, avoid
322  static void BuildAgentArray(int agents, array<int> agents_out)
323  {
324  int mask = 1;
325  for(int i = 0; i < BIT_INT_SIZE; i++)
326  {
327  if( mask & agents )
328  agents_out.Insert(mask);
329  mask = mask * 2;
330  }
331  }
332 
333 
334  static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter = true, int system = 0)
335  {
336  ItemBase attachment = ItemBase.Cast(player.GetInventory().FindAttachment(slot));
337 
338  if(!attachment)
339  return 0;
340 
341  return attachment.GetProtectionLevel(type, consider_filter, system);
342 
343  }
344 
345  protected float GetProtectionLevel(int type, int slot, Man player)
346  {
347  return GetProtectionLevelEx(type, slot, player);
348  }
349 
350  //------------------------------------------------------------------------------------------------------
351 
352  protected float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, int inject_type)
353  {
354 
355  //Debug.Log("protection: "+protection.ToString());
356  float prot = 1 - protection; //reverse the value (in config, the higher the value, the higher the protection: 0 - 1) so that we can easily interpolate between 0 and 1 by multiplication
357  //Debug.Log("prot: "+prot.ToString(), "Agents");
358  float transf;
359 
360  if( inject_type == InjectTypes.PLAYER_TO_ITEM )
361  {
362  transf = GetAgentTransferabilityOut(agent_id);
363  }
364  else if( inject_type == InjectTypes.ITEM_TO_PLAYER )
365  {
366  transf = GetAgentTransferabilityIn(agent_id);
367  }
368  else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER )
369  {
370  transf = GetAgentTransferabilityAirOut(agent_id);
371  }
372 
373  //Debug.Log("transf: "+transf.ToString(), "Agents");
374  //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
375  float result = 1 * prot * transf * dose_size;//final formula
376  //result = Math.Ceil(result);
377  //Debug.Log("result: "+result.ToString(), "Agents");
378  return result;
379  }
380 
381  //------------------------------------------------------------------------------------------------------
382  protected bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
383  {
384 
385  //Debug.Log("protection: "+protection.ToString());
386  float prot = 1 - protection; //reverse the value (in config, the higher the value, the higher the protection: 0 - 1) so that we can easily interpolate between 0 and 1 by multiplication
387  //Debug.Log("prot: "+prot.ToString(), "Agents");
388  float transf;
389 
390  if( inject_type == InjectTypes.PLAYER_TO_ITEM )
391  {
392  transf = GetAgentTransferabilityOut(agent_id);
393  }
394  else if( inject_type == InjectTypes.ITEM_TO_PLAYER )
395  {
396  transf = GetAgentTransferabilityIn(agent_id);
397  }
398  else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER )
399  {
400  transf = GetAgentTransferabilityAirOut(agent_id);
401  }
402  #ifdef DEVELOPER
403  //Debug.Log("transf: "+transf.ToString(), "Agents");
404  #endif
405  //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
406  bool dice = Math.RandomFloat01() < (prot * transf);
407  //result = Math.Ceil(result);
408 
409  return dice;
410  }
411  //------------------------------------------------------------------------------------------------------
412 
413 };
ItemBase
Definition: inventoryitem.c:730
RemoveAgent
override void RemoveAgent(int agent_id)
Definition: itembase.c:3841
AGT_UACTION_TO_PLAYER
const int AGT_UACTION_TO_PLAYER
Definition: constants.c:473
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
PLAYER_TO_ITEM
@ PLAYER_TO_ITEM
Definition: plugintransmissionagents.c:3
AGT_UACTION_TO_ITEM
const int AGT_UACTION_TO_ITEM
Definition: constants.c:474
ITEM_TO_PLAYER
@ ITEM_TO_PLAYER
Definition: plugintransmissionagents.c:4
PLAYER_AIR_PLAYER
@ PLAYER_AIR_PLAYER
Definition: plugintransmissionagents.c:5
PluginBase
Definition: pluginadminlog.c:1
AGT_ITEM_TO_FLESH
const int AGT_ITEM_TO_FLESH
Definition: constants.c:475
RemoveAllAgents
override void RemoveAllAgents()
Definition: itembase.c:3850
AGT_TRANSFER_COPY
const int AGT_TRANSFER_COPY
Definition: constants.c:469
AGT_AIRBOURNE_CHEMICAL
const int AGT_AIRBOURNE_CHEMICAL
Definition: constants.c:476
InjectTypes
InjectTypes
Definition: plugintransmissionagents.c:1
AGT_UACTION_TOUCH
const int AGT_UACTION_TOUCH
Definition: constants.c:470
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
eAgents
eAgents
Definition: eagents.c:2
AGT_INV_IN
const int AGT_INV_IN
Definition: constants.c:466
DEF_BIOLOGICAL
const int DEF_BIOLOGICAL
Definition: constants.c:478
GetProtectionLevel
float GetProtectionLevel(int type, bool consider_filter=false, int system=0)
Definition: itembase.c:3938
AgentBase
Definition: brainagent.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
AGT_INV_OUT
const int AGT_INV_OUT
Definition: constants.c:467
AGT_UACTION_CONSUME
const int AGT_UACTION_CONSUME
Definition: constants.c:468
EStatLevels
EStatLevels
Definition: estatlevels.c:1
DEF_CHEMICAL
const int DEF_CHEMICAL
Definition: constants.c:479
AGT_AIRBOURNE_BIOLOGICAL
const int AGT_AIRBOURNE_BIOLOGICAL
Definition: constants.c:472
Math
Definition: enmath.c:6
BIT_INT_SIZE
const int BIT_INT_SIZE
Definition: bitarray.c:4
AGT_WATER_POND
const int AGT_WATER_POND
Definition: constants.c:471
EntityAI
Definition: building.c:5