Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
plugintransmissionagents.c
Go to the documentation of this file.
7
13class PluginTransmissionAgents extends PluginBase
14{
15 static ref map<int, ref AgentBase> m_AgentList = new map<int, ref AgentBase>();
16 ref map<int, string> m_SimpleAgentList = new map<int, string>;
17 bool m_IsConstructed = false;
18
19 void PluginTransmissionAgents()
20 {
21 //add new agents here
22 RegisterAgent(new InfluenzaAgent);
23 RegisterAgent(new CholeraAgent);
24 RegisterAgent(new SalmonellaAgent);
25 RegisterAgent(new BrainAgent);
26 RegisterAgent(new FoodPoisonAgent);
27 RegisterAgent(new ChemicalAgent);
28 RegisterAgent(new WoundAgent);
29 RegisterAgent(new NerveAgent);
30 RegisterAgent(new HeavyMetalAgent);
31 }
32
37 void RegisterAgent(AgentBase agent)
38 {
39 m_AgentList.Insert(agent.GetAgentType(), agent);
40 }
41
45 void ConstructSimpleAgentList()
46 {
47 string agent_name;
48 int agent_type;
49
50 for(int i = 0; i < m_AgentList.Count();i++)
51 {
52 AgentBase agent = m_AgentList.GetElement(i);
53 agent_name = agent.GetName();
54 agent_type = agent.GetAgentType();
55 m_SimpleAgentList.Insert(agent_type, agent_name);
56 }
57 }
58
63 map<int, ref AgentBase> GetAgentList()
64 {
65 return m_AgentList;
66 }
67
72 map<int, string> GetSimpleAgentList()
73 {
74 if( !m_IsConstructed )
75 {
76 ConstructSimpleAgentList();
77 m_IsConstructed = true;
78 }
79 return m_SimpleAgentList;
80 }
81
87 static string GetNameByID(int agent_id)
88 {
89 return m_AgentList.Get(agent_id).GetName();
90 }
91
96 void RemoveAllAgents(EntityAI target)
97 {
98 target.RemoveAllAgents();
99 }
100
106 static void RemoveAgent(EntityAI target, int agent_id)
107 {
108 target.RemoveAgent(agent_id);
109 }
110
116 protected float GetAgentTransferabilityIn(int agent_id)
117 {
118 if( !m_AgentList.Get(agent_id) ) return 0;
119 return m_AgentList.Get(agent_id).GetTransferabilityIn();
120 }
121
123 {
124 AgentBase agent = m_AgentList.Get(agentId);
125 if (!agent)
126 return true;
127
128 return agent.GrowDuringMedicalDrugsAttack(drugType, player);
129 }
130
134 float GetDieOffSpeed( int agent_id )
135 {
136 if( !m_AgentList.Get(agent_id) )
137 return 0;
138 return m_AgentList.Get(agent_id).GetDieOffSpeed();
139 }
140
147 float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
148 {
149 if( !m_AgentList.Get(agent_id) ) return true;
150 return m_AgentList.Get(agent_id).GetDieOffSpeedEx(player);
151 }
152
156 EStatLevels GetPotency( int agent_id )
157 {
158 if( !m_AgentList.Get(agent_id) )
159 return 0;
160 return m_AgentList.Get(agent_id).GetPotency();
161 }
162
170 {
171 if( !m_AgentList.Get(agent_id) ) return true;
172 return m_AgentList.Get(agent_id).GetPotencyEx(player);
173 }
174
181 float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
182 {
183 if( !m_AgentList.Get(agent_id) ) return true;
184 return m_AgentList.Get(agent_id).GetInvasibilityEx(player);
185 }
186
187
191 float GetAgentAntiboticsResistance( int agent_id )
192 {
193 if( !m_AgentList.Get(agent_id) ) return 0;
194 return m_AgentList.Get(agent_id).GetAntiboticsResistance();
195 }
196
203 float GetAgentAntiboticsResistanceEx( int agent_id , PlayerBase player)
204 {
205 if( !m_AgentList.Get(agent_id) ) return 0;
206 return m_AgentList.Get(agent_id).GetAntibioticsResistanceEx(player);
207 }
208
214 protected float GetAgentTransferabilityOut( int agent_id )
215 {
216 if(!m_AgentList.Get(agent_id)) return 0;
217 return m_AgentList.Get(agent_id).GetTransferabilityOut();
218 }
219
225 protected float GetAgentTransferabilityAirOut( int agent_id )
226 {
227 if(!m_AgentList.Get(agent_id)) return 0;
228 return m_AgentList.Get(agent_id).GetTransferabilityAirOut();
229 }
230
236 float GetAgentInvasibility( int agent_id )
237 {
238 if( !m_AgentList.Get(agent_id) )
239 return 0;
240 return m_AgentList.Get(agent_id).GetInvasibility();
241 }
242
246 float GetAgentDigestibility( int agent_id )
247 {
248 if( !m_AgentList.Get(agent_id) )
249 return 0;
250 return m_AgentList.Get(agent_id).GetDigestibility();
251 }
252
259 float GetAgentDigestibilityEx(int agent_id, PlayerBase player)
260 {
261 if (!m_AgentList.Get(agent_id))
262 return 0;
263
264 return m_AgentList.Get(agent_id).GetDigestibilityEx(player);
265 }
266
272 static int GetAgentMaxCount( int agent_id )
273 {
274 if( !m_AgentList.Get(agent_id) ) return 0;
275 return m_AgentList.Get(agent_id).GetMaxCount();
276 }
277
287 float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size = 1000, int agents = 0)
288 {
289 //Debug.Log("Transmitting agents for source: " +source.ToString()+", target: " +target.ToString(),"Agents");
290 int sourceAgents = agents;
291 int targetAgents;
292 if(!sourceAgents && source) sourceAgents = source.GetAgents();//do not set sourceAgents again if already set
293 if(target) targetAgents = target.GetAgents();
294 int pollution = GetGame().GetMission().GetWorldData().GetPollution();
295
296 float count = 0;
297
298 switch (pathway)
299 {
300 case AGT_INV_OUT: //item leaving inventory
301 break;
302
303 case AGT_INV_IN: //item entering inventory
304 break;
305
306 case AGT_UACTION_TOUCH: //player touched the item
307 //InjectAgents( source, targetAgents ,GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.GLOVES, player) );
308 break;
309
310 case AGT_WATER_POND:
311 if (pollution & EPollution.HEAVYMETAL)
312 {
313 sourceAgents = sourceAgents | eAgents.HEAVYMETAL;
314 }
315 sourceAgents = sourceAgents | eAgents.CHOLERA;
316 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER );
317 break;
318
320 sourceAgents = sourceAgents | eAgents.FOOD_POISON | eAgents.HEAVYMETAL;
321 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER );
322 break;
323
324 case AGT_SNOW:
325 if (pollution & EPollution.HEAVYMETAL)
326 {
327 sourceAgents = sourceAgents | eAgents.HEAVYMETAL;
328 }
329 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER );
330 break;
331
333 //InjectAgentsWithPlayer( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
334 InjectAgentsWithPlayer( source, targetAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM );
335 break;
336
337 case AGT_UACTION_TO_PLAYER: //user action of a consumption, only from item to player
338 InjectAgentsWithPlayerCount( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
339 break;
340
341 case AGT_UACTION_TO_ITEM: //to transfer from the player to the consumed item
342 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM );
343 break;
344
345 case AGT_TRANSFER_COPY: //transferring liquid
346 InjectAgentsWithoutPlayer( target, sourceAgents );
347 break;
348
349 case AGT_ITEM_TO_FLESH: //transferring liquid
350 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER);
351 break;
352
354 float prot_level_mask_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( target ));
355 float prot_level_mask_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( source ));
356 float prot_level_headgear_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( target ));
357 float prot_level_headgear_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( source ));
358 float prot_level_target = Math.Max(prot_level_mask_target, prot_level_headgear_target);//find the bigger of the 2, TODO: should be improved
359 float prot_level_source = Math.Max(prot_level_mask_source, prot_level_headgear_source);//find the bigger of the 2, TODO: should be improved
360 float prot_level_combined = 1 - (1 - prot_level_target) * (1 - prot_level_source);
361 InjectAgentsWithPlayer( target, sourceAgents , prot_level_combined, 1, InjectTypes.PLAYER_AIR_PLAYER );
362 break;
364 float prot_level_mask_target2 = GetProtectionLevel(DEF_CHEMICAL,InventorySlots.MASK, Man.Cast( target ));
365
366 count = InjectAgentWithPlayerDose( target, agents , prot_level_mask_target2, dose_size, InjectTypes.PLAYER_AIR_PLAYER );
367 break;
368 default:
369 break;
370 }
371 return count;
372 }
373
377 void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size = 1000)
378 {
379 TransmitAgentsEx(source, target, pathway, dose_size);
380 }
381
387 protected void InjectAgentsWithoutPlayer(EntityAI target, int agents)
388 {
389 if( target.IsItemBase() )
390 {
391 ItemBase ib_target = ItemBase.Cast( target );
392 ib_target.TransferAgents(agents);
393 }
394 }
395
404 protected void InjectAgentsWithPlayer(EntityAI target, int agents, float protection, int dose_size, int inject_type)//target,array_of_agents,protection_lvl
405 {
406 if(target && (agents != 0) && target.IsEntityAI() )
407 {
408 int bit_count = Math.GetNumberOfSetBits(agents);
409
410 for (int i = 0; i < bit_count; i++)
411 {
412 int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i));
413 if( DetermineChanceToTransmit(agent_bit, protection, inject_type))
414 {
415 target.InsertAgent(agent_bit,dose_size);
416 }
417 }
418 }
419 }
420
429 protected void InjectAgentsWithPlayerCount(EntityAI target, int agents, float protection, int dose_size, int inject_type)//target,array_of_agents,protection_lvl
430 {
431 if(target && (agents != 0) && target.IsEntityAI() )
432 {
433 int bit_count = Math.GetNumberOfSetBits(agents);
434
435 for (int i = 0; i < bit_count; i++)
436 {
437 int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i));
438 float count = CalculateAgentsToTransmit(agent_bit, protection, dose_size, inject_type);
439 target.InsertAgent(agent_bit,count);
440 }
441 }
442 }
443
453 protected float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)//target,array_of_agents,protection_lvl
454 {
455 float count = CalculateAgentsToTransmit(agent, protection, dose_size, inject_type);
456 {
457 if(count > 0)
458 {
459 target.InsertAgent(agent, count);
460 return count;
461 }
462 }
463 return 0;
464 }
465
466 // !performance hog, avoid
467 static void BuildAgentArray(int agents, array<int> agents_out)
468 {
469 int mask = 1;
470 for(int i = 0; i < BIT_INT_SIZE; i++)
471 {
472 if( mask & agents )
473 agents_out.Insert(mask);
474 mask = mask * 2;
475 }
476 }
477
487 static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter = true, int system = 0)
488 {
489 ItemBase attachment = ItemBase.Cast(player.GetInventory().FindAttachment(slot));
490
491 if(!attachment)
492 return 0;
493
494 return attachment.GetProtectionLevel(type, consider_filter, system);
495
496 }
497
501 protected float GetProtectionLevel(int type, int slot, Man player)
502 {
503 return GetProtectionLevelEx(type, slot, player);
504 }
505
506 //------------------------------------------------------------------------------------------------------
507
516 protected float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, int inject_type)
517 {
518
519 //Debug.Log("protection: "+protection.ToString());
520 //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
521 float prot = 1 - protection;
522 //Debug.Log("prot: "+prot.ToString(), "Agents");
523 float transf;
524
525 if( inject_type == InjectTypes.PLAYER_TO_ITEM )
526 {
527 transf = GetAgentTransferabilityOut(agent_id);
528 }
529 else if( inject_type == InjectTypes.ITEM_TO_PLAYER )
530 {
531 transf = GetAgentTransferabilityIn(agent_id);
532 }
533 else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER )
534 {
535 transf = GetAgentTransferabilityAirOut(agent_id);
536 }
537
538 //Debug.Log("transf: "+transf.ToString(), "Agents");
539 //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
540 float result = 1 * prot * transf * dose_size;//final formula
541 //result = Math.Ceil(result);
542 //Debug.Log("result: "+result.ToString(), "Agents");
543 return result;
544 }
545
546 //------------------------------------------------------------------------------------------------------
554 protected bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
555 {
556
557 //Debug.Log("protection: "+protection.ToString());
558 //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
559 float prot = 1 - protection;
560 //Debug.Log("prot: "+prot.ToString(), "Agents");
561 float transf;
562
563 if( inject_type == InjectTypes.PLAYER_TO_ITEM )
564 {
565 transf = GetAgentTransferabilityOut(agent_id);
566 }
567 else if( inject_type == InjectTypes.ITEM_TO_PLAYER )
568 {
569 transf = GetAgentTransferabilityIn(agent_id);
570 }
571 else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER )
572 {
573 transf = GetAgentTransferabilityAirOut(agent_id);
574 }
575 #ifdef DEVELOPER
576 //Debug.Log("transf: "+transf.ToString(), "Agents");
577 #endif
578 //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
579 bool dice = Math.RandomFloat01() < (prot * transf);
580 //result = Math.Ceil(result);
581
582 return dice;
583 }
584 //------------------------------------------------------------------------------------------------------
585
586
588 bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
589 {
590 if (!m_AgentList.Get(agent_id))
591 return true;
592
593 return m_AgentList.Get(agent_id).GrowDuringMedicalDrugsAttack(EMedicalDrugsType.ANTIBIOTICS, player);
594 }
595}
const int BIT_INT_SIZE
Definition bitarray.c:4
provides access to slot configuration
Definition enmath.c:7
Plugin interface for controlling of agent pool system.
Definition pluginbase.c:2
float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)
Injects agent to a given target.
bool GrowDuringMedicalDrugsAttack(int agentId, EMedicalDrugsType drugType, PlayerBase player)
static int GetAgentMaxCount(int agent_id)
Returns max count attribute for given agent.
static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter=true, int system=0)
Protection level of an attachment against enviromental hazard (mask/filters for example)
float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
Returns invasibility attribute for given agent.
float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, int inject_type)
Calculates number of agents that can be transmitted (based on given dose_size)
bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
Agent transmission chance processing.
void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size=1000)
Process transmission of agents between entities (for specified transmission type) (see TransmitAgents...
float GetAgentDigestibility(int agent_id)
Returns stomach digetibility attribute for given agent (see GetAgentDigestibilityEx())
float GetDieOffSpeed(int agent_id)
Returns dieOfSpeed attribute for given agent (see GetDieOffSpeedEx())
void InjectAgentsWithPlayer(EntityAI target, int agents, float protection, int dose_size, int inject_type)
Injects agents to a given target, using chance of transmission and full dose size if chance succeeds.
float GetAgentTransferabilityAirOut(int agent_id)
Returns transferabilitAiryOut attribute for given agent.
float GetAgentInvasibility(int agent_id)
Returns invasibility attribute for given agent.
EStatLevels GetPotency(int agent_id)
Returns potency attribute for given agent (see GetAgentPotencyEx())
void InjectAgentsWithPlayerCount(EntityAI target, int agents, float protection, int dose_size, int inject_type)
Injects agents to a given target, with no probability, but the dose size is modified by m_Transferabi...
void InjectAgentsWithoutPlayer(EntityAI target, int agents)
Injects specified agents directly to target.
float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
Returns dieOfSpeed attribute for given agent.
float GetProtectionLevel(int type, int slot, Man player)
Protection level of an attachment against enviromental hazard (mask/filters for example) (see GetProt...
float GetAgentDigestibilityEx(int agent_id, PlayerBase player)
Returns stomach digetibility attribute for given agent.
bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
DEPRECATED.
static void BuildAgentArray(int agents, array< int > agents_out)
float GetAgentAntiboticsResistanceEx(int agent_id, PlayerBase player)
Returns antibiotics resistance attribute for given agent.
float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size=1000, int agents=0)
Process transmission of agents between entities (for specified transmission type)
float GetAgentAntiboticsResistance(int agent_id)
Returns antibiotics resistance attribute for given agent see GetAgentAntiboticsResistanceEx()
EStatLevels GetAgentPotencyEx(int agent_id, PlayerBase player)
Returns potency attribute for given agent.
float GetAgentTransferabilityIn(int agent_id)
Returns transferabilityIn attribute for given agent.
float GetAgentTransferabilityOut(int agent_id)
Returns transferabilityOut attribute for given agent.
int GetPollution()
Definition worlddata.c:281
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
eAgents
Definition eagents.c:3
EMedicalDrugsType
EStatLevels
Definition estatlevels.c:2
proto native CGame GetGame()
const int AGT_UACTION_CONSUME
Definition constants.c:499
const int AGT_ITEM_TO_FLESH
Definition constants.c:506
const int AGT_UACTION_TOUCH
Definition constants.c:501
const int DEF_BIOLOGICAL
Definition constants.c:512
const int DEF_CHEMICAL
Definition constants.c:513
const int AGT_AIRBOURNE_BIOLOGICAL
Definition constants.c:503
const int AGT_TRANSFER_COPY
Definition constants.c:500
const int AGT_WATER_HOT_SPRING
Definition constants.c:510
const int AGT_WATER_POND
Definition constants.c:502
const int AGT_INV_OUT
Definition constants.c:498
const int AGT_UACTION_TO_PLAYER
Definition constants.c:504
const int AGT_AIRBOURNE_CHEMICAL
Definition constants.c:507
const int AGT_UACTION_TO_ITEM
Definition constants.c:505
const int AGT_SNOW
Definition constants.c:508
const int AGT_INV_IN
Definition constants.c:497
override void RemoveAllAgents()
Definition itembase.c:8785
override void RemoveAgent(int agent_id)
Definition itembase.c:8776
@ PLAYER_AIR_PLAYER