DayZ 1.24
Loading...
Searching...
No Matches
PluginTransmissionAgents.c
Go to the documentation of this file.
7
8class PluginTransmissionAgents extends PluginBase
9{
11 ref map<int, string> m_SimpleAgentList = new map<int, string>;
12 bool m_IsConstructed = false;
13
26
28 {
29 m_AgentList.Insert(agent.GetAgentType(), agent);
30 }
31
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
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
52 {
53 if (!m_IsConstructed)
54 {
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
67 {
68 target.RemoveAllAgents();
69 }
70
72 {
73 target.RemoveAgent(agent_id);
74 }
75
76
78 {
79 if (!m_AgentList.Get(agent_id)) return 0;
80 return m_AgentList.Get(agent_id).GetTransferabilityIn();
81 }
82
83
85 {
86 if (!m_AgentList.Get(agent_id)) return true;
87 return m_AgentList.Get(agent_id).GrowDuringAntibioticsAttack(player);
88 }
89
90
92 {
93 if (!m_AgentList.Get(agent_id)) return true;
94 return m_AgentList.Get(agent_id).GetDieOffSpeedEx(player);
95 }
96
98 {
99 if (!m_AgentList.Get(agent_id)) return true;
100 return m_AgentList.Get(agent_id).GetPotencyEx(player);
101 }
102
104 {
105 if (!m_AgentList.Get(agent_id)) return true;
106 return m_AgentList.Get(agent_id).GetInvasibilityEx(player);
107 }
108
109
111 {
112 if (!m_AgentList.Get(agent_id)) return 0;
113 return m_AgentList.Get(agent_id).GetAntiboticsResistance();
114 }
115
116
118 {
119 if (!m_AgentList.Get(agent_id)) return 0;
120 return m_AgentList.Get(agent_id).GetAntibioticsResistanceEx(player);
121 }
122
124 {
125 if (!m_AgentList.Get(agent_id)) return 0;
126 return m_AgentList.Get(agent_id).GetTransferabilityOut();
127 }
128
130 {
131 if (!m_AgentList.Get(agent_id)) return 0;
132 return m_AgentList.Get(agent_id).GetTransferabilityAirOut();
133 }
134 /*
135 float GetAgentChance( int agent_id )
136 {
137 return m_AgentList.Get(agent_id).GetChanceOfInfection();
138 }
139 */
141 {
142 if (!m_AgentList.Get(agent_id))
143 return 0;
144 return m_AgentList.Get(agent_id).GetInvasibility();
145 }
146
147
149 {
150 if (!m_AgentList.Get(agent_id))
151 return 0;
152 return m_AgentList.Get(agent_id).GetDigestibility();
153 }
154
156 {
157 if (!m_AgentList.Get(agent_id))
158 return 0;
159 return m_AgentList.Get(agent_id).GetDieOffSpeed();
160 }
161
163 {
164 if (!m_AgentList.Get(agent_id))
165 return 0;
166 return m_AgentList.Get(agent_id).GetPotency();
167 }
168
170 {
171 if (!m_AgentList.Get(agent_id)) return 0;
172 return m_AgentList.Get(agent_id).GetMaxCount();
173 }
174
175 /*
176 private float GetAgentInitialCount( int agent_id )
177 {
178 return m_AgentList.Get(agent_id).GetInitialCount();
179 }
180 */
181
182 /*
183 float GetImmunityResistance( int agent_id )
184 {
185 if( !m_AgentList.Get(agent_id) ) return 0;
186 return m_AgentList.Get(agent_id).GetImmunityResistance();
187 }
188 */
190 {
191 //Debug.Log("Transmitting agents for source: " +source.ToString()+", target: " +target.ToString(),"Agents");
192 int sourceAgents = agents;
193 int targetAgents;
194 if (!sourceAgents && source) sourceAgents = source.GetAgents(); //do not set sourceAgents again if already set
195 if (target) targetAgents = target.GetAgents();
196 float count = 0;
197
198 switch (pathway)
199 {
200 case AGT_INV_OUT: //item leaving inventory
201 break;
202
203 case AGT_INV_IN: //item entering inventory
204 break;
205
206 case AGT_UACTION_TOUCH: //player touched the item
207 //InjectAgents( source, targetAgents ,GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.GLOVES, player) );
208 break;
209
210 case AGT_WATER_POND:
211 //target.InsertAgent(eAgents.CHOLERA, dose_size);
212 InjectAgentsWithPlayer(target, eAgents.CHOLERA, 0, 1, InjectTypes.ITEM_TO_PLAYER);
213 break;
214
216 //InjectAgentsWithPlayer( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER );
218 break;
219
220 case AGT_UACTION_TO_PLAYER: //user action of a consumption, only from item to player
222 break;
223
224 case AGT_UACTION_TO_ITEM: //to transfer from the player to the consumed item
226 break;
227
228 case AGT_TRANSFER_COPY: //transferring liquid
230 break;
231
232 case AGT_ITEM_TO_FLESH: //transferring liquid
234 break;
235
241 float prot_level_target = Math.Max(prot_level_mask_target, prot_level_headgear_target);//find the bigger of the 2, TODO: should be improved
242 float prot_level_source = Math.Max(prot_level_mask_source, prot_level_headgear_source);//find the bigger of the 2, TODO: should be improved
245 break;
248
250 break;
251 }
252 return count;
253 }
254
255
260
262 {
263 if (target.IsItemBase())
264 {
266 ib_target.TransferAgents(agents);
267 }
268 }
269
271 protected void InjectAgentsWithPlayer(EntityAI target, int agents, float protection, int dose_size, int inject_type) //target,array_of_agents,protection_lvl
272 {
273 if (target && (agents != 0) && target.IsEntityAI())
274 {
276
277 for (int i = 0; i < bit_count; i++)
278 {
281 target.InsertAgent(agent_bit, dose_size);
282 }
283 }
284 }
285
287 protected void InjectAgentsWithPlayerCount(EntityAI target, int agents, float protection, int dose_size, int inject_type) //target,array_of_agents,protection_lvl
288 {
289 if (target && (agents != 0) && target.IsEntityAI())
290 {
292
293 for (int i = 0; i < bit_count; i++)
294 {
297 target.InsertAgent(agent_bit, count);
298 }
299 }
300 }
301
303 protected float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)//target,array_of_agents,protection_lvl
304 {
306 {
307 if (count > 0)
308 {
309 target.InsertAgent(agent, count);
310 return count;
311 }
312 }
313 return 0;
314 }
315
316 // !performance hog, avoid
318 {
319 int mask = 1;
320 for (int i = 0; i < BIT_INT_SIZE; i++)
321 {
322 if (mask & agents)
323 agents_out.Insert(mask);
324 mask = mask * 2;
325 }
326 }
327
328
329 static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter = true, int system = 0)
330 {
331 ItemBase attachment = ItemBase.Cast(player.GetInventory().FindAttachment(slot));
332
333 if (!attachment)
334 return 0;
335
336 return attachment.GetProtectionLevel(type, consider_filter, system);
337
338 }
339
340 protected float GetProtectionLevel(int type, int slot, Man player)
341 {
342 return GetProtectionLevelEx(type, slot, player);
343 }
344
345 //------------------------------------------------------------------------------------------------------
346
348 {
349
350 //Debug.Log("protection: "+protection.ToString());
351 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
352 //Debug.Log("prot: "+prot.ToString(), "Agents");
353 float transf;
354
355 if (inject_type == InjectTypes.PLAYER_TO_ITEM)
357 else if (inject_type == InjectTypes.ITEM_TO_PLAYER)
359 else if (inject_type == InjectTypes.PLAYER_AIR_PLAYER)
361
362 //Debug.Log("transf: "+transf.ToString(), "Agents");
363 //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
364 float result = 1 * prot * transf * dose_size;//final formula
365 //result = Math.Ceil(result);
366 //Debug.Log("result: "+result.ToString(), "Agents");
367 return result;
368 }
369
370 //------------------------------------------------------------------------------------------------------
372 {
373
374 //Debug.Log("protection: "+protection.ToString());
375 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
376 //Debug.Log("prot: "+prot.ToString(), "Agents");
377 float transf;
378
379 if (inject_type == InjectTypes.PLAYER_TO_ITEM)
381 else if (inject_type == InjectTypes.ITEM_TO_PLAYER)
383 else if (inject_type == InjectTypes.PLAYER_AIR_PLAYER)
385#ifdef DEVELOPER
386 //Debug.Log("transf: "+transf.ToString(), "Agents");
387#endif
388 //float result = GetAgentInitialCount(agent_id) * prot * transf * dose_size;//final formula
389 bool dice = Math.RandomFloat01() < (prot * transf);
390 //result = Math.Ceil(result);
391
392 return dice;
393 }
394 //------------------------------------------------------------------------------------------------------
395
396};
const int BIT_INT_SIZE
Definition BitArray.c:4
eAgents
Definition EAgents.c:3
EStatLevels
Definition EStatLevels.c:2
@ PLAYER_AIR_PLAYER
provides access to slot configuration
Definition EnMath.c:7
float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type)
will add agent to a given target
static int GetAgentMaxCount(int agent_id)
void RemoveAllAgents(EntityAI target)
static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter=true, int system=0)
map< int, string > GetSimpleAgentList()
float GetAgentInvasibilityEx(int agent_id, PlayerBase player)
float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, int inject_type)
bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type)
void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size=1000)
float GetAgentDigestibility(int agent_id)
float GetDieOffSpeed(int agent_id)
static void RemoveAgent(EntityAI target, int agent_id)
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
static ref map< int, ref AgentBase > m_AgentList
float GetAgentTransferabilityAirOut(int agent_id)
float GetAgentInvasibility(int agent_id)
EStatLevels GetPotency(int agent_id)
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...
void InjectAgentsWithoutPlayer(EntityAI target, int agents)
float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player)
float GetProtectionLevel(int type, int slot, Man player)
bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player)
static void BuildAgentArray(int agents, array< int > agents_out)
void RegisterAgent(AgentBase agent)
map< int, ref AgentBase > GetAgentList()
float GetAgentAntiboticsResistanceEx(int agent_id, PlayerBase player)
float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size=1000, int agents=0)
float GetAgentAntiboticsResistance(int agent_id)
EStatLevels GetAgentPotencyEx(int agent_id, PlayerBase player)
static string GetNameByID(int agent_id)
float GetAgentTransferabilityIn(int agent_id)
ref map< int, string > m_SimpleAgentList
float GetAgentTransferabilityOut(int agent_id)
const int AGT_UACTION_CONSUME
Definition constants.c:468
const int AGT_ITEM_TO_FLESH
Definition constants.c:475
const int AGT_UACTION_TOUCH
Definition constants.c:470
const int DEF_BIOLOGICAL
Definition constants.c:478
const int DEF_CHEMICAL
Definition constants.c:479
const int AGT_AIRBOURNE_BIOLOGICAL
Definition constants.c:472
const int AGT_TRANSFER_COPY
Definition constants.c:469
const int AGT_WATER_POND
Definition constants.c:471
const int AGT_INV_OUT
Definition constants.c:467
const int AGT_UACTION_TO_PLAYER
Definition constants.c:473
const int AGT_AIRBOURNE_CHEMICAL
Definition constants.c:476
const int AGT_UACTION_TO_ITEM
Definition constants.c:474
const int AGT_INV_IN
Definition constants.c:466
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition 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