DayZ 1.24
Loading...
Searching...
No Matches
PlayerAgentPool.c
Go to the documentation of this file.
2{
5 float m_LastTicked = 0;
9
10 const int STORAGE_VERSION = 100;
11
12 PluginTransmissionAgents m_PluginTransmissionAgents = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
13
18
20 {
21
22 }
23
25 {
26 return STORAGE_VERSION;
27 }
28
30 {
31 if (m_VirusPool)
32 {
33 for (int i = 0; i < m_VirusPool.Count(); i++)
34 {
35 Debug.Log("Agent: " + m_VirusPool.GetKey(i).ToString(), "Agents");
36 Debug.Log("Count: " + m_VirusPool.GetElement(i).ToString(), "Agents");
37 }
38
39 }
40 }
41
42 void ImmuneSystemTick(float value, float deltaT)//this is a regular tick induced in the the player's immune system
43 {
46 }
47
48 void GrowAgents(float deltaT)
49 {
50 if (!IsPluginManagerExists()) //check if modules are running
51 return;
52
53 EStatLevels immunity_level = m_Player.GetImmunityLevel();
54
56 for (int i = 0; i < m_VirusPool.Count(); i++)
57 {
58 int agent_id = m_VirusPool.GetKey(i);
59 int max_count = m_PluginTransmissionAgents.GetAgentMaxCount(agent_id);
60
62
63 float grow_delta;
64
66 {
67 bool grow_during_antibiotics = m_PluginTransmissionAgents.GrowDuringAntibioticsAttack(agent_id, m_Player);
68 if (m_Player.IsAntibioticsActive() && !grow_during_antibiotics)
69 continue;
70 float invasibility = m_PluginTransmissionAgents.GetAgentInvasibilityEx(agent_id, m_Player);
72 }
73 else
74 {
75 float dieoff_speed = m_PluginTransmissionAgents.GetAgentDieOffSpeedEx(agent_id, m_Player);
77 }
78
79 //Print( agent_id );
80 //Print( grow_delta );
81
82 float old_count = m_VirusPool.Get(agent_id);
85
88 }
89 }
90
92 {
93 //Debug.Log("PlayerAgentPool OnStoreSave called", "Agents");
94
95 ctx.Write(m_VirusPool.Count());
96 for (int i = 0; i < m_VirusPool.Count(); i++)
97 {
98 int key = m_VirusPool.GetKey(i);
99 int value = m_VirusPool.GetElement(i);
100 ctx.Write(key);
101 ctx.Write(value);
102 }
103 }
104
106 {
107 //Debug.Log("PlayerAgentPool OnStoreLoad called", "Agents");
108 int count;
109
110 if (!ctx.Read(count))
111 return false;
112
113 for (int i = 0; i < count; i++)
114 {
115 int key;
116 int value;
117 if (!ctx.Read(key))
118 return false;
119
120 if (!ctx.Read(value))
121 return false;
122
124 }
125
126 return true;
127 }
128 void DigestAgent(int agent_id, float count)
129 {
130 AddAgent(agent_id, m_PluginTransmissionAgents.GetAgentDigestibility(agent_id) * count);
131 }
132
133 void AddAgent(int agent_id, float count)
134 {
135 int max_count = m_PluginTransmissionAgents.GetAgentMaxCount(agent_id);
136
137 if (!m_VirusPool.Contains(agent_id) && count > 0) //if it contains, maybe add count only ?
138 {
139 //m_VirusPool.Insert( agent_id, Math.Clamp(count,0,max_count) );
141 }
142 else
143 {
144 float new_value = m_VirusPool.Get(agent_id) + count;
145 //Print(new_value);
147 }
148 }
149
150 /*
151 void RemoveAgent(int agent_id)
152 {
153 if( m_VirusPool.Contains(agent_id) )
154 {
155 m_VirusPool.Remove( agent_id );
156 }
157 }
158 */
160 {
162 }
163
165 {
166 m_AgentMask = 0;
167 m_VirusPool.Clear();
168 }
169
170 /*
171 array<int GetAgents()
172 {
173 m_VirusPoolArray.Clear();
174
175 for(int i = 0; i < m_VirusPool.Count();i++)
176 {
177 m_VirusPoolArray.Insert( m_VirusPool.GetKey(i) );
178 }
179
180 return m_VirusPoolArray;
181 }
182 */
183
185 {
186 return m_AgentMask;
187 }
188
190 {
191 if (m_VirusPool.Contains(agent_id))
192 return m_VirusPool.Get(agent_id);
193 else return 0;
194 }
195
197 {
198 float agent_count;
199 for (int i = 0; i < m_VirusPool.Count(); i++)
200 agent_count += m_VirusPool.GetElement(i);
201 return agent_count;
202 }
203
204 void SpawnAgents(float deltaT)
205 {
206 int count = m_PluginTransmissionAgents.GetAgentList().Count();
207 for (int i = 0; i < count; i++)
208 {
209 AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
210 int agent_id = agent.GetAgentType();
211
212 if (GetSingleAgentCount(agent_id) == 0 && agent.AutoinfectCheck(deltaT, m_Player))
213 AddAgent(agent_id, 100);
214 }
215 }
216
217
218 void SetAgentCount(int agent_id, float count)
219 {
220 if (count > 0)
221 {
222 //Debug.Log("+ growing agent"+ agent_id.ToString() +"to count: "+count.ToString(), "Agents");
225 }
226 else
227 {
228 //Debug.Log("- REMOVING agent"+ agent_id.ToString(), "Agents");
229 m_VirusPool.Remove(agent_id);
231 }
232 if (m_Player.m_Agents != m_AgentMask)
233 {
234 m_Player.m_Agents = m_AgentMask;
235 m_Player.SetSynchDirty();
236 }
237 }
238
240 {
241 for (int i = 0; i < m_VirusPool.Count(); i++)
242 {
243 int agent_id = m_VirusPool.GetKey(i);
244 float antibiotics_resistance = 1 - m_PluginTransmissionAgents.GetAgentAntiboticsResistanceEx(agent_id, m_Player);
246 float old_count = m_VirusPool.Get(agent_id);
247 float new_count = old_count - delta;
248 //PrintString("delta:"+delta.ToString());
249 //PrintString("old_count:"+old_count.ToString());
250 //PrintString("new_count:"+new_count.ToString());
252 }
253 }
254
255
257 {
259 int id = CachedObjectsParams.PARAM1_INT.param1;
260 int max = m_PluginTransmissionAgents.GetAgentMaxCount(Math.AbsInt(id));
261 int grow = max / 10;
262 if (id > 0)
263 AddAgent(id, grow);
264 else if (id < 0)
265 AddAgent(-id, -grow);
266 }
267
269 {
270 int count = m_PluginTransmissionAgents.GetAgentList().Count();
271 for (int i = 0; i < count; i++)
272 {
273 AgentBase agent = m_PluginTransmissionAgents.GetAgentList().GetElement(i);
274 string agent_name = agent.GetName();
275 int agent_id = agent.GetAgentType();
276 int max_agents = m_PluginTransmissionAgents.GetAgentMaxCount(agent_id);
277 string amount = GetSingleAgentCount(agent_id).ToString() + "/" + max_agents.ToString();
279 }
280 object_out.InsertAt(new Param1<int>(count), 0);
281 }
282}
EStatLevels
Definition EStatLevels.c:2
PluginBase GetPlugin(typename plugin_type)
bool IsPluginManagerExists()
static ref Param1< int > PARAM1_INT
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
Definition EnMath.c:7
ref map< int, float > m_VirusPool
void OnStoreSave(ParamsWriteContext ctx)
void RemoteGrowRequestDebug(ParamsReadContext ctx)
void PlayerAgentPool(PlayerBase player)
PluginTransmissionAgents m_PluginTransmissionAgents
void RemoveAgent(int agent_id)
ref array< int > m_VirusPoolArray
void AddAgent(int agent_id, float count)
PlayerBase m_Player
void ImmuneSystemTick(float value, float deltaT)
void AntibioticsAttack(float attack_value)
bool OnStoreLoad(ParamsReadContext ctx, int version)
void DigestAgent(int agent_id, float count)
const int STORAGE_VERSION
void SetAgentCount(int agent_id, float count)
void GetDebugObject(array< ref Param > object_out)
int GetSingleAgentCount(int agent_id)
void SpawnAgents(float deltaT)
void GrowAgents(float deltaT)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
static proto int AbsInt(int i)
Returns absolute value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.