DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PluginTransmissionAgents.c
См. документацию.
7
8class PluginTransmissionAgents extends PluginBase
9{
12 bool m_IsConstructed = false;
13
15 {
16 //add new agents here
18 RegisterAgent(new CholeraAgent);
19 RegisterAgent(new SalmonellaAgent);
20 RegisterAgent(new BrainAgent);
22 RegisterAgent(new ChemicalAgent);
24 RegisterAgent(new NerveAgent);
26 }
27
29 {
30 m_AgentList.Insert(agent.GetAgentType(), agent);
31 }
32
34 {
35 string agent_name;
36 int agent_type;
37
38 for(int i = 0; i < m_AgentList.Count();i++)
39 {
40 AgentBase agent = m_AgentList.GetElement(i);
41 agent_name = agent.GetName();
42 agent_type = agent.GetAgentType();
43 m_SimpleAgentList.Insert(agent_type, agent_name);
44 }
45 }
46
51 // 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
61
62 static string GetNameByID(int agent_id)
63 {
64 return m_AgentList.Get(agent_id).GetName();
65 }
66
68 {
69 target.RemoveAllAgents();
70 }
71
72 static void RemoveAgent(EntityAI target, int agent_id )
73 {
74 target.RemoveAgent( agent_id );
75 }
76
77
78
79 protected float GetAgentTransferabilityIn( int agent_id )
80 {
81 if( !m_AgentList.Get(agent_id) ) return 0;
82 return m_AgentList.Get(agent_id).GetTransferabilityIn();
83 }
84
85 bool GrowDuringMedicalDrugsAttack(int agentId, EMedicalDrugsType drugType, PlayerBase player)
86 {
87 AgentBase agent = m_AgentList.Get(agentId);
88 if (!agent)
89 return true;
90
91 return agent.GrowDuringMedicalDrugsAttack(drugType, player);
92 }
93
94 float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
95 {
96 if( !m_AgentList.Get(agent_id) ) return true;
97 return m_AgentList.Get(agent_id).GetDieOffSpeedEx(player);
98 }
99
101 {
102 if( !m_AgentList.Get(agent_id) ) return true;
103 return m_AgentList.Get(agent_id).GetPotencyEx(player);
104 }
105
106 float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
107 {
108 if( !m_AgentList.Get(agent_id) ) return true;
109 return m_AgentList.Get(agent_id).GetInvasibilityEx(player);
110 }
111
112
113
114
115 float GetAgentAntiboticsResistance( int agent_id )
116 {
117 if( !m_AgentList.Get(agent_id) ) return 0;
118 return m_AgentList.Get(agent_id).GetAntiboticsResistance();
119 }
120
121
122 float GetAgentAntiboticsResistanceEx( int agent_id , PlayerBase player)
123 {
124 if( !m_AgentList.Get(agent_id) ) return 0;
125 return m_AgentList.Get(agent_id).GetAntibioticsResistanceEx(player);
126 }
127
128 protected float GetAgentTransferabilityOut( int agent_id )
129 {
130 if(!m_AgentList.Get(agent_id)) return 0;
131 return m_AgentList.Get(agent_id).GetTransferabilityOut();
132 }
133
134 protected float GetAgentTransferabilityAirOut( int agent_id )
135 {
136 if(!m_AgentList.Get(agent_id)) return 0;
137 return m_AgentList.Get(agent_id).GetTransferabilityAirOut();
138 }
139 /*
140 float GetAgentChance( int agent_id )
141 {
142 return m_AgentList.Get(agent_id).GetChanceOfInfection();
143 }
144 */
145 float GetAgentInvasibility( int agent_id )
146 {
147 if( !m_AgentList.Get(agent_id) )
148 return 0;
149 return m_AgentList.Get(agent_id).GetInvasibility();
150 }
151
152 float GetAgentDigestibilityEx(int agent_id, PlayerBase player)
153 {
154 if (!m_AgentList.Get(agent_id))
155 return 0;
156
157 return m_AgentList.Get(agent_id).GetDigestibilityEx(player);
158 }
159
160 float GetAgentDigestibility( int agent_id )
161 {
162 if( !m_AgentList.Get(agent_id) )
163 return 0;
164 return m_AgentList.Get(agent_id).GetDigestibility();
165 }
166
167 float GetDieOffSpeed( int agent_id )
168 {
169 if( !m_AgentList.Get(agent_id) )
170 return 0;
171 return m_AgentList.Get(agent_id).GetDieOffSpeed();
172 }
173
174 EStatLevels GetPotency( int agent_id )
175 {
176 if( !m_AgentList.Get(agent_id) )
177 return 0;
178 return m_AgentList.Get(agent_id).GetPotency();
179 }
180
181 static int GetAgentMaxCount( int agent_id )
182 {
183 if( !m_AgentList.Get(agent_id) ) return 0;
184 return m_AgentList.Get(agent_id).GetMaxCount();
185 }
186
187 /*
188 private float GetAgentInitialCount( int agent_id )
189 {
190 return m_AgentList.Get(agent_id).GetInitialCount();
191 }
192 */
193
194 /*
195 float GetImmunityResistance( int agent_id )
196 {
197 if( !m_AgentList.Get(agent_id) ) return 0;
198 return m_AgentList.Get(agent_id).GetImmunityResistance();
199 }
200 */
201 float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size = 1000, int agents = 0)
202 {
203 //Debug.Log("Transmitting agents for source: " +source.ToString()+", target: " +target.ToString(),"Agents");
204 int sourceAgents = agents;
205 int targetAgents;
206 if(!sourceAgents && source) sourceAgents = source.GetAgents();//do not set sourceAgents again if already set
207 if(target) targetAgents = target.GetAgents();
208 int pollution = GetGame().GetMission().GetWorldData().GetPollution();
209
210 float count = 0;
211
212 switch (pathway)
213 {
214 case AGT_INV_OUT: //item leaving inventory
215 break;
216
217 case AGT_INV_IN: //item entering inventory
218 break;
219
220 case AGT_UACTION_TOUCH: //player touched the item
221 //InjectAgents( source, targetAgents ,GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.GLOVES, player) );
222 break;
223
224 case AGT_WATER_POND:
225 if (pollution & EPollution.HEAVYMETAL)
226 {
227 sourceAgents = sourceAgents | eAgents.HEAVYMETAL;
228 }
229 sourceAgents = sourceAgents | eAgents.CHOLERA;
230 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER );
231 break;
232
234 sourceAgents = sourceAgents | eAgents.FOOD_POISON | eAgents.HEAVYMETAL;
235 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER );
236 break;
237
238 case AGT_SNOW:
239 if (pollution & EPollution.HEAVYMETAL)
240 {
241 sourceAgents = sourceAgents | eAgents.HEAVYMETAL;
242 }
243 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER );
244 break;
245
247 //InjectAgentsWithPlayer( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
248 InjectAgentsWithPlayer( source, targetAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM );
249 break;
250
251 case AGT_UACTION_TO_PLAYER: //user action of a consumption, only from item to player
252 InjectAgentsWithPlayerCount( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
253 break;
254
255 case AGT_UACTION_TO_ITEM: //to transfer from the player to the consumed item
256 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM );
257 break;
258
259 case AGT_TRANSFER_COPY: //transferring liquid
260 InjectAgentsWithoutPlayer( target, sourceAgents );
261 break;
262
263 case AGT_ITEM_TO_FLESH: //transferring liquid
264 InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER);
265 break;
266
268 float prot_level_mask_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( target ));
269 float prot_level_mask_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( source ));
270 float prot_level_headgear_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( target ));
271 float prot_level_headgear_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( source ));
272 float prot_level_target = Math.Max(prot_level_mask_target, prot_level_headgear_target);//find the bigger of the 2, TODO: should be improved
273 float prot_level_source = Math.Max(prot_level_mask_source, prot_level_headgear_source);//find the bigger of the 2, TODO: should be improved
274 float prot_level_combined = 1 - (1 - prot_level_target) * (1 - prot_level_source);
275 InjectAgentsWithPlayer( target, sourceAgents , prot_level_combined, 1, InjectTypes.PLAYER_AIR_PLAYER );
276 break;
278 float prot_level_mask_target2 = GetProtectionLevel(DEF_CHEMICAL,InventorySlots.MASK, Man.Cast( target ));
279
280 count = InjectAgentWithPlayerDose( target, agents , prot_level_mask_target2, dose_size, InjectTypes.PLAYER_AIR_PLAYER );
281 break;
282 default:
283 break;
284 }
285 return count;
286 }
287
288
289 void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size = 1000)
290 {
291 TransmitAgentsEx(source, target, pathway, dose_size);
292 }
293
294 protected void InjectAgentsWithoutPlayer(EntityAI target, int agents)
295 {
296 if( target.IsItemBase() )
297 {
298 ItemBase ib_target = ItemBase.Cast( target );
299 ib_target.TransferAgents(agents);
300 }
301 }
302
304 protected void InjectAgentsWithPlayer(EntityAI target, int agents,float protection, int dose_size, int inject_type)//target,array_of_agents,protection_lvl
305 {
306 if(target && (agents != 0) && target.IsEntityAI() )
307 {
308 int bit_count = Math.GetNumberOfSetBits(agents);
309
310 for (int i = 0; i < bit_count; i++)
311 {
312 int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i));
313 if( DetermineChanceToTransmit(agent_bit, protection, inject_type))
314 {
315 target.InsertAgent(agent_bit,dose_size);
316 }
317 }
318 }
319 }
320
322 protected void InjectAgentsWithPlayerCount(EntityAI target, int agents,float protection, int dose_size, int inject_type)//target,array_of_agents,protection_lvl
323 {
324 if(target && (agents != 0) && target.IsEntityAI() )
325 {
326 int bit_count = Math.GetNumberOfSetBits(agents);
327
328 for (int i = 0; i < bit_count; i++)
329 {
330 int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i));
331 float count = CalculateAgentsToTransmit(agent_bit, protection, dose_size, inject_type);
332 target.InsertAgent(agent_bit,count);
333 }
334 }
335 }
336
338 protected float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)//target,array_of_agents,protection_lvl
339 {
340 float count = CalculateAgentsToTransmit(agent, protection, dose_size, inject_type);
341 {
342 if(count > 0)
343 {
344 target.InsertAgent(agent, count);
345 return count;
346 }
347 }
348 return 0;
349 }
350
351 // !performance hog, avoid
352 static void BuildAgentArray(int agents, array<int> agents_out)
353 {
354 int mask = 1;
355 for(int i = 0; i < BIT_INT_SIZE; i++)
356 {
357 if( mask & agents )
358 agents_out.Insert(mask);
359 mask = mask * 2;
360 }
361 }
362
363
364 static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter = true, int system = 0)
365 {
366 ItemBase attachment = ItemBase.Cast(player.GetInventory().FindAttachment(slot));
367
368 if(!attachment)
369 return 0;
370
371 return attachment.GetProtectionLevel(type, consider_filter, system);
372
373 }
374
375 protected float GetProtectionLevel(int type, int slot, Man player)
376 {
377 return GetProtectionLevelEx(type, slot, player);
378 }
379
380 //------------------------------------------------------------------------------------------------------
381
382 protected float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, 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
403 //Debug.Log("transf: "+transf.ToString(), "Agents");
404 //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
405 float result = 1 * prot * transf * dose_size;//final formula
406 //result = Math.Ceil(result);
407 //Debug.Log("result: "+result.ToString(), "Agents");
408 return result;
409 }
410
411 //------------------------------------------------------------------------------------------------------
412 protected bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
413 {
414
415 //Debug.Log("protection: "+protection.ToString());
416 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
417 //Debug.Log("prot: "+prot.ToString(), "Agents");
418 float transf;
419
420 if( inject_type == InjectTypes.PLAYER_TO_ITEM )
421 {
422 transf = GetAgentTransferabilityOut(agent_id);
423 }
424 else if( inject_type == InjectTypes.ITEM_TO_PLAYER )
425 {
426 transf = GetAgentTransferabilityIn(agent_id);
427 }
428 else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER )
429 {
430 transf = GetAgentTransferabilityAirOut(agent_id);
431 }
432 #ifdef DEVELOPER
433 //Debug.Log("transf: "+transf.ToString(), "Agents");
434 #endif
435 //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
436 bool dice = Math.RandomFloat01() < (prot * transf);
437 //result = Math.Ceil(result);
438
439 return dice;
440 }
441 //------------------------------------------------------------------------------------------------------
442
443
445 bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
446 {
447 if (!m_AgentList.Get(agent_id))
448 return true;
449
450 return m_AgentList.Get(agent_id).GrowDuringMedicalDrugsAttack(EMedicalDrugsType.ANTIBIOTICS, player);
451 }
452}
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()
Определения Building.c:6
Определения FoodPoisonAgent.c:2
Определения HeavyMetalAgent.c:2
Определения InfluenzaAgent.c:2
provides access to slot configuration
Определения InventorySlots.c:6
Определения InventoryItem.c:731
Определения 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)
will add agent to a given target
Определения PluginTransmissionAgents.c:338
bool GrowDuringMedicalDrugsAttack(int agentId, EMedicalDrugsType drugType, PlayerBase player)
Определения PluginTransmissionAgents.c:85
static int GetAgentMaxCount(int agent_id)
Определения PluginTransmissionAgents.c:181
void RemoveAllAgents(EntityAI target)
Определения PluginTransmissionAgents.c:67
static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter=true, int system=0)
Определения PluginTransmissionAgents.c:364
map< int, string > GetSimpleAgentList()
Определения PluginTransmissionAgents.c:52
float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
Определения PluginTransmissionAgents.c:106
float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, int inject_type)
Определения PluginTransmissionAgents.c:382
void ConstructSimpleAgentList()
Определения PluginTransmissionAgents.c:33
bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
Определения PluginTransmissionAgents.c:412
void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size=1000)
Определения PluginTransmissionAgents.c:289
float GetAgentDigestibility(int agent_id)
Определения PluginTransmissionAgents.c:160
float GetDieOffSpeed(int agent_id)
Определения PluginTransmissionAgents.c:167
static void RemoveAgent(EntityAI target, int agent_id)
Определения PluginTransmissionAgents.c:72
void InjectAgentsWithPlayer(EntityAI target, int agents, float protection, int dose_size, int inject_type)
will add agents to a given target, using chance of transmission and full dose size if chance succeeds
Определения PluginTransmissionAgents.c:304
static ref map< int, ref AgentBase > m_AgentList
Определения PluginTransmissionAgents.c:10
float GetAgentTransferabilityAirOut(int agent_id)
Определения PluginTransmissionAgents.c:134
float GetAgentInvasibility(int agent_id)
Определения PluginTransmissionAgents.c:145
EStatLevels GetPotency(int agent_id)
Определения PluginTransmissionAgents.c:174
void InjectAgentsWithPlayerCount(EntityAI target, int agents, float protection, int dose_size, int inject_type)
will add agents to a given target, with no probability, but the dose size is modified by m_Transferab...
Определения PluginTransmissionAgents.c:322
void InjectAgentsWithoutPlayer(EntityAI target, int agents)
Определения PluginTransmissionAgents.c:294
float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
Определения PluginTransmissionAgents.c:94
bool m_IsConstructed
Определения PluginTransmissionAgents.c:12
float GetProtectionLevel(int type, int slot, Man player)
Определения PluginTransmissionAgents.c:375
float GetAgentDigestibilityEx(int agent_id, PlayerBase player)
Определения PluginTransmissionAgents.c:152
bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
DEPRECATED.
Определения PluginTransmissionAgents.c:445
static void BuildAgentArray(int agents, array< int > agents_out)
Определения PluginTransmissionAgents.c:352
void RegisterAgent(AgentBase agent)
Определения PluginTransmissionAgents.c:28
map< int, ref AgentBase > GetAgentList()
Определения PluginTransmissionAgents.c:47
float GetAgentAntiboticsResistanceEx(int agent_id, PlayerBase player)
Определения PluginTransmissionAgents.c:122
float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size=1000, int agents=0)
Определения PluginTransmissionAgents.c:201
float GetAgentAntiboticsResistance(int agent_id)
Определения PluginTransmissionAgents.c:115
EStatLevels GetAgentPotencyEx(int agent_id, PlayerBase player)
Определения PluginTransmissionAgents.c:100
void PluginTransmissionAgents()
Определения PluginTransmissionAgents.c:14
static string GetNameByID(int agent_id)
Определения PluginTransmissionAgents.c:62
float GetAgentTransferabilityIn(int agent_id)
Определения PluginTransmissionAgents.c:79
ref map< int, string > m_SimpleAgentList
Определения PluginTransmissionAgents.c:11
float GetAgentTransferabilityOut(int agent_id)
Определения PluginTransmissionAgents.c:128
Определения 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
Определения constants.c:497
const int AGT_ITEM_TO_FLESH
Определения constants.c:504
const int AGT_UACTION_TOUCH
Определения constants.c:499
const int DEF_BIOLOGICAL
Определения constants.c:510
const int DEF_CHEMICAL
Определения constants.c:511
const int AGT_AIRBOURNE_BIOLOGICAL
Определения constants.c:501
const int AGT_TRANSFER_COPY
Определения constants.c:498
const int AGT_WATER_HOT_SPRING
Определения constants.c:508
const int AGT_WATER_POND
Определения constants.c:500
const int AGT_INV_OUT
Определения constants.c:496
const int AGT_UACTION_TO_PLAYER
Определения constants.c:502
const int AGT_AIRBOURNE_CHEMICAL
Определения constants.c:505
const int AGT_UACTION_TO_ITEM
Определения constants.c:503
const int AGT_SNOW
Определения constants.c:506
const int AGT_INV_IN
Определения constants.c:495
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