Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
catchingcontexttraps.c
Go to the documentation of this file.
1class CatchingContextTrapsBase : CatchingContextBase
2{
8 protected int m_AttemptsCount;
9 protected ItemBase m_Bait;
10
11 override protected void DeserializeData(Param par)
12 {
14 if (Class.CastTo(p,par))
15 {
16 m_MainItem = p.param1;
17 m_AttemptsCount = p.param2;
18 }
19 }
20
21 override protected void CreateResultDataStructure()
22 {
24
25 super.CreateResultDataStructure();
26 }
27
28 override protected void ClearCatchingItemData()
29 {
30 super.ClearCatchingItemData();
31
33 m_QualityBaseMod = 0.0;
36 }
37
38 override protected void InitItemValues(EntityAI item)
39 {
40 //skip ruined or deleted items entirely
41 if (item.IsRuined() || item.IsSetForDeletion())
42 return;
43
44 string path = "" + CFG_VEHICLESPATH + " " + item.GetType() + " Trapping";
45 if (GetGame().ConfigIsExisting(path))
46 {
47 if (GetGame().ConfigIsExisting(path + " baitTypes") && GetGame().ConfigIsExisting(path + " baitTypeChances"))
48 {
49 CachedObjectsArrays.ARRAY_INT.Clear();
50 CachedObjectsArrays.ARRAY_FLOAT.Clear();
51 GetGame().ConfigGetIntArray(path + " baitTypes",CachedObjectsArrays.ARRAY_INT);
52 GetGame().ConfigGetFloatArray(path + " baitTypeChances",CachedObjectsArrays.ARRAY_FLOAT);
53 int count = CachedObjectsArrays.ARRAY_INT.Count();
54 if (count == CachedObjectsArrays.ARRAY_FLOAT.Count())
55 {
56 int key;
57 float value;
58 for (int i = 0; i < count; i++)
59 {
60 key = CachedObjectsArrays.ARRAY_INT[i];
61 value = AdjustBaitItemChance(item) * CachedObjectsArrays.ARRAY_FLOAT[i];
62 if (!m_BaitCompatibilityMap.Contains(key) || (m_BaitCompatibilityMap.Get(key).m_BaseProbability < value))
63 {
64 m_BaitCompatibilityMap.Set(key,new BaitData(value,item));
65 }
66 }
67 }
68 else
69 {
70 ErrorEx("'baitTypes' and 'baitTypeChances' arrray counts of " + item.GetType() + " do not match!",ErrorExSeverity.INFO);
71 }
72 }
73 if (GetGame().ConfigIsExisting(path + " resultQuantityBaseMod"))
74 m_QualityBaseMod += GetGame().ConfigGetFloat(path + " resultQuantityBaseMod");
75 if (GetGame().ConfigIsExisting(path + " resultQuantityDispersionMin"))
76 m_QualityDispersionMinMod += GetGame().ConfigGetFloat(path + " resultQuantityDispersionMin");
77 if (GetGame().ConfigIsExisting(path + " resultQuantityDispersionMax"))
78 m_QualityDispersionMaxMod += GetGame().ConfigGetFloat(path + " resultQuantityDispersionMax");
79 }
80 }
81
84 {
85 float ret = 1.0;
86 ItemBase ib;
87 if (Class.CastTo(ib,item))
88 {
89 //ret *= ib.GetBaitEffectivity(); //disconnected for the Time Being
90 }
91
92 return ret;
93 }
94
95 override protected void InitCatchEnviroMask()
96 {
97 vector pos = m_MainItem.GetPosition();
98 if (GetGame().SurfaceIsSea(pos[0], pos[2]))
99 m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_SEA;
100 else if (GetGame().SurfaceIsPond( pos[0], pos[2]))
101 m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_POND;
102 else
103 m_EnviroMask = AnimalCatchingConstants.MASK_ENVIRO_LAND_ALL;
104 }
105
106 override protected void Init(Param par)
107 {
108 super.Init(par);
109
111 }
112
113 override protected void SetupInitialTypes()
114 {
115 #ifdef DEVELOPER
116 if (IsCLIParam("catchingLogs"))
117 {
118 Print("********************"); //just for debug purposes to track the start
119 Print("dbgTrapz | START");
120 Print("********************");
121 }
122 #endif
123
124 super.SetupInitialTypes();
125
126 #ifdef DEVELOPER
127 if (IsCLIParam("catchingLogs"))
128 {
129 Print("***"); //just for debug purposes to track the start
130 }
131 #endif
132 }
133
135 {
137 InitCatchMethodMask(); //bait check
138 //InitCatchEnviroMask(); //skipping, raycasts are unreliable outside network bubbles
141 }
142
144 {
146 return GetCatchEnviroMask();
147 }
148
149 void SetTrapEnviroMask(int value)
150 {
151 m_EnviroMask = value;
152 }
153
155 void UpdateUsedBait(ECatchingBaitCategories type)
156 {
157 m_Bait = null;
158 if (type != ECatchingBaitCategories.BAIT_TYPE_EMPTY)
159 {
160 BaitData dta = m_BaitCompatibilityMap.Get(type);
161 if (dta)
162 {
163 ItemBase potentialBait = ItemBase.Cast(dta.m_Owner);
164 if (potentialBait != m_MainItem)
165 m_Bait = potentialBait;
166 }
167 else
168 ErrorEx("failed to acquire BaitData from type: " + type);
169 }
170
171 #ifdef DEVELOPER
172 if (IsCLIParam("catchingLogs"))
173 {
174 if (m_Bait)
175 Print("dbgTrapz | UpdateUsedBait to: " + m_Bait + " | with base bait probability used: " + m_BaitCompatibilityMap.Get(type).m_BaseProbability);
176 else
177 Print("dbgTrapz | UpdateUsedBait to 'null'!");
178 }
179 #endif
180 }
181
183 {
184 int baitType = ECatchingBaitCategories.BAIT_TYPE_EMPTY;
185 int usedType = -1;
186 float probability = -1;
187 float highestProbability = 0.0;
188 int count = m_BaitCompatibilityMap.Count();
189 for (int i = 0; i < count; i++)
190 {
191 baitType = m_BaitCompatibilityMap.GetKey(i);
192 probability = m_BaitCompatibilityMap.Get(baitType).m_BaseProbability * yItem.GetBaitTypeSensitivity(baitType);
193 if (probability > highestProbability)
194 {
195 highestProbability = probability;
196 usedType = baitType;
197 }
198 }
199
200 m_CumulativeTrappingSuccess = Math.Clamp(highestProbability,0,1);
201 #ifdef DEVELOPER
202 if (IsCLIParam("catchingLogs"))
203 {
204 //Print("********************");
205 Print("dbgTrapz | using bait type: " + baitType + " to catch: " + yItem);
206 }
207 #endif
208 UpdateUsedBait(usedType);
209
210 #ifdef DEVELOPER
211 if (IsCLIParam("catchingLogs"))
212 {
213 float dbgProb;
215 Print("dbgTrapz | starting catching of " + yItem + " | at probability: " + dbgProb + " | with target success: " + m_CumulativeTrappingSuccess);
216 }
217 #endif
218 }
219
220 override bool ModifySignalProbability(inout float probability)
221 {
222 probability = 1 - Math.Pow((1 - m_CumulativeTrappingSuccess),(1/m_AttemptsCount));
223
224 return true;
225 }
226
228 {
229 if (m_Bait)
230 m_Bait.DeleteSafe();
231 }
232
233 void ReduceBaitQty(float qtyNorm)
234 {
235 if (m_Bait)
236 {
237 if (m_Bait.HasQuantity() && !m_Bait.IsSplitable())
238 m_Bait.SetQuantityNormalized((m_Bait.GetQuantityNormalized() - qtyNorm));
239 else
240 m_Bait.DeleteSafe();
241 }
242 }
243}
244
245class CatchingContextTrapFishSmall : CatchingContextTrapsBase
246{
247 override protected void InitCatchMethodMask()
248 {
249 m_MethodMask = AnimalCatchingConstants.MASK_METHOD_FISHTRAP_SMALL;
250 }
251}
255 override protected void InitCatchMethodMask()
257 m_MethodMask = AnimalCatchingConstants.MASK_METHOD_FISHTRAP_LARGE;
258 }
259}
260
261class CatchingContextTrapLandSnare : CatchingContextTrapsBase
262{
263 override protected void InitCatchMethodMask()
264 {
265 m_MethodMask = AnimalCatchingConstants.MASK_METHOD_LANDTRAP_SNARE;
267}
int GetCatchEnviroMask()
float m_QualityBaseMod
ref map< int, ref BaitData > m_BaitCompatibilityMap
class BaitData m_MainItem
Definition actionbase.c:36
ref CatchingResultBasic m_Result
void GenerateResult()
int m_MethodMask
float m_QualityDispersionMinMod
void InitCatchingItemData()
float m_QualityDispersionMaxMod
int m_EnviroMask
void SetupProbabilityArray()
CatchingContextTrapsBase CatchingContextBase InitCatchMethodMask()
float AdjustBaitItemChance(EntityAI item)
Allows for adjustment of all catch probabilities from item qualities (damage, qty....
void ReduceBaitQty(float qtyNorm)
float m_CumulativeTrappingSuccess
after N attempts, the chance to catch should be this. Only highest one applies. @NOTE: Take care,...
void InitItemValues(EntityAI item)
override void UpdateBaseProbability(YieldItemBase yItem)
override bool ModifySignalProbability(inout float probability)
void UpdateUsedBait(ECatchingBaitCategories type)
if non-empty bait type is used, some 'Bait' attachment is picked as an active bait (currently no dire...
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition enmath.c:7
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
float GetBaitTypeSensitivity(ECatchingBaitCategories type)
proto native CGame GetGame()
ErrorExSeverity
Definition endebug.c:62
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
const string CFG_VEHICLESPATH
Definition constants.c:220
proto native bool IsCLIParam(string param)
Returns if command line argument is present.