|
enum InjectTypes |
|
{ |
|
PLAYER_TO_ITEM, |
|
ITEM_TO_PLAYER, |
|
PLAYER_AIR_PLAYER, |
|
}; |
|
|
|
class PluginTransmissionAgents extends PluginBase |
|
{ |
|
static ref map<int, ref AgentBase> m_AgentList = new map<int, ref AgentBase>; |
|
ref map<int, string> m_SimpleAgentList = new map<int, string>; |
|
bool m_IsConstructed = false; |
|
|
|
void PluginTransmissionAgents() |
|
{ |
|
|
|
RegisterAgent(new InfluenzaAgent); |
|
RegisterAgent(new CholeraAgent); |
|
RegisterAgent(new SalmonellaAgent); |
|
RegisterAgent(new BrainAgent); |
|
RegisterAgent(new FoodPoisonAgent); |
|
RegisterAgent(new ChemicalAgent); |
|
RegisterAgent(new WoundAgent); |
|
RegisterAgent(new NerveAgent); |
|
} |
|
|
|
void RegisterAgent(AgentBase agent) |
|
{ |
|
m_AgentList.Insert(agent.GetAgentType(), agent); |
|
} |
|
|
|
void ConstructSimpleAgentList() |
|
{ |
|
string agent_name; |
|
int agent_type; |
|
|
|
for(int i = 0; i < m_AgentList.Count();i++) |
|
{ |
|
AgentBase agent = m_AgentList.GetElement(i); |
|
agent_name = agent.GetName(); |
|
agent_type = agent.GetAgentType(); |
|
m_SimpleAgentList.Insert(agent_type, agent_name); |
|
} |
|
} |
|
|
|
map<int, ref AgentBase> GetAgentList() |
|
{ |
|
return m_AgentList; |
|
} |
|
|
|
map<int, string> GetSimpleAgentList() |
|
{ |
|
if( !m_IsConstructed ) |
|
{ |
|
ConstructSimpleAgentList(); |
|
m_IsConstructed = true; |
|
} |
|
return m_SimpleAgentList; |
|
} |
|
|
|
static string GetNameByID(int agent_id) |
|
{ |
|
return m_AgentList.Get(agent_id).GetName(); |
|
} |
|
|
|
void RemoveAllAgents(EntityAI target) |
|
{ |
|
target.RemoveAllAgents(); |
|
} |
|
|
|
static void RemoveAgent(EntityAI target, int agent_id ) |
|
{ |
|
target.RemoveAgent( agent_id ); |
|
} |
|
|
|
|
|
|
|
protected float GetAgentTransferabilityIn( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return 0; |
|
return m_AgentList.Get(agent_id).GetTransferabilityIn(); |
|
} |
|
|
|
|
|
bool GrowDuringAntibioticsAttack(int agent_id, PlayerBase player) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return true; |
|
return m_AgentList.Get(agent_id).GrowDuringAntibioticsAttack(player); |
|
} |
|
|
|
|
|
float GetAgentDieOffSpeedEx(int agent_id, PlayerBase player) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return true; |
|
return m_AgentList.Get(agent_id).GetDieOffSpeedEx(player); |
|
} |
|
|
|
EStatLevels GetAgentPotencyEx(int agent_id, PlayerBase player) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return true; |
|
return m_AgentList.Get(agent_id).GetPotencyEx(player); |
|
} |
|
|
|
float GetAgentInvasibilityEx(int agent_id, PlayerBase player) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return true; |
|
return m_AgentList.Get(agent_id).GetInvasibilityEx(player); |
|
} |
|
|
|
|
|
|
|
|
|
float GetAgentAntiboticsResistance( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return 0; |
|
return m_AgentList.Get(agent_id).GetAntiboticsResistance(); |
|
} |
|
|
|
|
|
float GetAgentAntiboticsResistanceEx( int agent_id , PlayerBase player) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return 0; |
|
return m_AgentList.Get(agent_id).GetAntibioticsResistanceEx(player); |
|
} |
|
|
|
protected float GetAgentTransferabilityOut( int agent_id ) |
|
{ |
|
if(!m_AgentList.Get(agent_id)) return 0; |
|
return m_AgentList.Get(agent_id).GetTransferabilityOut(); |
|
} |
|
|
|
protected float GetAgentTransferabilityAirOut( int agent_id ) |
|
{ |
|
if(!m_AgentList.Get(agent_id)) return 0; |
|
return m_AgentList.Get(agent_id).GetTransferabilityAirOut(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
float GetAgentInvasibility( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) |
|
return 0; |
|
return m_AgentList.Get(agent_id).GetInvasibility(); |
|
} |
|
|
|
|
|
float GetAgentDigestibility( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) |
|
return 0; |
|
return m_AgentList.Get(agent_id).GetDigestibility(); |
|
} |
|
|
|
float GetDieOffSpeed( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) |
|
return 0; |
|
return m_AgentList.Get(agent_id).GetDieOffSpeed(); |
|
} |
|
|
|
EStatLevels GetPotency( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) |
|
return 0; |
|
return m_AgentList.Get(agent_id).GetPotency(); |
|
} |
|
|
|
static int GetAgentMaxCount( int agent_id ) |
|
{ |
|
if( !m_AgentList.Get(agent_id) ) return 0; |
|
return m_AgentList.Get(agent_id).GetMaxCount(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float TransmitAgentsEx(EntityAI source, EntityAI target, int pathway, int dose_size = 1000, int agents = 0) |
|
{ |
|
|
|
int sourceAgents = agents; |
|
int targetAgents; |
|
if(!sourceAgents && source) sourceAgents = source.GetAgents(); |
|
if(target) targetAgents = target.GetAgents(); |
|
float count = 0; |
|
|
|
switch (pathway) |
|
{ |
|
case AGT_INV_OUT: |
|
break; |
|
|
|
case AGT_INV_IN: |
|
break; |
|
|
|
case AGT_UACTION_TOUCH: |
|
|
|
break; |
|
|
|
case AGT_WATER_POND: |
|
|
|
InjectAgentsWithPlayer( target, eAgents.CHOLERA , 0, 1, InjectTypes.ITEM_TO_PLAYER ); |
|
break; |
|
|
|
case AGT_UACTION_CONSUME: |
|
|
|
InjectAgentsWithPlayer( source, targetAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM ); |
|
break; |
|
|
|
case AGT_UACTION_TO_PLAYER: |
|
InjectAgentsWithPlayerCount( target, sourceAgents , 0, dose_size, InjectTypes.ITEM_TO_PLAYER ); |
|
break; |
|
|
|
case AGT_UACTION_TO_ITEM: |
|
InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.PLAYER_TO_ITEM ); |
|
break; |
|
|
|
case AGT_TRANSFER_COPY: |
|
InjectAgentsWithoutPlayer( target, sourceAgents ); |
|
break; |
|
|
|
case AGT_ITEM_TO_FLESH: |
|
InjectAgentsWithPlayer( target, sourceAgents , 0, 1, InjectTypes.ITEM_TO_PLAYER); |
|
break; |
|
|
|
case AGT_AIRBOURNE_BIOLOGICAL: |
|
float prot_level_mask_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( target )); |
|
float prot_level_mask_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.MASK, Man.Cast( source )); |
|
float prot_level_headgear_target = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( target )); |
|
float prot_level_headgear_source = GetProtectionLevel(DEF_BIOLOGICAL,InventorySlots.HEADGEAR, Man.Cast( source )); |
|
float prot_level_target = Math.Max(prot_level_mask_target, prot_level_headgear_target); |
|
float prot_level_source = Math.Max(prot_level_mask_source, prot_level_headgear_source); |
|
float prot_level_combined = 1 - (1 - prot_level_target) * (1 - prot_level_source); |
|
InjectAgentsWithPlayer( target, sourceAgents , prot_level_combined, 1, InjectTypes.PLAYER_AIR_PLAYER ); |
|
break; |
|
case AGT_AIRBOURNE_CHEMICAL: |
|
float prot_level_mask_target2 = GetProtectionLevel(DEF_CHEMICAL,InventorySlots.MASK, Man.Cast( target )); |
|
|
|
count = InjectAgentWithPlayerDose( target, agents , prot_level_mask_target2, dose_size, InjectTypes.PLAYER_AIR_PLAYER ); |
|
break; |
|
} |
|
return count; |
|
} |
|
|
|
|
|
void TransmitAgents(EntityAI source, EntityAI target, int pathway, int dose_size = 1000) |
|
{ |
|
TransmitAgentsEx(source, target, pathway, dose_size); |
|
} |
|
|
|
protected void InjectAgentsWithoutPlayer(EntityAI target, int agents) |
|
{ |
|
if( target.IsItemBase() ) |
|
{ |
|
ItemBase ib_target = ItemBase.Cast( target ); |
|
ib_target.TransferAgents(agents); |
|
} |
|
} |
|
|
|
|
|
protected void InjectAgentsWithPlayer(EntityAI target, int agents,float protection, int dose_size, int inject_type) |
|
{ |
|
if(target && (agents != 0) && target.IsEntityAI() ) |
|
{ |
|
int bit_count = Math.GetNumberOfSetBits(agents); |
|
|
|
for (int i = 0; i < bit_count; i++) |
|
{ |
|
int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i)); |
|
if( DetermineChanceToTransmit(agent_bit, protection, inject_type)) |
|
{ |
|
target.InsertAgent(agent_bit,dose_size); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
protected void InjectAgentsWithPlayerCount(EntityAI target, int agents,float protection, int dose_size, int inject_type) |
|
{ |
|
if(target && (agents != 0) && target.IsEntityAI() ) |
|
{ |
|
int bit_count = Math.GetNumberOfSetBits(agents); |
|
|
|
for (int i = 0; i < bit_count; i++) |
|
{ |
|
int agent_bit = Math.Pow(2,Math.GetNthBitSet(agents,i)); |
|
float count = CalculateAgentsToTransmit(agent_bit, protection, dose_size, inject_type); |
|
target.InsertAgent(agent_bit,count); |
|
} |
|
} |
|
} |
|
|
|
|
|
protected float InjectAgentWithPlayerDose(EntityAI target, int agent, float protection, float dose_size, int inject_type) |
|
{ |
|
float count = CalculateAgentsToTransmit(agent, protection, dose_size, inject_type); |
|
{ |
|
if(count > 0) |
|
{ |
|
target.InsertAgent(agent, count); |
|
return count; |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
|
|
static void BuildAgentArray(int agents, array<int> agents_out) |
|
{ |
|
int mask = 1; |
|
for(int i = 0; i < BIT_INT_SIZE; i++) |
|
{ |
|
if( mask & agents ) |
|
agents_out.Insert(mask); |
|
mask = mask * 2; |
|
} |
|
} |
|
|
|
|
|
static float GetProtectionLevelEx(int type, int slot, Man player, bool consider_filter = true, int system = 0) |
|
{ |
|
ItemBase attachment = ItemBase.Cast(player.GetInventory().FindAttachment(slot)); |
|
|
|
if(!attachment) |
|
return 0; |
|
|
|
return attachment.GetProtectionLevel(type, consider_filter, system); |
|
|
|
} |
|
|
|
protected float GetProtectionLevel(int type, int slot, Man player) |
|
{ |
|
return GetProtectionLevelEx(type, slot, player); |
|
} |
|
|
|
|
|
|
|
protected float CalculateAgentsToTransmit(int agent_id, float protection, int dose_size, int inject_type) |
|
{ |
|
|
|
|
|
float prot = 1 - protection; |
|
|
|
float transf; |
|
|
|
if( inject_type == InjectTypes.PLAYER_TO_ITEM ) |
|
{ |
|
transf = GetAgentTransferabilityOut(agent_id); |
|
} |
|
else if( inject_type == InjectTypes.ITEM_TO_PLAYER ) |
|
{ |
|
transf = GetAgentTransferabilityIn(agent_id); |
|
} |
|
else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER ) |
|
{ |
|
transf = GetAgentTransferabilityAirOut(agent_id); |
|
} |
|
|
|
|
|
|
|
float result = 1 * prot * transf * dose_size; |
|
|
|
|
|
return result; |
|
} |
|
|
|
|
|
protected bool DetermineChanceToTransmit(int agent_id, float protection, int inject_type) |
|
{ |
|
|
|
|
|
float prot = 1 - protection; |
|
|
|
float transf; |
|
|
|
if( inject_type == InjectTypes.PLAYER_TO_ITEM ) |
|
{ |
|
transf = GetAgentTransferabilityOut(agent_id); |
|
} |
|
else if( inject_type == InjectTypes.ITEM_TO_PLAYER ) |
|
{ |
|
transf = GetAgentTransferabilityIn(agent_id); |
|
} |
|
else if( inject_type == InjectTypes.PLAYER_AIR_PLAYER ) |
|
{ |
|
transf = GetAgentTransferabilityAirOut(agent_id); |
|
} |
|
#ifdef DEVELOPER |
|
|
|
#endif |
|
|
|
bool dice = Math.RandomFloat01() < (prot * transf); |
|
|
|
|
|
return dice; |
|
} |
|
|
|
|
|
}; |