Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
constructionactiondata.c
Go to the documentation of this file.
2{
4
5 //base building
8
9 int m_PartIndex; //used on client only, action synchronizes it to server to avoid mismatch
13
14 //combination lock
16
17 //attaching
20 //detaching
22
25
27
48
50 {
51 if (g_Game && (g_Game.IsClient() || !g_Game.IsMultiplayer()))
52 {
54 {
55 m_ActionVariantManager.GetOnUpdateInvoker().Remove(OnUpdateActions);
56 }
57
59 {
60 m_ActionNoToolVariantManager.GetOnUpdateInvoker().Remove(OnUpdateActionsNoTool);
61 }
62 }
63 }
64
65 //************************************************/
66 // Base building
67 //************************************************/
69 {
70 return m_MainPartName;
71 }
72
74 {
76 }
77
78 void SetTarget( Object target )
79 {
80 m_Target = target;
81 }
82
84 {
85 return m_Target;
86 }
87
88 void SetTargetPart( ConstructionPart target_part )
89 {
90 m_TargetPart = target_part;
91 }
92
97
98 void SetSlotId( int slot_id )
99 {
100 m_SlotId = slot_id;
101 }
102
104 {
105 return m_SlotId;
106 }
107
108 void SetActionInitiator( PlayerBase action_initiator )
109 {
110 m_ActionInitiator = action_initiator;
111 }
112
117
118 // deprecated
120 {
121 }
122
123 // deprecated
124 void RefreshPartsToBuild( string main_part_name, ItemBase tool, bool use_tool = true )
125 {
126
127 }
128
129 void OnUpdateActions( Object item, Object target, int component_index )
130 {
131 ItemBase tool = ItemBase.Cast( item );
132 if ( tool )
133 {
134 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
135 if ( base_building_object )
136 {
137 string main_part_name = target.GetActionComponentName( component_index );
138 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildParts, tool, m_MainPartName, true );
139 m_ActionVariantManager.SetActionVariantCount(m_BuildParts.Count());
140 }
141 else
142 {
143 m_BuildParts.Clear();
145 }
146
147 }
148 else
149 {
150 m_BuildParts.Clear();
152 }
153 //not needed
154 //m_Target = target;
155 }
156
157 void OnUpdateActionsNoTool( Object item, Object target, int component_index )
158 {
159 BaseBuildingBase base_building_object = BaseBuildingBase.Cast( target );
160 if ( base_building_object )
161 {
162 string main_part_name = target.GetActionComponentName( component_index );
163 base_building_object.GetConstruction().GetConstructionPartsToBuild( main_part_name, m_BuildPartsNoTool, null, m_MainPartNameNoTool, false );
164 m_ActionNoToolVariantManager.SetActionVariantCount(m_BuildPartsNoTool.Count());
165 }
166 else
167 {
168 m_BuildPartsNoTool.Clear();
170 }
171 }
172
174 {
175 return m_BuildParts.Count();
176 }
177
178 // deprecated
180 {
181 return null;
182 }
183
185 {
186 if( m_BuildParts.Count() > idx )
187 {
188 return m_BuildParts.Get( idx );
189 }
190 return null;
191 }
192
194 {
195 if( m_BuildPartsNoTool.Count() > idx )
196 {
197 return m_BuildPartsNoTool.Get( idx );
198 }
199 return null;
200 }
201
202 //************************************************/
203 // Combination lock
204 //************************************************/
209
210 void SetCombinationLock( CombinationLock combination_lock )
211 {
212 m_CombinationLock = CombinationLock.Cast( combination_lock );
213 }
214
216 {
217 string dial_text;
218
219 if ( m_CombinationLock )
220 {
221 string combination_text = m_CombinationLock.GetCombination().ToString();
222
223 //insert zeros to dials with 0 value
224 int length_diff = m_CombinationLock.GetLockDigits() - combination_text.Length();
225 for ( int i = 0; i < length_diff; ++i )
226 {
227 combination_text = "0" + combination_text;
228 }
229
230 //assemble the whole combination with selected part
231 for ( int j = 0; j < m_CombinationLock.GetLockDigits(); ++j )
232 {
233 if ( j == m_CombinationLock.GetDialIndex() )
234 {
235 dial_text += string.Format( "[%1]", combination_text.Get( j ) );
236 }
237 else
238 {
239 dial_text += string.Format( " %1 ", combination_text.Get( j ) );
240 }
241 }
242 }
243
244 return dial_text;
245 }
246
247 //************************************************/
248 // Attach/Detach actions
249 //************************************************/
250 int GetAttachmentSlotFromSelection( PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection )
251 {
252 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
253
254 if ( g_Game.ConfigIsExisting( cfg_path ) )
255 {
256 int child_count = g_Game.ConfigGetChildrenCount( cfg_path );
257
258 for ( int i = 0; i < child_count; i++ )
259 {
260 string child_name;
261 g_Game.ConfigGetChildName( cfg_path, i, child_name );
262
263 string child_selection;
264 g_Game.ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
265
266 if ( selection == child_selection )
267 {
268 ref array<string> attachment_slots = new array<string>;
269 g_Game.ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
270
271 for ( int j = 0; j < attachment_slots.Count(); ++j )
272 {
273 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
274 int item_slot_count = item_to_attach.GetInventory().GetSlotIdCount();
275
276 for ( int k = 0; k < item_slot_count; ++k )
277 {
278 int item_slot_id = item_to_attach.GetInventory().GetSlotId( k );
279 ItemBase attachment_item = ItemBase.Cast( target.GetInventory().FindAttachment( item_slot_id ) );
280
281 if ( target_slot_id == item_slot_id )
282 {
283 if ( target.GetInventory().CanAddAttachmentEx( item_to_attach, item_slot_id ) && target.CanReceiveAttachment( item_to_attach, item_slot_id ) || attachment_item && attachment_item.CanBeCombined( item_to_attach ) )
284 {
285 if(target.CanDisplayAttachmentSlot(target_slot_id))
286 return item_slot_id;
287 else
288 return -1;
289 }
290 }
291 }
292 }
293 }
294 }
295 }
296
297 return -1;
298 }
299
300 void GetAttachmentsFromSelection( EntityAI target, string selection, out array<EntityAI> attachments )
301 {
302 attachments.Clear(); //clear output
303
304 string cfg_path = "cfgVehicles" + " " + target.GetType() + " "+ "GUIInventoryAttachmentsProps";
305 if ( g_Game.ConfigIsExisting( cfg_path ) )
306 {
307 int child_count = g_Game.ConfigGetChildrenCount( cfg_path );
308
309 for ( int i = 0; i < child_count; i++ )
310 {
311 string child_name;
312 g_Game.ConfigGetChildName( cfg_path, i, child_name );
313
314 string child_selection;
315 g_Game.ConfigGetText( cfg_path + " " + child_name + " " + "selection", child_selection );
316
317 if ( selection == child_selection )
318 {
319 ref array<string> attachment_slots = new array<string>;
320 g_Game.ConfigGetTextArray( cfg_path + " " + child_name + " " + "attachmentSlots", attachment_slots );
321
322 for ( int j = 0; j < attachment_slots.Count(); ++j )
323 {
324 int target_slot_id = InventorySlots.GetSlotIdFromString( attachment_slots.Get( j ) );
325
326 //is attached and can be detached
327 EntityAI attachment = target.GetInventory().FindAttachment( target_slot_id );
328 if ( attachment && target.GetInventory().CanRemoveAttachmentEx( attachment, target_slot_id ) && !target.GetInventory().GetSlotLock( target_slot_id ) )
329 {
330 attachments.Insert( attachment );
331 }
332 }
333 }
334 }
335 }
336 }
337
338 void CombineItems( ItemBase target, ItemBase item )
339 {
340 if ( target.ConfigGetBool( "canBeSplit" ) && item && !target.IsFullQuantity() )
341 {
342 int quantity_used = target.ComputeQuantityUsed( item, true );
343 if( quantity_used != 0 )
344 {
345 target.AddQuantity( quantity_used );
346 item.AddQuantity( -quantity_used );
347 }
348 }
349 }
350
351 void RefreshAttachmentsToDetach( EntityAI target, string main_part_name )
352 {
353 GetAttachmentsFromSelection( target, main_part_name, m_Attachments );
354 }
355
357 {
358 if ( GetAttachmentsToDetachCount() > 1 )
359 {
361 {
363 }
365 {
367 }
368 }
369 else
370 {
372 }
373 }
374
376 {
377 return m_Attachments.Count();
378 }
379
381 {
382 if ( GetAttachmentsToDetachCount() > 0 )
383 {
385
387 {
388 return m_Attachments.Get( m_AttachmentsIndex );
389 }
390 }
391
392 return NULL;
393 }
394
395 //************************************************/
396 // Common
397 //************************************************/
399 {
400 m_PartIndex = 0;
402 }
403}
static ActionVariantManager GetVariantManager(typename actionName)
void CombineItems(ItemBase target, ItemBase item)
ActionVariantManager m_ActionVariantManager
void GetAttachmentsFromSelection(EntityAI target, string selection, out array< EntityAI > attachments)
ref array< ConstructionPart > m_BuildPartsNoTool
ref array< EntityAI > m_Attachments
int GetAttachmentSlotFromSelection(PlayerBase player, EntityAI target, ItemBase item_to_attach, string selection)
ConstructionPart GetTargetPart()
ref array< ConstructionPart > m_BuildParts
void RefreshAttachmentsToDetach(EntityAI target, string main_part_name)
void OnUpdateActionsNoTool(Object item, Object target, int component_index)
CombinationLock GetCombinationLock()
void SetCombinationLock(CombinationLock combination_lock)
ActionVariantManager m_ActionNoToolVariantManager
void SetActionInitiator(PlayerBase action_initiator)
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
ref ConstructionPart m_TargetPart
void SetTargetPart(ConstructionPart target_part)
void RefreshPartsToBuild(string main_part_name, ItemBase tool, bool use_tool=true)
void OnUpdateActions(Object item, Object target, int component_index)
ConstructionPart GetBuildPartAtIndex(int idx)
ConstructionPart GetCurrentBuildPart()
void SetTarget(Object target)
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
override bool CanBeCombined(EntityAI other_item, bool reservation_check=true, bool stack_max_limit=false)
Definition rag.c:61
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
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'.
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
proto string Get(int index)
Gets n-th character from string.
proto native int Length()
Returns length of string.