DayZ 1.28
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PluginTransmissionAgents.c
См. документацию.
7
13class PluginTransmissionAgents extends PluginBase
14{
17 bool m_IsConstructed = false;
18
20 {
21 //add new agents here
23 RegisterAgent(new CholeraAgent);
24 RegisterAgent(new SalmonellaAgent);
25 RegisterAgent(new BrainAgent);
27 RegisterAgent(new ChemicalAgent);
29 RegisterAgent(new NerveAgent);
31 }
32
38 {
39 m_AgentList.Insert(agent.GetAgentType(), agent);
40 }
41
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
67
81
87 static string GetNameByID(int agent_id)
88 {
89 return m_AgentList.Get(agent_id).GetName();
90 }
91
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
Определения BitArray.c:4
map
Определения ControlsXboxNew.c:4
eAgents
Определения EAgents.c:3
EMedicalDrugsType
Определения EMedicalDrugsType.c:2
EStatLevels
Определения EStatLevels.c:2
InjectTypes
Определения PluginTransmissionAgents.c:2
@ PLAYER_AIR_PLAYER
Определения PluginTransmissionAgents.c:5
@ PLAYER_TO_ITEM
Определения PluginTransmissionAgents.c:3
@ ITEM_TO_PLAYER
Определения PluginTransmissionAgents.c:4
int GetAgentType()
Определения AgentBase.c:24
bool GrowDuringMedicalDrugsAttack(EMedicalDrugsType drugType, PlayerBase player)
should this agent grow based on invasibility even during usage of specific medical drugs attack
Определения AgentBase.c:74
string GetName()
Определения AgentBase.c:132
Определения AgentBase.c:2
proto native Mission GetMission()
Определения FoodPoisonAgent.c:2
Определения HeavyMetalAgent.c:2
Определения InfluenzaAgent.c:2
provides access to slot configuration
Определения InventorySlots.c:6
Определения EnMath.c:7
WorldData GetWorldData()
Определения gameplay.c:743
Определения PlayerBaseClient.c:2
float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)
Injects agent to a given target.
Определения PluginTransmissionAgents.c:453
bool GrowDuringMedicalDrugsAttack(int agentId, EMedicalDrugsType drugType, PlayerBase player)
Определения PluginTransmissionAgents.c:122
static int GetAgentMaxCount(int agent_id)
Returns max count attribute for given agent.
Определения PluginTransmissionAgents.c:272
void RemoveAllAgents(EntityAI target)
Removes all agents from given entity.
Определения PluginTransmissionAgents.c:96
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)
Определения PluginTransmissionAgents.c:487
map< int, string > GetSimpleAgentList()
Returns map of all registered agents in simplified format(for non-gameplay purposas mainly)
Определения PluginTransmissionAgents.c:72
float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
Returns invasibility attribute for given agent.
Определения PluginTransmissionAgents.c:181
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)
Определения PluginTransmissionAgents.c:516
void ConstructSimpleAgentList()
Builds simplified list of agents in <id, name> format.
Определения PluginTransmissionAgents.c:45
bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
Agent transmission chance processing.
Определения PluginTransmissionAgents.c:554
void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size=1000)
Process transmission of agents between entities (for specified transmission type) (see TransmitAgents...
Определения PluginTransmissionAgents.c:377
float GetAgentDigestibility(int agent_id)
Returns stomach digetibility attribute for given agent (see GetAgentDigestibilityEx())
Определения PluginTransmissionAgents.c:246
float GetDieOffSpeed(int agent_id)
Returns dieOfSpeed attribute for given agent (see GetDieOffSpeedEx())
Определения PluginTransmissionAgents.c:134
static void RemoveAgent(EntityAI target, int agent_id)
Removes given agent from given entity.
Определения PluginTransmissionAgents.c:106
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.
Определения PluginTransmissionAgents.c:404
static ref map< int, ref AgentBase > m_AgentList
Определения PluginTransmissionAgents.c:15
float GetAgentTransferabilityAirOut(int agent_id)
Returns transferabilitAiryOut attribute for given agent.
Определения PluginTransmissionAgents.c:225
float GetAgentInvasibility(int agent_id)
Returns invasibility attribute for given agent.
Определения PluginTransmissionAgents.c:236
EStatLevels GetPotency(int agent_id)
Returns potency attribute for given agent (see GetAgentPotencyEx())
Определения PluginTransmissionAgents.c:156
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...
Определения PluginTransmissionAgents.c:429
void InjectAgentsWithoutPlayer(EntityAI target, int agents)
Injects specified agents directly to target.
Определения PluginTransmissionAgents.c:387
float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
Returns dieOfSpeed attribute for given agent.
Определения PluginTransmissionAgents.c:147
bool m_IsConstructed
simple <eAgents, agentName> pair
Определения PluginTransmissionAgents.c:17
float GetProtectionLevel(int type, int slot, Man player)
Protection level of an attachment against enviromental hazard (mask/filters for example) (see GetProt...
Определения PluginTransmissionAgents.c:501
float GetAgentDigestibilityEx(int agent_id, PlayerBase player)
Returns stomach digetibility attribute for given agent.
Определения PluginTransmissionAgents.c:259
bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
DEPRECATED.
Определения PluginTransmissionAgents.c:588
static void BuildAgentArray(int agents, array< int > agents_out)
Определения PluginTransmissionAgents.c:467
void RegisterAgent(AgentBase agent)
Registers new agent into system.
Определения PluginTransmissionAgents.c:37
map< int, ref AgentBase > GetAgentList()
Returns map of all registered agent classes.
Определения PluginTransmissionAgents.c:63
float GetAgentAntiboticsResistanceEx(int agent_id, PlayerBase player)
Returns antibiotics resistance attribute for given agent.
Определения PluginTransmissionAgents.c:203
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)
Определения PluginTransmissionAgents.c:287
float GetAgentAntiboticsResistance(int agent_id)
Returns antibiotics resistance attribute for given agent see GetAgentAntiboticsResistanceEx()
Определения PluginTransmissionAgents.c:191
EStatLevels GetAgentPotencyEx(int agent_id, PlayerBase player)
Returns potency attribute for given agent.
Определения PluginTransmissionAgents.c:169
void PluginTransmissionAgents()
Определения PluginTransmissionAgents.c:19
static string GetNameByID(int agent_id)
Returns agent's name from given id.
Определения PluginTransmissionAgents.c:87
float GetAgentTransferabilityIn(int agent_id)
Returns transferabilityIn attribute for given agent.
Определения PluginTransmissionAgents.c:116
ref map< int, string > m_SimpleAgentList
Определения PluginTransmissionAgents.c:16
float GetAgentTransferabilityOut(int agent_id)
Returns transferabilityOut attribute for given agent.
Определения PluginTransmissionAgents.c:214
Plugin interface for controlling of agent pool system.
Определения PluginBase.c:2
int GetPollution()
Определения WorldData.c:281
Определения WoundAgent.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
const int AGT_UACTION_CONSUME
Определения 3_Game/constants.c:499
const int AGT_ITEM_TO_FLESH
Определения 3_Game/constants.c:506
const int AGT_UACTION_TOUCH
Определения 3_Game/constants.c:501
const int DEF_BIOLOGICAL
Определения 3_Game/constants.c:512
const int DEF_CHEMICAL
Определения 3_Game/constants.c:513
const int AGT_AIRBOURNE_BIOLOGICAL
Определения 3_Game/constants.c:503
const int AGT_TRANSFER_COPY
Определения 3_Game/constants.c:500
const int AGT_WATER_HOT_SPRING
Определения 3_Game/constants.c:510
const int AGT_WATER_POND
Определения 3_Game/constants.c:502
const int AGT_INV_OUT
Определения 3_Game/constants.c:498
const int AGT_UACTION_TO_PLAYER
Определения 3_Game/constants.c:504
const int AGT_AIRBOURNE_CHEMICAL
Определения 3_Game/constants.c:507
const int AGT_UACTION_TO_ITEM
Определения 3_Game/constants.c:505
const int AGT_SNOW
Определения 3_Game/constants.c:508
const int AGT_INV_IN
Определения 3_Game/constants.c:497
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:126
static proto float Max(float x, float y)
Returns bigger of two given values.
static proto int GetNthBitSet(int value, int n)
returns the the index of n-th bit set in a bit mask counting from the right, for instance,...
static proto float Pow(float v, float power)
Return power of v ^ power.
static proto int GetNumberOfSetBits(int i)
returns the number of bits set in a bitmask i